File indexing completed on 2026-05-10 08:43:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
0015 #define LLVM_ANALYSIS_LAZYVALUEINFO_H
0016
0017 #include "llvm/IR/InstrTypes.h"
0018 #include "llvm/IR/PassManager.h"
0019 #include "llvm/Pass.h"
0020
0021 namespace llvm {
0022 class AssumptionCache;
0023 class BasicBlock;
0024 class Constant;
0025 class DataLayout;
0026 class DominatorTree;
0027 class Instruction;
0028 class Value;
0029 class Use;
0030 class LazyValueInfoImpl;
0031
0032 class LazyValueInfo {
0033 friend class LazyValueInfoWrapperPass;
0034 AssumptionCache *AC = nullptr;
0035 const DataLayout *DL = nullptr;
0036 LazyValueInfoImpl *PImpl = nullptr;
0037 LazyValueInfo(const LazyValueInfo &) = delete;
0038 void operator=(const LazyValueInfo &) = delete;
0039
0040 LazyValueInfoImpl *getImpl();
0041 LazyValueInfoImpl &getOrCreateImpl(const Module *M);
0042
0043 public:
0044 ~LazyValueInfo();
0045 LazyValueInfo() = default;
0046 LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_)
0047 : AC(AC_), DL(DL_) {}
0048 LazyValueInfo(LazyValueInfo &&Arg)
0049 : AC(Arg.AC), DL(Arg.DL), PImpl(Arg.PImpl) {
0050 Arg.PImpl = nullptr;
0051 }
0052 LazyValueInfo &operator=(LazyValueInfo &&Arg) {
0053 releaseMemory();
0054 AC = Arg.AC;
0055 DL = Arg.DL;
0056 PImpl = Arg.PImpl;
0057 Arg.PImpl = nullptr;
0058 return *this;
0059 }
0060
0061
0062
0063
0064
0065
0066 Constant *getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C,
0067 BasicBlock *FromBB, BasicBlock *ToBB,
0068 Instruction *CxtI = nullptr);
0069
0070
0071
0072
0073
0074 Constant *getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C,
0075 Instruction *CxtI, bool UseBlockValue);
0076
0077
0078
0079
0080
0081
0082 Constant *getPredicateAt(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
0083 Instruction *CxtI, bool UseBlockValue);
0084
0085
0086
0087 Constant *getConstant(Value *V, Instruction *CxtI);
0088
0089
0090
0091
0092 ConstantRange getConstantRange(Value *V, Instruction *CxtI,
0093 bool UndefAllowed);
0094
0095
0096
0097 ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed);
0098
0099
0100
0101 Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
0102 Instruction *CxtI = nullptr);
0103
0104
0105
0106
0107 ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB,
0108 BasicBlock *ToBB,
0109 Instruction *CxtI = nullptr);
0110
0111
0112
0113 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
0114 BasicBlock *NewSucc);
0115
0116
0117 void forgetValue(Value *V);
0118
0119
0120 void eraseBlock(BasicBlock *BB);
0121
0122
0123 void clear();
0124
0125
0126
0127
0128 void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS);
0129
0130
0131 void releaseMemory();
0132
0133
0134 bool invalidate(Function &F, const PreservedAnalyses &PA,
0135 FunctionAnalysisManager::Invalidator &Inv);
0136 };
0137
0138
0139 class LazyValueAnalysis : public AnalysisInfoMixin<LazyValueAnalysis> {
0140 public:
0141 typedef LazyValueInfo Result;
0142 Result run(Function &F, FunctionAnalysisManager &FAM);
0143
0144 private:
0145 static AnalysisKey Key;
0146 friend struct AnalysisInfoMixin<LazyValueAnalysis>;
0147 };
0148
0149
0150 class LazyValueInfoPrinterPass
0151 : public PassInfoMixin<LazyValueInfoPrinterPass> {
0152 raw_ostream &OS;
0153
0154 public:
0155 explicit LazyValueInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
0156
0157 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0158
0159 static bool isRequired() { return true; }
0160 };
0161
0162
0163 class LazyValueInfoWrapperPass : public FunctionPass {
0164 LazyValueInfoWrapperPass(const LazyValueInfoWrapperPass&) = delete;
0165 void operator=(const LazyValueInfoWrapperPass&) = delete;
0166 public:
0167 static char ID;
0168 LazyValueInfoWrapperPass();
0169 ~LazyValueInfoWrapperPass() override {
0170 assert(!Info.PImpl && "releaseMemory not called");
0171 }
0172
0173 LazyValueInfo &getLVI();
0174
0175 void getAnalysisUsage(AnalysisUsage &AU) const override;
0176 void releaseMemory() override;
0177 bool runOnFunction(Function &F) override;
0178 private:
0179 LazyValueInfo Info;
0180 };
0181
0182 }
0183
0184 #endif
0185