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
20
21namespace llvm {
22
23namespace sandboxir {
24
25static BundleTy getOperand(BndlRef<Value *> Bndl, unsigned OpIdx) {
27 for (Value *BndlV : Bndl) {
28 auto *BndlI = cast<Instruction>(BndlV);
29 Operands.push_back(BndlI->getOperand(OpIdx));
30 }
31 return Operands;
32}
33
34Value *BundleVec::createVectorInstr(BndlRef<Value *> Bndl,
36 auto CreateVectorInstr = [](BndlRef<Value *> Bndl,
38 assert(all_of(Bndl, [](auto *V) { return isa<Instruction>(V); }) &&
39 "Expect Instructions!");
40 auto &Ctx = Bndl[0]->getContext();
41
42 Type *ScalarTy = VecUtils::getElementType(Utils::getExpectedType(Bndl[0]));
43 auto *VecTy = VecUtils::getWideType(ScalarTy, VecUtils::getNumLanes(Bndl));
44
46 Bndl, cast<Instruction>(Bndl[0])->getParent());
47
48 auto Opcode = cast<Instruction>(Bndl[0])->getOpcode();
49 switch (Opcode) {
50 case Instruction::Opcode::ZExt:
51 case Instruction::Opcode::SExt:
52 case Instruction::Opcode::FPToUI:
53 case Instruction::Opcode::FPToSI:
54 case Instruction::Opcode::FPExt:
55 case Instruction::Opcode::PtrToAddr:
56 case Instruction::Opcode::PtrToInt:
57 case Instruction::Opcode::IntToPtr:
58 case Instruction::Opcode::SIToFP:
59 case Instruction::Opcode::UIToFP:
60 case Instruction::Opcode::Trunc:
61 case Instruction::Opcode::FPTrunc:
62 case Instruction::Opcode::BitCast: {
63 assert(Operands.size() == 1u && "Casts are unary!");
64 return CastInst::create(VecTy, Opcode, Operands[0], WhereIt, Ctx,
65 "VCast");
66 }
67 case Instruction::Opcode::FCmp:
68 case Instruction::Opcode::ICmp: {
69 auto Pred = cast<CmpInst>(Bndl[0])->getPredicate();
71 [Pred](auto *SBV) {
72 return cast<CmpInst>(SBV)->getPredicate() == Pred;
73 }) &&
74 "Expected same predicate across bundle.");
75 return CmpInst::create(Pred, Operands[0], Operands[1], WhereIt, Ctx,
76 "VCmp");
77 }
78 case Instruction::Opcode::Select: {
79 return SelectInst::create(Operands[0], Operands[1], Operands[2], WhereIt,
80 Ctx, "Vec");
81 }
82 case Instruction::Opcode::FNeg: {
83 auto *UOp0 = cast<UnaryOperator>(Bndl[0]);
84 auto OpC = UOp0->getOpcode();
86 WhereIt, Ctx, "Vec");
87 }
88 case Instruction::Opcode::Add:
89 case Instruction::Opcode::FAdd:
90 case Instruction::Opcode::Sub:
91 case Instruction::Opcode::FSub:
92 case Instruction::Opcode::Mul:
93 case Instruction::Opcode::FMul:
94 case Instruction::Opcode::UDiv:
95 case Instruction::Opcode::SDiv:
96 case Instruction::Opcode::FDiv:
97 case Instruction::Opcode::URem:
98 case Instruction::Opcode::SRem:
99 case Instruction::Opcode::FRem:
100 case Instruction::Opcode::Shl:
101 case Instruction::Opcode::LShr:
102 case Instruction::Opcode::AShr:
103 case Instruction::Opcode::And:
104 case Instruction::Opcode::Or:
105 case Instruction::Opcode::Xor: {
106 auto *BinOp0 = cast<BinaryOperator>(Bndl[0]);
107 auto *LHS = Operands[0];
108 auto *RHS = Operands[1];
110 BinOp0->getOpcode(), LHS, RHS, BinOp0, WhereIt, Ctx, "Vec");
111 }
112 case Instruction::Opcode::Load: {
113 auto Align = VecUtils::getVecAlignment(Bndl);
114 auto *Ld0 = cast<LoadInst>(Bndl[0]);
115 Value *Ptr = Ld0->getPointerOperand();
116 return LoadInst::create(VecTy, Ptr, Align, WhereIt, Ctx, "VecL");
117 }
118 case Instruction::Opcode::Store: {
119 auto Align = VecUtils::getVecAlignment(Bndl);
120 Value *Val = Operands[0];
121 Value *Ptr = Operands[1];
122 return StoreInst::create(Val, Ptr, Align, WhereIt, Ctx);
123 }
124 case Instruction::Opcode::UncondBr:
125 case Instruction::Opcode::CondBr:
126 case Instruction::Opcode::Ret:
127 case Instruction::Opcode::PHI:
128 case Instruction::Opcode::AddrSpaceCast:
129 case Instruction::Opcode::Call:
130 case Instruction::Opcode::GetElementPtr:
131 llvm_unreachable("Unimplemented");
132 break;
133 default:
134 llvm_unreachable("Unimplemented");
135 break;
136 }
137 llvm_unreachable("Missing switch case!");
138 // TODO: Propagate debug info.
139 };
140
141 auto *NewI = CreateVectorInstr(Bndl, Operands);
142 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "New instr: " << *NewI << "\n");
143 return NewI;
144}
145
146Value *BundleVec::createShuffle(Value *VecOp, const ShuffleMask &Mask,
147 BasicBlock *UserBB) {
148 BasicBlock::iterator WhereIt =
150 return ShuffleVectorInst::create(VecOp, VecOp, Mask, WhereIt,
151 VecOp->getContext(), "VShuf");
152}
153
154Value *BundleVec::createPack(BndlRef<Value *> ToPack, BasicBlock *UserBB) {
155 // If any of the instrs in ToPack are being vectorized, then we have to make
156 // sure we place the pack after the originals or the vector instruction, if
157 // available. Because in this case the packed value will need to come from an
158 // unpack of the vectorized instruction.
159 SmallVector<Value *, 8> ToPackAfter;
160 for (Value *V : ToPack) {
161 if (Action *Actn = IMaps->getVectorForOrig(V)) {
162 if (Actn->Vec)
163 ToPackAfter.push_back(Actn->Vec);
164 else
165 ToPackAfter.insert(ToPackAfter.end(), Actn->Bndl.begin(),
166 Actn->Bndl.end());
167 }
168 }
170 ToPackAfter.empty() ? ToPack : ToPackAfter, UserBB);
171
172 Type *ScalarTy = VecUtils::getCommonScalarType(ToPack);
173 unsigned Lanes = VecUtils::getNumLanes(ToPack);
174 Type *VecTy = VecUtils::getWideType(ScalarTy, Lanes);
175
176 // Create a series of pack instructions.
177 Value *LastInsert = PoisonValue::get(VecTy);
178
179 Context &Ctx = ToPack[0]->getContext();
180
181 unsigned InsertIdx = 0;
182 for (Value *Elm : ToPack) {
183 // An element can be either scalar or vector. We need to generate different
184 // IR for each case.
185 if (Elm->getType()->isVectorTy()) {
186 unsigned NumElms =
187 cast<FixedVectorType>(Elm->getType())->getNumElements();
188 for (auto ExtrLane : seq<int>(0, NumElms)) {
189 // We generate extract-insert pairs, for each lane in `Elm`.
190 Constant *ExtrLaneC =
192 // This may return a Constant if Elm is a Constant.
193 auto *ExtrI =
194 ExtractElementInst::create(Elm, ExtrLaneC, WhereIt, Ctx, "VPack");
195 if (!isa<Constant>(ExtrI))
196 WhereIt = std::next(cast<Instruction>(ExtrI)->getIterator());
197 Constant *InsertLaneC =
198 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
199 // This may also return a Constant if ExtrI is a Constant.
200 auto *InsertI = InsertElementInst::create(
201 LastInsert, ExtrI, InsertLaneC, WhereIt, Ctx, "VPack");
202 LastInsert = InsertI;
203 if (!isa<Constant>(InsertI))
204 WhereIt = std::next(cast<Instruction>(LastInsert)->getIterator());
205 }
206 } else {
207 Constant *InsertLaneC =
208 ConstantInt::getSigned(Type::getInt32Ty(Ctx), InsertIdx++);
209 // This may be folded into a Constant if LastInsert is a Constant. In
210 // that case we only collect the last constant.
211 LastInsert = InsertElementInst::create(LastInsert, Elm, InsertLaneC,
212 WhereIt, Ctx, "Pack");
213 if (auto *NewI = dyn_cast<Instruction>(LastInsert))
214 WhereIt = std::next(NewI->getIterator());
215 }
216 }
217 return LastInsert;
218}
219
220Action *BundleVec::vectorizeRec(BndlRef<Value *> Bndl,
221 BndlRef<Value *> UserBndl, unsigned Depth,
222 LegalityAnalysis &Legality) {
223 bool StopForDebug = DebugBndlCnt++ >= Opts->sbvec_stop_bndl &&
224 Opts->sbvec_stop_bndl != SBVecStopDisabled;
225 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
226 VecUtils::dump(Bndl));
227 const auto &LegalityRes = StopForDebug ? Legality.getForcedPackForDebugging()
228 : Legality.canVectorize(Bndl);
229 LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
230
231 if (Dir == SchedDirection::TopDown) {
232 // A non-Widen result means we can't extend the vectorized region into
233 // this bundle, so leave its instructions scalar and don't record an
234 // action for it.
235 if (LegalityRes.getSubclassID() != LegalityResultID::Widen)
236 return nullptr;
237
238 auto ActionPtr =
239 std::make_unique<Action>(&LegalityRes, Bndl, BndlRef<Value *>(), Depth);
240 Action *Action = ActionPtr.get();
241 IMaps->registerVector(Bndl, Action);
242 Actions.push_back(std::move(ActionPtr));
243
244 // Walk down the def-use chain. Each lane in \p Bndl may feed several
245 // users, so we form every compatible user bundle and recurse into each
246 // one.
247 SmallPtrSet<Instruction *, 4> Claimed;
248 for (const auto &NextUserBndl :
249 VecUtils::getNextUserBundles(Bndl, *IMaps, Claimed))
250 vectorizeRec(NextUserBndl, Bndl, Depth + 1, Legality);
251
252 return Action;
253 }
254
255 // Bottom up direction
256 auto ActionPtr =
257 std::make_unique<Action>(&LegalityRes, Bndl, UserBndl, Depth);
259 switch (LegalityRes.getSubclassID()) {
261 auto *I = cast<Instruction>(Bndl[0]);
262 switch (I->getOpcode()) {
263 case Instruction::Opcode::Load:
264 break;
265 case Instruction::Opcode::Store: {
266 // Don't recurse towards the pointer operand.
267 Action *OpA =
268 vectorizeRec(getOperand(Bndl, 0), Bndl, Depth + 1, Legality);
269 Operands.push_back(OpA);
270 break;
271 }
272 default:
273 // Visit all operands.
274 for (auto OpIdx : seq<unsigned>(I->getNumOperands())) {
275 Action *OpA =
276 vectorizeRec(getOperand(Bndl, OpIdx), Bndl, Depth + 1, Legality);
277 Operands.push_back(OpA);
278 }
279 break;
280 }
281 // Update the maps to mark Bndl as "vectorized".
282 IMaps->registerVector(Bndl, ActionPtr.get());
283 break;
284 }
289 break;
290 }
291 // Create actions in post-order.
292 ActionPtr->Operands = std::move(Operands);
293 auto *Action = ActionPtr.get();
294 Actions.push_back(std::move(ActionPtr));
295 return Action;
296}
297
298#ifndef NDEBUG
299void BundleVec::ActionsVector::print(raw_ostream &OS) const {
300 for (auto [Idx, Action] : enumerate(Actions)) {
301 Action->print(OS);
302 OS << "\n";
303 }
304}
305void BundleVec::ActionsVector::dump() const { print(dbgs()); }
306#endif // NDEBUG
307
308void BundleVec::emitUnpacksForExternalUses(BndlRef<Value *> Bndl, Value *Vec) {
309 // Find where we should emit the unpacks.
310 BasicBlock::iterator WhereIt;
311 if (auto *VecI = dyn_cast<Instruction>(Vec)) {
312 WhereIt = std::next(VecI->getIterator());
313 } else {
314 // If Vec is a constant then it should be safe to emit the unpacks at the
315 // top of the block.
316 // Note: Extracts from constants are usually folded to constants.
317 assert(isa<Constant>(Vec) && "Expected constant!");
318 assert(isa<Instruction>(Bndl[0]) &&
319 "A widened Bndl should contain instrs!");
320 BasicBlock *BB = cast<Instruction>(Bndl[0])->getParent();
321 WhereIt =
322 BB->empty()
323 ? BB->begin()
324 : std::next(
325 VecUtils::getLastPHIOrSelf(&*BB->begin())->getIterator());
326 }
327
328 for (auto [Lane, Elm] : VecUtils::enumerateLanes(Bndl)) {
329 // Only redirect the external (non-vectorized) uses to an unpack and leave
330 // the vectorized users untouched. A blanket replaceAllUsesWith() would
331 // also rewrite the operands of users we are going to vectorize but have
332 // not emitted yet (in the top-down direction a user bundle is emitted
333 // after its operand bundle), which would corrupt those operands.
334 auto IsExternal = [this](const Use &U) {
335 return !IMaps->isVectorized(U.getUser());
336 };
337 // Don't emit a dead unpack if all uses are internal to the vector region.
338 if (none_of(Elm->uses(), IsExternal))
339 continue;
340 auto *UnpackV = VecUtils::unpack(Vec, Elm->getType(), Lane, WhereIt);
341 Elm->replaceUsesWithIf(UnpackV, IsExternal);
342 }
343}
344
345Value *BundleVec::emitVectors() {
346 Value *NewVec = nullptr;
347 for (const auto &ActionPtr : Actions) {
348 BndlRef<Value *> Bndl = ActionPtr->Bndl;
349 BndlRef<Value *> UserBndl = ActionPtr->UserBndl;
350 const LegalityResult &LegalityRes = *ActionPtr->LegalityRes;
351 unsigned Depth = ActionPtr->Depth;
352 auto *UserBB = !UserBndl.empty()
353 ? cast<Instruction>(UserBndl.front())->getParent()
354 : cast<Instruction>(Bndl[0])->getParent();
355
356 switch (LegalityRes.getSubclassID()) {
358 auto *I = cast<Instruction>(Bndl[0]);
359 SmallVector<Value *, 2> VecOperands;
360 if (Dir == SchedDirection::BottomUp) {
361 switch (I->getOpcode()) {
362 case Instruction::Opcode::Load:
363 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
364 break;
365 case Instruction::Opcode::Store:
366 VecOperands.push_back(ActionPtr->Operands[0]->Vec);
367 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
368 break;
369 default:
370 for (Action *OpA : ActionPtr->Operands)
371 VecOperands.push_back(OpA->Vec);
372 break;
373 }
374 } else {
375 switch (I->getOpcode()) {
376 case Instruction::Opcode::Load:
377 VecOperands.push_back(cast<LoadInst>(I)->getPointerOperand());
378 break;
379 case Instruction::Opcode::Store: {
380 auto OpBndl = getOperand(Bndl, 0);
381 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
382 VecOperands.push_back(OpA->Vec);
383 else
384 VecOperands.push_back(createPack(OpBndl, UserBB));
385 VecOperands.push_back(cast<StoreInst>(I)->getPointerOperand());
386 break;
387 }
388 default:
389 for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) {
390 BundleTy OpBndl = getOperand(Bndl, OpIdx);
391 if (Action *OpA = IMaps->getVectorForOrig(OpBndl[0]))
392 VecOperands.push_back(OpA->Vec);
393 else
394 VecOperands.push_back(createPack(OpBndl, UserBB));
395 }
396 break;
397 }
398 }
399 NewVec = createVectorInstr(ActionPtr->Bndl, VecOperands);
400 // Collect any potentially dead scalar instructions, including the
401 // original scalars and pointer operands of loads/stores.
402 if (NewVec != nullptr)
403 DeadInstrMorgue.collectPotentiallyDeadInstrs(Bndl);
404
405 // Emit unpacks for all external uses, if any.
406 emitUnpacksForExternalUses(ActionPtr->Bndl, NewVec);
407 break;
408 }
410 NewVec = cast<DiamondReuse>(LegalityRes).getVector()->Vec;
411 break;
412 }
414 auto *VecOp = cast<DiamondReuseWithShuffle>(LegalityRes).getVector()->Vec;
415 const ShuffleMask &Mask =
416 cast<DiamondReuseWithShuffle>(LegalityRes).getMask();
417 NewVec = createShuffle(VecOp, Mask, UserBB);
418 assert(NewVec->getType() == VecOp->getType() &&
419 "Expected same type! Bad mask ?");
420 break;
421 }
423 const auto &Descr =
424 cast<DiamondReuseMultiInput>(LegalityRes).getCollectDescr();
425 Type *ResTy = VecUtils::getWideType(Bndl[0]->getType(), Bndl.size());
426
427 // TODO: Try to get WhereIt without creating a vector.
428 SmallVector<Value *, 4> DescrInstrs;
429 for (const auto &ElmDescr : Descr.getDescrs()) {
430 auto *V = ElmDescr.needsExtract() ? ElmDescr.getValue()->Vec
431 : ElmDescr.getScalar();
432 if (auto *I = dyn_cast<Instruction>(V))
433 DescrInstrs.push_back(I);
434 }
435 BasicBlock::iterator WhereIt =
436 VecUtils::getInsertPointAfterInstrs(DescrInstrs, UserBB);
437
438 Value *LastV = PoisonValue::get(ResTy);
439 Context &Ctx = LastV->getContext();
440 unsigned Lane = 0;
441 for (const auto &ElmDescr : Descr.getDescrs()) {
442 Value *VecOp = nullptr;
443 Value *ValueToInsert;
444 if (ElmDescr.needsExtract()) {
445 VecOp = ElmDescr.getValue()->Vec;
446 ConstantInt *IdxC =
447 ConstantInt::get(Type::getInt32Ty(Ctx), ElmDescr.getExtractIdx());
448 ValueToInsert = ExtractElementInst::create(
449 VecOp, IdxC, WhereIt, VecOp->getContext(), "VExt");
450 } else {
451 ValueToInsert = ElmDescr.getScalar();
452 }
453 auto NumLanesToInsert = VecUtils::getNumLanes(ValueToInsert);
454 if (NumLanesToInsert == 1) {
455 // If we are inserting a scalar element then we need a single insert.
456 // %VIns = insert %DstVec, %SrcScalar, Lane
457 ConstantInt *LaneC = ConstantInt::get(Type::getInt32Ty(Ctx), Lane);
458 LastV = InsertElementInst::create(LastV, ValueToInsert, LaneC,
459 WhereIt, Ctx, "VIns");
460 } else {
461 // If we are inserting a vector element then we need to extract and
462 // insert each vector element one by one with a chain of extracts and
463 // inserts, for example:
464 // %VExt0 = extract %SrcVec, 0
465 // %VIns0 = insert %DstVec, %Vect0, Lane + 0
466 // %VExt1 = extract %SrcVec, 1
467 // %VIns1 = insert %VIns0, %Vect0, Lane + 1
468 for (unsigned LnCnt = 0; LnCnt != NumLanesToInsert; ++LnCnt) {
469 auto *ExtrIdxC = ConstantInt::get(Type::getInt32Ty(Ctx), LnCnt);
470 auto *ExtrI = ExtractElementInst::create(ValueToInsert, ExtrIdxC,
471 WhereIt, Ctx, "VExt");
472 unsigned InsLane = Lane + LnCnt;
473 auto *InsLaneC = ConstantInt::get(Type::getInt32Ty(Ctx), InsLane);
474 LastV = InsertElementInst::create(LastV, ExtrI, InsLaneC, WhereIt,
475 Ctx, "VIns");
476 }
477 }
478 Lane += NumLanesToInsert;
479 }
480 NewVec = LastV;
481 break;
482 }
484 // If we can't vectorize the seeds then just return.
485 if (Depth == 0)
486 return nullptr;
487 NewVec = createPack(Bndl, UserBB);
488 break;
489 }
490 }
491 if (NewVec != nullptr) {
492 Change = true;
493 ActionPtr->Vec = NewVec;
494 }
495#ifndef NDEBUG
496 if (Opts->sbvec_always_verify) {
497 // This helps find broken IR by constantly verifying the function. Note
498 // that this is very expensive and should only be used for debugging.
499 Instruction *I0 = isa<Instruction>(Bndl[0])
500 ? cast<Instruction>(Bndl[0])
501 : cast<Instruction>(UserBndl[0]);
502 assert(!Utils::verifyFunction(I0->getParent()->getParent(), dbgs()) &&
503 "Broken function!");
504 }
505#endif // NDEBUG
506 }
507 return NewVec;
508}
509
510bool BundleVec::tryVectorize(BndlRef<Value *> Bndl,
511 LegalityAnalysis &Legality) {
512 Change = false;
513 if (LLVM_UNLIKELY(InvocationCnt++ >= Opts->sbvec_stop_at &&
514 Opts->sbvec_stop_at != SBVecStopDisabled))
515 return false;
516 Legality.clear();
517 Actions.clear();
518 DebugBndlCnt = 0;
519 vectorizeRec(Bndl, {}, /*Depth=*/0, Legality);
521 << "Vec: Vectorization Actions:\n";
522 Actions.dump());
523 Change |= !Actions.empty();
524 emitVectors();
525 DeadInstrMorgue.tryEraseDeadInstrs();
526 return Change;
527}
528
530 Opts = &getVectorizeOptions(Rgn.getContext());
531 const auto &SeedSlice = Rgn.getAux();
532 if (SeedSlice.size() < 2)
533 return false;
534 Function &F = *SeedSlice[0]->getParent()->getParent();
535 IMaps = std::make_unique<InstrMaps>();
536 LegalityAnalysis Legality(A.getAA(), A.getScalarEvolution(),
537 F.getParent()->getDataLayout(), A.getTTI(),
538 F.getContext(), *IMaps, Dir);
539
540 // TODO: Refactor to remove the unnecessary copy to SeedSliceVals.
541 SmallVector<Value *> SeedSliceVals(SeedSlice.begin(), SeedSlice.end());
542
543 Rgn.getContext().save();
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 bool Change = tryVectorize(SeedSliceVals, Legality);
548 if (!Change)
549 Rgn.getContext().revert();
550 else
551 Rgn.getContext().accept();
552 return Change;
553}
554
555} // namespace sandboxir
556} // namespace llvm
SDValue Pred
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:348
#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
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:169
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="")
An ArrayRef of Values or Instructions that we can print/dump for debugging.
Definition VecUtils.h:39
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
void revert(bool RevertAll=false)
Convenience function for getTracker().revert()
Definition Context.h:254
void accept(bool AcceptAll=false)
Convenience function for getTracker().accept()
Definition Context.h:256
void save()
Convenience function for getTracker().save()
Definition Context.h:252
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:322
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:74
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
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:35
static bool verifyFunction(const Function *F, raw_ostream &OS)
Equivalent to llvm::verifyFunction().
Definition Utils.h:134
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:331
static Instruction * getLastPHIOrSelf(Instruction *I)
If I is not a PHI it returns it.
Definition VecUtils.h:290
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 Type * getWideType(Type *ElemTy, unsigned NumElts)
\Returns <NumElts x ElemTy>.
Definition VecUtils.h:157
static auto enumerateLanes(const ValueContainerT &Range)
Helper for creating LaneValueEnumerator ranges.
Definition VecUtils.h:536
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Definition VecUtils.h:94
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 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:302
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:64
#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.
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
BndlRef(const T &OneElt) -> BndlRef< T >
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
static BundleTy getOperand(BndlRef< Value * > Bndl, unsigned OpIdx)
Definition BundleVec.cpp:25
SmallVector< Value *, 4 > BundleTy
Definition VecUtils.h:82
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
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
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:2575
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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
constexpr unsigned long SBVecStopDisabled
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:1769
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
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