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