LLVM  8.0.0svn
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  const DataLayout *DL = nullptr;
36  class TargetLibraryInfo *TLI = nullptr;
37  DominatorTree *DT = nullptr;
38  void *PImpl = nullptr;
39  LazyValueInfo(const LazyValueInfo&) = delete;
40  void operator=(const LazyValueInfo&) = delete;
41 public:
45  DominatorTree *DT_)
46  : AC(AC_), DL(DL_), TLI(TLI_), DT(DT_) {}
48  : AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), DT(Arg.DT), PImpl(Arg.PImpl) {
49  Arg.PImpl = nullptr;
50  }
52  releaseMemory();
53  AC = Arg.AC;
54  DL = Arg.DL;
55  TLI = Arg.TLI;
56  DT = Arg.DT;
57  PImpl = Arg.PImpl;
58  Arg.PImpl = nullptr;
59  return *this;
60  }
61 
62  /// This is used to return true/false/dunno results.
63  enum Tristate {
64  Unknown = -1, False = 0, True = 1
65  };
66 
67  // Public query interface.
68 
69  /// Determine whether the specified value comparison with a constant is known
70  /// to be true or false on the specified CFG edge.
71  /// Pred is a CmpInst predicate.
72  Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
73  BasicBlock *FromBB, BasicBlock *ToBB,
74  Instruction *CxtI = nullptr);
75 
76  /// Determine whether the specified value comparison with a constant is known
77  /// to be true or false at the specified instruction
78  /// (from an assume intrinsic). Pred is a CmpInst predicate.
79  Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
80  Instruction *CxtI);
81 
82  /// Determine whether the specified value is known to be a
83  /// constant at the end of the specified block. Return null if not.
84  Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
85 
86  /// Return the ConstantRange constraint that is known to hold for the
87  /// specified value at the end of the specified block. This may only be called
88  /// on integer-typed Values.
89  ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
90 
91  /// Determine whether the specified value is known to be a
92  /// constant on the specified edge. Return null if not.
94  Instruction *CxtI = nullptr);
95 
96  /// Return the ConstantRage constraint that is known to hold for the
97  /// specified value on the specified edge. This may be only be called
98  /// on integer-typed Values.
100  BasicBlock *ToBB,
101  Instruction *CxtI = nullptr);
102 
103  /// Inform the analysis cache that we have threaded an edge from
104  /// PredBB to OldSucc to be from PredBB to NewSucc instead.
105  void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
106 
107  /// Inform the analysis cache that we have erased a block.
108  void eraseBlock(BasicBlock *BB);
109 
110  /// Print the \LazyValueInfo Analysis.
111  /// We pass in the DTree that is required for identifying which basic blocks
112  /// we can solve/print for, in the LVIPrinter. The DT is optional
113  /// in LVI, so we need to pass it here as an argument.
114  void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
115 
116  /// Disables use of the DominatorTree within LVI.
117  void disableDT();
118 
119  /// Enables use of the DominatorTree within LVI. Does nothing if the class
120  /// instance was initialized without a DT pointer.
121  void enableDT();
122 
123  // For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
124  void releaseMemory();
125 
126  /// Handle invalidation events in the new pass manager.
127  bool invalidate(Function &F, const PreservedAnalyses &PA,
129 };
130 
131 /// Analysis to compute lazy value information.
132 class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
133 public:
135  Result run(Function &F, FunctionAnalysisManager &FAM);
136 
137 private:
138  static AnalysisKey Key;
140 };
141 
142 /// Wrapper around LazyValueInfo.
145  void operator=(const LazyValueInfoWrapperPass&) = delete;
146 public:
147  static char ID;
150  }
152  assert(!Info.PImpl && "releaseMemory not called");
153  }
154 
155  LazyValueInfo &getLVI();
156 
157  void getAnalysisUsage(AnalysisUsage &AU) const override;
158  void releaseMemory() override;
159  bool runOnFunction(Function &F) override;
160 private:
162 };
163 
164 } // end namespace llvm
165 
166 #endif
167 
uint64_t CallInst * C
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_, TargetLibraryInfo *TLI_, DominatorTree *DT_)
Definition: LazyValueInfo.h:44
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
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...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Wrapper around LazyValueInfo.
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
A cache of @llvm.assume calls within a function.
F(f)
friend class LazyValueInfoWrapperPass
Definition: LazyValueInfo.h:33
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...
Key
PAL metadata keys.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:145
Analysis containing CSE Info
Definition: CSEInfo.cpp:21
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
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:58
This is an important base class in LLVM.
Definition: Constant.h:42
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:383
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:63
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 ...
void enableDT()
Enables use of the DominatorTree within LVI.
Provides information about what library functions are available for the current target.
This class represents a range of values.
Definition: ConstantRange.h:47
amdgpu Simplify well known AMD library false Value Value * Arg
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:51
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:642
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:73
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:47
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A container for analyses that lazily runs them and caches their results.
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the Analysis.
ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Return the ConstantRage constraint that is known to hold for the specified value on the specified edg...
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:71
void disableDT()
Disables use of the DominatorTree within LVI.
Analysis to compute lazy value information.