Flutter Engine
The Flutter Engine
SkSLInliner.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_INLINER
9#define SKSL_INLINER
10
11#ifndef SK_ENABLE_OPTIMIZE_SIZE
12
13#include "src/core/SkTHash.h"
19
20#include <memory>
21#include <vector>
22
23namespace SkSL {
24
25class FunctionCall;
26class FunctionDeclaration;
27class FunctionDefinition;
28class Position;
29class ProgramElement;
30class ProgramUsage;
31class Statement;
32class SymbolTable;
33class Variable;
34struct InlineCandidate;
35struct InlineCandidateList;
36namespace Analysis { enum class ReturnComplexity; }
37
38/**
39 * Converts a FunctionCall in the IR to a set of statements to be injected ahead of the function
40 * call, and a replacement expression. Can also detect cases where inlining isn't cleanly possible
41 * (e.g. return statements nested inside of a loop construct). The inliner isn't able to guarantee
42 * identical-to-GLSL execution order if the inlined function has visible side effects.
43 */
44class Inliner {
45public:
46 Inliner(const Context* context) : fContext(context) {}
47
48 /** Inlines any eligible functions that are found. Returns true if any changes are made. */
49 bool analyze(const std::vector<std::unique_ptr<ProgramElement>>& elements,
52
53private:
55
56 const ProgramSettings& settings() const { return fContext->fConfig->fSettings; }
57
58 void buildCandidateList(const std::vector<std::unique_ptr<ProgramElement>>& elements,
59 SymbolTable* symbols,
60 ProgramUsage* usage,
61 InlineCandidateList* candidateList);
62
63 std::unique_ptr<Expression> inlineExpression(Position pos,
64 VariableRewriteMap* varMap,
65 SymbolTable* symbolTableForExpression,
66 const Expression& expression);
67 std::unique_ptr<Statement> inlineStatement(Position pos,
68 VariableRewriteMap* varMap,
69 SymbolTable* symbolTableForStatement,
70 std::unique_ptr<Expression>* resultExpr,
71 Analysis::ReturnComplexity returnComplexity,
72 const Statement& statement,
73 const ProgramUsage& usage,
74 bool isBuiltinCode);
75
76 /**
77 * Searches the rewrite map for an rewritten Variable* for the passed-in one. Asserts if the
78 * rewrite map doesn't contain the variable, or contains a different type of expression.
79 */
80 static const Variable* RemapVariable(const Variable* variable,
81 const VariableRewriteMap* varMap);
82
84 bool candidateCanBeInlined(const InlineCandidate& candidate,
85 const ProgramUsage& usage,
86 InlinabilityCache* cache);
87
88 bool functionCanBeInlined(const FunctionDeclaration& funcDecl,
89 const ProgramUsage& usage,
90 InlinabilityCache* cache);
91
93 int getFunctionSize(const FunctionDeclaration& fnDecl, FunctionSizeCache* cache);
94
95 /**
96 * Processes the passed-in FunctionCall expression. The FunctionCall expression should be
97 * replaced with `fReplacementExpr`. If non-null, `fInlinedBody` should be inserted immediately
98 * above the statement containing the inlined expression.
99 */
100 struct InlinedCall {
101 std::unique_ptr<Block> fInlinedBody;
102 std::unique_ptr<Expression> fReplacementExpr;
103 };
104 InlinedCall inlineCall(const FunctionCall&,
105 SymbolTable*,
106 const ProgramUsage&,
107 const FunctionDeclaration* caller);
108
109 /** Adds a scope to inlined bodies returned by `inlineCall`, if one is required. */
110 void ensureScopedBlocks(Statement* inlinedBody, Statement* parentStmt);
111
112 /** Checks whether inlining is viable for a FunctionCall, modulo recursion and function size. */
113 bool isSafeToInline(const FunctionDefinition* functionDef, const ProgramUsage& usage);
114
115 const Context* fContext = nullptr;
116 Mangler fMangler;
117 int fInlinedStatementCounter = 0;
118};
119
120} // namespace SkSL
121
122#endif // SK_ENABLE_OPTIMIZE_SIZE
123
124#endif // SKSL_INLINER
SkPoint pos
ProgramConfig * fConfig
Definition: SkSLContext.h:33
bool analyze(const std::vector< std::unique_ptr< ProgramElement > > &elements, SymbolTable *symbols, ProgramUsage *usage)
Inliner(const Context *context)
Definition: SkSLInliner.h:46
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
static void usage(char *argv0)
ProgramSettings fSettings