[wasm] Avoid temporary signature for call descriptor

When computing a call descriptor from a {wasm::FunctionSig} (which is
{Signature<ValueType>}), we were first computing a temporary
{Signature<MachineRepresentation>}.
This CL avoids this allocation by templatizing {BuildLocations} and
accepting either a {Signature<MachineRepresentation>} or a
{Signature<ValueType>}.

As {GetWasmCallDescriptor} shows up prominently in Liftoff performance
profiles (~2% of execution time), this optimization should give a slight
improvement in Liftoff compile time.

R=ahaas@chromium.org

Bug: v8:13565
Change-Id: Ibd2b72c29b965580e91e39bef560b82cc85d1b7a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4147614
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85155}
This commit is contained in:
Clemens Backes 2023-01-09 15:52:48 +01:00 committed by V8 LUCI CQ
parent 7f9197883d
commit 7e1c6eacbf

View File

@ -8717,20 +8717,16 @@ class LinkageLocationAllocator {
int slot_offset_;
};
const MachineSignature* FunctionSigToMachineSig(Zone* zone,
const wasm::FunctionSig* fsig) {
MachineSignature::Builder builder(zone, fsig->return_count(),
fsig->parameter_count());
for (wasm::ValueType ret : fsig->returns()) {
builder.AddReturn(ret.machine_type());
}
for (wasm::ValueType param : fsig->parameters()) {
builder.AddParam(param.machine_type());
}
return builder.Get();
MachineRepresentation GetMachineRepresentation(wasm::ValueType type) {
return type.machine_representation();
}
LocationSignature* BuildLocations(Zone* zone, const MachineSignature* sig,
MachineRepresentation GetMachineRepresentation(MachineType type) {
return type.representation();
}
template <typename T>
LocationSignature* BuildLocations(Zone* zone, const Signature<T>* sig,
bool extra_callable_param,
int* parameter_slots, int* return_slots) {
int extra_params = extra_callable_param ? 2 : 1;
@ -8750,7 +8746,7 @@ LocationSignature* BuildLocations(Zone* zone, const MachineSignature* sig,
// during frame iteration.
const size_t parameter_count = sig->parameter_count();
for (size_t i = 0; i < parameter_count; i++) {
MachineRepresentation param = sig->GetParam(i).representation();
MachineRepresentation param = GetMachineRepresentation(sig->GetParam(i));
// Skip tagged parameters (e.g. any-ref).
if (IsAnyTagged(param)) continue;
auto l = params.Next(param);
@ -8761,7 +8757,7 @@ LocationSignature* BuildLocations(Zone* zone, const MachineSignature* sig,
params.EndSlotArea();
for (size_t i = 0; i < parameter_count; i++) {
MachineRepresentation param = sig->GetParam(i).representation();
MachineRepresentation param = GetMachineRepresentation(sig->GetParam(i));
// Skip untagged parameters.
if (!IsAnyTagged(param)) continue;
auto l = params.Next(param);
@ -8783,7 +8779,7 @@ LocationSignature* BuildLocations(Zone* zone, const MachineSignature* sig,
const size_t return_count = locations.return_count_;
for (size_t i = 0; i < return_count; i++) {
MachineRepresentation ret = sig->GetReturn(i).representation();
MachineRepresentation ret = GetMachineRepresentation(sig->GetReturn(i));
locations.AddReturn(rets.Next(ret));
}
@ -8791,13 +8787,6 @@ LocationSignature* BuildLocations(Zone* zone, const MachineSignature* sig,
return locations.Get();
}
LocationSignature* BuildLocations(Zone* zone, const wasm::FunctionSig* fsig,
bool extra_callable_param,
int* parameter_slots, int* return_slots) {
return BuildLocations(zone, FunctionSigToMachineSig(zone, fsig),
extra_callable_param, parameter_slots, return_slots);
}
} // namespace
// General code uses the above configuration data.