diff options
author | Evan Cheng <evan.cheng@apple.com> | 2009-05-12 23:58:14 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2009-05-12 23:58:14 +0000 |
commit | 9d3094b38e51c85e93fc5a9c8ab23c95b73f78d4 (patch) | |
tree | 374063c19ca26b694e2ac9e2673cc729628ca4fa /lib/CodeGen | |
parent | eca24fba3fccb08ed822827601a0da32bf1d508d (diff) | |
download | external_llvm-9d3094b38e51c85e93fc5a9c8ab23c95b73f78d4.zip external_llvm-9d3094b38e51c85e93fc5a9c8ab23c95b73f78d4.tar.gz external_llvm-9d3094b38e51c85e93fc5a9c8ab23c95b73f78d4.tar.bz2 |
If header of inner loop is aligned, do not align the outer loop header. We don't want to add nops in the outer loop for the sake of aligning the inner loop.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71609 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CodePlacementOpt.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/lib/CodeGen/CodePlacementOpt.cpp b/lib/CodeGen/CodePlacementOpt.cpp index 2e1d12d..61a8b12 100644 --- a/lib/CodeGen/CodePlacementOpt.cpp +++ b/lib/CodeGen/CodePlacementOpt.cpp @@ -62,6 +62,8 @@ namespace { private: bool OptimizeIntraLoopEdges(); + bool HeaderShouldBeAligned(MachineBasicBlock *MBB, MachineLoop *L, + SmallPtrSet<MachineBasicBlock*, 4> &DoNotAlign); bool AlignLoops(MachineFunction &MF); }; @@ -244,14 +246,37 @@ bool CodePlacementOpt::OptimizeIntraLoopEdges() { /// should be aligned. For now, we will not align it if all the predcessors /// (i.e. loop back edges) are laid out above the header. FIXME: Do not /// align small loops. -static bool HeaderShouldBeAligned(MachineBasicBlock *MBB) { +bool +CodePlacementOpt::HeaderShouldBeAligned(MachineBasicBlock *MBB, MachineLoop *L, + SmallPtrSet<MachineBasicBlock*, 4> &DoNotAlign) { + if (DoNotAlign.count(MBB)) + return false; + + bool BackEdgeBelow = false; for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(), PE = MBB->pred_end(); PI != PE; ++PI) { MachineBasicBlock *PredMBB = *PI; - if (PredMBB == MBB || PredMBB->getNumber() > MBB->getNumber()) - return true; + if (PredMBB == MBB || PredMBB->getNumber() > MBB->getNumber()) { + BackEdgeBelow = true; + break; + } + } + + if (!BackEdgeBelow) + return false; + + // Ok, we are going to align this loop header. If it's an inner loop, + // do not align its outer loop. + MachineBasicBlock *PreHeader = L->getLoopPreheader(); + if (PreHeader) { + MachineLoop *L = MLI->getLoopFor(PreHeader); + if (L) { + MachineBasicBlock *HeaderBlock = L->getHeader(); + HeaderBlock->setAlignment(0); + DoNotAlign.insert(HeaderBlock); + } } - return false; + return true; } /// AlignLoops - Align loop headers to target preferred alignments. @@ -269,14 +294,16 @@ bool CodePlacementOpt::AlignLoops(MachineFunction &MF) { MF.RenumberBlocks(); bool Changed = false; + SmallPtrSet<MachineBasicBlock*, 4> DoNotAlign; for (unsigned i = 0, e = LoopHeaders.size(); i != e; ++i) { MachineBasicBlock *HeaderMBB = LoopHeaders[i]; MachineBasicBlock *PredMBB = prior(MachineFunction::iterator(HeaderMBB)); - if (MLI->getLoopFor(HeaderMBB) == MLI->getLoopFor(PredMBB)) + MachineLoop *L = MLI->getLoopFor(HeaderMBB); + if (L == MLI->getLoopFor(PredMBB)) // If previously BB is in the same loop, don't align this BB. We want // to prevent adding noop's inside a loop. continue; - if (HeaderShouldBeAligned(HeaderMBB)) { + if (HeaderShouldBeAligned(HeaderMBB, L, DoNotAlign)) { HeaderMBB->setAlignment(Align); Changed = true; ++NumHeaderAligned; |