Skip to content

Commit bf3b3d0

Browse files
authored
[mlir][GPU] Don't look into neighboring functions for barrier elimination (#135293)
If a `func.func` is nested in some other operation, the barrier eliminator's recursion into parents will examine the neighbors of each function. Therefore, don't recurse into the parent of an operation if that operation is IsolatedFromAbove, like a func.func is. Furthermore, define functions as a region that executes only once, since, within the context of this pass (which runs on functions) it is true.
1 parent 72560e7 commit bf3b3d0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mlir/lib/Dialect/GPU/Transforms/EliminateBarriers.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static bool isSequentialLoopLike(Operation *op) { return isa<scf::ForOp>(op); }
6868
/// most once. Thus, if an operation in one of the nested regions of `op` is
6969
/// executed than so are all the other operations in this region.
7070
static bool hasSingleExecutionBody(Operation *op) {
71-
return isa<scf::IfOp, memref::AllocaScopeOp>(op);
71+
return isa<FunctionOpInterface, scf::IfOp, memref::AllocaScopeOp>(op);
7272
}
7373

7474
/// Returns `true` if the operation is known to produce a pointer-like object
@@ -182,8 +182,10 @@ getEffectsBefore(Operation *op,
182182
if (isParallelRegionBoundary(op->getParentOp()))
183183
return true;
184184

185+
Operation *parent = op->getParentOp();
185186
// Otherwise, keep collecting above the parent operation.
186-
if (!getEffectsBefore(op->getParentOp(), effects, stopAtBarrier))
187+
if (!parent->hasTrait<OpTrait::IsIsolatedFromAbove>() &&
188+
!getEffectsBefore(parent, effects, stopAtBarrier))
187189
return false;
188190

189191
// If the op is loop-like, collect effects from the trailing operations until
@@ -200,7 +202,7 @@ getEffectsBefore(Operation *op,
200202
// the operation `op2` at iteration `i` is known to be executed before the
201203
// operation `op1` at iteration `i+1` and the side effects must be ordered
202204
// appropriately.
203-
if (isSequentialLoopLike(op->getParentOp())) {
205+
if (isSequentialLoopLike(parent)) {
204206
// Assuming loop terminators have no side effects.
205207
return getEffectsBeforeInBlock(op->getBlock()->getTerminator(), effects,
206208
/*stopAtBarrier=*/true);
@@ -268,12 +270,15 @@ getEffectsAfter(Operation *op,
268270
// Collect all effects after the op.
269271
getEffectsAfterInBlock(op, effects, stopAtBarrier);
270272

273+
Operation *parent = op->getParentOp();
271274
// Stop if reached the parallel region boundary.
272-
if (isParallelRegionBoundary(op->getParentOp()))
275+
if (isParallelRegionBoundary(parent))
273276
return true;
274277

275278
// Otherwise, keep collecting below the parent operation.
276-
if (!getEffectsAfter(op->getParentOp(), effects, stopAtBarrier))
279+
// Don't look into, for example, neighboring functions
280+
if (!parent->hasTrait<OpTrait::IsIsolatedFromAbove>() &&
281+
!getEffectsAfter(parent, effects, stopAtBarrier))
277282
return false;
278283

279284
// If the op is loop-like, collect effects from the leading operations until
@@ -290,7 +295,7 @@ getEffectsAfter(Operation *op,
290295
// the operation `op1` at iteration `i` is known to be executed after the
291296
// operation `op2` at iteration `i-1` and the side effects must be ordered
292297
// appropriately.
293-
if (isSequentialLoopLike(op->getParentOp())) {
298+
if (isSequentialLoopLike(parent)) {
294299
if (isa<BarrierOp>(op->getBlock()->front()))
295300
return true;
296301

0 commit comments

Comments
 (0)