LLVM  3.7.0
RegionInfo.cpp
Go to the documentation of this file.
1 //===- RegionInfo.cpp - SESE region detection analysis --------------------===//
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 // Detects single entry single exit regions in the control flow graph.
10 //===----------------------------------------------------------------------===//
11 
14 #include "llvm/ADT/Statistic.h"
15 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Support/Debug.h"
21 #include <algorithm>
22 #include <iterator>
23 #include <set>
24 
25 using namespace llvm;
26 
27 #define DEBUG_TYPE "region"
28 
29 namespace llvm {
30 template class RegionBase<RegionTraits<Function>>;
33 }
34 
35 STATISTIC(numRegions, "The # of regions");
36 STATISTIC(numSimpleRegions, "The # of simple regions");
37 
38 // Always verify if expensive checking is enabled.
39 
40 static cl::opt<bool,true>
42  "verify-region-info",
44  cl::desc("Verify region info (time consuming)"));
45 
46 
47 static cl::opt<Region::PrintStyle, true> printStyleX("print-region-style",
49  cl::Hidden,
50  cl::desc("style of printing regions"),
51  cl::values(
52  clEnumValN(Region::PrintNone, "none", "print no details"),
54  "print regions in detail with block_iterator"),
56  "print regions in detail with element_iterator"),
57  clEnumValEnd));
58 
59 
60 //===----------------------------------------------------------------------===//
61 // Region implementation
62 //
63 
65  RegionInfo* RI,
66  DominatorTree *DT, Region *Parent) :
67  RegionBase<RegionTraits<Function>>(Entry, Exit, RI, DT, Parent) {
68 
69 }
70 
72 
73 //===----------------------------------------------------------------------===//
74 // RegionInfo implementation
75 //
76 
79 
80 }
81 
83 
84 }
85 
87  ++numRegions;
88 
89  // TODO: Slow. Should only be enabled if -stats is used.
90  if (R->isSimple())
91  ++numSimpleRegions;
92 }
93 
96  DT = DT_;
97  PDT = PDT_;
98  DF = DF_;
99 
100  TopLevelRegion = new Region(&F.getEntryBlock(), nullptr,
101  this, DT, nullptr);
102  updateStatistics(TopLevelRegion);
103  calculate(F);
104 }
105 
106 //===----------------------------------------------------------------------===//
107 // RegionInfoPass implementation
108 //
109 
112 }
113 
115 
116 }
117 
119  releaseMemory();
120 
121  auto DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
122  auto PDT = &getAnalysis<PostDominatorTree>();
123  auto DF = &getAnalysis<DominanceFrontier>();
124 
125  RI.recalculate(F, DT, PDT, DF);
126  return false;
127 }
128 
130  RI.releaseMemory();
131 }
132 
134  RI.verifyAnalysis();
135 }
136 
138  AU.setPreservesAll();
142 }
143 
144 void RegionInfoPass::print(raw_ostream &OS, const Module *) const {
145  RI.print(OS);
146 }
147 
148 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
149 void RegionInfoPass::dump() const {
150  RI.dump();
151 }
152 #endif
153 
154 char RegionInfoPass::ID = 0;
155 
157  "Detect single entry single exit regions", true, true)
162  "Detect single entry single exit regions", true, true)
163 
164 // Create methods available outside of this file, to use them
165 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
166 // the link time optimization.
167 
168 namespace llvm {
170  return new RegionInfoPass();
171  }
172 }
173 
ValuesClass< DataType > LLVM_END_WITH_NULL values(const char *Arg, DataType Val, const char *Desc,...)
Definition: CommandLine.h:536
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
regions
Definition: RegionInfo.cpp:161
bool isSimple() const
Is this a simple region?
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
#define clEnumValEnd
Definition: CommandLine.h:498
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
Definition: RegionInfo.cpp:144
FunctionPass * createRegionInfoPass()
Definition: RegionInfo.cpp:169
F(f)
void recalculate(Function &F, DominatorTree *DT, PostDominatorTree *PDT, DominanceFrontier *DF)
Definition: RegionInfo.cpp:94
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: RegionInfo.cpp:137
void initializeRegionInfoPassPass(PassRegistry &)
Analysis that detects all canonical Regions.
Definition: RegionInfo.h:75
INITIALIZE_PASS_BEGIN(RegionInfoPass,"regions","Detect single entry single exit regions", true, true) INITIALIZE_PASS_END(RegionInfoPass
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:70
Detect single entry single exit true
Definition: RegionInfo.cpp:161
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
Definition: RegionInfo.h:110
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:75
void print(raw_ostream &OS) const
void verifyAnalysis() const
Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo *RI, DominatorTree *DT, Region *Parent=nullptr)
Definition: RegionInfo.cpp:64
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
Definition: RegionInfo.cpp:133
~RegionInfo() override
Definition: RegionInfo.cpp:82
void dump() const
Definition: RegionInfo.cpp:149
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:67
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
~RegionInfoPass() override
Definition: RegionInfo.cpp:114
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: RegionInfo.cpp:129
const BasicBlock & getEntryBlock() const
Definition: Function.h:442
A single entry single exit Region.
Definition: RegionInfo.h:71
void setPreservesAll()
Set by analyses that do not transform their input at all.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:497
static cl::opt< Region::PrintStyle, true > printStyleX("print-region-style", cl::location(RegionInfo::printStyle), cl::Hidden, cl::desc("style of printing regions"), cl::values(clEnumValN(Region::PrintNone,"none","print no details"), clEnumValN(Region::PrintBB,"bb","print regions in detail with block_iterator"), clEnumValN(Region::PrintRN,"rn","print regions in detail with element_iterator"), clEnumValEnd))
AnalysisUsage & addRequiredTransitive()
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Definition: RegionInfo.cpp:118
void updateStatistics(Region *R) final
Definition: RegionInfo.cpp:86
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:203
static cl::opt< bool, true > VerifyRegionInfoX("verify-region-info", cl::location(RegionInfoBase< RegionTraits< Function >>::VerifyRegionInfo), cl::desc("Verify region info (time consuming)"))
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:340