LLVM 23.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 : Ctx(Plan.getContext()), DL(Plan.getDataLayout()) {
29 if (auto LoopRegion = Plan.getVectorLoopRegion()) {
30 if (const auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(
31 &LoopRegion->getEntryBasicBlock()->front())) {
32 CanonicalIVTy = CanIV->getScalarType();
33 return;
34 }
35 }
36
37 // If there's no canonical IV, retrieve the type from the trip count
38 // expression.
39 auto *TC = Plan.getTripCount();
40 if (auto *TCIRV = dyn_cast<VPIRValue>(TC)) {
41 CanonicalIVTy = TCIRV->getType();
42 return;
43 }
44 CanonicalIVTy = cast<VPExpandSCEVRecipe>(TC)->getSCEV()->getType();
45}
46
47Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
48 Type *ResTy = inferScalarType(R->getIncomingValue(0));
49 for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {
50 VPValue *Inc = R->getIncomingValue(I);
51 assert(inferScalarType(Inc) == ResTy &&
52 "different types inferred for different incoming values");
53 CachedTypes[Inc] = ResTy;
54 }
55 return ResTy;
56}
57
58Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
59 // Set the result type from the first operand, check if the types for all
60 // other operands match and cache them.
61 auto SetResultTyFromOp = [this, R]() {
62 Type *ResTy = inferScalarType(R->getOperand(0));
63 unsigned NumOperands = R->getNumOperandsWithoutMask();
64 for (unsigned Op = 1; Op != NumOperands; ++Op) {
65 VPValue *OtherV = R->getOperand(Op);
66 assert(inferScalarType(OtherV) == ResTy &&
67 "different types inferred for different operands");
68 CachedTypes[OtherV] = ResTy;
69 }
70 return ResTy;
71 };
72
73 unsigned Opcode = R->getOpcode();
75 return SetResultTyFromOp();
76
77 switch (Opcode) {
78 case Instruction::ExtractElement:
79 case Instruction::Freeze:
80 case Instruction::PHI:
93 return inferScalarType(R->getOperand(0));
94 case Instruction::Select: {
95 Type *ResTy = inferScalarType(R->getOperand(1));
96 VPValue *OtherV = R->getOperand(2);
97 assert(inferScalarType(OtherV) == ResTy &&
98 "different types inferred for different operands");
99 CachedTypes[OtherV] = ResTy;
100 return ResTy;
101 }
102 case Instruction::ICmp:
103 case Instruction::FCmp:
105 assert(inferScalarType(R->getOperand(0)) ==
106 inferScalarType(R->getOperand(1)) &&
107 "different types inferred for different operands");
108 return IntegerType::get(Ctx, 1);
110 return inferScalarType(R->getOperand(1));
112 return Type::getIntNTy(Ctx, 32);
121 return SetResultTyFromOp();
123 return inferScalarType(R->getOperand(1));
126 // Assume that the maximum possible number of elements in a vector fits
127 // within the index type for the default address space.
128 return DL.getIndexType(Ctx, 0);
131 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1) &&
132 inferScalarType(R->getOperand(1))->isIntegerTy(1) &&
133 "LogicalAnd/Or operands should be bool");
134 return IntegerType::get(Ctx, 1);
136 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1));
137 return IntegerType::get(Ctx, 1);
141 case Instruction::Store:
142 return Type::getVoidTy(Ctx);
143 case Instruction::Load:
144 return cast<LoadInst>(R->getUnderlyingValue())->getType();
145 case Instruction::Alloca:
146 return cast<AllocaInst>(R->getUnderlyingValue())->getType();
147 case Instruction::Call: {
148 unsigned CallIdx = R->getNumOperandsWithoutMask() - 1;
149 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
150 ->getReturnType();
151 }
152 case Instruction::GetElementPtr:
153 return inferScalarType(R->getOperand(0));
154 case Instruction::ExtractValue:
155 return cast<ExtractValueInst>(R->getUnderlyingValue())->getType();
156 default:
157 break;
158 }
159 // Type inference not implemented for opcode.
160 LLVM_DEBUG({
161 dbgs() << "LV: Found unhandled opcode for: ";
162 R->getVPSingleValue()->dump();
163 });
164 llvm_unreachable("Unhandled opcode!");
165}
166
167Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
168 unsigned Opcode = R->getOpcode();
169 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
171 Type *ResTy = inferScalarType(R->getOperand(0));
172 assert(ResTy == inferScalarType(R->getOperand(1)) &&
173 "types for both operands must match for binary op");
174 CachedTypes[R->getOperand(1)] = ResTy;
175 return ResTy;
176 }
177
178 switch (Opcode) {
179 case Instruction::ICmp:
180 case Instruction::FCmp:
181 return IntegerType::get(Ctx, 1);
182 case Instruction::FNeg:
183 case Instruction::Freeze:
184 return inferScalarType(R->getOperand(0));
185 case Instruction::ExtractValue: {
186 assert(R->getNumOperands() == 2 && "expected single level extractvalue");
187 auto *StructTy = cast<StructType>(inferScalarType(R->getOperand(0)));
188 return StructTy->getTypeAtIndex(
189 cast<VPConstantInt>(R->getOperand(1))->getZExtValue());
190 }
191 case Instruction::Select: {
192 Type *ResTy = inferScalarType(R->getOperand(1));
193 VPValue *OtherV = R->getOperand(2);
194 assert(inferScalarType(OtherV) == ResTy &&
195 "different types inferred for different operands");
196 CachedTypes[OtherV] = ResTy;
197 return ResTy;
198 }
199 default:
200 break;
201 }
202
203 // Type inference not implemented for opcode.
204 LLVM_DEBUG({
205 dbgs() << "LV: Found unhandled opcode for: ";
206 R->getVPSingleValue()->dump();
207 });
208 llvm_unreachable("Unhandled opcode!");
209}
210
211Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenCallRecipe *R) {
212 auto &CI = *cast<CallInst>(R->getUnderlyingInstr());
213 return CI.getType();
214}
215
216Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R) {
218 "Store recipes should not define any values");
219 return cast<LoadInst>(&R->getIngredient())->getType();
220}
221
222Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
223 unsigned Opcode = R->getUnderlyingInstr()->getOpcode();
224
225 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
227 Type *ResTy = inferScalarType(R->getOperand(0));
228 assert(ResTy == inferScalarType(R->getOperand(1)) &&
229 "inferred types for operands of binary op don't match");
230 CachedTypes[R->getOperand(1)] = ResTy;
231 return ResTy;
232 }
233
234 if (Instruction::isCast(Opcode))
235 return R->getUnderlyingInstr()->getType();
236
237 switch (Opcode) {
238 case Instruction::Call: {
239 unsigned CallIdx = R->getNumOperands() - (R->isPredicated() ? 2 : 1);
240 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
241 ->getReturnType();
242 }
243 case Instruction::Select: {
244 Type *ResTy = inferScalarType(R->getOperand(1));
245 assert(ResTy == inferScalarType(R->getOperand(2)) &&
246 "inferred types for operands of select op don't match");
247 CachedTypes[R->getOperand(2)] = ResTy;
248 return ResTy;
249 }
250 case Instruction::ICmp:
251 case Instruction::FCmp:
252 return IntegerType::get(Ctx, 1);
253 case Instruction::Alloca:
254 case Instruction::ExtractValue:
255 return R->getUnderlyingInstr()->getType();
256 case Instruction::Freeze:
257 case Instruction::FNeg:
258 case Instruction::GetElementPtr:
259 return inferScalarType(R->getOperand(0));
260 case Instruction::Load:
261 return cast<LoadInst>(R->getUnderlyingInstr())->getType();
262 case Instruction::Store:
263 // FIXME: VPReplicateRecipes with store opcodes still define a result
264 // VPValue, so we need to handle them here. Remove the code here once this
265 // is modeled accurately in VPlan.
266 return Type::getVoidTy(Ctx);
267 default:
268 break;
269 }
270 // Type inference not implemented for opcode.
271 LLVM_DEBUG({
272 dbgs() << "LV: Found unhandled opcode for: ";
273 R->getVPSingleValue()->dump();
274 });
275 llvm_unreachable("Unhandled opcode");
276}
277
279 if (Type *CachedTy = CachedTypes.lookup(V))
280 return CachedTy;
281
282 if (auto *IRV = dyn_cast<VPIRValue>(V))
283 return IRV->getType();
284
285 if (isa<VPSymbolicValue>(V)) {
286 // All VPValues without any underlying IR value (like the vector trip count
287 // or the backedge-taken count) have the same type as the canonical IV.
288 return CanonicalIVTy;
289 }
290
291 Type *ResultTy =
292 TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe())
296 [this](const auto *R) {
297 // Handle header phi recipes, except VPWidenIntOrFpInduction
298 // which needs special handling due it being possibly truncated.
299 // TODO: consider inferring/caching type of siblings, e.g.,
300 // backedge value, here and in cases below.
301 return inferScalarType(R->getStartValue());
302 })
303 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
304 [](const auto *R) { return R->getScalarType(); })
308 [this](const VPRecipeBase *R) {
309 return inferScalarType(R->getOperand(0));
310 })
311 // VPInstructionWithType must be handled before VPInstruction.
314 [](const auto *R) { return R->getResultType(); })
317 [this](const auto *R) { return inferScalarTypeForRecipe(R); })
318 .Case([V](const VPInterleaveBase *R) {
319 // TODO: Use info from interleave group.
320 return V->getUnderlyingValue()->getType();
321 })
322 .Case([](const VPExpandSCEVRecipe *R) {
323 return R->getSCEV()->getType();
324 })
325 .Case([this](const VPReductionRecipe *R) {
326 return inferScalarType(R->getChainOp());
327 })
328 .Case([this](const VPExpressionRecipe *R) {
329 return inferScalarType(R->getOperandOfResultType());
330 });
331
332 assert(ResultTy && "could not infer type for the given VPValue");
333 CachedTypes[V] = ResultTy;
334 return ResultTy;
335}
336
338 VPlan &Plan, DenseSet<VPRecipeBase *> &EphRecipes) {
339 // First, collect seed recipes which are operands of assumes.
343 for (VPRecipeBase &R : *VPBB) {
344 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
345 if (!RepR || !match(RepR, m_Intrinsic<Intrinsic::assume>()))
346 continue;
347 Worklist.push_back(RepR);
348 EphRecipes.insert(RepR);
349 }
350 }
351
352 // Process operands of candidates in worklist and add them to the set of
353 // ephemeral recipes, if they don't have side-effects and are only used by
354 // other ephemeral recipes.
355 while (!Worklist.empty()) {
356 VPRecipeBase *Cur = Worklist.pop_back_val();
357 for (VPValue *Op : Cur->operands()) {
358 auto *OpR = Op->getDefiningRecipe();
359 if (!OpR || OpR->mayHaveSideEffects() || EphRecipes.contains(OpR))
360 continue;
361 if (any_of(Op->users(), [EphRecipes](VPUser *U) {
362 auto *UR = dyn_cast<VPRecipeBase>(U);
363 return !UR || !EphRecipes.contains(UR);
364 }))
365 continue;
366 EphRecipes.insert(OpR);
367 Worklist.push_back(OpR);
368 }
369 }
370}
371
374
376 const VPRecipeBase *B) {
377 if (A == B)
378 return false;
379
380 auto LocalComesBefore = [](const VPRecipeBase *A, const VPRecipeBase *B) {
381 for (auto &R : *A->getParent()) {
382 if (&R == A)
383 return true;
384 if (&R == B)
385 return false;
386 }
387 llvm_unreachable("recipe not found");
388 };
389 const VPBlockBase *ParentA = A->getParent();
390 const VPBlockBase *ParentB = B->getParent();
391 if (ParentA == ParentB)
392 return LocalComesBefore(A, B);
393
394 return Base::properlyDominates(ParentA, ParentB);
395}
396
398 unsigned OverrideMaxNumRegs) const {
400 for (const auto &[RegClass, MaxUsers] : MaxLocalUsers) {
401 unsigned AvailableRegs = OverrideMaxNumRegs > 0
402 ? OverrideMaxNumRegs
403 : Ctx.TTI.getNumberOfRegisters(RegClass);
404 if (MaxUsers > AvailableRegs) {
405 // Assume that for each register used past what's available we get one
406 // spill and reload.
407 unsigned Spills = MaxUsers - AvailableRegs;
408 InstructionCost SpillCost =
409 Ctx.TTI.getRegisterClassSpillCost(RegClass, Ctx.CostKind) +
410 Ctx.TTI.getRegisterClassReloadCost(RegClass, Ctx.CostKind);
411 InstructionCost TotalCost = Spills * SpillCost;
412 LLVM_DEBUG(dbgs() << "LV(REG): Cost of " << TotalCost << " from "
413 << Spills << " spills of "
414 << Ctx.TTI.getRegisterClassName(RegClass) << "\n");
415 Cost += TotalCost;
416 }
417 }
418 return Cost;
419}
420
423 const SmallPtrSetImpl<const Value *> &ValuesToIgnore) {
424 // Each 'key' in the map opens a new interval. The values
425 // of the map are the index of the 'last seen' usage of the
426 // VPValue that is the key.
428
429 // Maps indices to recipes.
431 // Marks the end of each interval.
432 IntervalMap EndPoint;
433 // Saves the list of VPValues that are used in the loop.
435 // Saves the list of values that are used in the loop but are defined outside
436 // the loop (not including non-recipe values such as arguments and
437 // constants).
438 SmallSetVector<VPValue *, 8> LoopInvariants;
439 if (Plan.getVectorTripCount().getNumUsers() > 0)
440 LoopInvariants.insert(&Plan.getVectorTripCount());
441
442 // We scan the loop in a topological order in order and assign a number to
443 // each recipe. We use RPO to ensure that defs are met before their users. We
444 // assume that each recipe that has in-loop users starts an interval. We
445 // record every time that an in-loop value is used, so we have a list of the
446 // first occurences of each recipe and last occurrence of each VPValue.
447 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
449 LoopRegion);
451 if (!VPBB->getParent())
452 break;
453 for (VPRecipeBase &R : *VPBB) {
454 Idx2Recipe.push_back(&R);
455
456 // Save the end location of each USE.
457 for (VPValue *U : R.operands()) {
458 if (isa<VPRecipeValue>(U)) {
459 // Overwrite previous end points.
460 EndPoint[U] = Idx2Recipe.size();
461 Ends.insert(U);
462 } else if (auto *IRV = dyn_cast<VPIRValue>(U)) {
463 // Ignore non-recipe values such as arguments, constants, etc.
464 // FIXME: Might need some motivation why these values are ignored. If
465 // for example an argument is used inside the loop it will increase
466 // the register pressure (so shouldn't we add it to LoopInvariants).
467 if (!isa<Instruction>(IRV->getValue()))
468 continue;
469 // This recipe is outside the loop, record it and continue.
470 LoopInvariants.insert(U);
471 }
472 // Other types of VPValue are currently not tracked.
473 }
474 }
475 if (VPBB == LoopRegion->getExiting()) {
476 // VPWidenIntOrFpInductionRecipes are used implicitly at the end of the
477 // exiting block, where their increment will get materialized eventually.
478 for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
479 if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
480 EndPoint[WideIV] = Idx2Recipe.size();
481 Ends.insert(WideIV);
482 }
483 }
484 }
485 }
486
487 // Saves the list of intervals that end with the index in 'key'.
488 using VPValueList = SmallVector<VPValue *, 2>;
490
491 // Next, we transpose the EndPoints into a multi map that holds the list of
492 // intervals that *end* at a specific location.
493 for (auto &Interval : EndPoint)
494 TransposeEnds[Interval.second].push_back(Interval.first);
495
496 SmallPtrSet<VPValue *, 8> OpenIntervals;
499
500 LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
501
502 VPTypeAnalysis TypeInfo(Plan);
503
504 const auto &TTICapture = TTI;
505 auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> unsigned {
506 if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty) ||
507 (VF.isScalable() &&
508 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
509 return 0;
510 return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
511 };
512
513 // We scan the instructions linearly and record each time that a new interval
514 // starts, by placing it in a set. If we find this value in TransposEnds then
515 // we remove it from the set. The max register usage is the maximum register
516 // usage of the recipes of the set.
517 for (unsigned int Idx = 0, Sz = Idx2Recipe.size(); Idx < Sz; ++Idx) {
518 VPRecipeBase *R = Idx2Recipe[Idx];
519
520 // Remove all of the VPValues that end at this location.
521 VPValueList &List = TransposeEnds[Idx];
522 for (VPValue *ToRemove : List)
523 OpenIntervals.erase(ToRemove);
524
525 // Ignore recipes that are never used within the loop and do not have side
526 // effects.
527 if (none_of(R->definedValues(),
528 [&Ends](VPValue *Def) { return Ends.count(Def); }) &&
529 !R->mayHaveSideEffects())
530 continue;
531
532 // Skip recipes for ignored values.
533 // TODO: Should mark recipes for ephemeral values that cannot be removed
534 // explictly in VPlan.
535 if (isa<VPSingleDefRecipe>(R) &&
536 ValuesToIgnore.contains(
537 cast<VPSingleDefRecipe>(R)->getUnderlyingValue()))
538 continue;
539
540 // For each VF find the maximum usage of registers.
541 for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
542 // Count the number of registers used, per register class, given all open
543 // intervals.
544 // Note that elements in this SmallMapVector will be default constructed
545 // as 0. So we can use "RegUsage[ClassID] += n" in the code below even if
546 // there is no previous entry for ClassID.
548
549 for (auto *VPV : OpenIntervals) {
550 // Skip artificial values or values that weren't present in the original
551 // loop.
552 // TODO: Remove skipping values that weren't present in the original
553 // loop after removing the legacy
554 // LoopVectorizationCostModel::calculateRegisterUsage
556 VPBranchOnMaskRecipe>(VPV) ||
558 continue;
559
560 if (VFs[J].isScalar() ||
565 (cast<VPReductionPHIRecipe>(VPV))->isInLoop())) {
566 unsigned ClassID =
567 TTI.getRegisterClassForType(false, TypeInfo.inferScalarType(VPV));
568 // FIXME: The target might use more than one register for the type
569 // even in the scalar case.
570 RegUsage[ClassID] += 1;
571 } else {
572 // The output from scaled phis and scaled reductions actually has
573 // fewer lanes than the VF.
574 unsigned ScaleFactor =
575 vputils::getVFScaleFactor(VPV->getDefiningRecipe());
576 ElementCount VF = VFs[J];
577 if (ScaleFactor > 1) {
578 VF = VFs[J].divideCoefficientBy(ScaleFactor);
579 LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J]
580 << " to " << VF << " for " << *R << "\n";);
581 }
582
583 Type *ScalarTy = TypeInfo.inferScalarType(VPV);
584 unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
585 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
586 }
587 }
588
589 for (const auto &Pair : RegUsage) {
590 auto &Entry = MaxUsages[J][Pair.first];
591 Entry = std::max(Entry, Pair.second);
592 }
593 }
594
595 LLVM_DEBUG(dbgs() << "LV(REG): At #" << Idx << " Interval # "
596 << OpenIntervals.size() << '\n');
597
598 // Add used VPValues defined by the current recipe to the list of open
599 // intervals.
600 for (VPValue *DefV : R->definedValues())
601 if (Ends.contains(DefV))
602 OpenIntervals.insert(DefV);
603 }
604
605 // We also search for instructions that are defined outside the loop, but are
606 // used inside the loop. We need this number separately from the max-interval
607 // usage number because when we unroll, loop-invariant values do not take
608 // more register.
610 for (unsigned Idx = 0, End = VFs.size(); Idx < End; ++Idx) {
611 // Note that elements in this SmallMapVector will be default constructed
612 // as 0. So we can use "Invariant[ClassID] += n" in the code below even if
613 // there is no previous entry for ClassID.
615
616 for (auto *In : LoopInvariants) {
617 // FIXME: The target might use more than one register for the type
618 // even in the scalar case.
619 bool IsScalar = vputils::onlyScalarValuesUsed(In);
620
621 ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[Idx];
622 unsigned ClassID = TTI.getRegisterClassForType(
623 VF.isVector(), TypeInfo.inferScalarType(In));
624 Invariant[ClassID] += GetRegUsage(TypeInfo.inferScalarType(In), VF);
625 }
626
627 LLVM_DEBUG({
628 dbgs() << "LV(REG): VF = " << VFs[Idx] << '\n';
629 dbgs() << "LV(REG): Found max usage: " << MaxUsages[Idx].size()
630 << " item\n";
631 for (const auto &pair : MaxUsages[Idx]) {
632 dbgs() << "LV(REG): RegisterClass: "
633 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
634 << " registers\n";
635 }
636 dbgs() << "LV(REG): Found invariant usage: " << Invariant.size()
637 << " item\n";
638 for (const auto &pair : Invariant) {
639 dbgs() << "LV(REG): RegisterClass: "
640 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
641 << " registers\n";
642 }
643 });
644
645 RU.LoopInvariantRegs = Invariant;
646 RU.MaxLocalUsers = MaxUsages[Idx];
647 RUs[Idx] = RU;
648 }
649
650 return RUs;
651}
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:354
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:89
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition TypeSwitch.h:98
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:286
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:317
A recipe for generating the active lane mask for the vector loop that is used to predicate the vector...
Definition VPlan.h:3889
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4253
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4341
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2794
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:98
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:182
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:272
A recipe for generating conditional branches on the bits of a mask.
Definition VPlan.h:3298
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3831
A recipe for generating the phi node tracking the current scalar iteration index.
Definition VPlan.h:3921
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:4001
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B)
Recipe to expand a SCEV expression.
Definition VPlan.h:3793
A recipe to combine multiple recipes into a single 'expression' recipe, which should be considered a ...
Definition VPlan.h:3343
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
Definition VPlan.h:1519
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1225
@ ExtractLastActive
Extracts the last active lane from a set of vectors.
Definition VPlan.h:1336
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1327
@ ExitingIVValue
Compute the exiting value of a wide induction after vectorization, that is the value of the last lane...
Definition VPlan.h:1343
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
Definition VPlan.h:1272
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1330
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
Definition VPlan.h:1269
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1321
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1264
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1261
@ CanonicalIVIncrementForPart
Definition VPlan.h:1245
A common base class for interleaved memory operations.
Definition VPlan.h:2873
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition VPlan.h:3485
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:406
A recipe for handling reduction phis.
Definition VPlan.h:2700
A recipe to represent inloop, ordered or partial reduction operations.
Definition VPlan.h:3063
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4441
const VPBlockBase * getEntry() const
Definition VPlan.h:4477
const VPBlockBase * getExiting() const
Definition VPlan.h:4489
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3217
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:4073
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:296
operand_range operands()
Definition VPlanValue.h:364
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:46
unsigned getNumUsers() const
Definition VPlanValue.h:107
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:2154
A recipe to compute the pointers for widened memory accesses of SourceElementTy.
Definition VPlan.h:2227
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1992
A Recipe for widening the canonical induction variable of the vector loop.
Definition VPlan.h:3964
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1840
A recipe for handling GEP instructions.
Definition VPlan.h:2090
A recipe for widening vector intrinsics.
Definition VPlan.h:1892
A common base class for widening memory operations.
Definition VPlan.h:3528
A recipe for widened phis.
Definition VPlan.h:2590
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1784
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4571
VPSymbolicValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4750
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1067
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))
auto m_VPValue()
Match an arbitrary VPValue and ignore it.
VPInstruction_match< VPInstruction::ExtractLastPart, Op0_t > m_ExtractLastPart(const Op0_t &Op0)
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.
InstructionCost Cost
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:279
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:1746
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:1753
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
Struct to hold various analysis needed for cost computations.
A recipe for handling first-order recurrence phis.
Definition VPlan.h:2638
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.
InstructionCost spillCost(VPCostContext &Ctx, unsigned OverrideMaxNumRegs=0) const
Calculate the estimated cost of any spills due to using more registers than the number available for ...
SmallMapVector< unsigned, unsigned, 4 > LoopInvariantRegs
Holds the number of loop invariant values that are used in the loop.