1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-18 04:08:58 +00:00
kickc/src/test/ref/string-const-consolidation-noroot.log

662 lines
20 KiB
Plaintext

Warning! Adding boolean cast to non-boolean condition *((byte*) print::string)
Culled Empty Block (label) @1
Culled Empty Block (label) print::@4
Culled Empty Block (label) print::@3
Culled Empty Block (label) print::@5
Culled Empty Block (label) print::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte*) screen#0 ← ((byte*)) (number) $400
to:@2
(void()) main()
main: scope:[main] from @2
(byte*) screen#15 ← phi( @2/(byte*) screen#17 )
(byte*) print::string#0 ← (const byte*) main::rex1
call print
to:main::@1
main::@1: scope:[main] from main
(byte*) screen#8 ← phi( main/(byte*) screen#6 )
(byte*) screen#1 ← (byte*) screen#8
(byte*) print::string#1 ← (const byte*) main::rex2
call print
to:main::@2
main::@2: scope:[main] from main::@1
(byte*) screen#9 ← phi( main::@1/(byte*) screen#6 )
(byte*) screen#2 ← (byte*) screen#9
(byte*) print::string#2 ← (const string) main::string
call print
to:main::@3
main::@3: scope:[main] from main::@2
(byte*) screen#10 ← phi( main::@2/(byte*) screen#6 )
(byte*) screen#3 ← (byte*) screen#10
to:main::@return
main::@return: scope:[main] from main::@3
(byte*) screen#11 ← phi( main::@3/(byte*) screen#3 )
(byte*) screen#4 ← (byte*) screen#11
return
to:@return
(void()) print((byte*) print::string)
print: scope:[print] from main main::@1 main::@2
(byte*) screen#18 ← phi( main/(byte*) screen#15 main::@1/(byte*) screen#1 main::@2/(byte*) screen#2 )
(byte*) print::string#6 ← phi( main/(byte*) print::string#0 main::@1/(byte*) print::string#1 main::@2/(byte*) print::string#2 )
to:print::@1
print::@1: scope:[print] from print print::@2
(byte*) screen#16 ← phi( print/(byte*) screen#18 print::@2/(byte*) screen#5 )
(byte*) print::string#4 ← phi( print/(byte*) print::string#6 print::@2/(byte*) print::string#3 )
(bool~) print::$0 ← (number) 0 != *((byte*) print::string#4)
if((bool~) print::$0) goto print::@2
to:print::@return
print::@2: scope:[print] from print::@1
(byte*) screen#12 ← phi( print::@1/(byte*) screen#16 )
(byte*) print::string#5 ← phi( print::@1/(byte*) print::string#4 )
*((byte*) screen#12) ← *((byte*) print::string#5)
(byte*) screen#5 ← ++ (byte*) screen#12
(byte*) print::string#3 ← ++ (byte*) print::string#5
to:print::@1
print::@return: scope:[print] from print::@1
(byte*) screen#13 ← phi( print::@1/(byte*) screen#16 )
(byte*) screen#6 ← (byte*) screen#13
return
to:@return
@2: scope:[] from @begin
(byte*) screen#17 ← phi( @begin/(byte*) screen#0 )
call main
to:@3
@3: scope:[] from @2
(byte*) screen#14 ← phi( @2/(byte*) screen#4 )
(byte*) screen#7 ← (byte*) screen#14
to:@end
@end: scope:[] from @3
SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(const byte*) main::rex1 = (string) "rex"
(const byte*) main::rex2 = (string) "rex"
(const string) main::string = (string) "rex"
(void()) print((byte*) print::string)
(bool~) print::$0
(label) print::@1
(label) print::@2
(label) print::@return
(byte*) print::string
(byte*) print::string#0
(byte*) print::string#1
(byte*) print::string#2
(byte*) print::string#3
(byte*) print::string#4
(byte*) print::string#5
(byte*) print::string#6
(byte*) screen
(byte*) screen#0
(byte*) screen#1
(byte*) screen#10
(byte*) screen#11
(byte*) screen#12
(byte*) screen#13
(byte*) screen#14
(byte*) screen#15
(byte*) screen#16
(byte*) screen#17
(byte*) screen#18
(byte*) screen#2
(byte*) screen#3
(byte*) screen#4
(byte*) screen#5
(byte*) screen#6
(byte*) screen#7
(byte*) screen#8
(byte*) screen#9
Adding number conversion cast (unumber) 0 in (bool~) print::$0 ← (number) 0 != *((byte*) print::string#4)
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) screen#1 = (byte*) screen#8
Alias (byte*) screen#2 = (byte*) screen#9
Alias (byte*) screen#10 = (byte*) screen#3 (byte*) screen#11 (byte*) screen#4
Alias (byte*) print::string#4 = (byte*) print::string#5
Alias (byte*) screen#12 = (byte*) screen#16 (byte*) screen#13 (byte*) screen#6
Alias (byte*) screen#0 = (byte*) screen#17
Alias (byte*) screen#14 = (byte*) screen#7
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) screen#15 (byte*) screen#0
Identical Phi Values (byte*) screen#1 (byte*) screen#12
Identical Phi Values (byte*) screen#2 (byte*) screen#12
Identical Phi Values (byte*) screen#10 (byte*) screen#12
Identical Phi Values (byte*) screen#14 (byte*) screen#10
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) print::$0 [20] if((byte) 0!=*((byte*) print::string#4)) goto print::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) screen#0 = (byte*) 1024
Constant (const byte*) print::string#0 = main::rex1
Constant (const byte*) print::string#1 = main::rex2
Constant (const byte*) print::string#2 = main::string
Successful SSA optimization Pass2ConstantIdentification
Successful SSA optimization Pass2ConstantStringConsolidation
Inlining constant with var siblings (const byte*) print::string#0
Inlining constant with var siblings (const byte*) print::string#1
Inlining constant with var siblings (const byte*) print::string#2
Inlining constant with var siblings (const byte*) screen#0
Constant inlined print::string#0 = (const byte*) main::rex1
Constant inlined print::string#1 = (const byte*) main::rex1
Constant inlined print::string#2 = (const byte*) main::rex1
Constant inlined main::rex2 = (const byte*) main::rex1
Constant inlined screen#0 = (byte*) 1024
Constant inlined main::string = (const byte*) main::rex1
Successful SSA optimization Pass2ConstantInlining
Identical Phi Values (byte*) print::string#6 (const byte*) main::rex1
Successful SSA optimization Pass2IdenticalPhiElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [] to main:2
Calls in [main] to print:6 print:8 print:10
Created 3 initial phi equivalence classes
Coalesced [7] screen#19 ← screen#12
Coalesced (already) [9] screen#20 ← screen#12
Coalesced (already) [14] screen#21 ← screen#18
Coalesced [21] print::string#7 ← print::string#3
Coalesced [22] screen#22 ← screen#5
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Renumbering block @2 to @1
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
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
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()
[5] call print
to:main::@1
main::@1: scope:[main] from main
[6] phi()
[7] call print
to:main::@2
main::@2: scope:[main] from main::@1
[8] phi()
[9] call print
to:main::@return
main::@return: scope:[main] from main::@2
[10] return
to:@return
(void()) print((byte*) print::string)
print: scope:[print] from main main::@1 main::@2
[11] (byte*) screen#18 ← phi( main/(byte*) 1024 main::@1/(byte*) screen#12 main::@2/(byte*) screen#12 )
to:print::@1
print::@1: scope:[print] from print print::@2
[12] (byte*) screen#12 ← phi( print/(byte*) screen#18 print::@2/(byte*) screen#5 )
[12] (byte*) print::string#4 ← phi( print/(const byte*) main::rex1 print::@2/(byte*) print::string#3 )
[13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2
to:print::@return
print::@return: scope:[print] from print::@1
[14] return
to:@return
print::@2: scope:[print] from print::@1
[15] *((byte*) screen#12) ← *((byte*) print::string#4)
[16] (byte*) screen#5 ← ++ (byte*) screen#12
[17] (byte*) print::string#3 ← ++ (byte*) print::string#4
to:print::@1
VARIABLE REGISTER WEIGHTS
(void()) main()
(void()) print((byte*) print::string)
(byte*) print::string
(byte*) print::string#3 22.0
(byte*) print::string#4 11.0
(byte*) screen
(byte*) screen#12 4.875
(byte*) screen#18 6.0
(byte*) screen#5 11.0
Initial phi equivalence classes
[ screen#18 screen#12 screen#5 ]
[ print::string#4 print::string#3 ]
Complete equivalence classes
[ screen#18 screen#12 screen#5 ]
[ print::string#4 print::string#3 ]
Allocated zp[2]:2 [ screen#18 screen#12 screen#5 ]
Allocated zp[2]:4 [ print::string#4 print::string#3 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Tests that identical strings are consolidated
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label screen = 2
// @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] call print
// [11] phi from main to print [phi:main->print]
print_from_main:
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print
// [11] phi from main::@1 to print [phi:main::@1->print]
print_from___b1:
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
jsr print
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
jmp __b2
// main::@2
__b2:
// [9] call print
// [11] phi from main::@2 to print [phi:main::@2->print]
print_from___b2:
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
jsr print
jmp __breturn
// main::@return
__breturn:
// [10] return
rts
rex1: .text "rex"
.byte 0
}
// print
// print(byte* zeropage(4) string)
print: {
.label string = 4
// [12] phi from print to print::@1 [phi:print->print::@1]
__b1_from_print:
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (const byte*) main::rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
lda #<main.rex1
sta.z string
lda #>main.rex1
sta.z string+1
jmp __b1
// print::@1
__b1:
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
ldy #0
lda (string),y
cmp #0
bne __b2
jmp __breturn
// print::@return
__breturn:
// [14] return
rts
// print::@2
__b2:
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (string),y
ldy #0
sta (screen),y
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
inc.z screen
bne !+
inc.z screen+1
!:
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
inc.z string
bne !+
inc.z string+1
!:
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
__b1_from___b2:
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 [ screen#12 print::string#4 ] ( main:2::print:5 [ screen#12 print::string#4 ] main:2::print:7 [ screen#12 print::string#4 ] main:2::print:9 [ screen#12 print::string#4 ] ) always clobbers reg byte a reg byte y
Statement [15] *((byte*) screen#12) ← *((byte*) print::string#4) [ screen#12 print::string#4 ] ( main:2::print:5 [ screen#12 print::string#4 ] main:2::print:7 [ screen#12 print::string#4 ] main:2::print:9 [ screen#12 print::string#4 ] ) always clobbers reg byte a reg byte y
Potential registers zp[2]:2 [ screen#18 screen#12 screen#5 ] : zp[2]:2 ,
Potential registers zp[2]:4 [ print::string#4 print::string#3 ] : zp[2]:4 ,
REGISTER UPLIFT SCOPES
Uplift Scope [print] 33: zp[2]:4 [ print::string#4 print::string#3 ]
Uplift Scope [] 21.88: zp[2]:2 [ screen#18 screen#12 screen#5 ]
Uplift Scope [main]
Uplifting [print] best 776 combination zp[2]:4 [ print::string#4 print::string#3 ]
Uplifting [] best 776 combination zp[2]:2 [ screen#18 screen#12 screen#5 ]
Uplifting [main] best 776 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Tests that identical strings are consolidated
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label screen = 2
// @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] call print
// [11] phi from main to print [phi:main->print]
print_from_main:
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print
// [11] phi from main::@1 to print [phi:main::@1->print]
print_from___b1:
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
jsr print
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
__b2_from___b1:
jmp __b2
// main::@2
__b2:
// [9] call print
// [11] phi from main::@2 to print [phi:main::@2->print]
print_from___b2:
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
jsr print
jmp __breturn
// main::@return
__breturn:
// [10] return
rts
rex1: .text "rex"
.byte 0
}
// print
// print(byte* zeropage(4) string)
print: {
.label string = 4
// [12] phi from print to print::@1 [phi:print->print::@1]
__b1_from_print:
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (const byte*) main::rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
lda #<main.rex1
sta.z string
lda #>main.rex1
sta.z string+1
jmp __b1
// print::@1
__b1:
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
ldy #0
lda (string),y
cmp #0
bne __b2
jmp __breturn
// print::@return
__breturn:
// [14] return
rts
// print::@2
__b2:
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (string),y
ldy #0
sta (screen),y
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
inc.z screen
bne !+
inc.z screen+1
!:
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
inc.z string
bne !+
inc.z string+1
!:
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
__b1_from___b2:
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from_main:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __b1_from_print:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(const byte*) main::rex1 = (string) "rex"
(void()) print((byte*) print::string)
(label) print::@1
(label) print::@2
(label) print::@return
(byte*) print::string
(byte*) print::string#3 string zp[2]:4 22.0
(byte*) print::string#4 string zp[2]:4 11.0
(byte*) screen
(byte*) screen#12 screen zp[2]:2 4.875
(byte*) screen#18 screen zp[2]:2 6.0
(byte*) screen#5 screen zp[2]:2 11.0
zp[2]:2 [ screen#18 screen#12 screen#5 ]
zp[2]:4 [ print::string#4 print::string#3 ]
FINAL ASSEMBLER
Score: 675
// File Comments
// Tests that identical strings are consolidated
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label screen = 2
// @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: {
// print(rex1)
// [5] call print
// [11] phi from main to print [phi:main->print]
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
jsr print
// [6] phi from main to main::@1 [phi:main->main::@1]
// main::@1
// print(rex2)
// [7] call print
// [11] phi from main::@1 to print [phi:main::@1->print]
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
jsr print
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
// main::@2
// print("rex")
// [9] call print
// [11] phi from main::@2 to print [phi:main::@2->print]
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
jsr print
// main::@return
// }
// [10] return
rts
rex1: .text "rex"
.byte 0
}
// print
// print(byte* zeropage(4) string)
print: {
.label string = 4
// [12] phi from print to print::@1 [phi:print->print::@1]
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (const byte*) main::rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
lda #<main.rex1
sta.z string
lda #>main.rex1
sta.z string+1
// print::@1
__b1:
// while(*string)
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
ldy #0
lda (string),y
cmp #0
bne __b2
// print::@return
// }
// [14] return
rts
// print::@2
__b2:
// *screen++ = *string++
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (string),y
sta (screen),y
// *screen++ = *string++;
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
inc.z screen
bne !+
inc.z screen+1
!:
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
inc.z string
bne !+
inc.z string+1
!:
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
jmp __b1
}
// File Data