| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
| 6 #include "src/compiler/generic-node-inl.h" | 6 #include "src/compiler/generic-node-inl.h" |
| 7 #include "src/compiler/graph-inl.h" | 7 #include "src/compiler/graph-inl.h" |
| 8 #include "src/compiler/js-context-specialization.h" | 8 #include "src/compiler/js-context-specialization.h" |
| 9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
| 10 #include "src/compiler/node-aux-data-inl.h" | 10 #include "src/compiler/node-aux-data-inl.h" |
| 11 #include "src/compiler/node-matchers.h" | 11 #include "src/compiler/node-matchers.h" |
| 12 #include "src/compiler/node-properties-inl.h" | 12 #include "src/compiler/node-properties-inl.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 namespace compiler { | 16 namespace compiler { |
| 17 | 17 |
| 18 // TODO(titzer): factor this out to a common routine with js-typed-lowering. | |
| 19 static void ReplaceEffectfulWithValue(Node* node, Node* value) { | |
| 20 Node* effect = NULL; | |
| 21 if (OperatorProperties::HasEffectInput(node->op())) { | |
| 22 effect = NodeProperties::GetEffectInput(node); | |
| 23 } | |
| 24 | |
| 25 // Requires distinguishing between value and effect edges. | |
| 26 UseIter iter = node->uses().begin(); | |
| 27 while (iter != node->uses().end()) { | |
| 28 if (NodeProperties::IsEffectEdge(iter.edge())) { | |
| 29 DCHECK_NE(NULL, effect); | |
| 30 iter = iter.UpdateToAndIncrement(effect); | |
| 31 } else { | |
| 32 iter = iter.UpdateToAndIncrement(value); | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 | |
| 38 class ContextSpecializationVisitor : public NullNodeVisitor { | 18 class ContextSpecializationVisitor : public NullNodeVisitor { |
| 39 public: | 19 public: |
| 40 explicit ContextSpecializationVisitor(JSContextSpecializer* spec) | 20 explicit ContextSpecializationVisitor(JSContextSpecializer* spec) |
| 41 : spec_(spec) {} | 21 : spec_(spec) {} |
| 42 | 22 |
| 43 GenericGraphVisit::Control Post(Node* node) { | 23 GenericGraphVisit::Control Post(Node* node) { |
| 44 switch (node->opcode()) { | 24 switch (node->opcode()) { |
| 45 case IrOpcode::kJSLoadContext: { | 25 case IrOpcode::kJSLoadContext: { |
| 46 Reduction r = spec_->ReduceJSLoadContext(node); | 26 Reduction r = spec_->ReduceJSLoadContext(node); |
| 47 if (r.Changed() && r.replacement() != node) { | 27 if (r.Changed() && r.replacement() != node) { |
| 48 ReplaceEffectfulWithValue(node, r.replacement()); | 28 NodeProperties::ReplaceWithValue(node, r.replacement()); |
| 29 node->RemoveAllInputs(); |
| 49 } | 30 } |
| 50 break; | 31 break; |
| 51 } | 32 } |
| 52 case IrOpcode::kJSStoreContext: { | 33 case IrOpcode::kJSStoreContext: { |
| 53 Reduction r = spec_->ReduceJSStoreContext(node); | 34 Reduction r = spec_->ReduceJSStoreContext(node); |
| 54 if (r.Changed() && r.replacement() != node) { | 35 if (r.Changed() && r.replacement() != node) { |
| 55 ReplaceEffectfulWithValue(node, r.replacement()); | 36 NodeProperties::ReplaceWithValue(node, r.replacement()); |
| 37 node->RemoveAllInputs(); |
| 56 } | 38 } |
| 57 break; | 39 break; |
| 58 } | 40 } |
| 59 default: | 41 default: |
| 60 break; | 42 break; |
| 61 } | 43 } |
| 62 return GenericGraphVisit::CONTINUE; | 44 return GenericGraphVisit::CONTINUE; |
| 63 } | 45 } |
| 64 | 46 |
| 65 private: | 47 private: |
| 66 JSContextSpecializer* spec_; | 48 JSContextSpecializer* spec_; |
| 67 }; | 49 }; |
| 68 | 50 |
| 69 | 51 |
| 70 void JSContextSpecializer::SpecializeToContext() { | 52 void JSContextSpecializer::SpecializeToContext() { |
| 71 ReplaceEffectfulWithValue(context_, jsgraph_->Constant(info_->context())); | 53 NodeProperties::ReplaceWithValue(context_, |
| 54 jsgraph_->Constant(info_->context())); |
| 72 | 55 |
| 73 ContextSpecializationVisitor visitor(this); | 56 ContextSpecializationVisitor visitor(this); |
| 74 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); | 57 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); |
| 75 } | 58 } |
| 76 | 59 |
| 77 | 60 |
| 78 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { | 61 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { |
| 79 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 62 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
| 80 | 63 |
| 81 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); | 64 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); | 131 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); |
| 149 node->set_op(op); | 132 node->set_op(op); |
| 150 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); | 133 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); |
| 151 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); | 134 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); |
| 152 | 135 |
| 153 return Reducer::Changed(node); | 136 return Reducer::Changed(node); |
| 154 } | 137 } |
| 155 } | 138 } |
| 156 } | 139 } |
| 157 } // namespace v8::internal::compiler | 140 } // namespace v8::internal::compiler |
| OLD | NEW |