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;
20class DominatorTree;
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 {
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.
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.
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.
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.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
Evaluate query assuming this condition holds.
CondContext(Value *Cond)
SmallPtrSet< Value *, 4 > AffectedValues
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
bool isExact(const BinaryOperator *Op) const
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
bool hasNoSignedZeros(const InstT *Op) const
bool hasNoSignedWrap(const InstT *Op) const
InstrInfoQuery()=default
bool hasNoUnsignedWrap(const InstT *Op) const
const DataLayout & DL
SimplifyQuery getWithoutCondContext() const
const Instruction * CxtI
SimplifyQuery(const DataLayout &DL, const Instruction *CXTI=nullptr)
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
const DominatorTree * DT
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)
LLVM_ABI bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
AssumptionCache * AC
const DomConditionCache * DC
SimplifyQuery(const DataLayout &DL, const DominatorTree *DT, AssumptionCache *AC=nullptr, const Instruction *CXTI=nullptr, bool UseInstrInfo=true, bool CanUseUndef=true)
const TargetLibraryInfo * TLI
SimplifyQuery getWithoutUndef() const
const InstrInfoQuery IIQ
SimplifyQuery getWithoutDomCondCache() const
const CondContext * CC