mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-10-21 17:24:39 +00:00
451 lines
12 KiB
Plaintext
451 lines
12 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) out::c#0 ← (byte) 'c'
|
|
call out
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
(byte) idx#7 ← phi( main/(byte) idx#5 )
|
|
(byte) idx#0 ← (byte) idx#7
|
|
(byte) out::c#1 ← (byte) 'm'
|
|
call out
|
|
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()) out((byte) out::c)
|
|
out: scope:[out] from main main::@1
|
|
(byte) idx#10 ← phi( main/(byte) idx#13 main::@1/(byte) idx#0 )
|
|
(byte) out::c#2 ← phi( main/(byte) out::c#0 main::@1/(byte) out::c#1 )
|
|
*((const nomodify byte*) SCREEN + (byte) idx#10) ← (byte) out::c#2
|
|
(byte) idx#4 ← ++ (byte) idx#10
|
|
to:out::@return
|
|
out::@return: scope:[out] from out
|
|
(byte) idx#11 ← phi( out/(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
|
|
(void()) out((byte) out::c)
|
|
(label) out::@return
|
|
(byte) out::c
|
|
(byte) out::c#0
|
|
(byte) out::c#1
|
|
(byte) out::c#2
|
|
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
Successful SSA optimization PassNCastSimplification
|
|
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) out::c#0 = 'c'
|
|
Constant (const byte) out::c#1 = 'm'
|
|
Constant (const byte) idx#14 = 0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Inlining constant with var siblings (const byte) out::c#0
|
|
Inlining constant with var siblings (const byte) out::c#1
|
|
Inlining constant with var siblings (const byte) idx#14
|
|
Constant inlined out::c#0 = (byte) 'c'
|
|
Constant inlined out::c#1 = (byte) 'm'
|
|
Constant inlined idx#14 = (byte) 0
|
|
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 out:7 out: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 out
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
[6] phi()
|
|
[7] call out
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[8] return
|
|
to:@return
|
|
|
|
(void()) out((byte) out::c)
|
|
out: scope:[out] from main main::@1
|
|
[9] (byte) idx#10 ← phi( main/(byte) 0 main::@1/(byte) idx#11 )
|
|
[9] (byte) out::c#2 ← phi( main/(byte) 'c' main::@1/(byte) 'm' )
|
|
[10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← (byte) out::c#2
|
|
[11] (byte) idx#11 ← ++ (byte) idx#10
|
|
to:out::@return
|
|
out::@return: scope:[out] from out
|
|
[12] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(byte) idx
|
|
(byte) idx#10 106.5
|
|
(byte) idx#11 28.0
|
|
(void()) main()
|
|
(void()) out((byte) out::c)
|
|
(byte) out::c
|
|
(byte) out::c#2 101.0
|
|
|
|
Initial phi equivalence classes
|
|
[ out::c#2 ]
|
|
[ idx#10 idx#11 ]
|
|
Complete equivalence classes
|
|
[ out::c#2 ]
|
|
[ idx#10 idx#11 ]
|
|
Allocated zp[1]:2 [ out::c#2 ]
|
|
Allocated zp[1]:3 [ idx#10 idx#11 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Test propagation of live ranges back over PHI-calls
|
|
// The idx-variable is alive between the two calls to out() - but not before the first call.
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label SCREEN = $400
|
|
.label idx = 3
|
|
// @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 out
|
|
// [9] phi from main to out [phi:main->out]
|
|
out_from_main:
|
|
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->out#0] -- vbuz1=vbuc1
|
|
lda #0
|
|
sta.z idx
|
|
// [9] phi (byte) out::c#2 = (byte) 'c' [phi:main->out#1] -- vbuz1=vbuc1
|
|
lda #'c'
|
|
sta.z out.c
|
|
jsr out
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call out
|
|
// [9] phi from main::@1 to out [phi:main::@1->out]
|
|
out_from___b1:
|
|
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->out#0] -- register_copy
|
|
// [9] phi (byte) out::c#2 = (byte) 'm' [phi:main::@1->out#1] -- vbuz1=vbuc1
|
|
lda #'m'
|
|
sta.z out.c
|
|
jsr out
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [8] return
|
|
rts
|
|
}
|
|
// out
|
|
// out(byte zp(2) c)
|
|
out: {
|
|
.label c = 2
|
|
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← (byte) out::c#2 -- pbuc1_derefidx_vbuz1=vbuz2
|
|
lda.z c
|
|
ldy.z idx
|
|
sta SCREEN,y
|
|
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuz1=_inc_vbuz1
|
|
inc.z idx
|
|
jmp __breturn
|
|
// out::@return
|
|
__breturn:
|
|
// [12] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Potential registers zp[1]:2 [ out::c#2 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:3 [ idx#10 idx#11 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [] 134.5: zp[1]:3 [ idx#10 idx#11 ]
|
|
Uplift Scope [out] 101: zp[1]:2 [ out::c#2 ]
|
|
Uplift Scope [main]
|
|
|
|
Uplifting [] best 67 combination reg byte x [ idx#10 idx#11 ]
|
|
Uplifting [out] best 58 combination reg byte a [ out::c#2 ]
|
|
Uplifting [main] best 58 combination
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Test propagation of live ranges back over PHI-calls
|
|
// The idx-variable is alive between the two calls to out() - but not before the first call.
|
|
// 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 out
|
|
// [9] phi from main to out [phi:main->out]
|
|
out_from_main:
|
|
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->out#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [9] phi (byte) out::c#2 = (byte) 'c' [phi:main->out#1] -- vbuaa=vbuc1
|
|
lda #'c'
|
|
jsr out
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call out
|
|
// [9] phi from main::@1 to out [phi:main::@1->out]
|
|
out_from___b1:
|
|
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->out#0] -- register_copy
|
|
// [9] phi (byte) out::c#2 = (byte) 'm' [phi:main::@1->out#1] -- vbuaa=vbuc1
|
|
lda #'m'
|
|
jsr out
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [8] return
|
|
rts
|
|
}
|
|
// out
|
|
// out(byte register(A) c)
|
|
out: {
|
|
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← (byte) out::c#2 -- pbuc1_derefidx_vbuxx=vbuaa
|
|
sta SCREEN,x
|
|
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
jmp __breturn
|
|
// out::@return
|
|
__breturn:
|
|
// [12] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
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 out_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bbegin:
|
|
Removing instruction __bend:
|
|
Removing instruction out_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
|
|
(void()) out((byte) out::c)
|
|
(label) out::@return
|
|
(byte) out::c
|
|
(byte) out::c#2 reg byte a 101.0
|
|
|
|
reg byte a [ out::c#2 ]
|
|
reg byte x [ idx#10 idx#11 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 37
|
|
|
|
// File Comments
|
|
// Test propagation of live ranges back over PHI-calls
|
|
// The idx-variable is alive between the two calls to out() - but not before the first call.
|
|
// 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: {
|
|
// out('c')
|
|
// [5] call out
|
|
// [9] phi from main to out [phi:main->out]
|
|
// [9] phi (byte) idx#10 = (byte) 0 [phi:main->out#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// [9] phi (byte) out::c#2 = (byte) 'c' [phi:main->out#1] -- vbuaa=vbuc1
|
|
lda #'c'
|
|
jsr out
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
// main::@1
|
|
// out('m')
|
|
// [7] call out
|
|
// [9] phi from main::@1 to out [phi:main::@1->out]
|
|
// [9] phi (byte) idx#10 = (byte) idx#11 [phi:main::@1->out#0] -- register_copy
|
|
// [9] phi (byte) out::c#2 = (byte) 'm' [phi:main::@1->out#1] -- vbuaa=vbuc1
|
|
lda #'m'
|
|
jsr out
|
|
// main::@return
|
|
// }
|
|
// [8] return
|
|
rts
|
|
}
|
|
// out
|
|
// out(byte register(A) c)
|
|
out: {
|
|
// SCREEN[idx++] = c
|
|
// [10] *((const nomodify byte*) SCREEN + (byte) idx#10) ← (byte) out::c#2 -- pbuc1_derefidx_vbuxx=vbuaa
|
|
sta SCREEN,x
|
|
// SCREEN[idx++] = c;
|
|
// [11] (byte) idx#11 ← ++ (byte) idx#10 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// out::@return
|
|
// }
|
|
// [12] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|