Skip to content

Commit dfb717d

Browse files
committed
[PowerPC] Remove support for VRSAVE save/restore/update.
After removal of Darwin as a PowerPC subtarget, the VRSAVE save/restore/spill/update code is no longer needed by any supported subtarget, so remove it while keeping support for vrsave and related instruction aliases for inline asm. I've pre-commited tests to document the existing vrsave handling in relation to @llvm.eh.unwind.init and inline asm usage, as well as a test which shows a beahviour change on AIX related to returning vector type as we were wrongly emiting VRSAVE_UPDATE on AIX.
1 parent 216af81 commit dfb717d

File tree

11 files changed

+14
-361
lines changed

11 files changed

+14
-361
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 4 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -262,153 +262,11 @@ const PPCFrameLowering::SpillSlot *PPCFrameLowering::getCalleeSavedSpillSlots(
262262
return AIXOffsets32;
263263
}
264264

265-
/// RemoveVRSaveCode - We have found that this function does not need any code
266-
/// to manipulate the VRSAVE register, even though it uses vector registers.
267-
/// This can happen when the only registers used are known to be live in or out
268-
/// of the function. Remove all of the VRSAVE related code from the function.
269-
/// FIXME: The removal of the code results in a compile failure at -O0 when the
270-
/// function contains a function call, as the GPR containing original VRSAVE
271-
/// contents is spilled and reloaded around the call. Without the prolog code,
272-
/// the spill instruction refers to an undefined register. This code needs
273-
/// to account for all uses of that GPR.
274-
static void RemoveVRSaveCode(MachineInstr &MI) {
275-
MachineBasicBlock *Entry = MI.getParent();
276-
MachineFunction *MF = Entry->getParent();
277-
278-
// We know that the MTVRSAVE instruction immediately follows MI. Remove it.
279-
MachineBasicBlock::iterator MBBI = MI;
280-
++MBBI;
281-
assert(MBBI != Entry->end() && MBBI->getOpcode() == PPC::MTVRSAVE);
282-
MBBI->eraseFromParent();
283-
284-
bool RemovedAllMTVRSAVEs = true;
285-
// See if we can find and remove the MTVRSAVE instruction from all of the
286-
// epilog blocks.
287-
for (MachineFunction::iterator I = MF->begin(), E = MF->end(); I != E; ++I) {
288-
// If last instruction is a return instruction, add an epilogue
289-
if (I->isReturnBlock()) {
290-
bool FoundIt = false;
291-
for (MBBI = I->end(); MBBI != I->begin(); ) {
292-
--MBBI;
293-
if (MBBI->getOpcode() == PPC::MTVRSAVE) {
294-
MBBI->eraseFromParent(); // remove it.
295-
FoundIt = true;
296-
break;
297-
}
298-
}
299-
RemovedAllMTVRSAVEs &= FoundIt;
300-
}
301-
}
302-
303-
// If we found and removed all MTVRSAVE instructions, remove the read of
304-
// VRSAVE as well.
305-
if (RemovedAllMTVRSAVEs) {
306-
MBBI = MI;
307-
assert(MBBI != Entry->begin() && "UPDATE_VRSAVE is first instr in block?");
308-
--MBBI;
309-
assert(MBBI->getOpcode() == PPC::MFVRSAVE && "VRSAVE instrs wandered?");
310-
MBBI->eraseFromParent();
311-
}
312-
313-
// Finally, nuke the UPDATE_VRSAVE.
314-
MI.eraseFromParent();
315-
}
316-
317-
// HandleVRSaveUpdate - MI is the UPDATE_VRSAVE instruction introduced by the
318-
// instruction selector. Based on the vector registers that have been used,
319-
// transform this into the appropriate ORI instruction.
320-
static void HandleVRSaveUpdate(MachineInstr &MI, const TargetInstrInfo &TII) {
321-
MachineFunction *MF = MI.getParent()->getParent();
322-
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
323-
DebugLoc dl = MI.getDebugLoc();
324-
325-
const MachineRegisterInfo &MRI = MF->getRegInfo();
326-
unsigned UsedRegMask = 0;
327-
for (unsigned i = 0; i != 32; ++i)
328-
if (MRI.isPhysRegModified(VRRegNo[i]))
329-
UsedRegMask |= 1 << (31-i);
330-
331-
// Live in and live out values already must be in the mask, so don't bother
332-
// marking them.
333-
for (std::pair<unsigned, unsigned> LI : MF->getRegInfo().liveins()) {
334-
unsigned RegNo = TRI->getEncodingValue(LI.first);
335-
if (VRRegNo[RegNo] == LI.first) // If this really is a vector reg.
336-
UsedRegMask &= ~(1 << (31-RegNo)); // Doesn't need to be marked.
337-
}
338-
339-
// Live out registers appear as use operands on return instructions.
340-
for (MachineFunction::const_iterator BI = MF->begin(), BE = MF->end();
341-
UsedRegMask != 0 && BI != BE; ++BI) {
342-
const MachineBasicBlock &MBB = *BI;
343-
if (!MBB.isReturnBlock())
344-
continue;
345-
const MachineInstr &Ret = MBB.back();
346-
for (unsigned I = 0, E = Ret.getNumOperands(); I != E; ++I) {
347-
const MachineOperand &MO = Ret.getOperand(I);
348-
if (!MO.isReg() || !PPC::VRRCRegClass.contains(MO.getReg()))
349-
continue;
350-
unsigned RegNo = TRI->getEncodingValue(MO.getReg());
351-
UsedRegMask &= ~(1 << (31-RegNo));
352-
}
353-
}
354-
355-
// If no registers are used, turn this into a copy.
356-
if (UsedRegMask == 0) {
357-
// Remove all VRSAVE code.
358-
RemoveVRSaveCode(MI);
359-
return;
360-
}
361-
362-
Register SrcReg = MI.getOperand(1).getReg();
363-
Register DstReg = MI.getOperand(0).getReg();
364-
365-
if ((UsedRegMask & 0xFFFF) == UsedRegMask) {
366-
if (DstReg != SrcReg)
367-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORI), DstReg)
368-
.addReg(SrcReg)
369-
.addImm(UsedRegMask);
370-
else
371-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORI), DstReg)
372-
.addReg(SrcReg, RegState::Kill)
373-
.addImm(UsedRegMask);
374-
} else if ((UsedRegMask & 0xFFFF0000) == UsedRegMask) {
375-
if (DstReg != SrcReg)
376-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORIS), DstReg)
377-
.addReg(SrcReg)
378-
.addImm(UsedRegMask >> 16);
379-
else
380-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORIS), DstReg)
381-
.addReg(SrcReg, RegState::Kill)
382-
.addImm(UsedRegMask >> 16);
383-
} else {
384-
if (DstReg != SrcReg)
385-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORIS), DstReg)
386-
.addReg(SrcReg)
387-
.addImm(UsedRegMask >> 16);
388-
else
389-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORIS), DstReg)
390-
.addReg(SrcReg, RegState::Kill)
391-
.addImm(UsedRegMask >> 16);
392-
393-
BuildMI(*MI.getParent(), MI, dl, TII.get(PPC::ORI), DstReg)
394-
.addReg(DstReg, RegState::Kill)
395-
.addImm(UsedRegMask & 0xFFFF);
396-
}
397-
398-
// Remove the old UPDATE_VRSAVE instruction.
399-
MI.eraseFromParent();
400-
}
401-
402265
static bool spillsCR(const MachineFunction &MF) {
403266
const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
404267
return FuncInfo->isCRSpilled();
405268
}
406269

