[Mlir-commits] [mlir] a25f5cd - Revert "[MLIR] Lower shape.num_elements -> shape.reduce."

Mehdi Amini llvmlistbot at llvm.org
Sun Jun 7 12:33:33 PDT 2020


Author: Mehdi Amini
Date: 2020-06-07T19:32:36Z
New Revision: a25f5cd70cef6f74eed45a61c14abca98cd416e4

URL: https://github.com/llvm/llvm-project/commit/a25f5cd70cef6f74eed45a61c14abca98cd416e4
DIFF: https://github.com/llvm/llvm-project/commit/a25f5cd70cef6f74eed45a61c14abca98cd416e4.diff

LOG: Revert "[MLIR] Lower shape.num_elements -> shape.reduce."

This reverts commit e80617df894b00d12d5afb9d819e6ff9141cc29e.

This broke the build with `-DBUILD_SHARED_LIBS=ON`

Added: 
    

Modified: 
    mlir/docs/Passes.md
    mlir/include/mlir/Dialect/Shape/CMakeLists.txt
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/include/mlir/InitAllPasses.h
    mlir/lib/Dialect/Shape/CMakeLists.txt
    mlir/lib/Dialect/Shape/IR/Shape.cpp

Removed: 
    mlir/include/mlir/Dialect/Shape/Transforms/CMakeLists.txt
    mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
    mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
    mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
    mlir/lib/Dialect/Shape/Transforms/PassDetail.h
    mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp
    mlir/test/Dialect/Shape/shape-to-shape.mlir


################################################################################
diff  --git a/mlir/docs/Passes.md b/mlir/docs/Passes.md
index 451b76370c7e..0f48396b220e 100644
--- a/mlir/docs/Passes.md
+++ b/mlir/docs/Passes.md
@@ -36,10 +36,6 @@ This document describes the available MLIR passes and their contracts.
 
 [include "QuantPasses.md"]
 
-## `shape` Dialect Passes
-
-[include "ShapePasses.md"]
-
 ## `spv` Dialect Passes
 
 [include "SPIRVPasses.md"]

diff  --git a/mlir/include/mlir/Dialect/Shape/CMakeLists.txt b/mlir/include/mlir/Dialect/Shape/CMakeLists.txt
index 9f57627c321f..f33061b2d87c 100644
--- a/mlir/include/mlir/Dialect/Shape/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Shape/CMakeLists.txt
@@ -1,2 +1 @@
 add_subdirectory(IR)
-add_subdirectory(Transforms)

diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index c0877be8eaf3..40fde4837407 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -327,7 +327,7 @@ def Shape_ReduceOp : Shape_Op<"reduce",
 
   let arguments = (ins Shape_ShapeType:$shape, Variadic<AnyType>:$initVals);
   let results = (outs Variadic<AnyType>:$result);
