Newer
Older
Evan Cheng
committed
//===-- 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/CommandLine.h"
Evan Cheng
committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#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;
}