Provide addc and subc
[llvm/msp430.git] / lib / CodeGen / LoopAligner.cpp
blobb67f5c3bf9192e0a9a444a813a4331d26a316102
1 //===-- LoopAligner.cpp - Loop aligner pass. ------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the pass that align loop headers to target specific
11 // alignment boundary.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "loopalign"
16 #include "llvm/CodeGen/MachineLoopInfo.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Target/TargetLowering.h"
20 #include "llvm/Target/TargetMachine.h"
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/Debug.h"
23 using namespace llvm;
25 namespace {
26 class LoopAligner : public MachineFunctionPass {
27 public:
28 static char ID;
29 LoopAligner() : MachineFunctionPass(&ID) {}
31 virtual bool runOnMachineFunction(MachineFunction &MF);
32 virtual const char *getPassName() const { return "Loop aligner"; }
34 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
35 AU.addRequired<MachineLoopInfo>();
36 AU.addPreserved<MachineLoopInfo>();
37 AU.addPreservedID(MachineDominatorsID);
38 MachineFunctionPass::getAnalysisUsage(AU);
42 char LoopAligner::ID = 0;
43 } // end anonymous namespace
45 FunctionPass *llvm::createLoopAlignerPass() { return new LoopAligner(); }
47 bool LoopAligner::runOnMachineFunction(MachineFunction &MF) {
48 const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
50 if (MLI->empty())
51 return false; // No loops.
53 const TargetLowering *TLI = MF.getTarget().getTargetLowering();
54 if (!TLI)
55 return false;
57 unsigned Align = TLI->getPrefLoopAlignment();
58 if (!Align)
59 return false; // Don't care about loop alignment.
61 const Function *F = MF.getFunction();
62 if (F->hasFnAttr(Attribute::OptimizeForSize))
63 return false;
65 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
66 MachineBasicBlock *MBB = I;
67 if (MLI->isLoopHeader(MBB)) {
68 MachineBasicBlock *PredBB = prior(I);
69 if (MLI->getLoopFor(MBB) == MLI->getLoopFor(PredBB))
70 // If previously BB is in the same loop, don't align this BB. We want
71 // to prevent adding noop's inside a loop.
72 continue;
73 MBB->setAlignment(Align);
77 return true;