Commit aae6b56e authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

Revert "[compiler] Rework calculation to start of return slots"

This reverts commit 2f3cda58.

Reason for revert: Failing tests on V8 Linux - arm64 - sim - MSAN
https://ci.chromium.org/p/v8/builders/ci/V8%20Linux%20-%20arm64%20-%20sim%20-%20MSAN/36207?

Original change's description:
> [compiler] Rework calculation to start of return slots
>
> - Changes GetOffsetToReturns to take into account return slot padding
>   and argument padding.
> - Changes GetStackParameterDelta to use GetOffsetToReturns for the SP
>   delta calculation.
> - Removes GetFirstUnusedStackSlot.
>
> Change-Id: I13df72e86750c62798bae262f0560cf1d7f981db
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2593306
> Commit-Queue: Bill Budge <bbudge@chromium.org>
> Reviewed-by: Andreas Haas <ahaas@chromium.org>
> Reviewed-by: Georg Neis <neis@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#72078}

TBR=bbudge@chromium.org,neis@chromium.org,ahaas@chromium.org

Change-Id: I2b35efcd27a5677ed56cff5c4096ccc91fd18209
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2627910Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72079}
parent 2f3cda58
......@@ -3076,7 +3076,7 @@ void InstructionSelector::VisitTailCall(Node* node) {
// instruction. This is used by backends that need to pad arguments for stack
// alignment, in order to store an optional slot of padding above the
// arguments.
const int optional_padding_slot = callee->GetOffsetToReturns();
const int optional_padding_slot = callee->GetFirstUnusedStackSlot();
buffer.instruction_args.push_back(g.TempImmediate(optional_padding_slot));
const int first_unused_stack_slot =
......
......@@ -77,6 +77,21 @@ MachineSignature* CallDescriptor::GetMachineSignature(Zone* zone) const {
return zone->New<MachineSignature>(return_count, param_count, types);
}
int CallDescriptor::GetFirstUnusedStackSlot() const {
int slots_above_sp = 0;
for (size_t i = 0; i < InputCount(); ++i) {
LinkageLocation operand = GetInputLocation(i);
if (!operand.IsRegister()) {
int new_candidate =
-operand.GetLocation() + operand.GetSizeInPointers() - 1;
if (new_candidate > slots_above_sp) {
slots_above_sp = new_candidate;
}
}
}
return slots_above_sp;
}
int CallDescriptor::GetStackParameterDelta(
CallDescriptor const* tail_caller) const {
// In the IsTailCallForTierUp case, the callee has
......@@ -85,8 +100,8 @@ int CallDescriptor::GetStackParameterDelta(
// inputs to the TailCall node, since they already exist on the stack.
if (IsTailCallForTierUp()) return 0;
int callee_slots_above_sp = GetOffsetToReturns();
int tail_caller_slots_above_sp = tail_caller->GetOffsetToReturns();
int callee_slots_above_sp = GetFirstUnusedStackSlot();
int tail_caller_slots_above_sp = tail_caller->GetFirstUnusedStackSlot();
int stack_param_delta = callee_slots_above_sp - tail_caller_slots_above_sp;
if (ShouldPadArguments(stack_param_delta)) {
if (callee_slots_above_sp % 2 != 0) {
......@@ -105,37 +120,9 @@ int CallDescriptor::GetStackParameterDelta(
}
int CallDescriptor::GetOffsetToReturns() const {
// If there are return stack slots, return the first slot of the last one.
constexpr int kNoReturnSlot = std::numeric_limits<int>::max();
int end_of_returns = kNoReturnSlot;
for (size_t i = 0; i < ReturnCount(); ++i) {
LinkageLocation operand = GetReturnLocation(i);
if (!operand.IsRegister()) {
// Reverse, since returns have negative offsets in the frame.
int reverse_location = -operand.GetLocation() - 1;
DCHECK_GE(reverse_location, 0);
end_of_returns = std::min(end_of_returns, reverse_location);
}
}
if (end_of_returns != kNoReturnSlot) return end_of_returns;
// Otherwise, return the first unused slot before the parameters, with any
// additional padding slot if it exists.
int start_of_args = 0;
for (size_t i = 0; i < InputCount(); ++i) {
LinkageLocation operand = GetInputLocation(i);
if (!operand.IsRegister()) {
// Reverse, since arguments have negative offsets in the frame.
int reverse_location =
-operand.GetLocation() + operand.GetSizeInPointers() - 1;
DCHECK_GE(reverse_location, 0);
start_of_args = std::max(start_of_args, reverse_location);
}
}
if (ShouldPadArguments(start_of_args)) start_of_args++;
DCHECK_EQ(start_of_args == 0, StackParameterCount() == 0);
return start_of_args;
int offset = static_cast<int>(StackParameterCount());
if (ShouldPadArguments(offset)) offset++;
return offset;
}
int CallDescriptor::GetTaggedParameterSlots() const {
......@@ -151,12 +138,11 @@ int CallDescriptor::GetTaggedParameterSlots() const {
bool CallDescriptor::CanTailCall(const CallDescriptor* callee) const {
if (ReturnCount() != callee->ReturnCount()) return false;
const int stack_returns_delta =
GetOffsetToReturns() - callee->GetOffsetToReturns();
const int stack_param_delta = callee->GetStackParameterDelta(this);
for (size_t i = 0; i < ReturnCount(); ++i) {
if (GetReturnLocation(i).IsCallerFrameSlot() &&
callee->GetReturnLocation(i).IsCallerFrameSlot()) {
if (GetReturnLocation(i).AsCallerFrameSlot() + stack_returns_delta !=
if (GetReturnLocation(i).AsCallerFrameSlot() - stack_param_delta !=
callee->GetReturnLocation(i).AsCallerFrameSlot()) {
return false;
}
......
......@@ -389,11 +389,12 @@ class V8_EXPORT_PRIVATE CallDescriptor final
bool UsesOnlyRegisters() const;
// Returns the first stack slot that is not used by the stack parameters.
int GetFirstUnusedStackSlot() const;
int GetStackParameterDelta(const CallDescriptor* tail_caller) const;
// If there are return stack slots, returns the first slot of the last one.
// Otherwise, return the first unused slot before the parameters. This is the
// slot where returns would go if there were any.
// Returns the number of slots to the first return value slot.
int GetOffsetToReturns() const;
int GetTaggedParameterSlots() const;
......
......@@ -29,26 +29,16 @@ class LinkageTailCall : public TestWithZone {
DCHECK(arraysize(kMachineTypes) >=
locations->return_count() + locations->parameter_count());
USE(kMachineTypes);
size_t stack_arguments = 0;
for (size_t i = 0; i < locations->parameter_count(); ++i) {
if (locations->GetParam(i).IsCallerFrameSlot()) stack_arguments++;
}
size_t stack_returns = 0;
for (size_t i = 0; i < locations->return_count(); ++i) {
if (locations->GetReturn(i).IsCallerFrameSlot()) stack_returns++;
}
return zone()->New<CallDescriptor>(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForAnyRegister(MachineType::Pointer()),
locations, // location_sig
stack_arguments,
locations, // location_sig
0, // js_parameter_count
Operator::kNoProperties, // properties
0, // callee-saved
0, // callee-saved fp
CallDescriptor::kNoFlags, // flags,
"", StackArgumentOrder::kDefault,
0, // allocatable_registers
stack_returns);
"");
}
LinkageLocation StackLocation(int loc) {
......
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