[Mlir-commits] [mlir] c05db63 - [mlir] Fix for 9a7d111f4fb65ad7343dcbd4f35ee608100634e8

Nicolas Vasilache llvmlistbot at llvm.org
Wed Jan 5 08:41:00 PST 2022


Author: Nicolas Vasilache
Date: 2022-01-05T11:40:51-05:00
New Revision: c05db63887e8e3725134f67642ce1c648171bbd5

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

LOG: [mlir] Fix for 9a7d111f4fb65ad7343dcbd4f35ee608100634e8

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
    mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
index 721c47ca0130..f8378d900952 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Generalization.cpp
@@ -29,39 +29,38 @@
 using namespace mlir;
 using namespace mlir::linalg;
 
-static LogicalResult generalizeNamedOpPrecondition(Operation *op) {
-  LinalgOp namedOp = dyn_cast<LinalgOp>(op);
+static LogicalResult generalizeNamedOpPrecondition(LinalgOp linalgOp) {
   // Check if the operation is a LinalgOp but not a GenericOp.
-  if (!namedOp || isa<GenericOp>(op))
+  if (isa<GenericOp>(linalgOp))
     return failure();
   // Check if the operation has a region builder.
-  if (!namedOp.getRegionBuilder())
+  if (!linalgOp.getRegionBuilder())
     return failure();
   return success();
 }
 
 FailureOr<GenericOp> mlir::linalg::generalizeNamedOp(RewriterBase &rewriter,
-                                                     LinalgOp namedOp) {
-  if (failed(generalizeNamedOpPrecondition(namedOp)))
-    return rewriter.notifyMatchFailure(namedOp, "preconditions not met");
+                                                     LinalgOp linalgOp) {
+  if (failed(generalizeNamedOpPrecondition(linalgOp)))
+    return rewriter.notifyMatchFailure(linalgOp, "preconditions not met");
 
-  SmallVector<Value> inputOperands = namedOp.getInputOperands();
-  SmallVector<Value> outputOperands = namedOp.getOutputOperands();
-  SmallVector<AffineMap> indexingMaps = namedOp.getIndexingMaps();
+  SmallVector<Value> inputOperands = linalgOp.getInputOperands();
+  SmallVector<Value> outputOperands = linalgOp.getOutputOperands();
+  SmallVector<AffineMap> indexingMaps = linalgOp.getIndexingMaps();
   SmallVector<StringRef> iterators = llvm::to_vector<4>(
-      namedOp.iterator_types().getAsValueRange<StringAttr>());
-  SmallVector<RankedTensorType> resultTypes = namedOp.getOutputTensorTypes();
+      linalgOp.iterator_types().getAsValueRange<StringAttr>());
+  SmallVector<RankedTensorType> resultTypes = linalgOp.getOutputTensorTypes();
   SmallVector<Type> types(resultTypes.begin(), resultTypes.end());
 
   // All named ops have a region attached that can be inlined.
-  assert(namedOp->getNumRegions() == 1 &&
+  assert(linalgOp->getNumRegions() == 1 &&
          "expect named op to have one region attached");
   GenericOp genericOp =
-      rewriter.create<GenericOp>(namedOp.getLoc(), types, inputOperands,
+      rewriter.create<GenericOp>(linalgOp.getLoc(), types, inputOperands,
                                  outputOperands, indexingMaps, iterators);
-  rewriter.inlineRegionBefore(namedOp->getRegion(0), genericOp.region(),
+  rewriter.inlineRegionBefore(linalgOp->getRegion(0), genericOp.region(),
                               genericOp.region().begin());
-  rewriter.replaceOp(namedOp, genericOp->getResults());
+  rewriter.replaceOp(linalgOp, genericOp->getResults());
   return genericOp;
 }
 

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
index c2a3c2bda630..8b9c7bd2f60d 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
@@ -648,9 +648,13 @@ mlir::linalg::LinalgGeneralizationPattern::LinalgGeneralizationPattern(
 
 LogicalResult mlir::linalg::LinalgGeneralizationPattern::matchAndRewrite(
     Operation *op, PatternRewriter &rewriter) const {
+  // TODO: Interface pattern.
+  LinalgOp linalgOp = dyn_cast<LinalgOp>(op);
+  if (!linalgOp)
+    return failure();
   if (failed(filter.checkAndNotify(rewriter, op)))
     return failure();
-  FailureOr<GenericOp> genericOp = generalizeNamedOp(rewriter, op);
+  FailureOr<GenericOp> genericOp = generalizeNamedOp(rewriter, linalgOp);
   if (failed(genericOp))
     return failure();
   filter.replaceLinalgTransformationFilter(rewriter, *genericOp);


        


More information about the Mlir-commits mailing list