From d166b66cba130f02e44c3ad85b1d5e5fe65230c7 Mon Sep 17 00:00:00 2001 From: Uday Bondhugula Date: Fri, 10 Jul 2020 17:03:44 +0000 Subject: [PATCH] =?UTF-8?q?PR=20#40925:=20[MLIR]=20Update=20lhlo.const=20t?= =?UTF-8?q?o=20linalg=20lowering=20to=20use=20affine.store=20inste?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/40925 …ad of std.store The xla_lhlo.const lowering uses std.store to store a constant to 0-d memrefs. Update it to affine.store since such an access is trivially affine (no indices). An affine.store can always be lowered to std.store. Copybara import of the project: -- 9e18ede72fbbca107177bd742921e4cbf77adc82 by Uday Bondhugula : [MLIR] Update lhlo.const to linalg lowering to use affine.store instead of std.store The xla_lhlo.const lowering uses std.store to store a constant to 0-d memrefs. Update it to affine.store since such an access is trivially affine (no indices). An affine.store can always be lowered to std.store. COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/tensorflow/pull/40925 from polymage-labs:lhlo_to_linalg_affine_store 9e18ede72fbbca107177bd742921e4cbf77adc82 PiperOrigin-RevId: 320623152 --- lib/Dialect/mhlo/transforms/legalize_to_linalg.cc | 7 +++++-- tests/lhlo-legalize-to-linalg.mlir | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc index c0d6e30..79530c0 100644 --- a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc +++ b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc @@ -16,6 +16,7 @@ limitations under the License. // This file implements logic for lowering HLO/LHLO dialect to Linalg dialect. #include "third_party/absl/memory/memory.h" +#include "third_party/llvm/llvm-project/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h" #include "third_party/llvm/llvm-project/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h" #include "third_party/llvm/llvm-project/mlir/include/mlir/Dialect/Linalg/IR/LinalgTypes.h" #include "third_party/llvm/llvm-project/mlir/include/mlir/Dialect/StandardOps/IR/Ops.h" @@ -692,7 +693,8 @@ class ConstConverter : public OpConversionPattern { if (valueAttr.getType().getRank() != 0) return failure(); auto stdConstOp = rewriter.create(loc, valueAttr.getValue({})); - rewriter.create(loc, stdConstOp, constOp.getOperand()); + rewriter.create(loc, stdConstOp, constOp.getOperand(), + ValueRange()); rewriter.eraseOp(constOp); return success(); } @@ -827,7 +829,8 @@ struct LhloLegalizeToLinalg void runOnFunction() override { OwningRewritePatternList patterns; ConversionTarget target(getContext()); - target.addLegalDialect(); + target.addLegalDialect(); auto func = getFunction(); populateLHLOToLinalgConversionPattern(func.getContext(), &patterns); diff --git a/tests/lhlo-legalize-to-linalg.mlir b/tests/lhlo-legalize-to-linalg.mlir index 6981466..dd88e5c 100644 --- a/tests/lhlo-legalize-to-linalg.mlir +++ b/tests/lhlo-legalize-to-linalg.mlir @@ -329,7 +329,7 @@ func @constant(%value: memref) { return } // CHECK: %[[CONSTANT:.*]] = constant 10 : i32 -// CHECK: store %[[CONSTANT]], %{{.*}}[] : memref +// CHECK: affine.store %[[CONSTANT]], %{{.*}}[] : memref // -----