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

436 lines
14 KiB
Plaintext

CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start
fibs[0] = 0
fibs[1] = 1
main::i#0 = 0
to:main::@1
main::@1: scope:[main] from main main::@2
main::i#2 = phi( main/main::i#0, main::@2/main::i#1 )
main::$0 = main::i#2 < $19-2
if(main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
main::i#3 = phi( main::@1/main::i#2 )
main::$1 = main::i#3 + 2
main::$2 = main::i#3 + 1
main::$3 = fibs[main::i#3] + fibs[main::$2]
fibs[main::$1] = main::$3
main::i#1 = ++ main::i#3
to:main::@1
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
void __start()
const byte* fibs[$19] = { fill( $19, 0) }
void main()
bool~ main::$0
number~ main::$1
number~ main::$2
byte~ main::$3
word main::i
word main::i#0
word main::i#1
word main::i#2
word main::i#3
Adding number conversion cast (unumber) 0 in fibs[0] = 0
Adding number conversion cast (unumber) 0 in fibs[0] = ((unumber)) 0
Adding number conversion cast (unumber) 1 in fibs[1] = 1
Adding number conversion cast (unumber) 1 in fibs[1] = ((unumber)) 1
Adding number conversion cast (unumber) $19-2 in main::$0 = main::i#2 < $19-2
Adding number conversion cast (unumber) 2 in main::$1 = main::i#3 + 2
Adding number conversion cast (unumber) main::$1 in main::$1 = main::i#3 + (unumber)2
Adding number conversion cast (unumber) 1 in main::$2 = main::i#3 + 1
Adding number conversion cast (unumber) main::$2 in main::$2 = main::i#3 + (unumber)1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast fibs[(unumber)0] = (unumber)0
Inlining cast fibs[(unumber)1] = (unumber)1
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to word in main::$1 = main::i#3 + 2
Inferred type updated to word in main::$2 = main::i#3 + 1
Alias main::i#2 = main::i#3
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [5] if(main::i#2<(byte)$19-2) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
De-inlining pointer[w] to *(pointer+w) [8] main::$3 = fibs[main::i#2] + fibs[main::$2]
De-inlining pointer[w] to *(pointer+w) [8] main::$3 = *main::$4 + fibs[main::$2]
De-inlining pointer[w] to *(pointer+w) [9] fibs[main::$1] = main::$3
Successful SSA optimization Pass2DeInlineWordDerefIdx
Simplifying expression containing zero fibs in [0] fibs[0] = 0
Successful SSA optimization PassNSimplifyExpressionWithZero
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
Inlining constant with var siblings main::i#0
Constant inlined main::i#0 = 0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(fibs+1)
Consolidated constant in assignment main::$5
Consolidated constant in assignment main::$6
Successful SSA optimization Pass2ConstantAdditionElimination
Alias main::i#2 = main::$1 main::$2
Successful SSA optimization Pass2AliasElimination
Finalized unsigned number type (byte) $19
Finalized unsigned number type (byte) $19
Finalized unsigned number type (byte) $19
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant integer cast $19-2
Successful SSA optimization PassNCastSimplification
CALL GRAPH
Created 1 initial phi equivalence classes
Coalesced [11] main::i#4 = main::i#1
Coalesced down to 1 phi equivalence classes
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] *fibs = 0
[1] *(fibs+1) = 1
to:main::@1
main::@1: scope:[main] from main main::@2
[2] main::i#2 = phi( main/0, main::@2/main::i#1 )
[3] if(main::i#2<$19-2) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[4] return
to:@return
main::@2: scope:[main] from main::@1
[5] main::$4 = fibs + main::i#2
[6] main::$5 = fibs+1 + main::i#2
[7] main::$3 = *main::$4 + *main::$5
[8] main::$6 = fibs+2 + main::i#2
[9] *main::$6 = main::$3
[10] main::i#1 = ++ main::i#2
to:main::@1
VARIABLE REGISTER WEIGHTS
void main()
byte~ main::$3 11.0
byte*~ main::$4 11.0
byte*~ main::$5 22.0
byte*~ main::$6 22.0
word main::i
word main::i#1 22.0
word main::i#2 9.428571428571429
Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$4 to live range equivalence class [ main::$4 ]
Added variable main::$5 to live range equivalence class [ main::$5 ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Added variable main::$6 to live range equivalence class [ main::$6 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$4 ]
[ main::$5 ]
[ main::$3 ]
[ main::$6 ]
Allocated zp[2]:2 [ main::i#2 main::i#1 ]
Allocated zp[2]:4 [ main::$4 ]
Allocated zp[2]:6 [ main::$5 ]
Allocated zp[1]:8 [ main::$3 ]
Allocated zp[2]:9 [ main::$6 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *fibs = 0 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [1] *(fibs+1) = 1 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [3] if(main::i#2<$19-2) goto main::@2 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a
Statement [5] main::$4 = fibs + main::i#2 [ main::i#2 main::$4 ] ( [ main::i#2 main::$4 ] { } ) always clobbers reg byte a
Statement [6] main::$5 = fibs+1 + main::i#2 [ main::i#2 main::$4 main::$5 ] ( [ main::i#2 main::$4 main::$5 ] { } ) always clobbers reg byte a
Statement [7] main::$3 = *main::$4 + *main::$5 [ main::i#2 main::$3 ] ( [ main::i#2 main::$3 ] { } ) always clobbers reg byte a reg byte y
Statement [8] main::$6 = fibs+2 + main::i#2 [ main::i#2 main::$3 main::$6 ] ( [ main::i#2 main::$3 main::$6 ] { } ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:8 [ main::$3 ]
Statement [9] *main::$6 = main::$3 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a reg byte y
Statement [0] *fibs = 0 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [1] *(fibs+1) = 1 [ ] ( [ ] { } ) always clobbers reg byte a
Statement [3] if(main::i#2<$19-2) goto main::@2 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a
Statement [5] main::$4 = fibs + main::i#2 [ main::i#2 main::$4 ] ( [ main::i#2 main::$4 ] { } ) always clobbers reg byte a
Statement [6] main::$5 = fibs+1 + main::i#2 [ main::i#2 main::$4 main::$5 ] ( [ main::i#2 main::$4 main::$5 ] { } ) always clobbers reg byte a
Statement [7] main::$3 = *main::$4 + *main::$5 [ main::i#2 main::$3 ] ( [ main::i#2 main::$3 ] { } ) always clobbers reg byte a reg byte y
Statement [8] main::$6 = fibs+2 + main::i#2 [ main::i#2 main::$3 main::$6 ] ( [ main::i#2 main::$3 main::$6 ] { } ) always clobbers reg byte a
Statement [9] *main::$6 = main::$3 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a reg byte y
Potential registers zp[2]:2 [ main::i#2 main::i#1 ] : zp[2]:2 ,
Potential registers zp[2]:4 [ main::$4 ] : zp[2]:4 ,
Potential registers zp[2]:6 [ main::$5 ] : zp[2]:6 ,
Potential registers zp[1]:8 [ main::$3 ] : zp[1]:8 , reg byte x , reg byte y ,
Potential registers zp[2]:9 [ main::$6 ] : zp[2]:9 ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 31.43: zp[2]:2 [ main::i#2 main::i#1 ] 22: zp[2]:6 [ main::$5 ] 22: zp[2]:9 [ main::$6 ] 11: zp[2]:4 [ main::$4 ] 11: zp[1]:8 [ main::$3 ]
Uplift Scope []
Uplifting [main] best 1293 combination zp[2]:2 [ main::i#2 main::i#1 ] zp[2]:6 [ main::$5 ] zp[2]:9 [ main::$6 ] zp[2]:4 [ main::$4 ] reg byte x [ main::$3 ]
Uplifting [] best 1293 combination
Allocated (was zp[2]:9) zp[2]:8 [ main::$6 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test array index pointer rewriting
// 8bit array with 16bit index
// Fibonacci calculation uses adjacent indices inside the loop
// Upstart
// Commodore 64 PRG executable file
.file [name="index-pointer-rewrite-6.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
.segment Code
// main
main: {
.label i = 2
.label __4 = 4
.label __5 = 6
.label __6 = 8
// [0] *fibs = 0 -- _deref_pbuc1=vbuc2
lda #0
sta fibs
// [1] *(fibs+1) = 1 -- _deref_pbuc1=vbuc2
lda #1
sta fibs+1
// [2] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [2] phi main::i#2 = 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
lda #<0
sta.z i
lda #>0
sta.z i+1
jmp __b1
// main::@1
__b1:
// [3] if(main::i#2<$19-2) goto main::@2 -- vwuz1_lt_vbuc1_then_la1
lda.z i+1
bne !+
lda.z i
cmp #$19-2
bcc __b2
!:
jmp __breturn
// main::@return
__breturn:
// [4] return
rts
// main::@2
__b2:
// [5] main::$4 = fibs + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs
sta.z __4
lda.z i+1
adc #>fibs
sta.z __4+1
// [6] main::$5 = fibs+1 + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs+1
sta.z __5
lda.z i+1
adc #>fibs+1
sta.z __5+1
// [7] main::$3 = *main::$4 + *main::$5 -- vbuxx=_deref_pbuz1_plus__deref_pbuz2
ldy #0
lda (__4),y
clc
ldy #0
adc (__5),y
tax
// [8] main::$6 = fibs+2 + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs+2
sta.z __6
lda.z i+1
adc #>fibs+2
sta.z __6+1
// [9] *main::$6 = main::$3 -- _deref_pbuz1=vbuxx
txa
ldy #0
sta (__6),y
// [10] main::i#1 = ++ main::i#2 -- vwuz1=_inc_vwuz1
inc.z i
bne !+
inc.z i+1
!:
// [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
__b1_from___b2:
// [2] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy
jmp __b1
}
// File Data
.segment Data
fibs: .fill $19, 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #>0
Removing instruction ldy #0
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
const byte* fibs[$19] = { fill( $19, 0) }
void main()
byte~ main::$3 reg byte x 11.0
byte*~ main::$4 zp[2]:4 11.0
byte*~ main::$5 zp[2]:6 22.0
byte*~ main::$6 zp[2]:8 22.0
word main::i
word main::i#1 i zp[2]:2 22.0
word main::i#2 i zp[2]:2 9.428571428571429
zp[2]:2 [ main::i#2 main::i#1 ]
zp[2]:4 [ main::$4 ]
zp[2]:6 [ main::$5 ]
reg byte x [ main::$3 ]
zp[2]:8 [ main::$6 ]
FINAL ASSEMBLER
Score: 1173
// File Comments
// Test array index pointer rewriting
// 8bit array with 16bit index
// Fibonacci calculation uses adjacent indices inside the loop
// Upstart
// Commodore 64 PRG executable file
.file [name="index-pointer-rewrite-6.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
.segment Code
// main
main: {
.label i = 2
.label __4 = 4
.label __5 = 6
.label __6 = 8
// fibs[0] = 0
// [0] *fibs = 0 -- _deref_pbuc1=vbuc2
lda #0
sta fibs
// fibs[1] = 1
// [1] *(fibs+1) = 1 -- _deref_pbuc1=vbuc2
lda #1
sta fibs+1
// [2] phi from main to main::@1 [phi:main->main::@1]
// [2] phi main::i#2 = 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
lda #<0
sta.z i
sta.z i+1
// main::@1
__b1:
// for(unsigned short i=0;i<NUM_FIBS-2;i++)
// [3] if(main::i#2<$19-2) goto main::@2 -- vwuz1_lt_vbuc1_then_la1
lda.z i+1
bne !+
lda.z i
cmp #$19-2
bcc __b2
!:
// main::@return
// }
// [4] return
rts
// main::@2
__b2:
// fibs[i]+fibs[i+1]
// [5] main::$4 = fibs + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs
sta.z __4
lda.z i+1
adc #>fibs
sta.z __4+1
// [6] main::$5 = fibs+1 + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs+1
sta.z __5
lda.z i+1
adc #>fibs+1
sta.z __5+1
// [7] main::$3 = *main::$4 + *main::$5 -- vbuxx=_deref_pbuz1_plus__deref_pbuz2
ldy #0
lda (__4),y
clc
adc (__5),y
tax
// fibs[i+2] = fibs[i]+fibs[i+1]
// [8] main::$6 = fibs+2 + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
clc
lda.z i
adc #<fibs+2
sta.z __6
lda.z i+1
adc #>fibs+2
sta.z __6+1
// [9] *main::$6 = main::$3 -- _deref_pbuz1=vbuxx
txa
sta (__6),y
// for(unsigned short i=0;i<NUM_FIBS-2;i++)
// [10] main::i#1 = ++ main::i#2 -- vwuz1=_inc_vwuz1
inc.z i
bne !+
inc.z i+1
!:
// [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
// [2] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy
jmp __b1
}
// File Data
.segment Data
fibs: .fill $19, 0