diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-02-28 00:43:03 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-02-28 00:43:03 +0000 |
commit | c799065cc34d90d67938098b6fec567addfbf931 (patch) | |
tree | aff43f7f613f03d6d13b9b7b7b9f4dfe8e1f278b /llvm/lib/CodeGen/LoopAligner.cpp | |
parent | 93e8b679a37c303f15a075e27f17f7e346238a4e (diff) | |
download | bcm5719-llvm-c799065cc34d90d67938098b6fec567addfbf931.tar.gz bcm5719-llvm-c799065cc34d90d67938098b6fec567addfbf931.zip |
Add a quick and dirty "loop aligner pass". x86 uses it to align its loops to 16-byte boundaries.
llvm-svn: 47703
Diffstat (limited to 'llvm/lib/CodeGen/LoopAligner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/LoopAligner.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/LoopAligner.cpp b/llvm/lib/CodeGen/LoopAligner.cpp new file mode 100644 index 00000000000..a40bb50565d --- /dev/null +++ b/llvm/lib/CodeGen/LoopAligner.cpp @@ -0,0 +1,65 @@ +//===-- 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 { + const TargetLowering *TLI; + + public: + static char ID; + LoopAligner() : MachineFunctionPass((intptr_t)&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>(); + 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->begin() == MLI->end()) + return false; // No loops. + + unsigned Align = MF.getTarget().getTargetLowering()->getPrefLoopAlignment(); + if (!Align) + return false; // Don't care about loop alignment. + + for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { + MachineBasicBlock *MBB = I; + if (MLI->isLoopHeader(MBB)) + MBB->setAlignment(Align); + } + + return true; +} |