Rename "loop aligner" pass to "code placement optimization" pass.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 7 May 2009 05:42:24 +0000 (05:42 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 7 May 2009 05:42:24 +0000 (05:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71150 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/Passes.h
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodePlacementOpt.cpp [new file with mode: 0644]
lib/CodeGen/LLVMTargetMachine.cpp
lib/CodeGen/LoopAligner.cpp [deleted file]

index faf98319525783d72f3d47bf77e8b31107ff62bc..ff80dbacd61abc4d805e99dfa95b75ad77ca4cb4 100644 (file)
@@ -146,9 +146,9 @@ namespace llvm {
   /// IfConverter Pass - This pass performs machine code if conversion.
   FunctionPass *createIfConverterPass();
 
-  /// LoopAligner Pass - This pass aligns loop headers to target specific
-  /// alignment boundary.
-  FunctionPass *createLoopAlignerPass();
+  /// Code Placement Pass - This pass optimize code placement and aligns loop
+  /// headers to target specific alignment boundary.
+  FunctionPass *createCodePlacementOptPass();
 
   /// DebugLabelFoldingPass - This pass prunes out redundant debug labels.  This
   /// allows a debug emitter to determine if the range of two labels is empty,
index bf8c153a32e009ee1d170d4c8dc82bbe6203edd3..2cae80f321dd12720e30694a258a4ca3a321aef1 100644 (file)
@@ -1,5 +1,6 @@
 add_llvm_library(LLVMCodeGen
   BranchFolding.cpp
+  CodePlacementOpt.cpp
   DeadMachineInstructionElim.cpp
   ELFWriter.cpp
   GCMetadata.cpp
@@ -13,7 +14,6 @@ add_llvm_library(LLVMCodeGen
   LiveIntervalAnalysis.cpp
   LiveStackAnalysis.cpp
   LiveVariables.cpp
-  LoopAligner.cpp
   LowerSubregs.cpp
   MachOWriter.cpp
   MachineBasicBlock.cpp
diff --git a/lib/CodeGen/CodePlacementOpt.cpp b/lib/CodeGen/CodePlacementOpt.cpp
new file mode 100644 (file)
index 0000000..54121af
--- /dev/null
@@ -0,0 +1,82 @@
+//===-- CodePlacementOpt.cpp - Code Placement pass. -----------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the pass that optimize code placement and align loop
+// headers to target specific alignment boundary.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "code-placement"
+#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Debug.h"
+using namespace llvm;
+
+namespace {
+  class CodePlacementOpt : public MachineFunctionPass {
+  public:
+    static char ID;
+    CodePlacementOpt() : MachineFunctionPass(&ID) {}
+
+    virtual bool runOnMachineFunction(MachineFunction &MF);
+    virtual const char *getPassName() const {
+      return "Code Placement Optimizater";
+    }
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<MachineLoopInfo>();
+      AU.addPreserved<MachineLoopInfo>();
+      AU.addPreservedID(MachineDominatorsID);
+      MachineFunctionPass::getAnalysisUsage(AU);
+    }
+  };
+
+  char CodePlacementOpt::ID = 0;
+} // end anonymous namespace
+
+FunctionPass *llvm::createCodePlacementOptPass() {
+  return new CodePlacementOpt();
+}
+
+bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) {
+  const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
+
+  if (MLI->empty())
+    return false;  // No loops.
+
+  const TargetLowering *TLI = MF.getTarget().getTargetLowering();
+  if (!TLI)
+    return false;
+
+  unsigned Align = TLI->getPrefLoopAlignment();
+  if (!Align)
+    return false;  // Don't care about loop alignment.
+
+  const Function *F = MF.getFunction();
+  if (F->hasFnAttr(Attribute::OptimizeForSize))
+    return false;
+
+  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
+    MachineBasicBlock *MBB = I;
+    if (MLI->isLoopHeader(MBB)) {
+      MachineBasicBlock *PredBB = prior(I);
+      if (MLI->getLoopFor(MBB) == MLI->getLoopFor(PredBB))
+        // If previously BB is in the same loop, don't align this BB. We want
+        // to prevent adding noop's inside a loop.
+        continue;
+      MBB->setAlignment(Align);
+    }
+  }
+
+  return true;
+}
index b4a0bc2b7ae128da107134b30fe60dfa7d6a1509..c93ecdab476950d1fb129d53987e17002a506c70 100644 (file)
@@ -70,7 +70,7 @@ LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
     PM.add(createMachineFunctionPrinterPass(cerr));
 
   if (OptLevel != CodeGenOpt::None)
-    PM.add(createLoopAlignerPass());
+    PM.add(createCodePlacementOptPass());
 
   switch (FileType) {
   default:
diff --git a/lib/CodeGen/LoopAligner.cpp b/lib/CodeGen/LoopAligner.cpp
deleted file mode 100644 (file)
index b67f5c3..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-//===-- LoopAligner.cpp - Loop aligner pass. ------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the pass that align loop headers to target specific
-// alignment boundary.
-//
-//===----------------------------------------------------------------------===//
-
-#define DEBUG_TYPE "loopalign"
-#include "llvm/CodeGen/MachineLoopInfo.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/Passes.h"
-#include "llvm/Target/TargetLowering.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Debug.h"
-using namespace llvm;
-
-namespace {
-  class LoopAligner : public MachineFunctionPass {
-  public:
-    static char ID;
-    LoopAligner() : MachineFunctionPass(&ID) {}
-
-    virtual bool runOnMachineFunction(MachineFunction &MF);
-    virtual const char *getPassName() const { return "Loop aligner"; }
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<MachineLoopInfo>();
-      AU.addPreserved<MachineLoopInfo>();
-      AU.addPreservedID(MachineDominatorsID);
-      MachineFunctionPass::getAnalysisUsage(AU);
-    }
-  };
-
-  char LoopAligner::ID = 0;
-} // end anonymous namespace
-
-FunctionPass *llvm::createLoopAlignerPass() { return new LoopAligner(); }
-
-bool LoopAligner::runOnMachineFunction(MachineFunction &MF) {
-  const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
-
-  if (MLI->empty())
-    return false;  // No loops.
-
-  const TargetLowering *TLI = MF.getTarget().getTargetLowering();
-  if (!TLI)
-    return false;
-
-  unsigned Align = TLI->getPrefLoopAlignment();
-  if (!Align)
-    return false;  // Don't care about loop alignment.
-
-  const Function *F = MF.getFunction();
-  if (F->hasFnAttr(Attribute::OptimizeForSize))
-    return false;
-
-  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
-    MachineBasicBlock *MBB = I;
-    if (MLI->isLoopHeader(MBB)) {
-      MachineBasicBlock *PredBB = prior(I);
-      if (MLI->getLoopFor(MBB) == MLI->getLoopFor(PredBB))
-        // If previously BB is in the same loop, don't align this BB. We want
-        // to prevent adding noop's inside a loop.
-        continue;
-      MBB->setAlignment(Align);
-    }
-  }
-
-  return true;
-}