1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00
kickc/src/test/ref/call-parameter-autocast.log
2023-04-23 11:54:47 +02:00

445 lines
13 KiB
Plaintext

Inlined call call __init
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start::@1
idx#17 = phi( __start::@1/idx#18 )
print::w#0 = $1234
call print
to:main::@1
main::@1: scope:[main] from main
idx#9 = phi( main/idx#5 )
idx#0 = idx#9
print::w#1 = main::w
call print
to:main::@2
main::@2: scope:[main] from main::@1
idx#10 = phi( main::@1/idx#5 )
idx#1 = idx#10
print::w#2 = $12w=$34
call print
to:main::@3
main::@3: scope:[main] from main::@2
idx#11 = phi( main::@2/idx#5 )
idx#2 = idx#11
to:main::@return
main::@return: scope:[main] from main::@3
idx#12 = phi( main::@3/idx#2 )
idx#3 = idx#12
return
to:@return
void print(unsigned int w)
print: scope:[print] from main main::@1 main::@2
print::w#3 = phi( main/print::w#0, main::@1/print::w#1, main::@2/print::w#2 )
idx#13 = phi( main/idx#17, main::@1/idx#0, main::@2/idx#1 )
print::$0 = idx#13 * SIZEOF_UNSIGNED_INT
SCREEN[print::$0] = print::w#3
idx#4 = ++ idx#13
to:print::@return
print::@return: scope:[print] from print
idx#14 = phi( print/idx#4 )
idx#5 = idx#14
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
idx#6 = 0
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
idx#18 = phi( __start::__init1/idx#6 )
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
idx#15 = phi( __start::@1/idx#3 )
idx#7 = idx#15
to:__start::@return
__start::@return: scope:[__start] from __start::@2
idx#16 = phi( __start::@2/idx#7 )
idx#8 = idx#16
return
to:@return
SYMBOL TABLE SSA
__constant unsigned int * const SCREEN = (unsigned int *)$400
__constant char SIZEOF_UNSIGNED_INT = 2
void __start()
char idx
char idx#0
char idx#1
char idx#10
char idx#11
char idx#12
char idx#13
char idx#14
char idx#15
char idx#16
char idx#17
char idx#18
char idx#2
char idx#3
char idx#4
char idx#5
char idx#6
char idx#7
char idx#8
char idx#9
void main()
__constant unsigned int main::w = $1234
void print(unsigned int w)
char print::$0
unsigned int print::w
unsigned int print::w#0
unsigned int print::w#1
unsigned int print::w#2
unsigned int print::w#3
Adding number conversion cast (unumber) $1234 in print::w#0 = $1234
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast print::w#0 = (unumber)$1234
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (unsigned int *) 1024
Simplifying constant integer cast $1234
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (unsigned int) $1234
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias idx#0 = idx#9
Alias idx#1 = idx#10
Alias idx#11 = idx#2 idx#12 idx#3
Alias idx#14 = idx#4 idx#5
Alias idx#18 = idx#6
Alias idx#15 = idx#7 idx#16 idx#8
Successful SSA optimization Pass2AliasElimination
Identical Phi Values idx#17 idx#18
Identical Phi Values idx#0 idx#14
Identical Phi Values idx#1 idx#14
Identical Phi Values idx#11 idx#14
Identical Phi Values idx#15 idx#11
Successful SSA optimization Pass2IdenticalPhiElimination
Constant print::w#0 = $1234
Constant print::w#1 = main::w
Constant print::w#2 = $12w=$34
Constant idx#18 = 0
Successful SSA optimization Pass2ConstantIdentification
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Rewriting multiplication to use shift [5] print::$0 = idx#13 * SIZEOF_UNSIGNED_INT
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings print::w#0
Inlining constant with var siblings print::w#1
Inlining constant with var siblings print::w#2
Inlining constant with var siblings idx#18
Constant inlined idx#18 = 0
Constant inlined print::w#2 = $12w=$34
Constant inlined print::w#1 = main::w
Constant inlined print::w#0 = $1234
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant SIZEOF_UNSIGNED_INT
Successful SSA optimization PassNEliminateUnusedVars
Finalized unsigned number type (char) $12
Finalized unsigned number type (char) $34
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [main] to print:1 print:3 print:5
Created 2 initial phi equivalence classes
Coalesced [2] idx#19 = idx#14
Coalesced (already) [4] idx#20 = idx#14
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@3
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call print
to:main::@1
main::@1: scope:[main] from main
[2] phi()
[3] call print
to:main::@2
main::@2: scope:[main] from main::@1
[4] phi()
[5] call print
to:main::@return
main::@return: scope:[main] from main::@2
[6] return
to:@return
void print(unsigned int w)
print: scope:[print] from main main::@1 main::@2
[7] print::w#3 = phi( main/$1234, main::@1/main::w, main::@2/$12w=$34 )
[7] idx#13 = phi( main/0, main::@1/idx#14, main::@2/idx#14 )
[8] print::$0 = idx#13 << 1
[9] SCREEN[print::$0] = print::w#3
[10] idx#14 = ++ idx#13
to:print::@return
print::@return: scope:[print] from print
[11] return
to:@return
VARIABLE REGISTER WEIGHTS
char idx
char idx#13 // 8.666666666666666
char idx#14 // 2.5
void main()
void print(unsigned int w)
char print::$0 // 22.0
unsigned int print::w
unsigned int print::w#3 // 5.5
Initial phi equivalence classes
[ idx#13 idx#14 ]
[ print::w#3 ]
Added variable print::$0 to live range equivalence class [ print::$0 ]
Complete equivalence classes
[ idx#13 idx#14 ]
[ print::w#3 ]
[ print::$0 ]
Allocated zp[1]:2 [ print::$0 ]
Allocated zp[1]:3 [ idx#13 idx#14 ]
Allocated zp[2]:4 [ print::w#3 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [8] print::$0 = idx#13 << 1 [ idx#13 print::w#3 print::$0 ] ( print:1 [ idx#13 print::w#3 print::$0 ] { } print:3 [ idx#13 print::w#3 print::$0 ] { { idx#13 = idx#14 } } print:5 [ idx#13 print::w#3 print::$0 ] { { idx#13 = idx#14 } } ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:3 [ idx#13 idx#14 ]
Statement [9] SCREEN[print::$0] = print::w#3 [ idx#13 ] ( print:1 [ idx#13 ] { } print:3 [ idx#13 ] { { idx#13 = idx#14 } } print:5 [ idx#13 ] { { idx#13 = idx#14 } } ) always clobbers reg byte a
Statement [8] print::$0 = idx#13 << 1 [ idx#13 print::w#3 print::$0 ] ( print:1 [ idx#13 print::w#3 print::$0 ] { } print:3 [ idx#13 print::w#3 print::$0 ] { { idx#13 = idx#14 } } print:5 [ idx#13 print::w#3 print::$0 ] { { idx#13 = idx#14 } } ) always clobbers reg byte a
Statement [9] SCREEN[print::$0] = print::w#3 [ idx#13 ] ( print:1 [ idx#13 ] { } print:3 [ idx#13 ] { { idx#13 = idx#14 } } print:5 [ idx#13 ] { { idx#13 = idx#14 } } ) always clobbers reg byte a
Potential registers zp[1]:3 [ idx#13 idx#14 ] : zp[1]:3 , reg byte x , reg byte y ,
Potential registers zp[2]:4 [ print::w#3 ] : zp[2]:4 ,
Potential registers zp[1]:2 [ print::$0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [print] 22: zp[1]:2 [ print::$0 ] 5.5: zp[2]:4 [ print::w#3 ]
Uplift Scope [] 11.17: zp[1]:3 [ idx#13 idx#14 ]
Uplift Scope [main]
Uplifting [print] best 105 combination reg byte a [ print::$0 ] zp[2]:4 [ print::w#3 ]
Uplifting [] best 98 combination reg byte x [ idx#13 idx#14 ]
Uplifting [main] best 98 combination
Allocated (was zp[2]:4) zp[2]:2 [ print::w#3 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test auto-casting of call-parameters
// Upstart
// Commodore 64 PRG executable file
.file [name="call-parameter-autocast.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
.label SCREEN = $400
.segment Code
// main
main: {
.const w = $1234
// [1] call print
// [7] phi from main to print [phi:main->print]
print_from_main:
// [7] phi print::w#3 = $1234 [phi:main->print#0] -- vwuz1=vwuc1
lda #<$1234
sta.z print.w
lda #>$1234
sta.z print.w+1
// [7] phi idx#13 = 0 [phi:main->print#1] -- vbuxx=vbuc1
ldx #0
jsr print
// [2] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [3] call print
// [7] phi from main::@1 to print [phi:main::@1->print]
print_from___b1:
// [7] phi print::w#3 = main::w [phi:main::@1->print#0] -- vwuz1=vwuc1
lda #<w
sta.z print.w
lda #>w
sta.z print.w+1
// [7] phi idx#13 = idx#14 [phi:main::@1->print#1] -- register_copy
jsr print
// [4] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
jmp __b2
// main::@2
__b2:
// [5] call print
// [7] phi from main::@2 to print [phi:main::@2->print]
print_from___b2:
// [7] phi print::w#3 = $12w=$34 [phi:main::@2->print#0] -- vwuz1=vwuc1
lda #<$12*$100+$34
sta.z print.w
lda #>$12*$100+$34
sta.z print.w+1
// [7] phi idx#13 = idx#14 [phi:main::@2->print#1] -- register_copy
jsr print
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// print
// void print(__zp(2) unsigned int w)
print: {
.label w = 2
// [8] print::$0 = idx#13 << 1 -- vbuaa=vbuxx_rol_1
txa
asl
// [9] SCREEN[print::$0] = print::w#3 -- pwuc1_derefidx_vbuaa=vwuz1
tay
lda.z w
sta SCREEN,y
lda.z w+1
sta SCREEN+1,y
// [10] idx#14 = ++ idx#13 -- vbuxx=_inc_vbuxx
inx
jmp __breturn
// print::@return
__breturn:
// [11] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from_main:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
__constant unsigned int * const SCREEN = (unsigned int *) 1024
char idx
char idx#13 // reg byte x 8.666666666666666
char idx#14 // reg byte x 2.5
void main()
__constant unsigned int main::w = $1234
void print(unsigned int w)
char print::$0 // reg byte a 22.0
unsigned int print::w
unsigned int print::w#3 // w zp[2]:2 5.5
reg byte x [ idx#13 idx#14 ]
zp[2]:2 [ print::w#3 ]
reg byte a [ print::$0 ]
FINAL ASSEMBLER
Score: 86
// File Comments
// Test auto-casting of call-parameters
// Upstart
// Commodore 64 PRG executable file
.file [name="call-parameter-autocast.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
.label SCREEN = $400
.segment Code
// main
main: {
.const w = $1234
// print(0x1234)
// [1] call print
// [7] phi from main to print [phi:main->print]
// [7] phi print::w#3 = $1234 [phi:main->print#0] -- vwuz1=vwuc1
lda #<$1234
sta.z print.w
lda #>$1234
sta.z print.w+1
// [7] phi idx#13 = 0 [phi:main->print#1] -- vbuxx=vbuc1
ldx #0
jsr print
// [2] phi from main to main::@1 [phi:main->main::@1]
// main::@1
// print(w)
// [3] call print
// [7] phi from main::@1 to print [phi:main::@1->print]
// [7] phi print::w#3 = main::w [phi:main::@1->print#0] -- vwuz1=vwuc1
lda #<w
sta.z print.w
lda #>w
sta.z print.w+1
// [7] phi idx#13 = idx#14 [phi:main::@1->print#1] -- register_copy
jsr print
// [4] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
// main::@2
// print( MAKEWORD(0x12,0x34) )
// [5] call print
// [7] phi from main::@2 to print [phi:main::@2->print]
// [7] phi print::w#3 = $12w=$34 [phi:main::@2->print#0] -- vwuz1=vwuc1
lda #<$12*$100+$34
sta.z print.w
lda #>$12*$100+$34
sta.z print.w+1
// [7] phi idx#13 = idx#14 [phi:main::@2->print#1] -- register_copy
jsr print
// main::@return
// }
// [6] return
rts
}
// print
// void print(__zp(2) unsigned int w)
print: {
.label w = 2
// SCREEN[idx++] = w
// [8] print::$0 = idx#13 << 1 -- vbuaa=vbuxx_rol_1
txa
asl
// [9] SCREEN[print::$0] = print::w#3 -- pwuc1_derefidx_vbuaa=vwuz1
tay
lda.z w
sta SCREEN,y
lda.z w+1
sta SCREEN+1,y
// SCREEN[idx++] = w;
// [10] idx#14 = ++ idx#13 -- vbuxx=_inc_vbuxx
inx
// print::@return
// }
// [11] return
rts
}
// File Data