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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/code-stubs.h" | 6 #include "src/code-stubs.h" |
7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
8 #include "src/compiler/js-generic-lowering.h" | 8 #include "src/compiler/js-generic-lowering.h" |
9 #include "src/compiler/machine-operator.h" | 9 #include "src/compiler/machine-operator.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 100 |
101 #define REPLACE_UNIMPLEMENTED(op) \ | 101 #define REPLACE_UNIMPLEMENTED(op) \ |
102 void JSGenericLowering::Lower##op(Node* node) { UNIMPLEMENTED(); } | 102 void JSGenericLowering::Lower##op(Node* node) { UNIMPLEMENTED(); } |
103 REPLACE_UNIMPLEMENTED(JSYield) | 103 REPLACE_UNIMPLEMENTED(JSYield) |
104 REPLACE_UNIMPLEMENTED(JSDebugger) | 104 REPLACE_UNIMPLEMENTED(JSDebugger) |
105 #undef REPLACE_UNIMPLEMENTED | 105 #undef REPLACE_UNIMPLEMENTED |
106 | 106 |
107 | 107 |
108 static CallDescriptor::Flags FlagsForNode(Node* node) { | 108 static CallDescriptor::Flags FlagsForNode(Node* node) { |
109 CallDescriptor::Flags result = CallDescriptor::kNoFlags; | 109 CallDescriptor::Flags result = CallDescriptor::kNoFlags; |
110 if (OperatorProperties::HasFrameStateInput(node->op())) { | 110 if (OperatorProperties::GetFrameStateInputCount(node->op()) > 0) { |
111 result |= CallDescriptor::kNeedsFrameState; | 111 result |= CallDescriptor::kNeedsFrameState; |
112 } | 112 } |
113 return result; | 113 return result; |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token) { | 117 void JSGenericLowering::ReplaceWithCompareIC(Node* node, Token::Value token) { |
118 Callable callable = CodeFactory::CompareIC(isolate(), token); | 118 Callable callable = CodeFactory::CompareIC(isolate(), token); |
119 CallDescriptor* desc_compare = Linkage::GetStubCallDescriptor( | 119 CallDescriptor* desc_compare = Linkage::GetStubCallDescriptor( |
120 isolate(), zone(), callable.descriptor(), 0, | 120 isolate(), zone(), callable.descriptor(), 0, |
121 CallDescriptor::kPatchableCallSiteWithNop | FlagsForNode(node)); | 121 CallDescriptor::kPatchableCallSiteWithNop | FlagsForNode(node)); |
122 | 122 |
123 // Create a new call node asking a CompareIC for help. | 123 // Create a new call node asking a CompareIC for help. |
124 NodeVector inputs(zone()); | 124 NodeVector inputs(zone()); |
125 inputs.reserve(node->InputCount() + 1); | 125 inputs.reserve(node->InputCount() + 1); |
126 inputs.push_back(jsgraph()->HeapConstant(callable.code())); | 126 inputs.push_back(jsgraph()->HeapConstant(callable.code())); |
127 inputs.push_back(NodeProperties::GetValueInput(node, 0)); | 127 inputs.push_back(NodeProperties::GetValueInput(node, 0)); |
128 inputs.push_back(NodeProperties::GetValueInput(node, 1)); | 128 inputs.push_back(NodeProperties::GetValueInput(node, 1)); |
129 inputs.push_back(NodeProperties::GetContextInput(node)); | 129 inputs.push_back(NodeProperties::GetContextInput(node)); |
130 if (node->op()->HasProperty(Operator::kPure)) { | 130 if (node->op()->HasProperty(Operator::kPure)) { |
131 // A pure (strict) comparison doesn't have an effect, control or frame | 131 // A pure (strict) comparison doesn't have an effect, control or frame |
132 // state. But for the graph, we need to add control and effect inputs. | 132 // state. But for the graph, we need to add control and effect inputs. |
133 DCHECK(!OperatorProperties::HasFrameStateInput(node->op())); | 133 DCHECK(OperatorProperties::GetFrameStateInputCount(node->op()) == 0); |
134 inputs.push_back(graph()->start()); | 134 inputs.push_back(graph()->start()); |
135 inputs.push_back(graph()->start()); | 135 inputs.push_back(graph()->start()); |
136 } else { | 136 } else { |
137 DCHECK(OperatorProperties::HasFrameStateInput(node->op()) == | 137 DCHECK((OperatorProperties::GetFrameStateInputCount(node->op()) == 1) == |
138 FLAG_turbo_deoptimization); | 138 FLAG_turbo_deoptimization); |
139 if (FLAG_turbo_deoptimization) { | 139 if (FLAG_turbo_deoptimization) { |
140 inputs.push_back(NodeProperties::GetFrameStateInput(node)); | 140 inputs.push_back(NodeProperties::GetFrameStateInput(node, 0)); |
141 } | 141 } |
142 inputs.push_back(NodeProperties::GetEffectInput(node)); | 142 inputs.push_back(NodeProperties::GetEffectInput(node)); |
143 inputs.push_back(NodeProperties::GetControlInput(node)); | 143 inputs.push_back(NodeProperties::GetControlInput(node)); |
144 } | 144 } |
145 Node* compare = | 145 Node* compare = |
146 graph()->NewNode(common()->Call(desc_compare), | 146 graph()->NewNode(common()->Call(desc_compare), |
147 static_cast<int>(inputs.size()), &inputs.front()); | 147 static_cast<int>(inputs.size()), &inputs.front()); |
148 NodeProperties::SetBounds( | 148 NodeProperties::SetBounds( |
149 compare, Bounds(Type::None(zone()), Type::UntaggedSigned(zone()))); | 149 compare, Bounds(Type::None(zone()), Type::UntaggedSigned(zone()))); |
150 | 150 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 node->ReplaceInput(0, booleanize); | 191 node->ReplaceInput(0, booleanize); |
192 node->ReplaceInput(1, true_value); | 192 node->ReplaceInput(1, true_value); |
193 node->ReplaceInput(2, false_value); | 193 node->ReplaceInput(2, false_value); |
194 node->set_op(common()->Select(kMachAnyTagged)); | 194 node->set_op(common()->Select(kMachAnyTagged)); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, | 198 void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, |
199 CallDescriptor::Flags flags) { | 199 CallDescriptor::Flags flags) { |
200 Operator::Properties properties = node->op()->properties(); | 200 Operator::Properties properties = node->op()->properties(); |
201 CallDescriptor* desc = | 201 flags |= FlagsForNode(node); |
202 Linkage::GetStubCallDescriptor(isolate(), zone(), callable.descriptor(), | 202 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
203 0, flags | FlagsForNode(node), properties); | 203 isolate(), zone(), callable.descriptor(), 0, flags, properties); |
204 const Operator* new_op = common()->Call(desc); | |
205 | |
206 // Take care of frame states. | |
207 int old_frame_state_count = | |
208 OperatorProperties::GetFrameStateInputCount(node->op()); | |
209 int new_frame_state_count = | |
210 (flags & CallDescriptor::kNeedsFrameState) ? 1 : 0; | |
211 DCHECK_GE(old_frame_state_count, new_frame_state_count); | |
212 // If there are extra frame states, get rid of them. | |
213 for (int i = new_frame_state_count; i < old_frame_state_count; i++) { | |
Benedikt Meurer
2015/03/09 05:32:34
This loop doesn't look right. If you remove input
Jarin
2015/03/09 07:47:11
Good catch! Done.
| |
214 node->RemoveInput(i + NodeProperties::FirstFrameStateIndex(node)); | |
215 } | |
216 | |
217 | |
204 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 218 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
205 node->InsertInput(zone(), 0, stub_code); | 219 node->InsertInput(zone(), 0, stub_code); |
206 node->set_op(common()->Call(desc)); | 220 node->set_op(new_op); |
207 } | 221 } |
208 | 222 |
209 | 223 |
210 void JSGenericLowering::ReplaceWithBuiltinCall(Node* node, | 224 void JSGenericLowering::ReplaceWithBuiltinCall(Node* node, |
211 Builtins::JavaScript id, | 225 Builtins::JavaScript id, |
212 int nargs) { | 226 int nargs) { |
213 Operator::Properties properties = node->op()->properties(); | 227 Operator::Properties properties = node->op()->properties(); |
214 Callable callable = | 228 Callable callable = |
215 CodeFactory::CallFunction(isolate(), nargs - 1, NO_CALL_FUNCTION_FLAGS); | 229 CodeFactory::CallFunction(isolate(), nargs - 1, NO_CALL_FUNCTION_FLAGS); |
216 CallDescriptor* desc = | 230 CallDescriptor* desc = |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 490 |
477 | 491 |
478 void JSGenericLowering::LowerJSCallRuntime(Node* node) { | 492 void JSGenericLowering::LowerJSCallRuntime(Node* node) { |
479 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); | 493 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); |
480 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); | 494 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); |
481 } | 495 } |
482 | 496 |
483 } // namespace compiler | 497 } // namespace compiler |
484 } // namespace internal | 498 } // namespace internal |
485 } // namespace v8 | 499 } // namespace v8 |
OLD | NEW |