mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-03 07:29:37 +00:00
498 lines
15 KiB
Plaintext
498 lines
15 KiB
Plaintext
Inlined call call __init
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start::@1
|
|
screen#15 = phi( __start::@1/screen#17 )
|
|
line::x0#0 = 1
|
|
line::x1#0 = 2
|
|
call line
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
screen#8 = phi( main/screen#4 )
|
|
screen#0 = screen#8
|
|
line::x0#1 = 3
|
|
line::x1#1 = 5
|
|
call line
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
screen#9 = phi( main::@1/screen#4 )
|
|
screen#1 = screen#9
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@2
|
|
screen#10 = phi( main::@2/screen#1 )
|
|
screen#2 = screen#10
|
|
return
|
|
to:@return
|
|
|
|
void line(char x0 , char x1)
|
|
line: scope:[line] from main main::@1
|
|
screen#18 = phi( main/screen#15, main::@1/screen#0 )
|
|
line::x1#3 = phi( main/line::x1#0, main::@1/line::x1#1 )
|
|
line::x0#2 = phi( main/line::x0#0, main::@1/line::x0#1 )
|
|
line::x#0 = line::x0#2
|
|
to:line::@1
|
|
line::@1: scope:[line] from line line::@2
|
|
screen#16 = phi( line/screen#18, line::@2/screen#3 )
|
|
line::x1#2 = phi( line/line::x1#3, line::@2/line::x1#4 )
|
|
line::x#2 = phi( line/line::x#0, line::@2/line::x#1 )
|
|
line::$0 = line::x#2 < line::x1#2
|
|
if(line::$0) goto line::@2
|
|
to:line::@return
|
|
line::@2: scope:[line] from line::@1
|
|
line::x1#4 = phi( line::@1/line::x1#2 )
|
|
screen#11 = phi( line::@1/screen#16 )
|
|
line::x#3 = phi( line::@1/line::x#2 )
|
|
*screen#11 = line::x#3
|
|
screen#3 = ++ screen#11
|
|
line::x#1 = ++ line::x#3
|
|
to:line::@1
|
|
line::@return: scope:[line] from line::@1
|
|
screen#12 = phi( line::@1/screen#16 )
|
|
screen#4 = screen#12
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
to:__start::__init1
|
|
__start::__init1: scope:[__start] from __start
|
|
screen#5 = (char *)$400
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start::__init1
|
|
screen#17 = phi( __start::__init1/screen#5 )
|
|
call main
|
|
to:__start::@2
|
|
__start::@2: scope:[__start] from __start::@1
|
|
screen#13 = phi( __start::@1/screen#2 )
|
|
screen#6 = screen#13
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@2
|
|
screen#14 = phi( __start::@2/screen#6 )
|
|
screen#7 = screen#14
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
void __start()
|
|
void line(char x0 , char x1)
|
|
bool line::$0
|
|
char line::x
|
|
char line::x#0
|
|
char line::x#1
|
|
char line::x#2
|
|
char line::x#3
|
|
char line::x0
|
|
char line::x0#0
|
|
char line::x0#1
|
|
char line::x0#2
|
|
char line::x1
|
|
char line::x1#0
|
|
char line::x1#1
|
|
char line::x1#2
|
|
char line::x1#3
|
|
char line::x1#4
|
|
void main()
|
|
char *screen
|
|
char *screen#0
|
|
char *screen#1
|
|
char *screen#10
|
|
char *screen#11
|
|
char *screen#12
|
|
char *screen#13
|
|
char *screen#14
|
|
char *screen#15
|
|
char *screen#16
|
|
char *screen#17
|
|
char *screen#18
|
|
char *screen#2
|
|
char *screen#3
|
|
char *screen#4
|
|
char *screen#5
|
|
char *screen#6
|
|
char *screen#7
|
|
char *screen#8
|
|
char *screen#9
|
|
|
|
Adding number conversion cast (unumber) 1 in line::x0#0 = 1
|
|
Adding number conversion cast (unumber) 2 in line::x1#0 = 2
|
|
Adding number conversion cast (unumber) 3 in line::x0#1 = 3
|
|
Adding number conversion cast (unumber) 5 in line::x1#1 = 5
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Inlining cast line::x0#0 = (unumber)1
|
|
Inlining cast line::x1#0 = (unumber)2
|
|
Inlining cast line::x0#1 = (unumber)3
|
|
Inlining cast line::x1#1 = (unumber)5
|
|
Successful SSA optimization Pass2InlineCast
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 2
|
|
Simplifying constant integer cast 3
|
|
Simplifying constant integer cast 5
|
|
Simplifying constant pointer cast (char *) 1024
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) 1
|
|
Finalized unsigned number type (char) 2
|
|
Finalized unsigned number type (char) 3
|
|
Finalized unsigned number type (char) 5
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias screen#0 = screen#8
|
|
Alias screen#1 = screen#9 screen#10 screen#2
|
|
Alias line::x#0 = line::x0#2
|
|
Alias line::x#2 = line::x#3
|
|
Alias screen#11 = screen#16 screen#12 screen#4
|
|
Alias line::x1#2 = line::x1#4
|
|
Alias screen#17 = screen#5
|
|
Alias screen#13 = screen#6 screen#14 screen#7
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values screen#15 screen#17
|
|
Identical Phi Values screen#0 screen#11
|
|
Identical Phi Values screen#1 screen#11
|
|
Identical Phi Values line::x1#2 line::x1#3
|
|
Identical Phi Values screen#13 screen#1
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Simple Condition line::$0 [13] if(line::x#2<line::x1#3) goto line::@2
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant line::x0#0 = 1
|
|
Constant line::x1#0 = 2
|
|
Constant line::x0#1 = 3
|
|
Constant line::x1#1 = 5
|
|
Constant screen#17 = (char *) 1024
|
|
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
|
|
Inlining constant with different constant siblings line::x0#0
|
|
Inlining constant with var siblings line::x1#0
|
|
Inlining constant with different constant siblings line::x0#1
|
|
Inlining constant with var siblings line::x1#1
|
|
Inlining constant with var siblings screen#17
|
|
Constant inlined line::x0#0 = 1
|
|
Constant inlined line::x1#1 = 5
|
|
Constant inlined screen#17 = (char *) 1024
|
|
Constant inlined line::x1#0 = 2
|
|
Constant inlined line::x0#1 = 3
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Adding NOP phi() at start of main
|
|
Adding NOP phi() at start of main::@2
|
|
CALL GRAPH
|
|
Calls in [main] to line:1 line:3
|
|
|
|
Created 5 initial phi equivalence classes
|
|
Coalesced [2] screen#19 = screen#11
|
|
Coalesced [7] line::x#4 = line::x#0
|
|
Coalesced (already) [8] screen#20 = screen#18
|
|
Coalesced [15] line::x#5 = line::x#1
|
|
Coalesced [16] screen#21 = screen#3
|
|
Coalesced down to 3 phi equivalence classes
|
|
Culled Empty Block label main::@2
|
|
Adding NOP phi() at start of main
|
|
Adding NOP phi() at start of main::@1
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
void main()
|
|
main: scope:[main] from
|
|
[0] phi()
|
|
[1] call line
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
[2] phi()
|
|
[3] call line
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[4] return
|
|
to:@return
|
|
|
|
void line(char x0 , char x1)
|
|
line: scope:[line] from main main::@1
|
|
[5] screen#18 = phi( main/(char *) 1024, main::@1/screen#11 )
|
|
[5] line::x1#3 = phi( main/2, main::@1/5 )
|
|
[5] line::x#0 = phi( main/1, main::@1/3 )
|
|
to:line::@1
|
|
line::@1: scope:[line] from line line::@2
|
|
[6] screen#11 = phi( line/screen#18, line::@2/screen#3 )
|
|
[6] line::x#2 = phi( line/line::x#0, line::@2/line::x#1 )
|
|
[7] if(line::x#2<line::x1#3) goto line::@2
|
|
to:line::@return
|
|
line::@return: scope:[line] from line::@1
|
|
[8] return
|
|
to:@return
|
|
line::@2: scope:[line] from line::@1
|
|
[9] *screen#11 = line::x#2
|
|
[10] screen#3 = ++ screen#11
|
|
[11] line::x#1 = ++ line::x#2
|
|
to:line::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
void line(char x0 , char x1)
|
|
char line::x
|
|
char line::x#0 // 11.0
|
|
char line::x#1 // 202.0
|
|
char line::x#2 // 103.75
|
|
char line::x0
|
|
char line::x1
|
|
char line::x1#3 // 16.833333333333332
|
|
void main()
|
|
char *screen
|
|
char *screen#11 // 52.66666666666666
|
|
char *screen#18 // 13.0
|
|
char *screen#3 // 101.0
|
|
|
|
Initial phi equivalence classes
|
|
[ line::x1#3 ]
|
|
[ screen#18 screen#11 screen#3 ]
|
|
[ line::x#2 line::x#0 line::x#1 ]
|
|
Complete equivalence classes
|
|
[ line::x1#3 ]
|
|
[ screen#18 screen#11 screen#3 ]
|
|
[ line::x#2 line::x#0 line::x#1 ]
|
|
Allocated zp[1]:2 [ line::x#2 line::x#0 line::x#1 ]
|
|
Allocated zp[2]:3 [ screen#18 screen#11 screen#3 ]
|
|
Allocated zp[1]:5 [ line::x1#3 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [9] *screen#11 = line::x#2 [ line::x1#3 screen#11 line::x#2 ] ( line:1 [ line::x1#3 screen#11 line::x#2 ] { } line:3 [ line::x1#3 screen#11 line::x#2 ] { { screen#11 = screen#18 } } ) always clobbers reg byte y
|
|
Removing always clobbered register reg byte y as potential for zp[1]:5 [ line::x1#3 ]
|
|
Removing always clobbered register reg byte y as potential for zp[1]:2 [ line::x#2 line::x#0 line::x#1 ]
|
|
Statement [9] *screen#11 = line::x#2 [ line::x1#3 screen#11 line::x#2 ] ( line:1 [ line::x1#3 screen#11 line::x#2 ] { } line:3 [ line::x1#3 screen#11 line::x#2 ] { { screen#11 = screen#18 } } ) always clobbers reg byte y
|
|
Potential registers zp[1]:5 [ line::x1#3 ] : zp[1]:5 , reg byte a , reg byte x ,
|
|
Potential registers zp[2]:3 [ screen#18 screen#11 screen#3 ] : zp[2]:3 ,
|
|
Potential registers zp[1]:2 [ line::x#2 line::x#0 line::x#1 ] : zp[1]:2 , reg byte a , reg byte x ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [line] 316.75: zp[1]:2 [ line::x#2 line::x#0 line::x#1 ] 16.83: zp[1]:5 [ line::x1#3 ]
|
|
Uplift Scope [] 166.67: zp[2]:3 [ screen#18 screen#11 screen#3 ]
|
|
Uplift Scope [main]
|
|
|
|
Uplifting [line] best 444 combination reg byte x [ line::x#2 line::x#0 line::x#1 ] zp[1]:5 [ line::x1#3 ]
|
|
Uplifting [] best 444 combination zp[2]:3 [ screen#18 screen#11 screen#3 ]
|
|
Uplifting [main] best 444 combination
|
|
Attempting to uplift remaining variables inzp[1]:5 [ line::x1#3 ]
|
|
Uplifting [line] best 444 combination zp[1]:5 [ line::x1#3 ]
|
|
Allocated (was zp[2]:3) zp[2]:2 [ screen#18 screen#11 screen#3 ]
|
|
Allocated (was zp[1]:5) zp[1]:4 [ line::x1#3 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Multiple calls with different (constant?) parameters should yield different values at runtime
|
|
// Currently the same constant parameter is passed on every call.
|
|
// Reason: Multiple versioned parameter constants x0#0, x0#1 are only output as a single constant in the ASM .const x0 = 0
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="callconstparam.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 = 2
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
// [1] call line
|
|
// [5] phi from main to line [phi:main->line]
|
|
line_from_main:
|
|
// [5] phi screen#18 = (char *) 1024 [phi:main->line#0] -- pbuz1=pbuc1
|
|
lda #<$400
|
|
sta.z screen
|
|
lda #>$400
|
|
sta.z screen+1
|
|
// [5] phi line::x1#3 = 2 [phi:main->line#1] -- vbuz1=vbuc1
|
|
lda #2
|
|
sta.z line.x1
|
|
// [5] phi line::x#0 = 1 [phi:main->line#2] -- vbuxx=vbuc1
|
|
ldx #1
|
|
jsr line
|
|
// [2] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [3] call line
|
|
// [5] phi from main::@1 to line [phi:main::@1->line]
|
|
line_from___b1:
|
|
// [5] phi screen#18 = screen#11 [phi:main::@1->line#0] -- register_copy
|
|
// [5] phi line::x1#3 = 5 [phi:main::@1->line#1] -- vbuz1=vbuc1
|
|
lda #5
|
|
sta.z line.x1
|
|
// [5] phi line::x#0 = 3 [phi:main::@1->line#2] -- vbuxx=vbuc1
|
|
ldx #3
|
|
jsr line
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [4] return
|
|
rts
|
|
}
|
|
// line
|
|
// void line(char x0, __zp(4) char x1)
|
|
line: {
|
|
.label x1 = 4
|
|
// [6] phi from line line::@2 to line::@1 [phi:line/line::@2->line::@1]
|
|
__b1_from_line:
|
|
__b1_from___b2:
|
|
// [6] phi screen#11 = screen#18 [phi:line/line::@2->line::@1#0] -- register_copy
|
|
// [6] phi line::x#2 = line::x#0 [phi:line/line::@2->line::@1#1] -- register_copy
|
|
jmp __b1
|
|
// line::@1
|
|
__b1:
|
|
// [7] if(line::x#2<line::x1#3) goto line::@2 -- vbuxx_lt_vbuz1_then_la1
|
|
cpx.z x1
|
|
bcc __b2
|
|
jmp __breturn
|
|
// line::@return
|
|
__breturn:
|
|
// [8] return
|
|
rts
|
|
// line::@2
|
|
__b2:
|
|
// [9] *screen#11 = line::x#2 -- _deref_pbuz1=vbuxx
|
|
txa
|
|
ldy #0
|
|
sta (screen),y
|
|
// [10] screen#3 = ++ screen#11 -- pbuz1=_inc_pbuz1
|
|
inc.z screen
|
|
bne !+
|
|
inc.z screen+1
|
|
!:
|
|
// [11] line::x#1 = ++ line::x#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
jmp __b1_from___b2
|
|
}
|
|
// File Data
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Replacing label __b1_from___b2 with __b1
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction line_from___b1:
|
|
Removing instruction __b1_from_line:
|
|
Removing instruction __b1_from___b2:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction line_from_main:
|
|
Removing instruction __b1:
|
|
Removing instruction __breturn:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
void line(char x0 , char x1)
|
|
char line::x
|
|
char line::x#0 // reg byte x 11.0
|
|
char line::x#1 // reg byte x 202.0
|
|
char line::x#2 // reg byte x 103.75
|
|
char line::x0
|
|
char line::x1
|
|
char line::x1#3 // x1 zp[1]:4 16.833333333333332
|
|
void main()
|
|
char *screen
|
|
char *screen#11 // screen zp[2]:2 52.66666666666666
|
|
char *screen#18 // screen zp[2]:2 13.0
|
|
char *screen#3 // screen zp[2]:2 101.0
|
|
|
|
zp[1]:4 [ line::x1#3 ]
|
|
zp[2]:2 [ screen#18 screen#11 screen#3 ]
|
|
reg byte x [ line::x#2 line::x#0 line::x#1 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 378
|
|
|
|
// File Comments
|
|
// Multiple calls with different (constant?) parameters should yield different values at runtime
|
|
// Currently the same constant parameter is passed on every call.
|
|
// Reason: Multiple versioned parameter constants x0#0, x0#1 are only output as a single constant in the ASM .const x0 = 0
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="callconstparam.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 = 2
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
// line(1,2)
|
|
// [1] call line
|
|
// [5] phi from main to line [phi:main->line]
|
|
// [5] phi screen#18 = (char *) 1024 [phi:main->line#0] -- pbuz1=pbuc1
|
|
lda #<$400
|
|
sta.z screen
|
|
lda #>$400
|
|
sta.z screen+1
|
|
// [5] phi line::x1#3 = 2 [phi:main->line#1] -- vbuz1=vbuc1
|
|
lda #2
|
|
sta.z line.x1
|
|
// [5] phi line::x#0 = 1 [phi:main->line#2] -- vbuxx=vbuc1
|
|
ldx #1
|
|
jsr line
|
|
// [2] phi from main to main::@1 [phi:main->main::@1]
|
|
// main::@1
|
|
// line(3,5)
|
|
// [3] call line
|
|
// [5] phi from main::@1 to line [phi:main::@1->line]
|
|
// [5] phi screen#18 = screen#11 [phi:main::@1->line#0] -- register_copy
|
|
// [5] phi line::x1#3 = 5 [phi:main::@1->line#1] -- vbuz1=vbuc1
|
|
lda #5
|
|
sta.z line.x1
|
|
// [5] phi line::x#0 = 3 [phi:main::@1->line#2] -- vbuxx=vbuc1
|
|
ldx #3
|
|
jsr line
|
|
// main::@return
|
|
// }
|
|
// [4] return
|
|
rts
|
|
}
|
|
// line
|
|
// void line(char x0, __zp(4) char x1)
|
|
line: {
|
|
.label x1 = 4
|
|
// [6] phi from line line::@2 to line::@1 [phi:line/line::@2->line::@1]
|
|
// [6] phi screen#11 = screen#18 [phi:line/line::@2->line::@1#0] -- register_copy
|
|
// [6] phi line::x#2 = line::x#0 [phi:line/line::@2->line::@1#1] -- register_copy
|
|
// line::@1
|
|
__b1:
|
|
// for(byte x = x0; x<x1; x++)
|
|
// [7] if(line::x#2<line::x1#3) goto line::@2 -- vbuxx_lt_vbuz1_then_la1
|
|
cpx.z x1
|
|
bcc __b2
|
|
// line::@return
|
|
// }
|
|
// [8] return
|
|
rts
|
|
// line::@2
|
|
__b2:
|
|
// *screen = x
|
|
// [9] *screen#11 = line::x#2 -- _deref_pbuz1=vbuxx
|
|
txa
|
|
ldy #0
|
|
sta (screen),y
|
|
// screen++;
|
|
// [10] screen#3 = ++ screen#11 -- pbuz1=_inc_pbuz1
|
|
inc.z screen
|
|
bne !+
|
|
inc.z screen+1
|
|
!:
|
|
// for(byte x = x0; x<x1; x++)
|
|
// [11] line::x#1 = ++ line::x#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
|