Skip to content

Commit fbe911e

Browse files
author
MaheshRavishankar
committed
[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
1 parent 05ad8e9 commit fbe911e

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

mlir/include/mlir/Conversion/Passes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ include "mlir/Pass/PassBase.td"
1515
// AffineToStandard
1616
//===----------------------------------------------------------------------===//
1717

18-
def ConvertAffineToStandard : FunctionPass<"lower-affine"> {
18+
def ConvertAffineToStandard : Pass<"lower-affine"> {
1919
let summary = "Lower Affine operations to a combination of Standard and SCF "
2020
"operations";
2121
let description = [{
2222

23-
Convert operations from the affine dialect into operations from the loop and
23+
Convert operations from the affine dialect into operations from the SCF and
2424
standard dialects.
2525

2626
`affine.for` operations are converted to `scf.for` operations that are free

mlir/include/mlir/Transforms/Passes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ std::unique_ptr<OperationPass<FuncOp>> createPipelineDataTransferPass();
5757
/// Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp)
5858
/// to equivalent lower-level constructs (flow of basic blocks and arithmetic
5959
/// primitives).
60-
std::unique_ptr<OperationPass<FuncOp>> createLowerAffinePass();
60+
std::unique_ptr<Pass> createLowerAffinePass();
6161

6262
/// Creates a pass that transforms perfectly nested loops with independent
6363
/// bounds into a single loop.

mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,21 +672,21 @@ void mlir::populateAffineToVectorConversionPatterns(
672672

673673
namespace {
674674
class LowerAffinePass : public ConvertAffineToStandardBase<LowerAffinePass> {
675-
void runOnFunction() override {
675+
void runOnOperation() override {
676676
OwningRewritePatternList patterns;
677677
populateAffineToStdConversionPatterns(patterns, &getContext());
678678
populateAffineToVectorConversionPatterns(patterns, &getContext());
679679
ConversionTarget target(getContext());
680680
target
681681
.addLegalDialect<scf::SCFDialect, StandardOpsDialect, VectorDialect>();
682-
if (failed(applyPartialConversion(getFunction(), target, patterns)))
682+
if (failed(applyPartialConversion(getOperation(), target, patterns)))
683683
signalPassFailure();
684684
}
685685
};
686686
} // namespace
687687

688688
/// Lowers If and For operations within a function into their lower level CFG
689689
/// equivalent blocks.
690-
std::unique_ptr<OperationPass<FuncOp>> mlir::createLowerAffinePass() {
690+
std::unique_ptr<Pass> mlir::createLowerAffinePass() {
691691
return std::make_unique<LowerAffinePass>();
692692
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: mlir-opt -pass-pipeline="gpu.module(lower-affine)" %s | FileCheck %s
2+
3+
#map0gpufunc = affine_map<(d0) -> (d0)>
4+
gpu.module @kernels {
5+
gpu.func @foo(%arg0 : index, %arg1 : memref<?xf32>) -> f32 {
6+
%0 = affine.apply #map0gpufunc(%arg0)
7+
%1 = load %arg1[%0] : memref<?xf32>
8+
gpu.return %1 : f32
9+
}
10+
11+
// CHECK: gpu.func
12+
// CHECK-SAME: %[[ARG0:.*]]: index
13+
// CHECK-NOT: affine.apply
14+
// CHECK: load %{{.*}}[%[[ARG0]]]
15+
}

0 commit comments

Comments
 (0)