LLVM  12.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:
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  /// (from an assume intrinsic). Pred is a CmpInst predicate.
76  Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
77  Instruction *CxtI);
78 
79  /// Determine whether the specified value is known to be a
80  /// constant at the end of the specified block. Return null if not.
81  Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
82 
83  /// Return the ConstantRange constraint that is known to hold for the
84  /// specified value at the end of the specified block. This may only be called
85  /// on integer-typed Values.
87  Instruction *CxtI = nullptr,
88  bool UndefAllowed = true);
89 
90  /// Determine whether the specified value is known to be a
91  /// constant on the specified edge. Return null if not.
93  Instruction *CxtI = nullptr);
94 
95  /// Return the ConstantRage constraint that is known to hold for the
96  /// specified value on the specified edge. This may be only be called
97  /// on integer-typed Values.
99  BasicBlock *ToBB,
100  Instruction *CxtI = nullptr);
101 
102  /// Inform the analysis cache that we have threaded an edge from
103  /// PredBB to OldSucc to be from PredBB to NewSucc instead.
104  void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
105 
106  /// Inform the analysis cache that we have erased a block.
107  void eraseBlock(BasicBlock *BB);
108 
109  /// Print the \LazyValueInfo Analysis.
110  /// We pass in the DTree that is required for identifying which basic blocks
111  /// we can solve/print for, in the LVIPrinter.
112  void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
113 
114  // For old PM pass. Delete once LazyValueInfoWrapperPass is gone.
115  void releaseMemory();
116 
117  /// Handle invalidation events in the new pass manager.
118  bool invalidate(Function &F, const PreservedAnalyses &PA,
120 };
121 
122 /// Analysis to compute lazy value information.
123 class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
124 public:
126  Result run(Function &F, FunctionAnalysisManager &FAM);
127 
128 private:
129  static AnalysisKey Key;
131 };
132 
133 /// Wrapper around LazyValueInfo.
136  void operator=(const LazyValueInfoWrapperPass&) = delete;
137 public:
138  static char ID;
141  assert(!Info.PImpl && "releaseMemory not called");
142  }
143 
144  LazyValueInfo &getLVI();
145 
146  void getAnalysisUsage(AnalysisUsage &AU) const override;
147  void releaseMemory() override;
148  bool runOnFunction(Function &F) override;
149 private:
151 };
152 
153 } // end namespace llvm
154 
155 #endif
156 
uint64_t CallInst * C
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Wrapper around LazyValueInfo.
A cache of @llvm.assume calls within a function.
F(f)
ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr, bool UndefAllowed=true)
Return the ConstantRange constraint that is known to hold for the specified value at the end of the s...
friend class LazyValueInfoWrapperPass
Definition: LazyValueInfo.h:32
Constant * getConstant(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant at the end of the specified block...
Key
PAL metadata keys.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
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.
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_, TargetLibraryInfo *TLI_)
Definition: LazyValueInfo.h:42
This is an important base class in LLVM.
Definition: Constant.h:41
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:390
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:60
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)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
Provides information about what library functions are available for the current target.
This class represents a range of values.
Definition: ConstantRange.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...
LazyValueInfo & operator=(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:49
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:654
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:31
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:74
LazyValueInfo(LazyValueInfo &&Arg)
Definition: LazyValueInfo.h:45
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A container for analyses that lazily runs them and caches their results.
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the Analysis.
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...
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
Analysis to compute lazy value information.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL