Commit 2da23e0e authored by Milad Fa's avatar Milad Fa Committed by Commit Bot

PPC/s390: [codegen] Handle alignment holes when pushing arguments

Port f9e76d6d

Original Commit Message:

    - Modify InstructionSelectors to track both padding and multiple
      slot values to correctly adjust stack pointers when pushing
      arguments. Pass stack offset as an immediate operand.
    - Modify CodeGenerators to handle alignment padding.

R=bbudge@chromium.org, joransiu@ca.ibm.com, junyan@redhat.com, midawson@redhat.com
BUG=
LOG=N

Change-Id: I639b6394f33e5e694882cb98c43b58edf5d93775
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2629947Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/master@{#72104}
parent e451d996
......@@ -1741,26 +1741,42 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ CanonicalizeNaN(result, value);
break;
}
case kPPC_Push:
if (instr->InputAt(0)->IsFPRegister()) {
LocationOperand* op = LocationOperand::cast(instr->InputAt(0));
case kPPC_Push: {
int stack_decrement = i.InputInt32(0);
if (instr->InputAt(1)->IsFPRegister()) {
LocationOperand* op = LocationOperand::cast(instr->InputAt(1));
switch (op->representation()) {
case MachineRepresentation::kFloat32:
__ StoreSingleU(i.InputDoubleRegister(0),
// 1 slot values are never padded.
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ StoreSingleU(i.InputDoubleRegister(1),
MemOperand(sp, -kSystemPointerSize), r0);
frame_access_state()->IncreaseSPDelta(1);
break;
case MachineRepresentation::kFloat64:
__ StoreDoubleU(i.InputDoubleRegister(0),
// 2 slot values have up to 1 slot of padding.
DCHECK_GE(stack_decrement, kDoubleSize);
if (stack_decrement > kDoubleSize) {
DCHECK_EQ(stack_decrement, kDoubleSize + kSystemPointerSize);
__ addi(sp, sp, Operand(-kSystemPointerSize));
}
__ StoreDoubleU(i.InputDoubleRegister(1),
MemOperand(sp, -kDoubleSize), r0);
frame_access_state()->IncreaseSPDelta(kDoubleSize /
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
case MachineRepresentation::kSimd128: {
// 4 slot values have up to 3 slots of padding.
DCHECK_GE(stack_decrement, kSimd128Size);
if (stack_decrement > kSimd128Size) {
int padding = stack_decrement - kSimd128Size;
DCHECK_LT(padding, kSimd128Size);
__ addi(sp, sp, Operand(-padding));
}
__ addi(sp, sp, Operand(-kSimd128Size));
__ StoreSimd128(i.InputSimd128Register(0), MemOperand(r0, sp), r0,
__ StoreSimd128(i.InputSimd128Register(1), MemOperand(r0, sp), r0,
kScratchSimd128Reg);
frame_access_state()->IncreaseSPDelta(kSimd128Size /
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
}
......@@ -1769,11 +1785,13 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
break;
}
} else {
__ StorePU(i.InputRegister(0), MemOperand(sp, -kSystemPointerSize), r0);
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ StorePU(i.InputRegister(1), MemOperand(sp, -kSystemPointerSize), r0);
frame_access_state()->IncreaseSPDelta(1);
}
DCHECK_EQ(LeaveRC, i.OutputRCBit());
break;
}
case kPPC_PushFrame: {
int num_slots = i.InputInt32(1);
if (instr->InputAt(0)->IsFPRegister()) {
......
......@@ -1862,10 +1862,14 @@ void InstructionSelector::EmitPrepareArguments(
}
} else {
// Push any stack arguments.
int stack_decrement = 0;
for (PushParameter input : base::Reversed(*arguments)) {
stack_decrement += kSystemPointerSize;
// Skip any alignment holes in pushed nodes.
if (input.node == nullptr) continue;
Emit(kPPC_Push, g.NoOutput(), g.UseRegister(input.node));
InstructionOperand decrement = g.UseImmediate(stack_decrement);
stack_decrement = 0;
Emit(kPPC_Push, g.NoOutput(), decrement, g.UseRegister(input.node));
}
}
}
......
......@@ -1991,25 +1991,41 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
__ CanonicalizeNaN(result, value);
break;
}
case kS390_Push:
if (instr->InputAt(0)->IsFPRegister()) {
LocationOperand* op = LocationOperand::cast(instr->InputAt(0));
case kS390_Push: {
int stack_decrement = i.InputInt32(0);
if (instr->InputAt(1)->IsFPRegister()) {
LocationOperand* op = LocationOperand::cast(instr->InputAt(1));
switch (op->representation()) {
case MachineRepresentation::kFloat32:
// 1 slot values are never padded.
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ lay(sp, MemOperand(sp, -kSystemPointerSize));
__ StoreF32(i.InputDoubleRegister(0), MemOperand(sp));
__ StoreF32(i.InputDoubleRegister(1), MemOperand(sp));
frame_access_state()->IncreaseSPDelta(1);
break;
case MachineRepresentation::kFloat64:
// 2 slot values have up to 1 slot of padding.
DCHECK_GE(stack_decrement, kDoubleSize);
if (stack_decrement > kDoubleSize) {
DCHECK_EQ(stack_decrement, kDoubleSize + kSystemPointerSize);
__ lay(sp, MemOperand(sp, -kSystemPointerSize));
}
__ lay(sp, MemOperand(sp, -kDoubleSize));
__ StoreF64(i.InputDoubleRegister(0), MemOperand(sp));
frame_access_state()->IncreaseSPDelta(kDoubleSize /
__ StoreF64(i.InputDoubleRegister(1), MemOperand(sp));
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
case MachineRepresentation::kSimd128: {
// 4 slot values have up to 3 slots of padding.
DCHECK_GE(stack_decrement, kSimd128Size);
if (stack_decrement > kSimd128Size) {
int padding = stack_decrement - kSimd128Size;
DCHECK_LT(padding, kSimd128Size);
__ lay(sp, MemOperand(sp, -padding));
}
__ lay(sp, MemOperand(sp, -kSimd128Size));
__ StoreV128(i.InputDoubleRegister(0), MemOperand(sp), kScratchReg);
frame_access_state()->IncreaseSPDelta(kSimd128Size /
__ StoreV128(i.InputDoubleRegister(1), MemOperand(sp), kScratchReg);
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
}
......@@ -2018,10 +2034,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
break;
}
} else {
__ Push(i.InputRegister(0));
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ Push(i.InputRegister(1));
frame_access_state()->IncreaseSPDelta(1);
}
break;
} break;
case kS390_PushFrame: {
int num_slots = i.InputInt32(1);
__ lay(sp, MemOperand(sp, -num_slots * kSystemPointerSize));
......
......@@ -2119,10 +2119,14 @@ void InstructionSelector::EmitPrepareArguments(
}
} else {
// Push any stack arguments.
int stack_decrement = 0;
for (PushParameter input : base::Reversed(*arguments)) {
stack_decrement += kSystemPointerSize;
// Skip any alignment holes in pushed nodes.
if (input.node == nullptr) continue;
Emit(kS390_Push, g.NoOutput(), g.UseRegister(input.node));
InstructionOperand decrement = g.UseImmediate(stack_decrement);
stack_decrement = 0;
Emit(kS390_Push, g.NoOutput(), decrement, g.UseRegister(input.node));
}
}
}
......
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