407-
static bool spillsVRSAVE(const MachineFunction &MF) {
408-
const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
409-
return FuncInfo->isVRSAVESpilled();
410-
}
411-
412270
static bool hasSpills(const MachineFunction &MF) {
413271
const PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
414272
return FuncInfo->hasSpills();
@@ -474,7 +332,7 @@ PPCFrameLowering::determineFrameLayout(const MachineFunction &MF,
474332
!FI->mustSaveTOC() && // No need to save TOC.
475333
!RegInfo->hasBasePointer(MF); // No special alignment.
476334

477-
// Note: for PPC32 SVR4ABI (Non-DarwinABI), we can still generate stackless
335+
// Note: for PPC32 SVR4ABI, we can still generate stackless
478336
// code if all local vars are reg-allocated.
479337
bool FitsInRedZone = FrameSize <= Subtarget.getRedZoneSize();
480338

@@ -775,21 +633,6 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
775633
bool isELFv2ABI = Subtarget.isELFv2ABI();
776634
assert((isSVR4ABI || isAIXABI) && "Unsupported PPC ABI.");
777635

778-
// Scan the prolog, looking for an UPDATE_VRSAVE instruction. If we find it,
779-
// process it.
780-
if (!isSVR4ABI)
781-
for (unsigned i = 0; MBBI != MBB.end(); ++i, ++MBBI) {
782-
if (MBBI->getOpcode() == PPC::UPDATE_VRSAVE) {
783-
if (isAIXABI)
784-
report_fatal_error("UPDATE_VRSAVE is unexpected on AIX.");
785-
HandleVRSaveUpdate(*MBBI, TII);
786-
break;
787-
}
788-
}
789-
790-
// Move MBBI back to the beginning of the prologue block.
791-
MBBI = MBB.begin();
792-
793636
// Work out frame sizes.
794637
unsigned FrameSize = determineFrameLayoutAndUpdate(MF);
795638
int NegFrameSize = -FrameSize;
@@ -2035,7 +1878,6 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
20351878
bool HasGPSaveArea = false;
20361879
bool HasG8SaveArea = false;
20371880
bool HasFPSaveArea = false;
2038-
bool HasVRSAVESaveArea = false;
20391881
bool HasVRSaveArea = false;
20401882

20411883
SmallVector<CalleeSavedInfo, 18> GPRegs;
@@ -2075,8 +1917,6 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
20751917
} else if (PPC::CRBITRCRegClass.contains(Reg) ||
20761918
PPC::CRRCRegClass.contains(Reg)) {
20771919
; // do nothing, as we already know whether CRs are spilled
2078-
} else if (PPC::VRSAVERCRegClass.contains(Reg)) {
2079-
HasVRSAVESaveArea = true;
20801920
} else if (PPC::VRRCRegClass.contains(Reg) ||
20811921
PPC::SPERCRegClass.contains(Reg)) {
20821922
// Altivec and SPE are mutually exclusive, but have the same stack
@@ -2199,23 +2039,6 @@ void PPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
21992039
LowerBound -= 4; // The CR save area is always 4 bytes long.
22002040
}
22012041

2202-
if (HasVRSAVESaveArea) {
2203-
// FIXME SVR4: Is it actually possible to have multiple elements in CSI
2204-
// which have the VRSAVE register class?
2205-
// Adjust the frame index of the VRSAVE spill slot.
2206-
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
2207-
unsigned Reg = CSI[i].getReg();
2208-
2209-
if (PPC::VRSAVERCRegClass.contains(Reg)) {
2210-
int FI = CSI[i].getFrameIdx();
2211-
2212-
MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2213-
}
2214-
}
2215-
2216-
LowerBound -= 4; // The VRSAVE save area is always 4 bytes long.
2217-
}
2218-
22192042
// Both Altivec and SPE have the same alignment and padding requirements
22202043
// within the stack frame.
22212044
if (HasVRSaveArea) {
@@ -2255,8 +2078,8 @@ PPCFrameLowering::addScavengingSpillSlot(MachineFunction &MF,
22552078
// needed alignment padding.
22562079
unsigned StackSize = determineFrameLayout(MF, true);
22572080
MachineFrameInfo &MFI = MF.getFrameInfo();
2258-
if (MFI.hasVarSizedObjects() || spillsCR(MF) || spillsVRSAVE(MF) ||
2259-
hasNonRISpills(MF) || (hasSpills(MF) && !isInt<16>(StackSize))) {
2081+
if (MFI.hasVarSizedObjects() || spillsCR(MF) || hasNonRISpills(MF) ||
2082+
(hasSpills(MF) && !isInt<16>(StackSize))) {
22602083
const TargetRegisterClass &GPRC = PPC::GPRCRegClass;
22612084
const TargetRegisterClass &G8RC = PPC::G8RCRegClass;
22622085
const TargetRegisterClass &RC = Subtarget.isPPC64() ? G8RC : GPRC;
@@ -2270,7 +2093,7 @@ PPCFrameLowering::addScavengingSpillSlot(MachineFunction &MF,
22702093
MFI.hasVarSizedObjects() && MFI.getMaxAlign() > getStackAlign();
22712094

22722095
// These kinds of spills might need two registers.
2273-
if (spillsCR(MF) || spillsVRSAVE(MF) || HasAlVars)
2096+
if (spillsCR(MF) || HasAlVars)
22742097
RS->addScavengingFrameIndex(
22752098
MFI.CreateStackObject(Size, Alignment, false));
22762099
}
@@ -2347,9 +2170,6 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
23472170

23482171
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
23492172
unsigned Reg = CSI[i].getReg();
2350-
// VRSAVE can appear here if, for example, @llvm.eh.unwind.init() is used.
2351-
if (Reg == PPC::VRSAVE)
2352-
continue;
23532173

23542174
// CR2 through CR4 are the nonvolatile CR fields.
23552175
bool IsCRField = PPC::CR2 <= Reg && Reg <= PPC::CR4;
@@ -2514,10 +2334,6 @@ bool PPCFrameLowering::restoreCalleeSavedRegisters(
25142334
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
25152335
unsigned Reg = CSI[i].getReg();
25162336

2517-
// VRSAVE can appear here if, for example, @llvm.eh.unwind.init() is used.
2518-
if (Reg == PPC::VRSAVE)
2519-
continue;
2520-
25212337
if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
25222338
continue;
25232339

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ namespace {
156156
PPCLowering = Subtarget->getTargetLowering();
157157
SelectionDAGISel::runOnMachineFunction(MF);
158158

159-
if (!Subtarget->isSVR4ABI())
160-
InsertVRSaveCode(MF);
161-
162159
return true;
163160
}
164161

@@ -341,8 +338,6 @@ namespace {
341338
return true;
342339
}
343340

344-
void InsertVRSaveCode(MachineFunction &MF);
345-
346341
StringRef getPassName() const override {
347342
return "PowerPC DAG->DAG Pattern Instruction Selection";
348343
}
@@ -376,70 +371,6 @@ namespace {
376371

377372
} // end anonymous namespace
378373

379-
/// InsertVRSaveCode - Once the entire function has been instruction selected,
380-
/// all virtual registers are created and all machine instructions are built,
381-
/// check to see if we need to save/restore VRSAVE. If so, do it.
382-
void PPCDAGToDAGISel::InsertVRSaveCode(MachineFunction &Fn) {
383-
// Check to see if this function uses vector registers, which means we have to
384-
// save and restore the VRSAVE register and update it with the regs we use.
385-
//
386-
// In this case, there will be virtual registers of vector type created
387-
// by the scheduler. Detect them now.
388-
bool HasVectorVReg = false;
389-
for (unsigned i = 0, e = RegInfo->getNumVirtRegs(); i != e; ++i) {
390-
unsigned Reg = Register::index2VirtReg(i);
391-
if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
392-
HasVectorVReg = true;
393-
break;
394-
}
395-
}
396-
if (!HasVectorVReg) return; // nothing to do.
397-
398-
// If we have a vector register, we want to emit code into the entry and exit
399-
// blocks to save and restore the VRSAVE register. We do this here (instead
400-
// of marking all vector instructions as clobbering VRSAVE) for two reasons:
401-
//
402-
// 1. This (trivially) reduces the load on the register allocator, by not
403-
// having to represent the live range of the VRSAVE register.
404-
// 2. This (more significantly) allows us to create a temporary virtual
405-
// register to hold the saved VRSAVE value, allowing this temporary to be
406-
// register allocated, instead of forcing it to be spilled to the stack.
407-
408-
// Create two vregs - one to hold the VRSAVE register that is live-in to the
409-
// function and one for the value after having bits or'd into it.
410-
Register InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
411-
Register UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
412-
413-
const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
414-
MachineBasicBlock &EntryBB = *Fn.begin();
415-
DebugLoc dl;
416-
// Emit the following code into the entry block:
417-
// InVRSAVE = MFVRSAVE
418-
// UpdatedVRSAVE = UPDATE_VRSAVE InVRSAVE
419-
// MTVRSAVE UpdatedVRSAVE
420-
MachineBasicBlock::iterator IP = EntryBB.begin(); // Insert Point
421-
BuildMI(EntryBB, IP, dl, TII.get(PPC::MFVRSAVE), InVRSAVE);
422-
BuildMI(EntryBB, IP, dl, TII.get(PPC::UPDATE_VRSAVE),
423-
UpdatedVRSAVE).addReg(InVRSAVE);
424-
BuildMI(EntryBB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
425-
426-
// Find all return blocks, outputting a restore in each epilog.
427-
for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
428-
if (BB->isReturnBlock()) {
429-
IP = BB->end(); --IP;
430-
431-
// Skip over all terminator instructions, which are part of the return
432-
// sequence.
433-
MachineBasicBlock::iterator I2 = IP;
434-
while (I2 != BB->begin() && (--I2)->isTerminator())
435-
IP = I2;
436-
437-
// Emit: MTVRSAVE InVRSave
438-
BuildMI(*BB, IP, dl, TII.get(PPC::MTVRSAVE)).addReg(InVRSAVE);
439-
}
440-
}
441-
}
442-
443374
/// getGlobalBaseReg - Output the instructions required to put the
444375
/// base address to use for accessing globals into a register.
445376
///

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7660,6 +7660,10 @@ PPCTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
76607660

76617661
SDValue Arg = OutVals[RealResIdx];
76627662

7663+
if (Subtarget.isAIXABI() &&
7664+
(VA.getLocVT().isVector() || VA.getValVT().isVector()))
7665+
report_fatal_error("Returning vector types not yet supported on AIX.");
7666+
76637667
switch (VA.getLocInfo()) {
76647668
default: llvm_unreachable("Unknown loc info!");
76657669
case CCValAssign::Full: break;

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,6 @@ static unsigned getSpillIndex(const TargetRegisterClass *RC) {
13741374
OpcodeIndex = SOK_VectorFloat8Spill;
13751375
} else if (PPC::VSSRCRegClass.hasSubClassEq(RC)) {
13761376
OpcodeIndex = SOK_VectorFloat4Spill;
1377-
} else if (PPC::VRSAVERCRegClass.hasSubClassEq(RC)) {
1378-
OpcodeIndex = SOK_VRSaveSpill;
13791377
} else if (PPC::SPILLTOVSRRCRegClass.hasSubClassEq(RC)) {
13801378
OpcodeIndex = SOK_SpillToVSR;
13811379
} else {
@@ -1414,9 +1412,6 @@ void PPCInstrInfo::StoreRegToStackSlot(
14141412
PPC::CRBITRCRegClass.hasSubClassEq(RC))
14151413
FuncInfo->setSpillsCR();
14161414

1417-
if (PPC::VRSAVERCRegClass.hasSubClassEq(RC))
1418-
FuncInfo->setSpillsVRSAVE();
1419-
14201415
if (isXFormMemOp(Opcode))
14211416
FuncInfo->setHasNonRISpills();
14221417
}
@@ -1472,9 +1467,6 @@ void PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, const DebugLoc &DL,
14721467
PPC::CRBITRCRegClass.hasSubClassEq(RC))
14731468
FuncInfo->setSpillsCR();
14741469

1475-
if (PPC::VRSAVERCRegClass.hasSubClassEq(RC))
1476-
FuncInfo->setSpillsVRSAVE();
1477-
14781470
if (isXFormMemOp(Opcode))
14791471
FuncInfo->setHasNonRISpills();
14801472
}

0 commit comments

Comments
 (0)