[Mlir-commits] [mlir] 0d61dcf - [mlir][EDSC] Make use of InsertGuard

Nicolas Vasilache llvmlistbot at llvm.org
Thu Apr 30 15:07:20 PDT 2020


Author: Nicolas Vasilache
Date: 2020-04-30T18:04:31-04:00
New Revision: 0d61dcf606b823c9cee4f16e89a7a0839be4ba36

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

LOG: [mlir][EDSC] Make use of InsertGuard

Summary:
This revision cleans up a layer of complexity in ScopedContext and uses InsertGuard instead of previously manual bookkeeping.
The method `getBuilder` is renamed to `getBuilderRef` and spurious copies of OpBuilder are tracked.

This results in some canonicalizations not happening anymore in the Linalg matmul to vector test. This test is retired because relying on DRRs for this has been shaky at best. The solution will be better support to write fused passes in C++ with more idiomatic pattern composition and application.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h
    mlir/include/mlir/Dialect/Linalg/Transforms/CMakeLists.txt
    mlir/include/mlir/EDSC/Builders.h
    mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
    mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
    mlir/lib/Dialect/Affine/EDSC/Builders.cpp
    mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
    mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
    mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
    mlir/lib/EDSC/Builders.cpp
    mlir/test/lib/DeclarativeTransforms/CMakeLists.txt
    mlir/test/lib/Transforms/CMakeLists.txt
    mlir/tools/mlir-opt/mlir-opt.cpp

Removed: 
    mlir/test/Dialect/Linalg/matmul-to-vector.mlir
    mlir/test/lib/DeclarativeTransforms/TestLinalgMatmulToVectorPatterns.td
    mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h b/mlir/include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h
