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