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/SkSLConstructor.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/SkSLConstructor.h')
-rw-r--r-- | src/sksl/ir/SkSLConstructor.h | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h index 691bea123a..5ecb74eb72 100644 --- a/src/sksl/ir/SkSLConstructor.h +++ b/src/sksl/ir/SkSLConstructor.h @@ -24,20 +24,36 @@ struct Constructor : public Expression { : INHERITED(position, kConstructor_Kind, type) , fArguments(std::move(arguments)) {} - virtual std::unique_ptr<Expression> constantPropagate( - const IRGenerator& irGenerator, - const DefinitionMap& definitions) override { - if (fArguments.size() == 1 && fArguments[0]->fKind == Expression::kIntLiteral_Kind && - // promote float(1) to 1.0 - fType == *irGenerator.fContext.fFloat_Type) { - int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; - return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, - fPosition, - intValue)); + std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, + const DefinitionMap& definitions) override { + if (fArguments.size() == 1 && fArguments[0]->fKind == Expression::kIntLiteral_Kind) { + if (fType == *irGenerator.fContext.fFloat_Type) { + // promote float(1) to 1.0 + int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; + return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, + fPosition, + intValue)); + } else if (fType == *irGenerator.fContext.fUInt_Type) { + // promote uint(1) to 1u + int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; + return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, + fPosition, + intValue, + &fType)); + } } return nullptr; } + bool hasSideEffects() const override { + for (const auto& arg : fArguments) { + if (arg->hasSideEffects()) { + return true; + } + } + return false; + } + SkString description() const override { SkString result = fType.description() + "("; SkString separator; |