LLVM API Documentation
00001 //===-- Analysis/CFG.h - BasicBlock Analyses --------------------*- C++ -*-===// 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 family of functions performs analyses on basic blocks, and instructions 00011 // contained within basic blocks. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_ANALYSIS_CFG_H 00016 #define LLVM_ANALYSIS_CFG_H 00017 00018 #include "llvm/IR/BasicBlock.h" 00019 #include "llvm/IR/CFG.h" 00020 00021 namespace llvm { 00022 00023 class BasicBlock; 00024 class DominatorTree; 00025 class Function; 00026 class Instruction; 00027 class LoopInfo; 00028 class TerminatorInst; 00029 00030 /// Analyze the specified function to find all of the loop backedges in the 00031 /// function and return them. This is a relatively cheap (compared to 00032 /// computing dominators and loop info) analysis. 00033 /// 00034 /// The output is added to Result, as pairs of <from,to> edge info. 00035 void FindFunctionBackedges( 00036 const Function &F, 00037 SmallVectorImpl<std::pair<const BasicBlock *, const BasicBlock *> > & 00038 Result); 00039 00040 /// Search for the specified successor of basic block BB and return its position 00041 /// in the terminator instruction's list of successors. It is an error to call 00042 /// this with a block that is not a successor. 00043 unsigned GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ); 00044 00045 /// Return true if the specified edge is a critical edge. Critical edges are 00046 /// edges from a block with multiple successors to a block with multiple 00047 /// predecessors. 00048 /// 00049 bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum, 00050 bool AllowIdenticalEdges = false); 00051 00052 /// \brief Determine whether instruction 'To' is reachable from 'From', 00053 /// returning true if uncertain. 00054 /// 00055 /// Determine whether there is a path from From to To within a single function. 00056 /// Returns false only if we can prove that once 'From' has been executed then 00057 /// 'To' can not be executed. Conservatively returns true. 00058 /// 00059 /// This function is linear with respect to the number of blocks in the CFG, 00060 /// walking down successors from From to reach To, with a fixed threshold. 00061 /// Using DT or LI allows us to answer more quickly. LI reduces the cost of 00062 /// an entire loop of any number of blocsk to be the same as the cost of a 00063 /// single block. DT reduces the cost by allowing the search to terminate when 00064 /// we find a block that dominates the block containing 'To'. DT is most useful 00065 /// on branchy code but not loops, and LI is most useful on code with loops but 00066 /// does not help on branchy code outside loops. 00067 bool isPotentiallyReachable(const Instruction *From, const Instruction *To, 00068 const DominatorTree *DT = nullptr, 00069 const LoopInfo *LI = nullptr); 00070 00071 /// \brief Determine whether block 'To' is reachable from 'From', returning 00072 /// true if uncertain. 00073 /// 00074 /// Determine whether there is a path from From to To within a single function. 00075 /// Returns false only if we can prove that once 'From' has been reached then 00076 /// 'To' can not be executed. Conservatively returns true. 00077 bool isPotentiallyReachable(const BasicBlock *From, const BasicBlock *To, 00078 const DominatorTree *DT = nullptr, 00079 const LoopInfo *LI = nullptr); 00080 00081 } // End llvm namespace 00082 00083 #endif