From 7132e12ee5658aa2b8ba6cdd81adb7944ddcb33e Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 7 May 2009 05:49:39 +0000 Subject: [PATCH] Code refactoring. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71151 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodePlacementOpt.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/CodeGen/CodePlacementOpt.cpp b/lib/CodeGen/CodePlacementOpt.cpp index 54121afefda..924a96930b5 100644 --- a/lib/CodeGen/CodePlacementOpt.cpp +++ b/lib/CodeGen/CodePlacementOpt.cpp @@ -24,6 +24,8 @@ using namespace llvm; namespace { class CodePlacementOpt : public MachineFunctionPass { + const MachineLoopInfo *MLI; + public: static char ID; CodePlacementOpt() : MachineFunctionPass(&ID) {} @@ -39,6 +41,9 @@ namespace { AU.addPreservedID(MachineDominatorsID); MachineFunctionPass::getAnalysisUsage(AU); } + + private: + bool AlignLoops(MachineFunction &MF); }; char CodePlacementOpt::ID = 0; @@ -48,12 +53,9 @@ FunctionPass *llvm::createCodePlacementOptPass() { return new CodePlacementOpt(); } -bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) { - const MachineLoopInfo *MLI = &getAnalysis(); - - if (MLI->empty()) - return false; // No loops. - +/// AlignLoops - Align loop headers to target preferred alignments. +/// +bool CodePlacementOpt::AlignLoops(MachineFunction &MF) { const TargetLowering *TLI = MF.getTarget().getTargetLowering(); if (!TLI) return false; @@ -66,6 +68,7 @@ bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) { if (F->hasFnAttr(Attribute::OptimizeForSize)) return false; + bool Changed = false; for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { MachineBasicBlock *MBB = I; if (MLI->isLoopHeader(MBB)) { @@ -75,8 +78,20 @@ bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) { // to prevent adding noop's inside a loop. continue; MBB->setAlignment(Align); + Changed = true; } } - return true; + return Changed; +} + +bool CodePlacementOpt::runOnMachineFunction(MachineFunction &MF) { + MLI = &getAnalysis(); + if (MLI->empty()) + return false; // No loops. + + bool Changed = false; + Changed |= AlignLoops(MF); + + return Changed; }