llvm.org GIT mirror llvm / 56e1394
[cleanup] Move the Dominators.h and Verifier.h headers into the IR directory. These passes are already defined in the IR library, and it doesn't make any sense to have the headers in Analysis. Long term, I think there is going to be a much better way to divide these matters. The dominators code should be fully separated into the abstract graph algorithm and have that put in Support where it becomes obvious that evn Clang's CFGBlock's can use it. Then the verifier can manually construct dominance information from the Support-driven interface while the Analysis library can provide a pass which both caches, reconstructs, and supports a nice update API. But those are very long term, and so I don't want to leave the really confusing structure until that day arrives. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199082 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
94 changed file(s) with 1403 addition(s) and 1403 deletion(s). Raw diff Collapse all Expand all
1717 #ifndef LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1818 #define LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1919
20 #include "llvm/Analysis/Dominators.h"
20 #include "llvm/IR/Dominators.h"
2121 #include
2222 #include
2323
+0
-289
include/llvm/Analysis/DominatorInternals.h less more
None //=== llvm/Analysis/DominatorInternals.h - Dominator Calculation -*- C++ -*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ANALYSIS_DOMINATOR_INTERNALS_H
10 #define LLVM_ANALYSIS_DOMINATOR_INTERNALS_H
11
12 #include "llvm/ADT/SmallPtrSet.h"
13 #include "llvm/Analysis/Dominators.h"
14
15 //===----------------------------------------------------------------------===//
16 //
17 // DominatorTree construction - This pass constructs immediate dominator
18 // information for a flow-graph based on the algorithm described in this
19 // document:
20 //
21 // A Fast Algorithm for Finding Dominators in a Flowgraph
22 // T. Lengauer & R. Tarjan, ACM TOPLAS July 1979, pgs 121-141.
23 //
24 // This implements the O(n*log(n)) versions of EVAL and LINK, because it turns
25 // out that the theoretically slower O(n*log(n)) implementation is actually
26 // faster than the almost-linear O(n*alpha(n)) version, even for large CFGs.
27 //
28 //===----------------------------------------------------------------------===//
29
30 namespace llvm {
31
32 template
33 unsigned DFSPass(DominatorTreeBase& DT,
34 typename GraphT::NodeType* V, unsigned N) {
35 // This is more understandable as a recursive algorithm, but we can't use the
36 // recursive algorithm due to stack depth issues. Keep it here for
37 // documentation purposes.
38 #if 0
39 InfoRec &VInfo = DT.Info[DT.Roots[i]];
40 VInfo.DFSNum = VInfo.Semi = ++N;
41 VInfo.Label = V;
42
43 Vertex.push_back(V); // Vertex[n] = V;
44
45 for (succ_iterator SI = succ_begin(V), E = succ_end(V); SI != E; ++SI) {
46 InfoRec &SuccVInfo = DT.Info[*SI];
47 if (SuccVInfo.Semi == 0) {
48 SuccVInfo.Parent = V;
49 N = DTDFSPass(DT, *SI, N);
50 }
51 }
52 #else
53 bool IsChildOfArtificialExit = (N != 0);
54
55 SmallVector
56 typename GraphT::ChildIteratorType>, 32> Worklist;
57 Worklist.push_back(std::make_pair(V, GraphT::child_begin(V)));
58 while (!Worklist.empty()) {
59 typename GraphT::NodeType* BB = Worklist.back().first;
60 typename GraphT::ChildIteratorType NextSucc = Worklist.back().second;
61
62 typename DominatorTreeBase::InfoRec &BBInfo =
63 DT.Info[BB];
64
65 // First time we visited this BB?
66 if (NextSucc == GraphT::child_begin(BB)) {
67 BBInfo.DFSNum = BBInfo.Semi = ++N;
68 BBInfo.Label = BB;
69
70 DT.Vertex.push_back(BB); // Vertex[n] = V;
71
72 if (IsChildOfArtificialExit)
73 BBInfo.Parent = 1;
74
75 IsChildOfArtificialExit = false;
76 }
77
78 // store the DFS number of the current BB - the reference to BBInfo might
79 // get invalidated when processing the successors.
80 unsigned BBDFSNum = BBInfo.DFSNum;
81
82 // If we are done with this block, remove it from the worklist.
83 if (NextSucc == GraphT::child_end(BB)) {
84 Worklist.pop_back();
85 continue;
86 }
87
88 // Increment the successor number for the next time we get to it.
89 ++Worklist.back().second;
90
91 // Visit the successor next, if it isn't already visited.
92 typename GraphT::NodeType* Succ = *NextSucc;
93
94 typename DominatorTreeBase::InfoRec &SuccVInfo =
95 DT.Info[Succ];
96 if (SuccVInfo.Semi == 0) {
97 SuccVInfo.Parent = BBDFSNum;
98 Worklist.push_back(std::make_pair(Succ, GraphT::child_begin(Succ)));
99 }
100 }
101 #endif
102 return N;
103 }
104
105 template
106 typename GraphT::NodeType*
107 Eval(DominatorTreeBase& DT,
108 typename GraphT::NodeType *VIn, unsigned LastLinked) {
109 typename DominatorTreeBase::InfoRec &VInInfo =
110 DT.Info[VIn];
111 if (VInInfo.DFSNum < LastLinked)
112 return VIn;
113
114 SmallVector Work;
115 SmallPtrSet Visited;
116
117 if (VInInfo.Parent >= LastLinked)
118 Work.push_back(VIn);
119
120 while (!Work.empty()) {
121 typename GraphT::NodeType* V = Work.back();
122 typename DominatorTreeBase::InfoRec &VInfo =
123 DT.Info[V];
124 typename GraphT::NodeType* VAncestor = DT.Vertex[VInfo.Parent];
125
126 // Process Ancestor first
127 if (Visited.insert(VAncestor) && VInfo.Parent >= LastLinked) {
128 Work.push_back(VAncestor);
129 continue;
130 }
131 Work.pop_back();
132
133 // Update VInfo based on Ancestor info
134 if (VInfo.Parent < LastLinked)
135 continue;
136
137 typename DominatorTreeBase::InfoRec &VAInfo =
138 DT.Info[VAncestor];
139 typename GraphT::NodeType* VAncestorLabel = VAInfo.Label;
140 typename GraphT::NodeType* VLabel = VInfo.Label;
141 if (DT.Info[VAncestorLabel].Semi < DT.Info[VLabel].Semi)
142 VInfo.Label = VAncestorLabel;
143 VInfo.Parent = VAInfo.Parent;
144 }
145
146 return VInInfo.Label;
147 }
148
149 template
150 void Calculate(DominatorTreeBase::NodeType>& DT,
151 FuncT& F) {
152 typedef GraphTraits GraphT;
153
154 unsigned N = 0;
155 bool MultipleRoots = (DT.Roots.size() > 1);
156 if (MultipleRoots) {
157 typename DominatorTreeBase::InfoRec &BBInfo =
158 DT.Info[NULL];
159 BBInfo.DFSNum = BBInfo.Semi = ++N;
160 BBInfo.Label = NULL;
161
162 DT.Vertex.push_back(NULL); // Vertex[n] = V;
163 }
164
165 // Step #1: Number blocks in depth-first order and initialize variables used
166 // in later stages of the algorithm.
167 for (unsigned i = 0, e = static_cast(DT.Roots.size());
168 i != e; ++i)
169 N = DFSPass(DT, DT.Roots[i], N);
170
171 // it might be that some blocks did not get a DFS number (e.g., blocks of
172 // infinite loops). In these cases an artificial exit node is required.
173 MultipleRoots |= (DT.isPostDominator() && N != GraphTraits::size(&F));
174
175 // When naively implemented, the Lengauer-Tarjan algorithm requires a separate
176 // bucket for each vertex. However, this is unnecessary, because each vertex
177 // is only placed into a single bucket (that of its semidominator), and each
178 // vertex's bucket is processed before it is added to any bucket itself.
179 //
180 // Instead of using a bucket per vertex, we use a single array Buckets that
181 // has two purposes. Before the vertex V with preorder number i is processed,
182 // Buckets[i] stores the index of the first element in V's bucket. After V's
183 // bucket is processed, Buckets[i] stores the index of the next element in the
184 // bucket containing V, if any.
185 SmallVector Buckets;
186 Buckets.resize(N + 1);
187 for (unsigned i = 1; i <= N; ++i)
188 Buckets[i] = i;
189
190 for (unsigned i = N; i >= 2; --i) {
191 typename GraphT::NodeType* W = DT.Vertex[i];
192 typename DominatorTreeBase::InfoRec &WInfo =
193 DT.Info[W];
194
195 // Step #2: Implicitly define the immediate dominator of vertices
196 for (unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
197 typename GraphT::NodeType* V = DT.Vertex[Buckets[j]];
198 typename GraphT::NodeType* U = Eval(DT, V, i + 1);
199 DT.IDoms[V] = DT.Info[U].Semi < i ? U : W;
200 }
201
202 // Step #3: Calculate the semidominators of all vertices
203
204 // initialize the semi dominator to point to the parent node
205 WInfo.Semi = WInfo.Parent;
206 typedef GraphTraits > InvTraits;
207 for (typename InvTraits::ChildIteratorType CI =
208 InvTraits::child_begin(W),
209 E = InvTraits::child_end(W); CI != E; ++CI) {
210 typename InvTraits::NodeType *N = *CI;
211 if (DT.Info.count(N)) { // Only if this predecessor is reachable!
212 unsigned SemiU = DT.Info[Eval(DT, N, i + 1)].Semi;
213 if (SemiU < WInfo.Semi)
214 WInfo.Semi = SemiU;
215 }
216 }
217
218 // If V is a non-root vertex and sdom(V) = parent(V), then idom(V) is
219 // necessarily parent(V). In this case, set idom(V) here and avoid placing
220 // V into a bucket.
221 if (WInfo.Semi == WInfo.Parent) {
222 DT.IDoms[W] = DT.Vertex[WInfo.Parent];
223 } else {
224 Buckets[i] = Buckets[WInfo.Semi];
225 Buckets[WInfo.Semi] = i;
226 }
227 }
228
229 if (N >= 1) {
230 typename GraphT::NodeType* Root = DT.Vertex[1];
231 for (unsigned j = 1; Buckets[j] != 1; j = Buckets[j]) {
232 typename GraphT::NodeType* V = DT.Vertex[Buckets[j]];
233 DT.IDoms[V] = Root;
234 }
235 }
236
237 // Step #4: Explicitly define the immediate dominator of each vertex
238 for (unsigned i = 2; i <= N; ++i) {
239 typename GraphT::NodeType* W = DT.Vertex[i];
240 typename GraphT::NodeType*& WIDom = DT.IDoms[W];
241 if (WIDom != DT.Vertex[DT.Info[W].Semi])
242 WIDom = DT.IDoms[WIDom];
243 }
244
245 if (DT.Roots.empty()) return;
246
247 // Add a node for the root. This node might be the actual root, if there is
248 // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
249 // which postdominates all real exits if there are multiple exit blocks, or
250 // an infinite loop.
251 typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : 0;
252
253 DT.DomTreeNodes[Root] = DT.RootNode =
254 new DomTreeNodeBase(Root, 0);
255
256 // Loop over all of the reachable blocks in the function...
257 for (unsigned i = 2; i <= N; ++i) {
258 typename GraphT::NodeType* W = DT.Vertex[i];
259
260 DomTreeNodeBase *BBNode = DT.DomTreeNodes[W];
261 if (BBNode) continue; // Haven't calculated this node yet?
262
263 typename GraphT::NodeType* ImmDom = DT.getIDom(W);
264
265 assert(ImmDom || DT.DomTreeNodes[NULL]);
266
267 // Get or calculate the node for the immediate dominator
268 DomTreeNodeBase *IDomNode =
269 DT.getNodeForBlock(ImmDom);
270
271 // Add a new tree node for this BasicBlock, and link it as a child of
272 // IDomNode
273 DomTreeNodeBase *C =
274 new DomTreeNodeBase(W, IDomNode);
275 DT.DomTreeNodes[W] = IDomNode->addChild(C);
276 }
277
278 // Free temporary memory used to construct idom's
279 DT.IDoms.clear();
280 DT.Info.clear();
281 std::vector().swap(DT.Vertex);
282
283 DT.updateDFSNumbers();
284 }
285
286 }
287
288 #endif
+0
-942
include/llvm/Analysis/Dominators.h less more
None //===- llvm/Analysis/Dominators.h - Dominator Info Calculation --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DominatorTree class, which provides fast and efficient
10 // dominance queries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_DOMINATORS_H
15 #define LLVM_ANALYSIS_DOMINATORS_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/DepthFirstIterator.h"
19 #include "llvm/ADT/GraphTraits.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Pass.h"
24 #include "llvm/Support/CFG.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include
28
29 namespace llvm {
30
31 //===----------------------------------------------------------------------===//
32 /// DominatorBase - Base class that other, more interesting dominator analyses
33 /// inherit from.
34 ///
35 template
36 class DominatorBase {
37 protected:
38 std::vector Roots;
39 const bool IsPostDominators;
40 inline explicit DominatorBase(bool isPostDom) :
41 Roots(), IsPostDominators(isPostDom) {}
42 public:
43
44 /// getRoots - Return the root blocks of the current CFG. This may include
45 /// multiple blocks if we are computing post dominators. For forward
46 /// dominators, this will always be a single block (the entry node).
47 ///
48 inline const std::vector &getRoots() const { return Roots; }
49
50 /// isPostDominator - Returns true if analysis based of postdoms
51 ///
52 bool isPostDominator() const { return IsPostDominators; }
53 };
54
55
56 //===----------------------------------------------------------------------===//
57 // DomTreeNode - Dominator Tree Node
58 template class DominatorTreeBase;
59 struct PostDominatorTree;
60 class MachineBasicBlock;
61
62 template
63 class DomTreeNodeBase {
64 NodeT *TheBB;
65 DomTreeNodeBase *IDom;
66 std::vector *> Children;
67 int DFSNumIn, DFSNumOut;
68
69 template friend class DominatorTreeBase;
70 friend struct PostDominatorTree;
71 public:
72 typedef typename std::vector *>::iterator iterator;
73 typedef typename std::vector *>::const_iterator
74 const_iterator;
75
76 iterator begin() { return Children.begin(); }
77 iterator end() { return Children.end(); }
78 const_iterator begin() const { return Children.begin(); }
79 const_iterator end() const { return Children.end(); }
80
81 NodeT *getBlock() const { return TheBB; }
82 DomTreeNodeBase *getIDom() const { return IDom; }
83 const std::vector*> &getChildren() const {
84 return Children;
85 }
86
87 DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom)
88 : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
89
90 DomTreeNodeBase *addChild(DomTreeNodeBase *C) {
91 Children.push_back(C);
92 return C;
93 }
94
95 size_t getNumChildren() const {
96 return Children.size();
97 }
98
99 void clearAllChildren() {
100 Children.clear();
101 }
102
103 bool compare(const DomTreeNodeBase *Other) const {
104 if (getNumChildren() != Other->getNumChildren())
105 return true;
106
107 SmallPtrSet OtherChildren;
108 for (const_iterator I = Other->begin(), E = Other->end(); I != E; ++I) {
109 const NodeT *Nd = (*I)->getBlock();
110 OtherChildren.insert(Nd);
111 }
112
113 for (const_iterator I = begin(), E = end(); I != E; ++I) {
114 const NodeT *N = (*I)->getBlock();
115 if (OtherChildren.count(N) == 0)
116 return true;
117 }
118 return false;
119 }
120
121 void setIDom(DomTreeNodeBase *NewIDom) {
122 assert(IDom && "No immediate dominator?");
123 if (IDom != NewIDom) {
124 typename std::vector*>::iterator I =
125 std::find(IDom->Children.begin(), IDom->Children.end(), this);
126 assert(I != IDom->Children.end() &&
127 "Not in immediate dominator children set!");
128 // I am no longer your child...
129 IDom->Children.erase(I);
130
131 // Switch to new dominator
132 IDom = NewIDom;
133 IDom->Children.push_back(this);
134 }
135 }
136
137 /// getDFSNumIn/getDFSNumOut - These are an internal implementation detail, do
138 /// not call them.
139 unsigned getDFSNumIn() const { return DFSNumIn; }
140 unsigned getDFSNumOut() const { return DFSNumOut; }
141 private:
142 // Return true if this node is dominated by other. Use this only if DFS info
143 // is valid.
144 bool DominatedBy(const DomTreeNodeBase *other) const {
145 return this->DFSNumIn >= other->DFSNumIn &&
146 this->DFSNumOut <= other->DFSNumOut;
147 }
148 };
149
150 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
151 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
152
153 template
154 inline raw_ostream &operator<<(raw_ostream &o,
155 const DomTreeNodeBase *Node) {
156 if (Node->getBlock())
157 Node->getBlock()->printAsOperand(o, false);
158 else
159 o << " <>";
160
161 o << " {" << Node->getDFSNumIn() << "," << Node->getDFSNumOut() << "}";
162
163 return o << "\n";
164 }
165
166 template
167 inline void PrintDomTree(const DomTreeNodeBase *N, raw_ostream &o,
168 unsigned Lev) {
169 o.indent(2*Lev) << "[" << Lev << "] " << N;
170 for (typename DomTreeNodeBase::const_iterator I = N->begin(),
171 E = N->end(); I != E; ++I)
172 PrintDomTree(*I, o, Lev+1);
173 }
174
175 typedef DomTreeNodeBase DomTreeNode;
176
177 //===----------------------------------------------------------------------===//
178 /// DominatorTree - Calculate the immediate dominator tree for a function.
179 ///
180
181 template
182 void Calculate(DominatorTreeBase::NodeType>& DT,
183 FuncT& F);
184
185 template
186 class DominatorTreeBase : public DominatorBase {
187 bool dominatedBySlowTreeWalk(const DomTreeNodeBase *A,
188 const DomTreeNodeBase *B) const {
189 assert(A != B);
190 assert(isReachableFromEntry(B));
191 assert(isReachableFromEntry(A));
192
193 const DomTreeNodeBase *IDom;
194 while ((IDom = B->getIDom()) != 0 && IDom != A && IDom != B)
195 B = IDom; // Walk up the tree
196 return IDom != 0;
197 }
198
199 protected:
200 typedef DenseMap*> DomTreeNodeMapType;
201 DomTreeNodeMapType DomTreeNodes;
202 DomTreeNodeBase *RootNode;
203
204 bool DFSInfoValid;
205 unsigned int SlowQueries;
206 // Information record used during immediate dominators computation.
207 struct InfoRec {
208 unsigned DFSNum;
209 unsigned Parent;
210 unsigned Semi;
211 NodeT *Label;
212
213 InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(0) {}
214 };
215
216 DenseMap IDoms;
217
218 // Vertex - Map the DFS number to the BasicBlock*
219 std::vector Vertex;
220
221 // Info - Collection of information used during the computation of idoms.
222 DenseMap Info;
223
224 void reset() {
225 for (typename DomTreeNodeMapType::iterator I = this->DomTreeNodes.begin(),
226 E = DomTreeNodes.end(); I != E; ++I)
227 delete I->second;
228 DomTreeNodes.clear();
229 IDoms.clear();
230 this->Roots.clear();
231 Vertex.clear();
232 RootNode = 0;
233 }
234
235 // NewBB is split and now it has one successor. Update dominator tree to
236 // reflect this change.
237 template
238 void Split(DominatorTreeBase& DT,
239 typename GraphT::NodeType* NewBB) {
240 assert(std::distance(GraphT::child_begin(NewBB),
241 GraphT::child_end(NewBB)) == 1 &&
242 "NewBB should have a single successor!");
243 typename GraphT::NodeType* NewBBSucc = *GraphT::child_begin(NewBB);
244
245 std::vector PredBlocks;
246 typedef GraphTraits > InvTraits;
247 for (typename InvTraits::ChildIteratorType PI =
248 InvTraits::child_begin(NewBB),
249 PE = InvTraits::child_end(NewBB); PI != PE; ++PI)
250 PredBlocks.push_back(*PI);
251
252 assert(!PredBlocks.empty() && "No predblocks?");
253
254 bool NewBBDominatesNewBBSucc = true;
255 for (typename InvTraits::ChildIteratorType PI =
256 InvTraits::child_begin(NewBBSucc),
257 E = InvTraits::child_end(NewBBSucc); PI != E; ++PI) {
258 typename InvTraits::NodeType *ND = *PI;
259 if (ND != NewBB && !DT.dominates(NewBBSucc, ND) &&
260 DT.isReachableFromEntry(ND)) {
261 NewBBDominatesNewBBSucc = false;
262 break;
263 }
264 }
265
266 // Find NewBB's immediate dominator and create new dominator tree node for
267 // NewBB.
268 NodeT *NewBBIDom = 0;
269 unsigned i = 0;
270 for (i = 0; i < PredBlocks.size(); ++i)
271 if (DT.isReachableFromEntry(PredBlocks[i])) {
272 NewBBIDom = PredBlocks[i];
273 break;
274 }
275
276 // It's possible that none of the predecessors of NewBB are reachable;
277 // in that case, NewBB itself is unreachable, so nothing needs to be
278 // changed.
279 if (!NewBBIDom)
280 return;
281
282 for (i = i + 1; i < PredBlocks.size(); ++i) {
283 if (DT.isReachableFromEntry(PredBlocks[i]))
284 NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
285 }
286
287 // Create the new dominator tree node... and set the idom of NewBB.
288 DomTreeNodeBase *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
289
290 // If NewBB strictly dominates other blocks, then it is now the immediate
291 // dominator of NewBBSucc. Update the dominator tree as appropriate.
292 if (NewBBDominatesNewBBSucc) {
293 DomTreeNodeBase *NewBBSuccNode = DT.getNode(NewBBSucc);
294 DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
295 }
296 }
297
298 public:
299 explicit DominatorTreeBase(bool isPostDom)
300 : DominatorBase(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
301 virtual ~DominatorTreeBase() { reset(); }
302
303 /// compare - Return false if the other dominator tree base matches this
304 /// dominator tree base. Otherwise return true.
305 bool compare(DominatorTreeBase &Other) const {
306
307 const DomTreeNodeMapType &OtherDomTreeNodes = Other.DomTreeNodes;
308 if (DomTreeNodes.size() != OtherDomTreeNodes.size())
309 return true;
310
311 for (typename DomTreeNodeMapType::const_iterator
312 I = this->DomTreeNodes.begin(),
313 E = this->DomTreeNodes.end(); I != E; ++I) {
314 NodeT *BB = I->first;
315 typename DomTreeNodeMapType::const_iterator OI = OtherDomTreeNodes.find(BB);
316 if (OI == OtherDomTreeNodes.end())
317 return true;
318
319 DomTreeNodeBase* MyNd = I->second;
320 DomTreeNodeBase* OtherNd = OI->second;
321
322 if (MyNd->compare(OtherNd))
323 return true;
324 }
325
326 return false;
327 }
328
329 virtual void releaseMemory() { reset(); }
330
331 /// getNode - return the (Post)DominatorTree node for the specified basic
332 /// block. This is the same as using operator[] on this class.
333 ///
334 inline DomTreeNodeBase *getNode(NodeT *BB) const {
335 return DomTreeNodes.lookup(BB);
336 }
337
338 /// getRootNode - This returns the entry node for the CFG of the function. If
339 /// this tree represents the post-dominance relations for a function, however,
340 /// this root may be a node with the block == NULL. This is the case when
341 /// there are multiple exit nodes from a particular function. Consumers of
342 /// post-dominance information must be capable of dealing with this
343 /// possibility.
344 ///
345 DomTreeNodeBase *getRootNode() { return RootNode; }
346 const DomTreeNodeBase *getRootNode() const { return RootNode; }
347
348 /// Get all nodes dominated by R, including R itself.
349 void getDescendants(NodeT *R, SmallVectorImpl &Result) const {
350 Result.clear();
351 const DomTreeNodeBase *RN = getNode(R);
352 if (RN == NULL)
353 return; // If R is unreachable, it will not be present in the DOM tree.
354 SmallVector *, 8> WL;
355 WL.push_back(RN);
356
357 while (!WL.empty()) {
358 const DomTreeNodeBase *N = WL.pop_back_val();
359 Result.push_back(N->getBlock());
360 WL.append(N->begin(), N->end());
361 }
362 }
363
364 /// properlyDominates - Returns true iff A dominates B and A != B.
365 /// Note that this is not a constant time operation!
366 ///
367 bool properlyDominates(const DomTreeNodeBase *A,
368 const DomTreeNodeBase *B) {
369 if (A == 0 || B == 0)
370 return false;
371 if (A == B)
372 return false;
373 return dominates(A, B);
374 }
375
376 bool properlyDominates(const NodeT *A, const NodeT *B);
377
378 /// isReachableFromEntry - Return true if A is dominated by the entry
379 /// block of the function containing it.
380 bool isReachableFromEntry(const NodeT* A) const {
381 assert(!this->isPostDominator() &&
382 "This is not implemented for post dominators");
383 return isReachableFromEntry(getNode(const_cast(A)));
384 }
385
386 inline bool isReachableFromEntry(const DomTreeNodeBase *A) const {
387 return A;
388 }
389
390 /// dominates - Returns true iff A dominates B. Note that this is not a
391 /// constant time operation!
392 ///
393 inline bool dominates(const DomTreeNodeBase *A,
394 const DomTreeNodeBase *B) {
395 // A node trivially dominates itself.
396 if (B == A)
397 return true;
398
399 // An unreachable node is dominated by anything.
400 if (!isReachableFromEntry(B))
401 return true;
402
403 // And dominates nothing.
404 if (!isReachableFromEntry(A))
405 return false;
406
407 // Compare the result of the tree walk and the dfs numbers, if expensive
408 // checks are enabled.
409 #ifdef XDEBUG
410 assert((!DFSInfoValid ||
411 (dominatedBySlowTreeWalk(A, B) == B->DominatedBy(A))) &&
412 "Tree walk disagrees with dfs numbers!");
413 #endif
414
415 if (DFSInfoValid)
416 return B->DominatedBy(A);
417
418 // If we end up with too many slow queries, just update the
419 // DFS numbers on the theory that we are going to keep querying.
420 SlowQueries++;
421 if (SlowQueries > 32) {
422 updateDFSNumbers();
423 return B->DominatedBy(A);
424 }
425
426 return dominatedBySlowTreeWalk(A, B);
427 }
428
429 bool dominates(const NodeT *A, const NodeT *B);
430
431 NodeT *getRoot() const {
432 assert(this->Roots.size() == 1 && "Should always have entry node!");
433 return this->Roots[0];
434 }
435
436 /// findNearestCommonDominator - Find nearest common dominator basic block
437 /// for basic block A and B. If there is no such block then return NULL.
438 NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) {
439 assert(A->getParent() == B->getParent() &&
440 "Two blocks are not in same function");
441
442 // If either A or B is a entry block then it is nearest common dominator
443 // (for forward-dominators).
444 if (!this->isPostDominator()) {
445 NodeT &Entry = A->getParent()->front();
446 if (A == &Entry || B == &Entry)
447 return &Entry;
448 }
449
450 // If B dominates A then B is nearest common dominator.
451 if (dominates(B, A))
452 return B;
453
454 // If A dominates B then A is nearest common dominator.
455 if (dominates(A, B))
456 return A;
457
458 DomTreeNodeBase *NodeA = getNode(A);
459 DomTreeNodeBase *NodeB = getNode(B);
460
461 // Collect NodeA dominators set.
462 SmallPtrSet*, 16> NodeADoms;
463 NodeADoms.insert(NodeA);
464 DomTreeNodeBase *IDomA = NodeA->getIDom();
465 while (IDomA) {
466 NodeADoms.insert(IDomA);
467 IDomA = IDomA->getIDom();
468 }
469
470 // Walk NodeB immediate dominators chain and find common dominator node.
471 DomTreeNodeBase *IDomB = NodeB->getIDom();
472 while (IDomB) {
473 if (NodeADoms.count(IDomB) != 0)
474 return IDomB->getBlock();
475
476 IDomB = IDomB->getIDom();
477 }
478
479 return NULL;
480 }
481
482 const NodeT *findNearestCommonDominator(const NodeT *A, const NodeT *B) {
483 // Cast away the const qualifiers here. This is ok since
484 // const is re-introduced on the return type.
485 return findNearestCommonDominator(const_cast(A),
486 const_cast(B));
487 }
488
489 //===--------------------------------------------------------------------===//
490 // API to update (Post)DominatorTree information based on modifications to
491 // the CFG...
492
493 /// addNewBlock - Add a new node to the dominator tree information. This
494 /// creates a new node as a child of DomBB dominator node,linking it into
495 /// the children list of the immediate dominator.
496 DomTreeNodeBase *addNewBlock(NodeT *BB, NodeT *DomBB) {
497 assert(getNode(BB) == 0 && "Block already in dominator tree!");
498 DomTreeNodeBase *IDomNode = getNode(DomBB);
499 assert(IDomNode && "Not immediate dominator specified for block!");
500 DFSInfoValid = false;
501 return DomTreeNodes[BB] =
502 IDomNode->addChild(new DomTreeNodeBase(BB, IDomNode));
503 }
504
505 /// changeImmediateDominator - This method is used to update the dominator
506 /// tree information when a node's immediate dominator changes.
507 ///
508 void changeImmediateDominator(DomTreeNodeBase *N,
509 DomTreeNodeBase *NewIDom) {
510 assert(N && NewIDom && "Cannot change null node pointers!");
511 DFSInfoValid = false;
512 N->setIDom(NewIDom);
513 }
514
515 void changeImmediateDominator(NodeT *BB, NodeT *NewBB) {
516 changeImmediateDominator(getNode(BB), getNode(NewBB));
517 }
518
519 /// eraseNode - Removes a node from the dominator tree. Block must not
520 /// dominate any other blocks. Removes node from its immediate dominator's
521 /// children list. Deletes dominator node associated with basic block BB.
522 void eraseNode(NodeT *BB) {
523 DomTreeNodeBase *Node = getNode(BB);
524 assert(Node && "Removing node that isn't in dominator tree.");
525 assert(Node->getChildren().empty() && "Node is not a leaf node.");
526
527 // Remove node from immediate dominator's children list.
528 DomTreeNodeBase *IDom = Node->getIDom();
529 if (IDom) {
530 typename std::vector*>::iterator I =
531 std::find(IDom->Children.begin(), IDom->Children.end(), Node);
532 assert(I != IDom->Children.end() &&
533 "Not in immediate dominator children set!");
534 // I am no longer your child...
535 IDom->Children.erase(I);
536 }
537
538 DomTreeNodes.erase(BB);
539 delete Node;
540 }
541
542 /// removeNode - Removes a node from the dominator tree. Block must not
543 /// dominate any other blocks. Invalidates any node pointing to removed
544 /// block.
545 void removeNode(NodeT *BB) {
546 assert(getNode(BB) && "Removing node that isn't in dominator tree.");
547 DomTreeNodes.erase(BB);
548 }
549
550 /// splitBlock - BB is split and now it has one successor. Update dominator
551 /// tree to reflect this change.
552 void splitBlock(NodeT* NewBB) {
553 if (this->IsPostDominators)
554 this->Split, GraphTraits > >(*this, NewBB);
555 else
556 this->Split >(*this, NewBB);
557 }
558
559 /// print - Convert to human readable form
560 ///
561 void print(raw_ostream &o) const {
562 o << "=============================--------------------------------\n";
563 if (this->isPostDominator())
564 o << "Inorder PostDominator Tree: ";
565 else
566 o << "Inorder Dominator Tree: ";
567 if (!this->DFSInfoValid)
568 o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
569 o << "\n";
570
571 // The postdom tree can have a null root if there are no returns.
572 if (getRootNode())
573 PrintDomTree(getRootNode(), o, 1);
574 }
575
576 protected:
577 template
578 friend typename GraphT::NodeType* Eval(
579 DominatorTreeBase& DT,
580 typename GraphT::NodeType* V,
581 unsigned LastLinked);
582
583 template
584 friend unsigned DFSPass(DominatorTreeBase& DT,
585 typename GraphT::NodeType* V,
586 unsigned N);
587
588 template
589 friend void Calculate(DominatorTreeBase::NodeType>& DT,
590 FuncT& F);
591
592 /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
593 /// dominator tree in dfs order.
594 void updateDFSNumbers() {
595 unsigned DFSNum = 0;
596
597 SmallVector*,
598 typename DomTreeNodeBase::iterator>, 32> WorkStack;
599
600 DomTreeNodeBase *ThisRoot = getRootNode();
601
602 if (!ThisRoot)
603 return;
604
605 // Even in the case of multiple exits that form the post dominator root
606 // nodes, do not iterate over all exits, but start from the virtual root
607 // node. Otherwise bbs, that are not post dominated by any exit but by the
608 // virtual root node, will never be assigned a DFS number.
609 WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
610 ThisRoot->DFSNumIn = DFSNum++;
611
612 while (!WorkStack.empty()) {
613 DomTreeNodeBase *Node = WorkStack.back().first;
614 typename DomTreeNodeBase::iterator ChildIt =
615 WorkStack.back().second;
616
617 // If we visited all of the children of this node, "recurse" back up the
618 // stack setting the DFOutNum.
619 if (ChildIt == Node->end()) {
620 Node->DFSNumOut = DFSNum++;
621 WorkStack.pop_back();
622 } else {
623 // Otherwise, recursively visit this child.
624 DomTreeNodeBase *Child = *ChildIt;
625 ++WorkStack.back().second;
626
627 WorkStack.push_back(std::make_pair(Child, Child->begin()));
628 Child->DFSNumIn = DFSNum++;
629 }
630 }
631
632 SlowQueries = 0;
633 DFSInfoValid = true;
634 }
635
636 DomTreeNodeBase *getNodeForBlock(NodeT *BB) {
637 if (DomTreeNodeBase *Node = getNode(BB))
638 return Node;
639
640 // Haven't calculated this node yet? Get or calculate the node for the
641 // immediate dominator.
642 NodeT *IDom = getIDom(BB);
643
644 assert(IDom || this->DomTreeNodes[NULL]);
645 DomTreeNodeBase *IDomNode = getNodeForBlock(IDom);
646
647 // Add a new tree node for this BasicBlock, and link it as a child of
648 // IDomNode
649 DomTreeNodeBase *C = new DomTreeNodeBase(BB, IDomNode);
650 return this->DomTreeNodes[BB] = IDomNode->addChild(C);
651 }
652
653 inline NodeT *getIDom(NodeT *BB) const {
654 return IDoms.lookup(BB);
655 }
656
657 inline void addRoot(NodeT* BB) {
658 this->Roots.push_back(BB);
659 }
660
661 public:
662 /// recalculate - compute a dominator tree for the given function
663 template
664 void recalculate(FT& F) {
665 typedef GraphTraits TraitsTy;
666 reset();
667 this->Vertex.push_back(0);
668
669 if (!this->IsPostDominators) {
670 // Initialize root
671 NodeT *entry = TraitsTy::getEntryNode(&F);
672 this->Roots.push_back(entry);
673 this->IDoms[entry] = 0;
674 this->DomTreeNodes[entry] = 0;
675
676 Calculate(*this, F);
677 } else {
678 // Initialize the roots list
679 for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
680 E = TraitsTy::nodes_end(&F); I != E; ++I) {
681 if (TraitsTy::child_begin(I) == TraitsTy::child_end(I))
682 addRoot(I);
683
684 // Prepopulate maps so that we don't get iterator invalidation issues later.
685 this->IDoms[I] = 0;
686 this->DomTreeNodes[I] = 0;
687 }
688
689 Calculate >(*this, F);
690 }
691 }
692 };
693
694 // These two functions are declared out of line as a workaround for building
695 // with old (< r147295) versions of clang because of pr11642.
696 template
697 bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) {
698 if (A == B)
699 return true;
700
701 // Cast away the const qualifiers here. This is ok since
702 // this function doesn't actually return the values returned
703 // from getNode.
704 return dominates(getNode(const_cast(A)),
705 getNode(const_cast(B)));
706 }
707 template
708 bool
709 DominatorTreeBase::properlyDominates(const NodeT *A, const NodeT *B) {
710 if (A == B)
711 return false;
712
713 // Cast away the const qualifiers here. This is ok since
714 // this function doesn't actually return the values returned
715 // from getNode.
716 return dominates(getNode(const_cast(A)),
717 getNode(const_cast(B)));
718 }
719
720 EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase);
721
722 class BasicBlockEdge {
723 const BasicBlock *Start;
724 const BasicBlock *End;
725 public:
726 BasicBlockEdge(const BasicBlock *Start_, const BasicBlock *End_) :
727 Start(Start_), End(End_) { }
728 const BasicBlock *getStart() const {
729 return Start;
730 }
731 const BasicBlock *getEnd() const {
732 return End;
733 }
734 bool isSingleEdge() const;
735 };
736
737 //===-------------------------------------
738 /// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
739 /// compute a normal dominator tree.
740 ///
741 class DominatorTree : public FunctionPass {
742 public:
743 static char ID; // Pass ID, replacement for typeid
744 DominatorTreeBase* DT;
745
746 DominatorTree() : FunctionPass(ID) {
747 initializeDominatorTreePass(*PassRegistry::getPassRegistry());
748 DT = new DominatorTreeBase(false);
749 }
750
751 ~DominatorTree() {
752 delete DT;
753 }
754
755 DominatorTreeBase& getBase() { return *DT; }
756
757 /// getRoots - Return the root blocks of the current CFG. This may include
758 /// multiple blocks if we are computing post dominators. For forward
759 /// dominators, this will always be a single block (the entry node).
760 ///
761 inline const std::vector &getRoots() const {
762 return DT->getRoots();
763 }
764
765 inline BasicBlock *getRoot() const {
766 return DT->getRoot();
767 }
768
769 inline DomTreeNode *getRootNode() const {
770 return DT->getRootNode();
771 }
772
773 /// Get all nodes dominated by R, including R itself.
774 void getDescendants(BasicBlock *R,
775 SmallVectorImpl &Result) const {
776 DT->getDescendants(R, Result);
777 }
778
779 /// compare - Return false if the other dominator tree matches this
780 /// dominator tree. Otherwise return true.
781 inline bool compare(DominatorTree &Other) const {
782 DomTreeNode *R = getRootNode();
783 DomTreeNode *OtherR = Other.getRootNode();
784
785 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
786 return true;
787
788 if (DT->compare(Other.getBase()))
789 return true;
790
791 return false;
792 }
793
794 virtual bool runOnFunction(Function &F);
795
796 virtual void verifyAnalysis() const;
797
798 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
799 AU.setPreservesAll();
800 }
801
802 inline bool dominates(const DomTreeNode* A, const DomTreeNode* B) const {
803 return DT->dominates(A, B);
804 }
805
806 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
807 return DT->dominates(A, B);
808 }
809
810 // dominates - Return true if Def dominates a use in User. This performs
811 // the special checks necessary if Def and User are in the same basic block.
812 // Note that Def doesn't dominate a use in Def itself!
813 bool dominates(const Instruction *Def, const Use &U) const;
814 bool dominates(const Instruction *Def, const Instruction *User) const;
815 bool dominates(const Instruction *Def, const BasicBlock *BB) const;
816 bool dominates(const BasicBlockEdge &BBE, const Use &U) const;
817 bool dominates(const BasicBlockEdge &BBE, const BasicBlock *BB) const;
818
819 bool properlyDominates(const DomTreeNode *A, const DomTreeNode *B) const {
820 return DT->properlyDominates(A, B);
821 }
822
823 bool properlyDominates(const BasicBlock *A, const BasicBlock *B) const {
824 return DT->properlyDominates(A, B);
825 }
826
827 /// findNearestCommonDominator - Find nearest common dominator basic block
828 /// for basic block A and B. If there is no such block then return NULL.
829 inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
830 return DT->findNearestCommonDominator(A, B);
831 }
832
833 inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
834 const BasicBlock *B) {
835 return DT->findNearestCommonDominator(A, B);
836 }
837
838 inline DomTreeNode *operator[](BasicBlock *BB) const {
839 return DT->getNode(BB);
840 }
841
842 /// getNode - return the (Post)DominatorTree node for the specified basic
843 /// block. This is the same as using operator[] on this class.
844 ///
845 inline DomTreeNode *getNode(BasicBlock *BB) const {
846 return DT->getNode(BB);
847 }
848
849 /// addNewBlock - Add a new node to the dominator tree information. This
850 /// creates a new node as a child of DomBB dominator node,linking it into
851 /// the children list of the immediate dominator.
852 inline DomTreeNode *addNewBlock(BasicBlock *BB, BasicBlock *DomBB) {
853 return DT->addNewBlock(BB, DomBB);
854 }
855
856 /// changeImmediateDominator - This method is used to update the dominator
857 /// tree information when a node's immediate dominator changes.
858 ///
859 inline void changeImmediateDominator(BasicBlock *N, BasicBlock* NewIDom) {
860 DT->changeImmediateDominator(N, NewIDom);
861 }
862
863 inline void changeImmediateDominator(DomTreeNode *N, DomTreeNode* NewIDom) {
864 DT->changeImmediateDominator(N, NewIDom);
865 }
866
867 /// eraseNode - Removes a node from the dominator tree. Block must not
868 /// dominate any other blocks. Removes node from its immediate dominator's
869 /// children list. Deletes dominator node associated with basic block BB.
870 inline void eraseNode(BasicBlock *BB) {
871 DT->eraseNode(BB);
872 }
873
874 /// splitBlock - BB is split and now it has one successor. Update dominator
875 /// tree to reflect this change.
876 inline void splitBlock(BasicBlock* NewBB) {
877 DT->splitBlock(NewBB);
878 }
879
880 bool isReachableFromEntry(const BasicBlock* A) const {
881 return DT->isReachableFromEntry(A);
882 }
883
884 bool isReachableFromEntry(const Use &U) const;
885
886
887 virtual void releaseMemory() {
888 DT->releaseMemory();
889 }
890
891 virtual void print(raw_ostream &OS, const Module* M= 0) const;
892 };
893
894 //===-------------------------------------
895 /// DominatorTree GraphTraits specialization so the DominatorTree can be
896 /// iterable by generic graph iterators.
897 ///
898 template <> struct GraphTraits {
899 typedef DomTreeNode NodeType;
900 typedef NodeType::iterator ChildIteratorType;
901
902 static NodeType *getEntryNode(NodeType *N) {
903 return N;
904 }
905 static inline ChildIteratorType child_begin(NodeType *N) {
906 return N->begin();
907 }
908 static inline ChildIteratorType child_end(NodeType *N) {
909 return N->end();
910 }
911
912 typedef df_iterator nodes_iterator;
913
914 static nodes_iterator nodes_begin(DomTreeNode *N) {
915 return df_begin(getEntryNode(N));
916 }
917
918 static nodes_iterator nodes_end(DomTreeNode *N) {
919 return df_end(getEntryNode(N));
920 }
921 };
922
923 template <> struct GraphTraits
924 : public GraphTraits {
925 static NodeType *getEntryNode(DominatorTree *DT) {
926 return DT->getRootNode();
927 }
928
929 static nodes_iterator nodes_begin(DominatorTree *N) {
930 return df_begin(getEntryNode(N));
931 }
932
933 static nodes_iterator nodes_end(DominatorTree *N) {
934 return df_end(getEntryNode(N));
935 }
936 };
937
938
939 } // End llvm namespace
940
941 #endif
1717 #include "llvm/ADT/DepthFirstIterator.h"
1818 #include "llvm/ADT/PostOrderIterator.h"
1919 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Analysis/Dominators.h"
2120 #include "llvm/Analysis/LoopInfo.h"
21 #include "llvm/IR/Dominators.h"
2222
2323 namespace llvm {
2424
1313 #ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
1414 #define LLVM_ANALYSIS_POSTDOMINATORS_H
1515
16 #include "llvm/Analysis/Dominators.h"
16 #include "llvm/IR/Dominators.h"
1717
1818 namespace llvm {
1919
+0
-75
include/llvm/Analysis/Verifier.h less more
None //===-- llvm/Analysis/Verifier.h - LLVM IR Verifier -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the function verifier interface, that can be used for some
10 // sanity checking of input to the system, and for checking that transformations
11 // haven't done something bad.
12 //
13 // Note that this does not provide full 'java style' security and verifications,
14 // instead it just tries to ensure that code is well formed.
15 //
16 // To see what specifically is checked, look at the top of Verifier.cpp
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_ANALYSIS_VERIFIER_H
21 #define LLVM_ANALYSIS_VERIFIER_H
22
23 #include
24
25 namespace llvm {
26
27 class FunctionPass;
28 class Module;
29 class Function;
30
31 /// @brief An enumeration to specify the action to be taken if errors found.
32 ///
33 /// This enumeration is used in the functions below to indicate what should
34 /// happen if the verifier finds errors. Each of the functions that uses
35 /// this enumeration as an argument provides a default value for it. The
36 /// actions are listed below.
37 enum VerifierFailureAction {
38 AbortProcessAction, ///< verifyModule will print to stderr and abort()
39 PrintMessageAction, ///< verifyModule will print to stderr and return true
40 ReturnStatusAction ///< verifyModule will just return true
41 };
42
43 /// @brief Create a verifier pass.
44 ///
45 /// Check a module or function for validity. When the pass is used, the
46 /// action indicated by the \p action argument will be used if errors are
47 /// found.
48 FunctionPass *createVerifierPass(
49 VerifierFailureAction action = AbortProcessAction ///< Action to take
50 );
51
52 /// @brief Check a module for errors.
53 ///
54 /// If there are no errors, the function returns false. If an error is found,
55 /// the action taken depends on the \p action parameter.
56 /// This should only be used for debugging, because it plays games with
57 /// PassManagers and stuff.
58
59 bool verifyModule(
60 const Module &M, ///< The module to be verified
61 VerifierFailureAction action = AbortProcessAction, ///< Action to take
62 std::string *ErrorInfo = 0 ///< Information about failures.
63 );
64
65 // verifyFunction - Check a function for errors, useful for use when debugging a
66 // pass.
67 bool verifyFunction(
68 const Function &F, ///< The function to be verified
69 VerifierFailureAction action = AbortProcessAction ///< Action to take
70 );
71
72 } // End llvm namespace
73
74 #endif
1414 #ifndef LLVM_CODEGEN_MACHINEDOMINATORS_H
1515 #define LLVM_CODEGEN_MACHINEDOMINATORS_H
1616
17 #include "llvm/Analysis/DominatorInternals.h"
18 #include "llvm/Analysis/Dominators.h"
1917 #include "llvm/CodeGen/MachineBasicBlock.h"
2018 #include "llvm/CodeGen/MachineFunction.h"
2119 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/IR/DominatorInternals.h"
21 #include "llvm/IR/Dominators.h"
2222
2323 namespace llvm {
2424
1414 #ifndef LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H
1515 #define LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H
1616
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/CodeGen/MachineDominators.h"
1918 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/IR/Dominators.h"
2020
2121 namespace llvm {
2222
1919 #include "llvm/ADT/SmallPtrSet.h"
2020 #include "llvm/ADT/Triple.h"
2121 #include "llvm/ADT/ValueMap.h"
22 #include "llvm/Analysis/Dominators.h"
22 #include "llvm/IR/Dominators.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Target/TargetLowering.h"
2525
0 //===- DominatorInternals.h - Dominator Calculation --------------*- C++ -*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_IR_DOMINATOR_INTERNALS_H
10 #define LLVM_IR_DOMINATOR_INTERNALS_H
11
12 #include "llvm/ADT/SmallPtrSet.h"
13 #include "llvm/IR/Dominators.h"
14
15 //===----------------------------------------------------------------------===//
16 //
17 // DominatorTree construction - This pass constructs immediate dominator
18 // information for a flow-graph based on the algorithm described in this
19 // document:
20 //
21 // A Fast Algorithm for Finding Dominators in a Flowgraph
22 // T. Lengauer & R. Tarjan, ACM TOPLAS July 1979, pgs 121-141.
23 //
24 // This implements the O(n*log(n)) versions of EVAL and LINK, because it turns
25 // out that the theoretically slower O(n*log(n)) implementation is actually
26 // faster than the almost-linear O(n*alpha(n)) version, even for large CFGs.
27 //
28 //===----------------------------------------------------------------------===//
29
30 namespace llvm {
31
32 template
33 unsigned DFSPass(DominatorTreeBase& DT,
34 typename GraphT::NodeType* V, unsigned N) {
35 // This is more understandable as a recursive algorithm, but we can't use the
36 // recursive algorithm due to stack depth issues. Keep it here for
37 // documentation purposes.
38 #if 0
39 InfoRec &VInfo = DT.Info[DT.Roots[i]];
40 VInfo.DFSNum = VInfo.Semi = ++N;
41 VInfo.Label = V;
42
43 Vertex.push_back(V); // Vertex[n] = V;
44
45 for (succ_iterator SI = succ_begin(V), E = succ_end(V); SI != E; ++SI) {
46 InfoRec &SuccVInfo = DT.Info[*SI];
47 if (SuccVInfo.Semi == 0) {
48 SuccVInfo.Parent = V;
49 N = DTDFSPass(DT, *SI, N);
50 }
51 }
52 #else
53 bool IsChildOfArtificialExit = (N != 0);
54
55 SmallVector
56 typename GraphT::ChildIteratorType>, 32> Worklist;
57 Worklist.push_back(std::make_pair(V, GraphT::child_begin(V)));
58 while (!Worklist.empty()) {
59 typename GraphT::NodeType* BB = Worklist.back().first;
60 typename GraphT::ChildIteratorType NextSucc = Worklist.back().second;
61
62 typename DominatorTreeBase::InfoRec &BBInfo =
63 DT.Info[BB];
64
65 // First time we visited this BB?
66 if (NextSucc == GraphT::child_begin(BB)) {
67 BBInfo.DFSNum = BBInfo.Semi = ++N;
68 BBInfo.Label = BB;
69
70 DT.Vertex.push_back(BB); // Vertex[n] = V;
71
72 if (IsChildOfArtificialExit)
73 BBInfo.Parent = 1;
74
75 IsChildOfArtificialExit = false;
76 }
77
78 // store the DFS number of the current BB - the reference to BBInfo might
79 // get invalidated when processing the successors.
80 unsigned BBDFSNum = BBInfo.DFSNum;
81
82 // If we are done with this block, remove it from the worklist.
83 if (NextSucc == GraphT::child_end(BB)) {
84 Worklist.pop_back();
85 continue;
86 }
87
88 // Increment the successor number for the next time we get to it.
89 ++Worklist.back().second;
90
91 // Visit the successor next, if it isn't already visited.
92 typename GraphT::NodeType* Succ = *NextSucc;
93
94 typename DominatorTreeBase::InfoRec &SuccVInfo =
95 DT.Info[Succ];
96 if (SuccVInfo.Semi == 0) {
97 SuccVInfo.Parent = BBDFSNum;
98 Worklist.push_back(std::make_pair(Succ, GraphT::child_begin(Succ)));
99 }
100 }
101 #endif
102 return N;
103 }
104
105 template
106 typename GraphT::NodeType*
107 Eval(DominatorTreeBase& DT,
108 typename GraphT::NodeType *VIn, unsigned LastLinked) {
109 typename DominatorTreeBase::InfoRec &VInInfo =
110 DT.Info[VIn];
111 if (VInInfo.DFSNum < LastLinked)
112 return VIn;
113
114 SmallVector Work;
115 SmallPtrSet Visited;
116
117 if (VInInfo.Parent >= LastLinked)
118 Work.push_back(VIn);
119
120 while (!Work.empty()) {
121 typename GraphT::NodeType* V = Work.back();
122 typename DominatorTreeBase::InfoRec &VInfo =
123 DT.Info[V];
124 typename GraphT::NodeType* VAncestor = DT.Vertex[VInfo.Parent];
125
126 // Process Ancestor first
127 if (Visited.insert(VAncestor) && VInfo.Parent >= LastLinked) {
128 Work.push_back(VAncestor);
129 continue;
130 }
131 Work.pop_back();
132
133 // Update VInfo based on Ancestor info
134 if (VInfo.Parent < LastLinked)
135 continue;
136
137 typename DominatorTreeBase::InfoRec &VAInfo =
138 DT.Info[VAncestor];
139 typename GraphT::NodeType* VAncestorLabel = VAInfo.Label;
140 typename GraphT::NodeType* VLabel = VInfo.Label;
141 if (DT.Info[VAncestorLabel].Semi < DT.Info[VLabel].Semi)
142 VInfo.Label = VAncestorLabel;
143 VInfo.Parent = VAInfo.Parent;
144 }
145
146 return VInInfo.Label;
147 }
148
149 template
150 void Calculate(DominatorTreeBase::NodeType>& DT,
151 FuncT& F) {
152 typedef GraphTraits GraphT;
153
154 unsigned N = 0;
155 bool MultipleRoots = (DT.Roots.size() > 1);
156 if (MultipleRoots) {
157 typename DominatorTreeBase::InfoRec &BBInfo =
158 DT.Info[NULL];
159 BBInfo.DFSNum = BBInfo.Semi = ++N;
160 BBInfo.Label = NULL;
161
162 DT.Vertex.push_back(NULL); // Vertex[n] = V;
163 }
164
165 // Step #1: Number blocks in depth-first order and initialize variables used
166 // in later stages of the algorithm.
167 for (unsigned i = 0, e = static_cast(DT.Roots.size());
168 i != e; ++i)
169 N = DFSPass(DT, DT.Roots[i], N);
170
171 // it might be that some blocks did not get a DFS number (e.g., blocks of
172 // infinite loops). In these cases an artificial exit node is required.
173 MultipleRoots |= (DT.isPostDominator() && N != GraphTraits::size(&F));
174
175 // When naively implemented, the Lengauer-Tarjan algorithm requires a separate
176 // bucket for each vertex. However, this is unnecessary, because each vertex
177 // is only placed into a single bucket (that of its semidominator), and each
178 // vertex's bucket is processed before it is added to any bucket itself.
179 //
180 // Instead of using a bucket per vertex, we use a single array Buckets that
181 // has two purposes. Before the vertex V with preorder number i is processed,
182 // Buckets[i] stores the index of the first element in V's bucket. After V's
183 // bucket is processed, Buckets[i] stores the index of the next element in the
184 // bucket containing V, if any.
185 SmallVector Buckets;
186 Buckets.resize(N + 1);
187 for (unsigned i = 1; i <= N; ++i)
188 Buckets[i] = i;
189
190 for (unsigned i = N; i >= 2; --i) {
191 typename GraphT::NodeType* W = DT.Vertex[i];
192 typename DominatorTreeBase::InfoRec &WInfo =
193 DT.Info[W];
194
195 // Step #2: Implicitly define the immediate dominator of vertices
196 for (unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
197 typename GraphT::NodeType* V = DT.Vertex[Buckets[j]];
198 typename GraphT::NodeType* U = Eval(DT, V, i + 1);
199 DT.IDoms[V] = DT.Info[U].Semi < i ? U : W;
200 }
201
202 // Step #3: Calculate the semidominators of all vertices
203
204 // initialize the semi dominator to point to the parent node
205 WInfo.Semi = WInfo.Parent;
206 typedef GraphTraits > InvTraits;
207 for (typename InvTraits::ChildIteratorType CI =
208 InvTraits::child_begin(W),
209 E = InvTraits::child_end(W); CI != E; ++CI) {
210 typename InvTraits::NodeType *N = *CI;
211 if (DT.Info.count(N)) { // Only if this predecessor is reachable!
212 unsigned SemiU = DT.Info[Eval(DT, N, i + 1)].Semi;
213 if (SemiU < WInfo.Semi)
214 WInfo.Semi = SemiU;
215 }
216 }
217
218 // If V is a non-root vertex and sdom(V) = parent(V), then idom(V) is
219 // necessarily parent(V). In this case, set idom(V) here and avoid placing
220 // V into a bucket.
221 if (WInfo.Semi == WInfo.Parent) {
222 DT.IDoms[W] = DT.Vertex[WInfo.Parent];
223 } else {
224 Buckets[i] = Buckets[WInfo.Semi];
225 Buckets[WInfo.Semi] = i;
226 }
227 }
228
229 if (N >= 1) {
230 typename GraphT::NodeType* Root = DT.Vertex[1];
231 for (unsigned j = 1; Buckets[j] != 1; j = Buckets[j]) {
232 typename GraphT::NodeType* V = DT.Vertex[Buckets[j]];
233 DT.IDoms[V] = Root;
234 }
235 }
236
237 // Step #4: Explicitly define the immediate dominator of each vertex
238 for (unsigned i = 2; i <= N; ++i) {
239 typename GraphT::NodeType* W = DT.Vertex[i];
240 typename GraphT::NodeType*& WIDom = DT.IDoms[W];
241 if (WIDom != DT.Vertex[DT.Info[W].Semi])
242 WIDom = DT.IDoms[WIDom];
243 }
244
245 if (DT.Roots.empty()) return;
246
247 // Add a node for the root. This node might be the actual root, if there is
248 // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
249 // which postdominates all real exits if there are multiple exit blocks, or
250 // an infinite loop.
251 typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : 0;
252
253 DT.DomTreeNodes[Root] = DT.RootNode =
254 new DomTreeNodeBase(Root, 0);
255
256 // Loop over all of the reachable blocks in the function...
257 for (unsigned i = 2; i <= N; ++i) {
258 typename GraphT::NodeType* W = DT.Vertex[i];
259
260 DomTreeNodeBase *BBNode = DT.DomTreeNodes[W];
261 if (BBNode) continue; // Haven't calculated this node yet?
262
263 typename GraphT::NodeType* ImmDom = DT.getIDom(W);
264
265 assert(ImmDom || DT.DomTreeNodes[NULL]);
266
267 // Get or calculate the node for the immediate dominator
268 DomTreeNodeBase *IDomNode =
269 DT.getNodeForBlock(ImmDom);
270
271 // Add a new tree node for this BasicBlock, and link it as a child of
272 // IDomNode
273 DomTreeNodeBase *C =
274 new DomTreeNodeBase(W, IDomNode);
275 DT.DomTreeNodes[W] = IDomNode->addChild(C);
276 }
277
278 // Free temporary memory used to construct idom's
279 DT.IDoms.clear();
280 DT.Info.clear();
281 std::vector().swap(DT.Vertex);
282
283 DT.updateDFSNumbers();
284 }
285
286 }
287
288 #endif
0 //===- Dominators.h - Dominator Info Calculation ----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DominatorTree class, which provides fast and efficient
10 // dominance queries.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_DOMINATORS_H
15 #define LLVM_IR_DOMINATORS_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/DepthFirstIterator.h"
19 #include "llvm/ADT/GraphTraits.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Pass.h"
24 #include "llvm/Support/CFG.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include
28
29 namespace llvm {
30
31 //===----------------------------------------------------------------------===//
32 /// DominatorBase - Base class that other, more interesting dominator analyses
33 /// inherit from.
34 ///
35 template
36 class DominatorBase {
37 protected:
38 std::vector Roots;
39 const bool IsPostDominators;
40 inline explicit DominatorBase(bool isPostDom) :
41 Roots(), IsPostDominators(isPostDom) {}
42 public:
43
44 /// getRoots - Return the root blocks of the current CFG. This may include
45 /// multiple blocks if we are computing post dominators. For forward
46 /// dominators, this will always be a single block (the entry node).
47 ///
48 inline const std::vector &getRoots() const { return Roots; }
49
50 /// isPostDominator - Returns true if analysis based of postdoms
51 ///
52 bool isPostDominator() const { return IsPostDominators; }
53 };
54
55
56 //===----------------------------------------------------------------------===//
57 // DomTreeNode - Dominator Tree Node
58 template class DominatorTreeBase;
59 struct PostDominatorTree;
60 class MachineBasicBlock;
61
62 template
63 class DomTreeNodeBase {
64 NodeT *TheBB;
65 DomTreeNodeBase *IDom;
66 std::vector *> Children;
67 int DFSNumIn, DFSNumOut;
68
69 template friend class DominatorTreeBase;
70 friend struct PostDominatorTree;
71 public:
72 typedef typename std::vector *>::iterator iterator;
73 typedef typename std::vector *>::const_iterator
74 const_iterator;
75
76 iterator begin() { return Children.begin(); }
77 iterator end() { return Children.end(); }
78 const_iterator begin() const { return Children.begin(); }
79 const_iterator end() const { return Children.end(); }
80
81 NodeT *getBlock() const { return TheBB; }
82 DomTreeNodeBase *getIDom() const { return IDom; }
83 const std::vector*> &getChildren() const {
84 return Children;
85 }
86
87 DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom)
88 : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) { }
89
90 DomTreeNodeBase *addChild(DomTreeNodeBase *C) {
91 Children.push_back(C);
92 return C;
93 }
94
95 size_t getNumChildren() const {
96 return Children.size();
97 }
98
99 void clearAllChildren() {
100 Children.clear();
101 }
102
103 bool compare(const DomTreeNodeBase *Other) const {
104 if (getNumChildren() != Other->getNumChildren())
105 return true;
106
107 SmallPtrSet OtherChildren;
108 for (const_iterator I = Other->begin(), E = Other->end(); I != E; ++I) {
109 const NodeT *Nd = (*I)->getBlock();
110 OtherChildren.insert(Nd);
111 }
112
113 for (const_iterator I = begin(), E = end(); I != E; ++I) {
114 const NodeT *N = (*I)->getBlock();
115 if (OtherChildren.count(N) == 0)
116 return true;
117 }
118 return false;
119 }
120
121 void setIDom(DomTreeNodeBase *NewIDom) {
122 assert(IDom && "No immediate dominator?");
123 if (IDom != NewIDom) {
124 typename std::vector*>::iterator I =
125 std::find(IDom->Children.begin(), IDom->Children.end(), this);
126 assert(I != IDom->Children.end() &&
127 "Not in immediate dominator children set!");
128 // I am no longer your child...
129 IDom->Children.erase(I);
130
131 // Switch to new dominator
132 IDom = NewIDom;
133 IDom->Children.push_back(this);
134 }
135 }
136
137 /// getDFSNumIn/getDFSNumOut - These are an internal implementation detail, do
138 /// not call them.
139 unsigned getDFSNumIn() const { return DFSNumIn; }
140 unsigned getDFSNumOut() const { return DFSNumOut; }
141 private:
142 // Return true if this node is dominated by other. Use this only if DFS info
143 // is valid.
144 bool DominatedBy(const DomTreeNodeBase *other) const {
145 return this->DFSNumIn >= other->DFSNumIn &&
146 this->DFSNumOut <= other->DFSNumOut;
147 }
148 };
149
150 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
151 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
152
153 template
154 inline raw_ostream &operator<<(raw_ostream &o,
155 const DomTreeNodeBase *Node) {
156 if (Node->getBlock())
157 Node->getBlock()->printAsOperand(o, false);
158 else
159 o << " <>";
160
161 o << " {" << Node->getDFSNumIn() << "," << Node->getDFSNumOut() << "}";
162
163 return o << "\n";
164 }
165
166 template
167 inline void PrintDomTree(const DomTreeNodeBase *N, raw_ostream &o,
168 unsigned Lev) {
169 o.indent(2*Lev) << "[" << Lev << "] " << N;
170 for (typename DomTreeNodeBase::const_iterator I = N->begin(),
171 E = N->end(); I != E; ++I)
172 PrintDomTree(*I, o, Lev+1);
173 }
174
175 typedef DomTreeNodeBase DomTreeNode;
176
177 //===----------------------------------------------------------------------===//
178 /// DominatorTree - Calculate the immediate dominator tree for a function.
179 ///
180
181 template
182 void Calculate(DominatorTreeBase::NodeType>& DT,
183 FuncT& F);
184
185 template
186 class DominatorTreeBase : public DominatorBase {
187 bool dominatedBySlowTreeWalk(const DomTreeNodeBase *A,
188 const DomTreeNodeBase *B) const {
189 assert(A != B);
190 assert(isReachableFromEntry(B));
191 assert(isReachableFromEntry(A));
192
193 const DomTreeNodeBase *IDom;
194 while ((IDom = B->getIDom()) != 0 && IDom != A && IDom != B)
195 B = IDom; // Walk up the tree
196 return IDom != 0;
197 }
198
199 protected:
200 typedef DenseMap*> DomTreeNodeMapType;
201 DomTreeNodeMapType DomTreeNodes;
202 DomTreeNodeBase *RootNode;
203
204 bool DFSInfoValid;
205 unsigned int SlowQueries;
206 // Information record used during immediate dominators computation.
207 struct InfoRec {
208 unsigned DFSNum;
209 unsigned Parent;
210 unsigned Semi;
211 NodeT *Label;
212
213 InfoRec() : DFSNum(0), Parent(0), Semi(0), Label(0) {}
214 };
215
216 DenseMap IDoms;
217
218 // Vertex - Map the DFS number to the BasicBlock*
219 std::vector Vertex;
220
221 // Info - Collection of information used during the computation of idoms.
222 DenseMap Info;
223
224 void reset() {
225 for (typename DomTreeNodeMapType::iterator I = this->DomTreeNodes.begin(),
226 E = DomTreeNodes.end(); I != E; ++I)
227 delete I->second;
228 DomTreeNodes.clear();
229 IDoms.clear();
230 this->Roots.clear();
231 Vertex.clear();
232 RootNode = 0;
233 }
234
235 // NewBB is split and now it has one successor. Update dominator tree to
236 // reflect this change.
237 template
238 void Split(DominatorTreeBase& DT,
239 typename GraphT::NodeType* NewBB) {
240 assert(std::distance(GraphT::child_begin(NewBB),
241 GraphT::child_end(NewBB)) == 1 &&
242 "NewBB should have a single successor!");
243 typename GraphT::NodeType* NewBBSucc = *GraphT::child_begin(NewBB);
244
245 std::vector PredBlocks;
246 typedef GraphTraits > InvTraits;
247 for (typename InvTraits::ChildIteratorType PI =
248 InvTraits::child_begin(NewBB),
249 PE = InvTraits::child_end(NewBB); PI != PE; ++PI)
250 PredBlocks.push_back(*PI);
251
252 assert(!PredBlocks.empty() && "No predblocks?");
253
254 bool NewBBDominatesNewBBSucc = true;
255 for (typename InvTraits::ChildIteratorType PI =
256 InvTraits::child_begin(NewBBSucc),
257 E = InvTraits::child_end(NewBBSucc); PI != E; ++PI) {
258 typename InvTraits::NodeType *ND = *PI;
259 if (ND != NewBB && !DT.dominates(NewBBSucc, ND) &&
260 DT.isReachableFromEntry(ND)) {
261 NewBBDominatesNewBBSucc = false;
262 break;
263 }
264 }
265
266 // Find NewBB's immediate dominator and create new dominator tree node for
267 // NewBB.
268 NodeT *NewBBIDom = 0;
269 unsigned i = 0;
270 for (i = 0; i < PredBlocks.size(); ++i)
271 if (DT.isReachableFromEntry(PredBlocks[i])) {
272 NewBBIDom = PredBlocks[i];
273 break;
274 }
275
276 // It's possible that none of the predecessors of NewBB are reachable;
277 // in that case, NewBB itself is unreachable, so nothing needs to be
278 // changed.
279 if (!NewBBIDom)
280 return;
281
282 for (i = i + 1; i < PredBlocks.size(); ++i) {
283 if (DT.isReachableFromEntry(PredBlocks[i]))
284 NewBBIDom = DT.findNearestCommonDominator(NewBBIDom, PredBlocks[i]);
285 }
286
287 // Create the new dominator tree node... and set the idom of NewBB.
288 DomTreeNodeBase *NewBBNode = DT.addNewBlock(NewBB, NewBBIDom);
289
290 // If NewBB strictly dominates other blocks, then it is now the immediate
291 // dominator of NewBBSucc. Update the dominator tree as appropriate.
292 if (NewBBDominatesNewBBSucc) {
293 DomTreeNodeBase *NewBBSuccNode = DT.getNode(NewBBSucc);
294 DT.changeImmediateDominator(NewBBSuccNode, NewBBNode);
295 }
296 }
297
298 public:
299 explicit DominatorTreeBase(bool isPostDom)
300 : DominatorBase(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
301 virtual ~DominatorTreeBase() { reset(); }
302
303 /// compare - Return false if the other dominator tree base matches this
304 /// dominator tree base. Otherwise return true.
305 bool compare(DominatorTreeBase &Other) const {
306
307 const DomTreeNodeMapType &OtherDomTreeNodes = Other.DomTreeNodes;
308 if (DomTreeNodes.size() != OtherDomTreeNodes.size())
309 return true;
310
311 for (typename DomTreeNodeMapType::const_iterator
312 I = this->DomTreeNodes.begin(),
313 E = this->DomTreeNodes.end(); I != E; ++I) {
314 NodeT *BB = I->first;
315 typename DomTreeNodeMapType::const_iterator OI = OtherDomTreeNodes.find(BB);
316 if (OI == OtherDomTreeNodes.end())
317 return true;
318
319 DomTreeNodeBase* MyNd = I->second;
320 DomTreeNodeBase* OtherNd = OI->second;
321
322 if (MyNd->compare(OtherNd))
323 return true;
324 }
325
326 return false;
327 }
328
329 virtual void releaseMemory() { reset(); }
330
331 /// getNode - return the (Post)DominatorTree node for the specified basic
332 /// block. This is the same as using operator[] on this class.
333 ///
334 inline DomTreeNodeBase *getNode(NodeT *BB) const {
335 return DomTreeNodes.lookup(BB);
336 }
337
338 /// getRootNode - This returns the entry node for the CFG of the function. If
339 /// this tree represents the post-dominance relations for a function, however,
340 /// this root may be a node with the block == NULL. This is the case when
341 /// there are multiple exit nodes from a particular function. Consumers of
342 /// post-dominance information must be capable of dealing with this
343 /// possibility.
344 ///
345 DomTreeNodeBase *getRootNode() { return RootNode; }
346 const DomTreeNodeBase *getRootNode() const { return RootNode; }
347
348 /// Get all nodes dominated by R, including R itself.
349 void getDescendants(NodeT *R, SmallVectorImpl &Result) const {
350 Result.clear();
351 const DomTreeNodeBase *RN = getNode(R);
352 if (RN == NULL)
353 return; // If R is unreachable, it will not be present in the DOM tree.
354 SmallVector *, 8> WL;
355 WL.push_back(RN);
356
357 while (!WL.empty()) {
358 const DomTreeNodeBase *N = WL.pop_back_val();
359 Result.push_back(N->getBlock());
360 WL.append(N->begin(), N->end());
361 }
362 }
363
364 /// properlyDominates - Returns true iff A dominates B and A != B.
365 /// Note that this is not a constant time operation!
366 ///
367 bool properlyDominates(const DomTreeNodeBase *A,
368 const DomTreeNodeBase *B) {
369 if (A == 0 || B == 0)
370 return false;
371 if (A == B)
372 return false;
373 return dominates(A, B);
374 }
375
376 bool properlyDominates(const NodeT *A, const NodeT *B);
377
378 /// isReachableFromEntry - Return true if A is dominated by the entry
379 /// block of the function containing it.
380 bool isReachableFromEntry(const NodeT* A) const {
381 assert(!this->isPostDominator() &&
382 "This is not implemented for post dominators");
383 return isReachableFromEntry(getNode(const_cast(A)));
384 }
385
386 inline bool isReachableFromEntry(const DomTreeNodeBase *A) const {
387 return A;
388 }
389
390 /// dominates - Returns true iff A dominates B. Note that this is not a
391 /// constant time operation!
392 ///
393 inline bool dominates(const DomTreeNodeBase *A,
394 const DomTreeNodeBase *B) {
395 // A node trivially dominates itself.
396 if (B == A)
397 return true;
398
399 // An unreachable node is dominated by anything.
400 if (!isReachableFromEntry(B))
401 return true;
402
403 // And dominates nothing.
404 if (!isReachableFromEntry(A))
405 return false;
406
407 // Compare the result of the tree walk and the dfs numbers, if expensive
408 // checks are enabled.
409 #ifdef XDEBUG
410 assert((!DFSInfoValid ||
411 (dominatedBySlowTreeWalk(A, B) == B->DominatedBy(A))) &&
412 "Tree walk disagrees with dfs numbers!");
413 #endif
414
415 if (DFSInfoValid)
416 return B->DominatedBy(A);
417
418 // If we end up with too many slow queries, just update the
419 // DFS numbers on the theory that we are going to keep querying.
420 SlowQueries++;
421 if (SlowQueries > 32) {
422 updateDFSNumbers();
423 return B->DominatedBy(A);
424 }
425
426 return dominatedBySlowTreeWalk(A, B);
427 }
428
429 bool dominates(const NodeT *A, const NodeT *B);
430
431 NodeT *getRoot() const {
432 assert(this->Roots.size() == 1 && "Should always have entry node!");
433 return this->Roots[0];
434 }
435
436 /// findNearestCommonDominator - Find nearest common dominator basic block
437 /// for basic block A and B. If there is no such block then return NULL.
438 NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) {
439 assert(A->getParent() == B->getParent() &&
440 "Two blocks are not in same function");
441
442 // If either A or B is a entry block then it is nearest common dominator
443 // (for forward-dominators).
444 if (!this->isPostDominator()) {
445 NodeT &Entry = A->getParent()->front();
446 if (A == &Entry || B == &Entry)
447 return &Entry;
448 }
449
450 // If B dominates A then B is nearest common dominator.
451 if (dominates(B, A))
452 return B;
453
454 // If A dominates B then A is nearest common dominator.
455 if (dominates(A, B))
456 return A;
457
458 DomTreeNodeBase *NodeA = getNode(A);
459 DomTreeNodeBase *NodeB = getNode(B);
460
461 // Collect NodeA dominators set.
462 SmallPtrSet*, 16> NodeADoms;
463 NodeADoms.insert(NodeA);
464 DomTreeNodeBase *IDomA = NodeA->getIDom();
465 while (IDomA) {
466 NodeADoms.insert(IDomA);
467 IDomA = IDomA->getIDom();
468 }
469
470 // Walk NodeB immediate dominators chain and find common dominator node.
471 DomTreeNodeBase *IDomB = NodeB->getIDom();
472 while (IDomB) {
473 if (NodeADoms.count(IDomB) != 0)
474 return IDomB->getBlock();
475
476 IDomB = IDomB->getIDom();
477 }
478
479 return NULL;
480 }
481
482 const NodeT *findNearestCommonDominator(const NodeT *A, const NodeT *B) {
483 // Cast away the const qualifiers here. This is ok since
484 // const is re-introduced on the return type.
485 return findNearestCommonDominator(const_cast(A),
486 const_cast(B));
487 }
488
489 //===--------------------------------------------------------------------===//
490 // API to update (Post)DominatorTree information based on modifications to
491 // the CFG...
492
493 /// addNewBlock - Add a new node to the dominator tree information. This
494 /// creates a new node as a child of DomBB dominator node,linking it into
495 /// the children list of the immediate dominator.
496 DomTreeNodeBase *addNewBlock(NodeT *BB, NodeT *DomBB) {
497 assert(getNode(BB) == 0 && "Block already in dominator tree!");
498 DomTreeNodeBase *IDomNode = getNode(DomBB);
499 assert(IDomNode && "Not immediate dominator specified for block!");
500 DFSInfoValid = false;
501 return DomTreeNodes[BB] =
502 IDomNode->addChild(new DomTreeNodeBase(BB, IDomNode));
503 }
504
505 /// changeImmediateDominator - This method is used to update the dominator
506 /// tree information when a node's immediate dominator changes.
507 ///
508 void changeImmediateDominator(DomTreeNodeBase *N,
509 DomTreeNodeBase *NewIDom) {
510 assert(N && NewIDom && "Cannot change null node pointers!");
511 DFSInfoValid = false;
512 N->setIDom(NewIDom);
513 }
514
515 void changeImmediateDominator(NodeT *BB, NodeT *NewBB) {
516 changeImmediateDominator(getNode(BB), getNode(NewBB));
517 }
518
519 /// eraseNode - Removes a node from the dominator tree. Block must not
520 /// dominate any other blocks. Removes node from its immediate dominator's
521 /// children list. Deletes dominator node associated with basic block BB.
522 void eraseNode(NodeT *BB) {
523 DomTreeNodeBase *Node = getNode(BB);
524 assert(Node && "Removing node that isn't in dominator tree.");
525 assert(Node->getChildren().empty() && "Node is not a leaf node.");
526
527 // Remove node from immediate dominator's children list.
528 DomTreeNodeBase *IDom = Node->getIDom();
529 if (IDom) {
530 typename std::vector*>::iterator I =
531 std::find(IDom->Children.begin(), IDom->Children.end(), Node);
532 assert(I != IDom->Children.end() &&
533 "Not in immediate dominator children set!");
534 // I am no longer your child...
535 IDom->Children.erase(I);
536 }
537
538 DomTreeNodes.erase(BB);
539 delete Node;
540 }
541
542 /// removeNode - Removes a node from the dominator tree. Block must not
543 /// dominate any other blocks. Invalidates any node pointing to removed
544 /// block.
545 void removeNode(NodeT *BB) {
546 assert(getNode(BB) && "Removing node that isn't in dominator tree.");
547 DomTreeNodes.erase(BB);
548 }
549
550 /// splitBlock - BB is split and now it has one successor. Update dominator
551 /// tree to reflect this change.
552 void splitBlock(NodeT* NewBB) {
553 if (this->IsPostDominators)
554 this->Split, GraphTraits > >(*this, NewBB);
555 else
556 this->Split >(*this, NewBB);
557 }
558
559 /// print - Convert to human readable form
560 ///
561 void print(raw_ostream &o) const {
562 o << "=============================--------------------------------\n";
563 if (this->isPostDominator())
564 o << "Inorder PostDominator Tree: ";
565 else
566 o << "Inorder Dominator Tree: ";
567 if (!this->DFSInfoValid)
568 o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
569 o << "\n";
570
571 // The postdom tree can have a null root if there are no returns.
572 if (getRootNode())
573 PrintDomTree(getRootNode(), o, 1);
574 }
575
576 protected:
577 template
578 friend typename GraphT::NodeType* Eval(
579 DominatorTreeBase& DT,
580 typename GraphT::NodeType* V,
581 unsigned LastLinked);
582
583 template
584 friend unsigned DFSPass(DominatorTreeBase& DT,
585 typename GraphT::NodeType* V,
586 unsigned N);
587
588 template
589 friend void Calculate(DominatorTreeBase::NodeType>& DT,
590 FuncT& F);
591
592 /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
593 /// dominator tree in dfs order.
594 void updateDFSNumbers() {
595 unsigned DFSNum = 0;
596
597 SmallVector*,
598 typename DomTreeNodeBase::iterator>, 32> WorkStack;
599
600 DomTreeNodeBase *ThisRoot = getRootNode();
601
602 if (!ThisRoot)
603 return;
604
605 // Even in the case of multiple exits that form the post dominator root
606 // nodes, do not iterate over all exits, but start from the virtual root
607 // node. Otherwise bbs, that are not post dominated by any exit but by the
608 // virtual root node, will never be assigned a DFS number.
609 WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
610 ThisRoot->DFSNumIn = DFSNum++;
611
612 while (!WorkStack.empty()) {
613 DomTreeNodeBase *Node = WorkStack.back().first;
614 typename DomTreeNodeBase::iterator ChildIt =
615 WorkStack.back().second;
616
617 // If we visited all of the children of this node, "recurse" back up the
618 // stack setting the DFOutNum.
619 if (ChildIt == Node->end()) {
620 Node->DFSNumOut = DFSNum++;
621 WorkStack.pop_back();
622 } else {
623 // Otherwise, recursively visit this child.
624 DomTreeNodeBase *Child = *ChildIt;
625 ++WorkStack.back().second;
626
627 WorkStack.push_back(std::make_pair(Child, Child->begin()));
628 Child->DFSNumIn = DFSNum++;
629 }
630 }
631
632 SlowQueries = 0;
633 DFSInfoValid = true;
634 }
635
636 DomTreeNodeBase *getNodeForBlock(NodeT *BB) {
637 if (DomTreeNodeBase *Node = getNode(BB))
638 return Node;
639
640 // Haven't calculated this node yet? Get or calculate the node for the
641 // immediate dominator.
642 NodeT *IDom = getIDom(BB);
643
644 assert(IDom || this->DomTreeNodes[NULL]);
645 DomTreeNodeBase *IDomNode = getNodeForBlock(IDom);
646
647 // Add a new tree node for this BasicBlock, and link it as a child of
648 // IDomNode
649 DomTreeNodeBase *C = new DomTreeNodeBase(BB, IDomNode);
650 return this->DomTreeNodes[BB] = IDomNode->addChild(C);
651 }
652
653 inline NodeT *getIDom(NodeT *BB) const {
654 return IDoms.lookup(BB);
655 }
656
657 inline void addRoot(NodeT* BB) {
658 this->Roots.push_back(BB);
659 }
660
661 public:
662 /// recalculate - compute a dominator tree for the given function
663 template
664 void recalculate(FT& F) {
665 typedef GraphTraits TraitsTy;
666 reset();
667 this->Vertex.push_back(0);
668
669 if (!this->IsPostDominators) {
670 // Initialize root
671 NodeT *entry = TraitsTy::getEntryNode(&F);
672 this->Roots.push_back(entry);
673 this->IDoms[entry] = 0;
674 this->DomTreeNodes[entry] = 0;
675
676 Calculate(*this, F);
677 } else {
678 // Initialize the roots list
679 for (typename TraitsTy::nodes_iterator I = TraitsTy::nodes_begin(&F),
680 E = TraitsTy::nodes_end(&F); I != E; ++I) {
681 if (TraitsTy::child_begin(I) == TraitsTy::child_end(I))
682 addRoot(I);
683
684 // Prepopulate maps so that we don't get iterator invalidation issues later.
685 this->IDoms[I] = 0;
686 this->DomTreeNodes[I] = 0;
687 }
688
689 Calculate >(*this, F);
690 }
691 }
692 };
693
694 // These two functions are declared out of line as a workaround for building
695 // with old (< r147295) versions of clang because of pr11642.
696 template
697 bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) {
698 if (A == B)
699 return true;
700
701 // Cast away the const qualifiers here. This is ok since
702 // this function doesn't actually return the values returned
703 // from getNode.
704 return dominates(getNode(const_cast(A)),
705 getNode(const_cast(B)));
706 }
707 template
708 bool
709 DominatorTreeBase::properlyDominates(const NodeT *A, const NodeT *B) {
710 if (A == B)
711 return false;
712
713 // Cast away the const qualifiers here. This is ok since
714 // this function doesn't actually return the values returned
715 // from getNode.
716 return dominates(getNode(const_cast(A)),
717 getNode(const_cast(B)));
718 }
719
720 EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase);
721
722 class BasicBlockEdge {
723 const BasicBlock *Start;
724 const BasicBlock *End;
725 public:
726 BasicBlockEdge(const BasicBlock *Start_, const BasicBlock *End_) :
727 Start(Start_), End(End_) { }
728 const BasicBlock *getStart() const {
729 return Start;
730 }
731 const BasicBlock *getEnd() const {
732 return End;
733 }
734 bool isSingleEdge() const;
735 };
736
737 //===-------------------------------------
738 /// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
739 /// compute a normal dominator tree.
740 ///
741 class DominatorTree : public FunctionPass {
742 public:
743 static char ID; // Pass ID, replacement for typeid
744 DominatorTreeBase* DT;
745
746 DominatorTree() : FunctionPass(ID) {
747 initializeDominatorTreePass(*PassRegistry::getPassRegistry());
748 DT = new DominatorTreeBase(false);
749 }
750
751 ~DominatorTree() {
752 delete DT;
753 }
754
755 DominatorTreeBase& getBase() { return *DT; }
756
757 /// getRoots - Return the root blocks of the current CFG. This may include
758 /// multiple blocks if we are computing post dominators. For forward
759 /// dominators, this will always be a single block (the entry node).
760 ///
761 inline const std::vector &getRoots() const {
762 return DT->getRoots();
763 }
764
765 inline BasicBlock *getRoot() const {
766 return DT->getRoot();
767 }
768
769 inline DomTreeNode *getRootNode() const {
770 return DT->getRootNode();
771 }
772
773 /// Get all nodes dominated by R, including R itself.
774 void getDescendants(BasicBlock *R,
775 SmallVectorImpl &Result) const {
776 DT->getDescendants(R, Result);
777 }
778
779 /// compare - Return false if the other dominator tree matches this
780 /// dominator tree. Otherwise return true.
781 inline bool compare(DominatorTree &Other) const {
782 DomTreeNode *R = getRootNode();
783 DomTreeNode *OtherR = Other.getRootNode();
784
785 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
786 return true;
787
788 if (DT->compare(Other.getBase()))
789 return true;
790
791 return false;
792 }
793
794 virtual bool runOnFunction(Function &F);
795
796 virtual void verifyAnalysis() const;
797
798 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
799 AU.setPreservesAll();
800 }
801
802 inline bool dominates(const DomTreeNode* A, const DomTreeNode* B) const {
803 return DT->dominates(A, B);
804 }
805
806 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
807 return DT->dominates(A, B);
808 }
809
810 // dominates - Return true if Def dominates a use in User. This performs
811 // the special checks necessary if Def and User are in the same basic block.
812 // Note that Def doesn't dominate a use in Def itself!
813 bool dominates(const Instruction *Def, const Use &U) const;
814 bool dominates(const Instruction *Def, const Instruction *User) const;
815 bool dominates(const Instruction *Def, const BasicBlock *BB) const;
816 bool dominates(const BasicBlockEdge &BBE, const Use &U) const;
817 bool dominates(const BasicBlockEdge &BBE, const BasicBlock *BB) const;
818
819 bool properlyDominates(const DomTreeNode *A, const DomTreeNode *B) const {
820 return DT->properlyDominates(A, B);
821 }
822
823 bool properlyDominates(const BasicBlock *A, const BasicBlock *B) const {
824 return DT->properlyDominates(A, B);
825 }
826
827 /// findNearestCommonDominator - Find nearest common dominator basic block
828 /// for basic block A and B. If there is no such block then return NULL.
829 inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
830 return DT->findNearestCommonDominator(A, B);
831 }
832
833 inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
834 const BasicBlock *B) {
835 return DT->findNearestCommonDominator(A, B);
836 }
837
838 inline DomTreeNode *operator[](BasicBlock *BB) const {
839 return DT->getNode(BB);
840 }
841
842 /// getNode - return the (Post)DominatorTree node for the specified basic
843 /// block. This is the same as using operator[] on this class.
844 ///
845 inline DomTreeNode *getNode(BasicBlock *BB) const {
846 return DT->getNode(BB);
847 }
848
849 /// addNewBlock - Add a new node to the dominator tree information. This
850 /// creates a new node as a child of DomBB dominator node,linking it into
851 /// the children list of the immediate dominator.
852 inline DomTreeNode *addNewBlock(BasicBlock *BB, BasicBlock *DomBB) {
853 return DT->addNewBlock(BB, DomBB);
854 }
855
856 /// changeImmediateDominator - This method is used to update the dominator
857 /// tree information when a node's immediate dominator changes.
858 ///
859 inline void changeImmediateDominator(BasicBlock *N, BasicBlock* NewIDom) {
860 DT->changeImmediateDominator(N, NewIDom);
861 }
862
863 inline void changeImmediateDominator(DomTreeNode *N, DomTreeNode* NewIDom) {
864 DT->changeImmediateDominator(N, NewIDom);
865 }
866
867 /// eraseNode - Removes a node from the dominator tree. Block must not
868 /// dominate any other blocks. Removes node from its immediate dominator's
869 /// children list. Deletes dominator node associated with basic block BB.
870 inline void eraseNode(BasicBlock *BB) {
871 DT->eraseNode(BB);
872 }
873
874 /// splitBlock - BB is split and now it has one successor. Update dominator
875 /// tree to reflect this change.
876 inline void splitBlock(BasicBlock* NewBB) {
877 DT->splitBlock(NewBB);
878 }
879
880 bool isReachableFromEntry(const BasicBlock* A) const {
881 return DT->isReachableFromEntry(A);
882 }
883
884 bool isReachableFromEntry(const Use &U) const;
885
886
887 virtual void releaseMemory() {
888 DT->releaseMemory();
889 }
890
891 virtual void print(raw_ostream &OS, const Module* M= 0) const;
892 };
893
894 //===-------------------------------------
895 /// DominatorTree GraphTraits specialization so the DominatorTree can be
896 /// iterable by generic graph iterators.
897 ///
898 template <> struct GraphTraits {
899 typedef DomTreeNode NodeType;
900 typedef NodeType::iterator ChildIteratorType;
901
902 static NodeType *getEntryNode(NodeType *N) {
903 return N;
904 }
905 static inline ChildIteratorType child_begin(NodeType *N) {
906 return N->begin();
907 }
908 static inline ChildIteratorType child_end(NodeType *N) {
909 return N->end();
910 }
911
912 typedef df_iterator nodes_iterator;
913
914 static nodes_iterator nodes_begin(DomTreeNode *N) {
915 return df_begin(getEntryNode(N));
916 }
917
918 static nodes_iterator nodes_end(DomTreeNode *N) {
919 return df_end(getEntryNode(N));
920 }
921 };
922
923 template <> struct GraphTraits
924 : public GraphTraits {
925 static NodeType *getEntryNode(DominatorTree *DT) {
926 return DT->getRootNode();
927 }
928
929 static nodes_iterator nodes_begin(DominatorTree *N) {
930 return df_begin(getEntryNode(N));
931 }
932
933 static nodes_iterator nodes_end(DominatorTree *N) {
934 return df_end(getEntryNode(N));
935 }
936 };
937
938
939 } // End llvm namespace
940
941 #endif
0 //===- Verifier.h - LLVM IR Verifier ----------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the function verifier interface, that can be used for some
10 // sanity checking of input to the system, and for checking that transformations
11 // haven't done something bad.
12 //
13 // Note that this does not provide full 'java style' security and verifications,
14 // instead it just tries to ensure that code is well formed.
15 //
16 // To see what specifically is checked, look at the top of Verifier.cpp
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_IR_VERIFIER_H
21 #define LLVM_IR_VERIFIER_H
22
23 #include
24
25 namespace llvm {
26
27 class FunctionPass;
28 class Module;
29 class Function;
30
31 /// @brief An enumeration to specify the action to be taken if errors found.
32 ///
33 /// This enumeration is used in the functions below to indicate what should
34 /// happen if the verifier finds errors. Each of the functions that uses
35 /// this enumeration as an argument provides a default value for it. The
36 /// actions are listed below.
37 enum VerifierFailureAction {
38 AbortProcessAction, ///< verifyModule will print to stderr and abort()
39 PrintMessageAction, ///< verifyModule will print to stderr and return true
40 ReturnStatusAction ///< verifyModule will just return true
41 };
42
43 /// @brief Create a verifier pass.
44 ///
45 /// Check a module or function for validity. When the pass is used, the
46 /// action indicated by the \p action argument will be used if errors are
47 /// found.
48 FunctionPass *createVerifierPass(
49 VerifierFailureAction action = AbortProcessAction ///< Action to take
50 );
51
52 /// @brief Check a module for errors.
53 ///
54 /// If there are no errors, the function returns false. If an error is found,
55 /// the action taken depends on the \p action parameter.
56 /// This should only be used for debugging, because it plays games with
57 /// PassManagers and stuff.
58
59 bool verifyModule(
60 const Module &M, ///< The module to be verified
61 VerifierFailureAction action = AbortProcessAction, ///< Action to take
62 std::string *ErrorInfo = 0 ///< Information about failures.
63 );
64
65 // verifyFunction - Check a function for errors, useful for use when debugging a
66 // pass.
67 bool verifyFunction(
68 const Function &F, ///< The function to be verified
69 VerifierFailureAction action = AbortProcessAction ///< Action to take
70 );
71
72 } // End llvm namespace
73
74 #endif
1515 #ifndef LLVM_LINKALLIR_H
1616 #define LLVM_LINKALLIR_H
1717
18 #include "llvm/Analysis/Verifier.h"
1918 #include "llvm/IR/InlineAsm.h"
2019 #include "llvm/IR/Instructions.h"
2120 #include "llvm/IR/IntrinsicInst.h"
2221 #include "llvm/IR/LLVMContext.h"
2322 #include "llvm/IR/Module.h"
23 #include "llvm/IR/Verifier.h"
2424 #include "llvm/Support/Dwarf.h"
2525 #include "llvm/Support/DynamicLibrary.h"
2626 #include "llvm/Support/MathExtras.h"
2626 #include "llvm/Analysis/AliasAnalysis.h"
2727 #include "llvm/Analysis/CFG.h"
2828 #include "llvm/Analysis/CaptureTracking.h"
29 #include "llvm/Analysis/Dominators.h"
3029 #include "llvm/Analysis/ValueTracking.h"
3130 #include "llvm/IR/BasicBlock.h"
3231 #include "llvm/IR/DataLayout.h"
32 #include "llvm/IR/Dominators.h"
3333 #include "llvm/IR/Function.h"
3434 #include "llvm/IR/Instructions.h"
3535 #include "llvm/IR/IntrinsicInst.h"
88
99 #include "llvm-c/Analysis.h"
1010 #include "llvm-c/Initialization.h"
11 #include "llvm/Analysis/Verifier.h"
1211 #include "llvm/IR/Module.h"
12 #include "llvm/IR/Verifier.h"
1313 #include "llvm/InitializePasses.h"
1414 #include "llvm/PassRegistry.h"
1515 #include
1818 #include "llvm/Analysis/AliasAnalysis.h"
1919 #include "llvm/Analysis/CFG.h"
2020 #include "llvm/Analysis/CaptureTracking.h"
21 #include "llvm/Analysis/Dominators.h"
2221 #include "llvm/Analysis/InstructionSimplify.h"
2322 #include "llvm/Analysis/LoopInfo.h"
2423 #include "llvm/Analysis/MemoryBuiltins.h"
2625 #include "llvm/IR/Constants.h"
2726 #include "llvm/IR/DataLayout.h"
2827 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Dominators.h"
2929 #include "llvm/IR/Function.h"
3030 #include "llvm/IR/GlobalAlias.h"
3131 #include "llvm/IR/GlobalVariable.h"
1313
1414 #include "llvm/Analysis/CFG.h"
1515 #include "llvm/ADT/SmallSet.h"
16 #include "llvm/Analysis/Dominators.h"
1716 #include "llvm/Analysis/LoopInfo.h"
17 #include "llvm/IR/Dominators.h"
1818
1919 using namespace llvm;
2020
1414 #define DEBUG_TYPE "iv-users"
1515 #include "llvm/Analysis/IVUsers.h"
1616 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/Analysis/LoopPass.h"
1918 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
2019 #include "llvm/Analysis/ValueTracking.h"
2120 #include "llvm/IR/Constants.h"
2221 #include "llvm/IR/DataLayout.h"
2322 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/Dominators.h"
2424 #include "llvm/IR/Instructions.h"
2525 #include "llvm/IR/Type.h"
2626 #include "llvm/Support/Debug.h"
2121 #include "llvm/ADT/SetVector.h"
2222 #include "llvm/ADT/Statistic.h"
2323 #include "llvm/Analysis/ConstantFolding.h"
24 #include "llvm/Analysis/Dominators.h"
2524 #include "llvm/Analysis/MemoryBuiltins.h"
2625 #include "llvm/Analysis/ValueTracking.h"
2726 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Dominators.h"
2828 #include "llvm/IR/GlobalAlias.h"
2929 #include "llvm/IR/Operator.h"
3030 #include "llvm/Support/ConstantRange.h"
3737 #include "llvm/ADT/STLExtras.h"
3838 #include "llvm/Analysis/AliasAnalysis.h"
3939 #include "llvm/Analysis/ConstantFolding.h"
40 #include "llvm/Analysis/Dominators.h"
4140 #include "llvm/Analysis/InstructionSimplify.h"
4241 #include "llvm/Analysis/Loads.h"
4342 #include "llvm/Analysis/Passes.h"
4443 #include "llvm/Analysis/ValueTracking.h"
4544 #include "llvm/IR/DataLayout.h"
45 #include "llvm/IR/Dominators.h"
4646 #include "llvm/IR/Function.h"
4747 #include "llvm/IR/IntrinsicInst.h"
4848 #include "llvm/InstVisitor.h"
1616 #include "llvm/Analysis/LoopInfo.h"
1717 #include "llvm/ADT/DepthFirstIterator.h"
1818 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/LoopInfoImpl.h"
2120 #include "llvm/Analysis/LoopIterator.h"
2221 #include "llvm/Analysis/ValueTracking.h"
2322 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/Dominators.h"
2424 #include "llvm/IR/Instructions.h"
2525 #include "llvm/IR/Metadata.h"
2626 #include "llvm/Support/CFG.h"
1818 #include "llvm/ADT/STLExtras.h"
1919 #include "llvm/ADT/Statistic.h"
2020 #include "llvm/Analysis/AliasAnalysis.h"
21 #include "llvm/Analysis/Dominators.h"
2221 #include "llvm/Analysis/InstructionSimplify.h"
2322 #include "llvm/Analysis/MemoryBuiltins.h"
2423 #include "llvm/Analysis/PHITransAddr.h"
2524 #include "llvm/Analysis/ValueTracking.h"
2625 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/Dominators.h"
2727 #include "llvm/IR/Function.h"
2828 #include "llvm/IR/Instructions.h"
2929 #include "llvm/IR/IntrinsicInst.h"
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Analysis/PHITransAddr.h"
14 #include "llvm/Analysis/Dominators.h"
1514 #include "llvm/Analysis/InstructionSimplify.h"
1615 #include "llvm/Analysis/ValueTracking.h"
1716 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Dominators.h"
1818 #include "llvm/IR/Instructions.h"
1919 #include "llvm/Support/Debug.h"
2020 #include "llvm/Support/ErrorHandling.h"
1515 #include "llvm/Analysis/PostDominators.h"
1616 #include "llvm/ADT/DepthFirstIterator.h"
1717 #include "llvm/ADT/SetOperations.h"
18 #include "llvm/Analysis/DominatorInternals.h"
18 #include "llvm/IR/DominatorInternals.h"
1919 #include "llvm/IR/Instructions.h"
2020 #include "llvm/Support/CFG.h"
2121 #include "llvm/Support/Debug.h"
6363 #include "llvm/ADT/SmallPtrSet.h"
6464 #include "llvm/ADT/Statistic.h"
6565 #include "llvm/Analysis/ConstantFolding.h"
66 #include "llvm/Analysis/Dominators.h"
6766 #include "llvm/Analysis/InstructionSimplify.h"
6867 #include "llvm/Analysis/LoopInfo.h"
6968 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
7170 #include "llvm/IR/Constants.h"
7271 #include "llvm/IR/DataLayout.h"
7372 #include "llvm/IR/DerivedTypes.h"
73 #include "llvm/IR/Dominators.h"
7474 #include "llvm/IR/GlobalAlias.h"
7575 #include "llvm/IR/GlobalVariable.h"
7676 #include "llvm/IR/Instructions.h"
1515 #include "llvm/Analysis/ScalarEvolutionExpander.h"
1616 #include "llvm/ADT/STLExtras.h"
1717 #include "llvm/ADT/SmallSet.h"
18 #include "llvm/Analysis/Dominators.h"
1918 #include "llvm/Analysis/LoopInfo.h"
2019 #include "llvm/Analysis/TargetTransformInfo.h"
2120 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/IntrinsicInst.h"
2323 #include "llvm/IR/LLVMContext.h"
2424 #include "llvm/Support/Debug.h"
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/Analysis/Dominators.h"
14 #include "llvm/IR/Dominators.h"
1515 #include "llvm/Analysis/LoopInfo.h"
1616 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
1717 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
1414 #define DEBUG_TYPE "dwarfehprepare"
1515 #include "llvm/CodeGen/Passes.h"
1616 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Analysis/Dominators.h"
17 #include "llvm/IR/Dominators.h"
1818 #include "llvm/IR/Function.h"
1919 #include "llvm/IR/Instructions.h"
2020 #include "llvm/IR/IntrinsicInst.h"
1515 //===----------------------------------------------------------------------===//
1616
1717 #include "llvm/CodeGen/GCStrategy.h"
18 #include "llvm/Analysis/DominatorInternals.h"
19 #include "llvm/Analysis/Dominators.h"
2018 #include "llvm/CodeGen/MachineFrameInfo.h"
2119 #include "llvm/CodeGen/MachineFunctionPass.h"
2220 #include "llvm/CodeGen/MachineInstrBuilder.h"
2321 #include "llvm/CodeGen/MachineModuleInfo.h"
2422 #include "llvm/CodeGen/Passes.h"
23 #include "llvm/IR/DominatorInternals.h"
24 #include "llvm/IR/Dominators.h"
2525 #include "llvm/IR/IntrinsicInst.h"
2626 #include "llvm/IR/Module.h"
2727 #include "llvm/Support/Debug.h"
1313
1414 #include "llvm/CodeGen/Passes.h"
1515 #include "llvm/Analysis/Passes.h"
16 #include "llvm/Analysis/Verifier.h"
1716 #include "llvm/CodeGen/GCStrategy.h"
1817 #include "llvm/CodeGen/MachineFunctionPass.h"
1918 #include "llvm/CodeGen/RegAllocRegistry.h"
2019 #include "llvm/IR/IRPrintingPasses.h"
20 #include "llvm/IR/Verifier.h"
2121 #include "llvm/MC/MCAsmInfo.h"
2222 #include "llvm/PassManager.h"
2323 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/ADT/SmallPtrSet.h"
3030 #include "llvm/ADT/SparseSet.h"
3131 #include "llvm/ADT/Statistic.h"
32 #include "llvm/Analysis/Dominators.h"
3332 #include "llvm/Analysis/ValueTracking.h"
3433 #include "llvm/CodeGen/LiveInterval.h"
3534 #include "llvm/CodeGen/MachineBasicBlock.h"
4443 #include "llvm/CodeGen/PseudoSourceValue.h"
4544 #include "llvm/CodeGen/SlotIndexes.h"
4645 #include "llvm/DebugInfo.h"
46 #include "llvm/IR/Dominators.h"
4747 #include "llvm/IR/Function.h"
4848 #include "llvm/IR/Instructions.h"
4949 #include "llvm/IR/Module.h"
2222 #include "llvm/CodeGen/Passes.h"
2323 #include "llvm/ADT/DepthFirstIterator.h"
2424 #include "llvm/ADT/SmallPtrSet.h"
25 #include "llvm/Analysis/Dominators.h"
2625 #include "llvm/CodeGen/MachineDominators.h"
2726 #include "llvm/CodeGen/MachineFunctionPass.h"
2827 #include "llvm/CodeGen/MachineLoopInfo.h"
2928 #include "llvm/CodeGen/MachineModuleInfo.h"
3029 #include "llvm/CodeGen/MachineRegisterInfo.h"
3130 #include "llvm/IR/Constant.h"
31 #include "llvm/IR/Dominators.h"
3232 #include "llvm/IR/Function.h"
3333 #include "llvm/IR/Instructions.h"
3434 #include "llvm/IR/Type.h"
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #include "llvm/Analysis/Dominators.h"
16 #include "llvm/IR/Dominators.h"
1717 #include "llvm/ADT/DepthFirstIterator.h"
1818 #include "llvm/ADT/SmallPtrSet.h"
1919 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Analysis/DominatorInternals.h"
20 #include "llvm/IR/DominatorInternals.h"
2121 #include "llvm/IR/Instructions.h"
2222 #include "llvm/Support/CFG.h"
2323 #include "llvm/Support/CommandLine.h"
4444 //
4545 //===----------------------------------------------------------------------===//
4646
47 #include "llvm/Analysis/Verifier.h"
47 #include "llvm/IR/Verifier.h"
4848 #include "llvm/ADT/STLExtras.h"
4949 #include "llvm/ADT/SetVector.h"
5050 #include "llvm/ADT/SmallPtrSet.h"
5151 #include "llvm/ADT/SmallVector.h"
5252 #include "llvm/ADT/StringExtras.h"
53 #include "llvm/Analysis/Dominators.h"
5453 #include "llvm/DebugInfo.h"
5554 #include "llvm/IR/CallingConv.h"
5655 #include "llvm/IR/Constants.h"
5756 #include "llvm/IR/DataLayout.h"
5857 #include "llvm/IR/DerivedTypes.h"
58 #include "llvm/IR/Dominators.h"
5959 #include "llvm/IR/InlineAsm.h"
6060 #include "llvm/IR/IntrinsicInst.h"
6161 #include "llvm/IR/LLVMContext.h"
1414 #include "llvm/LTO/LTOCodeGenerator.h"
1515 #include "llvm/ADT/StringExtras.h"
1616 #include "llvm/Analysis/Passes.h"
17 #include "llvm/Analysis/Verifier.h"
1817 #include "llvm/Bitcode/ReaderWriter.h"
1918 #include "llvm/CodeGen/RuntimeLibcalls.h"
2019 #include "llvm/Config/config.h"
2423 #include "llvm/IR/LLVMContext.h"
2524 #include "llvm/IR/Mangler.h"
2625 #include "llvm/IR/Module.h"
26 #include "llvm/IR/Verifier.h"
2727 #include "llvm/InitializePasses.h"
2828 #include "llvm/LTO/LTOModule.h"
2929 #include "llvm/Linker.h"
1818 #include "NVPTXSplitBBatBar.h"
1919 #include "llvm/ADT/OwningPtr.h"
2020 #include "llvm/Analysis/Passes.h"
21 #include "llvm/Analysis/Verifier.h"
2221 #include "llvm/CodeGen/AsmPrinter.h"
2322 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
2423 #include "llvm/CodeGen/MachineModuleInfo.h"
2524 #include "llvm/CodeGen/Passes.h"
2625 #include "llvm/IR/DataLayout.h"
2726 #include "llvm/IR/IRPrintingPasses.h"
27 #include "llvm/IR/Verifier.h"
2828 #include "llvm/MC/MCAsmInfo.h"
2929 #include "llvm/MC/MCInstrInfo.h"
3030 #include "llvm/MC/MCStreamer.h"
2929 #include "PPCTargetMachine.h"
3030 #include "llvm/ADT/STLExtras.h"
3131 #include "llvm/ADT/Statistic.h"
32 #include "llvm/Analysis/Dominators.h"
3332 #include "llvm/Analysis/LoopInfo.h"
3433 #include "llvm/Analysis/ScalarEvolutionExpander.h"
3534 #include "llvm/IR/Constants.h"
3635 #include "llvm/IR/DerivedTypes.h"
36 #include "llvm/IR/Dominators.h"
3737 #include "llvm/IR/InlineAsm.h"
3838 #include "llvm/IR/Instructions.h"
3939 #include "llvm/IR/IntrinsicInst.h"
2020 #include "SIISelLowering.h"
2121 #include "SIInstrInfo.h"
2222 #include "llvm/Analysis/Passes.h"
23 #include "llvm/Analysis/Verifier.h"
2423 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
2524 #include "llvm/CodeGen/MachineModuleInfo.h"
2625 #include "llvm/CodeGen/Passes.h"
26 #include "llvm/IR/Verifier.h"
2727 #include "llvm/MC/MCAsmInfo.h"
2828 #include "llvm/PassManager.h"
2929 #include "llvm/Support/TargetRegistry.h"
1616 #include "llvm/ADT/SCCIterator.h"
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/DominatorInternals.h"
20 #include "llvm/Analysis/Dominators.h"
2119 #include "llvm/CodeGen/MachineDominators.h"
2220 #include "llvm/CodeGen/MachineFunction.h"
2321 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
2725 #include "llvm/CodeGen/MachineLoopInfo.h"
2826 #include "llvm/CodeGen/MachinePostDominators.h"
2927 #include "llvm/CodeGen/MachineRegisterInfo.h"
28 #include "llvm/IR/DominatorInternals.h"
29 #include "llvm/IR/Dominators.h"
3030 #include "llvm/Support/Debug.h"
3131 #include "llvm/Support/raw_ostream.h"
3232 #include "llvm/Target/TargetInstrInfo.h"
1313
1414 #include "AMDGPU.h"
1515 #include "llvm/ADT/DepthFirstIterator.h"
16 #include "llvm/Analysis/Dominators.h"
1716 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Dominators.h"
1818 #include "llvm/IR/Instructions.h"
1919 #include "llvm/IR/Module.h"
2020 #include "llvm/Pass.h"
1616 #define DEBUG_TYPE "loop-extract"
1717 #include "llvm/Transforms/IPO.h"
1818 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/LoopPass.h"
20 #include "llvm/IR/Dominators.h"
2121 #include "llvm/IR/Instructions.h"
2222 #include "llvm/IR/Module.h"
2323 #include "llvm/Pass.h"
1414 #define DEBUG_TYPE "partialinlining"
1515 #include "llvm/Transforms/IPO.h"
1616 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Analysis/Dominators.h"
17 #include "llvm/IR/Dominators.h"
1818 #include "llvm/IR/Instructions.h"
1919 #include "llvm/IR/Module.h"
2020 #include "llvm/Pass.h"
1616 #include "llvm-c/Transforms/PassManagerBuilder.h"
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/Verifier.h"
19 #include "llvm/IR/Verifier.h"
2020 #include "llvm/PassManager.h"
2121 #include "llvm/Support/CommandLine.h"
2222 #include "llvm/Support/ManagedStatic.h"
3131 #include "DependencyAnalysis.h"
3232 #include "ProvenanceAnalysis.h"
3333 #include "llvm/ADT/Statistic.h"
34 #include "llvm/Analysis/Dominators.h"
34 #include "llvm/IR/Dominators.h"
3535 #include "llvm/IR/InlineAsm.h"
3636 #include "llvm/IR/Operator.h"
3737 #include "llvm/Support/Debug.h"
1818 #include "llvm/ADT/SmallSet.h"
1919 #include "llvm/ADT/Statistic.h"
2020 #include "llvm/ADT/ValueMap.h"
21 #include "llvm/Analysis/DominatorInternals.h"
22 #include "llvm/Analysis/Dominators.h"
2321 #include "llvm/Analysis/InstructionSimplify.h"
2422 #include "llvm/IR/Constants.h"
2523 #include "llvm/IR/DataLayout.h"
2624 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/DominatorInternals.h"
26 #include "llvm/IR/Dominators.h"
2727 #include "llvm/IR/Function.h"
2828 #include "llvm/IR/IRBuilder.h"
2929 #include "llvm/IR/InlineAsm.h"
2121 #include "llvm/ADT/Statistic.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
2323 #include "llvm/Analysis/CaptureTracking.h"
24 #include "llvm/Analysis/Dominators.h"
2524 #include "llvm/Analysis/MemoryBuiltins.h"
2625 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2726 #include "llvm/Analysis/ValueTracking.h"
2827 #include "llvm/IR/Constants.h"
2928 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/Dominators.h"
3030 #include "llvm/IR/Function.h"
3131 #include "llvm/IR/GlobalVariable.h"
3232 #include "llvm/IR/Instructions.h"
1616 #include "llvm/ADT/Hashing.h"
1717 #include "llvm/ADT/ScopedHashTable.h"
1818 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/InstructionSimplify.h"
2120 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/Instructions.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Support/Debug.h"
2525 #include "llvm/Analysis/AliasAnalysis.h"
2626 #include "llvm/Analysis/CFG.h"
2727 #include "llvm/Analysis/ConstantFolding.h"
28 #include "llvm/Analysis/Dominators.h"
2928 #include "llvm/Analysis/InstructionSimplify.h"
3029 #include "llvm/Analysis/Loads.h"
3130 #include "llvm/Analysis/MemoryBuiltins.h"
3332 #include "llvm/Analysis/PHITransAddr.h"
3433 #include "llvm/Analysis/ValueTracking.h"
3534 #include "llvm/IR/DataLayout.h"
35 #include "llvm/IR/Dominators.h"
3636 #include "llvm/IR/GlobalVariable.h"
3737 #include "llvm/IR/IRBuilder.h"
3838 #include "llvm/IR/IntrinsicInst.h"
2828 #include "llvm/ADT/DenseMap.h"
2929 #include "llvm/ADT/SmallVector.h"
3030 #include "llvm/ADT/Statistic.h"
31 #include "llvm/Analysis/Dominators.h"
3231 #include "llvm/Analysis/LoopInfo.h"
3332 #include "llvm/Analysis/LoopPass.h"
3433 #include "llvm/Analysis/ScalarEvolutionExpander.h"
3534 #include "llvm/IR/BasicBlock.h"
3635 #include "llvm/IR/Constants.h"
3736 #include "llvm/IR/DataLayout.h"
37 #include "llvm/IR/Dominators.h"
3838 #include "llvm/IR/Instructions.h"
3939 #include "llvm/IR/IntrinsicInst.h"
4040 #include "llvm/IR/LLVMContext.h"
3535 #include "llvm/Analysis/AliasAnalysis.h"
3636 #include "llvm/Analysis/AliasSetTracker.h"
3737 #include "llvm/Analysis/ConstantFolding.h"
38 #include "llvm/Analysis/Dominators.h"
3938 #include "llvm/Analysis/LoopInfo.h"
4039 #include "llvm/Analysis/LoopPass.h"
4140 #include "llvm/Analysis/ValueTracking.h"
4241 #include "llvm/IR/Constants.h"
4342 #include "llvm/IR/DataLayout.h"
4443 #include "llvm/IR/DerivedTypes.h"
44 #include "llvm/IR/Dominators.h"
4545 #include "llvm/IR/Instructions.h"
4646 #include "llvm/IR/IntrinsicInst.h"
4747 #include "llvm/IR/LLVMContext.h"
1717 #include "llvm/Transforms/Scalar.h"
1818 #include "llvm/ADT/SmallVector.h"
1919 #include "llvm/ADT/Statistic.h"
20 #include "llvm/Analysis/Dominators.h"
2120 #include "llvm/Analysis/LoopPass.h"
2221 #include "llvm/Analysis/ScalarEvolution.h"
22 #include "llvm/IR/Dominators.h"
2323 using namespace llvm;
2424
2525 STATISTIC(NumDeleted, "Number of loops deleted");
4444 #include "llvm/Transforms/Scalar.h"
4545 #include "llvm/ADT/Statistic.h"
4646 #include "llvm/Analysis/AliasAnalysis.h"
47 #include "llvm/Analysis/Dominators.h"
4847 #include "llvm/Analysis/LoopPass.h"
4948 #include "llvm/Analysis/ScalarEvolutionExpander.h"
5049 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
5150 #include "llvm/Analysis/TargetTransformInfo.h"
5251 #include "llvm/Analysis/ValueTracking.h"
5352 #include "llvm/IR/DataLayout.h"
53 #include "llvm/IR/Dominators.h"
5454 #include "llvm/IR/IRBuilder.h"
5555 #include "llvm/IR/IntrinsicInst.h"
5656 #include "llvm/IR/Module.h"
1414 #include "llvm/Transforms/Scalar.h"
1515 #include "llvm/ADT/STLExtras.h"
1616 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/Analysis/InstructionSimplify.h"
1918 #include "llvm/Analysis/LoopInfo.h"
2019 #include "llvm/Analysis/LoopPass.h"
2120 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/Instructions.h"
2323 #include "llvm/Support/Debug.h"
2424 #include "llvm/Target/TargetLibraryInfo.h"
1717 #include "llvm/ADT/Statistic.h"
1818 #include "llvm/Analysis/AliasAnalysis.h"
1919 #include "llvm/Analysis/AliasSetTracker.h"
20 #include "llvm/Analysis/Dominators.h"
2120 #include "llvm/Analysis/LoopPass.h"
2221 #include "llvm/Analysis/ScalarEvolution.h"
2322 #include "llvm/Analysis/ScalarEvolutionExpander.h"
2423 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
2524 #include "llvm/Analysis/ValueTracking.h"
2625 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/Dominators.h"
2727 #include "llvm/IR/IntrinsicInst.h"
2828 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/Support/Debug.h"
1414 #include "llvm/Transforms/Scalar.h"
1515 #include "llvm/ADT/Statistic.h"
1616 #include "llvm/Analysis/CodeMetrics.h"
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/Analysis/InstructionSimplify.h"
1918 #include "llvm/Analysis/LoopPass.h"
2019 #include "llvm/Analysis/ScalarEvolution.h"
2120 #include "llvm/Analysis/TargetTransformInfo.h"
2221 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/IR/Dominators.h"
2323 #include "llvm/IR/Function.h"
2424 #include "llvm/IR/IntrinsicInst.h"
2525 #include "llvm/Support/CFG.h"
5858 #include "llvm/ADT/STLExtras.h"
5959 #include "llvm/ADT/SetVector.h"
6060 #include "llvm/ADT/SmallBitVector.h"
61 #include "llvm/Analysis/Dominators.h"
6261 #include "llvm/Analysis/IVUsers.h"
6362 #include "llvm/Analysis/LoopPass.h"
6463 #include "llvm/Analysis/ScalarEvolutionExpander.h"
6564 #include "llvm/Analysis/TargetTransformInfo.h"
6665 #include "llvm/IR/Constants.h"
6766 #include "llvm/IR/DerivedTypes.h"
67 #include "llvm/IR/Dominators.h"
6868 #include "llvm/IR/Instructions.h"
6969 #include "llvm/IR/IntrinsicInst.h"
7070 #include "llvm/Support/CommandLine.h"
1414 #define DEBUG_TYPE "loop-unroll"
1515 #include "llvm/Transforms/Scalar.h"
1616 #include "llvm/Analysis/CodeMetrics.h"
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/Analysis/LoopPass.h"
1918 #include "llvm/Analysis/ScalarEvolution.h"
2019 #include "llvm/Analysis/TargetTransformInfo.h"
2120 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/IntrinsicInst.h"
2323 #include "llvm/Support/CommandLine.h"
2424 #include "llvm/Support/Debug.h"
3131 #include "llvm/ADT/SmallPtrSet.h"
3232 #include "llvm/ADT/Statistic.h"
3333 #include "llvm/Analysis/CodeMetrics.h"
34 #include "llvm/Analysis/Dominators.h"
3534 #include "llvm/Analysis/InstructionSimplify.h"
3635 #include "llvm/Analysis/LoopInfo.h"
3736 #include "llvm/Analysis/LoopPass.h"
3938 #include "llvm/Analysis/TargetTransformInfo.h"
4039 #include "llvm/IR/Constants.h"
4140 #include "llvm/IR/DerivedTypes.h"
41 #include "llvm/IR/Dominators.h"
4242 #include "llvm/IR/Function.h"
4343 #include "llvm/IR/Instructions.h"
4444 #include "llvm/Support/CommandLine.h"
1616 #include "llvm/ADT/SmallVector.h"
1717 #include "llvm/ADT/Statistic.h"
1818 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2120 #include "llvm/Analysis/ValueTracking.h"
2221 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/Dominators.h"
2323 #include "llvm/IR/GlobalVariable.h"
2424 #include "llvm/IR/IRBuilder.h"
2525 #include "llvm/IR/Instructions.h"
2828 #include "llvm/ADT/SetVector.h"
2929 #include "llvm/ADT/SmallVector.h"
3030 #include "llvm/ADT/Statistic.h"
31 #include "llvm/Analysis/Dominators.h"
3231 #include "llvm/Analysis/Loads.h"
3332 #include "llvm/Analysis/PtrUseVisitor.h"
3433 #include "llvm/Analysis/ValueTracking.h"
3736 #include "llvm/IR/Constants.h"
3837 #include "llvm/IR/DataLayout.h"
3938 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/Dominators.h"
4040 #include "llvm/IR/Function.h"
4141 #include "llvm/IR/IRBuilder.h"
4242 #include "llvm/IR/Instructions.h"
3030 #include "llvm/ADT/SmallSet.h"
3131 #include "llvm/ADT/StringMap.h"
3232 #include "llvm/ADT/StringRef.h"
33 #include "llvm/Analysis/Dominators.h"
3433 #include "llvm/Analysis/LoopInfo.h"
3534 #include "llvm/Analysis/PostDominators.h"
3635 #include "llvm/DebugInfo.h"
3736 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/Dominators.h"
3838 #include "llvm/IR/Function.h"
3939 #include "llvm/IR/Instructions.h"
4040 #include "llvm/IR/LLVMContext.h"
1616 #include "llvm-c/Initialization.h"
1717 #include "llvm-c/Transforms/Scalar.h"
1818 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/Verifier.h"
2019 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Verifier.h"
2121 #include "llvm/InitializePasses.h"
2222 #include "llvm/PassManager.h"
2323
2323 #include "llvm/ADT/SetVector.h"
2424 #include "llvm/ADT/SmallVector.h"
2525 #include "llvm/ADT/Statistic.h"
26 #include "llvm/Analysis/Dominators.h"
2726 #include "llvm/Analysis/Loads.h"
2827 #include "llvm/Analysis/ValueTracking.h"
2928 #include "llvm/DIBuilder.h"
3130 #include "llvm/IR/Constants.h"
3231 #include "llvm/IR/DataLayout.h"
3332 #include "llvm/IR/DerivedTypes.h"
33 #include "llvm/IR/Dominators.h"
3434 #include "llvm/IR/Function.h"
3535 #include "llvm/IR/GlobalVariable.h"
3636 #include "llvm/IR/IRBuilder.h"
1515 #include "llvm/Transforms/Scalar.h"
1616 #include "llvm/ADT/Statistic.h"
1717 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/Analysis/Dominators.h"
1918 #include "llvm/Analysis/LoopInfo.h"
2019 #include "llvm/Analysis/ValueTracking.h"
20 #include "llvm/IR/Dominators.h"
2121 #include "llvm/IR/IntrinsicInst.h"
2222 #include "llvm/Support/CFG.h"
2323 #include "llvm/Support/Debug.h"
1414 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
1515 #include "llvm/Analysis/AliasAnalysis.h"
1616 #include "llvm/Analysis/CFG.h"
17 #include "llvm/Analysis/Dominators.h"
1817 #include "llvm/Analysis/LoopInfo.h"
1918 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2019 #include "llvm/IR/Constant.h"
2120 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/Function.h"
2323 #include "llvm/IR/Instructions.h"
2424 #include "llvm/IR/IntrinsicInst.h"
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/ADT/Statistic.h"
2121 #include "llvm/Analysis/CFG.h"
22 #include "llvm/Analysis/Dominators.h"
2322 #include "llvm/Analysis/LoopInfo.h"
23 #include "llvm/IR/Dominators.h"
2424 #include "llvm/IR/Function.h"
2525 #include "llvm/IR/Instructions.h"
2626 #include "llvm/IR/Type.h"
1616 #include "llvm/ADT/STLExtras.h"
1717 #include "llvm/ADT/SetVector.h"
1818 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/LoopInfo.h"
2120 #include "llvm/Analysis/RegionInfo.h"
2221 #include "llvm/Analysis/RegionIterator.h"
23 #include "llvm/Analysis/Verifier.h"
2422 #include "llvm/IR/Constants.h"
2523 #include "llvm/IR/DerivedTypes.h"
24 #include "llvm/IR/Dominators.h"
2625 #include "llvm/IR/Instructions.h"
2726 #include "llvm/IR/Intrinsics.h"
2827 #include "llvm/IR/LLVMContext.h"
2928 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Verifier.h"
3030 #include "llvm/Pass.h"
3131 #include "llvm/Support/CommandLine.h"
3232 #include "llvm/Support/Debug.h"
3030 #include "llvm/Transforms/Scalar.h"
3131 #include "llvm/ADT/STLExtras.h"
3232 #include "llvm/ADT/Statistic.h"
33 #include "llvm/Analysis/Dominators.h"
3433 #include "llvm/Analysis/LoopPass.h"
3534 #include "llvm/Analysis/ScalarEvolution.h"
3635 #include "llvm/IR/Constants.h"
36 #include "llvm/IR/Dominators.h"
3737 #include "llvm/IR/Function.h"
3838 #include "llvm/IR/Instructions.h"
3939 #include "llvm/Pass.h"
1616 #include "llvm/ADT/STLExtras.h"
1717 #include "llvm/ADT/SmallPtrSet.h"
1818 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/Dominators.h"
2019 #include "llvm/Analysis/InstructionSimplify.h"
2120 #include "llvm/Analysis/MemoryBuiltins.h"
2221 #include "llvm/Analysis/ValueTracking.h"
2524 #include "llvm/IR/Constants.h"
2625 #include "llvm/IR/DataLayout.h"
2726 #include "llvm/IR/DerivedTypes.h"
27 #include "llvm/IR/Dominators.h"
2828 #include "llvm/IR/GlobalAlias.h"
2929 #include "llvm/IR/GlobalVariable.h"
3030 #include "llvm/IR/IRBuilder.h"
4444 #include "llvm/ADT/Statistic.h"
4545 #include "llvm/Analysis/AliasAnalysis.h"
4646 #include "llvm/Analysis/DependenceAnalysis.h"
47 #include "llvm/Analysis/Dominators.h"
4847