LLVM 22.0.0git
SimplifyQuery.h
Go to the documentation of this file.
1//===-- SimplifyQuery.h - Context for simplifications -----------*- 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#ifndef LLVM_ANALYSIS_SIMPLIFYQUERY_H
10#define LLVM_ANALYSIS_SIMPLIFYQUERY_H
11
13#include "llvm/IR/Operator.h"
15
16namespace llvm {
17
18class AssumptionCache;
19class DomConditionCache;
20class DominatorTree;
21class TargetLibraryInfo;
22
23/// InstrInfoQuery provides an interface to query additional information for
24/// instructions like metadata or keywords like nsw, which provides conservative
25/// results if the users specified it is safe to use.
27 InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
28 InstrInfoQuery() = default;
29 bool UseInstrInfo = true;
30
31 MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
32 if (UseInstrInfo)
33 return I->getMetadata(KindID);
34 return nullptr;
35 }
36
37 template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
38 if (UseInstrInfo)
39 return Op->hasNoUnsignedWrap();
40 return false;
41 }
42
43 template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
44 if (UseInstrInfo)
45 return Op->hasNoSignedWrap();
46 return false;
47 }
48
49 bool isExact(const BinaryOperator *Op) const {
50 if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
51 return cast<PossiblyExactOperator>(Op)->isExact();
52 return false;
53 }
54
55 template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
56 if (UseInstrInfo)
57 return Op->hasNoSignedZeros();
58 return false;
59 }
60};
61
62/// Evaluate query assuming this condition holds.
65 bool Invert = false;
67
69};
70
72 const DataLayout &DL;
73 const TargetLibraryInfo *TLI = nullptr;
74 const DominatorTree *DT = nullptr;
75 AssumptionCache *AC = nullptr;
76 const Instruction *CxtI = nullptr;
77 const DomConditionCache *DC = nullptr;
78 const CondContext *CC = nullptr;
79
80 // Wrapper to query additional information for instructions like metadata or
81 // keywords like nsw, which provides conservative results if those cannot
82 // be safely used.
84
85 /// Controls whether simplifications are allowed to constrain the range of
86 /// possible values for uses of undef. If it is false, simplifications are not
87 /// allowed to assume a particular value for a use of undef for example.
88 bool CanUseUndef = true;
89
90 SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
91 : DL(DL), CxtI(CXTI) {}
92
94 const DominatorTree *DT = nullptr,
95 AssumptionCache *AC = nullptr,
96 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
97 bool CanUseUndef = true, const DomConditionCache *DC = nullptr)
98 : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), DC(DC), IIQ(UseInstrInfo),
100
102 AssumptionCache *AC = nullptr,
103 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
104 bool CanUseUndef = true)
105 : DL(DL), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
107
109 SimplifyQuery Copy(*this);
110 Copy.CxtI = I;
111 return Copy;
112 }
114 SimplifyQuery Copy(*this);
115 Copy.CanUseUndef = false;
116 return Copy;
117 }
118
119 /// If CanUseUndef is true, returns whether \p V is undef.
120 /// Otherwise always return false.
121 LLVM_ABI bool isUndefValue(Value *V) const;
122
124 SimplifyQuery Copy(*this);
125 Copy.DC = nullptr;
126 return Copy;
127 }
128
130 SimplifyQuery Copy(*this);
131 Copy.CC = &CC;
132 return Copy;
133 }
134
136 SimplifyQuery Copy(*this);
137 Copy.CC = nullptr;
138 return Copy;
139 }
140};
141
142} // end namespace llvm
143
144#endif
#define LLVM_ABI
Definition: Compiler.h:213
#define I(x, y, z)
Definition: MD5.cpp:58
This file defines the SmallPtrSet class.
A cache of @llvm.assume calls within a function.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:165
Metadata node.
Definition: Metadata.h:1077
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:541
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition: Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Evaluate query assuming this condition holds.
Definition: SimplifyQuery.h:63
CondContext(Value *Cond)
Definition: SimplifyQuery.h:68
SmallPtrSet< Value *, 4 > AffectedValues
Definition: SimplifyQuery.h:66
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
Definition: SimplifyQuery.h:26
bool isExact(const BinaryOperator *Op) const
Definition: SimplifyQuery.h:49
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
Definition: SimplifyQuery.h:31
bool hasNoSignedZeros(const InstT *Op) const
Definition: SimplifyQuery.h:55
InstrInfoQuery(bool UMD)
Definition: SimplifyQuery.h:27
bool hasNoSignedWrap(const InstT *Op) const
Definition: SimplifyQuery.h:43
InstrInfoQuery()=default
bool hasNoUnsignedWrap(const InstT *Op) const
Definition: SimplifyQuery.h:37
const DataLayout & DL
Definition: SimplifyQuery.h:72
SimplifyQuery getWithoutCondContext() const
const Instruction * CxtI
Definition: SimplifyQuery.h:76
SimplifyQuery(const DataLayout &DL, const Instruction *CXTI=nullptr)
Definition: SimplifyQuery.h:90
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
Definition: SimplifyQuery.h:88
const DominatorTree * DT
Definition: SimplifyQuery.h:74
SimplifyQuery getWithCondContext(const CondContext &CC) const
SimplifyQuery getWithInstruction(const Instruction *I) const
SimplifyQuery(const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CXTI=nullptr, bool UseInstrInfo=true, bool CanUseUndef=true, const DomConditionCache *DC=nullptr)
Definition: SimplifyQuery.h:93
LLVM_ABI bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
AssumptionCache * AC
Definition: SimplifyQuery.h:75
const DomConditionCache * DC
Definition: SimplifyQuery.h:77
SimplifyQuery(const DataLayout &DL, const DominatorTree *DT, AssumptionCache *AC=nullptr, const Instruction *CXTI=nullptr, bool UseInstrInfo=true, bool CanUseUndef=true)
const TargetLibraryInfo * TLI
Definition: SimplifyQuery.h:73
SimplifyQuery getWithoutUndef() const
const InstrInfoQuery IIQ
Definition: SimplifyQuery.h:83
SimplifyQuery getWithoutDomCondCache() const
const CondContext * CC
Definition: SimplifyQuery.h:78