2019-05-30 20:29:04 +00:00
|
|
|
Culled Empty Block (label) main::@6
|
|
|
|
Culled Empty Block (label) main::@3
|
|
|
|
Culled Empty Block (label) main::@7
|
|
|
|
Culled Empty Block (label) main::@8
|
|
|
|
Culled Empty Block (label) main::@9
|
|
|
|
Culled Empty Block (label) main::@10
|
2019-03-31 21:32:25 +00:00
|
|
|
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
@begin: scope:[] from
|
|
|
|
to:@1
|
|
|
|
main: scope:[main] from @1
|
2019-05-30 20:29:04 +00:00
|
|
|
(byte*) main::screen#0 ← ((byte*)) (number) $400
|
2019-04-03 01:41:57 +00:00
|
|
|
(byte[]) main::str#0 ← (const string) main::$5
|
2019-06-02 22:44:46 +00:00
|
|
|
(byte) main::i#0 ← (byte) 0
|
2019-03-31 21:32:25 +00:00
|
|
|
to:main::@1
|
|
|
|
main::@1: scope:[main] from main main::@5
|
2019-04-03 01:41:57 +00:00
|
|
|
(byte*) main::screen#4 ← phi( main/(byte*) main::screen#0 main::@5/(byte*) main::screen#5 )
|
|
|
|
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@5/(byte) main::i#1 )
|
|
|
|
(bool~) main::$0 ← *((byte[]) main::str#0 + (byte) main::i#2) == (byte) '@'
|
|
|
|
(bool~) main::$1 ← ! (bool~) main::$0
|
2019-03-31 21:32:25 +00:00
|
|
|
if((bool~) main::$1) goto main::@2
|
|
|
|
to:main::@return
|
|
|
|
main::@2: scope:[main] from main::@1
|
2019-04-03 01:41:57 +00:00
|
|
|
(byte*) main::screen#3 ← phi( main::@1/(byte*) main::screen#4 )
|
|
|
|
(byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
|
|
|
|
(bool~) main::$2 ← *((byte[]) main::str#0 + (byte) main::i#3) == (byte) ' '
|
|
|
|
(bool~) main::$3 ← ! (bool~) main::$2
|
2019-03-31 21:32:25 +00:00
|
|
|
if((bool~) main::$3) goto main::@4
|
|
|
|
to:main::@5
|
|
|
|
main::@4: scope:[main] from main::@2
|
2019-04-03 01:41:57 +00:00
|
|
|
(byte*) main::screen#2 ← phi( main::@2/(byte*) main::screen#3 )
|
|
|
|
(byte) main::i#4 ← phi( main::@2/(byte) main::i#3 )
|
|
|
|
*((byte*) main::screen#2) ← *((byte[]) main::str#0 + (byte) main::i#4)
|
|
|
|
(byte*) main::screen#1 ← ++ (byte*) main::screen#2
|
2019-03-31 21:32:25 +00:00
|
|
|
to:main::@5
|
|
|
|
main::@5: scope:[main] from main::@2 main::@4
|
2019-04-03 01:41:57 +00:00
|
|
|
(byte*) main::screen#5 ← phi( main::@2/(byte*) main::screen#3 main::@4/(byte*) main::screen#1 )
|
|
|
|
(byte) main::i#5 ← phi( main::@2/(byte) main::i#3 main::@4/(byte) main::i#4 )
|
|
|
|
(byte) main::i#1 ← (byte) main::i#5 + rangenext(0,$ff)
|
|
|
|
(bool~) main::$4 ← (byte) main::i#1 != rangelast(0,$ff)
|
2019-03-31 21:32:25 +00:00
|
|
|
if((bool~) main::$4) goto main::@1
|
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main::@1 main::@5
|
|
|
|
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
|
|
|
|
(void()) main()
|
|
|
|
(bool~) main::$0
|
|
|
|
(bool~) main::$1
|
|
|
|
(bool~) main::$2
|
|
|
|
(bool~) main::$3
|
|
|
|
(bool~) main::$4
|
2019-08-07 17:36:19 +00:00
|
|
|
(const string) main::$5 = (string) "hello brave new world"
|
2019-03-31 21:32:25 +00:00
|
|
|
(label) main::@1
|
|
|
|
(label) main::@2
|
|
|
|
(label) main::@4
|
|
|
|
(label) main::@5
|
|
|
|
(label) main::@return
|
|
|
|
(byte) main::i
|
|
|
|
(byte) main::i#0
|
|
|
|
(byte) main::i#1
|
|
|
|
(byte) main::i#2
|
|
|
|
(byte) main::i#3
|
|
|
|
(byte) main::i#4
|
|
|
|
(byte) main::i#5
|
|
|
|
(byte*) main::screen
|
|
|
|
(byte*) main::screen#0
|
|
|
|
(byte*) main::screen#1
|
|
|
|
(byte*) main::screen#2
|
|
|
|
(byte*) main::screen#3
|
|
|
|
(byte*) main::screen#4
|
|
|
|
(byte*) main::screen#5
|
|
|
|
(byte[]) main::str
|
|
|
|
(byte[]) main::str#0
|
|
|
|
|
2019-05-30 20:29:04 +00:00
|
|
|
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
|
|
|
|
Successful SSA optimization Pass2InlineCast
|
|
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
|
|
Successful SSA optimization PassNCastSimplification
|
2019-04-03 01:41:57 +00:00
|
|
|
Inversing boolean not [5] (bool~) main::$1 ← *((byte[]) main::str#0 + (byte) main::i#2) != (byte) '@' from [4] (bool~) main::$0 ← *((byte[]) main::str#0 + (byte) main::i#2) == (byte) '@'
|
|
|
|
Inversing boolean not [9] (bool~) main::$3 ← *((byte[]) main::str#0 + (byte) main::i#3) != (byte) ' ' from [8] (bool~) main::$2 ← *((byte[]) main::str#0 + (byte) main::i#3) == (byte) ' '
|
2019-03-31 21:32:25 +00:00
|
|
|
Successful SSA optimization Pass2UnaryNotSimplification
|
|
|
|
Alias (byte) main::i#2 = (byte) main::i#3 (byte) main::i#4
|
|
|
|
Alias (byte*) main::screen#2 = (byte*) main::screen#3 (byte*) main::screen#4
|
|
|
|
Successful SSA optimization Pass2AliasElimination
|
|
|
|
Alias (byte) main::i#2 = (byte) main::i#5
|
|
|
|
Successful SSA optimization Pass2AliasElimination
|
|
|
|
Simple Condition (bool~) main::$1 [6] if(*((byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2
|
|
|
|
Simple Condition (bool~) main::$3 [10] if(*((byte[]) main::str#0 + (byte) main::i#2)!=(byte) ' ') goto main::@4
|
|
|
|
Simple Condition (bool~) main::$4 [17] if((byte) main::i#1!=rangelast(0,$ff)) goto main::@1
|
|
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
2019-05-30 20:29:04 +00:00
|
|
|
Negating conditional jump and destination [10] if(*((byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@5
|
|
|
|
Negating conditional jump and destination [17] if((byte) main::i#1==rangelast(0,$ff)) goto main::@return
|
|
|
|
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
|
|
|
|
Constant (const byte*) main::screen#0 = (byte*) 1024
|
2019-03-31 21:32:25 +00:00
|
|
|
Constant (const byte[]) main::str#0 = main::$5
|
|
|
|
Constant (const byte) main::i#0 = 0
|
|
|
|
Successful SSA optimization Pass2ConstantIdentification
|
2019-05-30 20:29:04 +00:00
|
|
|
Resolved ranged next value [15] main::i#1 ← ++ main::i#2 to ++
|
|
|
|
Resolved ranged comparison value [17] if(main::i#1==rangelast(0,$ff)) goto main::@return to (number) 0
|
|
|
|
Adding number conversion cast (unumber) 0 in if((byte) main::i#1==(number) 0) goto main::@return
|
|
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
|
|
Simplifying constant integer cast 0
|
|
|
|
Successful SSA optimization PassNCastSimplification
|
|
|
|
Finalized unsigned number type (byte) 0
|
|
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
2019-03-31 21:32:25 +00:00
|
|
|
Inlining constant with var siblings (const byte*) main::screen#0
|
|
|
|
Inlining constant with var siblings (const byte) main::i#0
|
|
|
|
Constant inlined main::$5 = (const byte[]) main::str#0
|
2019-05-30 20:29:04 +00:00
|
|
|
Constant inlined main::screen#0 = (byte*) 1024
|
|
|
|
Constant inlined main::i#0 = (byte) 0
|
2019-03-31 21:32:25 +00:00
|
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
|
|
Added new block during phi lifting main::@11(between main::@5 and main::@1)
|
|
|
|
Added new block during phi lifting main::@12(between main::@2 and main::@5)
|
|
|
|
Adding NOP phi() at start of @begin
|
|
|
|
Adding NOP phi() at start of @1
|
2019-05-30 20:29:04 +00:00
|
|
|
Adding NOP phi() at start of @2
|
2019-03-31 21:32:25 +00:00
|
|
|
Adding NOP phi() at start of @end
|
|
|
|
Adding NOP phi() at start of main
|
|
|
|
CALL GRAPH
|
|
|
|
Calls in [] to main:2
|
|
|
|
|
|
|
|
Created 3 initial phi equivalence classes
|
2019-05-30 20:29:04 +00:00
|
|
|
Coalesced [12] main::screen#8 ← main::screen#1
|
|
|
|
Coalesced [16] main::i#6 ← main::i#1
|
|
|
|
Coalesced [17] main::screen#6 ← main::screen#5
|
|
|
|
Coalesced (already) [18] main::screen#7 ← main::screen#2
|
2019-03-31 21:32:25 +00:00
|
|
|
Coalesced down to 2 phi equivalence classes
|
2019-05-30 20:29:04 +00:00
|
|
|
Culled Empty Block (label) @2
|
2019-03-31 21:32:25 +00:00
|
|
|
Culled Empty Block (label) main::@11
|
2019-05-30 20:29:04 +00:00
|
|
|
Culled Empty Block (label) main::@12
|
2019-03-31 21:32:25 +00:00
|
|
|
Renumbering block main::@4 to main::@3
|
|
|
|
Renumbering block main::@5 to main::@4
|
|
|
|
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
|
|
|
|
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
@begin: scope:[] from
|
|
|
|
[0] phi()
|
|
|
|
to:@1
|
|
|
|
@1: scope:[] from @begin
|
|
|
|
[1] phi()
|
|
|
|
[2] call main
|
|
|
|
to:@end
|
|
|
|
@end: scope:[] from @1
|
|
|
|
[3] phi()
|
|
|
|
main: scope:[main] from @1
|
|
|
|
[4] phi()
|
|
|
|
to:main::@1
|
|
|
|
main::@1: scope:[main] from main main::@4
|
2019-05-30 20:29:04 +00:00
|
|
|
[5] (byte*) main::screen#2 ← phi( main/(byte*) 1024 main::@4/(byte*) main::screen#5 )
|
|
|
|
[5] (byte) main::i#2 ← phi( main/(byte) 0 main::@4/(byte) main::i#1 )
|
2019-03-31 21:32:25 +00:00
|
|
|
[6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2
|
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main::@1 main::@4
|
|
|
|
[7] return
|
|
|
|
to:@return
|
|
|
|
main::@2: scope:[main] from main::@1
|
2019-05-30 20:29:04 +00:00
|
|
|
[8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4
|
|
|
|
to:main::@3
|
2019-03-31 21:32:25 +00:00
|
|
|
main::@3: scope:[main] from main::@2
|
2019-05-30 20:29:04 +00:00
|
|
|
[9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2)
|
|
|
|
[10] (byte*) main::screen#1 ← ++ (byte*) main::screen#2
|
2019-03-31 21:32:25 +00:00
|
|
|
to:main::@4
|
2019-05-30 20:29:04 +00:00
|
|
|
main::@4: scope:[main] from main::@2 main::@3
|
|
|
|
[11] (byte*) main::screen#5 ← phi( main::@2/(byte*) main::screen#2 main::@3/(byte*) main::screen#1 )
|
|
|
|
[12] (byte) main::i#1 ← ++ (byte) main::i#2
|
|
|
|
[13] if((byte) main::i#1==(byte) 0) goto main::@return
|
|
|
|
to:main::@1
|
2019-03-31 21:32:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
|
|
(void()) main()
|
|
|
|
(byte) main::i
|
|
|
|
(byte) main::i#1 16.5
|
|
|
|
(byte) main::i#2 9.166666666666666
|
|
|
|
(byte*) main::screen
|
|
|
|
(byte*) main::screen#1 22.0
|
|
|
|
(byte*) main::screen#2 11.0
|
|
|
|
(byte*) main::screen#5 11.0
|
|
|
|
(byte[]) main::str
|
|
|
|
|
|
|
|
Initial phi equivalence classes
|
|
|
|
[ main::i#2 main::i#1 ]
|
|
|
|
[ main::screen#2 main::screen#5 main::screen#1 ]
|
|
|
|
Complete equivalence classes
|
|
|
|
[ main::i#2 main::i#1 ]
|
|
|
|
[ main::screen#2 main::screen#5 main::screen#1 ]
|
|
|
|
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
|
|
|
Allocated zp ZP_WORD:3 [ main::screen#2 main::screen#5 main::screen#1 ]
|
|
|
|
|
|
|
|
INITIAL ASM
|
2019-07-25 15:06:17 +00:00
|
|
|
Target platform is c64basic
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-03-31 21:32:25 +00:00
|
|
|
// Illustrates both break & continue statements in a loop
|
|
|
|
// Prints a message ending at '@' skipping all spaces
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-03-31 21:32:25 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
|
|
|
// @begin
|
2019-03-31 21:32:25 +00:00
|
|
|
bbegin:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
2019-03-31 21:32:25 +00:00
|
|
|
b1_from_bbegin:
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// @1
|
2019-03-31 21:32:25 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [2] call main
|
|
|
|
// [4] phi from @1 to main [phi:@1->main]
|
2019-03-31 21:32:25 +00:00
|
|
|
main_from_b1:
|
|
|
|
jsr main
|
2019-07-08 14:43:09 +00:00
|
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
2019-03-31 21:32:25 +00:00
|
|
|
bend_from_b1:
|
|
|
|
jmp bend
|
2019-07-08 14:43:09 +00:00
|
|
|
// @end
|
2019-03-31 21:32:25 +00:00
|
|
|
bend:
|
2019-07-08 14:43:09 +00:00
|
|
|
// main
|
2019-03-31 21:32:25 +00:00
|
|
|
main: {
|
|
|
|
.label screen = 3
|
|
|
|
.label i = 2
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main to main::@1 [phi:main->main::@1]
|
2019-03-31 21:32:25 +00:00
|
|
|
b1_from_main:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda #<$400
|
|
|
|
sta screen
|
|
|
|
lda #>$400
|
|
|
|
sta screen+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda #0
|
|
|
|
sta i
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@1
|
2019-03-31 21:32:25 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2 -- pbuc1_derefidx_vbuz1_neq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda #'@'
|
|
|
|
ldy i
|
|
|
|
cmp str,y
|
|
|
|
bne b2
|
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
2019-03-31 21:32:25 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [7] return
|
2019-03-31 21:32:25 +00:00
|
|
|
rts
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@2
|
2019-03-31 21:32:25 +00:00
|
|
|
b2:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4 -- pbuc1_derefidx_vbuz1_eq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
ldy i
|
2019-05-30 20:29:04 +00:00
|
|
|
lda str,y
|
|
|
|
cmp #' '
|
|
|
|
beq b4_from_b2
|
|
|
|
jmp b3
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@3
|
2019-03-31 21:32:25 +00:00
|
|
|
b3:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2) -- _deref_pbuz1=pbuc1_derefidx_vbuz2
|
2019-03-31 21:32:25 +00:00
|
|
|
ldy i
|
|
|
|
lda str,y
|
|
|
|
ldy #0
|
|
|
|
sta (screen),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1
|
2019-03-31 21:32:25 +00:00
|
|
|
inc screen
|
|
|
|
bne !+
|
|
|
|
inc screen+1
|
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
|
2019-05-30 20:29:04 +00:00
|
|
|
b4_from_b2:
|
|
|
|
b4_from_b3:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] phi (byte*) main::screen#5 = (byte*) main::screen#2 [phi:main::@2/main::@3->main::@4#0] -- register_copy
|
2019-05-30 20:29:04 +00:00
|
|
|
jmp b4
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@4
|
2019-05-30 20:29:04 +00:00
|
|
|
b4:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
2019-05-30 20:29:04 +00:00
|
|
|
inc i
|
2019-07-08 14:43:09 +00:00
|
|
|
// [13] if((byte) main::i#1==(byte) 0) goto main::@return -- vbuz1_eq_0_then_la1
|
2019-05-30 20:29:04 +00:00
|
|
|
lda i
|
|
|
|
cmp #0
|
|
|
|
beq breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
|
2019-05-30 20:29:04 +00:00
|
|
|
b1_from_b4:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) main::screen#5 [phi:main::@4->main::@1#0] -- register_copy
|
|
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#1] -- register_copy
|
2019-05-30 20:29:04 +00:00
|
|
|
jmp b1
|
2019-08-07 17:36:19 +00:00
|
|
|
str: .text "hello brave new world"
|
|
|
|
.byte 0
|
2019-03-31 21:32:25 +00:00
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-03-31 21:32:25 +00:00
|
|
|
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
|
|
Statement [6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a
|
|
|
|
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
2019-05-30 20:29:04 +00:00
|
|
|
Statement [8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a
|
|
|
|
Statement [9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2) [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a reg byte y
|
2019-03-31 21:32:25 +00:00
|
|
|
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
|
|
|
Statement [6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a
|
2019-05-30 20:29:04 +00:00
|
|
|
Statement [8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a
|
|
|
|
Statement [9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2) [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a reg byte y
|
2019-03-31 21:32:25 +00:00
|
|
|
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x ,
|
|
|
|
Potential registers zp ZP_WORD:3 [ main::screen#2 main::screen#5 main::screen#1 ] : zp ZP_WORD:3 ,
|
|
|
|
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
|
|
Uplift Scope [main] 44: zp ZP_WORD:3 [ main::screen#2 main::screen#5 main::screen#1 ] 25.67: zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
|
|
|
|
Uplift Scope []
|
|
|
|
|
2019-05-30 20:29:04 +00:00
|
|
|
Uplifting [main] best 783 combination zp ZP_WORD:3 [ main::screen#2 main::screen#5 main::screen#1 ] reg byte x [ main::i#2 main::i#1 ]
|
|
|
|
Uplifting [] best 783 combination
|
2019-03-31 21:32:25 +00:00
|
|
|
Allocated (was zp ZP_WORD:3) zp ZP_WORD:2 [ main::screen#2 main::screen#5 main::screen#1 ]
|
|
|
|
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-03-31 21:32:25 +00:00
|
|
|
// Illustrates both break & continue statements in a loop
|
|
|
|
// Prints a message ending at '@' skipping all spaces
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-03-31 21:32:25 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
|
|
|
// @begin
|
2019-03-31 21:32:25 +00:00
|
|
|
bbegin:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
2019-03-31 21:32:25 +00:00
|
|
|
b1_from_bbegin:
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// @1
|
2019-03-31 21:32:25 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [2] call main
|
|
|
|
// [4] phi from @1 to main [phi:@1->main]
|
2019-03-31 21:32:25 +00:00
|
|
|
main_from_b1:
|
|
|
|
jsr main
|
2019-07-08 14:43:09 +00:00
|
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
2019-03-31 21:32:25 +00:00
|
|
|
bend_from_b1:
|
|
|
|
jmp bend
|
2019-07-08 14:43:09 +00:00
|
|
|
// @end
|
2019-03-31 21:32:25 +00:00
|
|
|
bend:
|
2019-07-08 14:43:09 +00:00
|
|
|
// main
|
2019-03-31 21:32:25 +00:00
|
|
|
main: {
|
|
|
|
.label screen = 2
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main to main::@1 [phi:main->main::@1]
|
2019-03-31 21:32:25 +00:00
|
|
|
b1_from_main:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda #<$400
|
|
|
|
sta screen
|
|
|
|
lda #>$400
|
|
|
|
sta screen+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
ldx #0
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@1
|
2019-03-31 21:32:25 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2 -- pbuc1_derefidx_vbuxx_neq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
cmp #'@'
|
|
|
|
bne b2
|
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
2019-03-31 21:32:25 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [7] return
|
2019-03-31 21:32:25 +00:00
|
|
|
rts
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@2
|
2019-03-31 21:32:25 +00:00
|
|
|
b2:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4 -- pbuc1_derefidx_vbuxx_eq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
cmp #' '
|
2019-05-30 20:29:04 +00:00
|
|
|
beq b4_from_b2
|
|
|
|
jmp b3
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@3
|
2019-03-31 21:32:25 +00:00
|
|
|
b3:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2) -- _deref_pbuz1=pbuc1_derefidx_vbuxx
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
ldy #0
|
|
|
|
sta (screen),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1
|
2019-03-31 21:32:25 +00:00
|
|
|
inc screen
|
|
|
|
bne !+
|
|
|
|
inc screen+1
|
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
|
2019-05-30 20:29:04 +00:00
|
|
|
b4_from_b2:
|
|
|
|
b4_from_b3:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] phi (byte*) main::screen#5 = (byte*) main::screen#2 [phi:main::@2/main::@3->main::@4#0] -- register_copy
|
2019-05-30 20:29:04 +00:00
|
|
|
jmp b4
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@4
|
2019-05-30 20:29:04 +00:00
|
|
|
b4:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
2019-05-30 20:29:04 +00:00
|
|
|
inx
|
2019-07-08 14:43:09 +00:00
|
|
|
// [13] if((byte) main::i#1==(byte) 0) goto main::@return -- vbuxx_eq_0_then_la1
|
2019-05-30 20:29:04 +00:00
|
|
|
cpx #0
|
|
|
|
beq breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
|
2019-05-30 20:29:04 +00:00
|
|
|
b1_from_b4:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) main::screen#5 [phi:main::@4->main::@1#0] -- register_copy
|
|
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#1] -- register_copy
|
2019-05-30 20:29:04 +00:00
|
|
|
jmp b1
|
2019-08-07 17:36:19 +00:00
|
|
|
str: .text "hello brave new world"
|
|
|
|
.byte 0
|
2019-03-31 21:32:25 +00:00
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-03-31 21:32:25 +00:00
|
|
|
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
|
|
Removing instruction jmp b1
|
|
|
|
Removing instruction jmp bend
|
|
|
|
Removing instruction jmp b1
|
|
|
|
Removing instruction jmp breturn
|
2019-05-30 20:29:04 +00:00
|
|
|
Removing instruction jmp b3
|
2019-03-31 21:32:25 +00:00
|
|
|
Removing instruction jmp b4
|
|
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
2019-05-30 20:29:04 +00:00
|
|
|
Replacing label b4_from_b2 with b4
|
2019-03-31 21:32:25 +00:00
|
|
|
Removing instruction b1_from_bbegin:
|
|
|
|
Removing instruction b1:
|
|
|
|
Removing instruction main_from_b1:
|
|
|
|
Removing instruction bend_from_b1:
|
|
|
|
Removing instruction b4_from_b2:
|
|
|
|
Removing instruction b4_from_b3:
|
|
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
|
|
Removing instruction bend:
|
|
|
|
Removing instruction b1_from_main:
|
2019-05-30 20:29:04 +00:00
|
|
|
Removing instruction b3:
|
|
|
|
Removing instruction b1_from_b4:
|
2019-03-31 21:32:25 +00:00
|
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
Updating BasicUpstart to call main directly
|
|
|
|
Removing instruction jsr main
|
|
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
|
|
Removing instruction bbegin:
|
|
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
|
|
|
|
FINAL SYMBOL TABLE
|
|
|
|
(label) @1
|
|
|
|
(label) @begin
|
|
|
|
(label) @end
|
|
|
|
(void()) main()
|
|
|
|
(label) main::@1
|
|
|
|
(label) main::@2
|
|
|
|
(label) main::@3
|
|
|
|
(label) main::@4
|
|
|
|
(label) main::@return
|
|
|
|
(byte) main::i
|
|
|
|
(byte) main::i#1 reg byte x 16.5
|
|
|
|
(byte) main::i#2 reg byte x 9.166666666666666
|
|
|
|
(byte*) main::screen
|
|
|
|
(byte*) main::screen#1 screen zp ZP_WORD:2 22.0
|
|
|
|
(byte*) main::screen#2 screen zp ZP_WORD:2 11.0
|
|
|
|
(byte*) main::screen#5 screen zp ZP_WORD:2 11.0
|
|
|
|
(byte[]) main::str
|
2019-08-07 17:36:19 +00:00
|
|
|
(const byte[]) main::str#0 str = (string) "hello brave new world"
|
2019-03-31 21:32:25 +00:00
|
|
|
|
|
|
|
reg byte x [ main::i#2 main::i#1 ]
|
|
|
|
zp ZP_WORD:2 [ main::screen#2 main::screen#5 main::screen#1 ]
|
|
|
|
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
2019-05-30 20:29:04 +00:00
|
|
|
Score: 651
|
2019-03-31 21:32:25 +00:00
|
|
|
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-03-31 21:32:25 +00:00
|
|
|
// Illustrates both break & continue statements in a loop
|
|
|
|
// Prints a message ending at '@' skipping all spaces
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-03-31 21:32:25 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
|
|
|
// @begin
|
|
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
|
|
// @1
|
|
|
|
// [2] call main
|
|
|
|
// [4] phi from @1 to main [phi:@1->main]
|
|
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
|
|
// @end
|
|
|
|
// main
|
2019-03-31 21:32:25 +00:00
|
|
|
main: {
|
|
|
|
.label screen = 2
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main to main::@1 [phi:main->main::@1]
|
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda #<$400
|
|
|
|
sta screen
|
|
|
|
lda #>$400
|
|
|
|
sta screen+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1
|
2019-03-31 21:32:25 +00:00
|
|
|
ldx #0
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@1
|
2019-03-31 21:32:25 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// if(str[i]=='@')
|
|
|
|
// [6] if(*((const byte[]) main::str#0 + (byte) main::i#2)!=(byte) '@') goto main::@2 -- pbuc1_derefidx_vbuxx_neq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
cmp #'@'
|
|
|
|
bne b2
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
2019-05-30 20:29:04 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// }
|
|
|
|
// [7] return
|
2019-03-31 21:32:25 +00:00
|
|
|
rts
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@2
|
2019-03-31 21:32:25 +00:00
|
|
|
b2:
|
2019-07-08 14:43:09 +00:00
|
|
|
// if(str[i]==' ')
|
|
|
|
// [8] if(*((const byte[]) main::str#0 + (byte) main::i#2)==(byte) ' ') goto main::@4 -- pbuc1_derefidx_vbuxx_eq_vbuc2_then_la1
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
cmp #' '
|
2019-05-30 20:29:04 +00:00
|
|
|
beq b4
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@3
|
|
|
|
// *screen++ = str[i]
|
|
|
|
// [9] *((byte*) main::screen#2) ← *((const byte[]) main::str#0 + (byte) main::i#2) -- _deref_pbuz1=pbuc1_derefidx_vbuxx
|
2019-03-31 21:32:25 +00:00
|
|
|
lda str,x
|
|
|
|
ldy #0
|
|
|
|
sta (screen),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// *screen++ = str[i];
|
|
|
|
// [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1
|
2019-03-31 21:32:25 +00:00
|
|
|
inc screen
|
|
|
|
bne !+
|
|
|
|
inc screen+1
|
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
|
|
|
|
// [11] phi (byte*) main::screen#5 = (byte*) main::screen#2 [phi:main::@2/main::@3->main::@4#0] -- register_copy
|
|
|
|
// main::@4
|
2019-05-30 20:29:04 +00:00
|
|
|
b4:
|
2019-07-08 14:43:09 +00:00
|
|
|
// for( byte i: 0..255)
|
|
|
|
// [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
2019-05-30 20:29:04 +00:00
|
|
|
inx
|
2019-07-08 14:43:09 +00:00
|
|
|
// [13] if((byte) main::i#1==(byte) 0) goto main::@return -- vbuxx_eq_0_then_la1
|
2019-05-30 20:29:04 +00:00
|
|
|
cpx #0
|
|
|
|
beq breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
|
|
|
|
// [5] phi (byte*) main::screen#2 = (byte*) main::screen#5 [phi:main::@4->main::@1#0] -- register_copy
|
|
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#1] -- register_copy
|
2019-05-30 20:29:04 +00:00
|
|
|
jmp b1
|
2019-08-07 17:36:19 +00:00
|
|
|
str: .text "hello brave new world"
|
|
|
|
.byte 0
|
2019-03-31 21:32:25 +00:00
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-03-31 21:32:25 +00:00
|
|
|
|