[Mlir-commits] [mlir] fbe911e - [mlir][AffineToStandard] Make LowerAffine pass Op-agnostic.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jul 27 12:14:35 PDT 2020


Author: MaheshRavishankar
Date: 2020-07-27T12:14:17-07:00
New Revision: fbe911ee750fe62061eb15c5c8f71270fdc2fe98

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

LOG: [mlir][AffineToStandard] Make LowerAffine pass Op-agnostic.

The LowerAffine psas was a FunctionPass only for legacy
reasons. Making this Op-agnostic allows it to be used from command
line when affine expressions are within operations other than
`std.func`.

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

Added: 
    mlir/test/Conversion/AffineToStandard/lower-affine-gpu.mlir

Modified: 
    mlir/include/mlir/Conversion/Passes.td
    mlir/include/mlir/Transforms/Passes.h
    mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index 1c3b776e9780..f4c790655b1f 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -15,12 +15,12 @@ include "mlir/Pass/PassBase.td"
 // AffineToStandard
 //===----------------------------------------------------------------------===//
 
-def ConvertAffineToStandard : FunctionPass<"lower-affine"> {
+def ConvertAffineToStandard : Pass<"lower-affine"> {
   let summary = "Lower Affine operations to a combination of Standard and SCF "
                 "operations";
   let description = [{
 
-    Convert operations from the affine dialect into operations from the loop and
+    Convert operations from the affine dialect into operations from the SCF and
     standard dialects.
 
     `affine.for` operations are converted to `scf.for` operations that are free

diff  --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h
index d528723af8ec..955b0e99a1d1 100644
--- a/mlir/include/mlir/Transforms/Passes.h
+++ b/mlir/include/mlir/Transforms/Passes.h
@@ -57,7 +57,7 @@ std::unique_ptr<OperationPass<FuncOp>> createPipelineDataTransferPass();
 /// Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp)
 /// to equivalent lower-level constructs (flow of basic blocks and arithmetic
 /// primitives).
-std::unique_ptr<OperationPass<FuncOp>> createLowerAffinePass();
+std::unique_ptr<Pass> createLowerAffinePass();
 
 /// Creates a pass that transforms perfectly nested loops with independent
 /// bounds into a single loop.

diff  --git a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
index bc48ef35fcd1..a0cfdb8e6fa7 100644
--- a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
+++ b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
@@ -672,14 +672,14 @@ void mlir::populateAffineToVectorConversionPatterns(
 
 namespace {
 class LowerAffinePass : public ConvertAffineToStandardBase<LowerAffinePass> {
-  void runOnFunction() override {
+  void runOnOperation() override {
     OwningRewritePatternList patterns;
     populateAffineToStdConversionPatterns(patterns, &getContext());
     populateAffineToVectorConversionPatterns(patterns, &getContext());
     ConversionTarget target(getContext());
     target
         .addLegalDialect<scf::SCFDialect, StandardOpsDialect, VectorDialect>();
-    if (failed(applyPartialConversion(getFunction(), target, patterns)))
+    if (failed(applyPartialConversion(getOperation(), target, patterns)))
       signalPassFailure();
   }
 };
@@ -687,6 +687,6 @@ class LowerAffinePass : public ConvertAffineToStandardBase<LowerAffinePass> {
 
 /// Lowers If and For operations within a function into their lower level CFG
 /// equivalent blocks.
-std::unique_ptr<OperationPass<FuncOp>> mlir::createLowerAffinePass() {
+std::unique_ptr<Pass> mlir::createLowerAffinePass() {
   return std::make_unique<LowerAffinePass>();
 }

diff  --git a/mlir/test/Conversion/AffineToStandard/lower-affine-gpu.mlir b/mlir/test/Conversion/AffineToStandard/lower-affine-gpu.mlir
new file mode 100644
index 000000000000..8e0d4f4fe8a4
--- /dev/null
+++ b/mlir/test/Conversion/AffineToStandard/lower-affine-gpu.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt -pass-pipeline="gpu.module(lower-affine)" %s | FileCheck %s
+
+#map0gpufunc = affine_map<(d0) -> (d0)>
+gpu.module @kernels {
+  gpu.func @foo(%arg0 : index, %arg1 : memref<?xf32>) -> f32 {
+    %0 = affine.apply #map0gpufunc(%arg0)
+    %1 = load %arg1[%0] : memref<?xf32>
+    gpu.return %1 : f32
+  }
+
+//      CHECK: gpu.func
+// CHECK-SAME: %[[ARG0:.*]]: index
+//  CHECK-NOT:   affine.apply
+//      CHECK:   load %{{.*}}[%[[ARG0]]]
+}


        


More information about the Mlir-commits mailing list