diff --git a/src/test/kc/var-register-zp-3.kc b/src/test/kc/var-register-zp-3.kc index 75902769a..cc4a39276 100644 --- a/src/test/kc/var-register-zp-3.kc +++ b/src/test/kc/var-register-zp-3.kc @@ -4,7 +4,7 @@ char* screen = $400; void main() { print2(screen, "hello"); - //print2(screen+80, "hello"); + print2(screen+80, "world"); } void print2(char* __address(250) at, char* __address(252) msg) { diff --git a/src/test/ref/var-register-zp-3.asm b/src/test/ref/var-register-zp-3.asm index e8a0cf04a..791d42f58 100644 --- a/src/test/ref/var-register-zp-3.asm +++ b/src/test/ref/var-register-zp-3.asm @@ -4,10 +4,29 @@ .pc = $80d "Program" .label screen = $400 main: { + lda #screen + sta.z print2.at+1 + lda #msg + sta.z print2.msg+1 + jsr print2 + lda #screen+$50 + sta.z print2.at+1 + lda #msg1 + sta.z print2.msg+1 jsr print2 rts msg: .text "hello" .byte 0 + msg1: .text "world" + .byte 0 } // print2(byte* zeropage($fa) at, byte* zeropage($fc) msg) print2: { @@ -15,16 +34,8 @@ print2: { .label msg = $fc .label at = $fa ldx #0 - lda #screen - sta.z at+1 txa sta.z i - lda #main.msg - sta.z msg+1 __b1: ldy.z i lda (msg),y diff --git a/src/test/ref/var-register-zp-3.cfg b/src/test/ref/var-register-zp-3.cfg index d789b1b86..437d38ca7 100644 --- a/src/test/ref/var-register-zp-3.cfg +++ b/src/test/ref/var-register-zp-3.cfg @@ -12,43 +12,48 @@ main: scope:[main] from @1 [4] phi() [5] call print2 + to:main::@1 +main::@1: scope:[main] from main + [6] phi() + [7] call print2 to:main::@return -main::@return: scope:[main] from main - [6] return +main::@return: scope:[main] from main::@1 + [8] return to:@return (void()) print2((byte*) print2::at , (byte*) print2::msg) -print2: scope:[print2] from main - [7] phi() +print2: scope:[print2] from main main::@1 + [9] (byte*) print2::at#4 ← phi( main/(const byte*) screen main::@1/(const byte*) screen+(byte) $50 ) + [9] (byte*) print2::msg#4 ← phi( main/(const string) main::msg main::@1/(const string) main::msg1 ) to:print2::@1 print2::@1: scope:[print2] from print2 print2::@3 - [8] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 ) - [8] (byte*) print2::at#1 ← phi( print2/(const byte*) screen print2::@3/(byte*) print2::at#1 ) - [8] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 ) - [8] (byte*) print2::msg#1 ← phi( print2/(const string) main::msg print2::@3/(byte*) print2::msg#1 ) - [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 + [10] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 ) + [10] (byte*) print2::at#2 ← phi( print2/(byte*) print2::at#4 print2::@3/(byte*) print2::at#2 ) + [10] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 ) + [10] (byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@3/(byte*) print2::msg#2 ) + [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 to:print2::@return print2::@return: scope:[print2] from print2::@1 - [10] return + [12] return to:@return print2::@2: scope:[print2] from print2::@1 - [11] (byte*) print_char::at#0 ← (byte*) print2::at#1 - [12] (byte) print_char::idx#0 ← (byte) print2::j#2 - [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) - [14] call print_char + [13] (byte*) print_char::at#0 ← (byte*) print2::at#2 + [14] (byte) print_char::idx#0 ← (byte) print2::j#2 + [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) + [16] call print_char to:print2::@3 print2::@3: scope:[print2] from print2::@2 - [15] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 - [16] (byte) print2::i#1 ← ++ (byte) print2::i#2 + [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 + [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 to:print2::@1 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) print_char: scope:[print_char] from print2::@2 - [17] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 ) - [17] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 ) - [17] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 ) - [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 + [19] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 ) + [19] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 ) + [19] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 ) + [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 to:print_char::@return print_char::@return: scope:[print_char] from print_char - [19] return + [21] return to:@return diff --git a/src/test/ref/var-register-zp-3.log b/src/test/ref/var-register-zp-3.log index dff04997f..b2731944e 100644 --- a/src/test/ref/var-register-zp-3.log +++ b/src/test/ref/var-register-zp-3.log @@ -18,39 +18,45 @@ main: scope:[main] from @3 call print2 to:main::@1 main::@1: scope:[main] from main + (byte*~) main::$1 ← (const byte*) screen + (number) $50 + (byte*) print2::at#1 ← (byte*~) main::$1 + (byte*) print2::msg#1 ← (const string) main::msg1 + call print2 + to:main::@2 +main::@2: scope:[main] from main::@1 to:main::@return -main::@return: scope:[main] from main::@1 +main::@return: scope:[main] from main::@2 return to:@return (void()) print2((byte*) print2::at , (byte*) print2::msg) -print2: scope:[print2] from main - (byte*) print2::at#3 ← phi( main/(byte*) print2::at#0 ) - (byte*) print2::msg#3 ← phi( main/(byte*) print2::msg#0 ) +print2: scope:[print2] from main main::@1 + (byte*) print2::at#4 ← phi( main/(byte*) print2::at#0 main::@1/(byte*) print2::at#1 ) + (byte*) print2::msg#4 ← phi( main/(byte*) print2::msg#0 main::@1/(byte*) print2::msg#1 ) (byte) print2::j#0 ← (number) 0 (byte) print2::i#0 ← (number) 0 to:print2::@1 print2::@1: scope:[print2] from print2 print2::@7 (byte) print2::j#4 ← phi( print2/(byte) print2::j#0 print2::@7/(byte) print2::j#1 ) - (byte*) print2::at#2 ← phi( print2/(byte*) print2::at#3 print2::@7/(byte*) print2::at#4 ) + (byte*) print2::at#3 ← phi( print2/(byte*) print2::at#4 print2::@7/(byte*) print2::at#5 ) (byte) print2::i#2 ← phi( print2/(byte) print2::i#0 print2::@7/(byte) print2::i#1 ) - (byte*) print2::msg#1 ← phi( print2/(byte*) print2::msg#3 print2::@7/(byte*) print2::msg#4 ) - (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#1 + (byte) print2::i#2) + (byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@7/(byte*) print2::msg#5 ) + (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#2 + (byte) print2::i#2) if((bool~) print2::$1) goto print2::@2 to:print2::@return print2::@2: scope:[print2] from print2::@1 (byte) print2::i#3 ← phi( print2::@1/(byte) print2::i#2 ) - (byte*) print2::msg#2 ← phi( print2::@1/(byte*) print2::msg#1 ) + (byte*) print2::msg#3 ← phi( print2::@1/(byte*) print2::msg#2 ) (byte) print2::j#2 ← phi( print2::@1/(byte) print2::j#4 ) - (byte*) print2::at#1 ← phi( print2::@1/(byte*) print2::at#2 ) - (byte*) print_char::at#0 ← (byte*) print2::at#1 + (byte*) print2::at#2 ← phi( print2::@1/(byte*) print2::at#3 ) + (byte*) print_char::at#0 ← (byte*) print2::at#2 (byte) print_char::idx#0 ← (byte) print2::j#2 - (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#3) + (byte) print_char::ch#0 ← *((byte*) print2::msg#3 + (byte) print2::i#3) call print_char to:print2::@7 print2::@7: scope:[print2] from print2::@2 - (byte*) print2::at#4 ← phi( print2::@2/(byte*) print2::at#1 ) - (byte*) print2::msg#4 ← phi( print2::@2/(byte*) print2::msg#2 ) + (byte*) print2::at#5 ← phi( print2::@2/(byte*) print2::at#2 ) + (byte*) print2::msg#5 ← phi( print2::@2/(byte*) print2::msg#3 ) (byte) print2::i#4 ← phi( print2::@2/(byte) print2::i#3 ) (byte) print2::j#3 ← phi( print2::@2/(byte) print2::j#2 ) (byte) print2::j#1 ← (byte) print2::j#3 + (number) 2 @@ -83,9 +89,12 @@ SYMBOL TABLE SSA (label) @begin (label) @end (void()) main() +(byte*~) main::$1 (label) main::@1 +(label) main::@2 (label) main::@return (const string) main::msg = (string) "hello" +(const string) main::msg1 = (string) "world" (void()) print2((byte*) print2::at , (byte*) print2::msg) (bool~) print2::$1 (label) print2::@1 @@ -98,6 +107,7 @@ SYMBOL TABLE SSA (byte*) print2::at#2 !zp[-1]:250 (byte*) print2::at#3 !zp[-1]:250 (byte*) print2::at#4 !zp[-1]:250 +(byte*) print2::at#5 !zp[-1]:250 (byte) print2::i (byte) print2::i#0 (byte) print2::i#1 @@ -116,6 +126,7 @@ SYMBOL TABLE SSA (byte*) print2::msg#2 !zp[-1]:252 (byte*) print2::msg#3 !zp[-1]:252 (byte*) print2::msg#4 !zp[-1]:252 +(byte*) print2::msg#5 !zp[-1]:252 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) (label) print_char::@return (byte*) print_char::at !zp[-1]:250 @@ -129,52 +140,57 @@ SYMBOL TABLE SSA (byte) print_char::idx#1 !reg byte x (const byte*) screen = (byte*)(number) $400 +Adding number conversion cast (unumber) $50 in (byte*~) main::$1 ← (const byte*) screen + (number) $50 Adding number conversion cast (unumber) 0 in (byte) print2::j#0 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) print2::i#0 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#1 + (byte) print2::i#2) +Adding number conversion cast (unumber) 0 in (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#2 + (byte) print2::i#2) Adding number conversion cast (unumber) 2 in (byte) print2::j#1 ← (byte) print2::j#3 + (number) 2 Successful SSA optimization PassNAddNumberTypeConversions Inlining cast (byte) print2::j#0 ← (unumber)(number) 0 Inlining cast (byte) print2::i#0 ← (unumber)(number) 0 Successful SSA optimization Pass2InlineCast Simplifying constant pointer cast (byte*) 1024 +Simplifying constant integer cast $50 Simplifying constant integer cast 0 Simplifying constant integer cast 0 Simplifying constant integer cast 0 Simplifying constant integer cast 2 Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (byte) $50 Finalized unsigned number type (byte) 0 Finalized unsigned number type (byte) 0 Finalized unsigned number type (byte) 0 Finalized unsigned number type (byte) 2 Successful SSA optimization PassNFinalizeNumberTypeConversions -Alias (byte*) print2::at#1 = (byte*) print2::at#2 (byte*) print2::at#4 +Alias (byte*) print2::at#1 = (byte*~) main::$1 +Alias (byte*) print2::at#2 = (byte*) print2::at#3 (byte*) print2::at#5 Alias (byte) print2::j#2 = (byte) print2::j#4 (byte) print2::j#3 -Alias (byte*) print2::msg#1 = (byte*) print2::msg#2 (byte*) print2::msg#4 +Alias (byte*) print2::msg#2 = (byte*) print2::msg#3 (byte*) print2::msg#5 Alias (byte) print2::i#2 = (byte) print2::i#3 (byte) print2::i#4 Successful SSA optimization Pass2AliasElimination -Simple Condition (bool~) print2::$1 [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 +Simple Condition (bool~) print2::$1 [13] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 Successful SSA optimization Pass2ConditionalJumpSimplification +Constant right-side identified [3] (byte*) print2::at#1 ← (const byte*) screen + (byte) $50 +Successful SSA optimization Pass2ConstantRValueConsolidation Constant (const byte*) print2::at#0 = screen Constant (const byte*) print2::msg#0 = main::msg +Constant (const byte*) print2::at#1 = screen+$50 +Constant (const byte*) print2::msg#1 = main::msg1 Constant (const byte) print2::j#0 = 0 Constant (const byte) print2::i#0 = 0 Successful SSA optimization Pass2ConstantIdentification -Constant (const byte*) print2::msg#3 = print2::msg#0 -Constant (const byte*) print2::at#3 = print2::at#0 -Successful SSA optimization Pass2ConstantIdentification Inlining constant with var siblings (const byte*) print2::at#0 Inlining constant with var siblings (const byte*) print2::msg#0 +Inlining constant with var siblings (const byte*) print2::at#1 +Inlining constant with var siblings (const byte*) print2::msg#1 Inlining constant with var siblings (const byte) print2::j#0 Inlining constant with var siblings (const byte) print2::i#0 -Inlining constant with var siblings (const byte*) print2::msg#3 -Inlining constant with var siblings (const byte*) print2::at#3 +Constant inlined print2::at#1 = (const byte*) screen+(byte) $50 Constant inlined print2::at#0 = (const byte*) screen -Constant inlined print2::msg#3 = (const string) main::msg +Constant inlined print2::msg#1 = (const string) main::msg1 Constant inlined print2::j#0 = (byte) 0 Constant inlined print2::msg#0 = (const string) main::msg Constant inlined print2::i#0 = (byte) 0 -Constant inlined print2::at#3 = (const byte*) screen Successful SSA optimization Pass2ConstantInlining Adding NOP phi() at start of @begin Adding NOP phi() at start of @3 @@ -182,30 +198,32 @@ Adding NOP phi() at start of @4 Adding NOP phi() at start of @end Adding NOP phi() at start of main Adding NOP phi() at start of main::@1 -Adding NOP phi() at start of print2 +Adding NOP phi() at start of main::@2 CALL GRAPH Calls in [] to main:2 -Calls in [main] to print2:6 -Calls in [print2] to print_char:19 +Calls in [main] to print2:6 print2:8 +Calls in [print2] to print_char:23 -Created 7 initial phi equivalence classes -Coalesced [16] print_char::ch#2 ← print_char::ch#0 -Coalesced [17] print_char::at#2 ← print_char::at#0 -Coalesced [18] print_char::idx#2 ← print_char::idx#0 -Coalesced (already) [22] print2::msg#5 ← print2::msg#1 -Coalesced [23] print2::i#5 ← print2::i#1 -Coalesced (already) [24] print2::at#5 ← print2::at#1 -Coalesced [25] print2::j#5 ← print2::j#1 +Created 9 initial phi equivalence classes +Coalesced [12] print2::msg#6 ← print2::msg#4 +Coalesced [13] print2::at#6 ← print2::at#4 +Coalesced [20] print_char::ch#2 ← print_char::ch#0 +Coalesced [21] print_char::at#2 ← print_char::at#0 +Coalesced [22] print_char::idx#2 ← print_char::idx#0 +Coalesced (already) [26] print2::msg#7 ← print2::msg#2 +Coalesced [27] print2::i#5 ← print2::i#1 +Coalesced (already) [28] print2::at#7 ← print2::at#2 +Coalesced [29] print2::j#5 ← print2::j#1 Coalesced down to 7 phi equivalence classes Culled Empty Block (label) @4 -Culled Empty Block (label) main::@1 +Culled Empty Block (label) main::@2 Renumbering block @3 to @1 Renumbering block print2::@7 to print2::@3 Adding NOP phi() at start of @begin Adding NOP phi() at start of @1 Adding NOP phi() at start of @end Adding NOP phi() at start of main -Adding NOP phi() at start of print2 +Adding NOP phi() at start of main::@1 FINAL CONTROL FLOW GRAPH @begin: scope:[] from @@ -222,45 +240,50 @@ FINAL CONTROL FLOW GRAPH main: scope:[main] from @1 [4] phi() [5] call print2 + to:main::@1 +main::@1: scope:[main] from main + [6] phi() + [7] call print2 to:main::@return -main::@return: scope:[main] from main - [6] return +main::@return: scope:[main] from main::@1 + [8] return to:@return (void()) print2((byte*) print2::at , (byte*) print2::msg) -print2: scope:[print2] from main - [7] phi() +print2: scope:[print2] from main main::@1 + [9] (byte*) print2::at#4 ← phi( main/(const byte*) screen main::@1/(const byte*) screen+(byte) $50 ) + [9] (byte*) print2::msg#4 ← phi( main/(const string) main::msg main::@1/(const string) main::msg1 ) to:print2::@1 print2::@1: scope:[print2] from print2 print2::@3 - [8] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 ) - [8] (byte*) print2::at#1 ← phi( print2/(const byte*) screen print2::@3/(byte*) print2::at#1 ) - [8] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 ) - [8] (byte*) print2::msg#1 ← phi( print2/(const string) main::msg print2::@3/(byte*) print2::msg#1 ) - [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 + [10] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 ) + [10] (byte*) print2::at#2 ← phi( print2/(byte*) print2::at#4 print2::@3/(byte*) print2::at#2 ) + [10] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 ) + [10] (byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@3/(byte*) print2::msg#2 ) + [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 to:print2::@return print2::@return: scope:[print2] from print2::@1 - [10] return + [12] return to:@return print2::@2: scope:[print2] from print2::@1 - [11] (byte*) print_char::at#0 ← (byte*) print2::at#1 - [12] (byte) print_char::idx#0 ← (byte) print2::j#2 - [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) - [14] call print_char + [13] (byte*) print_char::at#0 ← (byte*) print2::at#2 + [14] (byte) print_char::idx#0 ← (byte) print2::j#2 + [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) + [16] call print_char to:print2::@3 print2::@3: scope:[print2] from print2::@2 - [15] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 - [16] (byte) print2::i#1 ← ++ (byte) print2::i#2 + [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 + [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 to:print2::@1 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) print_char: scope:[print_char] from print2::@2 - [17] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 ) - [17] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 ) - [17] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 ) - [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 + [19] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 ) + [19] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 ) + [19] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 ) + [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 to:print_char::@return print_char::@return: scope:[print_char] from print_char - [19] return + [21] return to:@return @@ -268,7 +291,8 @@ VARIABLE REGISTER WEIGHTS (void()) main() (void()) print2((byte*) print2::at , (byte*) print2::msg) (byte*) print2::at !zp[-1]:250 -(byte*) print2::at#1 !zp[-1]:250 4.125 +(byte*) print2::at#2 !zp[-1]:250 4.375 +(byte*) print2::at#4 !zp[-1]:250 2.0 (byte) print2::i (byte) print2::i#1 22.0 (byte) print2::i#2 6.285714285714286 @@ -276,7 +300,8 @@ VARIABLE REGISTER WEIGHTS (byte) print2::j#1 11.0 (byte) print2::j#2 5.5 (byte*) print2::msg !zp[-1]:252 -(byte*) print2::msg#1 !zp[-1]:252 5.5 +(byte*) print2::msg#2 !zp[-1]:252 5.75 +(byte*) print2::msg#4 !zp[-1]:252 2.0 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) (byte*) print_char::at !zp[-1]:250 (byte*) print_char::at#0 !zp[-1]:250 7.333333333333333 @@ -289,17 +314,17 @@ VARIABLE REGISTER WEIGHTS (byte) print_char::idx#1 !reg byte x 13.0 Initial phi equivalence classes -[ print2::msg#1 ] +[ print2::msg#2 print2::msg#4 ] [ print2::i#2 print2::i#1 ] -[ print2::at#1 ] +[ print2::at#2 print2::at#4 ] [ print2::j#2 print2::j#1 ] [ print_char::ch#1 print_char::ch#0 ] [ print_char::at#1 print_char::at#0 ] [ print_char::idx#1 print_char::idx#0 ] Complete equivalence classes -[ print2::msg#1 ] +[ print2::msg#2 print2::msg#4 ] [ print2::i#2 print2::i#1 ] -[ print2::at#1 ] +[ print2::at#2 print2::at#4 ] [ print2::j#2 print2::j#1 ] [ print_char::ch#1 print_char::ch#0 ] [ print_char::at#1 print_char::at#0 ] @@ -336,16 +361,47 @@ __bend: // main main: { // [5] call print2 - // [7] phi from main to print2 [phi:main->print2] + // [9] phi from main to print2 [phi:main->print2] print2_from_main: + // [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1 + lda #screen + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1 + lda #msg + sta.z print2.msg+1 + jsr print2 + // [6] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + jmp __b1 + // main::@1 + __b1: + // [7] call print2 + // [9] phi from main::@1 to print2 [phi:main::@1->print2] + print2_from___b1: + // [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1 + lda #screen+$50 + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1 + lda #msg1 + sta.z print2.msg+1 jsr print2 jmp __breturn // main::@return __breturn: - // [6] return + // [8] return rts msg: .text "hello" .byte 0 + msg1: .text "world" + .byte 0 } // print2 // print2(byte* zeropage($fa) at, byte* zeropage($fc) msg) @@ -354,28 +410,20 @@ print2: { .label i = 2 .label msg = $fc .label at = $fa - // [8] phi from print2 to print2::@1 [phi:print2->print2::@1] + // [10] phi from print2 to print2::@1 [phi:print2->print2::@1] __b1_from_print2: - // [8] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuz1=vbuc1 + // [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuz1=vbuc1 lda #0 sta.z j - // [8] phi (byte*) print2::at#1 = (const byte*) screen [phi:print2->print2::@1#1] -- pbuz1=pbuc1 - lda #screen - sta.z at+1 - // [8] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 lda #0 sta.z i - // [8] phi (byte*) print2::msg#1 = (const string) main::msg [phi:print2->print2::@1#3] -- pbuz1=pbuc1 - lda #main.msg - sta.z msg+1 + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy jmp __b1 // print2::@1 __b1: - // [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 + // [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 ldy.z i lda (msg),y cmp #0 @@ -383,71 +431,71 @@ print2: { jmp __breturn // print2::@return __breturn: - // [10] return + // [12] return rts // print2::@2 __b2: - // [11] (byte*) print_char::at#0 ← (byte*) print2::at#1 - // [12] (byte) print_char::idx#0 ← (byte) print2::j#2 -- vbuxx=vbuz1 + // [13] (byte*) print_char::at#0 ← (byte*) print2::at#2 + // [14] (byte) print_char::idx#0 ← (byte) print2::j#2 -- vbuxx=vbuz1 ldx.z j - // [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 + // [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 ldy.z i lda (msg),y - // [14] call print_char - // [17] phi from print2::@2 to print_char [phi:print2::@2->print_char] + // [16] call print_char + // [19] phi from print2::@2 to print_char [phi:print2::@2->print_char] print_char_from___b2: - // [17] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy - // [17] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy - // [17] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy + // [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy + // [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy + // [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy jsr print_char jmp __b3 // print2::@3 __b3: - // [15] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuz1=vbuz1_plus_2 + // [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuz1=vbuz1_plus_2 lda.z j clc adc #2 sta.z j - // [16] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 + // [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 inc.z i - // [8] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] + // [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] __b1_from___b3: - // [8] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy - // [8] phi (byte*) print2::at#1 = (byte*) print2::at#1 [phi:print2::@3->print2::@1#1] -- register_copy - // [8] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy - // [8] phi (byte*) print2::msg#1 = (byte*) print2::msg#1 [phi:print2::@3->print2::@1#3] -- register_copy + // [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy jmp __b1 } // print_char // print_char(byte* zeropage($fa) at, byte register(X) idx, byte register(A) ch) print_char: { .label at = $fa - // [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa + // [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa stx.z $ff ldy.z $ff sta (at),y jmp __breturn // print_char::@return __breturn: - // [19] return + // [21] return rts } // File Data REGISTER UPLIFT POTENTIAL REGISTERS -Statement [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ( main:2::print2:5 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ) always clobbers reg byte a +Statement [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte a Removing always clobbered register reg byte a as potential for zp[1]:2 [ print2::i#2 print2::i#1 ] Removing always clobbered register reg byte a as potential for zp[1]:3 [ print2::j#2 print2::j#1 ] -Statement [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a -Statement [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:14 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ) always clobbers reg byte y +Statement [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a +Statement [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte y Removing always clobbered register reg byte y as potential for zp[1]:2 [ print2::i#2 print2::i#1 ] Removing always clobbered register reg byte y as potential for zp[1]:3 [ print2::j#2 print2::j#1 ] -Statement [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ( main:2::print2:5 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ) always clobbers reg byte a reg byte y -Statement [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a reg byte y -Statement [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:14 [ print2::msg#1 print2::i#2 print2::at#1 print2::j#2 ] ) always clobbers reg byte y -Potential registers zp[2]:252 [ print2::msg#1 ] : zp[2]:252 , +Statement [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte a reg byte y +Statement [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a reg byte y +Statement [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte y +Potential registers zp[2]:252 [ print2::msg#2 print2::msg#4 ] : zp[2]:252 , Potential registers zp[1]:2 [ print2::i#2 print2::i#1 ] : zp[1]:2 , reg byte x , -Potential registers zp[2]:250 [ print2::at#1 ] : zp[2]:250 , +Potential registers zp[2]:250 [ print2::at#2 print2::at#4 ] : zp[2]:250 , Potential registers zp[1]:3 [ print2::j#2 print2::j#1 ] : zp[1]:3 , reg byte x , Potential registers reg byte a [ print_char::ch#1 print_char::ch#0 ] : reg byte a , Potential registers zp[2]:250 [ print_char::at#1 print_char::at#0 ] : zp[2]:250 , @@ -455,17 +503,17 @@ Potential registers reg byte x [ print_char::idx#1 print_char::idx#0 ] : reg byt REGISTER UPLIFT SCOPES Uplift Scope [print_char] 35: reg byte a [ print_char::ch#1 print_char::ch#0 ] 24: reg byte x [ print_char::idx#1 print_char::idx#0 ] 20.33: zp[2]:250 [ print_char::at#1 print_char::at#0 ] -Uplift Scope [print2] 28.29: zp[1]:2 [ print2::i#2 print2::i#1 ] 16.5: zp[1]:3 [ print2::j#2 print2::j#1 ] 5.5: zp[2]:252 [ print2::msg#1 ] 4.12: zp[2]:250 [ print2::at#1 ] +Uplift Scope [print2] 28.29: zp[1]:2 [ print2::i#2 print2::i#1 ] 16.5: zp[1]:3 [ print2::j#2 print2::j#1 ] 7.75: zp[2]:252 [ print2::msg#2 print2::msg#4 ] 6.38: zp[2]:250 [ print2::at#2 print2::at#4 ] Uplift Scope [main] Uplift Scope [] -Uplifting [print_char] best 848 combination reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ] zp[2]:250 [ print_char::at#1 print_char::at#0 ] -Uplifting [print2] best 728 combination zp[1]:2 [ print2::i#2 print2::i#1 ] reg byte x [ print2::j#2 print2::j#1 ] zp[2]:252 [ print2::msg#1 ] zp[2]:250 [ print2::at#1 ] -Uplifting [main] best 728 combination -Uplifting [] best 728 combination +Uplifting [print_char] best 697 combination reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ] zp[2]:250 [ print_char::at#1 print_char::at#0 ] +Uplifting [print2] best 577 combination zp[1]:2 [ print2::i#2 print2::i#1 ] reg byte x [ print2::j#2 print2::j#1 ] zp[2]:252 [ print2::msg#2 print2::msg#4 ] zp[2]:250 [ print2::at#2 print2::at#4 ] +Uplifting [main] best 577 combination +Uplifting [] best 577 combination Attempting to uplift remaining variables inzp[1]:2 [ print2::i#2 print2::i#1 ] -Uplifting [print2] best 728 combination zp[1]:2 [ print2::i#2 print2::i#1 ] -Coalescing zero page register [ zp[2]:250 [ print2::at#1 ] ] with [ zp[2]:250 [ print_char::at#1 print_char::at#0 ] ] - score: 1 +Uplifting [print2] best 577 combination zp[1]:2 [ print2::i#2 print2::i#1 ] +Coalescing zero page register [ zp[2]:250 [ print2::at#2 print2::at#4 ] ] with [ zp[2]:250 [ print_char::at#1 print_char::at#0 ] ] - score: 1 ASSEMBLER BEFORE OPTIMIZATION // File Comments @@ -495,16 +543,47 @@ __bend: // main main: { // [5] call print2 - // [7] phi from main to print2 [phi:main->print2] + // [9] phi from main to print2 [phi:main->print2] print2_from_main: + // [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1 + lda #screen + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1 + lda #msg + sta.z print2.msg+1 + jsr print2 + // [6] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + jmp __b1 + // main::@1 + __b1: + // [7] call print2 + // [9] phi from main::@1 to print2 [phi:main::@1->print2] + print2_from___b1: + // [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1 + lda #screen+$50 + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1 + lda #msg1 + sta.z print2.msg+1 jsr print2 jmp __breturn // main::@return __breturn: - // [6] return + // [8] return rts msg: .text "hello" .byte 0 + msg1: .text "world" + .byte 0 } // print2 // print2(byte* zeropage($fa) at, byte* zeropage($fc) msg) @@ -512,27 +591,19 @@ print2: { .label i = 2 .label msg = $fc .label at = $fa - // [8] phi from print2 to print2::@1 [phi:print2->print2::@1] + // [10] phi from print2 to print2::@1 [phi:print2->print2::@1] __b1_from_print2: - // [8] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1 + // [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1 ldx #0 - // [8] phi (byte*) print2::at#1 = (const byte*) screen [phi:print2->print2::@1#1] -- pbuz1=pbuc1 - lda #screen - sta.z at+1 - // [8] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 lda #0 sta.z i - // [8] phi (byte*) print2::msg#1 = (const string) main::msg [phi:print2->print2::@1#3] -- pbuz1=pbuc1 - lda #main.msg - sta.z msg+1 + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy jmp __b1 // print2::@1 __b1: - // [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 + // [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 ldy.z i lda (msg),y cmp #0 @@ -540,50 +611,50 @@ print2: { jmp __breturn // print2::@return __breturn: - // [10] return + // [12] return rts // print2::@2 __b2: - // [11] (byte*) print_char::at#0 ← (byte*) print2::at#1 - // [12] (byte) print_char::idx#0 ← (byte) print2::j#2 - // [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 + // [13] (byte*) print_char::at#0 ← (byte*) print2::at#2 + // [14] (byte) print_char::idx#0 ← (byte) print2::j#2 + // [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 ldy.z i lda (msg),y - // [14] call print_char - // [17] phi from print2::@2 to print_char [phi:print2::@2->print_char] + // [16] call print_char + // [19] phi from print2::@2 to print_char [phi:print2::@2->print_char] print_char_from___b2: - // [17] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy - // [17] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy - // [17] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy + // [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy + // [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy + // [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy jsr print_char jmp __b3 // print2::@3 __b3: - // [15] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2 + // [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2 inx inx - // [16] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 + // [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 inc.z i - // [8] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] + // [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] __b1_from___b3: - // [8] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy - // [8] phi (byte*) print2::at#1 = (byte*) print2::at#1 [phi:print2::@3->print2::@1#1] -- register_copy - // [8] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy - // [8] phi (byte*) print2::msg#1 = (byte*) print2::msg#1 [phi:print2::@3->print2::@1#3] -- register_copy + // [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy jmp __b1 } // print_char // print_char(byte* zeropage($fa) at, byte register(X) idx, byte register(A) ch) print_char: { .label at = $fa - // [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa + // [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa stx.z $ff ldy.z $ff sta (at),y jmp __breturn // print_char::@return __breturn: - // [19] return + // [21] return rts } // File Data @@ -591,6 +662,7 @@ print_char: { ASSEMBLER OPTIMIZATIONS Removing instruction jmp __b1 Removing instruction jmp __bend +Removing instruction jmp __b1 Removing instruction jmp __breturn Removing instruction jmp __b1 Removing instruction jmp __breturn @@ -603,9 +675,12 @@ Removing instruction __bbegin: Removing instruction __b1_from___bbegin: Removing instruction main_from___b1: Removing instruction __bend_from___b1: +Removing instruction __b1_from_main: +Removing instruction print2_from___b1: Succesful ASM optimization Pass5RedundantLabelElimination Removing instruction __bend: Removing instruction print2_from_main: +Removing instruction __b1: Removing instruction __breturn: Removing instruction __b1_from_print2: Removing instruction __breturn: @@ -625,15 +700,18 @@ FINAL SYMBOL TABLE (label) @begin (label) @end (void()) main() +(label) main::@1 (label) main::@return (const string) main::msg = (string) "hello" +(const string) main::msg1 = (string) "world" (void()) print2((byte*) print2::at , (byte*) print2::msg) (label) print2::@1 (label) print2::@2 (label) print2::@3 (label) print2::@return (byte*) print2::at !zp[-1]:250 -(byte*) print2::at#1 at !zp[-1]:250 zp[2]:250 4.125 +(byte*) print2::at#2 at !zp[-1]:250 zp[2]:250 4.375 +(byte*) print2::at#4 at !zp[-1]:250 zp[2]:250 2.0 (byte) print2::i (byte) print2::i#1 i zp[1]:2 22.0 (byte) print2::i#2 i zp[1]:2 6.285714285714286 @@ -641,7 +719,8 @@ FINAL SYMBOL TABLE (byte) print2::j#1 reg byte x 11.0 (byte) print2::j#2 reg byte x 5.5 (byte*) print2::msg !zp[-1]:252 -(byte*) print2::msg#1 msg !zp[-1]:252 zp[2]:252 5.5 +(byte*) print2::msg#2 msg !zp[-1]:252 zp[2]:252 5.75 +(byte*) print2::msg#4 msg !zp[-1]:252 zp[2]:252 2.0 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) (label) print_char::@return (byte*) print_char::at !zp[-1]:250 @@ -655,16 +734,16 @@ FINAL SYMBOL TABLE (byte) print_char::idx#1 !reg byte x 13.0 (const byte*) screen = (byte*) 1024 -zp[2]:252 [ print2::msg#1 ] +zp[2]:252 [ print2::msg#2 print2::msg#4 ] zp[1]:2 [ print2::i#2 print2::i#1 ] -zp[2]:250 [ print2::at#1 print_char::at#1 print_char::at#0 ] +zp[2]:250 [ print2::at#2 print2::at#4 print_char::at#1 print_char::at#0 ] reg byte x [ print2::j#2 print2::j#1 ] reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ] FINAL ASSEMBLER -Score: 647 +Score: 493 // File Comments // Test declaring a variable as register on a specific ZP address @@ -685,14 +764,42 @@ Score: 647 main: { // print2(screen, "hello") // [5] call print2 - // [7] phi from main to print2 [phi:main->print2] + // [9] phi from main to print2 [phi:main->print2] + // [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1 + lda #screen + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1 + lda #msg + sta.z print2.msg+1 + jsr print2 + // [6] phi from main to main::@1 [phi:main->main::@1] + // main::@1 + // print2(screen+80, "world") + // [7] call print2 + // [9] phi from main::@1 to print2 [phi:main::@1->print2] + // [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1 + lda #screen+$50 + sta.z print2.at+1 + // [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1 + lda #msg1 + sta.z print2.msg+1 jsr print2 // main::@return // } - // [6] return + // [8] return rts msg: .text "hello" .byte 0 + msg1: .text "world" + .byte 0 } // print2 // print2(byte* zeropage($fa) at, byte* zeropage($fc) msg) @@ -700,61 +807,53 @@ print2: { .label i = 2 .label msg = $fc .label at = $fa - // [8] phi from print2 to print2::@1 [phi:print2->print2::@1] - // [8] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1 + // [10] phi from print2 to print2::@1 [phi:print2->print2::@1] + // [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1 ldx #0 - // [8] phi (byte*) print2::at#1 = (const byte*) screen [phi:print2->print2::@1#1] -- pbuz1=pbuc1 - lda #screen - sta.z at+1 - // [8] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1 txa sta.z i - // [8] phi (byte*) print2::msg#1 = (const string) main::msg [phi:print2->print2::@1#3] -- pbuz1=pbuc1 - lda #main.msg - sta.z msg+1 + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy // print2::@1 __b1: // for(byte i=0; msg[i]; i++) - // [9] if((byte) 0!=*((byte*) print2::msg#1 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 + // [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1 ldy.z i lda (msg),y cmp #0 bne __b2 // print2::@return // } - // [10] return + // [12] return rts // print2::@2 __b2: // print_char(at, j, msg[i]) - // [11] (byte*) print_char::at#0 ← (byte*) print2::at#1 - // [12] (byte) print_char::idx#0 ← (byte) print2::j#2 - // [13] (byte) print_char::ch#0 ← *((byte*) print2::msg#1 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 + // [13] (byte*) print_char::at#0 ← (byte*) print2::at#2 + // [14] (byte) print_char::idx#0 ← (byte) print2::j#2 + // [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2 ldy.z i lda (msg),y - // [14] call print_char - // [17] phi from print2::@2 to print_char [phi:print2::@2->print_char] - // [17] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy - // [17] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy - // [17] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy + // [16] call print_char + // [19] phi from print2::@2 to print_char [phi:print2::@2->print_char] + // [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy + // [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy + // [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy jsr print_char // print2::@3 // j += 2 - // [15] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2 + // [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2 inx inx // for(byte i=0; msg[i]; i++) - // [16] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 + // [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1 inc.z i - // [8] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] - // [8] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy - // [8] phi (byte*) print2::at#1 = (byte*) print2::at#1 [phi:print2::@3->print2::@1#1] -- register_copy - // [8] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy - // [8] phi (byte*) print2::msg#1 = (byte*) print2::msg#1 [phi:print2::@3->print2::@1#3] -- register_copy + // [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1] + // [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy + // [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy + // [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy + // [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy jmp __b1 } // print_char @@ -762,13 +861,13 @@ print2: { print_char: { .label at = $fa // at[idx] = ch - // [18] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa + // [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa stx.z $ff ldy.z $ff sta (at),y // print_char::@return // } - // [19] return + // [21] return rts } // File Data diff --git a/src/test/ref/var-register-zp-3.sym b/src/test/ref/var-register-zp-3.sym index 13690ef3b..d4a12d66e 100644 --- a/src/test/ref/var-register-zp-3.sym +++ b/src/test/ref/var-register-zp-3.sym @@ -2,15 +2,18 @@ (label) @begin (label) @end (void()) main() +(label) main::@1 (label) main::@return (const string) main::msg = (string) "hello" +(const string) main::msg1 = (string) "world" (void()) print2((byte*) print2::at , (byte*) print2::msg) (label) print2::@1 (label) print2::@2 (label) print2::@3 (label) print2::@return (byte*) print2::at !zp[-1]:250 -(byte*) print2::at#1 at !zp[-1]:250 zp[2]:250 4.125 +(byte*) print2::at#2 at !zp[-1]:250 zp[2]:250 4.375 +(byte*) print2::at#4 at !zp[-1]:250 zp[2]:250 2.0 (byte) print2::i (byte) print2::i#1 i zp[1]:2 22.0 (byte) print2::i#2 i zp[1]:2 6.285714285714286 @@ -18,7 +21,8 @@ (byte) print2::j#1 reg byte x 11.0 (byte) print2::j#2 reg byte x 5.5 (byte*) print2::msg !zp[-1]:252 -(byte*) print2::msg#1 msg !zp[-1]:252 zp[2]:252 5.5 +(byte*) print2::msg#2 msg !zp[-1]:252 zp[2]:252 5.75 +(byte*) print2::msg#4 msg !zp[-1]:252 zp[2]:252 2.0 (void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch) (label) print_char::@return (byte*) print_char::at !zp[-1]:250 @@ -32,9 +36,9 @@ (byte) print_char::idx#1 !reg byte x 13.0 (const byte*) screen = (byte*) 1024 -zp[2]:252 [ print2::msg#1 ] +zp[2]:252 [ print2::msg#2 print2::msg#4 ] zp[1]:2 [ print2::i#2 print2::i#1 ] -zp[2]:250 [ print2::at#1 print_char::at#1 print_char::at#0 ] +zp[2]:250 [ print2::at#2 print2::at#4 print_char::at#1 print_char::at#0 ] reg byte x [ print2::j#2 print2::j#1 ] reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ]