Skip to content

Commit ebf5497

Browse files
author
Muiez Ahmed
committed
Revert "[z/OS] Implement prologue and epilogue generation for z/OS target."
This reverts commit ffad4d7 because it introduced buildbot failures.
1 parent 803ec71 commit ebf5497

File tree

7 files changed

+11
-273
lines changed

7 files changed

+11
-273
lines changed

llvm/lib/Target/SystemZ/SystemZCallingConv.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ def CSR_SystemZ_NoRegs : CalleeSavedRegs<(add)>;
166166
// any non-leaf function and restored in the epilogue for use by the
167167
// return instruction so it functions exactly like a callee-saved register.
168168
def CSR_SystemZ_XPLINK64 : CalleeSavedRegs<(add (sequence "R%dD", 7, 15),
169-
(sequence "R%dD", 4, 4),
170169
(sequence "F%dD", 15, 8))>;
171170

172171
def CSR_SystemZ_XPLINK64_Vector : CalleeSavedRegs<(add CSR_SystemZ_XPLINK64,

llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp

Lines changed: 4 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ bool SystemZELFFrameLowering::usePackedStack(MachineFunction &MF) const {
818818
}
819819

820820
SystemZXPLINKFrameLowering::SystemZXPLINKFrameLowering()
821-
: SystemZFrameLowering(TargetFrameLowering::StackGrowsDown, Align(32), 0,
821+
: SystemZFrameLowering(TargetFrameLowering::StackGrowsUp, Align(32), 128,
822822
Align(32), /* StackRealignable */ false),
823823
RegSpillOffsets(-1) {
824824

@@ -990,183 +990,12 @@ bool SystemZXPLINKFrameLowering::spillCalleeSavedRegisters(
990990
return true;
991991
}
992992

993-
bool SystemZXPLINKFrameLowering::restoreCalleeSavedRegisters(
994-
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
995-
MutableArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
996-
997-
if (CSI.empty())
998-
return false;
999-
1000-
MachineFunction &MF = *MBB.getParent();
1001-
SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1002-
const SystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1003-
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1004-
auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1005-
1006-
DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
1007-
1008-
// Restore FPRs in the normal TargetInstrInfo way.
1009-
for (unsigned I = 0, E = CSI.size(); I != E; ++I) {
1010-
unsigned Reg = CSI[I].getReg();
1011-
if (SystemZ::FP64BitRegClass.contains(Reg))
1012-
TII->loadRegFromStackSlot(MBB, MBBI, Reg, CSI[I].getFrameIdx(),
1013-
&SystemZ::FP64BitRegClass, TRI);
1014-
if (SystemZ::VR128BitRegClass.contains(Reg))
1015-
TII->loadRegFromStackSlot(MBB, MBBI, Reg, CSI[I].getFrameIdx(),
1016-
&SystemZ::VR128BitRegClass, TRI);
1017-
}
1018-
1019-
// Restore call-saved GPRs (but not call-clobbered varargs, which at
1020-
// this point might hold return values).
1021-
SystemZ::GPRRegs RestoreGPRs = ZFI->getRestoreGPRRegs();
1022-
if (RestoreGPRs.LowGPR) {
1023-
assert(isInt<20>(Regs.getStackPointerBias() + RestoreGPRs.GPROffset));
1024-
if (RestoreGPRs.LowGPR == RestoreGPRs.HighGPR)
1025-
// Build an LG/L instruction.
1026-
BuildMI(MBB, MBBI, DL, TII->get(SystemZ::LG), RestoreGPRs.LowGPR)
1027-
.addReg(Regs.getStackPointerRegister())
1028-
.addImm(Regs.getStackPointerBias() + RestoreGPRs.GPROffset)
1029-
.addReg(0);
1030-
else {
1031-
// Build an LMG/LM instruction.
1032-
MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(SystemZ::LMG));
1033-
1034-
// Add the explicit register operands.
1035-
MIB.addReg(RestoreGPRs.LowGPR, RegState::Define);
1036-
MIB.addReg(RestoreGPRs.HighGPR, RegState::Define);
1037-
1038-
// Add the address.
1039-
MIB.addReg(Regs.getStackPointerRegister());
1040-
MIB.addImm(Regs.getStackPointerBias() + RestoreGPRs.GPROffset);
1041-
1042-
// Do a second scan adding regs as being defined by instruction
1043-
for (unsigned I = 0, E = CSI.size(); I != E; ++I) {
1044-
unsigned Reg = CSI[I].getReg();
1045-
if (Reg > RestoreGPRs.LowGPR && Reg < RestoreGPRs.HighGPR)
1046-
MIB.addReg(Reg, RegState::ImplicitDefine);
1047-
}
1048-
}
1049-
}
1050-
1051-
return true;
1052-
}
1053-
1054993
void SystemZXPLINKFrameLowering::emitPrologue(MachineFunction &MF,
1055-
MachineBasicBlock &MBB) const {
1056-
assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
1057-
const SystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1058-
SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1059-
MachineBasicBlock::iterator MBBI = MBB.begin();
1060-
auto *ZII = static_cast<const SystemZInstrInfo *>(Subtarget.getInstrInfo());
1061-
auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1062-
MachineFrameInfo &MFFrame = MF.getFrameInfo();
1063-
MachineInstr *StoreInstr = nullptr;
1064-
bool HasFP = hasFP(MF);
1065-
// Debug location must be unknown since the first debug location is used
1066-
// to determine the end of the prologue.
1067-
DebugLoc DL;
1068-
uint64_t Offset = 0;
1069-
1070-
// TODO: Support leaf functions; only add size of save+reserved area when
1071-
// function is non-leaf.
1072-
MFFrame.setStackSize(MFFrame.getStackSize() + Regs.getCallFrameSize());
1073-
uint64_t StackSize = MFFrame.getStackSize();
1074-
1075-
// FIXME: Implement support for large stack sizes, when the stack extension
1076-
// routine needs to be called.
1077-
if (StackSize > 1024 * 1024) {
1078-
llvm_unreachable("Huge Stack Frame not yet supported on z/OS");
1079-
}
1080-
1081-
if (ZFI->getSpillGPRRegs().LowGPR) {
1082-
// Skip over the GPR saves.
1083-
if ((MBBI != MBB.end()) && ((MBBI->getOpcode() == SystemZ::STMG))) {
1084-
const int Operand = 3;
1085-
// Now we can set the offset for the operation, since now the Stack
1086-
// has been finalized.
1087-
Offset = Regs.getStackPointerBias() + MBBI->getOperand(Operand).getImm();
1088-
// Maximum displacement for STMG instruction.
1089-
if (isInt<20>(Offset - StackSize))
1090-
Offset -= StackSize;
1091-
else
1092-
StoreInstr = &*MBBI;
1093-
MBBI->getOperand(Operand).setImm(Offset);
1094-
++MBBI;
1095-
} else
1096-
llvm_unreachable("Couldn't skip over GPR saves");
1097-
}
1098-
1099-
if (StackSize) {
1100-
MachineBasicBlock::iterator InsertPt = StoreInstr ? StoreInstr : MBBI;
1101-
// Allocate StackSize bytes.
1102-
int64_t Delta = -int64_t(StackSize);
1103-
1104-
// In case the STM(G) instruction also stores SP (R4), but the displacement
1105-
// is too large, the SP register is manipulated first before storing,
1106-
// resulting in the wrong value stored and retrieved later. In this case, we
1107-
// need to temporarily save the value of SP, and store it later to memory.
1108-
if (StoreInstr && HasFP) {
1109-
// Insert LR r0,r4 before STMG instruction.
1110-
BuildMI(MBB, InsertPt, DL, ZII->get(SystemZ::LGR))
1111-
.addReg(SystemZ::R0D, RegState::Define)
1112-
.addReg(SystemZ::R4D);
1113-
// Insert ST r0,xxx(,r4) after STMG instruction.
1114-
BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::STG), SystemZ::R0D)
1115-
.addReg(SystemZ::R4D)
1116-
.addImm(Offset)
1117-
.addReg(0);
1118-
}
1119-
1120-
emitIncrement(MBB, InsertPt, DL, Regs.getStackPointerRegister(), Delta,
1121-
ZII);
1122-
}
1123-
1124-
if (HasFP) {
1125-
// Copy the base of the frame to Frame Pointer Register.
1126-
BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::LGR),
1127-
Regs.getFramePointerRegister())
1128-
.addReg(Regs.getStackPointerRegister());
1129-
1130-
// Mark the FramePtr as live at the beginning of every block except
1131-
// the entry block. (We'll have marked R8 as live on entry when
1132-
// saving the GPRs.)
1133-
for (auto I = std::next(MF.begin()), E = MF.end(); I != E; ++I)
1134-
I->addLiveIn(Regs.getFramePointerRegister());
1135-
}
1136-
}
994+
MachineBasicBlock &MBB) const {}
1137995

1138996
void SystemZXPLINKFrameLowering::emitEpilogue(MachineFunction &MF,
1139-
MachineBasicBlock &MBB) const {
1140-
const SystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1141-
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
1142-
SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1143-
MachineFrameInfo &MFFrame = MF.getFrameInfo();
1144-
auto *ZII = static_cast<const SystemZInstrInfo *>(Subtarget.getInstrInfo());
1145-
auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1146-
1147-
// Skip the return instruction.
1148-
assert(MBBI->isReturn() && "Can only insert epilogue into returning blocks");
1149-
1150-
uint64_t StackSize = MFFrame.getStackSize();
1151-
if (StackSize) {
1152-
unsigned SPReg = Regs.getStackPointerRegister();
1153-
if (ZFI->getRestoreGPRRegs().LowGPR != SPReg) {
1154-
DebugLoc DL = MBBI->getDebugLoc();
1155-
emitIncrement(MBB, MBBI, DL, SPReg, StackSize, ZII);
1156-
}
1157-
}
1158-
}
997+
MachineBasicBlock &MBB) const {}
1159998

1160999
bool SystemZXPLINKFrameLowering::hasFP(const MachineFunction &MF) const {
1161-
return (MF.getFrameInfo().hasVarSizedObjects());
1162-
}
1163-
1164-
void SystemZXPLINKFrameLowering::processFunctionBeforeFrameFinalized(
1165-
MachineFunction &MF, RegScavenger *RS) const {
1166-
MachineFrameInfo &MFFrame = MF.getFrameInfo();
1167-
const SystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1168-
auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1169-
1170-
// Setup stack frame offset
1171-
MFFrame.setOffsetAdjustment(Regs.getStackPointerBias());
1000+
return false;
11721001
}

llvm/lib/Target/SystemZ/SystemZFrameLowering.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,11 @@ class SystemZXPLINKFrameLowering : public SystemZFrameLowering {
115115
ArrayRef<CalleeSavedInfo> CSI,
116116
const TargetRegisterInfo *TRI) const override;
117117

118-
bool
119-
restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
120-
MachineBasicBlock::iterator MBBII,
121-
MutableArrayRef<CalleeSavedInfo> CSI,
122-
const TargetRegisterInfo *TRI) const override;
123-
124118
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
125119

126120
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
127121

128122
bool hasFP(const MachineFunction &MF) const override;
129-
130-
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
131-
RegScavenger *RS) const override;
132123
};
133124
} // end namespace llvm
134125

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,16 +1500,8 @@ SDValue SystemZTargetLowering::LowerFormalArguments(
15001500
assert(VA.isMemLoc() && "Argument not register or memory");
15011501

15021502
// Create the frame index object for this incoming parameter.
1503-
// FIXME: Pre-include call frame size in the offset, should not
1504-
// need to manually add it here.
1505-
int64_t ArgSPOffset = VA.getLocMemOffset();
1506-
if (Subtarget.isTargetXPLINK64()) {
1507-
auto &XPRegs =
1508-
Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1509-
ArgSPOffset += XPRegs.getCallFrameSize();
1510-
}
1511-
int FI =
1512-
MFI.CreateFixedObject(LocVT.getSizeInBits() / 8, ArgSPOffset, true);
1503+
int FI = MFI.CreateFixedObject(LocVT.getSizeInBits() / 8,
1504+
VA.getLocMemOffset(), true);
15131505

15141506
// Create the SelectionDAG nodes corresponding to a load
15151507
// from this parameter. Unpromoted ints and floats are

llvm/test/CodeGen/SystemZ/call-zos-01.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ entry:
8686
}
8787

