LLVM 24.0.0git
SLPUtils.cpp
Go to the documentation of this file.
1//===- SLPUtils.cpp - SLP Vectorizer free utility helpers -----------------===//
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#include "SLPUtils.h"
10
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/Sequence.h"
15#include "llvm/IR/Constants.h"
23
24#include <algorithm>
25#include <string>
26#include <type_traits>
27
28using namespace llvm;
29using namespace llvm::PatternMatch;
30
31namespace llvm::slpvectorizer {
32
36
38 auto *I = dyn_cast<Instruction>(V);
39 // Non-instructions are vector-like only if they are undef.
40 if (!I)
41 return isa<UndefValue>(V);
42 switch (I->getOpcode()) {
43 case Instruction::ExtractValue:
44 case Instruction::InsertValue:
45 return true;
46 case Instruction::ExtractElement:
47 return isa<FixedVectorType>(I->getOperand(0)->getType()) &&
48 isConstant(I->getOperand(1));
49 case Instruction::InsertElement:
50 return isa<FixedVectorType>(I->getOperand(0)->getType()) &&
51 isConstant(I->getOperand(2));
52 default:
53 return false;
54 }
55}
56
57unsigned getNumElements(Type *Ty) {
59 "ScalableVectorType is not supported.");
60 if (isVectorizedTy(Ty))
62 return 1;
63}
64
65unsigned getPartNumElems(unsigned Size, unsigned NumParts) {
66 return std::min<unsigned>(Size, bit_ceil(divideCeil(Size, NumParts)));
67}
68
69unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part) {
70 return std::min<unsigned>(PartNumElems, Size - Part * PartNumElems);
71}
72
73#if !defined(NDEBUG)
74std::string shortBundleName(ArrayRef<Value *> VL, int Idx) {
75 std::string Result;
76 raw_string_ostream OS(Result);
77 if (Idx >= 0)
78 OS << "Idx: " << Idx << ", ";
79 OS << "n=" << VL.size() << " [" << *VL.front() << ", ..]";
80 return Result;
81}
82#endif
83
85 auto *It = find_if(VL, IsaPred<Instruction>);
86 if (It == VL.end())
87 return false;
90 return true;
91
92 BasicBlock *BB = I0->getParent();
93 for (Value *V : iterator_range(It, VL.end())) {
94 if (isa<PoisonValue>(V))
95 continue;
96 auto *II = dyn_cast<Instruction>(V);
97 if (!II)
98 return false;
99
100 if (BB != II->getParent())
101 return false;
102 }
103 return true;
104}
105
107 // Constant expressions and globals can't be vectorized like normal integer/FP
108 // constants.
109 return all_of(VL, isConstant);
110}
111
113 Value *FirstNonUndef = nullptr;
114 for (Value *V : VL) {
115 if (isa<UndefValue>(V))
116 continue;
117 if (!FirstNonUndef) {
118 FirstNonUndef = V;
119 continue;
120 }
121 if (V != FirstNonUndef)
122 return false;
123 }
124 return FirstNonUndef != nullptr;
125}
126
127bool isCommutative(const Instruction *I, const Value *ValWithUses,
128 bool IsCopyable) {
129 if (auto *Cmp = dyn_cast<CmpInst>(I))
130 return Cmp->isCommutative();
131 if (auto *BO = dyn_cast<BinaryOperator>(I))
132 return BO->isCommutative() ||
133 (BO->getOpcode() == Instruction::Sub && ValWithUses->hasUseList() &&
134 !ValWithUses->hasNUsesOrMore(UsesLimit) &&
135 all_of(
136 ValWithUses->uses(),
137 [&](const Use &U) {
138 // Commutative, if icmp eq/ne sub, 0
139 CmpPredicate Pred;
140 if (match(U.getUser(),
141 m_ICmp(Pred, m_Specific(U.get()), m_Zero())) &&
142 (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE))
143 return true;
144 // Commutative, if abs(sub nsw, true) or abs(sub, false).
145 ConstantInt *Flag;
146 auto *I = dyn_cast<BinaryOperator>(U.get());
147 return match(U.getUser(),
148 m_Intrinsic<Intrinsic::abs>(
149 m_Specific(U.get()), m_ConstantInt(Flag))) &&
150 ((!IsCopyable && I && !I->hasNoSignedWrap()) ||
151 Flag->isOne());
152 })) ||
153 (BO->getOpcode() == Instruction::FSub && ValWithUses->hasUseList() &&
154 !ValWithUses->hasNUsesOrMore(UsesLimit) &&
155 all_of(ValWithUses->uses(), [](const Use &U) {
156 return match(U.getUser(),
157 m_Intrinsic<Intrinsic::fabs>(m_Specific(U.get())));
158 }));
159 return I->isCommutative();
160}
161
162bool isCommutative(const Instruction *I) { return isCommutative(I, I); }
163
164bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op,
165 bool IsCopyable) {
166 assert(isCommutative(I, ValWithUses, IsCopyable) &&
167 "The instruction is not commutative.");
168 if (isa<CmpInst>(I))
169 return true;
170 if (auto *BO = dyn_cast<BinaryOperator>(I)) {
171 switch (BO->getOpcode()) {
172 case Instruction::Sub:
173 case Instruction::FSub:
174 return true;
175 default:
176 break;
177 }
178 }
179 return I->isCommutableOperand(Op);
180}
181
184 // IntrinsicInst::isCommutative returns true if swapping the first "two"
185 // arguments to the intrinsic produces the same result.
186 constexpr unsigned IntrinsicNumOperands = 2;
187 return IntrinsicNumOperands;
188 }
189 return I->getNumOperands();
190}
191
192std::optional<unsigned> getElementIndex(const Value *Inst, unsigned Offset) {
193 if (auto Index = getInsertExtractIndex<InsertElementInst>(Inst, Offset))
194 return Index;
196 return Index;
197
198 unsigned Index = Offset;
199
200 const auto *IV = dyn_cast<InsertValueInst>(Inst);
201 if (!IV)
202 return std::nullopt;
203
204 Type *CurrentType = IV->getType();
205 for (unsigned I : IV->indices()) {
206 if (const auto *ST = dyn_cast<StructType>(CurrentType)) {
207 Index *= ST->getNumElements();
208 CurrentType = ST->getElementType(I);
209 } else if (const auto *AT = dyn_cast<ArrayType>(CurrentType)) {
210 Index *= AT->getNumElements();
211 CurrentType = AT->getElementType();
212 } else {
213 return std::nullopt;
214 }
215 Index += I;
216 }
217 return Index;
218}
219
221 auto *It = find_if(VL, IsaPred<Instruction>);
222 if (It == VL.end())
223 return true;
224 Instruction *MainOp = cast<Instruction>(*It);
225 unsigned Opcode = MainOp->getOpcode();
226 bool IsCmpOp = isa<CmpInst>(MainOp);
227 CmpInst::Predicate BasePred = IsCmpOp ? cast<CmpInst>(MainOp)->getPredicate()
229 return all_of(make_range(It, VL.end()), [&](Value *V) {
230 if (auto *CI = dyn_cast<CmpInst>(V))
231 return BasePred == CI->getPredicate();
232 if (auto *I = dyn_cast<Instruction>(V))
233 return I->getOpcode() == Opcode;
234 return isa<PoisonValue>(V);
235 });
236}
237
238std::optional<unsigned> getExtractIndex(const Instruction *E) {
239 unsigned Opcode = E->getOpcode();
240 assert((Opcode == Instruction::ExtractElement ||
241 Opcode == Instruction::ExtractValue) &&
242 "Expected extractelement or extractvalue instruction.");
243 if (Opcode == Instruction::ExtractElement) {
244 auto *CI = dyn_cast<ConstantInt>(E->getOperand(1));
245 if (!CI)
246 return std::nullopt;
247 // Check if the index is out of bound. We can get the source vector from
248 // operand 0.
249 unsigned Idx = CI->getZExtValue();
250 auto *EE = cast<ExtractElementInst>(E);
251 const unsigned VF = getNumElements(EE->getVectorOperandType());
252 if (Idx >= VF)
253 return std::nullopt;
254 return Idx;
255 }
256 auto *EI = cast<ExtractValueInst>(E);
257 if (EI->getNumIndices() != 1)
258 return std::nullopt;
259 return *EI->idx_begin();
260}
261
263 SmallVectorImpl<int> &Mask) {
264 Mask.clear();
265 const unsigned E = Indices.size();
266 Mask.resize(E, PoisonMaskElem);
267 for (unsigned I = 0; I < E; ++I)
268 Mask[Indices[I]] = I;
269}
270
272 assert(!Mask.empty() && "Expected non-empty mask.");
273 SmallVector<Value *> Prev(Scalars.size(),
274 PoisonValue::get(Scalars.front()->getType()));
275 Prev.swap(Scalars);
276 for (unsigned I = 0, E = Prev.size(); I < E; ++I)
277 if (Mask[I] != PoisonMaskElem)
278 Scalars[Mask[I]] = Prev[I];
279}
280
282 assert(!VL.empty() && "Expected non-empty list of values.");
283 Type *Ty = VL.consume_front()->getType();
284 return all_of(VL, [&](Value *V) { return V->getType() == Ty; });
285}
286
287template <typename T>
288std::optional<unsigned> getInsertExtractIndex(const Value *Inst,
289 unsigned Offset) {
290 static_assert(std::is_same_v<T, InsertElementInst> ||
291 std::is_same_v<T, ExtractElementInst>,
292 "unsupported T");
293 const auto *IE = dyn_cast<T>(Inst);
294 if (!IE)
295 return std::nullopt;
296 // InsertElement: result is the vector, index is op 2.
297 // ExtractElement: result is scalar, vector is op 0, index is op 1.
298 constexpr bool IsInsert = std::is_same_v<T, InsertElementInst>;
299 Type *VecTy = IsInsert ? IE->getType() : IE->getOperand(0)->getType();
300 const auto *VT = dyn_cast<FixedVectorType>(VecTy);
301 if (!VT)
302 return std::nullopt;
303 const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(IsInsert ? 2 : 1));
304 if (!CI)
305 return std::nullopt;
306 if (CI->getValue().uge(VT->getNumElements()))
307 return std::nullopt;
308 unsigned Index = Offset;
309 Index *= VT->getNumElements();
310 Index += CI->getZExtValue();
311 return Index;
312}
313
314// Only these two specializations are used; instantiate them here so the
315// definition can stay out of the header.
316template std::optional<unsigned>
318template std::optional<unsigned>
320
322 auto *I = dyn_cast<Instruction>(V);
323 if (!I)
324 return true;
325 return !mayHaveNonDefUseDependency(*I) &&
326 all_of(I->operands(), [I](Value *V) {
327 auto *IO = dyn_cast<Instruction>(V);
328 if (!IO)
329 return true;
330 return isa<PHINode>(IO) || IO->getParent() != I->getParent();
331 });
332}
333
335 auto *I = dyn_cast<Instruction>(V);
336 if (!I)
337 return true;
338 // Limits the number of uses to save compile time.
339 return !I->mayReadOrWriteMemory() && !I->hasNUsesOrMore(UsesLimit) &&
340 all_of(I->users(), [I](User *U) {
341 auto *IU = dyn_cast<Instruction>(U);
342 if (!IU)
343 return true;
344 return IU->getParent() != I->getParent() || isa<PHINode>(IU);
345 });
346}
347
351
356
357void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements,
358 SmallVectorImpl<int> &Mask) {
359 // The ShuffleBuilder implementation use shufflevector to splat an "element".
360 // But the element have different meaning for SLP (scalar) and REVEC
361 // (vector). We need to expand Mask into masks which shufflevector can use
362 // directly.
363 SmallVector<int> NewMask(Mask.size() * VecTyNumElements);
364 for (unsigned I : seq<unsigned>(Mask.size()))
365 for (auto [J, MaskV] : enumerate(MutableArrayRef(NewMask).slice(
366 I * VecTyNumElements, VecTyNumElements)))
367 MaskV = Mask[I] == PoisonMaskElem ? PoisonMaskElem
368 : Mask[I] * VecTyNumElements + J;
369 Mask.swap(NewMask);
370}
371
373 if (VL.empty())
374 return 0;
376 return 0;
377 auto *SV = cast<ShuffleVectorInst>(VL.front());
378 unsigned SVNumElements =
379 cast<FixedVectorType>(SV->getOperand(0)->getType())->getNumElements();
380 unsigned ShuffleMaskSize = SV->getShuffleMask().size();
381 if (SVNumElements % ShuffleMaskSize != 0)
382 return 0;
383 unsigned GroupSize = SVNumElements / ShuffleMaskSize;
384 if (GroupSize == 0 || (VL.size() % GroupSize) != 0)
385 return 0;
386 unsigned NumGroup = 0;
387 for (size_t I = 0, E = VL.size(); I != E; I += GroupSize) {
388 auto *SV = cast<ShuffleVectorInst>(VL[I]);
389 Value *Src = SV->getOperand(0);
390 ArrayRef<Value *> Group = VL.slice(I, GroupSize);
391 SmallBitVector ExpectedIndex(GroupSize);
392 if (!all_of(Group, [&](Value *V) {
393 auto *SV = cast<ShuffleVectorInst>(V);
394 // From the same source.
395 if (SV->getOperand(0) != Src)
396 return false;
397 int Index;
398 if (!SV->isExtractSubvectorMask(Index))
399 return false;
400 ExpectedIndex.set(Index / ShuffleMaskSize);
401 return true;
402 }))
403 return 0;
404 if (!ExpectedIndex.all())
405 return 0;
406 ++NumGroup;
407 }
408 assert(NumGroup == (VL.size() / GroupSize) && "Unexpected number of groups");
409 return NumGroup;
410}
411
413 assert(getShufflevectorNumGroups(VL) && "Not supported shufflevector usage.");
414 auto *SV = cast<ShuffleVectorInst>(VL.front());
415 unsigned SVNumElements =
416 cast<FixedVectorType>(SV->getOperand(0)->getType())->getNumElements();
417 SmallVector<int> Mask;
418 unsigned AccumulateLength = 0;
419 for (Value *V : VL) {
420 auto *SV = cast<ShuffleVectorInst>(V);
421 for (int M : SV->getShuffleMask())
422 Mask.push_back(M == PoisonMaskElem ? PoisonMaskElem
423 : AccumulateLength + M);
424 AccumulateLength += SVNumElements;
425 }
426 return Mask;
427}
428
430 SmallBitVector UseMask(VF, true);
431 for (auto [Idx, Value] : enumerate(Mask)) {
432 if (Value == PoisonMaskElem) {
433 if (MaskArg == UseMask::UndefsAsMask)
434 UseMask.reset(Idx);
435 continue;
436 }
437 if (MaskArg == UseMask::FirstArg && Value < VF)
438 UseMask.reset(Value);
439 else if (MaskArg == UseMask::SecondArg && Value >= VF)
440 UseMask.reset(Value - VF);
441 }
442 return UseMask;
443}
444
445template <bool IsPoisonOnly>
447 SmallBitVector Res(UseMask.empty() ? 1 : UseMask.size(), true);
448 using T = std::conditional_t<IsPoisonOnly, PoisonValue, UndefValue>;
449 if (isa<T>(V))
450 return Res;
451 auto *VecTy = dyn_cast<FixedVectorType>(V->getType());
452 if (!VecTy)
453 return Res.reset();
454 auto *C = dyn_cast<Constant>(V);
455 if (!C) {
456 if (!UseMask.empty()) {
457 const Value *Base = V;
458 while (auto *II = dyn_cast<InsertElementInst>(Base)) {
459 Base = II->getOperand(0);
460 if (isa<T>(II->getOperand(1)))
461 continue;
462 std::optional<unsigned> Idx = getElementIndex(II);
463 if (!Idx) {
464 Res.reset();
465 return Res;
466 }
467 if (*Idx < UseMask.size() && !UseMask.test(*Idx))
468 Res.reset(*Idx);
469 }
470 // TODO: Add analysis for shuffles here too.
471 if (V == Base) {
472 Res.reset();
473 } else {
474 SmallBitVector SubMask(UseMask.size(), false);
475 Res &= isUndefVector<IsPoisonOnly>(Base, SubMask);
476 }
477 } else {
478 Res.reset();
479 }
480 return Res;
481 }
482 for (unsigned I = 0, E = VecTy->getNumElements(); I != E; ++I) {
483 if (Constant *Elem = C->getAggregateElement(I))
484 if (!isa<T>(Elem) &&
485 (UseMask.empty() || (I < UseMask.size() && !UseMask.test(I))))
486 Res.reset(I);
487 }
488 return Res;
489}
490
492 const SmallBitVector &);
494 const SmallBitVector &);
495
498 const TargetTransformInfo *TTI) {
499 if (!UserInst)
500 return false;
501 unsigned Opcode = UserInst->getOpcode();
502 switch (Opcode) {
503 case Instruction::Load: {
504 LoadInst *LI = cast<LoadInst>(UserInst);
505 return (LI->getPointerOperand() == Scalar);
506 }
507 case Instruction::Store: {
508 StoreInst *SI = cast<StoreInst>(UserInst);
509 return (SI->getPointerOperand() == Scalar);
510 }
511 case Instruction::Call: {
512 CallInst *CI = cast<CallInst>(UserInst);
514 return any_of(enumerate(CI->args()), [&](auto &&Arg) {
515 return isVectorIntrinsicWithScalarOpAtArg(ID, Arg.index(), TTI) &&
516 Arg.value().get() == Scalar;
517 });
518 }
519 default:
520 return false;
521 }
522}
523
531
533 if (LoadInst *LI = dyn_cast<LoadInst>(I))
534 return LI->isSimple();
536 return SI->isSimple();
538 return !MI->isVolatile();
539 return true;
540}
541
543 bool ExtendingManyInputs) {
544 if (SubMask.empty())
545 return;
546 assert(
547 (!ExtendingManyInputs || SubMask.size() > Mask.size() ||
548 // Check if input scalars were extended to match the size of other node.
549 (SubMask.size() == Mask.size() && Mask.back() == PoisonMaskElem)) &&
550 "SubMask with many inputs support must be larger than the mask.");
551 if (Mask.empty()) {
552 Mask.append(SubMask.begin(), SubMask.end());
553 return;
554 }
555 SmallVector<int> NewMask(SubMask.size(), PoisonMaskElem);
556 int TermValue = std::min(Mask.size(), SubMask.size());
557 for (int I = 0, E = SubMask.size(); I < E; ++I) {
558 if (SubMask[I] == PoisonMaskElem ||
559 (!ExtendingManyInputs &&
560 (SubMask[I] >= TermValue || Mask[SubMask[I]] >= TermValue)))
561 continue;
562 NewMask[I] = Mask[SubMask[I]];
563 }
564 Mask.swap(NewMask);
565}
566
568 const size_t Sz = Order.size();
569 SmallBitVector UnusedIndices(Sz, /*t=*/true);
570 SmallBitVector MaskedIndices(Sz);
571 for (unsigned I = 0; I < Sz; ++I) {
572 if (Order[I] < Sz)
573 UnusedIndices.reset(Order[I]);
574 else
575 MaskedIndices.set(I);
576 }
577 if (MaskedIndices.none())
578 return;
579 assert(UnusedIndices.count() == MaskedIndices.count() &&
580 "Non-synced masked/available indices.");
581 int Idx = UnusedIndices.find_first();
582 int MIdx = MaskedIndices.find_first();
583 while (MIdx >= 0) {
584 assert(Idx >= 0 && "Indices must be synced.");
585 Order[MIdx] = Idx;
586 Idx = UnusedIndices.find_next(Idx);
587 MIdx = MaskedIndices.find_next(MIdx);
588 }
589}
590
592 unsigned Opcode0, unsigned Opcode1) {
593 unsigned ScalarTyNumElements = getNumElements(ScalarTy);
594 SmallBitVector OpcodeMask(VL.size() * ScalarTyNumElements, false);
595 for (unsigned Lane : seq<unsigned>(VL.size())) {
596 if (isa<PoisonValue>(VL[Lane]))
597 continue;
598 if (cast<Instruction>(VL[Lane])->getOpcode() == Opcode1)
599 OpcodeMask.set(Lane * ScalarTyNumElements,
600 Lane * ScalarTyNumElements + ScalarTyNumElements);
601 }
602 return OpcodeMask;
603}
604
606 assert(none_of(Val, [](Constant *C) { return C->getType()->isVectorTy(); }) &&
607 "Expected scalar constants.");
608 SmallVector<Constant *> NewVal(Val.size() * VF);
609 for (auto [I, V] : enumerate(Val))
610 std::fill_n(NewVal.begin() + I * VF, VF, V);
611 return NewVal;
612}
613
614} // namespace llvm::slpvectorizer
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
#define T
uint64_t IntrinsicInst * II
This file contains some templates that are useful if you are working with the STL at all.
Provides some synthesis utilities to produce sequences of values.
static const uint32_t IV[8]
Definition blake3_impl.h:83
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
const T & front() const
Get the first element.
Definition ArrayRef.h:144
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:185
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:156
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
This is an important base class in LLVM.
Definition Constant.h:43
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
An instruction for reading from memory.
Value * getPointerOperand()
This is the common base class for memset/memcpy/memmove.
Representation for a specific memory location.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
SmallBitVector & set()
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
bool all() const
Returns true if all bits are set.
size_type count() const
Returns the number of bits which are set.
SmallBitVector & reset()
bool none() const
Returns true if none of the bits are set.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void swap(SmallVectorImpl &RHS)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
bool hasUseList() const
Check if this Value has a use-list.
Definition Value.h:344
LLVM_ABI bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
Definition Value.cpp:155
iterator_range< use_iterator > uses()
Definition Value.h:380
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
const ParentTy * getParent() const
Definition ilist_node.h:34
A raw_ostream that writes to an std::string.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
A private "module" namespace for types and utilities used by this pass.
std::optional< unsigned > getExtractIndex(const Instruction *E)
Definition SLPUtils.cpp:238
template SmallBitVector isUndefVector< true >(const Value *, const SmallBitVector &)
bool areAllOperandsNonInsts(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:321
std::optional< unsigned > getElementIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:192
bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst, TargetLibraryInfo *TLI, const TargetTransformInfo *TTI)
Definition SLPUtils.cpp:496
MemoryLocation getLocation(Instruction *I)
Definition SLPUtils.cpp:524
SmallBitVector getAltInstrMask(ArrayRef< Value * > VL, Type *ScalarTy, unsigned Opcode0, unsigned Opcode1)
Definition SLPUtils.cpp:591
SmallBitVector isUndefVector(const Value *V, const SmallBitVector &UseMask)
Checks if the given value is actually an undefined constant vector.
Definition SLPUtils.cpp:446
bool isUsedOutsideBlock(Value *V)
Checks if the provided value does not require scheduling.
Definition SLPUtils.cpp:334
bool doesNotNeedToSchedule(ArrayRef< Value * > VL)
Checks if the specified array of instructions does not require scheduling.
Definition SLPUtils.cpp:352
std::optional< unsigned > getInsertExtractIndex(const Value *Inst, unsigned Offset)
Definition SLPUtils.cpp:288
void reorderScalars(SmallVectorImpl< Value * > &Scalars, ArrayRef< int > Mask)
Reorders the list of scalars in accordance with the given Mask.
Definition SLPUtils.cpp:271
bool allSameType(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:281
bool allSameOpcode(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:220
bool isSplat(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:112
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:57
std::string shortBundleName(ArrayRef< Value * > VL, int Idx)
Print a short descriptor of the instruction bundle suitable for debug output.
Definition SLPUtils.cpp:74
unsigned getPartNumElems(unsigned Size, unsigned NumParts)
Returns power-of-2 number of elements in a single register (part), given the total number of elements...
Definition SLPUtils.cpp:65
bool isCommutableOperand(const Instruction *I, Value *ValWithUses, unsigned Op, bool IsCopyable)
Checks if the operand is commutative.
Definition SLPUtils.cpp:164
void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements, SmallVectorImpl< int > &Mask)
Definition SLPUtils.cpp:357
SmallVector< int > calculateShufflevectorMask(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:412
SmallBitVector buildUseMask(int VF, ArrayRef< int > Mask, UseMask MaskArg)
Prepares a use bitset for the given mask either for the first argument or for the second.
Definition SLPUtils.cpp:429
bool isCommutative(const Instruction *I, const Value *ValWithUses, bool IsCopyable)
Definition SLPUtils.cpp:127
template SmallBitVector isUndefVector< false >(const Value *, const SmallBitVector &)
unsigned getNumberOfPotentiallyCommutativeOps(Instruction *I)
Definition SLPUtils.cpp:182
bool allConstant(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:106
template std::optional< unsigned > getInsertExtractIndex< InsertElementInst >(const Value *, unsigned)
void inversePermutation(ArrayRef< unsigned > Indices, SmallVectorImpl< int > &Mask)
Compute the inverse permutation Mask of Indices.
Definition SLPUtils.cpp:262
bool allSameBlock(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:84
UseMask
Specifies the way the mask should be analyzed for undefs/poisonous elements in the shuffle mask.
Definition SLPUtils.h:214
@ SecondArg
The mask is expected to be for permutation of 2 vectors, check for the mask elements for the second a...
Definition SLPUtils.h:218
@ UndefsAsMask
Consider undef mask elements (-1) as placeholders for future shuffle elements and mark them as ones a...
Definition SLPUtils.h:221
@ FirstArg
The mask is expected to be for permutation of 1-2 vectors, check for the mask elements for the first ...
Definition SLPUtils.h:215
void addMask(SmallVectorImpl< int > &Mask, ArrayRef< int > SubMask, bool ExtendingManyInputs)
Shuffles Mask in accordance with the given SubMask.
Definition SLPUtils.cpp:542
bool isSimple(Instruction *I)
Definition SLPUtils.cpp:532
unsigned getShufflevectorNumGroups(ArrayRef< Value * > VL)
Definition SLPUtils.cpp:372
SmallVector< Constant * > replicateMask(ArrayRef< Constant * > Val, unsigned VF)
Replicates the given Val VF times.
Definition SLPUtils.cpp:605
bool isVectorLikeInstWithConstOps(Value *V)
Checks if V is one of vector-like instructions, i.e.
Definition SLPUtils.cpp:37
bool doesNotNeedToBeScheduled(Value *V)
Checks if the specified value does not require scheduling.
Definition SLPUtils.cpp:348
unsigned getNumElems(unsigned Size, unsigned PartNumElems, unsigned Part)
Returns correct remaining number of elements, considering total amount Size, (power-of-2 number) of e...
Definition SLPUtils.cpp:69
constexpr int UsesLimit
Limit of the number of uses for potentially transformed instructions/values, used in checks to avoid ...
Definition SLPUtils.h:40
bool isConstant(Value *V)
Definition SLPUtils.cpp:33
template std::optional< unsigned > getInsertExtractIndex< ExtractElementInst >(const Value *, unsigned)
void fixupOrderingIndices(MutableArrayRef< unsigned > Order)
Order may have elements assigned special value (size) which is out of bounds.
Definition SLPUtils.cpp:567
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
LLVM_ABI Intrinsic::ID getVectorIntrinsicIDForCall(const CallInst *CI, const TargetLibraryInfo *TLI)
Returns intrinsic ID for call.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isVectorizedTy(Type *Ty)
Returns true if Ty is a vector type or a struct of vector types where all vector types share the same...
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
Definition bit.h:362
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
ElementCount getVectorizedTypeVF(Type *Ty)
Returns the number of vector elements for a vectorized type.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1753
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:547
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
constexpr int PoisonMaskElem
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
Definition MathExtras.h:395
TargetTransformInfo TTI
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1772
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
LLVM_ABI bool mayHaveNonDefUseDependency(const Instruction &I)
Returns true if the result or effects of the given instructions I depend values not reachable through...
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866