PPC/s390: [compiler] Fix pushing of arguments

Port 8798b3ef4e
Port 1d3c80d303

Original Commit Message:

    - Fixes some incorrect assumptions about padding in the
      code generation. Slots may have apparent extra padding
      when allocation fragments go unused.
    - Reworks 32 bit push code to simplify skipping slot gaps
      when 'push' instructions are used.
    - Adds a ElementSizeInPointers function on machine
      representations.

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

Change-Id: I076ae8396434610c52fed040ace5e0f49ea3ef88
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2673142
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Reviewed-by: Junliang Yan <junyan@redhat.com>
Cr-Commit-Position: refs/heads/master@{#72516}
This commit is contained in:
Milad Fa 2021-02-03 16:06:26 -05:00 committed by Commit Bot
parent 1d3c80d303
commit 01fbc8c405
2 changed files with 60 additions and 90 deletions

View File

@ -1712,52 +1712,37 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
}
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:
// 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:
// 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(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(1), MemOperand(r0, sp), r0,
kScratchSimd128Reg);
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
}
default:
UNREACHABLE();
break;
}
} else {
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ StorePU(i.InputRegister(1), MemOperand(sp, -kSystemPointerSize), r0);
frame_access_state()->IncreaseSPDelta(1);
int slots = stack_decrement / kSystemPointerSize;
LocationOperand* op = LocationOperand::cast(instr->InputAt(1));
MachineRepresentation rep = op->representation();
int pushed_slots = ElementSizeInPointers(rep);
// Slot-sized arguments are never padded but there may be a gap if
// the slot allocator reclaimed other padding slots. Adjust the stack
// here to skip any gap.
if (slots > pushed_slots) {
__ addi(sp, sp,
Operand(-((slots - pushed_slots) * kSystemPointerSize)));
}
switch (rep) {
case MachineRepresentation::kFloat32:
__ StoreSingleU(i.InputDoubleRegister(1),
MemOperand(sp, -kSystemPointerSize), r0);
break;
case MachineRepresentation::kFloat64:
__ StoreDoubleU(i.InputDoubleRegister(1),
MemOperand(sp, -kDoubleSize), r0);
break;
case MachineRepresentation::kSimd128:
__ addi(sp, sp, Operand(-kSimd128Size));
__ StoreSimd128(i.InputSimd128Register(1), MemOperand(r0, sp), r0,
kScratchSimd128Reg);
break;
default:
__ StorePU(i.InputRegister(1), MemOperand(sp, -kSystemPointerSize),
r0);
break;
}
frame_access_state()->IncreaseSPDelta(slots);
DCHECK_EQ(LeaveRC, i.OutputRCBit());
break;
}

View File

@ -1962,52 +1962,37 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
}
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(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(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(1), MemOperand(sp), kScratchReg);
frame_access_state()->IncreaseSPDelta(stack_decrement /
kSystemPointerSize);
break;
}
default:
UNREACHABLE();
break;
}
} else {
DCHECK_EQ(stack_decrement, kSystemPointerSize);
__ Push(i.InputRegister(1));
frame_access_state()->IncreaseSPDelta(1);
int slots = stack_decrement / kSystemPointerSize;
LocationOperand* op = LocationOperand::cast(instr->InputAt(1));
MachineRepresentation rep = op->representation();
int pushed_slots = ElementSizeInPointers(rep);
// Slot-sized arguments are never padded but there may be a gap if
// the slot allocator reclaimed other padding slots. Adjust the stack
// here to skip any gap.
if (slots > pushed_slots) {
__ lay(sp,
MemOperand(sp, -((slots - pushed_slots) * kSystemPointerSize)));
}
} break;
switch (rep) {
case MachineRepresentation::kFloat32:
__ lay(sp, MemOperand(sp, -kSystemPointerSize));
__ StoreF32(i.InputDoubleRegister(1), MemOperand(sp));
break;
case MachineRepresentation::kFloat64:
__ lay(sp, MemOperand(sp, -kDoubleSize));
__ StoreF64(i.InputDoubleRegister(1), MemOperand(sp));
break;
case MachineRepresentation::kSimd128:
__ lay(sp, MemOperand(sp, -kSimd128Size));
__ StoreV128(i.InputDoubleRegister(1), MemOperand(sp), kScratchReg);
break;
default:
__ Push(i.InputRegister(1));
break;
}
frame_access_state()->IncreaseSPDelta(slots);
break;
}
case kS390_PushFrame: {
int num_slots = i.InputInt32(1);
__ lay(sp, MemOperand(sp, -num_slots * kSystemPointerSize));