use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(ResolveCallsiteObjectExpression aValue) {
print("bytecoder.resolveStaticCallSiteObject(");
print(JSWriterUtils.toClassName(aValue.getOwningClass().getThisInfo()));
print(",'");
print(aValue.getCallsiteId());
println("', function() {");
Program theProgram = aValue.getProgram();
RegionNode theBootstrapCode = aValue.getBootstrapMethod();
JSSSAWriter theNested = withDeeperIndent();
for (Variable theVariable : theProgram.globalVariables()) {
theNested.print("var ");
theNested.print(theVariable.getName());
theNested.println(" = null;");
}
theNested.writeExpressions(theBootstrapCode.getExpressions());
print("})");
}
use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.
the class OpenCLWriter method print.
private void print(Relooper.MultipleBlock aMultiple) {
OpenCLWriter theWriter = this;
if (aMultiple.isLabelRequired()) {
print("$");
print(aMultiple.label().name());
print(" : ");
theWriter = theWriter.withDeeperIndent();
}
println("switch ($__label__) {");
for (Relooper.Block theHandler : aMultiple.handlers()) {
for (RegionNode theEntry : theHandler.entries()) {
theWriter.print("case ");
theWriter.print(theEntry.getStartAddress().getAddress());
theWriter.println(" : ");
}
OpenCLWriter theHandlerWriter = theWriter.withDeeperIndent();
theHandlerWriter.print(theHandler);
}
println("}");
if (aMultiple.next() != null) {
print("$");
print(aMultiple.label().name());
println("_next:");
print(aMultiple.next());
}
}
use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.
the class InlineFinalNodesOptimizer method inline.
private void inline(Map<BytecodeOpcodeAddress, RegionNode> aFinalNodes, ExpressionList aList) {
for (Expression theExpression : aList.toList()) {
if (theExpression instanceof ExpressionListContainer) {
ExpressionListContainer theContainer = (ExpressionListContainer) theExpression;
for (ExpressionList theList : theContainer.getExpressionLists()) {
inline(aFinalNodes, theList);
}
}
if (theExpression instanceof GotoExpression) {
GotoExpression theGoto = (GotoExpression) theExpression;
RegionNode thePotentialFinal = aFinalNodes.get(theGoto.getJumpTarget());
if (thePotentialFinal != null) {
aList.replace(theExpression, thePotentialFinal.getExpressions());
}
}
}
}
use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.
the class InlineGotoOptimizer method performNodeInlining.
private boolean performNodeInlining(ControlFlowGraph aGraph, RegionNode aNode, ExpressionList aList, List<BytecodeOpcodeAddress> aJumpTargets) {
for (Expression theExpression : aList.toList()) {
if (theExpression instanceof ExpressionListContainer) {
ExpressionListContainer theContainer = (ExpressionListContainer) theExpression;
for (ExpressionList theList : theContainer.getExpressionLists()) {
if (performNodeInlining(aGraph, aNode, theList, aJumpTargets)) {
return true;
}
}
}
if (theExpression instanceof GotoExpression) {
GotoExpression theGOTO = (GotoExpression) theExpression;
RegionNode theTargetNode = aGraph.nodeStartingAt(theGOTO.getJumpTarget());
if (theTargetNode.isStrictlyDominatedBy(aNode)) {
BytecodeOpcodeAddress theJumpTarget = theGOTO.getJumpTarget();
int theCount = 0;
for (BytecodeOpcodeAddress theEntry : aJumpTargets) {
if (theEntry.equals(theJumpTarget)) {
theCount++;
}
}
if (theCount == 1) {
// Node can be inlined
aGraph.delete(theTargetNode);
aList.replace(theGOTO, theTargetNode.getExpressions());
aNode.inheritSuccessorsOf(theTargetNode);
for (RegionNode theNode : aGraph.getKnownNodes()) {
recomputeGotos(theNode.getExpressions(), theTargetNode.getStartAddress(), aNode.getStartAddress());
}
return true;
}
}
}
}
return false;
}
use of de.mirkosertic.bytecoder.ssa.RegionNode in project Bytecoder by mirkosertic.
the class RedundantAssignmentOptimizerTest method testBinaryOptimization.
@Test
public void testBinaryOptimization() {
Program theProgram = new Program();
ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
RegionNode theStart = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
ExpressionList theExpressions = theStart.getExpressions();
Variable theVariable1 = new Variable(TypeRef.Native.INT, "var1");
Variable theVariable2 = new Variable(TypeRef.Native.INT, "var2");
IntegerValue theInt1 = new IntegerValue(10);
theVariable1.initializeWith(theInt1);
theExpressions.add(new VariableAssignmentExpression(theVariable1, theInt1));
IntegerValue theInt2 = new IntegerValue(20);
theVariable2.initializeWith(theInt2);
theExpressions.add(new VariableAssignmentExpression(theVariable2, theInt2));
Variable theVariable3 = new Variable(TypeRef.Native.INT, "var3");
BinaryExpression theBinary = new BinaryExpression(TypeRef.Native.INT, theVariable1, BinaryExpression.Operator.ADD, theVariable2);
theVariable3.initializeWith(theBinary);
theExpressions.add(new VariableAssignmentExpression(theVariable3, theBinary));
theExpressions.add(new ReturnValueExpression(theVariable3));
RedundantAssignmentOptimizer theOptimizer = new RedundantAssignmentOptimizer();
theOptimizer.optimize(theGraph, null);
System.out.println(theExpressions);
}
Aggregations