diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-04-20 19:31:52 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-20 23:57:21 +0000 |
commit | cb67096b61f699b047fe8635984db1ac708a7b99 (patch) | |
tree | 3a8bda0962ad77d0d9ccb1d89c15f70578a7fe78 /src/sksl/ir/SkSLVariableReference.h | |
parent | e79b473714866682dea85b66c005c5bb2ff6a397 (diff) |
Improved skslc optimizer, particularly around vectors.
BUG=skia:
Change-Id: Idb364d9198f2ff84aad1eb68e236fb45ec1c86b7
Reviewed-on: https://skia-review.googlesource.com/8000
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'src/sksl/ir/SkSLVariableReference.h')
-rw-r--r-- | src/sksl/ir/SkSLVariableReference.h | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h index af181f84fd..3b8ebe3617 100644 --- a/src/sksl/ir/SkSLVariableReference.h +++ b/src/sksl/ir/SkSLVariableReference.h @@ -41,7 +41,7 @@ struct VariableReference : public Expression { } } - virtual ~VariableReference() override { + ~VariableReference() override { if (fRefKind != kWrite_RefKind) { fVariable.fReadCount--; } @@ -67,39 +67,63 @@ struct VariableReference : public Expression { fRefKind = refKind; } + bool hasSideEffects() const override { + return false; + } + String description() const override { return fVariable.fName; } - virtual std::unique_ptr<Expression> constantPropagate( - const IRGenerator& irGenerator, - const DefinitionMap& definitions) override { - auto exprIter = definitions.find(&fVariable); - if (exprIter != definitions.end() && exprIter->second) { - const Expression* expr = exprIter->second->get(); - switch (expr->fKind) { - case Expression::kIntLiteral_Kind: - return std::unique_ptr<Expression>(new IntLiteral( - irGenerator.fContext, - Position(), - ((IntLiteral*) expr)->fValue)); - case Expression::kFloatLiteral_Kind: - return std::unique_ptr<Expression>(new FloatLiteral( - irGenerator.fContext, + static std::unique_ptr<Expression> copy_constant(const IRGenerator& irGenerator, + const Expression* expr) { + ASSERT(expr->isConstant()); + switch (expr->fKind) { + case Expression::kIntLiteral_Kind: + return std::unique_ptr<Expression>(new IntLiteral( + irGenerator.fContext, + Position(), + ((IntLiteral*) expr)->fValue)); + case Expression::kFloatLiteral_Kind: + return std::unique_ptr<Expression>(new FloatLiteral( + irGenerator.fContext, + Position(), + ((FloatLiteral*) expr)->fValue)); + case Expression::kBoolLiteral_Kind: + return std::unique_ptr<Expression>(new BoolLiteral(irGenerator.fContext, Position(), - ((FloatLiteral*) expr)->fValue)); - default: - break; + ((BoolLiteral*) expr)->fValue)); + case Expression::kConstructor_Kind: { + const Constructor* c = (const Constructor*) expr; + std::vector<std::unique_ptr<Expression>> args; + for (const auto& arg : c->fArguments) { + args.push_back(copy_constant(irGenerator, arg.get())); + } + return std::unique_ptr<Expression>(new Constructor(Position(), c->fType, + std::move(args))); } + default: + ABORT("unsupported constant\n"); + } + } + + std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, + const DefinitionMap& definitions) override { + if (fRefKind != kRead_RefKind) { + return nullptr; + } + auto exprIter = definitions.find(&fVariable); + if (exprIter != definitions.end() && exprIter->second && + (*exprIter->second)->isConstant()) { + return copy_constant(irGenerator, exprIter->second->get()); } return nullptr; } const Variable& fVariable; - -private: RefKind fRefKind; +private: typedef Expression INHERITED; }; |