OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/load-elimination.h" |
| 6 |
| 7 #include "src/compiler/node-properties-inl.h" |
| 8 #include "src/compiler/simplified-operator.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace compiler { |
| 13 |
| 14 LoadElimination::~LoadElimination() {} |
| 15 |
| 16 |
| 17 Reduction LoadElimination::Reduce(Node* node) { |
| 18 switch (node->opcode()) { |
| 19 case IrOpcode::kLoadField: |
| 20 return ReduceLoadField(node); |
| 21 default: |
| 22 break; |
| 23 } |
| 24 return NoChange(); |
| 25 } |
| 26 |
| 27 |
| 28 Reduction LoadElimination::ReduceLoadField(Node* node) { |
| 29 DCHECK_EQ(IrOpcode::kLoadField, node->opcode()); |
| 30 FieldAccess const access = FieldAccessOf(node->op()); |
| 31 Node* const object = NodeProperties::GetValueInput(node, 0); |
| 32 for (Node* effect = NodeProperties::GetEffectInput(node);; |
| 33 effect = NodeProperties::GetEffectInput(effect)) { |
| 34 switch (effect->opcode()) { |
| 35 case IrOpcode::kLoadField: { |
| 36 if (object == NodeProperties::GetValueInput(effect, 0) && |
| 37 access == FieldAccessOf(effect->op())) { |
| 38 Node* const value = effect; |
| 39 NodeProperties::ReplaceWithValue(node, value); |
| 40 return Replace(value); |
| 41 } |
| 42 break; |
| 43 } |
| 44 case IrOpcode::kStoreField: { |
| 45 if (access == FieldAccessOf(effect->op())) { |
| 46 if (object == NodeProperties::GetValueInput(effect, 0)) { |
| 47 Node* const value = NodeProperties::GetValueInput(effect, 1); |
| 48 NodeProperties::ReplaceWithValue(node, value); |
| 49 return Replace(value); |
| 50 } |
| 51 // TODO(turbofan): Alias analysis to the rescue? |
| 52 return NoChange(); |
| 53 } |
| 54 break; |
| 55 } |
| 56 case IrOpcode::kStoreBuffer: |
| 57 case IrOpcode::kStoreElement: { |
| 58 // These can never interfere with field loads. |
| 59 break; |
| 60 } |
| 61 default: { |
| 62 if (!effect->op()->HasProperty(Operator::kNoWrite) || |
| 63 effect->op()->EffectInputCount() != 1) { |
| 64 return NoChange(); |
| 65 } |
| 66 break; |
| 67 } |
| 68 } |
| 69 } |
| 70 UNREACHABLE(); |
| 71 return NoChange(); |
| 72 } |
| 73 |
| 74 } // namespace compiler |
| 75 } // namespace internal |
| 76 } // namespace v8 |
OLD | NEW |