Skip to content

Commit

Permalink
#79 Implement Optimizer for inefficient Member and Array Access
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Dec 14, 2018
1 parent da3739f commit bf8c3b8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,11 @@ public JSCompileResult generateCodeFor(final CompileOptions aOptions, final Byte
theVariablesWriter.print("var ");
theVariablesWriter.print(theVariable.getName());
theVariablesWriter.print(" = null;");
theVariablesWriter.print(" // type is ");
theVariablesWriter.print(theVariable.resolveType().resolve().name());
theVariablesWriter.print(" # of inits = " + theVariable.incomingDataFlows().size());
if (aOptions.isDebugOutput()) {
theVariablesWriter.print(" // type is ");
theVariablesWriter.print(theVariable.resolveType().resolve().name());
theVariablesWriter.print(" # of inits = " + theVariable.incomingDataFlows().size());
}
theVariablesWriter.println();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,12 @@ public void writeExpressions(final ExpressionList aExpressions) {
print(theVariable.getName());
print(" = ");
print(theValue);
print("; // type is ");
println(theVariable.resolveType().resolve().name() + " value type is " + theValue.resolveType());
if (options.isDebugOutput()) {
print("; // type is ");
println(theVariable.resolveType().resolve().name() + " value type is " + theValue.resolveType());
} else {
println(";");
}
} else if (theExpression instanceof PutStaticExpression) {
final PutStaticExpression theE = (PutStaticExpression) theExpression;
final BytecodeFieldRefConstant theField = theE.getField();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public void optimize(final ControlFlowGraph aGraph, final BytecodeLinkerContext
theOptimizer.add(new InlineFinalNodesOptimizer());
theOptimizer.add(new InvokeVirtualOptimizer());
theOptimizer.add(new InlineGotoOptimizer());
theOptimizer.add(new InefficientFieldWriteOptimizer());
theOptimizer.add(new InefficientArrayWriteOptimizer());
run(aGraph, aLinkerContext, theOptimizer);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@
*/
package de.mirkosertic.bytecoder.optimizer;

import java.util.List;
import java.util.stream.Collectors;

import de.mirkosertic.bytecoder.core.BytecodeLinkerContext;
import de.mirkosertic.bytecoder.graph.Edge;
import de.mirkosertic.bytecoder.ssa.ArrayStoreExpression;
import de.mirkosertic.bytecoder.ssa.ControlFlowGraph;
import de.mirkosertic.bytecoder.ssa.DataFlowEdgeType;
import de.mirkosertic.bytecoder.ssa.Expression;
import de.mirkosertic.bytecoder.ssa.ExpressionList;
import de.mirkosertic.bytecoder.ssa.InvocationExpression;
import de.mirkosertic.bytecoder.ssa.PutFieldExpression;
import de.mirkosertic.bytecoder.ssa.PutStaticExpression;
import de.mirkosertic.bytecoder.ssa.RecursiveExpressionVisitor;
import de.mirkosertic.bytecoder.ssa.ReturnValueExpression;
import de.mirkosertic.bytecoder.ssa.Value;
import de.mirkosertic.bytecoder.ssa.Variable;
import de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression;

import java.util.List;
import java.util.stream.Collectors;

public class RedundantVariablesOptimizer extends RecursiveExpressionVisitor implements Optimizer {

@Override
Expand All @@ -42,7 +45,10 @@ public void optimize(final ControlFlowGraph aGraph, final BytecodeLinkerContext
protected void visit(final ControlFlowGraph aGraph, final ExpressionList aList, final Expression aExpression, final BytecodeLinkerContext aLinkerContext) {
if ((aExpression instanceof VariableAssignmentExpression) ||
(aExpression instanceof InvocationExpression) ||
(aExpression instanceof ReturnValueExpression)) {
(aExpression instanceof ReturnValueExpression) ||
(aExpression instanceof PutFieldExpression) ||
(aExpression instanceof PutStaticExpression) ||
(aExpression instanceof ArrayStoreExpression)) {
boolean modified = true;
while(modified) {
modified = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public TypeRef resolveType() {

@Override
public boolean isTrulyFunctional() {
return false;
return true;
}
}

0 comments on commit bf8c3b8

Please sign in to comment.