diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp index 3abfd956a8..6246c748d3 100644 --- a/src/sksl/SkSLInliner.cpp +++ b/src/sksl/SkSLInliner.cpp @@ -558,6 +558,7 @@ Inliner::InlineVariable Inliner::makeInlineVariable(const String& baseName, Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call, std::shared_ptr symbolTable, + const ProgramUsage& usage, const FunctionDeclaration* caller) { // Inlining is more complicated here than in a typical compiler, because we have to have a // high-level IR and can't just drop statements into the middle of an expression or even use @@ -610,7 +611,8 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call, const Variable* param = function.declaration().parameters()[i]; if (Analysis::IsTrivialExpression(*arguments[i])) { // ... and isn't written to within the inline function... - if (!Analysis::StatementWritesToVariable(body, *param)) { + const ProgramUsage::VariableCounts& paramUsage = usage.get(*param); + if (!paramUsage.fWrite) { // ... we don't need to copy it at all! We can just use the existing expression. varMap[param] = arguments[i]->clone(); continue; @@ -1087,7 +1089,7 @@ bool Inliner::analyze(const std::vector>& elemen } // Convert the function call to its inlined equivalent. - InlinedCall inlinedCall = this->inlineCall(&funcCall, candidate.fSymbols, + InlinedCall inlinedCall = this->inlineCall(&funcCall, candidate.fSymbols, *usage, &candidate.fEnclosingFunction->declaration()); // Stop if an error was detected during the inlining process. diff --git a/src/sksl/SkSLInliner.h b/src/sksl/SkSLInliner.h index 4103f2a230..29186dbbfe 100644 --- a/src/sksl/SkSLInliner.h +++ b/src/sksl/SkSLInliner.h @@ -93,6 +93,7 @@ private: }; InlinedCall inlineCall(FunctionCall*, std::shared_ptr, + const ProgramUsage&, const FunctionDeclaration* caller); /** Creates a scratch variable for the inliner to use. */