LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
22 using namespace llvm;
23 
24 // Explicitly instantiate methods in LoopInfoImpl.h for MI-level Loops.
27 
28 char MachineLoopInfo::ID = 0;
29 INITIALIZE_PASS_BEGIN(MachineLoopInfo, "machine-loops",
30  "Machine Natural Loop Construction", true, true)
33  "Machine Natural Loop Construction", true, true)
34 
35 char &llvm::MachineLoopInfoID = MachineLoopInfo::ID;
36 
37 bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) {
38  releaseMemory();
39  LI.Analyze(getAnalysis<MachineDominatorTree>().getBase());
40  return false;
41 }
42 
44  AU.setPreservesAll();
47 }
48 
50  MachineBasicBlock *TopMBB = getHeader();
51  MachineFunction::iterator Begin = TopMBB->getParent()->begin();
52  if (TopMBB != Begin) {
54  while (contains(PriorMBB)) {
55  TopMBB = PriorMBB;
56  if (TopMBB == Begin) break;
57  PriorMBB = prior(MachineFunction::iterator(TopMBB));
58  }
59  }
60  return TopMBB;
61 }
62 
64  MachineBasicBlock *BotMBB = getHeader();
65  MachineFunction::iterator End = BotMBB->getParent()->end();
66  if (BotMBB != prior(End)) {
68  while (contains(NextMBB)) {
69  BotMBB = NextMBB;
70  if (BotMBB == llvm::next(MachineFunction::iterator(BotMBB))) break;
71  NextMBB = llvm::next(MachineFunction::iterator(BotMBB));
72  }
73  }
74  return BotMBB;
75 }
76 
77 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
78 void MachineLoop::dump() const {
79  print(dbgs());
80 }
81 #endif
const MachineFunction * getParent() const
machine Machine Natural Loop true
LoopInfoBase< BlockT, LoopT > * LI
Definition: LoopInfoImpl.h:411
void print(raw_ostream &OS, unsigned Depth=0) const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:167
MachineBasicBlock * getTopBlock()
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
MachineBasicBlock * getBottomBlock()
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:172
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:211
void dump() const
INITIALIZE_PASS_BEGIN(MachineLoopInfo,"machine-loops","Machine Natural Loop Construction", true, true) INITIALIZE_PASS_END(MachineLoopInfo
ItTy next(ItTy it, Dist n)
Definition: STLExtras.h:154
virtual void getAnalysisUsage(AnalysisUsage &AU) const
machine loops
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
virtual void getAnalysisUsage(AnalysisUsage &AU) const
machine Machine Natural Loop Construction
BasicBlockListType::iterator iterator
ItTy prior(ItTy it, Dist n)
Definition: STLExtras.h:167