This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Remove `Transforms/SideEffectUtils.h` and move the methods into `Interface/SideEffectInterfaces.h`.
ClosedPublic

Authored by mravishankar on Nov 11 2022, 11:32 AM.

Details

Summary

The methods in SideEffectUtils.h (and their implementations in
SideEffectUtils.cpp) seem to have similar intent to methods already
existing in SideEffectInterfaces.h. Move the decleration (and
implementation) from SideEffectUtils.h (and SideEffectUtils.cpp)
into SideEffectInterfaces.h (and SideEffectInterface.cpp).

Also drop the SideEffectInterface::hasNoEffect method in favor of
mlir::isMemoryEffectFree which actually recurses into the operation
instead of just relying on the hasRecursiveMemoryEffectTrait
exclusively.

Diff Detail

Event Timeline

mravishankar created this revision.Nov 11 2022, 11:32 AM

Drop use of hasNoEffect and use isMemoryEffectFree.

mravishankar published this revision for review.Nov 11 2022, 1:56 PM
mravishankar retitled this revision from Fix bug in `hasNoEffect`. to Remove `Transforms/SideEffectUtils.h` and move the methods into `Interface/SideEffectInterfaces.h`..
mravishankar edited the summary of this revision. (Show Details)
rriddle accepted this revision.Nov 11 2022, 2:01 PM
rriddle added inline comments.
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
348–349

What is the relation with these changes?

This revision is now accepted and ready to land.Nov 11 2022, 2:01 PM
mravishankar added inline comments.Nov 11 2022, 2:12 PM
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
348–349

Good catch. This was something I hit while debugging before the better solution was suggest by @Mogball on discord. Ill revert this.

mravishankar retitled this revision from Remove `Transforms/SideEffectUtils.h` and move the methods into `Interface/SideEffectInterfaces.h`. to [mlir] Remove `Transforms/SideEffectUtils.h` and move the methods into `Interface/SideEffectInterfaces.h`..
mravishankar edited the summary of this revision. (Show Details)

Address comments.

mravishankar marked an inline comment as done.Nov 11 2022, 2:44 PM

Since hasNoEffect did not walk the op regions and isMemoryEffectFree does, I think with this change we have a couple of redundant checks on the attached regions.

mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
661

Do we still need the clone->getNumRegions() != 0 bit, now that isMemoryEffectFree recursively checks the regions? Same comment elsewhere.

mlir/lib/Interfaces/SideEffectInterfaces.cpp
160

These comments need to be adjusted -- it should no longer say "it cannot be moved". Same for code comments below.

sanjoy requested changes to this revision.Nov 14 2022, 2:32 PM
This revision now requires changes to proceed.Nov 14 2022, 2:32 PM

Since hasNoEffect did not walk the op regions and isMemoryEffectFree does, I think with this change we have a couple of redundant checks on the attached regions.

I am not sure I follow. It seems like dropping the checks you mentioned increases the scope of analysis past what is intended with this change. I think those need to be follow ups (by folks who understand that code which isnt me) . I hope I can land this change without this ballooning much more.

mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
661

I think that is outside the scope of this change. That seems like it can have non-trivial changes to the intent of the code here that I dont fully understand. It maybe a follow up for people who are currently working in this area.

mlir/lib/Interfaces/SideEffectInterfaces.cpp
160

This is just a move of the code. So the comment is what was there earlier. Can you suggest what you want here?

sanjoy added inline comments.Nov 14 2022, 3:46 PM
mlir/lib/Interfaces/SideEffectInterfaces.cpp
160

You could just delete the comment probably since saying "If the op has no memory effects then it is memory effect free" is not very useful :)

173

Maybe say "// Check if any operations in the inner regions have memory effects" or equivalent.

mravishankar marked 2 inline comments as done.

Maybe fix lit test failure on Windows.

Lit test fixes

This revision was not accepted when it landed; it landed in state Needs Review.Nov 15 2022, 12:08 PM
This revision was automatically updated to reflect the committed changes.

FYI, I landed this even though @sanjoy hasnt accepted it. I had a chat with him offline earlier where he was OK with making some of the more functional/comment changes after the fact.

mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp