class InlineFunctions extends java.lang.Object implements CompilerPass
Modifier and Type | Class and Description |
---|---|
private static class |
InlineFunctions.CallVisitor
Visit call sites for functions in functionMap.
|
private static interface |
InlineFunctions.CallVisitorCallback |
private class |
InlineFunctions.FindCandidateFunctions
Find functions that might be inlined.
|
private class |
InlineFunctions.FindCandidatesReferences
Find references to functions that are inlinable.
|
private static interface |
InlineFunctions.Function
Interface for dealing with function declarations and function
expressions equally
|
private static class |
InlineFunctions.FunctionExpression
FunctionExpression implementation of the Function interface
|
private static class |
InlineFunctions.FunctionState
Use to track the decisions that have been made about a function.
|
private class |
InlineFunctions.FunctionVar
FunctionVar implementation of the Function interface
|
private class |
InlineFunctions.Inline
Inline functions at the call sites.
|
private class |
InlineFunctions.NamedFunction
NamedFunction implementation of the Function interface
|
(package private) static class |
InlineFunctions.Reference |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<Node,java.lang.String> |
anonFns |
private boolean |
assumeMinimumCapture |
private boolean |
blockFunctionInliningEnabled |
private AbstractCompiler |
compiler |
private boolean |
enforceMaxSizeAfterInlining |
private java.util.Map<java.lang.String,InlineFunctions.FunctionState> |
fns |
private FunctionInjector |
injector |
private boolean |
inlineGlobalFunctions |
private boolean |
inlineLocalFunctions |
private int |
maxSizeAfterInlining |
Constructor and Description |
---|
InlineFunctions(AbstractCompiler compiler,
com.google.common.base.Supplier<java.lang.String> safeNameIdSupplier,
boolean inlineGlobalFunctions,
boolean inlineLocalFunctions,
boolean blockFunctionInliningEnabled,
boolean assumeStrictThis,
boolean assumeMinimumCapture,
int maxSizeAfterInlining) |
Modifier and Type | Method and Description |
---|---|
private void |
decomposeExpressions()
For any call-site that needs it, prepare the call-site for inlining
by rewriting the containing expression.
|
private java.util.Set<java.lang.String> |
findCalledFunctions(Node node)
This functions that may be called directly.
|
private static void |
findCalledFunctions(Node node,
java.util.Set<java.lang.String> changed) |
(package private) InlineFunctions.FunctionState |
getOrCreateFunctionState(java.lang.String fnName) |
private static boolean |
hasLocalNames(Node fnNode) |
private boolean |
inliningLowersCost(InlineFunctions.FunctionState fs) |
private static boolean |
isAlwaysInlinable(Node fn) |
private boolean |
isCandidateFunction(InlineFunctions.Function fn)
Checks if the given function matches the criteria for an inlinable
function.
|
(package private) static boolean |
isCandidateUsage(Node name) |
private void |
maybeAddFunction(InlineFunctions.Function fn,
JSModule module)
Updates the FunctionState object for the given function.
|
private boolean |
minimizeCost(InlineFunctions.FunctionState fs)
Determines if the function is worth inlining and potentially
trims references that increase the cost.
|
void |
process(Node externs,
Node root)
Process the JS with root node root.
|
(package private) void |
removeInlinedFunctions()
Removed inlined functions that no longer have any references.
|
private void |
resolveInlineConflicts()
Size base inlining calculations are thrown off when a function that is
being inlined also contains calls to functions that are slated for
inlining.
|
private void |
resolveInlineConflictsForFunction(InlineFunctions.FunctionState fs) |
private boolean |
targetSizeAfterInlineExceedsLimit(NodeTraversal t,
InlineFunctions.FunctionState fs) |
private void |
trimCandidatesNotMeetingMinimumRequirements()
Remove entries that aren't a valid inline candidates, from the list of
encountered names.
|
private void |
trimCandidatesUsingOnCost()
Remove entries from the list of candidates that can't be inlined.
|
(package private) void |
verifyAllReferencesInlined(InlineFunctions.FunctionState fs)
Sanity check to verify, that expression rewriting didn't
make a call inaccessible.
|
private final java.util.Map<java.lang.String,InlineFunctions.FunctionState> fns
private final java.util.Map<Node,java.lang.String> anonFns
private final AbstractCompiler compiler
private final FunctionInjector injector
private final boolean blockFunctionInliningEnabled
private final boolean inlineGlobalFunctions
private final boolean inlineLocalFunctions
private final boolean assumeMinimumCapture
private final boolean enforceMaxSizeAfterInlining
private final int maxSizeAfterInlining
InlineFunctions(AbstractCompiler compiler, com.google.common.base.Supplier<java.lang.String> safeNameIdSupplier, boolean inlineGlobalFunctions, boolean inlineLocalFunctions, boolean blockFunctionInliningEnabled, boolean assumeStrictThis, boolean assumeMinimumCapture, int maxSizeAfterInlining)
InlineFunctions.FunctionState getOrCreateFunctionState(java.lang.String fnName)
public void process(Node externs, Node root)
CompilerPass
process
in interface CompilerPass
externs
- Top of external JS treeroot
- Top of JS treeprivate static boolean isAlwaysInlinable(Node fn)
private boolean targetSizeAfterInlineExceedsLimit(NodeTraversal t, InlineFunctions.FunctionState fs)
private void maybeAddFunction(InlineFunctions.Function fn, JSModule module)
private static boolean hasLocalNames(Node fnNode)
fnNode
- The function to inspect.private boolean isCandidateFunction(InlineFunctions.Function fn)
static boolean isCandidateUsage(Node name)
private void trimCandidatesNotMeetingMinimumRequirements()
private void trimCandidatesUsingOnCost()
private boolean minimizeCost(InlineFunctions.FunctionState fs)
private boolean inliningLowersCost(InlineFunctions.FunctionState fs)
private void resolveInlineConflicts()
private void resolveInlineConflictsForFunction(InlineFunctions.FunctionState fs)
resolveInlineConflicts()
private java.util.Set<java.lang.String> findCalledFunctions(Node node)
private static void findCalledFunctions(Node node, java.util.Set<java.lang.String> changed)
findCalledFunctions(Node)
private void decomposeExpressions()
void removeInlinedFunctions()
void verifyAllReferencesInlined(InlineFunctions.FunctionState fs)