1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-10 13:38:18 +00:00

Added tests for __address(). VariableBuilder turns __address() into multiple-assignment. Fixed errors for multiple-assignment variables.

This commit is contained in:
jespergravgaard 2019-12-26 00:17:01 +01:00
parent 6ce7ac901e
commit 655dc48b7b
38 changed files with 2464 additions and 516 deletions

View File

@ -225,6 +225,9 @@ public class VariableBuilder {
if(hasDirective(Directive.FormMa.class))
// the __ma directive forces multiple-assignment
return false;
else if(hasDirective(Directive.Address.class))
// the __address directive forces multiple-assignment
return false;
else if(isVolatile())
// volatile variables must be load/store
return false;

View File

@ -11,10 +11,7 @@ import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.ConstantValue;
import dk.camelot64.kickc.model.values.PointerDereference;
import dk.camelot64.kickc.model.values.RValue;
import dk.camelot64.kickc.model.values.VariableRef;
import dk.camelot64.kickc.model.values.*;
import java.util.HashSet;
import java.util.Objects;
@ -40,17 +37,17 @@ public class Pass2DuplicateRValueIdentification extends Pass2SsaOptimization {
if(statement instanceof StatementAssignment) {
StatementAssignment assignment = (StatementAssignment) statement;
AssignmentRValue assignmentRValue = new AssignmentRValue(assignment, block);
if(!assignmentRValue.isConstant() && !assignmentRValue.isTrivial() && !assignmentRValue.isVolatile()) {
if(!assignmentRValue.isConstant() && !assignmentRValue.isTrivial() && !assignmentRValue.isVolatile()&& !assignmentRValue.isLoadStore()) {
if(rValues.contains(assignmentRValue)) {
AssignmentRValue firstAssignment = rValues.stream().filter(assignmentRValue1 -> assignmentRValue1.equals(assignmentRValue)).findFirst().get();
if(firstAssignment.assignment.getlValue() instanceof VariableRef) {
getLog().append("Identified duplicate assignment right side "+assignment.toString(getProgram(), false));
getLog().append("Identified duplicate assignment right side " + assignment.toString(getProgram(), false));
assignment.setrValue1(null);
assignment.setOperator(null);
assignment.setrValue2(firstAssignment.assignment.getlValue());
modified = true;
} else {
throw new InternalError("Complex lValue for duplicate rvalue "+firstAssignment.assignment.toString(getProgram(), false));
throw new InternalError("Complex lValue for duplicate rvalue " + firstAssignment.assignment.toString(getProgram(), false));
}
} else {
rValues.add(assignmentRValue);
@ -90,6 +87,21 @@ public class Pass2DuplicateRValueIdentification extends Pass2SsaOptimization {
return true;
}
private boolean isLoadStore() {
AtomicBoolean isLoadStore = new AtomicBoolean(false);
ProgramValueHandler loadStoreIdentificator = (programValue, currentStmt, stmtIt, currentBlock) -> {
Value value = programValue.get();
if(value instanceof VariableRef) {
Variable var = getScope().getVar((VariableRef) value);
if(var.isKindLoadStore())
isLoadStore.set(true);
}
};
ProgramValueIterator.execute(new ProgramValue.GenericValue(rValue1), loadStoreIdentificator, assignment, null, block);
ProgramValueIterator.execute(new ProgramValue.GenericValue(rValue2), loadStoreIdentificator, assignment, null, block);
return isLoadStore.get();
}
private boolean isVolatile() {
AtomicBoolean isVol = new AtomicBoolean(false);
ProgramValueHandler identifyVolatiles = (programValue, currentStmt, stmtIt, currentBlock) -> {
@ -97,7 +109,7 @@ public class Pass2DuplicateRValueIdentification extends Pass2SsaOptimization {
isVol.set(true);
if(programValue.get() instanceof VariableRef) {
Variable variable = getScope().getVariable((VariableRef) programValue.get());
if(variable.isAnyVolatile() )
if(variable.isAnyVolatile())
isVol.set(true);
}
};

View File

@ -261,25 +261,31 @@ public class Pass4CodeGeneration {
signature.append(" ").append(procedure.getLocalName()).append("(");
int i = 0;
for(Variable parameter : procedure.getParameters()) {
List<Variable> versions = new ArrayList<>(procedure.getVersions(parameter));
if(versions.size() > 0) {
Variable param = versions.get(0);
Registers.Register allocation = param.getAllocation();
if(i++ > 0) signature.append(", ");
signature.append(param.getType().getTypeName()).append(" ");
if(allocation instanceof Registers.RegisterZpMem) {
Registers.RegisterZpMem registerZp = (Registers.RegisterZpMem) allocation;
signature.append("zeropage(").append(AsmFormat.getAsmNumber(registerZp.getZp())).append(")");
} else if(allocation instanceof Registers.RegisterAByte) {
signature.append("register(A)");
} else if(allocation instanceof Registers.RegisterXByte) {
signature.append("register(X)");
} else if(allocation instanceof Registers.RegisterYByte) {
signature.append("register(Y)");
}
signature.append(" ");
signature.append(parameter.getLocalName());
Variable param = parameter;
if(param.isKindPhiMaster()) {
List<Variable> versions = new ArrayList<>(procedure.getVersions(parameter));
if(versions.size() > 0)
param = versions.get(0);
else
// Parameter optimized away to a constant or unused
continue;
}
Registers.Register allocation = param.getAllocation();
if(i++ > 0) signature.append(", ");
signature.append(param.getType().getTypeName()).append(" ");
if(allocation instanceof Registers.RegisterZpMem) {
Registers.RegisterZpMem registerZp = (Registers.RegisterZpMem) allocation;
signature.append("zeropage(").append(AsmFormat.getAsmNumber(registerZp.getZp())).append(")");
} else if(allocation instanceof Registers.RegisterAByte) {
signature.append("register(A)");
} else if(allocation instanceof Registers.RegisterXByte) {
signature.append("register(X)");
} else if(allocation instanceof Registers.RegisterYByte) {
signature.append("register(Y)");
}
signature.append(" ");
signature.append(parameter.getLocalName());
}
signature.append(")");
if(i > 0) {
@ -575,7 +581,7 @@ public class Pass4CodeGeneration {
Variable memberVariable = getScope().getVar(memberRef);
addChunkData(dataChunk, memberValue, memberVariable.getType(), memberVariable.getArraySpec(), scopeRef);
}
} else if(valueType instanceof SymbolTypePointer && valueArraySpec!=null) {
} else if(valueType instanceof SymbolTypePointer && valueArraySpec != null) {
SymbolTypePointer constTypeArray = (SymbolTypePointer) valueType;
SymbolType elementType = constTypeArray.getElementType();
@ -609,8 +615,8 @@ public class Pass4CodeGeneration {
// default - larger then 256
int bytes = 1023;
Integer declaredSize = getArrayDeclaredSize(valueArraySpec.getArraySize());
if(declaredSize!=null) {
bytes = declaredSize * elementType.getSizeBytes();
if(declaredSize != null) {
bytes = declaredSize * elementType.getSizeBytes();
}
dataChunk.addDataKickAsm(bytes, kickAsm.getKickAsmCode(), getEncoding(value));
dataNumElements = bytes;

View File

@ -31,9 +31,9 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization {
if(lValue instanceof VariableRef) {
VariableRef variableRef = (VariableRef) lValue;
Variable variable = getScope().getVariable(variableRef);
if(variable.isKindConstant() ) {
if(variable.isKindConstant() || variable.isNoModify()) {
if(assigned.contains(variableRef)) {
throw new CompileError("Error! Constants can not be modified", statement.getSource());
throw new CompileError("const variable may not be modified "+variable.toString(getProgram()), statement.getSource());
} else {
assigned.add(variableRef);
}

View File

@ -38,8 +38,28 @@ public class TestPrograms {
}
@Test
public void testKernalLoad() throws IOException, URISyntaxException {
compileAndCompare("examples/kernalload/kernalload");
public void testAddress4() throws IOException, URISyntaxException {
compileAndCompare("address-4");
}
@Test
public void testAddress3() throws IOException, URISyntaxException {
compileAndCompare("address-3");
}
@Test
public void testAddress2() throws IOException, URISyntaxException {
compileAndCompare("address-2");
}
@Test
public void testAddress1() throws IOException, URISyntaxException {
compileAndCompare("address-1");
}
@Test
public void testAddress0() throws IOException, URISyntaxException {
compileAndCompare("address-0");
}
@Test
@ -87,6 +107,11 @@ public class TestPrograms {
assertError("nomodify-0", "const variable may not be modified");
}
@Test
public void testKernalLoad() throws IOException, URISyntaxException {
compileAndCompare("examples/kernalload/kernalload");
}
@Test
public void testConstantWithPrePost() throws IOException, URISyntaxException {
assertError("constant-prepost", "Constant value contains a pre/post-modifier");
@ -3242,7 +3267,7 @@ public class TestPrograms {
@Test
public void testAssignConst() throws IOException, URISyntaxException {
assertError("assign-const", "Constants can not be modified");
assertError("assign-const", "const variable may not be modified");
}
@Test

11
src/test/kc/address-0.kc Normal file
View File

@ -0,0 +1,11 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - global variable
const char* SCREEN = 0x0400;
char __address(0x02) i = 3;
void main() {
while(i<7)
SCREEN[i++] = i;
}

11
src/test/kc/address-1.kc Normal file
View File

@ -0,0 +1,11 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - local variable
const char* SCREEN = 0x0400;
void main() {
char __address(0x02) i = 3;
while(i<7)
SCREEN[i++] = i;
}

11
src/test/kc/address-2.kc Normal file
View File

@ -0,0 +1,11 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem-page address - global variable
const char* SCREEN = 0x0400;
char __address(0x2000) i = 3;
void main() {
while(i<7)
SCREEN[i++] = i;
}

10
src/test/kc/address-3.kc Normal file
View File

@ -0,0 +1,10 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem address - local variable
const char* SCREEN = 0x0400;
void main() {
char __address(0x2000) i = 3;
while(i<7)
SCREEN[i++] = i;
}

13
src/test/kc/address-4.kc Normal file
View File

@ -0,0 +1,13 @@
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
unsigned int* SCREEN = 0x0400;
void main() {
__address(0x2) char i=0;
const unsigned int ch = 0x0102;
while(i<8) {
SCREEN[i++] = ch;
SCREEN[i++] = ch;
}
}

View File

@ -0,0 +1,25 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - global variable
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
.label SCREEN = $400
.label i = 2
__bbegin:
lda #3
sta.z i
jsr main
rts
main: {
__b1:
lda.z i
cmp #7
bcc __b2
rts
__b2:
ldy.z i
tya
sta SCREEN,y
inc.z i
jmp __b1
}

View File

@ -0,0 +1,24 @@
@begin: scope:[] from
[0] (byte) i ← (byte) 3
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()
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) i) ← (byte) i
[8] (byte) i ← ++ (byte) i
to:main::@1

321
src/test/ref/address-0.log Normal file
View File

@ -0,0 +1,321 @@
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte) i ← (number) 3
to:@1
(void()) main()
main: scope:[main] from @1
to:main::@1
main::@1: scope:[main] from main main::@2
(bool~) main::$0 ← (byte) i < (number) 7
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
*((const byte*) SCREEN + (byte) i) ← (byte) i
(byte) i ← ++ (byte) i
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(byte) i loadstore !zp[-1]:2
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@return
Adding number conversion cast (unumber) 3 in (byte) i ← (number) 3
Adding number conversion cast (unumber) 7 in (bool~) main::$0 ← (byte) i < (number) 7
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) i ← (unumber)(number) 3
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 3
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) i<(byte) 7) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
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
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] (byte) i ← (byte) 3
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()
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) i) ← (byte) i
[8] (byte) i ← ++ (byte) i
to:main::@1
VARIABLE REGISTER WEIGHTS
(byte) i loadstore !zp[-1]:2 11.400000000000002
(void()) main()
Initial phi equivalence classes
Added variable i to live range equivalence class [ i ]
Complete equivalence classes
[ i ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = 2
// @begin
__bbegin:
// [0] (byte) i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
// [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: {
jmp __b1
// main::@1
__b1:
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// [8] (byte) i ← ++ (byte) i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) i ← (byte) 3 [ i ] ( [ i ] ) always clobbers reg byte a
Statement [5] if((byte) i<(byte) 7) goto main::@2 [ i ] ( main:2 [ i ] ) always clobbers reg byte a
Statement [7] *((const byte*) SCREEN + (byte) i) ← (byte) i [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Potential registers zp[1]:2 [ i ] : zp[1]:2 ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 11.4: zp[1]:2 [ i ]
Uplift Scope [main]
Uplifting [] best 338 combination zp[1]:2 [ i ]
Uplifting [main] best 338 combination
Attempting to uplift remaining variables inzp[1]:2 [ i ]
Uplifting [] best 338 combination zp[1]:2 [ i ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = 2
// @begin
__bbegin:
// [0] (byte) i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
// [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: {
jmp __b1
// main::@1
__b1:
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// [8] (byte) i ← ++ (byte) i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block
Succesful ASM optimization Pass5AddMainRts
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) i loadstore !zp[-1]:2 zp[1]:2 11.400000000000002
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
zp[1]:2 [ i ]
FINAL ASSEMBLER
Score: 278
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = 2
// @begin
__bbegin:
// i = 3
// [0] (byte) i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
jsr main
rts
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// main::@1
__b1:
// while(i<7)
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
// main::@return
// }
// [6] return
rts
// main::@2
__b2:
// SCREEN[i++] = i
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// SCREEN[i++] = i;
// [8] (byte) i ← ++ (byte) i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data

View File

@ -0,0 +1,11 @@
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) i loadstore !zp[-1]:2 zp[1]:2 11.400000000000002
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
zp[1]:2 [ i ]

View File

@ -0,0 +1,22 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - local variable
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
main: {
.label i = 2
lda #3
sta.z i
__b1:
lda.z i
cmp #7
bcc __b2
rts
__b2:
ldy.z i
tya
sta SCREEN,y
inc.z i
jmp __b1
}

View File

@ -0,0 +1,24 @@
@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] (byte) main::i ← (byte) 3
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
[8] (byte) main::i ← ++ (byte) main::i
to:main::@1

316
src/test/ref/address-1.log Normal file
View File

@ -0,0 +1,316 @@
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
(byte) main::i ← (number) 3
to:main::@1
main::@1: scope:[main] from main main::@2
(bool~) main::$0 ← (byte) main::i < (number) 7
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
*((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
(byte) main::i ← ++ (byte) main::i
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !zp[-1]:2
Adding number conversion cast (unumber) 3 in (byte) main::i ← (number) 3
Adding number conversion cast (unumber) 7 in (bool~) main::$0 ← (byte) main::i < (number) 7
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) main::i ← (unumber)(number) 3
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 3
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) main::i<(byte) 7) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
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
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
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] (byte) main::i ← (byte) 3
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
[8] (byte) main::i ← ++ (byte) main::i
to:main::@1
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::i loadstore !zp[-1]:2 19.0
Initial phi equivalence classes
Added variable main::i to live range equivalence class [ main::i ]
Complete equivalence classes
[ main::i ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label i = 2
// [4] (byte) main::i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// [8] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte) main::i ← (byte) 3 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [5] if((byte) main::i<(byte) 7) goto main::@2 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Potential registers zp[1]:2 [ main::i ] : zp[1]:2 ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 19: zp[1]:2 [ main::i ]
Uplift Scope []
Uplifting [main] best 311 combination zp[1]:2 [ main::i ]
Uplifting [] best 311 combination
Attempting to uplift remaining variables inzp[1]:2 [ main::i ]
Uplifting [main] best 311 combination zp[1]:2 [ main::i ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label i = 2
// [4] (byte) main::i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// [8] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
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
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 19.0
zp[1]:2 [ main::i ]
FINAL ASSEMBLER
Score: 266
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded zero-page address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.label i = 2
// i = 3
// [4] (byte) main::i ← (byte) 3 -- vbuz1=vbuc1
lda #3
sta.z i
// main::@1
__b1:
// while(i<7)
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #7
bcc __b2
// main::@return
// }
// [6] return
rts
// main::@2
__b2:
// SCREEN[i++] = i
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbuz1=vbuz1
ldy.z i
tya
sta SCREEN,y
// SCREEN[i++] = i;
// [8] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data

View File

@ -0,0 +1,11 @@
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 19.0
zp[1]:2 [ main::i ]

View File

@ -0,0 +1,25 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem-page address - global variable
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
.label SCREEN = $400
.label i = $2000
__bbegin:
lda #3
sta i
jsr main
rts
main: {
__b1:
lda i
cmp #7
bcc __b2
rts
__b2:
ldy i
tya
sta SCREEN,y
inc i
jmp __b1
}

View File

@ -0,0 +1,24 @@
@begin: scope:[] from
[0] (byte) i ← (byte) 3
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()
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) i) ← (byte) i
[8] (byte) i ← ++ (byte) i
to:main::@1

321
src/test/ref/address-2.log Normal file
View File

@ -0,0 +1,321 @@
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte) i ← (number) 3
to:@1
(void()) main()
main: scope:[main] from @1
to:main::@1
main::@1: scope:[main] from main main::@2
(bool~) main::$0 ← (byte) i < (number) 7
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
*((const byte*) SCREEN + (byte) i) ← (byte) i
(byte) i ← ++ (byte) i
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(byte) i loadstore !mem[-1]:8192
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@return
Adding number conversion cast (unumber) 3 in (byte) i ← (number) 3
Adding number conversion cast (unumber) 7 in (bool~) main::$0 ← (byte) i < (number) 7
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) i ← (unumber)(number) 3
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 3
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) i<(byte) 7) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
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
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
[0] (byte) i ← (byte) 3
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()
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) i) ← (byte) i
[8] (byte) i ← ++ (byte) i
to:main::@1
VARIABLE REGISTER WEIGHTS
(byte) i loadstore !mem[-1]:8192 11.400000000000002
(void()) main()
Initial phi equivalence classes
Added variable i to live range equivalence class [ i ]
Complete equivalence classes
[ i ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = $2000
// @begin
__bbegin:
// [0] (byte) i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
// [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: {
jmp __b1
// main::@1
__b1:
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// [8] (byte) i ← ++ (byte) i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) i ← (byte) 3 [ i ] ( [ i ] ) always clobbers reg byte a
Statement [5] if((byte) i<(byte) 7) goto main::@2 [ i ] ( main:2 [ i ] ) always clobbers reg byte a
Statement [7] *((const byte*) SCREEN + (byte) i) ← (byte) i [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Potential registers mem[1]:8192 [ i ] : mem[1]:8192 ,
REGISTER UPLIFT SCOPES
Uplift Scope [] 11.4: mem[1]:8192 [ i ]
Uplift Scope [main]
Uplifting [] best 369 combination mem[1]:8192 [ i ]
Uplifting [main] best 369 combination
Attempting to uplift remaining variables inmem[1]:8192 [ i ]
Uplifting [] best 369 combination mem[1]:8192 [ i ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = $2000
// @begin
__bbegin:
// [0] (byte) i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
// [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: {
jmp __b1
// main::@1
__b1:
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// [8] (byte) i ← ++ (byte) i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __bend:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block
Succesful ASM optimization Pass5AddMainRts
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) i loadstore !mem[-1]:8192 mem[1]:8192 11.400000000000002
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
mem[1]:8192 [ i ]
FINAL ASSEMBLER
Score: 309
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem-page address - global variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
.label i = $2000
// @begin
__bbegin:
// i = 3
// [0] (byte) i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
jsr main
rts
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
// main::@1
__b1:
// while(i<7)
// [5] if((byte) i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
// main::@return
// }
// [6] return
rts
// main::@2
__b2:
// SCREEN[i++] = i
// [7] *((const byte*) SCREEN + (byte) i) ← (byte) i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// SCREEN[i++] = i;
// [8] (byte) i ← ++ (byte) i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data

View File

@ -0,0 +1,11 @@
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) i loadstore !mem[-1]:8192 mem[1]:8192 11.400000000000002
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
mem[1]:8192 [ i ]

View File

@ -0,0 +1,22 @@
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem address - local variable
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
main: {
.label i = $2000
lda #3
sta i
__b1:
lda i
cmp #7
bcc __b2
rts
__b2:
ldy i
tya
sta SCREEN,y
inc i
jmp __b1
}

View File

@ -0,0 +1,24 @@
@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] (byte) main::i ← (byte) 3
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
[8] (byte) main::i ← ++ (byte) main::i
to:main::@1

316
src/test/ref/address-3.log Normal file
View File

@ -0,0 +1,316 @@
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
(byte) main::i ← (number) 3
to:main::@1
main::@1: scope:[main] from main main::@2
(bool~) main::$0 ← (byte) main::i < (number) 7
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
*((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
(byte) main::i ← ++ (byte) main::i
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !mem[-1]:8192
Adding number conversion cast (unumber) 3 in (byte) main::i ← (number) 3
Adding number conversion cast (unumber) 7 in (bool~) main::$0 ← (byte) main::i < (number) 7
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) main::i ← (unumber)(number) 3
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 3
Simplifying constant integer cast 7
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 7
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) main::i<(byte) 7) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
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
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
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] (byte) main::i ← (byte) 3
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 7) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i
[8] (byte) main::i ← ++ (byte) main::i
to:main::@1
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::i loadstore !mem[-1]:8192 19.0
Initial phi equivalence classes
Added variable main::i to live range equivalence class [ main::i ]
Complete equivalence classes
[ main::i ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label i = $2000
// [4] (byte) main::i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// [8] (byte) main::i ← ++ (byte) main::i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte) main::i ← (byte) 3 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [5] if((byte) main::i<(byte) 7) goto main::@2 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Potential registers mem[1]:8192 [ main::i ] : mem[1]:8192 ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 19: mem[1]:8192 [ main::i ]
Uplift Scope []
Uplifting [main] best 342 combination mem[1]:8192 [ main::i ]
Uplifting [] best 342 combination
Attempting to uplift remaining variables inmem[1]:8192 [ main::i ]
Uplifting [main] best 342 combination mem[1]:8192 [ main::i ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.label i = $2000
// [4] (byte) main::i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// [8] (byte) main::i ← ++ (byte) main::i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
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
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !mem[-1]:8192 mem[1]:8192 19.0
mem[1]:8192 [ main::i ]
FINAL ASSEMBLER
Score: 297
// File Comments
// Test that address vars are turned into load/store and located at hardcoded addresses
// Hard-coded mainmem address - local variable
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.label i = $2000
// i = 3
// [4] (byte) main::i ← (byte) 3 -- vbum1=vbuc1
lda #3
sta i
// main::@1
__b1:
// while(i<7)
// [5] if((byte) main::i<(byte) 7) goto main::@2 -- vbum1_lt_vbuc1_then_la1
lda i
cmp #7
bcc __b2
// main::@return
// }
// [6] return
rts
// main::@2
__b2:
// SCREEN[i++] = i
// [7] *((const byte*) SCREEN + (byte) main::i) ← (byte) main::i -- pbuc1_derefidx_vbum1=vbum1
ldy i
tya
sta SCREEN,y
// SCREEN[i++] = i;
// [8] (byte) main::i ← ++ (byte) main::i -- vbum1=_inc_vbum1
inc i
jmp __b1
}
// File Data

View File

@ -0,0 +1,11 @@
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i loadstore !mem[-1]:8192 mem[1]:8192 19.0
mem[1]:8192 [ main::i ]

View File

@ -0,0 +1,35 @@
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
main: {
.const ch = $102
.label i = 2
lda #0
sta.z i
__b1:
lda.z i
cmp #8
bcc __b2
rts
__b2:
lda.z i
asl
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
inc.z i
lda.z i
asl
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
inc.z i
jmp __b1
}

View File

@ -0,0 +1,28 @@
@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] (byte) main::i ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 8) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] (byte~) main::$1 ← (byte) main::i << (byte) 1
[8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch
[9] (byte) main::i ← ++ (byte) main::i
[10] (byte~) main::$2 ← (byte) main::i << (byte) 1
[11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch
[12] (byte) main::i ← ++ (byte) main::i
to:main::@1

411
src/test/ref/address-4.log Normal file
View File

@ -0,0 +1,411 @@
Fixing pointer array-indexing *((word*) SCREEN + (byte) main::i)
Fixing pointer array-indexing *((word*) SCREEN + (byte) main::i)
Identified constant variable (word*) SCREEN
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
(byte) main::i ← (number) 0
to:main::@1
main::@1: scope:[main] from main main::@2
(bool~) main::$0 ← (byte) main::i < (number) 8
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
(byte~) main::$1 ← (byte) main::i * (const byte) SIZEOF_WORD
*((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch
(byte) main::i ← ++ (byte) main::i
(byte~) main::$2 ← (byte) main::i * (const byte) SIZEOF_WORD
*((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch
(byte) main::i ← ++ (byte) main::i
to:main::@1
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
call main
to:@2
@2: scope:[] from @1
to:@end
@end: scope:[] from @2
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const word*) SCREEN = (word*)(number) $400
(const byte) SIZEOF_WORD = (byte) 2
(void()) main()
(bool~) main::$0
(byte~) main::$1
(byte~) main::$2
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::ch = (number) $102
(byte) main::i loadstore !zp[-1]:2
Adding number conversion cast (unumber) 0 in (byte) main::i ← (number) 0
Adding number conversion cast (unumber) 8 in (bool~) main::$0 ← (byte) main::i < (number) 8
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) main::i ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [2] if((byte) main::i<(byte) 8) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Rewriting multiplication to use shift [2] (byte~) main::$1 ← (byte) main::i * (const byte) SIZEOF_WORD
Rewriting multiplication to use shift [5] (byte~) main::$2 ← (byte) main::i * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
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
CALL GRAPH
Calls in [] to main:2
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
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] (byte) main::i ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@2
[5] if((byte) main::i<(byte) 8) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
main::@2: scope:[main] from main::@1
[7] (byte~) main::$1 ← (byte) main::i << (byte) 1
[8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch
[9] (byte) main::i ← ++ (byte) main::i
[10] (byte~) main::$2 ← (byte) main::i << (byte) 1
[11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch
[12] (byte) main::i ← ++ (byte) main::i
to:main::@1
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 22.0
(byte~) main::$2 22.0
(byte) main::i loadstore !zp[-1]:2 19.75
Initial phi equivalence classes
Added variable main::i to live range equivalence class [ main::i ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Complete equivalence classes
[ main::i ]
[ main::$1 ]
[ main::$2 ]
Allocated zp[1]:3 [ main::$1 ]
Allocated zp[1]:4 [ main::$2 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.const ch = $102
.label i = 2
.label __1 = 3
.label __2 = 4
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #8
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1
lda.z i
asl
sta.z __1
// [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuz1=vwuc2
ldy.z __1
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1
lda.z i
asl
sta.z __2
// [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuz1=vwuc2
ldy.z __2
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte) main::i ← (byte) 0 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [5] if((byte) main::i<(byte) 8) goto main::@2 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 [ main::$1 ] ( main:2 [ main::$1 ] ) always clobbers reg byte a
Statement [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 [ main::$2 ] ( main:2 [ main::$2 ] ) always clobbers reg byte a
Statement [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch [ ] ( main:2 [ ] ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::i ] : zp[1]:2 ,
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:4 [ main::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp[1]:3 [ main::$1 ] 22: zp[1]:4 [ main::$2 ] 19.75: zp[1]:2 [ main::i ]
Uplift Scope []
Uplifting [main] best 681 combination reg byte a [ main::$1 ] reg byte a [ main::$2 ] zp[1]:2 [ main::i ]
Uplifting [] best 681 combination
Attempting to uplift remaining variables inzp[1]:2 [ main::i ]
Uplifting [main] best 681 combination zp[1]:2 [ main::i ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
// Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
__bbegin:
// [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
jmp __b1
// @1
__b1:
// [2] call main
jsr main
// [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
jmp __bend
// @end
__bend:
// main
main: {
.const ch = $102
.label i = 2
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
jmp __b1
// main::@1
__b1:
// [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #8
bcc __b2
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
// main::@2
__b2:
// [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
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
(const word*) SCREEN = (word*) 1024
(void()) main()
(byte~) main::$1 reg byte a 22.0
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::ch = (number) $102
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 19.75
zp[1]:2 [ main::i ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]
FINAL ASSEMBLER
Score: 636
// File Comments
// Test declaring a variable as at a hard-coded address
// Incrementing a load/store variable will result in cause two *SIZEOF's
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// @begin
// [1] phi from @begin to @1 [phi:@begin->@1]
// @1
// [2] call main
// [3] phi from @1 to @end [phi:@1->@end]
// @end
// main
main: {
.const ch = $102
.label i = 2
// i=0
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
// main::@1
__b1:
// while(i<8)
// [5] if((byte) main::i<(byte) 8) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #8
bcc __b2
// main::@return
// }
// [6] return
rts
// main::@2
__b2:
// SCREEN[i++] = ch
// [7] (byte~) main::$1 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [8] *((const word*) SCREEN + (byte~) main::$1) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// SCREEN[i++] = ch;
// [9] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// SCREEN[i++] = ch
// [10] (byte~) main::$2 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [11] *((const word*) SCREEN + (byte~) main::$2) ← (const word) main::ch -- pwuc1_derefidx_vbuaa=vwuc2
tay
lda #<ch
sta SCREEN,y
lda #>ch
sta SCREEN+1,y
// SCREEN[i++] = ch;
// [12] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
jmp __b1
}
// File Data

View File

@ -0,0 +1,16 @@
(label) @1
(label) @begin
(label) @end
(const word*) SCREEN = (word*) 1024
(void()) main()
(byte~) main::$1 reg byte a 22.0
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::ch = (number) $102
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 19.75
zp[1]:2 [ main::i ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]

View File

@ -30,9 +30,9 @@ main: {
}
// print2(byte* zeropage($fa) at, byte* zeropage($fc) msg)
print2: {
.label i = 2
.label msg = $fc
.label at = $fa
.label msg = $fc
.label i = 2
ldx #0
txa
sta.z i

View File

@ -10,50 +10,48 @@
(void()) main()
main: scope:[main] from @1
[4] phi()
[5] call print2
[4] (byte*) print2::at ← (const byte*) screen
[5] (byte*) print2::msg ← (const string) main::msg
[6] call print2
to:main::@1
main::@1: scope:[main] from main
[6] phi()
[7] call print2
[7] (byte*) print2::at ← (const byte*) screen+(byte) $50
[8] (byte*) print2::msg ← (const string) main::msg1
[9] call print2
to:main::@return
main::@return: scope:[main] from main::@1
[8] return
[10] return
to:@return
(void()) print2((byte*) print2::at , (byte*) print2::msg)
print2: scope:[print2] from main main::@1
[9] (byte*) print2::at#4 ← phi( main/(const byte*) screen main::@1/(const byte*) screen+(byte) $50 )
[9] (byte*) print2::msg#4 ← phi( main/(const string) main::msg main::@1/(const string) main::msg1 )
[11] phi()
to:print2::@1
print2::@1: scope:[print2] from print2 print2::@3
[10] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 )
[10] (byte*) print2::at#2 ← phi( print2/(byte*) print2::at#4 print2::@3/(byte*) print2::at#2 )
[10] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 )
[10] (byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@3/(byte*) print2::msg#2 )
[11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2
[12] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 )
[12] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 )
[13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2
to:print2::@return
print2::@return: scope:[print2] from print2::@1
[12] return
[14] return
to:@return
print2::@2: scope:[print2] from print2::@1
[13] (byte*) print_char::at#0 ← (byte*) print2::at#2
[14] (byte) print_char::idx#0 ← (byte) print2::j#2
[15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2)
[16] call print_char
[15] (byte*) print_char::at ← (byte*) print2::at
[16] (byte) print_char::idx#0 ← (byte) print2::j#2
[17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2)
[18] call print_char
to:print2::@3
print2::@3: scope:[print2] from print2::@2
[17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2
[18] (byte) print2::i#1 ← ++ (byte) print2::i#2
[19] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2
[20] (byte) print2::i#1 ← ++ (byte) print2::i#2
to:print2::@1
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
print_char: scope:[print_char] from print2::@2
[19] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 )
[19] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 )
[19] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 )
[20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1
[21] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 )
[21] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 )
[22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1
to:print_char::@return
print_char::@return: scope:[print_char] from print_char
[21] return
[23] return
to:@return

View File

@ -13,14 +13,14 @@ CONTROL FLOW GRAPH SSA
(void()) main()
main: scope:[main] from @3
(byte*) print2::at#0 ← (const byte*) screen
(byte*) print2::msg#0 ← (const string) main::msg
(byte*) print2::at ← (const byte*) screen
(byte*) print2::msg ← (const string) main::msg
call print2
to:main::@1
main::@1: scope:[main] from main
(byte*~) main::$1 ← (const byte*) screen + (number) $50
(byte*) print2::at#1 ← (byte*~) main::$1
(byte*) print2::msg#1 ← (const string) main::msg1
(byte*) print2::at ← (byte*~) main::$1
(byte*) print2::msg ← (const string) main::msg1
call print2
to:main::@2
main::@2: scope:[main] from main::@1
@ -31,32 +31,24 @@ main::@return: scope:[main] from main::@2
(void()) print2((byte*) print2::at , (byte*) print2::msg)
print2: scope:[print2] from main main::@1
(byte*) print2::at#4 ← phi( main/(byte*) print2::at#0 main::@1/(byte*) print2::at#1 )
(byte*) print2::msg#4 ← phi( main/(byte*) print2::msg#0 main::@1/(byte*) print2::msg#1 )
(byte) print2::j#0 ← (number) 0
(byte) print2::i#0 ← (number) 0
to:print2::@1
print2::@1: scope:[print2] from print2 print2::@7
(byte) print2::j#4 ← phi( print2/(byte) print2::j#0 print2::@7/(byte) print2::j#1 )
(byte*) print2::at#3 ← phi( print2/(byte*) print2::at#4 print2::@7/(byte*) print2::at#5 )
(byte) print2::i#2 ← phi( print2/(byte) print2::i#0 print2::@7/(byte) print2::i#1 )
(byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@7/(byte*) print2::msg#5 )
(bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#2 + (byte) print2::i#2)
(bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg + (byte) print2::i#2)
if((bool~) print2::$1) goto print2::@2
to:print2::@return
print2::@2: scope:[print2] from print2::@1
(byte) print2::i#3 ← phi( print2::@1/(byte) print2::i#2 )
(byte*) print2::msg#3 ← phi( print2::@1/(byte*) print2::msg#2 )
(byte) print2::j#2 ← phi( print2::@1/(byte) print2::j#4 )
(byte*) print2::at#2 ← phi( print2::@1/(byte*) print2::at#3 )
(byte*) print_char::at#0 ← (byte*) print2::at#2
(byte*) print_char::at ← (byte*) print2::at
(byte) print_char::idx#0 ← (byte) print2::j#2
(byte) print_char::ch#0 ← *((byte*) print2::msg#3 + (byte) print2::i#3)
(byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#3)
call print_char
to:print2::@7
print2::@7: scope:[print2] from print2::@2
(byte*) print2::at#5 ← phi( print2::@2/(byte*) print2::at#2 )
(byte*) print2::msg#5 ← phi( print2::@2/(byte*) print2::msg#3 )
(byte) print2::i#4 ← phi( print2::@2/(byte) print2::i#3 )
(byte) print2::j#3 ← phi( print2::@2/(byte) print2::j#2 )
(byte) print2::j#1 ← (byte) print2::j#3 + (number) 2
@ -69,9 +61,8 @@ print2::@return: scope:[print2] from print2::@1
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
print_char: scope:[print_char] from print2::@2
(byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 )
(byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 )
(byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 )
*((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1
*((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1
to:print_char::@return
print_char::@return: scope:[print_char] from print_char
return
@ -101,13 +92,7 @@ SYMBOL TABLE SSA
(label) print2::@2
(label) print2::@7
(label) print2::@return
(byte*) print2::at !zp[-1]:250
(byte*) print2::at#0 !zp[-1]:250
(byte*) print2::at#1 !zp[-1]:250
(byte*) print2::at#2 !zp[-1]:250
(byte*) print2::at#3 !zp[-1]:250
(byte*) print2::at#4 !zp[-1]:250
(byte*) print2::at#5 !zp[-1]:250
(byte*) print2::at loadstore !zp[-1]:250
(byte) print2::i
(byte) print2::i#0
(byte) print2::i#1
@ -120,18 +105,10 @@ SYMBOL TABLE SSA
(byte) print2::j#2
(byte) print2::j#3
(byte) print2::j#4
(byte*) print2::msg !zp[-1]:252
(byte*) print2::msg#0 !zp[-1]:252
(byte*) print2::msg#1 !zp[-1]:252
(byte*) print2::msg#2 !zp[-1]:252
(byte*) print2::msg#3 !zp[-1]:252
(byte*) print2::msg#4 !zp[-1]:252
(byte*) print2::msg#5 !zp[-1]:252
(byte*) print2::msg loadstore !zp[-1]:252
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
(label) print_char::@return
(byte*) print_char::at !zp[-1]:250
(byte*) print_char::at#0 !zp[-1]:250
(byte*) print_char::at#1 !zp[-1]:250
(byte*) print_char::at loadstore !zp[-1]:250
(byte) print_char::ch !reg byte a
(byte) print_char::ch#0 !reg byte a
(byte) print_char::ch#1 !reg byte a
@ -143,7 +120,7 @@ SYMBOL TABLE SSA
Adding number conversion cast (unumber) $50 in (byte*~) main::$1 ← (const byte*) screen + (number) $50
Adding number conversion cast (unumber) 0 in (byte) print2::j#0 ← (number) 0
Adding number conversion cast (unumber) 0 in (byte) print2::i#0 ← (number) 0
Adding number conversion cast (unumber) 0 in (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg#2 + (byte) print2::i#2)
Adding number conversion cast (unumber) 0 in (bool~) print2::$1 ← (number) 0 != *((byte*) print2::msg + (byte) print2::i#2)
Adding number conversion cast (unumber) 2 in (byte) print2::j#1 ← (byte) print2::j#3 + (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) print2::j#0 ← (unumber)(number) 0
@ -162,59 +139,42 @@ Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte*) print2::at#1 = (byte*~) main::$1
Alias (byte*) print2::at#2 = (byte*) print2::at#3 (byte*) print2::at#5
Alias candidate removed (volatile)(byte*) print2::at = (byte*~) main::$1
Alias (byte) print2::j#2 = (byte) print2::j#4 (byte) print2::j#3
Alias (byte*) print2::msg#2 = (byte*) print2::msg#3 (byte*) print2::msg#5
Alias (byte) print2::i#2 = (byte) print2::i#3 (byte) print2::i#4
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) print2::$1 [13] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2
Alias candidate removed (volatile)(byte*) print2::at = (byte*~) main::$1
Simple Condition (bool~) print2::$1 [12] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [3] (byte*) print2::at#1 ← (const byte*) screen + (byte) $50
Constant right-side identified [3] (byte*~) main::$1 ← (const byte*) screen + (byte) $50
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) print2::at#0 = screen
Constant (const byte*) print2::msg#0 = main::msg
Constant (const byte*) print2::at#1 = screen+$50
Constant (const byte*) print2::msg#1 = main::msg1
Constant (const byte*) main::$1 = screen+$50
Constant (const byte) print2::j#0 = 0
Constant (const byte) print2::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte*) print2::at#0
Inlining constant with var siblings (const byte*) print2::msg#0
Inlining constant with var siblings (const byte*) print2::at#1
Inlining constant with var siblings (const byte*) print2::msg#1
Inlining constant with var siblings (const byte) print2::j#0
Inlining constant with var siblings (const byte) print2::i#0
Constant inlined print2::at#1 = (const byte*) screen+(byte) $50
Constant inlined print2::at#0 = (const byte*) screen
Constant inlined print2::msg#1 = (const string) main::msg1
Constant inlined main::$1 = (const byte*) screen+(byte) $50
Constant inlined print2::j#0 = (byte) 0
Constant inlined print2::msg#0 = (const string) main::msg
Constant inlined print2::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
Adding NOP phi() at start of @4
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
Adding NOP phi() at start of print2
CALL GRAPH
Calls in [] to main:2
Calls in [main] to print2:6 print2:8
Calls in [print2] to print_char:23
Calls in [main] to print2:7 print2:10
Calls in [print2] to print_char:22
Created 9 initial phi equivalence classes
Coalesced [12] print2::msg#6 ← print2::msg#4
Coalesced [13] print2::at#6 ← print2::at#4
Created 4 initial phi equivalence classes
Coalesced [20] print_char::ch#2 ← print_char::ch#0
Coalesced [21] print_char::at#2 ← print_char::at#0
Coalesced [22] print_char::idx#2 ← print_char::idx#0
Coalesced (already) [26] print2::msg#7 ← print2::msg#2
Coalesced [27] print2::i#5 ← print2::i#1
Coalesced (already) [28] print2::at#7 ← print2::at#2
Coalesced [29] print2::j#5 ← print2::j#1
Coalesced down to 7 phi equivalence classes
Coalesced [21] print_char::idx#2 ← print_char::idx#0
Coalesced [25] print2::i#5 ← print2::i#1
Coalesced [26] print2::j#5 ← print2::j#1
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) main::@2
Renumbering block @3 to @1
@ -222,8 +182,7 @@ Renumbering block print2::@7 to print2::@3
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 print2
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
@ -238,74 +197,66 @@ FINAL CONTROL FLOW GRAPH
(void()) main()
main: scope:[main] from @1
[4] phi()
[5] call print2
[4] (byte*) print2::at ← (const byte*) screen
[5] (byte*) print2::msg ← (const string) main::msg
[6] call print2
to:main::@1
main::@1: scope:[main] from main
[6] phi()
[7] call print2
[7] (byte*) print2::at ← (const byte*) screen+(byte) $50
[8] (byte*) print2::msg ← (const string) main::msg1
[9] call print2
to:main::@return
main::@return: scope:[main] from main::@1
[8] return
[10] return
to:@return
(void()) print2((byte*) print2::at , (byte*) print2::msg)
print2: scope:[print2] from main main::@1
[9] (byte*) print2::at#4 ← phi( main/(const byte*) screen main::@1/(const byte*) screen+(byte) $50 )
[9] (byte*) print2::msg#4 ← phi( main/(const string) main::msg main::@1/(const string) main::msg1 )
[11] phi()
to:print2::@1
print2::@1: scope:[print2] from print2 print2::@3
[10] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 )
[10] (byte*) print2::at#2 ← phi( print2/(byte*) print2::at#4 print2::@3/(byte*) print2::at#2 )
[10] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 )
[10] (byte*) print2::msg#2 ← phi( print2/(byte*) print2::msg#4 print2::@3/(byte*) print2::msg#2 )
[11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2
[12] (byte) print2::j#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::j#1 )
[12] (byte) print2::i#2 ← phi( print2/(byte) 0 print2::@3/(byte) print2::i#1 )
[13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2
to:print2::@return
print2::@return: scope:[print2] from print2::@1
[12] return
[14] return
to:@return
print2::@2: scope:[print2] from print2::@1
[13] (byte*) print_char::at#0 ← (byte*) print2::at#2
[14] (byte) print_char::idx#0 ← (byte) print2::j#2
[15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2)
[16] call print_char
[15] (byte*) print_char::at ← (byte*) print2::at
[16] (byte) print_char::idx#0 ← (byte) print2::j#2
[17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2)
[18] call print_char
to:print2::@3
print2::@3: scope:[print2] from print2::@2
[17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2
[18] (byte) print2::i#1 ← ++ (byte) print2::i#2
[19] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2
[20] (byte) print2::i#1 ← ++ (byte) print2::i#2
to:print2::@1
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
print_char: scope:[print_char] from print2::@2
[19] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 )
[19] (byte*) print_char::at#1 ← phi( print2::@2/(byte*) print_char::at#0 )
[19] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 )
[20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1
[21] (byte) print_char::idx#1 ← phi( print2::@2/(byte) print_char::idx#0 )
[21] (byte) print_char::ch#1 ← phi( print2::@2/(byte) print_char::ch#0 )
[22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1
to:print_char::@return
print_char::@return: scope:[print_char] from print_char
[21] return
[23] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(void()) print2((byte*) print2::at , (byte*) print2::msg)
(byte*) print2::at !zp[-1]:250
(byte*) print2::at#2 !zp[-1]:250 4.375
(byte*) print2::at#4 !zp[-1]:250 2.0
(byte*) print2::at loadstore !zp[-1]:250 1.1538461538461537
(byte) print2::i
(byte) print2::i#1 22.0
(byte) print2::i#2 6.285714285714286
(byte) print2::j
(byte) print2::j#1 11.0
(byte) print2::j#2 5.5
(byte*) print2::msg !zp[-1]:252
(byte*) print2::msg#2 !zp[-1]:252 5.75
(byte*) print2::msg#4 !zp[-1]:252 2.0
(byte*) print2::msg loadstore !zp[-1]:252 2.3636363636363638
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
(byte*) print_char::at !zp[-1]:250
(byte*) print_char::at#0 !zp[-1]:250 7.333333333333333
(byte*) print_char::at#1 !zp[-1]:250 13.0
(byte*) print_char::at loadstore !zp[-1]:250 3.25
(byte) print_char::ch !reg byte a
(byte) print_char::ch#0 !reg byte a 22.0
(byte) print_char::ch#1 !reg byte a 13.0
@ -314,21 +265,21 @@ VARIABLE REGISTER WEIGHTS
(byte) print_char::idx#1 !reg byte x 13.0
Initial phi equivalence classes
[ print2::msg#2 print2::msg#4 ]
[ print2::i#2 print2::i#1 ]
[ print2::at#2 print2::at#4 ]
[ print2::j#2 print2::j#1 ]
[ print_char::ch#1 print_char::ch#0 ]
[ print_char::at#1 print_char::at#0 ]
[ print_char::idx#1 print_char::idx#0 ]
Added variable print2::at to live range equivalence class [ print2::at ]
Added variable print2::msg to live range equivalence class [ print2::msg ]
Added variable print_char::at to live range equivalence class [ print_char::at ]
Complete equivalence classes
[ print2::msg#2 print2::msg#4 ]
[ print2::i#2 print2::i#1 ]
[ print2::at#2 print2::at#4 ]
[ print2::j#2 print2::j#1 ]
[ print_char::ch#1 print_char::ch#0 ]
[ print_char::at#1 print_char::at#0 ]
[ print_char::idx#1 print_char::idx#0 ]
[ print2::at ]
[ print2::msg ]
[ print_char::at ]
Allocated zp[1]:2 [ print2::i#2 print2::i#1 ]
Allocated zp[1]:3 [ print2::j#2 print2::j#1 ]
@ -350,8 +301,6 @@ __b1_from___bbegin:
// @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:
@ -360,43 +309,41 @@ __bend_from___b1:
__bend:
// main
main: {
// [5] call print2
// [9] phi from main to print2 [phi:main->print2]
print2_from_main:
// [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1
// [4] (byte*) print2::at ← (const byte*) screen -- pbuz1=pbuc1
lda #<screen
sta.z print2.at
lda #>screen
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1
// [5] (byte*) print2::msg ← (const string) main::msg -- pbuz1=pbuc1
lda #<msg
sta.z print2.msg
lda #>msg
sta.z print2.msg+1
// [6] call print2
// [11] phi from main to print2 [phi:main->print2]
print2_from_main:
jsr print2
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print2
// [9] phi from main::@1 to print2 [phi:main::@1->print2]
print2_from___b1:
// [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1
// [7] (byte*) print2::at ← (const byte*) screen+(byte) $50 -- pbuz1=pbuc1
lda #<screen+$50
sta.z print2.at
lda #>screen+$50
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1
// [8] (byte*) print2::msg ← (const string) main::msg1 -- pbuz1=pbuc1
lda #<msg1
sta.z print2.msg
lda #>msg1
sta.z print2.msg+1
// [9] call print2
// [11] phi from main::@1 to print2 [phi:main::@1->print2]
print2_from___b1:
jsr print2
jmp __breturn
// main::@return
__breturn:
// [8] return
// [10] return
rts
msg: .text "hello"
.byte 0
@ -406,24 +353,22 @@ main: {
// print2
// print2(byte* zeropage($fa) at, byte* zeropage($fc) msg)
print2: {
.label at = $fa
.label msg = $fc
.label j = 3
.label i = 2
.label msg = $fc
.label at = $fa
// [10] phi from print2 to print2::@1 [phi:print2->print2::@1]
// [12] phi from print2 to print2::@1 [phi:print2->print2::@1]
__b1_from_print2:
// [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuz1=vbuc1
// [12] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuz1=vbuc1
lda #0
sta.z j
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1
// [12] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#1] -- vbuz1=vbuc1
lda #0
sta.z i
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy
jmp __b1
// print2::@1
__b1:
// [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
// [13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
ldy.z i
lda (msg),y
cmp #0
@ -431,89 +376,94 @@ print2: {
jmp __breturn
// print2::@return
__breturn:
// [12] return
// [14] return
rts
// print2::@2
__b2:
// [13] (byte*) print_char::at#0 ← (byte*) print2::at#2
// [14] (byte) print_char::idx#0 ← (byte) print2::j#2 -- vbuxx=vbuz1
// [15] (byte*) print_char::at ← (byte*) print2::at
// [16] (byte) print_char::idx#0 ← (byte) print2::j#2 -- vbuxx=vbuz1
ldx.z j
// [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
// [17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
ldy.z i
lda (msg),y
// [16] call print_char
// [19] phi from print2::@2 to print_char [phi:print2::@2->print_char]
// [18] call print_char
// [21] phi from print2::@2 to print_char [phi:print2::@2->print_char]
print_char_from___b2:
// [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy
// [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy
// [21] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [21] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#1] -- register_copy
jsr print_char
jmp __b3
// print2::@3
__b3:
// [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuz1=vbuz1_plus_2
// [19] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuz1=vbuz1_plus_2
lda.z j
clc
adc #2
sta.z j
// [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
// [20] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
inc.z i
// [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
// [12] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
__b1_from___b3:
// [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy
// [12] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [12] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#1] -- register_copy
jmp __b1
}
// print_char
// print_char(byte* zeropage($fa) at, byte register(X) idx, byte register(A) ch)
print_char: {
.label at = $fa
// [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
// [22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
stx.z $ff
ldy.z $ff
sta (at),y
jmp __breturn
// print_char::@return
__breturn:
// [21] return
// [23] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte a
Statement [4] (byte*) print2::at ← (const byte*) screen [ print2::at ] ( main:2 [ print2::at ] ) always clobbers reg byte a
Statement [5] (byte*) print2::msg ← (const string) main::msg [ print2::at print2::msg ] ( main:2 [ print2::at print2::msg ] ) always clobbers reg byte a
Statement [7] (byte*) print2::at ← (const byte*) screen+(byte) $50 [ print2::at ] ( main:2 [ print2::at ] ) always clobbers reg byte a
Statement [8] (byte*) print2::msg ← (const string) main::msg1 [ print2::at print2::msg ] ( main:2 [ print2::at print2::msg ] ) always clobbers reg byte a
Statement [13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2 [ print2::at print2::msg print2::i#2 print2::j#2 ] ( main:2::print2:6 [ print2::at print2::msg print2::i#2 print2::j#2 ] main:2::print2:9 [ print2::at print2::msg print2::i#2 print2::j#2 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:2 [ print2::i#2 print2::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ print2::j#2 print2::j#1 ]
Statement [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a
Statement [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte y
Statement [17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2) [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] ( main:2::print2:6 [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] main:2::print2:9 [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a
Statement [22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:6::print_char:18 [ print2::at print2::msg print2::i#2 print2::j#2 ] main:2::print2:9::print_char:18 [ print2::at print2::msg print2::i#2 print2::j#2 ] ) always clobbers reg byte y
Removing always clobbered register reg byte y as potential for zp[1]:2 [ print2::i#2 print2::i#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:3 [ print2::j#2 print2::j#1 ]
Statement [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte a reg byte y
Statement [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ( main:2::print2:5 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] main:2::print2:7 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 print_char::at#0 print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a reg byte y
Statement [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:5::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] main:2::print2:7::print_char:16 [ print2::msg#2 print2::i#2 print2::at#2 print2::j#2 ] ) always clobbers reg byte y
Potential registers zp[2]:252 [ print2::msg#2 print2::msg#4 ] : zp[2]:252 ,
Statement [4] (byte*) print2::at ← (const byte*) screen [ print2::at ] ( main:2 [ print2::at ] ) always clobbers reg byte a
Statement [5] (byte*) print2::msg ← (const string) main::msg [ print2::at print2::msg ] ( main:2 [ print2::at print2::msg ] ) always clobbers reg byte a
Statement [7] (byte*) print2::at ← (const byte*) screen+(byte) $50 [ print2::at ] ( main:2 [ print2::at ] ) always clobbers reg byte a
Statement [8] (byte*) print2::msg ← (const string) main::msg1 [ print2::at print2::msg ] ( main:2 [ print2::at print2::msg ] ) always clobbers reg byte a
Statement [13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2 [ print2::at print2::msg print2::i#2 print2::j#2 ] ( main:2::print2:6 [ print2::at print2::msg print2::i#2 print2::j#2 ] main:2::print2:9 [ print2::at print2::msg print2::i#2 print2::j#2 ] ) always clobbers reg byte a reg byte y
Statement [17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2) [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] ( main:2::print2:6 [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] main:2::print2:9 [ print2::at print2::msg print2::i#2 print2::j#2 print_char::at print_char::idx#0 print_char::ch#0 ] ) always clobbers reg byte a reg byte y
Statement [22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1 [ ] ( main:2::print2:6::print_char:18 [ print2::at print2::msg print2::i#2 print2::j#2 ] main:2::print2:9::print_char:18 [ print2::at print2::msg print2::i#2 print2::j#2 ] ) always clobbers reg byte y
Potential registers zp[1]:2 [ print2::i#2 print2::i#1 ] : zp[1]:2 , reg byte x ,
Potential registers zp[2]:250 [ print2::at#2 print2::at#4 ] : zp[2]:250 ,
Potential registers zp[1]:3 [ print2::j#2 print2::j#1 ] : zp[1]:3 , reg byte x ,
Potential registers reg byte a [ print_char::ch#1 print_char::ch#0 ] : reg byte a ,
Potential registers zp[2]:250 [ print_char::at#1 print_char::at#0 ] : zp[2]:250 ,
Potential registers reg byte x [ print_char::idx#1 print_char::idx#0 ] : reg byte x ,
Potential registers zp[2]:250 [ print2::at ] : zp[2]:250 ,
Potential registers zp[2]:252 [ print2::msg ] : zp[2]:252 ,
Potential registers zp[2]:250 [ print_char::at ] : zp[2]:250 ,
REGISTER UPLIFT SCOPES
Uplift Scope [print_char] 35: reg byte a [ print_char::ch#1 print_char::ch#0 ] 24: reg byte x [ print_char::idx#1 print_char::idx#0 ] 20.33: zp[2]:250 [ print_char::at#1 print_char::at#0 ]
Uplift Scope [print2] 28.29: zp[1]:2 [ print2::i#2 print2::i#1 ] 16.5: zp[1]:3 [ print2::j#2 print2::j#1 ] 7.75: zp[2]:252 [ print2::msg#2 print2::msg#4 ] 6.38: zp[2]:250 [ print2::at#2 print2::at#4 ]
Uplift Scope [print_char] 35: reg byte a [ print_char::ch#1 print_char::ch#0 ] 24: reg byte x [ print_char::idx#1 print_char::idx#0 ] 3.25: zp[2]:250 [ print_char::at ]
Uplift Scope [print2] 28.29: zp[1]:2 [ print2::i#2 print2::i#1 ] 16.5: zp[1]:3 [ print2::j#2 print2::j#1 ] 2.36: zp[2]:252 [ print2::msg ] 1.15: zp[2]:250 [ print2::at ]
Uplift Scope [main]
Uplift Scope []
Uplifting [print_char] best 697 combination reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ] zp[2]:250 [ print_char::at#1 print_char::at#0 ]
Uplifting [print2] best 577 combination zp[1]:2 [ print2::i#2 print2::i#1 ] reg byte x [ print2::j#2 print2::j#1 ] zp[2]:252 [ print2::msg#2 print2::msg#4 ] zp[2]:250 [ print2::at#2 print2::at#4 ]
Uplifting [print_char] best 697 combination reg byte a [ print_char::ch#1 print_char::ch#0 ] reg byte x [ print_char::idx#1 print_char::idx#0 ] zp[2]:250 [ print_char::at ]
Uplifting [print2] best 577 combination zp[1]:2 [ print2::i#2 print2::i#1 ] reg byte x [ print2::j#2 print2::j#1 ] zp[2]:252 [ print2::msg ] zp[2]:250 [ print2::at ]
Uplifting [main] best 577 combination
Uplifting [] best 577 combination
Attempting to uplift remaining variables inzp[1]:2 [ print2::i#2 print2::i#1 ]
Uplifting [print2] best 577 combination zp[1]:2 [ print2::i#2 print2::i#1 ]
Coalescing zero page register [ zp[2]:250 [ print2::at#2 print2::at#4 ] ] with [ zp[2]:250 [ print_char::at#1 print_char::at#0 ] ] - score: 1
Coalescing zero page register [ zp[2]:250 [ print2::at ] ] with [ zp[2]:250 [ print_char::at ] ] - score: 1
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
@ -532,8 +482,6 @@ __b1_from___bbegin:
// @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:
@ -542,43 +490,41 @@ __bend_from___b1:
__bend:
// main
main: {
// [5] call print2
// [9] phi from main to print2 [phi:main->print2]
print2_from_main:
// [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1
// [4] (byte*) print2::at ← (const byte*) screen -- pbuz1=pbuc1
lda #<screen
sta.z print2.at
lda #>screen
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1
// [5] (byte*) print2::msg ← (const string) main::msg -- pbuz1=pbuc1
lda #<msg
sta.z print2.msg
lda #>msg
sta.z print2.msg+1
// [6] call print2
// [11] phi from main to print2 [phi:main->print2]
print2_from_main:
jsr print2
// [6] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
jmp __b1
// main::@1
__b1:
// [7] call print2
// [9] phi from main::@1 to print2 [phi:main::@1->print2]
print2_from___b1:
// [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1
// [7] (byte*) print2::at ← (const byte*) screen+(byte) $50 -- pbuz1=pbuc1
lda #<screen+$50
sta.z print2.at
lda #>screen+$50
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1
// [8] (byte*) print2::msg ← (const string) main::msg1 -- pbuz1=pbuc1
lda #<msg1
sta.z print2.msg
lda #>msg1
sta.z print2.msg+1
// [9] call print2
// [11] phi from main::@1 to print2 [phi:main::@1->print2]
print2_from___b1:
jsr print2
jmp __breturn
// main::@return
__breturn:
// [8] return
// [10] return
rts
msg: .text "hello"
.byte 0
@ -588,22 +534,20 @@ main: {
// print2
// print2(byte* zeropage($fa) at, byte* zeropage($fc) msg)
print2: {
.label i = 2
.label msg = $fc
.label at = $fa
// [10] phi from print2 to print2::@1 [phi:print2->print2::@1]
.label msg = $fc
.label i = 2
// [12] phi from print2 to print2::@1 [phi:print2->print2::@1]
__b1_from_print2:
// [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1
// [12] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1
ldx #0
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1
// [12] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#1] -- vbuz1=vbuc1
lda #0
sta.z i
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy
jmp __b1
// print2::@1
__b1:
// [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
// [13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
ldy.z i
lda (msg),y
cmp #0
@ -611,50 +555,47 @@ print2: {
jmp __breturn
// print2::@return
__breturn:
// [12] return
// [14] return
rts
// print2::@2
__b2:
// [13] (byte*) print_char::at#0 ← (byte*) print2::at#2
// [14] (byte) print_char::idx#0 ← (byte) print2::j#2
// [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
// [15] (byte*) print_char::at ← (byte*) print2::at
// [16] (byte) print_char::idx#0 ← (byte) print2::j#2
// [17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
ldy.z i
lda (msg),y
// [16] call print_char
// [19] phi from print2::@2 to print_char [phi:print2::@2->print_char]
// [18] call print_char
// [21] phi from print2::@2 to print_char [phi:print2::@2->print_char]
print_char_from___b2:
// [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy
// [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy
// [21] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [21] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#1] -- register_copy
jsr print_char
jmp __b3
// print2::@3
__b3:
// [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2
// [19] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2
inx
inx
// [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
// [20] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
inc.z i
// [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
// [12] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
__b1_from___b3:
// [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy
// [12] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [12] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#1] -- register_copy
jmp __b1
}
// print_char
// print_char(byte* zeropage($fa) at, byte register(X) idx, byte register(A) ch)
print_char: {
.label at = $fa
// [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
// [22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
stx.z $ff
ldy.z $ff
sta (at),y
jmp __breturn
// print_char::@return
__breturn:
// [21] return
// [23] return
rts
}
// File Data
@ -673,14 +614,12 @@ Replacing instruction lda #0 with TXA
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 print2_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction print2_from_main:
Removing instruction __b1:
Removing instruction print2_from___b1:
Removing instruction __breturn:
Removing instruction __b1_from_print2:
Removing instruction __breturn:
@ -709,23 +648,17 @@ FINAL SYMBOL TABLE
(label) print2::@2
(label) print2::@3
(label) print2::@return
(byte*) print2::at !zp[-1]:250
(byte*) print2::at#2 at !zp[-1]:250 zp[2]:250 4.375
(byte*) print2::at#4 at !zp[-1]:250 zp[2]:250 2.0
(byte*) print2::at loadstore !zp[-1]:250 zp[2]:250 1.1538461538461537
(byte) print2::i
(byte) print2::i#1 i zp[1]:2 22.0
(byte) print2::i#2 i zp[1]:2 6.285714285714286
(byte) print2::j
(byte) print2::j#1 reg byte x 11.0
(byte) print2::j#2 reg byte x 5.5
(byte*) print2::msg !zp[-1]:252
(byte*) print2::msg#2 msg !zp[-1]:252 zp[2]:252 5.75
(byte*) print2::msg#4 msg !zp[-1]:252 zp[2]:252 2.0
(byte*) print2::msg loadstore !zp[-1]:252 zp[2]:252 2.3636363636363638
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
(label) print_char::@return
(byte*) print_char::at !zp[-1]:250
(byte*) print_char::at#0 at !zp[-1]:250 zp[2]:250 7.333333333333333
(byte*) print_char::at#1 at !zp[-1]:250 zp[2]:250 13.0
(byte*) print_char::at loadstore !zp[-1]:250 zp[2]:250 3.25
(byte) print_char::ch !reg byte a
(byte) print_char::ch#0 !reg byte a 22.0
(byte) print_char::ch#1 !reg byte a 13.0
@ -734,12 +667,12 @@ FINAL SYMBOL TABLE
(byte) print_char::idx#1 !reg byte x 13.0
(const byte*) screen = (byte*) 1024
zp[2]:252 [ print2::msg#2 print2::msg#4 ]
zp[1]:2 [ print2::i#2 print2::i#1 ]
zp[2]:250 [ print2::at#2 print2::at#4 print_char::at#1 print_char::at#0 ]
reg byte x [ print2::j#2 print2::j#1 ]
reg byte a [ print_char::ch#1 print_char::ch#0 ]
reg byte x [ print_char::idx#1 print_char::idx#0 ]
zp[2]:250 [ print2::at print_char::at ]
zp[2]:252 [ print2::msg ]
FINAL ASSEMBLER
@ -757,44 +690,42 @@ Score: 493
// [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: {
// print2(screen, "hello")
// [5] call print2
// [9] phi from main to print2 [phi:main->print2]
// [9] phi (byte*) print2::at#4 = (const byte*) screen [phi:main->print2#0] -- pbuz1=pbuc1
// [4] (byte*) print2::at ← (const byte*) screen -- pbuz1=pbuc1
lda #<screen
sta.z print2.at
lda #>screen
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg [phi:main->print2#1] -- pbuz1=pbuc1
// [5] (byte*) print2::msg ← (const string) main::msg -- pbuz1=pbuc1
lda #<msg
sta.z print2.msg
lda #>msg
sta.z print2.msg+1
// [6] call print2
// [11] phi from main to print2 [phi:main->print2]
jsr print2
// [6] phi from main to main::@1 [phi:main->main::@1]
// main::@1
// print2(screen+80, "world")
// [7] call print2
// [9] phi from main::@1 to print2 [phi:main::@1->print2]
// [9] phi (byte*) print2::at#4 = (const byte*) screen+(byte) $50 [phi:main::@1->print2#0] -- pbuz1=pbuc1
// [7] (byte*) print2::at ← (const byte*) screen+(byte) $50 -- pbuz1=pbuc1
lda #<screen+$50
sta.z print2.at
lda #>screen+$50
sta.z print2.at+1
// [9] phi (byte*) print2::msg#4 = (const string) main::msg1 [phi:main::@1->print2#1] -- pbuz1=pbuc1
// [8] (byte*) print2::msg ← (const string) main::msg1 -- pbuz1=pbuc1
lda #<msg1
sta.z print2.msg
lda #>msg1
sta.z print2.msg+1
// [9] call print2
// [11] phi from main::@1 to print2 [phi:main::@1->print2]
jsr print2
// main::@return
// }
// [8] return
// [10] return
rts
msg: .text "hello"
.byte 0
@ -804,56 +735,51 @@ main: {
// print2
// print2(byte* zeropage($fa) at, byte* zeropage($fc) msg)
print2: {
.label i = 2
.label msg = $fc
.label at = $fa
// [10] phi from print2 to print2::@1 [phi:print2->print2::@1]
// [10] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1
.label msg = $fc
.label i = 2
// [12] phi from print2 to print2::@1 [phi:print2->print2::@1]
// [12] phi (byte) print2::j#2 = (byte) 0 [phi:print2->print2::@1#0] -- vbuxx=vbuc1
ldx #0
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#4 [phi:print2->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#2] -- vbuz1=vbuc1
// [12] phi (byte) print2::i#2 = (byte) 0 [phi:print2->print2::@1#1] -- vbuz1=vbuc1
txa
sta.z i
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#4 [phi:print2->print2::@1#3] -- register_copy
// print2::@1
__b1:
// for(byte i=0; msg[i]; i++)
// [11] if((byte) 0!=*((byte*) print2::msg#2 + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
// [13] if((byte) 0!=*((byte*) print2::msg + (byte) print2::i#2)) goto print2::@2 -- vbuc1_neq_pbuz1_derefidx_vbuz2_then_la1
ldy.z i
lda (msg),y
cmp #0
bne __b2
// print2::@return
// }
// [12] return
// [14] return
rts
// print2::@2
__b2:
// print_char(at, j, msg[i])
// [13] (byte*) print_char::at#0 ← (byte*) print2::at#2
// [14] (byte) print_char::idx#0 ← (byte) print2::j#2
// [15] (byte) print_char::ch#0 ← *((byte*) print2::msg#2 + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
// [15] (byte*) print_char::at ← (byte*) print2::at
// [16] (byte) print_char::idx#0 ← (byte) print2::j#2
// [17] (byte) print_char::ch#0 ← *((byte*) print2::msg + (byte) print2::i#2) -- vbuaa=pbuz1_derefidx_vbuz2
ldy.z i
lda (msg),y
// [16] call print_char
// [19] phi from print2::@2 to print_char [phi:print2::@2->print_char]
// [19] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [19] phi (byte*) print_char::at#1 = (byte*) print_char::at#0 [phi:print2::@2->print_char#1] -- register_copy
// [19] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#2] -- register_copy
// [18] call print_char
// [21] phi from print2::@2 to print_char [phi:print2::@2->print_char]
// [21] phi (byte) print_char::idx#1 = (byte) print_char::idx#0 [phi:print2::@2->print_char#0] -- register_copy
// [21] phi (byte) print_char::ch#1 = (byte) print_char::ch#0 [phi:print2::@2->print_char#1] -- register_copy
jsr print_char
// print2::@3
// j += 2
// [17] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2
// [19] (byte) print2::j#1 ← (byte) print2::j#2 + (byte) 2 -- vbuxx=vbuxx_plus_2
inx
inx
// for(byte i=0; msg[i]; i++)
// [18] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
// [20] (byte) print2::i#1 ← ++ (byte) print2::i#2 -- vbuz1=_inc_vbuz1
inc.z i
// [10] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
// [10] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [10] phi (byte*) print2::at#2 = (byte*) print2::at#2 [phi:print2::@3->print2::@1#1] -- register_copy
// [10] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#2] -- register_copy
// [10] phi (byte*) print2::msg#2 = (byte*) print2::msg#2 [phi:print2::@3->print2::@1#3] -- register_copy
// [12] phi from print2::@3 to print2::@1 [phi:print2::@3->print2::@1]
// [12] phi (byte) print2::j#2 = (byte) print2::j#1 [phi:print2::@3->print2::@1#0] -- register_copy
// [12] phi (byte) print2::i#2 = (byte) print2::i#1 [phi:print2::@3->print2::@1#1] -- register_copy
jmp __b1
}
// print_char
@ -861,13 +787,13 @@ print2: {
print_char: {
.label at = $fa
// at[idx] = ch
// [20] *((byte*) print_char::at#1 + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
// [22] *((byte*) print_char::at + (byte) print_char::idx#1) ← (byte) print_char::ch#1 -- pbuz1_derefidx_vbuxx=vbuaa
stx.z $ff
ldy.z $ff
sta (at),y
// print_char::@return
// }
// [21] return
// [23] return
rts
}
// File Data

View File

@ -11,23 +11,17 @@
(label) print2::@2
(label) print2::@3
(label) print2::@return
(byte*) print2::at !zp[-1]:250
(byte*) print2::at#2 at !zp[-1]:250 zp[2]:250 4.375
(byte*) print2::at#4 at !zp[-1]:250 zp[2]:250 2.0
(byte*) print2::at loadstore !zp[-1]:250 zp[2]:250 1.1538461538461537
(byte) print2::i
(byte) print2::i#1 i zp[1]:2 22.0
(byte) print2::i#2 i zp[1]:2 6.285714285714286
(byte) print2::j
(byte) print2::j#1 reg byte x 11.0
(byte) print2::j#2 reg byte x 5.5
(byte*) print2::msg !zp[-1]:252
(byte*) print2::msg#2 msg !zp[-1]:252 zp[2]:252 5.75
(byte*) print2::msg#4 msg !zp[-1]:252 zp[2]:252 2.0
(byte*) print2::msg loadstore !zp[-1]:252 zp[2]:252 2.3636363636363638
(void()) print_char((byte*) print_char::at , (byte) print_char::idx , (byte) print_char::ch)
(label) print_char::@return
(byte*) print_char::at !zp[-1]:250
(byte*) print_char::at#0 at !zp[-1]:250 zp[2]:250 7.333333333333333
(byte*) print_char::at#1 at !zp[-1]:250 zp[2]:250 13.0
(byte*) print_char::at loadstore !zp[-1]:250 zp[2]:250 3.25
(byte) print_char::ch !reg byte a
(byte) print_char::ch#0 !reg byte a 22.0
(byte) print_char::ch#1 !reg byte a 13.0
@ -36,9 +30,9 @@
(byte) print_char::idx#1 !reg byte x 13.0
(const byte*) screen = (byte*) 1024
zp[2]:252 [ print2::msg#2 print2::msg#4 ]
zp[1]:2 [ print2::i#2 print2::i#1 ]
zp[2]:250 [ print2::at#2 print2::at#4 print_char::at#1 print_char::at#0 ]
reg byte x [ print2::j#2 print2::j#1 ]
reg byte a [ print_char::ch#1 print_char::ch#0 ]
reg byte x [ print_char::idx#1 print_char::idx#0 ]
zp[2]:250 [ print2::at print_char::at ]
zp[2]:252 [ print2::msg ]

View File

@ -4,14 +4,14 @@
.pc = $80d "Program"
.label SCREEN = $400
main: {
.label __1 = 6
.label i = 2
.label j = 4
.label __1 = 6
.label k = 6
lda #<0
lda #0
sta.z i
sta.z j
sta.z j+1
sta.z i
__b1:
lda.z i
cmp #4

View File

@ -10,24 +10,23 @@
(void()) main()
main: scope:[main] from @1
[4] phi()
[4] (byte) main::i ← (byte) 0
[5] (signed word) main::j ← (signed byte) 0
to:main::@1
main::@1: scope:[main] from main main::@2
[5] (signed word) main::j#2 ← phi( main/(signed byte) 0 main::@2/(signed word) main::j#1 )
[5] (byte) main::i#3 ← phi( main/(byte) 0 main::@2/(byte) main::i#2 )
[6] if((byte) main::i#3<(byte) 4) goto main::@2
[6] if((byte) main::i<(byte) 4) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[7] return
to:@return
main::@2: scope:[main] from main::@1
[8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1
[9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2
[10] (byte) main::i#1 ← ++ (byte) main::i#3
[11] (signed word) main::j#1 ← ++ (signed word) main::j#2
[12] (signed word~) main::$1 ← (signed word)(byte) main::i#1
[8] (byte~) main::$3 ← (byte) main::i << (byte) 1
[9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j
[10] (byte) main::i ← ++ (byte) main::i
[11] (signed word) main::j ← ++ (signed word) main::j
[12] (signed word~) main::$1 ← (signed word)(byte) main::i
[13] (signed word) main::k#0 ← (signed word~) main::$1 << (byte) 1
[14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1
[14] (byte~) main::$4 ← (byte) main::i << (byte) 1
[15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0
[16] (byte) main::i#2 ← ++ (byte) main::i#1
[16] (byte) main::i ← ++ (byte) main::i
to:main::@1

View File

@ -12,28 +12,24 @@ CONTROL FLOW GRAPH SSA
(void()) main()
main: scope:[main] from @1
(byte) main::i#0 ← (number) 0
(signed word) main::j#0 ← (number) 0
(byte) main::i ← (number) 0
(signed word) main::j ← (number) 0
to:main::@1
main::@1: scope:[main] from main main::@2
(signed word) main::j#3 ← phi( main/(signed word) main::j#0 main::@2/(signed word) main::j#1 )
(byte) main::i#3 ← phi( main/(byte) main::i#0 main::@2/(byte) main::i#2 )
(bool~) main::$0 ← (byte) main::i#3 < (number) 4
(bool~) main::$0 ← (byte) main::i < (number) 4
if((bool~) main::$0) goto main::@2
to:main::@return
main::@2: scope:[main] from main::@1
(signed word) main::j#2 ← phi( main::@1/(signed word) main::j#3 )
(byte) main::i#4 ← phi( main::@1/(byte) main::i#3 )
(byte~) main::$3 ← (byte) main::i#4 * (const byte) SIZEOF_SIGNED_WORD
*((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2
(byte) main::i#1 ← ++ (byte) main::i#4
(signed word) main::j#1 ← ++ (signed word) main::j#2
(signed word~) main::$1 ← ((signed word)) (byte) main::i#1
(byte~) main::$3 ← (byte) main::i * (const byte) SIZEOF_SIGNED_WORD
*((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j
(byte) main::i ← ++ (byte) main::i
(signed word) main::j ← ++ (signed word) main::j
(signed word~) main::$1 ← ((signed word)) (byte) main::i
(number~) main::$2 ← (signed word~) main::$1 * (number) 2
(signed word) main::k#0 ← (number~) main::$2
(byte~) main::$4 ← (byte) main::i#1 * (const byte) SIZEOF_SIGNED_WORD
(byte~) main::$4 ← (byte) main::i * (const byte) SIZEOF_SIGNED_WORD
*((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0
(byte) main::i#2 ← ++ (byte) main::i#1
(byte) main::i ← ++ (byte) main::i
to:main::@1
main::@return: scope:[main] from main::@1
return
@ -61,29 +57,20 @@ SYMBOL TABLE SSA
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i !zp[-1]:2
(byte) main::i#0 !zp[-1]:2
(byte) main::i#1 !zp[-1]:2
(byte) main::i#2 !zp[-1]:2
(byte) main::i#3 !zp[-1]:2
(byte) main::i#4 !zp[-1]:2
(signed word) main::j !zp[-1]:4
(signed word) main::j#0 !zp[-1]:4
(signed word) main::j#1 !zp[-1]:4
(signed word) main::j#2 !zp[-1]:4
(signed word) main::j#3 !zp[-1]:4
(byte) main::i loadstore !zp[-1]:2
(signed word) main::j loadstore !zp[-1]:4
(signed word) main::k
(signed word) main::k#0
Adding number conversion cast (unumber) 0 in (byte) main::i#0 ← (number) 0
Adding number conversion cast (snumber) 0 in (signed word) main::j#0 ← (number) 0
Adding number conversion cast (unumber) 4 in (bool~) main::$0 ← (byte) main::i#3 < (number) 4
Adding number conversion cast (unumber) 0 in (byte) main::i ← (number) 0
Adding number conversion cast (snumber) 0 in (signed word) main::j ← (number) 0
Adding number conversion cast (unumber) 4 in (bool~) main::$0 ← (byte) main::i < (number) 4
Adding number conversion cast (snumber) 2 in (number~) main::$2 ← (signed word~) main::$1 * (number) 2
Adding number conversion cast (snumber) main::$2 in (number~) main::$2 ← (signed word~) main::$1 * (snumber)(number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) main::i#0 ← (unumber)(number) 0
Inlining cast (signed word) main::j#0 ← (snumber)(number) 0
Inlining cast (signed word~) main::$1 ← (signed word)(byte) main::i#1
Inlining cast (byte) main::i ← (unumber)(number) 0
Inlining cast (signed word) main::j ← (snumber)(number) 0
Inlining cast (signed word~) main::$1 ← (signed word)(byte) main::i
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (signed word*) 1024
Simplifying constant integer cast 0
@ -97,43 +84,29 @@ Finalized unsigned number type (byte) 4
Finalized signed number type (signed byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to signed word in (snumber~) main::$2 ← (signed word~) main::$1 * (signed byte) 2
Alias (byte) main::i#3 = (byte) main::i#4
Alias (signed word) main::j#2 = (signed word) main::j#3
Alias (signed word) main::k#0 = (signed word~) main::$2
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$0 [4] if((byte) main::i#3<(byte) 4) goto main::@2
Simple Condition (bool~) main::$0 [3] if((byte) main::i<(byte) 4) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::i#0 = 0
Constant (const signed word) main::j#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Rewriting multiplication to use shift [2] (byte~) main::$3 ← (byte) main::i#3 * (const byte) SIZEOF_SIGNED_WORD
Rewriting multiplication to use shift [7] (signed word) main::k#0 ← (signed word~) main::$1 * (signed byte) 2
Rewriting multiplication to use shift [8] (byte~) main::$4 ← (byte) main::i#1 * (const byte) SIZEOF_SIGNED_WORD
Rewriting multiplication to use shift [3] (byte~) main::$3 ← (byte) main::i * (const byte) SIZEOF_SIGNED_WORD
Rewriting multiplication to use shift [8] (signed word) main::k#0 ← (signed word~) main::$1 * (signed byte) 2
Rewriting multiplication to use shift [9] (byte~) main::$4 ← (byte) main::i * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const signed word) main::j#0
Constant inlined main::i#0 = (byte) 0
Constant inlined main::j#0 = (signed byte) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNEliminateUnusedVars
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
CALL GRAPH
Calls in [] to main:2
Created 2 initial phi equivalence classes
Coalesced [18] main::i#5 ← main::i#2
Coalesced [19] main::j#4 ← main::j#1
Coalesced down to 2 phi equivalence classes
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
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
FINAL CONTROL FLOW GRAPH
@begin: scope:[] from
@ -148,26 +121,25 @@ FINAL CONTROL FLOW GRAPH
(void()) main()
main: scope:[main] from @1
[4] phi()
[4] (byte) main::i ← (byte) 0
[5] (signed word) main::j ← (signed byte) 0
to:main::@1
main::@1: scope:[main] from main main::@2
[5] (signed word) main::j#2 ← phi( main/(signed byte) 0 main::@2/(signed word) main::j#1 )
[5] (byte) main::i#3 ← phi( main/(byte) 0 main::@2/(byte) main::i#2 )
[6] if((byte) main::i#3<(byte) 4) goto main::@2
[6] if((byte) main::i<(byte) 4) goto main::@2
to:main::@return
main::@return: scope:[main] from main::@1
[7] return
to:@return
main::@2: scope:[main] from main::@1
[8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1
[9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2
[10] (byte) main::i#1 ← ++ (byte) main::i#3
[11] (signed word) main::j#1 ← ++ (signed word) main::j#2
[12] (signed word~) main::$1 ← (signed word)(byte) main::i#1
[8] (byte~) main::$3 ← (byte) main::i << (byte) 1
[9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j
[10] (byte) main::i ← ++ (byte) main::i
[11] (signed word) main::j ← ++ (signed word) main::j
[12] (signed word~) main::$1 ← (signed word)(byte) main::i
[13] (signed word) main::k#0 ← (signed word~) main::$1 << (byte) 1
[14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1
[14] (byte~) main::$4 ← (byte) main::i << (byte) 1
[15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0
[16] (byte) main::i#2 ← ++ (byte) main::i#1
[16] (byte) main::i ← ++ (byte) main::i
to:main::@1
@ -176,29 +148,22 @@ VARIABLE REGISTER WEIGHTS
(signed word~) main::$1 22.0
(byte~) main::$3 22.0
(byte~) main::$4 22.0
(byte) main::i !zp[-1]:2
(byte) main::i#1 !zp[-1]:2 5.5
(byte) main::i#2 !zp[-1]:2 22.0
(byte) main::i#3 !zp[-1]:2 11.0
(signed word) main::j !zp[-1]:4
(signed word) main::j#1 !zp[-1]:4 3.6666666666666665
(signed word) main::j#2 !zp[-1]:4 6.6000000000000005
(byte) main::i loadstore !zp[-1]:2 9.875
(signed word) main::j loadstore !zp[-1]:4 3.8888888888888893
(signed word) main::k
(signed word) main::k#0 11.0
Initial phi equivalence classes
[ main::i#3 main::i#2 ]
[ main::j#2 main::j#1 ]
Added variable main::i to live range equivalence class [ main::i ]
Added variable main::j to live range equivalence class [ main::j ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Added variable main::i#1 to live range equivalence class [ main::i#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::k#0 to live range equivalence class [ main::k#0 ]
Added variable main::$4 to live range equivalence class [ main::$4 ]
Complete equivalence classes
[ main::i#3 main::i#2 ]
[ main::j#2 main::j#1 ]
[ main::i ]
[ main::j ]
[ main::$3 ]
[ main::i#1 ]
[ main::$1 ]
[ main::k#0 ]
[ main::$4 ]
@ -225,8 +190,6 @@ __b1_from___bbegin:
// @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:
@ -235,26 +198,24 @@ __bend_from___b1:
__bend:
// main
main: {
.label i = 2
.label j = 4
.label __1 = 6
.label __3 = 3
.label __4 = $a
.label i = 2
.label j = 4
.label k = 8
// [5] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (signed word) main::j#2 = (signed byte) 0 [phi:main->main::@1#0] -- vwsz1=vbsc1
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
// [5] (signed word) main::j ← (signed byte) 0 -- vwsz1=vbsc1
lda #<0
sta.z j
lda #>0
sta.z j+1
// [5] phi (byte) main::i#3 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
lda #0
sta.z i
jmp __b1
// main::@1
__b1:
// [6] if((byte) main::i#3<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
// [6] if((byte) main::i<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #4
bcc __b2
@ -265,24 +226,24 @@ main: {
rts
// main::@2
__b2:
// [8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1 -- vbuz1=vbuz2_rol_1
// [8] (byte~) main::$3 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1
lda.z i
asl
sta.z __3
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2 -- pwsc1_derefidx_vbuz1=vwsz2
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j -- pwsc1_derefidx_vbuz1=vwsz2
ldy.z __3
lda.z j
sta SCREEN,y
lda.z j+1
sta SCREEN+1,y
// [10] (byte) main::i#1 ← ++ (byte) main::i#3 -- vbuz1=_inc_vbuz1
// [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [11] (signed word) main::j#1 ← ++ (signed word) main::j#2 -- vwsz1=_inc_vwsz1
// [11] (signed word) main::j ← ++ (signed word) main::j -- vwsz1=_inc_vwsz1
inc.z j
bne !+
inc.z j+1
!:
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i#1 -- vwsz1=_sword_vbuz2
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i -- vwsz1=_sword_vbuz2
lda.z i
sta.z __1
lda #0
@ -294,7 +255,7 @@ main: {
lda.z __1+1
rol
sta.z k+1
// [14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1 -- vbuz1=vbuz2_rol_1
// [14] (byte~) main::$4 ← (byte) main::i << (byte) 1 -- vbuz1=vbuz2_rol_1
lda.z i
asl
sta.z __4
@ -304,43 +265,37 @@ main: {
sta SCREEN,y
lda.z k+1
sta SCREEN+1,y
// [16] (byte) main::i#2 ← ++ (byte) main::i#1 -- vbuz1=_inc_vbuz1
// [16] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
__b1_from___b2:
// [5] phi (signed word) main::j#2 = (signed word) main::j#1 [phi:main::@2->main::@1#0] -- register_copy
// [5] phi (byte) main::i#3 = (byte) main::i#2 [phi:main::@2->main::@1#1] -- register_copy
jmp __b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] if((byte) main::i#3<(byte) 4) goto main::@2 [ main::i#3 main::j#2 ] ( main:2 [ main::i#3 main::j#2 ] ) always clobbers reg byte a
Statement [8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1 [ main::i#3 main::j#2 main::$3 ] ( main:2 [ main::i#3 main::j#2 main::$3 ] ) always clobbers reg byte a
Statement [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2 [ main::i#3 main::j#2 ] ( main:2 [ main::i#3 main::j#2 ] ) always clobbers reg byte a
Statement [12] (signed word~) main::$1 ← (signed word)(byte) main::i#1 [ main::j#1 main::i#1 main::$1 ] ( main:2 [ main::j#1 main::i#1 main::$1 ] ) always clobbers reg byte a
Statement [13] (signed word) main::k#0 ← (signed word~) main::$1 << (byte) 1 [ main::j#1 main::i#1 main::k#0 ] ( main:2 [ main::j#1 main::i#1 main::k#0 ] ) always clobbers reg byte a
Statement [14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1 [ main::j#1 main::i#1 main::k#0 main::$4 ] ( main:2 [ main::j#1 main::i#1 main::k#0 main::$4 ] ) always clobbers reg byte a
Statement [15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0 [ main::j#1 main::i#1 ] ( main:2 [ main::j#1 main::i#1 ] ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::i#3 main::i#2 ] : zp[1]:2 ,
Potential registers zp[2]:4 [ main::j#2 main::j#1 ] : zp[2]:4 ,
Statement [4] (byte) main::i ← (byte) 0 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a
Statement [5] (signed word) main::j ← (signed byte) 0 [ main::i main::j ] ( main:2 [ main::i main::j ] ) always clobbers reg byte a
Statement [6] if((byte) main::i<(byte) 4) goto main::@2 [ main::i main::j ] ( main:2 [ main::i main::j ] ) always clobbers reg byte a
Statement [8] (byte~) main::$3 ← (byte) main::i << (byte) 1 [ main::j main::$3 ] ( main:2 [ main::j main::$3 ] ) always clobbers reg byte a
Statement [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [12] (signed word~) main::$1 ← (signed word)(byte) main::i [ main::i main::j main::$1 ] ( main:2 [ main::i main::j main::$1 ] ) always clobbers reg byte a
Statement [13] (signed word) main::k#0 ← (signed word~) main::$1 << (byte) 1 [ main::i main::j main::k#0 ] ( main:2 [ main::i main::j main::k#0 ] ) always clobbers reg byte a
Statement [14] (byte~) main::$4 ← (byte) main::i << (byte) 1 [ main::j main::k#0 main::$4 ] ( main:2 [ main::j main::k#0 main::$4 ] ) always clobbers reg byte a
Statement [15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0 [ main::j ] ( main:2 [ main::j ] ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::i ] : zp[1]:2 ,
Potential registers zp[2]:4 [ main::j ] : zp[2]:4 ,
Potential registers zp[1]:3 [ main::$3 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:2 [ main::i#1 ] : zp[1]:2 ,
Potential registers zp[2]:6 [ main::$1 ] : zp[2]:6 ,
Potential registers zp[2]:8 [ main::k#0 ] : zp[2]:8 ,
Potential registers zp[1]:10 [ main::$4 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp[1]:2 [ main::i#3 main::i#2 ] 22: zp[1]:3 [ main::$3 ] 22: zp[2]:6 [ main::$1 ] 22: zp[1]:10 [ main::$4 ] 11: zp[2]:8 [ main::k#0 ] 10.27: zp[2]:4 [ main::j#2 main::j#1 ] 5.5: zp[1]:2 [ main::i#1 ]
Uplift Scope [main] 22: zp[1]:3 [ main::$3 ] 22: zp[2]:6 [ main::$1 ] 22: zp[1]:10 [ main::$4 ] 11: zp[2]:8 [ main::k#0 ] 9.88: zp[1]:2 [ main::i ] 3.89: zp[2]:4 [ main::j ]
Uplift Scope []
Uplifting [main] best 1288 combination zp[1]:2 [ main::i#3 main::i#2 ] reg byte a [ main::$3 ] zp[2]:6 [ main::$1 ] reg byte a [ main::$4 ] zp[2]:8 [ main::k#0 ] zp[2]:4 [ main::j#2 main::j#1 ] zp[1]:2 [ main::i#1 ]
Uplifting [] best 1288 combination
Attempting to uplift remaining variables inzp[1]:2 [ main::i#3 main::i#2 ]
Uplifting [main] best 1288 combination zp[1]:2 [ main::i#3 main::i#2 ]
Attempting to uplift remaining variables inzp[1]:2 [ main::i#1 ]
Uplifting [main] best 1288 combination zp[1]:2 [ main::i#1 ]
Coalescing zero page register [ zp[1]:2 [ main::i#3 main::i#2 ] ] with [ zp[1]:2 [ main::i#1 ] ] - score: 2
Uplifting [main] best 1126 combination reg byte a [ main::$3 ] zp[2]:6 [ main::$1 ] reg byte a [ main::$4 ] zp[2]:8 [ main::k#0 ] zp[1]:2 [ main::i ] zp[2]:4 [ main::j ]
Uplifting [] best 1126 combination
Attempting to uplift remaining variables inzp[1]:2 [ main::i ]
Uplifting [main] best 1126 combination zp[1]:2 [ main::i ]
Coalescing zero page register [ zp[2]:6 [ main::$1 ] ] with [ zp[2]:8 [ main::k#0 ] ] - score: 1
ASSEMBLER BEFORE OPTIMIZATION
@ -360,8 +315,6 @@ __b1_from___bbegin:
// @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:
@ -370,24 +323,22 @@ __bend_from___b1:
__bend:
// main
main: {
.label __1 = 6
.label i = 2
.label j = 4
.label __1 = 6
.label k = 6
// [5] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (signed word) main::j#2 = (signed byte) 0 [phi:main->main::@1#0] -- vwsz1=vbsc1
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
// [5] (signed word) main::j ← (signed byte) 0 -- vwsz1=vbsc1
lda #<0
sta.z j
lda #>0
sta.z j+1
// [5] phi (byte) main::i#3 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
lda #0
sta.z i
jmp __b1
// main::@1
__b1:
// [6] if((byte) main::i#3<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
// [6] if((byte) main::i<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #4
bcc __b2
@ -398,23 +349,23 @@ main: {
rts
// main::@2
__b2:
// [8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1 -- vbuaa=vbuz1_rol_1
// [8] (byte~) main::$3 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2 -- pwsc1_derefidx_vbuaa=vwsz1
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j -- pwsc1_derefidx_vbuaa=vwsz1
tay
lda.z j
sta SCREEN,y
lda.z j+1
sta SCREEN+1,y
// [10] (byte) main::i#1 ← ++ (byte) main::i#3 -- vbuz1=_inc_vbuz1
// [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [11] (signed word) main::j#1 ← ++ (signed word) main::j#2 -- vwsz1=_inc_vwsz1
// [11] (signed word) main::j ← ++ (signed word) main::j -- vwsz1=_inc_vwsz1
inc.z j
bne !+
inc.z j+1
!:
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i#1 -- vwsz1=_sword_vbuz2
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i -- vwsz1=_sword_vbuz2
lda.z i
sta.z __1
lda #0
@ -422,7 +373,7 @@ main: {
// [13] (signed word) main::k#0 ← (signed word~) main::$1 << (byte) 1 -- vwsz1=vwsz1_rol_1
asl.z k
rol.z k+1
// [14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1 -- vbuaa=vbuz1_rol_1
// [14] (byte~) main::$4 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0 -- pwsc1_derefidx_vbuaa=vwsz1
@ -431,12 +382,8 @@ main: {
sta SCREEN,y
lda.z k+1
sta SCREEN+1,y
// [16] (byte) main::i#2 ← ++ (byte) main::i#1 -- vbuz1=_inc_vbuz1
// [16] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
__b1_from___b2:
// [5] phi (signed word) main::j#2 = (signed word) main::j#1 [phi:main::@2->main::@1#0] -- register_copy
// [5] phi (byte) main::i#3 = (byte) main::i#2 [phi:main::@2->main::@1#1] -- register_copy
jmp __b1
}
// File Data
@ -447,19 +394,16 @@ Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #<0
Removing instruction lda #>0
Removing instruction lda #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:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
@ -479,25 +423,20 @@ FINAL SYMBOL TABLE
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i !zp[-1]:2
(byte) main::i#1 i !zp[-1]:2 zp[1]:2 5.5
(byte) main::i#2 i !zp[-1]:2 zp[1]:2 22.0
(byte) main::i#3 i !zp[-1]:2 zp[1]:2 11.0
(signed word) main::j !zp[-1]:4
(signed word) main::j#1 j !zp[-1]:4 zp[2]:4 3.6666666666666665
(signed word) main::j#2 j !zp[-1]:4 zp[2]:4 6.6000000000000005
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 9.875
(signed word) main::j loadstore !zp[-1]:4 zp[2]:4 3.8888888888888893
(signed word) main::k
(signed word) main::k#0 k zp[2]:6 11.0
zp[1]:2 [ main::i#3 main::i#2 main::i#1 ]
zp[2]:4 [ main::j#2 main::j#1 ]
zp[1]:2 [ main::i ]
zp[2]:4 [ main::j ]
reg byte a [ main::$3 ]
zp[2]:6 [ main::$1 main::k#0 ]
reg byte a [ main::$4 ]
FINAL ASSEMBLER
Score: 1116
Score: 1017
// File Comments
// Test declaring a variable as register on a specific ZP address
@ -511,26 +450,26 @@ Score: 1116
// [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: {
.label __1 = 6
.label i = 2
.label j = 4
.label __1 = 6
.label k = 6
// [5] phi from main to main::@1 [phi:main->main::@1]
// [5] phi (signed word) main::j#2 = (signed byte) 0 [phi:main->main::@1#0] -- vwsz1=vbsc1
lda #<0
// i=0
// [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1
lda #0
sta.z i
// j=0
// [5] (signed word) main::j ← (signed byte) 0 -- vwsz1=vbsc1
sta.z j
sta.z j+1
// [5] phi (byte) main::i#3 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1
sta.z i
// main::@1
__b1:
// while(i<4)
// [6] if((byte) main::i#3<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
// [6] if((byte) main::i<(byte) 4) goto main::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z i
cmp #4
bcc __b2
@ -541,25 +480,25 @@ main: {
// main::@2
__b2:
// SCREEN[i++] = j++
// [8] (byte~) main::$3 ← (byte) main::i#3 << (byte) 1 -- vbuaa=vbuz1_rol_1
// [8] (byte~) main::$3 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j#2 -- pwsc1_derefidx_vbuaa=vwsz1
// [9] *((const signed word*) SCREEN + (byte~) main::$3) ← (signed word) main::j -- pwsc1_derefidx_vbuaa=vwsz1
tay
lda.z j
sta SCREEN,y
lda.z j+1
sta SCREEN+1,y
// SCREEN[i++] = j++;
// [10] (byte) main::i#1 ← ++ (byte) main::i#3 -- vbuz1=_inc_vbuz1
// [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [11] (signed word) main::j#1 ← ++ (signed word) main::j#2 -- vwsz1=_inc_vwsz1
// [11] (signed word) main::j ← ++ (signed word) main::j -- vwsz1=_inc_vwsz1
inc.z j
bne !+
inc.z j+1
!:
// (int)i
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i#1 -- vwsz1=_sword_vbuz2
// [12] (signed word~) main::$1 ← (signed word)(byte) main::i -- vwsz1=_sword_vbuz2
lda.z i
sta.z __1
lda #0
@ -569,7 +508,7 @@ main: {
asl.z k
rol.z k+1
// SCREEN[i++] = k
// [14] (byte~) main::$4 ← (byte) main::i#1 << (byte) 1 -- vbuaa=vbuz1_rol_1
// [14] (byte~) main::$4 ← (byte) main::i << (byte) 1 -- vbuaa=vbuz1_rol_1
lda.z i
asl
// [15] *((const signed word*) SCREEN + (byte~) main::$4) ← (signed word) main::k#0 -- pwsc1_derefidx_vbuaa=vwsz1
@ -579,11 +518,8 @@ main: {
lda.z k+1
sta SCREEN+1,y
// SCREEN[i++] = k;
// [16] (byte) main::i#2 ← ++ (byte) main::i#1 -- vbuz1=_inc_vbuz1
// [16] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1
inc.z i
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
// [5] phi (signed word) main::j#2 = (signed word) main::j#1 [phi:main::@2->main::@1#0] -- register_copy
// [5] phi (byte) main::i#3 = (byte) main::i#2 [phi:main::@2->main::@1#1] -- register_copy
jmp __b1
}
// File Data

View File

@ -9,18 +9,13 @@
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i !zp[-1]:2
(byte) main::i#1 i !zp[-1]:2 zp[1]:2 5.5
(byte) main::i#2 i !zp[-1]:2 zp[1]:2 22.0
(byte) main::i#3 i !zp[-1]:2 zp[1]:2 11.0
(signed word) main::j !zp[-1]:4
(signed word) main::j#1 j !zp[-1]:4 zp[2]:4 3.6666666666666665
(signed word) main::j#2 j !zp[-1]:4 zp[2]:4 6.6000000000000005
(byte) main::i loadstore !zp[-1]:2 zp[1]:2 9.875
(signed word) main::j loadstore !zp[-1]:4 zp[2]:4 3.8888888888888893
(signed word) main::k
(signed word) main::k#0 k zp[2]:6 11.0
zp[1]:2 [ main::i#3 main::i#2 main::i#1 ]
zp[2]:4 [ main::j#2 main::j#1 ]
zp[1]:2 [ main::i ]
zp[2]:4 [ main::j ]
reg byte a [ main::$3 ]
zp[2]:6 [ main::$1 main::k#0 ]
reg byte a [ main::$4 ]