15
15
#include " VPlanVerifier.h"
16
16
#include " VPlan.h"
17
17
#include " VPlanCFG.h"
18
+ #include " VPlanDominatorTree.h"
18
19
#include " llvm/ADT/DepthFirstIterator.h"
19
20
#include " llvm/Support/CommandLine.h"
20
21
@@ -189,9 +190,8 @@ static bool verifyPhiRecipes(const VPBasicBlock *VPBB) {
189
190
return true ;
190
191
}
191
192
192
- static bool
193
- verifyVPBasicBlock (const VPBasicBlock *VPBB,
194
- DenseMap<const VPBlockBase *, unsigned > &BlockNumbering) {
193
+ static bool verifyVPBasicBlock (const VPBasicBlock *VPBB,
194
+ VPDominatorTree &VPDT) {
195
195
if (!verifyPhiRecipes (VPBB))
196
196
return false ;
197
197
@@ -206,7 +206,8 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
206
206
for (const VPValue *V : R.definedValues ()) {
207
207
for (const VPUser *U : V->users ()) {
208
208
auto *UI = dyn_cast<VPRecipeBase>(U);
209
- if (!UI || isa<VPHeaderPHIRecipe>(UI))
209
+ // TODO: check dominance of incoming values for phis properly.
210
+ if (!UI || isa<VPHeaderPHIRecipe>(UI) || isa<VPPredInstPHIRecipe>(UI))
210
211
continue ;
211
212
212
213
// If the user is in the same block, check it comes after R in the
@@ -219,27 +220,7 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
219
220
continue ;
220
221
}
221
222
222
- // Skip blocks outside any region for now and blocks outside
223
- // replicate-regions.
224
- auto *ParentR = VPBB->getParent ();
225
- if (!ParentR || !ParentR->isReplicator ())
226
- continue ;
227
-
228
- // For replicators, verify that VPPRedInstPHIRecipe defs are only used
229
- // in subsequent blocks.
230
- if (isa<VPPredInstPHIRecipe>(&R)) {
231
- auto I = BlockNumbering.find (UI->getParent ());
232
- unsigned BlockNumber = I == BlockNumbering.end () ? std::numeric_limits<unsigned >::max () : I->second ;
233
- if (BlockNumber < BlockNumbering[ParentR]) {
234
- errs () << " Use before def!\n " ;
235
- return false ;
236
- }
237
- continue ;
238
- }
239
-
240
- // All non-VPPredInstPHIRecipe recipes in the block must be used in
241
- // the replicate region only.
242
- if (UI->getParent ()->getParent () != ParentR) {
223
+ if (!VPDT.dominates (VPBB, UI->getParent ())) {
243
224
errs () << " Use before def!\n " ;
244
225
return false ;
245
226
}
@@ -250,15 +231,13 @@ verifyVPBasicBlock(const VPBasicBlock *VPBB,
250
231
}
251
232
252
233
bool VPlanVerifier::verifyPlanIsValid (const VPlan &Plan) {
253
- DenseMap<const VPBlockBase *, unsigned > BlockNumbering;
254
- unsigned Cnt = 0 ;
234
+ VPDominatorTree VPDT;
235
+ VPDT.recalculate (const_cast <VPlan &>(Plan));
236
+
255
237
auto Iter = vp_depth_first_deep (Plan.getEntry ());
256
- for (const VPBlockBase *VPB : Iter) {
257
- BlockNumbering[VPB] = Cnt++;
258
- auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
259
- if (!VPBB)
260
- continue ;
261
- if (!verifyVPBasicBlock (VPBB, BlockNumbering))
238
+ for (const VPBasicBlock *VPBB :
239
+ VPBlockUtils::blocksOnly<const VPBasicBlock>(Iter)) {
240
+ if (!verifyVPBasicBlock (VPBB, VPDT))
262
241
return false ;
263
242
}
264
243
0 commit comments