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 Constant;
22   class TargetData;
23   class Value;
24 
25 /// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
26 /// information.
27 class LazyValueInfo : public FunctionPass {
28   class TargetData *TD;
29   void *PImpl;
30   LazyValueInfo(const LazyValueInfo&); // DO NOT IMPLEMENT.
31   void operator=(const LazyValueInfo&); // DO NOT IMPLEMENT.
32 public:
33   static char ID;
34   LazyValueInfo() : FunctionPass(ID), PImpl(0) {
35     initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
36   }
37   ~LazyValueInfo() { assert(PImpl == 0 && "releaseMemory not called"); }
38 
39   /// Tristate - This is used to return true/false/dunno results.
40   enum Tristate {
41     Unknown = -1, False = 0, True = 1
42   };
43 
44 
45   // Public query interface.
46 
47   /// getPredicateOnEdge - Determine whether the specified value comparison
48   /// with a constant is known to be true or false on the specified CFG edge.
49   /// Pred is a CmpInst predicate.
50   Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
51                               BasicBlock *FromBB, BasicBlock *ToBB);
52 
53 
54   /// getConstant - Determine whether the specified value is known to be a
55   /// constant at the end of the specified block.  Return null if not.
56   Constant *getConstant(Value *V, BasicBlock *BB);
57 
58   /// getConstantOnEdge - 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 
62   /// threadEdge - 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 
66   /// eraseBlock - Inform the analysis cache that we have erased a block.
67   void eraseBlock(BasicBlock *BB);
68 
69   // Implementation boilerplate.
70 
71   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
72     AU.setPreservesAll();
73   }
74   virtual void releaseMemory();
75   virtual bool runOnFunction(Function &F);
76 };
77 
78 }  // end namespace llvm
79 
80 #endif
81 
82