1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Implemented variable register weight analysis.

This commit is contained in:
jespergravgaard 2017-07-29 17:10:32 +02:00
parent 0377193ec8
commit 7f20f2a6ba
26 changed files with 583 additions and 229 deletions

View File

@ -141,7 +141,8 @@ public class Compiler {
new Pass3ZeroPageAllocation(program, log).allocate();
new Pass3VariableRegisterWeightAnalysis(program, log).findWeights();
log.append("\nVARIABLE REGISTER WEIGHTS");
log.append(program.getScope().getSymbolTableContents(Variable.class));
new Pass3ZeroPageCoalesce(program, log).allocate();
new Pass3RegistersFinalize(program, log).allocate();

View File

@ -47,6 +47,15 @@ public class LiveRange {
public int getLastStatementIdx() {
return lastStatementIdx;
}
/** Get the number of statements in the live interval.
*
* @return The number of statements in the live interval.
*/
public int size() {
return lastStatementIdx-firstStatementIdx+1;
}
}
public LiveRange() {
@ -71,6 +80,19 @@ public class LiveRange {
return index;
}
/** Get the number of statements in the live range.
*
* @return The number of statements in the live range.
*/
public int size() {
int s = 0;
for (LiveInterval interval : intervals) {
s += interval.size();
}
return s;
}
/**
* Add an index to the live range
* @param index The index to add

View File

@ -96,4 +96,13 @@ public class NaturalLoopSet {
this.loops.remove(loop);
}
public int getMaxLoopDepth(LabelRef block) {
int maxDepth = 0;
for (NaturalLoop loop : getLoopsContainingBlock(block)) {
if(loop.getDepth()>maxDepth) {
maxDepth = loop.getDepth();
}
}
return maxDepth;
}
}

View File

@ -71,11 +71,11 @@ public class Procedure extends Scope {
return super.getFullName();
}
public String getSymbolTableContents(ProgramScope scope) {
public String getSymbolTableContents(ProgramScope scope, Class symbolClass) {
StringBuilder res = new StringBuilder();
res.append(toString(scope));
res.append("\n");
res.append(super.getSymbolTableContents(scope));
res.append(super.getSymbolTableContents(scope, symbolClass));
return res.toString();
}
@ -85,7 +85,8 @@ public class Procedure extends Scope {
}
@Override
RegisterAllocation getAllocation() {
@JsonIgnore
public RegisterAllocation getAllocation() {
if(getScope()!=null) {
return getScope().getAllocation();
} else {
@ -93,6 +94,16 @@ public class Procedure extends Scope {
}
}
@Override
@JsonIgnore
public VariableRegisterWeights getVariableRegisterWeights() {
if(getScope()!=null) {
return getScope().getVariableRegisterWeights();
} else {
return null;
}
}
@Override
public String toString() {
return toString(null);

View File

@ -10,10 +10,9 @@ import java.util.HashMap;
public class ProgramScope extends Scope {
private RegisterAllocation allocation;
private LiveRangeVariables liveRangeVariables;
private LiveRangeEquivalenceClassSet liveRangeEquivalenceClassSet;
private VariableRegisterWeights variableRegisterWeights;
public ProgramScope() {
super("", null);
@ -42,13 +41,13 @@ public class ProgramScope extends Scope {
public RegisterAllocation.Register getRegister(Variable variable) {
RegisterAllocation.Register register = null;
if (allocation != null) {
register = allocation.getRegister(variable);
register = allocation.getRegister(variable.getRef());
}
return register;
}
@Override
RegisterAllocation getAllocation() {
public RegisterAllocation getAllocation() {
return allocation;
}
@ -94,13 +93,18 @@ public class ProgramScope extends Scope {
@JsonIgnore
public String getSymbolTableContents() {
return getSymbolTableContents(this);
return getSymbolTableContents(this, null);
}
@JsonIgnore
public String getSymbolTableContents(Class symbolClass) {
return getSymbolTableContents(this, symbolClass);
}
@Override
public String getSymbolTableContents(ProgramScope scope) {
public String getSymbolTableContents(ProgramScope scope, Class symbolClass) {
StringBuilder out = new StringBuilder();
out.append(super.getSymbolTableContents(scope));
out.append(super.getSymbolTableContents(scope, symbolClass));
if(liveRangeEquivalenceClassSet!=null) {
out.append("\n");
for (LiveRangeEquivalenceClass liveRangeEquivalenceClass : liveRangeEquivalenceClassSet.getEquivalenceClasses()) {
@ -116,4 +120,11 @@ public class ProgramScope extends Scope {
return "program";
}
public void setVariableRegisterWeights(VariableRegisterWeights variableRegisterWeights) {
this.variableRegisterWeights = variableRegisterWeights;
}
public VariableRegisterWeights getVariableRegisterWeights() {
return variableRegisterWeights;
}
}

View File

@ -19,10 +19,6 @@ public class RegisterAllocation {
* @param variable The variable
* @return The allocated register.
*/
public Register getRegister(Variable variable) {
return allocation.get(variable.getRef());
}
public Register getRegister(VariableRef ref) {
return allocation.get(ref);
}

View File

@ -205,29 +205,40 @@ public abstract class Scope implements Symbol {
return (Procedure) getSymbol(ref);
}
abstract RegisterAllocation getAllocation();
public abstract RegisterAllocation getAllocation();
public abstract VariableRegisterWeights getVariableRegisterWeights();
@JsonIgnore
public String getSymbolTableContents(ProgramScope scope) {
public String getSymbolTableContents(ProgramScope scope, Class symbolClass) {
StringBuilder res = new StringBuilder();
Set<String> names = symbols.keySet();
List<String> sortedNames = new ArrayList<>(names);
Collections.sort(sortedNames);
RegisterAllocation allocation = getAllocation();
VariableRegisterWeights registerWeights = getVariableRegisterWeights();
for (String name : sortedNames) {
Symbol symbol = symbols.get(name);
if (symbol instanceof Scope) {
res.append(((Scope) symbol).getSymbolTableContents(scope));
res.append(((Scope) symbol).getSymbolTableContents(scope, symbolClass));
} else {
res.append(symbol.toString(scope));
}
if (symbol instanceof Variable && allocation!=null) {
RegisterAllocation.Register register = allocation.getRegister((Variable) symbol);
if (register != null) {
res.append(" " + register);
if (symbolClass == null || symbolClass.isInstance(symbol)) {
res.append(symbol.toString(scope));
if (symbol instanceof Variable && allocation != null) {
RegisterAllocation.Register register = allocation.getRegister(((Variable) symbol).getRef());
if (register != null) {
res.append(" " + register);
}
}
if (symbol instanceof Variable && registerWeights != null) {
Double weight = registerWeights.getWeight(((Variable) symbol).getRef());
if (weight != null) {
res.append(" " + weight);
}
}
res.append("\n");
}
}
res.append("\n");
}
return res.toString();
}

View File

@ -0,0 +1,36 @@
package dk.camelot64.kickc.icl;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* The register weights for each variable.
* The register weight signifies how beneficial it would be for the variable to assigned to a register (instead of zero page).
*/
public class VariableRegisterWeights {
private Map<VariableRef, Double> registerWeights;
public VariableRegisterWeights() {
this.registerWeights = new LinkedHashMap<>();
}
/**
* Add to the weight of a variable
*
* @param variableRef The variable
* @param w The amount to add to the weight
*/
public void addWeight(VariableRef variableRef, double w) {
Double weight = this.registerWeights.get(variableRef);
if (weight == null) {
weight = 0.0;
}
weight = weight + w;
this.registerWeights.put(variableRef, weight);
}
public Double getWeight(VariableRef variable) {
return registerWeights.get(variable);
}
}

View File

@ -1,15 +1,13 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.ControlFlowBlock;
import dk.camelot64.kickc.icl.Program;
import dk.camelot64.kickc.icl.Statement;
import dk.camelot64.kickc.icl.*;
/**
* Finds register weights for all variables.
*
* <p>
* The register weight signifies how beneficial it would be for the variable to assigned to a register (instead of zero page).
*
* <p>
* Uses Loop Depth and Live Ranges plus the statements of the control flow graph.
* <p>
* Based on ComputeWeight from http://compilers.cs.ucla.edu/fernando/projects/soc/reports/short_tech.pdf
@ -18,6 +16,9 @@ public class Pass3VariableRegisterWeightAnalysis {
private Program program;
private CompileLog log;
private NaturalLoopSet loopSet;
private VariableRegisterWeights variableRegisterWeights;
private LiveRangeVariables liveRangeVariables;
public Pass3VariableRegisterWeightAnalysis(Program program, CompileLog log) {
this.program = program;
@ -32,20 +33,76 @@ public class Pass3VariableRegisterWeightAnalysis {
return log;
}
/** Find register weights for all variables */
/**
* Find register weights for all variables
*/
public void findWeights() {
variableRegisterWeights = new VariableRegisterWeights();
loopSet = program.getGraph().getLoopSet();
liveRangeVariables = program.getScope().getLiveRangeVariables();
for (ControlFlowBlock block : program.getGraph().getAllBlocks()) {
for (Statement statement : block.getStatements()) {
if (statement instanceof StatementPhiBlock) {
for (StatementPhiBlock.PhiVariable phiVariable : ((StatementPhiBlock) statement).getPhiVariables()) {
// Add weights for the definition of the phi variable
VariableRef philVariable = phiVariable.getVariable();
for (StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
if (phiRValue.getrValue() instanceof VariableRef) {
double w = addWeight(philVariable, phiRValue.getPredecessor());
//log.append("Definition of " + philVariable + " w+:" + w + " - [" + statement.getIndex()+"]");
}
}
// Add weights for each usage of a variable
for (StatementPhiBlock.PhiRValue phiRValue : phiVariable.getValues()) {
addUsageWeightRValue(phiRValue.getrValue(), statement, phiRValue.getPredecessor());
}
}
} else if (statement instanceof StatementAssignment) {
// Add weights for the definition of the variable
LValue lValue = ((StatementAssignment) statement).getlValue();
if (lValue instanceof VariableRef) {
double w = addWeight((VariableRef) lValue, block.getLabel());
//log.append("Definition of " + lValue + " w+:" + w + " - [" + statement.getIndex()+"]");
}
// Also add weight to used pointers
if(lValue instanceof PointerDereferenceSimple) {
addUsageWeightRValue(((PointerDereference) lValue).getPointer(), statement, block.getLabel());
} else if(lValue instanceof PointerDereferenceIndexed) {
addUsageWeightRValue(((PointerDereference) lValue).getPointer(), statement, block.getLabel());
addUsageWeightRValue(((PointerDereferenceIndexed) lValue).getIndex(), statement, block.getLabel());
}
// Add weights for each usage of variables
addUsageWeightRValue(((StatementAssignment) statement).getrValue1(), statement, block.getLabel());
addUsageWeightRValue(((StatementAssignment) statement).getrValue2(), statement, block.getLabel());
} else if (statement instanceof StatementConditionalJump) {
// Add weights for each usage of variables
addUsageWeightRValue(((StatementConditionalJump) statement).getrValue1(), statement, block.getLabel());
addUsageWeightRValue(((StatementConditionalJump) statement).getrValue2(), statement, block.getLabel());
}
}
}
program.getScope().setVariableRegisterWeights(variableRegisterWeights);
}
private void addUsageWeightRValue(Value rValue, Statement statement, LabelRef block) {
if (rValue instanceof VariableRef) {
double w = addWeight((VariableRef) rValue, block);
//log.append("Usage of " + rValue + " w+:" + w + " - [" + statement.getIndex()+"]");
}
}
private double addWeight(VariableRef variable, LabelRef block) {
int depth = loopSet.getMaxLoopDepth(block);
double w = 1.0 + Math.pow(10.0, depth);
LiveRange liveRange = liveRangeVariables.getLiveRange(variable);
int s = liveRange.size();
variableRegisterWeights.addWeight(variable, w/s);
return w/s;
}
}

File diff suppressed because one or more lines are too long

View File

@ -1023,6 +1023,39 @@ Allocated zp ptr byte:2 to zp ptr byte:2 [ cursor#3 cursor#5 cursor#1 cursor#2 ]
Allocated zp byte:4 to zp byte:4 [ x#2 x#1 ]
Allocated zp byte:5 to zp byte:5 [ e#3 e#5 e#1 e#2 ]
Allocated zp byte:6 to zp byte:6 [ y#2 y#4 y#1 ]
VARIABLE REGISTER WEIGHTS
(byte[1000]) SCREEN
(byte) STAR
(byte*) cursor
(byte*) cursor#1 8.25
(byte*) cursor#2 11.0
(byte*) cursor#3 11.0
(byte*) cursor#5 16.5
(byte) e
(byte) e#1 11.0
(byte) e#2 22.0
(byte) e#3 5.5
(byte) e#5 16.5
(byte) x
(byte) x#1 3.666666666666667
(byte) x#2 11.0
(byte) x0
(byte) x1
(byte) xd
(byte) y
(byte) y#1 7.333333333333333
(byte) y#2 5.5
(byte) y#4 16.5
(byte) y0
(byte) y1
(byte) yd
zp ptr byte:2 [ cursor#3 cursor#5 cursor#1 cursor#2 ]
zp byte:4 [ x#2 x#1 ]
zp byte:5 [ e#3 e#5 e#1 e#2 ]
zp byte:6 [ y#2 y#4 y#1 ]
Re-allocated ZP register from zp ptr byte:2 to zp ptr byte:2
Re-allocated ZP register from zp byte:4 to zp byte:4
Re-allocated ZP register from zp byte:5 to zp byte:5
@ -1272,25 +1305,25 @@ FINAL SYMBOL TABLE
(byte[1000]) SCREEN
(byte) STAR
(byte*) cursor
(byte*) cursor#1 zp ptr byte:2
(byte*) cursor#2 zp ptr byte:2
(byte*) cursor#3 zp ptr byte:2
(byte*) cursor#5 zp ptr byte:2
(byte*) cursor#1 zp ptr byte:2 8.25
(byte*) cursor#2 zp ptr byte:2 11.0
(byte*) cursor#3 zp ptr byte:2 11.0
(byte*) cursor#5 zp ptr byte:2 16.5
(byte) e
(byte) e#1 zp byte:5
(byte) e#2 zp byte:5
(byte) e#3 zp byte:5
(byte) e#5 zp byte:5
(byte) e#1 zp byte:5 11.0
(byte) e#2 zp byte:5 22.0
(byte) e#3 zp byte:5 5.5
(byte) e#5 zp byte:5 16.5
(byte) x
(byte) x#1 zp byte:4
(byte) x#2 zp byte:4
(byte) x#1 zp byte:4 3.666666666666667
(byte) x#2 zp byte:4 11.0
(byte) x0
(byte) x1
(byte) xd
(byte) y
(byte) y#1 zp byte:6
(byte) y#2 zp byte:6
(byte) y#4 zp byte:6
(byte) y#1 zp byte:6 7.333333333333333
(byte) y#2 zp byte:6 5.5
(byte) y#4 zp byte:6 16.5
(byte) y0
(byte) y1
(byte) yd

View File

@ -6,25 +6,30 @@
(byte[1000]) SCREEN
(byte) STAR
(byte*) cursor
(byte*) cursor#1 zp ptr byte:2
(byte*) cursor#2 zp ptr byte:2
(byte*) cursor#3 zp ptr byte:2
(byte*) cursor#5 zp ptr byte:2
(byte*) cursor#1 zp ptr byte:2 8.25
(byte*) cursor#2 zp ptr byte:2 11.0
(byte*) cursor#3 zp ptr byte:2 11.0
(byte*) cursor#5 zp ptr byte:2 16.5
(byte) e
(byte) e#1 zp byte:5
(byte) e#2 zp byte:5
(byte) e#3 zp byte:5
(byte) e#5 zp byte:5
(byte) e#1 zp byte:5 11.0
(byte) e#2 zp byte:5 22.0
(byte) e#3 zp byte:5 5.5
(byte) e#5 zp byte:5 16.5
(byte) x
(byte) x#1 zp byte:4
(byte) x#2 zp byte:4
(byte) x#1 zp byte:4 3.666666666666667
(byte) x#2 zp byte:4 11.0
(byte) x0
(byte) x1
(byte) xd
(byte) y
(byte) y#1 zp byte:6
(byte) y#2 zp byte:6
(byte) y#4 zp byte:6
(byte) y#1 zp byte:6 7.333333333333333
(byte) y#2 zp byte:6 5.5
(byte) y#4 zp byte:6 16.5
(byte) y0
(byte) y1
(byte) yd
zp ptr byte:2 [ cursor#3 cursor#5 cursor#1 cursor#2 ]
zp byte:4 [ x#2 x#1 ]
zp byte:5 [ e#3 e#5 e#1 e#2 ]
zp byte:6 [ y#2 y#4 y#1 ]

View File

@ -183,7 +183,6 @@ SYMBOLS
(byte) flip::i
(byte) flip::r
(byte) flip::srcIdx
(void()) main()
(void~) main::$0
(byte~) main::$1
@ -199,7 +198,6 @@ SYMBOLS
(label) main::@4
(label) main::@return
(byte) main::c
(void()) plot()
(byte~) plot::$0
(byte*~) plot::$1
@ -215,14 +213,12 @@ SYMBOLS
(byte*) plot::line
(byte) plot::x
(byte) plot::y
(void()) prepare()
(boolean~) prepare::$0
(label) prepare::@1
(label) prepare::@return
(byte) prepare::i
INITIAL CONTROL FLOW GRAPH
@BEGIN: from
(byte[1000]) SCREEN ← (word) 1024
@ -3884,6 +3880,76 @@ Allocated zp byte:15 to zp byte:15 [ main::$3 ]
Allocated zp byte:16 to zp byte:16 [ plot::$3 ]
Allocated zp byte:17 to zp byte:17 [ flip::$0 ]
Allocated zp byte:18 to zp byte:18 [ flip::$4 ]
VARIABLE REGISTER WEIGHTS
(byte*) RASTER
(byte[1000]) SCREEN
(byte[256]) buffer1
(byte[256]) buffer2
(void()) flip()
(byte~) flip::$0 2002.0
(byte~) flip::$4 202.0
(byte) flip::c
(byte) flip::c#1 1501.5
(byte) flip::c#2 400.4
(byte) flip::dstIdx
(byte) flip::dstIdx#1 701.0
(byte) flip::dstIdx#2 67.33333333333333
(byte) flip::dstIdx#3 776.0
(byte) flip::dstIdx#5 202.0
(byte) flip::i
(byte) flip::i#1 151.5
(byte) flip::i#2 134.66666666666666
(byte) flip::r
(byte) flip::r#1 151.5
(byte) flip::r#2 22.444444444444443
(byte) flip::srcIdx
(byte) flip::srcIdx#1 300.42857142857144
(byte) flip::srcIdx#2 1034.6666666666667
(byte) flip::srcIdx#3 202.0
(void()) main()
(byte~) main::$1 2002.0
(byte~) main::$3 2002.0
(byte) main::c
(byte) main::c#1 151.5
(byte) main::c#2 40.4
(void()) plot()
(byte~) plot::$3 2002.0
(byte) plot::i
(byte) plot::i#1 350.5
(byte) plot::i#2 1034.6666666666667
(byte) plot::i#3 202.0
(byte*) plot::line
(byte*) plot::line#1 67.33333333333333
(byte*) plot::line#2 171.85714285714283
(byte) plot::x
(byte) plot::x#1 1501.5
(byte) plot::x#2 750.75
(byte) plot::y
(byte) plot::y#1 151.5
(byte) plot::y#2 25.25
(void()) prepare()
(byte) prepare::i
(byte) prepare::i#1 16.5
(byte) prepare::i#2 22.0
zp byte:2 [ main::c#2 main::c#1 ]
zp ptr byte:3 [ plot::line#2 plot::line#1 ]
zp byte:5 [ plot::y#2 plot::y#1 ]
zp byte:6 [ plot::i#2 plot::i#3 plot::i#1 ]
zp byte:7 [ plot::x#2 plot::x#1 ]
zp byte:8 [ flip::r#2 flip::r#1 ]
zp byte:9 [ flip::srcIdx#2 flip::srcIdx#3 flip::srcIdx#1 ]
zp byte:10 [ flip::dstIdx#3 flip::dstIdx#5 flip::dstIdx#2 flip::dstIdx#1 ]
zp byte:11 [ flip::c#2 flip::c#1 ]
zp byte:12 [ flip::i#2 flip::i#1 ]
zp byte:13 [ prepare::i#2 prepare::i#1 ]
zp byte:14 [ main::$1 ]
zp byte:15 [ main::$3 ]
zp byte:16 [ plot::$3 ]
zp byte:17 [ flip::$0 ]
zp byte:18 [ flip::$4 ]
Coalescing zero page register [ zp byte:2 [ main::c#2 main::c#1 ] ] with [ zp byte:5 [ plot::y#2 plot::y#1 ] ]
Coalescing zero page register [ zp byte:2 [ main::c#2 main::c#1 plot::y#2 plot::y#1 ] ] with [ zp byte:8 [ flip::r#2 flip::r#1 ] ]
Coalescing zero page register [ zp byte:2 [ main::c#2 main::c#1 plot::y#2 plot::y#1 flip::r#2 flip::r#1 ] ] with [ zp byte:12 [ flip::i#2 flip::i#1 ] ]
@ -4794,35 +4860,34 @@ FINAL SYMBOL TABLE
(byte[256]) buffer1
(byte[256]) buffer2
(void()) flip()
(byte~) flip::$0 zp byte:8
(byte~) flip::$4 zp byte:5
(byte~) flip::$0 zp byte:8 2002.0
(byte~) flip::$4 zp byte:5 202.0
(label) flip::@1
(label) flip::@2
(label) flip::@3
(label) flip::@4
(label) flip::@return
(byte) flip::c
(byte) flip::c#1 zp byte:7
(byte) flip::c#2 zp byte:7
(byte) flip::c#1 zp byte:7 1501.5
(byte) flip::c#2 zp byte:7 400.4
(byte) flip::dstIdx
(byte) flip::dstIdx#1 zp byte:6
(byte) flip::dstIdx#2 zp byte:6
(byte) flip::dstIdx#3 zp byte:6
(byte) flip::dstIdx#5 zp byte:6
(byte) flip::dstIdx#1 zp byte:6 701.0
(byte) flip::dstIdx#2 zp byte:6 67.33333333333333
(byte) flip::dstIdx#3 zp byte:6 776.0
(byte) flip::dstIdx#5 zp byte:6 202.0
(byte) flip::i
(byte) flip::i#1 zp byte:2
(byte) flip::i#2 zp byte:2
(byte) flip::i#1 zp byte:2 151.5
(byte) flip::i#2 zp byte:2 134.66666666666666
(byte) flip::r
(byte) flip::r#1 zp byte:2
(byte) flip::r#2 zp byte:2
(byte) flip::r#1 zp byte:2 151.5
(byte) flip::r#2 zp byte:2 22.444444444444443
(byte) flip::srcIdx
(byte) flip::srcIdx#1 zp byte:5
(byte) flip::srcIdx#2 zp byte:5
(byte) flip::srcIdx#3 zp byte:5
(byte) flip::srcIdx#1 zp byte:5 300.42857142857144
(byte) flip::srcIdx#2 zp byte:5 1034.6666666666667
(byte) flip::srcIdx#3 zp byte:5 202.0
(void()) main()
(byte~) main::$1 zp byte:5
(byte~) main::$3 zp byte:5
(byte~) main::$1 zp byte:5 2002.0
(byte~) main::$3 zp byte:5 2002.0
(label) main::@10
(label) main::@11
(label) main::@3
@ -4831,36 +4896,33 @@ FINAL SYMBOL TABLE
(label) main::@7
(label) main::@return
(byte) main::c
(byte) main::c#1 zp byte:2
(byte) main::c#2 zp byte:2
(byte) main::c#1 zp byte:2 151.5
(byte) main::c#2 zp byte:2 40.4
(void()) plot()
(byte~) plot::$3 zp byte:7
(byte~) plot::$3 zp byte:7 2002.0
(label) plot::@1
(label) plot::@2
(label) plot::@3
(label) plot::@return
(byte) plot::i
(byte) plot::i#1 zp byte:5
(byte) plot::i#2 zp byte:5
(byte) plot::i#3 zp byte:5
(byte) plot::i#1 zp byte:5 350.5
(byte) plot::i#2 zp byte:5 1034.6666666666667
(byte) plot::i#3 zp byte:5 202.0
(byte*) plot::line
(byte*) plot::line#1 zp ptr byte:3
(byte*) plot::line#2 zp ptr byte:3
(byte*) plot::line#1 zp ptr byte:3 67.33333333333333
(byte*) plot::line#2 zp ptr byte:3 171.85714285714283
(byte) plot::x
(byte) plot::x#1 zp byte:6
(byte) plot::x#2 zp byte:6
(byte) plot::x#1 zp byte:6 1501.5
(byte) plot::x#2 zp byte:6 750.75
(byte) plot::y
(byte) plot::y#1 zp byte:2
(byte) plot::y#2 zp byte:2
(byte) plot::y#1 zp byte:2 151.5
(byte) plot::y#2 zp byte:2 25.25
(void()) prepare()
(label) prepare::@1
(label) prepare::@return
(byte) prepare::i
(byte) prepare::i#1 zp byte:2
(byte) prepare::i#2 zp byte:2
(byte) prepare::i#1 zp byte:2 16.5
(byte) prepare::i#2 zp byte:2 22.0
zp byte:2 [ main::c#2 main::c#1 plot::y#2 plot::y#1 flip::r#2 flip::r#1 flip::i#2 flip::i#1 prepare::i#2 prepare::i#1 ]
zp ptr byte:3 [ plot::line#2 plot::line#1 ]

View File

@ -5,35 +5,34 @@
(byte[256]) buffer1
(byte[256]) buffer2
(void()) flip()
(byte~) flip::$0 zp byte:8
(byte~) flip::$4 zp byte:5
(byte~) flip::$0 zp byte:8 2002.0
(byte~) flip::$4 zp byte:5 202.0
(label) flip::@1
(label) flip::@2
(label) flip::@3
(label) flip::@4
(label) flip::@return
(byte) flip::c
(byte) flip::c#1 zp byte:7
(byte) flip::c#2 zp byte:7
(byte) flip::c#1 zp byte:7 1501.5
(byte) flip::c#2 zp byte:7 400.4
(byte) flip::dstIdx
(byte) flip::dstIdx#1 zp byte:6
(byte) flip::dstIdx#2 zp byte:6
(byte) flip::dstIdx#3 zp byte:6
(byte) flip::dstIdx#5 zp byte:6
(byte) flip::dstIdx#1 zp byte:6 701.0
(byte) flip::dstIdx#2 zp byte:6 67.33333333333333
(byte) flip::dstIdx#3 zp byte:6 776.0
(byte) flip::dstIdx#5 zp byte:6 202.0
(byte) flip::i
(byte) flip::i#1 zp byte:2
(byte) flip::i#2 zp byte:2
(byte) flip::i#1 zp byte:2 151.5
(byte) flip::i#2 zp byte:2 134.66666666666666
(byte) flip::r
(byte) flip::r#1 zp byte:2
(byte) flip::r#2 zp byte:2
(byte) flip::r#1 zp byte:2 151.5
(byte) flip::r#2 zp byte:2 22.444444444444443
(byte) flip::srcIdx
(byte) flip::srcIdx#1 zp byte:5
(byte) flip::srcIdx#2 zp byte:5
(byte) flip::srcIdx#3 zp byte:5
(byte) flip::srcIdx#1 zp byte:5 300.42857142857144
(byte) flip::srcIdx#2 zp byte:5 1034.6666666666667
(byte) flip::srcIdx#3 zp byte:5 202.0
(void()) main()
(byte~) main::$1 zp byte:5
(byte~) main::$3 zp byte:5
(byte~) main::$1 zp byte:5 2002.0
(byte~) main::$3 zp byte:5 2002.0
(label) main::@10
(label) main::@11
(label) main::@3
@ -42,33 +41,37 @@
(label) main::@7
(label) main::@return
(byte) main::c
(byte) main::c#1 zp byte:2
(byte) main::c#2 zp byte:2
(byte) main::c#1 zp byte:2 151.5
(byte) main::c#2 zp byte:2 40.4
(void()) plot()
(byte~) plot::$3 zp byte:7
(byte~) plot::$3 zp byte:7 2002.0
(label) plot::@1
(label) plot::@2
(label) plot::@3
(label) plot::@return
(byte) plot::i
(byte) plot::i#1 zp byte:5
(byte) plot::i#2 zp byte:5
(byte) plot::i#3 zp byte:5
(byte) plot::i#1 zp byte:5 350.5
(byte) plot::i#2 zp byte:5 1034.6666666666667
(byte) plot::i#3 zp byte:5 202.0
(byte*) plot::line
(byte*) plot::line#1 zp ptr byte:3
(byte*) plot::line#2 zp ptr byte:3
(byte*) plot::line#1 zp ptr byte:3 67.33333333333333
(byte*) plot::line#2 zp ptr byte:3 171.85714285714283
(byte) plot::x
(byte) plot::x#1 zp byte:6
(byte) plot::x#2 zp byte:6
(byte) plot::x#1 zp byte:6 1501.5
(byte) plot::x#2 zp byte:6 750.75
(byte) plot::y
(byte) plot::y#1 zp byte:2
(byte) plot::y#2 zp byte:2
(byte) plot::y#1 zp byte:2 151.5
(byte) plot::y#2 zp byte:2 25.25
(void()) prepare()
(label) prepare::@1
(label) prepare::@return
(byte) prepare::i
(byte) prepare::i#1 zp byte:2
(byte) prepare::i#2 zp byte:2
(byte) prepare::i#1 zp byte:2 16.5
(byte) prepare::i#2 zp byte:2 22.0
zp byte:2 [ main::c#2 main::c#1 plot::y#2 plot::y#1 flip::r#2 flip::r#1 flip::i#2 flip::i#1 prepare::i#2 prepare::i#1 ]
zp ptr byte:3 [ plot::line#2 plot::line#1 ]
zp byte:6 [ plot::i#2 plot::i#3 plot::i#1 flip::srcIdx#2 flip::srcIdx#3 flip::srcIdx#1 main::$1 main::$3 flip::$4 ]
zp byte:7 [ plot::x#2 plot::x#1 flip::dstIdx#3 flip::dstIdx#5 flip::dstIdx#2 flip::dstIdx#1 ]
zp byte:11 [ flip::c#2 flip::c#1 plot::$3 ]
zp byte:17 [ flip::$0 ]

View File

@ -371,6 +371,19 @@ Complete equivalence classes
[ s#2 s#4 s#1 ]
Allocated zp byte:2 to zp byte:2 [ i#2 i#1 ]
Allocated zp byte:3 to zp byte:3 [ s#2 s#4 s#1 ]
VARIABLE REGISTER WEIGHTS
(byte) i
(byte) i#1 16.5
(byte) i#2 11.0
(byte) s
(byte) s#1 22.0
(byte) s#2 16.5
(byte) s#4 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#2 s#4 s#1 ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
INITIAL ASM
@ -505,12 +518,12 @@ FINAL SYMBOL TABLE
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 16.5
(byte) i#2 zp byte:2 11.0
(byte) s
(byte) s#1 zp byte:3
(byte) s#2 zp byte:3
(byte) s#4 zp byte:3
(byte) s#1 zp byte:3 22.0
(byte) s#2 zp byte:3 16.5
(byte) s#4 zp byte:3 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#2 s#4 s#1 ]

View File

@ -4,9 +4,12 @@
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 16.5
(byte) i#2 zp byte:2 11.0
(byte) s
(byte) s#1 zp byte:3
(byte) s#2 zp byte:3
(byte) s#4 zp byte:3
(byte) s#1 zp byte:3 22.0
(byte) s#2 zp byte:3 16.5
(byte) s#4 zp byte:3 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#2 s#4 s#1 ]

View File

@ -51,14 +51,12 @@ SYMBOLS
(label) main::@1
(label) main::@return
(byte) main::i
(void()) nest()
(boolean~) nest::$0
(label) nest::@1
(label) nest::@return
(byte) nest::j
INITIAL CONTROL FLOW GRAPH
@BEGIN: from
(byte*) SCREEN ← (word) 1024
@ -721,6 +719,21 @@ Complete equivalence classes
[ nest::j#2 nest::j#1 ]
Allocated zp byte:2 to zp byte:2 [ main::i#2 main::i#1 ]
Allocated zp byte:3 to zp byte:3 [ nest::j#2 nest::j#1 ]
VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 3.142857142857143
(void()) nest()
(byte) nest::j
(byte) nest::j#1 151.5
(byte) nest::j#2 151.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ nest::j#2 nest::j#1 ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
INITIAL ASM
@ -872,16 +885,14 @@ FINAL SYMBOL TABLE
(label) main::@3
(label) main::@return
(byte) main::i
(byte) main::i#1 zp byte:2
(byte) main::i#2 zp byte:2
(byte) main::i#1 zp byte:2 16.5
(byte) main::i#2 zp byte:2 3.142857142857143
(void()) nest()
(label) nest::@1
(label) nest::@return
(byte) nest::j
(byte) nest::j#1 zp byte:3
(byte) nest::j#2 zp byte:3
(byte) nest::j#1 zp byte:3 151.5
(byte) nest::j#2 zp byte:3 151.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ nest::j#2 nest::j#1 ]

View File

@ -6,16 +6,14 @@
(label) main::@3
(label) main::@return
(byte) main::i
(byte) main::i#1 zp byte:2
(byte) main::i#2 zp byte:2
(byte) main::i#1 zp byte:2 16.5
(byte) main::i#2 zp byte:2 3.142857142857143
(void()) nest()
(label) nest::@1
(label) nest::@return
(byte) nest::j
(byte) nest::j#1 zp byte:3
(byte) nest::j#2 zp byte:3
(byte) nest::j#1 zp byte:3 151.5
(byte) nest::j#2 zp byte:3 151.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ nest::j#2 nest::j#1 ]

View File

@ -99,7 +99,6 @@ SYMBOLS
(label) main::@return
(byte) main::i
(byte) main::j
(void()) nest1()
(void~) nest1::$0
(boolean~) nest1::$1
@ -109,7 +108,6 @@ SYMBOLS
(label) nest1::@return
(byte) nest1::i
(byte) nest1::j
(void()) nest2()
(boolean~) nest2::$0
(boolean~) nest2::$1
@ -119,7 +117,6 @@ SYMBOLS
(byte) nest2::i
(byte) nest2::j
INITIAL CONTROL FLOW GRAPH
@BEGIN: from
(byte*) SCREEN ← (word) 1024
@ -1820,6 +1817,38 @@ Allocated zp byte:4 to zp byte:4 [ nest1::i#2 nest1::i#1 ]
Allocated zp byte:5 to zp byte:5 [ nest1::j#2 nest1::j#1 ]
Allocated zp byte:6 to zp byte:6 [ nest2::i#2 nest2::i#1 ]
Allocated zp byte:7 to zp byte:7 [ nest2::j#2 nest2::j#1 ]
VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(void()) main()
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 1.0476190476190477
(byte) main::j
(byte) main::j#1 151.5
(byte) main::j#2 11.222222222222221
(void()) nest1()
(byte) nest1::i
(byte) nest1::i#1 1501.5
(byte) nest1::i#2 154.0
(byte) nest1::j
(byte) nest1::j#1 15001.5
(byte) nest1::j#2 2000.2
(void()) nest2()
(byte) nest2::i
(byte) nest2::i#1 150001.5
(byte) nest2::i#2 40000.4
(byte) nest2::j
(byte) nest2::j#1 1500001.5
(byte) nest2::j#2 1500001.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ main::j#2 main::j#1 ]
zp byte:4 [ nest1::i#2 nest1::i#1 ]
zp byte:5 [ nest1::j#2 nest1::j#1 ]
zp byte:6 [ nest2::i#2 nest2::i#1 ]
zp byte:7 [ nest2::j#2 nest2::j#1 ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
Re-allocated ZP register from zp byte:4 to zp byte:4
@ -2175,12 +2204,11 @@ FINAL SYMBOL TABLE
(label) main::@5
(label) main::@return
(byte) main::i
(byte) main::i#1 zp byte:2
(byte) main::i#2 zp byte:2
(byte) main::i#1 zp byte:2 16.5
(byte) main::i#2 zp byte:2 1.0476190476190477
(byte) main::j
(byte) main::j#1 zp byte:3
(byte) main::j#2 zp byte:3
(byte) main::j#1 zp byte:3 151.5
(byte) main::j#2 zp byte:3 11.222222222222221
(void()) nest1()
(label) nest1::@1
(label) nest1::@2
@ -2188,24 +2216,22 @@ FINAL SYMBOL TABLE
(label) nest1::@5
(label) nest1::@return
(byte) nest1::i
(byte) nest1::i#1 zp byte:4
(byte) nest1::i#2 zp byte:4
(byte) nest1::i#1 zp byte:4 1501.5
(byte) nest1::i#2 zp byte:4 154.0
(byte) nest1::j
(byte) nest1::j#1 zp byte:5
(byte) nest1::j#2 zp byte:5
(byte) nest1::j#1 zp byte:5 15001.5
(byte) nest1::j#2 zp byte:5 2000.2
(void()) nest2()
(label) nest2::@1
(label) nest2::@2
(label) nest2::@3
(label) nest2::@return
(byte) nest2::i
(byte) nest2::i#1 zp byte:6
(byte) nest2::i#2 zp byte:6
(byte) nest2::i#1 zp byte:6 150001.5
(byte) nest2::i#2 zp byte:6 40000.4
(byte) nest2::j
(byte) nest2::j#1 zp byte:7
(byte) nest2::j#2 zp byte:7
(byte) nest2::j#1 zp byte:7 1500001.5
(byte) nest2::j#2 zp byte:7 1500001.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ main::j#2 main::j#1 ]

View File

@ -8,12 +8,11 @@
(label) main::@5
(label) main::@return
(byte) main::i
(byte) main::i#1 zp byte:2
(byte) main::i#2 zp byte:2
(byte) main::i#1 zp byte:2 16.5
(byte) main::i#2 zp byte:2 1.0476190476190477
(byte) main::j
(byte) main::j#1 zp byte:3
(byte) main::j#2 zp byte:3
(byte) main::j#1 zp byte:3 151.5
(byte) main::j#2 zp byte:3 11.222222222222221
(void()) nest1()
(label) nest1::@1
(label) nest1::@2
@ -21,24 +20,22 @@
(label) nest1::@5
(label) nest1::@return
(byte) nest1::i
(byte) nest1::i#1 zp byte:4
(byte) nest1::i#2 zp byte:4
(byte) nest1::i#1 zp byte:4 1501.5
(byte) nest1::i#2 zp byte:4 154.0
(byte) nest1::j
(byte) nest1::j#1 zp byte:5
(byte) nest1::j#2 zp byte:5
(byte) nest1::j#1 zp byte:5 15001.5
(byte) nest1::j#2 zp byte:5 2000.2
(void()) nest2()
(label) nest2::@1
(label) nest2::@2
(label) nest2::@3
(label) nest2::@return
(byte) nest2::i
(byte) nest2::i#1 zp byte:6
(byte) nest2::i#2 zp byte:6
(byte) nest2::i#1 zp byte:6 150001.5
(byte) nest2::i#2 zp byte:6 40000.4
(byte) nest2::j
(byte) nest2::j#1 zp byte:7
(byte) nest2::j#2 zp byte:7
(byte) nest2::j#1 zp byte:7 1500001.5
(byte) nest2::j#2 zp byte:7 1500001.5
zp byte:2 [ main::i#2 main::i#1 ]
zp byte:3 [ main::j#2 main::j#1 ]

View File

@ -395,6 +395,19 @@ Complete equivalence classes
[ s#3 s#1 s#2 ]
Allocated zp byte:2 to zp byte:2 [ i#2 i#1 ]
Allocated zp byte:3 to zp byte:3 [ s#3 s#1 s#2 ]
VARIABLE REGISTER WEIGHTS
(byte) i
(byte) i#1 11.0
(byte) i#2 33.0
(byte) s
(byte) s#1 22.0
(byte) s#2 22.0
(byte) s#3 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#3 s#1 s#2 ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
INITIAL ASM
@ -527,12 +540,12 @@ FINAL SYMBOL TABLE
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 11.0
(byte) i#2 zp byte:2 33.0
(byte) s
(byte) s#1 zp byte:3
(byte) s#2 zp byte:3
(byte) s#3 zp byte:3
(byte) s#1 zp byte:3 22.0
(byte) s#2 zp byte:3 22.0
(byte) s#3 zp byte:3 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#3 s#1 s#2 ]

View File

@ -5,9 +5,12 @@
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 11.0
(byte) i#2 zp byte:2 33.0
(byte) s
(byte) s#1 zp byte:3
(byte) s#2 zp byte:3
(byte) s#3 zp byte:3
(byte) s#1 zp byte:3 22.0
(byte) s#2 zp byte:3 22.0
(byte) s#3 zp byte:3 11.0
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ s#3 s#1 s#2 ]

View File

@ -291,6 +291,18 @@ Complete equivalence classes
[ $0 $1 ]
Allocated zp byte:2 to zp byte:2 [ i#2 i#1 ]
Allocated zp byte:3 to zp byte:3 [ $0 $1 ]
VARIABLE REGISTER WEIGHTS
(byte~) $0 22.0
(byte~) $1 22.0
(byte) i
(byte) i#1 16.5
(byte) i#2 11.0
(byte[16]) p
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ $0 $1 ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
INITIAL ASM
@ -396,14 +408,14 @@ B1:
BEND:
FINAL SYMBOL TABLE
(byte~) $0 zp byte:3
(byte~) $1 zp byte:3
(byte~) $0 zp byte:3 22.0
(byte~) $1 zp byte:3 22.0
(label) @1
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 16.5
(byte) i#2 zp byte:2 11.0
(byte[16]) p
zp byte:2 [ i#2 i#1 ]

View File

@ -1,9 +1,12 @@
(byte~) $0 zp byte:3
(byte~) $1 zp byte:3
(byte~) $0 zp byte:3 22.0
(byte~) $1 zp byte:3 22.0
(label) @1
(label) @BEGIN
(label) @END
(byte) i
(byte) i#1 zp byte:2
(byte) i#2 zp byte:2
(byte) i#1 zp byte:2 16.5
(byte) i#2 zp byte:2 11.0
(byte[16]) p
zp byte:2 [ i#2 i#1 ]
zp byte:3 [ $0 $1 ]

View File

@ -35,7 +35,6 @@ SYMBOLS
(byte) sum::b
(byte) sum::return
INITIAL CONTROL FLOW GRAPH
@BEGIN: from
(byte~) $0 ← call sum (byte) 1 (byte) 2
@ -370,6 +369,27 @@ Allocated zp byte:2 to zp byte:2 [ sum::a#2 sum::return#0 ]
Allocated zp byte:3 to zp byte:3 [ sum::b#2 ]
Allocated zp byte:4 to zp byte:4 [ s1#0 s3#0 ]
Allocated zp byte:5 to zp byte:5 [ s2#0 ]
VARIABLE REGISTER WEIGHTS
(byte) s1
(byte) s1#0 0.5714285714285714
(byte) s2
(byte) s2#0 4.0
(byte) s3
(byte) s3#0 Infinity
(byte()) sum((byte) sum::a , (byte) sum::b)
(byte) sum::a
(byte) sum::a#2 2.0
(byte) sum::b
(byte) sum::b#2 2.0
(byte) sum::return
(byte) sum::return#0 1.2000000000000002
zp byte:2 [ sum::a#2 sum::return#0 ]
zp byte:3 [ sum::b#2 ]
zp byte:4 [ s1#0 s3#0 ]
zp byte:5 [ s2#0 ]
Coalescing zero page register [ zp byte:2 [ sum::a#2 sum::return#0 ] ] with [ zp byte:5 [ s2#0 ] ]
Re-allocated ZP register from zp byte:2 to zp byte:2
Re-allocated ZP register from zp byte:3 to zp byte:3
@ -467,20 +487,19 @@ FINAL SYMBOL TABLE
(label) @BEGIN
(label) @END
(byte) s1
(byte) s1#0 zp byte:4
(byte) s1#0 zp byte:4 0.5714285714285714
(byte) s2
(byte) s2#0 zp byte:2
(byte) s2#0 zp byte:2 4.0
(byte) s3
(byte) s3#0 zp byte:4
(byte) s3#0 zp byte:4 Infinity
(byte()) sum((byte) sum::a , (byte) sum::b)
(label) sum::@return
(byte) sum::a
(byte) sum::a#2 zp byte:2
(byte) sum::a#2 zp byte:2 2.0
(byte) sum::b
(byte) sum::b#2 zp byte:3
(byte) sum::b#2 zp byte:3 2.0
(byte) sum::return
(byte) sum::return#0 zp byte:2
(byte) sum::return#0 zp byte:2 1.2000000000000002
zp byte:2 [ sum::a#2 sum::return#0 s2#0 ]
zp byte:3 [ sum::b#2 ]

View File

@ -3,20 +3,19 @@
(label) @BEGIN
(label) @END
(byte) s1
(byte) s1#0 zp byte:4
(byte) s1#0 zp byte:4 0.5714285714285714
(byte) s2
(byte) s2#0 zp byte:2
(byte) s2#0 zp byte:2 4.0
(byte) s3
(byte) s3#0 zp byte:4
(byte) s3#0 zp byte:4 Infinity
(byte()) sum((byte) sum::a , (byte) sum::b)
(label) sum::@return
(byte) sum::a
(byte) sum::a#2 zp byte:2
(byte) sum::a#2 zp byte:2 2.0
(byte) sum::b
(byte) sum::b#2 zp byte:3
(byte) sum::b#2 zp byte:3 2.0
(byte) sum::return
(byte) sum::return#0 zp byte:2
(byte) sum::return#0 zp byte:2 1.2000000000000002
zp byte:2 [ sum::a#2 sum::return#0 s2#0 ]
zp byte:3 [ sum::b#2 ]