mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-02 20:29:38 +00:00
Made statement loops simpler.
This commit is contained in:
parent
55bec51f09
commit
9dc17caab2
@ -155,7 +155,6 @@ public interface Graph {
|
|||||||
|
|
||||||
void addStatementBeforeCall(Statement newStatement);
|
void addStatementBeforeCall(Statement newStatement);
|
||||||
|
|
||||||
|
|
||||||
String toString(Program program, Graph graph);
|
String toString(Program program, Graph graph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package dk.camelot64.kickc.passes;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
|
||||||
import dk.camelot64.kickc.model.Graph;
|
|
||||||
import dk.camelot64.kickc.model.Program;
|
import dk.camelot64.kickc.model.Program;
|
||||||
import dk.camelot64.kickc.model.statements.Statement;
|
import dk.camelot64.kickc.model.statements.Statement;
|
||||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||||
@ -13,8 +11,11 @@ import dk.camelot64.kickc.model.values.CastValue;
|
|||||||
import dk.camelot64.kickc.model.values.RValue;
|
import dk.camelot64.kickc.model.values.RValue;
|
||||||
import dk.camelot64.kickc.model.values.SymbolRef;
|
import dk.camelot64.kickc.model.values.SymbolRef;
|
||||||
import dk.camelot64.kickc.model.values.VariableRef;
|
import dk.camelot64.kickc.model.values.VariableRef;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiler Pass inlining cast assignments that has no effect (byte to/from signed byte, word to/from signed word)
|
* Compiler Pass inlining cast assignments that has no effect (byte to/from signed byte, word to/from signed word)
|
||||||
@ -45,11 +46,9 @@ public class Pass2NopCastInlining extends Pass2SsaOptimization {
|
|||||||
ListIterator<Statement> stmtIt = block.getStatements().listIterator();
|
ListIterator<Statement> stmtIt = block.getStatements().listIterator();
|
||||||
while(stmtIt.hasNext()) {
|
while(stmtIt.hasNext()) {
|
||||||
Statement stmt = stmtIt.next();
|
Statement stmt = stmtIt.next();
|
||||||
if(stmt instanceof StatementAssignment) {
|
if(stmt instanceof StatementAssignment assignment) {
|
||||||
StatementAssignment assignment = (StatementAssignment) stmt;
|
|
||||||
// TODO: Handle constant values?
|
// TODO: Handle constant values?
|
||||||
if(assignment.getOperator() == null && assignment.getrValue2() instanceof CastValue) {
|
if(assignment.getOperator() == null && assignment.getrValue2() instanceof CastValue castValue) {
|
||||||
CastValue castValue = (CastValue) assignment.getrValue2();
|
|
||||||
SymbolType subValType = SymbolTypeInference.inferType(getProgramScope(), castValue.getValue());
|
SymbolType subValType = SymbolTypeInference.inferType(getProgramScope(), castValue.getValue());
|
||||||
final SymbolType castToType = castValue.getToType();
|
final SymbolType castToType = castValue.getToType();
|
||||||
boolean isNopCast = isNopCast(castToType, subValType);
|
boolean isNopCast = isNopCast(castToType, subValType);
|
||||||
@ -59,10 +58,8 @@ public class Pass2NopCastInlining extends Pass2SsaOptimization {
|
|||||||
if(assignmentVar.isKindLoadStore())
|
if(assignmentVar.isKindLoadStore())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
boolean isIntermediateVar = false;
|
boolean isIntermediateVar = castValue.getValue() instanceof VariableRef
|
||||||
if(castValue.getValue() instanceof VariableRef && ((VariableRef) castValue.getValue()).isIntermediate()) {
|
&& ((VariableRef) castValue.getValue()).isIntermediate();
|
||||||
isIntermediateVar = true;
|
|
||||||
}
|
|
||||||
if(isIntermediateVar) {
|
if(isIntermediateVar) {
|
||||||
if(mode == null || mode == Mode.VARS) {
|
if(mode == null || mode == Mode.VARS) {
|
||||||
mode = Mode.VARS;
|
mode = Mode.VARS;
|
||||||
@ -91,8 +88,7 @@ public class Pass2NopCastInlining extends Pass2SsaOptimization {
|
|||||||
while(castVal instanceof CastValue) {
|
while(castVal instanceof CastValue) {
|
||||||
castVal = ((CastValue) castVal).getValue();
|
castVal = ((CastValue) castVal).getValue();
|
||||||
}
|
}
|
||||||
if(castVal instanceof VariableRef) {
|
if(castVal instanceof VariableRef castVarRef) {
|
||||||
VariableRef castVarRef = (VariableRef) castVal;
|
|
||||||
VariableRef lValueRef = (VariableRef) assignment.getlValue();
|
VariableRef lValueRef = (VariableRef) assignment.getlValue();
|
||||||
if(castVarRef.getScopeNames().equals(lValueRef.getScopeNames())) {
|
if(castVarRef.getScopeNames().equals(lValueRef.getScopeNames())) {
|
||||||
// Same scope - optimize away
|
// Same scope - optimize away
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package dk.camelot64.kickc.passes;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.model.CompileError;
|
import dk.camelot64.kickc.model.CompileError;
|
||||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
|
||||||
import dk.camelot64.kickc.model.Graph;
|
|
||||||
import dk.camelot64.kickc.model.Program;
|
import dk.camelot64.kickc.model.Program;
|
||||||
import dk.camelot64.kickc.model.statements.Statement;
|
|
||||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||||
import dk.camelot64.kickc.model.symbols.Variable;
|
import dk.camelot64.kickc.model.symbols.Variable;
|
||||||
import dk.camelot64.kickc.model.types.SymbolType;
|
import dk.camelot64.kickc.model.types.SymbolType;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
|
import dk.camelot64.kickc.model.types.SymbolTypeConversion;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
import dk.camelot64.kickc.model.types.SymbolTypeInference;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
||||||
import dk.camelot64.kickc.model.values.*;
|
import dk.camelot64.kickc.model.values.AssignmentRValue;
|
||||||
|
import dk.camelot64.kickc.model.values.ConstantInteger;
|
||||||
|
import dk.camelot64.kickc.model.values.ConstantValue;
|
||||||
|
import dk.camelot64.kickc.model.values.LValue;
|
||||||
|
import dk.camelot64.kickc.model.values.RValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that types match in all assignments and calculations
|
* Asserts that types match in all assignments and calculations
|
||||||
|
Loading…
Reference in New Issue
Block a user