1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-15 16:30:02 +00:00

Removed early const data structure.

This commit is contained in:
jespergravgaard 2019-11-03 20:41:07 +01:00
parent b6b01ab232
commit 8d494cb587
5 changed files with 5 additions and 29 deletions

View File

@ -60,8 +60,6 @@ public class Program {
/** The initial statement sequence generated by the parser. PASS 1 (STATIC) */
private StatementSequence statementSequence;
/** Constants identified during pass 1. PASS 1 (STATIC) */
private Collection<SymbolVariableRef> earlyIdentifiedConstants;
/** Variables modified inside procedures. PASS 1 (STATIC) */
private ProcedureModifiedVars procedureModifiedVars;
/** Struct values unwound to individual variables. PASS 1 (STATIC) */
@ -120,7 +118,6 @@ public class Program {
this.importPaths = null;
this.imported = null;
this.statementSequence = null;
this.earlyIdentifiedConstants = null;
this.procedureModifiedVars = null;
this.structUnwinding = null;
}
@ -438,14 +435,6 @@ public class Program {
this.registerPotentials = registerPotentials;
}
public Collection<SymbolVariableRef> getEarlyIdentifiedConstants() {
return earlyIdentifiedConstants;
}
public void setEarlyIdentifiedConstants(Collection<SymbolVariableRef> earlyIdentifiedConstants) {
this.earlyIdentifiedConstants = earlyIdentifiedConstants;
}
public void setFileName(String fileName) {
this.fileName = fileName;

View File

@ -1406,12 +1406,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
if(lValue.isDeclaredConst() && rValue instanceof ForwardVariableRef) {
throw new CompileError("Variable used before being defined " + rValue.toString(), statementSource);
}
/*
if(lValue.isDeclaredConst() && !(rValue instanceof ConstantValue)) {
/* if(lValue.isDeclaredConst() && !(rValue instanceof ConstantValue)) {
throw new InternalError("RValue is not constant!");
}
*/
*/
if(lValue.isDeclaredConst() && rValue instanceof ConstantValue) {
Scope scope = lValue.getScope();
ConstantValue constantValue = (ConstantValue) rValue;

View File

@ -35,7 +35,6 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
public boolean step() {
HashMap<SymbolRef, RValue> aliases = new HashMap<>();
List<Statement> removeStmt = new ArrayList<>();
Collection<SymbolVariableRef> earlyConstants = new ArrayList<>();
for(Variable variable : getProgram().getScope().getAllVariables(true)) {
SymbolVariableRef variableRef = variable.getRef();
if(!variable.isDeclaredConst() && !variable.isVolatile() && !variableRef.isIntermediate()) {
@ -53,15 +52,11 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
StatementAssignment assign = (StatementAssignment) assignment;
if(assign.getrValue1() == null && assign.getOperator() == null && assign.getrValue2() instanceof ConstantValue) {
getLog().append("Identified constant variable " + variable.toString(getProgram()));
earlyConstants.add(variableRef);
//variable.setKind(Variable.Kind.CONSTANT);
ConstantValue constantValue = (ConstantValue) assign.getrValue2();
convertToConst(variable, constantValue, assign, aliases);
removeStmt.add(assign);
} else if(assign.getrValue1() == null && assign.getOperator() instanceof OperatorCastPtr && assign.getrValue2() instanceof ConstantValue) {
getLog().append("Identified constant variable " + variable.toString(getProgram()));
earlyConstants.add(variableRef);
variable.setKind(Variable.Kind.CONSTANT);
ConstantValue constantValue = new ConstantCastValue(((OperatorCastPtr) assign.getOperator()).getToType(), (ConstantValue) assign.getrValue2());
convertToConst(variable, constantValue, assign, aliases);
removeStmt.add(assign);
@ -77,7 +72,6 @@ public class Pass1EarlyConstantIdentification extends Pass1Base {
}
// Replace all variable refs with constant refs
ProgramValueIterator.execute(getProgram(), new AliasReplacer(aliases));
getProgram().setEarlyIdentifiedConstants(earlyConstants);
return false;
}

View File

@ -76,10 +76,9 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
* @param source The statement source - usable for error messages
*/
private void versionAssignment(VariableRef lValueRef, ProgramValue programLValue, StatementSource source) {
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Variable assignedVar = getScope().getVariable(lValueRef);
if(assignedVar.isKindPhiMaster()) {
if(assignedVar.isDeclaredConst() || earlyIdentifiedConstants.contains(assignedVar.getRef()))
if(assignedVar.isDeclaredConst())
throw new InternalError("Error! Constants can not be versioned ", source);
Variable version = assignedVar.createVersion();
programLValue.set(version.getRef());
@ -164,14 +163,13 @@ public class Pass1GenerateSingleStaticAssignmentForm extends Pass1Base {
Value rValue,
Map<Variable, Variable> blockVersions,
Map<Variable, Variable> blockNewPhis) {
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Variable version = null;
if(rValue instanceof VariableRef) {
Variable rValueVar = getScope().getVariable((VariableRef) rValue);
if(rValueVar.isKindPhiMaster()) {
// rValue needs versioning - look for version in statements
Variable rSymbol = rValueVar;
if(rSymbol.isDeclaredConst() || earlyIdentifiedConstants.contains(rSymbol.getRef())) {
if(rSymbol.isDeclaredConst()) {
// A constant - find the single created version
Scope scope = rSymbol.getScope();
Collection<Variable> versions = scope.getVersions(rSymbol);

View File

@ -7,10 +7,8 @@ import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementLValue;
import dk.camelot64.kickc.model.symbols.Variable;
import dk.camelot64.kickc.model.values.LValue;
import dk.camelot64.kickc.model.values.SymbolVariableRef;
import dk.camelot64.kickc.model.values.VariableRef;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@ -25,7 +23,6 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization {
@Override
public boolean step() {
Collection<SymbolVariableRef> earlyIdentifiedConstants = getProgram().getEarlyIdentifiedConstants();
Set<VariableRef> assigned = new HashSet<>();
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
@ -34,7 +31,7 @@ public class PassNAssertConstantModification extends Pass2SsaOptimization {
if(lValue instanceof VariableRef) {
VariableRef variableRef = (VariableRef) lValue;
Variable variable = getScope().getVariable(variableRef);
if(variable.isKindConstant() || earlyIdentifiedConstants.contains(variableRef)) {
if(variable.isKindConstant() ) {
if(assigned.contains(variableRef)) {
throw new CompileError("Error! Constants can not be modified", statement.getSource());
} else {