Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/compiler/ia32/instruction-selector-ia32.cc

Issue 1205023002: [turbofan] Add basic support for calling to (a subset of) C functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix argument slots. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 for (size_t n = 0; n < buffer.pushed_nodes.size(); ++n) {
843 if (Node* node = buffer.pushed_nodes[n]) {
844 int const slot = static_cast<int>(n);
845 InstructionOperand value =
846 g.CanBeImmediate(node) ? g.UseImmediate(node) : g.UseRegister(node);
847 Emit(kIA32Poke | MiscField::encode(slot), g.NoOutput(), value);
848 }
849 }
850 } else {
851 // Push any stack arguments.
852 for (Node* node : base::Reversed(buffer.pushed_nodes)) {
853 // TODO(titzer): handle pushing double parameters.
854 InstructionOperand value =
855 g.CanBeImmediate(node)
856 ? g.UseImmediate(node)
857 : IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node);
858 Emit(kIA32Push, g.NoOutput(), value);
859 }
841 } 860 }
842 861
843 // Pass label of exception handler block. 862 // Pass label of exception handler block.
844 CallDescriptor::Flags flags = descriptor->flags(); 863 CallDescriptor::Flags flags = descriptor->flags();
845 if (handler) { 864 if (handler) {
846 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode()); 865 DCHECK_EQ(IrOpcode::kIfException, handler->front()->opcode());
847 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front()); 866 IfExceptionHint hint = OpParameter<IfExceptionHint>(handler->front());
848 if (hint == IfExceptionHint::kLocallyCaught) { 867 if (hint == IfExceptionHint::kLocallyCaught) {
849 flags |= CallDescriptor::kHasLocalCatchHandler; 868 flags |= CallDescriptor::kHasLocalCatchHandler;
850 } 869 }
851 flags |= CallDescriptor::kHasExceptionHandler; 870 flags |= CallDescriptor::kHasExceptionHandler;
852 buffer.instruction_args.push_back(g.Label(handler)); 871 buffer.instruction_args.push_back(g.Label(handler));
853 } 872 }
854 873
855 // Select the appropriate opcode based on the call type. 874 // Select the appropriate opcode based on the call type.
856 InstructionCode opcode; 875 InstructionCode opcode;
857 switch (descriptor->kind()) { 876 switch (descriptor->kind()) {
858 case CallDescriptor::kCallCodeObject: { 877 case CallDescriptor::kCallAddress:
859 opcode = kArchCallCodeObject; 878 opcode =
879 kArchCallCFunction |
880 MiscField::encode(static_cast<int>(descriptor->CParameterCount()));
860 break; 881 break;
861 } 882 case CallDescriptor::kCallCodeObject:
883 opcode = kArchCallCodeObject | MiscField::encode(flags);
884 break;
862 case CallDescriptor::kCallJSFunction: 885 case CallDescriptor::kCallJSFunction:
863 opcode = kArchCallJSFunction; 886 opcode = kArchCallJSFunction | MiscField::encode(flags);
864 break; 887 break;
865 default: 888 default:
866 UNREACHABLE(); 889 UNREACHABLE();
867 return; 890 return;
868 } 891 }
869 opcode |= MiscField::encode(flags);
870 892
871 // Emit the call instruction. 893 // Emit the call instruction.
872 size_t const output_count = buffer.outputs.size(); 894 size_t const output_count = buffer.outputs.size();
873 auto* outputs = output_count ? &buffer.outputs.front() : nullptr; 895 auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
874 Emit(opcode, output_count, outputs, buffer.instruction_args.size(), 896 Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
875 &buffer.instruction_args.front())->MarkAsCall(); 897 &buffer.instruction_args.front())->MarkAsCall();
876 } 898 }
877 899
878 900
879 void InstructionSelector::VisitTailCall(Node* node) { 901 void InstructionSelector::VisitTailCall(Node* node) {
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 if (CpuFeatures::IsSupported(SSE4_1)) { 1341 if (CpuFeatures::IsSupported(SSE4_1)) {
1320 flags |= MachineOperatorBuilder::kFloat64RoundDown | 1342 flags |= MachineOperatorBuilder::kFloat64RoundDown |
1321 MachineOperatorBuilder::kFloat64RoundTruncate; 1343 MachineOperatorBuilder::kFloat64RoundTruncate;
1322 } 1344 }
1323 return flags; 1345 return flags;
1324 } 1346 }
1325 1347
1326 } // namespace compiler 1348 } // namespace compiler
1327 } // namespace internal 1349 } // namespace internal
1328 } // namespace v8 1350 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698