LLVM 24.0.0git
LazyValueInfo.h
Go to the documentation of this file.
1//===- LazyValueInfo.h - Value constraint analysis --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interface for lazy computation of value constraint
10// information.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
15#define LLVM_ANALYSIS_LAZYVALUEINFO_H
16
17#include "llvm/IR/InstrTypes.h"
18#include "llvm/IR/PassManager.h"
19#include "llvm/Pass.h"
20
21namespace llvm {
22 class AssumptionCache;
23 class BasicBlock;
24 class Constant;
25 class DataLayout;
26 class DominatorTree;
27 class Instruction;
28 class Value;
29 class Use;
31 /// This pass computes, caches, and vends lazy value constraint information.
32 class LazyValueInfo {
34 Function *F = nullptr;
35 AssumptionCache *AC = nullptr;
36 LazyValueInfoImpl *PImpl = nullptr;
37 LazyValueInfo(const LazyValueInfo &) = delete;
38 void operator=(const LazyValueInfo &) = delete;
39
40 LazyValueInfoImpl *getImpl();
41 LazyValueInfoImpl &getOrCreateImpl();
42
43 public:
45 LazyValueInfo() = default;
46 LazyValueInfo(Function *F, AssumptionCache *AC) : F(F), AC(AC) {}
47 LazyValueInfo(LazyValueInfo &&Arg)
48 : F(Arg.F), AC(Arg.AC), PImpl(Arg.PImpl) {
49 Arg.PImpl = nullptr;
50 }
51 LazyValueInfo &operator=(LazyValueInfo &&Arg) {
53 F = Arg.F;
54 AC = Arg.AC;
55 PImpl = Arg.PImpl;
56 Arg.PImpl = nullptr;
57 return *this;
58 }
59
60 // Public query interface.
61
62 /// Determine whether the specified value comparison with a constant is
63 /// known to be true or false on the specified CFG edge. Pred is a CmpInst
64 /// predicate.
66 Constant *C, BasicBlock *FromBB,
67 BasicBlock *ToBB,
68 Instruction *CtxI = nullptr);
69
70 /// Determine whether the specified value comparison with a constant is
71 /// known to be true or false at the specified instruction. \p Pred is a
72 /// CmpInst predicate. If \p UseBlockValue is true, the block value is also
73 /// taken into account.
75 Constant *C, Instruction *CtxI,
76 bool UseBlockValue);
77
78 /// Determine whether the specified value comparison is known to be true
79 /// or false at the specified instruction. While this takes two Value's,
80 /// it still requires that one of them is a constant.
81 /// \p Pred is a CmpInst predicate.
82 /// If \p UseBlockValue is true, the block value is also taken into account.
84 Value *RHS, Instruction *CtxI,
85 bool UseBlockValue);
86
87 /// Determine whether the specified value is known to be a constant at the
88 /// specified instruction. Return null if not. If \p U is provided and the
89 /// constant was derived from an equality predicate, the constant is
90 /// returned only if it may replace \p V at that use, as the two may differ
91 /// in pointer provenance.
93 const Use *U = nullptr);
94
95 /// Return the ConstantRange constraint that is known to hold for the
96 /// specified value at the specified instruction. This may only be called
97 /// on integer-typed Values.
99 bool UndefAllowed);
100
101 /// Return the ConstantRange constraint that is known to hold for the value
102 /// at a specific use-site.
103 /// \p UndefAllowed: the range may ignore that the value is known to
104 /// possibly be undef.
105 /// \p AssumeFrozen: use select conditions that may be undef, the range then
106 /// only holds after the value is frozen and its uses replaced.
108 const Use &U, bool UndefAllowed,
109 SmallVectorImpl<DbgVariableRecord *> *DebugUsers = nullptr,
110 bool AssumeFrozen = false);
111
112 /// Determine whether the specified value is known to be a
113 /// constant on the specified edge. Return null if not.
115 BasicBlock *ToBB,
116 Instruction *CtxI = nullptr,
117 const Use *U = nullptr);
118
119 /// Return the ConstantRage constraint that is known to hold for the
120 /// specified value on the specified edge. This may be only be called
121 /// on integer-typed Values.
123 BasicBlock *ToBB,
124 Instruction *CtxI = nullptr);
125
126 /// Inform the analysis cache that we have threaded an edge from
127 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
128 LLVM_ABI void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
129 BasicBlock *NewSucc);
130
131 /// Remove information related to this value from the cache.
133
134 /// Inform the analysis cache that we have erased a block.
136
137 /// Complete flush all previously computed values
138 LLVM_ABI void clear();
139
140 /// Print the \LazyValueInfo Analysis.
141 /// We pass in the DTree that is required for identifying which basic blocks
142 /// we can solve/print for, in the LVIPrinter.
144
145 // For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
146 LLVM_ABI void releaseMemory();
147
148 /// Handle invalidation events in the new pass manager.
150 FunctionAnalysisManager::Invalidator &Inv);
151 };
152
153/// Analysis to compute lazy value information.
154class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
155public:
158
159private:
160 static AnalysisKey Key;
162};
163
164/// Printer pass for the LazyValueAnalysis results.
166 : public RequiredPassInfoMixin<LazyValueInfoPrinterPass> {
167 raw_ostream &OS;
168
169public:
170 explicit LazyValueInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
171
173};
174
175/// Wrapper around LazyValueInfo.
176class LLVM_ABI LazyValueInfoWrapperPass : public FunctionPass {
177 LazyValueInfoWrapperPass(const LazyValueInfoWrapperPass&) = delete;
178 void operator=(const LazyValueInfoWrapperPass&) = delete;
179public:
180 static char ID;
181 LazyValueInfoWrapperPass();
183 assert(!Info.PImpl && "releaseMemory not called");
184 }
185
186 LazyValueInfo &getLVI();
187
188 void getAnalysisUsage(AnalysisUsage &AU) const override;
189 void releaseMemory() override;
190 bool runOnFunction(Function &F) override;
191private:
192 LazyValueInfo Info;
193};
194
195} // end namespace llvm
196
197#endif
198
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
FunctionAnalysisManager FAM
Value * RHS
Value * LHS
Represent the analysis usage information of a pass.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
This class represents a range of values.
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
FunctionPass(char &pid)
Definition Pass.h:314
Analysis to compute lazy value information.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LazyValueInfoPrinterPass(raw_ostream &OS)
This pass computes, caches, and vends lazy value constraint information.
LazyValueInfo & operator=(LazyValueInfo &&Arg)
LLVM_ABI ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed, SmallVectorImpl< DbgVariableRecord * > *DebugUsers=nullptr, bool AssumeFrozen=false)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
LLVM_ABI void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
LLVM_ABI Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr, const Use *U=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
LazyValueInfo(LazyValueInfo &&Arg)
LLVM_ABI 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...
LLVM_ABI void releaseMemory()
LLVM_ABI Constant * getConstant(Value *V, Instruction *CtxI, const Use *U=nullptr)
Determine whether the specified value is known to be a constant at the specified instruction.
LazyValueInfo(Function *F, AssumptionCache *AC)
LLVM_ABI void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the \LazyValueInfo Analysis.
LLVM_ABI Constant * getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C, Instruction *CtxI, bool UseBlockValue)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
LLVM_ABI void forgetValue(Value *V)
Remove information related to this value from the cache.
LLVM_ABI ConstantRange getConstantRange(Value *V, Instruction *CtxI, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
LazyValueInfo()=default
friend class LazyValueInfoWrapperPass
LLVM_ABI void clear()
Complete flush all previously computed values.
LLVM_ABI ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
Return the ConstantRage constraint that is known to hold for the specified value on the specified edg...
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
LLVM_ABI Constant * getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that should not be skipped.