private static class RemoveUnusedVars.CallSiteOptimizer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private SimpleDefinitionFinder |
defFinder |
private java.util.List<Node> |
toRemove |
private java.util.List<Node> |
toReplaceWithZero |
Constructor and Description |
---|
CallSiteOptimizer(AbstractCompiler compiler,
SimpleDefinitionFinder defFinder) |
Modifier and Type | Method and Description |
---|---|
void |
applyChanges()
Applies optimizations to all previously marked nodes.
|
private boolean |
canChangeSignature(Node function) |
(package private) boolean |
canModifyCallers(Node function) |
private boolean |
canRemoveArgFromCallSites(Node function,
int argIndex)
Remove all references to a parameter, otherwise simplify the known
references.
|
private static Node |
getArgumentForCallOrNewOrDotCall(UseSite site,
int argIndex)
Returns the nth argument node given a usage site for a direct function
call or for a func.call() node.
|
private DefinitionsRemover.Definition |
getFunctionDefinition(Node function) |
private static boolean |
isModifiableCallSite(UseSite site) |
private boolean |
markUnreferencedFunctionArgs(Scope scope,
Node function,
java.util.Set<Var> referenced,
Node param,
int paramIndex,
boolean canChangeSignature)
For each unused function parameter, determine if it can be removed
from all the call sites, if so, remove it from the function signature
and the call sites otherwise replace the unused value where possible
with a constant (0).
|
void |
optimize(Scope fnScope,
java.util.Set<Var> referenced) |
private void |
tryRemoveAllFollowingArgs(Node function,
int argIndex)
Remove all the following parameters without side-effects
|
private void |
tryRemoveArgFromCallSites(Node function,
int argIndex,
boolean canModifyAllSites)
Remove all references to a parameter if possible otherwise simplify the
side-effect free parameters.
|
private final AbstractCompiler compiler
private final SimpleDefinitionFinder defFinder
private final java.util.List<Node> toRemove
private final java.util.List<Node> toReplaceWithZero
CallSiteOptimizer(AbstractCompiler compiler, SimpleDefinitionFinder defFinder)
public void applyChanges()
private boolean markUnreferencedFunctionArgs(Scope scope, Node function, java.util.Set<Var> referenced, Node param, int paramIndex, boolean canChangeSignature)
scope
- The function scopefunction
- The functionparam
- The current parameter node in the parameter list.paramIndex
- The index of the current parametercanChangeSignature
- Whether function signature can be change.private boolean canRemoveArgFromCallSites(Node function, int argIndex)
private void tryRemoveArgFromCallSites(Node function, int argIndex, boolean canModifyAllSites)
private void tryRemoveAllFollowingArgs(Node function, int argIndex)
private static Node getArgumentForCallOrNewOrDotCall(UseSite site, int argIndex)
boolean canModifyCallers(Node function)
function
- private static boolean isModifiableCallSite(UseSite site)
site
- The site to inspectprivate boolean canChangeSignature(Node function)
private DefinitionsRemover.Definition getFunctionDefinition(Node function)
function
-