@@ -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,48 +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, Operation *b) {
331
- auto *aBlock = a->getBlock (), *bBlock = b->getBlock ();
332
- assert (aBlock && bBlock && " operations must be in a block" );
333
-
334
- // An instruction postDominates, but does not properlyPostDominate, itself
335
- // unless this is a graph region.
336
- if (a == b)
337
- return !hasSSADominance (aBlock);
338
-
339
- // If these ops are in different regions, then normalize one into the other.
340
- Region *aRegion = aBlock->getParent ();
341
- if (aRegion != bBlock->getParent ()) {
342
- // Scoot up b's region tree until we find an operation in A's region that
343
- // encloses it. If this fails, then we know there is no post-dom relation.
344
- b = aRegion ? aRegion->findAncestorOpInRegion (*b) : nullptr ;
345
- if (!b)
346
- return false ;
347
- bBlock = b->getBlock ();
348
- assert (bBlock->getParent () == aRegion);
349
-
350
- // If 'a' encloses 'b', then we consider it to postdominate.
351
- if (a == b)
352
- return true ;
353
- }
354
-
355
- // Ok, they are in the same region. If they are in the same block, check if b
356
- // is before a in the block.
357
- if (aBlock == bBlock) {
358
- // Dominance changes based on the region type.
359
- if (hasSSADominance (aBlock)) {
360
- // If the blocks are the same, then check if b is before a in the block.
361
- return b->isBeforeInBlock (a);
362
- }
363
- return true ;
364
- }
365
-
366
- // If the blocks are different, check if a's block post dominates b's.
367
- return getDomTree (aRegion).properlyDominates (aBlock, bBlock);
368
- }
0 commit comments