23
23
24
24
using namespace llvm ;
25
25
26
- // Verify that phi-like recipes are at the beginning of \p VPBB, with no
27
- // other recipes in between. Also check that only header blocks contain
28
- // VPHeaderPHIRecipes.
29
- static bool verifyPhiRecipes (const VPBasicBlock *VPBB) {
26
+ namespace {
27
+ class VPlanVerifier {
28
+ const VPDominatorTree &VPDT;
29
+
30
+ // Verify that phi-like recipes are at the beginning of \p VPBB, with no
31
+ // other recipes in between. Also check that only header blocks contain
32
+ // VPHeaderPHIRecipes.
33
+ bool verifyPhiRecipes (const VPBasicBlock *VPBB);
34
+
35
+ bool verifyVPBasicBlock (const VPBasicBlock *VPBB);
36
+
37
+ bool verifyBlock (const VPBlockBase *VPB);
38
+
39
+ // / Helper function that verifies the CFG invariants of the VPBlockBases
40
+ // / within
41
+ // / \p Region. Checks in this function are generic for VPBlockBases. They are
42
+ // / not specific for VPBasicBlocks or VPRegionBlocks.
43
+ bool verifyBlocksInRegion (const VPRegionBlock *Region);
44
+
45
+ // / Verify the CFG invariants of VPRegionBlock \p Region and its nested
46
+ // / VPBlockBases. Do not recurse inside nested VPRegionBlocks.
47
+ bool verifyRegion (const VPRegionBlock *Region);
48
+
49
+ // / Verify the CFG invariants of VPRegionBlock \p Region and its nested
50
+ // / VPBlockBases. Recurse inside nested VPRegionBlocks.
51
+ bool verifyRegionRec (const VPRegionBlock *Region);
52
+
53
+ public:
54
+ VPlanVerifier (VPDominatorTree &VPDT) : VPDT(VPDT) {}
55
+
56
+ bool verify (const VPlan &Plan);
57
+ };
58
+ } // namespace
59
+
60
+ bool VPlanVerifier::verifyPhiRecipes (const VPBasicBlock *VPBB) {
30
61
auto RecipeI = VPBB->begin ();
31
62
auto End = VPBB->end ();
32
63
unsigned NumActiveLaneMaskPhiRecipes = 0 ;
@@ -80,8 +111,7 @@ static bool verifyPhiRecipes(const VPBasicBlock *VPBB) {
80
111
return true ;
81
112
}
82
113
83
- static bool verifyVPBasicBlock (const VPBasicBlock *VPBB,
84
- const VPDominatorTree &VPDT) {
114
+ bool VPlanVerifier::verifyVPBasicBlock (const VPBasicBlock *VPBB) {
85
115
if (!verifyPhiRecipes (VPBB))
86
116
return false ;
87
117
@@ -133,7 +163,7 @@ static bool hasDuplicates(const SmallVectorImpl<VPBlockBase *> &VPBlockVec) {
133
163
return false ;
134
164
}
135
165
136
- static bool verifyBlock (const VPBlockBase *VPB, const VPDominatorTree &VPDT ) {
166
+ bool VPlanVerifier:: verifyBlock (const VPBlockBase *VPB) {
137
167
auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
138
168
// Check block's condition bit.
139
169
if (VPB->getNumSuccessors () > 1 ||
@@ -193,31 +223,24 @@ static bool verifyBlock(const VPBlockBase *VPB, const VPDominatorTree &VPDT) {
193
223
return false ;
194
224
}
195
225
}
196
- return !VPBB || verifyVPBasicBlock (VPBB, VPDT );
226
+ return !VPBB || verifyVPBasicBlock (VPBB);
197
227
}
198
228
199
- // / Helper function that verifies the CFG invariants of the VPBlockBases within
200
- // / \p Region. Checks in this function are generic for VPBlockBases. They are
201
- // / not specific for VPBasicBlocks or VPRegionBlocks.
202
- static bool verifyBlocksInRegion (const VPRegionBlock *Region,
203
- const VPDominatorTree &VPDT) {
229
+ bool VPlanVerifier::verifyBlocksInRegion (const VPRegionBlock *Region) {
204
230
for (const VPBlockBase *VPB : vp_depth_first_shallow (Region->getEntry ())) {
205
231
// Check block's parent.
206
232
if (VPB->getParent () != Region) {
207
233
errs () << " VPBlockBase has wrong parent\n " ;
208
234
return false ;
209
235
}
210
236
211
- if (!verifyBlock (VPB, VPDT ))
237
+ if (!verifyBlock (VPB))
212
238
return false ;
213
239
}
214
240
return true ;
215
241
}
216
242
217
- // / Verify the CFG invariants of VPRegionBlock \p Region and its nested
218
- // / VPBlockBases. Do not recurse inside nested VPRegionBlocks.
219
- static bool verifyRegion (const VPRegionBlock *Region,
220
- const VPDominatorTree &VPDT) {
243
+ bool VPlanVerifier::verifyRegion (const VPRegionBlock *Region) {
221
244
const VPBlockBase *Entry = Region->getEntry ();
222
245
const VPBlockBase *Exiting = Region->getExiting ();
223
246
@@ -231,33 +254,26 @@ static bool verifyRegion(const VPRegionBlock *Region,
231
254
return false ;
232
255
}
233
256
234
- return verifyBlocksInRegion (Region, VPDT );
257
+ return verifyBlocksInRegion (Region);
235
258
}
236
259
237
- // / Verify the CFG invariants of VPRegionBlock \p Region and its nested
238
- // / VPBlockBases. Recurse inside nested VPRegionBlocks.
239
- static bool verifyRegionRec (const VPRegionBlock *Region,
240
- const VPDominatorTree &VPDT) {
260
+ bool VPlanVerifier::verifyRegionRec (const VPRegionBlock *Region) {
241
261
// Recurse inside nested regions and check all blocks inside the region.
242
- return verifyRegion (Region, VPDT ) &&
262
+ return verifyRegion (Region) &&
243
263
all_of (vp_depth_first_shallow (Region->getEntry ()),
244
- [&VPDT ](const VPBlockBase *VPB) {
264
+ [this ](const VPBlockBase *VPB) {
245
265
const auto *SubRegion = dyn_cast<VPRegionBlock>(VPB);
246
- return !SubRegion || verifyRegionRec (SubRegion, VPDT );
266
+ return !SubRegion || verifyRegionRec (SubRegion);
247
267
});
248
268
}
249
269
250
- bool llvm::verifyVPlanIsValid (const VPlan &Plan) {
251
- VPDominatorTree VPDT;
252
- VPDT.recalculate (const_cast <VPlan &>(Plan));
253
-
254
- if (any_of (
255
- vp_depth_first_shallow (Plan.getEntry ()),
256
- [&VPDT](const VPBlockBase *VPB) { return !verifyBlock (VPB, VPDT); }))
270
+ bool VPlanVerifier::verify (const VPlan &Plan) {
271
+ if (any_of (vp_depth_first_shallow (Plan.getEntry ()),
272
+ [this ](const VPBlockBase *VPB) { return !verifyBlock (VPB); }))
257
273
return false ;
258
274
259
275
const VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
260
- if (!verifyRegionRec (TopRegion, VPDT ))
276
+ if (!verifyRegionRec (TopRegion))
261
277
return false ;
262
278
263
279
if (TopRegion->getParent ()) {
@@ -305,3 +321,10 @@ bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
305
321
306
322
return true ;
307
323
}
324
+
325
+ bool llvm::verifyVPlanIsValid (const VPlan &Plan) {
326
+ VPDominatorTree VPDT;
327
+ VPDT.recalculate (const_cast <VPlan &>(Plan));
328
+ VPlanVerifier Verifier (VPDT);
329
+ return Verifier.verify (Plan);
330
+ }
0 commit comments