summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodePlacementOpt.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-05-07 05:42:24 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-05-07 05:42:24 +0000
commitf356a89e926518249bace37cf2f5cefe1fcde878 (patch)
tree6dedb09dce71e4b4c9a7db7d9893bb704889d126 /llvm/lib/CodeGen/CodePlacementOpt.cpp
parenta55d46100e6981935323cccd34e3d0d2def0a553 (diff)
downloadbcm5719-llvm-f356a89e926518249bace37cf2f5cefe1fcde878.tar.gz
bcm5719-llvm-f356a89e926518249bace37cf2f5cefe1fcde878.zip
Rename "loop aligner" pass to "code placement optimization" pass.
llvm-svn: 71150
Diffstat (limited to 'llvm/lib/CodeGen/CodePlacementOpt.cpp')
-rw-r--r--llvm/lib/CodeGen/CodePlacementOpt.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodePlacementOpt.cpp b/llvm/lib/CodeGen/CodePlacementOpt.cpp
new file mode 100644
index 00000000000..54121afefda
--- /dev/null
+++ b/llvm/lib/CodeGen/CodePlacementOpt.cpp
@@ -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;
+}
OpenPOWER on IntegriCloud