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/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 UNREACHABLE(); | 201 UNREACHABLE(); |
202 } | 202 } |
203 Node* booleanize = graph()->NewNode(op, compare, jsgraph()->ZeroConstant()); | 203 Node* booleanize = graph()->NewNode(op, compare, jsgraph()->ZeroConstant()); |
204 | 204 |
205 // Finally patch the original node to select a boolean. | 205 // Finally patch the original node to select a boolean. |
206 NodeProperties::ReplaceUses(node, node, compare, compare, compare); | 206 NodeProperties::ReplaceUses(node, node, compare, compare, compare); |
207 node->TrimInputCount(3); | 207 node->TrimInputCount(3); |
208 node->ReplaceInput(0, booleanize); | 208 node->ReplaceInput(0, booleanize); |
209 node->ReplaceInput(1, true_value); | 209 node->ReplaceInput(1, true_value); |
210 node->ReplaceInput(2, false_value); | 210 node->ReplaceInput(2, false_value); |
211 node->set_op(common()->Select(kMachAnyTagged)); | 211 NodeProperties::ChangeOp(node, common()->Select(kMachAnyTagged)); |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, | 215 void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, |
216 CallDescriptor::Flags flags) { | 216 CallDescriptor::Flags flags) { |
217 Operator::Properties properties = node->op()->properties(); | 217 Operator::Properties properties = node->op()->properties(); |
218 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 218 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
219 isolate(), zone(), callable.descriptor(), 0, flags, properties); | 219 isolate(), zone(), callable.descriptor(), 0, flags, properties); |
220 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 220 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
221 node->InsertInput(zone(), 0, stub_code); | 221 node->InsertInput(zone(), 0, stub_code); |
222 node->set_op(common()->Call(desc)); | 222 NodeProperties::ChangeOp(node, common()->Call(desc)); |
223 } | 223 } |
224 | 224 |
225 | 225 |
226 void JSGenericLowering::ReplaceWithRuntimeCall(Node* node, | 226 void JSGenericLowering::ReplaceWithRuntimeCall(Node* node, |
227 Runtime::FunctionId f, | 227 Runtime::FunctionId f, |
228 int nargs_override) { | 228 int nargs_override) { |
229 Operator::Properties properties = node->op()->properties(); | 229 Operator::Properties properties = node->op()->properties(); |
230 const Runtime::Function* fun = Runtime::FunctionForId(f); | 230 const Runtime::Function* fun = Runtime::FunctionForId(f); |
231 int nargs = (nargs_override < 0) ? fun->nargs : nargs_override; | 231 int nargs = (nargs_override < 0) ? fun->nargs : nargs_override; |
232 CallDescriptor* desc = | 232 CallDescriptor* desc = |
233 Linkage::GetRuntimeCallDescriptor(zone(), f, nargs, properties); | 233 Linkage::GetRuntimeCallDescriptor(zone(), f, nargs, properties); |
234 Node* ref = jsgraph()->ExternalConstant(ExternalReference(f, isolate())); | 234 Node* ref = jsgraph()->ExternalConstant(ExternalReference(f, isolate())); |
235 Node* arity = jsgraph()->Int32Constant(nargs); | 235 Node* arity = jsgraph()->Int32Constant(nargs); |
236 node->InsertInput(zone(), 0, jsgraph()->CEntryStubConstant(fun->result_size)); | 236 node->InsertInput(zone(), 0, jsgraph()->CEntryStubConstant(fun->result_size)); |
237 node->InsertInput(zone(), nargs + 1, ref); | 237 node->InsertInput(zone(), nargs + 1, ref); |
238 node->InsertInput(zone(), nargs + 2, arity); | 238 node->InsertInput(zone(), nargs + 2, arity); |
239 node->set_op(common()->Call(desc)); | 239 NodeProperties::ChangeOp(node, common()->Call(desc)); |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 void JSGenericLowering::LowerJSUnaryNot(Node* node) { | 243 void JSGenericLowering::LowerJSUnaryNot(Node* node) { |
244 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); | 244 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
245 Callable callable = CodeFactory::ToBoolean( | 245 Callable callable = CodeFactory::ToBoolean( |
246 isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL); | 246 isolate(), ToBooleanStub::RESULT_AS_INVERSE_ODDBALL); |
247 ReplaceWithStubCall(node, callable, | 247 ReplaceWithStubCall(node, callable, |
248 CallDescriptor::kPatchableCallSite | flags); | 248 CallDescriptor::kPatchableCallSite | flags); |
249 } | 249 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 0, graph()->NewNode(machine()->Load(kMachAnyTagged), | 433 0, graph()->NewNode(machine()->Load(kMachAnyTagged), |
434 NodeProperties::GetValueInput(node, 0), | 434 NodeProperties::GetValueInput(node, 0), |
435 jsgraph()->Int32Constant( | 435 jsgraph()->Int32Constant( |
436 Context::SlotOffset(Context::PREVIOUS_INDEX)), | 436 Context::SlotOffset(Context::PREVIOUS_INDEX)), |
437 NodeProperties::GetEffectInput(node), | 437 NodeProperties::GetEffectInput(node), |
438 graph()->start())); | 438 graph()->start())); |
439 } | 439 } |
440 node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( | 440 node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( |
441 static_cast<int>(access.index())))); | 441 static_cast<int>(access.index())))); |
442 node->AppendInput(zone(), graph()->start()); | 442 node->AppendInput(zone(), graph()->start()); |
443 node->set_op(machine()->Load(kMachAnyTagged)); | 443 NodeProperties::ChangeOp(node, machine()->Load(kMachAnyTagged)); |
444 } | 444 } |
445 | 445 |
446 | 446 |
447 void JSGenericLowering::LowerJSStoreContext(Node* node) { | 447 void JSGenericLowering::LowerJSStoreContext(Node* node) { |
448 const ContextAccess& access = ContextAccessOf(node->op()); | 448 const ContextAccess& access = ContextAccessOf(node->op()); |
449 for (size_t i = 0; i < access.depth(); ++i) { | 449 for (size_t i = 0; i < access.depth(); ++i) { |
450 node->ReplaceInput( | 450 node->ReplaceInput( |
451 0, graph()->NewNode(machine()->Load(kMachAnyTagged), | 451 0, graph()->NewNode(machine()->Load(kMachAnyTagged), |
452 NodeProperties::GetValueInput(node, 0), | 452 NodeProperties::GetValueInput(node, 0), |
453 jsgraph()->Int32Constant( | 453 jsgraph()->Int32Constant( |
454 Context::SlotOffset(Context::PREVIOUS_INDEX)), | 454 Context::SlotOffset(Context::PREVIOUS_INDEX)), |
455 NodeProperties::GetEffectInput(node), | 455 NodeProperties::GetEffectInput(node), |
456 graph()->start())); | 456 graph()->start())); |
457 } | 457 } |
458 node->ReplaceInput(2, NodeProperties::GetValueInput(node, 1)); | 458 node->ReplaceInput(2, NodeProperties::GetValueInput(node, 1)); |
459 node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( | 459 node->ReplaceInput(1, jsgraph()->Int32Constant(Context::SlotOffset( |
460 static_cast<int>(access.index())))); | 460 static_cast<int>(access.index())))); |
461 node->set_op( | 461 NodeProperties::ChangeOp(node, machine()->Store(StoreRepresentation( |
462 machine()->Store(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier))); | 462 kMachAnyTagged, kFullWriteBarrier))); |
463 } | 463 } |
464 | 464 |
465 | 465 |
466 void JSGenericLowering::LowerJSLoadDynamicGlobal(Node* node) { | 466 void JSGenericLowering::LowerJSLoadDynamicGlobal(Node* node) { |
467 const DynamicGlobalAccess& access = DynamicGlobalAccessOf(node->op()); | 467 const DynamicGlobalAccess& access = DynamicGlobalAccessOf(node->op()); |
468 Runtime::FunctionId function_id = | 468 Runtime::FunctionId function_id = |
469 (access.typeof_mode() == NOT_INSIDE_TYPEOF) | 469 (access.typeof_mode() == NOT_INSIDE_TYPEOF) |
470 ? Runtime::kLoadLookupSlot | 470 ? Runtime::kLoadLookupSlot |
471 : Runtime::kLoadLookupSlotNoReferenceError; | 471 : Runtime::kLoadLookupSlotNoReferenceError; |
472 Node* projection = graph()->NewNode(common()->Projection(0), node); | 472 Node* projection = graph()->NewNode(common()->Projection(0), node); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 Linkage::GetStubCallDescriptor(isolate(), zone(), d, arity - 1, flags); | 544 Linkage::GetStubCallDescriptor(isolate(), zone(), d, arity - 1, flags); |
545 Node* stub_code = jsgraph()->HeapConstant(stub.GetCode()); | 545 Node* stub_code = jsgraph()->HeapConstant(stub.GetCode()); |
546 Node* actual_construct = NodeProperties::GetValueInput(node, 0); | 546 Node* actual_construct = NodeProperties::GetValueInput(node, 0); |
547 Node* original_construct = NodeProperties::GetValueInput(node, arity - 1); | 547 Node* original_construct = NodeProperties::GetValueInput(node, arity - 1); |
548 node->RemoveInput(arity - 1); // Drop original constructor. | 548 node->RemoveInput(arity - 1); // Drop original constructor. |
549 node->InsertInput(zone(), 0, stub_code); | 549 node->InsertInput(zone(), 0, stub_code); |
550 node->InsertInput(zone(), 1, jsgraph()->Int32Constant(arity - 2)); | 550 node->InsertInput(zone(), 1, jsgraph()->Int32Constant(arity - 2)); |
551 node->InsertInput(zone(), 2, actual_construct); | 551 node->InsertInput(zone(), 2, actual_construct); |
552 node->InsertInput(zone(), 3, original_construct); | 552 node->InsertInput(zone(), 3, original_construct); |
553 node->InsertInput(zone(), 4, jsgraph()->UndefinedConstant()); | 553 node->InsertInput(zone(), 4, jsgraph()->UndefinedConstant()); |
554 node->set_op(common()->Call(desc)); | 554 NodeProperties::ChangeOp(node, common()->Call(desc)); |
555 } | 555 } |
556 | 556 |
557 | 557 |
558 void JSGenericLowering::LowerJSCallFunction(Node* node) { | 558 void JSGenericLowering::LowerJSCallFunction(Node* node) { |
559 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | 559 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
560 int arg_count = static_cast<int>(p.arity() - 2); | 560 int arg_count = static_cast<int>(p.arity() - 2); |
561 CallFunctionStub stub(isolate(), arg_count, p.flags()); | 561 CallFunctionStub stub(isolate(), arg_count, p.flags()); |
562 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); | 562 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); |
563 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); | 563 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
564 if (p.AllowTailCalls()) { | 564 if (p.AllowTailCalls()) { |
565 flags |= CallDescriptor::kSupportsTailCalls; | 565 flags |= CallDescriptor::kSupportsTailCalls; |
566 } | 566 } |
567 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 567 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
568 isolate(), zone(), d, static_cast<int>(p.arity() - 1), flags); | 568 isolate(), zone(), d, static_cast<int>(p.arity() - 1), flags); |
569 Node* stub_code = jsgraph()->HeapConstant(stub.GetCode()); | 569 Node* stub_code = jsgraph()->HeapConstant(stub.GetCode()); |
570 node->InsertInput(zone(), 0, stub_code); | 570 node->InsertInput(zone(), 0, stub_code); |
571 node->set_op(common()->Call(desc)); | 571 NodeProperties::ChangeOp(node, common()->Call(desc)); |
572 } | 572 } |
573 | 573 |
574 | 574 |
575 void JSGenericLowering::LowerJSCallRuntime(Node* node) { | 575 void JSGenericLowering::LowerJSCallRuntime(Node* node) { |
576 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); | 576 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); |
577 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); | 577 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); |
578 } | 578 } |
579 | 579 |
580 | 580 |
581 void JSGenericLowering::LowerJSForInDone(Node* node) { | 581 void JSGenericLowering::LowerJSForInDone(Node* node) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 841 } |
842 | 842 |
843 | 843 |
844 MachineOperatorBuilder* JSGenericLowering::machine() const { | 844 MachineOperatorBuilder* JSGenericLowering::machine() const { |
845 return jsgraph()->machine(); | 845 return jsgraph()->machine(); |
846 } | 846 } |
847 | 847 |
848 } // namespace compiler | 848 } // namespace compiler |
849 } // namespace internal | 849 } // namespace internal |
850 } // namespace v8 | 850 } // namespace v8 |
OLD | NEW |