1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-22 03:29:59 +00:00

Eliminated old getAssignment() methods.

This commit is contained in:
jespergravgaard 2020-02-12 00:47:01 +01:00
parent 45019c1116
commit 92acd45493
2 changed files with 6 additions and 57 deletions

View File

@ -84,27 +84,6 @@ public class ControlFlowGraph implements Serializable {
return null;
}
/**
* Get all assignments of the passed variable.
*
* @param variable The variable to find the assignment for
* @return All assignments.
*/
public List<StatementLValue> getAssignments(SymbolVariableRef variable) {
ArrayList<StatementLValue> assignments = new ArrayList<>();
for(ControlFlowBlock block : getAllBlocks()) {
for(Statement statement : block.getStatements()) {
if(statement instanceof StatementLValue) {
StatementLValue assignment = (StatementLValue) statement;
if(variable.equals(assignment.getlValue())) {
assignments.add(assignment);
}
}
}
}
return assignments;
}
/** Any assignment of a value to a SymbolVariable.
* Potential assignments include StatementLValue, StatementPhi and Variable.initValue
* */
@ -174,33 +153,6 @@ public class ControlFlowGraph implements Serializable {
return varAssignments;
}
/**
* Get the block containing the assignment of the passed variable. Assumes that only a single assignment exists.
*
* @param variable The variable to find the assignment for
* @return The block containing the assignment. null if the variable is not assigned.
*/
public ControlFlowBlock getAssignmentBlock(VariableRef variable) {
for(ControlFlowBlock block : getAllBlocks()) {
for(Statement statement : block.getStatements()) {
if(statement instanceof StatementLValue) {
StatementLValue assignment = (StatementLValue) statement;
if(variable.equals(assignment.getlValue())) {
return block;
}
} else if(statement instanceof StatementPhiBlock) {
for(StatementPhiBlock.PhiVariable phiVariable : ((StatementPhiBlock) statement).getPhiVariables()) {
if(phiVariable.getVariable().equals(variable)) {
return block;
}
}
}
}
}
return null;
}
public ControlFlowBlock getDefaultSuccessor(ControlFlowBlock block) {
if(block.getDefaultSuccessor() != null) {
return getBlock(block.getDefaultSuccessor());

View File

@ -1,9 +1,6 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.CompileError;
import dk.camelot64.kickc.model.ConstantNotLiteral;
import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.operators.OperatorBinary;
import dk.camelot64.kickc.model.operators.OperatorUnary;
@ -170,13 +167,13 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
if(variable.isVolatile() || !variable.isKindLoadStore())
// Do not examine volatiles, non-constants or versioned variables
continue;
List<StatementLValue> assignments = getGraph().getAssignments(variable.getRef());
if(assignments.size() == 1) {
StatementLValue statementLValue = assignments.get(0);
if(!(statementLValue instanceof StatementAssignment))
final List<ControlFlowGraph.VarAssignment> varAssignments = ControlFlowGraph.getVarAssignments(variable.getRef(), getGraph(), getScope());
if(varAssignments.size() == 1) {
final ControlFlowGraph.VarAssignment varAssignment = varAssignments.get(0);
if(!ControlFlowGraph.VarAssignment.Type.STATEMENT_LVALUE.equals(varAssignment.type) || !(varAssignment.statementLValue instanceof StatementAssignment))
// Only look at assignments
continue;
StatementAssignment assignment = (StatementAssignment) statementLValue;
StatementAssignment assignment = (StatementAssignment) varAssignment.statementLValue;
LValue lValue = assignment.getlValue();
if(lValue instanceof VariableRef) {
VariableRef varRef = (VariableRef) lValue;