mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-10-21 17:24:39 +00:00
436 lines
15 KiB
Plaintext
436 lines
15 KiB
Plaintext
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
to:@1
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
(number~) main::$4 ← (number) 1 * (const byte) SIZEOF_WORD
|
|
(word) main::w1#0 ← *((const word*) main::words + (number~) main::$4)
|
|
(byte~) main::$0 ← < (word) main::w1#0
|
|
*((const nomodify byte*) main::SCREEN + (number) 0) ← (byte~) main::$0
|
|
(byte~) main::$1 ← > (word) main::w1#0
|
|
*((const nomodify byte*) main::SCREEN + (number) 1) ← (byte~) main::$1
|
|
(number~) main::$5 ← (number) 2 * (const byte) SIZEOF_WORD
|
|
(word) main::w2#0 ← *((const word*) main::words + (number~) main::$5)
|
|
(byte~) main::$2 ← < (word) main::w2#0
|
|
*((const nomodify byte*) main::SCREEN + (number) 2) ← (byte~) main::$2
|
|
(byte~) main::$3 ← > (word) main::w2#0
|
|
*((const nomodify byte*) main::SCREEN + (number) 3) ← (byte~) main::$3
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
return
|
|
to:@return
|
|
@1: scope:[] from @begin
|
|
call main
|
|
to:@2
|
|
@2: scope:[] from @1
|
|
to:@end
|
|
@end: scope:[] from @2
|
|
|
|
SYMBOL TABLE SSA
|
|
(label) @1
|
|
(label) @2
|
|
(label) @begin
|
|
(label) @end
|
|
(const byte) SIZEOF_WORD = (byte) 2
|
|
(void()) main()
|
|
(byte~) main::$0
|
|
(byte~) main::$1
|
|
(byte~) main::$2
|
|
(byte~) main::$3
|
|
(number~) main::$4
|
|
(number~) main::$5
|
|
(label) main::@return
|
|
(const nomodify byte*) main::SCREEN = (byte*)(number) $400+(number) 6*(number) $28
|
|
(word) main::w1
|
|
(word) main::w1#0
|
|
(word) main::w2
|
|
(word) main::w2#0
|
|
(const word*) main::words[(number) 3] = (word*)(number) $400
|
|
|
|
Adding number conversion cast (unumber) 1 in (number~) main::$4 ← (number) 1 * (const byte) SIZEOF_WORD
|
|
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (unumber)(number) 1 * (const byte) SIZEOF_WORD
|
|
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) main::SCREEN + (number) 0) ← (byte~) main::$0
|
|
Adding number conversion cast (unumber) 1 in *((const nomodify byte*) main::SCREEN + (number) 1) ← (byte~) main::$1
|
|
Adding number conversion cast (unumber) 2 in (number~) main::$5 ← (number) 2 * (const byte) SIZEOF_WORD
|
|
Adding number conversion cast (unumber) main::$5 in (number~) main::$5 ← (unumber)(number) 2 * (const byte) SIZEOF_WORD
|
|
Adding number conversion cast (unumber) 2 in *((const nomodify byte*) main::SCREEN + (number) 2) ← (byte~) main::$2
|
|
Adding number conversion cast (unumber) 3 in *((const nomodify byte*) main::SCREEN + (number) 3) ← (byte~) main::$3
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (word*) 1024
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 2
|
|
Simplifying constant integer cast 2
|
|
Simplifying constant integer cast 3
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 1
|
|
Finalized unsigned number type (byte) 0
|
|
Finalized unsigned number type (byte) 1
|
|
Finalized unsigned number type (byte) 2
|
|
Finalized unsigned number type (byte) 2
|
|
Finalized unsigned number type (byte) 3
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Inferred type updated to byte in (unumber~) main::$4 ← (byte) 1 * (const byte) SIZEOF_WORD
|
|
Inferred type updated to byte in (unumber~) main::$5 ← (byte) 2 * (const byte) SIZEOF_WORD
|
|
Constant right-side identified [0] (byte~) main::$4 ← (byte) 1 * (const byte) SIZEOF_WORD
|
|
Constant right-side identified [6] (byte~) main::$5 ← (byte) 2 * (const byte) SIZEOF_WORD
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant (const byte) main::$4 = 1*SIZEOF_WORD
|
|
Constant (const byte) main::$5 = 2*SIZEOF_WORD
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Simplifying expression containing zero main::SCREEN in [3] *((const nomodify byte*) main::SCREEN + (byte) 0) ← (byte~) main::$0
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Constant inlined main::$5 = (byte) 2*(const byte) SIZEOF_WORD
|
|
Constant inlined main::$4 = (byte) 1*(const byte) SIZEOF_WORD
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Consolidated array index constant in *(main::words+1*SIZEOF_WORD)
|
|
Consolidated array index constant in *(main::SCREEN+1)
|
|
Consolidated array index constant in *(main::words+2*SIZEOF_WORD)
|
|
Consolidated array index constant in *(main::SCREEN+2)
|
|
Consolidated array index constant in *(main::SCREEN+3)
|
|
Successful SSA optimization Pass2ConstantAdditionElimination
|
|
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 @end
|
|
CALL GRAPH
|
|
Calls in [] to main:2
|
|
|
|
Created 0 initial phi equivalence classes
|
|
Coalesced down to 0 phi equivalence classes
|
|
Culled Empty Block (label) @2
|
|
Adding NOP phi() at start of @begin
|
|
Adding NOP phi() at start of @1
|
|
Adding NOP phi() at start of @end
|
|
|
|
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] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD)
|
|
[5] (byte~) main::$0 ← < (word) main::w1#0
|
|
[6] *((const nomodify byte*) main::SCREEN) ← (byte~) main::$0
|
|
[7] (byte~) main::$1 ← > (word) main::w1#0
|
|
[8] *((const nomodify byte*) main::SCREEN+(byte) 1) ← (byte~) main::$1
|
|
[9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD)
|
|
[10] (byte~) main::$2 ← < (word) main::w2#0
|
|
[11] *((const nomodify byte*) main::SCREEN+(byte) 2) ← (byte~) main::$2
|
|
[12] (byte~) main::$3 ← > (word) main::w2#0
|
|
[13] *((const nomodify byte*) main::SCREEN+(byte) 3) ← (byte~) main::$3
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
[14] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(void()) main()
|
|
(byte~) main::$0 22.0
|
|
(byte~) main::$1 22.0
|
|
(byte~) main::$2 22.0
|
|
(byte~) main::$3 22.0
|
|
(word) main::w1
|
|
(word) main::w1#0 11.0
|
|
(word) main::w2
|
|
(word) main::w2#0 11.0
|
|
|
|
Initial phi equivalence classes
|
|
Added variable main::w1#0 to live range equivalence class [ main::w1#0 ]
|
|
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
|
Added variable main::$1 to live range equivalence class [ main::$1 ]
|
|
Added variable main::w2#0 to live range equivalence class [ main::w2#0 ]
|
|
Added variable main::$2 to live range equivalence class [ main::$2 ]
|
|
Added variable main::$3 to live range equivalence class [ main::$3 ]
|
|
Complete equivalence classes
|
|
[ main::w1#0 ]
|
|
[ main::$0 ]
|
|
[ main::$1 ]
|
|
[ main::w2#0 ]
|
|
[ main::$2 ]
|
|
[ main::$3 ]
|
|
Allocated zp[2]:2 [ main::w1#0 ]
|
|
Allocated zp[1]:4 [ main::$0 ]
|
|
Allocated zp[1]:5 [ main::$1 ]
|
|
Allocated zp[2]:6 [ main::w2#0 ]
|
|
Allocated zp[1]:8 [ main::$2 ]
|
|
Allocated zp[1]:9 [ main::$3 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Tests a simple word array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_WORD = 2
|
|
// @begin
|
|
__bbegin:
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
__b1_from___bbegin:
|
|
jmp __b1
|
|
// @1
|
|
__b1:
|
|
// [2] call main
|
|
jsr main
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
__bend_from___b1:
|
|
jmp __bend
|
|
// @end
|
|
__bend:
|
|
// main
|
|
main: {
|
|
.label SCREEN = $400+6*$28
|
|
.label words = $400
|
|
.label __0 = 4
|
|
.label __1 = 5
|
|
.label __2 = 8
|
|
.label __3 = 9
|
|
.label w1 = 2
|
|
.label w2 = 6
|
|
// [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+1*SIZEOF_WORD
|
|
sta.z w1
|
|
lda words+1*SIZEOF_WORD+1
|
|
sta.z w1+1
|
|
// [5] (byte~) main::$0 ← < (word) main::w1#0 -- vbuz1=_lo_vwuz2
|
|
lda.z w1
|
|
sta.z __0
|
|
// [6] *((const nomodify byte*) main::SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuz1
|
|
lda.z __0
|
|
sta SCREEN
|
|
// [7] (byte~) main::$1 ← > (word) main::w1#0 -- vbuz1=_hi_vwuz2
|
|
lda.z w1+1
|
|
sta.z __1
|
|
// [8] *((const nomodify byte*) main::SCREEN+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuz1
|
|
lda.z __1
|
|
sta SCREEN+1
|
|
// [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+2*SIZEOF_WORD
|
|
sta.z w2
|
|
lda words+2*SIZEOF_WORD+1
|
|
sta.z w2+1
|
|
// [10] (byte~) main::$2 ← < (word) main::w2#0 -- vbuz1=_lo_vwuz2
|
|
lda.z w2
|
|
sta.z __2
|
|
// [11] *((const nomodify byte*) main::SCREEN+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuz1
|
|
lda.z __2
|
|
sta SCREEN+2
|
|
// [12] (byte~) main::$3 ← > (word) main::w2#0 -- vbuz1=_hi_vwuz2
|
|
lda.z w2+1
|
|
sta.z __3
|
|
// [13] *((const nomodify byte*) main::SCREEN+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuz1
|
|
lda.z __3
|
|
sta SCREEN+3
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [14] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) [ main::w1#0 ] ( main:2 [ main::w1#0 ] { } ) always clobbers reg byte a
|
|
Statement [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) [ main::w2#0 ] ( main:2 [ main::w2#0 ] { } ) always clobbers reg byte a
|
|
Potential registers zp[2]:2 [ main::w1#0 ] : zp[2]:2 ,
|
|
Potential registers zp[1]:4 [ main::$0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:5 [ main::$1 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[2]:6 [ main::w2#0 ] : zp[2]:6 ,
|
|
Potential registers zp[1]:8 [ main::$2 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y ,
|
|
Potential registers zp[1]:9 [ main::$3 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [main] 22: zp[1]:4 [ main::$0 ] 22: zp[1]:5 [ main::$1 ] 22: zp[1]:8 [ main::$2 ] 22: zp[1]:9 [ main::$3 ] 11: zp[2]:2 [ main::w1#0 ] 11: zp[2]:6 [ main::w2#0 ]
|
|
Uplift Scope []
|
|
|
|
Uplifting [main] best 77 combination reg byte a [ main::$0 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$3 ] zp[2]:2 [ main::w1#0 ] zp[2]:6 [ main::w2#0 ]
|
|
Limited combination testing to 100 combinations of 256 possible.
|
|
Uplifting [] best 77 combination
|
|
Allocated (was zp[2]:6) zp[2]:4 [ main::w2#0 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Tests a simple word array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_WORD = 2
|
|
// @begin
|
|
__bbegin:
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
__b1_from___bbegin:
|
|
jmp __b1
|
|
// @1
|
|
__b1:
|
|
// [2] call main
|
|
jsr main
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
__bend_from___b1:
|
|
jmp __bend
|
|
// @end
|
|
__bend:
|
|
// main
|
|
main: {
|
|
.label SCREEN = $400+6*$28
|
|
.label words = $400
|
|
.label w1 = 2
|
|
.label w2 = 4
|
|
// [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+1*SIZEOF_WORD
|
|
sta.z w1
|
|
lda words+1*SIZEOF_WORD+1
|
|
sta.z w1+1
|
|
// [5] (byte~) main::$0 ← < (word) main::w1#0 -- vbuaa=_lo_vwuz1
|
|
lda.z w1
|
|
// [6] *((const nomodify byte*) main::SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN
|
|
// [7] (byte~) main::$1 ← > (word) main::w1#0 -- vbuaa=_hi_vwuz1
|
|
lda.z w1+1
|
|
// [8] *((const nomodify byte*) main::SCREEN+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+1
|
|
// [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+2*SIZEOF_WORD
|
|
sta.z w2
|
|
lda words+2*SIZEOF_WORD+1
|
|
sta.z w2+1
|
|
// [10] (byte~) main::$2 ← < (word) main::w2#0 -- vbuaa=_lo_vwuz1
|
|
lda.z w2
|
|
// [11] *((const nomodify byte*) main::SCREEN+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+2
|
|
// [12] (byte~) main::$3 ← > (word) main::w2#0 -- vbuaa=_hi_vwuz1
|
|
lda.z w2+1
|
|
// [13] *((const nomodify byte*) main::SCREEN+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+3
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [14] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction __b1_from___bbegin:
|
|
Removing instruction __b1:
|
|
Removing instruction __bend_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bbegin:
|
|
Removing instruction __bend:
|
|
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 byte) SIZEOF_WORD = (byte) 2
|
|
(void()) main()
|
|
(byte~) main::$0 reg byte a 22.0
|
|
(byte~) main::$1 reg byte a 22.0
|
|
(byte~) main::$2 reg byte a 22.0
|
|
(byte~) main::$3 reg byte a 22.0
|
|
(label) main::@return
|
|
(const nomodify byte*) main::SCREEN = (byte*)(number) $400+(number) 6*(number) $28
|
|
(word) main::w1
|
|
(word) main::w1#0 w1 zp[2]:2 11.0
|
|
(word) main::w2
|
|
(word) main::w2#0 w2 zp[2]:4 11.0
|
|
(const word*) main::words[(number) 3] = (word*) 1024
|
|
|
|
zp[2]:2 [ main::w1#0 ]
|
|
reg byte a [ main::$0 ]
|
|
reg byte a [ main::$1 ]
|
|
zp[2]:4 [ main::w2#0 ]
|
|
reg byte a [ main::$2 ]
|
|
reg byte a [ main::$3 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 62
|
|
|
|
// File Comments
|
|
// Tests a simple word array
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const SIZEOF_WORD = 2
|
|
// @begin
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
|
// @1
|
|
// [2] call main
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
|
// @end
|
|
// main
|
|
main: {
|
|
.label SCREEN = $400+6*$28
|
|
.label words = $400
|
|
.label w1 = 2
|
|
.label w2 = 4
|
|
// w1 = words[1]
|
|
// [4] (word) main::w1#0 ← *((const word*) main::words+(byte) 1*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+1*SIZEOF_WORD
|
|
sta.z w1
|
|
lda words+1*SIZEOF_WORD+1
|
|
sta.z w1+1
|
|
// <w1
|
|
// [5] (byte~) main::$0 ← < (word) main::w1#0 -- vbuaa=_lo_vwuz1
|
|
lda.z w1
|
|
// SCREEN[0] = <w1
|
|
// [6] *((const nomodify byte*) main::SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN
|
|
// >w1
|
|
// [7] (byte~) main::$1 ← > (word) main::w1#0 -- vbuaa=_hi_vwuz1
|
|
lda.z w1+1
|
|
// SCREEN[1] = >w1
|
|
// [8] *((const nomodify byte*) main::SCREEN+(byte) 1) ← (byte~) main::$1 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+1
|
|
// w2 = words[2]
|
|
// [9] (word) main::w2#0 ← *((const word*) main::words+(byte) 2*(const byte) SIZEOF_WORD) -- vwuz1=_deref_pwuc1
|
|
lda words+2*SIZEOF_WORD
|
|
sta.z w2
|
|
lda words+2*SIZEOF_WORD+1
|
|
sta.z w2+1
|
|
// <w2
|
|
// [10] (byte~) main::$2 ← < (word) main::w2#0 -- vbuaa=_lo_vwuz1
|
|
lda.z w2
|
|
// SCREEN[2] = <w2
|
|
// [11] *((const nomodify byte*) main::SCREEN+(byte) 2) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+2
|
|
// >w2
|
|
// [12] (byte~) main::$3 ← > (word) main::w2#0 -- vbuaa=_hi_vwuz1
|
|
lda.z w2+1
|
|
// SCREEN[3] = >w2
|
|
// [13] *((const nomodify byte*) main::SCREEN+(byte) 3) ← (byte~) main::$3 -- _deref_pbuc1=vbuaa
|
|
sta SCREEN+3
|
|
// main::@return
|
|
// }
|
|
// [14] return
|
|
rts
|
|
}
|
|
// File Data
|
|
|