mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-10-21 17:24:39 +00:00
458 lines
16 KiB
Plaintext
458 lines
16 KiB
Plaintext
Fixing constant pointer addition (const word*) seq+(number) 0
|
|
Fixing constant pointer addition (const struct Setting*) settings+(number) 0
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
to:@1
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
(byte) main::i#0 ← (byte) 0
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2
|
|
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@2/(byte) main::i#1 )
|
|
(byte*~) main::$4 ← (byte*)(const struct Setting*) main::setting
|
|
(byte*~) main::$2 ← (byte*~) main::$4 + (const byte) OFFSET_STRUCT_SETTING_LEN
|
|
(bool~) main::$0 ← (byte) main::i#2 < *((byte*~) main::$2)
|
|
if((bool~) main::$0) goto main::@2
|
|
to:main::@return
|
|
main::@2: scope:[main] from main::@1
|
|
(byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
|
|
(byte~) main::$1 ← (byte) main::i#3 * (const byte) SIZEOF_WORD
|
|
(word**~) main::$5 ← (word**)(const struct Setting*) main::setting
|
|
(word**~) main::$3 ← (word**~) main::$5 + (const byte) OFFSET_STRUCT_SETTING_BUF
|
|
*((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**~) main::$3) + (byte~) main::$1)
|
|
(byte) main::i#1 ← ++ (byte) main::i#3
|
|
to:main::@1
|
|
main::@return: scope:[main] from main::@1
|
|
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) OFFSET_STRUCT_SETTING_BUF = (byte) 1
|
|
(const byte) OFFSET_STRUCT_SETTING_LEN = (byte) 0
|
|
(const nomodify word*) SCREEN = (word*)(number) $400
|
|
(const byte) SIZEOF_STRUCT_SETTING = (byte) 3
|
|
(const byte) SIZEOF_WORD = (byte) 2
|
|
(word*) Setting::buf
|
|
(byte) Setting::len
|
|
(void()) main()
|
|
(bool~) main::$0
|
|
(byte~) main::$1
|
|
(byte*~) main::$2
|
|
(word**~) main::$3
|
|
(byte*~) main::$4
|
|
(word**~) main::$5
|
|
(label) main::@1
|
|
(label) main::@2
|
|
(label) main::@return
|
|
(byte) main::i
|
|
(byte) main::i#0
|
|
(byte) main::i#1
|
|
(byte) main::i#2
|
|
(byte) main::i#3
|
|
(const struct Setting*) main::setting = (const struct Setting*) settings+(number) 0*(const byte) SIZEOF_STRUCT_SETTING
|
|
(const word*) seq[] = { (word) 1, (word) 2, (word) 3 }
|
|
(const struct Setting*) settings[] = { { len: (byte) 3, buf: (const word*) seq+(number) 0*(const byte) SIZEOF_WORD } }
|
|
|
|
Adding number conversion cast (unumber) 0*SIZEOF_WORD in
|
|
Adding number conversion cast (unumber) 0 in
|
|
Adding number conversion cast (unumber) 0*SIZEOF_STRUCT_SETTING in
|
|
Adding number conversion cast (unumber) 0 in
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (word*) 1024
|
|
Simplifying constant integer cast (unumber)(number) 0*(const byte) SIZEOF_WORD
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast (unumber)(number) 0*(const byte) SIZEOF_STRUCT_SETTING
|
|
Simplifying constant integer cast 0
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 0
|
|
Finalized unsigned number type (byte) 0
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias main::i#2 = main::i#3
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Simple Condition (bool~) main::$0 [5] if((byte) main::i#2<*((byte*~) main::$2)) goto main::@2
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant right-side identified [2] (byte*~) main::$4 ← (byte*)(const struct Setting*) main::setting
|
|
Constant right-side identified [7] (word**~) main::$5 ← (word**)(const struct Setting*) main::setting
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant (const byte) main::i#0 = 0
|
|
Constant (const byte*) main::$4 = (byte*)main::setting
|
|
Constant (const word**) main::$5 = (word**)main::setting
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Converting *(pointer+n) to pointer[n] [5] if((byte) main::i#2<*((byte*~) main::$2)) goto main::@2 -- *(main::$4 + OFFSET_STRUCT_SETTING_LEN)
|
|
Converting *(pointer+n) to pointer[n] [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**~) main::$3) + (byte~) main::$1) -- *(main::$5 + OFFSET_STRUCT_SETTING_BUF)
|
|
Successful SSA optimization Pass2InlineDerefIdx
|
|
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_WORD in
|
|
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_STRUCT_SETTING in
|
|
Successful SSA optimization PassNSimplifyConstantZero
|
|
Simplifying expression containing zero seq in
|
|
Simplifying expression containing zero settings in
|
|
Simplifying expression containing zero main::$4 in [3] (byte*~) main::$2 ← (const byte*) main::$4 + (const byte) OFFSET_STRUCT_SETTING_LEN
|
|
Simplifying expression containing zero main::$4 in [5] if((byte) main::i#2<*((const byte*) main::$4 + (const byte) OFFSET_STRUCT_SETTING_LEN)) goto main::@2
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Eliminating unused variable (byte*~) main::$2 and assignment [1] (byte*~) main::$2 ← (const byte*) main::$4
|
|
Eliminating unused variable (word**~) main::$3 and assignment [4] (word**~) main::$3 ← (const word**) main::$5 + (const byte) OFFSET_STRUCT_SETTING_BUF
|
|
Eliminating unused constant (const byte) SIZEOF_STRUCT_SETTING
|
|
Eliminating unused constant (const byte) OFFSET_STRUCT_SETTING_LEN
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
Rewriting multiplication to use shift [2] (byte~) main::$1 ← (byte) main::i#2 * (const byte) SIZEOF_WORD
|
|
Successful SSA optimization Pass2MultiplyToShiftRewriting
|
|
Inlining constant with var siblings (const byte) main::i#0
|
|
Constant inlined main::$5 = (word**)(const struct Setting*) settings
|
|
Constant inlined main::i#0 = (byte) 0
|
|
Constant inlined main::$4 = (byte*)(const struct Setting*) settings
|
|
Constant inlined main::setting = (const struct Setting*) settings
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Consolidated array index constant in *((word**)settings+OFFSET_STRUCT_SETTING_BUF)
|
|
Successful SSA optimization Pass2ConstantAdditionElimination
|
|
Eliminating unused constant (const byte) SIZEOF_WORD
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
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
|
|
Adding NOP phi() at start of main
|
|
CALL GRAPH
|
|
Calls in [] to main:2
|
|
|
|
Created 1 initial phi equivalence classes
|
|
Coalesced [12] main::i#4 ← main::i#1
|
|
Coalesced down to 1 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
|
|
Adding NOP phi() at start of main
|
|
|
|
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()
|
|
to:main::@1
|
|
main::@1: scope:[main] from main main::@2
|
|
[5] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 )
|
|
[6] if((byte) main::i#2<*((byte*)(const struct Setting*) settings)) goto main::@2
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[7] return
|
|
to:@return
|
|
main::@2: scope:[main] from main::@1
|
|
[8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1
|
|
[9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1)
|
|
[10] (byte) main::i#1 ← ++ (byte) main::i#2
|
|
to:main::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(word*) Setting::buf
|
|
(byte) Setting::len
|
|
(void()) main()
|
|
(byte~) main::$1 303.0
|
|
(byte) main::i
|
|
(byte) main::i#1 202.0
|
|
(byte) main::i#2 101.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[1]:2 [ main::i#2 main::i#1 ]
|
|
Allocated zp[1]:3 [ main::$1 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Demonstrates problem with conditions using negated struct references
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const OFFSET_STRUCT_SETTING_BUF = 1
|
|
.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: {
|
|
.label __1 = 3
|
|
.label i = 2
|
|
// [5] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
|
lda #0
|
|
sta.z i
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [6] if((byte) main::i#2<*((byte*)(const struct Setting*) settings)) goto main::@2 -- vbuz1_lt__deref_pbuc1_then_la1
|
|
lda.z i
|
|
cmp settings
|
|
bcc __b2
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [7] return
|
|
rts
|
|
// main::@2
|
|
__b2:
|
|
// [8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1
|
|
lda.z i
|
|
asl
|
|
sta.z __1
|
|
// [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1) -- pwuc1_derefidx_vbuz1=(_deref_pptc2)_derefidx_vbuz1
|
|
ldy.z __1
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF
|
|
sta.z $fe
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF+1
|
|
sta.z $ff
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
iny
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
// [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
|
|
inc.z i
|
|
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
__b1_from___b2:
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
seq: .word 1, 2, 3
|
|
settings: .byte 3
|
|
.word seq
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] { } ) always clobbers reg byte a
|
|
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
|
|
Statement [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1) [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a reg byte y
|
|
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::i#2 main::i#1 ]
|
|
Statement [8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] { } ) always clobbers reg byte a
|
|
Statement [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1) [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a reg byte y
|
|
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x ,
|
|
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [main] 303: zp[1]:2 [ main::i#2 main::i#1 ] 303: zp[1]:3 [ main::$1 ]
|
|
Uplift Scope [Setting]
|
|
Uplift Scope []
|
|
|
|
Uplifting [main] best 643 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ]
|
|
Uplifting [Setting] best 643 combination
|
|
Uplifting [] best 643 combination
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Demonstrates problem with conditions using negated struct references
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const OFFSET_STRUCT_SETTING_BUF = 1
|
|
.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] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [6] if((byte) main::i#2<*((byte*)(const struct Setting*) settings)) goto main::@2 -- vbuxx_lt__deref_pbuc1_then_la1
|
|
cpx settings
|
|
bcc __b2
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [7] return
|
|
rts
|
|
// main::@2
|
|
__b2:
|
|
// [8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
|
|
txa
|
|
asl
|
|
// [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1) -- pwuc1_derefidx_vbuaa=(_deref_pptc2)_derefidx_vbuaa
|
|
tay
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF
|
|
sta.z $fe
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF+1
|
|
sta.z $ff
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
iny
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
// [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
__b1_from___b2:
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
seq: .word 1, 2, 3
|
|
settings: .byte 3
|
|
.word seq
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __b1
|
|
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:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bbegin:
|
|
Removing instruction __bend:
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction __breturn:
|
|
Removing instruction __b1_from___b2:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Removing instruction jsr main
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
|
|
FINAL SYMBOL TABLE
|
|
(label) @1
|
|
(label) @begin
|
|
(label) @end
|
|
(const byte) OFFSET_STRUCT_SETTING_BUF = (byte) 1
|
|
(const nomodify word*) SCREEN = (word*) 1024
|
|
(word*) Setting::buf
|
|
(byte) Setting::len
|
|
(void()) main()
|
|
(byte~) main::$1 reg byte a 303.0
|
|
(label) main::@1
|
|
(label) main::@2
|
|
(label) main::@return
|
|
(byte) main::i
|
|
(byte) main::i#1 reg byte x 202.0
|
|
(byte) main::i#2 reg byte x 101.0
|
|
(const word*) seq[] = { (word) 1, (word) 2, (word) 3 }
|
|
(const struct Setting*) settings[] = { { len: (byte) 3, buf: (const word*) seq } }
|
|
|
|
reg byte x [ main::i#2 main::i#1 ]
|
|
reg byte a [ main::$1 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 571
|
|
|
|
// File Comments
|
|
// Demonstrates problem with conditions using negated struct references
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.const OFFSET_STRUCT_SETTING_BUF = 1
|
|
.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: {
|
|
// [5] phi from main to main::@1 [phi:main->main::@1]
|
|
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
|
ldx #0
|
|
// main::@1
|
|
__b1:
|
|
// for( char i=0;i<setting->len;i++)
|
|
// [6] if((byte) main::i#2<*((byte*)(const struct Setting*) settings)) goto main::@2 -- vbuxx_lt__deref_pbuc1_then_la1
|
|
cpx settings
|
|
bcc __b2
|
|
// main::@return
|
|
// }
|
|
// [7] return
|
|
rts
|
|
// main::@2
|
|
__b2:
|
|
// SCREEN[i] = setting->buf[i]
|
|
// [8] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
|
|
txa
|
|
asl
|
|
// [9] *((const nomodify word*) SCREEN + (byte~) main::$1) ← *(*((word**)(const struct Setting*) settings+(const byte) OFFSET_STRUCT_SETTING_BUF) + (byte~) main::$1) -- pwuc1_derefidx_vbuaa=(_deref_pptc2)_derefidx_vbuaa
|
|
tay
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF
|
|
sta.z $fe
|
|
lda settings+OFFSET_STRUCT_SETTING_BUF+1
|
|
sta.z $ff
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
iny
|
|
lda ($fe),y
|
|
sta SCREEN,y
|
|
// for( char i=0;i<setting->len;i++)
|
|
// [10] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
|
|
inx
|
|
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
|
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
seq: .word 1, 2, 3
|
|
settings: .byte 3
|
|
.word seq
|
|
|