8888
; CHECK-LABEL: pass_integrals0:
89-
; CHECK: ag 2, 2328(4)
89+
; CHECK: ag 2, -{{[0-9]+}}(4)
9090
; CHECK-NEXT: lgr 3, 2
9191
define signext i64 @pass_integrals0(i64 signext %arg0, i32 signext %arg1, i16 signext %arg2, i64 signext %arg3) {
9292
entry:

llvm/test/CodeGen/SystemZ/call-zos-vec.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ entry:
1414
; CHECK: vaf 1, 1, 27
1515
; CHECK: vaf 1, 1, 28
1616
; CHECK: vaf 1, 1, 29
17-
; CHECK: vl 0, 2432(4), 4
17+
; CHECK: vl 0, 32(4), 4
1818
; CHECK: vaf 1, 1, 30
1919
; CHECK: vaf 1, 1, 31
2020
; CHECK: vaf 24, 1, 0

llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,15 @@
66

77
; Small stack frame.
88
; CHECK-LABEL: func0
9-
; CHECK64: stmg 6, 7, 1872(4)
10-
; stmg instruction's displacement field must be 2064-dsa_size
11-
; as per ABI
12-
; CHECK64: aghi 4, -192
13-
14-
; CHECK64: lg 7, 2072(4)
15-
; CHECK64: aghi 4, 192
16-
; CHECK64: b 2(7)
9+
; CHECK64: stmg 6, 7
1710
define void @func0() {
1811
call i64 (i64) @fun(i64 10)
1912
ret void
2013
}
2114

2215
; Spill all GPR CSRs
2316
; CHECK-LABEL: func1
24-
; CHECK64: stmg 6, 15, 1904(4)
25-
; CHECK64: aghi 4, -160
26-
27-
; CHECK64: lmg 7, 15, 2072(4)
28-
; CHECK64: aghi 4, 160
29-
; CHECK64: b 2(7)
17+
; CHECK64: stmg 6, 15
3018
define void @func1(i64 *%ptr) {
3119
%l01 = load volatile i64, i64 *%ptr
3220
%l02 = load volatile i64, i64 *%ptr
@@ -79,8 +67,6 @@ define void @func1(i64 *%ptr) {
7967

8068
; Spill all FPRs and VRs
8169
; CHECK-LABEL: func2
82-
; CHECK64: stmg 6, 7, 1744(4)
83-
; CHECK64: aghi 4, -320
8470
; CHECK64: std 15, {{[0-9]+}}(4) * 8-byte Folded Spill
8571
; CHECK64: std 14, {{[0-9]+}}(4) * 8-byte Folded Spill
8672
; CHECK64: std 13, {{[0-9]+}}(4) * 8-byte Folded Spill
@@ -97,27 +83,6 @@ define void @func1(i64 *%ptr) {
9783
; CHECK64: vst 18, {{[0-9]+}}(4), 4 * 16-byte Folded Spill
9884
; CHECK64: vst 17, {{[0-9]+}}(4), 4 * 16-byte Folded Spill
9985
; CHECK64: vst 16, {{[0-9]+}}(4), 4 * 16-byte Folded Spill
100-
101-
; CHECK64: ld 15, {{[0-9]+}}(4) * 8-byte Folded Reload
102-
; CHECK64: ld 14, {{[0-9]+}}(4) * 8-byte Folded Reload
103-
; CHECK64: ld 13, {{[0-9]+}}(4) * 8-byte Folded Reload
104-
; CHECK64: ld 12, {{[0-9]+}}(4) * 8-byte Folded Reload
105-
; CHECK64: ld 11, {{[0-9]+}}(4) * 8-byte Folded Reload
106-
; CHECK64: ld 10, {{[0-9]+}}(4) * 8-byte Folded Reload
107-
; CHECK64: ld 9, {{[0-9]+}}(4) * 8-byte Folded Reload
108-
; CHECK64: ld 8, {{[0-9]+}}(4) * 8-byte Folded Reload
109-
; CHECK64: vl 23, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
110-
; CHECK64: vl 22, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
111-
; CHECK64: vl 21, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
112-
; CHECK64: vl 20, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
113-
; CHECK64: vl 19, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
114-
; CHECK64: vl 18, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
115-
; CHECK64: vl 17, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
116-
; CHECK64: vl 16, {{[0-9]+}}(4), 4 * 16-byte Folded Reload
117-
; CHECK64: lg 7, 2072(4)
118-
; CHECK64: aghi 4, 320
119-
; CHECK64: b 2(7)
120-
12186
define void @func2(double *%ptr, <2 x i64> *%vec_ptr) {
12287
%l00 = load volatile double, double *%ptr
12388
%l01 = load volatile double, double *%ptr
@@ -267,43 +232,5 @@ define void @func2(double *%ptr, <2 x i64> *%vec_ptr) {
267232
ret void
268233
}
269234

270-
; Big stack frame, force the use of agfi before stmg
271-
; despite not requiring stack extension routine.
272-
; CHECK64: agfi 4, -1040768
273-
; CHECK64: stmg 6, 7, 2064(4)
274-
; CHECK64: agfi 4, 1040768
275-
define void @func3() {
276-
%arr = alloca [130070 x i64], align 8
277-
%ptr = bitcast [130070 x i64]* %arr to i8*
278-
call i64 (i8*) @fun1(i8* %ptr)
279-
ret void
280-
}
281-
282-
; Requires the saving of r4 due to variable sized
283-
; object in stack frame. (Eg: VLA)
284-
; CHECK64: stmg 4, 8, 1856(4)
285-
; CHECK64: aghi 4, -192
286-
; CHECK64: lmg 4, 8, 2048(4)
287-
define i64 @func4(i64 %n) {
288-
%vla = alloca i64, i64 %n, align 8
289-
%call = call i64 @fun2(i64 %n, i64* nonnull %vla, i64* nonnull %vla)
290-
ret i64 %call
291-
}
292-
293-
; Require saving of r4 and in addition, a displacement large enough
294-
; to force use of agfi before stmg.
295-
; CHECK64: lgr 0, 4
296-
; CHECK64: agfi 4, -1040192
297-
; CHECK64: stmg 4, 8, 2048(4)
298-
; CHECK64: lmg 4, 8, 2048(4)
299-
define i64 @func5(i64 %n) {
300-
%vla = alloca i64, i64 %n, align 8
301-
%arr = alloca [130000 x i64], align 8
302-
%ptr = bitcast [130000 x i64]* %arr to i64*
303-
%call = call i64 @fun2(i64 %n, i64* nonnull %vla, i64* %ptr)
304-
ret i64 %call
305-
}
306-
307235
declare i64 @fun(i64 %arg0)
308-
declare i64 @fun1(i8* %ptr)
309-
declare i64 @fun2(i64 %n, i64* %arr0, i64* %arr1)
236+

0 commit comments

Comments
 (0)