1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-26 18:29:54 +00:00

Fixed test data.

This commit is contained in:
jespergravgaard 2021-01-23 13:10:14 +01:00
parent 9250e346be
commit 5ddc33ceea
5 changed files with 1014 additions and 1 deletions

View File

@ -3553,7 +3553,7 @@ public class TestPrograms {
@Test
public void testStringConstConsolidationRoot() throws IOException, URISyntaxException {
compileAndCompare("string-const-consolidation-root.c", log());
compileAndCompare("string-const-consolidation-root.c");
}
@Test

View File

@ -0,0 +1,103 @@
// Tests that multiple different identical strings are consolidated to a root variable
// Commodore 64 PRG executable file
.file [name="string-const-consolidation-root.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)
.label screen = 2
.segment Code
main: {
// print1()
jsr print1
// print2()
jsr print2
// }
rts
}
print1: {
// print("string1")
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// print("string2")
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// print(s)
lda #<s
sta.z print.s
lda #>s
sta.z print.s+1
jsr print
// }
rts
}
print2: {
// print("string1")
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// print("string2")
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// print(s1)
lda #<s1
sta.z print.s
lda #>s1
sta.z print.s+1
jsr print
// }
rts
}
// print(byte* zp(4) s)
print: {
.label s = 4
__b1:
// while(*s)
ldy #0
lda (s),y
cmp #0
bne __b2
// }
rts
__b2:
// *screen++ = *s++
ldy #0
lda (s),y
sta (screen),y
// *screen++ = *s++;
inc.z screen
bne !+
inc.z screen+1
!:
inc.z s
bne !+
inc.z s+1
!:
jmp __b1
}
.segment Data
s: .text "string3"
.byte 0
s1: .text "string4"
.byte 0
string_0: .text "string1"
.byte 0
string_1: .text "string2"
.byte 0

View File

@ -0,0 +1,66 @@
void main()
main: scope:[main] from
[0] phi()
[1] call print1
to:main::@1
main::@1: scope:[main] from main
[2] phi()
[3] call print2
to:main::@return
main::@return: scope:[main] from main::@1
[4] return
to:@return
void print1()
print1: scope:[print1] from main
[5] phi()
[6] call print
to:print1::@1
print1::@1: scope:[print1] from print1
[7] phi()
[8] call print
to:print1::@2
print1::@2: scope:[print1] from print1::@1
[9] phi()
[10] call print
to:print1::@return
print1::@return: scope:[print1] from print1::@2
[11] return
to:@return
void print2()
print2: scope:[print2] from main::@1
[12] phi()
[13] call print
to:print2::@1
print2::@1: scope:[print2] from print2
[14] phi()
[15] call print
to:print2::@2
print2::@2: scope:[print2] from print2::@1
[16] phi()
[17] call print
to:print2::@return
print2::@return: scope:[print2] from print2::@2
[18] return
to:@return
void print(byte* print::s)
print: scope:[print] from print1 print1::@1 print1::@2 print2 print2::@1 print2::@2
[19] screen#36 = phi( print1/(byte*) 1024, print1::@1/screen#12, print1::@2/screen#12, print2/screen#12, print2::@1/screen#12, print2::@2/screen#12 )
[19] print::s#9 = phi( print1/string_0, print1::@1/string_1, print1::@2/s, print2/string_0, print2::@1/string_1, print2::@2/s1 )
to:print::@1
print::@1: scope:[print] from print print::@2
[20] screen#12 = phi( print/screen#36, print::@2/screen#11 )
[20] print::s#7 = phi( print/print::s#9, print::@2/print::s#6 )
[21] if(0!=*print::s#7) goto print::@2
to:print::@return
print::@return: scope:[print] from print::@1
[22] return
to:@return
print::@2: scope:[print] from print::@1
[23] *screen#12 = *print::s#7
[24] screen#11 = ++ screen#12
[25] print::s#6 = ++ print::s#7
to:print::@1

View File

@ -0,0 +1,825 @@
Inlined call call __init
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start::@1
screen#31 = phi( __start::@1/screen#35 )
call print1
to:main::@1
main::@1: scope:[main] from main
screen#16 = phi( main/screen#6 )
screen#0 = screen#16
call print2
to:main::@2
main::@2: scope:[main] from main::@1
screen#17 = phi( main::@1/screen#10 )
screen#1 = screen#17
to:main::@return
main::@return: scope:[main] from main::@2
screen#18 = phi( main::@2/screen#1 )
screen#2 = screen#18
return
to:@return
void print1()
print1: scope:[print1] from main
screen#32 = phi( main/screen#31 )
print::s#0 = print1::s
call print
to:print1::@1
print1::@1: scope:[print1] from print1
screen#19 = phi( print1/screen#12 )
screen#3 = screen#19
print::s#1 = print1::s1
call print
to:print1::@2
print1::@2: scope:[print1] from print1::@1
screen#20 = phi( print1::@1/screen#12 )
screen#4 = screen#20
print::s#2 = s
call print
to:print1::@3
print1::@3: scope:[print1] from print1::@2
screen#21 = phi( print1::@2/screen#12 )
screen#5 = screen#21
to:print1::@return
print1::@return: scope:[print1] from print1::@3
screen#22 = phi( print1::@3/screen#5 )
screen#6 = screen#22
return
to:@return
void print2()
print2: scope:[print2] from main::@1
screen#33 = phi( main::@1/screen#0 )
print::s#3 = print2::s
call print
to:print2::@1
print2::@1: scope:[print2] from print2
screen#23 = phi( print2/screen#12 )
screen#7 = screen#23
print::s#4 = print2::s1
call print
to:print2::@2
print2::@2: scope:[print2] from print2::@1
screen#24 = phi( print2::@1/screen#12 )
screen#8 = screen#24
print::s#5 = s1
call print
to:print2::@3
print2::@3: scope:[print2] from print2::@2
screen#25 = phi( print2::@2/screen#12 )
screen#9 = screen#25
to:print2::@return
print2::@return: scope:[print2] from print2::@3
screen#26 = phi( print2::@3/screen#9 )
screen#10 = screen#26
return
to:@return
void print(byte* print::s)
print: scope:[print] from print1 print1::@1 print1::@2 print2 print2::@1 print2::@2
screen#36 = phi( print1/screen#32, print1::@1/screen#3, print1::@2/screen#4, print2/screen#33, print2::@1/screen#7, print2::@2/screen#8 )
print::s#9 = phi( print1/print::s#0, print1::@1/print::s#1, print1::@2/print::s#2, print2/print::s#3, print2::@1/print::s#4, print2::@2/print::s#5 )
to:print::@1
print::@1: scope:[print] from print print::@2
screen#34 = phi( print/screen#36, print::@2/screen#11 )
print::s#7 = phi( print/print::s#9, print::@2/print::s#6 )
print::$0 = 0 != *print::s#7
if(print::$0) goto print::@2
to:print::@return
print::@2: scope:[print] from print::@1
screen#27 = phi( print::@1/screen#34 )
print::s#8 = phi( print::@1/print::s#7 )
*screen#27 = *print::s#8
screen#11 = ++ screen#27
print::s#6 = ++ print::s#8
to:print::@1
print::@return: scope:[print] from print::@1
screen#28 = phi( print::@1/screen#34 )
screen#12 = screen#28
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
screen#13 = (byte*)$400
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
screen#35 = phi( __start::__init1/screen#13 )
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
screen#29 = phi( __start::@1/screen#2 )
screen#14 = screen#29
to:__start::@return
__start::@return: scope:[__start] from __start::@2
screen#30 = phi( __start::@2/screen#14 )
screen#15 = screen#30
return
to:@return
SYMBOL TABLE SSA
void __start()
void main()
void print(byte* print::s)
bool~ print::$0
byte* print::s
byte* print::s#0
byte* print::s#1
byte* print::s#2
byte* print::s#3
byte* print::s#4
byte* print::s#5
byte* print::s#6
byte* print::s#7
byte* print::s#8
byte* print::s#9
void print1()
const byte* print1::s[8] = "string1"
const byte* print1::s1[8] = "string2"
void print2()
const byte* print2::s[8] = "string1"
const byte* print2::s1[8] = "string2"
const byte* s = "string3"
const byte* s1 = "string4"
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#19
byte* screen#2
byte* screen#20
byte* screen#21
byte* screen#22
byte* screen#23
byte* screen#24
byte* screen#25
byte* screen#26
byte* screen#27
byte* screen#28
byte* screen#29
byte* screen#3
byte* screen#30
byte* screen#31
byte* screen#32
byte* screen#33
byte* screen#34
byte* screen#35
byte* screen#36
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 print::$0 = 0 != *print::s#7
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 0
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias screen#0 = screen#16
Alias screen#1 = screen#17 screen#18 screen#2
Alias screen#19 = screen#3
Alias screen#20 = screen#4
Alias screen#21 = screen#5 screen#22 screen#6
Alias screen#23 = screen#7
Alias screen#24 = screen#8
Alias screen#10 = screen#9 screen#25 screen#26
Alias print::s#7 = print::s#8
Alias screen#12 = screen#27 screen#34 screen#28
Alias screen#13 = screen#35
Alias screen#14 = screen#29 screen#30 screen#15
Successful SSA optimization Pass2AliasElimination
Identical Phi Values screen#31 screen#13
Identical Phi Values screen#0 screen#21
Identical Phi Values screen#1 screen#10
Identical Phi Values screen#32 screen#31
Identical Phi Values screen#19 screen#12
Identical Phi Values screen#20 screen#12
Identical Phi Values screen#21 screen#12
Identical Phi Values screen#33 screen#0
Identical Phi Values screen#23 screen#12
Identical Phi Values screen#24 screen#12
Identical Phi Values screen#10 screen#12
Identical Phi Values screen#14 screen#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition print::$0 [31] if(0!=*print::s#7) goto print::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant print::s#0 = print1::s
Constant print::s#1 = print1::s1
Constant print::s#2 = s
Constant print::s#3 = print2::s
Constant print::s#4 = print2::s1
Constant print::s#5 = s1
Constant screen#13 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Consolidated constant strings into string_0
Consolidated constant strings into string_1
Successful SSA optimization Pass2ConstantStringConsolidation
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 print::s#0
Inlining constant with var siblings print::s#1
Inlining constant with var siblings print::s#2
Inlining constant with var siblings print::s#3
Inlining constant with var siblings print::s#4
Inlining constant with var siblings print::s#5
Inlining constant with var siblings screen#13
Constant inlined print::s#0 = string_0
Constant inlined print1::s1 = string_1
Constant inlined print2::s1 = string_1
Constant inlined print::s#4 = string_1
Constant inlined print::s#3 = string_0
Constant inlined print::s#2 = s
Constant inlined print::s#1 = string_1
Constant inlined print2::s = string_0
Constant inlined screen#13 = (byte*) 1024
Constant inlined print::s#5 = s1
Constant inlined print1::s = string_0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of print1
Adding NOP phi() at start of print1::@3
Adding NOP phi() at start of print2::@3
CALL GRAPH
Calls in [main] to print1:1 print2:3
Calls in [print1] to print:7 print:9 print:11
Calls in [print2] to print:15 print:17 print:19
Created 4 initial phi equivalence classes
Coalesced [8] screen#37 = screen#12
Coalesced (already) [10] screen#38 = screen#12
Coalesced (already) [14] screen#39 = screen#12
Coalesced (already) [16] screen#40 = screen#12
Coalesced (already) [18] screen#41 = screen#12
Coalesced [23] print::s#10 = print::s#9
Coalesced (already) [24] screen#42 = screen#36
Coalesced [31] print::s#11 = print::s#6
Coalesced [32] screen#43 = screen#11
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@2
Culled Empty Block label print1::@3
Culled Empty Block label print2::@3
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of print1
Adding NOP phi() at start of print1::@1
Adding NOP phi() at start of print1::@2
Adding NOP phi() at start of print2
Adding NOP phi() at start of print2::@1
Adding NOP phi() at start of print2::@2
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call print1
to:main::@1
main::@1: scope:[main] from main
[2] phi()
[3] call print2
to:main::@return
main::@return: scope:[main] from main::@1
[4] return
to:@return
void print1()
print1: scope:[print1] from main
[5] phi()
[6] call print
to:print1::@1
print1::@1: scope:[print1] from print1
[7] phi()
[8] call print
to:print1::@2
print1::@2: scope:[print1] from print1::@1
[9] phi()
[10] call print
to:print1::@return
print1::@return: scope:[print1] from print1::@2
[11] return
to:@return
void print2()
print2: scope:[print2] from main::@1
[12] phi()
[13] call print
to:print2::@1
print2::@1: scope:[print2] from print2
[14] phi()
[15] call print
to:print2::@2
print2::@2: scope:[print2] from print2::@1
[16] phi()
[17] call print
to:print2::@return
print2::@return: scope:[print2] from print2::@2
[18] return
to:@return
void print(byte* print::s)
print: scope:[print] from print1 print1::@1 print1::@2 print2 print2::@1 print2::@2
[19] screen#36 = phi( print1/(byte*) 1024, print1::@1/screen#12, print1::@2/screen#12, print2/screen#12, print2::@1/screen#12, print2::@2/screen#12 )
[19] print::s#9 = phi( print1/string_0, print1::@1/string_1, print1::@2/s, print2/string_0, print2::@1/string_1, print2::@2/s1 )
to:print::@1
print::@1: scope:[print] from print print::@2
[20] screen#12 = phi( print/screen#36, print::@2/screen#11 )
[20] print::s#7 = phi( print/print::s#9, print::@2/print::s#6 )
[21] if(0!=*print::s#7) goto print::@2
to:print::@return
print::@return: scope:[print] from print::@1
[22] return
to:@return
print::@2: scope:[print] from print::@1
[23] *screen#12 = *print::s#7
[24] screen#11 = ++ screen#12
[25] print::s#6 = ++ print::s#7
to:print::@1
VARIABLE REGISTER WEIGHTS
void main()
void print(byte* print::s)
byte* print::s
byte* print::s#6 2002.0
byte* print::s#7 1026.25
byte* print::s#9 101.0
void print1()
void print2()
byte* screen
byte* screen#11 1001.0
byte* screen#12 185.8235294117647
byte* screen#36 156.0
Initial phi equivalence classes
[ screen#36 screen#12 screen#11 ]
[ print::s#7 print::s#9 print::s#6 ]
Complete equivalence classes
[ screen#36 screen#12 screen#11 ]
[ print::s#7 print::s#9 print::s#6 ]
Allocated zp[2]:2 [ screen#36 screen#12 screen#11 ]
Allocated zp[2]:4 [ print::s#7 print::s#9 print::s#6 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [21] if(0!=*print::s#7) goto print::@2 [ screen#12 print::s#7 ] ( print1:1::print:6 [ screen#12 print::s#7 ] { } print1:1::print:8 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print1:1::print:10 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:13 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:15 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:17 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } ) always clobbers reg byte a reg byte y
Statement [23] *screen#12 = *print::s#7 [ screen#12 print::s#7 ] ( print1:1::print:6 [ screen#12 print::s#7 ] { } print1:1::print:8 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print1:1::print:10 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:13 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:15 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } print2:3::print:17 [ screen#12 print::s#7 ] { { screen#12 = screen#36 } } ) always clobbers reg byte a reg byte y
Potential registers zp[2]:2 [ screen#36 screen#12 screen#11 ] : zp[2]:2 ,
Potential registers zp[2]:4 [ print::s#7 print::s#9 print::s#6 ] : zp[2]:4 ,
REGISTER UPLIFT SCOPES
Uplift Scope [print] 3,129.25: zp[2]:4 [ print::s#7 print::s#9 print::s#6 ]
Uplift Scope [] 1,342.82: zp[2]:2 [ screen#36 screen#12 screen#11 ]
Uplift Scope [main]
Uplift Scope [print1]
Uplift Scope [print2]
Uplifting [print] best 781 combination zp[2]:4 [ print::s#7 print::s#9 print::s#6 ]
Uplifting [] best 781 combination zp[2]:2 [ screen#36 screen#12 screen#11 ]
Uplifting [main] best 781 combination
Uplifting [print1] best 781 combination
Uplifting [print2] best 781 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Tests that multiple different identical strings are consolidated to a root variable
// Upstart
// Commodore 64 PRG executable file
.file [name="string-const-consolidation-root.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 = 2
.segment Code
// main
main: {
// [1] call print1
// [5] phi from main to print1 [phi:main->print1]
print1_from_main:
jsr print1
// [2] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [3] call print2
// [12] phi from main::@1 to print2 [phi:main::@1->print2]
print2_from___b1:
jsr print2
jmp __breturn
// main::@return
__breturn:
// [4] return
rts
}
// print1
print1: {
// [6] call print
// [19] phi from print1 to print [phi:print1->print]
print_from_print1:
// [19] phi screen#36 = (byte*) 1024 [phi:print1->print#0] -- pbuz1=pbuc1
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
// [19] phi print::s#9 = string_0 [phi:print1->print#1] -- pbuz1=pbuc1
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// [7] phi from print1 to print1::@1 [phi:print1->print1::@1]
__b1_from_print1:
jmp __b1
// print1::@1
__b1:
// [8] call print
// [19] phi from print1::@1 to print [phi:print1::@1->print]
print_from___b1:
// [19] phi screen#36 = screen#12 [phi:print1::@1->print#0] -- register_copy
// [19] phi print::s#9 = string_1 [phi:print1::@1->print#1] -- pbuz1=pbuc1
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// [9] phi from print1::@1 to print1::@2 [phi:print1::@1->print1::@2]
__b2_from___b1:
jmp __b2
// print1::@2
__b2:
// [10] call print
// [19] phi from print1::@2 to print [phi:print1::@2->print]
print_from___b2:
// [19] phi screen#36 = screen#12 [phi:print1::@2->print#0] -- register_copy
// [19] phi print::s#9 = s [phi:print1::@2->print#1] -- pbuz1=pbuc1
lda #<s
sta.z print.s
lda #>s
sta.z print.s+1
jsr print
jmp __breturn
// print1::@return
__breturn:
// [11] return
rts
}
// print2
print2: {
// [13] call print
// [19] phi from print2 to print [phi:print2->print]
print_from_print2:
// [19] phi screen#36 = screen#12 [phi:print2->print#0] -- register_copy
// [19] phi print::s#9 = string_0 [phi:print2->print#1] -- pbuz1=pbuc1
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// [14] phi from print2 to print2::@1 [phi:print2->print2::@1]
__b1_from_print2:
jmp __b1
// print2::@1
__b1:
// [15] call print
// [19] phi from print2::@1 to print [phi:print2::@1->print]
print_from___b1:
// [19] phi screen#36 = screen#12 [phi:print2::@1->print#0] -- register_copy
// [19] phi print::s#9 = string_1 [phi:print2::@1->print#1] -- pbuz1=pbuc1
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// [16] phi from print2::@1 to print2::@2 [phi:print2::@1->print2::@2]
__b2_from___b1:
jmp __b2
// print2::@2
__b2:
// [17] call print
// [19] phi from print2::@2 to print [phi:print2::@2->print]
print_from___b2:
// [19] phi screen#36 = screen#12 [phi:print2::@2->print#0] -- register_copy
// [19] phi print::s#9 = s1 [phi:print2::@2->print#1] -- pbuz1=pbuc1
lda #<s1
sta.z print.s
lda #>s1
sta.z print.s+1
jsr print
jmp __breturn
// print2::@return
__breturn:
// [18] return
rts
}
// print
// print(byte* zp(4) s)
print: {
.label s = 4
// [20] phi from print print::@2 to print::@1 [phi:print/print::@2->print::@1]
__b1_from_print:
__b1_from___b2:
// [20] phi screen#12 = screen#36 [phi:print/print::@2->print::@1#0] -- register_copy
// [20] phi print::s#7 = print::s#9 [phi:print/print::@2->print::@1#1] -- register_copy
jmp __b1
// print::@1
__b1:
// [21] if(0!=*print::s#7) goto print::@2 -- 0_neq__deref_pbuz1_then_la1
ldy #0
lda (s),y
cmp #0
bne __b2
jmp __breturn
// print::@return
__breturn:
// [22] return
rts
// print::@2
__b2:
// [23] *screen#12 = *print::s#7 -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (s),y
ldy #0
sta (screen),y
// [24] screen#11 = ++ screen#12 -- pbuz1=_inc_pbuz1
inc.z screen
bne !+
inc.z screen+1
!:
// [25] print::s#6 = ++ print::s#7 -- pbuz1=_inc_pbuz1
inc.z s
bne !+
inc.z s+1
!:
jmp __b1_from___b2
}
// File Data
.segment Data
s: .text "string3"
.byte 0
s1: .text "string4"
.byte 0
string_0: .text "string1"
.byte 0
string_1: .text "string2"
.byte 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
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 __b1_from___b2 with __b1
Removing instruction __b1_from_main:
Removing instruction print2_from___b1:
Removing instruction __b1_from_print1:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Removing instruction __b1_from_print2:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Removing instruction __b1_from_print:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction print1_from_main:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction print_from_print1:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction print_from_print2:
Removing instruction __b1:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
void main()
void print(byte* print::s)
byte* print::s
byte* print::s#6 s zp[2]:4 2002.0
byte* print::s#7 s zp[2]:4 1026.25
byte* print::s#9 s zp[2]:4 101.0
void print1()
void print2()
const byte* s = "string3"
const byte* s1 = "string4"
byte* screen
byte* screen#11 screen zp[2]:2 1001.0
byte* screen#12 screen zp[2]:2 185.8235294117647
byte* screen#36 screen zp[2]:2 156.0
const byte* string_0[8] = "string1"
const byte* string_1[8] = "string2"
zp[2]:2 [ screen#36 screen#12 screen#11 ]
zp[2]:4 [ print::s#7 print::s#9 print::s#6 ]
FINAL ASSEMBLER
Score: 677
// File Comments
// Tests that multiple different identical strings are consolidated to a root variable
// Upstart
// Commodore 64 PRG executable file
.file [name="string-const-consolidation-root.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 = 2
.segment Code
// main
main: {
// print1()
// [1] call print1
// [5] phi from main to print1 [phi:main->print1]
jsr print1
// [2] phi from main to main::@1 [phi:main->main::@1]
// main::@1
// print2()
// [3] call print2
// [12] phi from main::@1 to print2 [phi:main::@1->print2]
jsr print2
// main::@return
// }
// [4] return
rts
}
// print1
print1: {
// print("string1")
// [6] call print
// [19] phi from print1 to print [phi:print1->print]
// [19] phi screen#36 = (byte*) 1024 [phi:print1->print#0] -- pbuz1=pbuc1
lda #<$400
sta.z screen
lda #>$400
sta.z screen+1
// [19] phi print::s#9 = string_0 [phi:print1->print#1] -- pbuz1=pbuc1
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// [7] phi from print1 to print1::@1 [phi:print1->print1::@1]
// print1::@1
// print("string2")
// [8] call print
// [19] phi from print1::@1 to print [phi:print1::@1->print]
// [19] phi screen#36 = screen#12 [phi:print1::@1->print#0] -- register_copy
// [19] phi print::s#9 = string_1 [phi:print1::@1->print#1] -- pbuz1=pbuc1
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// [9] phi from print1::@1 to print1::@2 [phi:print1::@1->print1::@2]
// print1::@2
// print(s)
// [10] call print
// [19] phi from print1::@2 to print [phi:print1::@2->print]
// [19] phi screen#36 = screen#12 [phi:print1::@2->print#0] -- register_copy
// [19] phi print::s#9 = s [phi:print1::@2->print#1] -- pbuz1=pbuc1
lda #<s
sta.z print.s
lda #>s
sta.z print.s+1
jsr print
// print1::@return
// }
// [11] return
rts
}
// print2
print2: {
// print("string1")
// [13] call print
// [19] phi from print2 to print [phi:print2->print]
// [19] phi screen#36 = screen#12 [phi:print2->print#0] -- register_copy
// [19] phi print::s#9 = string_0 [phi:print2->print#1] -- pbuz1=pbuc1
lda #<string_0
sta.z print.s
lda #>string_0
sta.z print.s+1
jsr print
// [14] phi from print2 to print2::@1 [phi:print2->print2::@1]
// print2::@1
// print("string2")
// [15] call print
// [19] phi from print2::@1 to print [phi:print2::@1->print]
// [19] phi screen#36 = screen#12 [phi:print2::@1->print#0] -- register_copy
// [19] phi print::s#9 = string_1 [phi:print2::@1->print#1] -- pbuz1=pbuc1
lda #<string_1
sta.z print.s
lda #>string_1
sta.z print.s+1
jsr print
// [16] phi from print2::@1 to print2::@2 [phi:print2::@1->print2::@2]
// print2::@2
// print(s1)
// [17] call print
// [19] phi from print2::@2 to print [phi:print2::@2->print]
// [19] phi screen#36 = screen#12 [phi:print2::@2->print#0] -- register_copy
// [19] phi print::s#9 = s1 [phi:print2::@2->print#1] -- pbuz1=pbuc1
lda #<s1
sta.z print.s
lda #>s1
sta.z print.s+1
jsr print
// print2::@return
// }
// [18] return
rts
}
// print
// print(byte* zp(4) s)
print: {
.label s = 4
// [20] phi from print print::@2 to print::@1 [phi:print/print::@2->print::@1]
// [20] phi screen#12 = screen#36 [phi:print/print::@2->print::@1#0] -- register_copy
// [20] phi print::s#7 = print::s#9 [phi:print/print::@2->print::@1#1] -- register_copy
// print::@1
__b1:
// while(*s)
// [21] if(0!=*print::s#7) goto print::@2 -- 0_neq__deref_pbuz1_then_la1
ldy #0
lda (s),y
cmp #0
bne __b2
// print::@return
// }
// [22] return
rts
// print::@2
__b2:
// *screen++ = *s++
// [23] *screen#12 = *print::s#7 -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (s),y
sta (screen),y
// *screen++ = *s++;
// [24] screen#11 = ++ screen#12 -- pbuz1=_inc_pbuz1
inc.z screen
bne !+
inc.z screen+1
!:
// [25] print::s#6 = ++ print::s#7 -- pbuz1=_inc_pbuz1
inc.z s
bne !+
inc.z s+1
!:
jmp __b1
}
// File Data
.segment Data
s: .text "string3"
.byte 0
s1: .text "string4"
.byte 0
string_0: .text "string1"
.byte 0
string_1: .text "string2"
.byte 0

View File

@ -0,0 +1,19 @@
void main()
void print(byte* print::s)
byte* print::s
byte* print::s#6 s zp[2]:4 2002.0
byte* print::s#7 s zp[2]:4 1026.25
byte* print::s#9 s zp[2]:4 101.0
void print1()
void print2()
const byte* s = "string3"
const byte* s1 = "string4"
byte* screen
byte* screen#11 screen zp[2]:2 1001.0
byte* screen#12 screen zp[2]:2 185.8235294117647
byte* screen#36 screen zp[2]:2 156.0
const byte* string_0[8] = "string1"
const byte* string_1[8] = "string2"
zp[2]:2 [ screen#36 screen#12 screen#11 ]
zp[2]:4 [ print::s#7 print::s#9 print::s#6 ]