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
164void BundleVec::tryEraseDeadInstrs() {
165 DenseMap<BasicBlock *, SmallVector<Instruction *>> SortedDeadInstrCandidates;
166 // The dead instrs could span BBs, so we need to collect and sort them per BB.
167 for (auto *DeadI : DeadInstrCandidates)
168 SortedDeadInstrCandidates[DeadI->getParent()].push_back(DeadI);
169 for (auto &Pair : SortedDeadInstrCandidates)
170 sort(Pair.second,
171 [](Instruction *I1, Instruction *I2) { return I1->comesBefore(I2); });
172 for (const auto &Pair : SortedDeadInstrCandidates) {
173 for (Instruction *I : reverse(Pair.second)) {
174 if (I->hasNUses(0)) {
175 // Erase the dead instructions bottom-to-top.
176 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Erase dead: " << *I << "\n");
177 I->eraseFromParent();
178 }
179 }
180 }
181 DeadInstrCandidates.clear();
182}
183
184Value *BundleVec::createShuffle(Value *VecOp, const ShuffleMask &Mask,
185 BasicBlock *UserBB) {
186 BasicBlock::iterator WhereIt =
188 return ShuffleVectorInst::create(VecOp, VecOp, Mask, WhereIt,
189 VecOp->getContext(), "VShuf");
190}
191
192Value *BundleVec::createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB) {
193 BasicBlock::iterator WhereIt =
195
196 Type *ScalarTy = VecUtils::getCommonScalarType(ToPack);
197 unsigned Lanes = VecUtils::getNumLanes(ToPack);
198 Type *VecTy = VecUtils::getWideType(ScalarTy, Lanes);
199
200 // Create a series of pack instructions.
201 Value *LastInsert = PoisonValue::get(VecTy);
202
203 Context &Ctx = ToPack[0]->getContext();
204
205 unsigned InsertIdx = 0;
206 for (Value *Elm : ToPack) {
207 // An element can be either scalar or vector. We need to generate different
208 // IR for each case.
209 if (Elm->getType()->isVectorTy()) {
210 unsigned NumElms =
211 cast<FixedVectorType>(Elm->getType())->getNumElements();
212 for (auto ExtrLane : seq<int>(0, NumElms)) {
213 // We generate extract-insert pairs, for each lane in `Elm`.
214 Constant *ExtrLaneC =
216 // This may return a Constant if Elm is a Constant.
217 auto *ExtrI =
218 ExtractElementInst::create(Elm, ExtrLaneC, WhereIt, Ctx, "VPack");
219 if (!isa<Constant>(ExtrI))
220 WhereIt = std::next(cast<Instruction>(ExtrI)->getIterator());
221 Constant *InsertLaneC =
222 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
223 // This may also return a Constant if ExtrI is a Constant.
224 auto *InsertI = InsertElementInst::create(
225 LastInsert, ExtrI, InsertLaneC, WhereIt, Ctx, "VPack");
226 LastInsert = InsertI;
227 if (!isa<Constant>(InsertI))
228 WhereIt = std::next(cast<Instruction>(LastInsert)->getIterator());
229 }
230 } else {
231 Constant *InsertLaneC =
232 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
233 // This may be folded into a Constant if LastInsert is a Constant. In
234 // that case we only collect the last constant.
235 LastInsert = InsertElementInst::create(LastInsert, Elm, InsertLaneC,
236 WhereIt, Ctx, "Pack");
237 if (auto *NewI = dyn_cast<Instruction>(LastInsert))
238 WhereIt = std::next(NewI->getIterator());
239 }
240 }
241 return LastInsert;
242}
243
244void BundleVec::collectPotentiallyDeadInstrs(ArrayRef<Value *> Bndl) {
245 for (Value *V : Bndl)
246 DeadInstrCandidates.insert(cast<Instruction>(V));
247 // Also collect the GEPs of vectorized loads and stores.
248 auto Opcode = cast<Instruction>(Bndl[0])->getOpcode();
249 switch (Opcode) {
250 case Instruction::Opcode::Load: {
251 for (Value *V : drop_begin(Bndl))
252 if (auto *Ptr =
254 DeadInstrCandidates.insert(Ptr);
255 break;
256 }
257 case Instruction::Opcode::Store: {
258 for (Value *V : drop_begin(Bndl))
259 if (auto *Ptr =
261 DeadInstrCandidates.insert(Ptr);
262 break;
263 }
264 default:
265 break;
266 }
267}
268
269Action *BundleVec::vectorizeRec(ArrayRef<Value *> Bndl,
270 ArrayRef<Value *> UserBndl, unsigned Depth,
271 LegalityAnalysis &Legality) {
272 bool StopForDebug =
273 DebugBndlCnt++ >= StopBundle && StopBundle != StopBundleDisabled;
274 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
275 VecUtils::dump(Bndl));
276 const auto &LegalityRes = StopForDebug ? Legality.getForcedPackForDebugging()
277 : Legality.canVectorize(Bndl);
278 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
279
280 if (Dir == SchedDirection::TopDown) {
281 // A non-Widen result means we can't extend the vectorized region into
282 // this bundle, so leave its instructions scalar and don't record an
283 // action for it.
284 if (LegalityRes.getSubclassID() != LegalityResultID::Widen)
285 return nullptr;
286
287 auto ActionPtr = std::make_unique<Action>(&LegalityRes, Bndl,
289 Action *Action = ActionPtr.get();
290 IMaps->registerVector(Bndl, Action);
291 Actions.push_back(std::move(ActionPtr));
292
293 // Walk down the def-use chain. Each lane in \p Bndl may feed several
294 // users, so we form every compatible user bundle and recurse into each
295 // one.
296 SmallPtrSet<Instruction *, 4> Claimed;
297 for (const auto &NextUserBndl :
298 VecUtils::getNextUserBundles(Bndl, *IMaps, Claimed))
299 vectorizeRec(NextUserBndl, Bndl, Depth + 1, Legality);
300
301 return Action;
302 }
303
304 // Bottom up direction
305 auto ActionPtr =
306 std::make_unique<Action>(&LegalityRes, Bndl, UserBndl, Depth);
308 switch (LegalityRes.getSubclassID()) {
310 auto *I = cast<Instruction>(Bndl[0]);
311 switch (I->getOpcode()) {
312 case Instruction::Opcode::Load:
313 break;
314 case Instruction::Opcode::Store: {
315 // Don't recurse towards the pointer operand.
316 Action *OpA =
317 vectorizeRec(getOperand(Bndl, 0), Bndl, Depth + 1, Legality);
318 Operands.push_back(OpA);
319 break;
320 }
321 default:
322 // Visit all operands.
323 for (auto OpIdx : seq<unsigned>(I->getNumOperands())) {
324 Action *OpA =
325 vectorizeRec(getOperand(Bndl, OpIdx), Bndl, Depth + 1, Legality);
326 Operands.push_back(OpA);
327 }
328 break;
329 }
330 // Update the maps to mark Bndl as "vectorized".
331 IMaps->registerVector(Bndl, ActionPtr.get());
332 break;
333 }
338 break;
339 }
340 // Create actions in post-order.
341 ActionPtr->Operands = std::move(Operands);
342 auto *Action = ActionPtr.get();
343 Actions.push_back(std::move(ActionPtr));
344 return Action;
345}
346
347#ifndef NDEBUG
348void BundleVec::ActionsVector::print(raw_ostream &OS) const {
349 for (auto [Idx, Action] : enumerate(Actions)) {
350 Action->print(OS);
351 OS << "\n";
352 }
353}
354void BundleVec::ActionsVector::dump() const { print(dbgs()); }
355#endif // NDEBUG
356
357void BundleVec::emitUnpacksForExternalUses(const ArrayRef<Value *> Bndl,
358 Value *Vec) {
359 // Find where we should emit the unpacks.
360 BasicBlock::iterator WhereIt;
361 if (auto *VecI = dyn_cast<Instruction>(Vec)) {
362 WhereIt = std::next(VecI->getIterator());
363 } else {
364 // If Vec is a constant then it should be safe to emit the unpacks at the
365 // top of the block.
366 // Note: Extracts from constants are usually folded to constants.
367 assert(isa<Constant>(Vec) && "Expected constant!");
368 assert(isa<Instruction>(Bndl[0]) &&
369 "A widened Bndl should contain instrs!");
370 BasicBlock *BB = cast<Instruction>(Bndl[0])->getParent();
371 WhereIt =
372 BB->empty()
373 ? BB->begin()
374 : std::next(
375 VecUtils::getLastPHIOrSelf(&*BB->begin())->getIterator());
376 }
377
378 for (auto [Lane, Elm] : VecUtils::enumerateLanes(Bndl)) {
379 // Only redirect the external (non-vectorized) uses to an unpack and leave
380 // the vectorized users untouched. A blanket replaceAllUsesWith() would
381 // also rewrite the operands of users we are going to vectorize but have
382 // not emitted yet (in the top-down direction a user bundle is emitted
383 // after its operand bundle), which would corrupt those operands.
384 auto IsExternal = [this](const Use &U) {
385 return !IMaps->isVectorized(U.getUser());
386 };
387 // Don't emit a dead unpack if all uses are internal to the vector region.
388 if (none_of(Elm->uses(), IsExternal))
389 continue;
390 auto *UnpackV = VecUtils::unpack(Vec, Elm->getType(), Lane, WhereIt);
391 Elm->replaceUsesWithIf(UnpackV, IsExternal);
392 }
393}
394
395Value *BundleVec::emitVectors() {
396 Value *NewVec = nullptr;
397 for (const auto &ActionPtr : Actions) {
398 ArrayRef<Value *> Bndl = ActionPtr->Bndl;
399 ArrayRef<Value *> UserBndl = ActionPtr->UserBndl;
400 const LegalityResult &LegalityRes = *ActionPtr->LegalityRes;
401 unsigned Depth = ActionPtr->Depth;
402 auto *UserBB = !UserBndl.empty()
403 ? cast<Instruction>(UserBndl.front())->getParent()
404 : cast<Instruction>(Bndl[0])->getParent();
405
406 switch (LegalityRes.getSubclassID()) {
408 auto *I = cast<Instruction>(Bndl[0]);
409 SmallVector<Value *, 2> VecOperands;
410 if (Dir == SchedDirection::BottomUp) {
411 switch (I->getOpcode()) {
412 case Instruction::Opcode::Load:
413 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
414 break;
415 case Instruction::Opcode::Store:
416 VecOperands.push_back(ActionPtr->Operands[0]->Vec);
417 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
418 break;
419 default:
420 for (Action *OpA : ActionPtr->Operands)
421 VecOperands.push_back(OpA->Vec);
422 break;
423 }
424 } else {
425 switch (I->getOpcode()) {
426 case Instruction::Opcode::Load:
427 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
428 break;
429 case Instruction::Opcode::Store: {
430 auto OpBndl = getOperand(Bndl, 0);
431 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
432 VecOperands.push_back(OpA->Vec);
433 else
434 VecOperands.push_back(createPack(OpBndl, UserBB));
435 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
436 break;
437 }
438 default:
439 for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) {
440 BundleTy OpBndl = getOperand(Bndl, OpIdx);
441 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
442 VecOperands.push_back(OpA->Vec);
443 else
444 VecOperands.push_back(createPack(OpBndl, UserBB));
445 }
446 break;
447 }
448 }
449 NewVec = createVectorInstr(ActionPtr->Bndl, VecOperands);
450 // Collect any potentially dead scalar instructions, including the
451 // original scalars and pointer operands of loads/stores.
452 if (NewVec != nullptr)
453 collectPotentiallyDeadInstrs(Bndl);
454
455 // Emit unpacks for all external uses, if any.
456 emitUnpacksForExternalUses(ActionPtr->Bndl, NewVec);
457 break;
458 }
460 NewVec = cast<DiamondReuse>(LegalityRes).getVector()->Vec;
461 break;
462 }
464 auto *VecOp = cast<DiamondReuseWithShuffle>(LegalityRes).getVector()->Vec;
465 const ShuffleMask &Mask =
466 cast<DiamondReuseWithShuffle>(LegalityRes).getMask();
467 NewVec = createShuffle(VecOp, Mask, UserBB);
468 assert(NewVec->getType() == VecOp->getType() &&
469 "Expected same type! Bad mask ?");
470 break;
471 }
473 const auto &Descr =
474 cast<DiamondReuseMultiInput>(LegalityRes).getCollectDescr();
475 Type *ResTy = VecUtils::getWideType(Bndl[0]->getType(), Bndl.size());
476
477 // TODO: Try to get WhereIt without creating a vector.
478 SmallVector<Value *, 4> DescrInstrs;
479 for (const auto &ElmDescr : Descr.getDescrs()) {
480 auto *V = ElmDescr.needsExtract() ? ElmDescr.getValue()->Vec
481 : ElmDescr.getScalar();
482 if (auto *I = dyn_cast<Instruction>(V))
483 DescrInstrs.push_back(I);
484 }
485 BasicBlock::iterator WhereIt =
486 VecUtils::getInsertPointAfterInstrs(DescrInstrs, UserBB);
487
488 Value *LastV = PoisonValue::get(ResTy);
489 Context &Ctx = LastV->getContext();
490 unsigned Lane = 0;
491 for (const auto &ElmDescr : Descr.getDescrs()) {
492 Value *VecOp = nullptr;
493 Value *ValueToInsert;
494 if (ElmDescr.needsExtract()) {
495 VecOp = ElmDescr.getValue()->Vec;
496 ConstantInt *IdxC =
497 ConstantInt::get(Type::getInt32Ty(Ctx), ElmDescr.getExtractIdx());
498 ValueToInsert = ExtractElementInst::create(
499 VecOp, IdxC, WhereIt, VecOp->getContext(), "VExt");
500 } else {
501 ValueToInsert = ElmDescr.getScalar();
502 }
503 auto NumLanesToInsert = VecUtils::getNumLanes(ValueToInsert);
504 if (NumLanesToInsert == 1) {
505 // If we are inserting a scalar element then we need a single insert.
506 // %VIns = insert %DstVec, %SrcScalar, Lane
507 ConstantInt *LaneC = ConstantInt::get(Type::getInt32Ty(Ctx), Lane);
508 LastV = InsertElementInst::create(LastV, ValueToInsert, LaneC,
509 WhereIt, Ctx, "VIns");
510 } else {
511 // If we are inserting a vector element then we need to extract and
512 // insert each vector element one by one with a chain of extracts and
513 // inserts, for example:
514 // %VExt0 = extract %SrcVec, 0
515 // %VIns0 = insert %DstVec, %Vect0, Lane + 0
516 // %VExt1 = extract %SrcVec, 1
517 // %VIns1 = insert %VIns0, %Vect0, Lane + 1
518 for (unsigned LnCnt = 0; LnCnt != NumLanesToInsert; ++LnCnt) {
519 auto *ExtrIdxC = ConstantInt::get(Type::getInt32Ty(Ctx), LnCnt);
520 auto *ExtrI = ExtractElementInst::create(ValueToInsert, ExtrIdxC,
521 WhereIt, Ctx, "VExt");
522 unsigned InsLane = Lane + LnCnt;
523 auto *InsLaneC = ConstantInt::get(Type::getInt32Ty(Ctx), InsLane);
524 LastV = InsertElementInst::create(LastV, ExtrI, InsLaneC, WhereIt,
525 Ctx, "VIns");
526 }
527 }
528 Lane += NumLanesToInsert;
529 }
530 NewVec = LastV;
531 break;
532 }
534 // If we can't vectorize the seeds then just return.
535 if (Depth == 0)
536 return nullptr;
537 NewVec = createPack(Bndl, UserBB);
538 break;
539 }
540 }
541 if (NewVec != nullptr) {
542 Change = true;
543 ActionPtr->Vec = NewVec;
544 }
545#ifndef NDEBUG
546 if (AlwaysVerify) {
547 // This helps find broken IR by constantly verifying the function. Note
548 // that this is very expensive and should only be used for debugging.
549 Instruction *I0 = isa<Instruction>(Bndl[0])
550 ? cast<Instruction>(Bndl[0])
551 : cast<Instruction>(UserBndl[0]);
552 assert(!Utils::verifyFunction(I0->getParent()->getParent(), dbgs()) &&
553 "Broken function!");
554 }
555#endif // NDEBUG
556 }
557 return NewVec;
558}
559
560bool BundleVec::tryVectorize(ArrayRef<Value *> Bndl,
561 LegalityAnalysis &Legality) {
562 Change = false;
563 if (LLVM_UNLIKELY(InvocationCnt++ >= StopAt && StopAt != StopAtDisabled))
564 return false;
565 DeadInstrCandidates.clear();
566 Legality.clear();
567 Actions.clear();
568 DebugBndlCnt = 0;
569 vectorizeRec(Bndl, {}, /*Depth=*/0, Legality);
571 << "Vec: Vectorization Actions:\n";
572 Actions.dump());
573 emitVectors();
574 tryEraseDeadInstrs();
575 return Change;
576}
577
579 const auto &SeedSlice = Rgn.getAux();
580 if (SeedSlice.size() < 2)
581 return false;
582 Function &F = *SeedSlice[0]->getParent()->getParent();
583 IMaps = std::make_unique<InstrMaps>();
584 LegalityAnalysis Legality(A.getAA(), A.getScalarEvolution(),
585 F.getParent()->getDataLayout(), F.getContext(),
586 *IMaps, Dir);
587
588 // TODO: Refactor to remove the unnecessary copy to SeedSliceVals.
589 SmallVector<Value *> SeedSliceVals(SeedSlice.begin(), SeedSlice.end());
590 // Try to vectorize starting from the seed slice. The returned value
591 // is true if we found vectorizable code and generated some vector
592 // code for it. It does not mean that the code is profitable.
593 return tryVectorize(SeedSliceVals, Legality);
594}
595
596} // namespace sandboxir
597} // 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:111
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:409
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:68
#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
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1636
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)."))