diff options
author | 2014-10-20 16:47:04 +0100 | |
---|---|---|
committer | 2014-10-21 13:48:41 +0100 | |
commit | 9240d6a2baa9ed1e18ee08744b461fe49a1ee269 (patch) | |
tree | 0adc27979a1c30defa16de4142b1d54fac6f93dc /compiler/optimizing/nodes.h | |
parent | 88cb1755e1d6acaed0f66ce65d7a2a4465053342 (diff) |
Constant folding on unary operations in the optimizing compiler.
Change-Id: I4b77afa2a89f5ad2eedd4d6c0c6c382585419349
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r-- | compiler/optimizing/nodes.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 26d9bd1b32..3f29e53d65 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -1101,6 +1101,15 @@ class HUnaryOperation : public HExpression<1> { virtual bool CanBeMoved() const { return true; } virtual bool InstructionDataEquals(HInstruction* other) const { return true; } + // Try to statically evaluate `operation` and return a HConstant + // containing the result of this evaluation. If `operation` cannot + // be evaluated as a constant, return nullptr. + HConstant* TryStaticEvaluation() const; + + // Apply this operation to `x`. + virtual int32_t Evaluate(int32_t x) const = 0; + virtual int64_t Evaluate(int64_t x) const = 0; + DECLARE_INSTRUCTION(UnaryOperation); private: @@ -1125,10 +1134,10 @@ class HBinaryOperation : public HExpression<2> { virtual bool CanBeMoved() const { return true; } virtual bool InstructionDataEquals(HInstruction* other) const { return true; } - // Try to statically evaluate `operation` and return an HConstant + // Try to statically evaluate `operation` and return a HConstant // containing the result of this evaluation. If `operation` cannot // be evaluated as a constant, return nullptr. - HConstant* TryStaticEvaluation(ArenaAllocator* allocator) const; + HConstant* TryStaticEvaluation() const; // Apply this operation to `x` and `y`. virtual int32_t Evaluate(int32_t x, int32_t y) const = 0; @@ -1544,6 +1553,9 @@ class HNeg : public HUnaryOperation { explicit HNeg(Primitive::Type result_type, HInstruction* input) : HUnaryOperation(result_type, input) {} + virtual int32_t Evaluate(int32_t x) const OVERRIDE { return -x; } + virtual int64_t Evaluate(int64_t x) const OVERRIDE { return -x; } + DECLARE_INSTRUCTION(Neg); private: |