[llvm-commits] [llvm] r71151 - /llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp

Evan Cheng evan.cheng at apple.com
Wed May 6 22:49:39 PDT 2009


Author: evancheng
Date: Thu May  7 00:49:39 2009
New Revision: 71151

URL: http://llvm.org/viewvc/llvm-project?rev=71151&view=rev
Log:
Code refactoring.

Modified:
    llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp

Modified: llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp?rev=71151&r1=71150&r2=71151&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodePlacementOpt.cpp Thu May  7 00:49:39 2009
@@ -24,6 +24,8 @@
 
 namespace {
   class CodePlacementOpt : public MachineFunctionPass {
+    const MachineLoopInfo *MLI;
+
   public:
     static char ID;
     CodePlacementOpt() : MachineFunctionPass(&ID) {}
@@ -39,6 +41,9 @@
       AU.addPreservedID(MachineDominatorsID);
       MachineFunctionPass::getAnalysisUsage(AU);
     }
+
+  private:
+    bool AlignLoops(MachineFunction &MF);
   };
 
   char CodePlacementOpt::ID = 0;
@@ -48,12 +53,9 @@
   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 @@
   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 @@
         // 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;
 }





More information about the llvm-commits mailing list