-  let regions = (region SizedRegion<1>:$region);
+  let regions = (region SizedRegion<1>:$body);
 
   let builders = [
     OpBuilder<"OpBuilder &builder, OperationState &result, "

diff  --git a/mlir/include/mlir/Dialect/Shape/Transforms/CMakeLists.txt b/mlir/include/mlir/Dialect/Shape/Transforms/CMakeLists.txt
deleted file mode 100644
index 629b8c0db294..000000000000
--- a/mlir/include/mlir/Dialect/Shape/Transforms/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-set(LLVM_TARGET_DEFINITIONS Passes.td)
-mlir_tablegen(Passes.h.inc -gen-pass-decls)
-add_public_tablegen_target(MLIRShapeTransformsIncGen)
-
-add_mlir_doc(Passes -gen-pass-doc ShapePasses ./)

diff  --git a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
deleted file mode 100644
index 29cf9d1b6715..000000000000
--- a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.h
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This header file defines prototypes that expose pass constructors in the
-// shape transformation library.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_
-#define MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_
-
-#include <memory>
-
-namespace mlir {
-
-class Pass;
-
-/// Creates an instance of the ShapeToShapeLowering pass that legalizes Shape
-/// dialect to be convertible to Standard. For example, `shape.num_elements` get
-/// transformed to `shape.reduce`, which can be lowered to SCF and Standard.
-std::unique_ptr<Pass> createShapeToShapeLowering();
-
-} // end namespace mlir
-
-#endif // MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES_H_

diff  --git a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td b/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
deleted file mode 100644
index 46dc4dc37160..000000000000
--- a/mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- Passes.td - ShapeOps pass definition file ----------*- tablegen -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES
-#define MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES
-
-include "mlir/Pass/PassBase.td"
-
-def ShapeToShapeLowering : FunctionPass<"shape-to-shape-lowering"> {
-  let summary = "Legalize Shape dialect to be convertible to Standard";
-  let constructor = "mlir::createShapeToShapeLowering()";
-}
-
-#endif // MLIR_DIALECT_SHAPE_TRANSFORMS_PASSES

diff  --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h
index 957153770351..c0c79d1c69ef 100644
--- a/mlir/include/mlir/InitAllPasses.h
+++ b/mlir/include/mlir/InitAllPasses.h
@@ -37,7 +37,6 @@
 #include "mlir/Dialect/Quant/Passes.h"
 #include "mlir/Dialect/SCF/Passes.h"
 #include "mlir/Dialect/SPIRV/Passes.h"
-#include "mlir/Dialect/Shape/Transforms/Passes.h"
 #include "mlir/Dialect/StandardOps/Transforms/Passes.h"
 #include "mlir/Transforms/LocationSnapshot.h"
 #include "mlir/Transforms/Passes.h"
@@ -95,10 +94,6 @@ inline void registerAllPasses() {
   // Standard
 #define GEN_PASS_REGISTRATION
 #include "mlir/Dialect/StandardOps/Transforms/Passes.h.inc"
-
-  // Shape
-#define GEN_PASS_REGISTRATION
-#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
 }
 
 } // namespace mlir

diff  --git a/mlir/lib/Dialect/Shape/CMakeLists.txt b/mlir/lib/Dialect/Shape/CMakeLists.txt
index 472d2c5d79b9..2af3de896568 100644
--- a/mlir/lib/Dialect/Shape/CMakeLists.txt
+++ b/mlir/lib/Dialect/Shape/CMakeLists.txt
@@ -14,5 +14,3 @@ add_mlir_dialect_library(MLIRShape
   MLIRIR
   MLIRSideEffectInterfaces
   )
-
-add_subdirectory(Transforms)

