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 CanonicalIVTy = LoopRegion->getCanonicalIVType();
31 return;
32 }
33
34 // If there's no loop region, retrieve the type from the trip count
35 // expression.
36 auto *TC = Plan.getTripCount();
37 if (auto *TCIRV = dyn_cast<VPIRValue>(TC)) {
38 CanonicalIVTy = TCIRV->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 unsigned NumOperands = R->getNumOperandsWithoutMask();
61 for (unsigned Op = 1; Op != NumOperands; ++Op) {
62 VPValue *OtherV = R->getOperand(Op);
63 assert(inferScalarType(OtherV) == ResTy &&
64 "different types inferred for different operands");
65 CachedTypes[OtherV] = ResTy;
66 }
67 return ResTy;
68 };
69
70 unsigned Opcode = R->getOpcode();
72 return SetResultTyFromOp();
73
74 switch (Opcode) {
75 case Instruction::ExtractElement:
76 case Instruction::InsertElement:
77 case Instruction::Freeze:
78 case Instruction::PHI:
91 return inferScalarType(R->getOperand(0));
92 case Instruction::Select: {
93 Type *ResTy = inferScalarType(R->getOperand(1));
94 VPValue *OtherV = R->getOperand(2);
95 assert(inferScalarType(OtherV) == ResTy &&
96 "different types inferred for different operands");
97 CachedTypes[OtherV] = ResTy;
98 return ResTy;
99 }
100 case Instruction::ICmp:
101 case Instruction::FCmp:
103 assert(inferScalarType(R->getOperand(0)) ==
104 inferScalarType(R->getOperand(1)) &&
105 "different types inferred for different operands");
106 return IntegerType::get(Ctx, 1);
108 return Type::getIntNTy(Ctx, 32);
117 return SetResultTyFromOp();
119 return inferScalarType(R->getOperand(1));
122 // Assume that the maximum possible number of elements in a vector fits
123 // within the index type for the default address space.
124 return DL.getIndexType(Ctx, 0);
127 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1) &&
128 inferScalarType(R->getOperand(1))->isIntegerTy(1) &&
129 "LogicalAnd/Or operands should be bool");
130 return IntegerType::get(Ctx, 1);
132 assert(inferScalarType(R->getOperand(0))->isIntegerTy(1));
133 return IntegerType::get(Ctx, 1);
137 case Instruction::Store:
138 case Instruction::Switch:
139 return Type::getVoidTy(Ctx);
140 case Instruction::Load:
141 return cast<LoadInst>(R->getUnderlyingValue())->getType();
142 case Instruction::Alloca:
143 return cast<AllocaInst>(R->getUnderlyingValue())->getType();
144 case Instruction::Call: {
145 unsigned CallIdx = R->getNumOperandsWithoutMask() - 1;
146 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
147 ->getReturnType();
148 }
149 case Instruction::GetElementPtr:
150 return inferScalarType(R->getOperand(0));
151 case Instruction::ExtractValue:
152 return cast<ExtractValueInst>(R->getUnderlyingValue())->getType();
153 default:
154 break;
155 }
156 // Type inference not implemented for opcode.
157 LLVM_DEBUG({
158 dbgs() << "LV: Found unhandled opcode for: ";
159 R->getVPSingleValue()->dump();
160 });
161 llvm_unreachable("Unhandled opcode!");
162}
163
164Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenRecipe *R) {
165 unsigned Opcode = R->getOpcode();
166 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
168 Type *ResTy = inferScalarType(R->getOperand(0));
169 assert(ResTy == inferScalarType(R->getOperand(1)) &&
170 "types for both operands must match for binary op");
171 CachedTypes[R->getOperand(1)] = ResTy;
172 return ResTy;
173 }
174
175 switch (Opcode) {
176 case Instruction::ICmp:
177 case Instruction::FCmp:
178 return IntegerType::get(Ctx, 1);
179 case Instruction::FNeg:
180 case Instruction::Freeze:
181 return inferScalarType(R->getOperand(0));
182 case Instruction::ExtractValue: {
183 assert(R->getNumOperands() == 2 && "expected single level extractvalue");
184 auto *StructTy = cast<StructType>(inferScalarType(R->getOperand(0)));
185 return StructTy->getTypeAtIndex(
186 cast<VPConstantInt>(R->getOperand(1))->getZExtValue());
187 }
188 case Instruction::Select: {
189 Type *ResTy = inferScalarType(R->getOperand(1));
190 VPValue *OtherV = R->getOperand(2);
191 assert(inferScalarType(OtherV) == ResTy &&
192 "different types inferred for different operands");
193 CachedTypes[OtherV] = ResTy;
194 return ResTy;
195 }
196 default:
197 break;
198 }
199
200 // Type inference not implemented for opcode.
201 LLVM_DEBUG({
202 dbgs() << "LV: Found unhandled opcode for: ";
203 R->getVPSingleValue()->dump();
204 });
205 llvm_unreachable("Unhandled opcode!");
206}
207
208Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenCallRecipe *R) {
209 auto &CI = *cast<CallInst>(R->getUnderlyingInstr());
210 return CI.getType();
211}
212
213Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R) {
215 "Store recipes should not define any values");
216 return cast<LoadInst>(&R->getIngredient())->getType();
217}
218
219Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
220 unsigned Opcode = R->getUnderlyingInstr()->getOpcode();
221
222 if (Instruction::isBinaryOp(Opcode) || Instruction::isShift(Opcode) ||
224 Type *ResTy = inferScalarType(R->getOperand(0));
225 assert(ResTy == inferScalarType(R->getOperand(1)) &&
226 "inferred types for operands of binary op don't match");
227 CachedTypes[R->getOperand(1)] = ResTy;
228 return ResTy;
229 }
230
231 if (Instruction::isCast(Opcode))
232 return R->getUnderlyingInstr()->getType();
233
234 switch (Opcode) {
235 case Instruction::Call: {
236 unsigned CallIdx = R->getNumOperands() - (R->isPredicated() ? 2 : 1);
237 return cast<Function>(R->getOperand(CallIdx)->getLiveInIRValue())
238 ->getReturnType();
239 }
240 case Instruction::Select: {
241 Type *ResTy = inferScalarType(R->getOperand(1));
242 assert(ResTy == inferScalarType(R->getOperand(2)) &&
243 "inferred types for operands of select op don't match");
244 CachedTypes[R->getOperand(2)] = ResTy;
245 return ResTy;
246 }
247 case Instruction::ICmp:
248 case Instruction::FCmp:
249 return IntegerType::get(Ctx, 1);
250 case Instruction::Alloca:
251 case Instruction::ExtractValue:
252 return R->getUnderlyingInstr()->getType();
253 case Instruction::Freeze:
254 case Instruction::FNeg:
255 case Instruction::GetElementPtr:
256 return inferScalarType(R->getOperand(0));
257 case Instruction::Load:
258 return cast<LoadInst>(R->getUnderlyingInstr())->getType();
259 case Instruction::Store:
260 // FIXME: VPReplicateRecipes with store opcodes still define a result
261 // VPValue, so we need to handle them here. Remove the code here once this
262 // is modeled accurately in VPlan.
263 return Type::getVoidTy(Ctx);
264 default:
265 break;
266 }
267 // Type inference not implemented for opcode.
268 LLVM_DEBUG({
269 dbgs() << "LV: Found unhandled opcode for: ";
270 R->getVPSingleValue()->dump();
271 });
272 llvm_unreachable("Unhandled opcode");
273}
274
276 if (Type *CachedTy = CachedTypes.lookup(V))
277 return CachedTy;
278
279 if (auto *IRV = dyn_cast<VPIRValue>(V))
280 return IRV->getType();
281
282 if (isa<VPSymbolicValue>(V)) {
283 // All VPValues without any underlying IR value (like the vector trip count
284 // or the backedge-taken count) have the same type as the canonical IV.
285 return CanonicalIVTy;
286 }
287
288 if (auto *RegionV = dyn_cast<VPRegionValue>(V))
289 return RegionV->getType();
290
291 Type *ResultTy =
292 TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe())
295 VPCurrentIterationPHIRecipe>([this](const auto *R) {
296 // Handle header phi recipes, except VPWidenIntOrFpInduction
297 // which needs special handling due it being possibly truncated.
298 // TODO: consider inferring/caching type of siblings, e.g.,
299 // backedge value, here and in cases below.
300 return inferScalarType(R->getStartValue());
301 })
302 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
303 [](const auto *R) { return R->getScalarType(); })
307 [this](const VPRecipeBase *R) {
308 return inferScalarType(R->getOperand(0));
309 })
310 // VPInstructionWithType must be handled before VPInstruction.
313 [](const auto *R) { return R->getResultType(); })
316 [this](const auto *R) { return inferScalarTypeForRecipe(R); })
317 .Case([V](const VPInterleaveBase *R) {
318 // TODO: Use info from interleave group.
319 return V->getUnderlyingValue()->getType();
320 })
321 .Case([](const VPExpandSCEVRecipe *R) {
322 return R->getSCEV()->getType();
323 })
324 .Case([this](const VPReductionRecipe *R) {
325 return inferScalarType(R->getChainOp());
326 })
327 .Case([this](const VPExpressionRecipe *R) {
328 return inferScalarType(R->getOperandOfResultType());
329 });
330
331 assert(ResultTy && "could not infer type for the given VPValue");
332 CachedTypes[V] = ResultTy;
333 return ResultTy;
334}
335
337 VPlan &Plan, DenseSet<VPRecipeBase *> &EphRecipes) {
338 // First, collect seed recipes which are operands of assumes.
342 for (VPRecipeBase &R : *VPBB) {
343 auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
344 if (!RepR || !match(RepR, m_Intrinsic<Intrinsic::assume>()))
345 continue;
346 Worklist.push_back(RepR);
347 EphRecipes.insert(RepR);
348 }
349 }
350
351 // Process operands of candidates in worklist and add them to the set of
352 // ephemeral recipes, if they don't have side-effects and are only used by
353 // other ephemeral recipes.
354 while (!Worklist.empty()) {
355 VPRecipeBase *Cur = Worklist.pop_back_val();
356 for (VPValue *Op : Cur->operands()) {
357 auto *OpR = Op->getDefiningRecipe();
358 if (!OpR || OpR->mayHaveSideEffects() || EphRecipes.contains(OpR))
359 continue;
360 if (any_of(Op->users(), [EphRecipes](VPUser *U) {
361 auto *UR = dyn_cast<VPRecipeBase>(U);
362 return !UR || !EphRecipes.contains(UR);
363 }))
364 continue;
365 EphRecipes.insert(OpR);
366 Worklist.push_back(OpR);
367 }
368 }
369}
370
373
375 const VPRecipeBase *B) {
376 if (A == B)
377 return false;
378
379 auto LocalComesBefore = [](const VPRecipeBase *A, const VPRecipeBase *B) {
380 for (auto &R : *A->getParent()) {
381 if (&R == A)
382 return true;
383 if (&R == B)
384 return false;
385 }
386 llvm_unreachable("recipe not found");
387 };
388 const VPBlockBase *ParentA = A->getParent();
389 const VPBlockBase *ParentB = B->getParent();
390 if (ParentA == ParentB)
391 return LocalComesBefore(A, B);
392
393 return Base::properlyDominates(ParentA, ParentB);
394}
395
399 unsigned OverrideMaxNumRegs) const {
401 for (const auto &[RegClass, MaxUsers] : MaxLocalUsers) {
402 unsigned AvailableRegs = OverrideMaxNumRegs > 0
403 ? OverrideMaxNumRegs
404 : TTI.getNumberOfRegisters(RegClass);
405 if (MaxUsers > AvailableRegs) {
406 // Assume that for each register used past what's available we get one
407 // spill and reload.
408 unsigned Spills = MaxUsers - AvailableRegs;
409 InstructionCost SpillCost =
410 TTI.getRegisterClassSpillCost(RegClass, CostKind) +
411 TTI.getRegisterClassReloadCost(RegClass, CostKind);
412 InstructionCost TotalCost = Spills * SpillCost;
413 LLVM_DEBUG(dbgs() << "LV(REG): Cost of " << TotalCost << " from "
414 << Spills << " spills of "
415 << TTI.getRegisterClassName(RegClass) << "\n");
416 Cost += TotalCost;
417 }
418 }
419 return Cost;
420}
421
424 const SmallPtrSetImpl<const Value *> &ValuesToIgnore) {
425 // Each 'key' in the map opens a new interval. The values
426 // of the map are the index of the 'last seen' usage of the
427 // VPValue that is the key.
429
430 // Maps indices to recipes.
432 // Marks the end of each interval.
433 IntervalMap EndPoint;
434 // Saves the list of VPValues that are used in the loop.
436 // Saves the list of values that are used in the loop but are defined outside
437 // the loop (not including non-recipe values such as arguments and
438 // constants).
439 SmallSetVector<VPValue *, 8> LoopInvariants;
440 if (Plan.getVectorTripCount().getNumUsers() > 0)
441 LoopInvariants.insert(&Plan.getVectorTripCount());
442
443 // We scan the loop in a topological order in order and assign a number to
444 // each recipe. We use RPO to ensure that defs are met before their users. We
445 // assume that each recipe that has in-loop users starts an interval. We
446 // record every time that an in-loop value is used, so we have a list of the
447 // first occurences of each recipe and last occurrence of each VPValue.
448 VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
450 LoopRegion);
452 if (!VPBB->getParent())
453 break;
454 for (VPRecipeBase &R : *VPBB) {
455 Idx2Recipe.push_back(&R);
456
457 // Save the end location of each USE.
458 for (VPValue *U : R.operands()) {
459 if (isa<VPRecipeValue>(U)) {
460 // Overwrite previous end points.
461 EndPoint[U] = Idx2Recipe.size();
462 Ends.insert(U);
463 } else if (auto *IRV = dyn_cast<VPIRValue>(U)) {
464 // Ignore non-recipe values such as arguments, constants, etc.
465 // FIXME: Might need some motivation why these values are ignored. If
466 // for example an argument is used inside the loop it will increase
467 // the register pressure (so shouldn't we add it to LoopInvariants).
468 if (!isa<Instruction>(IRV->getValue()))
469 continue;
470 // This recipe is outside the loop, record it and continue.
471 LoopInvariants.insert(U);
472 }
473 // Other types of VPValue are currently not tracked.
474 }
475 }
476 if (VPBB == LoopRegion->getExiting()) {
477 // VPWidenIntOrFpInductionRecipes are used implicitly at the end of the
478 // exiting block, where their increment will get materialized eventually.
479 for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
480 if (auto *WideIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R)) {
481 EndPoint[WideIV] = Idx2Recipe.size();
482 Ends.insert(WideIV);
483 }
484 }
485 }
486 }
487
488 // Saves the list of intervals that end with the index in 'key'.
489 using VPValueList = SmallVector<VPValue *, 2>;
491
492 // Next, we transpose the EndPoints into a multi map that holds the list of
493 // intervals that *end* at a specific location.
494 for (auto &Interval : EndPoint)
495 TransposeEnds[Interval.second].push_back(Interval.first);
496
497 SmallPtrSet<VPValue *, 8> OpenIntervals;
500
501 LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
502
503 VPTypeAnalysis TypeInfo(Plan);
504
505 const auto &TTICapture = TTI;
506 auto GetRegUsage = [&TTICapture](Type *Ty, ElementCount VF) -> unsigned {
507 if (Ty->isTokenTy() || !VectorType::isValidElementType(Ty) ||
508 (VF.isScalable() &&
509 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
510 return 0;
511 return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
512 };
513
514 VPValue *CanIV = LoopRegion->getCanonicalIV();
515 // Note: canonical IVs are retained even if they have no users.
516 if (CanIV->getNumUsers() != 0)
517 OpenIntervals.insert(CanIV);
518
519 // We scan the instructions linearly and record each time that a new interval
520 // starts, by placing it in a set. If we find this value in TransposEnds then
521 // we remove it from the set. The max register usage is the maximum register
522 // usage of the recipes of the set.
523 for (unsigned int Idx = 0, Sz = Idx2Recipe.size(); Idx < Sz; ++Idx) {
524 VPRecipeBase *R = Idx2Recipe[Idx];
525
526 // Remove all of the VPValues that end at this location.
527 VPValueList &List = TransposeEnds[Idx];
528 for (VPValue *ToRemove : List)
529 OpenIntervals.erase(ToRemove);
530
531 // Ignore recipes that are never used within the loop and do not have side
532 // effects.
533 if (none_of(R->definedValues(),
534 [&Ends](VPValue *Def) { return Ends.count(Def); }) &&
535 !R->mayHaveSideEffects())
536 continue;
537
538 // Skip recipes for ignored values.
539 // TODO: Should mark recipes for ephemeral values that cannot be removed
540 // explictly in VPlan.
541 if (isa<VPSingleDefRecipe>(R) &&
542 ValuesToIgnore.contains(
543 cast<VPSingleDefRecipe>(R)->getUnderlyingValue()))
544 continue;
545
546 // For each VF find the maximum usage of registers.
547 for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
548 // Count the number of registers used, per register class, given all open
549 // intervals.
550 // Note that elements in this SmallMapVector will be default constructed
551 // as 0. So we can use "RegUsage[ClassID] += n" in the code below even if
552 // there is no previous entry for ClassID.
554
555 for (auto *VPV : OpenIntervals) {
556 // Skip artificial values or values that weren't present in the original
557 // loop.
558 // TODO: Remove skipping values that weren't present in the original
559 // loop after removing the legacy
560 // LoopVectorizationCostModel::calculateRegisterUsage
562 VPBranchOnMaskRecipe>(VPV) ||
564 continue;
565
566 if (VFs[J].isScalar() ||
571 (cast<VPReductionPHIRecipe>(VPV))->isInLoop())) {
572 unsigned ClassID =
573 TTI.getRegisterClassForType(false, TypeInfo.inferScalarType(VPV));
574 // FIXME: The target might use more than one register for the type
575 // even in the scalar case.
576 RegUsage[ClassID] += 1;
577 } else {
578 // The output from scaled phis and scaled reductions actually has
579 // fewer lanes than the VF.
580 unsigned ScaleFactor =
581 vputils::getVFScaleFactor(VPV->getDefiningRecipe());
582 ElementCount VF = VFs[J];
583 if (ScaleFactor > 1) {
584 VF = VFs[J].divideCoefficientBy(ScaleFactor);
585 LLVM_DEBUG(dbgs() << "LV(REG): Scaled down VF from " << VFs[J]
586 << " to " << VF << " for " << *R << "\n";);
587 }
588
589 Type *ScalarTy = TypeInfo.inferScalarType(VPV);
590 unsigned ClassID = TTI.getRegisterClassForType(true, ScalarTy);
591 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
592 }
593 }
594
595 for (const auto &Pair : RegUsage) {
596 auto &Entry = MaxUsages[J][Pair.first];
597 Entry = std::max(Entry, Pair.second);
598 }
599 }
600
601 LLVM_DEBUG(dbgs() << "LV(REG): At #" << Idx << " Interval # "
602 << OpenIntervals.size() << '\n');
603
604 // Add used VPValues defined by the current recipe to the list of open
605 // intervals.
606 for (VPValue *DefV : R->definedValues())
607 if (Ends.contains(DefV))
608 OpenIntervals.insert(DefV);
609 }
610
611 // We also search for instructions that are defined outside the loop, but are
612 // used inside the loop. We need this number separately from the max-interval
613 // usage number because when we unroll, loop-invariant values do not take
614 // more register.
616 for (unsigned Idx = 0, End = VFs.size(); Idx < End; ++Idx) {
617 // Note that elements in this SmallMapVector will be default constructed
618 // as 0. So we can use "Invariant[ClassID] += n" in the code below even if
619 // there is no previous entry for ClassID.
621
622 for (auto *In : LoopInvariants) {
623 // FIXME: The target might use more than one register for the type
624 // even in the scalar case.
625 bool IsScalar = vputils::onlyScalarValuesUsed(In);
626
627 ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[Idx];
628 unsigned ClassID = TTI.getRegisterClassForType(
629 VF.isVector(), TypeInfo.inferScalarType(In));
630 Invariant[ClassID] += GetRegUsage(TypeInfo.inferScalarType(In), VF);
631 }
632
633 LLVM_DEBUG({
634 dbgs() << "LV(REG): VF = " << VFs[Idx] << '\n';
635 dbgs() << "LV(REG): Found max usage: " << MaxUsages[Idx].size()
636 << " item\n";
637 for (const auto &pair : MaxUsages[Idx]) {
638 dbgs() << "LV(REG): RegisterClass: "
639 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
640 << " registers\n";
641 }
642 dbgs() << "LV(REG): Found invariant usage: " << Invariant.size()
643 << " item\n";
644 for (const auto &pair : Invariant) {
645 dbgs() << "LV(REG): RegisterClass: "
646 << TTI.getRegisterClassName(pair.first) << ", " << pair.second
647 << " registers\n";
648 }
649 });
650
651 RU.LoopInvariantRegs = Invariant;
652 RU.MaxLocalUsers = MaxUsages[Idx];
653 RUs[Idx] = RU;
654 }
655
656 return RUs;
657}
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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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
if(PassOpts->AAPipeline)
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:
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:39
size_t size() const
Get the array size.
Definition ArrayRef.h:140
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:56
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:3782
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4149
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4237
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2775
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:97
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:286
A recipe for generating conditional branches on the bits of a mask.
Definition VPlan.h:3266
A recipe for generating the phi node tracking the current scalar iteration index.
Definition VPlan.h:3814
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3898
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B)
Recipe to expand a SCEV expression.
Definition VPlan.h:3746
A recipe to combine multiple recipes into a single 'expression' recipe, which should be considered a ...
Definition VPlan.h:3311
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
Definition VPlan.h:1511
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1222
@ ExtractLastActive
Extracts the last active lane from a set of vectors.
Definition VPlan.h:1328
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1319
@ ExitingIVValue
Compute the exiting value of a wide induction after vectorization, that is the value of the last lane...
Definition VPlan.h:1335
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1322
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
Definition VPlan.h:1262
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1313
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1257
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1254
@ CanonicalIVIncrementForPart
Definition VPlan.h:1238
@ ComputeReductionResult
Reduce the operands to the final reduction result using the operation specified via the operation's V...
Definition VPlan.h:1265
A common base class for interleaved memory operations.
Definition VPlan.h:2847
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition VPlan.h:3453
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:405
A recipe for handling reduction phis.
Definition VPlan.h:2681
A recipe to represent inloop, ordered or partial reduction operations.
Definition VPlan.h:3036
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4359
const VPBlockBase * getEntry() const
Definition VPlan.h:4403
VPRegionValue * getCanonicalIV()
Return the canonical induction variable of the region, null for replicating regions.
Definition VPlan.h:4471
const VPBlockBase * getExiting() const
Definition VPlan.h:4415
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:3190
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3969
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:329
operand_range operands()
Definition VPlanValue.h:397
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:2146
A recipe to compute the pointers for widened memory accesses of SourceElementTy.
Definition VPlan.h:2219
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1984
A Recipe for widening the canonical induction variable of the vector loop.
Definition VPlan.h:3857
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1832
A recipe for handling GEP instructions.
Definition VPlan.h:2082
A recipe for widening vector intrinsics.
Definition VPlan.h:1884
A common base class for widening memory operations.
Definition VPlan.h:3496
A recipe for widened phis.
Definition VPlan.h:2579
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1776
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4507
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4658
VPSymbolicValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4687
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1066
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:265
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: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: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:276
A recipe for handling first-order recurrence phis.
Definition VPlan.h:2619
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.