1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-09 08:54:40 +00:00
kickc/src/test/ref/deref-to-derefidx.log

496 lines
14 KiB
Plaintext

CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @2
(byte) idx#13 ← phi( @2/(byte) idx#14 )
(byte*) print::m#0 ← (const byte*) msg1
call print
to:main::@1
main::@1: scope:[main] from main
(byte) idx#7 ← phi( main/(byte) idx#5 )
(byte) idx#0 ← (byte) idx#7
(byte*) print::m#1 ← (const byte*) msg2
call print
to:main::@2
main::@2: scope:[main] from main::@1
(byte) idx#8 ← phi( main::@1/(byte) idx#5 )
(byte) idx#1 ← (byte) idx#8
to:main::@return
main::@return: scope:[main] from main::@2
(byte) idx#9 ← phi( main::@2/(byte) idx#1 )
(byte) idx#2 ← (byte) idx#9
return
to:@return
@1: scope:[] from @begin
(byte) idx#3 ← (byte) 0
to:@2
(void()) print((byte*) print::m)
print: scope:[print] from main main::@1
(byte) idx#10 ← phi( main/(byte) idx#13 main::@1/(byte) idx#0 )
(byte*) print::m#2 ← phi( main/(byte*) print::m#0 main::@1/(byte*) print::m#1 )
(byte*~) print::$0 ← (byte*) print::m#2 + (number) 2
*((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*~) print::$0)
(byte) idx#4 ← ++ (byte) idx#10
to:print::@return
print::@return: scope:[print] from print
(byte) idx#11 ← phi( print/(byte) idx#4 )
(byte) idx#5 ← (byte) idx#11
return
to:@return
@2: scope:[] from @1
(byte) idx#14 ← phi( @1/(byte) idx#3 )
call main
to:@3
@3: scope:[] from @2
(byte) idx#12 ← phi( @2/(byte) idx#2 )
(byte) idx#6 ← (byte) idx#12
to:@end
@end: scope:[] from @3
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*)(number) $400
(byte) idx
(byte) idx#0
(byte) idx#1
(byte) idx#10
(byte) idx#11
(byte) idx#12
(byte) idx#13
(byte) idx#14
(byte) idx#2
(byte) idx#3
(byte) idx#4
(byte) idx#5
(byte) idx#6
(byte) idx#7
(byte) idx#8
(byte) idx#9
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(const byte*) msg1[] = { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }
(const byte*) msg2[] = { (byte) '1', (byte) '2', (byte) '3', (byte) '4' }
(void()) print((byte*) print::m)
(byte*~) print::$0
(label) print::@return
(byte*) print::m
(byte*) print::m#0
(byte*) print::m#1
(byte*) print::m#2
Adding number conversion cast (unumber) 2 in (byte*~) print::$0 ← (byte*) print::m#2 + (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias idx#0 = idx#7
Alias idx#1 = idx#8 idx#9 idx#2
Alias idx#11 = idx#4 idx#5
Alias idx#14 = idx#3
Alias idx#12 = idx#6
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) idx#13 (byte) idx#14
Identical Phi Values (byte) idx#0 (byte) idx#11
Identical Phi Values (byte) idx#1 (byte) idx#11
Identical Phi Values (byte) idx#12 (byte) idx#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant (const byte*) print::m#0 = msg1
Constant (const byte*) print::m#1 = msg2
Constant (const byte) idx#14 = 0
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [11] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*~) print::$0) -- *(print::m#2 + 2)
Successful SSA optimization Pass2InlineDerefIdx
Eliminating unused variable (byte*~) print::$0 and assignment [4] (byte*~) print::$0 ← (byte*) print::m#2 + (byte) 2
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with var siblings (const byte*) print::m#0
Inlining constant with var siblings (const byte*) print::m#1
Inlining constant with var siblings (const byte) idx#14
Constant inlined idx#14 = (byte) 0
Constant inlined print::m#1 = (const byte*) msg2
Constant inlined print::m#0 = (const byte*) msg1
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:3
Calls in [main] to print:7 print:9
Created 2 initial phi equivalence classes
Coalesced [8] idx#15 ← idx#11
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @3
Culled Empty Block (label) main::@2
Renumbering block @2 to @1
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 main::@1
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()
(void()) main()
main: scope:[main] from @1
[4] phi()
[5] call print
to:main::@1
main::@1: scope:[main] from main
[6] phi()
[7] call print
to:main::@return
main::@return: scope:[main] from main::@1
[8] return
to:@return
(void()) print((byte*) print::m)
print: scope:[print] from main main::@1
[9] (byte) idx#10 ← phi( main/(byte) 0 main::@1/(byte) idx#11 )
[9] (byte*) print::m#2 ← phi( main/(const byte*) msg1 main::@1/(const byte*) msg2 )
[10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2)
[11] (byte) idx#11 ← ++ (byte) idx#10
to:print::@return
print::@return: scope:[print] from print
[12] return
to:@return
VARIABLE REGISTER WEIGHTS
(byte) idx
(byte) idx#10 106.5
(byte) idx#11 28.0
(void()) main()
(void()) print((byte*) print::m)
(byte*) print::m
(byte*) print::m#2 101.0
Initial phi equivalence classes
[ print::m#2 ]
[ idx#10 idx#11 ]
Complete equivalence classes
[ print::m#2 ]
[ idx#10 idx#11 ]
Allocated zp[2]:2 [ print::m#2 ]
Allocated zp[1]:4 [ idx#10 idx#11 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Tests optimizing derefs of *(ptr+b) to ptr[b]
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label idx = 4
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [5] call print
// [9] phi from main to print [phi:main->print]
print_from_main:
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->print#0] -- vbuz1=vbuc1
lda #0
sta.z idx
// [9] phi (byte*) print::m#2 = (const byte*) msg1 [phi:main->print#1] -- pbuz1=pbuc1
lda #<msg1
sta.z print.m
lda #>msg1
sta.z print.m+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print
// [9] phi from main::@1 to print [phi:main::@1->print]
print_from___b1:
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->print#0] -- register_copy
// [9] phi (byte*) print::m#2 = (const byte*) msg2 [phi:main::@1->print#1] -- pbuz1=pbuc1
lda #<msg2
sta.z print.m
lda #>msg2
sta.z print.m+1
jsr print
jmp __breturn
// main::@return
__breturn:
// [8] return
rts
}
// print
// print(byte* zp(2) m)
print: {
.label m = 2
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2) -- pbuc1_derefidx_vbuz1=pbuz2_derefidx_vbuc2
ldx.z idx
ldy #2
lda (m),y
sta SCREEN,x
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuz1=_inc_vbuz1
inc.z idx
jmp __breturn
// print::@return
__breturn:
// [12] return
rts
}
// File Data
msg1: .byte 'a', 'b', 'c', 'd'
msg2: .byte '1', '2', '3', '4'
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2) [ idx#10 ] ( main:2::print:5 [ idx#10 ] { } main:2::print:7 [ idx#10 ] { { idx#10 = idx#11 } } ) always clobbers reg byte a reg byte y
Removing always clobbered register reg byte a as potential for zp[1]:4 [ idx#10 idx#11 ]
Removing always clobbered register reg byte y as potential for zp[1]:4 [ idx#10 idx#11 ]
Statement [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2) [ idx#10 ] ( main:2::print:5 [ idx#10 ] { } main:2::print:7 [ idx#10 ] { { idx#10 = idx#11 } } ) always clobbers reg byte a reg byte y
Potential registers zp[2]:2 [ print::m#2 ] : zp[2]:2 ,
Potential registers zp[1]:4 [ idx#10 idx#11 ] : zp[1]:4 , reg byte x ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 134.5: zp[1]:4 [ idx#10 idx#11 ]
Uplift Scope [print] 101: zp[2]:2 [ print::m#2 ]
Uplift Scope [main]
Uplifting [] best 81 combination reg byte x [ idx#10 idx#11 ]
Uplifting [print] best 81 combination zp[2]:2 [ print::m#2 ]
Uplifting [main] best 81 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Tests optimizing derefs of *(ptr+b) to ptr[b]
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from___b1:
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
// [5] call print
// [9] phi from main to print [phi:main->print]
print_from_main:
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->print#0] -- vbuxx=vbuc1
ldx #0
// [9] phi (byte*) print::m#2 = (const byte*) msg1 [phi:main->print#1] -- pbuz1=pbuc1
lda #<msg1
sta.z print.m
lda #>msg1
sta.z print.m+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print
// [9] phi from main::@1 to print [phi:main::@1->print]
print_from___b1:
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->print#0] -- register_copy
// [9] phi (byte*) print::m#2 = (const byte*) msg2 [phi:main::@1->print#1] -- pbuz1=pbuc1
lda #<msg2
sta.z print.m
lda #>msg2
sta.z print.m+1
jsr print
jmp __breturn
// main::@return
__breturn:
// [8] return
rts
}
// print
// print(byte* zp(2) m)
print: {
.label m = 2
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
ldy #2
lda (m),y
sta SCREEN,x
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuxx=_inc_vbuxx
inx
jmp __breturn
// print::@return
__breturn:
// [12] return
rts
}
// File Data
msg1: .byte 'a', 'b', 'c', 'd'
msg2: .byte '1', '2', '3', '4'
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from_main:
Removing instruction print_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bbegin:
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) SCREEN = (byte*) 1024
(byte) idx
(byte) idx#10 reg byte x 106.5
(byte) idx#11 reg byte x 28.0
(void()) main()
(label) main::@1
(label) main::@return
(const byte*) msg1[] = { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' }
(const byte*) msg2[] = { (byte) '1', (byte) '2', (byte) '3', (byte) '4' }
(void()) print((byte*) print::m)
(label) print::@return
(byte*) print::m
(byte*) print::m#2 m zp[2]:2 101.0
zp[2]:2 [ print::m#2 ]
reg byte x [ idx#10 idx#11 ]
FINAL ASSEMBLER
Score: 60
// File Comments
// Tests optimizing derefs of *(ptr+b) to ptr[b]
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @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
main: {
// print(msg1)
// [5] call print
// [9] phi from main to print [phi:main->print]
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->print#0] -- vbuxx=vbuc1
ldx #0
// [9] phi (byte*) print::m#2 = (const byte*) msg1 [phi:main->print#1] -- pbuz1=pbuc1
lda #<msg1
sta.z print.m
lda #>msg1
sta.z print.m+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
// main::@1
// print(msg2)
// [7] call print
// [9] phi from main::@1 to print [phi:main::@1->print]
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->print#0] -- register_copy
// [9] phi (byte*) print::m#2 = (const byte*) msg2 [phi:main::@1->print#1] -- pbuz1=pbuc1
lda #<msg2
sta.z print.m
lda #>msg2
sta.z print.m+1
jsr print
// main::@return
// }
// [8] return
rts
}
// print
// print(byte* zp(2) m)
print: {
.label m = 2
// SCREEN[idx++] = *(m+2)
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← *((byte*) print::m#2 + (byte) 2) -- pbuc1_derefidx_vbuxx=pbuz1_derefidx_vbuc2
ldy #2
lda (m),y
sta SCREEN,x
// SCREEN[idx++] = *(m+2);
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuxx=_inc_vbuxx
inx
// print::@return
// }
// [12] return
rts
}
// File Data
msg1: .byte 'a', 'b', 'c', 'd'
msg2: .byte '1', '2', '3', '4'