forked from OSchip/llvm-project
Revert "[PEI] Separate saving and restoring CSRs into different functions. NFC"
This reverts commit 540f6a26ae932469804a379ce9a8cbe715d59c23. sanitizer-ppc64le-linux seems to segfault when testing the sanitizers. llvm-svn: 308580
This commit is contained in:
parent
364b535234
commit
b3ddc1686b
|
@ -455,47 +455,76 @@ static void updateLiveness(MachineFunction &MF) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert restore code for the callee-saved registers used in the function.
|
/// insertCSRSpillsAndRestores - Insert spill and restore code for
|
||||||
static void insertCSRSaves(MachineBasicBlock &SaveBlock,
|
/// callee saved registers used in the function.
|
||||||
ArrayRef<CalleeSavedInfo> CSI) {
|
///
|
||||||
MachineFunction &Fn = *SaveBlock.getParent();
|
static void insertCSRSpillsAndRestores(MachineFunction &Fn,
|
||||||
|
const MBBVector &SaveBlocks,
|
||||||
|
const MBBVector &RestoreBlocks) {
|
||||||
|
// Get callee saved register information.
|
||||||
|
MachineFrameInfo &MFI = Fn.getFrameInfo();
|
||||||
|
const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
|
||||||
|
|
||||||
|
MFI.setCalleeSavedInfoValid(true);
|
||||||
|
|
||||||
|
// Early exit if no callee saved registers are modified!
|
||||||
|
if (CSI.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
|
const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
|
||||||
const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering();
|
const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering();
|
||||||
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
|
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
|
||||||
|
MachineBasicBlock::iterator I;
|
||||||
|
|
||||||
MachineBasicBlock::iterator I = SaveBlock.begin();
|
// Spill using target interface.
|
||||||
if (!TFI->spillCalleeSavedRegisters(SaveBlock, I, CSI, TRI)) {
|
for (MachineBasicBlock *SaveBlock : SaveBlocks) {
|
||||||
for (const CalleeSavedInfo &CS : CSI) {
|
I = SaveBlock->begin();
|
||||||
// Insert the spill to the stack frame.
|
if (!TFI->spillCalleeSavedRegisters(*SaveBlock, I, CSI, TRI)) {
|
||||||
unsigned Reg = CS.getReg();
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
||||||
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
// Insert the spill to the stack frame.
|
||||||
TII.storeRegToStackSlot(SaveBlock, I, Reg, true, CS.getFrameIdx(), RC,
|
unsigned Reg = CSI[i].getReg();
|
||||||
TRI);
|
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
||||||
|
TII.storeRegToStackSlot(*SaveBlock, I, Reg, true, CSI[i].getFrameIdx(),
|
||||||
|
RC, TRI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Update the live-in information of all the blocks up to the save point.
|
||||||
|
updateLiveness(Fn);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert restore code for the callee-saved registers used in the function.
|
// Restore using target interface.
|
||||||
static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
|
for (MachineBasicBlock *MBB : RestoreBlocks) {
|
||||||
ArrayRef<CalleeSavedInfo> CSI) {
|
I = MBB->end();
|
||||||
MachineFunction &Fn = *RestoreBlock.getParent();
|
|
||||||
const TargetInstrInfo &TII = *Fn.getSubtarget().getInstrInfo();
|
|
||||||
const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering();
|
|
||||||
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
|
|
||||||
|
|
||||||
// Restore all registers immediately before the return and any
|
// Skip over all terminator instructions, which are part of the return
|
||||||
// terminators that precede it.
|
// sequence.
|
||||||
MachineBasicBlock::iterator I = RestoreBlock.getFirstTerminator();
|
MachineBasicBlock::iterator I2 = I;
|
||||||
|
while (I2 != MBB->begin() && (--I2)->isTerminator())
|
||||||
|
I = I2;
|
||||||
|
|
||||||
if (!TFI->restoreCalleeSavedRegisters(RestoreBlock, I, CSI, TRI)) {
|
bool AtStart = I == MBB->begin();
|
||||||
for (const CalleeSavedInfo &CI : reverse(CSI)) {
|
MachineBasicBlock::iterator BeforeI = I;
|
||||||
unsigned Reg = CI.getReg();
|
if (!AtStart)
|
||||||
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
--BeforeI;
|
||||||
TII.loadRegFromStackSlot(RestoreBlock, I, Reg, CI.getFrameIdx(), RC, TRI);
|
|
||||||
assert(I != RestoreBlock.begin() &&
|
// Restore all registers immediately before the return and any
|
||||||
"loadRegFromStackSlot didn't insert any code!");
|
// terminators that precede it.
|
||||||
// Insert in reverse order. loadRegFromStackSlot can insert
|
if (!TFI->restoreCalleeSavedRegisters(*MBB, I, CSI, TRI)) {
|
||||||
// multiple instructions.
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
||||||
|
unsigned Reg = CSI[i].getReg();
|
||||||
|
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
||||||
|
TII.loadRegFromStackSlot(*MBB, I, Reg, CSI[i].getFrameIdx(), RC, TRI);
|
||||||
|
assert(I != MBB->begin() &&
|
||||||
|
"loadRegFromStackSlot didn't insert any code!");
|
||||||
|
// Insert in reverse order. loadRegFromStackSlot can insert
|
||||||
|
// multiple instructions.
|
||||||
|
if (AtStart)
|
||||||
|
I = MBB->begin();
|
||||||
|
else {
|
||||||
|
I = BeforeI;
|
||||||
|
++I;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,7 +532,6 @@ static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
|
||||||
void PEI::doSpillCalleeSavedRegs(MachineFunction &Fn) {
|
void PEI::doSpillCalleeSavedRegs(MachineFunction &Fn) {
|
||||||
const Function *F = Fn.getFunction();
|
const Function *F = Fn.getFunction();
|
||||||
const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering();
|
const TargetFrameLowering *TFI = Fn.getSubtarget().getFrameLowering();
|
||||||
MachineFrameInfo &MFI = Fn.getFrameInfo();
|
|
||||||
MinCSFrameIndex = std::numeric_limits<unsigned>::max();
|
MinCSFrameIndex = std::numeric_limits<unsigned>::max();
|
||||||
MaxCSFrameIndex = 0;
|
MaxCSFrameIndex = 0;
|
||||||
|
|
||||||
|
@ -515,21 +543,8 @@ void PEI::doSpillCalleeSavedRegs(MachineFunction &Fn) {
|
||||||
assignCalleeSavedSpillSlots(Fn, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex);
|
assignCalleeSavedSpillSlots(Fn, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex);
|
||||||
|
|
||||||
// Add the code to save and restore the callee saved registers.
|
// Add the code to save and restore the callee saved registers.
|
||||||
if (!F->hasFnAttribute(Attribute::Naked)) {
|
if (!F->hasFnAttribute(Attribute::Naked))
|
||||||
MFI.setCalleeSavedInfoValid(true);
|
insertCSRSpillsAndRestores(Fn, SaveBlocks, RestoreBlocks);
|
||||||
|
|
||||||
ArrayRef<CalleeSavedInfo> CSI = MFI.getCalleeSavedInfo();
|
|
||||||
if (!CSI.empty()) {
|
|
||||||
for (MachineBasicBlock *SaveBlock : SaveBlocks) {
|
|
||||||
insertCSRSaves(*SaveBlock, CSI);
|
|
||||||
// Update the live-in information of all the blocks up to the save
|
|
||||||
// point.
|
|
||||||
updateLiveness(Fn);
|
|
||||||
}
|
|
||||||
for (MachineBasicBlock *RestoreBlock : RestoreBlocks)
|
|
||||||
insertCSRRestores(*RestoreBlock, CSI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
|
/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
|
||||||
|
|
Loading…
Reference in New Issue