24#define DEBUG_TYPE "loop-vectorize"
67 : VPDT(VPDT), TypeInfo(TypeInfo), VerifyLate(VerifyLate) {}
73bool VPlanVerifier::verifyPhiRecipes(
const VPBasicBlock *VPBB) {
74 auto RecipeI = VPBB->
begin();
75 auto End = VPBB->
end();
76 unsigned NumActiveLaneMaskPhiRecipes = 0;
78 while (RecipeI != End && RecipeI->isPhi()) {
80 NumActiveLaneMaskPhiRecipes++;
84 errs() <<
"Found non-header PHI recipe in header VPBB";
85#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
93 errs() <<
"Found header PHI recipe in non-header VPBB";
94#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
105 errs() <<
"Phi-like recipe with different number of operands and "
116 if (!VerifyLate && NumActiveLaneMaskPhiRecipes > 1) {
117 errs() <<
"There should be no more than one VPActiveLaneMaskPHIRecipe";
121 while (RecipeI != End) {
123 errs() <<
"Found phi-like recipe after non-phi recipe";
125#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
129 std::prev(RecipeI)->dump();
138bool VPlanVerifier::verifyEVLRecipe(
const VPInstruction &EVL)
const {
140 errs() <<
"verifyEVLRecipe should only be called on "
141 "VPInstruction::ExplicitVectorLength\n";
144 auto VerifyEVLUse = [&](
const VPRecipeBase &
R,
145 const unsigned ExpectedIdx) ->
bool {
147 unsigned UseCount =
count(
Ops, &EVL);
148 if (UseCount != 1 ||
Ops[ExpectedIdx] != &EVL) {
149 errs() <<
"EVL is used as non-last operand in EVL-based recipe\n";
154 return all_of(EVL.
users(), [
this, &VerifyEVLUse](VPUser *U) {
155 return TypeSwitch<const VPUser *, bool>(U)
156 .Case<VPWidenIntrinsicRecipe>([&](const VPWidenIntrinsicRecipe *S) {
157 return VerifyEVLUse(*S, S->getNumOperands() - 1);
159 .Case<VPWidenStoreEVLRecipe, VPReductionEVLRecipe,
160 VPWidenIntOrFpInductionRecipe, VPWidenPointerInductionRecipe>(
161 [&](
const VPRecipeBase *S) {
return VerifyEVLUse(*S, 2); })
162 .Case<VPScalarIVStepsRecipe>([&](
auto *R) {
163 if (
R->getNumOperands() != 3) {
164 errs() <<
"Unrolling with EVL tail folding not yet supported\n";
167 return VerifyEVLUse(*R, 2);
169 .Case<VPWidenLoadEVLRecipe, VPVectorEndPointerRecipe,
170 VPInterleaveEVLRecipe>(
171 [&](
const VPRecipeBase *R) {
return VerifyEVLUse(*R, 1); })
172 .Case<VPInstructionWithType>(
173 [&](
const VPInstructionWithType *S) {
return VerifyEVLUse(*S, 0); })
174 .Case<VPInstruction>([&](
const VPInstruction *
I) {
175 if (
I->getOpcode() == Instruction::PHI ||
176 I->getOpcode() == Instruction::ICmp ||
177 I->getOpcode() == Instruction::Sub)
178 return VerifyEVLUse(*
I, 1);
179 switch (
I->getOpcode()) {
180 case Instruction::Add:
182 case Instruction::UIToFP:
183 case Instruction::Trunc:
184 case Instruction::ZExt:
185 case Instruction::Mul:
186 case Instruction::FMul:
191 errs() <<
"EVL used by unexpected VPInstruction\n";
196 errs() <<
"EVL used by unexpected VPInstruction\n";
201 if ((
I->getNumUsers() != 1) &&
202 (
I->getNumUsers() != 2 ||
none_of(
I->users(), [&
I](VPUser *U) {
203 using namespace llvm::VPlanPatternMatch;
204 return match(U, m_BranchOnCount(m_Specific(I), m_VPValue()));
206 errs() <<
"EVL is used in VPInstruction with multiple users\n";
210 errs() <<
"Result of VPInstruction::Add with EVL operand is "
211 "not used by VPEVLBasedIVPHIRecipe\n";
216 .
Default([&](
const VPUser *U) {
217 errs() <<
"EVL has unexpected user\n";
223bool VPlanVerifier::verifyVPBasicBlock(
const VPBasicBlock *VPBB) {
224 if (!verifyPhiRecipes(VPBB))
228 DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
230 for (
const VPRecipeBase &R : *VPBB)
231 RecipeNumbering[&
R] = Cnt++;
233 for (
const VPRecipeBase &R : *VPBB) {
235 errs() <<
"VPIRInstructions ";
236#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
240 errs() <<
"not in a VPIRBasicBlock!\n";
243 for (
const VPValue *V :
R.definedValues()) {
248 errs() <<
"Failed to infer scalar type!\n";
252 for (
const VPUser *U :
V->users()) {
255 for (
const auto &[IncomingVPV, IncomingVPBB] :
256 Phi->incoming_values_and_blocks()) {
257 if (IncomingVPV != V)
263 errs() <<
"Incoming def does not dominate incoming block!\n";
264#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
265 VPSlotTracker Tracker(VPBB->getPlan());
266 IncomingVPV->getDefiningRecipe()->print(
errs(),
" ", Tracker);
267 errs() <<
"\n does not dominate " << IncomingVPBB->getName()
269 UI->print(
errs(),
" ", Tracker);
281 if (UI->getParent() == VPBB) {
282 if (RecipeNumbering[UI] >= RecipeNumbering[&R])
285 if (VPDT.
dominates(VPBB, UI->getParent()))
289 errs() <<
"Use before def!\n";
290#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
291 VPSlotTracker Tracker(VPBB->getPlan());
292 UI->print(
errs(),
" ", Tracker);
293 errs() <<
"\n before\n";
294 R.print(
errs(),
" ", Tracker);
302 !verifyEVLRecipe(*EVL)) {
303 errs() <<
"EVL VPValue is not used correctly\n";
313 if (!WrappedIRBBs.
insert(IRBB->getIRBasicBlock()).second) {
314 errs() <<
"Same IR basic block used by multiple wrapper blocks!\n";
325 for (
const auto *
Block : VPBlockVec) {
332bool VPlanVerifier::verifyBlock(
const VPBlockBase *VPB) {
337 (VPBB && VPBB->getParent() && VPBB->isExiting() &&
338 !VPBB->getParent()->isReplicator())) {
339 if (!VPBB || !VPBB->getTerminator()) {
340 errs() <<
"Block has multiple successors but doesn't "
341 "have a proper branch recipe!\n";
345 if (VPBB && VPBB->getTerminator()) {
346 errs() <<
"Unexpected branch recipe!\n";
357 errs() <<
"Multiple instances of the same successor.\n";
361 for (
const VPBlockBase *Succ : Successors) {
363 const auto &SuccPreds = Succ->getPredecessors();
365 errs() <<
"Missing predecessor link.\n";
376 errs() <<
"Multiple instances of the same predecessor.\n";
380 for (
const VPBlockBase *Pred : Predecessors) {
382 if (Pred->getParent() != VPB->
getParent()) {
383 errs() <<
"Predecessor is not in the same region.\n";
388 const auto &PredSuccs = Pred->getSuccessors();
390 errs() <<
"Missing successor link.\n";
394 return !VPBB || verifyVPBasicBlock(VPBB);
397bool VPlanVerifier::verifyBlocksInRegion(
const VPRegionBlock *Region) {
401 errs() <<
"VPBlockBase has wrong parent\n";
405 if (!verifyBlock(VPB))
411bool VPlanVerifier::verifyRegion(
const VPRegionBlock *Region) {
413 const VPBlockBase *Exiting =
Region->getExiting();
416 if (
Entry->hasPredecessors()) {
417 errs() <<
"region entry block has predecessors\n";
421 errs() <<
"region exiting block has successors\n";
425 return verifyBlocksInRegion(Region);
428bool VPlanVerifier::verifyRegionRec(
const VPRegionBlock *Region) {
430 return verifyRegion(Region) &&
432 [
this](
const VPBlockBase *VPB) {
433 const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
434 return !SubRegion || verifyRegionRec(SubRegion);
438bool VPlanVerifier::verify(
const VPlan &Plan) {
440 [
this](
const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
448 if (!verifyRegionRec(TopRegion))
452 errs() <<
"VPlan Top Region should have no parent.\n";
458 errs() <<
"VPlan entry block is not a VPBasicBlock\n";
463 errs() <<
"VPlan vector loop header does not start with a "
464 "VPCanonicalIVPHIRecipe\n";
470 errs() <<
"VPlan exiting block is not a VPBasicBlock\n";
474 if (Exiting->
empty()) {
475 errs() <<
"VPlan vector loop exiting block must end with BranchOnCount or "
476 "BranchOnCond VPInstruction but is empty\n";
483 errs() <<
"VPlan vector loop exit must end with BranchOnCount or "
484 "BranchOnCond VPInstruction\n";
495 VPlanVerifier
Verifier(VPDT, TypeInfo, VerifyLate);
496 return Verifier.verify(Plan);
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
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.
static bool hasDuplicates(const SmallVectorImpl< VPBlockBase * > &VPBlockVec)
Utility function that checks whether VPBlockVec has duplicate VPBlockBases.
This file declares the class VPlanVerifier, which contains utility functions to check the consistency...
This file contains the declarations of the Vectorization Plan base classes:
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Implements a dense probed hash-table based set with some number of buckets stored inline.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
iterator begin()
Recipe iterator methods.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
VPRegionBlock * getParent()
size_t getNumSuccessors() const
size_t getNumPredecessors() const
const VPBlocksTy & getPredecessors() const
const VPBlocksTy & getSuccessors() const
static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop header, based on regions or VPDT in their absence.
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
This is a concrete Recipe that models a single VPlan-level instruction.
unsigned getOpcode() const
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
const VPBlockBase * getExiting() const
An analysis for type-inference for VPValues.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPBasicBlock * getEntry()
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
std::pair< iterator, bool > insert(const ValueT &V)
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI_FOR_TEST bool verifyVPlanIsValid(const VPlan &Plan, bool VerifyLate=false)
Verify invariants for general VPlans.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< df_iterator< VPBlockShallowTraversalWrapper< VPBlockBase * > > > vp_depth_first_shallow(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.