Skip to content

Commit 7af408e

Browse files
committed
[JumpThreading][NFC] Improved access to LazyValueInfoImpl.
1 parent 7ded71b commit 7af408e

File tree

2 files changed

+159
-158
lines changed

2 files changed

+159
-158
lines changed

llvm/include/llvm/Analysis/LazyValueInfo.h

Lines changed: 112 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -26,117 +26,120 @@ namespace llvm {
2626
class Instruction;
2727
class TargetLibraryInfo;
2828
class Value;
29-
30-
/// This pass computes, caches, and vends lazy value constraint information.
31-
class LazyValueInfo {
32-
friend class LazyValueInfoWrapperPass;
33-
AssumptionCache *AC = nullptr;
34-
const DataLayout *DL = nullptr;
35-
class TargetLibraryInfo *TLI = nullptr;
36-
void *PImpl = nullptr;
37-
LazyValueInfo(const LazyValueInfo&) = delete;
38-
void operator=(const LazyValueInfo&) = delete;
39-
public:
40-
~LazyValueInfo();
41-
LazyValueInfo() = default;
42-
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_,
43-
TargetLibraryInfo *TLI_)
44-
: AC(AC_), DL(DL_), TLI(TLI_) {}
45-
LazyValueInfo(LazyValueInfo &&Arg)
46-
: AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), PImpl(Arg.PImpl) {
47-
Arg.PImpl = nullptr;
48-
}
49-
LazyValueInfo &operator=(LazyValueInfo &&Arg) {
50-
releaseMemory();
51-
AC = Arg.AC;
52-
DL = Arg.DL;
53-
TLI = Arg.TLI;
54-
PImpl = Arg.PImpl;
55-
Arg.PImpl = nullptr;
56-
return *this;
57-
}
58-
59-
/// This is used to return true/false/dunno results.
60-
enum Tristate {
61-
Unknown = -1, False = 0, True = 1
29+
class LazyValueInfoImpl;
30+
/// This pass computes, caches, and vends lazy value constraint information.
31+
class LazyValueInfo {
32+
friend class LazyValueInfoWrapperPass;
33+
AssumptionCache *AC = nullptr;
34+
const DataLayout *DL = nullptr;
35+
class TargetLibraryInfo *TLI = nullptr;
36+
LazyValueInfoImpl *PImpl = nullptr;
37+
LazyValueInfo(const LazyValueInfo &) = delete;
38+
void operator=(const LazyValueInfo &) = delete;
39+
40+
LazyValueInfoImpl *getImpl();
41+
LazyValueInfoImpl &getOrCreateImpl(const Module *M);
42+
43+
public:
44+
~LazyValueInfo();
45+
LazyValueInfo() = default;
46+
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_,
47+
TargetLibraryInfo *TLI_)
48+
: AC(AC_), DL(DL_), TLI(TLI_) {}
49+
LazyValueInfo(LazyValueInfo &&Arg)
50+
: AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), PImpl(Arg.PImpl) {
51+
Arg.PImpl = nullptr;
52+
}
53+
LazyValueInfo &operator=(LazyValueInfo &&Arg) {
54+
releaseMemory();
55+
AC = Arg.AC;
56+
DL = Arg.DL;
57+
TLI = Arg.TLI;
58+
PImpl = Arg.PImpl;
59+
Arg.PImpl = nullptr;
60+
return *this;
61+
}
62+
63+
/// This is used to return true/false/dunno results.
64+
enum Tristate { Unknown = -1, False = 0, True = 1 };
65+
66+
// Public query interface.
67+
68+
/// Determine whether the specified value comparison with a constant is
69+
/// known to be true or false on the specified CFG edge. Pred is a CmpInst
70+
/// predicate.
71+
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
72+
BasicBlock *FromBB, BasicBlock *ToBB,
73+
Instruction *CxtI = nullptr);
74+
75+
/// Determine whether the specified value comparison with a constant is
76+
/// known to be true or false at the specified instruction. \p Pred is a
77+
/// CmpInst predicate. If \p UseBlockValue is true, the block value is also
78+
/// taken into account.
79+
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
80+
Instruction *CxtI, bool UseBlockValue);
81+
82+
/// Determine whether the specified value comparison is known to be true
83+
/// or false at the specified instruction. While this takes two Value's,
84+
/// it still requires that one of them is a constant.
85+
/// \p Pred is a CmpInst predicate.
86+
/// If \p UseBlockValue is true, the block value is also taken into account.
87+
Tristate getPredicateAt(unsigned Pred, Value *LHS, Value *RHS,
88+
Instruction *CxtI, bool UseBlockValue);
89+
90+
/// Determine whether the specified value is known to be a constant at the
91+
/// specified instruction. Return null if not.
92+
Constant *getConstant(Value *V, Instruction *CxtI);
93+
94+
/// Return the ConstantRange constraint that is known to hold for the
95+
/// specified value at the specified instruction. This may only be called
96+
/// on integer-typed Values.
97+
ConstantRange getConstantRange(Value *V, Instruction *CxtI,
98+
bool UndefAllowed = true);
99+
100+
/// Return the ConstantRange constraint that is known to hold for the value
101+
/// at a specific use-site.
102+
ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed = true);
103+
104+
/// Determine whether the specified value is known to be a
105+
/// constant on the specified edge. Return null if not.
106+
Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
107+
Instruction *CxtI = nullptr);
108+
109+
/// Return the ConstantRage constraint that is known to hold for the
110+
/// specified value on the specified edge. This may be only be called
111+
/// on integer-typed Values.
112+
ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB,
113+
BasicBlock *ToBB,
114+
Instruction *CxtI = nullptr);
115+
116+
/// Inform the analysis cache that we have threaded an edge from
117+
/// PredBB to OldSucc to be from PredBB to NewSucc instead.
118+
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
119+
BasicBlock *NewSucc);
120+
121+
/// Remove information related to this value from the cache.
122+
void forgetValue(Value *V);
123+
124+
/// Inform the analysis cache that we have erased a block.
125+
void eraseBlock(BasicBlock *BB);
126+
127+
/// Complete flush all previously computed values
128+
void clear();
129+
130+
/// Print the \LazyValueInfo Analysis.
131+
/// We pass in the DTree that is required for identifying which basic blocks
132+
/// we can solve/print for, in the LVIPrinter.
133+
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
134+
135+
// For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
136+
void releaseMemory();
137+
138+
/// Handle invalidation events in the new pass manager.
139+
bool invalidate(Function &F, const PreservedAnalyses &PA,
140+
FunctionAnalysisManager::Invalidator &Inv);
62141
};
63142

