LLVM 19.0.0git
VPlan.cpp
Go to the documentation of this file.
1//===- VPlan.cpp - Vectorizer Plan ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This is the LLVM vectorization plan. It represents a candidate for
11/// vectorization, allowing to plan and optimize how to vectorize a given loop
12/// before generating LLVM-IR.
13/// The vectorizer uses vectorization plans to estimate the costs of potential
14/// candidates and if profitable to execute the desired plan, generating vector
15/// LLVM-IR code.
16///
17//===----------------------------------------------------------------------===//
18
19#include "VPlan.h"
21#include "VPlanCFG.h"
22#include "VPlanDominatorTree.h"
23#include "VPlanPatternMatch.h"
25#include "llvm/ADT/STLExtras.h"
28#include "llvm/ADT/Twine.h"
31#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/CFG.h"
33#include "llvm/IR/IRBuilder.h"
34#include "llvm/IR/Instruction.h"
36#include "llvm/IR/Type.h"
37#include "llvm/IR/Value.h"
40#include "llvm/Support/Debug.h"
47#include <cassert>
48#include <string>
49#include <vector>
50
51using namespace llvm;
52using namespace llvm::VPlanPatternMatch;
53
54namespace llvm {
56}
57
58#define DEBUG_TYPE "vplan"
59
60#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
62 const VPInstruction *Instr = dyn_cast<VPInstruction>(&V);
64 (Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr);
65 V.print(OS, SlotTracker);
66 return OS;
67}
68#endif
69
71 const ElementCount &VF) const {
72 switch (LaneKind) {
74 // Lane = RuntimeVF - VF.getKnownMinValue() + Lane
75 return Builder.CreateSub(getRuntimeVF(Builder, Builder.getInt32Ty(), VF),
76 Builder.getInt32(VF.getKnownMinValue() - Lane));
78 return Builder.getInt32(Lane);
79 }
80 llvm_unreachable("Unknown lane kind");
81}
82
83VPValue::VPValue(const unsigned char SC, Value *UV, VPDef *Def)
84 : SubclassID(SC), UnderlyingVal(UV), Def(Def) {
85 if (Def)
86 Def->addDefinedValue(this);
87}
88
90 assert(Users.empty() && "trying to delete a VPValue with remaining users");
91 if (Def)
92 Def->removeDefinedValue(this);
93}
94
95#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
97 if (const VPRecipeBase *R = dyn_cast_or_null<VPRecipeBase>(Def))
98 R->print(OS, "", SlotTracker);
99 else
101}
102
103void VPValue::dump() const {
104 const VPRecipeBase *Instr = dyn_cast_or_null<VPRecipeBase>(this->Def);
106 (Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr);
108 dbgs() << "\n";
109}
110
111void VPDef::dump() const {
112 const VPRecipeBase *Instr = dyn_cast_or_null<VPRecipeBase>(this);
114 (Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr);
115 print(dbgs(), "", SlotTracker);
116 dbgs() << "\n";
117}
118#endif
119
121 return cast_or_null<VPRecipeBase>(Def);
122}
123
125 return cast_or_null<VPRecipeBase>(Def);
126}
127
128// Get the top-most entry block of \p Start. This is the entry block of the
129// containing VPlan. This function is templated to support both const and non-const blocks
130template <typename T> static T *getPlanEntry(T *Start) {
131 T *Next = Start;
132 T *Current = Start;
133 while ((Next = Next->getParent()))
134 Current = Next;
135
136 SmallSetVector<T *, 8> WorkList;
137 WorkList.insert(Current);
138
139 for (unsigned i = 0; i < WorkList.size(); i++) {
140 T *Current = WorkList[i];
141 if (Current->getNumPredecessors() == 0)
142 return Current;
143 auto &Predecessors = Current->getPredecessors();
144 WorkList.insert(Predecessors.begin(), Predecessors.end());
145 }
146
147 llvm_unreachable("VPlan without any entry node without predecessors");
148}
149
150VPlan *VPBlockBase::getPlan() { return getPlanEntry(this)->Plan; }
151
152const VPlan *VPBlockBase::getPlan() const { return getPlanEntry(this)->Plan; }
153
154/// \return the VPBasicBlock that is the entry of Block, possibly indirectly.
156 const VPBlockBase *Block = this;
157 while (const VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
158 Block = Region->getEntry();
159 return cast<VPBasicBlock>(Block);
160}
161
163 VPBlockBase *Block = this;
164 while (VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
165 Block = Region->getEntry();
166 return cast<VPBasicBlock>(Block);
167}
168
169void VPBlockBase::setPlan(VPlan *ParentPlan) {
170 assert(
171 (ParentPlan->getEntry() == this || ParentPlan->getPreheader() == this) &&
172 "Can only set plan on its entry or preheader block.");
173 Plan = ParentPlan;
174}
175
176/// \return the VPBasicBlock that is the exit of Block, possibly indirectly.
178 const VPBlockBase *Block = this;
179 while (const VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
180 Block = Region->getExiting();
181 return cast<VPBasicBlock>(Block);
182}
183
185 VPBlockBase *Block = this;
186 while (VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
187 Block = Region->getExiting();
188 return cast<VPBasicBlock>(Block);
189}
190
192 if (!Successors.empty() || !Parent)
193 return this;
194 assert(Parent->getExiting() == this &&
195 "Block w/o successors not the exiting block of its parent.");
196 return Parent->getEnclosingBlockWithSuccessors();
197}
198
200 if (!Predecessors.empty() || !Parent)
201 return this;
202 assert(Parent->getEntry() == this &&
203 "Block w/o predecessors not the entry of its parent.");
204 return Parent->getEnclosingBlockWithPredecessors();
205}
206
209 delete Block;
210}
211
213 iterator It = begin();
214 while (It != end() && It->isPhi())
215 It++;
216 return It;
217}
218
220 DominatorTree *DT, IRBuilderBase &Builder,
221 InnerLoopVectorizer *ILV, VPlan *Plan,
222 LLVMContext &Ctx)
223 : VF(VF), UF(UF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan),
224 LVer(nullptr),
225 TypeAnalysis(Plan->getCanonicalIV()->getScalarType(), Ctx) {}
226
228 if (Def->isLiveIn())
229 return Def->getLiveInIRValue();
230
231 if (hasScalarValue(Def, Instance)) {
232 return Data
233 .PerPartScalars[Def][Instance.Part][Instance.Lane.mapToCacheIndex(VF)];
234 }
235 if (!Instance.Lane.isFirstLane() &&
238 return Data.PerPartScalars[Def][Instance.Part][0];
239 }
240
241 assert(hasVectorValue(Def, Instance.Part));
242 auto *VecPart = Data.PerPartOutput[Def][Instance.Part];
243 if (!VecPart->getType()->isVectorTy()) {
244 assert(Instance.Lane.isFirstLane() && "cannot get lane > 0 for scalar");
245 return VecPart;
246 }
247 // TODO: Cache created scalar values.
248 Value *Lane = Instance.Lane.getAsRuntimeExpr(Builder, VF);
249 auto *Extract = Builder.CreateExtractElement(VecPart, Lane);
250 // set(Def, Extract, Instance);
251 return Extract;
252}
253
254Value *VPTransformState::get(VPValue *Def, unsigned Part, bool NeedsScalar) {
255 if (NeedsScalar) {
256 assert((VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) ||
258 (hasScalarValue(Def, VPIteration(Part, 0)) &&
259 Data.PerPartScalars[Def][Part].size() == 1)) &&
260 "Trying to access a single scalar per part but has multiple scalars "
261 "per part.");
262 return get(Def, VPIteration(Part, 0));
263 }
264
265 // If Values have been set for this Def return the one relevant for \p Part.
266 if (hasVectorValue(Def, Part))
267 return Data.PerPartOutput[Def][Part];
268
269 auto GetBroadcastInstrs = [this, Def](Value *V) {
270 bool SafeToHoist = Def->isDefinedOutsideVectorRegions();
271 if (VF.isScalar())
272 return V;
273 // Place the code for broadcasting invariant variables in the new preheader.
275 if (SafeToHoist) {
276 BasicBlock *LoopVectorPreHeader = CFG.VPBB2IRBB[cast<VPBasicBlock>(
278 if (LoopVectorPreHeader)
279 Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
280 }
281
282 // Place the code for broadcasting invariant variables in the new preheader.
283 // Broadcast the scalar into all locations in the vector.
284 Value *Shuf = Builder.CreateVectorSplat(VF, V, "broadcast");
285
286 return Shuf;
287 };
288
289 if (!hasScalarValue(Def, {Part, 0})) {
290 assert(Def->isLiveIn() && "expected a live-in");
291 if (Part != 0)
292 return get(Def, 0);
293 Value *IRV = Def->getLiveInIRValue();
294 Value *B = GetBroadcastInstrs(IRV);
295 set(Def, B, Part);
296 return B;
297 }
298
299 Value *ScalarValue = get(Def, {Part, 0});
300 // If we aren't vectorizing, we can just copy the scalar map values over
301 // to the vector map.
302 if (VF.isScalar()) {
303 set(Def, ScalarValue, Part);
304 return ScalarValue;
305 }
306
307 bool IsUniform = vputils::isUniformAfterVectorization(Def);
308
309 unsigned LastLane = IsUniform ? 0 : VF.getKnownMinValue() - 1;
310 // Check if there is a scalar value for the selected lane.
311 if (!hasScalarValue(Def, {Part, LastLane})) {
312 // At the moment, VPWidenIntOrFpInductionRecipes, VPScalarIVStepsRecipes and
313 // VPExpandSCEVRecipes can also be uniform.
314 assert((isa<VPWidenIntOrFpInductionRecipe>(Def->getDefiningRecipe()) ||
315 isa<VPScalarIVStepsRecipe>(Def->getDefiningRecipe()) ||
316 isa<VPExpandSCEVRecipe>(Def->getDefiningRecipe())) &&
317 "unexpected recipe found to be invariant");
318 IsUniform = true;
319 LastLane = 0;
320 }
321
322 auto *LastInst = cast<Instruction>(get(Def, {Part, LastLane}));
323 // Set the insert point after the last scalarized instruction or after the
324 // last PHI, if LastInst is a PHI. This ensures the insertelement sequence
325 // will directly follow the scalar definitions.
326 auto OldIP = Builder.saveIP();
327 auto NewIP =
328 isa<PHINode>(LastInst)
329 ? BasicBlock::iterator(LastInst->getParent()->getFirstNonPHI())
330 : std::next(BasicBlock::iterator(LastInst));
331 Builder.SetInsertPoint(&*NewIP);
332
333 // However, if we are vectorizing, we need to construct the vector values.
334 // If the value is known to be uniform after vectorization, we can just
335 // broadcast the scalar value corresponding to lane zero for each unroll
336 // iteration. Otherwise, we construct the vector values using
337 // insertelement instructions. Since the resulting vectors are stored in
338 // State, we will only generate the insertelements once.
339 Value *VectorValue = nullptr;
340 if (IsUniform) {
341 VectorValue = GetBroadcastInstrs(ScalarValue);
342 set(Def, VectorValue, Part);
343 } else {
344 // Initialize packing with insertelements to start from undef.
345 assert(!VF.isScalable() && "VF is assumed to be non scalable.");
346 Value *Undef = PoisonValue::get(VectorType::get(LastInst->getType(), VF));
347 set(Def, Undef, Part);
348 for (unsigned Lane = 0; Lane < VF.getKnownMinValue(); ++Lane)
349 packScalarIntoVectorValue(Def, {Part, Lane});
350 VectorValue = get(Def, Part);
351 }
352 Builder.restoreIP(OldIP);
353 return VectorValue;
354}
355
357 VPRegionBlock *LoopRegion = R->getParent()->getEnclosingLoopRegion();
358 return VPBB2IRBB[LoopRegion->getPreheaderVPBB()];
359}
360
362 const Instruction *Orig) {
363 // If the loop was versioned with memchecks, add the corresponding no-alias
364 // metadata.
365 if (LVer && (isa<LoadInst>(Orig) || isa<StoreInst>(Orig)))
366 LVer->annotateInstWithNoAlias(To, Orig);
367}
368
370 // No source instruction to transfer metadata from?
371 if (!From)
372 return;
373
374 if (Instruction *ToI = dyn_cast<Instruction>(To)) {
376 addNewMetadata(ToI, From);
377 }
378}
379
381 const DILocation *DIL = DL;
382 // When a FSDiscriminator is enabled, we don't need to add the multiply
383 // factors to the discriminators.
384 if (DIL &&
386 ->getParent()
389 // FIXME: For scalable vectors, assume vscale=1.
390 auto NewDIL =
392 if (NewDIL)
394 else
395 LLVM_DEBUG(dbgs() << "Failed to create new discriminator: "
396 << DIL->getFilename() << " Line: " << DIL->getLine());
397 } else
399}
400
402 const VPIteration &Instance) {
403 Value *ScalarInst = get(Def, Instance);
404 Value *VectorValue = get(Def, Instance.Part);
405 VectorValue = Builder.CreateInsertElement(
406 VectorValue, ScalarInst, Instance.Lane.getAsRuntimeExpr(Builder, VF));
407 set(Def, VectorValue, Instance.Part);
408}
409
411VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
412 // BB stands for IR BasicBlocks. VPBB stands for VPlan VPBasicBlocks.
413 // Pred stands for Predessor. Prev stands for Previous - last visited/created.
414 BasicBlock *PrevBB = CFG.PrevBB;
415 BasicBlock *NewBB = BasicBlock::Create(PrevBB->getContext(), getName(),
416 PrevBB->getParent(), CFG.ExitBB);
417 LLVM_DEBUG(dbgs() << "LV: created " << NewBB->getName() << '\n');
418
419 // Hook up the new basic block to its predecessors.
420 for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) {
421 VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock();
422 auto &PredVPSuccessors = PredVPBB->getHierarchicalSuccessors();
423 BasicBlock *PredBB = CFG.VPBB2IRBB[PredVPBB];
424
425 assert(PredBB && "Predecessor basic-block not found building successor.");
426 auto *PredBBTerminator = PredBB->getTerminator();
427 LLVM_DEBUG(dbgs() << "LV: draw edge from" << PredBB->getName() << '\n');
428
429 auto *TermBr = dyn_cast<BranchInst>(PredBBTerminator);
430 if (isa<UnreachableInst>(PredBBTerminator)) {
431 assert(PredVPSuccessors.size() == 1 &&
432 "Predecessor ending w/o branch must have single successor.");
433 DebugLoc DL = PredBBTerminator->getDebugLoc();
434 PredBBTerminator->eraseFromParent();
435 auto *Br = BranchInst::Create(NewBB, PredBB);
436 Br->setDebugLoc(DL);
437 } else if (TermBr && !TermBr->isConditional()) {
438 TermBr->setSuccessor(0, NewBB);
439 } else {
440 // Set each forward successor here when it is created, excluding
441 // backedges. A backward successor is set when the branch is created.
442 unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
443 assert(!TermBr->getSuccessor(idx) &&
444 "Trying to reset an existing successor block.");
445 TermBr->setSuccessor(idx, NewBB);
446 }
447 CFG.DTU.applyUpdates({{DominatorTree::Insert, PredBB, NewBB}});
448 }
449 return NewBB;
450}
451
453 assert(getHierarchicalSuccessors().size() <= 2 &&
454 "VPIRBasicBlock can have at most two successors at the moment!");
455 State->Builder.SetInsertPoint(getIRBasicBlock()->getTerminator());
456 executeRecipes(State, getIRBasicBlock());
457 if (getSingleSuccessor()) {
458 assert(isa<UnreachableInst>(getIRBasicBlock()->getTerminator()));
459 auto *Br = State->Builder.CreateBr(getIRBasicBlock());
460 Br->setOperand(0, nullptr);
461 getIRBasicBlock()->getTerminator()->eraseFromParent();
462 }
463
464 for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) {
465 VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock();
466 BasicBlock *PredBB = State->CFG.VPBB2IRBB[PredVPBB];
467 assert(PredBB && "Predecessor basic-block not found building successor.");
468 LLVM_DEBUG(dbgs() << "LV: draw edge from" << PredBB->getName() << '\n');
469
470 auto *PredBBTerminator = PredBB->getTerminator();
471 auto *TermBr = cast<BranchInst>(PredBBTerminator);
472 // Set each forward successor here when it is created, excluding
473 // backedges. A backward successor is set when the branch is created.
474 const auto &PredVPSuccessors = PredVPBB->getHierarchicalSuccessors();
475 unsigned idx = PredVPSuccessors.front() == this ? 0 : 1;
476 assert(!TermBr->getSuccessor(idx) &&
477 "Trying to reset an existing successor block.");
478 TermBr->setSuccessor(idx, IRBB);
479 State->CFG.DTU.applyUpdates({{DominatorTree::Insert, PredBB, IRBB}});
480 }
481}
482
484 bool Replica = State->Instance && !State->Instance->isFirstIteration();
485 VPBasicBlock *PrevVPBB = State->CFG.PrevVPBB;
486 VPBlockBase *SingleHPred = nullptr;
487 BasicBlock *NewBB = State->CFG.PrevBB; // Reuse it if possible.
488
489 auto IsLoopRegion = [](VPBlockBase *BB) {
490 auto *R = dyn_cast<VPRegionBlock>(BB);
491 return R && !R->isReplicator();
492 };
493
494 // 1. Create an IR basic block.
495 if (PrevVPBB && /* A */
496 !((SingleHPred = getSingleHierarchicalPredecessor()) &&
497 SingleHPred->getExitingBasicBlock() == PrevVPBB &&
498 PrevVPBB->getSingleHierarchicalSuccessor() &&
499 (SingleHPred->getParent() == getEnclosingLoopRegion() &&
500 !IsLoopRegion(SingleHPred))) && /* B */
501 !(Replica && getPredecessors().empty())) { /* C */
502 // The last IR basic block is reused, as an optimization, in three cases:
503 // A. the first VPBB reuses the loop pre-header BB - when PrevVPBB is null;
504 // B. when the current VPBB has a single (hierarchical) predecessor which
505 // is PrevVPBB and the latter has a single (hierarchical) successor which
506 // both are in the same non-replicator region; and
507 // C. when the current VPBB is an entry of a region replica - where PrevVPBB
508 // is the exiting VPBB of this region from a previous instance, or the
509 // predecessor of this region.
510
511 NewBB = createEmptyBasicBlock(State->CFG);
512 State->Builder.SetInsertPoint(NewBB);
513 // Temporarily terminate with unreachable until CFG is rewired.
514 UnreachableInst *Terminator = State->Builder.CreateUnreachable();
515 // Register NewBB in its loop. In innermost loops its the same for all
516 // BB's.
517 if (State->CurrentVectorLoop)
518 State->CurrentVectorLoop->addBasicBlockToLoop(NewBB, *State->LI);
519 State->Builder.SetInsertPoint(Terminator);
520 State->CFG.PrevBB = NewBB;
521 }
522
523 // 2. Fill the IR basic block with IR instructions.
524 executeRecipes(State, NewBB);
525}
526
528 for (VPRecipeBase &R : Recipes) {
529 for (auto *Def : R.definedValues())
530 Def->replaceAllUsesWith(NewValue);
531
532 for (unsigned I = 0, E = R.getNumOperands(); I != E; I++)
533 R.setOperand(I, NewValue);
534 }
535}
536
538 LLVM_DEBUG(dbgs() << "LV: vectorizing VPBB:" << getName()
539 << " in BB:" << BB->getName() << '\n');
540
541 State->CFG.VPBB2IRBB[this] = BB;
542 State->CFG.PrevVPBB = this;
543
544 for (VPRecipeBase &Recipe : Recipes)
545 Recipe.execute(*State);
546
547 LLVM_DEBUG(dbgs() << "LV: filled BB:" << *BB);
548}
549
551 assert((SplitAt == end() || SplitAt->getParent() == this) &&
552 "can only split at a position in the same block");
553
555 // First, disconnect the current block from its successors.
556 for (VPBlockBase *Succ : Succs)
558
559 // Create new empty block after the block to split.
560 auto *SplitBlock = new VPBasicBlock(getName() + ".split");
562
563 // Add successors for block to split to new block.
564 for (VPBlockBase *Succ : Succs)
566
567 // Finally, move the recipes starting at SplitAt to new block.
568 for (VPRecipeBase &ToMove :
569 make_early_inc_range(make_range(SplitAt, this->end())))
570 ToMove.moveBefore(*SplitBlock, SplitBlock->end());
571
572 return SplitBlock;
573}
574
577 if (P && P->isReplicator()) {
578 P = P->getParent();
579 assert(!cast<VPRegionBlock>(P)->isReplicator() &&
580 "unexpected nested replicate regions");
581 }
582 return P;
583}
584
585static bool hasConditionalTerminator(const VPBasicBlock *VPBB) {
586 if (VPBB->empty()) {
587 assert(
588 VPBB->getNumSuccessors() < 2 &&
589 "block with multiple successors doesn't have a recipe as terminator");
590 return false;
591 }
592
593 const VPRecipeBase *R = &VPBB->back();
594 bool IsCondBranch = isa<VPBranchOnMaskRecipe>(R) ||
597 (void)IsCondBranch;
598
599 if (VPBB->getNumSuccessors() >= 2 ||
600 (VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
601 assert(IsCondBranch && "block with multiple successors not terminated by "
602 "conditional branch recipe");
603
604 return true;
605 }
606
607 assert(
608 !IsCondBranch &&
609 "block with 0 or 1 successors terminated by conditional branch recipe");
610 return false;
611}
612
614 if (hasConditionalTerminator(this))
615 return &back();
616 return nullptr;
617}
618
620 if (hasConditionalTerminator(this))
621 return &back();
622 return nullptr;
623}
624
626 return getParent() && getParent()->getExitingBasicBlock() == this;
627}
628
629#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
630void VPBlockBase::printSuccessors(raw_ostream &O, const Twine &Indent) const {
631 if (getSuccessors().empty()) {
632 O << Indent << "No successors\n";
633 } else {
634 O << Indent << "Successor(s): ";
635 ListSeparator LS;
636 for (auto *Succ : getSuccessors())
637 O << LS << Succ->getName();
638 O << '\n';
639 }
640}
641
642void VPBasicBlock::print(raw_ostream &O, const Twine &Indent,
643 VPSlotTracker &SlotTracker) const {
644 O << Indent << getName() << ":\n";
645
646 auto RecipeIndent = Indent + " ";
647 for (const VPRecipeBase &Recipe : *this) {
648 Recipe.print(O, RecipeIndent, SlotTracker);
649 O << '\n';
650 }
651
652 printSuccessors(O, Indent);
653}
654#endif
655
656static std::pair<VPBlockBase *, VPBlockBase *> cloneFrom(VPBlockBase *Entry);
657
658// Clone the CFG for all nodes reachable from \p Entry, this includes cloning
659// the blocks and their recipes. Operands of cloned recipes will NOT be updated.
660// Remapping of operands must be done separately. Returns a pair with the new
661// entry and exiting blocks of the cloned region. If \p Entry isn't part of a
662// region, return nullptr for the exiting block.
663static std::pair<VPBlockBase *, VPBlockBase *> cloneFrom(VPBlockBase *Entry) {
665 VPBlockBase *Exiting = nullptr;
666 bool InRegion = Entry->getParent();
667 // First, clone blocks reachable from Entry.
668 for (VPBlockBase *BB : vp_depth_first_shallow(Entry)) {
669 VPBlockBase *NewBB = BB->clone();
670 Old2NewVPBlocks[BB] = NewBB;
671 if (InRegion && BB->getNumSuccessors() == 0) {
672 assert(!Exiting && "Multiple exiting blocks?");
673 Exiting = BB;
674 }
675 }
676 assert((!InRegion || Exiting) && "regions must have a single exiting block");
677
678 // Second, update the predecessors & successors of the cloned blocks.
679 for (VPBlockBase *BB : vp_depth_first_shallow(Entry)) {
680 VPBlockBase *NewBB = Old2NewVPBlocks[BB];
682 for (VPBlockBase *Pred : BB->getPredecessors()) {
683 NewPreds.push_back(Old2NewVPBlocks[Pred]);
684 }
685 NewBB->setPredecessors(NewPreds);
687 for (VPBlockBase *Succ : BB->successors()) {
688 NewSuccs.push_back(Old2NewVPBlocks[Succ]);
689 }
690 NewBB->setSuccessors(NewSuccs);
691 }
692
693#if !defined(NDEBUG)
694 // Verify that the order of predecessors and successors matches in the cloned
695 // version.
696 for (const auto &[OldBB, NewBB] :
698 vp_depth_first_shallow(Old2NewVPBlocks[Entry]))) {
699 for (const auto &[OldPred, NewPred] :
700 zip(OldBB->getPredecessors(), NewBB->getPredecessors()))
701 assert(NewPred == Old2NewVPBlocks[OldPred] && "Different predecessors");
702
703 for (const auto &[OldSucc, NewSucc] :
704 zip(OldBB->successors(), NewBB->successors()))
705 assert(NewSucc == Old2NewVPBlocks[OldSucc] && "Different successors");
706 }
707#endif
708
709 return std::make_pair(Old2NewVPBlocks[Entry],
710 Exiting ? Old2NewVPBlocks[Exiting] : nullptr);
711}
712
714 const auto &[NewEntry, NewExiting] = cloneFrom(getEntry());
715 auto *NewRegion =
716 new VPRegionBlock(NewEntry, NewExiting, getName(), isReplicator());
717 for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
718 Block->setParent(NewRegion);
719 return NewRegion;
720}
721
724 // Drop all references in VPBasicBlocks and replace all uses with
725 // DummyValue.
726 Block->dropAllReferences(NewValue);
727}
728
731 RPOT(Entry);
732
733 if (!isReplicator()) {
734 // Create and register the new vector loop.
735 Loop *PrevLoop = State->CurrentVectorLoop;
736 State->CurrentVectorLoop = State->LI->AllocateLoop();
737 BasicBlock *VectorPH = State->CFG.VPBB2IRBB[getPreheaderVPBB()];
738 Loop *ParentLoop = State->LI->getLoopFor(VectorPH);
739
740 // Insert the new loop into the loop nest and register the new basic blocks
741 // before calling any utilities such as SCEV that require valid LoopInfo.
742 if (ParentLoop)
743 ParentLoop->addChildLoop(State->CurrentVectorLoop);
744 else
745 State->LI->addTopLevelLoop(State->CurrentVectorLoop);
746
747 // Visit the VPBlocks connected to "this", starting from it.
748 for (VPBlockBase *Block : RPOT) {
749 LLVM_DEBUG(dbgs() << "LV: VPBlock in RPO " << Block->getName() << '\n');
750 Block->execute(State);
751 }
752
753 State->CurrentVectorLoop = PrevLoop;
754 return;
755 }
756
757 assert(!State->Instance && "Replicating a Region with non-null instance.");
758
759 // Enter replicating mode.
760 State->Instance = VPIteration(0, 0);
761
762 for (unsigned Part = 0, UF = State->UF; Part < UF; ++Part) {
763 State->Instance->Part = Part;
764 assert(!State->VF.isScalable() && "VF is assumed to be non scalable.");
765 for (unsigned Lane = 0, VF = State->VF.getKnownMinValue(); Lane < VF;
766 ++Lane) {
767 State->Instance->Lane = VPLane(Lane, VPLane::Kind::First);
768 // Visit the VPBlocks connected to \p this, starting from it.
769 for (VPBlockBase *Block : RPOT) {
770 LLVM_DEBUG(dbgs() << "LV: VPBlock in RPO " << Block->getName() << '\n');
771 Block->execute(State);
772 }
773 }
774 }
775
776 // Exit replicating mode.
777 State->Instance.reset();
778}
779
782 for (VPRecipeBase &R : Recipes)
783 Cost += R.cost(VF, Ctx);
784 return Cost;
785}
786
788 if (!isReplicator()) {
790 for (VPBlockBase *Block : vp_depth_first_shallow(getEntry()))
791 Cost += Block->cost(VF, Ctx);
792 InstructionCost BackedgeCost =
793 Ctx.TTI.getCFInstrCost(Instruction::Br, TTI::TCK_RecipThroughput);
794 LLVM_DEBUG(dbgs() << "Cost of " << BackedgeCost << " for VF " << VF
795 << ": vector loop backedge\n");
796 Cost += BackedgeCost;
797 return Cost;
798 }
799
800 // Compute the cost of a replicate region. Replicating isn't supported for
801 // scalable vectors, return an invalid cost for them.
802 // TODO: Discard scalable VPlans with replicate recipes earlier after
803 // construction.
804 if (VF.isScalable())
806
807 // First compute the cost of the conditionally executed recipes, followed by
808 // account for the branching cost, except if the mask is a header mask or
809 // uniform condition.
810 using namespace llvm::VPlanPatternMatch;
811 VPBasicBlock *Then = cast<VPBasicBlock>(getEntry()->getSuccessors()[0]);
812 InstructionCost ThenCost = Then->cost(VF, Ctx);
813
814 // For the scalar case, we may not always execute the original predicated
815 // block, Thus, scale the block's cost by the probability of executing it.
816 if (VF.isScalar())
817 return ThenCost / getReciprocalPredBlockProb();
818
819 return ThenCost;
820}
821
822#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
824 VPSlotTracker &SlotTracker) const {
825 O << Indent << (isReplicator() ? "<xVFxUF> " : "<x1> ") << getName() << ": {";
826 auto NewIndent = Indent + " ";
827 for (auto *BlockBase : vp_depth_first_shallow(Entry)) {
828 O << '\n';
829 BlockBase->print(O, NewIndent, SlotTracker);
830 }
831 O << Indent << "}\n";
832
833 printSuccessors(O, Indent);
834}
835#endif
836
838 for (auto &KV : LiveOuts)
839 delete KV.second;
840 LiveOuts.clear();
841
842 if (Entry) {
843 VPValue DummyValue;
845 Block->dropAllReferences(&DummyValue);
846
848
849 Preheader->dropAllReferences(&DummyValue);
850 delete Preheader;
851 }
852 for (VPValue *VPV : VPLiveInsToFree)
853 delete VPV;
854 if (BackedgeTakenCount)
855 delete BackedgeTakenCount;
856}
857
859 bool RequiresScalarEpilogueCheck,
860 bool TailFolded, Loop *TheLoop) {
861 VPIRBasicBlock *Entry = new VPIRBasicBlock(TheLoop->getLoopPreheader());
862 VPBasicBlock *VecPreheader = new VPBasicBlock("vector.ph");
863 auto Plan = std::make_unique<VPlan>(Entry, VecPreheader);
864 Plan->TripCount =
866 // Create VPRegionBlock, with empty header and latch blocks, to be filled
867 // during processing later.
868 VPBasicBlock *HeaderVPBB = new VPBasicBlock("vector.body");
869 VPBasicBlock *LatchVPBB = new VPBasicBlock("vector.latch");
870 VPBlockUtils::insertBlockAfter(LatchVPBB, HeaderVPBB);
871 auto *TopRegion = new VPRegionBlock(HeaderVPBB, LatchVPBB, "vector loop",
872 false /*isReplicator*/);
873
874 VPBlockUtils::insertBlockAfter(TopRegion, VecPreheader);
875 VPBasicBlock *MiddleVPBB = new VPBasicBlock("middle.block");
876 VPBlockUtils::insertBlockAfter(MiddleVPBB, TopRegion);
877
878 VPBasicBlock *ScalarPH = new VPBasicBlock("scalar.ph");
879 if (!RequiresScalarEpilogueCheck) {
880 VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH);
881 return Plan;
882 }
883
884 // If needed, add a check in the middle block to see if we have completed
885 // all of the iterations in the first vector loop. Three cases:
886 // 1) If (N - N%VF) == N, then we *don't* need to run the remainder.
887 // Thus if tail is to be folded, we know we don't need to run the
888 // remainder and we can set the condition to true.
889 // 2) If we require a scalar epilogue, there is no conditional branch as
890 // we unconditionally branch to the scalar preheader. Do nothing.
891 // 3) Otherwise, construct a runtime check.
892 BasicBlock *IRExitBlock = TheLoop->getUniqueExitBlock();
893 auto *VPExitBlock = new VPIRBasicBlock(IRExitBlock);
894 // The connection order corresponds to the operands of the conditional branch.
895 VPBlockUtils::insertBlockAfter(VPExitBlock, MiddleVPBB);
896 VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH);
897
898 auto *ScalarLatchTerm = TheLoop->getLoopLatch()->getTerminator();
899 // Here we use the same DebugLoc as the scalar loop latch terminator instead
900 // of the corresponding compare because they may have ended up with
901 // different line numbers and we want to avoid awkward line stepping while
902 // debugging. Eg. if the compare has got a line number inside the loop.
903 VPBuilder Builder(MiddleVPBB);
904 VPValue *Cmp =
905 TailFolded
907 IntegerType::getInt1Ty(TripCount->getType()->getContext())))
908 : Builder.createICmp(CmpInst::ICMP_EQ, Plan->getTripCount(),
910 ScalarLatchTerm->getDebugLoc(), "cmp.n");
911 Builder.createNaryOp(VPInstruction::BranchOnCond, {Cmp},
912 ScalarLatchTerm->getDebugLoc());
913 return Plan;
914}
915
916void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
917 Value *CanonicalIVStartValue,
918 VPTransformState &State) {
919 // Check if the backedge taken count is needed, and if so build it.
920 if (BackedgeTakenCount && BackedgeTakenCount->getNumUsers()) {
922 auto *TCMO = Builder.CreateSub(TripCountV,
923 ConstantInt::get(TripCountV->getType(), 1),
924 "trip.count.minus.1");
925 BackedgeTakenCount->setUnderlyingValue(TCMO);
926 }
927
928 VectorTripCount.setUnderlyingValue(VectorTripCountV);
929
931 // FIXME: Model VF * UF computation completely in VPlan.
932 VFxUF.setUnderlyingValue(
933 createStepForVF(Builder, TripCountV->getType(), State.VF, State.UF));
934
935 // When vectorizing the epilogue loop, the canonical induction start value
936 // needs to be changed from zero to the value after the main vector loop.
937 // FIXME: Improve modeling for canonical IV start values in the epilogue loop.
938 if (CanonicalIVStartValue) {
939 VPValue *VPV = getOrAddLiveIn(CanonicalIVStartValue);
940 auto *IV = getCanonicalIV();
941 assert(all_of(IV->users(),
942 [](const VPUser *U) {
943 return isa<VPScalarIVStepsRecipe>(U) ||
944 isa<VPScalarCastRecipe>(U) ||
945 isa<VPDerivedIVRecipe>(U) ||
946 cast<VPInstruction>(U)->getOpcode() ==
947 Instruction::Add;
948 }) &&
949 "the canonical IV should only be used by its increment or "
950 "ScalarIVSteps when resetting the start value");
951 IV->setOperand(0, VPV);
952 }
953}
954
955/// Replace \p VPBB with a VPIRBasicBlock wrapping \p IRBB. All recipes from \p
956/// VPBB are moved to the newly created VPIRBasicBlock. VPBB must have a single
957/// predecessor, which is rewired to the new VPIRBasicBlock. All successors of
958/// VPBB, if any, are rewired to the new VPIRBasicBlock.
960 VPIRBasicBlock *IRMiddleVPBB = new VPIRBasicBlock(IRBB);
961 for (auto &R : make_early_inc_range(*VPBB))
962 R.moveBefore(*IRMiddleVPBB, IRMiddleVPBB->end());
963 VPBlockBase *PredVPBB = VPBB->getSinglePredecessor();
964 VPBlockUtils::disconnectBlocks(PredVPBB, VPBB);
965 VPBlockUtils::connectBlocks(PredVPBB, IRMiddleVPBB);
966 for (auto *Succ : to_vector(VPBB->getSuccessors())) {
967 VPBlockUtils::connectBlocks(IRMiddleVPBB, Succ);
969 }
970 delete VPBB;
971}
972
973/// Generate the code inside the preheader and body of the vectorized loop.
974/// Assumes a single pre-header basic-block was created for this. Introduce
975/// additional basic-blocks as needed, and fill them all.
977 // Initialize CFG state.
978 State->CFG.PrevVPBB = nullptr;
979 State->CFG.ExitBB = State->CFG.PrevBB->getSingleSuccessor();
980 BasicBlock *VectorPreHeader = State->CFG.PrevBB;
981 State->Builder.SetInsertPoint(VectorPreHeader->getTerminator());
982
983 // Disconnect VectorPreHeader from ExitBB in both the CFG and DT.
984 cast<BranchInst>(VectorPreHeader->getTerminator())->setSuccessor(0, nullptr);
985 State->CFG.DTU.applyUpdates(
986 {{DominatorTree::Delete, VectorPreHeader, State->CFG.ExitBB}});
987
988 // Replace regular VPBB's for the middle and scalar preheader blocks with
989 // VPIRBasicBlocks wrapping their IR blocks. The IR blocks are created during
990 // skeleton creation, so we can only create the VPIRBasicBlocks now during
991 // VPlan execution rather than earlier during VPlan construction.
992 BasicBlock *MiddleBB = State->CFG.ExitBB;
993 VPBasicBlock *MiddleVPBB =
994 cast<VPBasicBlock>(getVectorLoopRegion()->getSingleSuccessor());
995 // Find the VPBB for the scalar preheader, relying on the current structure
996 // when creating the middle block and its successrs: if there's a single
997 // predecessor, it must be the scalar preheader. Otherwise, the second
998 // successor is the scalar preheader.
999 BasicBlock *ScalarPh = MiddleBB->getSingleSuccessor();
1000 auto &MiddleSuccs = MiddleVPBB->getSuccessors();
1001 assert((MiddleSuccs.size() == 1 || MiddleSuccs.size() == 2) &&
1002 "middle block has unexpected successors");
1003 VPBasicBlock *ScalarPhVPBB = cast<VPBasicBlock>(
1004 MiddleSuccs.size() == 1 ? MiddleSuccs[0] : MiddleSuccs[1]);
1005 assert(!isa<VPIRBasicBlock>(ScalarPhVPBB) &&
1006 "scalar preheader cannot be wrapped already");
1007 replaceVPBBWithIRVPBB(ScalarPhVPBB, ScalarPh);
1008 replaceVPBBWithIRVPBB(MiddleVPBB, MiddleBB);
1009
1010 // Disconnect the middle block from its single successor (the scalar loop
1011 // header) in both the CFG and DT. The branch will be recreated during VPlan
1012 // execution.
1013 auto *BrInst = new UnreachableInst(MiddleBB->getContext());
1014 BrInst->insertBefore(MiddleBB->getTerminator());
1015 MiddleBB->getTerminator()->eraseFromParent();
1016 State->CFG.DTU.applyUpdates({{DominatorTree::Delete, MiddleBB, ScalarPh}});
1017
1018 // Generate code in the loop pre-header and body.
1020 Block->execute(State);
1021
1022 VPBasicBlock *LatchVPBB = getVectorLoopRegion()->getExitingBasicBlock();
1023 BasicBlock *VectorLatchBB = State->CFG.VPBB2IRBB[LatchVPBB];
1024
1025 // Fix the latch value of canonical, reduction and first-order recurrences
1026 // phis in the vector loop.
1027 VPBasicBlock *Header = getVectorLoopRegion()->getEntryBasicBlock();
1028 for (VPRecipeBase &R : Header->phis()) {
1029 // Skip phi-like recipes that generate their backedege values themselves.
1030 if (isa<VPWidenPHIRecipe>(&R))
1031 continue;
1032
1033 if (isa<VPWidenPointerInductionRecipe>(&R) ||
1034 isa<VPWidenIntOrFpInductionRecipe>(&R)) {
1035 PHINode *Phi = nullptr;
1036 if (isa<VPWidenIntOrFpInductionRecipe>(&R)) {
1037 Phi = cast<PHINode>(State->get(R.getVPSingleValue(), 0));
1038 } else {
1039 auto *WidenPhi = cast<VPWidenPointerInductionRecipe>(&R);
1040 assert(!WidenPhi->onlyScalarsGenerated(State->VF.isScalable()) &&
1041 "recipe generating only scalars should have been replaced");
1042 auto *GEP = cast<GetElementPtrInst>(State->get(WidenPhi, 0));
1043 Phi = cast<PHINode>(GEP->getPointerOperand());
1044 }
1045
1046 Phi->setIncomingBlock(1, VectorLatchBB);
1047
1048 // Move the last step to the end of the latch block. This ensures
1049 // consistent placement of all induction updates.
1050 Instruction *Inc = cast<Instruction>(Phi->getIncomingValue(1));
1051 Inc->moveBefore(VectorLatchBB->getTerminator()->getPrevNode());
1052 continue;
1053 }
1054
1055 auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
1056 // For canonical IV, first-order recurrences and in-order reduction phis,
1057 // only a single part is generated, which provides the last part from the
1058 // previous iteration. For non-ordered reductions all UF parts are
1059 // generated.
1060 bool SinglePartNeeded =
1061 isa<VPCanonicalIVPHIRecipe>(PhiR) ||
1062 isa<VPFirstOrderRecurrencePHIRecipe, VPEVLBasedIVPHIRecipe>(PhiR) ||
1063 (isa<VPReductionPHIRecipe>(PhiR) &&
1064 cast<VPReductionPHIRecipe>(PhiR)->isOrdered());
1065 bool NeedsScalar =
1066 isa<VPCanonicalIVPHIRecipe, VPEVLBasedIVPHIRecipe>(PhiR) ||
1067 (isa<VPReductionPHIRecipe>(PhiR) &&
1068 cast<VPReductionPHIRecipe>(PhiR)->isInLoop());
1069 unsigned LastPartForNewPhi = SinglePartNeeded ? 1 : State->UF;
1070
1071 for (unsigned Part = 0; Part < LastPartForNewPhi; ++Part) {
1072 Value *Phi = State->get(PhiR, Part, NeedsScalar);
1073 Value *Val =
1074 State->get(PhiR->getBackedgeValue(),
1075 SinglePartNeeded ? State->UF - 1 : Part, NeedsScalar);
1076 cast<PHINode>(Phi)->addIncoming(Val, VectorLatchBB);
1077 }
1078 }
1079
1080 State->CFG.DTU.flush();
1081 assert(State->CFG.DTU.getDomTree().verify(
1082 DominatorTree::VerificationLevel::Fast) &&
1083 "DT not preserved correctly");
1084}
1085
1087 // For now only return the cost of the vector loop region, ignoring any other
1088 // blocks, like the preheader or middle blocks.
1089 return getVectorLoopRegion()->cost(VF, Ctx);
1090}
1091
1092#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1095
1096 if (VFxUF.getNumUsers() > 0) {
1097 O << "\nLive-in ";
1098 VFxUF.printAsOperand(O, SlotTracker);
1099 O << " = VF * UF";
1100 }
1101
1102 if (VectorTripCount.getNumUsers() > 0) {
1103 O << "\nLive-in ";
1104 VectorTripCount.printAsOperand(O, SlotTracker);
1105 O << " = vector-trip-count";
1106 }
1107
1108 if (BackedgeTakenCount && BackedgeTakenCount->getNumUsers()) {
1109 O << "\nLive-in ";
1110 BackedgeTakenCount->printAsOperand(O, SlotTracker);
1111 O << " = backedge-taken count";
1112 }
1113
1114 O << "\n";
1115 if (TripCount->isLiveIn())
1116 O << "Live-in ";
1117 TripCount->printAsOperand(O, SlotTracker);
1118 O << " = original trip-count";
1119 O << "\n";
1120}
1121
1125
1126 O << "VPlan '" << getName() << "' {";
1127
1128 printLiveIns(O);
1129
1130 if (!getPreheader()->empty()) {
1131 O << "\n";
1132 getPreheader()->print(O, "", SlotTracker);
1133 }
1134
1135 for (const VPBlockBase *Block : vp_depth_first_shallow(getEntry())) {
1136 O << '\n';
1137 Block->print(O, "", SlotTracker);
1138 }
1139
1140 if (!LiveOuts.empty())
1141 O << "\n";
1142 for (const auto &KV : LiveOuts) {
1143 KV.second->print(O, SlotTracker);
1144 }
1145
1146 O << "}\n";
1147}
1148
1149std::string VPlan::getName() const {
1150 std::string Out;
1151 raw_string_ostream RSO(Out);
1152 RSO << Name << " for ";
1153 if (!VFs.empty()) {
1154 RSO << "VF={" << VFs[0];
1155 for (ElementCount VF : drop_begin(VFs))
1156 RSO << "," << VF;
1157 RSO << "},";
1158 }
1159
1160 if (UFs.empty()) {
1161 RSO << "UF>=1";
1162 } else {
1163 RSO << "UF={" << UFs[0];
1164 for (unsigned UF : drop_begin(UFs))
1165 RSO << "," << UF;
1166 RSO << "}";
1167 }
1168
1169 return Out;
1170}
1171
1174 VPlanPrinter Printer(O, *this);
1175 Printer.dump();
1176}
1177
1179void VPlan::dump() const { print(dbgs()); }
1180#endif
1181
1183 assert(LiveOuts.count(PN) == 0 && "an exit value for PN already exists");
1184 LiveOuts.insert({PN, new VPLiveOut(PN, V)});
1185}
1186
1187static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry,
1188 DenseMap<VPValue *, VPValue *> &Old2NewVPValues) {
1189 // Update the operands of all cloned recipes starting at NewEntry. This
1190 // traverses all reachable blocks. This is done in two steps, to handle cycles
1191 // in PHI recipes.
1193 OldDeepRPOT(Entry);
1195 NewDeepRPOT(NewEntry);
1196 // First, collect all mappings from old to new VPValues defined by cloned
1197 // recipes.
1198 for (const auto &[OldBB, NewBB] :
1199 zip(VPBlockUtils::blocksOnly<VPBasicBlock>(OldDeepRPOT),
1200 VPBlockUtils::blocksOnly<VPBasicBlock>(NewDeepRPOT))) {
1201 assert(OldBB->getRecipeList().size() == NewBB->getRecipeList().size() &&
1202 "blocks must have the same number of recipes");
1203 for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
1204 assert(OldR.getNumOperands() == NewR.getNumOperands() &&
1205 "recipes must have the same number of operands");
1206 assert(OldR.getNumDefinedValues() == NewR.getNumDefinedValues() &&
1207 "recipes must define the same number of operands");
1208 for (const auto &[OldV, NewV] :
1209 zip(OldR.definedValues(), NewR.definedValues()))
1210 Old2NewVPValues[OldV] = NewV;
1211 }
1212 }
1213
1214 // Update all operands to use cloned VPValues.
1215 for (VPBasicBlock *NewBB :
1216 VPBlockUtils::blocksOnly<VPBasicBlock>(NewDeepRPOT)) {
1217 for (VPRecipeBase &NewR : *NewBB)
1218 for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
1219 VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
1220 NewR.setOperand(I, NewOp);
1221 }
1222 }
1223}
1224
1226 // Clone blocks.
1227 VPBasicBlock *NewPreheader = Preheader->clone();
1228 const auto &[NewEntry, __] = cloneFrom(Entry);
1229
1230 // Create VPlan, clone live-ins and remap operands in the cloned blocks.
1231 auto *NewPlan = new VPlan(NewPreheader, cast<VPBasicBlock>(NewEntry));
1232 DenseMap<VPValue *, VPValue *> Old2NewVPValues;
1233 for (VPValue *OldLiveIn : VPLiveInsToFree) {
1234 Old2NewVPValues[OldLiveIn] =
1235 NewPlan->getOrAddLiveIn(OldLiveIn->getLiveInIRValue());
1236 }
1237 Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
1238 Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
1239 if (BackedgeTakenCount) {
1240 NewPlan->BackedgeTakenCount = new VPValue();
1241 Old2NewVPValues[BackedgeTakenCount] = NewPlan->BackedgeTakenCount;
1242 }
1243 assert(TripCount && "trip count must be set");
1244 if (TripCount->isLiveIn())
1245 Old2NewVPValues[TripCount] =
1246 NewPlan->getOrAddLiveIn(TripCount->getLiveInIRValue());
1247 // else NewTripCount will be created and inserted into Old2NewVPValues when
1248 // TripCount is cloned. In any case NewPlan->TripCount is updated below.
1249
1250 remapOperands(Preheader, NewPreheader, Old2NewVPValues);
1251 remapOperands(Entry, NewEntry, Old2NewVPValues);
1252
1253 // Clone live-outs.
1254 for (const auto &[_, LO] : LiveOuts)
1255 NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
1256
1257 // Initialize remaining fields of cloned VPlan.
1258 NewPlan->VFs = VFs;
1259 NewPlan->UFs = UFs;
1260 // TODO: Adjust names.
1261 NewPlan->Name = Name;
1262 assert(Old2NewVPValues.contains(TripCount) &&
1263 "TripCount must have been added to Old2NewVPValues");
1264 NewPlan->TripCount = Old2NewVPValues[TripCount];
1265 return NewPlan;
1266}
1267
1268#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1269
1270Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
1271 return (isa<VPRegionBlock>(Block) ? "cluster_N" : "N") +
1272 Twine(getOrCreateBID(Block));
1273}
1274
1275Twine VPlanPrinter::getOrCreateName(const VPBlockBase *Block) {
1276 const std::string &Name = Block->getName();
1277 if (!Name.empty())
1278 return Name;
1279 return "VPB" + Twine(getOrCreateBID(Block));
1280}
1281
1283 Depth = 1;
1284 bumpIndent(0);
1285 OS << "digraph VPlan {\n";
1286 OS << "graph [labelloc=t, fontsize=30; label=\"Vectorization Plan";
1287 if (!Plan.getName().empty())
1288 OS << "\\n" << DOT::EscapeString(Plan.getName());
1289
1290 {
1291 // Print live-ins.
1292 std::string Str;
1293 raw_string_ostream SS(Str);
1294 Plan.printLiveIns(SS);
1296 StringRef(Str).rtrim('\n').split(Lines, "\n");
1297 for (auto Line : Lines)
1298 OS << DOT::EscapeString(Line.str()) << "\\n";
1299 }
1300
1301 OS << "\"]\n";
1302 OS << "node [shape=rect, fontname=Courier, fontsize=30]\n";
1303 OS << "edge [fontname=Courier, fontsize=30]\n";
1304 OS << "compound=true\n";
1305
1306 dumpBlock(Plan.getPreheader());
1307
1309 dumpBlock(Block);
1310
1311 OS << "}\n";
1312}
1313
1314void VPlanPrinter::dumpBlock(const VPBlockBase *Block) {
1315 if (const VPBasicBlock *BasicBlock = dyn_cast<VPBasicBlock>(Block))
1316 dumpBasicBlock(BasicBlock);
1317 else if (const VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
1318 dumpRegion(Region);
1319 else
1320 llvm_unreachable("Unsupported kind of VPBlock.");
1321}
1322
1323void VPlanPrinter::drawEdge(const VPBlockBase *From, const VPBlockBase *To,
1324 bool Hidden, const Twine &Label) {
1325 // Due to "dot" we print an edge between two regions as an edge between the
1326 // exiting basic block and the entry basic of the respective regions.
1327 const VPBlockBase *Tail = From->getExitingBasicBlock();
1328 const VPBlockBase *Head = To->getEntryBasicBlock();
1329 OS << Indent << getUID(Tail) << " -> " << getUID(Head);
1330 OS << " [ label=\"" << Label << '\"';
1331 if (Tail != From)
1332 OS << " ltail=" << getUID(From);
1333 if (Head != To)
1334 OS << " lhead=" << getUID(To);
1335 if (Hidden)
1336 OS << "; splines=none";
1337 OS << "]\n";
1338}
1339
1340void VPlanPrinter::dumpEdges(const VPBlockBase *Block) {
1341 auto &Successors = Block->getSuccessors();
1342 if (Successors.size() == 1)
1343 drawEdge(Block, Successors.front(), false, "");
1344 else if (Successors.size() == 2) {
1345 drawEdge(Block, Successors.front(), false, "T");
1346 drawEdge(Block, Successors.back(), false, "F");
1347 } else {
1348 unsigned SuccessorNumber = 0;
1349 for (auto *Successor : Successors)
1350 drawEdge(Block, Successor, false, Twine(SuccessorNumber++));
1351 }
1352}
1353
1354void VPlanPrinter::dumpBasicBlock(const VPBasicBlock *BasicBlock) {
1355 // Implement dot-formatted dump by performing plain-text dump into the
1356 // temporary storage followed by some post-processing.
1357 OS << Indent << getUID(BasicBlock) << " [label =\n";
1358 bumpIndent(1);
1359 std::string Str;
1361 // Use no indentation as we need to wrap the lines into quotes ourselves.
1362 BasicBlock->print(SS, "", SlotTracker);
1363
1364 // We need to process each line of the output separately, so split
1365 // single-string plain-text dump.
1367 StringRef(Str).rtrim('\n').split(Lines, "\n");
1368
1369 auto EmitLine = [&](StringRef Line, StringRef Suffix) {
1370 OS << Indent << '"' << DOT::EscapeString(Line.str()) << "\\l\"" << Suffix;
1371 };
1372
1373 // Don't need the "+" after the last line.
1374 for (auto Line : make_range(Lines.begin(), Lines.end() - 1))
1375 EmitLine(Line, " +\n");
1376 EmitLine(Lines.back(), "\n");
1377
1378 bumpIndent(-1);
1379 OS << Indent << "]\n";
1380
1382}
1383
1384void VPlanPrinter::dumpRegion(const VPRegionBlock *Region) {
1385 OS << Indent << "subgraph " << getUID(Region) << " {\n";
1386 bumpIndent(1);
1387 OS << Indent << "fontname=Courier\n"
1388 << Indent << "label=\""
1389 << DOT::EscapeString(Region->isReplicator() ? "<xVFxUF> " : "<x1> ")
1390 << DOT::EscapeString(Region->getName()) << "\"\n";
1391 // Dump the blocks of the region.
1392 assert(Region->getEntry() && "Region contains no inner blocks.");
1394 dumpBlock(Block);
1395 bumpIndent(-1);
1396 OS << Indent << "}\n";
1398}
1399
1401 if (auto *Inst = dyn_cast<Instruction>(V)) {
1402 if (!Inst->getType()->isVoidTy()) {
1403 Inst->printAsOperand(O, false);
1404 O << " = ";
1405 }
1406 O << Inst->getOpcodeName() << " ";
1407 unsigned E = Inst->getNumOperands();
1408 if (E > 0) {
1409 Inst->getOperand(0)->printAsOperand(O, false);
1410 for (unsigned I = 1; I < E; ++I)
1411 Inst->getOperand(I)->printAsOperand(O << ", ", false);
1412 }
1413 } else // !Inst
1414 V->printAsOperand(O, false);
1415}
1416
1417#endif
1418
1419template void DomTreeBuilder::Calculate<VPDominatorTree>(VPDominatorTree &DT);
1420
1422 replaceUsesWithIf(New, [](VPUser &, unsigned) { return true; });
1423}
1424
1426 VPValue *New,
1427 llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace) {
1428 // Note that this early exit is required for correctness; the implementation
1429 // below relies on the number of users for this VPValue to decrease, which
1430 // isn't the case if this == New.
1431 if (this == New)
1432 return;
1433
1434 for (unsigned J = 0; J < getNumUsers();) {
1435 VPUser *User = Users[J];
1436 bool RemovedUser = false;
1437 for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I) {
1438 if (User->getOperand(I) != this || !ShouldReplace(*User, I))
1439 continue;
1440
1441 RemovedUser = true;
1442 User->setOperand(I, New);
1443 }
1444 // If a user got removed after updating the current user, the next user to
1445 // update will be moved to the current position, so we only need to
1446 // increment the index if the number of users did not change.
1447 if (!RemovedUser)
1448 J++;
1449 }
1450}
1451
1452#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1454 OS << Tracker.getOrCreateName(this);
1455}
1456
1458 interleaveComma(operands(), O, [&O, &SlotTracker](VPValue *Op) {
1459 Op->printAsOperand(O, SlotTracker);
1460 });
1461}
1462#endif
1463
1464void VPInterleavedAccessInfo::visitRegion(VPRegionBlock *Region,
1465 Old2NewTy &Old2New,
1466 InterleavedAccessInfo &IAI) {
1468 RPOT(Region->getEntry());
1469 for (VPBlockBase *Base : RPOT) {
1470 visitBlock(Base, Old2New, IAI);
1471 }
1472}
1473
1474void VPInterleavedAccessInfo::visitBlock(VPBlockBase *Block, Old2NewTy &Old2New,
1475 InterleavedAccessInfo &IAI) {
1476 if (VPBasicBlock *VPBB = dyn_cast<VPBasicBlock>(Block)) {
1477 for (VPRecipeBase &VPI : *VPBB) {
1478 if (isa<VPWidenPHIRecipe>(&VPI))
1479 continue;
1480 assert(isa<VPInstruction>(&VPI) && "Can only handle VPInstructions");
1481 auto *VPInst = cast<VPInstruction>(&VPI);
1482
1483 auto *Inst = dyn_cast_or_null<Instruction>(VPInst->getUnderlyingValue());
1484 if (!Inst)
1485 continue;
1486 auto *IG = IAI.getInterleaveGroup(Inst);
1487 if (!IG)
1488 continue;
1489
1490 auto NewIGIter = Old2New.find(IG);
1491 if (NewIGIter == Old2New.end())
1492 Old2New[IG] = new InterleaveGroup<VPInstruction>(
1493 IG->getFactor(), IG->isReverse(), IG->getAlign());
1494
1495 if (Inst == IG->getInsertPos())
1496 Old2New[IG]->setInsertPos(VPInst);
1497
1498 InterleaveGroupMap[VPInst] = Old2New[IG];
1499 InterleaveGroupMap[VPInst]->insertMember(
1500 VPInst, IG->getIndex(Inst),
1501 Align(IG->isReverse() ? (-1) * int(IG->getFactor())
1502 : IG->getFactor()));
1503 }
1504 } else if (VPRegionBlock *Region = dyn_cast<VPRegionBlock>(Block))
1505 visitRegion(Region, Old2New, IAI);
1506 else
1507 llvm_unreachable("Unsupported kind of VPBlock.");
1508}
1509
1511 InterleavedAccessInfo &IAI) {
1512 Old2NewTy Old2New;
1513 visitRegion(Plan.getVectorLoopRegion(), Old2New, IAI);
1514}
1515
1516void VPSlotTracker::assignName(const VPValue *V) {
1517 assert(!VPValue2Name.contains(V) && "VPValue already has a name!");
1518 auto *UV = V->getUnderlyingValue();
1519 if (!UV) {
1520 VPValue2Name[V] = (Twine("vp<%") + Twine(NextSlot) + ">").str();
1521 NextSlot++;
1522 return;
1523 }
1524
1525 // Use the name of the underlying Value, wrapped in "ir<>", and versioned by
1526 // appending ".Number" to the name if there are multiple uses.
1527 std::string Name;
1529 UV->printAsOperand(S, false);
1530 assert(!Name.empty() && "Name cannot be empty.");
1531 std::string BaseName = (Twine("ir<") + Name + Twine(">")).str();
1532
1533 // First assign the base name for V.
1534 const auto &[A, _] = VPValue2Name.insert({V, BaseName});
1535 // Integer or FP constants with different types will result in he same string
1536 // due to stripping types.
1537 if (V->isLiveIn() && isa<ConstantInt, ConstantFP>(UV))
1538 return;
1539
1540 // If it is already used by C > 0 other VPValues, increase the version counter
1541 // C and use it for V.
1542 const auto &[C, UseInserted] = BaseName2Version.insert({BaseName, 0});
1543 if (!UseInserted) {
1544 C->second++;
1545 A->second = (BaseName + Twine(".") + Twine(C->second)).str();
1546 }
1547}
1548
1549void VPSlotTracker::assignNames(const VPlan &Plan) {
1550 if (Plan.VFxUF.getNumUsers() > 0)
1551 assignName(&Plan.VFxUF);
1552 assignName(&Plan.VectorTripCount);
1553 if (Plan.BackedgeTakenCount)
1554 assignName(Plan.BackedgeTakenCount);
1555 for (VPValue *LI : Plan.VPLiveInsToFree)
1556 assignName(LI);
1557 assignNames(Plan.getPreheader());
1558
1561 for (const VPBasicBlock *VPBB :
1562 VPBlockUtils::blocksOnly<const VPBasicBlock>(RPOT))
1563 assignNames(VPBB);
1564}
1565
1566void VPSlotTracker::assignNames(const VPBasicBlock *VPBB) {
1567 for (const VPRecipeBase &Recipe : *VPBB)
1568 for (VPValue *Def : Recipe.definedValues())
1569 assignName(Def);
1570}
1571
1572std::string VPSlotTracker::getOrCreateName(const VPValue *V) const {
1573 std::string Name = VPValue2Name.lookup(V);
1574 if (!Name.empty())
1575 return Name;
1576
1577 // If no name was assigned, no VPlan was provided when creating the slot
1578 // tracker or it is not reachable from the provided VPlan. This can happen,
1579 // e.g. when trying to print a recipe that has not been inserted into a VPlan
1580 // in a debugger.
1581 // TODO: Update VPSlotTracker constructor to assign names to recipes &
1582 // VPValues not associated with a VPlan, instead of constructing names ad-hoc
1583 // here.
1584 const VPRecipeBase *DefR = V->getDefiningRecipe();
1585 (void)DefR;
1586 assert((!DefR || !DefR->getParent() || !DefR->getParent()->getPlan()) &&
1587 "VPValue defined by a recipe in a VPlan?");
1588
1589 // Use the underlying value's name, if there is one.
1590 if (auto *UV = V->getUnderlyingValue()) {
1591 std::string Name;
1593 UV->printAsOperand(S, false);
1594 return (Twine("ir<") + Name + ">").str();
1595 }
1596
1597 return "<badref>";
1598}
1599
1601 return all_of(Def->users(),
1602 [Def](const VPUser *U) { return U->onlyFirstLaneUsed(Def); });
1603}
1604
1606 return all_of(Def->users(),
1607 [Def](const VPUser *U) { return U->onlyFirstPartUsed(Def); });
1608}
1609
1611 ScalarEvolution &SE) {
1612 if (auto *Expanded = Plan.getSCEVExpansion(Expr))
1613 return Expanded;
1614 VPValue *Expanded = nullptr;
1615 if (auto *E = dyn_cast<SCEVConstant>(Expr))
1616 Expanded = Plan.getOrAddLiveIn(E->getValue());
1617 else if (auto *E = dyn_cast<SCEVUnknown>(Expr))
1618 Expanded = Plan.getOrAddLiveIn(E->getValue());
1619 else {
1620 Expanded = new VPExpandSCEVRecipe(Expr, SE);
1622 }
1623 Plan.addSCEVExpansion(Expr, Expanded);
1624 return Expanded;
1625}
1626
1628 if (isa<VPActiveLaneMaskPHIRecipe>(V))
1629 return true;
1630
1631 auto IsWideCanonicalIV = [](VPValue *A) {
1632 return isa<VPWidenCanonicalIVRecipe>(A) ||
1633 (isa<VPWidenIntOrFpInductionRecipe>(A) &&
1634 cast<VPWidenIntOrFpInductionRecipe>(A)->isCanonical());
1635 };
1636
1637 VPValue *A, *B;
1639 return B == Plan.getTripCount() &&
1641 IsWideCanonicalIV(A));
1642
1643 return match(V, m_Binary<Instruction::ICmp>(m_VPValue(A), m_VPValue(B))) &&
1644 IsWideCanonicalIV(A) && B == Plan.getOrCreateBackedgeTakenCount();
1645}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:537
dxil pretty DXIL Metadata Pretty Printer
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(X)
Definition: Debug.h:101
std::string Name
Flatten the CFG
static void dumpEdges(CFGMST< Edge, BBInfo > &MST, GCOVFunction &GF)
Generic dominator tree construction - this file provides routines to construct immediate dominator in...
Hexagon Common GEP
#define _
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
iv Induction Variable Users
Definition: IVUsers.cpp:48
This file provides a LoopVectorizationPlanner class.
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static StringRef getName(Value *V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
static T * getPlanEntry(T *Start)
Definition: VPlan.cpp:130
static void replaceVPBBWithIRVPBB(VPBasicBlock *VPBB, BasicBlock *IRBB)
Replace VPBB with a VPIRBasicBlock wrapping IRBB.
Definition: VPlan.cpp:959
static bool hasConditionalTerminator(const VPBasicBlock *VPBB)
Definition: VPlan.cpp:585
static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry, DenseMap< VPValue *, VPValue * > &Old2NewVPValues)
Definition: VPlan.cpp:1187
static std::pair< VPBlockBase *, VPBlockBase * > cloneFrom(VPBlockBase *Entry)
Definition: VPlan.cpp:663
This file contains the declarations of the Vectorization Plan base classes:
static bool IsCondBranch(unsigned BrOpc)
static const uint32_t IV[8]
Definition: blake3_impl.h:78
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
iterator end()
Definition: BasicBlock.h:451
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the basic block to an output stream with an optional AssemblyAnnotationWriter.
Definition: AsmWriter.cpp:4862
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:202
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:487
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:209
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:167
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:168
size_t size() const
Definition: BasicBlock.h:459
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:229
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
@ ICMP_EQ
equal
Definition: InstrTypes.h:778
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:850
Debug location.
std::optional< const DILocation * > cloneByMultiplyingDuplicationFactor(unsigned DF) const
Returns a new DILocation with duplication factor DF * current duplication factor encoded in the discr...
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:33
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition: DenseMap.h:145
Core dominator tree base class.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
constexpr bool isScalar() const
Exactly one element.
Definition: TypeSize.h:322
bool shouldEmitDebugInfoForProfiling() const
Returns true if we should emit debug info for profiling.
Definition: Metadata.cpp:1834
DomTreeT & getDomTree()
Flush DomTree updates and return DomTree.
void applyUpdates(ArrayRef< typename DomTreeT::UpdateType > Updates)
Submit updates to all available trees.
void flush()
Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2477
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition: IRBuilder.h:2465
UnreachableInst * CreateUnreachable()
Definition: IRBuilder.h:1268
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Definition: IRBuilder.cpp:1193
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:523
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:171
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Definition: IRBuilder.h:217
InsertPoint saveIP() const
Returns the current insert point.
Definition: IRBuilder.h:274
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:483
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1349
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
Definition: IRBuilder.h:1119
void restoreIP(InsertPoint IP)
Sets the current insert point to a previously-saved location.
Definition: IRBuilder.h:286
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition: IRBuilder.h:177
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2671
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
static InstructionCost getInvalid(CostType Val=0)
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:92
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
The group of interleaved loads/stores sharing the same stride and close to each other.
Definition: VectorUtils.h:470
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:612
InterleaveGroup< Instruction > * getInterleaveGroup(const Instruction *Instr) const
Get the interleave group that Instr belongs to.
Definition: VectorUtils.h:657
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
BlockT * getLoopLatch() const
If there is a single latch block for this loop, return it.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
void addChildLoop(LoopT *NewChild)
Add the specified loop to be a child of this loop.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
BlockT * getUniqueExitBlock() const
If getUniqueExitBlocks would return exactly one block, return that block.
void addTopLevelLoop(LoopT *New)
This adds the specified loop to the collection of top-level loops.
LoopT * AllocateLoop(ArgsTy &&...Args)
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void annotateInstWithNoAlias(Instruction *VersionedInst, const Instruction *OrigInst)
Add the noalias annotations to VersionedInst.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:44
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:5298
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1852
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
Definition: RegionInfo.h:322
This class represents an analyzed expression in the program.
Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:98
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:162
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:696
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:370
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:685
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
Definition: StringRef.h:788
@ TCK_RecipThroughput
Reciprocal throughput.
InstructionCost getCFInstrCost(unsigned Opcode, TTI::TargetCostKind CostKind=TTI::TCK_SizeAndLatency, const Instruction *I=nullptr) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static IntegerType * getInt1Ty(LLVMContext &C)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
This function has undefined behavior.
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
Value * getOperand(unsigned i) const
Definition: User.h:169
unsigned getNumOperands() const
Definition: User.h:191
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:2969
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition: VPlan.h:3041
VPBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition: VPlan.h:3088
RecipeListTy::iterator iterator
Instruction iterators...
Definition: VPlan.h:2993
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:483
iterator end()
Definition: VPlan.h:3003
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:3001
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of this VPBasicBlock.
Definition: VPlan.cpp:780
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition: VPlan.cpp:212
VPRegionBlock * getEnclosingLoopRegion()
Definition: VPlan.cpp:575
void dropAllReferences(VPValue *NewValue) override
Replace all operands of VPUsers in the block with NewValue and also replaces all uses of VPValues def...
Definition: VPlan.cpp:527
VPBasicBlock * splitAt(iterator SplitAt)
Split current block at SplitAt by inserting a new block between the current block and its successors ...
Definition: VPlan.cpp:550
void executeRecipes(VPTransformState *State, BasicBlock *BB)
Execute the recipes in the IR basic block BB.
Definition: VPlan.cpp:537
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPBsicBlock to O, prefixing all lines with Indent.
Definition: VPlan.cpp:642
bool isExiting() const
Returns true if the block is exiting it's parent region.
Definition: VPlan.cpp:625
VPRecipeBase * getTerminator()
If the block has multiple successors, return the branch recipe terminating the block.
Definition: VPlan.cpp:613
const VPRecipeBase & back() const
Definition: VPlan.h:3015
bool empty() const
Definition: VPlan.h:3012
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:437
void setSuccessors(ArrayRef< VPBlockBase * > NewSuccs)
Set each VPBasicBlock in NewSuccss as successor of this VPBlockBase.
Definition: VPlan.h:632
VPRegionBlock * getParent()
Definition: VPlan.h:509
const VPBasicBlock * getExitingBasicBlock() const
Definition: VPlan.cpp:177
size_t getNumSuccessors() const
Definition: VPlan.h:554
iterator_range< VPBlockBase ** > successors()
Definition: VPlan.h:537
void printSuccessors(raw_ostream &O, const Twine &Indent) const
Print the successors of this block to O, prefixing all lines with Indent.
Definition: VPlan.cpp:630
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition: VPlan.h:623
VPBlockBase * getEnclosingBlockWithPredecessors()
Definition: VPlan.cpp:199
const VPBlocksTy & getPredecessors() const
Definition: VPlan.h:539
static void deleteCFG(VPBlockBase *Entry)
Delete all blocks reachable from a given VPBlockBase, inclusive.
Definition: VPlan.cpp:207
VPlan * getPlan()
Definition: VPlan.cpp:150
void setPlan(VPlan *ParentPlan)
Sets the pointer of the plan containing the block.
Definition: VPlan.cpp:169
VPBlockBase * getSingleHierarchicalSuccessor()
Definition: VPlan.h:580
VPBlockBase * getSinglePredecessor() const
Definition: VPlan.h:550
const VPBlocksTy & getHierarchicalSuccessors()
Definition: VPlan.h:574
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
Definition: VPlan.cpp:191
const VPBasicBlock * getEntryBasicBlock() const
Definition: VPlan.cpp:155
const VPBlocksTy & getSuccessors() const
Definition: VPlan.h:534
Helper for GraphTraits specialization that traverses through VPRegionBlocks.
Definition: VPlanCFG.h:115
static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBase NewBlock after BlockPtr.
Definition: VPlan.h:3582
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
Definition: VPlan.h:3629
static void connectBlocks(VPBlockBase *From, VPBlockBase *To)
Connect VPBlockBases From and To bi-directionally.
Definition: VPlan.h:3618
VPlan-based builder utility analogous to IRBuilder.
This class augments a recipe with a set of VPValues defined by the recipe.
Definition: VPlanValue.h:307
void dump() const
Dump the VPDef to stderr (for debugging).
Definition: VPlan.cpp:111
virtual void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const =0
Each concrete VPDef prints itself.
Recipe to expand a SCEV expression.
Definition: VPlan.h:2676
A special type of VPBasicBlock that wraps an existing IR basic block.
Definition: VPlan.h:3110
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:452
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:1229
VPInterleavedAccessInfo(VPlan &Plan, InterleavedAccessInfo &IAI)
Definition: VPlan.cpp:1510
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
Definition: VPlan.h:156
Value * getAsRuntimeExpr(IRBuilderBase &Builder, const ElementCount &VF) const
Returns an expression describing the lane index that can be used at runtime.
Definition: VPlan.cpp:70
static VPLane getFirstLane()
Definition: VPlan.h:180
@ ScalableLast
For ScalableLast, Lane is the offset from the start of the last N-element subvector in a scalable vec...
@ First
For First, Lane is the index into the first N elements of a fixed-vector <N x <ElTy>> or a scalable v...
A value that is used outside the VPlan.
Definition: VPlan.h:704
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:764
VPBasicBlock * getParent()
Definition: VPlan.h:789
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:3147
VPRegionBlock * clone() override
Clone all blocks in the single-entry single-exit region of the block and their recipes without updati...
Definition: VPlan.cpp:713
const VPBlockBase * getEntry() const
Definition: VPlan.h:3186
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition: VPlan.h:3218
void dropAllReferences(VPValue *NewValue) override
Replace all operands of VPUsers in the block with NewValue and also replaces all uses of VPValues def...
Definition: VPlan.cpp:722
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of the block.
Definition: VPlan.cpp:787
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPRegionBlock to O (recursively), prefixing all lines with Indent.
Definition: VPlan.cpp:823
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPRegionBlock,...
Definition: VPlan.cpp:729
const VPBlockBase * getExiting() const
Definition: VPlan.h:3198
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition: VPlan.h:3211
This class can be used to assign names to VPValues.
Definition: VPlanValue.h:449
std::string getOrCreateName(const VPValue *V) const
Returns the name assigned to V, if there is one, otherwise try to construct one from the underlying v...
Definition: VPlan.cpp:1572
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition: VPlanValue.h:202
void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the operands to O.
Definition: VPlan.cpp:1457
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition: VPlan.cpp:120
void printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const
Definition: VPlan.cpp:1453
void dump() const
Dump the value to stderr (for debugging).
Definition: VPlan.cpp:103
VPValue(const unsigned char SC, Value *UV=nullptr, VPDef *Def=nullptr)
Definition: VPlan.cpp:83
virtual ~VPValue()
Definition: VPlan.cpp:89
void print(raw_ostream &OS, VPSlotTracker &Tracker) const
Definition: VPlan.cpp:96
void replaceAllUsesWith(VPValue *New)
Definition: VPlan.cpp:1421
unsigned getNumUsers() const
Definition: VPlanValue.h:111
void replaceUsesWithIf(VPValue *New, llvm::function_ref< bool(VPUser &U, unsigned Idx)> ShouldReplace)
Go through the uses list for this VPValue and make each use point to New if the callback ShouldReplac...
Definition: VPlan.cpp:1425
VPDef * Def
Pointer to the VPDef that defines this VPValue.
Definition: VPlanValue.h:64
VPlanPrinter prints a given VPlan to a given output stream.
Definition: VPlan.h:3502
LLVM_DUMP_METHOD void dump()
Definition: VPlan.cpp:1282
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3251
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition: VPlan.cpp:1173
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition: VPlan.cpp:1149
void prepareToExecute(Value *TripCount, Value *VectorTripCount, Value *CanonicalIVStartValue, VPTransformState &State)
Prepare the plan for execution, setting up the required live-in values.
Definition: VPlan.cpp:916
VPBasicBlock * getEntry()
Definition: VPlan.h:3353
VPValue & getVectorTripCount()
The vector trip count.
Definition: VPlan.h:3378
VPValue * getTripCount() const
The trip count of the original loop.
Definition: VPlan.h:3357
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition: VPlan.h:3371
void addLiveOut(PHINode *PN, VPValue *V)
Definition: VPlan.cpp:1182
VPBasicBlock * getPreheader()
Definition: VPlan.h:3491
VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition: VPlan.h:3453
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition: VPlan.h:3485
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition: VPlan.cpp:1086
static VPlanPtr createInitialVPlan(const SCEV *TripCount, ScalarEvolution &PSE, bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop)
Create initial VPlan, having an "entry" VPBasicBlock (wrapping original scalar pre-header ) which con...
Definition: VPlan.cpp:858
VPValue * getOrAddLiveIn(Value *V)
Gets the live-in VPValue for V or adds a new live-in (if none exists yet) for V.
Definition: VPlan.h:3419
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition: VPlan.cpp:1179
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
Definition: VPlan.cpp:976
void print(raw_ostream &O) const
Print this VPlan to O.
Definition: VPlan.cpp:1123
VPValue * getSCEVExpansion(const SCEV *S) const
Definition: VPlan.h:3481
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition: VPlan.cpp:1093
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition: VPlan.cpp:1225
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:676
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition: CallingConv.h:76
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
std::string EscapeString(const std::string &Label)
Definition: GraphWriter.cpp:56
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
Definition: PatternMatch.h:972
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:49
BinaryVPInstruction_match< Op0_t, Op1_t, VPInstruction::ActiveLaneMask > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1)
VPCanonicalIVPHI_match m_CanonicalIV()
VPScalarIVSteps_match< Op0_t, Op1_t > m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1)
BinaryVPInstruction_match< Op0_t, Op1_t, VPInstruction::BranchOnCount > m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1)
UnaryVPInstruction_match< Op0_t, VPInstruction::BranchOnCond > m_BranchOnCond(const Op0_t &Op0)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
@ SS
Definition: X86.h:211
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, ScalarEvolution &SE)
Get or create a VPValue that corresponds to the expansion of Expr.
Definition: VPlan.cpp:1610
bool isUniformAfterVectorization(VPValue *VPV)
Returns true if VPV is uniform after vectorization.
Definition: VPlan.h:3806
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
Definition: VPlan.cpp:1605
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
Definition: VPlan.cpp:1600
bool isHeaderMask(VPValue *V, VPlan &Plan)
Return true if V is a header mask in Plan.
Definition: VPlan.cpp:1627
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition: STLExtras.h:329
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition: STLExtras.h:853
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:1722
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1680
auto successors(const MachineBasicBlock *BB)
Value * getRuntimeVF(IRBuilderBase &B, Type *Ty, ElementCount VF)
Return the runtime value for VF.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
Definition: STLExtras.h:2159
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:656
iterator_range< df_iterator< VPBlockShallowTraversalWrapper< VPBlockBase * > > > vp_depth_first_shallow(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order.
Definition: VPlanCFG.h:214
Instruction * propagateMetadata(Instruction *I, ArrayRef< Value * > VL)
Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath, MD_nontemporal,...
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
cl::opt< bool > EnableFSDiscriminator
cl::opt< bool > EnableVPlanNativePath("enable-vplan-native-path", cl::Hidden, cl::desc("Enable VPlan-native vectorization path with " "support for outer loop vectorization."))
Definition: VPlan.cpp:55
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:147
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
Definition: SmallVector.h:1312
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:293
Value * createStepForVF(IRBuilderBase &B, Type *Ty, ElementCount VF, int64_t Step)
Return a value for Step multiplied by VF.
BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
InstructionCost Cost
unsigned getReciprocalPredBlockProb()
A helper function that returns the reciprocal of the block probability of predicated blocks.
Definition: VPlan.h:95
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Struct to hold various analysis needed for cost computations.
Definition: VPlan.h:737
const TargetTransformInfo & TTI
Definition: VPlan.h:738
VPIteration represents a single point in the iteration space of the output (vectorized and/or unrolle...
Definition: VPlan.h:238
Hold state information used when constructing the CFG of the output IR, traversing the VPBasicBlocks ...
Definition: VPlan.h:378
BasicBlock * PrevBB
The previous IR BasicBlock created or used.
Definition: VPlan.h:384
SmallDenseMap< VPBasicBlock *, BasicBlock * > VPBB2IRBB
A mapping of each VPBasicBlock to the corresponding BasicBlock.
Definition: VPlan.h:392
VPBasicBlock * PrevVPBB
The previous VPBasicBlock visited. Initially set to null.
Definition: VPlan.h:380
BasicBlock * ExitBB
The last IR BasicBlock in the output IR.
Definition: VPlan.h:388
BasicBlock * getPreheaderBBFor(VPRecipeBase *R)
Returns the BasicBlock* mapped to the pre-header of the loop region containing R.
Definition: VPlan.cpp:356
DomTreeUpdater DTU
Updater for the DominatorTree.
Definition: VPlan.h:395
DenseMap< VPValue *, ScalarsPerPartValuesTy > PerPartScalars
Definition: VPlan.h:278
DenseMap< VPValue *, PerPartValuesTy > PerPartOutput
Definition: VPlan.h:275
VPTransformState holds information passed down when "executing" a VPlan, needed for generating the ou...
Definition: VPlan.h:255
Value * get(VPValue *Def, unsigned Part, bool IsScalar=false)
Get the generated vector Value for a given VPValue Def and a given Part if IsScalar is false,...
Definition: VPlan.cpp:254
LoopInfo * LI
Hold a pointer to LoopInfo to register new basic blocks in the loop.
Definition: VPlan.h:406
VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI, DominatorTree *DT, IRBuilderBase &Builder, InnerLoopVectorizer *ILV, VPlan *Plan, LLVMContext &Ctx)
Definition: VPlan.cpp:219
struct llvm::VPTransformState::DataState Data
void addMetadata(Value *To, Instruction *From)
Add metadata from one instruction to another.
Definition: VPlan.cpp:369
struct llvm::VPTransformState::CFGState CFG
LoopVersioning * LVer
LoopVersioning.
Definition: VPlan.h:425
void addNewMetadata(Instruction *To, const Instruction *Orig)
Add additional metadata to To that was not present on Orig.
Definition: VPlan.cpp:361
void packScalarIntoVectorValue(VPValue *Def, const VPIteration &Instance)
Construct the vector value of a scalarized value V one lane at a time.
Definition: VPlan.cpp:401
void set(VPValue *Def, Value *V, unsigned Part, bool IsScalar=false)
Set the generated vector Value for a given VPValue and a given Part, if IsScalar is false.
Definition: VPlan.h:307
std::optional< VPIteration > Instance
Hold the indices to generate specific scalar instructions.
Definition: VPlan.h:267
IRBuilderBase & Builder
Hold a reference to the IRBuilder used to generate output IR code.
Definition: VPlan.h:409
bool hasScalarValue(VPValue *Def, VPIteration Instance)
Definition: VPlan.h:295
VPlan * Plan
Pointer to the VPlan code is generated for.
Definition: VPlan.h:415
bool hasVectorValue(VPValue *Def, unsigned Part)
Definition: VPlan.h:289
ElementCount VF
The chosen Vectorization and Unroll Factors of the loop being vectorized.
Definition: VPlan.h:261
Loop * CurrentVectorLoop
The loop object for the current parent region, or nullptr.
Definition: VPlan.h:418
void setDebugLocFrom(DebugLoc DL)
Set the debug location in the builder using the debug location DL.
Definition: VPlan.cpp:380
void print(raw_ostream &O) const
Definition: VPlan.cpp:1400