Commit 73010d22 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][bigint] Fix calls to imports with I64 in their signature

For import wrappers, we add a special "callable" parameter as the last
parameter. This parameter is not set in the TurboFan graph but in the
code generator. Therefore this parameter has to be allocated in a
special register and cannot be lowered generically. With this CL we
detect in the CallDescriptor lowering if the last parameter is this
special "callable" parameter. If so, we preserve it in the lowered
CallDescriptor in the same register.

R=jkummerow@chromium.org

Bug: v8:7741
Change-Id: I884baa41813011c811612ec84f4e3cfe86a0e83a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1762014Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63344}
parent 6d9b7988
......@@ -3950,17 +3950,21 @@ Signature<MachineRepresentation>* CreateMachineSignature(
Signature<MachineRepresentation>::Builder builder(zone, sig->return_count(),
sig->parameter_count());
for (auto ret : sig->returns()) {
builder.AddReturn(wasm::ValueTypes::MachineRepresentationFor(ret));
if (origin == WasmGraphBuilder::kCalledFromJS) {
builder.AddReturn(MachineRepresentation::kTagged);
} else {
builder.AddReturn(wasm::ValueTypes::MachineRepresentationFor(ret));
}
}
for (auto param : sig->parameters()) {
if (origin == WasmGraphBuilder::kCalledFromWasm) {
builder.AddParam(wasm::ValueTypes::MachineRepresentationFor(param));
} else {
if (origin == WasmGraphBuilder::kCalledFromJS) {
// Parameters coming from JavaScript are always tagged values. Especially
// when the signature says that it's an I64 value, then a BigInt object is
// provided by JavaScript, and not two 32-bit parameters.
builder.AddParam(MachineRepresentation::kTagged);
} else {
builder.AddParam(wasm::ValueTypes::MachineRepresentationFor(param));
}
}
return builder.Build();
......@@ -7089,9 +7093,18 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
LocationSignature::Builder locations(zone, return_count, parameter_count);
// The last parameter may be the special callable parameter. In that case we
// have to preserve it as the last parameter, i.e. we allocate it in the new
// location signature again in the same register.
bool has_callable_param =
(call_descriptor->GetInputLocation(call_descriptor->InputCount() - 1) ==
LinkageLocation::ForRegister(kJSFunctionRegister.code(),
MachineType::TaggedPointer()));
LinkageLocationAllocator params(wasm::kGpParamRegisters,
wasm::kFpParamRegisters);
for (size_t i = 0; i < call_descriptor->ParameterCount(); i++) {
for (size_t i = 0, e = call_descriptor->ParameterCount() -
(has_callable_param ? 1 : 0);
i < e; i++) {
if (call_descriptor->GetParameterType(i) == input_type) {
for (size_t j = 0; j < num_replacements; j++) {
locations.AddParam(params.Next(output_type));
......@@ -7101,6 +7114,10 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
params.Next(call_descriptor->GetParameterType(i).representation()));
}
}
if (has_callable_param) {
locations.AddParam(LinkageLocation::ForRegister(
kJSFunctionRegister.code(), MachineType::TaggedPointer()));
}
LinkageLocationAllocator rets(wasm::kGpReturnRegisters,
wasm::kFpReturnRegisters);
......
......@@ -363,7 +363,7 @@ class WasmGraphBuilder {
wasm::FunctionSig* GetFunctionSignature() { return sig_; }
enum CallOrigin : bool { kCalledFromWasm, kCalledFromJS };
enum CallOrigin { kCalledFromWasm, kCalledFromJS };
V8_EXPORT_PRIVATE void LowerInt64(CallOrigin origin);
......
......@@ -1078,13 +1078,6 @@
'wasm/asm-wasm-f64': [SKIP],
}], # arch == x64
##############################################################################
['arch in [arm, android_arm, android_ia32, ia32, ppc, s390, s390x, mipsel, mips]', {
# TODO(ssauleau): implement BigInt<>Wasm conversion for other arch -
# crbug.com/v8/7741
'wasm/bigint-i64-to-imported-js-func': [SKIP],
}], # arch in [arm, android_arm, android_ia32, ia32, ppc, s390, s390x, mipsel, mips]
##############################################################################
['arch not in [x64, arm, arm64] or system != linux', {
# Unwinding info writer is only supported on x64, arm, and arm64 Linux
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment