Track variable writes via ProgramUsage instead of ProgramVisitor.

This replaces a potentially expensive tree walk with a map lookup. It
should speed up the inliner (on sksl_large) by about 4%, and speed up
the benchmark overall by >1%.

Change-Id: I68ef492d2aba6303753fad01dcbef1eaffb7a6f9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386556
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-03-18 09:24:06 -04:00 committed by Skia Commit-Bot
parent 39465b8f95
commit 30fce9c2ab
2 changed files with 5 additions and 2 deletions

View File

@ -558,6 +558,7 @@ Inliner::InlineVariable Inliner::makeInlineVariable(const String& baseName,
Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call,
std::shared_ptr<SymbolTable> 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<std::unique_ptr<ProgramElement>>& 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.

View File

@ -93,6 +93,7 @@ private:
};
InlinedCall inlineCall(FunctionCall*,
std::shared_ptr<SymbolTable>,
const ProgramUsage&,
const FunctionDeclaration* caller);
/** Creates a scratch variable for the inliner to use. */