[llvm] r276886 - [Hexagon] Add saved callee-saved registers as live-in in non-wrapped blocks
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 27 09:26:40 PDT 2016
Author: kparzysz
Date: Wed Jul 27 11:26:39 2016
New Revision: 276886
URL: http://llvm.org/viewvc/llvm-project?rev=276886&view=rev
Log:
[Hexagon] Add saved callee-saved registers as live-in in non-wrapped blocks
The callee-saved registers that are saved in a function are not pristine,
and so they can be defined and used. In case of shrink-wrapping though,
there are blocks that are outside of the save/restore range, and in those
blocks the saved registers must be treated as pristine. To avoid any uses
of these registers, add them as live-in in all those blocks.
This was already done for blocks reaching function exits after restore,
add code that does the same for blocks reached from the function entry
before save.
Modified:
llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp
llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.h
Modified: llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp?rev=276886&r1=276885&r2=276886&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp Wed Jul 27 11:26:39 2016
@@ -457,6 +457,7 @@ void HexagonFrameLowering::emitPrologue(
bool PrologueStubs = false;
insertCSRSpillsInBlock(*PrologB, CSI, HRI, PrologueStubs);
insertPrologueInBlock(*PrologB, PrologueStubs);
+ updateEntryPaths(MF, *PrologB);
if (EpilogB) {
insertCSRRestoresInBlock(*EpilogB, CSI, HRI);
@@ -485,12 +486,9 @@ void HexagonFrameLowering::emitPrologue(
// If there is an epilog block, it may not have a return instruction.
// In such case, we need to add the callee-saved registers as live-ins
// in all blocks on all paths from the epilog to any return block.
- unsigned MaxBN = 0;
- for (auto &B : MF)
- if (B.getNumber() >= 0)
- MaxBN = std::max(MaxBN, unsigned(B.getNumber()));
+ unsigned MaxBN = MF.getNumBlockIDs();
BitVector DoneT(MaxBN+1), DoneF(MaxBN+1), Path(MaxBN+1);
- updateExitPaths(*EpilogB, EpilogB, DoneT, DoneF, Path);
+ updateExitPaths(*EpilogB, *EpilogB, DoneT, DoneF, Path);
}
}
@@ -653,9 +651,30 @@ void HexagonFrameLowering::insertEpilogu
MBB.erase(RetI);
}
+void HexagonFrameLowering::updateEntryPaths(MachineFunction &MF,
+ MachineBasicBlock &SaveB) const {
+ SetVector<unsigned> Worklist;
+
+ MachineBasicBlock &EntryB = MF.front();
+ Worklist.insert(EntryB.getNumber());
+
+ unsigned SaveN = SaveB.getNumber();
+ auto &CSI = MF.getFrameInfo()->getCalleeSavedInfo();
+
+ for (unsigned i = 0; i < Worklist.size(); ++i) {
+ unsigned BN = Worklist[i];
+ MachineBasicBlock &MBB = *MF.getBlockNumbered(BN);
+ for (auto &R : CSI)
+ if (!MBB.isLiveIn(R.getReg()))
+ MBB.addLiveIn(R.getReg());
+ if (BN != SaveN)
+ for (auto &SB : MBB.successors())
+ Worklist.insert(SB->getNumber());
+ }
+}
bool HexagonFrameLowering::updateExitPaths(MachineBasicBlock &MBB,
- MachineBasicBlock *RestoreB, BitVector &DoneT, BitVector &DoneF,
+ MachineBasicBlock &RestoreB, BitVector &DoneT, BitVector &DoneF,
BitVector &Path) const {
assert(MBB.getNumber() >= 0);
unsigned BN = MBB.getNumber();
@@ -685,7 +704,7 @@ bool HexagonFrameLowering::updateExitPat
// We don't want to add unnecessary live-ins to the restore block: since
// the callee-saved registers are being defined in it, the entry of the
// restore block cannot be on the path from the definitions to any exit.
- if (ReachedExit && &MBB != RestoreB) {
+ if (ReachedExit && &MBB != &RestoreB) {
for (auto &R : CSI)
if (!MBB.isLiveIn(R.getReg()))
MBB.addLiveIn(R.getReg());
Modified: llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.h?rev=276886&r1=276885&r2=276886&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.h (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.h Wed Jul 27 11:26:39 2016
@@ -91,7 +91,8 @@ private:
const HexagonRegisterInfo &HRI, bool &PrologueStubs) const;
bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,
const HexagonRegisterInfo &HRI) const;
- bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock *RestoreB,
+ void updateEntryPaths(MachineFunction &MF, MachineBasicBlock &SaveB) const;
+ bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock &RestoreB,
BitVector &DoneT, BitVector &DoneF, BitVector &Path) const;
void insertCFIInstructionsAt(MachineBasicBlock &MBB,
MachineBasicBlock::iterator At) const;
More information about the llvm-commits
mailing list