diff options
| author | 2019-06-23 22:05:08 +0000 | |
|---|---|---|
| committer | 2019-06-23 22:05:08 +0000 | |
| commit | f27a781c9811da94fe68b2cf34237c2a61b48c96 (patch) | |
| tree | 820064216b8f115ba79122ebd03c5451b59fd690 /gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp | |
| parent | Import LLVM 8.0.0 release including clang, lld and lldb. (diff) | |
| download | wireguard-openbsd-f27a781c9811da94fe68b2cf34237c2a61b48c96.tar.xz wireguard-openbsd-f27a781c9811da94fe68b2cf34237c2a61b48c96.zip | |
Merge LLVM 8.0.0 release.
Prepared with help from jsg@ and mortimer@
Tested on amd64 by bcallah@, krw@, naddy@
Tested on arm64 by patrick@
Tested on macppc by kettenis@
Tested on octeon by visa@
Tested on sparc64 by claudio@
Diffstat (limited to 'gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp')
| -rw-r--r-- | gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 1119b570b7e..16c53cb6dbf 100644 --- a/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/gnu/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -75,6 +75,10 @@ using namespace llvm; using MBBVector = SmallVector<MachineBasicBlock *, 4>; +STATISTIC(NumLeafFuncWithSpills, "Number of leaf functions with CSRs"); +STATISTIC(NumFuncSeen, "Number of functions seen in PEI"); + + namespace { class PEI : public MachineFunctionPass { @@ -168,6 +172,7 @@ using StackObjSet = SmallSetVector<int, 8>; /// runOnMachineFunction - Insert prolog/epilog code and replace abstract /// frame indexes with appropriate references. bool PEI::runOnMachineFunction(MachineFunction &MF) { + NumFuncSeen++; const Function &F = MF.getFunction(); const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); @@ -385,6 +390,11 @@ static void assignCalleeSavedSpillSlots(MachineFunction &F, // Now that we know which registers need to be saved and restored, allocate // stack slots for them. for (auto &CS : CSI) { + // If the target has spilled this register to another register, we don't + // need to allocate a stack slot. + if (CS.isSpilledToReg()) + continue; + unsigned Reg = CS.getReg(); const TargetRegisterClass *RC = RegInfo->getMinimalPhysRegClass(Reg); @@ -482,7 +492,22 @@ static void updateLiveness(MachineFunction &MF) { if (!MRI.isReserved(Reg) && !MBB->isLiveIn(Reg)) MBB->addLiveIn(Reg); } + // If callee-saved register is spilled to another register rather than + // spilling to stack, the destination register has to be marked as live for + // each MBB between the prologue and epilogue so that it is not clobbered + // before it is reloaded in the epilogue. The Visited set contains all + // blocks outside of the region delimited by prologue/epilogue. + if (CSI[i].isSpilledToReg()) { + for (MachineBasicBlock &MBB : MF) { + if (Visited.count(&MBB)) + continue; + MCPhysReg DstReg = CSI[i].getDstReg(); + if (!MBB.isLiveIn(DstReg)) + MBB.addLiveIn(DstReg); + } + } } + } /// Insert restore code for the callee-saved registers used in the function. @@ -558,6 +583,9 @@ void PEI::spillCalleeSavedRegs(MachineFunction &MF) { std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo(); if (!CSI.empty()) { + if (!MFI.hasCalls()) + NumLeafFuncWithSpills++; + for (MachineBasicBlock *SaveBlock : SaveBlocks) { insertCSRSaves(*SaveBlock, CSI); // Update the live-in information of all the blocks up to the save @@ -1118,7 +1146,7 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF, MachineOperand &Offset = MI.getOperand(i + 1); int refOffset = TFI->getFrameIndexReferencePreferSP( MF, MI.getOperand(i).getIndex(), Reg, /*IgnoreSPUpdates*/ false); - Offset.setImm(Offset.getImm() + refOffset); + Offset.setImm(Offset.getImm() + refOffset + SPAdj); MI.getOperand(i).ChangeToRegister(Reg, false /*isDef*/); continue; } |
