Index: src/compiler/wasm-linkage.cc |
diff --git a/src/compiler/wasm-linkage.cc b/src/compiler/wasm-linkage.cc |
index 7dd36621e9ae97f454c73c0f4fc9d554d97ca0e9..09a697ed8a76f2098b220d41545f8a27dced4872 100644 |
--- a/src/compiler/wasm-linkage.cc |
+++ b/src/compiler/wasm-linkage.cc |
@@ -191,15 +191,7 @@ struct Allocator { |
}; |
} // namespace |
- |
-// General code uses the above configuration data. |
-CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, |
- FunctionSig* fsig) { |
- MachineSignature::Builder msig(zone, fsig->return_count(), |
- fsig->parameter_count()); |
- LocationSignature::Builder locations(zone, fsig->return_count(), |
- fsig->parameter_count()); |
- |
+static Allocator GetReturnRegisters() { |
#ifdef GP_RETURN_REGISTERS |
static const Register kGPReturnRegisters[] = {GP_RETURN_REGISTERS}; |
static const int kGPReturnRegistersCount = |
@@ -221,14 +213,10 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, |
Allocator rets(kGPReturnRegisters, kGPReturnRegistersCount, |
kFPReturnRegisters, kFPReturnRegistersCount); |
- // Add return location(s). |
- const int return_count = static_cast<int>(locations.return_count_); |
- for (int i = 0; i < return_count; i++) { |
- LocalType ret = fsig->GetReturn(i); |
- msig.AddReturn(MachineTypeFor(ret)); |
- locations.AddReturn(rets.Next(ret)); |
- } |
+ return rets; |
+} |
+static Allocator GetParameterRegisters() { |
#ifdef GP_PARAM_REGISTERS |
static const Register kGPParamRegisters[] = {GP_PARAM_REGISTERS}; |
static const int kGPParamRegistersCount = |
@@ -250,6 +238,29 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, |
Allocator params(kGPParamRegisters, kGPParamRegistersCount, kFPParamRegisters, |
kFPParamRegistersCount); |
+ return params; |
+} |
+ |
+// General code uses the above configuration data. |
+CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, |
+ FunctionSig* fsig) { |
+ MachineSignature::Builder msig(zone, fsig->return_count(), |
+ fsig->parameter_count()); |
+ LocationSignature::Builder locations(zone, fsig->return_count(), |
+ fsig->parameter_count()); |
+ |
+ Allocator rets = GetReturnRegisters(); |
+ |
+ // Add return location(s). |
+ const int return_count = static_cast<int>(locations.return_count_); |
+ for (int i = 0; i < return_count; i++) { |
+ LocalType ret = fsig->GetReturn(i); |
+ msig.AddReturn(MachineTypeFor(ret)); |
+ locations.AddReturn(rets.Next(ret)); |
+ } |
+ |
+ Allocator params = GetParameterRegisters(); |
+ |
// Add register and/or stack parameter(s). |
const int parameter_count = static_cast<int>(fsig->parameter_count()); |
for (int i = 0; i < parameter_count; i++) { |
@@ -276,8 +287,82 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, |
kCalleeSaveRegisters, // callee-saved registers |
kCalleeSaveFPRegisters, // callee-saved fp regs |
CallDescriptor::kUseNativeStack, // flags |
- "c-call"); |
+ "wasm-call"); |
+} |
+ |
+CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor( |
+ Zone* zone, CallDescriptor* descriptor) { |
+ const MachineSignature* signature = descriptor->GetMachineSignature(); |
+ size_t parameter_count = signature->parameter_count(); |
+ size_t return_count = signature->return_count(); |
+ for (size_t i = 0; i < signature->parameter_count(); i++) { |
+ if (signature->GetParam(i) == MachineType::Int64()) { |
+ // For each int64 input we get two int32 inputs. |
+ parameter_count++; |
+ } |
+ } |
+ for (size_t i = 0; i < signature->return_count(); i++) { |
+ if (signature->GetReturn(i) == MachineType::Int64()) { |
+ // For each int64 return we get two int32 returns. |
+ return_count++; |
+ } |
+ } |
+ if (parameter_count == signature->parameter_count() && |
+ return_count == signature->return_count()) { |
+ // If there is no int64 parameter or return value, we can just return the |
+ // original descriptor. |
+ return descriptor; |
+ } |
+ |
+ MachineSignature::Builder msig(zone, return_count, parameter_count); |
+ LocationSignature::Builder locations(zone, return_count, parameter_count); |
+ |
+ Allocator rets = GetReturnRegisters(); |
+ |
+ for (size_t i = 0; i < signature->return_count(); i++) { |
+ if (signature->GetReturn(i) == MachineType::Int64()) { |
+ // For each int64 return we get two int32 returns. |
+ msig.AddReturn(MachineType::Int32()); |
+ msig.AddReturn(MachineType::Int32()); |
+ locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); |
+ locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); |
+ } else { |
+ msig.AddReturn(signature->GetReturn(i)); |
+ locations.AddReturn(rets.Next(signature->GetReturn(i).representation())); |
+ } |
+ } |
+ |
+ Allocator params = GetParameterRegisters(); |
+ |
+ for (size_t i = 0; i < signature->parameter_count(); i++) { |
+ if (signature->GetParam(i) == MachineType::Int64()) { |
+ // For each int64 input we get two int32 inputs. |
+ msig.AddParam(MachineType::Int32()); |
+ msig.AddParam(MachineType::Int32()); |
+ locations.AddParam(params.Next(MachineRepresentation::kWord32)); |
+ locations.AddParam(params.Next(MachineRepresentation::kWord32)); |
+ } else { |
+ msig.AddParam(signature->GetParam(i)); |
+ locations.AddParam(params.Next(signature->GetParam(i).representation())); |
+ } |
+ } |
+ |
+ return new (zone) CallDescriptor( // -- |
+ descriptor->kind(), // kind |
+ descriptor->GetInputType(0), // target MachineType |
+ descriptor->GetInputLocation(0), // target location |
+ msig.Build(), // machine_sig |
+ locations.Build(), // location_sig |
+ params.stack_offset, // stack_parameter_count |
+ descriptor->properties(), // properties |
+ descriptor->CalleeSavedRegisters(), // callee-saved registers |
+ descriptor->CalleeSavedFPRegisters(), // callee-saved fp regs |
+ descriptor->flags(), // flags |
+ descriptor->debug_name()); |
+ |
+ return descriptor; |
} |
+ |
} // namespace wasm |
} // namespace internal |
} // namespace v8 |