1 //===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the post-dominator construction algorithms.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/PostDominators.h"
15 #include "llvm/Instructions.h"
16 #include "llvm/Support/CFG.h"
17 #include "llvm/ADT/DepthFirstIterator.h"
18 #include "llvm/ADT/SetOperations.h"
19 #include "PostDominatorCalculation.h"
22 //===----------------------------------------------------------------------===//
23 // PostDominatorTree Implementation
24 //===----------------------------------------------------------------------===//
26 char PostDominatorTree::ID = 0;
27 char PostDominanceFrontier::ID = 0;
28 static RegisterPass<PostDominatorTree>
29 F("postdomtree", "Post-Dominator Tree Construction", true);
31 //===----------------------------------------------------------------------===//
32 // PostDominanceFrontier Implementation
33 //===----------------------------------------------------------------------===//
35 static RegisterPass<PostDominanceFrontier>
36 H("postdomfrontier", "Post-Dominance Frontier Construction", true);
38 const DominanceFrontier::DomSetType &
39 PostDominanceFrontier::calculate(const PostDominatorTree &DT,
40 const DomTreeNode *Node) {
41 // Loop over CFG successors to calculate DFlocal[Node]
42 BasicBlock *BB = Node->getBlock();
43 DomSetType &S = Frontiers[BB]; // The new set to fill in...
44 if (getRoots().empty()) return S;
47 for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
49 // Does Node immediately dominate this predecessor?
50 DomTreeNode *SINode = DT[*SI];
51 if (SINode && SINode->getIDom() != Node)
55 // At this point, S is DFlocal. Now we union in DFup's of our children...
56 // Loop through and visit the nodes that Node immediately dominates (Node's
57 // children in the IDomTree)
59 for (DomTreeNode::const_iterator
60 NI = Node->begin(), NE = Node->end(); NI != NE; ++NI) {
61 DomTreeNode *IDominee = *NI;
62 const DomSetType &ChildDF = calculate(DT, IDominee);
64 DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end();
65 for (; CDFI != CDFE; ++CDFI) {
66 if (!DT.properlyDominates(Node, DT[*CDFI]))
74 // Ensure that this .cpp file gets linked when PostDominators.h is used.
75 DEFINING_FILE_FOR(PostDominanceFrontier)