64-
// Public query interface.
65-
66-
/// Determine whether the specified value comparison with a constant is known
67-
/// to be true or false on the specified CFG edge.
68-
/// Pred is a CmpInst predicate.
69-
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
70-
BasicBlock *FromBB, BasicBlock *ToBB,
71-
Instruction *CxtI = nullptr);
72-
73-
/// Determine whether the specified value comparison with a constant is known
74-
/// to be true or false at the specified instruction.
75-
/// \p Pred is a CmpInst predicate. If \p UseBlockValue is true, the block
76-
/// value is also taken into account.
77-
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
78-
Instruction *CxtI, bool UseBlockValue);
79-
80-
/// Determine whether the specified value comparison is known to be true
81-
/// or false at the specified instruction. While this takes two Value's,
82-
/// it still requires that one of them is a constant.
83-
/// \p Pred is a CmpInst predicate.
84-
/// If \p UseBlockValue is true, the block value is also taken into account.
85-
Tristate getPredicateAt(unsigned Pred, Value *LHS, Value *RHS,
86-
Instruction *CxtI, bool UseBlockValue);
87-
88-
/// Determine whether the specified value is known to be a constant at the
89-
/// specified instruction. Return null if not.
90-
Constant *getConstant(Value *V, Instruction *CxtI);
91-
92-
/// Return the ConstantRange constraint that is known to hold for the
93-
/// specified value at the specified instruction. This may only be called
94-
/// on integer-typed Values.
95-
ConstantRange getConstantRange(Value *V, Instruction *CxtI,
96-
bool UndefAllowed = true);
97-
98-
/// Return the ConstantRange constraint that is known to hold for the value
99-
/// at a specific use-site.
100-
ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed = true);
101-
102-
/// Determine whether the specified value is known to be a
103-
/// constant on the specified edge. Return null if not.
104-
Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
105-
Instruction *CxtI = nullptr);
106-
107-
/// Return the ConstantRage constraint that is known to hold for the
108-
/// specified value on the specified edge. This may be only be called
109-
/// on integer-typed Values.
110-
ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB,
111-
BasicBlock *ToBB,
112-
Instruction *CxtI = nullptr);
113-
114-
/// Inform the analysis cache that we have threaded an edge from
115-
/// PredBB to OldSucc to be from PredBB to NewSucc instead.
116-
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
117-
118-
/// Remove information related to this value from the cache.
119-
void forgetValue(Value *V);
120-
121-
/// Inform the analysis cache that we have erased a block.
122-
void eraseBlock(BasicBlock *BB);
123-
124-
/// Complete flush all previously computed values
125-
void clear(const Module *M);
126-
127-
/// Print the \LazyValueInfo Analysis.
128-
/// We pass in the DTree that is required for identifying which basic blocks
129-
/// we can solve/print for, in the LVIPrinter.
130-
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
131-
132-
// For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
133-
void releaseMemory();
134-
135-
/// Handle invalidation events in the new pass manager.
136-
bool invalidate(Function &F, const PreservedAnalyses &PA,
137-
FunctionAnalysisManager::Invalidator &Inv);
138-
};
139-
140143
/// Analysis to compute lazy value information.
141144
class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
142145
public:

0 commit comments

Comments
 (0)