1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-09 08:54:40 +00:00
kickc/src/test/ref/interrupt-volatile-reuse-problem2.log

794 lines
27 KiB
Plaintext

Resolved forward reference irq to interrupt(KERNEL_MIN)(void()) irq()
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(volatile byte) col1 ← (byte) 0
to:@1
(void()) main()
main: scope:[main] from @1
*((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq()
to:main::@1
main::@1: scope:[main] from main main::@7
if(true) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
(byte) main::x#0 ← (byte) 0
to:main::@3
main::@3: scope:[main] from main::@2 main::@7
(byte) main::x#6 ← phi( main::@2/(byte) main::x#0 main::@7/(byte) main::x#1 )
(byte) main::y#0 ← (byte) 0
to:main::@4
main::@4: scope:[main] from main::@3 main::@6
(byte) main::x#4 ← phi( main::@3/(byte) main::x#6 main::@6/(byte) main::x#5 )
(byte) main::y#4 ← phi( main::@3/(byte) main::y#0 main::@6/(byte) main::y#1 )
(byte) main::a#0 ← (byte) 0
to:main::@5
main::@5: scope:[main] from main::@4 main::@5
(byte) main::x#2 ← phi( main::@4/(byte) main::x#4 main::@5/(byte) main::x#2 )
(byte) main::y#2 ← phi( main::@4/(byte) main::y#4 main::@5/(byte) main::y#2 )
(byte) main::a#2 ← phi( main::@4/(byte) main::a#0 main::@5/(byte) main::a#1 )
(byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#2
*((const nomodify byte*) SCREEN + (byte) main::x#2) ← (byte~) main::$0
(byte) main::a#1 ← (byte) main::a#2 + rangenext(0,$a)
(bool~) main::$1 ← (byte) main::a#1 != rangelast(0,$a)
if((bool~) main::$1) goto main::@5
to:main::@6
main::@6: scope:[main] from main::@5
(byte) main::x#5 ← phi( main::@5/(byte) main::x#2 )
(byte) main::y#3 ← phi( main::@5/(byte) main::y#2 )
(byte) main::y#1 ← (byte) main::y#3 + rangenext(0,$a)
(bool~) main::$2 ← (byte) main::y#1 != rangelast(0,$a)
if((bool~) main::$2) goto main::@4
to:main::@7
main::@7: scope:[main] from main::@6
(byte) main::x#3 ← phi( main::@6/(byte) main::x#5 )
(byte) main::x#1 ← (byte) main::x#3 + rangenext(0,$a)
(bool~) main::$3 ← (byte) main::x#1 != rangelast(0,$a)
if((bool~) main::$3) goto main::@3
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
interrupt(KERNEL_MIN)(void()) irq()
irq: scope:[irq] from
*((const nomodify byte*) IRQ_STATUS) ← (number) 1
asm { lda$dc0d }
*((const nomodify byte*) SCREEN + (number) $28) ← (volatile byte) col1
(volatile byte) col1 ← ++ (volatile byte) col1
to:irq::@return
irq::@return: scope:[irq] from irq
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const nomodify byte*) IRQ_STATUS = (byte*)(number) $d019
(const nomodify void()**) KERNEL_IRQ = (void()**)(number) $314
(const nomodify byte*) SCREEN = (byte*)(number) $400
(volatile byte) col1 loadstore
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(byte~) main::$0
(bool~) main::$1
(bool~) main::$2
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@return
(byte) main::a
(byte) main::a#0
(byte) main::a#1
(byte) main::a#2
(byte) main::x
(byte) main::x#0
(byte) main::x#1
(byte) main::x#2
(byte) main::x#3
(byte) main::x#4
(byte) main::x#5
(byte) main::x#6
(byte) main::y
(byte) main::y#0
(byte) main::y#1
(byte) main::y#2
(byte) main::y#3
(byte) main::y#4
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) IRQ_STATUS) ← (number) 1
Adding number conversion cast (unumber) $28 in *((const nomodify byte*) SCREEN + (number) $28) ← (volatile byte) col1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((const nomodify byte*) IRQ_STATUS) ← (unumber)(number) 1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (void()**) 788
Simplifying constant pointer cast (byte*) 53273
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast $28
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::y#2 = main::y#3
Alias main::x#2 = main::x#5 main::x#3
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) main::y#2 (byte) main::y#4
Identical Phi Values (byte) main::x#2 (byte) main::x#4
Successful SSA optimization Pass2IdenticalPhiElimination
Identical Phi Values (byte) main::x#4 (byte) main::x#6
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [13] if((byte) main::a#1!=rangelast(0,$a)) goto main::@5
Simple Condition (bool~) main::$2 [16] if((byte) main::y#1!=rangelast(0,$a)) goto main::@4
Simple Condition (bool~) main::$3 [19] if((byte) main::x#1!=rangelast(0,$a)) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::x#0 = 0
Constant (const byte) main::y#0 = 0
Constant (const byte) main::a#0 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [2] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Resolved ranged next value [11] main::a#1 ← ++ main::a#2 to ++
Resolved ranged comparison value [13] if(main::a#1!=rangelast(0,$a)) goto main::@5 to (number) $b
Resolved ranged next value [14] main::y#1 ← ++ main::y#4 to ++
Resolved ranged comparison value [16] if(main::y#1!=rangelast(0,$a)) goto main::@4 to (number) $b
Resolved ranged next value [17] main::x#1 ← ++ main::x#6 to ++
Resolved ranged comparison value [19] if(main::x#1!=rangelast(0,$a)) goto main::@3 to (number) $b
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Adding number conversion cast (unumber) $b in if((byte) main::a#1!=(number) $b) goto main::@5
Adding number conversion cast (unumber) $b in if((byte) main::y#1!=(number) $b) goto main::@4
Adding number conversion cast (unumber) $b in if((byte) main::x#1!=(number) $b) goto main::@3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $b
Finalized unsigned number type (byte) $b
Finalized unsigned number type (byte) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::x#0
Inlining constant with var siblings (const byte) main::y#0
Inlining constant with var siblings (const byte) main::a#0
Constant inlined main::a#0 = (byte) 0
Constant inlined main::x#0 = (byte) 0
Constant inlined main::y#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+$28)
Successful SSA optimization Pass2ConstantAdditionElimination
Added new block during phi lifting main::@8(between main::@7 and main::@3)
Added new block during phi lifting main::@9(between main::@6 and main::@4)
Added new block during phi lifting main::@10(between main::@5 and main::@5)
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2
Created 3 initial phi equivalence classes
Coalesced [19] main::x#7 ← main::x#1
Coalesced [20] main::y#5 ← main::y#1
Coalesced [21] main::a#3 ← main::a#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@1
Culled Empty Block (label) main::@2
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Renumbering block main::@3 to main::@1
Renumbering block main::@4 to main::@2
Renumbering block main::@5 to main::@3
Renumbering block main::@6 to main::@4
Renumbering block main::@7 to main::@5
Renumbering block main::@8 to main::@6
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main::@6
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] (volatile byte) col1 ← (byte) 0
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
[4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq()
to:main::@1
main::@1: scope:[main] from main main::@5 main::@6
[5] (byte) main::x#6 ← phi( main/(byte) 0 main::@6/(byte) main::x#1 main::@5/(byte) 0 )
to:main::@2
main::@2: scope:[main] from main::@1 main::@4
[6] (byte) main::y#4 ← phi( main::@1/(byte) 0 main::@4/(byte) main::y#1 )
to:main::@3
main::@3: scope:[main] from main::@2 main::@3
[7] (byte) main::a#2 ← phi( main::@2/(byte) 0 main::@3/(byte) main::a#1 )
[8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4
[9] *((const nomodify byte*) SCREEN + (byte) main::x#6) ← (byte~) main::$0
[10] (byte) main::a#1 ← ++ (byte) main::a#2
[11] if((byte) main::a#1!=(byte) $b) goto main::@3
to:main::@4
main::@4: scope:[main] from main::@3
[12] (byte) main::y#1 ← ++ (byte) main::y#4
[13] if((byte) main::y#1!=(byte) $b) goto main::@2
to:main::@5
main::@5: scope:[main] from main::@4
[14] (byte) main::x#1 ← ++ (byte) main::x#6
[15] if((byte) main::x#1!=(byte) $b) goto main::@6
to:main::@1
main::@6: scope:[main] from main::@5
[16] phi()
to:main::@1
interrupt(KERNEL_MIN)(void()) irq()
irq: scope:[irq] from
[17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1
asm { lda$dc0d }
[19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1
[20] (volatile byte) col1 ← ++ (volatile byte) col1
to:irq::@return
irq::@return: scope:[irq] from irq
[21] return
to:@return
VARIABLE REGISTER WEIGHTS
(volatile byte) col1 loadstore 2.6666666666666665
interrupt(KERNEL_MIN)(void()) irq()
(void()) main()
(byte~) main::$0 200002.0
(byte) main::a
(byte) main::a#1 150001.5
(byte) main::a#2 100001.0
(byte) main::x
(byte) main::x#1 701.0
(byte) main::x#6 11233.666666666668
(byte) main::y
(byte) main::y#1 15001.5
(byte) main::y#4 20000.499999999996
Initial phi equivalence classes
[ main::x#6 main::x#1 ]
[ main::y#4 main::y#1 ]
[ main::a#2 main::a#1 ]
Added variable col1 to live range equivalence class [ col1 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Complete equivalence classes
[ main::x#6 main::x#1 ]
[ main::y#4 main::y#1 ]
[ main::a#2 main::a#1 ]
[ col1 ]
[ main::$0 ]
Allocated zp[1]:2 [ main::x#6 main::x#1 ]
Allocated zp[1]:3 [ main::y#4 main::y#1 ]
Allocated zp[1]:4 [ main::a#2 main::a#1 ]
Allocated zp[1]:5 [ col1 ]
Allocated zp[1]:6 [ main::$0 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label KERNEL_IRQ = $314
.label IRQ_STATUS = $d019
.label SCREEN = $400
.label col1 = 5
// @begin
__bbegin:
// [0] (volatile byte) col1 ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z col1
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label __0 = 6
.label a = 4
.label y = 3
.label x = 2
// [4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2
lda #<irq
sta KERNEL_IRQ
lda #>irq
sta KERNEL_IRQ+1
// [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
__b1_from_main:
__b1_from___b5:
// [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuz1=vbuc1
lda #0
sta.z x
jmp __b1
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
// [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1
lda #0
sta.z y
jmp __b2
// [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
__b2_from___b4:
// [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy
jmp __b2
// main::@2
__b2:
// [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
__b3_from___b2:
// [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuz1=vbuc1
lda #0
sta.z a
jmp __b3
// [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
__b3_from___b3:
// [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy
jmp __b3
// main::@3
__b3:
// [8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4 -- vbuz1=vbuz2_plus_vbuz3
lda.z a
clc
adc.z y
sta.z __0
// [9] *((const nomodify byte*) SCREEN + (byte) main::x#6) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
lda.z __0
ldy.z x
sta SCREEN,y
// [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuz1=_inc_vbuz1
inc.z a
// [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuz1_neq_vbuc1_then_la1
lda #$b
cmp.z a
bne __b3_from___b3
jmp __b4
// main::@4
__b4:
// [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1
inc.z y
// [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1
lda #$b
cmp.z y
bne __b2_from___b4
jmp __b5
// main::@5
__b5:
// [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuz1=_inc_vbuz1
inc.z x
// [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuz1_neq_vbuc1_then_la1
lda #$b
cmp.z x
bne __b6_from___b5
jmp __b1_from___b5
// [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
__b6_from___b5:
jmp __b6
// main::@6
__b6:
// [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
__b1_from___b6:
// [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy
jmp __b1
}
// irq
irq: {
// entry interrupt(KERNEL_MIN)
// [17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1 -- _deref_pbuc1=vbuc2
// Acknowledge the IRQ
lda #1
sta IRQ_STATUS
// asm { lda$dc0d }
lda $dc0d
// [19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1 -- _deref_pbuc1=vbuz1
lda.z col1
sta SCREEN+$28
// [20] (volatile byte) col1 ← ++ (volatile byte) col1 -- vbuz1=_inc_vbuz1
inc.z col1
jmp __breturn
// irq::@return
__breturn:
// [21] return - exit interrupt(KERNEL_MIN)
jmp $ea81
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (volatile byte) col1 ← (byte) 0 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq() [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4 [ main::x#6 main::y#4 main::a#2 main::$0 ] ( main:2 [ main::x#6 main::y#4 main::a#2 main::$0 ] { } ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::x#6 main::x#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::y#4 main::y#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::a#2 main::a#1 ]
Statement [17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1 [ col1 ] ( [ col1 ] { } ) always clobbers reg byte a
Statement asm { lda$dc0d } always clobbers reg byte a
Statement [19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1 [ col1 ] ( [ col1 ] { } ) always clobbers reg byte a
Statement [0] (volatile byte) col1 ← (byte) 0 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq() [ ] ( main:2 [ ] { } ) always clobbers reg byte a
Statement [8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4 [ main::x#6 main::y#4 main::a#2 main::$0 ] ( main:2 [ main::x#6 main::y#4 main::a#2 main::$0 ] { } ) always clobbers reg byte a
Statement [17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1 [ col1 ] ( [ col1 ] { } ) always clobbers reg byte a
Statement asm { lda$dc0d } always clobbers reg byte a
Statement [19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1 [ col1 ] ( [ col1 ] { } ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::x#6 main::x#1 ] : zp[1]:2 , reg byte x , reg byte y ,
Potential registers zp[1]:3 [ main::y#4 main::y#1 ] : zp[1]:3 , reg byte x , reg byte y ,
Potential registers zp[1]:4 [ main::a#2 main::a#1 ] : zp[1]:4 , reg byte x , reg byte y ,
Potential registers zp[1]:5 [ col1 ] : zp[1]:5 ,
Potential registers zp[1]:6 [ main::$0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 250,002.5: zp[1]:4 [ main::a#2 main::a#1 ] 200,002: zp[1]:6 [ main::$0 ] 35,002: zp[1]:3 [ main::y#4 main::y#1 ] 11,934.67: zp[1]:2 [ main::x#6 main::x#1 ]
Uplift Scope [] 2.67: zp[1]:5 [ col1 ]
Uplift Scope [irq]
Uplifting [main] best 323337 combination reg byte y [ main::a#2 main::a#1 ] reg byte a [ main::$0 ] zp[1]:3 [ main::y#4 main::y#1 ] reg byte x [ main::x#6 main::x#1 ]
Limited combination testing to 100 combinations of 108 possible.
Uplifting [] best 323337 combination zp[1]:5 [ col1 ]
Uplifting [irq] best 323337 combination
Attempting to uplift remaining variables inzp[1]:3 [ main::y#4 main::y#1 ]
Uplifting [main] best 323337 combination zp[1]:3 [ main::y#4 main::y#1 ]
Attempting to uplift remaining variables inzp[1]:5 [ col1 ]
Uplifting [] best 323337 combination zp[1]:5 [ col1 ]
Allocated (was zp[1]:3) zp[1]:2 [ main::y#4 main::y#1 ]
Allocated (was zp[1]:5) zp[1]:3 [ col1 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label KERNEL_IRQ = $314
.label IRQ_STATUS = $d019
.label SCREEN = $400
.label col1 = 3
// @begin
__bbegin:
// [0] (volatile byte) col1 ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z col1
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label y = 2
// [4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2
lda #<irq
sta KERNEL_IRQ
lda #>irq
sta KERNEL_IRQ+1
// [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
__b1_from_main:
__b1_from___b5:
// [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuxx=vbuc1
ldx #0
jmp __b1
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
// [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1
lda #0
sta.z y
jmp __b2
// [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
__b2_from___b4:
// [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy
jmp __b2
// main::@2
__b2:
// [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
__b3_from___b2:
// [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1
ldy #0
jmp __b3
// [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
__b3_from___b3:
// [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy
jmp __b3
// main::@3
__b3:
// [8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4 -- vbuaa=vbuyy_plus_vbuz1
tya
clc
adc.z y
// [9] *((const nomodify byte*) SCREEN + (byte) main::x#6) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
sta SCREEN,x
// [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy
iny
// [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1
cpy #$b
bne __b3_from___b3
jmp __b4
// main::@4
__b4:
// [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1
inc.z y
// [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1
lda #$b
cmp.z y
bne __b2_from___b4
jmp __b5
// main::@5
__b5:
// [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuxx=_inc_vbuxx
inx
// [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuxx_neq_vbuc1_then_la1
cpx #$b
bne __b6_from___b5
jmp __b1_from___b5
// [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
__b6_from___b5:
jmp __b6
// main::@6
__b6:
// [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
__b1_from___b6:
// [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy
jmp __b1
}
// irq
irq: {
// entry interrupt(KERNEL_MIN)
// [17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1 -- _deref_pbuc1=vbuc2
// Acknowledge the IRQ
lda #1
sta IRQ_STATUS
// asm { lda$dc0d }
lda $dc0d
// [19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1 -- _deref_pbuc1=vbuz1
lda.z col1
sta SCREEN+$28
// [20] (volatile byte) col1 ← ++ (volatile byte) col1 -- vbuz1=_inc_vbuz1
inc.z col1
jmp __breturn
// irq::@return
__breturn:
// [21] return - exit interrupt(KERNEL_MIN)
jmp $ea81
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b5
Removing instruction jmp __b6
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b3_from___b3 with __b3
Replacing label __b2_from___b4 with __b2
Replacing label __b6_from___b5 with __b6
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Removing instruction __b1_from_main:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b4:
Removing instruction __b3_from___b2:
Removing instruction __b3_from___b3:
Removing instruction __b6_from___b5:
Removing instruction __b1_from___b6:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __bend:
Removing instruction __b4:
Removing instruction __b5:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Skipping double jump to __b1 in bne __b6
Succesful ASM optimization Pass5DoubleJumpElimination
Relabelling long label __b1_from___b5 to __b4
Succesful ASM optimization Pass5RelabelLongLabels
Adding RTS to root block
Succesful ASM optimization Pass5AddMainRts
Removing instruction jmp __b2
Removing instruction jmp __b3
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b6:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing unreachable instruction jmp __b1
Succesful ASM optimization Pass5UnreachableCodeElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) IRQ_STATUS = (byte*) 53273
(const nomodify void()**) KERNEL_IRQ = (void()**) 788
(const nomodify byte*) SCREEN = (byte*) 1024
(volatile byte) col1 loadstore zp[1]:3 2.6666666666666665
interrupt(KERNEL_MIN)(void()) irq()
(label) irq::@return
(void()) main()
(byte~) main::$0 reg byte a 200002.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(byte) main::a
(byte) main::a#1 reg byte y 150001.5
(byte) main::a#2 reg byte y 100001.0
(byte) main::x
(byte) main::x#1 reg byte x 701.0
(byte) main::x#6 reg byte x 11233.666666666668
(byte) main::y
(byte) main::y#1 y zp[1]:2 15001.5
(byte) main::y#4 y zp[1]:2 20000.499999999996
reg byte x [ main::x#6 main::x#1 ]
zp[1]:2 [ main::y#4 main::y#1 ]
reg byte y [ main::a#2 main::a#1 ]
zp[1]:3 [ col1 ]
reg byte a [ main::$0 ]
FINAL ASSEMBLER
Score: 223704
// File Comments
// Illustrates problem where volatiles reuse ZP addresses of other variables
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label KERNEL_IRQ = $314
.label IRQ_STATUS = $d019
.label SCREEN = $400
.label col1 = 3
// @begin
__bbegin:
// col1 = 0
// [0] (volatile byte) col1 ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z col1
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
jsr main
rts
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.label y = 2
// *KERNEL_IRQ = &irq
// [4] *((const nomodify void()**) KERNEL_IRQ) ← &interrupt(KERNEL_MIN)(void()) irq() -- _deref_pptc1=pprc2
lda #<irq
sta KERNEL_IRQ
lda #>irq
sta KERNEL_IRQ+1
// [5] phi from main main::@5 to main::@1 [phi:main/main::@5->main::@1]
__b4:
// [5] phi (byte) main::x#6 = (byte) 0 [phi:main/main::@5->main::@1#0] -- vbuxx=vbuc1
ldx #0
// main::@1
__b1:
// [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
// [6] phi (byte) main::y#4 = (byte) 0 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1
lda #0
sta.z y
// [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
// [6] phi (byte) main::y#4 = (byte) main::y#1 [phi:main::@4->main::@2#0] -- register_copy
// main::@2
__b2:
// [7] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
// [7] phi (byte) main::a#2 = (byte) 0 [phi:main::@2->main::@3#0] -- vbuyy=vbuc1
ldy #0
// [7] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
// [7] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@3->main::@3#0] -- register_copy
// main::@3
__b3:
// a+y
// [8] (byte~) main::$0 ← (byte) main::a#2 + (byte) main::y#4 -- vbuaa=vbuyy_plus_vbuz1
tya
clc
adc.z y
// SCREEN[x] = a+y
// [9] *((const nomodify byte*) SCREEN + (byte) main::x#6) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
sta SCREEN,x
// for (byte a:0..10)
// [10] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy
iny
// [11] if((byte) main::a#1!=(byte) $b) goto main::@3 -- vbuyy_neq_vbuc1_then_la1
cpy #$b
bne __b3
// main::@4
// for(byte y: 0..10)
// [12] (byte) main::y#1 ← ++ (byte) main::y#4 -- vbuz1=_inc_vbuz1
inc.z y
// [13] if((byte) main::y#1!=(byte) $b) goto main::@2 -- vbuz1_neq_vbuc1_then_la1
lda #$b
cmp.z y
bne __b2
// main::@5
// for(byte x: 0..10)
// [14] (byte) main::x#1 ← ++ (byte) main::x#6 -- vbuxx=_inc_vbuxx
inx
// [15] if((byte) main::x#1!=(byte) $b) goto main::@6 -- vbuxx_neq_vbuc1_then_la1
cpx #$b
bne __b1
jmp __b4
// [16] phi from main::@5 to main::@6 [phi:main::@5->main::@6]
// main::@6
// [5] phi from main::@6 to main::@1 [phi:main::@6->main::@1]
// [5] phi (byte) main::x#6 = (byte) main::x#1 [phi:main::@6->main::@1#0] -- register_copy
}
// irq
irq: {
// entry interrupt(KERNEL_MIN)
// *IRQ_STATUS = 1
// [17] *((const nomodify byte*) IRQ_STATUS) ← (byte) 1 -- _deref_pbuc1=vbuc2
// Acknowledge the IRQ
lda #1
sta IRQ_STATUS
// asm
// asm { lda$dc0d }
lda $dc0d
// SCREEN[40] = col1++
// [19] *((const nomodify byte*) SCREEN+(byte) $28) ← (volatile byte) col1 -- _deref_pbuc1=vbuz1
lda.z col1
sta SCREEN+$28
// SCREEN[40] = col1++;
// [20] (volatile byte) col1 ← ++ (volatile byte) col1 -- vbuz1=_inc_vbuz1
inc.z col1
// irq::@return
// }
// [21] return - exit interrupt(KERNEL_MIN)
jmp $ea81
}
// File Data