LLVM 24.0.0git
VecUtils.h
Go to the documentation of this file.
1//===- VecUtils.h -----------------------------------------------*- 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// Collector for SandboxVectorizer related convenience functions that don't
10// belong in other classes.
11
12#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
13#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
14
15#include "llvm/ADT/DenseSet.h"
17#include "llvm/IR/DataLayout.h"
18#include "llvm/SandboxIR/Type.h"
21#include <iterator>
22
23namespace llvm {
24/// Traits for DenseMap.
25template <> struct DenseMapInfo<SmallVector<sandboxir::Value *>> {
26 static unsigned getHashValue(const SmallVector<sandboxir::Value *> &Vec) {
27 return hash_combine_range(Vec);
28 }
31 return Vec1 == Vec2;
32 }
33};
34
35namespace sandboxir {
36
37/// An ArrayRef of Values or Instructions that we can print/dump for debugging.
38/// It is mainly used for the vectorizer's instr/value bundles.
39template <typename T> class BndlRef : public ArrayRef<T> {
40public:
41 // Inherit constructors.
42 using ArrayRef<T>::ArrayRef;
43
44#ifndef NDEBUG
45 /// Helper dump function for debugging.
46 void print(raw_ostream &OS) const {
47 for (const auto &[Idx, Val] : enumerate(*this))
48 OS << Idx << ". " << *Val << "\n";
49 }
50 LLVM_DUMP_METHOD void dump() const;
51#endif // NDEBUG
52};
53
54/// @name BndlRef Deduction guides
55/// @{
56/// Deduction guide to construct a BndlRef from a single element.
57template <typename T> BndlRef(const T &OneElt) -> BndlRef<T>;
58/// Deduction guide to construct a BndlRef from a pointer and length
59template <typename T> BndlRef(const T *data, size_t length) -> BndlRef<T>;
60/// Deduction guide to construct a BndlRef from a range
61template <typename T> BndlRef(const T *data, const T *end) -> BndlRef<T>;
62/// Deduction guide to construct a BndlRef from a SmallVector
63template <typename T> BndlRef(const SmallVectorImpl<T> &Vec) -> BndlRef<T>;
64/// Deduction guide to construct a BndlRef from a SmallVector
65template <typename T, unsigned N>
67/// Deduction guide to construct a BndlRef from a std::vector
68template <typename T> BndlRef(const std::vector<T> &Vec) -> BndlRef<T>;
69/// Deduction guide to construct a BndlRef from a std::array
70template <typename T, std::size_t N>
71BndlRef(const std::array<T, N> &Vec) -> BndlRef<T>;
72/// Deduction guide to construct a BndlRef from an BndlRef (const)
73template <typename T> BndlRef(const BndlRef<T> &Vec) -> BndlRef<T>;
74/// Deduction guide to construct a BndlRef from an BndlRef
75template <typename T> BndlRef(BndlRef<T> &Vec) -> BndlRef<T>;
76/// Deduction guide to construct a BndlRef from a C array.
77template <typename T, size_t N> BndlRef(const T (&Arr)[N]) -> BndlRef<T>;
78/// @}
79
80class InstrMaps;
81
83
84class VecUtils {
85public:
86 /// \Returns the number of elements in \p Ty. That is the number of lanes if a
87 /// fixed vector or 1 if scalar. ScalableVectors have unknown size and
88 /// therefore are unsupported.
89 static int getNumElements(Type *Ty) {
91 return Ty->isVectorTy() ? cast<FixedVectorType>(Ty)->getNumElements() : 1;
92 }
93 /// Returns \p Ty if scalar or its element type if vector.
94 static Type *getElementType(Type *Ty) {
95 return Ty->isVectorTy() ? cast<FixedVectorType>(Ty)->getElementType() : Ty;
96 }
97
98 /// \Returns true if \p I1 and \p I2 are load/stores accessing consecutive
99 /// memory addresses.
100 template <typename LoadOrStoreT>
101 static bool areConsecutive(LoadOrStoreT *I1, LoadOrStoreT *I2,
102 ScalarEvolution &SE, const DataLayout &DL) {
103 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
104 std::is_same<LoadOrStoreT, StoreInst>::value,
105 "Expected Load or Store!");
106 auto Diff = Utils::getPointerDiffInBytes(I1, I2, SE);
107 if (!Diff)
108 return false;
109 int ElmBytes = Utils::getNumBits(I1) / 8;
110 return *Diff == ElmBytes;
111 }
112
113 template <typename LoadOrStoreT, typename ValT>
115 const DataLayout &DL) {
116 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
117 std::is_same<LoadOrStoreT, StoreInst>::value,
118 "Expected Load or Store!");
119 assert(isa<LoadOrStoreT>(Bndl[0]) && "Expected Load or Store!");
120 auto *LastLS = cast<LoadOrStoreT>(Bndl[0]);
121 for (Value *V : drop_begin(Bndl)) {
123 "Unimplemented: we only support StoreInst!");
124 auto *LS = cast<LoadOrStoreT>(V);
125 if (!VecUtils::areConsecutive(LastLS, LS, SE, DL))
126 return false;
127 LastLS = LS;
128 }
129 return true;
130 }
131
132 /// \Returns the number of vector lanes of \p Ty or 1 if not a vector.
133 /// NOTE: It asserts that \p Ty is a fixed vector type.
134 static unsigned getNumLanes(Type *Ty) {
135 assert(!isa<ScalableVectorType>(Ty) && "Expect scalar or fixed vector");
136 if (auto *FixedVecTy = dyn_cast<FixedVectorType>(Ty))
137 return FixedVecTy->getNumElements();
138 return 1u;
139 }
140
141 /// \Returns the expected vector lanes of \p V or 1 if not a vector.
142 /// NOTE: It asserts that \p V is a fixed vector.
143 static unsigned getNumLanes(Value *V) {
145 }
146
147 /// \Returns the total number of lanes across all values in \p Bndl.
148 static unsigned getNumLanes(ArrayRef<Value *> Bndl) {
149 unsigned Lanes = 0;
150 for (Value *V : Bndl)
151 Lanes += getNumLanes(V);
152 return Lanes;
153 }
154
155 /// \Returns <NumElts x ElemTy>.
156 /// It works for both scalar and vector \p ElemTy.
157 static Type *getWideType(Type *ElemTy, unsigned NumElts) {
158 if (ElemTy->isVectorTy()) {
159 auto *VecTy = cast<FixedVectorType>(ElemTy);
160 ElemTy = VecTy->getElementType();
161 NumElts = VecTy->getNumElements() * NumElts;
162 }
163 return FixedVectorType::get(ElemTy, NumElts);
164 }
165 /// \Returns the combined vector type for \p Bndl, even when the element types
166 /// differ. For example: i8,i8,i16 will return <4 x i8>. \Returns null if
167 /// types are of mixed float/integer types.
168 template <typename T>
170 const DataLayout &DL) {
171 assert(!Bndl.empty() && "Expected non-empty Bndl!");
172 unsigned TotalBits = 0;
173 unsigned MinElmBits = std::numeric_limits<unsigned>::max();
174 Type *MinElmTy = nullptr;
175 for (T *V : Bndl) {
177
178 unsigned ElmBits = Utils::getNumBits(ElmTy, DL);
179 TotalBits += ElmBits * VecUtils::getNumLanes(V);
180 if (ElmBits < MinElmBits) {
181 MinElmBits = ElmBits;
182 MinElmTy = ElmTy;
183 }
184 }
185 unsigned NumElms = TotalBits / MinElmBits;
186 return FixedVectorType::get(MinElmTy, NumElms);
187 }
188
189 static Type *getCombinedVectorTypeFor(std::initializer_list<Value *> Bndl,
190 const DataLayout &DL) {
192 }
193 /// \Returns the instruction in \p Instrs that is lowest in the BB. Expects
194 /// that all instructions are in the same BB.
196 Instruction *LowestI = Instrs.front();
197 for (auto *I : drop_begin(Instrs)) {
198 if (LowestI->comesBefore(I))
199 LowestI = I;
200 }
201 return LowestI;
202 }
203 /// \Returns the instruction in \p Instrs that is highest in the BB. Expects
204 /// that all instructions are in the same BB.
206 Instruction *HighestI = Instrs.front();
207 for (auto *I : drop_begin(Instrs)) {
208 if (I->comesBefore(HighestI))
209 HighestI = I;
210 }
211 return HighestI;
212 }
213 /// \Returns the lowest instruction in \p Vals, or nullptr if no instructions
214 /// are found. Skips instructions not in \p BB.
216 // Find the first Instruction in Vals that is also in `BB`.
217 auto It = find_if(Vals, [BB](Value *V) {
218 return isa<Instruction>(V) && cast<Instruction>(V)->getParent() == BB;
219 });
220 // If we couldn't find an instruction return nullptr.
221 if (It == Vals.end())
222 return nullptr;
223 Instruction *FirstI = cast<Instruction>(*It);
224 // Now look for the lowest instruction in Vals starting from one position
225 // after FirstI.
226 Instruction *LowestI = FirstI;
227 for (auto *V : make_range(std::next(It), Vals.end())) {
228 auto *I = dyn_cast<Instruction>(V);
229 // Skip non-instructions.
230 if (I == nullptr)
231 continue;
232 // Skips instructions not in \p BB.
233 if (I->getParent() != BB)
234 continue;
235 // If `LowestI` comes before `I` then `I` is the new lowest.
236 if (LowestI->comesBefore(I))
237 LowestI = I;
238 }
239 return LowestI;
240 }
241
242 /// If \p I is not a PHI it returns it. Else it walks down the instruction
243 /// chain looking for the last PHI and returns it. \Returns nullptr if \p I is
244 /// nullptr.
246 Instruction *LastI = I;
247 while (I != nullptr && isa<PHINode>(I)) {
248 LastI = I;
249 I = I->getNextNode();
250 }
251 return LastI;
252 }
253
254 /// \Returns the BB iterator after the lowest instruction in \p Vals
255 /// (skipping instructions not in \p BB), or the top of BB if no
256 /// instruction found in \p Vals.
258 BasicBlock *BB) {
259 auto *BotI = getLastPHIOrSelf(getLowest(Vals, BB));
260 if (BotI == nullptr)
261 // We are using BB->begin() (or after PHIs) as the fallback insert point.
262 return BB->empty()
263 ? BB->begin()
264 : std::next(getLastPHIOrSelf(&*BB->begin())->getIterator());
265 return std::next(BotI->getIterator());
266 }
267
268 /// If all values in \p Bndl are of the same scalar type then return it,
269 /// otherwise return nullptr.
271 Value *V0 = Bndl[0];
272 Type *Ty0 = Utils::getExpectedType(V0);
273 Type *ScalarTy = VecUtils::getElementType(Ty0);
274 for (auto *V : drop_begin(Bndl)) {
276 Type *NScalarTy = VecUtils::getElementType(NTy);
277 if (NScalarTy != ScalarTy)
278 return nullptr;
279 }
280 return ScalarTy;
281 }
282
283 /// Similar to tryGetCommonScalarType() but will assert that there is a common
284 /// type. So this is faster in release builds as it won't iterate through the
285 /// values.
287 Value *V0 = Bndl[0];
288 Type *Ty0 = Utils::getExpectedType(V0);
289 Type *ScalarTy = VecUtils::getElementType(Ty0);
290 assert(tryGetCommonScalarType(Bndl) && "Expected common scalar type!");
291 return ScalarTy;
292 }
293 /// \Returns the first integer power of 2 that is <= Num.
294 LLVM_ABI static unsigned getFloorPowerOf2(unsigned Num);
295
296 /// For each user of lane 0 in \p Bndl, try to form a bundle of matching
297 /// users for all lanes. Returns all complete user bundles found.
298 /// \p Claimed contains instructions that have already been claimed by a
299 /// bundle.
303
304 /// Helper struct for `matchPack()`. Describes the instructions and operands
305 /// of a pack pattern.
306 struct PackPattern {
307 /// The insertelement instructions that form the pack pattern in bottom-up
308 /// order, i.e., the first instruction in `Instrs` is the bottom-most
309 /// InsertElement instruction of the pack pattern.
310 /// For example in this simple pack pattern:
311 /// %Pack0 = insertelement <2 x i8> poison, i8 %v0, i64 0
312 /// %Pack1 = insertelement <2 x i8> %Pack0, i8 %v1, i64 1
313 /// this is [ %Pack1, %Pack0 ].
315 /// The "external" operands of the pack pattern, i.e., the values that get
316 /// packed into a vector, skipping the ones in `Instrs`. The operands are in
317 /// bottom-up order, starting from the operands of the bottom-most insert.
318 /// So in our example this would be [ %v1, %v0 ].
320 };
321
322 /// If \p I is the last instruction of a pack pattern (i.e., an InsertElement
323 /// into a vector), then this function returns the instructions in the pack
324 /// and the operands in the pack, else returns nullopt.
325 /// Here is an example of a matched pattern:
326 /// %PackA0 = insertelement <2 x i8> poison, i8 %v0, i64 0
327 /// %PackA1 = insertelement <2 x i8> %PackA0, i8 %v1, i64 1
328 /// TODO: this currently detects only simple canonicalized patterns.
329 static std::optional<PackPattern> matchPack(Instruction *I) {
330 // TODO: Support vector pack patterns.
331 // TODO: Support out-of-order inserts.
332
333 // Early return if `I` is not an Insert.
335 return std::nullopt;
336 auto *BB0 = I->getParent();
337 // The pack contains as many instrs as the lanes of the bottom-most Insert
338 unsigned ExpectedNumInserts = VecUtils::getNumLanes(I);
339 assert(ExpectedNumInserts >= 2 && "Expected at least 2 inserts!");
341 Pack.Operands.resize(ExpectedNumInserts);
342 // Collect the inserts by walking up the use-def chain.
343 Instruction *InsertI = I;
344 for (auto ExpectedLane : reverse(seq<unsigned>(ExpectedNumInserts))) {
345 if (InsertI == nullptr)
346 return std::nullopt;
347 if (InsertI->getParent() != BB0)
348 return std::nullopt;
349 // Check the lane.
350 auto *LaneC = dyn_cast<ConstantInt>(InsertI->getOperand(2));
351 if (LaneC == nullptr || LaneC->getSExtValue() != ExpectedLane)
352 return std::nullopt;
353 Pack.Instrs.push_back(InsertI);
354 Pack.Operands[ExpectedLane] = InsertI->getOperand(1);
355
356 Value *Op = InsertI->getOperand(0);
357 if (ExpectedLane == 0) {
358 // Check the topmost insert. The operand should be a Poison.
359 if (!isa<PoisonValue>(Op))
360 return std::nullopt;
361 } else {
363 }
364 }
365 return Pack;
366 }
367
368 /// Emits the necessary instruction sequence to extract element of type \p
369 /// ExtrTy at \p Lane from \p FromVec. Emits instructions before \p WhereIt.
370 /// Returns the extracted value.
371 /// Note: This handles both vectors and scalars. In the vector case it
372 /// extracts an N-wide element (with N dictated by \p ExtrTy).
373 static Value *unpack(Value *FromVec, Type *ExtrTy, unsigned Lane,
374 BasicBlock::iterator WhereIt) {
375 assert(isa<FixedVectorType>(FromVec->getType()) && "Expected vector!");
376 auto &Ctx = FromVec->getContext();
377 if (!ExtrTy->isVectorTy()) {
378 // For scalar elements we emit a single ExtractElementInst.
379 assert(Lane <
380 cast<FixedVectorType>(FromVec->getType())->getNumElements() &&
381 "Out of bounds!");
382 assert(ExtrTy ==
383 cast<FixedVectorType>(FromVec->getType())->getElementType() &&
384 "Expected same element type!");
385 Constant *ExtractLaneC =
387 // Note: This may be folded into a Constant if FromVec is a Constant.
388 return ExtractElementInst::create(FromVec, ExtractLaneC, WhereIt, Ctx,
389 "Unpack");
390 }
391 // For vector elements we emit a shuffle.
392 // For example, extracting lanes 2 and 3 of a <4 x i32> vector %vec:
393 // shufflevector <4 x i32> %vec, <4 x i32> poison, <2 x i32> <i32 2, i32 3>
394 auto *VecTy = cast<FixedVectorType>(FromVec->getType());
395 auto *ExtrVecTy = cast<FixedVectorType>(ExtrTy);
396 assert(ExtrVecTy->getElementType() == VecTy->getElementType() &&
397 "Expected same element type!");
399 for (unsigned Idx = 0, E = ExtrVecTy->getNumElements(); Idx != E; ++Idx) {
400 int MaskLane = Lane + Idx;
401 assert((unsigned)MaskLane <
402 cast<FixedVectorType>(FromVec->getType())->getNumElements() &&
403 "Out of bounds!");
404 Mask.push_back(MaskLane);
405 }
406 return ShuffleVectorInst::create(FromVec, PoisonValue::get(VecTy), Mask,
407 WhereIt, Ctx, "Unpack");
408 }
409
410 /// Iterate over all lanes and Value pairs.
411 // For example, given a range: {i32 %v0, <2 x i32> %v1, i32 %v2} we get:
412 // Lane Elm
413 // 0 %v0
414 // 1 %v1
415 // 3 %v2
416 template <typename RangeIteratorT> class LaneValueEnumerator {
417 /// Points to current element.
418 RangeIteratorT It;
419 RangeIteratorT ItE;
420 /// Accumulator of lanes.
421 unsigned Lane;
422
423 public:
424 // Note that We can start counting from a non-zero BeginLane, though the
425 // user must make sure it corresponds to the correct lane matching Begin.
426 LaneValueEnumerator(RangeIteratorT Begin, RangeIteratorT End,
427 unsigned BeginLane)
428 : It(Begin), ItE(End), Lane(BeginLane) {}
429 using iterator_catecotry = std::input_iterator_tag;
430 // NOTE: dereference returns by value instead of by reference.
431 using value_type = std::pair<unsigned, Value *>;
432 using difference_type = std::ptrdiff_t;
433 using pointer = std::pair<unsigned, Value *> *;
434 using reference = std::pair<unsigned, Value *> &;
436 assert(It != ItE && "Already at end!");
437 auto *Ty = Utils::getExpectedType(*It);
438 if (auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
439 Lane += VecTy->getNumElements();
440 } else {
441 assert(!isa<VectorType>(Ty) && "Expected scalar type!");
442 Lane += 1;
443 }
444 ++It;
445 return *this;
446 }
447 value_type operator*() const { return {Lane, *It}; }
449 return It == Other.It;
450 }
452 return !(*this == Other);
453 }
454 };
455
456 /// Utility class to collect and erase dead instructions.
458 public:
461
462 /// Record instructions in \p Bndl that may be dead after vectorization.
463 /// For load/store bundles, also record non-first-lane pointer operands;
464 /// the first lane's pointer is skipped because the vector load/store
465 /// reuses it. Erased later by \c tryEraseDeadInstrs().
466 template <typename T> void collectPotentiallyDeadInstrs(BndlRef<T *> Bndl);
467
468 /// Erase candidates recorded by \c collectPotentiallyDeadInstrs() that
469 /// now have no uses, then clear the candidate set.
471
472#ifndef NDEBUG
473 void print(raw_ostream &OS) const {
474 OS << "DeadInstrCandidates:\n";
475 for (auto *I : DeadInstrCandidates)
476 OS << *I << '\n';
477 }
478 LLVM_DUMP_METHOD void debug() const {
479 print(dbgs());
480 dbgs() << '\n';
481 }
482#endif /* NDEBUG */
483
484 private:
485 DenseSet<Instruction *> DeadInstrCandidates;
486 };
487
488 /// Helper for creating LaneValueEnumerator ranges. Can be used in for loops
489 /// like: `for (auto [Lane, V] : enumerateLanes(Range))`
490 template <typename ValueContainerT>
491 static auto enumerateLanes(const ValueContainerT &Range) {
492 auto Begin = LaneValueEnumerator<decltype(Range.begin())>(Range.begin(),
493 Range.end(), 0);
494 auto End = LaneValueEnumerator<decltype(Range.begin())>(Range.end(),
495 Range.end(), 0);
496 return make_range(Begin, End);
497 }
498
499#ifndef NDEBUG
500 /// Helper dump function for debugging.
501 LLVM_DUMP_METHOD static void dump(ArrayRef<Value *> Bndl);
503#endif // NDEBUG
504};
505
506extern template LLVM_TEMPLATE_ABI void
509
510} // namespace sandboxir
511
512} // namespace llvm
513
514#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:216
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:686
This file defines the DenseSet and SmallDenseSet classes.
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static Split data
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
ArrayRef()=default
Construct an empty ArrayRef.
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
iterator begin()
Instruction iterator methods.
Definition BasicBlock.h:446
bool empty() const
Definition BasicBlock.h:468
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Implements a dense probed hash-table based set.
Definition DenseSet.h:281
The main scalar evolution driver.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
An ArrayRef of Values or Instructions that we can print/dump for debugging.
Definition VecUtils.h:39
void print(raw_ostream &OS) const
Helper dump function for debugging.
Definition VecUtils.h:46
LLVM_DUMP_METHOD void dump() const
Definition VecUtils.cpp:174
static LLVM_ABI ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition Constant.cpp:56
static LLVM_ABI Value * create(Value *Vec, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Maps the original instructions to the vectorized instrs and the reverse.
Definition InstrMaps.h:50
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
LLVM_ABI BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
LLVM_ABI BasicBlock * getParent() const
\Returns the BasicBlock containing this Instruction, or null if it is detached.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition Constant.cpp:263
static LLVM_ABI Value * create(Value *V1, Value *V2, Value *Mask, InsertPosition Pos, Context &Ctx, const Twine &Name="")
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:49
static LLVM_ABI IntegerType * getInt32Ty(Context &Ctx)
Definition Type.cpp:21
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:213
Value * getOperand(unsigned OpIdx) const
Definition User.h:123
static std::optional< int > getPointerDiffInBytes(LoadOrStoreT *I0, LoadOrStoreT *I1, ScalarEvolution &SE)
\Returns the gap between the memory locations accessed by I0 and I1 in bytes.
Definition Utils.h:93
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
Definition Utils.h:67
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
Definition Utils.h:33
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
LLVM_ABI Type * getType() const
Definition Value.cpp:46
Context & getContext() const
Definition Value.h:285
DeadInstructionMorgue(const DeadInstructionMorgue &)=delete
LLVM_DUMP_METHOD void debug() const
Definition VecUtils.h:478
LLVM_ABI void tryEraseDeadInstrs()
Erase candidates recorded by collectPotentiallyDeadInstrs() that now have no uses,...
Definition VecUtils.cpp:144
void collectPotentiallyDeadInstrs(BndlRef< T * > Bndl)
Record instructions in Bndl that may be dead after vectorization.
Definition VecUtils.cpp:109
Iterate over all lanes and Value pairs.
Definition VecUtils.h:416
bool operator==(const LaneValueEnumerator &Other) const
Definition VecUtils.h:448
bool operator!=(const LaneValueEnumerator &Other) const
Definition VecUtils.h:451
std::pair< unsigned, Value * > value_type
Definition VecUtils.h:431
std::pair< unsigned, Value * > & reference
Definition VecUtils.h:434
LaneValueEnumerator(RangeIteratorT Begin, RangeIteratorT End, unsigned BeginLane)
Definition VecUtils.h:426
std::pair< unsigned, Value * > * pointer
Definition VecUtils.h:433
static Type * tryGetCommonScalarType(ArrayRef< Value * > Bndl)
If all values in Bndl are of the same scalar type then return it, otherwise return nullptr.
Definition VecUtils.h:270
static Instruction * getLowest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is lowest in the BB.
Definition VecUtils.h:195
static Type * getCommonScalarType(ArrayRef< Value * > Bndl)
Similar to tryGetCommonScalarType() but will assert that there is a common type.
Definition VecUtils.h:286
static int getNumElements(Type *Ty)
\Returns the number of elements in Ty.
Definition VecUtils.h:89
static std::optional< PackPattern > matchPack(Instruction *I)
If I is the last instruction of a pack pattern (i.e., an InsertElement into a vector),...
Definition VecUtils.h:329
static Instruction * getLastPHIOrSelf(Instruction *I)
If I is not a PHI it returns it.
Definition VecUtils.h:245
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
Definition VecUtils.h:134
static Instruction * getLowest(ArrayRef< Value * > Vals, BasicBlock *BB)
\Returns the lowest instruction in Vals, or nullptr if no instructions are found.
Definition VecUtils.h:215
static Value * unpack(Value *FromVec, Type *ExtrTy, unsigned Lane, BasicBlock::iterator WhereIt)
Emits the necessary instruction sequence to extract element of type ExtrTy at Lane from FromVec.
Definition VecUtils.h:373
static LLVM_DUMP_METHOD void dump(ArrayRef< Value * > Bndl)
Helper dump function for debugging.
Definition VecUtils.cpp:171
static Type * getWideType(Type *ElemTy, unsigned NumElts)
\Returns <NumElts x ElemTy>.
Definition VecUtils.h:157
static Instruction * getHighest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is highest in the BB.
Definition VecUtils.h:205
static auto enumerateLanes(const ValueContainerT &Range)
Helper for creating LaneValueEnumerator ranges.
Definition VecUtils.h:491
static bool areConsecutive(LoadOrStoreT *I1, LoadOrStoreT *I2, ScalarEvolution &SE, const DataLayout &DL)
\Returns true if I1 and I2 are load/stores accessing consecutive memory addresses.
Definition VecUtils.h:101
static Type * getCombinedVectorTypeFor(std::initializer_list< Value * > Bndl, const DataLayout &DL)
Definition VecUtils.h:189
static bool areConsecutive(ArrayRef< ValT * > Bndl, ScalarEvolution &SE, const DataLayout &DL)
Definition VecUtils.h:114
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Definition VecUtils.h:94
static unsigned getNumLanes(Value *V)
\Returns the expected vector lanes of V or 1 if not a vector.
Definition VecUtils.h:143
static Type * getCombinedVectorTypeFor(BndlRef< T * > Bndl, const DataLayout &DL)
\Returns the combined vector type for Bndl, even when the element types differ.
Definition VecUtils.h:169
static unsigned getNumLanes(ArrayRef< Value * > Bndl)
\Returns the total number of lanes across all values in Bndl.
Definition VecUtils.h:148
static BasicBlock::iterator getInsertPointAfterInstrs(ArrayRef< Value * > Vals, BasicBlock *BB)
\Returns the BB iterator after the lowest instruction in Vals (skipping instructions not in BB),...
Definition VecUtils.h:257
static LLVM_ABI unsigned getFloorPowerOf2(unsigned Num)
\Returns the first integer power of 2 that is <= Num.
Definition VecUtils.cpp:98
static LLVM_ABI SmallVector< BundleTy > getNextUserBundles(ArrayRef< Value * > Bndl, const InstrMaps &IMaps, SmallPtrSet< Instruction *, 4 > &Claimed)
For each user of lane 0 in Bndl, try to form a bundle of matching users for all lanes.
Definition VecUtils.cpp:70
BndlRef(const T &OneElt) -> BndlRef< T >
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
iterator end() const
Definition BasicBlock.h:89
SmallVector< Value *, 4 > BundleTy
Definition VecUtils.h:82
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
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:2570
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.
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
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
@ Other
Any other memory.
Definition ModRef.h:68
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:1788
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition Hashing.h:287
#define N
static bool isEqual(const SmallVector< sandboxir::Value * > &Vec1, const SmallVector< sandboxir::Value * > &Vec2)
Definition VecUtils.h:29
static unsigned getHashValue(const SmallVector< sandboxir::Value * > &Vec)
Definition VecUtils.h:26
An information struct used to provide DenseMap with the various necessary components for a given valu...
Helper struct for matchPack().
Definition VecUtils.h:306
SmallVector< Value * > Operands
The "external" operands of the pack pattern, i.e., the values that get packed into a vector,...
Definition VecUtils.h:319
SmallVector< Instruction * > Instrs
The insertelement instructions that form the pack pattern in bottom-up order, i.e....
Definition VecUtils.h:314