xref: /src/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1eb11fae6SDimitry Andric //===-- VPlanVerifier.cpp -------------------------------------------------===//
2eb11fae6SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6eb11fae6SDimitry Andric //
7eb11fae6SDimitry Andric //===----------------------------------------------------------------------===//
8eb11fae6SDimitry Andric ///
9eb11fae6SDimitry Andric /// \file
10eb11fae6SDimitry Andric /// This file defines the class VPlanVerifier, which contains utility functions
11eb11fae6SDimitry Andric /// to check the consistency and invariants of a VPlan.
12eb11fae6SDimitry Andric ///
13eb11fae6SDimitry Andric //===----------------------------------------------------------------------===//
14eb11fae6SDimitry Andric 
15eb11fae6SDimitry Andric #include "VPlanVerifier.h"
16cfca06d7SDimitry Andric #include "VPlan.h"
17e3b55780SDimitry Andric #include "VPlanCFG.h"
187fa27ce4SDimitry Andric #include "VPlanDominatorTree.h"
19eb11fae6SDimitry Andric #include "llvm/ADT/DepthFirstIterator.h"
20ac9a064cSDimitry Andric #include "llvm/ADT/SmallPtrSet.h"
21706b4fc4SDimitry Andric #include "llvm/Support/CommandLine.h"
22eb11fae6SDimitry Andric 
23eb11fae6SDimitry Andric #define DEBUG_TYPE "loop-vectorize"
24eb11fae6SDimitry Andric 
25eb11fae6SDimitry Andric using namespace llvm;
26eb11fae6SDimitry Andric 
27ac9a064cSDimitry Andric namespace {
28ac9a064cSDimitry Andric class VPlanVerifier {
29ac9a064cSDimitry Andric   const VPDominatorTree &VPDT;
30eb11fae6SDimitry Andric 
31ac9a064cSDimitry Andric   SmallPtrSet<BasicBlock *, 8> WrappedIRBBs;
32c0981da4SDimitry Andric 
33e3b55780SDimitry Andric   // Verify that phi-like recipes are at the beginning of \p VPBB, with no
34e3b55780SDimitry Andric   // other recipes in between. Also check that only header blocks contain
35e3b55780SDimitry Andric   // VPHeaderPHIRecipes.
36ac9a064cSDimitry Andric   bool verifyPhiRecipes(const VPBasicBlock *VPBB);
37ac9a064cSDimitry Andric 
38ac9a064cSDimitry Andric   bool verifyVPBasicBlock(const VPBasicBlock *VPBB);
39ac9a064cSDimitry Andric 
40ac9a064cSDimitry Andric   bool verifyBlock(const VPBlockBase *VPB);
41ac9a064cSDimitry Andric 
42ac9a064cSDimitry Andric   /// Helper function that verifies the CFG invariants of the VPBlockBases
43ac9a064cSDimitry Andric   /// within
44ac9a064cSDimitry Andric   /// \p Region. Checks in this function are generic for VPBlockBases. They are
45ac9a064cSDimitry Andric   /// not specific for VPBasicBlocks or VPRegionBlocks.
46ac9a064cSDimitry Andric   bool verifyBlocksInRegion(const VPRegionBlock *Region);
47ac9a064cSDimitry Andric 
48ac9a064cSDimitry Andric   /// Verify the CFG invariants of VPRegionBlock \p Region and its nested
49ac9a064cSDimitry Andric   /// VPBlockBases. Do not recurse inside nested VPRegionBlocks.
50ac9a064cSDimitry Andric   bool verifyRegion(const VPRegionBlock *Region);
51ac9a064cSDimitry Andric 
52ac9a064cSDimitry Andric   /// Verify the CFG invariants of VPRegionBlock \p Region and its nested
53ac9a064cSDimitry Andric   /// VPBlockBases. Recurse inside nested VPRegionBlocks.
54ac9a064cSDimitry Andric   bool verifyRegionRec(const VPRegionBlock *Region);
55ac9a064cSDimitry Andric 
56ac9a064cSDimitry Andric public:
VPlanVerifier(VPDominatorTree & VPDT)57ac9a064cSDimitry Andric   VPlanVerifier(VPDominatorTree &VPDT) : VPDT(VPDT) {}
58ac9a064cSDimitry Andric 
59ac9a064cSDimitry Andric   bool verify(const VPlan &Plan);
60ac9a064cSDimitry Andric };
61ac9a064cSDimitry Andric } // namespace
62ac9a064cSDimitry Andric 
verifyPhiRecipes(const VPBasicBlock * VPBB)63ac9a064cSDimitry Andric bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
64c0981da4SDimitry Andric   auto RecipeI = VPBB->begin();
65c0981da4SDimitry Andric   auto End = VPBB->end();
661f917f69SDimitry Andric   unsigned NumActiveLaneMaskPhiRecipes = 0;
67e3b55780SDimitry Andric   const VPRegionBlock *ParentR = VPBB->getParent();
68e3b55780SDimitry Andric   bool IsHeaderVPBB = ParentR && !ParentR->isReplicator() &&
69e3b55780SDimitry Andric                       ParentR->getEntryBasicBlock() == VPBB;
701f917f69SDimitry Andric   while (RecipeI != End && RecipeI->isPhi()) {
711f917f69SDimitry Andric     if (isa<VPActiveLaneMaskPHIRecipe>(RecipeI))
721f917f69SDimitry Andric       NumActiveLaneMaskPhiRecipes++;
73e3b55780SDimitry Andric 
74ac9a064cSDimitry Andric     if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI)) {
75e3b55780SDimitry Andric       errs() << "Found non-header PHI recipe in header VPBB";
76e3b55780SDimitry Andric #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
77e3b55780SDimitry Andric       errs() << ": ";
78e3b55780SDimitry Andric       RecipeI->dump();
79e3b55780SDimitry Andric #endif
80e3b55780SDimitry Andric       return false;
81e3b55780SDimitry Andric     }
82e3b55780SDimitry Andric 
83e3b55780SDimitry Andric     if (!IsHeaderVPBB && isa<VPHeaderPHIRecipe>(*RecipeI)) {
84e3b55780SDimitry Andric       errs() << "Found header PHI recipe in non-header VPBB";
85e3b55780SDimitry Andric #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
86e3b55780SDimitry Andric       errs() << ": ";
87e3b55780SDimitry Andric       RecipeI->dump();
88e3b55780SDimitry Andric #endif
89e3b55780SDimitry Andric       return false;
90e3b55780SDimitry Andric     }
91e3b55780SDimitry Andric 
92c0981da4SDimitry Andric     RecipeI++;
931f917f69SDimitry Andric   }
941f917f69SDimitry Andric 
951f917f69SDimitry Andric   if (NumActiveLaneMaskPhiRecipes > 1) {
961f917f69SDimitry Andric     errs() << "There should be no more than one VPActiveLaneMaskPHIRecipe";
971f917f69SDimitry Andric     return false;
981f917f69SDimitry Andric   }
99c0981da4SDimitry Andric 
100c0981da4SDimitry Andric   while (RecipeI != End) {
101c0981da4SDimitry Andric     if (RecipeI->isPhi() && !isa<VPBlendRecipe>(&*RecipeI)) {
102c0981da4SDimitry Andric       errs() << "Found phi-like recipe after non-phi recipe";
103c0981da4SDimitry Andric 
104c0981da4SDimitry Andric #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
105c0981da4SDimitry Andric       errs() << ": ";
106c0981da4SDimitry Andric       RecipeI->dump();
107c0981da4SDimitry Andric       errs() << "after\n";
108c0981da4SDimitry Andric       std::prev(RecipeI)->dump();
109c0981da4SDimitry Andric #endif
110c0981da4SDimitry Andric       return false;
111c0981da4SDimitry Andric     }
112c0981da4SDimitry Andric     RecipeI++;
113c0981da4SDimitry Andric   }
114e3b55780SDimitry Andric   return true;
115e3b55780SDimitry Andric }
116e3b55780SDimitry Andric 
verifyVPBasicBlock(const VPBasicBlock * VPBB)117ac9a064cSDimitry Andric bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
118e3b55780SDimitry Andric   if (!verifyPhiRecipes(VPBB))
119e3b55780SDimitry Andric     return false;
1201f917f69SDimitry Andric 
1214b4fe385SDimitry Andric   // Verify that defs in VPBB dominate all their uses. The current
1224b4fe385SDimitry Andric   // implementation is still incomplete.
1234b4fe385SDimitry Andric   DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
1244b4fe385SDimitry Andric   unsigned Cnt = 0;
1254b4fe385SDimitry Andric   for (const VPRecipeBase &R : *VPBB)
1264b4fe385SDimitry Andric     RecipeNumbering[&R] = Cnt++;
1274b4fe385SDimitry Andric 
1284b4fe385SDimitry Andric   for (const VPRecipeBase &R : *VPBB) {
1294b4fe385SDimitry Andric     for (const VPValue *V : R.definedValues()) {
1304b4fe385SDimitry Andric       for (const VPUser *U : V->users()) {
1314b4fe385SDimitry Andric         auto *UI = dyn_cast<VPRecipeBase>(U);
1327fa27ce4SDimitry Andric         // TODO: check dominance of incoming values for phis properly.
133ac9a064cSDimitry Andric         if (!UI ||
134ac9a064cSDimitry Andric             isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPredInstPHIRecipe>(UI))
1354b4fe385SDimitry Andric           continue;
1364b4fe385SDimitry Andric 
1374b4fe385SDimitry Andric         // If the user is in the same block, check it comes after R in the
1384b4fe385SDimitry Andric         // block.
1394b4fe385SDimitry Andric         if (UI->getParent() == VPBB) {
1404b4fe385SDimitry Andric           if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
1414b4fe385SDimitry Andric             errs() << "Use before def!\n";
1424b4fe385SDimitry Andric             return false;
1434b4fe385SDimitry Andric           }
1444b4fe385SDimitry Andric           continue;
1454b4fe385SDimitry Andric         }
1464b4fe385SDimitry Andric 
1477fa27ce4SDimitry Andric         if (!VPDT.dominates(VPBB, UI->getParent())) {
1484b4fe385SDimitry Andric           errs() << "Use before def!\n";
1494b4fe385SDimitry Andric           return false;
1504b4fe385SDimitry Andric         }
1514b4fe385SDimitry Andric       }
1524b4fe385SDimitry Andric     }
1534b4fe385SDimitry Andric   }
154ac9a064cSDimitry Andric 
155ac9a064cSDimitry Andric   auto *IRBB = dyn_cast<VPIRBasicBlock>(VPBB);
156ac9a064cSDimitry Andric   if (!IRBB)
1571f917f69SDimitry Andric     return true;
1581f917f69SDimitry Andric 
159ac9a064cSDimitry Andric   if (!WrappedIRBBs.insert(IRBB->getIRBasicBlock()).second) {
160ac9a064cSDimitry Andric     errs() << "Same IR basic block used by multiple wrapper blocks!\n";
1611f917f69SDimitry Andric     return false;
162c0981da4SDimitry Andric   }
16377fc4c14SDimitry Andric 
164ac9a064cSDimitry Andric   VPBlockBase *MiddleBB =
165ac9a064cSDimitry Andric       IRBB->getPlan()->getVectorLoopRegion()->getSingleSuccessor();
166ac9a064cSDimitry Andric   if (IRBB != IRBB->getPlan()->getPreheader() &&
167ac9a064cSDimitry Andric       IRBB->getSinglePredecessor() != MiddleBB) {
168ac9a064cSDimitry Andric     errs() << "VPIRBasicBlock can only be used as pre-header or a successor of "
169ac9a064cSDimitry Andric               "middle-block at the moment!\n";
170ac9a064cSDimitry Andric     return false;
171ac9a064cSDimitry Andric   }
172ac9a064cSDimitry Andric   return true;
173ac9a064cSDimitry Andric }
174ac9a064cSDimitry Andric 
175ac9a064cSDimitry Andric /// Utility function that checks whether \p VPBlockVec has duplicate
176ac9a064cSDimitry Andric /// VPBlockBases.
hasDuplicates(const SmallVectorImpl<VPBlockBase * > & VPBlockVec)177ac9a064cSDimitry Andric static bool hasDuplicates(const SmallVectorImpl<VPBlockBase *> &VPBlockVec) {
178ac9a064cSDimitry Andric   SmallDenseSet<const VPBlockBase *, 8> VPBlockSet;
179ac9a064cSDimitry Andric   for (const auto *Block : VPBlockVec) {
180ac9a064cSDimitry Andric     if (VPBlockSet.count(Block))
181ac9a064cSDimitry Andric       return true;
182ac9a064cSDimitry Andric     VPBlockSet.insert(Block);
183ac9a064cSDimitry Andric   }
184ac9a064cSDimitry Andric   return false;
185ac9a064cSDimitry Andric }
186ac9a064cSDimitry Andric 
verifyBlock(const VPBlockBase * VPB)187ac9a064cSDimitry Andric bool VPlanVerifier::verifyBlock(const VPBlockBase *VPB) {
188ac9a064cSDimitry Andric   auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
189ac9a064cSDimitry Andric   // Check block's condition bit.
190ac9a064cSDimitry Andric   if (VPB->getNumSuccessors() > 1 ||
191ac9a064cSDimitry Andric       (VPBB && VPBB->getParent() && VPBB->isExiting() &&
192ac9a064cSDimitry Andric        !VPBB->getParent()->isReplicator())) {
193ac9a064cSDimitry Andric     if (!VPBB || !VPBB->getTerminator()) {
194ac9a064cSDimitry Andric       errs() << "Block has multiple successors but doesn't "
195ac9a064cSDimitry Andric                 "have a proper branch recipe!\n";
196ac9a064cSDimitry Andric       return false;
197ac9a064cSDimitry Andric     }
198ac9a064cSDimitry Andric   } else {
199ac9a064cSDimitry Andric     if (VPBB && VPBB->getTerminator()) {
200ac9a064cSDimitry Andric       errs() << "Unexpected branch recipe!\n";
201ac9a064cSDimitry Andric       return false;
202ac9a064cSDimitry Andric     }
203ac9a064cSDimitry Andric   }
204ac9a064cSDimitry Andric 
205ac9a064cSDimitry Andric   // Check block's successors.
206ac9a064cSDimitry Andric   const auto &Successors = VPB->getSuccessors();
207ac9a064cSDimitry Andric   // There must be only one instance of a successor in block's successor list.
208ac9a064cSDimitry Andric   // TODO: This won't work for switch statements.
209ac9a064cSDimitry Andric   if (hasDuplicates(Successors)) {
210ac9a064cSDimitry Andric     errs() << "Multiple instances of the same successor.\n";
211ac9a064cSDimitry Andric     return false;
212ac9a064cSDimitry Andric   }
213ac9a064cSDimitry Andric 
214ac9a064cSDimitry Andric   for (const VPBlockBase *Succ : Successors) {
215ac9a064cSDimitry Andric     // There must be a bi-directional link between block and successor.
216ac9a064cSDimitry Andric     const auto &SuccPreds = Succ->getPredecessors();
217ac9a064cSDimitry Andric     if (!is_contained(SuccPreds, VPB)) {
218ac9a064cSDimitry Andric       errs() << "Missing predecessor link.\n";
219ac9a064cSDimitry Andric       return false;
220ac9a064cSDimitry Andric     }
221ac9a064cSDimitry Andric   }
222ac9a064cSDimitry Andric 
223ac9a064cSDimitry Andric   // Check block's predecessors.
224ac9a064cSDimitry Andric   const auto &Predecessors = VPB->getPredecessors();
225ac9a064cSDimitry Andric   // There must be only one instance of a predecessor in block's predecessor
226ac9a064cSDimitry Andric   // list.
227ac9a064cSDimitry Andric   // TODO: This won't work for switch statements.
228ac9a064cSDimitry Andric   if (hasDuplicates(Predecessors)) {
229ac9a064cSDimitry Andric     errs() << "Multiple instances of the same predecessor.\n";
230ac9a064cSDimitry Andric     return false;
231ac9a064cSDimitry Andric   }
232ac9a064cSDimitry Andric 
233ac9a064cSDimitry Andric   for (const VPBlockBase *Pred : Predecessors) {
234ac9a064cSDimitry Andric     // Block and predecessor must be inside the same region.
235ac9a064cSDimitry Andric     if (Pred->getParent() != VPB->getParent()) {
236ac9a064cSDimitry Andric       errs() << "Predecessor is not in the same region.\n";
237ac9a064cSDimitry Andric       return false;
238ac9a064cSDimitry Andric     }
239ac9a064cSDimitry Andric 
240ac9a064cSDimitry Andric     // There must be a bi-directional link between block and predecessor.
241ac9a064cSDimitry Andric     const auto &PredSuccs = Pred->getSuccessors();
242ac9a064cSDimitry Andric     if (!is_contained(PredSuccs, VPB)) {
243ac9a064cSDimitry Andric       errs() << "Missing successor link.\n";
244ac9a064cSDimitry Andric       return false;
245ac9a064cSDimitry Andric     }
246ac9a064cSDimitry Andric   }
247ac9a064cSDimitry Andric   return !VPBB || verifyVPBasicBlock(VPBB);
248ac9a064cSDimitry Andric }
249ac9a064cSDimitry Andric 
verifyBlocksInRegion(const VPRegionBlock * Region)250ac9a064cSDimitry Andric bool VPlanVerifier::verifyBlocksInRegion(const VPRegionBlock *Region) {
251ac9a064cSDimitry Andric   for (const VPBlockBase *VPB : vp_depth_first_shallow(Region->getEntry())) {
252ac9a064cSDimitry Andric     // Check block's parent.
253ac9a064cSDimitry Andric     if (VPB->getParent() != Region) {
254ac9a064cSDimitry Andric       errs() << "VPBlockBase has wrong parent\n";
255ac9a064cSDimitry Andric       return false;
256ac9a064cSDimitry Andric     }
257ac9a064cSDimitry Andric 
258ac9a064cSDimitry Andric     if (!verifyBlock(VPB))
259ac9a064cSDimitry Andric       return false;
260ac9a064cSDimitry Andric   }
261ac9a064cSDimitry Andric   return true;
262ac9a064cSDimitry Andric }
263ac9a064cSDimitry Andric 
verifyRegion(const VPRegionBlock * Region)264ac9a064cSDimitry Andric bool VPlanVerifier::verifyRegion(const VPRegionBlock *Region) {
265ac9a064cSDimitry Andric   const VPBlockBase *Entry = Region->getEntry();
266ac9a064cSDimitry Andric   const VPBlockBase *Exiting = Region->getExiting();
267ac9a064cSDimitry Andric 
268ac9a064cSDimitry Andric   // Entry and Exiting shouldn't have any predecessor/successor, respectively.
269ac9a064cSDimitry Andric   if (Entry->getNumPredecessors() != 0) {
270ac9a064cSDimitry Andric     errs() << "region entry block has predecessors\n";
271ac9a064cSDimitry Andric     return false;
272ac9a064cSDimitry Andric   }
273ac9a064cSDimitry Andric   if (Exiting->getNumSuccessors() != 0) {
274ac9a064cSDimitry Andric     errs() << "region exiting block has successors\n";
275ac9a064cSDimitry Andric     return false;
276ac9a064cSDimitry Andric   }
277ac9a064cSDimitry Andric 
278ac9a064cSDimitry Andric   return verifyBlocksInRegion(Region);
279ac9a064cSDimitry Andric }
280ac9a064cSDimitry Andric 
verifyRegionRec(const VPRegionBlock * Region)281ac9a064cSDimitry Andric bool VPlanVerifier::verifyRegionRec(const VPRegionBlock *Region) {
282ac9a064cSDimitry Andric   // Recurse inside nested regions and check all blocks inside the region.
283ac9a064cSDimitry Andric   return verifyRegion(Region) &&
284ac9a064cSDimitry Andric          all_of(vp_depth_first_shallow(Region->getEntry()),
285ac9a064cSDimitry Andric                 [this](const VPBlockBase *VPB) {
286ac9a064cSDimitry Andric                   const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
287ac9a064cSDimitry Andric                   return !SubRegion || verifyRegionRec(SubRegion);
288ac9a064cSDimitry Andric                 });
289ac9a064cSDimitry Andric }
290ac9a064cSDimitry Andric 
verify(const VPlan & Plan)291ac9a064cSDimitry Andric bool VPlanVerifier::verify(const VPlan &Plan) {
292ac9a064cSDimitry Andric   if (any_of(vp_depth_first_shallow(Plan.getEntry()),
293ac9a064cSDimitry Andric              [this](const VPBlockBase *VPB) { return !verifyBlock(VPB); }))
294ac9a064cSDimitry Andric     return false;
295ac9a064cSDimitry Andric 
296145449b1SDimitry Andric   const VPRegionBlock *TopRegion = Plan.getVectorLoopRegion();
297ac9a064cSDimitry Andric   if (!verifyRegionRec(TopRegion))
298ac9a064cSDimitry Andric     return false;
299ac9a064cSDimitry Andric 
300ac9a064cSDimitry Andric   if (TopRegion->getParent()) {
301ac9a064cSDimitry Andric     errs() << "VPlan Top Region should have no parent.\n";
302ac9a064cSDimitry Andric     return false;
303ac9a064cSDimitry Andric   }
304ac9a064cSDimitry Andric 
30577fc4c14SDimitry Andric   const VPBasicBlock *Entry = dyn_cast<VPBasicBlock>(TopRegion->getEntry());
30677fc4c14SDimitry Andric   if (!Entry) {
30777fc4c14SDimitry Andric     errs() << "VPlan entry block is not a VPBasicBlock\n";
30877fc4c14SDimitry Andric     return false;
30977fc4c14SDimitry Andric   }
3106f8fc217SDimitry Andric 
3116f8fc217SDimitry Andric   if (!isa<VPCanonicalIVPHIRecipe>(&*Entry->begin())) {
3126f8fc217SDimitry Andric     errs() << "VPlan vector loop header does not start with a "
3136f8fc217SDimitry Andric               "VPCanonicalIVPHIRecipe\n";
3146f8fc217SDimitry Andric     return false;
3156f8fc217SDimitry Andric   }
3166f8fc217SDimitry Andric 
317145449b1SDimitry Andric   const VPBasicBlock *Exiting = dyn_cast<VPBasicBlock>(TopRegion->getExiting());
318145449b1SDimitry Andric   if (!Exiting) {
319145449b1SDimitry Andric     errs() << "VPlan exiting block is not a VPBasicBlock\n";
32077fc4c14SDimitry Andric     return false;
32177fc4c14SDimitry Andric   }
32277fc4c14SDimitry Andric 
323145449b1SDimitry Andric   if (Exiting->empty()) {
3241f917f69SDimitry Andric     errs() << "VPlan vector loop exiting block must end with BranchOnCount or "
3251f917f69SDimitry Andric               "BranchOnCond VPInstruction but is empty\n";
3266f8fc217SDimitry Andric     return false;
3276f8fc217SDimitry Andric   }
3286f8fc217SDimitry Andric 
329145449b1SDimitry Andric   auto *LastInst = dyn_cast<VPInstruction>(std::prev(Exiting->end()));
3301f917f69SDimitry Andric   if (!LastInst || (LastInst->getOpcode() != VPInstruction::BranchOnCount &&
3311f917f69SDimitry Andric                     LastInst->getOpcode() != VPInstruction::BranchOnCond)) {
3321f917f69SDimitry Andric     errs() << "VPlan vector loop exit must end with BranchOnCount or "
3331f917f69SDimitry Andric               "BranchOnCond VPInstruction\n";
3346f8fc217SDimitry Andric     return false;
3356f8fc217SDimitry Andric   }
3366f8fc217SDimitry Andric 
337e3b55780SDimitry Andric   for (const auto &KV : Plan.getLiveOuts())
338145449b1SDimitry Andric     if (KV.second->getNumOperands() != 1) {
339145449b1SDimitry Andric       errs() << "live outs must have a single operand\n";
340145449b1SDimitry Andric       return false;
341145449b1SDimitry Andric     }
342145449b1SDimitry Andric 
343c0981da4SDimitry Andric   return true;
344c0981da4SDimitry Andric }
345ac9a064cSDimitry Andric 
verifyVPlanIsValid(const VPlan & Plan)346ac9a064cSDimitry Andric bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
347ac9a064cSDimitry Andric   VPDominatorTree VPDT;
348ac9a064cSDimitry Andric   VPDT.recalculate(const_cast<VPlan &>(Plan));
349ac9a064cSDimitry Andric   VPlanVerifier Verifier(VPDT);
350ac9a064cSDimitry Andric   return Verifier.verify(Plan);
351ac9a064cSDimitry Andric }
352