Commit dd7a9e31 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm] Early exit in ReplaceTypeInCallDescriptorWith

Bug: v8:12986
Change-Id: I5aa8dbc7f387856cc017ac9fd72ff57bc1d44af9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3716469Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81282}
parent 6f398553
......@@ -8504,37 +8504,39 @@ CallDescriptor* ReplaceTypeInCallDescriptorWith(
size_t parameter_count =
call_descriptor->ParameterCount() - (extra_callable_param ? 2 : 1);
// Precompute if the descriptor contains {from}.
bool needs_change = false;
for (size_t i = 0; !needs_change && i < return_count; i++) {
needs_change = call_descriptor->GetReturnType(i) == from;
}
for (size_t i = 1; !needs_change && i < parameter_count + 1; i++) {
needs_change = call_descriptor->GetParameterType(i) == from;
}
if (!needs_change) return const_cast<CallDescriptor*>(call_descriptor);
std::vector<MachineType> reps;
bool changed = false;
for (int i = 0; i < static_cast<int>(call_descriptor->ReturnCount()); i++) {
for (size_t i = 0, limit = return_count; i < limit; i++) {
MachineType initial_type = call_descriptor->GetReturnType(i);
if (initial_type == from) {
for (size_t j = 0; j < num_replacements; j++) reps.push_back(to);
return_count += num_replacements - 1;
changed = true;
} else {
reps.push_back(initial_type);
}
}
// Disregard the instance (first) parameter, and the extra callable (last)
// parameter if present.
for (int i = 1; i < static_cast<int>(call_descriptor->ParameterCount()) -
(extra_callable_param ? 1 : 0);
i++) {
// Disregard the instance (first) parameter.
for (size_t i = 1, limit = parameter_count + 1; i < limit; i++) {
MachineType initial_type = call_descriptor->GetParameterType(i);
if (initial_type == from) {
for (size_t j = 0; j < num_replacements; j++) reps.push_back(to);
parameter_count += num_replacements - 1;
changed = true;
} else {
reps.push_back(initial_type);
}
}
if (!changed) return const_cast<CallDescriptor*>(call_descriptor);
MachineSignature sig(return_count, parameter_count, reps.data());
int parameter_slots;
......
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