mirror of https://gitlab.com/camelot/kickc.git
268 lines
10 KiB
Plaintext
268 lines
10 KiB
Plaintext
Fixing struct type size struct Point to 7
|
|
Fixing struct type size struct Point to 7
|
|
Fixing struct type SIZE_OF struct Point to 7
|
|
Fixing struct type SIZE_OF struct Point to 7
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
void main()
|
|
main: scope:[main] from __start
|
|
main::$0 = 0 * SIZEOF_UNSIGNED_INT
|
|
SCREEN[main::$0] = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID)
|
|
main::$1 = 0 * SIZEOF_UNSIGNED_INT
|
|
main::$2 = 1 * SIZEOF_UNSIGNED_INT
|
|
SCREEN[main::$2] = ((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS)[main::$1]
|
|
main::$3 = 1 * SIZEOF_UNSIGNED_INT
|
|
main::$4 = 2 * SIZEOF_UNSIGNED_INT
|
|
SCREEN[main::$4] = ((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS)[main::$3]
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
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
|
|
__constant char OFFSET_STRUCT_POINT_ID = 5
|
|
__constant char OFFSET_STRUCT_POINT_POS = 1
|
|
__constant unsigned int * const SCREEN = (char *)$400
|
|
__constant char SIZEOF_UNSIGNED_INT = 2
|
|
void __start()
|
|
void main()
|
|
number main::$0
|
|
number main::$1
|
|
number main::$2
|
|
number main::$3
|
|
number main::$4
|
|
__loadstore struct Point point1 = { x: 4, pos: { 1, 2 }, id: 3 }
|
|
|
|
Adding number conversion cast (unumber) 0 in main::$0 = 0 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) main::$0 in main::$0 = (unumber)0 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) 0 in main::$1 = 0 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) main::$1 in main::$1 = (unumber)0 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) 1 in main::$2 = 1 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) main::$2 in main::$2 = (unumber)1 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) 1 in main::$3 = 1 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) main::$3 in main::$3 = (unumber)1 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) 2 in main::$4 = 2 * SIZEOF_UNSIGNED_INT
|
|
Adding number conversion cast (unumber) main::$4 in main::$4 = (unumber)2 * SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (char *) 1024
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 0
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 1
|
|
Simplifying constant integer cast 2
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (char) 0
|
|
Finalized unsigned number type (char) 0
|
|
Finalized unsigned number type (char) 1
|
|
Finalized unsigned number type (char) 1
|
|
Finalized unsigned number type (char) 2
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Inferred type updated to char in main::$0 = 0 * SIZEOF_UNSIGNED_INT
|
|
Inferred type updated to char in main::$1 = 0 * SIZEOF_UNSIGNED_INT
|
|
Inferred type updated to char in main::$2 = 1 * SIZEOF_UNSIGNED_INT
|
|
Inferred type updated to char in main::$3 = 1 * SIZEOF_UNSIGNED_INT
|
|
Inferred type updated to char in main::$4 = 2 * SIZEOF_UNSIGNED_INT
|
|
Constant right-side identified [0] main::$0 = 0 * SIZEOF_UNSIGNED_INT
|
|
Constant right-side identified [2] main::$1 = 0 * SIZEOF_UNSIGNED_INT
|
|
Constant right-side identified [3] main::$2 = 1 * SIZEOF_UNSIGNED_INT
|
|
Constant right-side identified [5] main::$3 = 1 * SIZEOF_UNSIGNED_INT
|
|
Constant right-side identified [6] main::$4 = 2 * SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
|
Constant main::$0 = 0*SIZEOF_UNSIGNED_INT
|
|
Constant main::$1 = 0*SIZEOF_UNSIGNED_INT
|
|
Constant main::$2 = 1*SIZEOF_UNSIGNED_INT
|
|
Constant main::$3 = 1*SIZEOF_UNSIGNED_INT
|
|
Constant main::$4 = 2*SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Simplifying constant evaluating to zero 0*SIZEOF_UNSIGNED_INT in
|
|
Simplifying constant evaluating to zero 0*SIZEOF_UNSIGNED_INT in
|
|
Successful SSA optimization PassNSimplifyConstantZero
|
|
Simplifying expression containing zero SCREEN in [1] SCREEN[main::$0] = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID)
|
|
Simplifying expression containing zero (unsigned int *)&point1+OFFSET_STRUCT_POINT_POS in [4] SCREEN[main::$2] = ((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS)[main::$1]
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Eliminating unused constant main::$0
|
|
Eliminating unused constant main::$1
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
|
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
|
|
Constant inlined main::$2 = 1*SIZEOF_UNSIGNED_INT
|
|
Constant inlined main::$3 = 1*SIZEOF_UNSIGNED_INT
|
|
Constant inlined main::$4 = 2*SIZEOF_UNSIGNED_INT
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Consolidated array index constant in *(SCREEN+1*SIZEOF_UNSIGNED_INT)
|
|
Consolidated array index constant in *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT)
|
|
Consolidated array index constant in *(SCREEN+2*SIZEOF_UNSIGNED_INT)
|
|
Successful SSA optimization Pass2ConstantAdditionElimination
|
|
Finalized unsigned number type (char) 2
|
|
Finalized unsigned number type (char) 2
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
CALL GRAPH
|
|
|
|
Created 0 initial phi equivalence classes
|
|
Coalesced down to 0 phi equivalence classes
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
void main()
|
|
main: scope:[main] from
|
|
[0] *SCREEN = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID)
|
|
[1] *(SCREEN+1*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS)
|
|
[2] *(SCREEN+2*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT)
|
|
to:main::@return
|
|
main::@return: scope:[main] from main
|
|
[3] return
|
|
to:@return
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
void main()
|
|
__loadstore struct Point point1 = { x: 4, pos: { 1, 2 }, id: 3 }
|
|
|
|
Initial phi equivalence classes
|
|
Added variable point1 to live range equivalence class [ point1 ]
|
|
Complete equivalence classes
|
|
[ point1 ]
|
|
Allocated mem[7] [ point1 ]
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [0] *SCREEN = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID) [ point1 ] ( [ point1 ] { } ) always clobbers reg byte a
|
|
Statement [1] *(SCREEN+1*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS) [ point1 ] ( [ point1 ] { } ) always clobbers reg byte a
|
|
Statement [2] *(SCREEN+2*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT) [ ] ( [ ] { } ) always clobbers reg byte a
|
|
Potential registers mem[7] [ point1 ] : mem[7] ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [Point]
|
|
Uplift Scope [main]
|
|
Uplift Scope [] 0: mem[7] [ point1 ]
|
|
|
|
Uplifting [Point] best 57 combination
|
|
Uplifting [main] best 57 combination
|
|
Uplifting [] best 57 combination mem[7] [ point1 ]
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Minimal struct with C-Standard behavior - struct with internal int array
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="struct-43.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
|
|
.const SIZEOF_UNSIGNED_INT = 2
|
|
.const OFFSET_STRUCT_POINT_ID = 5
|
|
.const OFFSET_STRUCT_POINT_POS = 1
|
|
.label SCREEN = $400
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
// [0] *SCREEN = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_ID
|
|
sta SCREEN
|
|
lda point1+OFFSET_STRUCT_POINT_ID+1
|
|
sta SCREEN+1
|
|
// [1] *(SCREEN+1*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_POS
|
|
sta SCREEN+1*SIZEOF_UNSIGNED_INT
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1
|
|
sta SCREEN+1*SIZEOF_UNSIGNED_INT+1
|
|
// [2] *(SCREEN+2*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT
|
|
sta SCREEN+2*SIZEOF_UNSIGNED_INT
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT+1
|
|
sta SCREEN+2*SIZEOF_UNSIGNED_INT+1
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [3] return
|
|
rts
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
point1: .byte 4
|
|
.word 1, 2, 3
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction __breturn:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
FINAL SYMBOL TABLE
|
|
__constant char OFFSET_STRUCT_POINT_ID = 5
|
|
__constant char OFFSET_STRUCT_POINT_POS = 1
|
|
__constant unsigned int * const SCREEN = (char *) 1024
|
|
__constant char SIZEOF_UNSIGNED_INT = 2
|
|
void main()
|
|
__loadstore struct Point point1 = { x: 4, pos: { 1, 2 }, id: 3 } // mem[7]
|
|
|
|
mem[7] [ point1 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 54
|
|
|
|
// File Comments
|
|
// Minimal struct with C-Standard behavior - struct with internal int array
|
|
// Upstart
|
|
// Commodore 64 PRG executable file
|
|
.file [name="struct-43.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
|
|
.const SIZEOF_UNSIGNED_INT = 2
|
|
.const OFFSET_STRUCT_POINT_ID = 5
|
|
.const OFFSET_STRUCT_POINT_POS = 1
|
|
.label SCREEN = $400
|
|
.segment Code
|
|
// main
|
|
main: {
|
|
// SCREEN[0] = point1.id
|
|
// [0] *SCREEN = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_ID) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_ID
|
|
sta SCREEN
|
|
lda point1+OFFSET_STRUCT_POINT_ID+1
|
|
sta SCREEN+1
|
|
// SCREEN[1] = point1.pos[0]
|
|
// [1] *(SCREEN+1*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_POS
|
|
sta SCREEN+1*SIZEOF_UNSIGNED_INT
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1
|
|
sta SCREEN+1*SIZEOF_UNSIGNED_INT+1
|
|
// SCREEN[2] = point1.pos[1]
|
|
// [2] *(SCREEN+2*SIZEOF_UNSIGNED_INT) = *((unsigned int *)&point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT) -- _deref_pwuc1=_deref_pwuc2
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT
|
|
sta SCREEN+2*SIZEOF_UNSIGNED_INT
|
|
lda point1+OFFSET_STRUCT_POINT_POS+1*SIZEOF_UNSIGNED_INT+1
|
|
sta SCREEN+2*SIZEOF_UNSIGNED_INT+1
|
|
// main::@return
|
|
// }
|
|
// [3] return
|
|
rts
|
|
}
|
|
// File Data
|
|
.segment Data
|
|
point1: .byte 4
|
|
.word 1, 2, 3
|
|
|