From 1b999c8c1db673211ec0f9fe505d6e19787272ef Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sat, 11 Nov 2017 18:45:33 +0100 Subject: [PATCH] Using cached symbol table for faster uplift --- .../kickc/fragment/AsmFragmentSignature.java | 4 ++-- .../kickc/model/LiveRangeEquivalenceClassSet.java | 2 +- .../java/dk/camelot64/kickc/model/PhiTransitions.java | 11 +++++------ .../dk/camelot64/kickc/model/RegisterCombination.java | 4 ++-- .../camelot64/kickc/passes/Pass4CodeGeneration.java | 2 +- .../kickc/passes/Pass4RegisterUpliftCombinations.java | 2 +- .../Pass4RegisterUpliftPotentialRegisterAnalysis.java | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentSignature.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentSignature.java index ccbd209bf..2227895ff 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentSignature.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentSignature.java @@ -63,7 +63,7 @@ public class AsmFragmentSignature { throw new AsmFragment.AluNotApplicableException("Error! ALU register only allowed as rValue2. " + assignment); } VariableRef assignmentRValue2 = (VariableRef) assignment.getrValue2(); - Variable assignmentRValue2Var = program.getScope().getVariable(assignmentRValue2); + Variable assignmentRValue2Var = program.getSymbolInfos().getVariable(assignmentRValue2); Registers.Register rVal2Register = assignmentRValue2Var.getAllocation(); if (!rVal2Register.getType().equals(Registers.RegisterType.REG_ALU_BYTE)) { @@ -256,7 +256,7 @@ public class AsmFragmentSignature { } if (value instanceof VariableRef) { - value = program.getScope().getVariable((VariableRef) value); + value = program.getSymbolInfos().getVariable((VariableRef) value); } if (value instanceof ConstantRef) { value = program.getScope().getConstant((ConstantRef) value); diff --git a/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClassSet.java b/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClassSet.java index f60bd6493..f2edbae16 100644 --- a/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClassSet.java +++ b/src/main/java/dk/camelot64/kickc/model/LiveRangeEquivalenceClassSet.java @@ -105,7 +105,7 @@ public class LiveRangeEquivalenceClassSet { for (LiveRangeEquivalenceClass equivalenceClass : getEquivalenceClasses()) { Registers.Register register = equivalenceClass.getRegister(); for (VariableRef variable : equivalenceClass.getVariables()) { - Variable var = program.getScope().getVariable(variable); + Variable var = program.getSymbolInfos().getVariable(variable); var.setAllocation(register); } } diff --git a/src/main/java/dk/camelot64/kickc/model/PhiTransitions.java b/src/main/java/dk/camelot64/kickc/model/PhiTransitions.java index 635ff1ea4..b6c447fe8 100644 --- a/src/main/java/dk/camelot64/kickc/model/PhiTransitions.java +++ b/src/main/java/dk/camelot64/kickc/model/PhiTransitions.java @@ -186,10 +186,9 @@ public class PhiTransitions { for (int i = 0; i < assignments.size(); i++) { PhiTransition.PhiAssignment assignment = assignments.get(i); PhiTransition.PhiAssignment otherAssignment = otherAssignments.get(i); - ProgramScope scope = program.getScope(); - if (assignment.getVariable() instanceof VariableRef && otherAssignment.getVariable() instanceof VariableRef) { - Variable var = scope.getVariable((VariableRef) assignment.getVariable()); - Variable otherVar = scope.getVariable((VariableRef) otherAssignment.getVariable()); + if (assignment.getVariable() != null && otherAssignment.getVariable() != null) { + Variable var = program.getSymbolInfos().getVariable(assignment.getVariable()); + Variable otherVar = program.getSymbolInfos().getVariable(otherAssignment.getVariable()); if (!var.getAllocation().equals(otherVar.getAllocation())) { return false; } @@ -197,8 +196,8 @@ public class PhiTransitions { return false; } if (assignment.getrValue() instanceof VariableRef && otherAssignment.getrValue() instanceof VariableRef) { - Variable var = scope.getVariable((VariableRef) assignment.getrValue()); - Variable otherVar = scope.getVariable((VariableRef) otherAssignment.getrValue()); + Variable var = program.getSymbolInfos().getVariable((VariableRef) assignment.getrValue()); + Variable otherVar = program.getSymbolInfos().getVariable((VariableRef) otherAssignment.getrValue()); if (!var.getAllocation().equals(otherVar.getAllocation())) { return false; } diff --git a/src/main/java/dk/camelot64/kickc/model/RegisterCombination.java b/src/main/java/dk/camelot64/kickc/model/RegisterCombination.java index 4eb762def..543b976e1 100644 --- a/src/main/java/dk/camelot64/kickc/model/RegisterCombination.java +++ b/src/main/java/dk/camelot64/kickc/model/RegisterCombination.java @@ -25,11 +25,11 @@ public class RegisterCombination { * Allocate the registers of the combination into the programs register allocation * (does not update the allocation in the equivalence classes). */ - public void allocate(ProgramScope scope) { + public void allocate(Program program) { for (LiveRangeEquivalenceClass equivalenceClass : allocation.keySet()) { Registers.Register register = allocation.get(equivalenceClass); for (VariableRef variable : equivalenceClass.getVariables()) { - Variable var = scope.getVariable(variable); + Variable var = program.getSymbolInfos().getVariable(variable); var.setAllocation(register); } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java index cbd61992f..7e4a48b84 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4CodeGeneration.java @@ -386,7 +386,7 @@ public class Pass4CodeGeneration { private Registers.Register getRegister(RValue rValue) { if (rValue instanceof VariableRef) { VariableRef rValueRef = (VariableRef) rValue; - return program.getScope().getVariable(rValueRef).getAllocation(); + return program.getSymbolInfos().getVariable(rValueRef).getAllocation(); } else { return null; } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftCombinations.java b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftCombinations.java index d2477822b..e0536fd5e 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftCombinations.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftCombinations.java @@ -112,7 +112,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base { // Reset register allocation to original zero page allocation new Pass4RegistersFinalize(program).allocate(false); // Apply the uplift combination - combination.allocate(program.getScope()); + combination.allocate(program); // Check the register allocation for whether a is register being allocated to two variables with overlapping live ranges if (isAllocationOverlapping(program)) { if (program.getLog().isVerboseUplift()) { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialRegisterAnalysis.java b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialRegisterAnalysis.java index f68e3122c..cee1cc20a 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialRegisterAnalysis.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass4RegisterUpliftPotentialRegisterAnalysis.java @@ -129,7 +129,7 @@ public class Pass4RegisterUpliftPotentialRegisterAnalysis extends Pass2Base { // Reset register allocation to original zero page allocation new Pass4RegistersFinalize(getProgram()).allocate(false); // Apply the combination - combination.allocate(getProgram().getScope()); + combination.allocate(getProgram()); // Generate ASM AsmProgram asm = new AsmProgram(); asm.startSegment(statement.getIndex(), statement.toString(getProgram(), true));