Refactor / improve replaceAllMemRefUsesWith
authorUday Bondhugula <udayb@iisc.ac.in>
Wed, 28 Aug 2019 00:56:25 +0000 (17:56 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 28 Aug 2019 00:56:56 +0000 (17:56 -0700)
commitaa2cee9cf53678dde2950087548f502009fec814
tree3921f5aaf7e1a9d05ebbdb56bb7345d6f97abec3
parent6f68def852c2443782b8ed61e9320d6aebb2ec76
Refactor / improve replaceAllMemRefUsesWith

Refactor replaceAllMemRefUsesWith to split it into two methods: the new
method does the replacement on a single op, and is used by the existing
one.

- make the methods return LogicalResult instead of bool

- Earlier, when replacement failed (due to non-deferencing uses of the
  memref), the set of ops that had already been processed would have
  been replaced leaving the IR in an inconsistent state. Now, a
  pass is made over all ops to first check for non-deferencing
  uses, and then replacement is performed. No test cases were affected
  because all clients of this method were first checking for
  non-deferencing uses before calling this method (for other reasons).
  This isn't true for a use case in another upcoming PR (scalar
  replacement); clients can now bail out with consistent IR on failure
  of replaceAllMemRefUsesWith. Add test case.

- multiple deferencing uses of the same memref in a single op is
  possible (we have no such use cases/scenarios), and this has always
  remained unsupported. Add an assertion for this.

- minor fix to another test pipeline-data-transfer case.

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#87

PiperOrigin-RevId: 265808183
mlir/include/mlir/Transforms/Utils.h
mlir/lib/Transforms/LoopFusion.cpp
mlir/lib/Transforms/PipelineDataTransfer.cpp
mlir/lib/Transforms/Utils/Utils.cpp
mlir/test/Transforms/pipeline-data-transfer.mlir