LazyValueInfo.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //===- LazyValueInfo.h - Value constraint analysis --------------*- 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 file defines the interface for lazy computation of value constraint
  11. // information.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
  15. #define LLVM_ANALYSIS_LAZYVALUEINFO_H
  16. #include "llvm/Pass.h"
  17. namespace llvm {
  18. class AssumptionCache;
  19. class Constant;
  20. class DataLayout;
  21. class DominatorTree;
  22. class Instruction;
  23. class TargetLibraryInfo;
  24. class Value;
  25. /// This pass computes, caches, and vends lazy value constraint information.
  26. class LazyValueInfo : public FunctionPass {
  27. AssumptionCache *AC;
  28. class TargetLibraryInfo *TLI;
  29. DominatorTree *DT;
  30. void *PImpl;
  31. LazyValueInfo(const LazyValueInfo&) = delete;
  32. void operator=(const LazyValueInfo&) = delete;
  33. public:
  34. static char ID;
  35. LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
  36. initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
  37. }
  38. ~LazyValueInfo() override { assert(!PImpl && "releaseMemory not called"); }
  39. /// This is used to return true/false/dunno results.
  40. enum Tristate {
  41. Unknown = -1, False = 0, True = 1
  42. };
  43. // Public query interface.
  44. /// Determine whether the specified value comparison with a constant is known
  45. /// to be true or false on the specified CFG edge.
  46. /// Pred is a CmpInst predicate.
  47. Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
  48. BasicBlock *FromBB, BasicBlock *ToBB,
  49. Instruction *CxtI = nullptr);
  50. /// Determine whether the specified value comparison with a constant is known
  51. /// to be true or false at the specified instruction
  52. /// (from an assume intrinsic). Pred is a CmpInst predicate.
  53. Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
  54. Instruction *CxtI);
  55. /// Determine whether the specified value is known to be a
  56. /// constant at the end of the specified block. Return null if not.
  57. Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
  58. /// Determine whether the specified value is known to be a
  59. /// constant on the specified edge. Return null if not.
  60. Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
  61. Instruction *CxtI = nullptr);
  62. /// Inform the analysis cache that we have threaded an edge from
  63. /// PredBB to OldSucc to be from PredBB to NewSucc instead.
  64. void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
  65. /// Inform the analysis cache that we have erased a block.
  66. void eraseBlock(BasicBlock *BB);
  67. // Implementation boilerplate.
  68. void getAnalysisUsage(AnalysisUsage &AU) const override;
  69. void releaseMemory() override;
  70. bool runOnFunction(Function &F) override;
  71. };
  72. } // end namespace llvm
  73. #endif