13#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H 
   14#define LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H 
   18#include "llvm/ADT/DepthFirstIterator.h" 
   19#include "llvm/ADT/GraphTraits.h" 
   20#include "llvm/ADT/iterator.h" 
   21#include "llvm/Support/GenericIteratedDominanceFrontier.h" 
   22#include "llvm/Support/GenericDomTree.h" 
   23#include "llvm/Support/GenericDomTreeConstruction.h" 
   24#include "llvm/Support/raw_ostream.h" 
   41template <
bool IsPostDom>
 
   43  virtual void anchor();
 
   67    return DT.getRootNode();
 
 
   77    if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
 
   80    if (DT.compare(
Other.getBase()))
 
 
   95    llvm::errs() << 
"Immediate " << (IsPostDom ? 
"post " : 
"")
 
   96                 << 
"dominance tree (Node#,IDom#):\n";
 
   98        E = cfg->end(); I != E; ++I) {
 
  101             "LLVM's Dominator tree builder uses nullpointers to signify the " 
  105      if (IDom && IDom->getBlock())
 
  106        llvm::errs() << 
"(" << (*I)->getBlockID()
 
  108                     << IDom->getBlock()->getBlockID()
 
  111        bool IsEntryBlock = *I == &(*I)->getParent()->getEntry();
 
  112        bool IsExitBlock = *I == &(*I)->getParent()->getExit();
 
  114        bool IsDomTreeRoot = !IDom && !IsPostDom && IsEntryBlock;
 
  115        bool IsPostDomTreeRoot =
 
  116            IDom && !IDom->getBlock() && IsPostDom && IsExitBlock;
 
  118        assert((IsDomTreeRoot || IsPostDomTreeRoot) &&
 
  119               "If the immediate dominator node is nullptr, the CFG block " 
  120               "should be the exit point (since it's the root of the dominator " 
  121               "tree), or if the CFG block it refers to is a nullpointer, it " 
  122               "must be the entry block (since it's the root of the post " 
  126        (void)IsPostDomTreeRoot;
 
  128        llvm::errs() << 
"(" << (*I)->getBlockID()
 
  129                     << 
"," << (*I)->getBlockID() << 
")\n";
 
 
  137    return DT.dominates(A, B);
 
 
  144    return DT.properlyDominates(A, B);
 
 
  150    return DT.findNearestCommonDominator(A, B);
 
 
  155    return DT.findNearestCommonDominator(A, B);
 
 
  161    DT.changeImmediateDominator(N, NewIDom);
 
 
  166    return DT.isReachableFromEntry(A);
 
 
  173  virtual void print(raw_ostream &OS, 
const llvm::Module* M= 
nullptr)
 const {
 
 
 
  185template<> 
void CFGDominatorTreeImpl<true>::anchor();
 
  186template<> 
void CFGDominatorTreeImpl<false>::anchor();
 
  194template <
bool IsPostDom>
 
  195struct ChildrenGetterTy<
clang::CFGBlock, IsPostDom> {
 
  196  using NodeRef = 
typename GraphTraits<clang::CFGBlock *>::NodeRef;
 
  200    using OrderedNodeTy =
 
  201        typename IDFCalculatorBase<clang::CFGBlock, IsPostDom>::OrderedNodeTy;
 
  203    auto Children = children<OrderedNodeTy>(N);
 
  205    llvm::erase(Ret, 
nullptr);
 
 
 
 
  216  using IDFCalculator = llvm::IDFCalculatorBase<
CFGBlock, 
true>;
 
  221  IDFCalculator IDFCalc;
 
  223  llvm::DenseMap<CFGBlock *, CFGBlockVector> ControlDepenencyMap;
 
  227    : PostDomTree(cfg), IDFCalc(PostDomTree.getBase()) {}
 
 
  233    auto It = ControlDepenencyMap.find(A);
 
  234    if (It == ControlDepenencyMap.end()) {
 
  235      CFGBlockSet DefiningBlock = {A};
 
  236      IDFCalc.setDefiningBlocks(DefiningBlock);
 
  238      CFGBlockVector ControlDependencies;
 
  239      IDFCalc.calculate(ControlDependencies);
 
  241      It = ControlDepenencyMap.insert({A, ControlDependencies}).first;
 
  244    assert(It != ControlDepenencyMap.end());
 
 
  255    CFG *cfg = PostDomTree.getCFG();
 
  256    llvm::errs() << 
"Control dependencies (Node#,Dependency#):\n";
 
  260             "LLVM's Dominator tree builder uses nullpointers to signify the " 
  264        llvm::errs() << 
"(" << BB->getBlockID()
 
  266                     << isControlDependency->getBlockID()
 
 
 
  280template <> 
struct GraphTraits<
clang::DomTreeNode *> {
 
  289      llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>>;
 
 
  300template <> 
struct GraphTraits<
clang::CFGDomTree *>
 
  301    : 
public GraphTraits<clang::DomTreeNode *> {
 
 
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Represents a single basic block in a source-level CFG.
Dominator tree builder for Clang's CFG based on llvm::DominatorTreeBase.
virtual void releaseMemory()
Releases the memory held by the dominator tree.
CFGDominatorTreeImpl(CFG *cfg)
virtual void print(raw_ostream &OS, const llvm::Module *M=nullptr) const
Converts the dominator tree to human readable form.
CFGBlock * findNearestCommonDominator(CFGBlock *A, CFGBlock *B)
bool compare(CFGDominatorTreeImpl &Other) const
Compares two dominator trees.
CFGBlock * getRoot() const
void dump()
Dumps immediate dominators for each block.
void buildDominatorTree(CFG *cfg)
Builds the dominator tree for a given CFG.
~CFGDominatorTreeImpl() override=default
llvm::DominatorTreeBase< CFGBlock, IsPostDom > DominatorTreeBase
const CFGBlock * findNearestCommonDominator(const CFGBlock *A, const CFGBlock *B)
bool properlyDominates(const CFGBlock *A, const CFGBlock *B) const
Tests whether A properly dominates B.
DomTreeNode * getRootNode()
void changeImmediateDominator(CFGBlock *N, CFGBlock *NewIDom)
Update the dominator tree information when a node's immediate dominator changes.
DominatorTreeBase & getBase()
CFGDominatorTreeImpl()=default
bool dominates(const CFGBlock *A, const CFGBlock *B) const
Tests whether A dominates B.
bool isReachableFromEntry(const CFGBlock *A)
Tests whether A is reachable from the entry block.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
CFGBlockListTy::const_iterator const_iterator
ControlDependencyCalculator(CFG *cfg)
LLVM_DUMP_METHOD void dump()
const CFGBlockVector & getControlDependencies(CFGBlock *A)
const CFGPostDomTree & getCFGPostDomTree() const
bool isControlDependent(CFGBlock *A, CFGBlock *B)
Whether A is control dependent on B.
ManagedAnalysis()=default
The JSON file list parser is used to communicate input to InstallAPI.
CFGDominatorTreeImpl< true > CFGPostDomTree
CFGDominatorTreeImpl< false > CFGDomTree
llvm::DomTreeNodeBase< CFGBlock > DomTreeNode
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
static nodes_iterator nodes_end(clang::CFGDomTree *N)
static nodes_iterator nodes_begin(clang::CFGDomTree *N)
static NodeRef getEntryNode(clang::CFGDomTree *DT)
static NodeRef getEntryNode(NodeRef N)
::clang::DomTreeNode::const_iterator ChildIteratorType
::clang::DomTreeNode * NodeRef
static ChildIteratorType child_end(NodeRef N)
static nodes_iterator nodes_begin(::clang::DomTreeNode *N)
static ChildIteratorType child_begin(NodeRef N)
llvm::pointer_iterator< df_iterator<::clang::DomTreeNode * > > nodes_iterator
static nodes_iterator nodes_end(::clang::DomTreeNode *N)
ChildrenTy get(const NodeRef &N)
typename GraphTraits< clang::CFGBlock * >::NodeRef NodeRef
SmallVector< NodeRef, 8 > ChildrenTy