25#define DEBUG_TYPE "loop-vectorize"
43 bool verifyLastActiveLaneRecipe(
const VPInstruction &LastActiveLane)
const;
71 : VPDT(VPDT), TypeInfo(TypeInfo) {}
77bool VPlanVerifier::verifyPhiRecipes(
const VPBasicBlock *VPBB) {
78 auto RecipeI = VPBB->
begin();
79 auto End = VPBB->
end();
80 unsigned NumActiveLaneMaskPhiRecipes = 0;
82 while (RecipeI != End && RecipeI->isPhi()) {
84 NumActiveLaneMaskPhiRecipes++;
88 errs() <<
"Found non-header PHI recipe in header VPBB";
89#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
97 errs() <<
"Found header PHI recipe in non-header VPBB";
98#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
106 RecipeI->getIterator() != VPBB->
begin()) {
107 errs() <<
"CurrentIteration PHI is not the first recipe\n";
115 errs() <<
"Phi-like recipe with different number of operands and "
127 errs() <<
"There should be no more than one VPActiveLaneMaskPHIRecipe";
131 while (RecipeI != End) {
133 errs() <<
"Found phi-like recipe after non-phi recipe";
135#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
139 std::prev(RecipeI)->dump();
157 return WidenIV->isCanonical() || WidenIV->hasNoUnsignedWrap();
159 return match(Steps->getOperand(0),
169bool VPlanVerifier::verifyLastActiveLaneRecipe(
170 const VPInstruction &LastActiveLane)
const {
172 "must be called with VPInstruction::LastActiveLane");
175 errs() <<
"LastActiveLane must have at least one operand\n";
182 for (VPValue *
Op : LastActiveLane.
operands()) {
195 errs() <<
"LastActiveLane operand ";
196#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
197 VPSlotTracker Tracker(&Plan);
198 Op->printAsOperand(
errs(), Tracker);
200 errs() <<
" must be prefix mask (a header mask or an "
201 "EVL-derived mask currently)\n";
208bool VPlanVerifier::verifyRecipeTypes(
const VPRecipeBase &R)
const {
213 auto CheckScalarType = [&](
Type *Derived) ->
bool {
214 if (Derived == SR->getScalarType())
216 errs() <<
"Recipe result type does not match type derived from operands";
217#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
225 auto CheckOperandTypes = [&]() ->
bool {
227 return getScalarTypeOrInfer(R.getOperand(0)) ==
228 getScalarTypeOrInfer(Op);
231 errs() <<
"Recipe operand types do not match";
232#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
241 return CheckScalarType(WII->getTruncInst()
242 ? WII->getTruncInst()->getType()
243 : WII->getStartValue()->getScalarType());
245 switch (
R.getVPRecipeID()) {
246 case VPRecipeBase::VPVectorPointerSC:
247 case VPRecipeBase::VPVectorEndPointerSC:
248 case VPRecipeBase::VPWidenGEPSC:
249 case VPRecipeBase::VPScalarIVStepsSC:
250 case VPRecipeBase::VPWidenPointerInductionSC:
251 case VPRecipeBase::VPDerivedIVSC:
253 case VPRecipeBase::VPWidenPHISC:
254 case VPRecipeBase::VPPredInstPHISC:
255 case VPRecipeBase::VPReductionPHISC:
256 case VPRecipeBase::VPActiveLaneMaskPHISC:
257 case VPRecipeBase::VPCurrentIterationPHISC:
258 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
259 return CheckOperandTypes() &&
267bool VPlanVerifier::verifyVPBasicBlock(
const VPBasicBlock *VPBB) {
268 if (!verifyPhiRecipes(VPBB))
272 DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
274 for (
const VPRecipeBase &R : *VPBB)
275 RecipeNumbering[&
R] = Cnt++;
277 for (
const VPRecipeBase &R : *VPBB) {
279 errs() <<
"VPIRInstructions ";
280#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
284 errs() <<
"not in a VPIRBasicBlock!\n";
287 if (!verifyRecipeTypes(R))
289 for (
const VPValue *V :
R.definedValues()) {
294 errs() <<
"Failed to infer scalar type!\n";
303 for (
const VPUser *U :
V->users()) {
306 UI->getNumOperands() != UI->getParent()->getNumPredecessors()) {
307 errs() <<
"Phi-like recipe with different number of operands and "
313 for (
const auto &[IncomingVPV, IncomingVPBB] :
314 Phi->incoming_values_and_blocks()) {
315 if (IncomingVPV != V)
321 errs() <<
"Incoming def does not dominate incoming block!\n";
322#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
323 VPSlotTracker Tracker(VPBB->getPlan());
324 IncomingVPV->getDefiningRecipe()->print(
errs(),
" ", Tracker);
325 errs() <<
"\n does not dominate " << IncomingVPBB->getName()
327 UI->print(
errs(),
" ", Tracker);
339 if (UI->getParent() == VPBB) {
340 if (RecipeNumbering[UI] >= RecipeNumbering[&R])
343 if (VPDT.
dominates(VPBB, UI->getParent()))
350 bool BlockHasMaskedCond =
any_of(*VPBB, [](
const VPRecipeBase &R) {
353 if (BlockHasMaskedCond &&
354 any_of(VPBB->getPlan()->getExitBlocks(), [UI](VPIRBasicBlock *EB) {
355 return is_contained(EB->getPredecessors(), UI->getParent());
360 errs() <<
"Use before def!\n";
361#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
362 VPSlotTracker Tracker(VPBB->getPlan());
363 UI->print(
errs(),
" ", Tracker);
364 errs() <<
"\n before\n";
365 R.print(
errs(),
" ", Tracker);
372 switch (VPI->getOpcode()) {
374 if (!verifyLastActiveLaneRecipe(*VPI))
382 unsigned NumOps = ScalarIVSteps->getNumOperands();
384 errs() <<
"VPScalarIVStepsRecipe must have 3 or 4 operands\n";
394 if (!WrappedIRBBs.
insert(IRBB->getIRBasicBlock()).second) {
395 errs() <<
"Same IR basic block used by multiple wrapper blocks!\n";
402bool VPlanVerifier::verifyBlock(
const VPBlockBase *VPB) {
407 if (!VPBB->getParent()) {
411 <<
"Header block in plain CFG VPlan must have 2 predecessors!\n";
416 errs() <<
"Header's second predecessor must be the latch!\n";
422 auto BranchTerminator =
425 if (!
match(VPBB->getTerminator(), BranchTerminator)) {
426 errs() <<
"Latch block must have a branch terminator!\n";
431 errs() <<
"Latch's first successor must not be the header (must be "
437 (VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
438 if (!VPBB->getTerminator()) {
439 errs() <<
"Block has multiple successors but doesn't "
440 "have a proper branch recipe!\n";
443 }
else if (VPBB->getTerminator()) {
444 errs() <<
"Unexpected branch recipe!\n";
451 for (
const VPBlockBase *Succ : Successors) {
453 const auto &SuccPreds = Succ->getPredecessors();
455 errs() <<
"Missing predecessor link.\n";
463 for (
const VPBlockBase *Pred : Predecessors) {
465 if (Pred->getParent() != VPB->
getParent()) {
466 errs() <<
"Predecessor is not in the same region.\n";
471 const auto &PredSuccs = Pred->getSuccessors();
473 errs() <<
"Missing successor link.\n";
477 return !VPBB || verifyVPBasicBlock(VPBB);
480bool VPlanVerifier::verifyBlocksInRegion(
const VPRegionBlock *Region) {
484 errs() <<
"VPBlockBase has wrong parent\n";
488 if (!verifyBlock(VPB))
494bool VPlanVerifier::verifyRegion(
const VPRegionBlock *Region) {
496 const VPBlockBase *Exiting =
Region->getExiting();
499 if (
Entry->hasPredecessors()) {
500 errs() <<
"region entry block has predecessors\n";
504 errs() <<
"region exiting block has successors\n";
508 return verifyBlocksInRegion(Region);
511bool VPlanVerifier::verifyRegionRec(
const VPRegionBlock *Region) {
513 return verifyRegion(Region) &&
515 [
this](
const VPBlockBase *VPB) {
516 const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
517 return !SubRegion || verifyRegionRec(SubRegion);
521bool VPlanVerifier::verify(
const VPlan &Plan) {
523 [
this](
const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
531 if (!verifyRegionRec(TopRegion))
535 errs() <<
"VPlan Top Region should have no parent.\n";
541 errs() <<
"VPlan entry block is not a VPBasicBlock\n";
547 errs() <<
"VPlan exiting block is not a VPBasicBlock\n";
551 if (Exiting->
empty()) {
552 errs() <<
"VPlan vector loop exiting block must end with BranchOnCount, "
553 "BranchOnCond, or BranchOnTwoConds VPInstruction but is empty\n";
561 errs() <<
"VPlan vector loop exit must end with BranchOnCount, "
562 "BranchOnCond, or BranchOnTwoConds VPInstruction\n";
572 VPlanVerifier
Verifier(VPDT, TypeInfo);
573 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 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 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
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
VPBasicBlock * getParent()
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.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
VPInstruction_match< VPInstruction::StepVector > m_StepVector()
VPInstruction_match< VPInstruction::BranchOnTwoConds > m_BranchOnTwoConds()
VPInstruction_match< VPInstruction::BranchOnCount > m_BranchOnCount()
canonical_iv_match m_CanonicalIV()
auto m_VPValue()
Match an arbitrary VPValue and ignore it.
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)
VPInstruction_match< VPInstruction::BranchOnCond > m_BranchOnCond()
NodeAddr< PhiNode * > Phi
bool isUniformAcrossVFsAndUFs(const VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
bool isHeaderMask(const VPValue *V, const VPlan &Plan)
Return true if V is a header mask in Plan.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
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
LLVM_ABI Type * getScalarTypeOrInfer(VPValue *V)
Return the scalar type of V.
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.