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/js-context-specialization.h" | 5 #include "src/compiler/js-context-specialization.h" |
6 | 6 |
7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/js-operator.h" | 9 #include "src/compiler/js-operator.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 return NoChange(); | 28 return NoChange(); |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext( | 32 MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext( |
33 Node* node) { | 33 Node* node) { |
34 DCHECK(node->opcode() == IrOpcode::kJSLoadContext || | 34 DCHECK(node->opcode() == IrOpcode::kJSLoadContext || |
35 node->opcode() == IrOpcode::kJSStoreContext); | 35 node->opcode() == IrOpcode::kJSStoreContext); |
36 Node* const object = NodeProperties::GetValueInput(node, 0); | 36 Node* const object = NodeProperties::GetValueInput(node, 0); |
37 switch (object->opcode()) { | 37 return NodeProperties::GetSpecializationContext(object, context()); |
38 case IrOpcode::kHeapConstant: | |
39 return Handle<Context>::cast(OpParameter<Handle<HeapObject>>(object)); | |
40 case IrOpcode::kParameter: { | |
41 Node* const start = NodeProperties::GetValueInput(object, 0); | |
42 DCHECK_EQ(IrOpcode::kStart, start->opcode()); | |
43 int const index = ParameterIndexOf(object->op()); | |
44 // The context is always the last parameter to a JavaScript function, and | |
45 // {Parameter} indices start at -1, so value outputs of {Start} look like | |
46 // this: closure, receiver, param0, ..., paramN, context. | |
47 if (index == start->op()->ValueOutputCount() - 2) { | |
48 return context(); | |
49 } | |
50 break; | |
51 } | |
52 default: | |
53 break; | |
54 } | |
55 return MaybeHandle<Context>(); | |
56 } | 38 } |
57 | 39 |
58 | 40 |
59 Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { | 41 Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { |
60 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); | 42 DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); |
61 | 43 |
62 // Get the specialization context from the node. | 44 // Get the specialization context from the node. |
63 Handle<Context> context; | 45 Handle<Context> context; |
64 if (!GetSpecializationContext(node).ToHandle(&context)) return NoChange(); | 46 if (!GetSpecializationContext(node).ToHandle(&context)) return NoChange(); |
65 | 47 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 115 } |
134 | 116 |
135 | 117 |
136 JSOperatorBuilder* JSContextSpecialization::javascript() const { | 118 JSOperatorBuilder* JSContextSpecialization::javascript() const { |
137 return jsgraph()->javascript(); | 119 return jsgraph()->javascript(); |
138 } | 120 } |
139 | 121 |
140 } // namespace compiler | 122 } // namespace compiler |
141 } // namespace internal | 123 } // namespace internal |
142 } // namespace v8 | 124 } // namespace v8 |
OLD | NEW |