LLVM  4.0.0
LazyValueInfo.h
Go to the documentation of this file.
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/IR/PassManager.h"
19 #include "llvm/Pass.h"
20 
21 namespace llvm {
22  class AssumptionCache;
23  class Constant;
24  class ConstantRange;
25  class DataLayout;
26  class DominatorTree;
27  class Instruction;
28  class TargetLibraryInfo;
29  class Value;
30 
31 /// This pass computes, caches, and vends lazy value constraint information.
34  AssumptionCache *AC = nullptr;
35  class TargetLibraryInfo *TLI = nullptr;
36  DominatorTree *DT = nullptr;
37  void *PImpl = nullptr;
38  LazyValueInfo(const LazyValueInfo&) = delete;
39  void operator=(const LazyValueInfo&) = delete;
40 public:
44  DominatorTree *DT_)
45  : AC(AC_), TLI(TLI_), DT(DT_) {}
47  : AC(Arg.AC), TLI(Arg.TLI), DT(Arg.DT), PImpl(Arg.PImpl) {
48  Arg.PImpl = nullptr;
49  }
51  releaseMemory();
52  AC = Arg.AC;
53  TLI = Arg.TLI;
54  DT = Arg.DT;
55  PImpl = Arg.PImpl;
56  Arg.PImpl = nullptr;
57  return *this;
58  }
59 
60  /// This is used to return true/false/dunno results.
61  enum Tristate {
62  Unknown = -1, False = 0, True = 1
63  };
64 
65  // Public query interface.
66 
67  /// Determine whether the specified value comparison with a constant is known
68  /// to be true or false on the specified CFG edge.
69  /// Pred is a CmpInst predicate.
70  Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
71  BasicBlock *FromBB, BasicBlock *ToBB,
72  Instruction *CxtI = nullptr);
73 
74  /// Determine whether the specified value comparison with a constant is known
75  /// to be true or false at the specified instruction
76  /// (from an assume intrinsic). Pred is a CmpInst predicate.
77  Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
78  Instruction *CxtI);
79 
80  /// Determine whether the specified value is known to be a
81  /// constant at the end of the specified block. Return null if not.
82  Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
83 
84  /// Return the ConstantRange constraint that is known to hold for the
85  /// specified value at the end of the specified block. This may only be called
86  /// on integer-typed Values.
87  ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
88 
89  /// Determine whether the specified value is known to be a
90  /// constant on the specified edge. Return null if not.
92  Instruction *CxtI = nullptr);
93 
94  /// Inform the analysis cache that we have threaded an edge from
95  /// PredBB to OldSucc to be from PredBB to NewSucc instead.
96  void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
97 
98  /// Inform the analysis cache that we have erased a block.
99  void eraseBlock(BasicBlock *BB);
100 
101  // For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
102  void releaseMemory();
103 };
104 
105 /// \brief Analysis to compute lazy value information.
106 class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
107 public:
110 
111 private:
112  static AnalysisKey Key;
114 };
115 
116 /// Wrapper around LazyValueInfo.
119  void operator=(const LazyValueInfoWrapperPass&) = delete;
120 public:
121  static char ID;
124  }
126  assert(!Info.PImpl && "releaseMemory not called");
127  }
128 
130 
131  void getAnalysisUsage(AnalysisUsage &AU) const override;
132  void releaseMemory() override;
133  bool runOnFunction(Function &F) override;
134 private:
135  LazyValueInfo Info;
136 };
137 
138 } // end namespace llvm
139 
140 #endif
141 
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Return the ConstantRange constraint that is known to hold for the specified value at the end of the s...
Wrapper around LazyValueInfo.
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
A cache of .assume calls within a function.
Constant * getConstant(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant at the end of the specified block...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Result run(Function &F, FunctionAnalysisManager &FAM)
#define F(x, y, z)
Definition: MD5.cpp:51
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
This is an important base class in LLVM.
Definition: Constant.h:42
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:328
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:61
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C, Instruction *CxtI)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Provides information about what library functions are available for the current target.
This class represents a range of values.
Definition: ConstantRange.h:45
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
LazyValueInfo(AssumptionCache *AC_, TargetLibraryInfo *TLI_, DominatorTree *DT_)
Definition: LazyValueInfo.h:43
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc)
Inform the analysis cache that we have threaded an edge from PredBB to OldSucc to be from PredBB to N...
LazyValueInfo & operator=(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:50
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:32
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:46
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:64
Analysis to compute lazy value information.