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

Added cached symbol table for faster uplift

This commit is contained in:
jespergravgaard 2017-11-11 18:07:44 +01:00
parent af281612d2
commit 796edcc05b
7 changed files with 72 additions and 4 deletions

View File

@ -212,6 +212,7 @@ public class Compiler {
new Pass3CallGraphAnalysis(program).findCallGraph();
new Pass3StatementInfos(program).generateStatementInfos();
new Pass3VariableReferenceInfos(program).generateVariableReferenceInfos();
new Pass3SymbolInfos(program).generateSymbolInfos();
new Pass3LiveRangesAnalysis(program).findLiveRanges();
program.getLog().append("CONTROL FLOW GRAPH - BEFORE EFFECTIVE LIVE RANGES");
program.getLog().append(program.getGraph().toString(program));

View File

@ -43,6 +43,7 @@ public class Program {
private RegisterPotentials registerPotentials;
/** Separation of live range equivalence classes into scopes - used for register uplift */
private RegisterUpliftProgram registerUpliftProgram;
private SymbolInfos symbolInfos;
@JsonCreator
public Program(
@ -131,6 +132,14 @@ public class Program {
this.statementInfos = statementInfos;
}
public SymbolInfos getSymbolInfos() {
return symbolInfos;
}
public void setSymbolInfos(SymbolInfos symbolInfos) {
this.symbolInfos = symbolInfos;
}
public void setLiveRangeVariables(LiveRangeVariables liveRangeVariables) {
this.liveRangeVariables = liveRangeVariables;
}

View File

@ -2,7 +2,7 @@ package dk.camelot64.kickc.model;
import java.util.Map;
/** Cached information about statements is a part of (which block they bloing to, statement from idx, ...) */
/** Cached information about statements (which block they belong to, statement from idx, ...) */
public class StatementInfos {
/** The control flow graph. */

View File

@ -0,0 +1,22 @@
package dk.camelot64.kickc.model;
import java.util.Map;
/** Cached information about symbols. Contains a symbol table cache for fast access. */
public class SymbolInfos {
private Map<SymbolRef, Symbol> symbols;
public SymbolInfos(Map<SymbolRef, Symbol> symbols) {
this.symbols = symbols;
}
public Symbol getSymbol(SymbolRef ref) {
return symbols.get(ref);
}
public Variable getVariable(VariableRef ref) {
return (Variable) getSymbol(ref);
}
}

View File

@ -6,7 +6,7 @@ import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Map;
/** */
/** Cached information about which variables are defined/referenced/used in statements / blocks. */
public class VariableReferenceInfos {
/** Variables referenced in each block. */
@ -39,7 +39,6 @@ public class VariableReferenceInfos {
*/
public Collection<VariableRef> getReferenced(LabelRef labelRef) {
return blockReferenced.get(labelRef);
}
/**

View File

@ -0,0 +1,37 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.*;
import java.util.LinkedHashMap;
/** Create the symbol table cache */
public class Pass3SymbolInfos extends Pass2Base {
public Pass3SymbolInfos(Program program) {
super(program);
}
/**
* Create map from statement index to block
*/
public void generateSymbolInfos() {
LinkedHashMap<SymbolRef, Symbol> symbolCache = new LinkedHashMap<>();
ProgramScope scope = getProgram().getScope();
generateCache(symbolCache, scope);
SymbolInfos symbolInfos = new SymbolInfos(symbolCache);
getProgram().setSymbolInfos(symbolInfos);
}
private void generateCache(LinkedHashMap<SymbolRef, Symbol> symbolCache, Scope scope) {
for (Symbol symbol : scope.getAllSymbols()) {
symbolCache.put(symbol.getRef(), symbol);
if(symbol instanceof Scope) {
generateCache(symbolCache, (Scope) symbol);
}
}
}
}

View File

@ -223,7 +223,7 @@ public class Pass4RegisterUpliftCombinations extends Pass2Base {
Collection<VariableRef> alive = aliveCombinations.getEffectiveAliveAtStmt(callPath);
Pass2AliasElimination.Aliases callPathAliases = aliveCombinations.getEffectiveAliasesAtStmt(callPath);
for (VariableRef varRef : alive) {
Variable var = programScope.getVariable(varRef);
Variable var = program.getSymbolInfos().getVariable(varRef);
Registers.Register allocation = var.getAllocation();
LiveRangeEquivalenceClass allocationClass = usedRegisters.get(allocation);
if (allocationClass != null && !allocationClass.contains(varRef)) {