48 #define DEBUG_TYPE "vplan" 63 return cast<VPBasicBlock>(Block);
70 return cast<VPBasicBlock>(Block);
78 return cast<VPBasicBlock>(Block);
85 return cast<VPBasicBlock>(Block);
89 if (!Successors.empty() || !Parent)
92 "Block w/o successors not the exit of its parent.");
97 if (!Predecessors.empty() || !Parent)
100 "Block w/o predecessors not the entry of its parent.");
127 assert(PredBB &&
"Predecessor basic-block not found building successor.");
130 if (isa<UnreachableInst>(PredBBTerminator)) {
131 assert(PredVPSuccessors.size() == 1 &&
132 "Predecessor ending w/o branch must have single successor.");
133 PredBBTerminator->eraseFromParent();
136 assert(PredVPSuccessors.size() == 2 &&
137 "Predecessor ending with branch must have two successors.");
138 unsigned idx = PredVPSuccessors.front() ==
this ? 0 : 1;
139 assert(!PredBBTerminator->getSuccessor(idx) &&
140 "Trying to reset an existing successor block.");
141 PredBBTerminator->setSuccessor(idx, NewBB);
167 NewBB = createEmptyBasicBlock(State->
CFG);
180 <<
" in BB:" << NewBB->
getName() <<
'\n');
194 if (!isReplicator()) {
197 LLVM_DEBUG(
dbgs() <<
"LV: VPBlock in RPO " << Block->getName() <<
'\n');
198 Block->execute(State);
203 assert(!State->
Instance &&
"Replicating a Region with non-null instance.");
208 for (
unsigned Part = 0, UF = State->
UF; Part < UF; ++Part) {
210 for (
unsigned Lane = 0, VF = State->
VF; Lane < VF; ++Lane) {
214 LLVM_DEBUG(
dbgs() <<
"LV: VPBlock in RPO " << Block->getName() <<
'\n');
215 Block->execute(State);
226 Parent->getRecipeList().insert(InsertPos->
getIterator(),
this);
230 return getParent()->getRecipeList().erase(getIterator());
238 Value *A = State.
get(getOperand(0), Part);
239 Value *
B = State.
get(getOperand(1), Part);
241 State.
set(
this, V, Part);
245 switch (getOpcode()) {
247 Value *A = State.
get(getOperand(0), Part);
249 State.
set(
this, V, Part);
259 for (
unsigned Part = 0; Part < State.
UF; ++Part)
260 generateInstruction(State, Part);
264 O <<
" +\n" << Indent <<
"\"EMIT ";
273 switch (getOpcode()) {
281 for (
const VPValue *Operand : operands()) {
283 Operand->printAsOperand(O);
292 for (
auto &Entry : Value2VPValue)
297 assert(VectorHeaderBB &&
"Loop preheader does not have a single successor.");
320 Block->execute(State);
326 "Expected VPlan CFG to terminate with unreachable");
333 assert(Merged &&
"Could not merge last basic block with latch.");
334 VectorLatchBB = LastBB;
336 updateDominatorTree(State->
DT, VectorPreHeaderBB, VectorLatchBB);
342 assert(LoopHeaderBB &&
"Loop preheader does not have a single successor.");
348 for (
auto *BB = LoopHeaderBB; BB != LoopLatchBB; BB = PostDomSucc) {
351 assert(Succs.size() <= 2 &&
352 "Basic block in vector loop has more than 2 successors.");
353 PostDomSucc = Succs[0];
354 if (Succs.size() == 1) {
355 assert(PostDomSucc->getSinglePredecessor() &&
356 "PostDom successor has more than one predecessor.");
361 if (PostDomSucc->getSingleSuccessor() == InterimSucc) {
362 PostDomSucc = Succs[1];
363 InterimSucc = Succs[0];
366 "One successor of a basic block does not lead to the other.");
368 "Interim successor has more than one predecessor.");
370 "PostDom successor has more than two predecessors.");
377 return (isa<VPRegionBlock>(Block) ?
"cluster_N" :
"N") +
378 Twine(getOrCreateBID(Block));
382 const std::string &Name = Block->
getName();
385 return "VPB" +
Twine(getOrCreateBID(Block));
388 void VPlanPrinter::dump() {
391 OS <<
"digraph VPlan {\n";
392 OS <<
"graph [labelloc=t, fontsize=30; label=\"Vectorization Plan";
393 if (!Plan.getName().empty())
395 if (!Plan.Value2VPValue.empty()) {
397 for (
auto Entry : Plan.Value2VPValue) {
398 OS <<
"\\n" << *Entry.second;
400 Entry.first->printAsOperand(OS,
false);
404 OS <<
"node [shape=rect, fontname=Courier, fontsize=30]\n";
405 OS <<
"edge [fontname=Courier, fontsize=30]\n";
406 OS <<
"compound=true\n";
414 void VPlanPrinter::dumpBlock(
const VPBlockBase *Block) {
429 OS <<
Indent << getUID(Tail) <<
" -> " << getUID(Head);
430 OS <<
" [ label=\"" << Label <<
'\"';
432 OS <<
" ltail=" << getUID(From);
434 OS <<
" lhead=" << getUID(To);
436 OS <<
"; splines=none";
440 void VPlanPrinter::dumpEdges(
const VPBlockBase *Block) {
442 if (Successors.size() == 1)
443 drawEdge(Block, Successors.front(),
false,
"");
444 else if (Successors.size() == 2) {
445 drawEdge(Block, Successors.front(),
false,
"T");
446 drawEdge(Block, Successors.back(),
false,
"F");
448 unsigned SuccessorNumber = 0;
455 OS <<
Indent << getUID(BasicBlock) <<
" [label =\n";
463 const VPValue *CBV = BasicBlock->getCondBit();
465 OS <<
" +\n" <<
Indent <<
" \"CondBit: ";
466 if (
const VPInstruction *CBI = dyn_cast<VPInstruction>(CBV)) {
467 CBI->printAsOperand(OS);
474 OS <<
"\n" <<
Indent <<
"]\n";
475 dumpEdges(BasicBlock);
479 OS <<
Indent <<
"subgraph " << getUID(Region) <<
" {\n";
481 OS <<
Indent <<
"fontname=Courier\n" 495 std::string IngredientString;
497 if (
auto *Inst = dyn_cast<Instruction>(V)) {
498 if (!Inst->getType()->isVoidTy()) {
499 Inst->printAsOperand(RSO,
false);
502 RSO << Inst->getOpcodeName() <<
" ";
503 unsigned E = Inst->getNumOperands();
505 Inst->getOperand(0)->printAsOperand(RSO,
false);
506 for (
unsigned I = 1;
I <
E; ++
I)
507 Inst->getOperand(
I)->printAsOperand(RSO <<
", ",
false);
516 O <<
" +\n" << Indent <<
"\"WIDEN\\l\"";
523 O <<
" +\n" << Indent <<
"\"WIDEN-INDUCTION";
533 O <<
" +\n" << Indent <<
"\"WIDEN-PHI " <<
VPlanIngredient(Phi) <<
"\\l\"";
537 O <<
" +\n" << Indent <<
"\"BLEND ";
538 Phi->printAsOperand(O,
false);
544 Phi->getIncomingValue(0)->printAsOperand(O,
false);
548 Phi->getIncomingValue(
I)->printAsOperand(O,
false);
558 << Indent <<
"\"" << (IsUniform ?
"CLONE " :
"REPLICATE ")
567 << Indent <<
"\"PHI-PREDICATED-INSTRUCTION " <<
VPlanIngredient(PredInst)
581 template void DomTreeBuilder::Calculate<VPDominatorTree>(
VPDominatorTree &DT);
const std::string & getName() const
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemoryDependenceResults *MemDep=nullptr, DeferredDominance *DDT=nullptr)
Attempts to merge a block into its predecessor, if possible.
void execute(struct VPTransformState *State)
Generate the IR code for this VPlan.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Compute iterated dominance frontiers using a linear time algorithm.
VPRegionBlock * getParent()
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
const VPBasicBlock * getExitBasicBlock() const
BlockT * getExit() const
Get the exit BasicBlock of the Region.
LLVMContext & getContext() const
Get the context in which this basic block lives.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Value * CreateNot(Value *V, const Twine &Name="")
void execute(VPTransformState &State) override
Generate the instruction.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void execute(struct VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock, thereby "executing" the VPlan.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const VPBasicBlock * getEntryBasicBlock() const
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
const VPBlockBase * getExit() const
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
VPBlockBase * getSingleHierarchicalSuccessor()
VPBlockBase * getSingleHierarchicalPredecessor()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
Interval::succ_iterator succ_end(Interval *I)
Core dominator tree base class.
const VPBlocksTy & getHierarchicalPredecessors()
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM Basic Block Representation.
std::string EscapeString(const std::string &Label)
This file contains the declarations of the Vectorization Plan base classes:
UnreachableInst * CreateUnreachable()
This function has undefined behavior.
const char * getOpcodeName() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
void printAsOperand(raw_ostream &OS, bool PrintType) const
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
void printAsOperand(raw_ostream &OS) const
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
static void deleteCFG(VPBlockBase *Entry)
Delete all blocks reachable from a given VPBlockBase, inclusive.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned getNumOperands() const
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Generic dominator tree construction - This file provides routines to construct immediate dominator in...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
void execute(struct VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPRegionBlock, thereby "executing" the VPlan.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
const VPBlocksTy & getSuccessors() const
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const VPBlockBase * getEntry() const
void print(raw_ostream &O, const Twine &Indent) const override
Print the recipe.
void print(raw_ostream &OS) const
const VPBlocksTy & getPredecessors() const
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned pred_size(const BasicBlock *BB)
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
iterator_range< df_iterator< T > > depth_first(const T &G)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
VPBasicBlock * getParent()
A raw_ostream that writes to an std::string.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
VPBlockBase * getEnclosingBlockWithPredecessors()
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This is a concrete Recipe that models a single VPlan-level instruction.
void print(raw_ostream &O, const Twine &Indent) const override
Print the Recipe.