diff  --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index 0077b354adec..d29f48e7c51e 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -473,7 +473,7 @@ void ReduceOp::build(OpBuilder &builder, OperationState &result, Value shape,
 
 static LogicalResult verify(ReduceOp op) {
   // Verify block arg types.
-  Block &block = op.region().front();
+  Block &block = op.body().front();
 
   auto blockArgsCount = op.initVals().size() + 2;
   if (block.getNumArguments() != blockArgsCount)
@@ -529,7 +529,7 @@ static void print(OpAsmPrinter &p, ReduceOp op) {
   p << op.getOperationName() << '(' << op.shape() << ", " << op.initVals()
     << ") ";
   p.printOptionalArrowTypeList(op.getResultTypes());
-  p.printRegion(op.region());
+  p.printRegion(op.body());
   p.printOptionalAttrDict(op.getAttrs());
 }
 

diff  --git a/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
deleted file mode 100644
index 3c0ec3211e69..000000000000
--- a/mlir/lib/Dialect/Shape/Transforms/CMakeLists.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-add_mlir_dialect_library(MLIRShapeOpsTransforms
-  ShapeToShapeLowering.cpp
-
-  ADDITIONAL_HEADER_DIRS
-  ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/ShapeOps/Transforms
-
-  DEPENDS
-  MLIRShapeTransformsIncGen
-  )
-
-target_link_libraries(MLIRShapeOpsTransforms
-  PUBLIC
-  MLIRIR
-  MLIRPass
-  MLIRShape
-  MLIRSupport
-  )

diff  --git a/mlir/lib/Dialect/Shape/Transforms/PassDetail.h b/mlir/lib/Dialect/Shape/Transforms/PassDetail.h
deleted file mode 100644
index abb5c21d66bb..000000000000
--- a/mlir/lib/Dialect/Shape/Transforms/PassDetail.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===- PassDetail.h - Shape Pass class details ------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef DIALECT_SHAPE_TRANSFORMS_PASSDETAIL_H_
-#define DIALECT_SHAPE_TRANSFORMS_PASSDETAIL_H_
-
-#include "mlir/Pass/Pass.h"
-
-namespace mlir {
-
-#define GEN_PASS_CLASSES
-#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
-
-} // end namespace mlir
-
-#endif // DIALECT_SHAPE_TRANSFORMS_PASSDETAIL_H_

diff  --git a/mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp b/mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp
deleted file mode 100644
index 1ba68a0a94ee..000000000000
--- a/mlir/lib/Dialect/Shape/Transforms/ShapeToShapeLowering.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-//===- ShapeToShapeLowering.cpp - Prepare for lowering to Standard --------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "PassDetail.h"
-#include "mlir/Dialect/Shape/IR/Shape.h"
-#include "mlir/Dialect/Shape/Transforms/Passes.h"
-#include "mlir/IR/Builders.h"
-#include "mlir/IR/PatternMatch.h"
-#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/DialectConversion.h"
-
-using namespace mlir;
-using namespace mlir::shape;
-
-namespace {
-/// Converts `shape.num_elements` to `shape.reduce`.
-struct NumElementsOpConverter : public OpRewritePattern<NumElementsOp> {
-public:
-  using OpRewritePattern::OpRewritePattern;
-
-  LogicalResult matchAndRewrite(NumElementsOp op,
-                                PatternRewriter &rewriter) const final;
-};
-} // namespace
-
-LogicalResult
-NumElementsOpConverter::matchAndRewrite(NumElementsOp op,
-                                        PatternRewriter &rewriter) const {
-  auto loc = op.getLoc();
-  Value init = rewriter.create<ConstSizeOp>(loc, rewriter.getIndexAttr(1));
-  ReduceOp reduce = rewriter.create<ReduceOp>(loc, op.shape(), init);
-
-  // Generate reduce operator.
-  Block *body = reduce.getBody();
-  OpBuilder b = OpBuilder::atBlockEnd(body);
-  Value product =
-      b.create<MulOp>(loc, body->getArgument(1), body->getArgument(2));
-  b.create<YieldOp>(loc, product);
-
-  rewriter.replaceOp(op, reduce.result());
-  return success();
-}
-
-namespace {
-struct ShapeToShapeLowering
-    : public ShapeToShapeLoweringBase<ShapeToShapeLowering> {
-  void runOnFunction() override;
-};
-} // namespace
-
-void ShapeToShapeLowering::runOnFunction() {
-  OwningRewritePatternList patterns;
-  patterns.insert<NumElementsOpConverter>(&getContext());
-
-  ConversionTarget target(getContext());
-  target.addLegalDialect<ShapeDialect>();
-  target.addIllegalOp<NumElementsOp>();
-  if (failed(mlir::applyPartialConversion(getFunction(), target, patterns)))
-    signalPassFailure();
-}
-
-std::unique_ptr<Pass> mlir::createShapeToShapeLowering() {
-  return std::make_unique<ShapeToShapeLowering>();
-}

diff  --git a/mlir/test/Dialect/Shape/shape-to-shape.mlir b/mlir/test/Dialect/Shape/shape-to-shape.mlir
deleted file mode 100644
index d2338cddc5e1..000000000000
--- a/mlir/test/Dialect/Shape/shape-to-shape.mlir
+++ /dev/null
@@ -1,16 +0,0 @@
-// RUN: mlir-opt -shape-to-shape-lowering -split-input-file %s | FileCheck %s --dump-input-on-failure
-
-// CHECK-LABEL: func @num_elements_to_reduce(
-// CHECK-SAME:    [[ARG:%.*]]: !shape.shape) -> [[SIZE_TY:!.*]] {
-func @num_elements_to_reduce(%shape : !shape.shape) -> !shape.size {
-  %num_elements = shape.num_elements %shape
-  return %num_elements : !shape.size
-}
-// CHECK: [[C1:%.*]] = shape.const_size 1
-// CHECK: [[NUM_ELEMENTS:%.*]] = shape.reduce([[ARG]], [[C1]])  -> [[SIZE_TY]]
-// CHECK: ^bb0({{.*}}: index, [[DIM:%.*]]: [[SIZE_TY]], [[ACC:%.*]]: [[SIZE_TY]]
-// CHECK:   [[NEW_ACC:%.*]] = shape.mul [[DIM]], [[ACC]]
-// CHECK:   shape.yield [[NEW_ACC]] : [[SIZE_TY]]
-// CHECK: }
-// CHECK: return [[NUM_ELEMENTS]] : [[SIZE_TY]]
-


        


More information about the Mlir-commits mailing list