LLVM API Documentation

LoopAligner.cpp

Go to the documentation of this file.
00001 //===-- LoopAligner.cpp - Loop aligner pass. ------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the pass that align loop headers to target specific
00011 // alignment boundary.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #define DEBUG_TYPE "loopalign"
00016 #include "llvm/CodeGen/MachineLoopInfo.h"
00017 #include "llvm/CodeGen/MachineFunctionPass.h"
00018 #include "llvm/CodeGen/Passes.h"
00019 #include "llvm/Target/TargetLowering.h"
00020 #include "llvm/Target/TargetMachine.h"
00021 #include "llvm/Support/Compiler.h"
00022 #include "llvm/Support/Debug.h"
00023 using namespace llvm;
00024 
00025 namespace {
00026   class LoopAligner : public MachineFunctionPass {
00027   public:
00028     static char ID;
00029     LoopAligner() : MachineFunctionPass(&ID) {}
00030 
00031     virtual bool runOnMachineFunction(MachineFunction &MF);
00032     virtual const char *getPassName() const { return "Loop aligner"; }
00033 
00034     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00035       AU.addRequired<MachineLoopInfo>();
00036       AU.addPreserved<MachineLoopInfo>();
00037       AU.addPreservedID(MachineDominatorsID);
00038       MachineFunctionPass::getAnalysisUsage(AU);
00039     }
00040   };
00041 
00042   char LoopAligner::ID = 0;
00043 } // end anonymous namespace
00044 
00045 FunctionPass *llvm::createLoopAlignerPass() { return new LoopAligner(); }
00046 
00047 bool LoopAligner::runOnMachineFunction(MachineFunction &MF) {
00048   const MachineLoopInfo *MLI = &getAnalysis<MachineLoopInfo>();
00049 
00050   if (MLI->empty())
00051     return false;  // No loops.
00052 
00053   const TargetLowering *TLI = MF.getTarget().getTargetLowering();
00054   if (!TLI)
00055     return false;
00056 
00057   unsigned Align = TLI->getPrefLoopAlignment();
00058   if (!Align)
00059     return false;  // Don't care about loop alignment.
00060 
00061   const Function *F = MF.getFunction();
00062   if (F->hasFnAttr(Attribute::OptimizeForSize))
00063     return false;
00064 
00065   for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
00066     MachineBasicBlock *MBB = I;
00067     if (MLI->isLoopHeader(MBB))
00068       MBB->setAlignment(Align);
00069   }
00070 
00071   return true;
00072 }



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.