1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-29 09:29:31 +00:00
kickc/src/test/ref/pointer-void-3.log

489 lines
16 KiB
Plaintext

Inlined call call __init
Eliminating unused variable with no statement main::$0
Eliminating unused variable with no statement main::$1
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start::@1
heap_head#15 = phi( __start::@1/heap_head#16 )
call malloc
malloc::return#0 = malloc::return#3
to:main::@1
main::@1: scope:[main] from main
heap_head#8 = phi( main/heap_head#4 )
malloc::return#4 = phi( main/malloc::return#0 )
main::buf1#0 = ((char *)) malloc::return#4
heap_head#0 = heap_head#8
call malloc
malloc::return#1 = malloc::return#3
to:main::@2
main::@2: scope:[main] from main::@1
main::buf1#1 = phi( main::@1/main::buf1#0 )
heap_head#9 = phi( main::@1/heap_head#4 )
malloc::return#5 = phi( main::@1/malloc::return#1 )
main::buf2#0 = ((char *)) malloc::return#5
heap_head#1 = heap_head#9
*main::buf1#1 = 'a'
*main::buf2#0 = 'b'
SCREEN[0] = *main::buf1#1
SCREEN[1] = *main::buf2#0
to:main::@return
main::@return: scope:[main] from main::@2
heap_head#10 = phi( main::@2/heap_head#1 )
heap_head#2 = heap_head#10
return
to:@return
void * malloc()
malloc: scope:[malloc] from main main::@1
heap_head#11 = phi( main/heap_head#15, main::@1/heap_head#0 )
heap_head#3 = ++ heap_head#11
malloc::return#2 = ((void *)) heap_head#3
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
heap_head#12 = phi( malloc/heap_head#3 )
malloc::return#6 = phi( malloc/malloc::return#2 )
malloc::return#3 = malloc::return#6
heap_head#4 = heap_head#12
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
heap_head#5 = (char *)$c000
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
heap_head#16 = phi( __start::__init1/heap_head#5 )
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
heap_head#13 = phi( __start::@1/heap_head#2 )
heap_head#6 = heap_head#13
to:__start::@return
__start::@return: scope:[__start] from __start::@2
heap_head#14 = phi( __start::@2/heap_head#6 )
heap_head#7 = heap_head#14
return
to:@return
SYMBOL TABLE SSA
__constant char * const SCREEN = (char *)$400
void __start()
char *heap_head
char *heap_head#0
char *heap_head#1
char *heap_head#10
char *heap_head#11
char *heap_head#12
char *heap_head#13
char *heap_head#14
char *heap_head#15
char *heap_head#16
char *heap_head#2
char *heap_head#3
char *heap_head#4
char *heap_head#5
char *heap_head#6
char *heap_head#7
char *heap_head#8
char *heap_head#9
void main()
char *main::buf1
char *main::buf1#0
char *main::buf1#1
char *main::buf2
char *main::buf2#0
void * malloc()
void *malloc::return
void *malloc::return#0
void *malloc::return#1
void *malloc::return#2
void *malloc::return#3
void *malloc::return#4
void *malloc::return#5
void *malloc::return#6
Adding number conversion cast (unumber) 0 in SCREEN[0] = *main::buf1#1
Adding number conversion cast (unumber) 1 in SCREEN[1] = *main::buf2#0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast main::buf1#0 = (char *)malloc::return#4
Inlining cast main::buf2#0 = (char *)malloc::return#5
Inlining cast malloc::return#2 = (void *)heap_head#3
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant pointer cast (char *) 49152
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias malloc::return#0 = malloc::return#4
Alias heap_head#0 = heap_head#8
Alias malloc::return#1 = malloc::return#5
Alias main::buf1#0 = main::buf1#1
Alias heap_head#1 = heap_head#9 heap_head#10 heap_head#2
Alias malloc::return#2 = malloc::return#6 malloc::return#3
Alias heap_head#12 = heap_head#3 heap_head#4
Alias heap_head#16 = heap_head#5
Alias heap_head#13 = heap_head#6 heap_head#14 heap_head#7
Successful SSA optimization Pass2AliasElimination
Identical Phi Values heap_head#15 heap_head#16
Identical Phi Values heap_head#0 heap_head#12
Identical Phi Values heap_head#1 heap_head#12
Identical Phi Values heap_head#13 heap_head#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant heap_head#16 = (char *) 49152
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN in [11] SCREEN[0] = *main::buf1#0
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Inlining constant with var siblings heap_head#16
Constant inlined heap_head#16 = (char *) 49152
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to malloc:1 malloc:5
Created 1 initial phi equivalence classes
Coalesced [4] heap_head#17 = heap_head#12
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()
[1] call malloc
[2] malloc::return#0 = malloc::return#2
to:main::@1
main::@1: scope:[main] from main
[3] main::buf1#0 = (char *)malloc::return#0
[4] call malloc
[5] malloc::return#1 = malloc::return#2
to:main::@2
main::@2: scope:[main] from main::@1
[6] main::buf2#0 = (char *)malloc::return#1
[7] *main::buf1#0 = 'a'
[8] *main::buf2#0 = 'b'
[9] *SCREEN = *main::buf1#0
[10] *(SCREEN+1) = *main::buf2#0
to:main::@return
main::@return: scope:[main] from main::@2
[11] return
to:@return
void * malloc()
malloc: scope:[malloc] from main main::@1
[12] heap_head#11 = phi( main/(char *) 49152, main::@1/heap_head#12 )
[13] heap_head#12 = ++ heap_head#11
[14] malloc::return#2 = (void *)heap_head#12
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
[15] return
to:@return
VARIABLE REGISTER WEIGHTS
char *heap_head
char *heap_head#11 // 13.0
char *heap_head#12 // 2.1666666666666665
void main()
char *main::buf1
char *main::buf1#0 // 1.0
char *main::buf2
char *main::buf2#0 // 1.5
void * malloc()
void *malloc::return
void *malloc::return#0 // 2.0
void *malloc::return#1 // 2.0
void *malloc::return#2 // 3.75
Initial phi equivalence classes
[ heap_head#11 heap_head#12 ]
Added variable malloc::return#0 to live range equivalence class [ malloc::return#0 ]
Added variable main::buf1#0 to live range equivalence class [ main::buf1#0 ]
Added variable malloc::return#1 to live range equivalence class [ malloc::return#1 ]
Added variable main::buf2#0 to live range equivalence class [ main::buf2#0 ]
Added variable malloc::return#2 to live range equivalence class [ malloc::return#2 ]
Complete equivalence classes
[ heap_head#11 heap_head#12 ]
[ malloc::return#0 ]
[ main::buf1#0 ]
[ malloc::return#1 ]
[ main::buf2#0 ]
[ malloc::return#2 ]
Allocated zp[2]:2 [ heap_head#11 heap_head#12 ]
Allocated zp[2]:4 [ malloc::return#2 ]
Allocated zp[2]:6 [ malloc::return#0 ]
Allocated zp[2]:8 [ malloc::return#1 ]
Allocated zp[2]:10 [ main::buf2#0 ]
Allocated zp[2]:12 [ main::buf1#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] malloc::return#0 = malloc::return#2 [ malloc::return#0 heap_head#12 ] ( [ malloc::return#0 heap_head#12 ] { { malloc::return#0 = malloc::return#2 } } ) always clobbers reg byte a
Statement [3] main::buf1#0 = (char *)malloc::return#0 [ main::buf1#0 heap_head#12 ] ( [ main::buf1#0 heap_head#12 ] { { heap_head#11 = heap_head#12 } { malloc::return#1 = malloc::return#2 } } ) always clobbers reg byte a
Statement [5] malloc::return#1 = malloc::return#2 [ main::buf1#0 malloc::return#1 ] ( [ main::buf1#0 malloc::return#1 ] { { heap_head#11 = heap_head#12 } { malloc::return#1 = malloc::return#2 } } ) always clobbers reg byte a
Statement [6] main::buf2#0 = (char *)malloc::return#1 [ main::buf1#0 main::buf2#0 ] ( [ main::buf1#0 main::buf2#0 ] { } ) always clobbers reg byte a
Statement [7] *main::buf1#0 = 'a' [ main::buf1#0 main::buf2#0 ] ( [ main::buf1#0 main::buf2#0 ] { } ) always clobbers reg byte a reg byte y
Statement [8] *main::buf2#0 = 'b' [ main::buf1#0 main::buf2#0 ] ( [ main::buf1#0 main::buf2#0 ] { } ) always clobbers reg byte a reg byte y
Statement [9] *SCREEN = *main::buf1#0 [ main::buf2#0 ] ( [ main::buf2#0 ] { } ) always clobbers reg byte a reg byte y
Statement [10] *(SCREEN+1) = *main::buf2#0 [ ] ( [ ] { } ) always clobbers reg byte a reg byte y
Statement [14] malloc::return#2 = (void *)heap_head#12 [ malloc::return#2 heap_head#12 ] ( malloc:1 [ malloc::return#2 heap_head#12 ] { { malloc::return#0 = malloc::return#2 } } malloc:4 [ main::buf1#0 malloc::return#2 heap_head#12 ] { { heap_head#11 = heap_head#12 } { malloc::return#1 = malloc::return#2 } } ) always clobbers reg byte a
Potential registers zp[2]:2 [ heap_head#11 heap_head#12 ] : zp[2]:2 ,
Potential registers zp[2]:6 [ malloc::return#0 ] : zp[2]:6 ,
Potential registers zp[2]:12 [ main::buf1#0 ] : zp[2]:12 ,
Potential registers zp[2]:8 [ malloc::return#1 ] : zp[2]:8 ,
Potential registers zp[2]:10 [ main::buf2#0 ] : zp[2]:10 ,
Potential registers zp[2]:4 [ malloc::return#2 ] : zp[2]:4 ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 15.17: zp[2]:2 [ heap_head#11 heap_head#12 ]
Uplift Scope [malloc] 3.75: zp[2]:4 [ malloc::return#2 ] 2: zp[2]:6 [ malloc::return#0 ] 2: zp[2]:8 [ malloc::return#1 ]
Uplift Scope [main] 1.5: zp[2]:10 [ main::buf2#0 ] 1: zp[2]:12 [ main::buf1#0 ]
Uplifting [] best 160 combination zp[2]:2 [ heap_head#11 heap_head#12 ]
Uplifting [malloc] best 160 combination zp[2]:4 [ malloc::return#2 ] zp[2]:6 [ malloc::return#0 ] zp[2]:8 [ malloc::return#1 ]
Uplifting [main] best 160 combination zp[2]:10 [ main::buf2#0 ] zp[2]:12 [ main::buf1#0 ]
Coalescing zero page register [ zp[2]:6 [ malloc::return#0 ] ] with [ zp[2]:12 [ main::buf1#0 ] ] - score: 1
Coalescing zero page register [ zp[2]:8 [ malloc::return#1 ] ] with [ zp[2]:10 [ main::buf2#0 ] ] - score: 1
Coalescing zero page register [ zp[2]:8 [ malloc::return#1 main::buf2#0 ] ] with [ zp[2]:4 [ malloc::return#2 ] ] - score: 1
Allocated (was zp[2]:8) zp[2]:4 [ malloc::return#1 main::buf2#0 malloc::return#2 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test void pointer - issues when assigning returns from malloc()
// Upstart
// Commodore 64 PRG executable file
.file [name="pointer-void-3.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
.label SCREEN = $400
.label heap_head = 2
.segment Code
// main
main: {
.label buf1 = 6
.label buf2 = 4
// [1] call malloc
// [12] phi from main to malloc [phi:main->malloc]
malloc_from_main:
// [12] phi heap_head#11 = (char *) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000
sta.z heap_head
lda #>$c000
sta.z heap_head+1
jsr malloc
// [2] malloc::return#0 = malloc::return#2 -- pvoz1=pvoz2
lda.z malloc.return_1
sta.z malloc.return
lda.z malloc.return_1+1
sta.z malloc.return+1
jmp __b1
// main::@1
__b1:
// [3] main::buf1#0 = (char *)malloc::return#0
// [4] call malloc
// [12] phi from main::@1 to malloc [phi:main::@1->malloc]
malloc_from___b1:
// [12] phi heap_head#11 = heap_head#12 [phi:main::@1->malloc#0] -- register_copy
jsr malloc
// [5] malloc::return#1 = malloc::return#2
jmp __b2
// main::@2
__b2:
// [6] main::buf2#0 = (char *)malloc::return#1
// [7] *main::buf1#0 = 'a' -- _deref_pbuz1=vbuc1
lda #'a'
ldy #0
sta (buf1),y
// [8] *main::buf2#0 = 'b' -- _deref_pbuz1=vbuc1
lda #'b'
ldy #0
sta (buf2),y
// [9] *SCREEN = *main::buf1#0 -- _deref_pbuc1=_deref_pbuz1
ldy #0
lda (buf1),y
sta SCREEN
// [10] *(SCREEN+1) = *main::buf2#0 -- _deref_pbuc1=_deref_pbuz1
ldy #0
lda (buf2),y
sta SCREEN+1
jmp __breturn
// main::@return
__breturn:
// [11] return
rts
}
// malloc
malloc: {
.label return = 6
.label return_1 = 4
// [13] heap_head#12 = ++ heap_head#11 -- pbuz1=_inc_pbuz1
inc.z heap_head
bne !+
inc.z heap_head+1
!:
// [14] malloc::return#2 = (void *)heap_head#12 -- pvoz1=pvoz2
lda.z heap_head
sta.z return_1
lda.z heap_head+1
sta.z return_1+1
jmp __breturn
// malloc::@return
__breturn:
// [15] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Removing instruction ldy #0
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction malloc_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction malloc_from_main:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
__constant char * const SCREEN = (char *) 1024
char *heap_head
char *heap_head#11 // heap_head zp[2]:2 13.0
char *heap_head#12 // heap_head zp[2]:2 2.1666666666666665
void main()
char *main::buf1
char *main::buf1#0 // buf1 zp[2]:6 1.0
char *main::buf2
char *main::buf2#0 // buf2 zp[2]:4 1.5
void * malloc()
void *malloc::return
void *malloc::return#0 // return zp[2]:6 2.0
void *malloc::return#1 // return_1 zp[2]:4 2.0
void *malloc::return#2 // return_1 zp[2]:4 3.75
zp[2]:2 [ heap_head#11 heap_head#12 ]
zp[2]:6 [ malloc::return#0 main::buf1#0 ]
zp[2]:4 [ malloc::return#1 main::buf2#0 malloc::return#2 ]
FINAL ASSEMBLER
Score: 106
// File Comments
// Test void pointer - issues when assigning returns from malloc()
// Upstart
// Commodore 64 PRG executable file
.file [name="pointer-void-3.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
.label SCREEN = $400
.label heap_head = 2
.segment Code
// main
main: {
.label buf1 = 6
.label buf2 = 4
// byte* buf1 = malloc()
// [1] call malloc
// [12] phi from main to malloc [phi:main->malloc]
// [12] phi heap_head#11 = (char *) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000
sta.z heap_head
lda #>$c000
sta.z heap_head+1
jsr malloc
// byte* buf1 = malloc()
// [2] malloc::return#0 = malloc::return#2 -- pvoz1=pvoz2
lda.z malloc.return_1
sta.z malloc.return
lda.z malloc.return_1+1
sta.z malloc.return+1
// main::@1
// [3] main::buf1#0 = (char *)malloc::return#0
// byte* buf2 = malloc()
// [4] call malloc
// [12] phi from main::@1 to malloc [phi:main::@1->malloc]
// [12] phi heap_head#11 = heap_head#12 [phi:main::@1->malloc#0] -- register_copy
jsr malloc
// byte* buf2 = malloc()
// [5] malloc::return#1 = malloc::return#2
// main::@2
// [6] main::buf2#0 = (char *)malloc::return#1
// *buf1 = 'a'
// [7] *main::buf1#0 = 'a' -- _deref_pbuz1=vbuc1
lda #'a'
ldy #0
sta (buf1),y
// *buf2 = 'b'
// [8] *main::buf2#0 = 'b' -- _deref_pbuz1=vbuc1
lda #'b'
sta (buf2),y
// SCREEN[0] = *buf1
// [9] *SCREEN = *main::buf1#0 -- _deref_pbuc1=_deref_pbuz1
lda (buf1),y
sta SCREEN
// SCREEN[1] = *buf2
// [10] *(SCREEN+1) = *main::buf2#0 -- _deref_pbuc1=_deref_pbuz1
lda (buf2),y
sta SCREEN+1
// main::@return
// }
// [11] return
rts
}
// malloc
malloc: {
.label return = 6
.label return_1 = 4
// heap_head++;
// [13] heap_head#12 = ++ heap_head#11 -- pbuz1=_inc_pbuz1
inc.z heap_head
bne !+
inc.z heap_head+1
!:
// return heap_head;
// [14] malloc::return#2 = (void *)heap_head#12 -- pvoz1=pvoz2
lda.z heap_head
sta.z return_1
lda.z heap_head+1
sta.z return_1+1
// malloc::@return
// }
// [15] return
rts
}
// File Data