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

Improve pass structure

This commit is contained in:
jespergravgaard 2017-08-13 00:30:51 +02:00
parent 9c8372b989
commit 4741a2d22e
33 changed files with 263 additions and 265 deletions

View File

@ -6,7 +6,8 @@ import dk.camelot64.kickc.parser.KickCParser;
import dk.camelot64.kickc.passes.*;
import org.antlr.v4.runtime.*;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
/**
* Perform KickC compilation and optimizations
@ -22,8 +23,7 @@ public class Compiler {
pass2OptimizeSSA(program);
pass3Analysis(program);
pass4RegisterAllocation(program);
pass5GenerateAsm(program);
pass6OptimizeAsm(program);
pass5GenerateAndOptimizeAsm(program);
log.append("FINAL SYMBOL TABLE");
log.append(program.getScope().getSymbolTableContents(program));
@ -37,155 +37,24 @@ public class Compiler {
}
}
public void pass6OptimizeAsm(Program program) {
List<Pass6AsmOptimization> pass6Optimizations = new ArrayList<>();
pass6Optimizations.add(new Pass6NextJumpElimination(program));
pass6Optimizations.add(new Pass6UnnecesaryLoadElimination(program));
pass6Optimizations.add(new Pass6RedundantLabelElimination(program));
pass6Optimizations.add(new Pass6UnusedLabelElimination(program));
boolean asmOptimized = true;
CompileLog log = program.getLog();
while (asmOptimized) {
asmOptimized = false;
for (Pass6AsmOptimization optimization : pass6Optimizations) {
boolean stepOptimized = optimization.optimize();
if (stepOptimized) {
log.append("Succesful ASM optimization " + optimization.getClass().getSimpleName());
asmOptimized = true;
log.append("ASSEMBLER");
log.append(program.getAsm().toString());
}
public KickCParser.FileContext pass0ParseInput(final CharStream input, CompileLog log) {
log.append(input.toString());
KickCLexer lexer = new KickCLexer(input);
KickCParser parser = new KickCParser(new CommonTokenStream(lexer));
parser.setBuildParseTree(true);
parser.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(
Recognizer<?, ?> recognizer,
Object offendingSymbol,
int line,
int charPositionInLine,
String msg,
RecognitionException e) {
throw new RuntimeException("Error parsing file " + input.getSourceName() + "\n - Line: " + line + "\n - Message: " + msg);
}
}
}
private void pass5GenerateAsm(Program program) {
new Pass3CodeGeneration(program).generate();
new Pass3AssertNoCpuClobber(program).check();
}
private void pass4RegisterAllocation(Program program) {
// Find potential registers for each live range equivalence class - based on clobbering of fragments
boolean change;
do {
change = new Pass3RegisterUpliftPotentialRegisterAnalysis(program).findPotentialRegisters();
} while (change);
new Pass3RegisterUpliftPotentialAluAnalysis(program).findPotentialAlu();
program.getLog().append("REGISTER UPLIFT POTENTIAL REGISTERS");
program.getLog().append(program.getRegisterPotentials().toString());
// Find register uplift scopes
new Pass3RegisterUpliftScopeAnalysis(program).findScopes();
program.getLog().append("REGISTER UPLIFT SCOPES");
program.getLog().append(program.getRegisterUpliftProgram().toString((program.getVariableRegisterWeights())));
// Attempt uplifting registers through a lot of combinations
new Pass3RegisterUpliftCombinations(program).performUplift(10_000);
// Attempt uplifting registers one at a time to catch remaining potential not realized by combination search
new Pass3RegisterUpliftRemains(program).performUplift();
// Final register coalesce and code generation
new Pass3ZeroPageCoalesce(program).allocate();
new Pass3RegistersFinalize(program).allocate(true);
}
private void pass3Analysis(Program program) {
new Pass3BlockSequencePlanner(program).plan();
// Phi lifting ensures that all variables in phi-blocks are in different live range equivalence classes
new Pass3PhiLifting(program).perform();
new Pass3BlockSequencePlanner(program).plan();
program.getLog().append("CONTROL FLOW GRAPH - PHI LIFTED");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
new Pass3LiveRangesAnalysis(program).findLiveRanges();
program.getLog().append("CONTROL FLOW GRAPH - LIVE RANGES");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
// Phi mem coalesce removes as many variables introduced by phi lifting as possible - as long as their live ranges do not overlap
new Pass3PhiMemCoalesce(program).optimize();
new Pass2CullEmptyBlocks(program).optimize();
new Pass3BlockSequencePlanner(program).plan();
new Pass3LiveRangesAnalysis(program).findLiveRanges();
program.getLog().append("CONTROL FLOW GRAPH - PHI MEM COALESCED");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
new Pass3CallGraphAnalysis(program).findCallGraph();
program.getLog().append("CALL GRAPH");
program.getLog().append(program.getCallGraph().toString());
new Pass3DominatorsAnalysis(program).findDominators();
program.getLog().append("DOMINATORS");
program.getLog().append(program.getDominators().toString());
new Pass3LoopAnalysis(program).findLoops();
program.getLog().append("NATURAL LOOPS");
program.getLog().append(program.getLoopSet().toString());
new Pass3LoopDepthAnalysis(program).findLoopDepths();
program.getLog().append("NATURAL LOOPS WITH DEPTH");
program.getLog().append(program.getLoopSet().toString());
new Pass3VariableRegisterWeightAnalysis(program).findWeights();
program.getLog().append("\nVARIABLE REGISTER WEIGHTS");
program.getLog().append(program.getScope().getSymbolTableContents(program, Variable.class));
new Pass3ZeroPageAllocation(program).allocate();
new Pass3RegistersFinalize(program).allocate(false);
// Initial Code generation
new Pass3CodeGeneration(program).generate();
new Pass3AssertNoCpuClobber(program).check();
program.getLog().append("INITIAL ASM");
program.getLog().append(program.getAsm().toString());
}
public void pass2OptimizeSSA(Program program) {
List<Pass2SsaOptimization> optimizations = new ArrayList<>();
optimizations.add(new Pass2CullEmptyBlocks(program));
optimizations.add(new Pass2ConstantPropagation(program));
optimizations.add(new Pass2ConstantAdditionElimination(program));
optimizations.add(new Pass2AliasElimination(program));
optimizations.add(new Pass2RedundantPhiElimination(program));
optimizations.add(new Pass2SelfPhiElimination(program));
optimizations.add(new Pass2ConditionalJumpSimplification(program));
boolean ssaOptimized = true;
while (ssaOptimized) {
pass2AssertSSA(program);
ssaOptimized = false;
for (Pass2SsaOptimization optimization : optimizations) {
boolean stepOptimized = optimization.optimize();
if (stepOptimized) {
program.getLog().append("Succesful SSA optimization " + optimization.getClass().getSimpleName() + "");
ssaOptimized = true;
program.getLog().append("CONTROL FLOW GRAPH");
program.getLog().append(program.getGraph().toString(program));
}
}
}
}
public void pass2AssertSSA(Program program) {
List<Pass2SsaAssertion> assertions = new ArrayList<>();
assertions.add(new Pass2AssertSymbols(program));
assertions.add(new Pass2AssertBlocks(program));
assertions.add(new Pass2AssertNoCallParameters(program));
assertions.add(new Pass2AssertNoCallLvalues(program));
assertions.add(new Pass2AssertNoReturnValues(program));
assertions.add(new Pass2AssertNoProcs(program));
assertions.add(new Pass2AssertNoLabels(program));
for (Pass2SsaAssertion assertion : assertions) {
assertion.check();
}
});
return parser.file();
}
public Program pass1GenerateSSA(KickCParser.FileContext file, CompileLog log) {
@ -244,24 +113,155 @@ public class Compiler {
return program;
}
public KickCParser.FileContext pass0ParseInput(final CharStream input, CompileLog log) {
log.append(input.toString());
KickCLexer lexer = new KickCLexer(input);
KickCParser parser = new KickCParser(new CommonTokenStream(lexer));
parser.setBuildParseTree(true);
parser.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(
Recognizer<?, ?> recognizer,
Object offendingSymbol,
int line,
int charPositionInLine,
String msg,
RecognitionException e) {
throw new RuntimeException("Error parsing file " + input.getSourceName() + "\n - Line: " + line + "\n - Message: " + msg);
public void pass2AssertSSA(Program program) {
List<Pass2SsaAssertion> assertions = new ArrayList<>();
assertions.add(new Pass2AssertSymbols(program));
assertions.add(new Pass2AssertBlocks(program));
assertions.add(new Pass2AssertNoCallParameters(program));
assertions.add(new Pass2AssertNoCallLvalues(program));
assertions.add(new Pass2AssertNoReturnValues(program));
assertions.add(new Pass2AssertNoProcs(program));
assertions.add(new Pass2AssertNoLabels(program));
for (Pass2SsaAssertion assertion : assertions) {
assertion.check();
}
}
public void pass2OptimizeSSA(Program program) {
List<Pass2SsaOptimization> optimizations = new ArrayList<>();
optimizations.add(new Pass2CullEmptyBlocks(program));
optimizations.add(new Pass2ConstantPropagation(program));
optimizations.add(new Pass2ConstantAdditionElimination(program));
optimizations.add(new Pass2AliasElimination(program));
optimizations.add(new Pass2RedundantPhiElimination(program));
optimizations.add(new Pass2SelfPhiElimination(program));
optimizations.add(new Pass2ConditionalJumpSimplification(program));
boolean ssaOptimized = true;
while (ssaOptimized) {
pass2AssertSSA(program);
ssaOptimized = false;
for (Pass2SsaOptimization optimization : optimizations) {
boolean stepOptimized = optimization.optimize();
if (stepOptimized) {
program.getLog().append("Succesful SSA optimization " + optimization.getClass().getSimpleName() + "");
ssaOptimized = true;
program.getLog().append("CONTROL FLOW GRAPH");
program.getLog().append(program.getGraph().toString(program));
}
}
});
return parser.file();
}
}
private void pass3Analysis(Program program) {
new Pass3BlockSequencePlanner(program).plan();
// Phi lifting ensures that all variables in phi-blocks are in different live range equivalence classes
new Pass3PhiLifting(program).perform();
new Pass3BlockSequencePlanner(program).plan();
program.getLog().append("CONTROL FLOW GRAPH - PHI LIFTED");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
new Pass3LiveRangesAnalysis(program).findLiveRanges();
program.getLog().append("CONTROL FLOW GRAPH - LIVE RANGES");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
// Phi mem coalesce removes as many variables introduced by phi lifting as possible - as long as their live ranges do not overlap
new Pass3PhiMemCoalesce(program).optimize();
new Pass2CullEmptyBlocks(program).optimize();
new Pass3BlockSequencePlanner(program).plan();
new Pass3LiveRangesAnalysis(program).findLiveRanges();
program.getLog().append("CONTROL FLOW GRAPH - PHI MEM COALESCED");
program.getLog().append(program.getGraph().toString(program));
pass2AssertSSA(program);
new Pass3CallGraphAnalysis(program).findCallGraph();
program.getLog().append("CALL GRAPH");
program.getLog().append(program.getCallGraph().toString());
new Pass3DominatorsAnalysis(program).findDominators();
program.getLog().append("DOMINATORS");
program.getLog().append(program.getDominators().toString());
new Pass3LoopAnalysis(program).findLoops();
program.getLog().append("NATURAL LOOPS");
program.getLog().append(program.getLoopSet().toString());
new Pass3LoopDepthAnalysis(program).findLoopDepths();
program.getLog().append("NATURAL LOOPS WITH DEPTH");
program.getLog().append(program.getLoopSet().toString());
new Pass3VariableRegisterWeightAnalysis(program).findWeights();
program.getLog().append("\nVARIABLE REGISTER WEIGHTS");
program.getLog().append(program.getScope().getSymbolTableContents(program, Variable.class));
}
private void pass4RegisterAllocation(Program program) {
new Pass4ZeroPageAllocation(program).allocate();
new Pass4RegistersFinalize(program).allocate(false);
// Initial Code generation
new Pass4CodeGeneration(program).generate();
new Pass4AssertNoCpuClobber(program).check();
program.getLog().append("INITIAL ASM");
program.getLog().append(program.getAsm().toString());
// Find potential registers for each live range equivalence class - based on clobbering of fragments
boolean change;
do {
change = new Pass4RegisterUpliftPotentialRegisterAnalysis(program).findPotentialRegisters();
} while (change);
new Pass4RegisterUpliftPotentialAluAnalysis(program).findPotentialAlu();
program.getLog().append("REGISTER UPLIFT POTENTIAL REGISTERS");
program.getLog().append(program.getRegisterPotentials().toString());
// Find register uplift scopes
new Pass4RegisterUpliftScopeAnalysis(program).findScopes();
program.getLog().append("REGISTER UPLIFT SCOPES");
program.getLog().append(program.getRegisterUpliftProgram().toString((program.getVariableRegisterWeights())));
// Attempt uplifting registers through a lot of combinations
new Pass4RegisterUpliftCombinations(program).performUplift(10_000);
// Attempt uplifting registers one at a time to catch remaining potential not realized by combination search
new Pass4RegisterUpliftRemains(program).performUplift();
// Final register coalesce and finalization
new Pass4ZeroPageCoalesce(program).allocate();
new Pass4RegistersFinalize(program).allocate(true);
}
public void pass5GenerateAndOptimizeAsm(Program program) {
// Final ASM code generation before optimization
new Pass4CodeGeneration(program).generate();
new Pass4AssertNoCpuClobber(program).check();
List<Pass5AsmOptimization> pass5Optimizations = new ArrayList<>();
pass5Optimizations.add(new Pass5NextJumpElimination(program));
pass5Optimizations.add(new Pass5UnnecesaryLoadElimination(program));
pass5Optimizations.add(new Pass5RedundantLabelElimination(program));
pass5Optimizations.add(new Pass5UnusedLabelElimination(program));
boolean asmOptimized = true;
CompileLog log = program.getLog();
while (asmOptimized) {
asmOptimized = false;
for (Pass5AsmOptimization optimization : pass5Optimizations) {
boolean stepOptimized = optimization.optimize();
if (stepOptimized) {
log.append("Succesful ASM optimization " + optimization.getClass().getSimpleName());
asmOptimized = true;
log.append("ASSEMBLER");
log.append(program.getAsm().toString());
}
}
}
}
}

View File

@ -2,6 +2,7 @@ Features
- Move the main code into a main() function, and disallow code outside functions. The main function per default has no parameters and exits with RTS.
- Add a for loop for(init;condition;increment) {stmt} -> { init; do { stmt; increment } while (condition) }
- Add for loop for(byte i: 1..100) { } and for(byte i : 100..0) {} (plus maybe .+. and .-. to make the inc/dec unambiguous)
- Optimize if's without else if(expr) { stmt; } -> $1=!expr; if($1) goto @1; stmt; @1:
- Add signed bytes
- Add signed words
- Add Fixed Point number types fixed[8.8], fixed[16.8] - maybe even fixed[24.4]
@ -26,7 +27,7 @@ Assembler Improvements
- Make generated ASM human readable.
+ Use hex-numbers
- add labels for constants and zp-variables.
- Eliminate unnecessary labels in ASM
+ Eliminate unnecessary labels in ASM
- Eliminate CPX from DEX, CPX #0, BNE la1
- Eliminate LDA from DEC $2, LDA $2, BNE la1
- Eliminate LDA from STA $11, LDA $11

View File

@ -58,8 +58,8 @@ public class Pass3RegisterUpliftTest extends Pass2Base {
allocation.setRegister(var, register);
}
getProgram().setAllocation(allocation);
new Pass3CodeGeneration(getProgram()).generate();
Pass3AssertNoCpuClobber clobber = new Pass3AssertNoCpuClobber(getProgram());
new Pass4CodeGeneration(getProgram()).generate();
Pass4AssertNoCpuClobber clobber = new Pass4AssertNoCpuClobber(getProgram());
if (clobber.hasClobberProblem(false)) {
getLog().append("Uplift to " + register + " resulted in clobber.");
} else {

View File

@ -10,9 +10,9 @@ import java.util.Collection;
import java.util.List;
/*** Ensures that no statement clobbers a CPU register used by an alive variable - and that assigning statements clobber the CPU registers they assign to */
public class Pass3AssertNoCpuClobber extends Pass2Base {
public class Pass4AssertNoCpuClobber extends Pass2Base {
public Pass3AssertNoCpuClobber(Program program) {
public Pass4AssertNoCpuClobber(Program program) {
super(program);
}
@ -44,7 +44,7 @@ public class Pass3AssertNoCpuClobber extends Pass2Base {
AsmClobber asmSegmentClobber = asmSegment.getClobber();
Collection<RegisterAllocation.Register> clobberRegisters = getClobberRegisters(asmSegmentClobber);
// Find vars assigned to in the statement
Collection<VariableRef> assignedVars = Pass3RegisterUpliftPotentialRegisterAnalysis.getAssignedVars(statement);
Collection<VariableRef> assignedVars = Pass4RegisterUpliftPotentialRegisterAnalysis.getAssignedVars(statement);
// Two assigned vars cannot use same register
if(assignedVars.size()>1) {
for (VariableRef assignedVar1 : assignedVars) {

View File

@ -8,12 +8,12 @@ import java.util.*;
/**
* Code Generation of 6502 Assembler from ICL/SSA Control Flow Graph
*/
public class Pass3CodeGeneration {
public class Pass4CodeGeneration {
private Program program;
public Pass3CodeGeneration(Program program) {
public Pass4CodeGeneration(Program program) {
this.program = program;
}

View File

@ -10,9 +10,9 @@ import java.util.List;
import java.util.Set;
/*** Find the variable equivalence classes to attempt to uplift in each scope */
public class Pass3RegisterUpliftCombinations extends Pass2Base {
public class Pass4RegisterUpliftCombinations extends Pass2Base {
public Pass3RegisterUpliftCombinations(Program program) {
public Pass4RegisterUpliftCombinations(Program program) {
super(program);
}
@ -33,12 +33,12 @@ public class Pass3RegisterUpliftCombinations extends Pass2Base {
}
RegisterCombination combination = combinationIterator.next();
// Reset register allocation to original zero page allocation
new Pass3RegistersFinalize(getProgram()).allocate(false);
new Pass4RegistersFinalize(getProgram()).allocate(false);
// Apply the uplift combination
combination.allocate(getProgram().getAllocation());
// Generate ASM
try {
new Pass3CodeGeneration(getProgram()).generate();
new Pass4CodeGeneration(getProgram()).generate();
} catch (AsmFragment.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());
//StringBuilder msg = new StringBuilder();
@ -56,7 +56,7 @@ public class Pass3RegisterUpliftCombinations extends Pass2Base {
continue;
}
// If no clobber - Find value of the resulting allocation
boolean hasClobberProblem = new Pass3AssertNoCpuClobber(getProgram()).hasClobberProblem(false);
boolean hasClobberProblem = new Pass4AssertNoCpuClobber(getProgram()).hasClobberProblem(false);
int combinationScore = getAsmScore(getProgram());
StringBuilder msg = new StringBuilder();
//msg.append("Uplift attempt [" + upliftScope.getScopeRef() + "] ");

View File

@ -5,11 +5,11 @@ import dk.camelot64.kickc.icl.*;
/***
* Find equivalence classes that could be assigned to the special ALU register.
*/
public class Pass3RegisterUpliftPotentialAluAnalysis extends Pass2Base {
public class Pass4RegisterUpliftPotentialAluAnalysis extends Pass2Base {
private LiveRangeEquivalenceClassSet liveRangeEquivalenceClassSet;
public Pass3RegisterUpliftPotentialAluAnalysis(Program program) {
public Pass4RegisterUpliftPotentialAluAnalysis(Program program) {
super(program);
}

View File

@ -13,9 +13,9 @@ import java.util.*;
* in the statement - except the variable assigned by the statement.
*
* */
public class Pass3RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
public Pass3RegisterUpliftPotentialRegisterAnalysis(Program program) {
public Pass4RegisterUpliftPotentialRegisterAnalysis(Program program) {
super(program);
}
@ -138,15 +138,15 @@ public class Pass3RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
while (combinations.hasNext()) {
RegisterCombination combination = combinations.next();
// Reset register allocation to original zero page allocation
new Pass3RegistersFinalize(getProgram()).allocate(false);
new Pass4RegistersFinalize(getProgram()).allocate(false);
// Apply the combination
combination.allocate(getProgram().getAllocation());
// Generate ASM
AsmProgram asm = new AsmProgram();
asm.startSegment(statement.getIndex(), statement.toString(getProgram()));
Pass3CodeGeneration.AsmCodegenAluState aluState = new Pass3CodeGeneration.AsmCodegenAluState();
Pass4CodeGeneration.AsmCodegenAluState aluState = new Pass4CodeGeneration.AsmCodegenAluState();
try {
(new Pass3CodeGeneration(getProgram())).generateStatementAsm(asm, block, statement, aluState, false);
(new Pass4CodeGeneration(getProgram())).generateStatementAsm(asm, block, statement, aluState, false);
} catch (AsmFragment.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());
StringBuilder msg = new StringBuilder();
@ -157,7 +157,7 @@ public class Pass3RegisterUpliftPotentialRegisterAnalysis extends Pass2Base {
continue;
}
AsmClobber clobber = asm.getClobber();
Collection<RegisterAllocation.Register> clobberRegisters = Pass3AssertNoCpuClobber.getClobberRegisters(clobber);
Collection<RegisterAllocation.Register> clobberRegisters = Pass4AssertNoCpuClobber.getClobberRegisters(clobber);
Iterator<RegisterAllocation.Register> alwaysClobberIt = alwaysClobbered.iterator();
while (alwaysClobberIt.hasNext()) {
RegisterAllocation.Register alwaysClobberRegister = alwaysClobberIt.next();

View File

@ -1,16 +1,14 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.asm.AsmFragment;
import dk.camelot64.kickc.asm.AsmProgram;
import dk.camelot64.kickc.asm.AsmSegment;
import dk.camelot64.kickc.icl.*;
import java.util.*;
/*** For eac non-uplifted equivalence class attempt to put it in a register */
public class Pass3RegisterUpliftRemains extends Pass2Base {
public class Pass4RegisterUpliftRemains extends Pass2Base {
public Pass3RegisterUpliftRemains(Program program) {
public Pass4RegisterUpliftRemains(Program program) {
super(program);
}
@ -37,12 +35,12 @@ public class Pass3RegisterUpliftRemains extends Pass2Base {
while (combinationIterator.hasNext()) {
RegisterCombination combination = combinationIterator.next();
// Reset register allocation to original zero page allocation
new Pass3RegistersFinalize(getProgram()).allocate(false);
new Pass4RegistersFinalize(getProgram()).allocate(false);
// Apply the uplift combination
combination.allocate(getProgram().getAllocation());
// Generate ASM
try {
new Pass3CodeGeneration(getProgram()).generate();
new Pass4CodeGeneration(getProgram()).generate();
} catch (AsmFragment.UnknownFragmentException e) {
unknownFragments.add(e.getFragmentSignature());
//StringBuilder msg = new StringBuilder();
@ -60,8 +58,8 @@ public class Pass3RegisterUpliftRemains extends Pass2Base {
continue;
}
// If no clobber - Find value of the resulting allocation
boolean hasClobberProblem = new Pass3AssertNoCpuClobber(getProgram()).hasClobberProblem(false);
int combinationScore = Pass3RegisterUpliftCombinations.getAsmScore(getProgram());
boolean hasClobberProblem = new Pass4AssertNoCpuClobber(getProgram()).hasClobberProblem(false);
int combinationScore = Pass4RegisterUpliftCombinations.getAsmScore(getProgram());
//StringBuilder msg = new StringBuilder();
//msg.append("Uplift remains attempt [" + equivalenceClass + "] ");
//if (hasClobberProblem) {

View File

@ -5,9 +5,9 @@ import dk.camelot64.kickc.icl.*;
import java.util.*;
/*** Find the variable equivalence classes to attempt to uplift in each scope */
public class Pass3RegisterUpliftScopeAnalysis extends Pass2Base {
public class Pass4RegisterUpliftScopeAnalysis extends Pass2Base {
public Pass3RegisterUpliftScopeAnalysis(Program program) {
public Pass4RegisterUpliftScopeAnalysis(Program program) {
super(program);
}

View File

@ -6,9 +6,9 @@ import dk.camelot64.kickc.icl.*;
* Move register allocation from equivalence classes to RegisterAllocation.
* Also rebase zero page registers.
*/
public class Pass3RegistersFinalize extends Pass2Base {
public class Pass4RegistersFinalize extends Pass2Base {
public Pass3RegistersFinalize(Program program) {
public Pass4RegistersFinalize(Program program) {
super(program);
}

View File

@ -8,9 +8,9 @@ import java.util.List;
/**
* Zero Page Register Allocation for variables based on live ranges and phi equivalence classes.
*/
public class Pass3ZeroPageAllocation extends Pass2Base {
public class Pass4ZeroPageAllocation extends Pass2Base {
public Pass3ZeroPageAllocation(Program program) {
public Pass4ZeroPageAllocation(Program program) {
super(program);
}

View File

@ -6,10 +6,10 @@ import dk.camelot64.kickc.icl.*;
* Coalesces zero page registers where their live ranges do not overlap.
* A final step done after all other register optimizations and before ASM generation.
*/
public class Pass3ZeroPageCoalesce extends Pass2Base {
public class Pass4ZeroPageCoalesce extends Pass2Base {
public Pass3ZeroPageCoalesce(Program program) {
public Pass4ZeroPageCoalesce(Program program) {
super(program);
}

View File

@ -14,11 +14,11 @@ import java.util.List;
* Optimization performed on Assembler Code (Asm Code).
* Optimizations are performed repeatedly until none of them yield any result
**/
public abstract class Pass6AsmOptimization {
public abstract class Pass5AsmOptimization {
private Program program;
public Pass6AsmOptimization(Program program) {
public Pass5AsmOptimization(Program program) {
this.program = program;
}

View File

@ -9,9 +9,9 @@ import java.util.List;
/**
* Optimize assembler code by removing jumps to labels immediately following the jump
*/
public class Pass6NextJumpElimination extends Pass6AsmOptimization {
public class Pass5NextJumpElimination extends Pass5AsmOptimization {
public Pass6NextJumpElimination(Program program) {
public Pass5NextJumpElimination(Program program) {
super(program);
}

View File

@ -11,9 +11,9 @@ import java.util.Set;
/**
* Optimize assembler code by removing all unused labels
*/
public class Pass6RedundantLabelElimination extends Pass6AsmOptimization {
public class Pass5RedundantLabelElimination extends Pass5AsmOptimization {
public Pass6RedundantLabelElimination(Program program) {
public Pass5RedundantLabelElimination(Program program) {
super(program);
}

View File

@ -9,9 +9,9 @@ import java.util.List;
/**
* Maps out register values entering all instructions. Removes unnecessary loads / clears / sets
*/
public class Pass6UnnecesaryLoadElimination extends Pass6AsmOptimization {
public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization {
public Pass6UnnecesaryLoadElimination(Program program) {
public Pass5UnnecesaryLoadElimination(Program program) {
super(program);
}

View File

@ -1,6 +1,5 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.asm.*;
import dk.camelot64.kickc.icl.Program;
@ -12,9 +11,9 @@ import java.util.Set;
/**
* Optimize assembler code by removing all unused labels
*/
public class Pass6UnusedLabelElimination extends Pass6AsmOptimization {
public class Pass5UnusedLabelElimination extends Pass5AsmOptimization {
public Pass6UnusedLabelElimination(Program program) {
public Pass5UnusedLabelElimination(Program program) {
super(program);
}

View File

@ -1201,7 +1201,7 @@ Re-allocated ZP register from zp byte:6 to zp byte:5
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp bend
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -1290,7 +1290,7 @@ Removing instruction b1_from_bbegin:
Removing instruction b1_from_b3:
Removing instruction b3_from_b1:
Removing instruction bend:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -1372,7 +1372,7 @@ b3_from_b2:
Removing instruction bbegin:
Removing instruction b3_from_b2:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1
@ -1451,7 +1451,7 @@ b2:
jmp b3
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1

View File

@ -693,7 +693,7 @@ MISSING FRAGMENTS
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -741,7 +741,7 @@ main: {
Replacing label b1_from_b1 with b1
Removing instruction b1_from_b1:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -790,7 +790,7 @@ Removing instruction bbegin:
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -832,7 +832,7 @@ main: {
}
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -4467,7 +4467,7 @@ Removing instruction jmp b3
Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -4723,7 +4723,7 @@ Removing instruction b2_from_b1:
Removing instruction b2_from_b2:
Removing instruction b3_from_b3:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -4971,7 +4971,7 @@ Removing instruction b3_from_b4:
Removing instruction breturn:
Removing instruction b1_from_prepare:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -5192,7 +5192,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b3
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -5401,7 +5401,7 @@ prepare: {
Replacing label b3_from_b3 with b3
Removing instruction b3_from_b3:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -5608,7 +5608,7 @@ prepare: {
}
Removing instruction jmp b3
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -442,7 +442,7 @@ Uplifting [] best 405 combination reg byte a [ s#2 s#4 s#1 ] reg byte x [ i#2 i#
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp bend
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -492,7 +492,7 @@ Removing instruction b1_from_bbegin:
Removing instruction b1_from_b3:
Removing instruction b3_from_b1:
Removing instruction bend:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -535,7 +535,7 @@ b3_from_b2:
Removing instruction bbegin:
Removing instruction b3_from_b2:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1
@ -575,7 +575,7 @@ b2:
jmp b3
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1

View File

@ -820,7 +820,7 @@ Removing instruction jmp b3
Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -883,7 +883,7 @@ Replacing label b1_from_b3 with b1
Replacing label b1_from_b1 with b1
Removing instruction b1_from_b3:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -947,7 +947,7 @@ Removing instruction b3:
Removing instruction breturn:
Removing instruction b1_from_nest:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -999,7 +999,7 @@ nest: {
Removing instruction jmp b1
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -2118,7 +2118,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b3
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -2273,7 +2273,7 @@ Removing instruction b2_from_b5:
Removing instruction b1_from_b3:
Removing instruction b2_from_b1:
Removing instruction b2_from_b2:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -2417,7 +2417,7 @@ Removing instruction breturn:
Removing instruction b1_from_nest2:
Removing instruction b3:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -2541,7 +2541,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b1
Removing instruction jmp b2
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -608,7 +608,7 @@ Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp b5
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -669,7 +669,7 @@ Removing instruction breturn:
Removing instruction b5:
Removing instruction b1_from_b5:
Removing instruction b1_from_b4:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -355,7 +355,7 @@ Uplift Scope [] 31.17: zp byte:2 [ i#2 i#1 ] 22: zp byte:3 [ $1 ]
Uplifting [] best 285 combination reg byte x [ i#2 i#1 ] reg byte a [ $1 ]
Removing instruction jmp b1
Removing instruction jmp bend
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -386,7 +386,7 @@ bend:
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -414,7 +414,7 @@ bend:
Removing instruction bbegin:
Removing instruction bend:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1
@ -439,7 +439,7 @@ b1:
//SEG10 @end
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] phi from @begin to @1

View File

@ -810,7 +810,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -875,7 +875,7 @@ Removing instruction inccnt_from_b1:
Removing instruction b2:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -636,7 +636,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -692,7 +692,7 @@ Removing instruction inccnt_from_b1:
Removing instruction b2:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -2129,7 +2129,7 @@ Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -2317,7 +2317,7 @@ Removing instruction b1_from_b2:
Removing instruction b1_from_lvalue:
Removing instruction breturn:
Removing instruction b1_from_b2:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -504,7 +504,7 @@ Uplifting [] best 235 combination
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -544,7 +544,7 @@ Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Removing instruction b1_from_b2:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -597,7 +597,7 @@ Removing instruction jmp b3
Removing instruction jmp b4
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -659,7 +659,7 @@ sum: {
}
Removing instruction sum_from_bbegin:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -727,7 +727,7 @@ Removing instruction sum_from_b3:
Removing instruction b4:
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call sum param-assignment [ sum::return#0 ]

View File

@ -240,7 +240,7 @@ Uplifting [main] best 24 combination
Uplifting [] best 24 combination
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -262,7 +262,7 @@ main: {
Removing instruction bbegin:
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]

View File

@ -7523,7 +7523,7 @@ Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -8046,7 +8046,7 @@ Removing instruction b8_from_b7:
Removing instruction b11_from_b10:
Removing instruction b13_from_b11:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass6RedundantLabelElimination
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 @begin
bbegin:
@ -8564,7 +8564,7 @@ Removing instruction b8_from_b6:
Removing instruction b1_from_initscreen:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass6UnusedLabelElimination
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]
@ -9034,7 +9034,7 @@ Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b1
Removing instruction jmp b1
Succesful ASM optimization Pass6NextJumpElimination
Succesful ASM optimization Pass5NextJumpElimination
ASSEMBLER
//SEG0 @begin
//SEG1 [0] call main param-assignment [ ]