[llvm-branch-commits] [llvm-branch] r71614 - in /llvm/branches/Apple/Dib: lib/CodeGen/CodePlacementOpt.cpp test/CodeGen/X86/avoid-loop-align-2.ll
Bill Wendling
isanbard at gmail.com
Tue May 12 17:36:49 PDT 2009
Author: void
Date: Tue May 12 19:36:30 2009
New Revision: 71614
URL: http://llvm.org/viewvc/llvm-project?rev=71614&view=rev
Log:
--- Merging r71609 into '.':
A test/CodeGen/X86/avoid-loop-align-2.ll
U lib/CodeGen/CodePlacementOpt.cpp
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.
Added:
llvm/branches/Apple/Dib/test/CodeGen/X86/avoid-loop-align-2.ll
- copied unchanged from r71609, llvm/trunk/test/CodeGen/X86/avoid-loop-align-2.ll
Modified:
llvm/branches/Apple/Dib/lib/CodeGen/CodePlacementOpt.cpp
Modified: llvm/branches/Apple/Dib/lib/CodeGen/CodePlacementOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/CodePlacementOpt.cpp?rev=71614&r1=71613&r2=71614&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/CodePlacementOpt.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/CodePlacementOpt.cpp Tue May 12 19:36:30 2009
@@ -62,6 +62,8 @@
private:
bool OptimizeIntraLoopEdges();
+ bool HeaderShouldBeAligned(MachineBasicBlock *MBB, MachineLoop *L,
+ SmallPtrSet<MachineBasicBlock*, 4> &DoNotAlign);
bool AlignLoops(MachineFunction &MF);
};
@@ -243,14 +245,37 @@
/// 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.
@@ -268,14 +293,16 @@
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;
More information about the llvm-branch-commits
mailing list