24#define DEBUG_TYPE "loop-vectorize"
41 bool verifyLastActiveLaneRecipe(
const VPInstruction &LastActiveLane)
const;
68bool VPlanVerifier::verifyPhiRecipes(
const VPBasicBlock *VPBB) {
69 auto RecipeI = VPBB->
begin();
70 auto End = VPBB->
end();
71 unsigned NumActiveLaneMaskPhiRecipes = 0;
73 while (RecipeI != End && RecipeI->isPhi()) {
75 NumActiveLaneMaskPhiRecipes++;
79 errs() <<
"Found non-header PHI recipe in header VPBB";
80#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
88 errs() <<
"Found header PHI recipe in non-header VPBB";
89#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
100 ? RecipeI->getIterator() != VPBB->
begin()
101 : RecipeI->getIterator() != VPBB->
begin() &&
102 RecipeI->getIterator() != std::next(VPBB->
begin()))) {
103 errs() <<
"CurrentIteration PHI is not the first/second recipe\n";
111 errs() <<
"Phi-like recipe with different number of operands and "
123 errs() <<
"There should be no more than one VPActiveLaneMaskPHIRecipe";
127 while (RecipeI != End) {
129 errs() <<
"Found phi-like recipe after non-phi recipe";
131#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
135 std::prev(RecipeI)->dump();
153 return WidenIV->isCanonical() || WidenIV->hasNoUnsignedWrap();
155 return match(Steps->getOperand(0),
165bool VPlanVerifier::verifyLastActiveLaneRecipe(
166 const VPInstruction &LastActiveLane)
const {
168 "must be called with VPInstruction::LastActiveLane");
171 errs() <<
"LastActiveLane must have at least one operand\n";
177 for (VPValue *
Op : LastActiveLane.
operands()) {
214 errs() <<
"LastActiveLane operand ";
215#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
217 Op->printAsOperand(
errs(), Tracker);
219 errs() <<
" must be prefix mask (a header mask or an "
220 "EVL-derived mask currently)\n";
227bool VPlanVerifier::verifyVPBasicBlock(
const VPBasicBlock *VPBB) {
228 if (!verifyPhiRecipes(VPBB))
232 DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
234 for (
const VPRecipeBase &R : *VPBB)
235 RecipeNumbering[&
R] = Cnt++;
237 for (
const VPRecipeBase &R : *VPBB) {
239 errs() <<
"VPIRInstructions ";
240#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
244 errs() <<
"not in a VPIRBasicBlock!\n";
247 for (
const VPValue *V :
R.definedValues()) {
249 if (!
V->getScalarType()) {
250 errs() <<
"VPValue without scalar type!\n";
259 for (
const VPUser *U :
V->users()) {
262 UI->getNumOperands() != UI->getParent()->getNumPredecessors()) {
263 errs() <<
"Phi-like recipe with different number of operands and "
269 for (
const auto &[IncomingVPV, IncomingVPBB] :
270 Phi->incoming_values_and_blocks()) {
271 if (IncomingVPV != V)
277 errs() <<
"Incoming def does not dominate incoming block!\n";
278#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
279 VPSlotTracker Tracker(VPBB->getPlan());
280 IncomingVPV->getDefiningRecipe()->print(
errs(),
" ", Tracker);
281 errs() <<
"\n does not dominate " << IncomingVPBB->getName()
283 UI->print(
errs(),
" ", Tracker);
295 if (UI->getParent() == VPBB) {
296 if (RecipeNumbering[UI] >= RecipeNumbering[&R])
299 if (VPDT.
dominates(VPBB, UI->getParent()))
306 bool BlockHasMaskedCond =
any_of(*VPBB, [](
const VPRecipeBase &R) {
309 if (BlockHasMaskedCond &&
310 any_of(VPBB->getPlan()->getExitBlocks(), [UI](VPIRBasicBlock *EB) {
311 return is_contained(EB->getPredecessors(), UI->getParent());
316 errs() <<
"Use before def!\n";
317#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
318 VPSlotTracker Tracker(VPBB->getPlan());
319 UI->print(
errs(),
" ", Tracker);
320 errs() <<
"\n before\n";
321 R.print(
errs(),
" ", Tracker);
328 switch (VPI->getOpcode()) {
330 if (!verifyLastActiveLaneRecipe(*VPI))
338 if (!DIV->getStartValue()->isDefinedOutsideLoopRegions()) {
339 errs() <<
"VPDerivedIVRecipe must have start value defined outside "
345 unsigned NumOps = ScalarIVSteps->getNumOperands();
347 errs() <<
"VPScalarIVStepsRecipe must have 3 or 4 operands\n";
357 if (!WrappedIRBBs.
insert(IRBB->getIRBasicBlock()).second) {
358 errs() <<
"Same IR basic block used by multiple wrapper blocks!\n";
365bool VPlanVerifier::verifyBlock(
const VPBlockBase *VPB) {
370 if (!VPBB->getParent()) {
374 <<
"Header block in plain CFG VPlan must have 2 predecessors!\n";
379 errs() <<
"Header's second predecessor must be the latch!\n";
386 errs() <<
"Latch block must have a branch terminator!\n";
391 errs() <<
"Latch's first successor must not be the header (must be "
397 (VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
398 if (!VPBB->getTerminator()) {
399 errs() <<
"Block has multiple successors but doesn't "
400 "have a proper branch recipe!\n";
403 }
else if (VPBB->getTerminator()) {
404 errs() <<
"Unexpected branch recipe!\n";
411 for (
const VPBlockBase *Succ : Successors) {
413 const auto &SuccPreds = Succ->getPredecessors();
415 errs() <<
"Missing predecessor link.\n";
423 for (
const VPBlockBase *Pred : Predecessors) {
425 if (Pred->getParent() != VPB->
getParent()) {
426 errs() <<
"Predecessor is not in the same region.\n";
431 const auto &PredSuccs = Pred->getSuccessors();
433 errs() <<
"Missing successor link.\n";
437 return !VPBB || verifyVPBasicBlock(VPBB);
440bool VPlanVerifier::verifyBlocksInRegion(
const VPRegionBlock *Region) {
444 errs() <<
"VPBlockBase has wrong parent\n";
448 if (!verifyBlock(VPB))
454bool VPlanVerifier::verifyRegion(
const VPRegionBlock *Region) {
456 const VPBlockBase *Exiting =
Region->getExiting();
459 if (
Entry->hasPredecessors()) {
460 errs() <<
"region entry block has predecessors\n";
464 errs() <<
"region exiting block has successors\n";
468 return verifyBlocksInRegion(Region);
471bool VPlanVerifier::verifyRegionRec(
const VPRegionBlock *Region) {
473 return verifyRegion(Region) &&
475 [
this](
const VPBlockBase *VPB) {
476 const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
477 return !SubRegion || verifyRegionRec(SubRegion);
481bool VPlanVerifier::verify(
const VPlan &Plan) {
483 [
this](
const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
491 if (!verifyRegionRec(TopRegion))
495 errs() <<
"VPlan Top Region should have no parent.\n";
501 errs() <<
"VPlan entry block is not a VPBasicBlock\n";
507 errs() <<
"VPlan exiting block is not a VPBasicBlock\n";
511 if (Exiting->
empty()) {
512 errs() <<
"VPlan vector loop exiting block must end with BranchOnCount, "
513 "BranchOnCond, or BranchOnTwoConds VPInstruction but is empty\n";
519 errs() <<
"VPlan vector loop exit must end with BranchOnCount, "
520 "BranchOnCond, or BranchOnTwoConds VPInstruction\n";
530 return Verifier.verify(Plan);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
verify safepoint Safepoint IR Verifier
This file defines the SmallPtrSet class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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 isKnownMonotonic(VPValue *V)
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:
@ ICMP_ULT
unsigned less than
@ ICMP_ULE
unsigned less or equal
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
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.
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 isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop latch, using isHeader().
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
VPBasicBlock * getParent()
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
const VPBlockBase * getExiting() const
unsigned getNumOperands() const
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
VPBasicBlock * getEntry()
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
AllRecipe_commutative_match< Instruction::And, Op0_t, Op1_t > m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1)
Match a binary AND operation.
VPInstruction_match< VPInstruction::StepVector > m_StepVector()
VPInstruction_match< VPInstruction::ActiveLaneMask, Op0_t, Op1_t, Op2_t > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
canonical_iv_match m_CanonicalIV()
auto m_VPValue()
Match an arbitrary VPValue and ignore it.
header_mask_match m_HeaderMask()
VPInstruction_match< VPInstruction::ExplicitVectorLength, Op0_t > m_EVL(const Op0_t &Op0)
match_bind< VPInstruction > m_VPInstruction(VPInstruction *&V)
Match a VPInstruction, capturing if we match.
auto m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
NodeAddr< PhiNode * > Phi
bool isUniformAcrossVFsAndUFs(const VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
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.
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 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.
DWARFExpression::Operation Op
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.
LLVM_ABI_FOR_TEST bool verifyVPlanIsValid(const VPlan &Plan)
Verify invariants for general VPlans.