LLVM API Documentation

PostDominators.cpp

Go to the documentation of this file.
00001 //===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the post-dominator construction algorithms.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #define DEBUG_TYPE "postdomtree"
00015 
00016 #include "llvm/Analysis/PostDominators.h"
00017 #include "llvm/Instructions.h"
00018 #include "llvm/Support/CFG.h"
00019 #include "llvm/Support/Debug.h"
00020 #include "llvm/ADT/DepthFirstIterator.h"
00021 #include "llvm/ADT/SetOperations.h"
00022 #include "llvm/Analysis/DominatorInternals.h"
00023 using namespace llvm;
00024 
00025 //===----------------------------------------------------------------------===//
00026 //  PostDominatorTree Implementation
00027 //===----------------------------------------------------------------------===//
00028 
00029 char PostDominatorTree::ID = 0;
00030 char PostDominanceFrontier::ID = 0;
00031 static RegisterPass<PostDominatorTree>
00032 F("postdomtree", "Post-Dominator Tree Construction", true, true);
00033 
00034 bool PostDominatorTree::runOnFunction(Function &F) {
00035   DT->recalculate(F);
00036   DEBUG(DT->dump());
00037   return false;
00038 }
00039 
00040 PostDominatorTree::~PostDominatorTree()
00041 {
00042   delete DT;
00043 }
00044 
00045 FunctionPass* llvm::createPostDomTree() {
00046   return new PostDominatorTree();
00047 }
00048 
00049 //===----------------------------------------------------------------------===//
00050 //  PostDominanceFrontier Implementation
00051 //===----------------------------------------------------------------------===//
00052 
00053 static RegisterPass<PostDominanceFrontier>
00054 H("postdomfrontier", "Post-Dominance Frontier Construction", true, true);
00055 
00056 const DominanceFrontier::DomSetType &
00057 PostDominanceFrontier::calculate(const PostDominatorTree &DT,
00058                                  const DomTreeNode *Node) {
00059   // Loop over CFG successors to calculate DFlocal[Node]
00060   BasicBlock *BB = Node->getBlock();
00061   DomSetType &S = Frontiers[BB];       // The new set to fill in...
00062   if (getRoots().empty()) return S;
00063 
00064   if (BB)
00065     for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
00066          SI != SE; ++SI) {
00067       // Does Node immediately dominate this predecessor?
00068       DomTreeNode *SINode = DT[*SI];
00069       if (SINode && SINode->getIDom() != Node)
00070         S.insert(*SI);
00071     }
00072 
00073   // At this point, S is DFlocal.  Now we union in DFup's of our children...
00074   // Loop through and visit the nodes that Node immediately dominates (Node's
00075   // children in the IDomTree)
00076   //
00077   for (DomTreeNode::const_iterator
00078          NI = Node->begin(), NE = Node->end(); NI != NE; ++NI) {
00079     DomTreeNode *IDominee = *NI;
00080     const DomSetType &ChildDF = calculate(DT, IDominee);
00081 
00082     DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end();
00083     for (; CDFI != CDFE; ++CDFI) {
00084       if (!DT.properlyDominates(Node, DT[*CDFI]))
00085         S.insert(*CDFI);
00086     }
00087   }
00088 
00089   return S;
00090 }
00091 
00092 FunctionPass* llvm::createPostDomFrontier() {
00093   return new PostDominanceFrontier();
00094 }



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.