aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Springer <mspringer@nvidia.com>2024-10-28 03:46:58 +0100
committerMatthias Springer <mspringer@nvidia.com>2024-10-28 05:44:53 +0100
commitf6b15963995594d4ea61f56d7473e38b2583fe53 (patch)
tree4865fb72dde4494a4707392845449d8eaa768f1a
parent5621929f7f4878c318deecb592cd03f5ecbb83ba (diff)
downloadllvm-users/matthias-springer/finalize_memref.zip
llvm-users/matthias-springer/finalize_memref.tar.gz
llvm-users/matthias-springer/finalize_memref.tar.bz2
[mlir][memref] Make `finalize-memref-to-llvm` the last MemRef passusers/matthias-springer/finalize_memref
This commit updates all test cases and pass pipelines such that `finalize-memref-to-llvm` is the last pass that deals with MemRef types. (As the name already suggests.) This is now also mentioned in the pass documentation. This change is preparation of merging the 1:1 and 1:N dialect conversions. As part of that change, argument materializations are going to disappear. To understand why `finalize-memref-to-llvm` should be the final MemRef pass, consider this example: ```mlir // RUN: mlir-opt -convert-func-to-llvm func.func @foo(%m: memref<5xf32>) { %r = vector.transfer_read %m[...] ... ... } ``` The output (assuming bare pointer calling convention) will be as follows: ```mlir func.func @foo(%ptr: !llvm.ptr) { %m = builtin.unrealized_conversion_cast %ptr : !llvm.ptr to memref<5xf32> } ```
-rw-r--r--mlir/include/mlir/Conversion/Passes.td15
-rw-r--r--mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp3
-rw-r--r--mlir/test/Conversion/FuncToLLVM/calling-convention.mlir4
-rw-r--r--mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp4
-rw-r--r--mlir/test/mlir-cpu-runner/async-value.mlir2
-rw-r--r--mlir/test/mlir-cpu-runner/bare-ptr-call-conv.mlir2
-rw-r--r--mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir2
-rw-r--r--mlir/test/mlir-cpu-runner/memref-reshape.mlir2
-rw-r--r--mlir/test/mlir-cpu-runner/sgemm-naive-codegen.mlir2
-rw-r--r--mlir/test/mlir-cpu-runner/unranked-memref.mlir2
-rw-r--r--mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp2
-rw-r--r--mlir/unittests/ExecutionEngine/Invoke.cpp2
12 files changed, 24 insertions, 18 deletions
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index 4d272ba..8cfdf22 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -829,11 +829,16 @@ def FinalizeMemRefToLLVMConversionPass :
Pass<"finalize-memref-to-llvm", "ModuleOp"> {
let summary = "Finalize MemRef dialect to LLVM dialect conversion";
let description = [{
- Finalize the conversion of the operations from the MemRef
- dialect to the LLVM dialect.
- This conversion will not convert some complex MemRef
- operations. Make sure to run `expand-strided-metadata`
- beforehand for these.
+ Finalize the conversion of operations with MemRef semantics to the LLVM
+ dialect. This pass converts operations from the MemRef dialect. This pass
+ should be the last pass that deals with MemRef types in your pass pipeline.
+ I.e., passes like `convert-func-to-llvm` and `convert-vector-to-llvm`
+ should run before this pass.
+
+ This conversion will not convert some complex MemRef operations. Make sure
+ to run `expand-strided-metadata` beforehand for these. It will also not
+ convert operations with MemRef semantics from dialects that have their own
+ conversion passes (e.g., `convert-func-to-llvm`).
}];
let dependentDialects = ["LLVM::LLVMDialect"];
let options = [
diff --git a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
index abc4a4c..9736951 100644
--- a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp
@@ -79,7 +79,6 @@ void mlir::sparse_tensor::buildSparsifier(OpPassManager &pm,
pm.addPass(createLowerAffinePass());
pm.addPass(
createConvertVectorToLLVMPass(options.convertVectorToLLVMOptions()));
- pm.addPass(createFinalizeMemRefToLLVMConversionPass());
pm.addNestedPass<func::FuncOp>(createConvertComplexToStandardPass());
pm.addNestedPass<func::FuncOp>(arith::createArithExpandOpsPass());
pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
@@ -105,6 +104,8 @@ void mlir::sparse_tensor::buildSparsifier(OpPassManager &pm,
pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
}
+ pm.addPass(createFinalizeMemRefToLLVMConversionPass());
+
// Ensure all casts are realized.
pm.addPass(createReconcileUnrealizedCastsPass());
}
diff --git a/mlir/test/Conversion/FuncToLLVM/calling-convention.mlir b/mlir/test/Conversion/FuncToLLVM/calling-convention.mlir
index 18734d1..9143b93 100644
--- a/mlir/test/Conversion/FuncToLLVM/calling-convention.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/calling-convention.mlir
@@ -1,5 +1,5 @@
-// RUN: mlir-opt -finalize-memref-to-llvm -llvm-request-c-wrappers -convert-func-to-llvm -reconcile-unrealized-casts %s | FileCheck %s
-// RUN: mlir-opt -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts %s | FileCheck %s --check-prefix=EMIT_C_ATTRIBUTE
+// RUN: mlir-opt -llvm-request-c-wrappers -convert-func-to-llvm -finalize-memref-to-llvm -reconcile-unrealized-casts %s | FileCheck %s
+// RUN: mlir-opt -convert-func-to-llvm -finalize-memref-to-llvm -reconcile-unrealized-casts %s | FileCheck %s --check-prefix=EMIT_C_ATTRIBUTE
// This tests the default memref calling convention and the emission of C
// wrappers. We don't need to separate runs because the wrapper-emission
diff --git a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
index 10c2161..f130d4a 100644
--- a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
+++ b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
@@ -69,10 +69,10 @@ void buildTestLowerToLLVM(OpPassManager &pm,
pm.addPass(memref::createExpandStridedMetadataPass());
// The expansion may create affine expressions. Get rid of them.
pm.addPass(createLowerAffinePass());
- // Convert MemRef to LLVM (always needed).
- pm.addPass(createFinalizeMemRefToLLVMConversionPass());
// Convert Func to LLVM (always needed).
pm.addPass(createConvertFuncToLLVMPass());
+ // Convert MemRef to LLVM (always needed).
+ pm.addPass(createFinalizeMemRefToLLVMConversionPass());
// Convert Index to LLVM (always needed).
pm.addPass(createConvertIndexToLLVMPass());
// Convert remaining unrealized_casts (always needed).
diff --git a/mlir/test/mlir-cpu-runner/async-value.mlir b/mlir/test/mlir-cpu-runner/async-value.mlir
index 836b40a..b20d8e4 100644
--- a/mlir/test/mlir-cpu-runner/async-value.mlir
+++ b/mlir/test/mlir-cpu-runner/async-value.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline="builtin.module(async-to-async-runtime,func.func(async-runtime-ref-counting,async-runtime-ref-counting-opt),convert-async-to-llvm,func.func(convert-arith-to-llvm),convert-vector-to-llvm,finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \
+// RUN: mlir-opt %s -pass-pipeline="builtin.module(async-to-async-runtime,func.func(async-runtime-ref-counting,async-runtime-ref-counting-opt),convert-async-to-llvm,func.func(convert-arith-to-llvm),convert-vector-to-llvm,convert-func-to-llvm,finalize-memref-to-llvm,reconcile-unrealized-casts)" \
// RUN: | mlir-cpu-runner \
// RUN: -e main -entry-point-result=void -O0 \
// RUN: -shared-libs=%mlir_c_runner_utils \
diff --git a/mlir/test/mlir-cpu-runner/bare-ptr-call-conv.mlir b/mlir/test/mlir-cpu-runner/bare-ptr-call-conv.mlir
index 8bbaf3f..05927ae 100644
--- a/mlir/test/mlir-cpu-runner/bare-ptr-call-conv.mlir
+++ b/mlir/test/mlir-cpu-runner/bare-ptr-call-conv.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm{use-bare-ptr-memref-call-conv=1},reconcile-unrealized-casts)" | mlir-cpu-runner -shared-libs=%mlir_c_runner_utils -entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf,convert-arith-to-llvm),convert-func-to-llvm{use-bare-ptr-memref-call-conv=1},finalize-memref-to-llvm,reconcile-unrealized-casts)" | mlir-cpu-runner -shared-libs=%mlir_c_runner_utils -entry-point-result=void | FileCheck %s
// Verify bare pointer memref calling convention. `simple_add1_add2_test`
// gets two 2xf32 memrefs, adds 1.0f to the first one and 2.0f to the second
diff --git a/mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir b/mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir
index f8f9d35..c981389 100644
--- a/mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir
+++ b/mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf),finalize-memref-to-llvm,func.func(convert-arith-to-llvm),convert-func-to-llvm,reconcile-unrealized-casts)" \
+// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf),func.func(convert-arith-to-llvm),convert-func-to-llvm,finalize-memref-to-llvm,reconcile-unrealized-casts)" \
// RUN: | mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils \
// RUN: | FileCheck %s
diff --git a/mlir/test/mlir-cpu-runner/memref-reshape.mlir b/mlir/test/mlir-cpu-runner/memref-reshape.mlir
index fc74d64..cbd0c11 100644
--- a/mlir/test/mlir-cpu-runner/memref-reshape.mlir
+++ b/mlir/test/mlir-cpu-runner/memref-reshape.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf,memref-expand,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" \
+// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-scf-to-cf,memref-expand,convert-arith-to-llvm),convert-func-to-llvm,finalize-memref-to-llvm,reconcile-unrealized-casts)" \
// RUN: | mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils \
// RUN: | FileCheck %s
diff --git a/mlir/test/mlir-cpu-runner/sgemm-naive-codegen.mlir b/mlir/test/mlir-cpu-runner/sgemm-naive-codegen.mlir
index c82e78b..5c45a87 100644
--- a/mlir/test/mlir-cpu-runner/sgemm-naive-codegen.mlir
+++ b/mlir/test/mlir-cpu-runner/sgemm-naive-codegen.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,lower-affine,convert-scf-to-cf,convert-arith-to-llvm),convert-vector-to-llvm,finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" %s | mlir-cpu-runner -O3 -e main -entry-point-result=void -shared-libs=%mlir_c_runner_utils | FileCheck %s
+// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,lower-affine,convert-scf-to-cf,convert-arith-to-llvm),convert-vector-to-llvm,convert-func-to-llvm,finalize-memref-to-llvm,reconcile-unrealized-casts)" %s | mlir-cpu-runner -O3 -e main -entry-point-result=void -shared-libs=%mlir_c_runner_utils | FileCheck %s
func.func @main() {
%A = memref.alloc() : memref<16x16xf32>
diff --git a/mlir/test/mlir-cpu-runner/unranked-memref.mlir b/mlir/test/mlir-cpu-runner/unranked-memref.mlir
index 5b33ecb4..3d05def 100644
--- a/mlir/test/mlir-cpu-runner/unranked-memref.mlir
+++ b/mlir/test/mlir-cpu-runner/unranked-memref.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),finalize-memref-to-llvm,convert-func-to-llvm,reconcile-unrealized-casts)" | \
+// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-linalg-to-loops,convert-scf-to-cf,convert-arith-to-llvm),convert-func-to-llvm,finalize-memref-to-llvm,reconcile-unrealized-casts)" | \
// RUN: mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils | FileCheck %s
diff --git a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
index 2dd539e..7edab72 100644
--- a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
+++ b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
@@ -75,13 +75,13 @@ static LogicalResult runMLIRPasses(Operation *op,
modulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
passManager.addPass(createConvertGpuLaunchFuncToVulkanLaunchFuncPass());
- passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
passManager.addPass(createConvertVectorToLLVMPass());
passManager.nest<func::FuncOp>().addPass(LLVM::createRequestCWrappersPass());
ConvertFuncToLLVMPassOptions funcToLLVMOptions{};
funcToLLVMOptions.indexBitwidth =
DataLayout(module).getTypeSizeInBits(IndexType::get(module.getContext()));
passManager.addPass(createConvertFuncToLLVMPass(funcToLLVMOptions));
+ passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
passManager.addPass(createReconcileUnrealizedCastsPass());
passManager.addPass(createConvertVulkanLaunchFuncToVulkanCallsPass());
diff --git a/mlir/unittests/ExecutionEngine/Invoke.cpp b/mlir/unittests/ExecutionEngine/Invoke.cpp
index ff87fc9..b945396 100644
--- a/mlir/unittests/ExecutionEngine/Invoke.cpp
+++ b/mlir/unittests/ExecutionEngine/Invoke.cpp
@@ -53,9 +53,9 @@ static struct LLVMInitializer {
/// dialects lowering to LLVM Dialect.
static LogicalResult lowerToLLVMDialect(ModuleOp module) {
PassManager pm(module->getName());
- pm.addPass(mlir::createFinalizeMemRefToLLVMConversionPass());
pm.addNestedPass<func::FuncOp>(mlir::createArithToLLVMConversionPass());
pm.addPass(mlir::createConvertFuncToLLVMPass());
+ pm.addPass(mlir::createFinalizeMemRefToLLVMConversionPass());
pm.addPass(mlir::createReconcileUnrealizedCastsPass());
return pm.run(module);
}