From a94e0261ef436b46ec63f2f72a654ce97b278901 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Tue, 27 Apr 2021 17:29:59 -0400 Subject: [PATCH] Add Make factory method to VariableReference. There aren't any optimization opportunities here, but it was the only expression/statement type left without a Make or Convert factory. Change-Id: I4c413a3b2619261f9e974528fa45211383e56fa7 Bug: skia:11342 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402017 Auto-Submit: John Stiles Commit-Queue: Ethan Nicholas Reviewed-by: Ethan Nicholas --- src/sksl/SkSLIRGenerator.cpp | 20 ++++++++------------ src/sksl/SkSLInliner.cpp | 6 +++--- src/sksl/SkSLRehydrator.cpp | 2 +- src/sksl/ir/SkSLVariableReference.h | 14 +++++++++++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 4b8b083e56..cab4592b18 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -702,12 +702,12 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< const Variable* loopIdx = &(*fSymbolTable)["sk_InvocationID"]->as(); auto test = BinaryExpression::Make( fContext, - std::make_unique(/*offset=*/-1, loopIdx), + VariableReference::Make(/*offset=*/-1, loopIdx), Token::Kind::TK_LT, IntLiteral::Make(fContext, /*offset=*/-1, fInvocations)); auto next = PostfixExpression::Make( fContext, - std::make_unique(/*offset=*/-1, loopIdx,VariableRefKind::kReadWrite), + VariableReference::Make(/*offset=*/-1, loopIdx, VariableRefKind::kReadWrite), Token::Kind::TK_PLUSPLUS); ASTNode endPrimitiveID(&fFile->fNodes, -1, ASTNode::Kind::kIdentifier, "EndPrimitive"); std::unique_ptr endPrimitive = this->convertExpression(endPrimitiveID); @@ -723,7 +723,7 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< ExpressionArray{}))); auto assignment = BinaryExpression::Make( fContext, - std::make_unique(/*offset=*/-1, loopIdx, VariableRefKind::kWrite), + VariableReference::Make(/*offset=*/-1, loopIdx, VariableRefKind::kWrite), Token::Kind::TK_EQ, IntLiteral::Make(fContext, /*offset=*/-1, /*value=*/0)); auto initializer = ExpressionStatement::Make(fContext, std::move(assignment)); @@ -750,12 +750,10 @@ std::unique_ptr IRGenerator::getNormalizeSkPositionCode() { // sk_Position.w); SkASSERT(skPerVertex && fRTAdjust); auto Ref = [](const Variable* var) -> std::unique_ptr { - return std::make_unique(/*offset=*/-1, var, - VariableReference::RefKind::kRead); + return VariableReference::Make(/*offset=*/-1, var, VariableReference::RefKind::kRead); }; auto WRef = [](const Variable* var) -> std::unique_ptr { - return std::make_unique(/*offset=*/-1, var, - VariableReference::RefKind::kWrite); + return VariableReference::Make(/*offset=*/-1, var, VariableReference::RefKind::kWrite); }; auto Field = [&](const Variable* var, int idx) -> std::unique_ptr { return FieldAccess::Make(fContext, Ref(var), idx, @@ -1590,14 +1588,12 @@ std::unique_ptr IRGenerator::convertIdentifier(int offset, StringFra } } // default to kRead_RefKind; this will be corrected later if the variable is written to - return std::make_unique(offset, - var, - VariableReference::RefKind::kRead); + return VariableReference::Make(offset, var, VariableReference::RefKind::kRead); } case Symbol::Kind::kField: { const Field* field = &result->as(); - auto base = std::make_unique(offset, &field->owner(), - VariableReference::RefKind::kRead); + auto base = VariableReference::Make(offset, &field->owner(), + VariableReference::RefKind::kRead); return FieldAccess::Make(fContext, std::move(base), field->fieldIndex(), FieldAccess::OwnerKind::kAnonymousInterfaceBlock); } diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp index 0d265c1001..ae92cc6899 100644 --- a/src/sksl/SkSLInliner.cpp +++ b/src/sksl/SkSLInliner.cpp @@ -550,7 +550,7 @@ std::unique_ptr Inliner::inlineStatement(int offset, variable.type().clone(symbolTableForStatement), isBuiltinCode, variable.storage()); - (*varMap)[&variable] = std::make_unique(offset, clonedVar.get()); + (*varMap)[&variable] = VariableReference::Make(offset, clonedVar.get()); auto result = VarDeclaration::Make(*fContext, clonedVar.get(), decl.baseType().clone(symbolTableForStatement), @@ -646,7 +646,7 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call, symbolTable.get(), Modifiers{}, caller->isBuiltin(), &noInitialValue); inlineStatements.push_back(std::move(var.fVarDecl)); - resultExpr = std::make_unique(/*offset=*/-1, var.fVarSymbol); + resultExpr = VariableReference::Make(/*offset=*/-1, var.fVarSymbol); } // Create variables in the extra statements to hold the arguments, and assign the arguments to @@ -670,7 +670,7 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call, symbolTable.get(), param->modifiers(), caller->isBuiltin(), &arguments[i]); inlineStatements.push_back(std::move(var.fVarDecl)); - varMap[param] = std::make_unique(/*offset=*/-1, var.fVarSymbol); + varMap[param] = VariableReference::Make(/*offset=*/-1, var.fVarSymbol); } for (const std::unique_ptr& stmt : body.children()) { diff --git a/src/sksl/SkSLRehydrator.cpp b/src/sksl/SkSLRehydrator.cpp index c4dd94fe46..46adfc7ec9 100644 --- a/src/sksl/SkSLRehydrator.cpp +++ b/src/sksl/SkSLRehydrator.cpp @@ -564,7 +564,7 @@ std::unique_ptr Rehydrator::expression() { case Rehydrator::kVariableReference_Command: { const Variable* var = this->symbolRef(Symbol::Kind::kVariable); VariableReference::RefKind refKind = (VariableReference::RefKind) this->readU8(); - return std::make_unique(-1, var, refKind); + return VariableReference::Make(/*offset=*/-1, var, refKind); } case Rehydrator::kVoid_Command: return nullptr; diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h index 30e48f66d7..e5a6d803a6 100644 --- a/src/sksl/ir/SkSLVariableReference.h +++ b/src/sksl/ir/SkSLVariableReference.h @@ -37,7 +37,16 @@ public: static constexpr Kind kExpressionKind = Kind::kVariableReference; - VariableReference(int offset, const Variable* variable, RefKind refKind = RefKind::kRead); + VariableReference(int offset, const Variable* variable, RefKind refKind); + + // Creates a VariableReference. There isn't much in the way of error-checking or optimization + // opportunities here. + static std::unique_ptr Make(int offset, + const Variable* variable, + RefKind refKind = RefKind::kRead) { + SkASSERT(variable); + return std::make_unique(offset, variable, refKind); + } VariableReference(const VariableReference&) = delete; VariableReference& operator=(const VariableReference&) = delete; @@ -58,8 +67,7 @@ public: bool isConstantOrUniform() const override; std::unique_ptr clone() const override { - return std::unique_ptr(new VariableReference(fOffset, this->variable(), - this->refKind())); + return std::make_unique(fOffset, this->variable(), this->refKind()); } String description() const override;