LLVM 18.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/PassManager.h"
18#include "llvm/Pass.h"
19
20namespace llvm {
21 class AssumptionCache;
22 class Constant;
23 class ConstantRange;
24 class DataLayout;
25 class DominatorTree;
26 class Instruction;
27 class TargetLibraryInfo;
28 class Value;
29 class LazyValueInfoImpl;
30 /// This pass computes, caches, and vends lazy value constraint information.
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:
45 LazyValueInfo() = default;
48 : AC(AC_), DL(DL_), TLI(TLI_) {}
50 : AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), PImpl(Arg.PImpl) {
51 Arg.PImpl = nullptr;
52 }
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.
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.
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.
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.
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.
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,
141 };
142
143/// Analysis to compute lazy value information.
144class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
145public:
148
149private:
150 static AnalysisKey Key;
152};
153
154/// Wrapper around LazyValueInfo.
157 void operator=(const LazyValueInfoWrapperPass&) = delete;
158public:
159 static char ID;
162 assert(!Info.PImpl && "releaseMemory not called");
163 }
164
166
167 void getAnalysisUsage(AnalysisUsage &AU) const override;
168 void releaseMemory() override;
169 bool runOnFunction(Function &F) override;
170private:
171 LazyValueInfo Info;
172};
173
174} // end namespace llvm
175
176#endif
177
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Value * LHS
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:661
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
Represent the analysis usage information of a pass.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
This class represents a range of values.
Definition: ConstantRange.h:47
This is an important base class in LLVM.
Definition: Constant.h:41
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
Analysis to compute lazy value information.
Result run(Function &F, FunctionAnalysisManager &FAM)
Wrapper around LazyValueInfo.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:31
LazyValueInfo & operator=(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:53
ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed=true)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:49
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...
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:64
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.
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...
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, bool UseBlockValue)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
Constant * getConstant(Value *V, Instruction *CxtI)
Determine whether the specified value is known to be a constant at the specified instruction.
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the \LazyValueInfo Analysis.
void forgetValue(Value *V)
Remove information related to this value from the cache.
LazyValueInfo()=default
void clear()
Complete flush all previously computed values.
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_, TargetLibraryInfo *TLI_)
Definition: LazyValueInfo.h:46
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
ConstantRange getConstantRange(Value *V, Instruction *CxtI, bool UndefAllowed=true)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
Provides information about what library functions are available for the current target.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69