Inlined call call __init CONTROL FLOW GRAPH SSA void main() main: scope:[main] from __start::@1 main::y#0 = 5 to:main::@1 main::@1: scope:[main] from main main::@3 main::y#2 = phi( main/main::y#0, main::@3/main::y#1 ) main::$5 = (word)main::y#2 main::$0 = main::$5 * $28 main::$1 = SCREEN + main::$0 main::line#0 = main::$1 main::x#0 = 5 to:main::@2 main::@2: scope:[main] from main::@1 main::@2 main::line#1 = phi( main::@1/main::line#0, main::@2/main::line#1 ) main::y#3 = phi( main::@1/main::y#2, main::@2/main::y#3 ) main::x#2 = phi( main::@1/main::x#0, main::@2/main::x#1 ) main::$2 = main::x#2 + main::y#3 main::line#1[main::x#2] = main::$2 main::x#1 = main::x#2 + rangenext(5,$f) main::$3 = main::x#1 != rangelast(5,$f) if(main::$3) goto main::@2 to:main::@3 main::@3: scope:[main] from main::@2 main::y#4 = phi( main::@2/main::y#3 ) main::y#1 = main::y#4 + rangenext(5,$f) main::$4 = main::y#1 != rangelast(5,$f) if(main::$4) goto main::@1 to:main::@return main::@return: scope:[main] from main::@3 return to:@return void __start() __start: scope:[__start] from to:__start::__init1 __start::__init1: scope:[__start] from __start to:__start::@1 __start::@1: scope:[__start] from __start::__init1 call main to:__start::@2 __start::@2: scope:[__start] from __start::@1 to:__start::@return __start::@return: scope:[__start] from __start::@2 return to:@return SYMBOL TABLE SSA const byte* SCREEN = (byte*)$400 void __start() void main() number~ main::$0 byte*~ main::$1 byte~ main::$2 bool~ main::$3 bool~ main::$4 word~ main::$5 byte* main::line byte* main::line#0 byte* main::line#1 byte main::x byte main::x#0 byte main::x#1 byte main::x#2 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) $28 in main::$0 = main::$5 * $28 Adding number conversion cast (unumber) main::$0 in main::$0 = main::$5 * (unumber)$28 Successful SSA optimization PassNAddNumberTypeConversions Simplifying constant pointer cast (byte*) 1024 Simplifying constant integer cast $28 Successful SSA optimization PassNCastSimplification Finalized unsigned number type (byte) $28 Successful SSA optimization PassNFinalizeNumberTypeConversions Inferred type updated to word in main::$0 = main::$5 * $28 Alias main::line#0 = main::$1 Alias main::y#3 = main::y#4 Successful SSA optimization Pass2AliasElimination Identical Phi Values main::y#3 main::y#2 Identical Phi Values main::line#1 main::line#0 Successful SSA optimization Pass2IdenticalPhiElimination Simple Condition main::$3 [11] if(main::x#1!=rangelast(5,$f)) goto main::@2 Simple Condition main::$4 [14] if(main::y#1!=rangelast(5,$f)) goto main::@1 Successful SSA optimization Pass2ConditionalJumpSimplification Constant main::y#0 = 5 Constant main::x#0 = 5 Successful SSA optimization Pass2ConstantIdentification Resolved ranged next value [9] main::x#1 = ++ main::x#2 to ++ Resolved ranged comparison value [11] if(main::x#1!=rangelast(5,$f)) goto main::@2 to $10 Resolved ranged next value [12] main::y#1 = ++ main::y#2 to ++ Resolved ranged comparison value [14] if(main::y#1!=rangelast(5,$f)) goto main::@1 to $10 Removing unused procedure __start Removing unused procedure block __start Removing unused procedure block __start::__init1 Removing unused procedure block __start::@1 Removing unused procedure block __start::@2 Removing unused procedure block __start::@return Successful SSA optimization PassNEliminateEmptyStart Adding number conversion cast (unumber) $10 in [8] if(main::x#1!=$10) goto main::@2 Adding number conversion cast (unumber) $10 in [10] if(main::y#1!=$10) goto main::@1 Successful SSA optimization PassNAddNumberTypeConversions Simplifying constant integer cast $10 Simplifying constant integer cast $10 Successful SSA optimization PassNCastSimplification Finalized unsigned number type (byte) $10 Finalized unsigned number type (byte) $10 Successful SSA optimization PassNFinalizeNumberTypeConversions Rewriting multiplication to use shift and addition[2] main::$0 = main::$5 * $28 Inlining constant with var siblings main::y#0 Inlining constant with var siblings main::x#0 Constant inlined main::x#0 = 5 Constant inlined main::y#0 = 5 Successful SSA optimization Pass2ConstantInlining Alias main::$0 = main::$8 Successful SSA optimization Pass2AliasElimination Added new block during phi lifting main::@4(between main::@3 and main::@1) Added new block during phi lifting main::@5(between main::@2 and main::@2) Adding NOP phi() at start of main CALL GRAPH Created 2 initial phi equivalence classes Coalesced [15] main::y#5 = main::y#1 Coalesced [16] main::x#3 = main::x#1 Coalesced down to 2 phi equivalence classes Culled Empty Block label main::@4 Culled Empty Block label main::@5 Adding NOP phi() at start of main FINAL CONTROL FLOW GRAPH void main() main: scope:[main] from [0] phi() to:main::@1 main::@1: scope:[main] from main main::@3 [1] main::y#2 = phi( main/5, main::@3/main::y#1 ) [2] main::$5 = (word)main::y#2 [3] main::$6 = main::$5 << 2 [4] main::$7 = main::$6 + main::$5 [5] main::$0 = main::$7 << 3 [6] main::line#0 = SCREEN + main::$0 to:main::@2 main::@2: scope:[main] from main::@1 main::@2 [7] main::x#2 = phi( main::@1/5, main::@2/main::x#1 ) [8] main::$2 = main::x#2 + main::y#2 [9] main::line#0[main::x#2] = main::$2 [10] main::x#1 = ++ main::x#2 [11] if(main::x#1!=$10) goto main::@2 to:main::@3 main::@3: scope:[main] from main::@2 [12] main::y#1 = ++ main::y#2 [13] if(main::y#1!=$10) goto main::@1 to:main::@return main::@return: scope:[main] from main::@3 [14] return to:@return VARIABLE REGISTER WEIGHTS void main() word~ main::$0 22.0 byte~ main::$2 202.0 word~ main::$5 16.5 word~ main::$6 22.0 word~ main::$7 22.0 byte* main::line byte* main::line#0 18.666666666666664 byte main::x byte main::x#1 151.5 byte main::x#2 134.66666666666666 byte main::y byte main::y#1 16.5 byte main::y#2 11.181818181818182 Initial phi equivalence classes [ main::y#2 main::y#1 ] [ main::x#2 main::x#1 ] Added variable main::$5 to live range equivalence class [ main::$5 ] Added variable main::$6 to live range equivalence class [ main::$6 ] Added variable main::$7 to live range equivalence class [ main::$7 ] Added variable main::$0 to live range equivalence class [ main::$0 ] Added variable main::line#0 to live range equivalence class [ main::line#0 ] Added variable main::$2 to live range equivalence class [ main::$2 ] Complete equivalence classes [ main::y#2 main::y#1 ] [ main::x#2 main::x#1 ] [ main::$5 ] [ main::$6 ] [ main::$7 ] [ main::$0 ] [ main::line#0 ] [ main::$2 ] Allocated zp[1]:2 [ main::y#2 main::y#1 ] Allocated zp[1]:3 [ main::x#2 main::x#1 ] Allocated zp[2]:4 [ main::$5 ] Allocated zp[2]:6 [ main::$6 ] Allocated zp[2]:8 [ main::$7 ] Allocated zp[2]:10 [ main::$0 ] Allocated zp[2]:12 [ main::line#0 ] Allocated zp[1]:14 [ main::$2 ] REGISTER UPLIFT POTENTIAL REGISTERS Statement [2] main::$5 = (word)main::y#2 [ main::y#2 main::$5 ] ( [ main::y#2 main::$5 ] { } ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::y#2 main::y#1 ] Statement [3] main::$6 = main::$5 << 2 [ main::y#2 main::$5 main::$6 ] ( [ main::y#2 main::$5 main::$6 ] { } ) always clobbers reg byte a Statement [4] main::$7 = main::$6 + main::$5 [ main::y#2 main::$7 ] ( [ main::y#2 main::$7 ] { } ) always clobbers reg byte a Statement [5] main::$0 = main::$7 << 3 [ main::y#2 main::$0 ] ( [ main::y#2 main::$0 ] { } ) always clobbers reg byte a Statement [6] main::line#0 = SCREEN + main::$0 [ main::y#2 main::line#0 ] ( [ main::y#2 main::line#0 ] { } ) always clobbers reg byte a Statement [8] main::$2 = main::x#2 + main::y#2 [ main::y#2 main::line#0 main::x#2 main::$2 ] ( [ main::y#2 main::line#0 main::x#2 main::$2 ] { } ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::x#2 main::x#1 ] Statement [2] main::$5 = (word)main::y#2 [ main::y#2 main::$5 ] ( [ main::y#2 main::$5 ] { } ) always clobbers reg byte a Statement [3] main::$6 = main::$5 << 2 [ main::y#2 main::$5 main::$6 ] ( [ main::y#2 main::$5 main::$6 ] { } ) always clobbers reg byte a Statement [4] main::$7 = main::$6 + main::$5 [ main::y#2 main::$7 ] ( [ main::y#2 main::$7 ] { } ) always clobbers reg byte a Statement [5] main::$0 = main::$7 << 3 [ main::y#2 main::$0 ] ( [ main::y#2 main::$0 ] { } ) always clobbers reg byte a Statement [6] main::line#0 = SCREEN + main::$0 [ main::y#2 main::line#0 ] ( [ main::y#2 main::line#0 ] { } ) always clobbers reg byte a Statement [8] main::$2 = main::x#2 + main::y#2 [ main::y#2 main::line#0 main::x#2 main::$2 ] ( [ main::y#2 main::line#0 main::x#2 main::$2 ] { } ) always clobbers reg byte a Potential registers zp[1]:2 [ main::y#2 main::y#1 ] : zp[1]:2 , reg byte x , reg byte y , Potential registers zp[1]:3 [ main::x#2 main::x#1 ] : zp[1]:3 , reg byte x , reg byte y , Potential registers zp[2]:4 [ main::$5 ] : zp[2]:4 , Potential registers zp[2]:6 [ main::$6 ] : zp[2]:6 , Potential registers zp[2]:8 [ main::$7 ] : zp[2]:8 , Potential registers zp[2]:10 [ main::$0 ] : zp[2]:10 , Potential registers zp[2]:12 [ main::line#0 ] : zp[2]:12 , Potential registers zp[1]:14 [ main::$2 ] : zp[1]:14 , reg byte a , reg byte x , reg byte y , REGISTER UPLIFT SCOPES Uplift Scope [main] 286.17: zp[1]:3 [ main::x#2 main::x#1 ] 202: zp[1]:14 [ main::$2 ] 27.68: zp[1]:2 [ main::y#2 main::y#1 ] 22: zp[2]:6 [ main::$6 ] 22: zp[2]:8 [ main::$7 ] 22: zp[2]:10 [ main::$0 ] 18.67: zp[2]:12 [ main::line#0 ] 16.5: zp[2]:4 [ main::$5 ] Uplift Scope [] Uplifting [main] best 4431 combination reg byte y [ main::x#2 main::x#1 ] reg byte a [ main::$2 ] zp[1]:2 [ main::y#2 main::y#1 ] zp[2]:6 [ main::$6 ] zp[2]:8 [ main::$7 ] zp[2]:10 [ main::$0 ] zp[2]:12 [ main::line#0 ] zp[2]:4 [ main::$5 ] Uplifting [] best 4431 combination Attempting to uplift remaining variables inzp[1]:2 [ main::y#2 main::y#1 ] Uplifting [main] best 4431 combination zp[1]:2 [ main::y#2 main::y#1 ] Coalescing zero page register [ zp[2]:4 [ main::$5 ] ] with [ zp[2]:8 [ main::$7 ] ] - score: 1 Coalescing zero page register [ zp[2]:10 [ main::$0 ] ] with [ zp[2]:12 [ main::line#0 ] ] - score: 1 Coalescing zero page register [ zp[2]:4 [ main::$5 main::$7 ] ] with [ zp[2]:10 [ main::$0 main::line#0 ] ] - score: 1 Allocated (was zp[2]:4) zp[2]:3 [ main::$5 main::$7 main::$0 main::line#0 ] Allocated (was zp[2]:6) zp[2]:5 [ main::$6 ] ASSEMBLER BEFORE OPTIMIZATION // File Comments // Fill a square on the screen // Upstart .pc = $801 "Basic" :BasicUpstart(main) .pc = $80d "Program" // Global Constants & labels .label SCREEN = $400 // main main: { .label __0 = 3 .label __5 = 3 .label line = 3 .label y = 2 .label __6 = 5 .label __7 = 3 // [1] phi from main to main::@1 [phi:main->main::@1] __b1_from_main: // [1] phi main::y#2 = 5 [phi:main->main::@1#0] -- vbuz1=vbuc1 lda #5 sta.z y jmp __b1 // [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1] __b1_from___b3: // [1] phi main::y#2 = main::y#1 [phi:main::@3->main::@1#0] -- register_copy jmp __b1 // main::@1 __b1: // [2] main::$5 = (word)main::y#2 -- vwuz1=_word_vbuz2 lda.z y sta.z __5 lda #0 sta.z __5+1 // [3] main::$6 = main::$5 << 2 -- vwuz1=vwuz2_rol_2 lda.z __5 asl sta.z __6 lda.z __5+1 rol sta.z __6+1 asl.z __6 rol.z __6+1 // [4] main::$7 = main::$6 + main::$5 -- vwuz1=vwuz2_plus_vwuz1 lda.z __7 clc adc.z __6 sta.z __7 lda.z __7+1 adc.z __6+1 sta.z __7+1 // [5] main::$0 = main::$7 << 3 -- vwuz1=vwuz1_rol_3 asl.z __0 rol.z __0+1 asl.z __0 rol.z __0+1 asl.z __0 rol.z __0+1 // [6] main::line#0 = SCREEN + main::$0 -- pbuz1=pbuc1_plus_vwuz1 clc lda.z line adc #SCREEN sta.z line+1 // [7] phi from main::@1 to main::@2 [phi:main::@1->main::@2] __b2_from___b1: // [7] phi main::x#2 = 5 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1 ldy #5 jmp __b2 // [7] phi from main::@2 to main::@2 [phi:main::@2->main::@2] __b2_from___b2: // [7] phi main::x#2 = main::x#1 [phi:main::@2->main::@2#0] -- register_copy jmp __b2 // main::@2 __b2: // [8] main::$2 = main::x#2 + main::y#2 -- vbuaa=vbuyy_plus_vbuz1 tya clc adc.z y // [9] main::line#0[main::x#2] = main::$2 -- pbuz1_derefidx_vbuyy=vbuaa sta (line),y // [10] main::x#1 = ++ main::x#2 -- vbuyy=_inc_vbuyy iny // [11] if(main::x#1!=$10) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 cpy #$10 bne __b2_from___b2 jmp __b3 // main::@3 __b3: // [12] main::y#1 = ++ main::y#2 -- vbuz1=_inc_vbuz1 inc.z y // [13] if(main::y#1!=$10) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 lda #$10 cmp.z y bne __b1_from___b3 jmp __breturn // main::@return __breturn: // [14] return rts } // File Data ASSEMBLER OPTIMIZATIONS Removing instruction jmp __b1 Removing instruction jmp __b2 Removing instruction jmp __b3 Removing instruction jmp __breturn Succesful ASM optimization Pass5NextJumpElimination Replacing label __b2_from___b2 with __b2 Replacing label __b1_from___b3 with __b1 Removing instruction __b1_from___b3: Removing instruction __b2_from___b2: Succesful ASM optimization Pass5RedundantLabelElimination Removing instruction __b1_from_main: Removing instruction __b2_from___b1: Removing instruction __b3: Removing instruction __breturn: Succesful ASM optimization Pass5UnusedLabelElimination Removing instruction jmp __b1 Removing instruction jmp __b2 Succesful ASM optimization Pass5NextJumpElimination FINAL SYMBOL TABLE const byte* SCREEN = (byte*) 1024 void main() word~ main::$0 zp[2]:3 22.0 byte~ main::$2 reg byte a 202.0 word~ main::$5 zp[2]:3 16.5 word~ main::$6 zp[2]:5 22.0 word~ main::$7 zp[2]:3 22.0 byte* main::line byte* main::line#0 line zp[2]:3 18.666666666666664 byte main::x byte main::x#1 reg byte y 151.5 byte main::x#2 reg byte y 134.66666666666666 byte main::y byte main::y#1 y zp[1]:2 16.5 byte main::y#2 y zp[1]:2 11.181818181818182 zp[1]:2 [ main::y#2 main::y#1 ] reg byte y [ main::x#2 main::x#1 ] zp[2]:3 [ main::$5 main::$7 main::$0 main::line#0 ] zp[2]:5 [ main::$6 ] reg byte a [ main::$2 ] FINAL ASSEMBLER Score: 3381 // File Comments // Fill a square on the screen // Upstart .pc = $801 "Basic" :BasicUpstart(main) .pc = $80d "Program" // Global Constants & labels .label SCREEN = $400 // main main: { .label __0 = 3 .label __5 = 3 .label line = 3 .label y = 2 .label __6 = 5 .label __7 = 3 // [1] phi from main to main::@1 [phi:main->main::@1] // [1] phi main::y#2 = 5 [phi:main->main::@1#0] -- vbuz1=vbuc1 lda #5 sta.z y // [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1] // [1] phi main::y#2 = main::y#1 [phi:main::@3->main::@1#0] -- register_copy // main::@1 __b1: // (word)y*40 // [2] main::$5 = (word)main::y#2 -- vwuz1=_word_vbuz2 lda.z y sta.z __5 lda #0 sta.z __5+1 // [3] main::$6 = main::$5 << 2 -- vwuz1=vwuz2_rol_2 lda.z __5 asl sta.z __6 lda.z __5+1 rol sta.z __6+1 asl.z __6 rol.z __6+1 // [4] main::$7 = main::$6 + main::$5 -- vwuz1=vwuz2_plus_vwuz1 lda.z __7 clc adc.z __6 sta.z __7 lda.z __7+1 adc.z __6+1 sta.z __7+1 // [5] main::$0 = main::$7 << 3 -- vwuz1=vwuz1_rol_3 asl.z __0 rol.z __0+1 asl.z __0 rol.z __0+1 asl.z __0 rol.z __0+1 // line = SCREEN+(word)y*40 // [6] main::line#0 = SCREEN + main::$0 -- pbuz1=pbuc1_plus_vwuz1 clc lda.z line adc #SCREEN sta.z line+1 // [7] phi from main::@1 to main::@2 [phi:main::@1->main::@2] // [7] phi main::x#2 = 5 [phi:main::@1->main::@2#0] -- vbuyy=vbuc1 ldy #5 // [7] phi from main::@2 to main::@2 [phi:main::@2->main::@2] // [7] phi main::x#2 = main::x#1 [phi:main::@2->main::@2#0] -- register_copy // main::@2 __b2: // x+y // [8] main::$2 = main::x#2 + main::y#2 -- vbuaa=vbuyy_plus_vbuz1 tya clc adc.z y // line[x] = x+y // [9] main::line#0[main::x#2] = main::$2 -- pbuz1_derefidx_vbuyy=vbuaa sta (line),y // for( byte x: 5..15) // [10] main::x#1 = ++ main::x#2 -- vbuyy=_inc_vbuyy iny // [11] if(main::x#1!=$10) goto main::@2 -- vbuyy_neq_vbuc1_then_la1 cpy #$10 bne __b2 // main::@3 // for( byte y: 5..15) // [12] main::y#1 = ++ main::y#2 -- vbuz1=_inc_vbuz1 inc.z y // [13] if(main::y#1!=$10) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 lda #$10 cmp.z y bne __b1 // main::@return // } // [14] return rts } // File Data