1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-16 21:07:56 +00:00
kickc/src/test/ref/word-pointer-iteration.log

445 lines
15 KiB
Plaintext

CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start
main::idx#0 = 0
main::wp#0 = main::words
main::i#0 = 0
to:main::@1
main::@1: scope:[main] from main main::@1
main::i#2 = phi( main/main::i#0, main::@1/main::i#1 )
main::idx#4 = phi( main/main::idx#0, main::@1/main::idx#3 )
main::wp#2 = phi( main/main::wp#0, main::@1/main::wp#1 )
main::w#0 = *main::wp#2
main::wp#1 = main::wp#2 + SIZEOF_WORD
main::$0 = < main::w#0
main::SCREEN[main::idx#4] = main::$0
main::idx#1 = ++ main::idx#4
main::$1 = > main::w#0
main::SCREEN[main::idx#1] = main::$1
main::idx#2 = ++ main::idx#1
main::idx#3 = ++ main::idx#2
main::i#1 = main::i#2 + rangenext(0,3)
main::$2 = main::i#1 != rangelast(0,3)
if(main::$2) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
return
to:@return
void __start()
__start: scope:[__start] from
call main
to:__start::@1
__start::@1: scope:[__start] from __start
to:__start::@return
__start::@return: scope:[__start] from __start::@1
return
to:@return
SYMBOL TABLE SSA
const byte SIZEOF_WORD = 2
void __start()
void main()
byte~ main::$0
byte~ main::$1
bool~ main::$2
const nomodify byte* main::SCREEN = (byte*)$400
byte main::i
byte main::i#0
byte main::i#1
byte main::i#2
byte main::idx
byte main::idx#0
byte main::idx#1
byte main::idx#2
byte main::idx#3
byte main::idx#4
word main::w
word main::w#0
const word* main::words[] = { $3130, $3332, $3534, $3736 }
word* main::wp
word* main::wp#0
word* main::wp#1
word* main::wp#2
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Simple Condition main::$2 [15] if(main::i#1!=rangelast(0,3)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::idx#0 = 0
Constant main::wp#0 = main::words
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [13] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [15] if(main::i#1!=rangelast(0,3)) goto main::@1 to 4
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) 4 in [11] if(main::i#1!=4) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::idx#0
Inlining constant with var siblings main::wp#0
Inlining constant with var siblings main::i#0
Constant inlined main::i#0 = 0
Constant inlined main::wp#0 = main::words
Constant inlined main::idx#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@2(between main::@1 and main::@1)
Adding NOP phi() at start of main
CALL GRAPH
Created 3 initial phi equivalence classes
Coalesced [14] main::wp#3 = main::wp#1
Coalesced [15] main::idx#5 = main::idx#3
Coalesced [16] main::i#3 = main::i#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block label main::@2
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::@1
[1] main::i#2 = phi( main/0, main::@1/main::i#1 )
[1] main::idx#4 = phi( main/0, main::@1/main::idx#3 )
[1] main::wp#2 = phi( main/main::words, main::@1/main::wp#1 )
[2] main::w#0 = *main::wp#2
[3] main::wp#1 = main::wp#2 + SIZEOF_WORD
[4] main::$0 = < main::w#0
[5] main::SCREEN[main::idx#4] = main::$0
[6] main::idx#1 = ++ main::idx#4
[7] main::$1 = > main::w#0
[8] main::SCREEN[main::idx#1] = main::$1
[9] main::idx#2 = ++ main::idx#1
[10] main::idx#3 = ++ main::idx#2
[11] main::i#1 = ++ main::i#2
[12] if(main::i#1!=4) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[13] return
to:@return
VARIABLE REGISTER WEIGHTS
void main()
byte~ main::$0 22.0
byte~ main::$1 22.0
byte main::i
byte main::i#1 16.5
byte main::i#2 2.2
byte main::idx
byte main::idx#1 11.0
byte main::idx#2 22.0
byte main::idx#3 7.333333333333333
byte main::idx#4 6.6000000000000005
word main::w
word main::w#0 6.6000000000000005
word* main::wp
word* main::wp#1 2.2
word* main::wp#2 16.5
Initial phi equivalence classes
[ main::wp#2 main::wp#1 ]
[ main::idx#4 main::idx#3 ]
[ main::i#2 main::i#1 ]
Added variable main::w#0 to live range equivalence class [ main::w#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::idx#1 to live range equivalence class [ main::idx#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::idx#2 to live range equivalence class [ main::idx#2 ]
Complete equivalence classes
[ main::wp#2 main::wp#1 ]
[ main::idx#4 main::idx#3 ]
[ main::i#2 main::i#1 ]
[ main::w#0 ]
[ main::$0 ]
[ main::idx#1 ]
[ main::$1 ]
[ main::idx#2 ]
Allocated zp[2]:2 [ main::wp#2 main::wp#1 ]
Allocated zp[1]:4 [ main::idx#4 main::idx#3 ]
Allocated zp[1]:5 [ main::i#2 main::i#1 ]
Allocated zp[2]:6 [ main::w#0 ]
Allocated zp[1]:8 [ main::$0 ]
Allocated zp[1]:9 [ main::idx#1 ]
Allocated zp[1]:10 [ main::$1 ]
Allocated zp[1]:11 [ main::idx#2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] main::w#0 = *main::wp#2 [ main::wp#2 main::idx#4 main::i#2 main::w#0 ] ( [ main::wp#2 main::idx#4 main::i#2 main::w#0 ] { } ) always clobbers reg byte a reg byte y
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::idx#4 main::idx#3 ]
Removing always clobbered register reg byte y as potential for zp[1]:4 [ main::idx#4 main::idx#3 ]
Removing always clobbered register reg byte a as potential for zp[1]:5 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:5 [ main::i#2 main::i#1 ]
Statement [3] main::wp#1 = main::wp#2 + SIZEOF_WORD [ main::idx#4 main::i#2 main::wp#1 main::w#0 ] ( [ main::idx#4 main::i#2 main::wp#1 main::w#0 ] { } ) always clobbers reg byte a
Statement [2] main::w#0 = *main::wp#2 [ main::wp#2 main::idx#4 main::i#2 main::w#0 ] ( [ main::wp#2 main::idx#4 main::i#2 main::w#0 ] { } ) always clobbers reg byte a reg byte y
Statement [3] main::wp#1 = main::wp#2 + SIZEOF_WORD [ main::idx#4 main::i#2 main::wp#1 main::w#0 ] ( [ main::idx#4 main::i#2 main::wp#1 main::w#0 ] { } ) always clobbers reg byte a
Potential registers zp[2]:2 [ main::wp#2 main::wp#1 ] : zp[2]:2 ,
Potential registers zp[1]:4 [ main::idx#4 main::idx#3 ] : zp[1]:4 , reg byte x ,
Potential registers zp[1]:5 [ main::i#2 main::i#1 ] : zp[1]:5 , reg byte x ,
Potential registers zp[2]:6 [ main::w#0 ] : zp[2]:6 ,
Potential registers zp[1]:8 [ main::$0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:9 [ main::idx#1 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:10 [ main::$1 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:11 [ main::idx#2 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp[1]:8 [ main::$0 ] 22: zp[1]:10 [ main::$1 ] 22: zp[1]:11 [ main::idx#2 ] 18.7: zp[2]:2 [ main::wp#2 main::wp#1 ] 18.7: zp[1]:5 [ main::i#2 main::i#1 ] 13.93: zp[1]:4 [ main::idx#4 main::idx#3 ] 11: zp[1]:9 [ main::idx#1 ] 6.6: zp[2]:6 [ main::w#0 ]
Uplift Scope []
Uplifting [main] best 1156 combination reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte a [ main::idx#2 ] zp[2]:2 [ main::wp#2 main::wp#1 ] reg byte x [ main::i#2 main::i#1 ] zp[1]:4 [ main::idx#4 main::idx#3 ] zp[1]:9 [ main::idx#1 ] zp[2]:6 [ main::w#0 ]
Limited combination testing to 100 combinations of 1024 possible.
Uplifting [] best 1156 combination
Attempting to uplift remaining variables inzp[1]:4 [ main::idx#4 main::idx#3 ]
Uplifting [main] best 1156 combination zp[1]:4 [ main::idx#4 main::idx#3 ]
Attempting to uplift remaining variables inzp[1]:9 [ main::idx#1 ]
Uplifting [main] best 1066 combination reg byte y [ main::idx#1 ]
Allocated (was zp[2]:6) zp[2]:5 [ main::w#0 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Tests simple word pointer iteration
// Upstart
// Commodore 64 PRG executable file
.file [name="word-pointer-iteration.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
// Global Constants & labels
.const SIZEOF_WORD = 2
.segment Code
// main
main: {
.label SCREEN = $400
.label w = 5
.label wp = 2
.label idx = 4
// [1] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
// [1] phi main::idx#4 = 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
lda #0
sta.z idx
// [1] phi main::wp#2 = main::words [phi:main->main::@1#2] -- pwuz1=pwuc1
lda #<words
sta.z wp
lda #>words
sta.z wp+1
jmp __b1
// [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
__b1_from___b1:
// [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy
// [1] phi main::idx#4 = main::idx#3 [phi:main::@1->main::@1#1] -- register_copy
// [1] phi main::wp#2 = main::wp#1 [phi:main::@1->main::@1#2] -- register_copy
jmp __b1
// main::@1
__b1:
// [2] main::w#0 = *main::wp#2 -- vwuz1=_deref_pwuz2
ldy #0
lda (wp),y
sta.z w
iny
lda (wp),y
sta.z w+1
// [3] main::wp#1 = main::wp#2 + SIZEOF_WORD -- pwuz1=pwuz1_plus_vbuc1
lda #SIZEOF_WORD
clc
adc.z wp
sta.z wp
bcc !+
inc.z wp+1
!:
// [4] main::$0 = < main::w#0 -- vbuaa=_lo_vwuz1
lda.z w
// [5] main::SCREEN[main::idx#4] = main::$0 -- pbuc1_derefidx_vbuz1=vbuaa
ldy.z idx
sta SCREEN,y
// [6] main::idx#1 = ++ main::idx#4 -- vbuyy=_inc_vbuz1
ldy.z idx
iny
// [7] main::$1 = > main::w#0 -- vbuaa=_hi_vwuz1
lda.z w+1
// [8] main::SCREEN[main::idx#1] = main::$1 -- pbuc1_derefidx_vbuyy=vbuaa
sta SCREEN,y
// [9] main::idx#2 = ++ main::idx#1 -- vbuaa=_inc_vbuyy
iny
tya
// [10] main::idx#3 = ++ main::idx#2 -- vbuz1=_inc_vbuaa
clc
adc #1
sta.z idx
// [11] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx
inx
// [12] if(main::i#1!=4) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #4
bne __b1_from___b1
jmp __breturn
// main::@return
__breturn:
// [13] return
rts
.segment Data
// Clever word array that represents C64 numbers 0-7
words: .word $3130, $3332, $3534, $3736
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction lda #0 with TXA
Removing instruction ldy.z idx
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label __b1_from___b1 with __b1
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
FINAL SYMBOL TABLE
const byte SIZEOF_WORD = 2
void main()
byte~ main::$0 reg byte a 22.0
byte~ main::$1 reg byte a 22.0
const nomodify byte* main::SCREEN = (byte*) 1024
byte main::i
byte main::i#1 reg byte x 16.5
byte main::i#2 reg byte x 2.2
byte main::idx
byte main::idx#1 reg byte y 11.0
byte main::idx#2 reg byte a 22.0
byte main::idx#3 idx zp[1]:4 7.333333333333333
byte main::idx#4 idx zp[1]:4 6.6000000000000005
word main::w
word main::w#0 w zp[2]:5 6.6000000000000005
const word* main::words[] = { $3130, $3332, $3534, $3736 }
word* main::wp
word* main::wp#1 wp zp[2]:2 2.2
word* main::wp#2 wp zp[2]:2 16.5
zp[2]:2 [ main::wp#2 main::wp#1 ]
zp[1]:4 [ main::idx#4 main::idx#3 ]
reg byte x [ main::i#2 main::i#1 ]
zp[2]:5 [ main::w#0 ]
reg byte a [ main::$0 ]
reg byte y [ main::idx#1 ]
reg byte a [ main::$1 ]
reg byte a [ main::idx#2 ]
FINAL ASSEMBLER
Score: 946
// File Comments
// Tests simple word pointer iteration
// Upstart
// Commodore 64 PRG executable file
.file [name="word-pointer-iteration.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
// Global Constants & labels
.const SIZEOF_WORD = 2
.segment Code
// main
main: {
.label SCREEN = $400
.label w = 5
.label wp = 2
.label idx = 4
// [1] phi from main to main::@1 [phi:main->main::@1]
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
// [1] phi main::idx#4 = 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
txa
sta.z idx
// [1] phi main::wp#2 = main::words [phi:main->main::@1#2] -- pwuz1=pwuc1
lda #<words
sta.z wp
lda #>words
sta.z wp+1
// [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
// [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy
// [1] phi main::idx#4 = main::idx#3 [phi:main::@1->main::@1#1] -- register_copy
// [1] phi main::wp#2 = main::wp#1 [phi:main::@1->main::@1#2] -- register_copy
// main::@1
__b1:
// w = *(wp++)
// [2] main::w#0 = *main::wp#2 -- vwuz1=_deref_pwuz2
ldy #0
lda (wp),y
sta.z w
iny
lda (wp),y
sta.z w+1
// [3] main::wp#1 = main::wp#2 + SIZEOF_WORD -- pwuz1=pwuz1_plus_vbuc1
lda #SIZEOF_WORD
clc
adc.z wp
sta.z wp
bcc !+
inc.z wp+1
!:
// <w
// [4] main::$0 = < main::w#0 -- vbuaa=_lo_vwuz1
lda.z w
// SCREEN[idx++] = <w
// [5] main::SCREEN[main::idx#4] = main::$0 -- pbuc1_derefidx_vbuz1=vbuaa
ldy.z idx
sta SCREEN,y
// SCREEN[idx++] = <w;
// [6] main::idx#1 = ++ main::idx#4 -- vbuyy=_inc_vbuz1
iny
// >w
// [7] main::$1 = > main::w#0 -- vbuaa=_hi_vwuz1
lda.z w+1
// SCREEN[idx++] = >w
// [8] main::SCREEN[main::idx#1] = main::$1 -- pbuc1_derefidx_vbuyy=vbuaa
sta SCREEN,y
// SCREEN[idx++] = >w;
// [9] main::idx#2 = ++ main::idx#1 -- vbuaa=_inc_vbuyy
iny
tya
// idx++;
// [10] main::idx#3 = ++ main::idx#2 -- vbuz1=_inc_vbuaa
clc
adc #1
sta.z idx
// for( byte i: 0..3)
// [11] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx
inx
// [12] if(main::i#1!=4) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #4
bne __b1
// main::@return
// }
// [13] return
rts
.segment Data
// Clever word array that represents C64 numbers 0-7
words: .word $3130, $3332, $3534, $3736
}
// File Data