LLVM 24.0.0git
LoadStoreVec.cpp
Go to the documentation of this file.
1//===- LoadStoreVec.cpp - Vectorizer pass short load-store chains ---------===//
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
11#include "llvm/ADT/STLExtras.h"
21
22namespace llvm {
23
24namespace sandboxir {
25
26#define DEBUG_PREFIX_LOCAL DEBUG_PREFIX "LoadStoreVec: "
27
28/// \returns true if \p Ty is a pointer, or a vector of pointers, in a
29/// non-integral address space, which has no stable integer representation.
30static bool isNonIntegralPtr(Type *Ty, const DataLayout &DL) {
31 Type *ScalarTy = Ty->getScalarType();
32 return ScalarTy->isPointerTy() &&
33 DL.isNonIntegralAddressSpace(ScalarTy->getPointerAddressSpace());
34}
35
36std::optional<Type *> LoadStoreVec::canVectorize(BndlRef<Instruction *> Bndl) {
37 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
38 VecUtils::dump(Bndl));
39 const auto &LegalityRes = Legality->canVectorizeLSV(Bndl);
40 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
41
42 if (LegalityRes.getSubclassID() != LegalityResultID::Widen)
43 return std::nullopt;
45}
46
47void LoadStoreVec::saveIR(Region &R) {
48 Rgn = &R;
49 const auto &SB = cast<RegionWithScore>(Rgn)->getScoreboard();
50 CostBefore = SB.getAfterCost() - SB.getBeforeCost();
51 Rgn->getContext().save();
52}
53
54bool LoadStoreVec::acceptOrRevert() {
55 const auto &SB = cast<RegionWithScore>(*Rgn).getScoreboard();
56 InstructionCost CostAfter = SB.getAfterCost() - SB.getBeforeCost();
57 InstructionCost CostGain = CostAfter - CostBefore;
58 LLVM_DEBUG(dbgs() << DEBUG_PREFIX_LOCAL << "CostGain=" << CostGain
59 << " (After=" << CostAfter << " Before=" << CostBefore
60 << ")\n");
61 const VectorizeOptions &Opts = getVectorizeOptions(*Ctx);
62 if (CostGain > Opts.sbvec_cost_threshold) {
63 LLVM_DEBUG(dbgs() << DEBUG_PREFIX_LOCAL << "Not profitable, reverting.\n");
64 Ctx->revert();
65 return false;
66 }
67 LLVM_DEBUG(dbgs() << DEBUG_PREFIX_LOCAL << "Profitable accepting.\n");
68 Ctx->accept();
69 return true;
70}
71
72/// \returns \p ElemTy if \p N is 1, otherwise < \p N x \p ElemTy >.
73static Type *getWidenedType(Type *ElemTy, unsigned N) {
74 assert(!ElemTy->isVectorTy() && "Expected a scalar element type!");
75 return N == 1 ? ElemTy : FixedVectorType::get(ElemTy, N);
76}
77
78template <typename TypeRangeT>
79bool LoadStoreVec::canUnpack(FixedVectorType *FromTy, TypeRangeT ToTypes) {
80 Type *VecElemTy = FromTy->getElementType();
81 return all_of(ToTypes, [this, VecElemTy](Type *ToTy) {
82 unsigned NumElems =
83 Utils::getNumBits(ToTy, *DL) / Utils::getNumBits(VecElemTy, *DL);
85 getWidenedType(VecElemTy, NumElems), ToTy, *DL);
86 });
87}
88
89/// Replaces the uses of \p V for which \p ShouldReplace returns true with the
90/// value returned by \p NewValBuilder.
91static void lazyRAUWIf(Value *V, function_ref<bool(const Use &)> ShouldReplace,
92 function_ref<Value *()> NewValBuilder) {
93 Value *NewVal = nullptr;
94 for (auto It = V->use_begin(), E = V->use_end(); It != E;) {
95 Use U = *It;
96 ++It; // Advance first: U.set() unlinks U from V's use list.
97 if (!ShouldReplace(U))
98 continue;
99 if (NewVal == nullptr)
100 NewVal = NewValBuilder();
101 U.set(NewVal);
102 }
103}
104
105void LoadStoreVec::unpackIfNeeded(LoadInst *VecLoad,
106 BndlRef<Instruction *> OrigLoads,
107 BndlRef<Instruction *> SkipUsers) {
108 Type *VecElemTy = cast<FixedVectorType>(VecLoad->getType())->getElementType();
109 BasicBlock::iterator WhereIt = std::next(VecLoad->getIterator());
110 unsigned Lane = 0;
111 for (Instruction *I : OrigLoads) {
112 auto *Orig = cast<LoadInst>(I);
113 unsigned NumElems = Utils::getNumBits(Orig->getType(), *DL) /
114 Utils::getNumBits(VecElemTy, *DL);
115 Type *LanesTy = getWidenedType(VecElemTy, NumElems);
116 auto CreateUnpack = [&, Lane]() -> Value * {
117 Value *Unpacked = VecUtils::unpack(VecLoad, LanesTy, Lane, WhereIt);
118 return SameSizeReinterpret::reinterpretValue(Unpacked, Orig->getType(),
119 WhereIt, *Ctx, *DL);
120 };
121
122 // This is used instead of the usual `Value::replaceUsesWithIf()` because
123 // that API takes the replacement value up front. Here the replacement (an
124 // unpack plus possible reinterpret casts) is materialized as new
125 // instructions, so building it eagerly would leave dead instructions behind
126 // whenever no use ends up being replaced (e.g. all users are in the skip
127 // list). Instead,
128 // \p NewValBuilder is invoked lazily, at most once, only when the first use
129 // that needs replacing is found.
131 Orig,
132 [&SkipUsers](const Use &U) {
133 return !is_contained(SkipUsers, U.getUser());
134 },
135 CreateUnpack);
136 Lane += VecUtils::getNumLanes(LanesTy);
137 }
138}
139
140LoadInst *LoadStoreVec::createVectorLoad(BndlRef<Instruction *> Loads) {
142 Value *LdPtr = cast<LoadInst>(Loads[0])->getPointerOperand();
143 Align LdAlign = VecUtils::getVecAlignment(Loads);
144 auto LdWhereIt = std::next(VecUtils::getLowest(Loads)->getIterator());
145 auto *VecL =
146 LoadInst::create(Ty, LdPtr, LdAlign, LdWhereIt, *Ctx, "VecIinitL");
148 return VecL;
149}
150
152 const DataLayout &DL) {
153 return !isNonIntegralPtr(SrcTy, DL) && !isNonIntegralPtr(DestTy, DL);
154}
155
156Type *SameSizeReinterpret::getIntTypeFor(Type *Ty, const DataLayout &DL) {
157 Context &Ctx = Ty->getContext();
158 if (auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
159 auto *ElmIntTy =
160 IntegerType::get(Ctx, Utils::getNumBits(VecTy->getElementType(), DL));
161 return FixedVectorType::get(ElmIntTy, VecTy->getNumElements());
162 }
163 return IntegerType::get(Ctx, Utils::getNumBits(Ty, DL));
164}
165
167SameSizeReinterpret::getCastChain(Type *SrcTy, Type *DestTy,
168 const DataLayout &DL) {
169 assert(canReinterpret(SrcTy, DestTy, DL) &&
170 "Cannot reinterpret a non-integral pointer!");
171 assert(Utils::getNumBits(SrcTy, DL) == Utils::getNumBits(DestTy, DL) &&
172 "Expected types of the same size!");
174 if (SrcTy == DestTy)
175 return Chain;
176 Type *Ty = SrcTy;
177 if (Ty->getScalarType()->isPointerTy()) {
178 Ty = getIntTypeFor(Ty, DL);
179 Chain.emplace_back(Instruction::Opcode::PtrToInt, Ty);
180 }
181 bool DestIsPtr = DestTy->getScalarType()->isPointerTy();
182 Type *BitCastTy = DestIsPtr ? getIntTypeFor(DestTy, DL) : DestTy;
183 if (Ty != BitCastTy)
184 Chain.emplace_back(Instruction::Opcode::BitCast, BitCastTy);
185 if (DestIsPtr)
186 Chain.emplace_back(Instruction::Opcode::IntToPtr, DestTy);
187 // ptrtoint, bitcast, and inttoptr, with any step omitted. A vector of
188 // pointers and a scalar pointer of the same width need all three.
189 assert(Chain.size() <= 3 && "Unexpected reinterpret cast chain!");
190 return Chain;
191}
192
194 BasicBlock::iterator WhereIt,
195 Context &Ctx,
196 const DataLayout &DL) {
197 if (!canReinterpret(V->getType(), DestTy, DL))
198 return nullptr;
199 Value *NewV = V;
200 for (auto [Opc, Ty] : getCastChain(V->getType(), DestTy, DL))
201 NewV = CastInst::create(Ty, Opc, NewV, WhereIt, Ctx, "VCast");
202 return NewV;
203}
204
206 const DataLayout &DL) {
207 if (!canReinterpret(C->getType(), DestTy, DL))
208 return nullptr;
209 Constant *NewC = C;
210 for (auto [Opc, Ty] : getCastChain(C->getType(), DestTy, DL)) {
211 switch (Opc) {
212 case Instruction::Opcode::PtrToInt:
213 NewC = ConstantExpr::getPtrToInt(NewC, Ty);
214 break;
215 case Instruction::Opcode::BitCast:
216 NewC = ConstantExpr::getBitCast(NewC, Ty);
217 break;
218 case Instruction::Opcode::IntToPtr:
219 NewC = ConstantExpr::getIntToPtr(NewC, Ty);
220 break;
221 default:
222 llvm_unreachable("Unexpected cast in reinterpret chain!");
223 }
224 }
225 return NewC;
226}
227
228Constant *LoadStoreVec::createConstantVector(BndlRef<Constant *> Constants) {
229 auto *VecTy =
231 auto *LaneTy = VecTy->getScalarType();
232 unsigned LaneBits = Utils::getNumBits(LaneTy, *DL);
233 assert(all_of(Constants,
234 [&](Value *V) {
235 return Utils::getNumBits(V, *DL) % LaneBits == 0;
236 }) &&
237 "Chain contains a constant which cannot be converted or split");
238
239 // Some of the contents of Constants may be vectors, like <i8 1, i8 2>.
240 // Collect each scalar element in ConstantElements.
241 SmallVector<Constant *, 4> ConstantElements;
242 for (Constant *COp : Constants) {
243 if (auto *AggrCOp = dyn_cast<ConstantAggregate>(COp)) {
244 // If the operand is a constant aggregate, then append all its elements.
245 // TODO: Flatten nested aggregates such as {i32, {i32, <2 x i32>}} in a
246 // follow-up.
247 for (Value *Elm : AggrCOp->operands())
248 ConstantElements.push_back(cast<Constant>(Elm));
249 } else if (auto *SeqCOp = dyn_cast<ConstantDataSequential>(COp)) {
250 for (auto ElmIdx : seq<unsigned>(SeqCOp->getNumElements()))
251 ConstantElements.push_back(SeqCOp->getElementAsConstant(ElmIdx));
252 } else if (auto *Zero = dyn_cast<ConstantAggregateZero>(COp)) {
253 auto *ZeroElm = Zero->getSequentialElement();
254 for ([[maybe_unused]] auto Cnt :
255 seq<unsigned>(Zero->getElementCount().getFixedValue()))
256 ConstantElements.push_back(ZeroElm);
257 } else if (isa<ConstantInt>(COp) && isa<VectorType>(COp->getType())) {
258 auto *Elm = ConstantInt::get(*Ctx, cast<ConstantInt>(COp)->getValue());
259 for ([[maybe_unused]] auto Cnt :
260 seq<unsigned>(cast<VectorType>(COp->getType())
261 ->getElementCount()
262 .getFixedValue()))
263 ConstantElements.push_back(Elm);
264 } else if (isa<ConstantFP>(COp) && isa<VectorType>(COp->getType())) {
265 auto *Elm = ConstantFP::get(cast<ConstantFP>(COp)->getValue(), *Ctx);
266 for ([[maybe_unused]] auto Cnt :
267 seq<unsigned>(cast<VectorType>(COp->getType())
268 ->getElementCount()
269 .getFixedValue()))
270 ConstantElements.push_back(Elm);
271 } else if (isa<PoisonValue>(COp) && isa<VectorType>(COp->getType())) {
272 auto *Elm =
273 PoisonValue::get(cast<VectorType>(COp->getType())->getElementType());
274 for ([[maybe_unused]] auto Cnt :
275 seq<unsigned>(cast<VectorType>(COp->getType())
276 ->getElementCount()
277 .getFixedValue()))
278 ConstantElements.push_back(Elm);
279 } else if (isa<VectorType>(COp->getType())) {
280 // TODO: Flatten the remaining vector constants.
281 return nullptr;
282 } else {
283 ConstantElements.push_back(COp);
284 }
285 }
286
287 // The elements in ConstantElements may not be of the same type, so we need to
288 // convert them to LaneTy such that we end up getting a vector
289 // <ConstantElements.size() x LaneTy>. This may involve converting integers to
290 // floats (e.g., float 1.0 to i32 0x3f800000), widening or slicing values if
291 // not at LaneTy bit-width (e.g., i16 0x0101 to i8 0x01, i8 0x01 on
292 // little-endian), or a combination of the two.
293 SmallVector<Constant *, 8> LaneTyConstants;
294 LaneTyConstants.reserve(ConstantElements.size());
295 for (Constant *C : ConstantElements) {
296 unsigned Bits = Utils::getNumBits(C, *DL);
297 if (Bits == LaneBits) {
299 if (Lane == nullptr)
300 return nullptr;
301 LaneTyConstants.push_back(Lane);
302 } else if (Bits > LaneBits) {
303 // C is wider than LaneTy, so slice it into LaneTy-sized pieces. That
304 // needs a known bit pattern. A ConstantExpr (for example, ptrtoint of a
305 // global) or a global's address is only known at link time and cannot
306 // be sliced.
308 return nullptr;
309 APInt Val;
310 if (auto *CI = dyn_cast<ConstantInt>(C))
311 Val = CI->getValue();
312 else if (auto *CFP = dyn_cast<ConstantFP>(C))
313 Val = CFP->getValue().bitcastToAPInt();
314 else
315 Val = APInt::getZero(Bits);
316 unsigned NumSlices = Bits / LaneBits;
317 for (unsigned SliceIdx : seq<unsigned>(NumSlices)) {
318 unsigned EndianAwareSlice =
319 DL->isLittleEndian() ? SliceIdx : NumSlices - 1 - SliceIdx;
320 // extractBits returns an integer. Convert that slice back to LaneTy
321 // without changing its bits, so a float lane stays a float.
322 Constant *SliceCInt = ConstantInt::get(
323 *Ctx, Val.extractBits(LaneBits, EndianAwareSlice * LaneBits));
324 Constant *SliceC =
325 SameSizeReinterpret::reinterpretConstant(SliceCInt, LaneTy, *DL);
326 if (SliceC == nullptr)
327 return nullptr;
328 LaneTyConstants.push_back(SliceC);
329 }
330 } else {
331 llvm_unreachable("Vector element type size was calculated incorrectly");
332 }
333 }
334 return ConstantVector::get(LaneTyConstants);
335}
336
337bool LoadStoreVec::vectorizeStores(BndlRef<Instruction *> Stores, Region &Rgn) {
338 if (!canVectorize(Stores))
339 return false;
340 SmallVector<Value *, 4> Operands;
341 Operands.reserve(Stores.size());
342 for (auto *I : Stores) {
343 auto *Op = cast<StoreInst>(I)->getValueOperand();
344 Operands.push_back(Op);
345 }
346 BasicBlock *BB = Stores[0]->getParent();
347 // TODO: For now we only support load operands.
348 // TODO: For now we don't cross BBs.
349 bool AllLoadsInSameBB = all_of(Operands, [BB](Value *V) {
350 auto *LI = dyn_cast<LoadInst>(V);
351 return LI && LI->getParent() == BB;
352 });
353 bool AllConstants =
354 all_of(Operands, [](Value *V) { return isa<Constant>(V); });
355 if (!AllLoadsInSameBB && !AllConstants)
356 return false;
357
358 // Vectorizing mixed floats and integers with external uses may not be
359 // profitable on some targets, so save state here.
360 saveIR(Rgn);
361 Value *VecOp = nullptr;
362 SmallVector<Instruction *, 8> Loads;
364 if (AllLoadsInSameBB) {
365 Loads.reserve(Operands.size());
366 TypeVec.reserve(Operands.size());
367 for (Value *Op : Operands) {
368 Loads.push_back(cast<Instruction>(Op));
369 TypeVec.push_back(Op->getType());
370 }
371
372 std::optional<Type *> LoadsVecTy = canVectorize(Loads);
373
374 if (!LoadsVecTy) {
375 // TODO: Add an optimization remark
376 Ctx->accept();
377 return false;
378 }
379 if (!canUnpack(cast<FixedVectorType>(*LoadsVecTy), TypeVec)) {
380 // TODO: Add an optimization remark
381 Ctx->accept();
382 return false;
383 }
384
385 VecOp = createVectorLoad(Loads);
386 assert(VecOp != nullptr && "Expected vector value!");
387 } else if (AllConstants) {
389 Constants.reserve(Operands.size());
390 for (Value *Op : Operands)
391 Constants.push_back(cast<Constant>(Op));
392 VecOp = createConstantVector(Constants);
393 if (VecOp == nullptr) {
394 Ctx->accept();
395 return false;
396 }
397 }
398
399 // Generate vector store.
400 Value *StPtr = cast<StoreInst>(Stores[0])->getPointerOperand();
401 Align StAlign = VecUtils::getVecAlignment(Stores);
402 auto StWhereIt = std::next(VecUtils::getLowest(Stores)->getIterator());
403 auto *VecS = StoreInst::create(VecOp, StPtr, StAlign, StWhereIt, *Ctx);
405
406 if (AllLoadsInSameBB) {
407 // The scalar stores are about to be erased, so only unpack the loads for
408 // their other users.
409 unpackIfNeeded(cast<LoadInst>(VecOp), Loads, Stores);
410 DeadInstrMorgue.collectPotentiallyDeadInstrs<Instruction>(Loads);
411 }
412 DeadInstrMorgue.collectPotentiallyDeadInstrs(Stores);
413 DeadInstrMorgue.tryEraseDeadInstrs();
414
415 return acceptOrRevert();
416}
417
418LoadInst *LoadStoreVec::vectorizeLoads(BndlRef<Instruction *> Loads,
419 Region &Rgn) {
420 auto VecTy = canVectorize(Loads);
421 if (!VecTy)
422 return nullptr;
423
424 // Each load is unpacked from the lanes it occupies in the vector and, for a
425 // chain of mixed types, reinterpreted back as the type of the load.
426 if (!canUnpack(cast<FixedVectorType>(*VecTy),
427 map_range(Loads, [](Instruction *I) { return I->getType(); })))
428 return nullptr;
429
430 saveIR(Rgn);
431
432 auto *VecLoad = createVectorLoad(Loads);
433 assert(VecLoad != nullptr && "Expected vector load");
434 unpackIfNeeded(VecLoad, Loads);
435
436 DeadInstrMorgue.collectPotentiallyDeadInstrs(Loads);
437 DeadInstrMorgue.tryEraseDeadInstrs();
438
439 if (!acceptOrRevert())
440 return nullptr;
441 return VecLoad;
442}
443
444bool LoadStoreVec::runOnRegion(Region &Rgn, const Analyses &RegionAnalyses) {
445 SmallVector<Instruction *, 8> Bndl(Rgn.getAux().begin(), Rgn.getAux().end());
446 if (Bndl.size() < 2)
447 return false;
448 Function &F = *Bndl[0]->getParent()->getParent();
449 DL = &F.getParent()->getDataLayout();
450 Ctx = &F.getContext();
451 A = &RegionAnalyses;
452 InstrMaps IMaps;
453 auto Opc = Bndl[0]->getOpcode();
454 assert(
455 all_of(Bndl, [Opc](Instruction *I) { return I->getOpcode() == Opc; }) &&
456 "Expected a homogeneous seed slice!");
457
458 SchedDirection Dir;
459 switch (Opc) {
460 case Instruction::Opcode::Load:
462 break;
463 case Instruction::Opcode::Store:
465 break;
466 default:
467 llvm_unreachable("Expected Load or Store");
468 }
469
470 LegalityAnalysis L(A->getAA(), A->getScalarEvolution(),
471 F.getParent()->getDataLayout(), A->getTTI(),
472 F.getContext(), IMaps, Dir);
473 Legality = &L;
474
475 // Save state for the top-level roll-back if not Changed (below).
476 Ctx->save();
477
478 bool Changed = false;
479 switch (Opc) {
480 case Instruction::Opcode::Load:
481 Changed = vectorizeLoads(Bndl, Rgn) != nullptr;
482 break;
483 case Instruction::Opcode::Store:
484 Changed = vectorizeStores(Bndl, Rgn);
485 break;
486 default:
487 llvm_unreachable("Expected Load or Store");
488 }
489
490 // The IR may have changed even if Changed == false, because of scheduling.
491 // So to be save revert the state.
492 if (!Changed)
493 Ctx->revert();
494 else
495 Ctx->accept();
496 return Changed;
497}
498
499} // namespace sandboxir
500
501} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
static constexpr Value * getValue(Ty &ValueOrUse)
#define DEBUG_PREFIX_LOCAL
unsigned Opc
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
SI Fold Operands
This file contains some templates that are useful if you are working with the STL at all.
#define LLVM_DEBUG(...)
Definition Debug.h:119
#define DEBUG_PREFIX
Definition Debug.h:19
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:169
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
Class to represent fixed width SIMD vectors.
An instruction for reading from memory.
void reserve(size_type N)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
Type * getElementType() const
An efficient, type-erasing, non-owning reference to a callable.
An ArrayRef of Values or Instructions that we can print/dump for debugging.
Definition VecUtils.h:39
static LLVM_ABI Value * create(Type *DestTy, Opcode Op, Value *Operand, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty)
Definition Constant.cpp:482
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty)
Definition Constant.cpp:470
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty)
Definition Constant.cpp:476
static LLVM_ABI Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition Constant.cpp:90
static LLVM_ABI Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition Constant.cpp:48
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
Definition Constant.cpp:176
void save()
Convenience function for getTracker().save()
Definition Context.h:252
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Maps the original instructions to the vectorized instrs and the reverse.
Definition InstrMaps.h:49
A sandboxir::User with operands, opcode and linked with previous/next instructions in an instruction ...
Definition Instruction.h:43
static LLVM_ABI IntegerType * get(Context &C, unsigned NumBits)
Performs the legality analysis and returns a LegalityResult object.
Definition Legality.h:322
LLVM_ABI const LegalityResult & canVectorizeLSV(BndlRef< Instruction * > Bndl)
Similar to canVectorize() but specific to LoadStoreVec.
Definition Legality.cpp:286
static LLVM_ABI LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx, const Twine &Name="")
bool runOnRegion(Region &Rgn, const Analyses &A) final
\Returns true if it modifies R.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition Constant.cpp:263
Context & getContext() const
Definition Region.h:169
static LLVM_ABI Constant * reinterpretConstant(Constant *C, Type *DestTy, const DataLayout &DL)
Reinterprets constant C as DestTy, e.g., float 1.0 to i32 0x3f800000, or a null pointer to i64 0.
static LLVM_ABI Value * reinterpretValue(Value *V, Type *DestTy, BasicBlock::iterator WhereIt, Context &Ctx, const DataLayout &DL)
Reinterprets V as DestTy, which must have the same size in DL, inserting casts before WhereIt.
static LLVM_ABI bool canReinterpret(Type *SrcTy, Type *DestTy, const DataLayout &DL)
static LLVM_ABI StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition Type.h:48
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition Type.h:301
LLVM_ABI Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:206
Represents a Def-use/Use-def edge in SandboxIR.
Definition Use.h:42
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
Definition Utils.h:69
static void propagateMetadataForVectorization(Instruction *I, const ValueRangeT &VL)
Definition Utils.h:149
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
static Instruction * getLowest(ArrayRef< Instruction * > Instrs)
\Returns the instruction in Instrs that is lowest in the BB.
Definition VecUtils.h:240
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
Definition VecUtils.h:134
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:418
static LLVM_DUMP_METHOD void dump(ArrayRef< Value * > Bndl)
Helper dump function for debugging.
Definition VecUtils.cpp:166
static Align getVecAlignment(AlignRangeT AlignRange, TypeRangeT TypeRange)
Given the alignments of the instructions before vectorization, this returns the alignment of the vect...
Definition VecUtils.h:547
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:205
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
BndlRef(const T &OneElt) -> BndlRef< T >
static void lazyRAUWIf(Value *V, function_ref< bool(const Use &)> ShouldReplace, function_ref< Value *()> NewValBuilder)
Replaces the uses of V for which ShouldReplace returns true with the value returned by NewValBuilder.
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
static bool isNonIntegralPtr(Type *Ty, const DataLayout &DL)
static Type * getWidenedType(Type *ElemTy, unsigned N)
This is an optimization pass for GlobalISel generic memory operations.
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:1755
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:366
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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
DWARFExpression::Operation Op
const VectorizeOptions & getVectorizeOptions(const LLVMContext &C)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
#define N