15#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANHELPERS_H
16#define LLVM_TRANSFORMS_VECTORIZE_VPLANHELPERS_H
67 return End.getKnownMinValue() <=
Start.getKnownMinValue();
73 "Both Start and End should have the same scalable flag");
75 "Expected Start to be a power of 2");
77 "Expected End to be a power of 2");
136 VPLane(
unsigned Lane,
Kind LaneKind) : Lane(Lane), LaneKind(LaneKind) {}
142 "trying to extract with invalid offset");
151 return VPLane(LaneOffset, LaneKind);
162 "can only get known lane from the beginning");
181 "ScalableLast can only be used with scalable VFs");
185 "Cannot extract lane larger than VF");
220 return Data.VPV2Vector.contains(Def);
224 auto I =
Data.VPV2Scalars.find(Def);
225 if (
I ==
Data.VPV2Scalars.end())
228 return CacheIdx <
I->second.size() &&
I->second[CacheIdx];
239 "scalar values must be stored as (0, 0)");
240 Data.VPV2Vector[Def] = V;
245 assert(
Data.VPV2Vector.contains(Def) &&
"need to overwrite existing value");
246 Data.VPV2Vector[Def] = V;
251 auto &Scalars =
Data.VPV2Scalars[Def];
253 if (Scalars.size() <= CacheIdx)
254 Scalars.resize(CacheIdx + 1);
255 assert(!Scalars[CacheIdx] &&
"should overwrite existing value");
256 Scalars[CacheIdx] = V;
261 auto Iter =
Data.VPV2Scalars.find(Def);
263 "need to overwrite existing value");
265 assert(CacheIdx < Iter->second.size() &&
266 "need to overwrite existing value");
267 Iter->second[CacheIdx] = V;
345 bool ReusePrintingSlotTracker =
false);
381 bool AlwaysIncludeReplicatingR =
false);
391#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
400 const VPlan *PlanForSlotTracker =
nullptr;
403 std::unique_ptr<VPSlotTracker> SlotTracker;
421 unsigned NextSlot = 0;
425 std::unique_ptr<ModuleSlotTracker> MST;
431 const Module *M =
nullptr;
433 void assignName(
const VPValue *V);
436 std::string getName(
const Value *V);
443 M = ScalarHeader->getIRBasicBlock()->getModule();
454 if (MDNames.empty() && M)
455 M->getContext().getMDKindNames(MDNames);
463#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
470 unsigned TabWidth = 2;
478 void bumpIndent(
int b) { Indent = std::string((Depth += b) * TabWidth,
' '); }
506 : OS(O), Plan(
P), SlotTracker(&
P) {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_ABI_FOR_TEST
This file defines the DenseMap class.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
This class represents a function call, abstracting a target machine's calling convention.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Common base class shared among various IRBuilders.
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
This is an important class for using LLVM in a threaded context.
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This class represents an analyzed expression in the program.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Provides information about what library functions are available for the current target.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
Iterator to iterate over vectorization factors in a VFRange.
ElementCount operator*() const
iterator(ElementCount VF)
bool operator==(const iterator &Other) const
Holds state needed to make cost decisions before computing costs per-VF, including the maximum VFs.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
static VPLane getLastLaneForVF(const ElementCount &VF)
Value * getAsRuntimeExpr(IRBuilderBase &Builder, const ElementCount &VF) const
Returns an expression describing the lane index that can be used at runtime.
VPLane(unsigned Lane, Kind LaneKind)
Kind getKind() const
Returns the Kind of lane offset.
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset)
bool isFirstLane() const
Returns true if this is the first lane of the whole vector.
unsigned getKnownLane() const
Returns a compile-time known value for the lane index and asserts if the lane can only be calculated ...
static VPLane getFirstLane()
Kind
Kind describes how to interpret Lane.
@ ScalableLast
For ScalableLast, Lane is the offset from the start of the last N-element subvector in a scalable vec...
@ First
For First, Lane is the index into the first N elements of a fixed-vector <N x <ElTy>> or a scalable v...
unsigned mapToCacheIndex(const ElementCount &VF) const
Maps the lane to a cache index based on VF.
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
This class can be used to assign names to VPValues.
ArrayRef< StringRef > getMDNames()
Returns the cached metadata kind names.
std::string getOrCreateName(const VPValue *V) const
Returns the name assigned to V, if there is one, otherwise try to construct one from the underlying v...
const Module * getModule() const
Returns the cached Module pointer.
VPSlotTracker(const VPlan *Plan=nullptr)
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
VPlanPrinter(raw_ostream &O, const VPlan &P)
LLVM_DUMP_METHOD void dump()
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
LLVM Value Representation.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
This class implements an extremely fast bulk output stream that can only output to a stream.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
This is an optimization pass for GlobalISel generic memory operations.
Value * getRuntimeVF(IRBuilderBase &B, Type *Ty, ElementCount VF)
Return the runtime value for VF.
bool isVectorizedTy(Type *Ty)
Returns true if Ty is a vector type or a struct of vector types where all vector types share the same...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool canConstantBeExtended(const APInt *C, Type *NarrowType, TTI::PartialReductionExtendKind ExtKind)
Check if a constant CI can be safely treated as having been extended from a narrower type with the gi...
VFRange(const ElementCount &Start, const ElementCount &End)
const VFSelectionContext & Config
LoopVectorizationCostModel & CM
TargetTransformInfo::OperandValueInfo getOperandInfo(VPValue *V) const
Returns the OperandInfo for V, if it is a live-in.
VPCostContext(const TargetLibraryInfo &TLI, const VPlan &Plan, LoopVectorizationCostModel &CM, VFSelectionContext &Config, bool ReusePrintingSlotTracker=false)
static bool isFreeScalarIntrinsic(Intrinsic::ID ID)
Returns true if ID is a pseudo intrinsic that is dropped via scalarization rather than widened.
bool skipCostComputation(Instruction *UI, bool IsVector) const
Return true if the cost for UI shouldn't be computed, e.g.
InstructionCost getLegacyCost(Instruction *UI, ElementCount VF) const
Return the cost for UI with VF using the legacy cost model as fallback until computing the cost of al...
bool isMaskRequired(Instruction *I) const
Forwards to LoopVectorizationCostModel::isMaskRequired.
void invalidateWideningDecision(Instruction *I, ElementCount VF)
Mark the widening decision for I at VF as invalidated since a VPlan transform replaced the original r...
PredicatedScalarEvolution & PSE
bool willBeScalarized(Instruction *I, ElementCount VF) const
Returns true if I is known to be scalarized at VF.
uint64_t getPredBlockCostDivisor(BasicBlock *BB) const
std::optional< unsigned > NumPredStores
Number of predicated stores in the VPlan, computed on demand.
InstructionCost getScalarizationOverhead(Type *ResultTy, ArrayRef< const VPValue * > Operands, ElementCount VF, TTI::VectorInstrContext VIC=TTI::VectorInstrContext::None, bool AlwaysIncludeReplicatingR=false)
Estimate the overhead of scalarizing a recipe with result type ResultTy and Operands with VF.
TargetTransformInfo::TargetCostKind CostKind
VPSlotTracker * getSlotTracker()
Return a VPSlotTracker to re-use for printing, lazily constructing it on first use.
const TargetLibraryInfo & TLI
const TargetTransformInfo & TTI
SmallPtrSet< Instruction *, 8 > SkipCostComputation
bool useEmulatedMaskMemRefHack(const VPReplicateRecipe *R, ElementCount VF)
Returns true if an artificially high cost for emulated masked memrefs should be used.