25#define DEBUG_TYPE "loop-vectorize"
42 bool verifyLastActiveLaneRecipe(
const VPInstruction &LastActiveLane)
const;
75bool VPlanVerifier::verifyPhiRecipes(
const VPBasicBlock *VPBB) {
76 auto RecipeI = VPBB->
begin();
77 auto End = VPBB->
end();
78 unsigned NumActiveLaneMaskPhiRecipes = 0;
80 while (RecipeI != End && RecipeI->isPhi()) {
82 NumActiveLaneMaskPhiRecipes++;
86 errs() <<
"Found non-header PHI recipe in header VPBB";
87#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
95 errs() <<
"Found header PHI recipe in non-header VPBB";
96#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
104 RecipeI->getIterator() != VPBB->
begin()) {
105 errs() <<
"CurrentIteration PHI is not the first recipe\n";
113 errs() <<
"Phi-like recipe with different number of operands and "
125 errs() <<
"There should be no more than one VPActiveLaneMaskPHIRecipe";
129 while (RecipeI != End) {
131 errs() <<
"Found phi-like recipe after non-phi recipe";
133#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
137 std::prev(RecipeI)->dump();
155 return WidenIV->isCanonical() || WidenIV->hasNoUnsignedWrap();
157 return match(Steps->getOperand(0),
167bool VPlanVerifier::verifyLastActiveLaneRecipe(
168 const VPInstruction &LastActiveLane)
const {
170 "must be called with VPInstruction::LastActiveLane");
173 errs() <<
"LastActiveLane must have at least one operand\n";
180 for (VPValue *
Op : LastActiveLane.
operands()) {
208 errs() <<
"LastActiveLane operand ";
209#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
210 VPSlotTracker Tracker(&Plan);
211 Op->printAsOperand(
errs(), Tracker);
213 errs() <<
" must be prefix mask (a header mask or an "
214 "EVL-derived mask currently)\n";
221bool VPlanVerifier::verifyRecipeTypes(
const VPRecipeBase &R)
const {
226 auto CheckScalarType = [&](
Type *Derived) ->
bool {
227 if (Derived == SR->getScalarType())
229 errs() <<
"Recipe result type does not match type derived from operands";
230#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
238 auto CheckOperandTypes = [&]() ->
bool {
240 return R.getOperand(0)->getScalarType() == Op->getScalarType();
243 errs() <<
"Recipe operand types do not match";
244#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
253 return CheckScalarType(WII->getTruncInst()
254 ? WII->getTruncInst()->getType()
255 : WII->getStartValue()->getScalarType());
257 switch (
R.getVPRecipeID()) {
258 case VPRecipeBase::VPVectorPointerSC:
259 case VPRecipeBase::VPVectorEndPointerSC:
260 case VPRecipeBase::VPWidenGEPSC:
261 case VPRecipeBase::VPScalarIVStepsSC:
262 case VPRecipeBase::VPWidenPointerInductionSC:
263 case VPRecipeBase::VPDerivedIVSC:
264 return CheckScalarType(
R.getOperand(0)->getScalarType());
265 case VPRecipeBase::VPWidenPHISC:
266 case VPRecipeBase::VPPredInstPHISC:
267 case VPRecipeBase::VPReductionPHISC:
268 case VPRecipeBase::VPActiveLaneMaskPHISC:
269 case VPRecipeBase::VPCurrentIterationPHISC:
270 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
271 return CheckOperandTypes() &&
272 CheckScalarType(
R.getOperand(0)->getScalarType());
273 case VPRecipeBase::VPInstructionSC: {
281 Instruction::Alloca, Instruction::Call},
285 return CheckScalarType(
288 case VPRecipeBase::VPReplicateSC: {
291 if (RepR->isPredicated())
293 return CheckScalarType(
296 case VPRecipeBase::VPWidenSC: {
301 case VPRecipeBase::VPExpressionSC:
303 ->getOperandOfResultType()
311bool VPlanVerifier::verifyVPBasicBlock(
const VPBasicBlock *VPBB) {
312 if (!verifyPhiRecipes(VPBB))
316 DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
318 for (
const VPRecipeBase &R : *VPBB)
319 RecipeNumbering[&
R] = Cnt++;
321 for (
const VPRecipeBase &R : *VPBB) {
323 errs() <<
"VPIRInstructions ";
324#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
328 errs() <<
"not in a VPIRBasicBlock!\n";
331 if (!verifyRecipeTypes(R))
333 for (
const VPValue *V :
R.definedValues()) {
335 if (!
V->getScalarType()) {
336 errs() <<
"VPValue without scalar type!\n";
345 for (
const VPUser *U :
V->users()) {
348 UI->getNumOperands() != UI->getParent()->getNumPredecessors()) {
349 errs() <<
"Phi-like recipe with different number of operands and "
355 for (
const auto &[IncomingVPV, IncomingVPBB] :
356 Phi->incoming_values_and_blocks()) {
357 if (IncomingVPV != V)
363 errs() <<
"Incoming def does not dominate incoming block!\n";
364#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
365 VPSlotTracker Tracker(VPBB->getPlan());
366 IncomingVPV->getDefiningRecipe()->print(
errs(),
" ", Tracker);
367 errs() <<
"\n does not dominate " << IncomingVPBB->getName()
369 UI->print(
errs(),
" ", Tracker);
381 if (UI->getParent() == VPBB) {
382 if (RecipeNumbering[UI] >= RecipeNumbering[&R])
385 if (VPDT.
dominates(VPBB, UI->getParent()))
392 bool BlockHasMaskedCond =
any_of(*VPBB, [](
const VPRecipeBase &R) {
395 if (BlockHasMaskedCond &&
396 any_of(VPBB->getPlan()->getExitBlocks(), [UI](VPIRBasicBlock *EB) {
397 return is_contained(EB->getPredecessors(), UI->getParent());
402 errs() <<
"Use before def!\n";
403#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
404 VPSlotTracker Tracker(VPBB->getPlan());
405 UI->print(
errs(),
" ", Tracker);
406 errs() <<
"\n before\n";
407 R.print(
errs(),
" ", Tracker);
414 switch (VPI->getOpcode()) {
416 if (!verifyLastActiveLaneRecipe(*VPI))
424 unsigned NumOps = ScalarIVSteps->getNumOperands();
426 errs() <<
"VPScalarIVStepsRecipe must have 3 or 4 operands\n";
436 if (!WrappedIRBBs.
insert(IRBB->getIRBasicBlock()).second) {
437 errs() <<
"Same IR basic block used by multiple wrapper blocks!\n";
444bool VPlanVerifier::verifyBlock(
const VPBlockBase *VPB) {
449 if (!VPBB->getParent()) {
453 <<
"Header block in plain CFG VPlan must have 2 predecessors!\n";
458 errs() <<
"Header's second predecessor must be the latch!\n";
464 auto BranchTerminator =
467 if (!
match(VPBB->getTerminator(), BranchTerminator)) {
468 errs() <<
"Latch block must have a branch terminator!\n";
473 errs() <<
"Latch's first successor must not be the header (must be "
479 (VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
480 if (!VPBB->getTerminator()) {
481 errs() <<
"Block has multiple successors but doesn't "
482 "have a proper branch recipe!\n";
485 }
else if (VPBB->getTerminator()) {
486 errs() <<
"Unexpected branch recipe!\n";
493 for (
const VPBlockBase *Succ : Successors) {
495 const auto &SuccPreds = Succ->getPredecessors();
497 errs() <<
"Missing predecessor link.\n";
505 for (
const VPBlockBase *Pred : Predecessors) {
507 if (Pred->getParent() != VPB->
getParent()) {
508 errs() <<
"Predecessor is not in the same region.\n";
513 const auto &PredSuccs = Pred->getSuccessors();
515 errs() <<
"Missing successor link.\n";
519 return !VPBB || verifyVPBasicBlock(VPBB);
522bool VPlanVerifier::verifyBlocksInRegion(
const VPRegionBlock *Region) {
526 errs() <<
"VPBlockBase has wrong parent\n";
530 if (!verifyBlock(VPB))
536bool VPlanVerifier::verifyRegion(
const VPRegionBlock *Region) {
538 const VPBlockBase *Exiting =
Region->getExiting();
541 if (
Entry->hasPredecessors()) {
542 errs() <<
"region entry block has predecessors\n";
546 errs() <<
"region exiting block has successors\n";
550 return verifyBlocksInRegion(Region);
553bool VPlanVerifier::verifyRegionRec(
const VPRegionBlock *Region) {
555 return verifyRegion(Region) &&
557 [
this](
const VPBlockBase *VPB) {
558 const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
559 return !SubRegion || verifyRegionRec(SubRegion);
563bool VPlanVerifier::verify(
const VPlan &Plan) {
565 [
this](
const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
573 if (!verifyRegionRec(TopRegion))
577 errs() <<
"VPlan Top Region should have no parent.\n";
583 errs() <<
"VPlan entry block is not a VPBasicBlock\n";
589 errs() <<
"VPlan exiting block is not a VPBasicBlock\n";
593 if (Exiting->
empty()) {
594 errs() <<
"VPlan vector loop exiting block must end with BranchOnCount, "
595 "BranchOnCond, or BranchOnTwoConds VPInstruction but is empty\n";
603 errs() <<
"VPlan vector loop exit must end with BranchOnCount, "
604 "BranchOnCond, or BranchOnTwoConds VPInstruction\n";
614 return Verifier.verify(Plan);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Value * getOpcode(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
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
static Type * computeScalarType(const Instruction *I, ArrayRef< VPValue * > Operands)
Compute the scalar result type for a VPReplicateRecipe wrapping I with Operands (excluding any predic...
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.
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.
IntrinsicID_match m_Intrinsic()
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::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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI Type * computeScalarTypeForInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands)
Compute the scalar result type for an IR Opcode given Operands.
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.