diff options
author | Roland Levillain <rpl@google.com> | 2015-03-12 17:00:14 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-12 17:00:15 +0000 |
commit | 97d30aca68af2aa4f114a01d7a7d73e4bf009fe0 (patch) | |
tree | e441187dfab14ffab41aff6576df6aaa14ce8b1c /compiler/optimizing/nodes.cc | |
parent | 3848c4fbc189287bca1298d45d07e21ec90c7c82 (diff) | |
parent | b2fd7bca70b580921eebf7c45769c39d2dfd8a5a (diff) | |
download | android_art-97d30aca68af2aa4f114a01d7a7d73e4bf009fe0.tar.gz android_art-97d30aca68af2aa4f114a01d7a7d73e4bf009fe0.tar.bz2 android_art-97d30aca68af2aa4f114a01d7a7d73e4bf009fe0.zip |
Merge "Opt compiler: Basic simplification for arithmetic operations."
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r-- | compiler/optimizing/nodes.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index a6adcca490..a90ebced69 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -673,10 +673,43 @@ HConstant* HBinaryOperation::TryStaticEvaluation() const { return nullptr; } +HConstant* HBinaryOperation::GetConstantRight() const { + if (GetRight()->IsConstant()) { + return GetRight()->AsConstant(); + } else if (IsCommutative() && GetLeft()->IsConstant()) { + return GetLeft()->AsConstant(); + } else { + return nullptr; + } +} + +// If `GetConstantRight()` returns one of the input, this returns the other +// one. Otherwise it returns nullptr. +HInstruction* HBinaryOperation::GetLeastConstantLeft() const { + HInstruction* most_constant_right = GetConstantRight(); + if (most_constant_right == nullptr) { + return nullptr; + } else if (most_constant_right == GetLeft()) { + return GetRight(); + } else { + return GetLeft(); + } +} + bool HCondition::IsBeforeWhenDisregardMoves(HIf* if_) const { return this == if_->GetPreviousDisregardingMoves(); } +HConstant* HConstant::NewConstant(ArenaAllocator* allocator, Primitive::Type type, int64_t val) { + if (type == Primitive::kPrimInt) { + DCHECK(IsInt<32>(val)); + return new (allocator) HIntConstant(val); + } else { + DCHECK_EQ(type, Primitive::kPrimLong); + return new (allocator) HLongConstant(val); + } +} + bool HInstruction::Equals(HInstruction* other) const { if (!InstructionTypeEquals(other)) return false; DCHECK_EQ(GetKind(), other->GetKind()); |