diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-02-02 16:11:39 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-03 14:37:55 +0000 |
commit | 113628d76176a1ab3e6719c59efff23cd10ab213 (patch) | |
tree | 89c7815c9b7e86a4b9b573ee8ecc6bb7a946de2d /src/sksl/ir/SkSLVariableReference.h | |
parent | 3f36369a94d2c49c91bcd0249bf351da36a6d40d (diff) |
Added dead variable / code elimination to skslc.
BUG=skia:
Change-Id: Ib037730803a8f222f099de0e001fe06ad452a22c
Reviewed-on: https://skia-review.googlesource.com/7584
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 | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h index fecb04e2e5..75b7f3dcd4 100644 --- a/src/sksl/ir/SkSLVariableReference.h +++ b/src/sksl/ir/SkSLVariableReference.h @@ -38,7 +38,7 @@ struct VariableReference : public Expression { } } - virtual ~VariableReference() override { + ~VariableReference() override { if (fRefKind != kWrite_RefKind) { fVariable.fReadCount--; } @@ -64,13 +64,19 @@ struct VariableReference : public Expression { fRefKind = refKind; } + bool hasSideEffects() const override { + return false; + } + SkString description() const override { return fVariable.fName; } - virtual std::unique_ptr<Expression> constantPropagate( - const IRGenerator& irGenerator, - const DefinitionMap& definitions) override { + 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) { const Expression* expr = exprIter->second->get(); @@ -85,6 +91,11 @@ struct VariableReference : public Expression { irGenerator.fContext, Position(), ((FloatLiteral*) expr)->fValue)); + case Expression::kBoolLiteral_Kind: + return std::unique_ptr<Expression>(new BoolLiteral( + irGenerator.fContext, + Position(), + ((BoolLiteral*) expr)->fValue)); default: break; } @@ -93,10 +104,9 @@ struct VariableReference : public Expression { } const Variable& fVariable; - -private: RefKind fRefKind; +private: typedef Expression INHERITED; }; |