1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-08-10 11:25:09 +00:00

Caching alive combinations for better performance.

This commit is contained in:
Jesper Gravgaard
2018-03-05 10:45:07 +01:00
parent 133f8603c7
commit 7876b98573

View File

@@ -22,7 +22,7 @@ public class LiveRangeVariablesEffective {
private Map<ProcedureRef, CallPaths> procedureCallPaths;
/** Variables (normally) alive at each statement by index. */
private Map<Integer, Collection<VariableRef>> statementsLiveVariables;
private Map<Integer, Collection<VariableRef>> statementLiveVariables;
/**
* Information about which procedures reference which variables.
@@ -33,14 +33,17 @@ public class LiveRangeVariablesEffective {
this.program = program;
this.procedureCallPaths = procedureCallPaths;
this.referenceInfo = referenceInfo;
this.statementsLiveVariables = new LinkedHashMap<>();
this.statementLiveVariables = new LinkedHashMap<>();
for(ControlFlowBlock block : program.getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
statementsLiveVariables.put(statement.getIndex(), liveRangeVariables.getAlive(statement));
statementLiveVariables.put(statement.getIndex(), liveRangeVariables.getAlive(statement));
}
}
}
/** Cached alive effective by statement index. */
Map<Integer, Collection<VariableRef>> statementAliveEffective = new LinkedHashMap<>();
/**
* Get all variables potentially alive at a statement.
* If the statement is inside a method this also includes all variables alive at the exit of any call.
@@ -50,15 +53,22 @@ public class LiveRangeVariablesEffective {
* @return All variables potentially alive at the statement
*/
public Collection<VariableRef> getAliveEffective(Statement statement) {
Set<VariableRef> effectiveAliveTotal = new LinkedHashSet<>();
Collection<VariableRef> effectiveAliveTotal = statementAliveEffective.get(statement.getIndex());
if(effectiveAliveTotal==null) {
effectiveAliveTotal = new LinkedHashSet<>();
AliveCombinations aliveCombinations = getAliveCombinations(statement);
for(CallPath callPath : aliveCombinations.getCallPaths().getCallPaths()) {
Collection<VariableRef> alive = aliveCombinations.getEffectiveAliveAtStmt(callPath);
effectiveAliveTotal.addAll(alive);
}
statementAliveEffective.put(statement.getIndex(), effectiveAliveTotal);
}
return effectiveAliveTotal;
}
/** Cached alive combinations. */
Map<Integer, AliveCombinations> statementAliveCombinations = new LinkedHashMap<>();
/**
* Get all combinations of variables alive at a statement.
* If the statement is inside a method the different combinations in the result arises from different calls of the method
@@ -71,7 +81,9 @@ public class LiveRangeVariablesEffective {
* @return All combinations of variables alive at the statement
*/
public AliveCombinations getAliveCombinations(Statement statement) {
Collection<VariableRef> aliveAtStmt = statementsLiveVariables.get(statement.getIndex());
AliveCombinations stmtCombinations = this.statementAliveCombinations.get(statement.getIndex());
if(stmtCombinations==null) {
Collection<VariableRef> aliveAtStmt = statementLiveVariables.get(statement.getIndex());
CallPaths callPaths;
Collection<VariableRef> referencedInProcedure;
ControlFlowBlock block = program.getStatementInfos().getBlock(statement);
@@ -108,8 +120,10 @@ public class LiveRangeVariablesEffective {
}
}
}
return new AliveCombinations(callPaths, referencedInProcedure, aliveAtStmt, callAliases);
stmtCombinations = new AliveCombinations(callPaths, referencedInProcedure, aliveAtStmt, callAliases);
statementAliveCombinations.put(statement.getIndex(), stmtCombinations);
}
return stmtCombinations;
}
/**