aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-05-08 19:01:44 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-05-08 19:01:44 +0000
commit0269d3cbf37227c48b7ce0f9710f0c6a15ff6fa9 (patch)
tree10d027a87292b5f82ca9ebd8dee08f03e0ef5dc5
parentc1c6ef8f74fc550f29cfec1f2fb699dd8c2fb94e (diff)
downloadexternal_llvm-0269d3cbf37227c48b7ce0f9710f0c6a15ff6fa9.zip
external_llvm-0269d3cbf37227c48b7ce0f9710f0c6a15ff6fa9.tar.gz
external_llvm-0269d3cbf37227c48b7ce0f9710f0c6a15ff6fa9.tar.bz2
Don't align loop header unless the loop back edge is below the header.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71242 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CodePlacementOpt.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/CodeGen/CodePlacementOpt.cpp b/lib/CodeGen/CodePlacementOpt.cpp
index 4276651..1848378 100644
--- a/lib/CodeGen/CodePlacementOpt.cpp
+++ b/lib/CodeGen/CodePlacementOpt.cpp
@@ -249,6 +249,20 @@ bool CodePlacementOpt::OptimizeIntraLoopEdges() {
return Changed;
}
+/// HeaderShouldBeAligned - Return true if the specified loop header block
+/// 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) {
+ for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
+ PE = MBB->pred_end(); PI != PE; ++PI) {
+ MachineBasicBlock *PredMBB = *PI;
+ if (PredMBB->getNumber() > MBB->getNumber())
+ return true;
+ }
+ return false;
+}
+
/// AlignLoops - Align loop headers to target preferred alignments.
///
bool CodePlacementOpt::AlignLoops(MachineFunction &MF) {
@@ -267,9 +281,11 @@ bool CodePlacementOpt::AlignLoops(MachineFunction &MF) {
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)) {
+ if (MLI->getLoopFor(HeaderMBB) == 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)) {
HeaderMBB->setAlignment(Align);
Changed = true;
++NumHeaderAligned;