LLVM  3.7.0
MachineLoopInfo.cpp
Go to the documentation of this file.
1 //===- MachineLoopInfo.cpp - Natural Loop Calculator ----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the MachineLoopInfo class that is used to identify natural
11 // loops and determine the loop depth of various nodes of the CFG. Note that
12 // the loops identified may actually be several natural loops that share the
13 // same header node... not just a single natural loop.
14 //
15 //===----------------------------------------------------------------------===//
16 
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Support/Debug.h"
23 using namespace llvm;
24 
25 // Explicitly instantiate methods in LoopInfoImpl.h for MI-level Loops.
28 
29 char MachineLoopInfo::ID = 0;
30 INITIALIZE_PASS_BEGIN(MachineLoopInfo, "machine-loops",
31  "Machine Natural Loop Construction", true, true)
34  "Machine Natural Loop Construction", true, true)
35 
36 char &llvm::MachineLoopInfoID = MachineLoopInfo::ID;
37 
38 bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) {
39  releaseMemory();
40  LI.Analyze(getAnalysis<MachineDominatorTree>().getBase());
41  return false;
42 }
43 
45  AU.setPreservesAll();
48 }
49 
51  MachineBasicBlock *TopMBB = getHeader();
52  MachineFunction::iterator Begin = TopMBB->getParent()->begin();
53  if (TopMBB != Begin) {
54  MachineBasicBlock *PriorMBB = std::prev(MachineFunction::iterator(TopMBB));
55  while (contains(PriorMBB)) {
56  TopMBB = PriorMBB;
57  if (TopMBB == Begin) break;
58  PriorMBB = std::prev(MachineFunction::iterator(TopMBB));
59  }
60  }
61  return TopMBB;
62 }
63 
65  MachineBasicBlock *BotMBB = getHeader();
66  MachineFunction::iterator End = BotMBB->getParent()->end();
67  if (BotMBB != std::prev(End)) {
68  MachineBasicBlock *NextMBB = std::next(MachineFunction::iterator(BotMBB));
69  while (contains(NextMBB)) {
70  BotMBB = NextMBB;
71  if (BotMBB == std::next(MachineFunction::iterator(BotMBB))) break;
72  NextMBB = std::next(MachineFunction::iterator(BotMBB));
73  }
74  }
75  return BotMBB;
76 }
77 
78 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
79 void MachineLoop::dump() const {
80  print(dbgs());
81 }
82 #endif
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
machine Machine Natural Loop true
void print(raw_ostream &OS, unsigned Depth=0) const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:70
MachineBasicBlock * getTopBlock()
getTopBlock - Return the "top" block in the loop, which is the first block in the linear layout...
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
MachineBasicBlock * getBottomBlock()
getBottomBlock - Return the "bottom" block in the loop, which is the last block in the linear layout...
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:75
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:301
void dump() const
INITIALIZE_PASS_BEGIN(MachineLoopInfo,"machine-loops","Machine Natural Loop Construction", true, true) INITIALIZE_PASS_END(MachineLoopInfo
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
bool contains(const LoopT *L) const
contains - Return true if the specified loop is contained within in this loop.
Definition: LoopInfo.h:105
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
machine loops
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
void setPreservesAll()
Set by analyses that do not transform their input at all.
machine Machine Natural Loop Construction
BasicBlockListType::iterator iterator
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
LoopInfo - This class builds and contains all of the top level loop structures in the specified funct...
Definition: LoopInfo.h:57