File indexing completed on 2026-05-10 08:44:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 #ifndef LLVM_TRANSFORMS_UTILS_PREDICATEINFO_H
0051 #define LLVM_TRANSFORMS_UTILS_PREDICATEINFO_H
0052
0053 #include "llvm/ADT/DenseMap.h"
0054 #include "llvm/ADT/SmallSet.h"
0055 #include "llvm/ADT/ilist.h"
0056 #include "llvm/ADT/ilist_node.h"
0057 #include "llvm/IR/Instructions.h"
0058 #include "llvm/IR/PassManager.h"
0059 #include "llvm/IR/ValueHandle.h"
0060
0061 namespace llvm {
0062
0063 class AssumptionCache;
0064 class DominatorTree;
0065 class Function;
0066 class Value;
0067 class IntrinsicInst;
0068 class raw_ostream;
0069
0070 enum PredicateType { PT_Branch, PT_Assume, PT_Switch };
0071
0072
0073
0074 struct PredicateConstraint {
0075 CmpInst::Predicate Predicate;
0076 Value *OtherOp;
0077 };
0078
0079
0080
0081 class PredicateBase : public ilist_node<PredicateBase> {
0082 public:
0083 PredicateType Type;
0084
0085
0086
0087 Value *OriginalOp;
0088
0089
0090
0091 Value *RenamedOp;
0092
0093 Value *Condition;
0094
0095 PredicateBase(const PredicateBase &) = delete;
0096 PredicateBase &operator=(const PredicateBase &) = delete;
0097 PredicateBase() = delete;
0098 virtual ~PredicateBase() = default;
0099 static bool classof(const PredicateBase *PB) {
0100 return PB->Type == PT_Assume || PB->Type == PT_Branch ||
0101 PB->Type == PT_Switch;
0102 }
0103
0104
0105 std::optional<PredicateConstraint> getConstraint() const;
0106
0107 protected:
0108 PredicateBase(PredicateType PT, Value *Op, Value *Condition)
0109 : Type(PT), OriginalOp(Op), Condition(Condition) {}
0110 };
0111
0112
0113
0114
0115 class PredicateAssume : public PredicateBase {
0116 public:
0117 IntrinsicInst *AssumeInst;
0118 PredicateAssume(Value *Op, IntrinsicInst *AssumeInst, Value *Condition)
0119 : PredicateBase(PT_Assume, Op, Condition), AssumeInst(AssumeInst) {}
0120 PredicateAssume() = delete;
0121 static bool classof(const PredicateBase *PB) {
0122 return PB->Type == PT_Assume;
0123 }
0124 };
0125
0126
0127
0128
0129 class PredicateWithEdge : public PredicateBase {
0130 public:
0131 BasicBlock *From;
0132 BasicBlock *To;
0133 PredicateWithEdge() = delete;
0134 static bool classof(const PredicateBase *PB) {
0135 return PB->Type == PT_Branch || PB->Type == PT_Switch;
0136 }
0137
0138 protected:
0139 PredicateWithEdge(PredicateType PType, Value *Op, BasicBlock *From,
0140 BasicBlock *To, Value *Cond)
0141 : PredicateBase(PType, Op, Cond), From(From), To(To) {}
0142 };
0143
0144
0145 class PredicateBranch : public PredicateWithEdge {
0146 public:
0147
0148 bool TrueEdge;
0149 PredicateBranch(Value *Op, BasicBlock *BranchBB, BasicBlock *SplitBB,
0150 Value *Condition, bool TakenEdge)
0151 : PredicateWithEdge(PT_Branch, Op, BranchBB, SplitBB, Condition),
0152 TrueEdge(TakenEdge) {}
0153 PredicateBranch() = delete;
0154 static bool classof(const PredicateBase *PB) {
0155 return PB->Type == PT_Branch;
0156 }
0157 };
0158
0159 class PredicateSwitch : public PredicateWithEdge {
0160 public:
0161 Value *CaseValue;
0162
0163 SwitchInst *Switch;
0164 PredicateSwitch(Value *Op, BasicBlock *SwitchBB, BasicBlock *TargetBB,
0165 Value *CaseValue, SwitchInst *SI)
0166 : PredicateWithEdge(PT_Switch, Op, SwitchBB, TargetBB,
0167 SI->getCondition()),
0168 CaseValue(CaseValue), Switch(SI) {}
0169 PredicateSwitch() = delete;
0170 static bool classof(const PredicateBase *PB) {
0171 return PB->Type == PT_Switch;
0172 }
0173 };
0174
0175
0176
0177 class PredicateInfo {
0178 public:
0179 PredicateInfo(Function &, DominatorTree &, AssumptionCache &);
0180 ~PredicateInfo();
0181
0182 void verifyPredicateInfo() const;
0183
0184 void dump() const;
0185 void print(raw_ostream &) const;
0186
0187 const PredicateBase *getPredicateInfoFor(const Value *V) const {
0188 return PredicateMap.lookup(V);
0189 }
0190
0191 protected:
0192
0193 friend class PredicateInfoAnnotatedWriter;
0194 friend class PredicateInfoBuilder;
0195
0196 private:
0197 Function &F;
0198
0199
0200 iplist<PredicateBase> AllInfos;
0201
0202
0203
0204
0205 DenseMap<const Value *, const PredicateBase *> PredicateMap;
0206
0207 SmallSet<AssertingVH<Function>, 20> CreatedDeclarations;
0208 };
0209
0210
0211 class PredicateInfoPrinterPass
0212 : public PassInfoMixin<PredicateInfoPrinterPass> {
0213 raw_ostream &OS;
0214
0215 public:
0216 explicit PredicateInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
0217 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0218 static bool isRequired() { return true; }
0219 };
0220
0221
0222 struct PredicateInfoVerifierPass : PassInfoMixin<PredicateInfoVerifierPass> {
0223 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
0224 static bool isRequired() { return true; }
0225 };
0226
0227 }
0228
0229 #endif