Skip to content

Commit 7b46300

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Move ownership of SkSL::Inliner to SkSL::Compiler.
This will allow the Compiler to access the Inliner (in addition to the IRGenerator, as before). Change-Id: I1aeeaf8e3d3fb5d15533f7bf5c635a4798115d1f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314357 Auto-Submit: John Stiles <[email protected]> Reviewed-by: Brian Osman <[email protected]> Commit-Queue: John Stiles <[email protected]>
1 parent cf936f9 commit 7b46300

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

src/sksl/SkSLCompiler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Compiler::Compiler(Flags flags)
106106
, fContext(std::make_shared<Context>())
107107
, fErrorCount(0) {
108108
auto symbols = std::make_shared<SymbolTable>(this);
109-
fIRGenerator = std::make_unique<IRGenerator>(fContext.get(), symbols, *this);
109+
fIRGenerator = std::make_unique<IRGenerator>(fContext.get(), &fInliner, symbols, *this);
110110
#define ADD_TYPE(t) symbols->addWithoutOwnership(fContext->f ## t ## _Type->fName, \
111111
fContext->f ## t ## _Type.get())
112112
ADD_TYPE(Void);
@@ -1547,6 +1547,7 @@ std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, String tex
15471547
const Program::Settings& settings) {
15481548
fErrorText = "";
15491549
fErrorCount = 0;
1550+
fInliner.reset(context(), settings);
15501551
std::vector<std::unique_ptr<ProgramElement>>* inherited;
15511552
std::vector<std::unique_ptr<ProgramElement>> elements;
15521553
switch (kind) {

src/sksl/SkSLCompiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/sksl/SkSLCFGGenerator.h"
1717
#include "src/sksl/SkSLContext.h"
1818
#include "src/sksl/SkSLErrorReporter.h"
19+
#include "src/sksl/SkSLInliner.h"
1920
#include "src/sksl/SkSLLexer.h"
2021
#include "src/sksl/ir/SkSLProgram.h"
2122
#include "src/sksl/ir/SkSLSymbolTable.h"
@@ -241,6 +242,7 @@ class SK_API Compiler : public ErrorReporter {
241242
std::vector<std::unique_ptr<ProgramElement>> fFPInclude;
242243
std::shared_ptr<SymbolTable> fFPSymbolTable;
243244

245+
Inliner fInliner;
244246
std::unique_ptr<IRGenerator> fIRGenerator;
245247
int fFlags;
246248

src/sksl/SkSLIRGenerator.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,18 @@ class AutoDisableInline {
120120
bool fOldCanInline;
121121
};
122122

123-
IRGenerator::IRGenerator(const Context* context, std::shared_ptr<SymbolTable> symbolTable,
124-
ErrorReporter& errorReporter)
125-
: fContext(*context)
126-
, fCurrentFunction(nullptr)
127-
, fRootSymbolTable(symbolTable)
128-
, fSymbolTable(symbolTable)
129-
, fLoopLevel(0)
130-
, fSwitchLevel(0)
131-
, fErrors(errorReporter) {}
123+
IRGenerator::IRGenerator(const Context* context, Inliner* inliner,
124+
std::shared_ptr<SymbolTable> symbolTable, ErrorReporter& errorReporter)
125+
: fContext(*context)
126+
, fInliner(inliner)
127+
, fCurrentFunction(nullptr)
128+
, fRootSymbolTable(symbolTable)
129+
, fSymbolTable(symbolTable)
130+
, fLoopLevel(0)
131+
, fSwitchLevel(0)
132+
, fErrors(errorReporter) {
133+
SkASSERT(fInliner);
134+
}
132135

133136
void IRGenerator::pushSymbolTable() {
134137
fSymbolTable.reset(new SymbolTable(std::move(fSymbolTable)));
@@ -176,7 +179,6 @@ void IRGenerator::start(const Program::Settings* settings,
176179
this->pushSymbolTable();
177180
fInvocations = -1;
178181
fInputs.reset();
179-
fInliner.reset(fContext, *fSettings);
180182
fSkPerVertex = nullptr;
181183
fRTAdjust = nullptr;
182184
fRTAdjustInterfaceBlock = nullptr;
@@ -1990,9 +1992,9 @@ std::unique_ptr<Expression> IRGenerator::call(int offset,
19901992

19911993
auto funcCall = std::make_unique<FunctionCall>(offset, *returnType, function,
19921994
std::move(arguments));
1993-
if (fCanInline && fInliner.isSafeToInline(*funcCall, fSettings->fInlineThreshold)) {
1994-
Inliner::InlinedCall inlinedCall = fInliner.inlineCall(std::move(funcCall),
1995-
fSymbolTable.get());
1995+
if (fCanInline && fInliner->isSafeToInline(*funcCall, fSettings->fInlineThreshold)) {
1996+
Inliner::InlinedCall inlinedCall = fInliner->inlineCall(std::move(funcCall),
1997+
fSymbolTable.get());
19961998
if (inlinedCall.fInlinedBody) {
19971999
fExtraStatements.push_back(std::move(inlinedCall.fInlinedBody));
19982000
}

src/sksl/SkSLIRGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using IRIntrinsicMap = std::unordered_map<String, IRIntrinsic>;
5151
*/
5252
class IRGenerator {
5353
public:
54-
IRGenerator(const Context* context, std::shared_ptr<SymbolTable> root,
54+
IRGenerator(const Context* context, Inliner* inliner, std::shared_ptr<SymbolTable> root,
5555
ErrorReporter& errorReporter);
5656

5757
void convertProgram(Program::Kind kind,
@@ -168,7 +168,7 @@ class IRGenerator {
168168
bool checkSwizzleWrite(const Swizzle& swizzle);
169169
void copyIntrinsicIfNeeded(const FunctionDeclaration& function);
170170

171-
Inliner fInliner;
171+
Inliner* fInliner = nullptr;
172172
std::unique_ptr<ASTFile> fFile;
173173
const FunctionDeclaration* fCurrentFunction;
174174
std::unordered_map<String, Program::Settings::Value> fCapsMap;

0 commit comments

Comments
 (0)