From fb8075d03f5c87bd57dcc9c5f2304f6b13c55aad Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 28 Feb 2008 00:43:03 +0000 Subject: Add a quick and dirty "loop aligner pass". x86 uses it to align its loops to 16-byte boundaries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47703 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/LoopAligner.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/CodeGen/LoopAligner.cpp (limited to 'lib/CodeGen/LoopAligner.cpp') diff --git a/lib/CodeGen/LoopAligner.cpp b/lib/CodeGen/LoopAligner.cpp new file mode 100644 index 0000000000..a40bb50565 --- /dev/null +++ b/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(); + AU.addPreserved(); + 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(); + + 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; +} -- cgit v1.2.3