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.cc | |
parent | 88cb1755e1d6acaed0f66ce65d7a2a4465053342 (diff) |
Constant folding on unary operations in the optimizing compiler.
Change-Id: I4b77afa2a89f5ad2eedd4d6c0c6c382585419349
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r-- | compiler/optimizing/nodes.cc | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 10c60140ec..a219b97cc8 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -572,15 +572,26 @@ void HGraphVisitor::VisitBasicBlock(HBasicBlock* block) { } } -HConstant* HBinaryOperation::TryStaticEvaluation(ArenaAllocator* allocator) const { +HConstant* HUnaryOperation::TryStaticEvaluation() const { + if (GetInput()->IsIntConstant()) { + int32_t value = Evaluate(GetInput()->AsIntConstant()->GetValue()); + return new(GetBlock()->GetGraph()->GetArena()) HIntConstant(value); + } else if (GetInput()->IsLongConstant()) { + LOG(FATAL) << "Static evaluation of long unary operations is not yet implemented."; + return nullptr; + } + return nullptr; +} + +HConstant* HBinaryOperation::TryStaticEvaluation() const { if (GetLeft()->IsIntConstant() && GetRight()->IsIntConstant()) { int32_t value = Evaluate(GetLeft()->AsIntConstant()->GetValue(), GetRight()->AsIntConstant()->GetValue()); - return new(allocator) HIntConstant(value); + return new(GetBlock()->GetGraph()->GetArena()) HIntConstant(value); } else if (GetLeft()->IsLongConstant() && GetRight()->IsLongConstant()) { int64_t value = Evaluate(GetLeft()->AsLongConstant()->GetValue(), GetRight()->AsLongConstant()->GetValue()); - return new(allocator) HLongConstant(value); + return new(GetBlock()->GetGraph()->GetArena()) HLongConstant(value); } return nullptr; } |