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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 if (descriptor->NeedsFrameState()) { | 823 if (descriptor->NeedsFrameState()) { |
824 frame_state_descriptor = | 824 frame_state_descriptor = |
825 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount())); | 825 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount())); |
826 } | 826 } |
827 | 827 |
828 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); | 828 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); |
829 | 829 |
830 // Compute InstructionOperands for inputs and outputs. | 830 // Compute InstructionOperands for inputs and outputs. |
831 InitializeCallBuffer(node, &buffer, true, true); | 831 InitializeCallBuffer(node, &buffer, true, true); |
832 | 832 |
833 // Push any stack arguments. | 833 // Prepare for C function call. |
834 for (Node* node : base::Reversed(buffer.pushed_nodes)) { | 834 if (descriptor->IsCFunctionCall()) { |
835 // TODO(titzer): handle pushing double parameters. | 835 InstructionOperand temps[] = {g.TempRegister()}; |
836 InstructionOperand value = | 836 size_t const temp_count = arraysize(temps); |
837 g.CanBeImmediate(node) | 837 Emit(kArchPrepareCallCFunction | |
838 ? g.UseImmediate(node) | 838 MiscField::encode(static_cast<int>(descriptor->CParameterCount())), |
839 : IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node); | 839 0, nullptr, 0, nullptr, temp_count, temps); |
840 Emit(kIA32Push, g.NoOutput(), value); | 840 |
| 841 // Poke any stack arguments. |
| 842 int slot = 0; |
| 843 for (Node* node : buffer.pushed_nodes) { |
| 844 InstructionOperand value = |
| 845 g.CanBeImmediate(node) ? g.UseImmediate(node) : g.UseRegister(node); |
| 846 Emit(kIA32Poke | MiscField::encode(slot), g.NoOutput(), value); |
| 847 ++slot; |
| 848 } |
| 849 } else { |
| 850 // Push any stack arguments. |
| 851 for (Node* node : base::Reversed(buffer.pushed_nodes)) { |
| 852 // TODO(titzer): handle pushing double parameters. |
| 853 InstructionOperand value = |
| 854 g.CanBeImmediate(node) |
| 855 ? g.UseImmediate(node) |
| 856 : IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node); |
| 857 Emit(kIA32Push, g.NoOutput(), value); |
| 858 } |
841 } | 859 } |
842 | 860 |
843 // Pass label of exception handler block. | 861 // Pass label of exception handler block. |
844 CallDescriptor::Flags flags = descriptor->flags(); | 862 CallDescriptor::Flags flags = descriptor->flags(); |
845 if (handler) { | 863 if (handler) { |
846 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); | 864 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); |
847 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); | 865 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); |
848 if (hint == IfExceptionHint::kLocallyCaught) { | 866 if (hint == IfExceptionHint::kLocallyCaught) { |
849 flags |= CallDescriptor::kHasLocalCatchHandler; | 867 flags |= CallDescriptor::kHasLocalCatchHandler; |
850 } | 868 } |
851 flags |= CallDescriptor::kHasExceptionHandler; | 869 flags |= CallDescriptor::kHasExceptionHandler; |
852 buffer.instruction_args.push_back(g.Label(handler)); | 870 buffer.instruction_args.push_back(g.Label(handler)); |
853 } | 871 } |
854 | 872 |
855 // Select the appropriate opcode based on the call type. | 873 // Select the appropriate opcode based on the call type. |
856 InstructionCode opcode; | 874 InstructionCode opcode; |
857 switch (descriptor->kind()) { | 875 switch (descriptor->kind()) { |
858 case CallDescriptor::kCallCodeObject: { | 876 case CallDescriptor::kCallAddress: |
859 opcode = kArchCallCodeObject; | 877 opcode = |
| 878 kArchCallCFunction | |
| 879 MiscField::encode(static_cast<int>(descriptor->CParameterCount())); |
860 break; | 880 break; |
861 } | 881 case CallDescriptor::kCallCodeObject: |
| 882 opcode = kArchCallCodeObject | MiscField::encode(flags); |
| 883 break; |
862 case CallDescriptor::kCallJSFunction: | 884 case CallDescriptor::kCallJSFunction: |
863 opcode = kArchCallJSFunction; | 885 opcode = kArchCallJSFunction | MiscField::encode(flags); |
864 break; | 886 break; |
865 default: | 887 default: |
866 UNREACHABLE(); | 888 UNREACHABLE(); |
867 return; | 889 return; |
868 } | 890 } |
869 opcode |= MiscField::encode(flags); | |
870 | 891 |
871 // Emit the call instruction. | 892 // Emit the call instruction. |
872 size_t const output_count = buffer.outputs.size(); | 893 size_t const output_count = buffer.outputs.size(); |
873 auto* outputs = output_count ? &buffer.outputs.front() : nullptr; | 894 auto* outputs = output_count ? &buffer.outputs.front() : nullptr; |
874 Emit(opcode, output_count, outputs, buffer.instruction_args.size(), | 895 Emit(opcode, output_count, outputs, buffer.instruction_args.size(), |
875 &buffer.instruction_args.front())->MarkAsCall(); | 896 &buffer.instruction_args.front())->MarkAsCall(); |
876 } | 897 } |
877 | 898 |
878 | 899 |
879 void InstructionSelector::VisitTailCall(Node* node) { | 900 void InstructionSelector::VisitTailCall(Node* node) { |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 if (CpuFeatures::IsSupported(SSE4_1)) { | 1340 if (CpuFeatures::IsSupported(SSE4_1)) { |
1320 flags |= MachineOperatorBuilder::kFloat64RoundDown | | 1341 flags |= MachineOperatorBuilder::kFloat64RoundDown | |
1321 MachineOperatorBuilder::kFloat64RoundTruncate; | 1342 MachineOperatorBuilder::kFloat64RoundTruncate; |
1322 } | 1343 } |
1323 return flags; | 1344 return flags; |
1324 } | 1345 } |
1325 | 1346 |
1326 } // namespace compiler | 1347 } // namespace compiler |
1327 } // namespace internal | 1348 } // namespace internal |
1328 } // namespace v8 | 1349 } // namespace v8 |
OLD | NEW |