diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-20 04:16:37 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-20 04:16:37 +0000 |
commit | 7e3f3cec672df37935f6c651d1135657fdfe5cdd (patch) | |
tree | 8a389b6896953c690b4842840dccf7fc7c11dccf | |
parent | b2455d2907541391f396ae4eecd5814aecb6ce4d (diff) | |
download | external_llvm-7e3f3cec672df37935f6c651d1135657fdfe5cdd.zip external_llvm-7e3f3cec672df37935f6c651d1135657fdfe5cdd.tar.gz external_llvm-7e3f3cec672df37935f6c651d1135657fdfe5cdd.tar.bz2 |
Add getTopBlock and getBottomBlock member functions to MachineLoopInfo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84596 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/CodeGen/MachineLoopInfo.h | 11 | ||||
-rw-r--r-- | lib/CodeGen/MachineLoopInfo.cpp | 28 |
2 files changed, 39 insertions, 0 deletions
diff --git a/include/llvm/CodeGen/MachineLoopInfo.h b/include/llvm/CodeGen/MachineLoopInfo.h index 65ad4e4..d3df805 100644 --- a/include/llvm/CodeGen/MachineLoopInfo.h +++ b/include/llvm/CodeGen/MachineLoopInfo.h @@ -38,6 +38,17 @@ namespace llvm { class MachineLoop : public LoopBase<MachineBasicBlock, MachineLoop> { public: MachineLoop(); + + /// getTopBlock - Return the "top" block in the loop, which is the first + /// block in the linear layout, ignoring any parts of the loop not + /// contiguous with the part the contains the header. + MachineBasicBlock *getTopBlock(); + + /// getBottomBlock - Return the "bottom" block in the loop, which is the last + /// block in the linear layout, ignoring any parts of the loop not + /// contiguous with the part the contains the header. + MachineBasicBlock *getBottomBlock(); + private: friend class LoopInfoBase<MachineBasicBlock, MachineLoop>; explicit MachineLoop(MachineBasicBlock *MBB) diff --git a/lib/CodeGen/MachineLoopInfo.cpp b/lib/CodeGen/MachineLoopInfo.cpp index 2da8e37..db77d19 100644 --- a/lib/CodeGen/MachineLoopInfo.cpp +++ b/lib/CodeGen/MachineLoopInfo.cpp @@ -43,3 +43,31 @@ void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<MachineDominatorTree>(); MachineFunctionPass::getAnalysisUsage(AU); } + +MachineBasicBlock *MachineLoop::getTopBlock() { + MachineBasicBlock *TopMBB = getHeader(); + MachineFunction::iterator Begin = TopMBB->getParent()->begin(); + if (TopMBB != Begin) { + MachineBasicBlock *PriorMBB = prior(MachineFunction::iterator(TopMBB)); + while (contains(PriorMBB)) { + TopMBB = PriorMBB; + if (TopMBB == Begin) break; + PriorMBB = prior(MachineFunction::iterator(TopMBB)); + } + } + return TopMBB; +} + +MachineBasicBlock *MachineLoop::getBottomBlock() { + MachineBasicBlock *BotMBB = getHeader(); + MachineFunction::iterator End = BotMBB->getParent()->end(); + if (BotMBB != prior(End)) { + MachineBasicBlock *NextMBB = next(MachineFunction::iterator(BotMBB)); + while (contains(NextMBB)) { + BotMBB = NextMBB; + if (BotMBB == next(MachineFunction::iterator(BotMBB))) break; + NextMBB = next(MachineFunction::iterator(BotMBB)); + } + } + return BotMBB; +} |