| 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 |
| 18 class ContextSpecializationVisitor : public NullNodeVisitor { | 38 class ContextSpecializationVisitor : public NullNodeVisitor { |
| 19 public: | 39 public: |
| 20 explicit ContextSpecializationVisitor(JSContextSpecializer* spec) | 40 explicit ContextSpecializationVisitor(JSContextSpecializer* spec) |
| 21 : spec_(spec) {} | 41 : spec_(spec) {} |
| 22 | 42 |
| 23 GenericGraphVisit::Control Post(Node* node) { | 43 GenericGraphVisit::Control Post(Node* node) { |
| 24 switch (node->opcode()) { | 44 switch (node->opcode()) { |
| 25 case IrOpcode::kJSLoadContext: { | 45 case IrOpcode::kJSLoadContext: { |
| 26 Reduction r = spec_->ReduceJSLoadContext(node); | 46 Reduction r = spec_->ReduceJSLoadContext(node); |
| 27 if (r.Changed() && r.replacement() != node) { | 47 if (r.Changed() && r.replacement() != node) { |
| 28 NodeProperties::ReplaceWithValue(node, r.replacement()); | 48 ReplaceEffectfulWithValue(node, r.replacement()); |
| 29 node->RemoveAllInputs(); | |
| 30 } | 49 } |
| 31 break; | 50 break; |
| 32 } | 51 } |
| 33 case IrOpcode::kJSStoreContext: { | 52 case IrOpcode::kJSStoreContext: { |
| 34 Reduction r = spec_->ReduceJSStoreContext(node); | 53 Reduction r = spec_->ReduceJSStoreContext(node); |
| 35 if (r.Changed() && r.replacement() != node) { | 54 if (r.Changed() && r.replacement() != node) { |
| 36 NodeProperties::ReplaceWithValue(node, r.replacement()); | 55 ReplaceEffectfulWithValue(node, r.replacement()); |
| 37 node->RemoveAllInputs(); | |
| 38 } | 56 } |
| 39 break; | 57 break; |
| 40 } | 58 } |
| 41 default: | 59 default: |
| 42 break; | 60 break; |
| 43 } | 61 } |
| 44 return GenericGraphVisit::CONTINUE; | 62 return GenericGraphVisit::CONTINUE; |
| 45 } | 63 } |
| 46 | 64 |
| 47 private: | 65 private: |
| 48 JSContextSpecializer* spec_; | 66 JSContextSpecializer* spec_; |
| 49 }; | 67 }; |
| 50 | 68 |
| 51 | 69 |
| 52 void JSContextSpecializer::SpecializeToContext() { | 70 void JSContextSpecializer::SpecializeToContext() { |
| 53 NodeProperties::ReplaceWithValue(context_, | 71 ReplaceEffectfulWithValue(context_, jsgraph_->Constant(info_->context())); |
| 54 jsgraph_->Constant(info_->context())); | |
| 55 | 72 |
| 56 ContextSpecializationVisitor visitor(this); | 73 ContextSpecializationVisitor visitor(this); |
| 57 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); | 74 jsgraph_->graph()->VisitNodeInputsFromEnd(&visitor); |
| 58 } | 75 } |
| 59 | 76 |
| 60 | 77 |
| 61 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { | 78 Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) { |
| 62 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 79 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
| 63 | 80 |
| 64 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); | 81 ValueMatcher<Handle<Context> > match(NodeProperties::GetValueInput(node, 0)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); | 148 Operator* op = jsgraph_->javascript()->StoreContext(0, access.index()); |
| 132 node->set_op(op); | 149 node->set_op(op); |
| 133 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); | 150 Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate()); |
| 134 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); | 151 node->ReplaceInput(0, jsgraph_->Constant(new_context_handle)); |
| 135 | 152 |
| 136 return Reducer::Changed(node); | 153 return Reducer::Changed(node); |
| 137 } | 154 } |
| 138 } | 155 } |
| 139 } | 156 } |
| 140 } // namespace v8::internal::compiler | 157 } // namespace v8::internal::compiler |
| OLD | NEW |