summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r--compiler/optimizing/nodes.h62
1 files changed, 54 insertions, 8 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 7e075644ef..b7dd756452 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -113,6 +113,7 @@ class HGraph : public ArenaObject<kArenaAllocMisc> {
number_of_vregs_(0),
number_of_in_vregs_(0),
temporaries_vreg_slots_(0),
+ has_array_accesses_(false),
current_instruction_id_(start_instruction_id) {}
ArenaAllocator* GetArena() const { return arena_; }
@@ -199,6 +200,14 @@ class HGraph : public ArenaObject<kArenaAllocMisc> {
return reverse_post_order_;
}
+ bool HasArrayAccesses() const {
+ return has_array_accesses_;
+ }
+
+ void SetHasArrayAccesses(bool value) {
+ has_array_accesses_ = value;
+ }
+
HNullConstant* GetNullConstant();
private:
@@ -236,6 +245,9 @@ class HGraph : public ArenaObject<kArenaAllocMisc> {
// Number of vreg size slots that the temporaries use (used in baseline compiler).
size_t temporaries_vreg_slots_;
+ // Has array accesses. We can totally skip BCE if it's false.
+ bool has_array_accesses_;
+
// The current id to assign to a newly added instruction. See HInstruction.id_.
int32_t current_instruction_id_;
@@ -1500,7 +1512,39 @@ class HBinaryOperation : public HExpression<2> {
HInstruction* GetRight() const { return InputAt(1); }
Primitive::Type GetResultType() const { return GetType(); }
- virtual bool IsCommutative() { return false; }
+ virtual bool IsCommutative() const { return false; }
+
+ // Put constant on the right.
+ // Returns whether order is changed.
+ bool OrderInputsWithConstantOnTheRight() {
+ HInstruction* left = InputAt(0);
+ HInstruction* right = InputAt(1);
+ if (left->IsConstant() && !right->IsConstant()) {
+ ReplaceInput(right, 0);
+ ReplaceInput(left, 1);
+ return true;
+ }
+ return false;
+ }
+
+ // Order inputs by instruction id, but favor constant on the right side.
+ // This helps GVN for commutative ops.
+ void OrderInputs() {
+ DCHECK(IsCommutative());
+ HInstruction* left = InputAt(0);
+ HInstruction* right = InputAt(1);
+ if (left == right || (!left->IsConstant() && right->IsConstant())) {
+ return;
+ }
+ if (OrderInputsWithConstantOnTheRight()) {
+ return;
+ }
+ // Order according to instruction id.
+ if (left->GetId() > right->GetId()) {
+ ReplaceInput(right, 0);
+ ReplaceInput(left, 1);
+ }
+ }
virtual bool CanBeMoved() const { return true; }
virtual bool InstructionDataEquals(HInstruction* other) const {
@@ -1529,8 +1573,6 @@ class HCondition : public HBinaryOperation {
: HBinaryOperation(Primitive::kPrimBoolean, first, second),
needs_materialization_(true) {}
- virtual bool IsCommutative() { return true; }
-
bool NeedsMaterialization() const { return needs_materialization_; }
void ClearNeedsMaterialization() { needs_materialization_ = false; }
@@ -1556,6 +1598,8 @@ class HEqual : public HCondition {
HEqual(HInstruction* first, HInstruction* second)
: HCondition(first, second) {}
+ bool IsCommutative() const OVERRIDE { return true; }
+
virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
return x == y ? 1 : 0;
}
@@ -1578,6 +1622,8 @@ class HNotEqual : public HCondition {
HNotEqual(HInstruction* first, HInstruction* second)
: HCondition(first, second) {}
+ bool IsCommutative() const OVERRIDE { return true; }
+
virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
return x != y ? 1 : 0;
}
@@ -2136,7 +2182,7 @@ class HAdd : public HBinaryOperation {
HAdd(Primitive::Type result_type, HInstruction* left, HInstruction* right)
: HBinaryOperation(result_type, left, right) {}
- virtual bool IsCommutative() { return true; }
+ virtual bool IsCommutative() const OVERRIDE { return true; }
virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
return x + y;
@@ -2174,7 +2220,7 @@ class HMul : public HBinaryOperation {
HMul(Primitive::Type result_type, HInstruction* left, HInstruction* right)
: HBinaryOperation(result_type, left, right) {}
- virtual bool IsCommutative() { return true; }
+ virtual bool IsCommutative() const OVERRIDE { return true; }
virtual int32_t Evaluate(int32_t x, int32_t y) const { return x * y; }
virtual int64_t Evaluate(int64_t x, int64_t y) const { return x * y; }
@@ -2323,7 +2369,7 @@ class HAnd : public HBinaryOperation {
HAnd(Primitive::Type result_type, HInstruction* left, HInstruction* right)
: HBinaryOperation(result_type, left, right) {}
- bool IsCommutative() OVERRIDE { return true; }
+ bool IsCommutative() const OVERRIDE { return true; }
int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x & y; }
int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x & y; }
@@ -2339,7 +2385,7 @@ class HOr : public HBinaryOperation {
HOr(Primitive::Type result_type, HInstruction* left, HInstruction* right)
: HBinaryOperation(result_type, left, right) {}
- bool IsCommutative() OVERRIDE { return true; }
+ bool IsCommutative() const OVERRIDE { return true; }
int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x | y; }
int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x | y; }
@@ -2355,7 +2401,7 @@ class HXor : public HBinaryOperation {
HXor(Primitive::Type result_type, HInstruction* left, HInstruction* right)
: HBinaryOperation(result_type, left, right) {}
- bool IsCommutative() OVERRIDE { return true; }
+ bool IsCommutative() const OVERRIDE { return true; }
int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x ^ y; }
int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x ^ y; }