25#define DEBUG_TYPE "vplan"
28 : Ctx(Plan.
getContext()), DL(Plan.getDataLayout()) {
30 CanonicalIVTy = LoopRegion->getCanonicalIVType();
38 CanonicalIVTy = TCIRV->getType();
46 for (
unsigned I = 1, E = R->getNumIncomingValues();
I != E; ++
I) {
47 VPValue *Inc = R->getIncomingValue(
I);
49 "different types inferred for different incoming values");
50 CachedTypes[Inc] = ResTy;
58 auto SetResultTyFromOp = [
this,
R]() {
60 unsigned NumOperands =
R->getNumOperandsWithoutMask();
61 for (
unsigned Op = 1;
Op != NumOperands; ++
Op) {
62 VPValue *OtherV =
R->getOperand(
Op);
64 "different types inferred for different operands");
65 CachedTypes[OtherV] = ResTy;
70 unsigned Opcode =
R->getOpcode();
72 return SetResultTyFromOp();
75 case Instruction::PHI:
76 for (VPValue *
Op :
R->operands()) {
78 return VIR->getType();
79 if (
auto *Ty = CachedTypes.lookup(
Op))
83 case Instruction::ExtractElement:
84 case Instruction::InsertElement:
85 case Instruction::Freeze:
99 case Instruction::Select: {
101 VPValue *OtherV =
R->getOperand(2);
103 "different types inferred for different operands");
104 CachedTypes[OtherV] = ResTy;
107 case Instruction::ICmp:
108 case Instruction::FCmp:
112 "different types inferred for different operands");
124 return SetResultTyFromOp();
131 return DL.getIndexType(Ctx, 0);
136 "LogicalAnd/Or operands should be bool");
144 case Instruction::Store:
145 case Instruction::Switch:
147 case Instruction::Load:
149 case Instruction::Alloca:
151 case Instruction::Call: {
152 unsigned CallIdx =
R->getNumOperandsWithoutMask() - 1;
156 case Instruction::GetElementPtr:
158 case Instruction::ExtractValue:
165 dbgs() <<
"LV: Found unhandled opcode for: ";
166 R->getVPSingleValue()->dump();
172 unsigned Opcode =
R->getOpcode();
177 "types for both operands must match for binary op");
178 CachedTypes[
R->getOperand(1)] = ResTy;
183 case Instruction::ICmp:
184 case Instruction::FCmp:
186 case Instruction::FNeg:
187 case Instruction::Freeze:
189 case Instruction::ExtractValue: {
190 assert(
R->getNumOperands() == 2 &&
"expected single level extractvalue");
192 return StructTy->getTypeAtIndex(
195 case Instruction::Select: {
197 VPValue *OtherV =
R->getOperand(2);
199 "different types inferred for different operands");
200 CachedTypes[OtherV] = ResTy;
209 dbgs() <<
"LV: Found unhandled opcode for: ";
210 R->getVPSingleValue()->dump();
222 "Store recipes should not define any values");
227 unsigned Opcode =
R->getUnderlyingInstr()->getOpcode();
233 "inferred types for operands of binary op don't match");
234 CachedTypes[
R->getOperand(1)] = ResTy;
239 return R->getUnderlyingInstr()->getType();
242 case Instruction::Call: {
243 unsigned CallIdx =
R->getNumOperands() - (
R->isPredicated() ? 2 : 1);
247 case Instruction::Select: {
250 "inferred types for operands of select op don't match");
251 CachedTypes[
R->getOperand(2)] = ResTy;
254 case Instruction::ICmp:
255 case Instruction::FCmp:
257 case Instruction::Alloca:
258 case Instruction::ExtractValue:
259 return R->getUnderlyingInstr()->getType();
260 case Instruction::Freeze:
261 case Instruction::FNeg:
262 case Instruction::GetElementPtr:
264 case Instruction::Load:
266 case Instruction::Store:
276 dbgs() <<
"LV: Found unhandled opcode for: ";
277 R->getVPSingleValue()->dump();
283 if (
Type *CachedTy = CachedTypes.lookup(V))
287 return IRV->getType();
292 return CanonicalIVTy;
296 return RegionV->getType();
309 .Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>(
310 [](
const auto *R) {
return R->getScalarType(); })
320 [](
const auto *R) {
return R->getResultType(); })
323 [
this](
const auto *R) {
return inferScalarTypeForRecipe(R); })
326 return V->getUnderlyingValue()->getType();
329 return R->getSCEV()->getType();
338 assert(ResultTy &&
"could not infer type for the given VPValue");
339 CachedTypes[V] = ResultTy;
361 while (!Worklist.
empty()) {
364 auto *OpR =
Op->getDefiningRecipe();
365 if (!OpR || OpR->mayHaveSideEffects() || EphRecipes.
contains(OpR))
368 auto *UR = dyn_cast<VPRecipeBase>(U);
369 return !UR || !EphRecipes.contains(UR);
387 for (
auto &R : *
A->getParent()) {
397 if (ParentA == ParentB)
398 return LocalComesBefore(
A,
B);
406 unsigned OverrideMaxNumRegs)
const {
409 unsigned AvailableRegs = OverrideMaxNumRegs > 0
411 :
TTI.getNumberOfRegisters(RegClass);
412 if (MaxUsers > AvailableRegs) {
415 unsigned Spills = MaxUsers - AvailableRegs;
417 TTI.getRegisterClassSpillCost(RegClass,
CostKind) +
418 TTI.getRegisterClassReloadCost(RegClass,
CostKind);
421 << Spills <<
" spills of "
422 <<
TTI.getRegisterClassName(RegClass) <<
"\n");
459 if (!VPBB->getParent())
465 for (
VPValue *U : R.operands()) {
468 EndPoint[U] = Idx2Recipe.
size();
488 EndPoint[WideIV] = Idx2Recipe.
size();
508 LLVM_DEBUG(
dbgs() <<
"LV(REG): Calculating max register usage:\n");
512 const auto &TTICapture =
TTI;
516 !TTICapture.isElementTypeLegalForScalableVector(Ty)))
524 OpenIntervals.
insert(CanIV);
530 for (
unsigned int Idx = 0, Sz = Idx2Recipe.
size(); Idx < Sz; ++Idx) {
534 VPValueList &
List = TransposeEnds[Idx];
540 if (
none_of(R->definedValues(),
541 [&Ends](
VPValue *Def) { return Ends.count(Def); }) &&
542 !R->mayHaveSideEffects())
554 for (
unsigned J = 0, E = VFs.
size(); J < E; ++J) {
562 for (
auto *VPV : OpenIntervals) {
573 if (VFs[J].isScalar() ||
587 unsigned ScaleFactor =
590 if (ScaleFactor > 1) {
591 VF = VFs[J].divideCoefficientBy(ScaleFactor);
593 <<
" to " << VF <<
" for " << *R <<
"\n";);
597 unsigned ClassID =
TTI.getRegisterClassForType(
true, ScalarTy);
598 RegUsage[ClassID] += GetRegUsage(ScalarTy, VF);
603 auto &Entry = MaxUsages[J][Pair.first];
604 Entry = std::max(Entry, Pair.second);
609 << OpenIntervals.
size() <<
'\n');
613 for (
VPValue *DefV : R->definedValues())
615 OpenIntervals.
insert(DefV);
623 for (
unsigned Idx = 0, End = VFs.
size(); Idx < End; ++Idx) {
629 for (
auto *In : LoopInvariants) {
635 unsigned ClassID =
TTI.getRegisterClassForType(
641 dbgs() <<
"LV(REG): VF = " << VFs[Idx] <<
'\n';
642 dbgs() <<
"LV(REG): Found max usage: " << MaxUsages[Idx].
size()
644 for (
const auto &pair : MaxUsages[Idx]) {
645 dbgs() <<
"LV(REG): RegisterClass: "
646 <<
TTI.getRegisterClassName(pair.first) <<
", " << pair.second
649 dbgs() <<
"LV(REG): Found invariant usage: " << Invariant.
size()
651 for (
const auto &pair : Invariant) {
652 dbgs() <<
"LV(REG): RegisterClass: "
653 <<
TTI.getRegisterClassName(pair.first) <<
", " << pair.second
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")
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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")))
std::pair< uint64_t, uint64_t > Interval
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
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),...
size_t size() const
Get the array size.
Implements a dense probed hash-table based set.
Core dominator tree base class.
bool properlyDominates(const DomTreeNodeBase< VPBlockBase > *A, const DomTreeNodeBase< VPBlockBase > *B) const
constexpr bool isVector() const
One or more elements.
static constexpr ElementCount getFixed(ScalarTy MinVal)
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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.
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 class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionalit...
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
A recipe for generating the active lane mask for the vector loop that is used to predicate the vector...
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
const VPBasicBlock * getEntryBasicBlock() const
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
A recipe for generating conditional branches on the bits of a mask.
A recipe for generating the phi node tracking the current scalar iteration index.
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B)
Recipe to expand a SCEV expression.
A recipe to combine multiple recipes into a single 'expression' recipe, which should be considered a ...
A specialization of VPInstruction augmenting it with a dedicated result type, to be used when the opc...
This is a concrete Recipe that models a single VPlan-level instruction.
@ ExtractLastActive
Extracts the last active lane from a set of vectors.
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
@ ExitingIVValue
Compute the exiting value of a wide induction after vectorization, that is the value of the last lane...
@ ExtractPenultimateElement
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
@ FirstOrderRecurrenceSplice
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
@ BuildVector
Creates a fixed-width vector containing all operands.
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
@ CanonicalIVIncrementForPart
@ ComputeReductionResult
Reduce the operands to the final reduction result using the operation specified via the operation's V...
@ CalculateTripCountMinusVF
A common base class for interleaved memory operations.
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
A recipe for handling reduction phis.
A recipe to represent inloop, ordered or partial reduction operations.
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
VPRegionValue * getCanonicalIV()
Return the canonical induction variable of the region, null for replicating regions.
const VPBlockBase * getExiting() const
VPValues defined by a VPRegionBlock, like the canonical IV.
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
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...
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
unsigned getNumUsers() const
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
A recipe to compute the pointers for widened memory accesses of SourceElementTy.
A recipe for widening Call instructions using library calls.
A Recipe for widening the canonical induction variable of the vector loop.
VPWidenCastRecipe is a recipe to create vector cast instructions.
A recipe for handling GEP instructions.
A recipe for widening vector intrinsics.
A common base class for widening memory operations.
A recipe for widened phis.
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPValue * getTripCount() const
The trip count of the original loop.
VPSymbolicValue & getVectorTripCount()
The vector trip count.
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
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)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void Calculate(DomTreeT &DT)
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
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.
void collectEphemeralRecipesForVPlan(VPlan &Plan, DenseSet< VPRecipeBase * > &EphRecipes)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
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...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
A MapVector that performs no allocations if smaller than a certain size.
A recipe for handling first-order recurrence phis.
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.