summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodePlacementOpt.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-05-07 05:49:39 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-05-07 05:49:39 +0000
commit7132e12ee5658aa2b8ba6cdd81adb7944ddcb33e (patch)
treeeaacccda2782d082713bf7bbb7266eba3b48eaec /lib/CodeGen/CodePlacementOpt.cpp
parentbbf1db72133e9cf986e4da6260736335533067db (diff)
downloadllvm-7132e12ee5658aa2b8ba6cdd81adb7944ddcb33e.tar.gz
llvm-7132e12ee5658aa2b8ba6cdd81adb7944ddcb33e.tar.bz2
llvm-7132e12ee5658aa2b8ba6cdd81adb7944ddcb33e.tar.xz
Code refactoring.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71151 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodePlacementOpt.cpp')
-rw-r--r--lib/CodeGen/CodePlacementOpt.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/CodeGen/CodePlacementOpt.cpp b/lib/CodeGen/CodePlacementOpt.cpp
index 54121afefd..924a96930b 100644
--- a/lib/CodeGen/CodePlacementOpt.cpp
+++ b/lib/CodeGen/CodePlacementOpt.cpp
@@ -24,6 +24,8 @@ using namespace llvm;
namespace {
class CodePlacementOpt : public MachineFunctionPass {
+ const MachineLoopInfo *MLI;
+
public:
static char ID;
CodePlacementOpt() : MachineFunctionPass(&ID) {}
@@ -39,6 +41,9 @@ namespace {
AU.addPreservedID(MachineDominatorsID);
MachineFunctionPass::getAnalysisUsage(AU);
}
+
+ private:
+ bool AlignLoops(MachineFunction &MF);
};
char CodePlacementOpt::ID = 0;
@@ -48,12 +53,9 @@ FunctionPass *llvm::createCodePlacementOptPass() {
return new CodePlacementOpt();
}
-bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) {
- const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
-
- if (MLI->empty())
- return false; // No loops.
-
+/// AlignLoops - Align loop headers to target preferred alignments.
+///
+bool CodePlacementOpt::AlignLoops(MachineFunction &MF) {
const TargetLowering *TLI = MF.getTarget().getTargetLowering();
if (!TLI)
return false;
@@ -66,6 +68,7 @@ bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) {
if (F->hasFnAttr(Attribute::OptimizeForSize))
return false;
+ bool Changed = false;
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
MachineBasicBlock *MBB = I;
if (MLI->isLoopHeader(MBB)) {
@@ -75,8 +78,20 @@ bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) {
// to prevent adding noop's inside a loop.
continue;
MBB->setAlignment(Align);
+ Changed = true;
}
}
- return true;
+ return Changed;
+}
+
+bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) {
+ MLI = &getAnalysis<MachineLoopInfo>();
+ if (MLI->empty())
+ return false; // No loops.
+
+ bool Changed = false;
+ Changed |= AlignLoops(MF);
+
+ return Changed;
}