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"
15#include "llvm/ADT/TypeSwitch.h"
18#include "llvm/IR/Instruction.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "vplan"
24
26 if (auto LoopRegion = Plan.getVectorLoopRegion()) {
27 if (const auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(
28 &LoopRegion->getEntryBasicBlock()->front())) {
29 CanonicalIVTy = CanIV->getScalarType();
30 return;
31 }
32 }
33
34 // If there's no canonical IV, retrieve the type from the trip count
35 // expression.
36 auto *TC = Plan.getTripCount();
37 if (TC->isLiveIn()) {
38 CanonicalIVTy = TC->getLiveInIRValue()->getType();
39 return;
40 }
41 CanonicalIVTy = cast<VPExpandSCEVRecipe>(TC)->getSCEV()->getType();
42}
43
44Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
45 Type *ResTy = inferScalarType(R->getIncomingValue(0));
46 for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {
47 VPValue *Inc = R->getIncomingValue(I);
48 assert(inferScalarType(Inc) == ResTy &&
49 "different types inferred for different incoming values");
50 CachedTypes[Inc] = ResTy;
51 }
52 return ResTy;
53}
54
55Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
56 // Set the result type from the first operand, check if the types for all
57 // other operands match and cache them.
58 auto SetResultTyFromOp = [this, R]() {
59 Type *ResTy = inferScalarType(R->getOperand(0));
60 for (unsigned Op = 1; Op != R->getNumOperands(); ++Op) {
61 VPValue *OtherV = R->getOperand(Op);
62 assert(inferScalarType(OtherV) == ResTy &&
63 "different types inferred for different operands");
64 CachedTypes[OtherV] = ResTy;
65 }
66 return ResTy;
67 };
68
69 unsigned Opcode = R->getOpcode();
71 return SetResultTyFromOp();
72
73 switch (Opcode) {
74 case Instruction::ExtractElement:
75 case Instruction::Freeze:
78 return inferScalarType(R->getOperand(0));
79 case Instruction::Select: {
80 Type *ResTy = inferScalarType(R->getOperand(1));
81 VPValue *OtherV = R->getOperand(2);
82 assert(inferScalarType(OtherV) == ResTy &&
83 "different types inferred for different operands");
84 CachedTypes[OtherV] = ResTy;
85 return ResTy;
86 }
87 case Instruction::ICmp:
88 case Instruction::FCmp:
90 assert(inferScalarType(R->getOperand(0)) ==
91 inferScalarType(R->getOperand(1)) &&
92 "different types inferred for different operands");
93 return IntegerType::get(Ctx, 1);
95 return inferScalarType(R->getOperand(1));
98 return inferScalarType(R->getOperand(0));
99 }
101 return Type::getIntNTy(Ctx, 32);
102 case Instruction::PHI:
103 // Infer the type of first operand only, as other operands of header phi's
104 // may lead to infinite recursion.
105 return inferScalarType(R->getOperand(0));
114 return SetResultTyFromOp();
116 return inferScalarType(R->getOperand(1));
119 return Type::getIntNTy(Ctx, 64);
123 Type *BaseTy = inferScalarType(R->getOperand(0));
124 if (auto *VecTy = dyn_cast<VectorType>(BaseTy))
125 return VecTy->getElementType();
126 return BaseTy;
127 }
129 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1) &&
130 inferScalarType(R->getOperand(1))->isIntegerTy(1) &&
131 "LogicalAnd operands should be bool");
132 return IntegerType::get(Ctx, 1);
136 // Return the type based on first operand.
137 return inferScalarType(R->getOperand(0));
140 return Type::getVoidTy(Ctx);
141 default:
142 break;
143 }
144 // Type inference not implemented for opcode.
145 LLVM_DEBUG({
146 dbgs() << "LV: Found unhandled opcode for: ";
147 R->getVPSingleValue()->dump();
148 });
149 llvm_unreachable("Unhandled opcode!");
150}
151
152Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
153 unsigned Opcode = R->getOpcode();
154 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
156 Type *ResTy = inferScalarType(R->getOperand(0));
157 assert(ResTy == inferScalarType(R->getOperand(1)) &&
158 "types for both operands must match for binary op");
159 CachedTypes[R->getOperand(1)] = ResTy;
160 return ResTy;
161 }
162
163 switch (Opcode) {
164 case Instruction::ICmp:
165 case Instruction::FCmp:
166 return IntegerType::get(Ctx, 1);
167 case Instruction::FNeg:
168 case Instruction::Freeze:
169 return inferScalarType(R->getOperand(0));
170 case Instruction::ExtractValue: {
171 assert(R->getNumOperands() == 2 && "expected single level extractvalue");
172 auto *StructTy = cast<StructType>(inferScalarType(R->getOperand(0)));
173 auto *CI = cast<ConstantInt>(R->getOperand(1)->getLiveInIRValue());
174 return StructTy->getTypeAtIndex(CI->getZExtValue());
175 }
176 default:
177 break;
178 }
179
180 // Type inference not implemented for opcode.
181 LLVM_DEBUG({
182 dbgs() << "LV: Found unhandled opcode for: ";
183 R->getVPSingleValue()->dump();
184 });
185 llvm_unreachable("Unhandled opcode!");
186}
187
188Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenCallRecipe *R) {
189 auto &CI = *cast<CallInst>(R->getUnderlyingInstr());
190 return CI.getType();
191}
192
193Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R) {
195 "Store recipes should not define any values");
196 return cast<LoadInst>(&R->getIngredient())->getType();
197}
198
199Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenSelectRecipe *R) {
200 Type *ResTy = inferScalarType(R->getOperand(1));
201 VPValue *OtherV = R->getOperand(2);
202 assert(inferScalarType(OtherV) == ResTy &&
203 "different types inferred for different operands");
204 CachedTypes[OtherV] = ResTy;
205 return ResTy;
206}
207
208Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
209 unsigned Opcode = R->getUnderlyingInstr()->getOpcode();
210
211 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
213 Type *ResTy = inferScalarType(R->getOperand(0));
214 assert(ResTy == inferScalarType(R->getOperand(1)) &&
215 "inferred types for operands of binary op don't match");
216 CachedTypes[R->getOperand(1)] = ResTy;
217 return ResTy;
218 }
219
220 if (Instruction::isCast(Opcode))
221 return R->getUnderlyingInstr()->getType();
222
223 switch (Opcode) {
224 case Instruction::Call: {
225 unsigned CallIdx = R->getNumOperands() - (R->isPredicated() ? 2 : 1);
226 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
227 ->getReturnType();
228 }
229 case Instruction::Select: {
230 Type *ResTy = inferScalarType(R->getOperand(1));
231 assert(ResTy == inferScalarType(R->getOperand(2)) &&
232 "inferred types for operands of select op don't match");
233 CachedTypes[R->getOperand(2)] = ResTy;
234 return ResTy;
235 }
236 case Instruction::ICmp:
237 case Instruction::FCmp:
238 return IntegerType::get(Ctx, 1);
239 case Instruction::Alloca:
240 case Instruction::ExtractValue:
241 return R->getUnderlyingInstr()->getType();
242 case Instruction::Freeze:
243 case Instruction::FNeg:
244 case Instruction::GetElementPtr:
245 return inferScalarType(R->getOperand(0));
246 case Instruction::Load:
247 return cast<LoadInst>(R->getUnderlyingInstr())->getType();
248 case Instruction::Store:
249 // FIXME: VPReplicateRecipes with store opcodes still define a result
250 // VPValue, so we need to handle them here. Remove the code here once this
251 // is modeled accurately in VPlan.
252 return Type::getVoidTy(Ctx);
253 default:
254 break;
255 }
256 // Type inference not implemented for opcode.
257 LLVM_DEBUG({
258 dbgs() << "LV: Found unhandled opcode for: ";
259 R->getVPSingleValue()->dump();
260 });
261 llvm_unreachable("Unhandled opcode");
262}
263
265 if (Type *CachedTy = CachedTypes.lookup(V))
266 return CachedTy;
267
268 if (V->isLiveIn()) {
269 if (auto *IRValue = V->getLiveInIRValue())
270 return IRValue->getType();
271 // All VPValues without any underlying IR value (like the vector trip count
272 // or the backedge-taken count) have the same type as the canonical IV.
273 return CanonicalIVTy;
274 }
275
276 Type *ResultTy =
277 TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe())
281 [this](const auto *R) {
282 // Handle header phi recipes, except VPWidenIntOrFpInduction
283 // which needs special handling due it being possibly truncated.
284 // TODO: consider inferring/caching type of siblings, e.g.,
285 // backedge value, here and in cases below.
286 return inferScalarType(R->getStartValue());
287 })
288 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
289 [](const auto *R) { return R->getScalarType(); })
293 VPPartialReductionRecipe>([this](const VPRecipeBase *R) {
294 return inferScalarType(R->getOperand(0));
295 })
296 // VPInstructionWithType must be handled before VPInstruction.
299 [](const auto *R) { return R->getResultType(); })
302 [this](const auto *R) { return inferScalarTypeForRecipe(R); })
303 .Case<VPInterleaveBase>([V](const auto *R) {
304 // TODO: Use info from interleave group.
305 return V->getUnderlyingValue()->getType();
306 })
307 .Case<VPExpandSCEVRecipe>([](const VPExpandSCEVRecipe *R) {
308 return R->getSCEV()->getType();
309 })
310 .Case<VPReductionRecipe>([this](const auto *R) {
311 return inferScalarType(R->getChainOp());
312 })
313 .Case<VPExpressionRecipe>([this](const auto *R) {
314 return inferScalarType(R->getOperandOfResultType());
315 });
316
317 assert(ResultTy && "could not infer type for the given VPValue");
318 CachedTypes[V] = ResultTy;
319 return ResultTy;
320}
321
323 VPlan &Plan, DenseSet<VPRecipeBase *> &EphRecipes) {
324 // First, collect seed recipes which are operands of assumes.
328 for (VPRecipeBase &R : *VPBB) {
329 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
330 if (!RepR || !match(RepR->getUnderlyingInstr(),
332 continue;
333 Worklist.push_back(RepR);
334 EphRecipes.insert(RepR);
335 }
336 }
337
338 // Process operands of candidates in worklist and add them to the set of
339 // ephemeral recipes, if they don't have side-effects and are only used by
340 // other ephemeral recipes.
341 while (!Worklist.empty()) {
342 VPRecipeBase *Cur = Worklist.pop_back_val();
343 for (VPValue *Op : Cur->operands()) {
344 auto *OpR = Op->getDefiningRecipe();
345 if (!OpR || OpR->mayHaveSideEffects() || EphRecipes.contains(OpR))
346 continue;
347 if (any_of(Op->users(), [EphRecipes](VPUser *U) {
348 auto *UR = dyn_cast<VPRecipeBase>(U);
349 return !UR || !EphRecipes.contains(UR);
350 }))
351 continue;
352 EphRecipes.insert(OpR);
353 Worklist.push_back(OpR);
354 }
355 }
356}
357
360
362 const VPRecipeBase *B) {
363 if (A == B)
364 return false;
365
366 auto LocalComesBefore = [](const VPRecipeBase *A, const VPRecipeBase *B) {
367 for (auto &R : *A->getParent()) {
368 if (&R == A)
369 return true;
370 if (&R == B)
371 return false;
372 }
373 llvm_unreachable("recipe not found");
374 };
375 const VPBlockBase *ParentA = A->getParent();
376 const VPBlockBase *ParentB = B->getParent();
377 if (ParentA == ParentB)
378 return LocalComesBefore(A, B);
379
380#ifndef NDEBUG
381 auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * {
382 VPRegionBlock *Region = R->getRegion();
383 if (Region && Region->isReplicator()) {
384 assert(Region->getNumSuccessors() == 1 &&
385 Region->getNumPredecessors() == 1 && "Expected SESE region!");
386 assert(R->getParent()->size() == 1 &&
387 "A recipe in an original replicator region must be the only "
388 "recipe in its block");
389 return Region;
390 }
391 return nullptr;
392 };
393 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(A)) &&
394 "No replicate regions expected at this point");
395 assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(B)) &&
396 "No replicate regions expected at this point");
397#endif
398 return Base::properlyDominates(ParentA, ParentB);
399}
400
402 unsigned OverrideMaxNumRegs) const {
403 return any_of(MaxLocalUsers, [&TTI, &OverrideMaxNumRegs](auto &LU) {
404 return LU.second > (OverrideMaxNumRegs > 0
405 ? OverrideMaxNumRegs
406 : TTI.getNumberOfRegisters(LU.first));
407 });
408}
409
412 const SmallPtrSetImpl<const Value *> &ValuesToIgnore) {
413 // Each 'key' in the map opens a new interval. The values
414 // of the map are the index of the 'last seen' usage of the
415 // VPValue that is the key.
417
418 // Maps indices to recipes.
420 // Marks the end of each interval.
421 IntervalMap EndPoint;
422 // Saves the list of VPValues that are used in the loop.
424 // Saves the list of values that are used in the loop but are defined outside
425 // the loop (not including non-recipe values such as arguments and
426 // constants).
427 SmallSetVector<VPValue *, 8> LoopInvariants;
428 LoopInvariants.insert(&Plan.getVectorTripCount());
429
430 // We scan the loop in a topological order in order and assign a number to
431 // each recipe. We use RPO to ensure that defs are met before their users. We
432 // assume that each recipe that has in-loop users starts an interval. We
433 // record every time that an in-loop value is used, so we have a list of the
434 // first occurences of each recipe and last occurrence of each VPValue.
435 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
437 LoopRegion);
439 if (!VPBB->getParent())
440 break;
441 for (VPRecipeBase &R : *VPBB) {
442 Idx2Recipe.push_back(&R);
443
444 // Save the end location of each USE.
445 for (VPValue *U : R.operands()) {
446 auto *DefR = U->getDefiningRecipe();
447
448 // Ignore non-recipe values such as arguments, constants, etc.
449 // FIXME: Might need some motivation why these values are ignored. If
450 // for example an argument is used inside the loop it will increase the
451 // register pressure (so shouldn't we add it to LoopInvariants).
452 if (!DefR && (!U->getLiveInIRValue() ||
453 !isa<Instruction>(U->getLiveInIRValue())))
454 continue;
455
456 // If this recipe is outside the loop then record it and continue.
457 if (!DefR) {
458 LoopInvariants.insert(U);
459 continue;
460 }
461
462 // Overwrite previous end points.
463 EndPoint[U] = Idx2Recipe.size();
464 Ends.insert(U);
465 }
466 }
467 if (VPBB == LoopRegion->getExiting()) {
468 // VPWidenIntOrFpInductionRecipes are used implicitly at the end of the
469 // exiting block, where their increment will get materialized eventually.
470 for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
471 if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
472 EndPoint[WideIV] = Idx2Recipe.size();
473 Ends.insert(WideIV);
474 }
475 }
476 }
477 }
478
479 // Saves the list of intervals that end with the index in 'key'.
480 using VPValueList = SmallVector<VPValue *, 2>;
482
483 // Next, we transpose the EndPoints into a multi map that holds the list of
484 // intervals that *end* at a specific location.
485 for (auto &Interval : EndPoint)
486 TransposeEnds[Interval.second].push_back(Interval.first);
487
488 SmallPtrSet<VPValue *, 8> OpenIntervals;
491
492 LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
493
494 VPTypeAnalysis TypeInfo(Plan);
495
496 const auto &TTICapture = TTI;
497 auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> unsigned {
498 if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty) ||
499 (VF.isScalable() &&
500 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
501 return 0;
502 return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
503 };
504
505 // We scan the instructions linearly and record each time that a new interval
506 // starts, by placing it in a set. If we find this value in TransposEnds then
507 // we remove it from the set. The max register usage is the maximum register
508 // usage of the recipes of the set.
509 for (unsigned int Idx = 0, Sz = Idx2Recipe.size(); Idx < Sz; ++Idx) {
510 VPRecipeBase *R = Idx2Recipe[Idx];
511
512 // Remove all of the VPValues that end at this location.
513 VPValueList &List = TransposeEnds[Idx];
514 for (VPValue *ToRemove : List)
515 OpenIntervals.erase(ToRemove);
516
517 // Ignore recipes that are never used within the loop and do not have side
518 // effects.
519 if (none_of(R->definedValues(),
520 [&Ends](VPValue *Def) { return Ends.count(Def); }) &&
521 !R->mayHaveSideEffects())
522 continue;
523
524 // Skip recipes for ignored values.
525 // TODO: Should mark recipes for ephemeral values that cannot be removed
526 // explictly in VPlan.
527 if (isa<VPSingleDefRecipe>(R) &&
528 ValuesToIgnore.contains(
529 cast<VPSingleDefRecipe>(R)->getUnderlyingValue()))
530 continue;
531
532 // For each VF find the maximum usage of registers.
533 for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
534 // Count the number of registers used, per register class, given all open
535 // intervals.
536 // Note that elements in this SmallMapVector will be default constructed
537 // as 0. So we can use "RegUsage[ClassID] += n" in the code below even if
538 // there is no previous entry for ClassID.
540
541 for (auto *VPV : OpenIntervals) {
542 // Skip values that weren't present in the original loop.
543 // TODO: Remove after removing the legacy
544 // LoopVectorizationCostModel::calculateRegisterUsage
547 continue;
548
549 if (VFs[J].isScalar() ||
554 (cast<VPReductionPHIRecipe>(VPV))->isInLoop())) {
555 unsigned ClassID =
556 TTI.getRegisterClassForType(false, TypeInfo.inferScalarType(VPV));
557 // FIXME: The target might use more than one register for the type
558 // even in the scalar case.
559 RegUsage[ClassID] += 1;
560 } else {
561 // The output from scaled phis and scaled reductions actually has
562 // fewer lanes than the VF.
563 unsigned ScaleFactor =
564 vputils::getVFScaleFactor(VPV->getDefiningRecipe());
565 ElementCount VF = VFs[J].divideCoefficientBy(ScaleFactor);
566 LLVM_DEBUG(if (VF != VFs[J]) {
567 dbgs() << "LV(REG): Scaled down VF from " << VFs[J] << " to " << VF
568 << " for " << *R << "\n";
569 });
570
571 Type *ScalarTy = TypeInfo.inferScalarType(VPV);
572 unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
573 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
574 }
575 }
576
577 for (const auto &Pair : RegUsage) {
578 auto &Entry = MaxUsages[J][Pair.first];
579 Entry = std::max(Entry, Pair.second);
580 }
581 }
582
583 LLVM_DEBUG(dbgs() << "LV(REG): At #" << Idx << " Interval # "
584 << OpenIntervals.size() << '\n');
585
586 // Add used VPValues defined by the current recipe to the list of open
587 // intervals.
588 for (VPValue *DefV : R->definedValues())
589 if (Ends.contains(DefV))
590 OpenIntervals.insert(DefV);
591 }
592
593 // We also search for instructions that are defined outside the loop, but are
594 // used inside the loop. We need this number separately from the max-interval
595 // usage number because when we unroll, loop-invariant values do not take
596 // more register.
598 for (unsigned Idx = 0, End = VFs.size(); Idx < End; ++Idx) {
599 // Note that elements in this SmallMapVector will be default constructed
600 // as 0. So we can use "Invariant[ClassID] += n" in the code below even if
601 // there is no previous entry for ClassID.
603
604 for (auto *In : LoopInvariants) {
605 // FIXME: The target might use more than one register for the type
606 // even in the scalar case.
607 bool IsScalar = vputils::onlyScalarValuesUsed(In);
608
609 ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[Idx];
610 unsigned ClassID = TTI.getRegisterClassForType(
611 VF.isVector(), TypeInfo.inferScalarType(In));
612 Invariant[ClassID] += GetRegUsage(TypeInfo.inferScalarType(In), VF);
613 }
614
615 LLVM_DEBUG({
616 dbgs() << "LV(REG): VF = " << VFs[Idx] << '\n';
617 dbgs() << "LV(REG): Found max usage: " << MaxUsages[Idx].size()
618 << " item\n";
619 for (const auto &pair : MaxUsages[Idx]) {
620 dbgs() << "LV(REG): RegisterClass: "
621 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
622 << " registers\n";
623 }
624 dbgs() << "LV(REG): Found invariant usage: " << Invariant.size()
625 << " item\n";
626 for (const auto &pair : Invariant) {
627 dbgs() << "LV(REG): RegisterClass: "
628 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
629 << " registers\n";
630 }
631 });
632
633 RU.LoopInvariantRegs = Invariant;
634 RU.MaxLocalUsers = MaxUsages[Idx];
635 RUs[Idx] = RU;
636 }
637
638 return RUs;
639}
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:149
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:337
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:3544
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:3831
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:3919
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2419
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:80
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:189
A recipe for generating conditional branches on the bits of a mask.
Definition VPlan.h:2963
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3487
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3652
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:3575
Recipe to expand a SCEV expression.
Definition VPlan.h:3450
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
Definition VPlan.h:1200
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:981
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1072
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
Definition VPlan.h:1019
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1075
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
Definition VPlan.h:1016
@ FirstOrderRecurrenceSplice
Definition VPlan.h:987
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1066
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1011
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1008
@ CanonicalIVIncrementForPart
Definition VPlan.h:1001
@ CalculateTripCountMinusVF
Definition VPlan.h:999
A recipe for forming partial reductions.
Definition VPlan.h:2779
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition VPlan.h:3149
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:386
A recipe for handling reduction phis.
Definition VPlan.h:2347
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition VPlan.h:2682
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4019
const VPBlockBase * getEntry() const
Definition VPlan.h:4055
const VPBlockBase * getExiting() const
Definition VPlan.h:4067
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2885
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3721
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:1858
A recipe to compute the pointers for widened memory accesses of IndexTy.
Definition VPlan.h:1917
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1648
A Recipe for widening the canonical induction variable of the vector loop.
Definition VPlan.h:3616
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1501
A recipe for handling GEP instructions.
Definition VPlan.h:1786
A recipe for widening vector intrinsics.
Definition VPlan.h:1559
A common base class for widening memory operations.
Definition VPlan.h:3191
A recipe for widened phis.
Definition VPlan.h:2270
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1458
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4149
VPValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4334
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1012
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))
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:1732
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:1739
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:257
A recipe for handling first-order recurrence phis.
Definition VPlan.h:2312
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:1744