LLVM: lib/Analysis/AssumeBundleQueries.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
18
19#define DEBUG_TYPE "assume-queries"
20
21using namespace llvm;
23
24STATISTIC(NumAssumeQueries, "Number of Queries into an assume assume bundles");
26 NumUsefullAssumeQueries,
27 "Number of Queries into an assume assume bundles that were satisfied");
28
29DEBUG_COUNTER(AssumeQueryCounter, "assume-queries-counter",
30 "Controls which assumes gets created");
31
33 return BOI.End - BOI.Begin > Idx;
34}
35
38 unsigned Idx) {
40 return (Assume.op_begin() + BOI.Begin + Idx)->get();
41}
42
46 "this attribute doesn't exist");
49 "requested value for an attribute that has no argument");
50 if (Assume.bundle_op_infos().empty())
51 return false;
52
53 for (auto &BOI : Assume.bundle_op_infos()) {
54 if (BOI.Tag->getKey() != AttrName)
55 continue;
56 if (IsOn && (BOI.End - BOI.Begin <= ABA_WasOn ||
58 continue;
59 if (ArgVal) {
61 *ArgVal =
63 ->getZExtValue();
64 }
65 return true;
66 }
67 return false;
68}
69
71 for (auto &Bundles : Assume.bundle_op_infos()) {
72 std::pair<Value *, Attribute::AttrKind> Key{
76
78 continue;
80 Result[Key][&Assume] = {0, 0};
81 continue;
82 }
85 if (!CI)
86 continue;
87 uint64_t Val = CI->getZExtValue();
88 auto [It, Inserted] = Result[Key].try_emplace(&Assume);
89 if (Inserted) {
90 It->second = {Val, Val};
91 continue;
92 }
93 auto &MinMax = It->second;
96 }
97}
98
104 return Result;
105
109 auto GetArgOr1 = [&](unsigned Idx) -> uint64_t {
112 return ConstInt->getZExtValue();
113 return 1;
114 };
116 Result.ArgValue = GetArgOr1(0);
119 : nullptr;
120 if (Result.AttrKind == Attribute::Alignment)
122 Result.ArgValue = MinAlign(Result.ArgValue, GetArgOr1(1));
123 return Result;
124}
125
131
133 return none_of(Assume.bundle_op_infos(),
135 return BOI.Tag->getKey() != IgnoreBundleTag;
136 });
137}
138
140 if ((U->getUser(),
142 return nullptr;
144 return &Intr->getBundleOpInfoForOperand(U->getOperandNo());
145}
146
151 if (!Bundle)
156 return RK;
158}
159
167 NumAssumeQueries++;
171 continue;
173 *II, II->bundle_op_info_begin()[Elem.Index])) {
174 if (V != RK.WasOn)
175 continue;
177 Filter(RK, II, &II->bundle_op_info_begin()[Elem.Index])) {
178 NumUsefullAssumeQueries++;
179 return RK;
180 }
181 }
182 }
183
185}
186
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static CallInst::BundleOpInfo * getBundleFromUse(const Use *U)
Definition AssumeBundleQueries.cpp:139
static Value * getValueFromBundleOpInfo(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI, unsigned Idx)
Definition AssumeBundleQueries.cpp:36
static bool bundleHasArgument(const CallBase::BundleOpInfo &BOI, unsigned Idx)
Definition AssumeBundleQueries.cpp:32
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
uint64_t IntrinsicInst * II
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This represents the llvm.assume intrinsic.
A cache of @llvm.assume calls within a function.
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.
static LLVM_ABI Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static LLVM_ABI bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
@ None
No attributes have been set.
static bool isIntAttrKind(AttrKind Kind)
static bool shouldExecute(CounterInfo &Counter)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
StringRef - Represent a constant reference to a string, i.e.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_IntrinsicIntrinsic::fabs(m_Value(X))
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
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...
Definition AssumeBundleQueries.cpp:161
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI RetainedKnowledge getKnowledgeFromOperandInAssume(AssumeInst &Assume, unsigned Idx)
Retreive the information help by Assume on the operand at index Idx.
Definition AssumeBundleQueries.cpp:126
auto cast_or_null(const Y &Val)
LLVM_ABI bool isAssumeWithEmptyBundle(const AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
Definition AssumeBundleQueries.cpp:132
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
LLVM_ABI RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI)
This extracts the Knowledge from an element of an operand bundle.
Definition AssumeBundleQueries.cpp:100
DenseMap< RetainedKnowledgeKey, Assume2KnowledgeMap > RetainedKnowledgeMap
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
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.
Definition AssumeBundleQueries.cpp:148
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
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...
Definition AssumeBundleQueries.cpp:187
LLVM_ABI bool hasAttributeInAssume(AssumeInst &Assume, Value *IsOn, StringRef AttrName, uint64_t *ArgVal=nullptr)
Query the operand bundle of an llvm.assume to find a single attribute of the specified kind applied o...
Definition AssumeBundleQueries.cpp:43
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result)
Insert into the map all the informations contained in the operand bundles of the llvm....
Definition AssumeBundleQueries.cpp:70
Used to keep track of an operand bundle.
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
uint32_t End
The index in the Use& vector where operands for this operand bundle ends.
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
Represent one information held inside an operand bundle of an llvm.assume.
Attribute::AttrKind AttrKind
static RetainedKnowledge none()