mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-16 21:07:56 +00:00
291 lines
7.8 KiB
Plaintext
291 lines
7.8 KiB
Plaintext
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start
|
|
main::i#0 = 0
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2
|
|
main::i#2 = phi( main/main::i#0, main::@2/main::i#1 )
|
|
main::$0 = main::i#2 < $19
|
|
if(main::$0) goto main::@2
|
|
to:main::@return
|
|
main::@2: scope:[main] from main::@1
|
|
main::i#3 = phi( main::@1/main::i#2 )
|
|
entities[main::i#3] = 7
|
|
main::i#1 = ++ main::i#3
|
|
to:main::@1
|
|
main::@return: scope:[main] from main::@1
|
|
return
|
|
to:@return
|
|
|
|
void __start()
|
|
__start: scope:[__start] from
|
|
call main
|
|
to:__start::@1
|
|
__start::@1: scope:[__start] from __start
|
|
to:__start::@return
|
|
__start::@return: scope:[__start] from __start::@1
|
|
return
|
|
to:@return
|
|
|
|
SYMBOL TABLE SSA
|
|
void __start()
|
|
const byte* entities[$19] = { fill( $19, 0) }
|
|
void main()
|
|
bool~ main::$0
|
|
word main::i
|
|
word main::i#0
|
|
word main::i#1
|
|
word main::i#2
|
|
word main::i#3
|
|
|
|
Adding number conversion cast (unumber) $19 in main::$0 = main::i#2 < $19
|
|
Adding number conversion cast (unumber) 7 in entities[main::i#3] = 7
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Inlining cast entities[main::i#3] = (unumber)7
|
|
Successful SSA optimization Pass2InlineCast
|
|
Simplifying constant integer cast $19
|
|
Simplifying constant integer cast 7
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) $19
|
|
Finalized unsigned number type (byte) 7
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias main::i#2 = main::i#3
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Simple Condition main::$0 [3] if(main::i#2<$19) goto main::@2
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant main::i#0 = 0
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
De-inlining pointer[w] to *(pointer+w) [4] entities[main::i#2] = 7
|
|
Successful SSA optimization Pass2DeInlineWordDerefIdx
|
|
Removing unused procedure __start
|
|
Removing unused procedure block __start
|
|
Removing unused procedure block __start::@1
|
|
Removing unused procedure block __start::@return
|
|
Successful SSA optimization PassNEliminateEmptyStart
|
|
Inlining constant with var siblings main::i#0
|
|
Constant inlined main::i#0 = 0
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Finalized unsigned number type (byte) $19
|
|
Finalized unsigned number type (byte) $19
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Adding NOP phi() at start of main
|
|
CALL GRAPH
|
|
|
|
Created 1 initial phi equivalence classes
|
|
Coalesced [7] main::i#4 = main::i#1
|
|
Coalesced down to 1 phi equivalence classes
|
|
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::@2
|
|
[1] main::i#2 = phi( main/0, main::@2/main::i#1 )
|
|
[2] if(main::i#2<$19) goto main::@2
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[3] return
|
|
to:@return
|
|
main::@2: scope:[main] from main::@1
|
|
[4] main::$1 = entities + main::i#2
|
|
[5] *main::$1 = 7
|
|
[6] main::i#1 = ++ main::i#2
|
|
to:main::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
void main()
|
|
byte*~ main::$1 22.0
|
|
word main::i
|
|
word main::i#1 22.0
|
|
word main::i#2 11.0
|
|
|
|
Initial phi equivalence classes
|
|
[ main::i#2 main::i#1 ]
|
|
Added variable main::$1 to live range equivalence class [ main::$1 ]
|
|
Complete equivalence classes
|
|
[ main::i#2 main::i#1 ]
|
|
[ main::$1 ]
|
|
Allocated zp[2]:2 [ main::i#2 main::i#1 ]
|
|
Allocated zp[2]:4 [ main::$1 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [2] if(main::i#2<$19) goto main::@2 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a
|
|
Statement [4] main::$1 = entities + main::i#2 [ main::i#2 main::$1 ] ( [ main::i#2 main::$1 ] { } ) always clobbers reg byte a
|
|
Statement [5] *main::$1 = 7 [ main::i#2 ] ( [ main::i#2 ] { } ) always clobbers reg byte a reg byte y
|
|
Potential registers zp[2]:2 [ main::i#2 main::i#1 ] : zp[2]:2 ,
|
|
Potential registers zp[2]:4 [ main::$1 ] : zp[2]:4 ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [main] 33: zp[2]:2 [ main::i#2 main::i#1 ] 22: zp[2]:4 [ main::$1 ]
|
|
Uplift Scope []
|
|
|
|
Uplifting [main] best 731 combination zp[2]:2 [ main::i#2 main::i#1 ] zp[2]:4 [ main::$1 ]
|
|
Uplifting [] best 731 combination
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Test array index pointer rewriting
|
|
// 8bit array with 16bit index
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="index-pointer-rewrite-2.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
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
.label i = 2
|
|
.label __1 = 4
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
|
|
lda #<0
|
|
sta.z i
|
|
lda #>0
|
|
sta.z i+1
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [2] if(main::i#2<$19) goto main::@2 -- vwuz1_lt_vbuc1_then_la1
|
|
lda.z i+1
|
|
bne !+
|
|
lda.z i
|
|
cmp #$19
|
|
bcc __b2
|
|
!:
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [3] return
|
|
rts
|
|
// main::@2
|
|
__b2:
|
|
// [4] main::$1 = entities + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
|
|
clc
|
|
lda.z i
|
|
adc #<entities
|
|
sta.z __1
|
|
lda.z i+1
|
|
adc #>entities
|
|
sta.z __1+1
|
|
// [5] *main::$1 = 7 -- _deref_pbuz1=vbuc1
|
|
lda #7
|
|
ldy #0
|
|
sta (__1),y
|
|
// [6] main::i#1 = ++ main::i#2 -- vwuz1=_inc_vwuz1
|
|
inc.z i
|
|
bne !+
|
|
inc.z i+1
|
|
!:
|
|
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
__b1_from___b2:
|
|
// [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
entities: .fill $19, 0
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction lda #>0
|
|
Succesful ASM optimization Pass5UnnecesaryLoadElimination
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction __breturn:
|
|
Removing instruction __b1_from___b2:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
const byte* entities[$19] = { fill( $19, 0) }
|
|
void main()
|
|
byte*~ main::$1 zp[2]:4 22.0
|
|
word main::i
|
|
word main::i#1 i zp[2]:2 22.0
|
|
word main::i#2 i zp[2]:2 11.0
|
|
|
|
zp[2]:2 [ main::i#2 main::i#1 ]
|
|
zp[2]:4 [ main::$1 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 651
|
|
|
|
// File Comments
|
|
// Test array index pointer rewriting
|
|
// 8bit array with 16bit index
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="index-pointer-rewrite-2.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
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
.label i = 2
|
|
.label __1 = 4
|
|
// [1] phi from main to main::@1 [phi:main->main::@1]
|
|
// [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vwuz1=vwuc1
|
|
lda #<0
|
|
sta.z i
|
|
sta.z i+1
|
|
// main::@1
|
|
__b1:
|
|
// for(unsigned short i=0;i<NUM_ENTITIES;i++)
|
|
// [2] if(main::i#2<$19) goto main::@2 -- vwuz1_lt_vbuc1_then_la1
|
|
lda.z i+1
|
|
bne !+
|
|
lda.z i
|
|
cmp #$19
|
|
bcc __b2
|
|
!:
|
|
// main::@return
|
|
// }
|
|
// [3] return
|
|
rts
|
|
// main::@2
|
|
__b2:
|
|
// entities[i] = 7
|
|
// [4] main::$1 = entities + main::i#2 -- pbuz1=pbuc1_plus_vwuz2
|
|
clc
|
|
lda.z i
|
|
adc #<entities
|
|
sta.z __1
|
|
lda.z i+1
|
|
adc #>entities
|
|
sta.z __1+1
|
|
// [5] *main::$1 = 7 -- _deref_pbuz1=vbuc1
|
|
lda #7
|
|
ldy #0
|
|
sta (__1),y
|
|
// for(unsigned short i=0;i<NUM_ENTITIES;i++)
|
|
// [6] main::i#1 = ++ main::i#2 -- vwuz1=_inc_vwuz1
|
|
inc.z i
|
|
bne !+
|
|
inc.z i+1
|
|
!:
|
|
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
// [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
entities: .fill $19, 0
|
|
|