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