LLVM 23.0.0git
AssumeBundleQueries.h
Go to the documentation of this file.
1//===- AssumeBundleQueries.h - utilis to query assume bundles ---*- 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// This file contain tools to query into assume bundles. assume bundles can be
10// built using utilities from Transform/Utils/AssumeBundleBuilder.h
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_ASSUMEBUNDLEQUERIES_H
15#define LLVM_ANALYSIS_ASSUMEBUNDLEQUERIES_H
16
17#include "llvm/ADT/DenseMap.h"
20
21namespace llvm {
22class AssumptionCache;
23class DominatorTree;
24class Instruction;
25
26/// Index of elements in the operand bundle.
27/// If the element exist it is guaranteed to be what is specified in this enum
28/// but it may not exist.
33
34template <> struct DenseMapInfo<Attribute::AttrKind> {
35 static unsigned getHashValue(Attribute::AttrKind AK) {
36 return hash_combine(AK);
37 }
39 return LHS == RHS;
40 }
41};
42
43/// The map Key contains the Value on for which the attribute is valid and
44/// the Attribute that is valid for that value.
45/// If the Attribute is not on any value, the Value is nullptr.
46using RetainedKnowledgeKey = std::pair<Value *, Attribute::AttrKind>;
47
52
53/// A mapping from intrinsics (=`llvm.assume` calls) to a value range
54/// (=knowledge) that is encoded in them. How the value range is interpreted
55/// depends on the RetainedKnowledgeKey that was used to get this out of the
56/// RetainedKnowledgeMap.
58
61
62/// Insert into the map all the informations contained in the operand bundles of
63/// the llvm.assume. This should be used when many queries are going to be made
64/// on the same llvm.assume. String attributes are not inserted in the map.
65/// If the IR changes the map will be outdated.
67 RetainedKnowledgeMap &Result);
68
69/// Represent one information held inside an operand bundle of an llvm.assume.
70/// AttrKind is the property that holds.
71/// WasOn if not null is that Value for which AttrKind holds.
72/// ArgValue is optionally an argument of the attribute.
73/// For example if we know that %P has an alignment of at least four:
74/// - AttrKind will be Attribute::Alignment.
75/// - WasOn will be %P.
76/// - ArgValue will be 4.
80 Value *IRArgValue = nullptr;
81 Value *WasOn = nullptr;
86 return AttrKind == Other.AttrKind && WasOn == Other.WasOn &&
87 ArgValue == Other.ArgValue && IRArgValue == Other.IRArgValue;
88 }
89 bool operator!=(RetainedKnowledge Other) const { return !(*this == Other); }
90 /// This is only intended for use in std::min/std::max between attribute that
91 /// only differ in ArgValue.
93 assert(((AttrKind == Other.AttrKind && WasOn == Other.WasOn) ||
94 AttrKind == Attribute::None || Other.AttrKind == Attribute::None) &&
95 "This is only intend for use in min/max to select the best for "
96 "RetainedKnowledge that is otherwise equal");
97 return ArgValue < Other.ArgValue;
98 }
99 operator bool() const { return AttrKind != Attribute::None; }
101};
102
103/// Tag in operand bundle indicating that this bundle should be ignored.
104constexpr StringRef IgnoreBundleTag = "ignore";
105
106/// Return true iff the operand bundles of the provided llvm.assume doesn't
107/// contain any valuable information. This is true when:
108/// - The operand bundle is empty
109/// - The operand bundle only contains information about dropped values or
110/// constant folded values.
111///
112/// the argument to the call of llvm.assume may still be useful even if the
113/// function returned true.
115
116/// Return a valid Knowledge associated to the Use U if its Attribute kind is
117/// in AttrKinds.
120
121/// Return a valid Knowledge associated to the Value V if its Attribute kind is
122/// in AttrKinds and it matches the Filter.
124 const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
125 AssumptionCache &AC,
127 const CallBase::BundleOpInfo *)>
128 Filter = [](auto...) { return true; });
129
130/// Return a valid Knowledge associated to the Value V if its Attribute kind is
131/// in AttrKinds and the knowledge is suitable to be used in the context of
132/// CtxI.
133LLVM_ABI RetainedKnowledge getKnowledgeValidInContext(
134 const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
135 AssumptionCache &AC, const Instruction *CtxI,
136 const DominatorTree *DT = nullptr);
137
138/// This extracts the Knowledge from an element of an operand bundle.
139/// This is mostly for use in the assume builder.
140LLVM_ABI RetainedKnowledge
141getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI);
142
143} // namespace llvm
144
145#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This represents the llvm.assume intrinsic.
A cache of @llvm.assume calls within a function.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
@ None
No attributes have been set.
Definition Attributes.h:126
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI RetainedKnowledge getKnowledgeForValue(const Value *V, ArrayRef< Attribute::AttrKind > AttrKinds, AssumptionCache &AC, function_ref< bool(RetainedKnowledge, Instruction *, const CallBase::BundleOpInfo *)> Filter=[](auto...) { return true;})
Return a valid Knowledge associated to the Value V if its Attribute kind is in AttrKinds and it match...
DenseMap< AssumeInst *, MinMax > Assume2KnowledgeMap
A mapping from intrinsics (=llvm.assume calls) to a value range (=knowledge) that is encoded in them.
constexpr StringRef IgnoreBundleTag
Tag in operand bundle indicating that this bundle should be ignored.
LLVM_ABI bool isAssumeWithEmptyBundle(const AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
LLVM_ABI RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI)
This extracts the Knowledge from an element of an operand bundle.
DenseMap< RetainedKnowledgeKey, Assume2KnowledgeMap > RetainedKnowledgeMap
LLVM_ABI RetainedKnowledge getKnowledgeFromUse(const Use *U, ArrayRef< Attribute::AttrKind > AttrKinds)
Return a valid Knowledge associated to the Use U if its Attribute kind is in AttrKinds.
std::pair< Value *, Attribute::AttrKind > RetainedKnowledgeKey
The map Key contains the Value on for which the attribute is valid and the Attribute that is valid fo...
LLVM_ABI RetainedKnowledge getKnowledgeValidInContext(const Value *V, ArrayRef< Attribute::AttrKind > AttrKinds, AssumptionCache &AC, const Instruction *CtxI, const DominatorTree *DT=nullptr)
Return a valid Knowledge associated to the Value V if its Attribute kind is in AttrKinds and the know...
@ Other
Any other memory.
Definition ModRef.h:68
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI void fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result)
Insert into the map all the informations contained in the operand bundles of the llvm....
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:305
AssumeBundleArg
Index of elements in the operand bundle.
Used to keep track of an operand bundle.
static unsigned getHashValue(Attribute::AttrKind AK)
static bool isEqual(Attribute::AttrKind LHS, Attribute::AttrKind RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Represent one information held inside an operand bundle of an llvm.assume.
Attribute::AttrKind AttrKind
RetainedKnowledge(Attribute::AttrKind AttrKind=Attribute::None, uint64_t ArgValue=0, Value *WasOn=nullptr)
static RetainedKnowledge none()
bool operator!=(RetainedKnowledge Other) const
bool operator==(RetainedKnowledge Other) const
bool operator<(RetainedKnowledge Other) const
This is only intended for use in std::min/stdmax between attribute that only differ in ArgValue.