mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-12 11:31:11 +00:00
Added cached symbol table for faster uplift
This commit is contained in:
parent
af281612d2
commit
796edcc05b
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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. */
|
||||
|
22
src/main/java/dk/camelot64/kickc/model/SymbolInfos.java
Normal file
22
src/main/java/dk/camelot64/kickc/model/SymbolInfos.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user