DataLayout is mandatory, update the API to reflect it with references.
[oota-llvm.git] / include / llvm / Analysis / LazyValueInfo.h
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;
39   LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
40     initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
41   }
42   ~LazyValueInfo() { 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   
50   // Public query interface.
51   
52   /// Determine whether the specified value comparison with a constant is known
53   /// to be true or false on the specified CFG edge.
54   /// Pred is a CmpInst predicate.
55   Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
56                               BasicBlock *FromBB, BasicBlock *ToBB,
57                               Instruction *CxtI = nullptr);
58   
59   /// Determine whether the specified value comparison with a constant is known
60   /// to be true or false at the specified instruction
61   /// (from an assume intrinsic). Pred is a CmpInst predicate.
62   Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
63                           Instruction *CxtI);
64  
65   /// Determine whether the specified value is known to be a
66   /// constant at the end of the specified block.  Return null if not.
67   Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
68
69   /// Determine whether the specified value is known to be a
70   /// constant on the specified edge.  Return null if not.
71   Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
72                               Instruction *CxtI = nullptr);
73   
74   /// Inform the analysis cache that we have threaded an edge from
75   /// PredBB to OldSucc to be from PredBB to NewSucc instead.
76   void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
77   
78   /// Inform the analysis cache that we have erased a block.
79   void eraseBlock(BasicBlock *BB);
80   
81   // Implementation boilerplate.
82
83   void getAnalysisUsage(AnalysisUsage &AU) const override;
84   void releaseMemory() override;
85   bool runOnFunction(Function &F) override;
86 };
87
88 }  // end namespace llvm
89
90 #endif
91