CFG.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===-- Analysis/CFG.h - BasicBlock Analyses --------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This family of functions performs analyses on basic blocks, and instructions
  11. // contained within basic blocks.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_ANALYSIS_CFG_H
  15. #define LLVM_ANALYSIS_CFG_H
  16. #include "llvm/IR/BasicBlock.h"
  17. #include "llvm/IR/CFG.h"
  18. namespace llvm {
  19. class BasicBlock;
  20. class DominatorTree;
  21. class Function;
  22. class Instruction;
  23. class LoopInfo;
  24. class TerminatorInst;
  25. /// Analyze the specified function to find all of the loop backedges in the
  26. /// function and return them. This is a relatively cheap (compared to
  27. /// computing dominators and loop info) analysis.
  28. ///
  29. /// The output is added to Result, as pairs of <from,to> edge info.
  30. void FindFunctionBackedges(
  31. const Function &F,
  32. SmallVectorImpl<std::pair<const BasicBlock *, const BasicBlock *> > &
  33. Result);
  34. /// Search for the specified successor of basic block BB and return its position
  35. /// in the terminator instruction's list of successors. It is an error to call
  36. /// this with a block that is not a successor.
  37. unsigned GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ);
  38. /// Return true if the specified edge is a critical edge. Critical edges are
  39. /// edges from a block with multiple successors to a block with multiple
  40. /// predecessors.
  41. ///
  42. bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
  43. bool AllowIdenticalEdges = false);
  44. /// \brief Determine whether instruction 'To' is reachable from 'From',
  45. /// returning true if uncertain.
  46. ///
  47. /// Determine whether there is a path from From to To within a single function.
  48. /// Returns false only if we can prove that once 'From' has been executed then
  49. /// 'To' can not be executed. Conservatively returns true.
  50. ///
  51. /// This function is linear with respect to the number of blocks in the CFG,
  52. /// walking down successors from From to reach To, with a fixed threshold.
  53. /// Using DT or LI allows us to answer more quickly. LI reduces the cost of
  54. /// an entire loop of any number of blocsk to be the same as the cost of a
  55. /// single block. DT reduces the cost by allowing the search to terminate when
  56. /// we find a block that dominates the block containing 'To'. DT is most useful
  57. /// on branchy code but not loops, and LI is most useful on code with loops but
  58. /// does not help on branchy code outside loops.
  59. bool isPotentiallyReachable(const Instruction *From, const Instruction *To,
  60. const DominatorTree *DT = nullptr,
  61. const LoopInfo *LI = nullptr);
  62. /// \brief Determine whether block 'To' is reachable from 'From', returning
  63. /// true if uncertain.
  64. ///
  65. /// Determine whether there is a path from From to To within a single function.
  66. /// Returns false only if we can prove that once 'From' has been reached then
  67. /// 'To' can not be executed. Conservatively returns true.
  68. bool isPotentiallyReachable(const BasicBlock *From, const BasicBlock *To,
  69. const DominatorTree *DT = nullptr,
  70. const LoopInfo *LI = nullptr);
  71. /// \brief Determine whether there is at least one path from a block in
  72. /// 'Worklist' to 'StopBB', returning true if uncertain.
  73. ///
  74. /// Determine whether there is a path from at least one block in Worklist to
  75. /// StopBB within a single function. Returns false only if we can prove that
  76. /// once any block in 'Worklist' has been reached then 'StopBB' can not be
  77. /// executed. Conservatively returns true.
  78. bool isPotentiallyReachableFromMany(SmallVectorImpl<BasicBlock *> &Worklist,
  79. BasicBlock *StopBB,
  80. const DominatorTree *DT = nullptr,
  81. const LoopInfo *LI = nullptr);
  82. } // End llvm namespace
  83. #endif