Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
12#include "llvm/ADT/SmallPtrSet.h"
13#include "llvm/IR/Operator.h"
14
15namespacellvm {
16
17classAssumptionCache;
18classDomConditionCache;
19classDominatorTree;
20classTargetLibraryInfo;
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.
25structInstrInfoQuery {
26InstrInfoQuery(bool UMD) :UseInstrInfo(UMD) {}
27InstrInfoQuery() =default;
28boolUseInstrInfo =true;
29
30MDNode *getMetadata(constInstruction *I,unsigned KindID) const{
31if (UseInstrInfo)
32returnI->getMetadata(KindID);
33returnnullptr;
34 }
35
36template <class InstT>boolhasNoUnsignedWrap(const InstT *Op) const{
37if (UseInstrInfo)
38returnOp->hasNoUnsignedWrap();
39returnfalse;
40 }
41
42template <class InstT>boolhasNoSignedWrap(const InstT *Op) const{
43if (UseInstrInfo)
44returnOp->hasNoSignedWrap();
45returnfalse;
46 }
47
48boolisExact(constBinaryOperator *Op) const{
49if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
50return cast<PossiblyExactOperator>(Op)->isExact();
51returnfalse;
52 }
53
54template <class InstT>boolhasNoSignedZeros(const InstT *Op) const{
55if (UseInstrInfo)
56returnOp->hasNoSignedZeros();
57returnfalse;
58 }
59};
60
61/// Evaluate query assuming this condition holds.
62structCondContext {
63Value *Cond;
64boolInvert =false;
65SmallPtrSet<Value *, 4>AffectedValues;
66
67CondContext(Value *Cond) :Cond(Cond) {}
68};
69
70structSimplifyQuery {
71constDataLayout &DL;
72constTargetLibraryInfo *TLI =nullptr;
73constDominatorTree *DT =nullptr;
74AssumptionCache *AC =nullptr;
75constInstruction *CxtI =nullptr;
76constDomConditionCache *DC =nullptr;
77constCondContext *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.
82constInstrInfoQueryIIQ;
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.
87boolCanUseUndef =true;
88
89SimplifyQuery(constDataLayout &DL,constInstruction *CXTI =nullptr)
90 :DL(DL),CxtI(CXTI) {}
91
92SimplifyQuery(constDataLayout &DL,constTargetLibraryInfo *TLI,
93constDominatorTree *DT =nullptr,
94AssumptionCache *AC =nullptr,
95constInstruction *CXTI =nullptr,bool UseInstrInfo =true,
96boolCanUseUndef =true,constDomConditionCache *DC =nullptr)
97 :DL(DL),TLI(TLI),DT(DT),AC(AC),CxtI(CXTI),DC(DC),IIQ(UseInstrInfo),
98CanUseUndef(CanUseUndef) {}
99
100SimplifyQuery(constDataLayout &DL,constDominatorTree *DT,
101AssumptionCache *AC =nullptr,
102constInstruction *CXTI =nullptr,bool UseInstrInfo =true,
103boolCanUseUndef =true)
104 :DL(DL),DT(DT),AC(AC),CxtI(CXTI),IIQ(UseInstrInfo),
105CanUseUndef(CanUseUndef) {}
106
107SimplifyQuerygetWithInstruction(constInstruction *I) const{
108SimplifyQuery Copy(*this);
109 Copy.CxtI =I;
110return Copy;
111 }
112SimplifyQuerygetWithoutUndef() const{
113SimplifyQuery Copy(*this);
114 Copy.CanUseUndef =false;
115return Copy;
116 }
117
118 /// If CanUseUndef is true, returns whether \p V is undef.
119 /// Otherwise always return false.
120boolisUndefValue(Value *V)const;
121
122SimplifyQuerygetWithoutDomCondCache() const{
123SimplifyQuery Copy(*this);
124 Copy.DC =nullptr;
125return Copy;
126 }
127
128SimplifyQuerygetWithCondContext(constCondContext &CC) const{
129SimplifyQuery Copy(*this);
130 Copy.CC = &CC;
131return Copy;
132 }
133
134SimplifyQuerygetWithoutCondContext() const{
135SimplifyQuery Copy(*this);
136 Copy.CC =nullptr;
137return Copy;
138 }
139};
140
141}// end namespace llvm
142
143#endif
Operator.h
I
#define I(x, y, z)
Definition:MD5.cpp:58
SmallPtrSet.h
This file defines the SmallPtrSet class.
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition:AssumptionCache.h:42
llvm::BinaryOperator
Definition:InstrTypes.h:170
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DomConditionCache
Definition:DomConditionCache.h:29
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition:Dominators.h:162
llvm::Instruction
Definition:Instruction.h:68
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition:TargetLibraryInfo.h:280
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::CondContext
Evaluate query assuming this condition holds.
Definition:SimplifyQuery.h:62
llvm::CondContext::CondContext
CondContext(Value *Cond)
Definition:SimplifyQuery.h:67
llvm::CondContext::Invert
bool Invert
Definition:SimplifyQuery.h:64
llvm::CondContext::AffectedValues
SmallPtrSet< Value *, 4 > AffectedValues
Definition:SimplifyQuery.h:65
llvm::CondContext::Cond
Value * Cond
Definition:SimplifyQuery.h:63
llvm::InstrInfoQuery
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
Definition:SimplifyQuery.h:25
llvm::InstrInfoQuery::isExact
bool isExact(const BinaryOperator *Op) const
Definition:SimplifyQuery.h:48
llvm::InstrInfoQuery::getMetadata
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
Definition:SimplifyQuery.h:30
llvm::InstrInfoQuery::hasNoSignedZeros
bool hasNoSignedZeros(const InstT *Op) const
Definition:SimplifyQuery.h:54
llvm::InstrInfoQuery::InstrInfoQuery
InstrInfoQuery(bool UMD)
Definition:SimplifyQuery.h:26
llvm::InstrInfoQuery::hasNoSignedWrap
bool hasNoSignedWrap(const InstT *Op) const
Definition:SimplifyQuery.h:42
llvm::InstrInfoQuery::UseInstrInfo
bool UseInstrInfo
Definition:SimplifyQuery.h:28
llvm::InstrInfoQuery::InstrInfoQuery
InstrInfoQuery()=default
llvm::InstrInfoQuery::hasNoUnsignedWrap
bool hasNoUnsignedWrap(const InstT *Op) const
Definition:SimplifyQuery.h:36
llvm::SimplifyQuery
Definition:SimplifyQuery.h:70
llvm::SimplifyQuery::DL
const DataLayout & DL
Definition:SimplifyQuery.h:71
llvm::SimplifyQuery::getWithoutCondContext
SimplifyQuery getWithoutCondContext() const
Definition:SimplifyQuery.h:134
llvm::SimplifyQuery::CxtI
const Instruction * CxtI
Definition:SimplifyQuery.h:75
llvm::SimplifyQuery::SimplifyQuery
SimplifyQuery(const DataLayout &DL, const Instruction *CXTI=nullptr)
Definition:SimplifyQuery.h:89
llvm::SimplifyQuery::CanUseUndef
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
Definition:SimplifyQuery.h:87
llvm::SimplifyQuery::DT
const DominatorTree * DT
Definition:SimplifyQuery.h:73
llvm::SimplifyQuery::getWithCondContext
SimplifyQuery getWithCondContext(const CondContext &CC) const
Definition:SimplifyQuery.h:128
llvm::SimplifyQuery::getWithInstruction
SimplifyQuery getWithInstruction(const Instruction *I) const
Definition:SimplifyQuery.h:107
llvm::SimplifyQuery::SimplifyQuery
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
llvm::SimplifyQuery::isUndefValue
bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
Definition:InstructionSimplify.cpp:7347
llvm::SimplifyQuery::AC
AssumptionCache * AC
Definition:SimplifyQuery.h:74
llvm::SimplifyQuery::DC
const DomConditionCache * DC
Definition:SimplifyQuery.h:76
llvm::SimplifyQuery::SimplifyQuery
SimplifyQuery(const DataLayout &DL, const DominatorTree *DT, AssumptionCache *AC=nullptr, const Instruction *CXTI=nullptr, bool UseInstrInfo=true, bool CanUseUndef=true)
Definition:SimplifyQuery.h:100
llvm::SimplifyQuery::TLI
const TargetLibraryInfo * TLI
Definition:SimplifyQuery.h:72
llvm::SimplifyQuery::getWithoutUndef
SimplifyQuery getWithoutUndef() const
Definition:SimplifyQuery.h:112
llvm::SimplifyQuery::IIQ
const InstrInfoQuery IIQ
Definition:SimplifyQuery.h:82
llvm::SimplifyQuery::getWithoutDomCondCache
SimplifyQuery getWithoutDomCondCache() const
Definition:SimplifyQuery.h:122
llvm::SimplifyQuery::CC
const CondContext * CC
Definition:SimplifyQuery.h:77

Generated on Thu Jul 17 2025 09:32:22 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp