tensorflow / mlir

"Multi-Level Intermediate Representation" Compiler Infrastructure
1.74k stars 260 forks source link

Implement removeOpIfDeadResults in PatternRewriter #212

Closed dcaballe closed 4 years ago

dcaballe commented 5 years ago

'replaceOp' and 'replaceOpWithNewOp' accept an list of valuesToRemoveIfDead. However, such removal functionality wasn't implemented.

There are quite a few tests using this feature already:

    MLIR :: AffineOps/canonicalize.mlir
    MLIR :: Dialect/FxpMathOps/lower-uniform-casts.mlir
    MLIR :: Dialect/FxpMathOps/lower-uniform-real-math-addew.mlir
    MLIR :: Dialect/FxpMathOps/lower-uniform-real-math-mulew.mlir
    MLIR :: Dialect/GPU/canonicalize.mlir
    MLIR :: Dialect/QuantOps/canonicalize.mlir
    MLIR :: Dialect/QuantOps/convert-const.mlir
    MLIR :: Dialect/QuantOps/convert-fakequant.mlir
    MLIR :: Dialect/SPIRV/canonicalize.mlir
    MLIR :: Examples/Toy/Ch4/shape_inference.mlir
    MLIR :: Examples/Toy/Ch5/affine-lowering.mlir
    MLIR :: Examples/Toy/Ch5/shape_inference.mlir
    MLIR :: Examples/Toy/Ch6/affine-lowering.mlir
    MLIR :: Examples/Toy/Ch6/llvm-lowering.mlir
    MLIR :: Examples/Toy/Ch6/shape_inference.mlir
    MLIR :: Quantizer/matmul.mlir
    MLIR :: Quantizer/remove-instrumentation.mlir
    MLIR :: Transforms/Vectorize/lower_vector_transfers.mlir
    MLIR :: Transforms/canonicalize.mlir
    MLIR :: Transforms/inlining.mlir
    MLIR :: mlir-tblgen/pattern.mlir

However, maybe adding a couple of tests to cover Operation with multiple results could be a good idea. Any suggestion of a multi-result Operation and could trigger this feature?

This patch also needs https://github.com/tensorflow/mlir/pull/211 to land. Otherwise, Transforms/canonicalize.mlir will fail.

googlebot commented 5 years ago

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

googlebot commented 5 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

dcaballe commented 5 years ago

@kiszk, thanks for the feedback (not sure why I can't see your comment in github). has no side effect refers to Operation. Maybe I can reword that to make it clearer.

@River707, what do you think about this PR after the Stripe use case? Should we proceed with this implementation or remove valuesToRemoveIfDead from the API? I think it still makes sense for the simple cases I pointed out before but I'll be happy to remove it if you think it doesn't make sense. I just don't want to leave valuesToRemoveIfDead in the API without implementation :)

River707 commented 5 years ago

I apologize for the tardiness, can you share the use case you have for Stripe?

dcaballe commented 5 years ago

Sorry, I wasn't clear. Stripe use case is the one that evolved into the BlockArgument conversion problem (https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/Jpn5eX2Bcpg) so I no longer have a simple case that can benefit from this. However, I still see some value, as I mentioned before.

River707 commented 4 years ago

Sorry for the delay. I may be biased, but I say we just remove it until there is a clear story in how it fits in with the rest of the infra.

dcaballe commented 4 years ago

That should be it!

dcaballe commented 4 years ago

Moved to https://reviews.llvm.org/D72545