File indexing completed on 2026-05-10 08:43:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_ANALYSIS_SIMPLIFYQUERY_H
0010 #define LLVM_ANALYSIS_SIMPLIFYQUERY_H
0011
0012 #include "llvm/ADT/SmallPtrSet.h"
0013 #include "llvm/IR/Operator.h"
0014
0015 namespace llvm {
0016
0017 class AssumptionCache;
0018 class DomConditionCache;
0019 class DominatorTree;
0020 class TargetLibraryInfo;
0021
0022
0023
0024
0025 struct InstrInfoQuery {
0026 InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
0027 InstrInfoQuery() = default;
0028 bool UseInstrInfo = true;
0029
0030 MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
0031 if (UseInstrInfo)
0032 return I->getMetadata(KindID);
0033 return nullptr;
0034 }
0035
0036 template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
0037 if (UseInstrInfo)
0038 return Op->hasNoUnsignedWrap();
0039 return false;
0040 }
0041
0042 template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
0043 if (UseInstrInfo)
0044 return Op->hasNoSignedWrap();
0045 return false;
0046 }
0047
0048 bool isExact(const BinaryOperator *Op) const {
0049 if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
0050 return cast<PossiblyExactOperator>(Op)->isExact();
0051 return false;
0052 }
0053
0054 template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
0055 if (UseInstrInfo)
0056 return Op->hasNoSignedZeros();
0057 return false;
0058 }
0059 };
0060
0061
0062 struct CondContext {
0063 Value *Cond;
0064 bool Invert = false;
0065 SmallPtrSet<Value *, 4> AffectedValues;
0066
0067 CondContext(Value *Cond) : Cond(Cond) {}
0068 };
0069
0070 struct SimplifyQuery {
0071 const DataLayout &DL;
0072 const TargetLibraryInfo *TLI = nullptr;
0073 const DominatorTree *DT = nullptr;
0074 AssumptionCache *AC = nullptr;
0075 const Instruction *CxtI = nullptr;
0076 const DomConditionCache *DC = nullptr;
0077 const CondContext *CC = nullptr;
0078
0079
0080
0081
0082 const InstrInfoQuery IIQ;
0083
0084
0085
0086
0087 bool CanUseUndef = true;
0088
0089 SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
0090 : DL(DL), CxtI(CXTI) {}
0091
0092 SimplifyQuery(const DataLayout &DL, const TargetLibraryInfo *TLI,
0093 const DominatorTree *DT = nullptr,
0094 AssumptionCache *AC = nullptr,
0095 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
0096 bool CanUseUndef = true, const DomConditionCache *DC = nullptr)
0097 : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), DC(DC), IIQ(UseInstrInfo),
0098 CanUseUndef(CanUseUndef) {}
0099
0100 SimplifyQuery(const DataLayout &DL, const DominatorTree *DT,
0101 AssumptionCache *AC = nullptr,
0102 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
0103 bool CanUseUndef = true)
0104 : DL(DL), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
0105 CanUseUndef(CanUseUndef) {}
0106
0107 SimplifyQuery getWithInstruction(const Instruction *I) const {
0108 SimplifyQuery Copy(*this);
0109 Copy.CxtI = I;
0110 return Copy;
0111 }
0112 SimplifyQuery getWithoutUndef() const {
0113 SimplifyQuery Copy(*this);
0114 Copy.CanUseUndef = false;
0115 return Copy;
0116 }
0117
0118
0119
0120 bool isUndefValue(Value *V) const;
0121
0122 SimplifyQuery getWithoutDomCondCache() const {
0123 SimplifyQuery Copy(*this);
0124 Copy.DC = nullptr;
0125 return Copy;
0126 }
0127
0128 SimplifyQuery getWithCondContext(const CondContext &CC) const {
0129 SimplifyQuery Copy(*this);
0130 Copy.CC = &CC;
0131 return Copy;
0132 }
0133
0134 SimplifyQuery getWithoutCondContext() const {
0135 SimplifyQuery Copy(*this);
0136 Copy.CC = nullptr;
0137 return Copy;
0138 }
0139 };
0140
0141 }
0142
0143 #endif