LLVM 19.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"
14
15namespace llvm {
16
17class AssumptionCache;
18class DomConditionCache;
19class DominatorTree;
20class TargetLibraryInfo;
21
22/// InstrInfoQuery provides an interface to query additional information for
23/// instructions like metadata or keywords like nsw, which provides conservative
24/// results if the users specified it is safe to use.
26 InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
27 InstrInfoQuery() = default;
28 bool UseInstrInfo = true;
29
30 MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
31 if (UseInstrInfo)
32 return I->getMetadata(KindID);
33 return nullptr;
34 }
35
36 template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
37 if (UseInstrInfo)
38 return Op->hasNoUnsignedWrap();
39 return false;
40 }
41
42 template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
43 if (UseInstrInfo)
44 return Op->hasNoSignedWrap();
45 return false;
46 }
47
48 bool isExact(const BinaryOperator *Op) const {
49 if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
50 return cast<PossiblyExactOperator>(Op)->isExact();
51 return false;
52 }
53
54 template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
55 if (UseInstrInfo)
56 return Op->hasNoSignedZeros();
57 return false;
58 }
59};
60
61/// Evaluate query assuming this condition holds.
64 bool Invert = false;
66
68};
69
71 const DataLayout &DL;
72 const TargetLibraryInfo *TLI = nullptr;
73 const DominatorTree *DT = nullptr;
74 AssumptionCache *AC = nullptr;
75 const Instruction *CxtI = nullptr;
76 const DomConditionCache *DC = nullptr;
77 const CondContext *CC = nullptr;
78
79 // Wrapper to query additional information for instructions like metadata or
80 // keywords like nsw, which provides conservative results if those cannot
81 // be safely used.
83
84 /// Controls whether simplifications are allowed to constrain the range of
85 /// possible values for uses of undef. If it is false, simplifications are not
86 /// allowed to assume a particular value for a use of undef for example.
87 bool CanUseUndef = true;
88
89 SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
90 : DL(DL), CxtI(CXTI) {}
91
93 const DominatorTree *DT = nullptr,
94 AssumptionCache *AC = nullptr,
95 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
96 bool CanUseUndef = true, const DomConditionCache *DC = nullptr)
97 : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), DC(DC), IIQ(UseInstrInfo),
99
101 AssumptionCache *AC = nullptr,
102 const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
103 bool CanUseUndef = true)
104 : DL(DL), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
106
108 SimplifyQuery Copy(*this);
109 Copy.CxtI = I;
110 return Copy;
111 }
113 SimplifyQuery Copy(*this);
114 Copy.CanUseUndef = false;
115 return Copy;
116 }
117
118 /// If CanUseUndef is true, returns whether \p V is undef.
119 /// Otherwise always return false.
120 bool isUndefValue(Value *V) const;
121
123 SimplifyQuery Copy(*this);
124 Copy.DC = nullptr;
125 return Copy;
126 }
127
129 SimplifyQuery Copy(*this);
130 Copy.CC = &CC;
131 return Copy;
132 }
133};
134
135} // end namespace llvm
136
137#endif
#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:110
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Metadata node.
Definition: Metadata.h:1067
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:479
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Evaluate query assuming this condition holds.
Definition: SimplifyQuery.h:62
CondContext(Value *Cond)
Definition: SimplifyQuery.h:67
SmallPtrSet< Value *, 4 > AffectedValues
Definition: SimplifyQuery.h:65
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
Definition: SimplifyQuery.h:25
bool isExact(const BinaryOperator *Op) const
Definition: SimplifyQuery.h:48
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
Definition: SimplifyQuery.h:30
bool hasNoSignedZeros(const InstT *Op) const
Definition: SimplifyQuery.h:54
InstrInfoQuery(bool UMD)
Definition: SimplifyQuery.h:26
bool hasNoSignedWrap(const InstT *Op) const
Definition: SimplifyQuery.h:42
InstrInfoQuery()=default
bool hasNoUnsignedWrap(const InstT *Op) const
Definition: SimplifyQuery.h:36
const DataLayout & DL
Definition: SimplifyQuery.h:71
const Instruction * CxtI
Definition: SimplifyQuery.h:75
SimplifyQuery(const DataLayout &DL, const Instruction *CXTI=nullptr)
Definition: SimplifyQuery.h:89
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
Definition: SimplifyQuery.h:87
const DominatorTree * DT
Definition: SimplifyQuery.h:73
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:92
bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
AssumptionCache * AC
Definition: SimplifyQuery.h:74
const DomConditionCache * DC
Definition: SimplifyQuery.h:76
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:72
SimplifyQuery getWithoutUndef() const
const InstrInfoQuery IIQ
Definition: SimplifyQuery.h:82
SimplifyQuery getWithoutDomCondCache() const
const CondContext * CC
Definition: SimplifyQuery.h:77