1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-21 02:24:34 +00:00
kickc/src/test/ref/malloc-0.log

578 lines
18 KiB
Plaintext

Fixing pointer addition (word*~) bsearch16u::$7 ← (word*) bsearch16u::items + (byte~) bsearch16u::$6
Fixing pointer addition (word*~) bsearch16u::$15 ← (word*) bsearch16u::pivot + (number) 1
Fixing pointer addition (word*~) bsearch16u::$1 ← (word*) bsearch16u::items - (number) 1
Fixing pointer array-indexing *((word*) utoa::digit_values + (byte) utoa::digit)
Fixing pointer array-indexing *((dword*) ultoa::digit_values + (byte) ultoa::digit)
Warning! Adding boolean cast to non-boolean condition *((byte*) strcpy::src)
Identified constant variable (byte*) HEAP_TOP
Culled Empty Block (label) @1
Culled Empty Block (label) @2
Culled Empty Block (label) @3
Culled Empty Block (label) malloc::@1
Culled Empty Block (label) @5
Culled Empty Block (label) @6
Culled Empty Block (label) @7
Culled Empty Block (label) @8
Culled Empty Block (label) @9
Culled Empty Block (label) @10
Culled Empty Block (label) @11
Culled Empty Block (label) main::@2
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@4
@4: scope:[] from @begin
(byte*) HEAP_TOP#0 ← ((byte*)) (number) $a000
(byte*) heap_head#0 ← (byte*) HEAP_TOP#0
to:@12
malloc: scope:[malloc] from @12
(word) malloc::size#1 ← phi( @12/(word) malloc::size#0 )
(byte*) heap_head#4 ← phi( @12/(byte*) heap_head#7 )
(byte*~) malloc::$0 ← (byte*) heap_head#4 - (word) malloc::size#1
(byte*) malloc::mem#0 ← (byte*~) malloc::$0
(byte*) heap_head#1 ← (byte*) malloc::mem#0
(void*) malloc::return#0 ← ((void*)) (byte*) malloc::mem#0
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
(byte*) heap_head#5 ← phi( malloc/(byte*) heap_head#1 )
(void*) malloc::return#3 ← phi( malloc/(void*) malloc::return#0 )
(void*) malloc::return#1 ← (void*) malloc::return#3
(byte*) heap_head#2 ← (byte*) heap_head#5
return
to:@return
@12: scope:[] from @4
(byte*) heap_head#7 ← phi( @4/(byte*) heap_head#0 )
(word) malloc::size#0 ← (number) $100
call malloc
(void*) malloc::return#2 ← (void*) malloc::return#1
to:@14
@14: scope:[] from @12
(byte*) heap_head#6 ← phi( @12/(byte*) heap_head#2 )
(void*) malloc::return#4 ← phi( @12/(void*) malloc::return#2 )
(void*~) $0 ← (void*) malloc::return#4
(byte*) heap_head#3 ← (byte*) heap_head#6
(byte*) BYTES#0 ← ((byte*)) (void*~) $0
to:@13
main: scope:[main] from @13
(byte*) BYTES#2 ← phi( @13/(byte*) BYTES#3 )
(byte) main::i#0 ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@1
(byte*) BYTES#1 ← phi( main/(byte*) BYTES#2 main::@1/(byte*) BYTES#1 )
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
*((byte*) BYTES#1 + (byte) main::i#2) ← (byte) main::i#2
(byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$ff)
(bool~) main::$0 ← (byte) main::i#1 != rangelast(0,$ff)
if((bool~) main::$0) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
return
to:@return
@13: scope:[] from @14
(byte*) BYTES#3 ← phi( @14/(byte*) BYTES#0 )
call main
to:@15
@15: scope:[] from @13
to:@end
@end: scope:[] from @15
SYMBOL TABLE SSA
(void*~) $0
(label) @12
(label) @13
(label) @14
(label) @15
(label) @4
(label) @begin
(label) @end
(byte*) BYTES
(byte*) BYTES#0
(byte*) BYTES#1
(byte*) BYTES#2
(byte*) BYTES#3
(byte*) HEAP_TOP
(byte*) HEAP_TOP#0
(const byte) RADIX::BINARY = (number) 2
(const byte) RADIX::DECIMAL = (number) $a
(const byte) RADIX::HEXADECIMAL = (number) $10
(const byte) RADIX::OCTAL = (number) 8
(byte*) heap_head
(byte*) heap_head#0
(byte*) heap_head#1
(byte*) heap_head#2
(byte*) heap_head#3
(byte*) heap_head#4
(byte*) heap_head#5
(byte*) heap_head#6
(byte*) heap_head#7
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(void*()) malloc((word) malloc::size)
(byte*~) malloc::$0
(label) malloc::@return
(byte*) malloc::mem
(byte*) malloc::mem#0
(void*) malloc::return
(void*) malloc::return#0
(void*) malloc::return#1
(void*) malloc::return#2
(void*) malloc::return#3
(void*) malloc::return#4
(word) malloc::size
(word) malloc::size#0
(word) malloc::size#1
Adding number conversion cast (unumber) $100 in (word) malloc::size#0 ← (number) $100
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) HEAP_TOP#0 ← (byte*)(number) $a000
Inlining cast (void*) malloc::return#0 ← (void*)(byte*) malloc::mem#0
Inlining cast (word) malloc::size#0 ← (unumber)(number) $100
Inlining cast (byte*) BYTES#0 ← (byte*)(void*~) $0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 40960
Simplifying constant integer cast $100
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $100
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) HEAP_TOP#0 = (byte*) heap_head#0 (byte*) heap_head#7
Alias (byte*) malloc::mem#0 = (byte*~) malloc::$0
Alias (void*) malloc::return#0 = (void*) malloc::return#3 (void*) malloc::return#1
Alias (byte*) heap_head#1 = (byte*) heap_head#5 (byte*) heap_head#2
Alias (void*) malloc::return#2 = (void*) malloc::return#4
Alias (byte*) heap_head#3 = (byte*) heap_head#6
Alias (byte*) BYTES#0 = (byte*) BYTES#3
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) heap_head#4 (byte*) HEAP_TOP#0
Identical Phi Values (word) malloc::size#1 (word) malloc::size#0
Identical Phi Values (byte*) heap_head#3 (byte*) heap_head#1
Identical Phi Values (byte*) BYTES#2 (byte*) BYTES#0
Identical Phi Values (byte*) BYTES#1 (byte*) BYTES#2
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$0 [25] if((byte) main::i#1!=rangelast(0,$ff)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) HEAP_TOP#0 = (byte*) 40960
Constant (const word) malloc::size#0 = $100
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [23] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [25] if(main::i#1!=rangelast(0,$ff)) goto main::@1 to (number) 0
Eliminating unused variable (byte*) heap_head#1 and assignment [1] (byte*) heap_head#1 ← (byte*) malloc::mem#0
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) 0 in if((byte) main::i#1!=(number) 0) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant right-side identified [0] (byte*) malloc::mem#0 ← (const byte*) HEAP_TOP#0 - (const word) malloc::size#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) malloc::mem#0 = HEAP_TOP#0-malloc::size#0
Successful SSA optimization Pass2ConstantIdentification
Constant value identified (void*)malloc::mem#0 in [1] (void*) malloc::return#0 ← (void*)(const byte*) malloc::mem#0
Successful SSA optimization Pass2ConstantValues
Constant (const void*) malloc::return#0 = (void*)malloc::mem#0
Successful SSA optimization Pass2ConstantIdentification
Constant (const void*) malloc::return#2 = malloc::return#0
Successful SSA optimization Pass2ConstantIdentification
Constant (const void*) $0 = malloc::return#2
Successful SSA optimization Pass2ConstantIdentification
Constant value identified (byte*)$0 in [5] (byte*) BYTES#0 ← (byte*)(const void*) $0
Successful SSA optimization Pass2ConstantValues
Constant (const byte*) BYTES#0 = (byte*)$0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with different constant siblings (const void*) malloc::return#2
Inlining constant with var siblings (const byte) main::i#0
Constant inlined $0 = (const void*) malloc::return#0
Constant inlined main::i#0 = (byte) 0
Constant inlined malloc::return#2 = (const void*) malloc::return#0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @4
Adding NOP phi() at start of @12
Adding NOP phi() at start of @14
Adding NOP phi() at start of @13
Adding NOP phi() at start of @15
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of malloc
CALL GRAPH
Calls in [] to malloc:3 main:6
Created 1 initial phi equivalence classes
Coalesced [15] main::i#3 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) @14
Culled Empty Block (label) @15
Culled Empty Block (label) main::@3
Renumbering block @12 to @1
Renumbering block @13 to @2
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
Adding NOP phi() at start of malloc
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call malloc
to:@2
@2: scope:[] from @1
[3] phi()
[4] call main
to:@end
@end: scope:[] from @2
[5] phi()
main: scope:[main] from @2
[6] phi()
to:main::@1
main::@1: scope:[main] from main main::@1
[7] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
[8] *((const byte*) BYTES#0 + (byte) main::i#2) ← (byte) main::i#2
[9] (byte) main::i#1 ← ++ (byte) main::i#2
[10] if((byte) main::i#1!=(byte) 0) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[11] return
to:@return
malloc: scope:[malloc] from @1
[12] phi()
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
[13] return
to:@return
VARIABLE REGISTER WEIGHTS
(byte*) BYTES
(byte*) HEAP_TOP
(byte*) heap_head
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 22.0
(void*()) malloc((word) malloc::size)
(byte*) malloc::mem
(void*) malloc::return
(word) malloc::size
Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Experiments with malloc() - a byte array
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// Top of the heap used by malloc()
.label HEAP_TOP = $a000
.label BYTES = malloc.return
// @begin
bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
// @1
b1:
// [2] call malloc
// [12] phi from @1 to malloc [phi:@1->malloc]
malloc_from_b1:
jsr malloc
// [3] phi from @1 to @2 [phi:@1->@2]
b2_from_b1:
jmp b2
// @2
b2:
// [4] call main
// [6] phi from @2 to main [phi:@2->main]
main_from_b2:
jsr main
// [5] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
jmp bend
// @end
bend:
// main
main: {
.label i = 2
// [7] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
// [7] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta.z i
jmp b1
// [7] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
// [7] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
// main::@1
b1:
// [8] *((const byte*) BYTES#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta BYTES,y
// [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
inc.z i
// [10] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuz1_neq_0_then_la1
lda.z i
cmp #0
bne b1_from_b1
jmp breturn
// main::@return
breturn:
// [11] return
rts
}
// malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
.const size = $100
.label mem = HEAP_TOP-size
.label return = mem
jmp breturn
// malloc::@return
breturn:
// [13] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 38.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Uplift Scope [malloc]
Uplift Scope [RADIX]
Uplift Scope []
Uplifting [main] best 308 combination reg byte x [ main::i#2 main::i#1 ]
Uplifting [malloc] best 308 combination
Uplifting [RADIX] best 308 combination
Uplifting [] best 308 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Experiments with malloc() - a byte array
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// Top of the heap used by malloc()
.label HEAP_TOP = $a000
.label BYTES = malloc.return
// @begin
bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
// @1
b1:
// [2] call malloc
// [12] phi from @1 to malloc [phi:@1->malloc]
malloc_from_b1:
jsr malloc
// [3] phi from @1 to @2 [phi:@1->@2]
b2_from_b1:
jmp b2
// @2
b2:
// [4] call main
// [6] phi from @2 to main [phi:@2->main]
main_from_b2:
jsr main
// [5] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
jmp bend
// @end
bend:
// main
main: {
// [7] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
// [7] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
jmp b1
// [7] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
// [7] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
// main::@1
b1:
// [8] *((const byte*) BYTES#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx
txa
sta BYTES,x
// [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
// [10] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuxx_neq_0_then_la1
cpx #0
bne b1_from_b1
jmp breturn
// main::@return
breturn:
// [11] return
rts
}
// malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
.const size = $100
.label mem = HEAP_TOP-size
.label return = mem
jmp breturn
// malloc::@return
breturn:
// [13] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction malloc_from_b1:
Removing instruction b2_from_b1:
Removing instruction main_from_b2:
Removing instruction bend_from_b2:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b2:
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block
Succesful ASM optimization Pass5AddMainRts
Removing instruction jmp b1
Succesful ASM optimization Pass5NextJumpElimination
FINAL SYMBOL TABLE
(label) @1
(label) @2
(label) @begin
(label) @end
(byte*) BYTES
(const byte*) BYTES#0 BYTES = (byte*)(const void*) malloc::return#0
(byte*) HEAP_TOP
(const byte*) HEAP_TOP#0 HEAP_TOP = (byte*) 40960
(const byte) RADIX::BINARY BINARY = (number) 2
(const byte) RADIX::DECIMAL DECIMAL = (number) $a
(const byte) RADIX::HEXADECIMAL HEXADECIMAL = (number) $10
(const byte) RADIX::OCTAL OCTAL = (number) 8
(byte*) heap_head
(void()) main()
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 22.0
(void*()) malloc((word) malloc::size)
(label) malloc::@return
(byte*) malloc::mem
(const byte*) malloc::mem#0 mem = (const byte*) HEAP_TOP#0-(const word) malloc::size#0
(void*) malloc::return
(const void*) malloc::return#0 return = (void*)(const byte*) malloc::mem#0
(word) malloc::size
(const word) malloc::size#0 size = (word) $100
reg byte x [ main::i#2 main::i#1 ]
FINAL ASSEMBLER
Score: 185
// File Comments
// Experiments with malloc() - a byte array
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
// Top of the heap used by malloc()
.label HEAP_TOP = $a000
.label BYTES = malloc.return
// @begin
bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// malloc(0x100)
// [2] call malloc
// [12] phi from @1 to malloc [phi:@1->malloc]
jsr malloc
// [3] phi from @1 to @2 [phi:@1->@2]
// @2
// [4] call main
// [6] phi from @2 to main [phi:@2->main]
jsr main
rts
// [5] phi from @2 to @end [phi:@2->@end]
// @end
// main
main: {
// [7] phi from main to main::@1 [phi:main->main::@1]
// [7] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
// [7] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
// [7] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
// main::@1
b1:
// BYTES[i] = i
// [8] *((const byte*) BYTES#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx
txa
sta BYTES,x
// for( byte i: 0..255)
// [9] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
// [10] if((byte) main::i#1!=(byte) 0) goto main::@1 -- vbuxx_neq_0_then_la1
cpx #0
bne b1
// main::@return
// }
// [11] return
rts
}
// malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
.const size = $100
.label mem = HEAP_TOP-size
.label return = mem
// malloc::@return
// [13] return
rts
}
// File Data