| 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/base/adapters.h" | 5 #include "src/base/adapters.h" |
| 6 #include "src/compiler/instruction-selector-impl.h" | 6 #include "src/compiler/instruction-selector-impl.h" |
| 7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
| 8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) { | 836 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) { |
| 837 VisitRR(this, node, kSSEFloat64Round | MiscField::encode(kRoundToZero)); | 837 VisitRR(this, node, kSSEFloat64Round | MiscField::encode(kRoundToZero)); |
| 838 } | 838 } |
| 839 | 839 |
| 840 | 840 |
| 841 void InstructionSelector::VisitFloat64RoundTiesAway(Node* node) { | 841 void InstructionSelector::VisitFloat64RoundTiesAway(Node* node) { |
| 842 UNREACHABLE(); | 842 UNREACHABLE(); |
| 843 } | 843 } |
| 844 | 844 |
| 845 | 845 |
| 846 void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) { | 846 void InstructionSelector::EmitPrepareArguments(NodeVector* arguments, |
| 847 const CallDescriptor* descriptor, |
| 848 Node* node) { |
| 847 IA32OperandGenerator g(this); | 849 IA32OperandGenerator g(this); |
| 848 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node); | |
| 849 | |
| 850 FrameStateDescriptor* frame_state_descriptor = nullptr; | |
| 851 if (descriptor->NeedsFrameState()) { | |
| 852 frame_state_descriptor = | |
| 853 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount())); | |
| 854 } | |
| 855 | |
| 856 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); | |
| 857 | |
| 858 // Compute InstructionOperands for inputs and outputs. | |
| 859 InitializeCallBuffer(node, &buffer, true, true); | |
| 860 | 850 |
| 861 // Prepare for C function call. | 851 // Prepare for C function call. |
| 862 if (descriptor->IsCFunctionCall()) { | 852 if (descriptor->IsCFunctionCall()) { |
| 863 InstructionOperand temps[] = {g.TempRegister()}; | 853 InstructionOperand temps[] = {g.TempRegister()}; |
| 864 size_t const temp_count = arraysize(temps); | 854 size_t const temp_count = arraysize(temps); |
| 865 Emit(kArchPrepareCallCFunction | | 855 Emit(kArchPrepareCallCFunction | |
| 866 MiscField::encode(static_cast<int>(descriptor->CParameterCount())), | 856 MiscField::encode(static_cast<int>(descriptor->CParameterCount())), |
| 867 0, nullptr, 0, nullptr, temp_count, temps); | 857 0, nullptr, 0, nullptr, temp_count, temps); |
| 868 | 858 |
| 869 // Poke any stack arguments. | 859 // Poke any stack arguments. |
| 870 for (size_t n = 0; n < buffer.pushed_nodes.size(); ++n) { | 860 for (size_t n = 0; n < arguments->size(); ++n) { |
| 871 if (Node* input = buffer.pushed_nodes[n]) { | 861 if (Node* input = (*arguments)[n]) { |
| 872 int const slot = static_cast<int>(n); | 862 int const slot = static_cast<int>(n); |
| 873 InstructionOperand value = g.CanBeImmediate(node) | 863 InstructionOperand value = g.CanBeImmediate(node) |
| 874 ? g.UseImmediate(input) | 864 ? g.UseImmediate(input) |
| 875 : g.UseRegister(input); | 865 : g.UseRegister(input); |
| 876 Emit(kIA32Poke | MiscField::encode(slot), g.NoOutput(), value); | 866 Emit(kIA32Poke | MiscField::encode(slot), g.NoOutput(), value); |
| 877 } | 867 } |
| 878 } | 868 } |
| 879 } else { | 869 } else { |
| 880 // Push any stack arguments. | 870 // Push any stack arguments. |
| 881 for (Node* input : base::Reversed(buffer.pushed_nodes)) { | 871 for (Node* input : base::Reversed(*arguments)) { |
| 882 // Skip any alignment holes in pushed nodes. | 872 // Skip any alignment holes in pushed nodes. |
| 883 if (input == nullptr) continue; | 873 if (input == nullptr) continue; |
| 884 // TODO(titzer): IA32Push cannot handle stack->stack double moves | 874 // TODO(titzer): IA32Push cannot handle stack->stack double moves |
| 885 // because there is no way to encode fixed double slots. | 875 // because there is no way to encode fixed double slots. |
| 886 InstructionOperand value = | 876 InstructionOperand value = |
| 887 g.CanBeImmediate(input) | 877 g.CanBeImmediate(input) |
| 888 ? g.UseImmediate(input) | 878 ? g.UseImmediate(input) |
| 889 : IsSupported(ATOM) || | 879 : IsSupported(ATOM) || |
| 890 sequence()->IsFloat(GetVirtualRegister(input)) | 880 sequence()->IsFloat(GetVirtualRegister(input)) |
| 891 ? g.UseRegister(input) | 881 ? g.UseRegister(input) |
| 892 : g.Use(input); | 882 : g.Use(input); |
| 893 Emit(kIA32Push, g.NoOutput(), value); | 883 Emit(kIA32Push, g.NoOutput(), value); |
| 894 } | 884 } |
| 895 } | 885 } |
| 896 | |
| 897 // Pass label of exception handler block. | |
| 898 CallDescriptor::Flags flags = descriptor->flags(); | |
| 899 if (handler) { | |
| 900 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); | |
| 901 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); | |
| 902 if (hint == IfExceptionHint::kLocallyCaught) { | |
| 903 flags |= CallDescriptor::kHasLocalCatchHandler; | |
| 904 } | |
| 905 flags |= CallDescriptor::kHasExceptionHandler; | |
| 906 buffer.instruction_args.push_back(g.Label(handler)); | |
| 907 } | |
| 908 | |
| 909 // Select the appropriate opcode based on the call type. | |
| 910 InstructionCode opcode = kArchNop; | |
| 911 switch (descriptor->kind()) { | |
| 912 case CallDescriptor::kCallAddress: | |
| 913 opcode = | |
| 914 kArchCallCFunction | | |
| 915 MiscField::encode(static_cast<int>(descriptor->CParameterCount())); | |
| 916 break; | |
| 917 case CallDescriptor::kCallCodeObject: | |
| 918 opcode = kArchCallCodeObject | MiscField::encode(flags); | |
| 919 break; | |
| 920 case CallDescriptor::kCallJSFunction: | |
| 921 opcode = kArchCallJSFunction | MiscField::encode(flags); | |
| 922 break; | |
| 923 case CallDescriptor::kLazyBailout: | |
| 924 opcode = kArchLazyBailout | MiscField::encode(flags); | |
| 925 break; | |
| 926 } | |
| 927 | |
| 928 // Emit the call instruction. | |
| 929 size_t const output_count = buffer.outputs.size(); | |
| 930 auto* outputs = output_count ? &buffer.outputs.front() : nullptr; | |
| 931 Emit(opcode, output_count, outputs, buffer.instruction_args.size(), | |
| 932 &buffer.instruction_args.front())->MarkAsCall(); | |
| 933 } | 886 } |
| 934 | 887 |
| 935 | 888 |
| 936 void InstructionSelector::VisitTailCall(Node* node) { | 889 void InstructionSelector::VisitTailCall(Node* node) { |
| 937 IA32OperandGenerator g(this); | 890 IA32OperandGenerator g(this); |
| 938 CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node); | 891 CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node); |
| 939 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls); | 892 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls); |
| 940 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite); | 893 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite); |
| 941 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall); | 894 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall); |
| 942 | 895 |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 if (CpuFeatures::IsSupported(SSE4_1)) { | 1330 if (CpuFeatures::IsSupported(SSE4_1)) { |
| 1378 flags |= MachineOperatorBuilder::kFloat64RoundDown | | 1331 flags |= MachineOperatorBuilder::kFloat64RoundDown | |
| 1379 MachineOperatorBuilder::kFloat64RoundTruncate; | 1332 MachineOperatorBuilder::kFloat64RoundTruncate; |
| 1380 } | 1333 } |
| 1381 return flags; | 1334 return flags; |
| 1382 } | 1335 } |
| 1383 | 1336 |
| 1384 } // namespace compiler | 1337 } // namespace compiler |
| 1385 } // namespace internal | 1338 } // namespace internal |
| 1386 } // namespace v8 | 1339 } // namespace v8 |
| OLD | NEW |