llvm.org GIT mirror llvm / 46bb007
Fix PR1098 by correcting the postdominators analysis. Patch by Florian Brandner. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50628 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
4 changed file(s) with 30 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
232232 typedef GraphTraits GraphT;
233233
234234 unsigned N = 0;
235
236 // Add a node for the root. This node might be the actual root, if there is
237 // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
238 // which postdominates all real exits if there are multiple exit blocks.
239 typename GraphT::NodeType* Root = DT.Roots.size() == 1 ? DT.Roots[0]
240 : 0;
241235 bool MultipleRoots = (DT.Roots.size() > 1);
242
243236 if (MultipleRoots) {
244237 typename DominatorTreeBase::InfoRec &BBInfo =
245238 DT.Info[NULL];
256249 // in later stages of the algorithm.
257250 for (unsigned i = 0, e = DT.Roots.size(); i != e; ++i)
258251 N = DFSPass(DT, DT.Roots[i], N);
252
253 // it might be that some blocks did not get a DFS number (e.g., blocks of
254 // infinite loops). In these cases an artificial exit node is required.
255 MultipleRoots |= (DT.isPostDominator() && N != F.size());
259256
260257 for (unsigned i = N; i >= 2; --i) {
261258 typename GraphT::NodeType* W = DT.Vertex[i];
310307 if (WIDom != DT.Vertex[DT.Info[W].Semi])
311308 WIDom = DT.IDoms[WIDom];
312309 }
313
310
314311 if (DT.Roots.empty()) return;
315
312
316313 // Add a node for the root. This node might be the actual root, if there is
317314 // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
318 // which postdominates all real exits if there are multiple exit blocks.
315 // which postdominates all real exits if there are multiple exit blocks, or
316 // an infinite loop.
317 typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : 0;
318
319319 DT.DomTreeNodes[Root] = DT.RootNode =
320320 new DomTreeNodeBase(Root, 0);
321
321
322322 // Loop over all of the reachable blocks in the function...
323323 for (unsigned i = 2; i <= N; ++i) {
324324 typename GraphT::NodeType* W = DT.Vertex[i];
328328
329329 typename GraphT::NodeType* ImmDom = DT.getIDom(W);
330330
331 // skip all non root nodes that have no dominator - this occures with
332 // infinite loops.
333 if (!ImmDom && std::count(DT.Roots.begin(), DT.Roots.end(), W) == 0)
334 continue;
331 assert(ImmDom || DT.DomTreeNodes[NULL]);
335332
336333 // Get or calculate the node for the immediate dominator
337334 DomTreeNodeBase *IDomNode =
338335 DT.getNodeForBlock(ImmDom);
339
340 // skip all children that are dominated by a non root node that, by itself,
341 // has no dominator.
342 if (!IDomNode)
343 continue;
344336
345337 // Add a new tree node for this BasicBlock, and link it as a child of
346338 // IDomNode
604604 // immediate dominator.
605605 NodeT *IDom = getIDom(BB);
606606
607 // skip all non root nodes that have no dominator
608 if (!IDom && std::count(this->Roots.begin(), this->Roots.end(), BB) == 0)
609 return NULL;
610
607 assert(IDom || this->DomTreeNodes[NULL]);
611608 DomTreeNodeBase *IDomNode = getNodeForBlock(IDom);
612
613 // skip all nodes that are dominated by a non root node that, by itself,
614 // has no dominator.
615 if (!IDomNode)
616 return NULL;
617609
618610 // Add a new tree node for this BasicBlock, and link it as a child of
619611 // IDomNode
0 load_lib llvm.exp
1
2 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]
0 ; RUN: llvm-as < %s | opt -postdomtree -analyze | grep entry
1 ; PR932
2
3 define void @foo(i1 %x) {
4 entry:
5 br i1 %x, label %bb1, label %bb0
6 bb0: ; preds = %entry, bb0
7 br label %bb0
8 bb1: ; preds = %entry
9 br label %bb2
10 bb2: ; preds = %bb1
11 ret void
12 }
13