26 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_H 27 #define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H 50 class LoopVectorizationLegality;
51 class LoopVectorizationCostModel;
54 class InnerLoopVectorizer;
55 class InterleaveGroup;
121 std::map<Value *, VectorParts> VectorMapStorage;
122 std::map<Value *, ScalarParts> ScalarMapStorage;
130 return VectorMapStorage.count(Key);
135 assert(Part < UF &&
"Queried Vector Part is too large.");
136 if (!hasAnyVectorValue(Key))
138 const VectorParts &Entry = VectorMapStorage.find(Key)->second;
139 assert(Entry.
size() == UF &&
"VectorParts has wrong dimensions.");
140 return Entry[Part] !=
nullptr;
145 return ScalarMapStorage.count(Key);
150 assert(Instance.
Part < UF &&
"Queried Scalar Part is too large.");
151 assert(Instance.
Lane < VF &&
"Queried Scalar Lane is too large.");
152 if (!hasAnyScalarValue(Key))
154 const ScalarParts &Entry = ScalarMapStorage.find(Key)->second;
155 assert(Entry.
size() == UF &&
"ScalarParts has wrong dimensions.");
157 "ScalarParts has wrong dimensions.");
158 return Entry[Instance.
Part][Instance.
Lane] !=
nullptr;
164 assert(hasVectorValue(Key, Part) &&
"Getting non-existent value.");
165 return VectorMapStorage[
Key][Part];
171 assert(hasScalarValue(Key, Instance) &&
"Getting non-existent value.");
172 return ScalarMapStorage[
Key][Instance.
Part][Instance.
Lane];
178 assert(!hasVectorValue(Key, Part) &&
"Vector value already set for part");
179 if (!VectorMapStorage.count(Key)) {
181 VectorMapStorage[
Key] = Entry;
183 VectorMapStorage[
Key][Part] = Vector;
189 assert(!hasScalarValue(Key, Instance) &&
"Scalar value already set");
190 if (!ScalarMapStorage.count(Key)) {
194 for (
unsigned Part = 0; Part < UF; ++Part)
195 Entry[Part].resize(VF,
nullptr);
196 ScalarMapStorage[
Key] = Entry;
206 assert(hasVectorValue(Key, Part) &&
"Vector value not set for part");
207 VectorMapStorage[
Key][Part] = Vector;
216 assert(hasScalarValue(Key, Instance) &&
217 "Scalar value not set for part and lane");
226 virtual Value *getOrCreateVectorValues(
Value *V,
unsigned Part) = 0;
235 : VF(VF), UF(UF), Instance(), LI(LI), DT(DT), Builder(Builder),
236 ValueMap(ValueMap), ILV(ILV), Callback(Callback) {}
263 if (
Data.PerPartOutput.count(Def))
264 return Data.PerPartOutput[Def][Part];
266 return Callback.getOrCreateVectorValues(VPValue2Value[Def], Part);
271 if (!
Data.PerPartOutput.count(Def)) {
273 Data.PerPartOutput[
Def] = Entry;
275 Data.PerPartOutput[
Def][Part] = V;
328 const unsigned char SubclassID;
348 assert(Successor &&
"Cannot add nullptr successor!");
354 assert(Predecessor &&
"Cannot add nullptr predecessor!");
361 assert(Pos &&
"Predecessor does not exist");
362 Predecessors.
erase(Pos);
368 assert(Pos &&
"Successor does not exist");
369 Successors.
erase(Pos);
374 : SubclassID(SC), Name(N) {}
381 using VPBlockTy =
enum { VPBasicBlockSC, VPRegionBlockSC };
422 return (Successors.
size() == 1 ? *Successors.
begin() :
nullptr);
428 return (Predecessors.
size() == 1 ? *Predecessors.
begin() :
nullptr);
488 assert(Successors.
empty() &&
"Setting one successor when others exist.");
489 appendSuccessor(Successor);
498 assert(Successors.
empty() &&
"Setting two successors when others exist.");
499 assert(Condition &&
"Setting two successors without condition!");
501 appendSuccessor(IfTrue);
502 appendSuccessor(IfFalse);
509 assert(Predecessors.
empty() &&
"Block predecessors already set.");
510 for (
auto *Pred : NewPreds)
511 appendPredecessor(Pred);
528 printAsOperand(OS,
false);
545 const unsigned char SubclassID;
562 VPWidenIntOrFpInductionSC,
563 VPWidenMemoryInstructionSC,
606 enum { Not = Instruction::OtherOpsEnd + 1 };
609 typedef unsigned char OpcodeTy;
695 :
VPRecipeBase(VPWidenIntOrFpInductionSC), IV(IV), Trunc(Trunc) {}
700 return V->
getVPRecipeID() == VPRecipeBase::VPWidenIntOrFpInductionSC;
739 std::unique_ptr<VPUser>
User;
746 "Expected the same number of incoming values and masks");
748 User.reset(
new VPUser(Masks));
808 :
VPRecipeBase(VPReplicateSC), Ingredient(I), IsUniform(IsUniform),
809 IsPredicated(IsPredicated) {
815 AlsoPack = IsPredicated && !I->
use_empty();
839 std::unique_ptr<VPUser>
User;
844 User.reset(
new VPUser({BlockInMask}));
858 O <<
" +\n" << Indent <<
"\"BRANCH-ON-MASK ";
860 O << *User->getOperand(0);
901 std::unique_ptr<VPUser>
User;
905 :
VPRecipeBase(VPWidenMemoryInstructionSC), Instr(Instr) {
907 User.reset(
new VPUser({Mask}));
912 return V->
getVPRecipeID() == VPRecipeBase::VPWidenMemoryInstructionSC;
937 appendRecipe(Recipe);
961 inline size_t size()
const {
return Recipes.size(); }
962 inline bool empty()
const {
return Recipes.empty(); }
973 return &VPBasicBlock::Recipes;
978 return V->
getVPBlockID() == VPBlockBase::VPBasicBlockSC;
982 assert(Recipe &&
"No recipe to append.");
983 assert(!Recipe->Parent &&
"Recipe already in VPlan");
984 Recipe->Parent =
this;
985 Recipes.
insert(InsertPt, Recipe);
1024 const std::string &Name =
"",
bool IsReplicator =
false)
1025 :
VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exit(Exit),
1026 IsReplicator(IsReplicator) {
1033 :
VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exit(nullptr),
1034 IsReplicator(IsReplicator) {}
1043 return V->
getVPBlockID() == VPBlockBase::VPRegionBlockSC;
1053 "Entry block cannot have predecessors.");
1071 "Exit block cannot have successors.");
1123 for (
auto &MapEntry : Value2VPValue)
1124 delete MapEntry.second;
1148 VPExternalDefs.
insert(VPVal);
1152 assert(V &&
"Trying to add a null Value to VPlan");
1153 assert(!Value2VPValue.
count(V) &&
"Value already exists in VPlan");
1154 Value2VPValue[V] =
new VPValue();
1158 assert(V &&
"Trying to get the VPValue of a null Value");
1159 assert(Value2VPValue.
count(V) &&
"Value does not exist in VPlan");
1160 return Value2VPValue[V];
1186 unsigned TabWidth = 2;
1194 void bumpIndent(
int b) { Indent = std::string((Depth += b) * TabWidth,
' '); }
1210 unsigned getOrCreateBID(
const VPBlockBase *Block) {
1211 return BlockID.
count(Block) ? BlockID[Block] : BlockID[Block] = BID++;
1220 const Twine &Label);
1234 VPlanPrinter::printAsIngredient(OS, I.
V);
1352 return N.
Graph->getExit();
1382 "Can't insert new block with successors.");
1400 "Can't insert IfTrue with successors.");
1402 "Can't insert IfFalse with successors.");
1416 "Can't connect two block with different parents");
1418 "Blocks can't have more than two successors.");
1419 From->appendSuccessor(To);
1420 To->appendPredecessor(From);
1426 assert(To &&
"Successor to disconnect is null.");
1427 From->removeSuccessor(To);
1428 To->removePredecessor(From);
1434 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H const std::string & getName() const
VPWidenRecipe(Instruction *I)
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
const VPRegionBlock * getParent() const
bool appendInstruction(Instruction *Instr)
Augment the recipe to include Instr, if it lies at its End.
static NodeRef getEntryNode(Inverse< GraphRef > N)
void setAlsoPack(bool Pack)
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
enum { VPBasicBlockSC, VPRegionBlockSC } VPBlockTy
An enumeration for keeping track of the concrete subclass of VPBlockBase that are actually instantiat...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
VectorizerValueMap(unsigned UF, unsigned VF)
Construct an empty map with the given unroll and vectorization factors.
SmallVectorImpl< VPBlockBase * >::const_iterator ChildIteratorType
Compute iterated dominance frontiers using a linear time algorithm.
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exit, const std::string &Name="", bool IsReplicator=false)
const_reverse_iterator rbegin() const
static NodeRef getEntryNode(GraphRef N)
VPRegionBlock * getParent()
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPInstruction(unsigned Opcode, ArrayRef< VPValue *> Operands)
Value * getScalarValue(Value *Key, const VPIteration &Instance)
Retrieve the existing scalar value that corresponds to Key and Instance.
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
VPlanIngredient(Value *V)
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
enum { VPBlendSC, VPBranchOnMaskSC, VPInstructionSC, VPInterleaveSC, VPPredInstPHISC, VPReplicateSC, VPWidenIntOrFpInductionSC, VPWidenMemoryInstructionSC, VPWidenPHISC, VPWidenSC, } VPRecipeTy
An enumeration for keeping track of the concrete subclass of VPRecipeBase that is actually instantiat...
This is a helper struct for maintaining vectorization state.
A Recipe for widening load/store operations.
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
bool hasAnyScalarValue(Value *Key) const
void addExternalDef(VPValue *VPVal)
Add VPVal to the pool of external definitions if it's not already in the pool.
VPBlockBase * getSingleSuccessor() const
void addVPValue(Value *V)
print alias Alias Set Printer
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
unsigned getVPRecipeID() const
VPValue * getVPValue(Value *V)
bool hasAnyVectorValue(Value *Key) const
static bool classof(const VPRecipeBase *R)
Method to support type inquiry through isa, cast, and dyn_cast.
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
const VPBlocksTy & getHierarchicalSuccessors()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBase NewBlock after BlockPtr.
bool hasVectorValue(Value *Key, unsigned Part) const
VPBlocksTy & getSuccessors()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static StringRef getName(Value *V)
A recipe for handling all phi nodes except for integer and FP inductions.
~VPRegionBlock() override
void setName(const Twine &newName)
void insert(VPRecipeBase *Recipe, iterator InsertPt)
const std::string & getName() const
VPBlocksTy & getPredecessors()
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
static ChildIteratorType child_end(NodeRef N)
void setName(const Twine &newName)
VPWidenPHIRecipe(PHINode *Phi)
static ChildIteratorType child_begin(NodeRef N)
VPBlockBase * getSinglePredecessor() const
VPlanPrinter prints a given VPlan to a given output stream.
static ChildIteratorType child_end(NodeRef N)
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
static nodes_iterator nodes_begin(GraphRef N)
static NodeRef getEntryNode(GraphRef N)
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
This class is used to enable the VPlan to invoke a method of ILV.
The group of interleaved loads/stores sharing the same stride and close to each other.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const VPBlockBase * getExit() const
VPBlockBase * getSingleHierarchicalSuccessor()
VPBlockBase * getSingleHierarchicalPredecessor()
unsigned getVPBlockID() const
static bool classof(const VPValue *V)
Method to support type inquiry through isa, cast, and dyn_cast.
unsigned getVPValueID() const
VPInstruction(unsigned Opcode, std::initializer_list< VPValue *> Operands)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
This class represents a truncation of integer types.
iterator begin()
Recipe iterator methods.
void resetScalarValue(Value *Key, const VPIteration &Instance, Value *Scalar)
Reset the scalar value associated with Key for Part and Lane.
bool isLegalToHoistInto()
Return true if it is legal to hoist instructions into this block.
SmallVectorImpl< VPBlockBase * >::iterator ChildIteratorType
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe...
const VPBlocksTy & getHierarchicalPredecessors()
static nodes_iterator nodes_end(GraphRef N)
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
An ilist node that can access its parent list.
typename VPBlockBase *::UnknownGraphTypeError NodeRef
void setOneSuccessor(VPBlockBase *Successor)
Set a given VPBlockBase Successor as the single successor of this VPBlockBase.
const InterleaveGroup * getInterleaveGroup()
VPWidenMemoryInstructionRecipe(Instruction &Instr, VPValue *Mask)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
static ChildIteratorType child_begin(NodeRef N)
VPBlendRecipe(PHINode *Phi, ArrayRef< VPValue *> Masks)
void setExit(VPBlockBase *ExitBlock)
Set ExitBlock as the exit VPBlockBase of this VPRegionBlock.
This file defines VPLoopInfo analysis and VPLoop class.
reverse_iterator rbegin()
LLVM Basic Block Representation.
const VPValue * getCondBit() const
size_t size() const
size - Get the array size.
bool hasScalarValue(Value *Key, const VPIteration &Instance) const
VPWidenIntOrFpInductionRecipe(PHINode *IV, TruncInst *Trunc=nullptr)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
size_t getNumPredecessors() const
static NodeRef getEntryNode(NodeRef N)
std::unique_ptr< VPlan > VPlanPtr
static ChildIteratorType child_end(NodeRef N)
void printAsOperand(raw_ostream &OS, bool PrintType) const
size_t getNumSuccessors() const
VPBlockBase * setEntry(VPBlockBase *Block)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPBlockBase & front() const
SmallVectorImpl< VPBlockBase * >::iterator ChildIteratorType
iterator erase(const_iterator CI)
static void connectBlocks(VPBlockBase *From, VPBlockBase *To)
Connect VPBlockBases From and To bi-directionally.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
void setScalarValue(Value *Key, const VPIteration &Instance, Value *Scalar)
Set a scalar value associated with Key and Instance.
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
static nodes_iterator nodes_end(GraphRef N)
static void deleteCFG(VPBlockBase *Entry)
Delete all blocks reachable from a given VPBlockBase, inclusive.
void setPredecessors(ArrayRef< VPBlockBase *> NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
VPBlockBase(const unsigned char SC, const std::string &N)
const_iterator begin() const
const VPRecipeBase & back() const
Iterator for intrusive lists based on ilist_node.
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse, VPValue *Condition)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse, VPValue *Condition, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBases IfTrue and IfFalse after BlockPtr.
A range of powers-of-2 vectorization factors with fixed start and adjustable end. ...
const VPRecipeBase & front() const
VPLoopInfo & getVPLoopInfo()
Return the VPLoopInfo analysis for this VPlan.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
static NodeRef getEntryNode(Inverse< NodeRef > B)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
VPReplicateRecipe(Instruction *I, bool IsUniform, bool IsPredicated=false)
Class that provides utilities for VPBlockBases in VPlan.
static NodeRef getEntryNode(NodeRef N)
CHAIN = SC CHAIN, Imm128 - System call.
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
void setCondBit(VPValue *CV)
const VPBlocksTy & getSuccessors() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
const VPBlockBase * getEntry() const
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
void resetVectorValue(Value *Key, unsigned Part, Value *Vector)
Reset the vector value associated with Key for the given Part.
VPRegionBlock(const std::string &Name="", bool IsReplicator=false)
const VPBasicBlock * getParent() const
void print(raw_ostream &OS) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
VPInterleaveRecipe(const InterleaveGroup *IG)
iterator insert(iterator where, pointer New)
const VPBlocksTy & getPredecessors() const
static nodes_iterator nodes_begin(GraphRef N)
Value * getVectorValue(Value *Key, unsigned Part)
Retrieve the existing vector value that corresponds to Key and Part.
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
LLVM_NODISCARD bool empty() const
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPRecipeBase(const unsigned char SC)
VPPredInstPHIRecipe(Instruction *PredInst)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
const VPBlockBase * getEntry() const
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPlan(VPBlockBase *Entry=nullptr)
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector and ...
unsigned getOpcode() const
const_iterator end() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::string str() const
Return the twine contents as a std::string.
void setVectorValue(Value *Key, unsigned Part, Value *Vector)
Set a vector value associated with Key and Part.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPBasicBlock * getParent()
VPWidenRecipe is a recipe for producing a copy of vector type for each Instruction in its ingredients...
This file contains the declarations of the entities induced by Vectorization Plans, e.g.
LLVM Value Representation.
A recipe for generating conditional branches on the bits of a mask.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static ChildIteratorType child_begin(NodeRef N)
This class implements an extremely fast bulk output stream that can only output to a stream...
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
static nodes_iterator nodes_end(GraphRef N)
static bool classof(const VPRecipeBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
This is a concrete Recipe that models a single VPlan-level instruction.
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
VPBranchOnMaskRecipe(VPValue *BlockInMask)
const_reverse_iterator rend() const
static nodes_iterator nodes_begin(GraphRef N)
VPBasicBlock(const Twine &Name="", VPRecipeBase *Recipe=nullptr)
void setParent(VPRegionBlock *P)
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
bool empty() const
empty - Check if the array is empty.
const VPLoopInfo & getVPLoopInfo() const
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.