Add 'kOnlySingleReturn' complexity type to the Inliner.
This can be used in followup CLs to test various forms of inliner simplification. (More info: http://go/optimization-in-sksl-inliner ) Change-Id: Icd12a1ae1481c9aeacf3f11e85872fecfa972ec3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/384836 Commit-Queue: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
da16367907
commit
99b2d04d31
@ -200,12 +200,14 @@ public:
|
||||
return (fNumReturns >= fLimit) || INHERITED::visitStatement(stmt);
|
||||
}
|
||||
case Statement::Kind::kVarDeclaration: {
|
||||
++fNumNonReturnStatements;
|
||||
if (fScopedBlockDepth > 1) {
|
||||
fVariablesInBlocks = true;
|
||||
}
|
||||
return INHERITED::visitStatement(stmt);
|
||||
}
|
||||
case Statement::Kind::kBlock: {
|
||||
// Don't count Block as a statement.
|
||||
int depthIncrement = stmt.as<Block>().isScope() ? 1 : 0;
|
||||
fScopedBlockDepth += depthIncrement;
|
||||
bool result = INHERITED::visitStatement(stmt);
|
||||
@ -219,12 +221,18 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case Statement::Kind::kNop:
|
||||
case Statement::Kind::kInlineMarker:
|
||||
// Don't count no-op statements.
|
||||
return false;
|
||||
default:
|
||||
++fNumNonReturnStatements;
|
||||
return INHERITED::visitStatement(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
int fNumReturns = 0;
|
||||
int fNumNonReturnStatements = 0;
|
||||
int fDeepestReturn = 0;
|
||||
int fLimit = 0;
|
||||
int fScopedBlockDepth = 0;
|
||||
@ -246,7 +254,10 @@ Inliner::ReturnComplexity Inliner::GetReturnComplexity(const FunctionDefinition&
|
||||
if (counter.fVariablesInBlocks && counter.fDeepestReturn > 1) {
|
||||
return ReturnComplexity::kScopedReturns;
|
||||
}
|
||||
return ReturnComplexity::kSingleSafeReturn;
|
||||
if (counter.fNumNonReturnStatements > 0) {
|
||||
return ReturnComplexity::kSingleSafeReturn;
|
||||
}
|
||||
return ReturnComplexity::kOnlySingleReturn;
|
||||
}
|
||||
|
||||
void Inliner::ensureScopedBlocks(Statement* inlinedBody, Statement* parentStmt) {
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
using VariableRewriteMap = std::unordered_map<const Variable*, std::unique_ptr<Expression>>;
|
||||
|
||||
enum class ReturnComplexity {
|
||||
kOnlySingleReturn,
|
||||
kSingleSafeReturn,
|
||||
kScopedReturns,
|
||||
kEarlyReturns,
|
||||
|
Loading…
Reference in New Issue
Block a user