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
27Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
28 Type *ResTy = inferScalarType(R->getIncomingValue(0));
29 for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {
30 VPValue *Inc = R->getIncomingValue(I);
31 assert(inferScalarType(Inc) == ResTy &&
32 "different types inferred for different incoming values");
33 CachedTypes[Inc] = ResTy;
34 }
35 return ResTy;
36}
37
38Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
39 // Set the result type from the first operand, check if the types for all
40 // other operands match and cache them.
41 auto SetResultTyFromOp = [this, R]() {
42 Type *ResTy = inferScalarType(R->getOperand(0));
43 unsigned NumOperands = R->getNumOperandsWithoutMask();
44 for (unsigned Op = 1; Op != NumOperands; ++Op) {
45 VPValue *OtherV = R->getOperand(Op);
46 assert(inferScalarType(OtherV) == ResTy &&
47 "different types inferred for different operands");
48 CachedTypes[OtherV] = ResTy;
49 }
50 return ResTy;
51 };
52
53 unsigned Opcode = R->getOpcode();
55 return SetResultTyFromOp();
56
57 switch (Opcode) {
58 case Instruction::PHI:
59 for (VPValue *Op : R->operands()) {
60 if (auto *VIR = dyn_cast<VPIRValue>(Op))
61 return VIR->getType();
62 if (auto *Ty = CachedTypes.lookup(Op))
63 return Ty;
64 }
66 case Instruction::ExtractElement:
67 case Instruction::InsertElement:
68 case Instruction::Freeze:
81 return inferScalarType(R->getOperand(0));
82 case Instruction::Select: {
83 Type *ResTy = inferScalarType(R->getOperand(1));
84 VPValue *OtherV = R->getOperand(2);
85 assert(inferScalarType(OtherV) == ResTy &&
86 "different types inferred for different operands");
87 CachedTypes[OtherV] = ResTy;
88 return ResTy;
89 }
90 case Instruction::ICmp:
91 case Instruction::FCmp:
93 assert(inferScalarType(R->getOperand(0)) ==
94 inferScalarType(R->getOperand(1)) &&
95 "different types inferred for different operands");
96 return IntegerType::get(Ctx, 1);
98 return Type::getIntNTy(Ctx, 32);
107 return SetResultTyFromOp();
109 return inferScalarType(R->getOperand(1));
112 // Assume that the maximum possible number of elements in a vector fits
113 // within the index type for the default address space.
114 return DL.getIndexType(Ctx, 0);
117 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1) &&
118 inferScalarType(R->getOperand(1))->isIntegerTy(1) &&
119 "LogicalAnd/Or operands should be bool");
120 return IntegerType::get(Ctx, 1);
122 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1));
123 return IntegerType::get(Ctx, 1);
127 case Instruction::Store:
128 case Instruction::Switch:
129 return Type::getVoidTy(Ctx);
130 case Instruction::Load:
131 return cast<LoadInst>(R->getUnderlyingValue())->getType();
132 case Instruction::Alloca:
133 return cast<AllocaInst>(R->getUnderlyingValue())->getType();
134 case Instruction::Call: {
135 unsigned CallIdx = R->getNumOperandsWithoutMask() - 1;
136 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
137 ->getReturnType();
138 }
139 case Instruction::GetElementPtr:
140 return inferScalarType(R->getOperand(0));
141 case Instruction::ExtractValue:
142 return cast<ExtractValueInst>(R->getUnderlyingValue())->getType();
143 default:
144 break;
145 }
146 // Type inference not implemented for opcode.
147 LLVM_DEBUG({
148 dbgs() << "LV: Found unhandled opcode for: ";
149 R->getVPSingleValue()->dump();
150 });
151 llvm_unreachable("Unhandled opcode!");
152}
153
154Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
155 unsigned Opcode = R->getOpcode();
156 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
158 Type *ResTy = inferScalarType(R->getOperand(0));
159 assert(ResTy == inferScalarType(R->getOperand(1)) &&
160 "types for both operands must match for binary op");
161 CachedTypes[R->getOperand(1)] = ResTy;
162 return ResTy;
163 }
164
165 switch (Opcode) {
166 case Instruction::ICmp:
167 case Instruction::FCmp:
168 return IntegerType::get(Ctx, 1);
169 case Instruction::FNeg:
170 case Instruction::Freeze:
171 return inferScalarType(R->getOperand(0));
172 case Instruction::ExtractValue: {
173 assert(R->getNumOperands() == 2 && "expected single level extractvalue");
174 auto *StructTy = cast<StructType>(inferScalarType(R->getOperand(0)));
175 return StructTy->getTypeAtIndex(
176 cast<VPConstantInt>(R->getOperand(1))->getZExtValue());
177 }
178 case Instruction::Select: {
179 Type *ResTy = inferScalarType(R->getOperand(1));
180 VPValue *OtherV = R->getOperand(2);
181 assert(inferScalarType(OtherV) == ResTy &&
182 "different types inferred for different operands");
183 CachedTypes[OtherV] = ResTy;
184 return ResTy;
185 }
186 default:
187 break;
188 }
189
190 // Type inference not implemented for opcode.
191 LLVM_DEBUG({
192 dbgs() << "LV: Found unhandled opcode for: ";
193 R->getVPSingleValue()->dump();
194 });
195 llvm_unreachable("Unhandled opcode!");
196}
197
198Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenCallRecipe *R) {
199 auto &CI = *cast<CallInst>(R->getUnderlyingInstr());
200 return CI.getType();
201}
202
203Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R) {
205 "Store recipes should not define any values");
206 return cast<LoadInst>(&R->getIngredient())->getType();
207}
208
209Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
210 unsigned Opcode = R->getUnderlyingInstr()->getOpcode();
211
212 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
214 Type *ResTy = inferScalarType(R->getOperand(0));
215 assert(ResTy == inferScalarType(R->getOperand(1)) &&
216 "inferred types for operands of binary op don't match");
217 CachedTypes[R->getOperand(1)] = ResTy;
218 return ResTy;
219 }
220
221 if (Instruction::isCast(Opcode))
222 return R->getUnderlyingInstr()->getType();
223
224 switch (Opcode) {
225 case Instruction::Call: {
226 unsigned CallIdx = R->getNumOperands() - (R->isPredicated() ? 2 : 1);
227 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
228 ->getReturnType();
229 }
230 case Instruction::Select: {
231 Type *ResTy = inferScalarType(R->getOperand(1));
232 assert(ResTy == inferScalarType(R->getOperand(2)) &&
233 "inferred types for operands of select op don't match");
234 CachedTypes[R->getOperand(2)] = ResTy;
235 return ResTy;
236 }
237 case Instruction::ICmp:
238 case Instruction::FCmp:
239 return IntegerType::get(Ctx, 1);
240 case Instruction::Alloca:
241 case Instruction::ExtractValue:
242 return R->getUnderlyingInstr()->getType();
243 case Instruction::Freeze:
244 case Instruction::FNeg:
245 case Instruction::GetElementPtr:
246 return inferScalarType(R->getOperand(0));
247 case Instruction::Load:
248 return cast<LoadInst>(R->getUnderlyingInstr())->getType();
249 case Instruction::Store:
250 // FIXME: VPReplicateRecipes with store opcodes still define a result
251 // VPValue, so we need to handle them here. Remove the code here once this
252 // is modeled accurately in VPlan.
253 return Type::getVoidTy(Ctx);
254 default:
255 break;
256 }
257 // Type inference not implemented for opcode.
258 LLVM_DEBUG({
259 dbgs() << "LV: Found unhandled opcode for: ";
260 R->getVPSingleValue()->dump();
261 });
262 llvm_unreachable("Unhandled opcode");
263}
264
266 if (Type *CachedTy = CachedTypes.lookup(V))
267 return CachedTy;
268
269 if (auto *IRV = dyn_cast<VPIRValue>(V))
270 return IRV->getType();
271
272 if (auto *SymbolicV = dyn_cast<VPSymbolicValue>(V))
273 return SymbolicV->getType();
274
275 if (auto *RegionV = dyn_cast<VPRegionValue>(V))
276 return RegionV->getType();
277
278 Type *ResultTy =
279 TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe())
282 VPCurrentIterationPHIRecipe>([this](const auto *R) {
283 // Handle header phi recipes, except VPWidenIntOrFpInduction
284 // which needs special handling due it being possibly truncated.
285 // TODO: consider inferring/caching type of siblings, e.g.,
286 // backedge value, here and in cases below.
287 return inferScalarType(R->getStartValue());
288 })
289 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
290 [](const auto *R) { return R->getScalarType(); })
294 [this](const VPRecipeBase *R) {
295 return inferScalarType(R->getOperand(0));
296 })
297 // VPInstructionWithType must be handled before VPInstruction.
300 [](const auto *R) { return R->getResultType(); })
303 [this](const auto *R) { return inferScalarTypeForRecipe(R); })
304 .Case([V](const VPInterleaveBase *R) {
305 // TODO: Use info from interleave group.
306 return V->getUnderlyingValue()->getType();
307 })
308 .Case([](const VPExpandSCEVRecipe *R) {
309 return R->getSCEV()->getType();
310 })
311 .Case([this](const VPReductionRecipe *R) {
312 return inferScalarType(R->getChainOp());
313 })
314 .Case([this](const VPExpressionRecipe *R) {
315 return inferScalarType(R->getOperandOfResultType());
316 });
317
318 assert(ResultTy && "could not infer type for the given VPValue");
319 CachedTypes[V] = ResultTy;
320 return ResultTy;
321}
322
324 VPlan &Plan, DenseSet<VPRecipeBase *> &EphRecipes) {
325 // First, collect seed recipes which are operands of assumes.
329 for (VPRecipeBase &R : *VPBB) {
330 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
331 if (!RepR || !match(RepR, m_Intrinsic<Intrinsic::assume>()))
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 return Base::properlyDominates(ParentA, ParentB);
381}
382
386 unsigned OverrideMaxNumRegs) const {
388 for (const auto &[RegClass, MaxUsers] : MaxLocalUsers) {
389 unsigned AvailableRegs = OverrideMaxNumRegs > 0
390 ? OverrideMaxNumRegs
391 : TTI.getNumberOfRegisters(RegClass);
392 if (MaxUsers > AvailableRegs) {
393 // Assume that for each register used past what's available we get one
394 // spill and reload.
395 unsigned Spills = MaxUsers - AvailableRegs;
396 InstructionCost SpillCost =
397 TTI.getRegisterClassSpillCost(RegClass, CostKind) +
398 TTI.getRegisterClassReloadCost(RegClass, CostKind);
399 InstructionCost TotalCost = Spills * SpillCost;
400 LLVM_DEBUG(dbgs() << "LV(REG): Cost of " << TotalCost << " from "
401 << Spills << " spills of "
402 << TTI.getRegisterClassName(RegClass) << "\n");
403 Cost += TotalCost;
404 }
405 }
406 return Cost;
407}
408
411 const SmallPtrSetImpl<const Value *> &ValuesToIgnore) {
412 // Each 'key' in the map opens a new interval. The values
413 // of the map are the index of the 'last seen' usage of the
414 // VPValue that is the key.
416
417 // Maps indices to recipes.
419 // Marks the end of each interval.
420 IntervalMap EndPoint;
421 // Saves the list of VPValues that are used in the loop.
423 // Saves the list of values that are used in the loop but are defined outside
424 // the loop (not including non-recipe values such as arguments and
425 // constants).
426 SmallSetVector<VPValue *, 8> LoopInvariants;
427 if (Plan.getVectorTripCount().getNumUsers() > 0)
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 if (isa<VPRecipeValue>(U)) {
447 // Overwrite previous end points.
448 EndPoint[U] = Idx2Recipe.size();
449 Ends.insert(U);
450 } else if (auto *IRV = dyn_cast<VPIRValue>(U)) {
451 // Ignore non-recipe values such as arguments, constants, etc.
452 // FIXME: Might need some motivation why these values are ignored. If
453 // for example an argument is used inside the loop it will increase
454 // the register pressure (so shouldn't we add it to LoopInvariants).
455 if (!isa<Instruction>(IRV->getValue()))
456 continue;
457 // This recipe is outside the loop, record it and continue.
458 LoopInvariants.insert(U);
459 }
460 // Other types of VPValue are currently not tracked.
461 }
462 }
463 if (VPBB == LoopRegion->getExiting()) {
464 // VPWidenIntOrFpInductionRecipes are used implicitly at the end of the
465 // exiting block, where their increment will get materialized eventually.
466 for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
467 if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
468 EndPoint[WideIV] = Idx2Recipe.size();
469 Ends.insert(WideIV);
470 }
471 }
472 }
473 }
474
475 // Saves the list of intervals that end with the index in 'key'.
476 using VPValueList = SmallVector<VPValue *, 2>;
478
479 // Next, we transpose the EndPoints into a multi map that holds the list of
480 // intervals that *end* at a specific location.
481 for (auto &Interval : EndPoint)
482 TransposeEnds[Interval.second].push_back(Interval.first);
483
484 SmallPtrSet<VPValue *, 8> OpenIntervals;
487
488 LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
489
490 VPTypeAnalysis TypeInfo(Plan);
491
492 const auto &TTICapture = TTI;
493 auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> unsigned {
494 if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty) ||
495 (VF.isScalable() &&
496 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
497 return 0;
498 return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
499 };
500
501 VPValue *CanIV = LoopRegion->getCanonicalIV();
502 // Note: canonical IVs are retained even if they have no users.
503 if (CanIV->getNumUsers() != 0)
504 OpenIntervals.insert(CanIV);
505
506 // We scan the instructions linearly and record each time that a new interval
507 // starts, by placing it in a set. If we find this value in TransposEnds then
508 // we remove it from the set. The max register usage is the maximum register
509 // usage of the recipes of the set.
510 for (unsigned int Idx = 0, Sz = Idx2Recipe.size(); Idx < Sz; ++Idx) {
511 VPRecipeBase *R = Idx2Recipe[Idx];
512
513 // Remove all of the VPValues that end at this location.
514 VPValueList &List = TransposeEnds[Idx];
515 for (VPValue *ToRemove : List)
516 OpenIntervals.erase(ToRemove);
517
518 // Ignore recipes that are never used within the loop and do not have side
519 // effects.
520 if (none_of(R->definedValues(),
521 [&Ends](VPValue *Def) { return Ends.count(Def); }) &&
522 !R->mayHaveSideEffects())
523 continue;
524
525 // Skip recipes for ignored values.
526 // TODO: Should mark recipes for ephemeral values that cannot be removed
527 // explictly in VPlan.
528 if (isa<VPSingleDefRecipe>(R) &&
529 ValuesToIgnore.contains(
530 cast<VPSingleDefRecipe>(R)->getUnderlyingValue()))
531 continue;
532
533 // For each VF find the maximum usage of registers.
534 for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
535 // Count the number of registers used, per register class, given all open
536 // intervals.
537 // Note that elements in this SmallMapVector will be default constructed
538 // as 0. So we can use "RegUsage[ClassID] += n" in the code below even if
539 // there is no previous entry for ClassID.
541
542 for (auto *VPV : OpenIntervals) {
543 // Skip artificial values or values that weren't present in the original
544 // loop.
545 // TODO: Remove skipping values that weren't present in the original
546 // loop after removing the legacy
547 // LoopVectorizationCostModel::calculateRegisterUsage
549 VPBranchOnMaskRecipe>(VPV) ||
551 continue;
552
553 if (VFs[J].isScalar() ||
558 (cast<VPReductionPHIRecipe>(VPV))->isInLoop())) {
559 unsigned ClassID =
560 TTI.getRegisterClassForType(false, TypeInfo.inferScalarType(VPV));
561 // FIXME: The target might use more than one register for the type
562 // even in the scalar case.
563 RegUsage[ClassID] += 1;
564 } else {
565 // The output from scaled phis and scaled reductions actually has
566 // fewer lanes than the VF.
567 unsigned ScaleFactor =
568 vputils::getVFScaleFactor(VPV->getDefiningRecipe());
569 ElementCount VF = VFs[J];
570 if (ScaleFactor > 1) {
571 VF = VFs[J].divideCoefficientBy(ScaleFactor);
572 LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J]
573 << " to " << VF << " for " << *R << "\n";);
574 }
575
576 Type *ScalarTy = TypeInfo.inferScalarType(VPV);
577 unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
578 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
579 }
580 }
581
582 for (const auto &Pair : RegUsage) {
583 auto &Entry = MaxUsages[J][Pair.first];
584 Entry = std::max(Entry, Pair.second);
585 }
586 }
587
588 LLVM_DEBUG(dbgs() << "LV(REG): At #" << Idx << " Interval # "
589 << OpenIntervals.size() << '\n');
590
591 // Add used VPValues defined by the current recipe to the list of open
592 // intervals.
593 for (VPValue *DefV : R->definedValues())
594 if (Ends.contains(DefV))
595 OpenIntervals.insert(DefV);
596 }
597
598 // We also search for instructions that are defined outside the loop, but are
599 // used inside the loop. We need this number separately from the max-interval
600 // usage number because when we unroll, loop-invariant values do not take
601 // more register.
603 for (unsigned Idx = 0, End = VFs.size(); Idx < End; ++Idx) {
604 // Note that elements in this SmallMapVector will be default constructed
605 // as 0. So we can use "Invariant[ClassID] += n" in the code below even if
606 // there is no previous entry for ClassID.
608
609 for (auto *In : LoopInvariants) {
610 // FIXME: The target might use more than one register for the type
611 // even in the scalar case.
612 bool IsScalar = vputils::onlyScalarValuesUsed(In);
613
614 ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[Idx];
615 unsigned ClassID = TTI.getRegisterClassForType(
616 VF.isVector(), TypeInfo.inferScalarType(In));
617 Invariant[ClassID] += GetRegUsage(TypeInfo.inferScalarType(In), VF);
618 }
619
620 LLVM_DEBUG({
621 dbgs() << "LV(REG): VF = " << VFs[Idx] << '\n';
622 dbgs() << "LV(REG): Found max usage: " << MaxUsages[Idx].size()
623 << " item\n";
624 for (const auto &pair : MaxUsages[Idx]) {
625 dbgs() << "LV(REG): RegisterClass: "
626 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
627 << " registers\n";
628 }
629 dbgs() << "LV(REG): Found invariant usage: " << Invariant.size()
630 << " item\n";
631 for (const auto &pair : Invariant) {
632 dbgs() << "LV(REG): RegisterClass: "
633 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
634 << " registers\n";
635 }
636 });
637
638 RU.LoopInvariantRegs = Invariant;
639 RU.MaxLocalUsers = MaxUsages[Idx];
640 RUs[Idx] = RU;
641 }
642
643 return RUs;
644}
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 LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition Compiler.h:404
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
#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:119
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:
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
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
size_type size() const
Definition MapVector.h:58
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.
TargetCostKind
The kind of cost model.
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:3806
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4148
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4236
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2785
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:93
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:183
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:295
A recipe for generating conditional branches on the bits of a mask.
Definition VPlan.h:3283
A recipe for generating the phi node tracking the current scalar iteration index.
Definition VPlan.h:3838
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3922
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B)
Recipe to expand a SCEV expression.
Definition VPlan.h:3770
A recipe to combine multiple recipes into a single 'expression' recipe, which should be considered a ...
Definition VPlan.h:3328
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
Definition VPlan.h:1509
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1220
@ ExtractLastActive
Extracts the last active lane from a set of vectors.
Definition VPlan.h:1326
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1317
@ ExitingIVValue
Compute the exiting value of a wide induction after vectorization, that is the value of the last lane...
Definition VPlan.h:1333
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1320
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
Definition VPlan.h:1260
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1311
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1255
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1252
@ CanonicalIVIncrementForPart
Definition VPlan.h:1236
@ ComputeReductionResult
Reduce the operands to the final reduction result using the operation specified via the operation's V...
Definition VPlan.h:1263
A common base class for interleaved memory operations.
Definition VPlan.h:2857
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition VPlan.h:3470
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:401
A recipe for handling reduction phis.
Definition VPlan.h:2691
A recipe to represent inloop, ordered or partial reduction operations.
Definition VPlan.h:3046
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4358
const VPBlockBase * getEntry() const
Definition VPlan.h:4402
VPRegionValue * getCanonicalIV()
Return the canonical induction variable of the region, null for replicating regions.
Definition VPlan.h:4470
const VPBlockBase * getExiting() const
Definition VPlan.h:4414
VPValues defined by a VPRegionBlock, like the canonical IV.
Definition VPlanValue.h:209
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3200
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3993
An analysis for type-inference for VPValues.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:335
operand_range operands()
Definition VPlanValue.h:403
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:49
unsigned getNumUsers() const
Definition VPlanValue.h:113
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:2156
A recipe to compute the pointers for widened memory accesses of SourceElementTy.
Definition VPlan.h:2229
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1988
A Recipe for widening the canonical induction variable of the vector loop.
Definition VPlan.h:3881
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1830
A recipe for handling GEP instructions.
Definition VPlan.h:2092
A recipe for widening vector intrinsics.
Definition VPlan.h:1882
A common mixin class for widening memory operations.
Definition VPlan.h:3505
A recipe for widened phis.
Definition VPlan.h:2589
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1774
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4506
VPSymbolicValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4695
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1065
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:283
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:1745
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:209
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1752
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:334
A recipe for handling first-order recurrence phis.
Definition VPlan.h:2629
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(const TargetTransformInfo &TTI, TargetTransformInfo::TargetCostKind CostKind, 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.