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
37class InstrMaps;
38
40
41class VecUtils {
42public:
43 /// \Returns the number of elements in \p Ty. That is the number of lanes if a
44 /// fixed vector or 1 if scalar. ScalableVectors have unknown size and
45 /// therefore are unsupported.
46 static int getNumElements(Type *Ty) {
48 return Ty->isVectorTy() ? cast<FixedVectorType>(Ty)->getNumElements() : 1;
49 }
50 /// Returns \p Ty if scalar or its element type if vector.
51 static Type *getElementType(Type *Ty) {
52 return Ty->isVectorTy() ? cast<FixedVectorType>(Ty)->getElementType() : Ty;
53 }
54
55 /// \Returns true if \p I1 and \p I2 are load/stores accessing consecutive
56 /// memory addresses.
57 template <typename LoadOrStoreT>
58 static bool areConsecutive(LoadOrStoreT *I1, LoadOrStoreT *I2,
59 ScalarEvolution &SE, const DataLayout &DL) {
60 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
61 std::is_same<LoadOrStoreT, StoreInst>::value,
62 "Expected Load or Store!");
63 auto Diff = Utils::getPointerDiffInBytes(I1, I2, SE);
64 if (!Diff)
65 return false;
66 int ElmBytes = Utils::getNumBits(I1) / 8;
67 return *Diff == ElmBytes;
68 }
69
70 template <typename LoadOrStoreT, typename ValT>
72 const DataLayout &DL) {
73 static_assert(std::is_same<LoadOrStoreT, LoadInst>::value ||
74 std::is_same<LoadOrStoreT, StoreInst>::value,
75 "Expected Load or Store!");
76 assert(isa<LoadOrStoreT>(Bndl[0]) && "Expected Load or Store!");
77 auto *LastLS = cast<LoadOrStoreT>(Bndl[0]);
78 for (Value *V : drop_begin(Bndl)) {
80 "Unimplemented: we only support StoreInst!");
81 auto *LS = cast<LoadOrStoreT>(V);
82 if (!VecUtils::areConsecutive(LastLS, LS, SE, DL))
83 return false;
84 LastLS = LS;
85 }
86 return true;
87 }
88
89 /// \Returns the number of vector lanes of \p Ty or 1 if not a vector.
90 /// NOTE: It asserts that \p Ty is a fixed vector type.
91 static unsigned getNumLanes(Type *Ty) {
92 assert(!isa<ScalableVectorType>(Ty) && "Expect scalar or fixed vector");
93 if (auto *FixedVecTy = dyn_cast<FixedVectorType>(Ty))
94 return FixedVecTy->getNumElements();
95 return 1u;
96 }
97
98 /// \Returns the expected vector lanes of \p V or 1 if not a vector.
99 /// NOTE: It asserts that \p V is a fixed vector.
100 static unsigned getNumLanes(Value *V) {
102 }
103
104 /// \Returns the total number of lanes across all values in \p Bndl.
105 static unsigned getNumLanes(ArrayRef<Value *> Bndl) {
106 unsigned Lanes = 0;
107 for (Value *V : Bndl)
108 Lanes += getNumLanes(V);
109 return Lanes;
110 }
111
112 /// \Returns <NumElts x ElemTy>.
113 /// It works for both scalar and vector \p ElemTy.
114 static Type *getWideType(Type *ElemTy, unsigned NumElts) {
115 if (ElemTy->isVectorTy()) {
116 auto *VecTy = cast<FixedVectorType>(ElemTy);
117 ElemTy = VecTy->getElementType();
118 NumElts = VecTy->getNumElements() * NumElts;
119 }
120 return FixedVectorType::get(ElemTy, NumElts);
121 }
122 /// \Returns the combined vector type for \p Bndl, even when the element types
123 /// differ. For example: i8,i8,i16 will return <4 x i8>. \Returns null if
124 /// types are of mixed float/integer types.
126 const DataLayout &DL) {
127 assert(!Bndl.empty() && "Expected non-empty Bndl!");
128 unsigned TotalBits = 0;
129 unsigned MinElmBits = std::numeric_limits<unsigned>::max();
130 Type *MinElmTy = nullptr;
131 for (auto [Idx, V] : enumerate(Bndl)) {
133
134 unsigned ElmBits = Utils::getNumBits(ElmTy, DL);
135 TotalBits += ElmBits * VecUtils::getNumLanes(V);
136 if (ElmBits < MinElmBits) {
137 MinElmBits = ElmBits;
138 MinElmTy = ElmTy;
139 }
140 }
141 unsigned NumElms = TotalBits / MinElmBits;
142 return FixedVectorType::get(MinElmTy, NumElms);
143 }
144 /// \Returns the instruction in \p Instrs that is lowest in the BB. Expects
145 /// that all instructions are in the same BB.
147 Instruction *LowestI = Instrs.front();
148 for (auto *I : drop_begin(Instrs)) {
149 if (LowestI->comesBefore(I))
150 LowestI = I;
151 }
152 return LowestI;
153 }
154 /// \Returns the instruction in \p Instrs that is highest in the BB. Expects
155 /// that all instructions are in the same BB.
157 Instruction *HighestI = Instrs.front();
158 for (auto *I : drop_begin(Instrs)) {
159 if (I->comesBefore(HighestI))
160 HighestI = I;
161 }
162 return HighestI;
163 }
164 /// \Returns the lowest instruction in \p Vals, or nullptr if no instructions
165 /// are found. Skips instructions not in \p BB.
167 // Find the first Instruction in Vals that is also in `BB`.
168 auto It = find_if(Vals, [BB](Value *V) {
169 return isa<Instruction>(V) && cast<Instruction>(V)->getParent() == BB;
170 });
171 // If we couldn't find an instruction return nullptr.
172 if (It == Vals.end())
173 return nullptr;
174 Instruction *FirstI = cast<Instruction>(*It);
175 // Now look for the lowest instruction in Vals starting from one position
176 // after FirstI.
177 Instruction *LowestI = FirstI;
178 for (auto *V : make_range(std::next(It), Vals.end())) {
179 auto *I = dyn_cast<Instruction>(V);
180 // Skip non-instructions.
181 if (I == nullptr)
182 continue;
183 // Skips instructions not in \p BB.
184 if (I->getParent() != BB)
185 continue;
186 // If `LowestI` comes before `I` then `I` is the new lowest.
187 if (LowestI->comesBefore(I))
188 LowestI = I;
189 }
190 return LowestI;
191 }
192
193 /// If \p I is not a PHI it returns it. Else it walks down the instruction
194 /// chain looking for the last PHI and returns it. \Returns nullptr if \p I is
195 /// nullptr.
197 Instruction *LastI = I;
198 while (I != nullptr && isa<PHINode>(I)) {
199 LastI = I;
200 I = I->getNextNode();
201 }
202 return LastI;
203 }
204
205 /// \Returns the BB iterator after the lowest instruction in \p Vals
206 /// (skipping instructions not in \p BB), or the top of BB if no
207 /// instruction found in \p Vals.
209 BasicBlock *BB) {
210 auto *BotI = getLastPHIOrSelf(getLowest(Vals, BB));
211 if (BotI == nullptr)
212 // We are using BB->begin() (or after PHIs) as the fallback insert point.
213 return BB->empty()
214 ? BB->begin()
215 : std::next(getLastPHIOrSelf(&*BB->begin())->getIterator());
216 return std::next(BotI->getIterator());
217 }
218
219 /// If all values in \p Bndl are of the same scalar type then return it,
220 /// otherwise return nullptr.
222 Value *V0 = Bndl[0];
223 Type *Ty0 = Utils::getExpectedType(V0);
224 Type *ScalarTy = VecUtils::getElementType(Ty0);
225 for (auto *V : drop_begin(Bndl)) {
227 Type *NScalarTy = VecUtils::getElementType(NTy);
228 if (NScalarTy != ScalarTy)
229 return nullptr;
230 }
231 return ScalarTy;
232 }
233
234 /// Similar to tryGetCommonScalarType() but will assert that there is a common
235 /// type. So this is faster in release builds as it won't iterate through the
236 /// values.
238 Value *V0 = Bndl[0];
239 Type *Ty0 = Utils::getExpectedType(V0);
240 Type *ScalarTy = VecUtils::getElementType(Ty0);
241 assert(tryGetCommonScalarType(Bndl) && "Expected common scalar type!");
242 return ScalarTy;
243 }
244 /// \Returns the first integer power of 2 that is <= Num.
245 LLVM_ABI static unsigned getFloorPowerOf2(unsigned Num);
246
247 /// For each user of lane 0 in \p Bndl, try to form a bundle of matching
248 /// users for all lanes. Returns all complete user bundles found.
249 /// \p Claimed contains instructions that have already been claimed by a
250 /// bundle.
254
255 /// Helper struct for `matchPack()`. Describes the instructions and operands
256 /// of a pack pattern.
257 struct PackPattern {
258 /// The insertelement instructions that form the pack pattern in bottom-up
259 /// order, i.e., the first instruction in `Instrs` is the bottom-most
260 /// InsertElement instruction of the pack pattern.
261 /// For example in this simple pack pattern:
262 /// %Pack0 = insertelement <2 x i8> poison, i8 %v0, i64 0
263 /// %Pack1 = insertelement <2 x i8> %Pack0, i8 %v1, i64 1
264 /// this is [ %Pack1, %Pack0 ].
266 /// The "external" operands of the pack pattern, i.e., the values that get
267 /// packed into a vector, skipping the ones in `Instrs`. The operands are in
268 /// bottom-up order, starting from the operands of the bottom-most insert.
269 /// So in our example this would be [ %v1, %v0 ].
271 };
272
273 /// If \p I is the last instruction of a pack pattern (i.e., an InsertElement
274 /// into a vector), then this function returns the instructions in the pack
275 /// and the operands in the pack, else returns nullopt.
276 /// Here is an example of a matched pattern:
277 /// %PackA0 = insertelement <2 x i8> poison, i8 %v0, i64 0
278 /// %PackA1 = insertelement <2 x i8> %PackA0, i8 %v1, i64 1
279 /// TODO: this currently detects only simple canonicalized patterns.
280 static std::optional<PackPattern> matchPack(Instruction *I) {
281 // TODO: Support vector pack patterns.
282 // TODO: Support out-of-order inserts.
283
284 // Early return if `I` is not an Insert.
286 return std::nullopt;
287 auto *BB0 = I->getParent();
288 // The pack contains as many instrs as the lanes of the bottom-most Insert
289 unsigned ExpectedNumInserts = VecUtils::getNumLanes(I);
290 assert(ExpectedNumInserts >= 2 && "Expected at least 2 inserts!");
292 Pack.Operands.resize(ExpectedNumInserts);
293 // Collect the inserts by walking up the use-def chain.
294 Instruction *InsertI = I;
295 for (auto ExpectedLane : reverse(seq<unsigned>(ExpectedNumInserts))) {
296 if (InsertI == nullptr)
297 return std::nullopt;
298 if (InsertI->getParent() != BB0)
299 return std::nullopt;
300 // Check the lane.
301 auto *LaneC = dyn_cast<ConstantInt>(InsertI->getOperand(2));
302 if (LaneC == nullptr || LaneC->getSExtValue() != ExpectedLane)
303 return std::nullopt;
304 Pack.Instrs.push_back(InsertI);
305 Pack.Operands[ExpectedLane] = InsertI->getOperand(1);
306
307 Value *Op = InsertI->getOperand(0);
308 if (ExpectedLane == 0) {
309 // Check the topmost insert. The operand should be a Poison.
310 if (!isa<PoisonValue>(Op))
311 return std::nullopt;
312 } else {
314 }
315 }
316 return Pack;
317 }
318
319 /// Emits the necessary instruction sequence to extract element of type \p
320 /// ExtrTy at \p Lane from \p FromVec. Emits instructions before \p WhereIt.
321 /// Returns the extracted value.
322 /// Note: This handles both vectors and scalars. In the vector case it
323 /// extracts an N-wide element (with N dictated by \p ExtrTy).
324 static Value *unpack(Value *FromVec, Type *ExtrTy, unsigned Lane,
325 BasicBlock::iterator WhereIt) {
326 assert(isa<FixedVectorType>(FromVec->getType()) && "Expected vector!");
327 auto &Ctx = FromVec->getContext();
328 if (!ExtrTy->isVectorTy()) {
329 // For scalar elements we emit a single ExtractElementInst.
330 assert(Lane <
331 cast<FixedVectorType>(FromVec->getType())->getNumElements() &&
332 "Out of bounds!");
333 assert(ExtrTy ==
334 cast<FixedVectorType>(FromVec->getType())->getElementType() &&
335 "Expected same element type!");
336 Constant *ExtractLaneC =
338 // Note: This may be folded into a Constant if FromVec is a Constant.
339 return ExtractElementInst::create(FromVec, ExtractLaneC, WhereIt, Ctx,
340 "Unpack");
341 }
342 // For vector elements we emit a shuffle.
343 // For example, extracting lanes 2 and 3 of a <4 x i32> vector %vec:
344 // shufflevector <4 x i32> %vec, <4 x i32> poison, <2 x i32> <i32 2, i32 3>
345 auto *VecTy = cast<FixedVectorType>(FromVec->getType());
346 auto *ExtrVecTy = cast<FixedVectorType>(ExtrTy);
347 assert(ExtrVecTy->getElementType() == VecTy->getElementType() &&
348 "Expected same element type!");
350 for (unsigned Idx = 0, E = ExtrVecTy->getNumElements(); Idx != E; ++Idx) {
351 int MaskLane = Lane + Idx;
352 assert((unsigned)MaskLane <
353 cast<FixedVectorType>(FromVec->getType())->getNumElements() &&
354 "Out of bounds!");
355 Mask.push_back(MaskLane);
356 }
357 return ShuffleVectorInst::create(FromVec, PoisonValue::get(VecTy), Mask,
358 WhereIt, Ctx, "Unpack");
359 }
360
361 /// Iterate over all lanes and Value pairs.
362 // For example, given a range: {i32 %v0, <2 x i32> %v1, i32 %v2} we get:
363 // Lane Elm
364 // 0 %v0
365 // 1 %v1
366 // 3 %v2
367 template <typename RangeIteratorT> class LaneValueEnumerator {
368 /// Points to current element.
369 RangeIteratorT It;
370 RangeIteratorT ItE;
371 /// Accumulator of lanes.
372 unsigned Lane;
373
374 public:
375 // Note that We can start counting from a non-zero BeginLane, though the
376 // user must make sure it corresponds to the correct lane matching Begin.
377 LaneValueEnumerator(RangeIteratorT Begin, RangeIteratorT End,
378 unsigned BeginLane)
379 : It(Begin), ItE(End), Lane(BeginLane) {}
380 using iterator_catecotry = std::input_iterator_tag;
381 // NOTE: dereference returns by value instead of by reference.
382 using value_type = std::pair<unsigned, Value *>;
383 using difference_type = std::ptrdiff_t;
384 using pointer = std::pair<unsigned, Value *> *;
385 using reference = std::pair<unsigned, Value *> &;
387 assert(It != ItE && "Already at end!");
388 auto *Ty = Utils::getExpectedType(*It);
389 if (auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
390 Lane += VecTy->getNumElements();
391 } else {
392 assert(!isa<VectorType>(Ty) && "Expected scalar type!");
393 Lane += 1;
394 }
395 ++It;
396 return *this;
397 }
398 value_type operator*() const { return {Lane, *It}; }
400 return It == Other.It;
401 }
403 return !(*this == Other);
404 }
405 };
406
407 /// Utility class to collect and erase dead instructions.
409 public:
412
413 /// Record instructions in \p Bndl that may be dead after vectorization.
414 /// For load/store bundles, also record non-first-lane pointer operands;
415 /// the first lane's pointer is skipped because the vector load/store
416 /// reuses it. Erased later by \c tryEraseDeadInstrs().
417 template <typename T> void collectPotentiallyDeadInstrs(ArrayRef<T *> Bndl);
418
419 /// Erase candidates recorded by \c collectPotentiallyDeadInstrs() that
420 /// now have no uses, then clear the candidate set.
422
423#ifndef NDEBUG
424 void print(raw_ostream &OS) const {
425 OS << "DeadInstrCandidates:\n";
426 for (auto *I : DeadInstrCandidates)
427 OS << *I << '\n';
428 }
429 LLVM_DUMP_METHOD void debug() const {
430 print(dbgs());
431 dbgs() << '\n';
432 }
433#endif /* NDEBUG */
434
435 private:
436 DenseSet<Instruction *> DeadInstrCandidates;
437 };
438
439 /// Helper for creating LaneValueEnumerator ranges. Can be used in for loops
440 /// like: `for (auto [Lane, V] : enumerateLanes(Range))`
441 template <typename ValueContainerT>
442 static auto enumerateLanes(const ValueContainerT &Range) {
443 auto Begin = LaneValueEnumerator<decltype(Range.begin())>(Range.begin(),
444 Range.end(), 0);
445 auto End = LaneValueEnumerator<decltype(Range.begin())>(Range.end(),
446 Range.end(), 0);
447 return make_range(Begin, End);
448 }
449
450#ifndef NDEBUG
451 /// Helper dump function for debugging.
452 LLVM_DUMP_METHOD static void dump(ArrayRef<Value *> Bndl);
454#endif // NDEBUG
455};
456
457/// An ArrayRef of Values or Instructions that we can print/dump for debugging.
458/// It is mainly used for the vectorizer's instr/value bundles.
459template <typename T> class BndlRef : public ArrayRef<T> {
460public:
461 // Inherit constructors.
462 using ArrayRef<T>::ArrayRef;
463
464#ifndef NDEBUG
465 /// Helper dump function for debugging.
466 void print(raw_ostream &OS) const {
467 for (const auto &[Idx, Val] : enumerate(*this))
468 OS << Idx << ". " << *Val << "\n";
469 }
470 LLVM_DUMP_METHOD void dump() const;
471#endif // NDEBUG
472};
473
474/// @name BndlRef Deduction guides
475/// @{
476/// Deduction guide to construct a BndlRef from a single element.
477template <typename T> BndlRef(const T &OneElt) -> BndlRef<T>;
478/// Deduction guide to construct a BndlRef from a pointer and length
479template <typename T> BndlRef(const T *data, size_t length) -> BndlRef<T>;
480/// Deduction guide to construct a BndlRef from a range
481template <typename T> BndlRef(const T *data, const T *end) -> BndlRef<T>;
482/// Deduction guide to construct a BndlRef from a SmallVector
483template <typename T> BndlRef(const SmallVectorImpl<T> &Vec) -> BndlRef<T>;
484/// Deduction guide to construct a BndlRef from a SmallVector
485template <typename T, unsigned N>
487/// Deduction guide to construct a BndlRef from a std::vector
488template <typename T> BndlRef(const std::vector<T> &Vec) -> BndlRef<T>;
489/// Deduction guide to construct a BndlRef from a std::array
490template <typename T, std::size_t N>
491BndlRef(const std::array<T, N> &Vec) -> BndlRef<T>;
492/// Deduction guide to construct a BndlRef from an BndlRef (const)
493template <typename T> BndlRef(const BndlRef<T> &Vec) -> BndlRef<T>;
494/// Deduction guide to construct a BndlRef from an BndlRef
495template <typename T> BndlRef(BndlRef<T> &Vec) -> BndlRef<T>;
496/// Deduction guide to construct a BndlRef from a C array.
497template <typename T, size_t N> BndlRef(const T (&Arr)[N]) -> BndlRef<T>;
498/// @}
499
500} // namespace sandboxir
501
502} // namespace llvm
503
504#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_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:678
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:459
void print(raw_ostream &OS) const
Helper dump function for debugging.
Definition VecUtils.h:466
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:92
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
Definition Utils.h:66
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
Definition Utils.h:32
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:429
LLVM_ABI void tryEraseDeadInstrs()
Erase candidates recorded by collectPotentiallyDeadInstrs() that now have no uses,...
Definition VecUtils.cpp:144
void collectPotentiallyDeadInstrs(ArrayRef< 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:367
bool operator==(const LaneValueEnumerator &Other) const
Definition VecUtils.h:399
bool operator!=(const LaneValueEnumerator &Other) const
Definition VecUtils.h:402
std::pair< unsigned, Value * > value_type
Definition VecUtils.h:382
std::pair< unsigned, Value * > & reference
Definition VecUtils.h:385
LaneValueEnumerator(RangeIteratorT Begin, RangeIteratorT End, unsigned BeginLane)
Definition VecUtils.h:377
std::pair< unsigned, Value * > * pointer
Definition VecUtils.h:384
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:221
static Instruction * getLowest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is lowest in the BB.
Definition VecUtils.h:146
static Type * getCommonScalarType(ArrayRef< Value * > Bndl)
Similar to tryGetCommonScalarType() but will assert that there is a common type.
Definition VecUtils.h:237
static int getNumElements(Type *Ty)
\Returns the number of elements in Ty.
Definition VecUtils.h:46
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:280
static Type * getCombinedVectorTypeFor(ArrayRef< Instruction * > Bndl, const DataLayout &DL)
\Returns the combined vector type for Bndl, even when the element types differ.
Definition VecUtils.h:125
static Instruction * getLastPHIOrSelf(Instruction *I)
If I is not a PHI it returns it.
Definition VecUtils.h:196
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
Definition VecUtils.h:91
static Instruction * getLowest(ArrayRef< Value * > Vals, BasicBlock *BB)
\Returns the lowest instruction in Vals, or nullptr if no instructions are found.
Definition VecUtils.h:166
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:324
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:114
static Instruction * getHighest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is highest in the BB.
Definition VecUtils.h:156
static auto enumerateLanes(const ValueContainerT &Range)
Helper for creating LaneValueEnumerator ranges.
Definition VecUtils.h:442
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:58
static bool areConsecutive(ArrayRef< ValT * > Bndl, ScalarEvolution &SE, const DataLayout &DL)
Definition VecUtils.h:71
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Definition VecUtils.h:51
static unsigned getNumLanes(Value *V)
\Returns the expected vector lanes of V or 1 if not a vector.
Definition VecUtils.h:100
static unsigned getNumLanes(ArrayRef< Value * > Bndl)
\Returns the total number of lanes across all values in Bndl.
Definition VecUtils.h:105
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:208
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:39
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:257
SmallVector< Value * > Operands
The "external" operands of the pack pattern, i.e., the values that get packed into a vector,...
Definition VecUtils.h:270
SmallVector< Instruction * > Instrs
The insertelement instructions that form the pack pattern in bottom-up order, i.e....
Definition VecUtils.h:265