LLVM 24.0.0git
BundleVec.cpp
Go to the documentation of this file.
1//===- BundleVec.cpp - A bundle-forming SLP-style vectorizer pass ---------===//
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
19
20namespace llvm {
21
22#ifndef NDEBUG
23static cl::opt<bool>
24 AlwaysVerify("sbvec-always-verify", cl::init(false), cl::Hidden,
25 cl::desc("Helps find bugs by verifying the IR whenever we "
26 "emit new instructions (*very* expensive)."));
27#endif // NDEBUG
28
29static constexpr unsigned long StopAtDisabled =
30 std::numeric_limits<unsigned long>::max();
33 cl::desc("Vectorize if the invocation count is < than this. 0 "
34 "disables vectorization."));
35
36static constexpr unsigned long StopBundleDisabled =
37 std::numeric_limits<unsigned long>::max();
40 cl::desc("Vectorize up to this many bundles."));
41
42namespace sandboxir {
43
44static BundleTy getOperand(ArrayRef<Value *> Bndl, unsigned OpIdx) {
46 for (Value *BndlV : Bndl) {
47 auto *BndlI = cast<Instruction>(BndlV);
48 Operands.push_back(BndlI->getOperand(OpIdx));
49 }
50 return Operands;
51}
52
53Value *BundleVec::createVectorInstr(ArrayRef<Value *> Bndl,
55 auto CreateVectorInstr = [](ArrayRef<Value *> Bndl,
57 assert(all_of(Bndl, [](auto *V) { return isa<Instruction>(V); }) &&
58 "Expect Instructions!");
59 auto &Ctx = Bndl[0]->getContext();
60
61 Type *ScalarTy = VecUtils::getElementType(Utils::getExpectedType(Bndl[0]));
62 auto *VecTy = VecUtils::getWideType(ScalarTy, VecUtils::getNumLanes(Bndl));
63
65 Bndl, cast<Instruction>(Bndl[0])->getParent());
66
67 auto Opcode = cast<Instruction>(Bndl[0])->getOpcode();
68 switch (Opcode) {
69 case Instruction::Opcode::ZExt:
70 case Instruction::Opcode::SExt:
71 case Instruction::Opcode::FPToUI:
72 case Instruction::Opcode::FPToSI:
73 case Instruction::Opcode::FPExt:
74 case Instruction::Opcode::PtrToInt:
75 case Instruction::Opcode::IntToPtr:
76 case Instruction::Opcode::SIToFP:
77 case Instruction::Opcode::UIToFP:
78 case Instruction::Opcode::Trunc:
79 case Instruction::Opcode::FPTrunc:
80 case Instruction::Opcode::BitCast: {
81 assert(Operands.size() == 1u && "Casts are unary!");
82 return CastInst::create(VecTy, Opcode, Operands[0], WhereIt, Ctx,
83 "VCast");
84 }
85 case Instruction::Opcode::FCmp:
86 case Instruction::Opcode::ICmp: {
87 auto Pred = cast<CmpInst>(Bndl[0])->getPredicate();
89 [Pred](auto *SBV) {
90 return cast<CmpInst>(SBV)->getPredicate() == Pred;
91 }) &&
92 "Expected same predicate across bundle.");
93 return CmpInst::create(Pred, Operands[0], Operands[1], WhereIt, Ctx,
94 "VCmp");
95 }
96 case Instruction::Opcode::Select: {
97 return SelectInst::create(Operands[0], Operands[1], Operands[2], WhereIt,
98 Ctx, "Vec");
99 }
100 case Instruction::Opcode::FNeg: {
101 auto *UOp0 = cast<UnaryOperator>(Bndl[0]);
102 auto OpC = UOp0->getOpcode();
104 WhereIt, Ctx, "Vec");
105 }
106 case Instruction::Opcode::Add:
107 case Instruction::Opcode::FAdd:
108 case Instruction::Opcode::Sub:
109 case Instruction::Opcode::FSub:
110 case Instruction::Opcode::Mul:
111 case Instruction::Opcode::FMul:
112 case Instruction::Opcode::UDiv:
113 case Instruction::Opcode::SDiv:
114 case Instruction::Opcode::FDiv:
115 case Instruction::Opcode::URem:
116 case Instruction::Opcode::SRem:
117 case Instruction::Opcode::FRem:
118 case Instruction::Opcode::Shl:
119 case Instruction::Opcode::LShr:
120 case Instruction::Opcode::AShr:
121 case Instruction::Opcode::And:
122 case Instruction::Opcode::Or:
123 case Instruction::Opcode::Xor: {
124 auto *BinOp0 = cast<BinaryOperator>(Bndl[0]);
125 auto *LHS = Operands[0];
126 auto *RHS = Operands[1];
128 BinOp0->getOpcode(), LHS, RHS, BinOp0, WhereIt, Ctx, "Vec");
129 }
130 case Instruction::Opcode::Load: {
131 auto *Ld0 = cast<LoadInst>(Bndl[0]);
132 Value *Ptr = Ld0->getPointerOperand();
133 return LoadInst::create(VecTy, Ptr, Ld0->getAlign(), WhereIt, Ctx,
134 "VecL");
135 }
136 case Instruction::Opcode::Store: {
137 auto Align = cast<StoreInst>(Bndl[0])->getAlign();
138 Value *Val = Operands[0];
139 Value *Ptr = Operands[1];
140 return StoreInst::create(Val, Ptr, Align, WhereIt, Ctx);
141 }
142 case Instruction::Opcode::UncondBr:
143 case Instruction::Opcode::CondBr:
144 case Instruction::Opcode::Ret:
145 case Instruction::Opcode::PHI:
146 case Instruction::Opcode::AddrSpaceCast:
147 case Instruction::Opcode::Call:
148 case Instruction::Opcode::GetElementPtr:
149 llvm_unreachable("Unimplemented");
150 break;
151 default:
152 llvm_unreachable("Unimplemented");
153 break;
154 }
155 llvm_unreachable("Missing switch case!");
156 // TODO: Propagate debug info.
157 };
158
159 auto *NewI = CreateVectorInstr(Bndl, Operands);
160 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "New instr: " << *NewI << "\n");
161 return NewI;
162}
163
164Value *BundleVec::createShuffle(Value *VecOp, const ShuffleMask &Mask,
165 BasicBlock *UserBB) {
166 BasicBlock::iterator WhereIt =
168 return ShuffleVectorInst::create(VecOp, VecOp, Mask, WhereIt,
169 VecOp->getContext(), "VShuf");
170}
171
172Value *BundleVec::createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB) {
173 BasicBlock::iterator WhereIt =
175
176 Type *ScalarTy = VecUtils::getCommonScalarType(ToPack);
177 unsigned Lanes = VecUtils::getNumLanes(ToPack);
178 Type *VecTy = VecUtils::getWideType(ScalarTy, Lanes);
179
180 // Create a series of pack instructions.
181 Value *LastInsert = PoisonValue::get(VecTy);
182
183 Context &Ctx = ToPack[0]->getContext();
184
185 unsigned InsertIdx = 0;
186 for (Value *Elm : ToPack) {
187 // An element can be either scalar or vector. We need to generate different
188 // IR for each case.
189 if (Elm->getType()->isVectorTy()) {
190 unsigned NumElms =
191 cast<FixedVectorType>(Elm->getType())->getNumElements();
192 for (auto ExtrLane : seq<int>(0, NumElms)) {
193 // We generate extract-insert pairs, for each lane in `Elm`.
194 Constant *ExtrLaneC =
196 // This may return a Constant if Elm is a Constant.
197 auto *ExtrI =
198 ExtractElementInst::create(Elm, ExtrLaneC, WhereIt, Ctx, "VPack");
199 if (!isa<Constant>(ExtrI))
200 WhereIt = std::next(cast<Instruction>(ExtrI)->getIterator());
201 Constant *InsertLaneC =
202 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
203 // This may also return a Constant if ExtrI is a Constant.
204 auto *InsertI = InsertElementInst::create(
205 LastInsert, ExtrI, InsertLaneC, WhereIt, Ctx, "VPack");
206 LastInsert = InsertI;
207 if (!isa<Constant>(InsertI))
208 WhereIt = std::next(cast<Instruction>(LastInsert)->getIterator());
209 }
210 } else {
211 Constant *InsertLaneC =
212 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
213 // This may be folded into a Constant if LastInsert is a Constant. In
214 // that case we only collect the last constant.
215 LastInsert = InsertElementInst::create(LastInsert, Elm, InsertLaneC,
216 WhereIt, Ctx, "Pack");
217 if (auto *NewI = dyn_cast<Instruction>(LastInsert))
218 WhereIt = std::next(NewI->getIterator());
219 }
220 }
221 return LastInsert;
222}
223
224Action *BundleVec::vectorizeRec(ArrayRef<Value *> Bndl,
225 ArrayRef<Value *> UserBndl, unsigned Depth,
226 LegalityAnalysis &Legality) {
227 bool StopForDebug =
228 DebugBndlCnt++ >= StopBundle && StopBundle != StopBundleDisabled;
229 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
230 VecUtils::dump(Bndl));
231 const auto &LegalityRes = StopForDebug ? Legality.getForcedPackForDebugging()
232 : Legality.canVectorize(Bndl);
233 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
234
235 if (Dir == SchedDirection::TopDown) {
236 // A non-Widen result means we can't extend the vectorized region into
237 // this bundle, so leave its instructions scalar and don't record an
238 // action for it.
239 if (LegalityRes.getSubclassID() != LegalityResultID::Widen)
240 return nullptr;
241
242 auto ActionPtr = std::make_unique<Action>(&LegalityRes, Bndl,
244 Action *Action = ActionPtr.get();
245 IMaps->registerVector(Bndl, Action);
246 Actions.push_back(std::move(ActionPtr));
247
248 // Walk down the def-use chain. Each lane in \p Bndl may feed several
249 // users, so we form every compatible user bundle and recurse into each
250 // one.
251 SmallPtrSet<Instruction *, 4> Claimed;
252 for (const auto &NextUserBndl :
253 VecUtils::getNextUserBundles(Bndl, *IMaps, Claimed))
254 vectorizeRec(NextUserBndl, Bndl, Depth + 1, Legality);
255
256 return Action;
257 }
258
259 // Bottom up direction
260 auto ActionPtr =
261 std::make_unique<Action>(&LegalityRes, Bndl, UserBndl, Depth);
263 switch (LegalityRes.getSubclassID()) {
265 auto *I = cast<Instruction>(Bndl[0]);
266 switch (I->getOpcode()) {
267 case Instruction::Opcode::Load:
268 break;
269 case Instruction::Opcode::Store: {
270 // Don't recurse towards the pointer operand.
271 Action *OpA =
272 vectorizeRec(getOperand(Bndl, 0), Bndl, Depth + 1, Legality);
273 Operands.push_back(OpA);
274 break;
275 }
276 default:
277 // Visit all operands.
278 for (auto OpIdx : seq<unsigned>(I->getNumOperands())) {
279 Action *OpA =
280 vectorizeRec(getOperand(Bndl, OpIdx), Bndl, Depth + 1, Legality);
281 Operands.push_back(OpA);
282 }
283 break;
284 }
285 // Update the maps to mark Bndl as "vectorized".
286 IMaps->registerVector(Bndl, ActionPtr.get());
287 break;
288 }
293 break;
294 }
295 // Create actions in post-order.
296 ActionPtr->Operands = std::move(Operands);
297 auto *Action = ActionPtr.get();
298 Actions.push_back(std::move(ActionPtr));
299 return Action;
300}
301
302#ifndef NDEBUG
303void BundleVec::ActionsVector::print(raw_ostream &OS) const {
304 for (auto [Idx, Action] : enumerate(Actions)) {
305 Action->print(OS);
306 OS << "\n";
307 }
308}
309void BundleVec::ActionsVector::dump() const { print(dbgs()); }
310#endif // NDEBUG
311
312void BundleVec::emitUnpacksForExternalUses(const ArrayRef<Value *> Bndl,
313 Value *Vec) {
314 // Find where we should emit the unpacks.
315 BasicBlock::iterator WhereIt;
316 if (auto *VecI = dyn_cast<Instruction>(Vec)) {
317 WhereIt = std::next(VecI->getIterator());
318 } else {
319 // If Vec is a constant then it should be safe to emit the unpacks at the
320 // top of the block.
321 // Note: Extracts from constants are usually folded to constants.
322 assert(isa<Constant>(Vec) && "Expected constant!");
323 assert(isa<Instruction>(Bndl[0]) &&
324 "A widened Bndl should contain instrs!");
325 BasicBlock *BB = cast<Instruction>(Bndl[0])->getParent();
326 WhereIt =
327 BB->empty()
328 ? BB->begin()
329 : std::next(
330 VecUtils::getLastPHIOrSelf(&*BB->begin())->getIterator());
331 }
332
333 for (auto [Lane, Elm] : VecUtils::enumerateLanes(Bndl)) {
334 // Only redirect the external (non-vectorized) uses to an unpack and leave
335 // the vectorized users untouched. A blanket replaceAllUsesWith() would
336 // also rewrite the operands of users we are going to vectorize but have
337 // not emitted yet (in the top-down direction a user bundle is emitted
338 // after its operand bundle), which would corrupt those operands.
339 auto IsExternal = [this](const Use &U) {
340 return !IMaps->isVectorized(U.getUser());
341 };
342 // Don't emit a dead unpack if all uses are internal to the vector region.
343 if (none_of(Elm->uses(), IsExternal))
344 continue;
345 auto *UnpackV = VecUtils::unpack(Vec, Elm->getType(), Lane, WhereIt);
346 Elm->replaceUsesWithIf(UnpackV, IsExternal);
347 }
348}
349
350Value *BundleVec::emitVectors() {
351 Value *NewVec = nullptr;
352 for (const auto &ActionPtr : Actions) {
353 ArrayRef<Value *> Bndl = ActionPtr->Bndl;
354 ArrayRef<Value *> UserBndl = ActionPtr->UserBndl;
355 const LegalityResult &LegalityRes = *ActionPtr->LegalityRes;
356 unsigned Depth = ActionPtr->Depth;
357 auto *UserBB = !UserBndl.empty()
358 ? cast<Instruction>(UserBndl.front())->getParent()
359 : cast<Instruction>(Bndl[0])->getParent();
360
361 switch (LegalityRes.getSubclassID()) {
363 auto *I = cast<Instruction>(Bndl[0]);
364 SmallVector<Value *, 2> VecOperands;
365 if (Dir == SchedDirection::BottomUp) {
366 switch (I->getOpcode()) {
367 case Instruction::Opcode::Load:
368 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
369 break;
370 case Instruction::Opcode::Store:
371 VecOperands.push_back(ActionPtr->Operands[0]->Vec);
372 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
373 break;
374 default:
375 for (Action *OpA : ActionPtr->Operands)
376 VecOperands.push_back(OpA->Vec);
377 break;
378 }
379 } else {
380 switch (I->getOpcode()) {
381 case Instruction::Opcode::Load:
382 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
383 break;
384 case Instruction::Opcode::Store: {
385 auto OpBndl = getOperand(Bndl, 0);
386 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
387 VecOperands.push_back(OpA->Vec);
388 else
389 VecOperands.push_back(createPack(OpBndl, UserBB));
390 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
391 break;
392 }
393 default:
394 for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) {
395 BundleTy OpBndl = getOperand(Bndl, OpIdx);
396 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
397 VecOperands.push_back(OpA->Vec);
398 else
399 VecOperands.push_back(createPack(OpBndl, UserBB));
400 }
401 break;
402 }
403 }
404 NewVec = createVectorInstr(ActionPtr->Bndl, VecOperands);
405 // Collect any potentially dead scalar instructions, including the
406 // original scalars and pointer operands of loads/stores.
407 if (NewVec != nullptr)
408 DeadInstrMorgue.collectPotentiallyDeadInstrs(Bndl);
409
410 // Emit unpacks for all external uses, if any.
411 emitUnpacksForExternalUses(ActionPtr->Bndl, NewVec);
412 break;
413 }
415 NewVec = cast<DiamondReuse>(LegalityRes).getVector()->Vec;
416 break;
417 }
419 auto *VecOp = cast<DiamondReuseWithShuffle>(LegalityRes).getVector()->Vec;
420 const ShuffleMask &Mask =
421 cast<DiamondReuseWithShuffle>(LegalityRes).getMask();
422 NewVec = createShuffle(VecOp, Mask, UserBB);
423 assert(NewVec->getType() == VecOp->getType() &&
424 "Expected same type! Bad mask ?");
425 break;
426 }
428 const auto &Descr =
429 cast<DiamondReuseMultiInput>(LegalityRes).getCollectDescr();
430 Type *ResTy = VecUtils::getWideType(Bndl[0]->getType(), Bndl.size());
431
432 // TODO: Try to get WhereIt without creating a vector.
433 SmallVector<Value *, 4> DescrInstrs;
434 for (const auto &ElmDescr : Descr.getDescrs()) {
435 auto *V = ElmDescr.needsExtract() ? ElmDescr.getValue()->Vec
436 : ElmDescr.getScalar();
437 if (auto *I = dyn_cast<Instruction>(V))
438 DescrInstrs.push_back(I);
439 }
440 BasicBlock::iterator WhereIt =
441 VecUtils::getInsertPointAfterInstrs(DescrInstrs, UserBB);
442
443 Value *LastV = PoisonValue::get(ResTy);
444 Context &Ctx = LastV->getContext();
445 unsigned Lane = 0;
446 for (const auto &ElmDescr : Descr.getDescrs()) {
447 Value *VecOp = nullptr;
448 Value *ValueToInsert;
449 if (ElmDescr.needsExtract()) {
450 VecOp = ElmDescr.getValue()->Vec;
451 ConstantInt *IdxC =
452 ConstantInt::get(Type::getInt32Ty(Ctx), ElmDescr.getExtractIdx());
453 ValueToInsert = ExtractElementInst::create(
454 VecOp, IdxC, WhereIt, VecOp->getContext(), "VExt");
455 } else {
456 ValueToInsert = ElmDescr.getScalar();
457 }
458 auto NumLanesToInsert = VecUtils::getNumLanes(ValueToInsert);
459 if (NumLanesToInsert == 1) {
460 // If we are inserting a scalar element then we need a single insert.
461 // %VIns = insert %DstVec, %SrcScalar, Lane
462 ConstantInt *LaneC = ConstantInt::get(Type::getInt32Ty(Ctx), Lane);
463 LastV = InsertElementInst::create(LastV, ValueToInsert, LaneC,
464 WhereIt, Ctx, "VIns");
465 } else {
466 // If we are inserting a vector element then we need to extract and
467 // insert each vector element one by one with a chain of extracts and
468 // inserts, for example:
469 // %VExt0 = extract %SrcVec, 0
470 // %VIns0 = insert %DstVec, %Vect0, Lane + 0
471 // %VExt1 = extract %SrcVec, 1
472 // %VIns1 = insert %VIns0, %Vect0, Lane + 1
473 for (unsigned LnCnt = 0; LnCnt != NumLanesToInsert; ++LnCnt) {
474 auto *ExtrIdxC = ConstantInt::get(Type::getInt32Ty(Ctx), LnCnt);
475 auto *ExtrI = ExtractElementInst::create(ValueToInsert, ExtrIdxC,
476 WhereIt, Ctx, "VExt");
477 unsigned InsLane = Lane + LnCnt;
478 auto *InsLaneC = ConstantInt::get(Type::getInt32Ty(Ctx), InsLane);
479 LastV = InsertElementInst::create(LastV, ExtrI, InsLaneC, WhereIt,
480 Ctx, "VIns");
481 }
482 }
483 Lane += NumLanesToInsert;
484 }
485 NewVec = LastV;
486 break;
487 }
489 // If we can't vectorize the seeds then just return.
490 if (Depth == 0)
491 return nullptr;
492 NewVec = createPack(Bndl, UserBB);
493 break;
494 }
495 }
496 if (NewVec != nullptr) {
497 Change = true;
498 ActionPtr->Vec = NewVec;
499 }
500#ifndef NDEBUG
501 if (AlwaysVerify) {
502 // This helps find broken IR by constantly verifying the function. Note
503 // that this is very expensive and should only be used for debugging.
504 Instruction *I0 = isa<Instruction>(Bndl[0])
505 ? cast<Instruction>(Bndl[0])
506 : cast<Instruction>(UserBndl[0]);
507 assert(!Utils::verifyFunction(I0->getParent()->getParent(), dbgs()) &&
508 "Broken function!");
509 }
510#endif // NDEBUG
511 }
512 return NewVec;
513}
514
515bool BundleVec::tryVectorize(ArrayRef<Value *> Bndl,
516 LegalityAnalysis &Legality) {
517 Change = false;
518 if (LLVM_UNLIKELY(InvocationCnt++ >= StopAt && StopAt != StopAtDisabled))
519 return false;
520 Legality.clear();
521 Actions.clear();
522 DebugBndlCnt = 0;
523 vectorizeRec(Bndl, {}, /*Depth=*/0, Legality);
525 << "Vec: Vectorization Actions:\n";
526 Actions.dump());
527 emitVectors();
528 DeadInstrMorgue.tryEraseDeadInstrs();
529 return Change;
530}
531
533 const auto &SeedSlice = Rgn.getAux();
534 if (SeedSlice.size() < 2)
535 return false;
536 Function &F = *SeedSlice[0]->getParent()->getParent();
537 IMaps = std::make_unique<InstrMaps>();
538 LegalityAnalysis Legality(A.getAA(), A.getScalarEvolution(),
539 F.getParent()->getDataLayout(), F.getContext(),
540 *IMaps, Dir);
541
542 // TODO: Refactor to remove the unnecessary copy to SeedSliceVals.
543 SmallVector<Value *> SeedSliceVals(SeedSlice.begin(), SeedSlice.end());
544 // Try to vectorize starting from the seed slice. The returned value
545 // is true if we found vectorizable code and generated some vector
546 // code for it. It does not mean that the code is profitable.
547 return tryVectorize(SeedSliceVals, Legality);
548}
549
550} // namespace sandboxir
551} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_UNLIKELY(EXPR)
Definition Compiler.h:344
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
SI Fold Operands
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
#define DEBUG_PREFIX
Definition Debug.h:19
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
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
static LLVM_ABI Value * createWithCopiedFlags(Instruction::Opcode Op, Value *LHS, Value *RHS, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
bool runOnRegion(Region &Rgn, const Analyses &A) final
\Returns true if it modifies R.
static LLVM_ABI Value * create(Type *DestTy, Opcode Op, Value *Operand, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Value * create(Predicate Pred, Value *S1, Value *S2, InsertPosition Pos, Context &Ctx, const Twine &Name="")
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 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 Value * create(Value *Vec, Value *NewElt, Value *Idx, InsertPosition Pos, Context &Ctx, const Twine &Name="")
LLVM_ABI BBIterator getIterator() const
\Returns a BasicBlock::iterator for this Instruction.
Performs the legality analysis and returns a LegalityResult object.
Definition Legality.h:318
static LLVM_ABI LoadInst * create(Type *Ty, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx, const Twine &Name="")
virtual void print(raw_ostream &OS) const
Definition Pass.h:67
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition Constant.cpp:263
const SmallVector< Instruction * > & getAux() const
\Returns the auxiliary vector.
Definition Region.h:177
static LLVM_ABI Value * create(Value *Cond, Value *True, Value *False, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI Value * create(Value *V1, Value *V2, Value *Mask, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static LLVM_ABI StoreInst * create(Value *V, Value *Ptr, MaybeAlign Align, InsertPosition Pos, bool IsVolatile, Context &Ctx)
static LLVM_ABI IntegerType * getInt32Ty(Context &Ctx)
Definition Type.cpp:21
static LLVM_ABI Value * createWithCopiedFlags(Instruction::Opcode Op, Value *OpV, Value *CopyFrom, InsertPosition Pos, Context &Ctx, const Twine &Name="")
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
Definition Utils.h:32
static bool verifyFunction(const Function *F, raw_ostream &OS)
Equivalent to llvm::verifyFunction().
Definition Utils.h:131
A SandboxIR Value has users. This is the base class.
Definition Value.h:72
static Type * getCommonScalarType(ArrayRef< Value * > Bndl)
Similar to tryGetCommonScalarType() but will assert that there is a common type.
Definition VecUtils.h:236
static Instruction * getLastPHIOrSelf(Instruction *I)
If I is not a PHI it returns it.
Definition VecUtils.h:195
static unsigned getNumLanes(Type *Ty)
\Returns the number of vector lanes of Ty or 1 if not a vector.
Definition VecUtils.h:90
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:323
static LLVM_DUMP_METHOD void dump(ArrayRef< Value * > Bndl)
Helper dump function for debugging.
Definition VecUtils.cpp:160
static Type * getWideType(Type *ElemTy, unsigned NumElts)
\Returns <NumElts x ElemTy>.
Definition VecUtils.h:113
static auto enumerateLanes(const ValueContainerT &Range)
Helper for creating LaneValueEnumerator ranges.
Definition VecUtils.h:441
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Definition VecUtils.h:50
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:207
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:69
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
initializer< Ty > init(const Ty &Val)
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
LLVM_ABI Function * getParent() const
StringLiteral schedDirectionToStr(SchedDirection Dir)
BasicBlock(llvm::BasicBlock *BB, Context &SBCtx)
Definition BasicBlock.h:75
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
SmallVector< Value *, 4 > BundleTy
Definition VecUtils.h:38
static BundleTy getOperand(ArrayRef< Value * > Bndl, unsigned OpIdx)
Definition BundleVec.cpp:44
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:315
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
static cl::opt< unsigned long > StopAt("sbvec-stop-at", cl::init(StopAtDisabled), cl::Hidden, cl::desc("Vectorize if the invocation count is < than this. 0 " "disables vectorization."))
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
static constexpr unsigned long StopBundleDisabled
Definition BundleVec.cpp:36
static cl::opt< unsigned long > StopBundle("sbvec-stop-bndl", cl::init(StopBundleDisabled), cl::Hidden, cl::desc("Vectorize up to this many bundles."))
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
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
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
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
ArrayRef(const T &OneElt) -> ArrayRef< T >
static constexpr unsigned long StopAtDisabled
Definition BundleVec.cpp:29
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
static cl::opt< bool > AlwaysVerify("sbvec-always-verify", cl::init(false), cl::Hidden, cl::desc("Helps find bugs by verifying the IR whenever we " "emit new instructions (*very* expensive)."))