LLVM  15.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 
20 namespace 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 
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  void *PImpl = nullptr;
37  LazyValueInfo(const LazyValueInfo&) = delete;
38  void operator=(const LazyValueInfo&) = delete;
39 public:
41  LazyValueInfo() = default;
43  TargetLibraryInfo *TLI_)
44  : AC(AC_), DL(DL_), TLI(TLI_) {}
46  : AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), PImpl(Arg.PImpl) {
47  Arg.PImpl = nullptr;
48  }
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
62  };
63 
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.
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.
96  bool UndefAllowed = true);
97 
98  /// Determine whether the specified value is known to be a
99  /// constant on the specified edge. Return null if not.
101  Instruction *CxtI = nullptr);
102 
103  /// Return the ConstantRage constraint that is known to hold for the
104  /// specified value on the specified edge. This may be only be called
105  /// on integer-typed Values.
107  BasicBlock *ToBB,
108  Instruction *CxtI = nullptr);
109 
110  /// Inform the analysis cache that we have threaded an edge from
111  /// PredBB to OldSucc to be from PredBB to NewSucc instead.
112  void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
113 
114  /// Inform the analysis cache that we have erased a block.
115  void eraseBlock(BasicBlock *BB);
116 
117  /// Complete flush all previously computed values
118  void clear(const Module *M);
119 
120  /// Print the \LazyValueInfo Analysis.
121  /// We pass in the DTree that is required for identifying which basic blocks
122  /// we can solve/print for, in the LVIPrinter.
123  void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
124 
125  // For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
126  void releaseMemory();
127 
128  /// Handle invalidation events in the new pass manager.
129  bool invalidate(Function &F, const PreservedAnalyses &PA,
131 };
132 
133 /// Analysis to compute lazy value information.
134 class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
135 public:
138 
139 private:
140  static AnalysisKey Key;
142 };
143 
144 /// Wrapper around LazyValueInfo.
147  void operator=(const LazyValueInfoWrapperPass&) = delete;
148 public:
149  static char ID;
152  assert(!Info.PImpl && "releaseMemory not called");
153  }
154 
156 
157  void getAnalysisUsage(AnalysisUsage &AU) const override;
158  void releaseMemory() override;
159  bool runOnFunction(Function &F) override;
160 private:
161  LazyValueInfo Info;
162 };
163 
164 } // end namespace llvm
165 
166 #endif
167 
llvm::LazyValueInfo::getConstantOnEdge
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.
Definition: LazyValueInfo.cpp:1630
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::LazyValueInfo::~LazyValueInfo
~LazyValueInfo()
Definition: LazyValueInfo.cpp:1546
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::LazyValueInfo::getPredicateOnEdge
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 ...
Definition: LazyValueInfo.cpp:1735
llvm::Function
Definition: Function.h:60
Pass.h
llvm::LazyValueAnalysis
Analysis to compute lazy value information.
Definition: LazyValueInfo.h:134
llvm::LazyValueInfo::getConstantRangeOnEdge
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...
Definition: LazyValueInfo.cpp:1647
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::LazyValueInfo::getConstant
Constant * getConstant(Value *V, Instruction *CxtI)
Determine whether the specified value is known to be a constant at the specified instruction.
Definition: LazyValueInfo.cpp:1591
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::LazyValueAnalysis::run
Result run(Function &F, FunctionAnalysisManager &FAM)
Definition: LazyValueInfo.cpp:1569
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::LazyValueInfoWrapperPass::~LazyValueInfoWrapperPass
~LazyValueInfoWrapperPass() override
Definition: LazyValueInfo.h:151
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::LazyValueInfo::Unknown
@ Unknown
Definition: LazyValueInfo.h:61
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::LazyValueInfoWrapperPass::ID
static char ID
Definition: LazyValueInfo.h:149
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::LazyValueInfo::LazyValueInfo
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:45
llvm::LazyValueInfo::True
@ True
Definition: LazyValueInfo.h:61
llvm::Instruction
Definition: Instruction.h:42
llvm::LazyValueInfo::printLVI
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the \LazyValueInfo Analysis.
Definition: LazyValueInfo.cpp:1888
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::LazyValueInfoWrapperPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LazyValueInfo.cpp:1538
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:667
llvm::LazyValueInfoWrapperPass::runOnFunction
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition: LazyValueInfo.cpp:1527
llvm::LazyValueInfo::invalidate
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
Definition: LazyValueInfo.cpp:1556
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::LazyValueInfo::getConstantRange
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...
Definition: LazyValueInfo.cpp:1610
llvm::LazyValueInfoWrapperPass
Wrapper around LazyValueInfo.
Definition: LazyValueInfo.h:145
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::LazyValueInfo
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:31
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
llvm::LazyValueInfo::releaseMemory
void releaseMemory()
Definition: LazyValueInfo.cpp:1548
llvm::LazyValueInfo::LazyValueInfo
LazyValueInfo()=default
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::LazyValueInfo::operator=
LazyValueInfo & operator=(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:49
llvm::LazyValueInfoWrapperPass::LazyValueInfoWrapperPass
LazyValueInfoWrapperPass()
Definition: LazyValueInfo.cpp:51
llvm::LazyValueAnalysis::Result
LazyValueInfo Result
Definition: LazyValueInfo.h:136
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::LazyValueInfoWrapperPass::releaseMemory
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: LazyValueInfo.cpp:1567
llvm::LazyValueInfo::clear
void clear(const Module *M)
Complete flush all previously computed values.
Definition: LazyValueInfo.cpp:1882
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:222
llvm::LazyValueInfoWrapperPass::getLVI
LazyValueInfo & getLVI()
Definition: LazyValueInfo.cpp:1544
llvm::ConstantRange
This class represents a range of values.
Definition: ConstantRange.h:47
llvm::LazyValueInfo::LazyValueInfo
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_, TargetLibraryInfo *TLI_)
Definition: LazyValueInfo.h:42
llvm::LazyValueInfo::Tristate
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:60
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::LazyValueInfo::False
@ False
Definition: LazyValueInfo.h:61
llvm::LazyValueInfo::eraseBlock
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
Definition: LazyValueInfo.cpp:1876
llvm::LazyValueInfo::getPredicateAt
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 ...
Definition: LazyValueInfo.cpp:1746
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::LazyValueInfo::threadEdge
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...
Definition: LazyValueInfo.cpp:1868