mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-29 09:29:31 +00:00
403 lines
13 KiB
Plaintext
403 lines
13 KiB
Plaintext
Inlined call call __init
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start::@1
|
|
idx#12 = phi( __start::@1/idx#11 )
|
|
main::c1#0 = 0
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@3
|
|
main::c1#4 = phi( main/main::c1#0, main::@3/main::c1#1 )
|
|
idx#9 = phi( main/idx#12, main::@3/idx#10 )
|
|
main::c2#0 = 0
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1 main::@2
|
|
main::c1#3 = phi( main::@1/main::c1#4, main::@2/main::c1#3 )
|
|
main::c2#2 = phi( main::@1/main::c2#0, main::@2/main::c2#1 )
|
|
idx#5 = phi( main::@1/idx#9, main::@2/idx#0 )
|
|
SCREEN[idx#5] = '*'
|
|
idx#0 = ++ idx#5
|
|
main::c2#1 = main::c2#2 + rangenext(0,$a)
|
|
main::$0 = main::c2#1 != rangelast(0,$a)
|
|
if(main::$0) goto main::@2
|
|
to:main::@3
|
|
main::@3: scope:[main] from main::@2
|
|
idx#10 = phi( main::@2/idx#0 )
|
|
main::c1#2 = phi( main::@2/main::c1#3 )
|
|
main::c1#1 = main::c1#2 + rangenext(0,$a)
|
|
main::$1 = main::c1#1 != rangelast(0,$a)
|
|
if(main::$1) goto main::@1
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@3
|
|
idx#6 = phi( main::@3/idx#10 )
|
|
idx#1 = idx#6
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
to:__start::__init1
|
|
__start::__init1: scope:[__start] from __start
|
|
idx#2 = 0
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start::__init1
|
|
idx#11 = phi( __start::__init1/idx#2 )
|
|
call main
|
|
to:__start::@2
|
|
__start::@2: scope:[__start] from __start::@1
|
|
idx#7 = phi( __start::@1/idx#1 )
|
|
idx#3 = idx#7
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@2
|
|
idx#8 = phi( __start::@2/idx#3 )
|
|
idx#4 = idx#8
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
__constant char * const SCREEN = (char *)$400
|
|
void __start()
|
|
char idx
|
|
char idx#0
|
|
char idx#1
|
|
char idx#10
|
|
char idx#11
|
|
char idx#12
|
|
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()
|
|
bool main::$0
|
|
bool main::$1
|
|
char main::c1
|
|
char main::c1#0
|
|
char main::c1#1
|
|
char main::c1#2
|
|
char main::c1#3
|
|
char main::c1#4
|
|
char main::c2
|
|
char main::c2#0
|
|
char main::c2#1
|
|
char main::c2#2
|
|
|
|
Simplifying constant pointer cast (char *) 1024
|
|
Successful SSA optimization PassNCastSimplification
|
|
Alias main::c1#2 = main::c1#3
|
|
Alias idx#0 = idx#10 idx#6 idx#1
|
|
Alias idx#11 = idx#2
|
|
Alias idx#3 = idx#7 idx#8 idx#4
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values idx#12 idx#11
|
|
Identical Phi Values main::c1#2 main::c1#4
|
|
Identical Phi Values idx#3 idx#0
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Simple Condition main::$0 [9] if(main::c2#1!=rangelast(0,$a)) goto main::@2
|
|
Simple Condition main::$1 [12] if(main::c1#1!=rangelast(0,$a)) goto main::@1
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant main::c1#0 = 0
|
|
Constant main::c2#0 = 0
|
|
Constant idx#11 = 0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Resolved ranged next value [7] main::c2#1 = ++ main::c2#2 to ++
|
|
Resolved ranged comparison value [9] if(main::c2#1!=rangelast(0,$a)) goto main::@2 to $b
|
|
Resolved ranged next value [10] main::c1#1 = ++ main::c1#4 to ++
|
|
Resolved ranged comparison value [12] if(main::c1#1!=rangelast(0,$a)) goto main::@1 to $b
|
|
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
|
|
Adding number conversion cast (unumber) $b in [5] if(main::c2#1!=$b) goto main::@2
|
|
Adding number conversion cast (unumber) $b in [7] if(main::c1#1!=$b) goto main::@1
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant integer cast $b
|
|
Simplifying constant integer cast $b
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) $b
|
|
Finalized unsigned number type (char) $b
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Inlining constant with var siblings main::c1#0
|
|
Inlining constant with var siblings main::c2#0
|
|
Inlining constant with var siblings idx#11
|
|
Constant inlined main::c1#0 = 0
|
|
Constant inlined main::c2#0 = 0
|
|
Constant inlined idx#11 = 0
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Added new block during phi lifting main::@4(between main::@3 and main::@1)
|
|
Added new block during phi lifting main::@5(between main::@2 and main::@2)
|
|
Adding NOP phi() at start of main
|
|
CALL GRAPH
|
|
|
|
Created 4 initial phi equivalence classes
|
|
Coalesced [2] idx#14 = idx#9
|
|
Coalesced [11] idx#13 = idx#0
|
|
Coalesced [12] main::c1#5 = main::c1#1
|
|
Coalesced (already) [13] idx#15 = idx#0
|
|
Coalesced [14] main::c2#3 = main::c2#1
|
|
Coalesced down to 3 phi equivalence classes
|
|
Culled Empty Block label main::@4
|
|
Culled Empty Block label main::@5
|
|
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::@3
|
|
[1] main::c1#4 = phi( main/0, main::@3/main::c1#1 )
|
|
[1] idx#9 = phi( main/0, main::@3/idx#0 )
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1 main::@2
|
|
[2] main::c2#2 = phi( main::@1/0, main::@2/main::c2#1 )
|
|
[2] idx#5 = phi( main::@1/idx#9, main::@2/idx#0 )
|
|
[3] SCREEN[idx#5] = '*'
|
|
[4] idx#0 = ++ idx#5
|
|
[5] main::c2#1 = ++ main::c2#2
|
|
[6] if(main::c2#1!=$b) goto main::@2
|
|
to:main::@3
|
|
main::@3: scope:[main] from main::@2
|
|
[7] main::c1#1 = ++ main::c1#4
|
|
[8] if(main::c1#1!=$b) goto main::@1
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@3
|
|
[9] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
char idx
|
|
char idx#0 // 42.599999999999994
|
|
char idx#5 // 157.0
|
|
char idx#9 // 22.0
|
|
void main()
|
|
char main::c1
|
|
char main::c1#1 // 16.5
|
|
char main::c1#4 // 3.6666666666666665
|
|
char main::c2
|
|
char main::c2#1 // 151.5
|
|
char main::c2#2 // 67.33333333333333
|
|
|
|
Initial phi equivalence classes
|
|
[ main::c1#4 main::c1#1 ]
|
|
[ idx#5 idx#9 idx#0 ]
|
|
[ main::c2#2 main::c2#1 ]
|
|
Complete equivalence classes
|
|
[ main::c1#4 main::c1#1 ]
|
|
[ idx#5 idx#9 idx#0 ]
|
|
[ main::c2#2 main::c2#1 ]
|
|
Allocated zp[1]:2 [ idx#5 idx#9 idx#0 ]
|
|
Allocated zp[1]:3 [ main::c2#2 main::c2#1 ]
|
|
Allocated zp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [3] SCREEN[idx#5] = '*' [ main::c1#4 idx#5 main::c2#2 ] ( [ main::c1#4 idx#5 main::c2#2 ] { } ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
Removing always clobbered register reg byte a as potential for zp[1]:2 [ idx#5 idx#9 idx#0 ]
|
|
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::c2#2 main::c2#1 ]
|
|
Statement [3] SCREEN[idx#5] = '*' [ main::c1#4 idx#5 main::c2#2 ] ( [ main::c1#4 idx#5 main::c2#2 ] { } ) always clobbers reg byte a
|
|
Potential registers zp[1]:4 [ main::c1#4 main::c1#1 ] : zp[1]:4 , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:2 [ idx#5 idx#9 idx#0 ] : zp[1]:2 , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:3 [ main::c2#2 main::c2#1 ] : zp[1]:3 , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [main] 218.83: zp[1]:3 [ main::c2#2 main::c2#1 ] 20.17: zp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
Uplift Scope [] 221.6: zp[1]:2 [ idx#5 idx#9 idx#0 ]
|
|
|
|
Uplifting [main] best 3571 combination reg byte x [ main::c2#2 main::c2#1 ] zp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
Uplifting [] best 2941 combination reg byte y [ idx#5 idx#9 idx#0 ]
|
|
Attempting to uplift remaining variables inzp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
Uplifting [main] best 2941 combination zp[1]:4 [ main::c1#4 main::c1#1 ]
|
|
Allocated (was zp[1]:4) zp[1]:2 [ main::c1#4 main::c1#1 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Test legal definition of multiple local variables with the same name
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="cstyle-decl-var-multiple.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
|
|
// And a little code using them
|
|
main: {
|
|
.label c1 = 2
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
// [1] phi main::c1#4 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
|
lda #0
|
|
sta.z c1
|
|
// [1] phi idx#9 = 0 [phi:main->main::@1#1] -- vbuyy=vbuc1
|
|
ldy #0
|
|
jmp __b1
|
|
// [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
|
|
__b1_from___b3:
|
|
// [1] phi main::c1#4 = main::c1#1 [phi:main::@3->main::@1#0] -- register_copy
|
|
// [1] phi idx#9 = idx#0 [phi:main::@3->main::@1#1] -- register_copy
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
__b2_from___b1:
|
|
// [2] phi main::c2#2 = 0 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [2] phi idx#5 = idx#9 [phi:main::@1->main::@2#1] -- register_copy
|
|
jmp __b2
|
|
// [2] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
|
|
__b2_from___b2:
|
|
// [2] phi main::c2#2 = main::c2#1 [phi:main::@2->main::@2#0] -- register_copy
|
|
// [2] phi idx#5 = idx#0 [phi:main::@2->main::@2#1] -- register_copy
|
|
jmp __b2
|
|
// main::@2
|
|
__b2:
|
|
// [3] SCREEN[idx#5] = '*' -- pbuc1_derefidx_vbuyy=vbuc2
|
|
lda #'*'
|
|
sta SCREEN,y
|
|
// [4] idx#0 = ++ idx#5 -- vbuyy=_inc_vbuyy
|
|
iny
|
|
// [5] main::c2#1 = ++ main::c2#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [6] if(main::c2#1!=$b) goto main::@2 -- vbuxx_neq_vbuc1_then_la1
|
|
cpx #$b
|
|
bne __b2_from___b2
|
|
jmp __b3
|
|
// main::@3
|
|
__b3:
|
|
// [7] main::c1#1 = ++ main::c1#4 -- vbuz1=_inc_vbuz1
|
|
inc.z c1
|
|
// [8] if(main::c1#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
|
lda #$b
|
|
cmp.z c1
|
|
bne __b1_from___b3
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [9] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __b2
|
|
Removing instruction jmp __b3
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Replacing instruction ldy #0 with TAY
|
|
Replacing label __b2_from___b2 with __b2
|
|
Replacing label __b1_from___b3 with __b1
|
|
Removing instruction __b1_from___b3:
|
|
Removing instruction __b2_from___b1:
|
|
Removing instruction __b2_from___b2:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction __b3:
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __b2
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
__constant char * const SCREEN = (char *) 1024
|
|
char idx
|
|
char idx#0 // reg byte y 42.599999999999994
|
|
char idx#5 // reg byte y 157.0
|
|
char idx#9 // reg byte y 22.0
|
|
void main()
|
|
char main::c1
|
|
char main::c1#1 // c1 zp[1]:2 16.5
|
|
char main::c1#4 // c1 zp[1]:2 3.6666666666666665
|
|
char main::c2
|
|
char main::c2#1 // reg byte x 151.5
|
|
char main::c2#2 // reg byte x 67.33333333333333
|
|
|
|
zp[1]:2 [ main::c1#4 main::c1#1 ]
|
|
reg byte y [ idx#5 idx#9 idx#0 ]
|
|
reg byte x [ main::c2#2 main::c2#1 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 1951
|
|
|
|
// File Comments
|
|
// Test legal definition of multiple local variables with the same name
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="cstyle-decl-var-multiple.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
|
|
// And a little code using them
|
|
main: {
|
|
.label c1 = 2
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
// [1] phi main::c1#4 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
|
lda #0
|
|
sta.z c1
|
|
// [1] phi idx#9 = 0 [phi:main->main::@1#1] -- vbuyy=vbuc1
|
|
tay
|
|
// [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
|
|
// [1] phi main::c1#4 = main::c1#1 [phi:main::@3->main::@1#0] -- register_copy
|
|
// [1] phi idx#9 = idx#0 [phi:main::@3->main::@1#1] -- register_copy
|
|
// main::@1
|
|
__b1:
|
|
// [2] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
// [2] phi main::c2#2 = 0 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [2] phi idx#5 = idx#9 [phi:main::@1->main::@2#1] -- register_copy
|
|
// [2] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
|
|
// [2] phi main::c2#2 = main::c2#1 [phi:main::@2->main::@2#0] -- register_copy
|
|
// [2] phi idx#5 = idx#0 [phi:main::@2->main::@2#1] -- register_copy
|
|
// main::@2
|
|
__b2:
|
|
// SCREEN[idx++] = '*'
|
|
// [3] SCREEN[idx#5] = '*' -- pbuc1_derefidx_vbuyy=vbuc2
|
|
lda #'*'
|
|
sta SCREEN,y
|
|
// SCREEN[idx++] = '*';
|
|
// [4] idx#0 = ++ idx#5 -- vbuyy=_inc_vbuyy
|
|
iny
|
|
// for( char c: 0..10)
|
|
// [5] main::c2#1 = ++ main::c2#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [6] if(main::c2#1!=$b) goto main::@2 -- vbuxx_neq_vbuc1_then_la1
|
|
cpx #$b
|
|
bne __b2
|
|
// main::@3
|
|
// [7] main::c1#1 = ++ main::c1#4 -- vbuz1=_inc_vbuz1
|
|
inc.z c1
|
|
// [8] if(main::c1#1!=$b) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
|
lda #$b
|
|
cmp.z c1
|
|
bne __b1
|
|
// main::@return
|
|
// }
|
|
// [9] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|