[all-commits] [llvm/llvm-project] 567fd5: [mlir][SCF] Add utility method to add new yield va...

Nicolas Vasilache via All-commits all-commits at lists.llvm.org
Tue May 10 11:44:38 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 567fd523bf538523f58779e5af9d20c3e48838a2
      https://github.com/llvm/llvm-project/commit/567fd523bf538523f58779e5af9d20c3e48838a2
  Author: Mahesh Ravishankar <ravishankarm at google.com>
  Date:   2022-05-10 (Tue, 10 May 2022)

  Changed paths:
    M mlir/include/mlir/Dialect/SCF/Utils/Utils.h
    M mlir/lib/Dialect/SCF/Utils/Utils.cpp
    M mlir/test/Transforms/scf-loop-utils.mlir
    A mlir/test/Transforms/scf-replace-with-new-yields.mlir
    M mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp

  Log Message:
  -----------
  [mlir][SCF] Add utility method to add new yield values to a loop.

The current implementation of `cloneWithNewYields` has a few issues
- It clones the loop body of the original loop to create a new
  loop. This is very expensive.
- It performs `erase` operations which are incompatible when this
  method is called from within a pattern rewrite. All erases need to
  go through `PatternRewriter`.

To address these a new utility method `replaceLoopWithNewYields` is added
which
- moves the operations from the original loop into the new loop.
- replaces all uses of the original loop with the corresponding
  results of the new loop
- use a call back to allow caller to generate the new yield values.
- the original loop is modified to just yield the basic block
  arguments corresponding to the iter_args of the loop. This
  represents a no-op loop. The loop itself is dead (since all its uses
  are replaced), but is not removed. The caller is expected to erase
  the op. Consequently, this method can be called from within a
  `matchAndRewrite` method of a `PatternRewriter`.

The `cloneWithNewYields` could be replaces with
`replaceLoopWithNewYields`, but that seems to trigger a failure during
walks, potentially due to the operations being moved. That is left as
a TODO.

Differential Revision: https://reviews.llvm.org/D125147


  Commit: 1f23211cb1eee2c08713512b1ecc30c78a90dc64
      https://github.com/llvm/llvm-project/commit/1f23211cb1eee2c08713512b1ecc30c78a90dc64
  Author: Nicolas Vasilache <ntv at google.com>
  Date:   2022-05-10 (Tue, 10 May 2022)

  Changed paths:
    M mlir/include/mlir/Dialect/SCF/Utils/Utils.h
    M mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
    M mlir/lib/Dialect/SCF/Utils/Utils.cpp
    R mlir/test/Transforms/scf-loop-utils.mlir
    M mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp

  Log Message:
  -----------
  [mlir][SCF] Retire `cloneWithNewYields` helper function.

This is now subsumed by `replaceLoopWithNewYields`.

Differential Revision: https://reviews.llvm.org/D125309


Compare: https://github.com/llvm/llvm-project/compare/82c5e302f9e6...1f23211cb1ee


More information about the All-commits mailing list