public class DeadCodeElimination.DeadCodeVisitor extends JChangeTrackingVisitor
x || true
" to "x
".
This visitor should perform all of its optimizations in a single pass.
Except in rare cases, running this pass multiple times should produce no
changes after the first pass. The only currently known exception to this
rule is in endVisit(JNewInstance, Context)
, where the target
constructor may be non-empty at the beginning of DCE and become empty
during the run, which potentially unlocks optimizations at call sites.
TODO: leverage ignoring expression output more to remove intermediary
operations in favor of pure side effects.
TODO: move more simplifications into methods like
simplifyCast
, so
that more simplifications can be made on a single pass through a tree.LVALUE_CONTEXT, UNMODIFIABLE_CONTEXT
Constructor and Description |
---|
DeadCodeVisitor(OptimizerContext optimizerCtx) |
Modifier and Type | Method and Description |
---|---|
void |
endVisit(JBinaryOperation x,
Context ctx)
Short circuit binary operations.
|
void |
endVisit(JBlock x,
Context ctx)
Prune dead statements and empty blocks.
|
void |
endVisit(JCastOperation x,
Context ctx) |
void |
endVisit(JConditional x,
Context ctx) |
void |
endVisit(JDeclarationStatement x,
Context ctx) |
void |
endVisit(JDoStatement x,
Context ctx)
Convert do { } while (false); into a block.
|
void |
endVisit(JExpressionStatement x,
Context ctx) |
void |
endVisit(JFieldRef x,
Context ctx)
NOTE: not called from JsniFieldRef.
|
void |
endVisit(JForStatement x,
Context ctx)
Prune for (X; false; Y) statements, but make sure X is run.
|
void |
endVisit(JIfStatement x,
Context ctx)
Simplify if statements.
|
void |
endVisit(JInstanceOf x,
Context ctx)
Simplify JInstanceOf expression whose output is ignored.
|
void |
endVisit(JLocalRef x,
Context ctx) |
void |
endVisit(JMethodCall x,
Context ctx)
Resolve method calls that can be computed statically.
|
void |
endVisit(JMultiExpression x,
Context ctx)
Remove any parts of JMultiExpression that have no side-effect.
|
void |
endVisit(JNewInstance x,
Context ctx) |
void |
endVisit(JParameterRef x,
Context ctx) |
void |
endVisit(JPostfixOperation x,
Context ctx)
Replace post-inc/dec with pre-inc/dec if the result doesn't matter.
|
void |
endVisit(JPrefixOperation x,
Context ctx)
Simplify the ! operator if possible.
|
void |
endVisit(JSwitchStatement x,
Context ctx)
Optimize switch statements.
|
void |
endVisit(JTryStatement x,
Context ctx)
1) Remove catch blocks whose exception type is not instantiable.
|
void |
endVisit(JWhileStatement x,
Context ctx)
Prune while (false) statements.
|
boolean |
visit(JBinaryOperation x,
Context ctx) |
boolean |
visit(JClassType x,
Context ctx) |
boolean |
visit(JDeclarationStatement x,
Context ctx) |
boolean |
visit(JExpressionStatement x,
Context ctx) |
boolean |
visit(JMethodCall x,
Context ctx)
NOTE: not called from JsniMethodRef.
|
boolean |
visit(JMultiExpression x,
Context ctx) |
boolean |
visit(JPostfixOperation x,
Context ctx) |
boolean |
visit(JPrefixOperation x,
Context ctx) |
boolean |
visit(JSwitchStatement x,
Context ctx) |
endVisit, endVisit, endVisit, endVisit, enter, enter, enter, enter, exit, exit, exit, exit, fieldsWereRemoved, getCurrentField, getCurrentMethod, madeChanges, methodsWereRemoved, visit, visit, visit, visit, wasRemoved, wasRemoved
accept, accept, accept, acceptImmutable, acceptLvalue, acceptWithInsertRemove, acceptWithInsertRemoveImmutable, checkReplacement, didChange, getNumMods, traverse
accept, accept, accept, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, endVisit, translateException, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
public DeadCodeVisitor(OptimizerContext optimizerCtx)
public void endVisit(JBinaryOperation x, Context ctx)
public void endVisit(JCastOperation x, Context ctx)
public void endVisit(JConditional x, Context ctx)
public void endVisit(JDeclarationStatement x, Context ctx)
public void endVisit(JDoStatement x, Context ctx)
public void endVisit(JExpressionStatement x, Context ctx)
public void endVisit(JFieldRef x, Context ctx)
JVisitor
public void endVisit(JForStatement x, Context ctx)
public void endVisit(JIfStatement x, Context ctx)
public void endVisit(JInstanceOf x, Context ctx)
public void endVisit(JMethodCall x, Context ctx)
public void endVisit(JMultiExpression x, Context ctx)
public void endVisit(JNewInstance x, Context ctx)
public void endVisit(JParameterRef x, Context ctx)
public void endVisit(JPostfixOperation x, Context ctx)
public void endVisit(JPrefixOperation x, Context ctx)
public void endVisit(JSwitchStatement x, Context ctx)
public void endVisit(JTryStatement x, Context ctx)
public void endVisit(JWhileStatement x, Context ctx)
public boolean visit(JBinaryOperation x, Context ctx)
public boolean visit(JClassType x, Context ctx)
public boolean visit(JDeclarationStatement x, Context ctx)
public boolean visit(JExpressionStatement x, Context ctx)
public boolean visit(JMethodCall x, Context ctx)
JVisitor
public boolean visit(JMultiExpression x, Context ctx)
public boolean visit(JPostfixOperation x, Context ctx)
public boolean visit(JPrefixOperation x, Context ctx)
public boolean visit(JSwitchStatement x, Context ctx)
Copyright © 2018. All rights reserved.