@@ -215,7 +215,8 @@ DominanceInfoBase<IsPostDom>::findNearestCommonDominator(Block *a,
215
215
216
216
// / Return true if the specified block A properly dominates block B.
217
217
template <bool IsPostDom>
218
- bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) const {
218
+ bool DominanceInfoBase<IsPostDom>::properlyDominatesImpl(Block *a,
219
+ Block *b) const {
219
220
assert (a && b && " null blocks not allowed" );
220
221
221
222
// A block dominates, but does not properly dominate, itself unless this
@@ -243,51 +244,29 @@ bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) const {
243
244
return getDomTree (regionA).properlyDominates (a, b);
244
245
}
245
246
246
- // / Return true if the specified block is reachable from the entry block of
247
- // / its region.
248
247
template <bool IsPostDom>
249
- bool DominanceInfoBase<IsPostDom>::isReachableFromEntry(Block *a) const {
250
- // If this is the first block in its region, then it is obviously reachable.
251
- Region *region = a->getParent ();
252
- if (®ion->front () == a)
253
- return true ;
254
-
255
- // Otherwise this is some block in a multi-block region. Check DomTree.
256
- return getDomTree (region).isReachableFromEntry (a);
257
- }
258
-
259
- template class detail ::DominanceInfoBase</* IsPostDom=*/ true >;
260
- template class detail ::DominanceInfoBase</* IsPostDom=*/ false >;
261
-
262
- // ===----------------------------------------------------------------------===//
263
- // DominanceInfo
264
- // ===----------------------------------------------------------------------===//
265
-
266
- // / Return true if operation `a` properly dominates operation `b`. The
267
- // / 'enclosingOpOk' flag says whether we should return true if the `b` op is
268
- // / enclosed by a region on 'a'.
269
- bool DominanceInfo::properlyDominates (Operation *a, Operation *b,
270
- bool enclosingOpOk) const {
248
+ bool DominanceInfoBase<IsPostDom>::properlyDominatesImpl(
249
+ Operation *a, Operation *b, bool enclosingOpOk) const {
271
250
Block *aBlock = a->getBlock (), *bBlock = b->getBlock ();
272
251
assert (aBlock && bBlock && " operations must be in a block" );
273
252
274
- // An operation dominates, but does not properly dominate, itself unless this
275
- // is a graph region.
253
+ // An operation (pos) dominates, but does not properly (pos) dominate, itself
254
+ // unless this is a graph region.
276
255
if (a == b)
277
256
return !hasSSADominance (aBlock);
278
257
279
258
// If these ops are in different regions, then normalize one into the other.
280
259
Region *aRegion = aBlock->getParent ();
281
260
if (aRegion != bBlock->getParent ()) {
282
261
// Scoot up b's region tree until we find an operation in A's region that
283
- // encloses it. If this fails, then we know there is no post- dom relation.
262
+ // encloses it. If this fails, then we know there is no ( post) dom relation.
284
263
b = aRegion ? aRegion->findAncestorOpInRegion (*b) : nullptr ;
285
264
if (!b)
286
265
return false ;
287
266
bBlock = b->getBlock ();
288
267
assert (bBlock->getParent () == aRegion);
289
268
290
- // If 'a' encloses 'b', then we consider it to dominate.
269
+ // If 'a' encloses 'b', then we consider it to (post) dominate.
291
270
if (a == b && enclosingOpOk)
292
271
return true ;
293
272
}
@@ -297,17 +276,39 @@ bool DominanceInfo::properlyDominates(Operation *a, Operation *b,
297
276
// Dominance changes based on the region type. In a region with SSA
298
277
// dominance, uses inside the same block must follow defs. In other
299
278
// regions kinds, uses and defs can come in any order inside a block.
300
- if (hasSSADominance (aBlock)) {
301
- // If the blocks are the same, then check if b is before a in the block.
279
+ if (!hasSSADominance (aBlock))
280
+ return true ;
281
+ if constexpr (IsPostDom) {
282
+ return b->isBeforeInBlock (a);
283
+ } else {
302
284
return a->isBeforeInBlock (b);
303
285
}
304
- return true ;
305
286
}
306
287
307
288
// If the blocks are different, use DomTree to resolve the query.
308
289
return getDomTree (aRegion).properlyDominates (aBlock, bBlock);
309
290
}
310
291
292
+ // / Return true if the specified block is reachable from the entry block of
293
+ // / its region.
294
+ template <bool IsPostDom>
295
+ bool DominanceInfoBase<IsPostDom>::isReachableFromEntry(Block *a) const {
296
+ // If this is the first block in its region, then it is obviously reachable.
297
+ Region *region = a->getParent ();
298
+ if (®ion->front () == a)
299
+ return true ;
300
+
301
+ // Otherwise this is some block in a multi-block region. Check DomTree.
302
+ return getDomTree (region).isReachableFromEntry (a);
303
+ }
304
+
305
+ template class detail ::DominanceInfoBase</* IsPostDom=*/ true >;
306
+ template class detail ::DominanceInfoBase</* IsPostDom=*/ false >;
307
+
308
+ // ===----------------------------------------------------------------------===//
309
+ // DominanceInfo
310
+ // ===----------------------------------------------------------------------===//
311
+
311
312
// / Return true if the `a` value properly dominates operation `b`, i.e if the
312
313
// / operation that defines `a` properlyDominates `b` and the operation that
313
314
// / defines `a` does not contain `b`.
@@ -321,49 +322,3 @@ bool DominanceInfo::properlyDominates(Value a, Operation *b) const {
321
322
// `b`, but `a` does not itself enclose `b` in one of its regions.
322
323
return properlyDominates (a.getDefiningOp (), b, /* enclosingOpOk=*/ false );
323
324
}
324
-
325
- // ===----------------------------------------------------------------------===//
326
- // PostDominanceInfo
327
- // ===----------------------------------------------------------------------===//
328
-
329
- // / Returns true if statement 'a' properly postdominates statement b.
330
- bool PostDominanceInfo::properlyPostDominates (Operation *a,
331
- Operation *b) const {
332
- auto *aBlock = a->getBlock (), *bBlock = b->getBlock ();
333
- assert (aBlock && bBlock && " operations must be in a block" );
334
-
335
- // An instruction postDominates, but does not properlyPostDominate, itself
336
- // unless this is a graph region.
337
- if (a == b)
338
- return !hasSSADominance (aBlock);
339
-
340
- // If these ops are in different regions, then normalize one into the other.
341
- Region *aRegion = aBlock->getParent ();
342
- if (aRegion != bBlock->getParent ()) {
343
- // Scoot up b's region tree until we find an operation in A's region that
344
- // encloses it. If this fails, then we know there is no post-dom relation.
345
- b = aRegion ? aRegion->findAncestorOpInRegion (*b) : nullptr ;
346
- if (!b)
347
- return false ;
348
- bBlock = b->getBlock ();
349
- assert (bBlock->getParent () == aRegion);
350
-
351
- // If 'a' encloses 'b', then we consider it to postdominate.
352
- if (a == b)
353
- return true ;
354
- }
355
-
356
- // Ok, they are in the same region. If they are in the same block, check if b
357
- // is before a in the block.
358
- if (aBlock == bBlock) {
359
- // Dominance changes based on the region type.
360
- if (hasSSADominance (aBlock)) {
361
- // If the blocks are the same, then check if b is before a in the block.
362
- return b->isBeforeInBlock (a);
363
- }
364
- return true ;
365
- }
366
-
367
- // If the blocks are different, check if a's block post dominates b's.
368
- return getDomTree (aRegion).properlyDominates (aBlock, bBlock);
369
- }
0 commit comments