mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-09 04:25:12 +00:00
Eliminated old getAssignment() methods.
This commit is contained in:
@@ -84,27 +84,6 @@ public class ControlFlowGraph implements Serializable {
|
|||||||
return null;
|
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.
|
/** Any assignment of a value to a SymbolVariable.
|
||||||
* Potential assignments include StatementLValue, StatementPhi and Variable.initValue
|
* Potential assignments include StatementLValue, StatementPhi and Variable.initValue
|
||||||
* */
|
* */
|
||||||
@@ -174,33 +153,6 @@ public class ControlFlowGraph implements Serializable {
|
|||||||
return varAssignments;
|
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) {
|
public ControlFlowBlock getDefaultSuccessor(ControlFlowBlock block) {
|
||||||
if(block.getDefaultSuccessor() != null) {
|
if(block.getDefaultSuccessor() != null) {
|
||||||
return getBlock(block.getDefaultSuccessor());
|
return getBlock(block.getDefaultSuccessor());
|
||||||
|
@@ -1,9 +1,6 @@
|
|||||||
package dk.camelot64.kickc.passes;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.model.CompileError;
|
import dk.camelot64.kickc.model.*;
|
||||||
import dk.camelot64.kickc.model.ConstantNotLiteral;
|
|
||||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
|
||||||
import dk.camelot64.kickc.model.Program;
|
|
||||||
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
|
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
|
||||||
import dk.camelot64.kickc.model.operators.OperatorBinary;
|
import dk.camelot64.kickc.model.operators.OperatorBinary;
|
||||||
import dk.camelot64.kickc.model.operators.OperatorUnary;
|
import dk.camelot64.kickc.model.operators.OperatorUnary;
|
||||||
@@ -170,13 +167,13 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
|
|||||||
if(variable.isVolatile() || !variable.isKindLoadStore())
|
if(variable.isVolatile() || !variable.isKindLoadStore())
|
||||||
// Do not examine volatiles, non-constants or versioned variables
|
// Do not examine volatiles, non-constants or versioned variables
|
||||||
continue;
|
continue;
|
||||||
List<StatementLValue> assignments = getGraph().getAssignments(variable.getRef());
|
final List<ControlFlowGraph.VarAssignment> varAssignments = ControlFlowGraph.getVarAssignments(variable.getRef(), getGraph(), getScope());
|
||||||
if(assignments.size() == 1) {
|
if(varAssignments.size() == 1) {
|
||||||
StatementLValue statementLValue = assignments.get(0);
|
final ControlFlowGraph.VarAssignment varAssignment = varAssignments.get(0);
|
||||||
if(!(statementLValue instanceof StatementAssignment))
|
if(!ControlFlowGraph.VarAssignment.Type.STATEMENT_LVALUE.equals(varAssignment.type) || !(varAssignment.statementLValue instanceof StatementAssignment))
|
||||||
// Only look at assignments
|
// Only look at assignments
|
||||||
continue;
|
continue;
|
||||||
StatementAssignment assignment = (StatementAssignment) statementLValue;
|
StatementAssignment assignment = (StatementAssignment) varAssignment.statementLValue;
|
||||||
LValue lValue = assignment.getlValue();
|
LValue lValue = assignment.getlValue();
|
||||||
if(lValue instanceof VariableRef) {
|
if(lValue instanceof VariableRef) {
|
||||||
VariableRef varRef = (VariableRef) lValue;
|
VariableRef varRef = (VariableRef) lValue;
|
||||||
|
Reference in New Issue
Block a user