summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/nodes.cc
diff options
context:
space:
mode:
authorAlexandre Rames <alexandre.rames@arm.com>2015-03-11 16:48:16 +0000
committerAlexandre Rames <alexandre.rames@arm.com>2015-03-11 16:48:16 +0000
commitb2fd7bca70b580921eebf7c45769c39d2dfd8a5a (patch)
treec5dae29519df73f889ba14495eb79d545cd7d6e5 /compiler/optimizing/nodes.cc
parent356286f989941ac495417195e4129aaceaf36a83 (diff)
downloadart-b2fd7bca70b580921eebf7c45769c39d2dfd8a5a.zip
art-b2fd7bca70b580921eebf7c45769c39d2dfd8a5a.tar.gz
art-b2fd7bca70b580921eebf7c45769c39d2dfd8a5a.tar.bz2
Opt compiler: Basic simplification for arithmetic operations.
The optimisations in this patch do not look further than the inputs of each operation. Change-Id: Iddd0ab6b360b9e7bb042db22086d51a31be85530
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r--compiler/optimizing/nodes.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index e51bbc3..adcadf5 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());