index 2c506a87dc5e..3575d55c3d53 100644
--- a/mlir/include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h
+++ b/mlir/include/mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h
@@ -22,9 +22,9 @@ struct FoldedValueBuilder {
   // Builder-based
   template <typename... Args>
   FoldedValueBuilder(OperationFolder *folder, Args... args) {
-    value = folder ? folder->create<Op>(ScopedContext::getBuilder(),
+    value = folder ? folder->create<Op>(ScopedContext::getBuilderRef(),
                                         ScopedContext::getLocation(), args...)
-                   : ScopedContext::getBuilder().create<Op>(
+                   : ScopedContext::getBuilderRef().create<Op>(
                          ScopedContext::getLocation(), args...);
   }
 

diff  --git a/mlir/include/mlir/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/Transforms/CMakeLists.txt
index 932a213980f4..e90626134897 100644
--- a/mlir/include/mlir/Dialect/Linalg/Transforms/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Linalg/Transforms/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_TARGET_DEFINITIONS LinalgTransformPatterns.td)
-mlir_tablegen(TestLinalgMatmulToVectorPatterns.h.inc -gen-rewriters)
 mlir_tablegen(LinalgTransformPatterns.h.inc -gen-rewriters)
 add_public_tablegen_target(MLIRLinalgTransformPatternsIncGen)
 

diff  --git a/mlir/include/mlir/EDSC/Builders.h b/mlir/include/mlir/EDSC/Builders.h
index b5e86ae30161..7e0fbb7093b3 100644
--- a/mlir/include/mlir/EDSC/Builders.h
+++ b/mlir/include/mlir/EDSC/Builders.h
@@ -33,17 +33,17 @@ class NestedBuilder;
 /// setting and restoring of insertion points.
 class ScopedContext {
 public:
-  ScopedContext(OpBuilder &builder, Location location);
+  ScopedContext(OpBuilder &b, Location location);
 
   /// Sets the insertion point of the builder to 'newInsertPt' for the duration
   /// of the scope. The existing insertion point of the builder is restored on
   /// destruction.
-  ScopedContext(OpBuilder &builder, OpBuilder::InsertPoint newInsertPt,
+  ScopedContext(OpBuilder &b, OpBuilder::InsertPoint newInsertPt,
                 Location location);
   ~ScopedContext();
 
   static MLIRContext *getContext();
-  static OpBuilder &getBuilder();
+  static OpBuilder &getBuilderRef();
   static Location getLocation();
 
 private:
@@ -59,22 +59,19 @@ class ScopedContext {
 
   /// Top level OpBuilder.
   OpBuilder &builder;
-  /// The previous insertion point of the builder.
-  Optional<OpBuilder::InsertPoint> prevBuilderInsertPoint;
+  /// Guard to the previous insertion point.
+  OpBuilder::InsertionGuard guard;
   /// Current location.
   Location location;
   /// Parent context we return into.
   ScopedContext *enclosingScopedContext;
-  /// Defensively keeps track of the current NestedBuilder to ensure proper
-  /// scoping usage.
-  NestedBuilder *nestedBuilder;
 };
 
 template <typename Op>
 struct ValueBuilder {
   template <typename... Args>
   ValueBuilder(Args... args) {
-    value = ScopedContext::getBuilder()
+    value = ScopedContext::getBuilderRef()
                 .create<Op>(ScopedContext::getLocation(), args...)
                 .getResult();
   }
@@ -86,8 +83,8 @@ template <typename Op>
 struct OperationBuilder {
   template <typename... Args>
   OperationBuilder(Args... args) {
-    op = ScopedContext::getBuilder().create<Op>(ScopedContext::getLocation(),
-                                                args...);
+    op = ScopedContext::getBuilderRef().create<Op>(ScopedContext::getLocation(),
+                                                   args...);
   }
   operator Op() { return op; }
   operator Operation *() { return op.getOperation(); }
@@ -122,22 +119,19 @@ class NestedBuilder {
   /// let the escape.
   void enter(mlir::Block *block) {
     bodyScope = new ScopedContext(
-        ScopedContext::getBuilder(),
+        ScopedContext::getBuilderRef(),
         OpBuilder::InsertPoint(block, std::prev(block->end())),
         ScopedContext::getLocation());
     if (!block->empty()) {
       auto &termOp = block->back();
       if (termOp.isKnownTerminator())
-        ScopedContext::getBuilder().setInsertionPoint(&termOp);
+        ScopedContext::getBuilderRef().setInsertionPoint(&termOp);
     }
-    bodyScope->nestedBuilder = this;
   }
 
   /// Exit the current mlir::Block by explicitly deleting the dynamically
   /// allocated OpBuilder and ScopedContext.
   void exit() {
-    // Reclaim now to exit the scope.
-    bodyScope->nestedBuilder = nullptr;
     delete bodyScope;
     bodyScope = nullptr;
   }

diff  --git a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
index d9f5f1e2e073..3b3bf0f08370 100644
--- a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
+++ b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
@@ -118,7 +118,7 @@ class BaseViewConversionHelper {
   operator Value() { return d; }
 
 private:
-  OpBuilder &rewriter() { return ScopedContext::getBuilder(); }
+  OpBuilder &rewriter() { return ScopedContext::getBuilderRef(); }
   Location loc() { return ScopedContext::getLocation(); }
 
   MemRefDescriptor d;

diff  --git a/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp b/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
index 0335f9bb93fd..5cb781b02b2a 100644
--- a/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
+++ b/mlir/lib/Conversion/VectorToLoops/ConvertVectorToLoops.cpp
@@ -168,7 +168,7 @@ void NDTransferOpHelper<ConcreteOp>::emitInBounds(
     inBounds = inBounds && inBounds2;
   }
 
-  auto ifOp = ScopedContext::getBuilder().create<loop::IfOp>(
+  auto ifOp = ScopedContext::getBuilderRef().create<loop::IfOp>(
       ScopedContext::getLocation(), TypeRange{}, inBounds,
       /*withElseRegion=*/std::is_same<ConcreteOp, TransferReadOp>());
   BlockBuilder(&ifOp.thenRegion().front(),

diff  --git a/mlir/lib/Dialect/Affine/EDSC/Builders.cpp b/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
index 9ea37bc6d80a..50e26574b7d5 100644
--- a/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/Affine/EDSC/Builders.cpp
@@ -28,7 +28,7 @@ static Optional<Value> emitStaticFor(ArrayRef<Value> lbs, ArrayRef<Value> ubs,
   auto ubConst = dyn_cast<ConstantIndexOp>(ubDef);
   if (!lbConst || !ubConst)
     return Optional<Value>();
-  return ScopedContext::getBuilder()
+  return ScopedContext::getBuilderRef()
       .create<AffineForOp>(ScopedContext::getLocation(), lbConst.getValue(),
                            ubConst.getValue(), step)
       .getInductionVar();
@@ -38,16 +38,19 @@ LoopBuilder mlir::edsc::makeAffineLoopBuilder(Value *iv, ArrayRef<Value> lbs,
                                               ArrayRef<Value> ubs,
                                               int64_t step) {
   mlir::edsc::LoopBuilder result;
-  if (auto staticForIv = emitStaticFor(lbs, ubs, step)) {
+  if (auto staticForIv = emitStaticFor(lbs, ubs, step))
     *iv = staticForIv.getValue();
-  } else {
-    auto b = ScopedContext::getBuilder();
-    *iv =
-        Value(b.create<AffineForOp>(ScopedContext::getLocation(), lbs,
-                                    b.getMultiDimIdentityMap(lbs.size()), ubs,
-                                    b.getMultiDimIdentityMap(ubs.size()), step)
-                  .getInductionVar());
-  }
+  else
+    *iv = ScopedContext::getBuilderRef()
+              .create<AffineForOp>(
+                  ScopedContext::getLocation(), lbs,
+                  ScopedContext::getBuilderRef().getMultiDimIdentityMap(
+                      lbs.size()),
+                  ubs,
+                  ScopedContext::getBuilderRef().getMultiDimIdentityMap(
+                      ubs.size()),
+                  step)
+              .getInductionVar();
 
   auto *body = getForInductionVarOwner(*iv).getBody();
   result.enter(body);
@@ -122,7 +125,7 @@ static Value createBinaryIndexHandle(
 
   // TODO: createOrFold when available.
   Operation *op =
-      makeComposedAffineApply(ScopedContext::getBuilder(),
+      makeComposedAffineApply(ScopedContext::getBuilderRef(),
                               ScopedContext::getLocation(), map, operands)
           .getOperation();
   assert(op->getNumResults() == 1 && "Expected single result AffineApply");
@@ -218,7 +221,7 @@ static Value createIComparisonExpr(CmpIPredicate predicate, Value lhs,
   assert((lhsType.isa<IndexType>() || lhsType.isSignlessInteger()) &&
          "only integer comparisons are supported");
 
-  return ScopedContext::getBuilder().create<CmpIOp>(
+  return ScopedContext::getBuilderRef().create<CmpIOp>(
       ScopedContext::getLocation(), predicate, lhs, rhs);
 }
 
@@ -231,7 +234,7 @@ static Value createFComparisonExpr(CmpFPredicate predicate, Value lhs,
   assert(lhsType == rhsType && "cannot mix types in operators");
   assert(lhsType.isa<FloatType>() && "only float comparisons are supported");
 
-  return ScopedContext::getBuilder().create<CmpFOp>(
+  return ScopedContext::getBuilderRef().create<CmpFOp>(
       ScopedContext::getLocation(), predicate, lhs, rhs);
 }
 

diff  --git a/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp b/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
index 6ab7f043ff12..dac139f2baa7 100644
--- a/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/Linalg/EDSC/Builders.cpp
@@ -128,7 +128,7 @@ Operation *mlir::edsc::makeGenericLinalgOp(
     assert(!(outputs[i].getType().isa<RankedTensorType>() &&
              outputs[i + 1].getType().isa<MemRefType>()) &&
            "output tensors must be passed after output buffers");
-  auto &builder = edsc::ScopedContext::getBuilder();
+  auto &builder = edsc::ScopedContext::getBuilderRef();
   auto *ctx = builder.getContext();
   unsigned nInputs = inputs.size();
   unsigned nOutputs = outputs.size();
@@ -157,7 +157,7 @@ Operation *mlir::edsc::makeGenericLinalgOp(
       llvm::to_vector<8>(llvm::map_range(iteratorTypes, toString));
   // clang-format off
   auto *op =
-      edsc::ScopedContext::getBuilder()
+      edsc::ScopedContext::getBuilderRef()
           .create<linalg::GenericOp>(
               edsc::ScopedContext::getLocation(),
               types,

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
index 62a5a02ea3be..de4b6f18e42d 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/LinalgToLoops.cpp
@@ -52,7 +52,7 @@ static SmallVector<Value, 8> makeCanonicalAffineApplies(OpBuilder &b,
 
 static SmallVector<Value, 4> permuteIvs(ArrayRef<Value> ivs,
                                         Optional<AffineMap> permutation) {
-  return permutation ? applyMapToValues(ScopedContext::getBuilder(),
+  return permutation ? applyMapToValues(ScopedContext::getBuilderRef(),
                                         ScopedContext::getLocation(),
                                         permutation.getValue(), ivs)
                      : SmallVector<Value, 4>(ivs.begin(), ivs.end());
@@ -82,7 +82,7 @@ template <typename IndexedValueType, typename OpType>
 static void inlineRegionAndEmitStore(OpType op, ArrayRef<Value> indexedValues,
                                      ArrayRef<SmallVector<Value, 8>> indexing,
                                      ArrayRef<Value> outputBuffers) {
-  auto &b = ScopedContext::getBuilder();
+  auto &b = ScopedContext::getBuilderRef();
   auto &block = op.region().front();
   BlockAndValueMapping map;
   map.map(block.getArguments(), indexedValues);
@@ -110,7 +110,7 @@ struct InputAndOutputIndices {
 template <typename SingleInputPoolingOp>
 static InputAndOutputIndices getInputAndOutputIndices(ArrayRef<Value> allIvs,
                                                       SingleInputPoolingOp op) {
-  auto &b = ScopedContext::getBuilder();
+  auto &b = ScopedContext::getBuilderRef();
   auto loc = ScopedContext::getLocation();
   auto mapsRange = op.indexing_maps().template getAsRange<AffineMapAttr>();
   auto maps = llvm::to_vector<8>(
@@ -159,7 +159,7 @@ class LinalgScopedEmitter {
                                        LinalgOpType linalgOp) {
     assert(linalgOp.hasBufferSemantics() &&
            "expected linalg op with buffer semantics");
-    auto b = ScopedContext::getBuilder();
+    auto &b = ScopedContext::getBuilderRef();
     auto loc = ScopedContext::getLocation();
     unsigned nInputs = linalgOp.getNumInputs();
     unsigned nOutputs = linalgOp.getNumOutputs();
@@ -331,7 +331,7 @@ class LinalgScopedEmitter<IndexedValueType, ConvOp> {
           affine_max(dim.getType(), maxMap, ValueRange{dim}));
     }
 
-    auto b = ScopedContext::getBuilder();
+    auto &b = ScopedContext::getBuilderRef();
     Type type = convOp.input().getType().cast<MemRefType>().getElementType();
     Value zero = std_constant(type, b.getZeroAttr(type));
     Value readInput = im(clampedImIdx);
@@ -342,7 +342,7 @@ class LinalgScopedEmitter<IndexedValueType, ConvOp> {
   static void emitScalarImplementation(ArrayRef<Value> allIvs, ConvOp convOp) {
     assert(convOp.hasBufferSemantics() &&
            "expected linalg op with buffer semantics");
-    auto b = ScopedContext::getBuilder();
+    auto &b = ScopedContext::getBuilderRef();
     auto loc = ScopedContext::getLocation();
     auto mapsRange = convOp.indexing_maps().getAsRange<AffineMapAttr>();
     auto maps = llvm::to_vector<8>(llvm::map_range(
@@ -445,7 +445,7 @@ class LinalgScopedEmitter<IndexedValueType, IndexedGenericOp> {
                                        IndexedGenericOp indexedGenericOp) {
     assert(indexedGenericOp.hasBufferSemantics() &&
            "expected linalg op with buffer semantics");
-    auto b = ScopedContext::getBuilder();
+    auto &b = ScopedContext::getBuilderRef();
     auto loc = ScopedContext::getLocation();
     unsigned nInputs = indexedGenericOp.getNumInputs();
     unsigned nOutputs = indexedGenericOp.getNumOutputs();
@@ -606,7 +606,7 @@ LinalgOpToLoopsImpl<LoopTy, ConcreteOpTy>::doit(Operation *op,
 
   SmallVector<Value, 4> allIvs(nLoops);
   auto loopRanges =
-      emitLoopRanges(scope.getBuilder(), scope.getLocation(), invertedMap,
+      emitLoopRanges(scope.getBuilderRef(), scope.getLocation(), invertedMap,
                      getViewSizes(rewriter, linalgOp));
   assert(loopRanges.size() == allIvs.size());
   Impl::doit(linalgOp, loopRanges, allIvs);

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
index dd872a69d28d..4b1fed8d3427 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
@@ -384,7 +384,7 @@ Optional<TiledLinalgOp> static tileLinalgOpImpl(OpBuilder &b, LinalgOp op,
         linalg_range(range.offset, range.size, range.stride));
   }
   GenericLoopNestRangeBuilder<LoopTy>(ivs, linalgRanges)([&] {
-    auto b = ScopedContext::getBuilder();
+    auto &b = ScopedContext::getBuilderRef();
     auto loc = ScopedContext::getLocation();
     SmallVector<Value, 4> ivValues(ivs.begin(), ivs.end());
 

diff  --git a/mlir/lib/EDSC/Builders.cpp b/mlir/lib/EDSC/Builders.cpp
index 5b94ebc994a7..ad12561d81c1 100644
--- a/mlir/lib/EDSC/Builders.cpp
+++ b/mlir/lib/EDSC/Builders.cpp
@@ -15,32 +15,25 @@
 using namespace mlir;
 using namespace mlir::edsc;
 
-mlir::edsc::ScopedContext::ScopedContext(OpBuilder &builder, Location location)
-    : builder(builder), location(location),
-      enclosingScopedContext(ScopedContext::getCurrentScopedContext()),
-      nestedBuilder(nullptr) {
+mlir::edsc::ScopedContext::ScopedContext(OpBuilder &b, Location location)
+    : builder(b), guard(builder), location(location),
+      enclosingScopedContext(ScopedContext::getCurrentScopedContext()) {
   getCurrentScopedContext() = this;
 }
 
 /// Sets the insertion point of the builder to 'newInsertPt' for the duration
 /// of the scope. The existing insertion point of the builder is restored on
 /// destruction.
-mlir::edsc::ScopedContext::ScopedContext(OpBuilder &builder,
+mlir::edsc::ScopedContext::ScopedContext(OpBuilder &b,
                                          OpBuilder::InsertPoint newInsertPt,
                                          Location location)
-    : builder(builder), prevBuilderInsertPoint(builder.saveInsertionPoint()),
-      location(location),
-      enclosingScopedContext(ScopedContext::getCurrentScopedContext()),
-      nestedBuilder(nullptr) {
+    : builder(b), guard(builder), location(location),
+      enclosingScopedContext(ScopedContext::getCurrentScopedContext()) {
   getCurrentScopedContext() = this;
   builder.restoreInsertionPoint(newInsertPt);
 }
 
 mlir::edsc::ScopedContext::~ScopedContext() {
-  assert(!nestedBuilder &&
-         "Active NestedBuilder must have been exited at this point!");
-  if (prevBuilderInsertPoint)
-    builder.restoreInsertionPoint(*prevBuilderInsertPoint);
   getCurrentScopedContext() = enclosingScopedContext;
 }
 
@@ -49,7 +42,7 @@ ScopedContext *&mlir::edsc::ScopedContext::getCurrentScopedContext() {
   return context;
 }
 
-OpBuilder &mlir::edsc::ScopedContext::getBuilder() {
+OpBuilder &mlir::edsc::ScopedContext::getBuilderRef() {
   assert(ScopedContext::getCurrentScopedContext() &&
          "Unexpected Null ScopedContext");
   return ScopedContext::getCurrentScopedContext()->builder;
@@ -62,15 +55,15 @@ Location mlir::edsc::ScopedContext::getLocation() {
 }
 
 MLIRContext *mlir::edsc::ScopedContext::getContext() {
-  return getBuilder().getContext();
+  return getBuilderRef().getContext();
 }
 
 BlockHandle mlir::edsc::BlockHandle::create(ArrayRef<Type> argTypes) {
-  auto &currentB = ScopedContext::getBuilder();
+  auto &currentB = ScopedContext::getBuilderRef();
   auto *ib = currentB.getInsertionBlock();
   auto ip = currentB.getInsertionPoint();
   BlockHandle res;
-  res.block = ScopedContext::getBuilder().createBlock(ib->getParent());
+  res.block = ScopedContext::getBuilderRef().createBlock(ib->getParent());
   // createBlock sets the insertion point inside the block.
   // We do not want this behavior when using declarative builders with nesting.
   currentB.setInsertionPoint(ib, ip);
@@ -82,17 +75,15 @@ BlockHandle mlir::edsc::BlockHandle::create(ArrayRef<Type> argTypes) {
 
 BlockHandle mlir::edsc::BlockHandle::createInRegion(Region &region,
                                                     ArrayRef<Type> argTypes) {
-  auto &currentB = ScopedContext::getBuilder();
   BlockHandle res;
   region.push_back(new Block);
   res.block = &region.back();
   // createBlock sets the insertion point inside the block.
   // We do not want this behavior when using declarative builders with nesting.
-  OpBuilder::InsertionGuard g(currentB);
-  currentB.setInsertionPoint(res.block, res.block->begin());
-  for (auto t : argTypes) {
-    res.block->addArgument(t);
-  }
+  OpBuilder::InsertionGuard g(ScopedContext::getBuilderRef());
+  ScopedContext::getBuilderRef().setInsertionPoint(res.block,
+                                                   res.block->begin());
+  res.block->addArguments(argTypes);
   return res;
 }
 

diff  --git a/mlir/test/Dialect/Linalg/matmul-to-vector.mlir b/mlir/test/Dialect/Linalg/matmul-to-vector.mlir
deleted file mode 100644
index 351b2041d8c0..000000000000
--- a/mlir/test/Dialect/Linalg/matmul-to-vector.mlir
+++ /dev/null
@@ -1,16 +0,0 @@
-// RUN: mlir-opt %s -linalg-matmul-to-vector | FileCheck %s
-
-func @matmul_perm(%A: memref<1584x1584xf32, offset: 0, strides: [1584, 1]>,
-                  %B: memref<1584x1584xf32, offset: 0, strides: [1584, 1]>,
-                  %C: memref<1584x1584xf32, offset: 0, strides: [1584, 1]>) {
-  linalg.matmul(%A, %B, %C) {__internal_linalg_transform__ = "__with_perm__"} :
-    memref<1584x1584xf32, offset: 0, strides: [1584, 1]>,
-    memref<1584x1584xf32, offset: 0, strides: [1584, 1]>,
-    memref<1584x1584xf32, offset: 0, strides: [1584, 1]>
-  return
-}
-
-// CHECK-LABEL:func @matmul_perm
-//      CHECK:        vector.contract
-// CHECK-SAME: iterator_types = ["parallel", "parallel", "reduction"]
-// CHECK-SAME: : vector<8x16xf32>, vector<16x12xf32> into vector<8x12xf32>

diff  --git a/mlir/test/lib/DeclarativeTransforms/CMakeLists.txt b/mlir/test/lib/DeclarativeTransforms/CMakeLists.txt
index 0ac97b9291d3..4ca78772b68a 100644
--- a/mlir/test/lib/DeclarativeTransforms/CMakeLists.txt
+++ b/mlir/test/lib/DeclarativeTransforms/CMakeLists.txt
@@ -7,9 +7,3 @@ add_dependencies(MLIRTestLinalgTransformPatternsIncGen LinalgOdsGen)
 set(LLVM_TARGET_DEFINITIONS TestVectorTransformPatterns.td)
 mlir_tablegen(TestVectorTransformPatterns.h.inc -gen-rewriters)
 add_public_tablegen_target(MLIRTestVectorTransformPatternsIncGen)
-
-set(LLVM_TARGET_DEFINITIONS TestLinalgMatmulToVectorPatterns.td)
-mlir_tablegen(TestLinalgMatmulToVectorPatterns.h.inc -gen-rewriters)
-add_public_tablegen_target(MLIRTestLinalgMatmulToVectorPatternsIncGen)
-# Including Linalg in TableGen requires to depends on generated files
-add_dependencies(MLIRTestLinalgTransformPatternsIncGen LinalgOdsGen)

diff  --git a/mlir/test/lib/DeclarativeTransforms/TestLinalgMatmulToVectorPatterns.td b/mlir/test/lib/DeclarativeTransforms/TestLinalgMatmulToVectorPatterns.td
deleted file mode 100644
index 7fa4a3db6128..000000000000
--- a/mlir/test/lib/DeclarativeTransforms/TestLinalgMatmulToVectorPatterns.td
+++ /dev/null
@@ -1,43 +0,0 @@
-//===- TestLinalgMatmulToVectorPatterns.td - Test patterns -*- 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
-//
-//===----------------------------------------------------------------------===//
-//
-// This is the pattern definition file for declarative Linalg transformations
-// tests.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef TEST_LINALG_MATMUL_TO_VECTOR_PATTERNS
-#define TEST_LINALG_MATMUL_TO_VECTOR_PATTERNS
-
-include "mlir/Dialect/Linalg/Transforms/LinalgTransformPatterns.td"
-include "mlir/Dialect/Vector/VectorTransformPatterns.td"
-
-//===----------------------------------------------------------------------===//
-// Linalg tiling and permutation patterns.
-//===----------------------------------------------------------------------===//
-def : Pat<(MatmulOp:$op $_, $_, $_),
-          (TileLinalgOp<[768, 264, 768], "L2__with_perm__", [1, 2, 0]>),
-         [(Constraint<HasLinalgTransformMarker<"__with_perm__">>)]>;
-def : Pat<(MatmulOp:$op $_, $_, $_),
-          (TileLinalgOp<[8, 12, 16], "L1__with_perm__", [1, 0, 2]>),
-         [(Constraint<HasLinalgTransformMarker<"L2__with_perm__">>)]>;
-def : Pat<(MatmulOp:$op $_, $_, $_),
-          (PromoteSubviewsLinalgOp),
-         [(Constraint<HasOperandsOfType<"SubViewOp">>),
-          (Constraint<HasLinalgTransformMarker<"L1__with_perm__">>)]>;
-
-//===----------------------------------------------------------------------===//
-// Linalg to vector contraction patterns.
-//===----------------------------------------------------------------------===//
-def : Pattern<(MatmulOp:$op $_, $_, $_),
-              [(VectorizeLinalgOp)],
-              [(Constraint<And<[
-                HasLinalgTransformMarker<"L1__with_perm__">,
-                PreconditionVectorizeLinalgOp]>>)]>;
-
-#endif // TEST_LINALG_MATMUL_TO_VECTOR_PATTERNS

diff  --git a/mlir/test/lib/Transforms/CMakeLists.txt b/mlir/test/lib/Transforms/CMakeLists.txt
index 118c70c62266..0e0e15fb2a93 100644
--- a/mlir/test/lib/Transforms/CMakeLists.txt
+++ b/mlir/test/lib/Transforms/CMakeLists.txt
@@ -9,7 +9,6 @@ add_llvm_library(MLIRTestTransforms
   TestGpuMemoryPromotion.cpp
   TestGpuParallelLoopMapping.cpp
   TestInlining.cpp
-  TestLinalgMatmulToVector.cpp
   TestLinalgTransforms.cpp
   TestLiveness.cpp
   TestLoopMapping.cpp
@@ -26,7 +25,6 @@ add_llvm_library(MLIRTestTransforms
 
   DEPENDS
   MLIRStandardOpsIncGen
-  MLIRTestLinalgMatmulToVectorPatternsIncGen
   MLIRTestLinalgTransformPatternsIncGen
   MLIRTestVectorTransformPatternsIncGen
 )

diff  --git a/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp b/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
deleted file mode 100644
index e32f4d3dd6c5..000000000000
--- a/mlir/test/lib/Transforms/TestLinalgMatmulToVector.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-//===- TestLinalgMatmulToVector.cpp - Test VectorTransfers lowering -------===//
-//
-// 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 <type_traits>
-
-#include "mlir/Dialect/Affine/IR/AffineOps.h"
-#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
-#include "mlir/Dialect/Linalg/Transforms/LinalgTransforms.h"
-#include "mlir/Dialect/Vector/VectorOps.h"
-#include "mlir/Dialect/Vector/VectorTransforms.h"
-#include "mlir/IR/PatternMatch.h"
-#include "mlir/IR/StandardTypes.h"
-#include "mlir/Pass/Pass.h"
-
-using namespace mlir;
-using namespace mlir::linalg;
-using namespace mlir::vector;
-
-namespace {
-#include "TestLinalgMatmulToVectorPatterns.h.inc"
-
-struct DeclarativeTransforms
-    : public PassWrapper<DeclarativeTransforms, FunctionPass> {
-  void runOnFunction() override {
-    OwningRewritePatternList patterns;
-    auto *context = &getContext();
-    AffineApplyOp::getCanonicalizationPatterns(patterns, context);
-    AffineMinOp::getCanonicalizationPatterns(patterns, context);
-    AffineMaxOp::getCanonicalizationPatterns(patterns, context);
-    AllocOp::getCanonicalizationPatterns(patterns, context);
-    SubViewOp::getCanonicalizationPatterns(patterns, context);
-    ViewOp::getCanonicalizationPatterns(patterns, context);
-    populateWithGenerated(context, &patterns);
-    applyPatternsAndFoldGreedily(getFunction(), patterns);
-  }
-};
-} // end anonymous namespace
-
-namespace mlir {
-void registerTestLinalgMatmulToVectorPass() {
-  PassRegistration<DeclarativeTransforms> pass(
-      "linalg-matmul-to-vector",
-      "Test declarative transform patterns for matmul 3-D tiling + promotion"
-      " + vectorization");
-}
-} // namespace mlir

diff  --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index c08b9c2cc1cf..d9c822169932 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -42,7 +42,6 @@ void registerTestAffineDataCopyPass();
 void registerTestAllReduceLoweringPass();
 void registerTestAffineLoopUnswitchingPass();
 void registerTestBufferPlacementPreparationPass();
-void registerTestLinalgMatmulToVectorPass();
 void registerTestLoopPermutationPass();
 void registerTestCallGraphPass();
 void registerTestConstantFold();
@@ -106,7 +105,6 @@ void registerTestPasses() {
   registerTestAffineDataCopyPass();
   registerTestAllReduceLoweringPass();
   registerTestAffineLoopUnswitchingPass();
-  registerTestLinalgMatmulToVectorPass();
   registerTestLoopPermutationPass();
   registerTestCallGraphPass();
   registerTestConstantFold();


        


More information about the Mlir-commits mailing list