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