mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-27 04:49:27 +00:00
Implemented cast constant identification. 282/359
This commit is contained in:
parent
6e0b665423
commit
6cfa5c750c
@ -249,6 +249,7 @@ public class Compiler {
|
||||
optimizations.add(new Pass2ConditionalAndOrRewriting(program));
|
||||
optimizations.add(new Pass2ConstantRValueConsolidation(program));
|
||||
optimizations.add(new Pass2ConstantIdentification(program));
|
||||
optimizations.add(new Pass2ConstantValues(program));
|
||||
optimizations.add(new PassNStatementIndices(program));
|
||||
optimizations.add(new PassNVariableReferenceInfos(program));
|
||||
//optimizations.add(new Pass2ConstantAdditionElimination(program));
|
||||
@ -308,6 +309,7 @@ public class Compiler {
|
||||
constantOptimizations.add(new Pass2IdenticalPhiElimination(program));
|
||||
constantOptimizations.add(new Pass2ConstantRValueConsolidation(program));
|
||||
constantOptimizations.add(new Pass2ConstantIdentification(program));
|
||||
constantOptimizations.add(new Pass2ConstantValues(program));
|
||||
constantOptimizations.add(new Pass2ConstantAdditionElimination(program));
|
||||
constantOptimizations.add(new Pass2ConstantSimplification(program));
|
||||
constantOptimizations.add(new Pass2ConstantCastSimplification(program));
|
||||
|
@ -0,0 +1,36 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Compiler Pass identifying constants values
|
||||
*/
|
||||
public class Pass2ConstantValues extends Pass2SsaOptimization {
|
||||
|
||||
public Pass2ConstantValues(Program program) {
|
||||
super(program);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean step() {
|
||||
AtomicBoolean modified = new AtomicBoolean(false);
|
||||
|
||||
ProgramValueIterator.execute(getProgram().getGraph(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||
Value value = programValue.get();
|
||||
if((value instanceof RValue) && !(value instanceof ConstantValue)) {
|
||||
ConstantValue constant = Pass2ConstantIdentification.getConstant((RValue) value);
|
||||
if(constant!=null) {
|
||||
programValue.set(constant);
|
||||
getLog().append("Constant value identified " + value+ " in "+ (currentStmt==null?"":currentStmt.toString(getProgram(), false)));
|
||||
modified.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
return modified.get();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user