LLVM 19.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 LazyValueInfoImpl *PImpl = nullptr;
36 LazyValueInfo(const LazyValueInfo &) = delete;
37 void operator=(const LazyValueInfo &) = delete;
38
39 LazyValueInfoImpl *getImpl();
40 LazyValueInfoImpl &getOrCreateImpl(const Module *M);
41
42 public:
44 LazyValueInfo() = default;
46 : AC(AC_), DL(DL_) {}
48 : AC(Arg.AC), DL(Arg.DL), PImpl(Arg.PImpl) {
49 Arg.PImpl = nullptr;
50 }
53 AC = Arg.AC;
54 DL = Arg.DL;
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 { Unknown = -1, False = 0, True = 1 };
62
63 // Public query interface.
64
65 /// Determine whether the specified value comparison with a constant is
66 /// known to be true or false on the specified CFG edge. Pred is a CmpInst
67 /// predicate.
68 Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
69 BasicBlock *FromBB, BasicBlock *ToBB,
70 Instruction *CxtI = nullptr);
71
72 /// Determine whether the specified value comparison with a constant is
73 /// known to be true or false at the specified instruction. \p Pred is a
74 /// CmpInst predicate. If \p UseBlockValue is true, the block value is also
75 /// taken into account.
76 Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
77 Instruction *CxtI, bool UseBlockValue);
78
79 /// Determine whether the specified value comparison is known to be true
80 /// or false at the specified instruction. While this takes two Value's,
81 /// it still requires that one of them is a constant.
82 /// \p Pred is a CmpInst predicate.
83 /// If \p UseBlockValue is true, the block value is also taken into account.
84 Tristate getPredicateAt(unsigned Pred, Value *LHS, Value *RHS,
85 Instruction *CxtI, bool UseBlockValue);
86
87 /// Determine whether the specified value is known to be a constant at the
88 /// specified instruction. Return null if not.
90
91 /// Return the ConstantRange constraint that is known to hold for the
92 /// specified value at the specified instruction. This may only be called
93 /// on integer-typed Values.
95 bool UndefAllowed);
96
97 /// Return the ConstantRange constraint that is known to hold for the value
98 /// at a specific use-site.
99 ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed);
100
101 /// Determine whether the specified value is known to be a
102 /// constant on the specified edge. Return null if not.
104 Instruction *CxtI = nullptr);
105
106 /// Return the ConstantRage constraint that is known to hold for the
107 /// specified value on the specified edge. This may be only be called
108 /// on integer-typed Values.
110 BasicBlock *ToBB,
111 Instruction *CxtI = nullptr);
112
113 /// Inform the analysis cache that we have threaded an edge from
114 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
115 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
116 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();
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.
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,
138 };
139
140/// Analysis to compute lazy value information.
141class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
142public:
145
146private:
147 static AnalysisKey Key;
149};
150
151/// Printer pass for the LazyValueAnalysis results.
153 : public PassInfoMixin<LazyValueInfoPrinterPass> {
154 raw_ostream &OS;
155
156public:
158
160
161 static bool isRequired() { return true; }
162};
163
164/// Wrapper around LazyValueInfo.
167 void operator=(const LazyValueInfoWrapperPass&) = delete;
168public:
169 static char ID;
172 assert(!Info.PImpl && "releaseMemory not called");
173 }
174
176
177 void getAnalysisUsage(AnalysisUsage &AU) const override;
178 void releaseMemory() override;
179 bool runOnFunction(Function &F) override;
180private:
181 LazyValueInfo Info;
182};
183
184} // end namespace llvm
185
186#endif
187
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:387
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
Represent the analysis usage information of a pass.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
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:162
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)
Printer pass for the LazyValueAnalysis results.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LazyValueInfoPrinterPass(raw_ostream &OS)
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:51
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_)
Definition: LazyValueInfo.h:45
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
ConstantRange getConstantRange(Value *V, Instruction *CxtI, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:47
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:61
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.
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
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: Analysis.h:109
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:114
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:91