LLVM 22.0.0git
VPlanAnalysis.cpp
Go to the documentation of this file.
1//===- VPlanAnalysis.cpp - Various Analyses working on VPlan ----*- C++ -*-===//
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#include "VPlanAnalysis.h"
10#include "VPlan.h"
11#include "VPlanCFG.h"
12#include "VPlanDominatorTree.h"
13#include "VPlanHelpers.h"
14#include "VPlanPatternMatch.h"
16#include "llvm/ADT/TypeSwitch.h"
19#include "llvm/IR/Instruction.h"
21
22using namespace llvm;
23using namespace VPlanPatternMatch;
24
25#define DEBUG_TYPE "vplan"
26
28 if (auto LoopRegion = Plan.getVectorLoopRegion()) {
29 if (const auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(
30 &LoopRegion->getEntryBasicBlock()->front())) {
31 CanonicalIVTy = CanIV->getScalarType();
32 return;
33 }
34 }
35
36 // If there's no canonical IV, retrieve the type from the trip count
37 // expression.
38 auto *TC = Plan.getTripCount();
39 if (TC->isLiveIn()) {
40 CanonicalIVTy = TC->getLiveInIRValue()->getType();
41 return;
42 }
43 CanonicalIVTy = cast<VPExpandSCEVRecipe>(TC)->getSCEV()->getType();
44}
45
46Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
47 Type *ResTy = inferScalarType(R->getIncomingValue(0));
48 for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {
49 VPValue *Inc = R->getIncomingValue(I);
50 assert(inferScalarType(Inc) == ResTy &&
51 "different types inferred for different incoming values");
52 CachedTypes[Inc] = ResTy;
53 }
54 return ResTy;
55}
56
57Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
58 // Set the result type from the first operand, check if the types for all
59 // other operands match and cache them.
60 auto SetResultTyFromOp = [this, R]() {
61 Type *ResTy = inferScalarType(R->getOperand(0));
62 for (unsigned Op = 1; Op != R->getNumOperands(); ++Op) {
63 VPValue *OtherV = R->getOperand(Op);
64 assert(inferScalarType(OtherV) == ResTy &&
65 "different types inferred for different operands");
66 CachedTypes[OtherV] = ResTy;
67 }
68 return ResTy;
69 };
70
71 unsigned Opcode = R->getOpcode();
73 return SetResultTyFromOp();
74
75 switch (Opcode) {
76 case Instruction::ExtractElement:
77 case Instruction::Freeze:
80 return inferScalarType(R->getOperand(0));
81 case Instruction::Select: {
82 Type *ResTy = inferScalarType(R->getOperand(1));
83 VPValue *OtherV = R->getOperand(2);
84 assert(inferScalarType(OtherV) == ResTy &&
85 "different types inferred for different operands");
86 CachedTypes[OtherV] = ResTy;
87 return ResTy;
88 }
89 case Instruction::ICmp:
90 case Instruction::FCmp:
92 assert(inferScalarType(R->getOperand(0)) ==
93 inferScalarType(R->getOperand(1)) &&
94 "different types inferred for different operands");
95 return IntegerType::get(Ctx, 1);
97 return inferScalarType(R->getOperand(1));
100 return inferScalarType(R->getOperand(0));
101 }
103 return Type::getIntNTy(Ctx, 32);
104 case Instruction::PHI:
105 // Infer the type of first operand only, as other operands of header phi's
106 // may lead to infinite recursion.
107 return inferScalarType(R->getOperand(0));
116 return SetResultTyFromOp();
118 return inferScalarType(R->getOperand(1));
121 return Type::getIntNTy(Ctx, 64);
124 Type *BaseTy = inferScalarType(R->getOperand(0));
125 if (auto *VecTy = dyn_cast<VectorType>(BaseTy))
126 return VecTy->getElementType();
127 return BaseTy;
128 }
130 return inferScalarType(R->getOperand(0));
132 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1) &&
133 inferScalarType(R->getOperand(1))->isIntegerTy(1) &&
134 "LogicalAnd operands should be bool");
135 return IntegerType::get(Ctx, 1);
139 // Return the type based on first operand.
140 return inferScalarType(R->getOperand(0));
143 return Type::getVoidTy(Ctx);
144 default:
145 break;
146 }
147 // Type inference not implemented for opcode.
148 LLVM_DEBUG({
149 dbgs() << "LV: Found unhandled opcode for: ";
150 R->getVPSingleValue()->dump();
151 });
152 llvm_unreachable("Unhandled opcode!");
153}
154
155Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
156 unsigned Opcode = R->getOpcode();
157 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
159 Type *ResTy = inferScalarType(R->getOperand(0));
160 assert(ResTy == inferScalarType(R->getOperand(1)) &&
161 "types for both operands must match for binary op");
162 CachedTypes[R->getOperand(1)] = ResTy;
163 return ResTy;
164 }
165
166 switch (Opcode) {
167 case Instruction::ICmp:
168 case Instruction::FCmp:
169 return IntegerType::get(Ctx, 1);
170 case Instruction::FNeg:
171 case Instruction::Freeze:
172 return inferScalarType(R->getOperand(0));
173 case Instruction::ExtractValue: {
174 assert(R->getNumOperands() == 2 && "expected single level extractvalue");
175 auto *StructTy = cast<StructType>(inferScalarType(R->getOperand(0)));
176 auto *CI = cast<ConstantInt>(R->getOperand(1)->getLiveInIRValue());
177 return StructTy->getTypeAtIndex(CI->getZExtValue());
178 }
179 default:
180 break;
181 }
182
183 // Type inference not implemented for opcode.
184 LLVM_DEBUG({
185 dbgs() << "LV: Found unhandled opcode for: ";
186 R->getVPSingleValue()->dump();
187 });
188 llvm_unreachable("Unhandled opcode!");
189}
190
191Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenCallRecipe *R) {
192 auto &CI = *cast<CallInst>(R->getUnderlyingInstr());
193 return CI.getType();
194}
195
196Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R) {
198 "Store recipes should not define any values");
199 return cast<LoadInst>(&R->getIngredient())->getType();
200}
201
202Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenSelectRecipe *R) {
203 Type *ResTy = inferScalarType(R->getOperand(1));
204 VPValue *OtherV = R->getOperand(2);
205 assert(inferScalarType(OtherV) == ResTy &&
206 "different types inferred for different operands");
207 CachedTypes[OtherV] = ResTy;
208 return ResTy;
209}
210
211Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
212 unsigned Opcode = R->getUnderlyingInstr()->getOpcode();
213
214 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
216 Type *ResTy = inferScalarType(R->getOperand(0));
217 assert(ResTy == inferScalarType(R->getOperand(1)) &&
218 "inferred types for operands of binary op don't match");
219 CachedTypes[R->getOperand(1)] = ResTy;
220 return ResTy;
221 }
222
223 if (Instruction::isCast(Opcode))
224 return R->getUnderlyingInstr()->getType();
225
226 switch (Opcode) {
227 case Instruction::Call: {
228 unsigned CallIdx = R->getNumOperands() - (R->isPredicated() ? 2 : 1);
229 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
230 ->getReturnType();
231 }
232 case Instruction::Select: {
233 Type *ResTy = inferScalarType(R->getOperand(1));
234 assert(ResTy == inferScalarType(R->getOperand(2)) &&
235 "inferred types for operands of select op don't match");
236 CachedTypes[R->getOperand(2)] = ResTy;
237 return ResTy;
238 }
239 case Instruction::ICmp:
240 case Instruction::FCmp:
241 return IntegerType::get(Ctx, 1);
242 case Instruction::Alloca:
243 case Instruction::ExtractValue:
244 return R->getUnderlyingInstr()->getType();
245 case Instruction::Freeze:
246 case Instruction::FNeg:
247 case Instruction::GetElementPtr:
248 return inferScalarType(R->getOperand(0));
249 case Instruction::Load:
250 return cast<LoadInst>(R->getUnderlyingInstr())->getType();
251 case Instruction::Store:
252 // FIXME: VPReplicateRecipes with store opcodes still define a result
253 // VPValue, so we need to handle them here. Remove the code here once this
254 // is modeled accurately in VPlan.
255 return Type::getVoidTy(Ctx);
256 default:
257 break;
258 }
259 // Type inference not implemented for opcode.
260 LLVM_DEBUG({
261 dbgs() << "LV: Found unhandled opcode for: ";
262 R->getVPSingleValue()->dump();
263 });
264 llvm_unreachable("Unhandled opcode");
265}
266
268 if (Type *CachedTy = CachedTypes.lookup(V))
269 return CachedTy;
270
271 if (V->isLiveIn()) {
272 if (auto *IRValue = V->getLiveInIRValue())
273 return IRValue->getType();
274 // All VPValues without any underlying IR value (like the vector trip count
275 // or the backedge-taken count) have the same type as the canonical IV.
276 return CanonicalIVTy;
277 }
278
279 Type *ResultTy =
280 TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe())
284 [this](const auto *R) {
285 // Handle header phi recipes, except VPWidenIntOrFpInduction
286 // which needs special handling due it being possibly truncated.
287 // TODO: consider inferring/caching type of siblings, e.g.,
288 // backedge value, here and in cases below.
289 return inferScalarType(R->getStartValue());
290 })
291 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
292 [](const auto *R) { return R->getScalarType(); })
296 [this](const VPRecipeBase *R) {
297 return inferScalarType(R->getOperand(0));
298 })
299 // VPInstructionWithType must be handled before VPInstruction.
302 [](const auto *R) { return R->getResultType(); })
305 [this](const auto *R) { return inferScalarTypeForRecipe(R); })
306 .Case<VPInterleaveBase>([V](const auto *R) {
307 // TODO: Use info from interleave group.
308 return V->getUnderlyingValue()->getType();
309 })
310 .Case<VPExpandSCEVRecipe>([](const VPExpandSCEVRecipe *R) {
311 return R->getSCEV()->getType();
312 })
313 .Case<VPReductionRecipe>([this](const auto *R) {
314 return inferScalarType(R->getChainOp());
315 })
316 .Case<VPExpressionRecipe>([this](const auto *R) {
317 return inferScalarType(R->getOperandOfResultType());
318 });
319
320 assert(ResultTy && "could not infer type for the given VPValue");
321 CachedTypes[V] = ResultTy;
322 return ResultTy;
323}
324
326 VPlan &Plan, DenseSet<VPRecipeBase *> &EphRecipes) {
327 // First, collect seed recipes which are operands of assumes.
331 for (VPRecipeBase &R : *VPBB) {
332 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
333 if (!RepR || !match(RepR, m_Intrinsic<Intrinsic::assume>()))
334 continue;
335 Worklist.push_back(RepR);
336 EphRecipes.insert(RepR);
337 }
338 }
339
340 // Process operands of candidates in worklist and add them to the set of
341 // ephemeral recipes, if they don't have side-effects and are only used by
342 // other ephemeral recipes.
343 while (!Worklist.empty()) {
344 VPRecipeBase *Cur = Worklist.pop_back_val();
345 for (VPValue *Op : Cur->operands()) {
346 auto *OpR = Op->getDefiningRecipe();
347 if (!OpR || OpR->mayHaveSideEffects() || EphRecipes.contains(OpR))
348 continue;
349 if (any_of(Op->users(), [EphRecipes](VPUser *U) {
350 auto *UR = dyn_cast<VPRecipeBase>(U);
351 return !UR || !EphRecipes.contains(UR);
352 }))
353 continue;
354 EphRecipes.insert(OpR);
355 Worklist.push_back(OpR);
356 }
357 }
358}
359
362
364 const VPRecipeBase *B) {
365 if (A == B)
366 return false;
367
368 auto LocalComesBefore = [](const VPRecipeBase *A, const VPRecipeBase *B) {
369 for (auto &R : *A->getParent()) {
370 if (&R == A)
371 return true;
372 if (&R == B)
373 return false;
374 }
375 llvm_unreachable("recipe not found");
376 };
377 const VPBlockBase *ParentA = A->getParent();
378 const VPBlockBase *ParentB = B->getParent();
379 if (ParentA == ParentB)
380 return LocalComesBefore(A, B);
381
382#ifndef NDEBUG
383 auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * {
384 VPRegionBlock *Region = R->getRegion();
385 if (Region && Region->isReplicator()) {
386 assert(Region->getNumSuccessors() == 1 &&
387 Region->getNumPredecessors() == 1 && "Expected SESE region!");
388 assert(R->getParent()->size() == 1 &&
389 "A recipe in an original replicator region must be the only "
390 "recipe in its block");
391 return Region;
392 }
393 return nullptr;
394 };
395 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(A)) &&
396 "No replicate regions expected at this point");
397 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(B)) &&
398 "No replicate regions expected at this point");
399#endif
400 return Base::properlyDominates(ParentA, ParentB);
401}
402
404 unsigned OverrideMaxNumRegs) const {
405 return any_of(MaxLocalUsers, [&TTI, &OverrideMaxNumRegs](auto &LU) {
406 return LU.second > (OverrideMaxNumRegs > 0
407 ? OverrideMaxNumRegs
408 : TTI.getNumberOfRegisters(LU.first));
409 });
410}
411
414 const SmallPtrSetImpl<const Value *> &ValuesToIgnore) {
415 // Each 'key' in the map opens a new interval. The values
416 // of the map are the index of the 'last seen' usage of the
417 // VPValue that is the key.
419
420 // Maps indices to recipes.
422 // Marks the end of each interval.
423 IntervalMap EndPoint;
424 // Saves the list of VPValues that are used in the loop.
426 // Saves the list of values that are used in the loop but are defined outside
427 // the loop (not including non-recipe values such as arguments and
428 // constants).
429 SmallSetVector<VPValue *, 8> LoopInvariants;
430 LoopInvariants.insert(&Plan.getVectorTripCount());
431
432 // We scan the loop in a topological order in order and assign a number to
433 // each recipe. We use RPO to ensure that defs are met before their users. We
434 // assume that each recipe that has in-loop users starts an interval. We
435 // record every time that an in-loop value is used, so we have a list of the
436 // first occurences of each recipe and last occurrence of each VPValue.
437 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
439 LoopRegion);
441 if (!VPBB->getParent())
442 break;
443 for (VPRecipeBase &R : *VPBB) {
444 Idx2Recipe.push_back(&R);
445
446 // Save the end location of each USE.
447 for (VPValue *U : R.operands()) {
448 auto *DefR = U->getDefiningRecipe();
449
450 // Ignore non-recipe values such as arguments, constants, etc.
451 // FIXME: Might need some motivation why these values are ignored. If
452 // for example an argument is used inside the loop it will increase the
453 // register pressure (so shouldn't we add it to LoopInvariants).
454 if (!DefR && (!U->getLiveInIRValue() ||
455 !isa<Instruction>(U->getLiveInIRValue())))
456 continue;
457
458 // If this recipe is outside the loop then record it and continue.
459 if (!DefR) {
460 LoopInvariants.insert(U);
461 continue;
462 }
463
464 // Overwrite previous end points.
465 EndPoint[U] = Idx2Recipe.size();
466 Ends.insert(U);
467 }
468 }
469 if (VPBB == LoopRegion->getExiting()) {
470 // VPWidenIntOrFpInductionRecipes are used implicitly at the end of the
471 // exiting block, where their increment will get materialized eventually.
472 for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
473 if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
474 EndPoint[WideIV] = Idx2Recipe.size();
475 Ends.insert(WideIV);
476 }
477 }
478 }
479 }
480
481 // Saves the list of intervals that end with the index in 'key'.
482 using VPValueList = SmallVector<VPValue *, 2>;
484
485 // Next, we transpose the EndPoints into a multi map that holds the list of
486 // intervals that *end* at a specific location.
487 for (auto &Interval : EndPoint)
488 TransposeEnds[Interval.second].push_back(Interval.first);
489
490 SmallPtrSet<VPValue *, 8> OpenIntervals;
493
494 LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
495
496 VPTypeAnalysis TypeInfo(Plan);
497
498 const auto &TTICapture = TTI;
499 auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> unsigned {
500 if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty) ||
501 (VF.isScalable() &&
502 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
503 return 0;
504 return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
505 };
506
507 // We scan the instructions linearly and record each time that a new interval
508 // starts, by placing it in a set. If we find this value in TransposEnds then
509 // we remove it from the set. The max register usage is the maximum register
510 // usage of the recipes of the set.
511 for (unsigned int Idx = 0, Sz = Idx2Recipe.size(); Idx < Sz; ++Idx) {
512 VPRecipeBase *R = Idx2Recipe[Idx];
513
514 // Remove all of the VPValues that end at this location.
515 VPValueList &List = TransposeEnds[Idx];
516 for (VPValue *ToRemove : List)
517 OpenIntervals.erase(ToRemove);
518
519 // Ignore recipes that are never used within the loop and do not have side
520 // effects.
521 if (none_of(R->definedValues(),
522 [&Ends](VPValue *Def) { return Ends.count(Def); }) &&
523 !R->mayHaveSideEffects())
524 continue;
525
526 // Skip recipes for ignored values.
527 // TODO: Should mark recipes for ephemeral values that cannot be removed
528 // explictly in VPlan.
529 if (isa<VPSingleDefRecipe>(R) &&
530 ValuesToIgnore.contains(
531 cast<VPSingleDefRecipe>(R)->getUnderlyingValue()))
532 continue;
533
534 // For each VF find the maximum usage of registers.
535 for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
536 // Count the number of registers used, per register class, given all open
537 // intervals.
538 // Note that elements in this SmallMapVector will be default constructed
539 // as 0. So we can use "RegUsage[ClassID] += n" in the code below even if
540 // there is no previous entry for ClassID.
542
543 for (auto *VPV : OpenIntervals) {
544 // Skip artificial values or values that weren't present in the original
545 // loop.
546 // TODO: Remove skipping values that weren't present in the original
547 // loop after removing the legacy
548 // LoopVectorizationCostModel::calculateRegisterUsage
550 VPBranchOnMaskRecipe>(VPV) ||
552 continue;
553
554 if (VFs[J].isScalar() ||
559 (cast<VPReductionPHIRecipe>(VPV))->isInLoop())) {
560 unsigned ClassID =
561 TTI.getRegisterClassForType(false, TypeInfo.inferScalarType(VPV));
562 // FIXME: The target might use more than one register for the type
563 // even in the scalar case.
564 RegUsage[ClassID] += 1;
565 } else {
566 // The output from scaled phis and scaled reductions actually has
567 // fewer lanes than the VF.
568 unsigned ScaleFactor =
569 vputils::getVFScaleFactor(VPV->getDefiningRecipe());
570 ElementCount VF = VFs[J];
571 if (ScaleFactor > 1) {
572 VF = VFs[J].divideCoefficientBy(ScaleFactor);
573 LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J]
574 << " to " << VF << " for " << *R << "\n";);
575 }
576
577 Type *ScalarTy = TypeInfo.inferScalarType(VPV);
578 unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
579 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
580 }
581 }
582
583 for (const auto &Pair : RegUsage) {
584 auto &Entry = MaxUsages[J][Pair.first];
585 Entry = std::max(Entry, Pair.second);
586 }
587 }
588
589 LLVM_DEBUG(dbgs() << "LV(REG): At #" << Idx << " Interval # "
590 << OpenIntervals.size() << '\n');
591
592 // Add used VPValues defined by the current recipe to the list of open
593 // intervals.
594 for (VPValue *DefV : R->definedValues())
595 if (Ends.contains(DefV))
596 OpenIntervals.insert(DefV);
597 }
598
599 // We also search for instructions that are defined outside the loop, but are
600 // used inside the loop. We need this number separately from the max-interval
601 // usage number because when we unroll, loop-invariant values do not take
602 // more register.
604 for (unsigned Idx = 0, End = VFs.size(); Idx < End; ++Idx) {
605 // Note that elements in this SmallMapVector will be default constructed
606 // as 0. So we can use "Invariant[ClassID] += n" in the code below even if
607 // there is no previous entry for ClassID.
609
610 for (auto *In : LoopInvariants) {
611 // FIXME: The target might use more than one register for the type
612 // even in the scalar case.
613 bool IsScalar = vputils::onlyScalarValuesUsed(In);
614
615 ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[Idx];
616 unsigned ClassID = TTI.getRegisterClassForType(
617 VF.isVector(), TypeInfo.inferScalarType(In));
618 Invariant[ClassID] += GetRegUsage(TypeInfo.inferScalarType(In), VF);
619 }
620
621 LLVM_DEBUG({
622 dbgs() << "LV(REG): VF = " << VFs[Idx] << '\n';
623 dbgs() << "LV(REG): Found max usage: " << MaxUsages[Idx].size()
624 << " item\n";
625 for (const auto &pair : MaxUsages[Idx]) {
626 dbgs() << "LV(REG): RegisterClass: "
627 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
628 << " registers\n";
629 }
630 dbgs() << "LV(REG): Found invariant usage: " << Invariant.size()
631 << " item\n";
632 for (const auto &pair : Invariant) {
633 dbgs() << "LV(REG): RegisterClass: "
634 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
635 << " registers\n";
636 }
637 });
638
639 RU.LoopInvariantRegs = Invariant;
640 RU.MaxLocalUsers = MaxUsages[Idx];
641 RUs[Idx] = RU;
642 }
643
644 return RUs;
645}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet & ToRemove
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define I(x, y, z)
Definition MD5.cpp:57
std::pair< uint64_t, uint64_t > Interval
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
#define LLVM_DEBUG(...)
Definition Debug.h:114
This pass exposes codegen information to IR-level passes.
This file implements the TypeSwitch template, which mimics a switch() statement whose cases are type ...
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
This file contains the declarations of different VPlan-related auxiliary helpers.
This file contains the declarations of the Vectorization Plan base classes:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Core dominator tree base class.
bool properlyDominates(const DomTreeNodeBase< VPBlockBase > *A, const DomTreeNodeBase< VPBlockBase > *B) const
constexpr bool isVector() const
One or more elements.
Definition TypeSize.h:324
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
bool isCast() const
bool isBinaryOp() const
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
bool isShift() const
bool isUnaryOp() const
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:318
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
size_type size() const
Definition SmallPtrSet.h:99
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
Remove pointer from the set.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:339
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionalit...
Definition TypeSwitch.h:88
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition TypeSwitch.h:97
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:280
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:300
A recipe for generating the active lane mask for the vector loop that is used to predicate the vector...
Definition VPlan.h:3605
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:3966
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4054
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2512
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:81
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:166
static auto blocksOnly(const T &Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:211
A recipe for generating conditional branches on the bits of a mask.
Definition VPlan.h:3016
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3547
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3716
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B)
A recipe for generating the phi node for the current index of elements, adjusted in accordance with E...
Definition VPlan.h:3637
Recipe to expand a SCEV expression.
Definition VPlan.h:3509
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
Definition VPlan.h:1256
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1036
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1127
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
Definition VPlan.h:1074
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1130
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
Definition VPlan.h:1071
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1121
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1066
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1063
@ CanonicalIVIncrementForPart
Definition VPlan.h:1056
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition VPlan.h:3203
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:387
A recipe for handling reduction phis.
Definition VPlan.h:2427
A recipe to represent inloop, ordered or partial reduction operations.
Definition VPlan.h:2779
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4154
const VPBlockBase * getEntry() const
Definition VPlan.h:4190
const VPBlockBase * getExiting() const
Definition VPlan.h:4202
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2935
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3786
An analysis for type-inference for VPValues.
LLVMContext & getContext()
Return the LLVMContext used by the analysis.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
VPTypeAnalysis(const VPlan &Plan)
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:207
operand_range operands()
Definition VPlanValue.h:275
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:48
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:1911
A recipe to compute the pointers for widened memory accesses of IndexTy.
Definition VPlan.h:1971
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1702
A Recipe for widening the canonical induction variable of the vector loop.
Definition VPlan.h:3679
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1552
A recipe for handling GEP instructions.
Definition VPlan.h:1848
A recipe for widening vector intrinsics.
Definition VPlan.h:1602
A common base class for widening memory operations.
Definition VPlan.h:3246
A recipe for widened phis.
Definition VPlan.h:2326
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1512
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4284
VPValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4468
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1011
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:175
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool match(Val *V, const Pattern &P)
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
VPInstruction_match< VPInstruction::ExtractLastPart, Op0_t > m_ExtractLastPart(const Op0_t &Op0)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
unsigned getVFScaleFactor(VPRecipeBase *R)
Get the VF scaling factor applied to the recipe's output, if the recipe has one.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< df_iterator< VPBlockDeepTraversalWrapper< VPBlockBase * > > > vp_depth_first_deep(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order while traversing t...
Definition VPlanCFG.h:243
SmallVector< VPRegisterUsage, 8 > calculateRegisterUsageForPlan(VPlan &Plan, ArrayRef< ElementCount > VFs, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &ValuesToIgnore)
Estimate the register usage for Plan and vectorization factors in VFs by calculating the highest numb...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1744
void collectEphemeralRecipesForVPlan(VPlan &Plan, DenseSet< VPRecipeBase * > &EphRecipes)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
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:1751
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
TargetTransformInfo TTI
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:276
A recipe for handling first-order recurrence phis.
Definition VPlan.h:2368
A struct that represents some properties of the register usage of a loop.
SmallMapVector< unsigned, unsigned, 4 > MaxLocalUsers
Holds the maximum number of concurrent live intervals in the loop.
bool exceedsMaxNumRegs(const TargetTransformInfo &TTI, unsigned OverrideMaxNumRegs=0) const
Check if any of the tracked live intervals exceeds the number of available registers for the target.
SmallMapVector< unsigned, unsigned, 4 > LoopInvariantRegs
Holds the number of loop invariant values that are used in the loop.
A recipe for widening select instructions.
Definition VPlan.h:1801