Revert "Clean up SkSL inliner and allow it to be disabled."

This reverts commit d34d56e279.

Reason for revert: Pinpoint

This is not a pure rollback (we keep the early-out checks for
fInlineThreshold to avoid breaking tests).

Original change's description:
> Clean up SkSL inliner and allow it to be disabled.
>
> - When fInlineThreshold is zero, the inliner doesn't need to run at all.
> - Inlining functionality outside of `analyze` can be made private now;
>   it's not referenced by the IRGenerator any more.
>
> Change-Id: If61fd8998bc024201bf4489b7aa48ac4d117e449
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325617
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: John Stiles <johnstiles@google.com>

TBR=brianosman@google.com,ethannicholas@google.com,johnstiles@google.com

Change-Id: I288d82273abfc2587859cc92d5a4c663694c38a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325621
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-10-13 10:30:23 -04:00 committed by Skia Commit-Bot
parent f1319c3756
commit 1c03d336d7
2 changed files with 39 additions and 27 deletions

View File

@ -747,6 +747,11 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call,
bool Inliner::isSafeToInline(const FunctionDefinition* functionDef) {
SkASSERT(fSettings);
// A threshold of zero indicates that the inliner is completely disabled, so we can just return.
if (fSettings->fInlineThreshold <= 0) {
return false;
}
if (functionDef == nullptr) {
// Can't inline something if we don't actually have its definition.
return false;
@ -1069,25 +1074,30 @@ public:
};
bool Inliner::candidateCanBeInlined(const InlineCandidate& candidate, InlinabilityCache* cache) {
const FunctionDeclaration& fnDecl = (*candidate.fCandidateExpr)->as<FunctionCall>().function();
const FunctionDeclaration& funcDecl =
(*candidate.fCandidateExpr)->as<FunctionCall>().function();
auto [iter, wasInserted] = cache->insert({&fnDecl, false});
auto [iter, wasInserted] = cache->insert({&funcDecl, false});
if (wasInserted) {
// Recursion is forbidden here to avoid an infinite death spiral of inlining.
iter->second = this->isSafeToInline(fnDecl.definition()) &&
!contains_recursive_call(fnDecl);
iter->second = this->isSafeToInline(funcDecl.definition()) &&
!contains_recursive_call(funcDecl);
}
return iter->second;
}
bool Inliner::isLargeFunction(const InlineCandidate& candidate, LargeFunctionCache* cache) {
const FunctionDeclaration& fnDecl = (*candidate.fCandidateExpr)->as<FunctionCall>().function();
bool Inliner::isLargeFunction(const FunctionDefinition* functionDef) {
return Analysis::NodeCountExceeds(*functionDef, fSettings->fInlineThreshold);
}
auto [iter, wasInserted] = cache->insert({&fnDecl, false});
bool Inliner::isLargeFunction(const InlineCandidate& candidate, LargeFunctionCache* cache) {
const FunctionDeclaration& funcDecl =
(*candidate.fCandidateExpr)->as<FunctionCall>().function();
auto [iter, wasInserted] = cache->insert({&funcDecl, false});
if (wasInserted) {
iter->second = Analysis::NodeCountExceeds(*fnDecl.definition(),
fSettings->fInlineThreshold);
iter->second = this->isLargeFunction(funcDecl.definition());
}
return iter->second;

View File

@ -40,6 +40,26 @@ public:
void reset(const Context*, ModifiersPool* modifiers, const Program::Settings*);
/**
* Processes the passed-in FunctionCall expression. The FunctionCall expression should be
* replaced with `fReplacementExpr`. If non-null, `fInlinedBody` should be inserted immediately
* above the statement containing the inlined expression.
*/
struct InlinedCall {
std::unique_ptr<Block> fInlinedBody;
std::unique_ptr<Expression> fReplacementExpr;
};
InlinedCall inlineCall(FunctionCall*, SymbolTable*, const FunctionDeclaration* caller);
/** Adds a scope to inlined bodies returned by `inlineCall`, if one is required. */
void ensureScopedBlocks(Statement* inlinedBody, Statement* parentStmt);
/** Checks whether inlining is viable for a FunctionCall, modulo recursion and function size. */
bool isSafeToInline(const FunctionDefinition* functionDef);
/** Checks whether a function's size exceeds the inline threshold from Settings. */
bool isLargeFunction(const FunctionDefinition* functionDef);
/** Inlines any eligible functions that are found. Returns true if any changes are made. */
bool analyze(Program& program);
@ -64,27 +84,9 @@ private:
using InlinabilityCache = std::unordered_map<const FunctionDeclaration*, bool>;
bool candidateCanBeInlined(const InlineCandidate& candidate, InlinabilityCache* cache);
/** Checks whether a function's size exceeds the inline threshold from Settings. */
using LargeFunctionCache = std::unordered_map<const FunctionDeclaration*, bool>;
bool isLargeFunction(const InlineCandidate& candidate, LargeFunctionCache* cache);
/** Adds a scope to inlined bodies returned by `inlineCall`, if one is required. */
void ensureScopedBlocks(Statement* inlinedBody, Statement* parentStmt);
/**
* Processes the passed-in FunctionCall expression. The FunctionCall expression should be
* replaced with `fReplacementExpr`. If non-null, `fInlinedBody` should be inserted immediately
* above the statement containing the inlined expression.
*/
struct InlinedCall {
std::unique_ptr<Block> fInlinedBody;
std::unique_ptr<Expression> fReplacementExpr;
};
InlinedCall inlineCall(FunctionCall*, SymbolTable*, const FunctionDeclaration* caller);
/** Checks whether inlining is viable for a FunctionCall, modulo recursion and function size. */
bool isSafeToInline(const FunctionDefinition* functionDef);
const Context* fContext = nullptr;
ModifiersPool* fModifiers = nullptr;
const Program::Settings* fSettings = nullptr;