Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- PostDominators.cpp - Post-Dominator Calculation --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the post-dominator construction algorithms. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 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" |
Owen Anderson | 0ce522f | 2007-09-23 22:21:00 +0000 | [diff] [blame] | 19 | #include "PostDominatorCalculation.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // PostDominatorTree Implementation |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | char PostDominatorTree::ID = 0; |
| 27 | char PostDominanceFrontier::ID = 0; |
| 28 | static RegisterPass<PostDominatorTree> |
| 29 | F("postdomtree", "Post-Dominator Tree Construction", true); |
| 30 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
| 32 | // PostDominanceFrontier Implementation |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | |
| 35 | static RegisterPass<PostDominanceFrontier> |
| 36 | H("postdomfrontier", "Post-Dominance Frontier Construction", true); |
| 37 | |
| 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; |
| 45 | |
| 46 | if (BB) |
| 47 | for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB); |
| 48 | SI != SE; ++SI) { |
| 49 | // Does Node immediately dominate this predecessor? |
| 50 | DomTreeNode *SINode = DT[*SI]; |
| 51 | if (SINode && SINode->getIDom() != Node) |
| 52 | S.insert(*SI); |
| 53 | } |
| 54 | |
| 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) |
| 58 | // |
| 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); |
| 63 | |
| 64 | DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end(); |
| 65 | for (; CDFI != CDFE; ++CDFI) { |
| 66 | if (!DT.properlyDominates(Node, DT[*CDFI])) |
| 67 | S.insert(*CDFI); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return S; |
| 72 | } |
| 73 | |
| 74 | // Ensure that this .cpp file gets linked when PostDominators.h is used. |
| 75 | DEFINING_FILE_FOR(PostDominanceFrontier) |