[mlir][LinalgToLLVM] Add pass option for emitting opaque-pointers
authorMarkus Böck <markus.boeck02@gmail.com>
Fri, 24 Feb 2023 13:10:26 +0000 (14:10 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Fri, 24 Feb 2023 13:27:16 +0000 (14:27 +0100)
While the pass itself doesn't directly require any changes to be compatible with opaque-pointers, it does import patterns for lowering MemRefs to LLVM.
Adding this pass option allows any users of the pass to switch to emitting opaque-pointers via the pass option

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

mlir/include/mlir/Conversion/Passes.td
mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
mlir/test/Dialect/Linalg/affine.mlir
mlir/test/Dialect/Linalg/loops.mlir
mlir/test/Dialect/Linalg/roundtrip.mlir

index ef4ba18..b069627 100644 (file)
@@ -534,6 +534,12 @@ def ConvertLinalgToLLVMPass : Pass<"convert-linalg-to-llvm", "ModuleOp"> {
   let summary = "Convert the operations from the linalg dialect into the LLVM "
                 "dialect";
   let dependentDialects = ["scf::SCFDialect", "LLVM::LLVMDialect"];
+
+  let options = [
+     Option<"useOpaquePointers", "use-opaque-pointers", "bool",
+            /*default=*/"false", "Generate LLVM IR using opaque pointers "
+            "instead of typed pointers">
+  ];
 }
 
 //===----------------------------------------------------------------------===//
index 8eb7bbe..fb3d9ff 100644 (file)
@@ -79,6 +79,9 @@ void mlir::populateLinalgToLLVMConversionPatterns(LLVMTypeConverter &converter,
 namespace {
 struct ConvertLinalgToLLVMPass
     : public impl::ConvertLinalgToLLVMPassBase<ConvertLinalgToLLVMPass> {
+
+  using Base::Base;
+
   void runOnOperation() override;
 };
 } // namespace
@@ -88,7 +91,9 @@ void ConvertLinalgToLLVMPass::runOnOperation() {
 
   // Convert to the LLVM IR dialect using the converter defined above.
   RewritePatternSet patterns(&getContext());
-  LLVMTypeConverter converter(&getContext());
+  LowerToLLVMOptions options(&getContext());
+  options.useOpaquePointers = useOpaquePointers;
+  LLVMTypeConverter converter(&getContext(), options);
   populateLinalgToLLVMConversionPatterns(converter, patterns);
   populateFinalizeMemRefToLLVMConversionPatterns(converter, patterns);
 
index 46dd2a3..6e8380b 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: mlir-opt %s -convert-linalg-to-affine-loops | FileCheck %s
 
 // Test that we can lower all the way to LLVM without crashing, don't check results here.
-// RUN: mlir-opt %s -convert-linalg-to-affine-loops -convert-linalg-to-llvm -o=/dev/null 2>&1
+// RUN: mlir-opt %s -convert-linalg-to-affine-loops -convert-linalg-to-llvm='use-opaque-pointers=1' -o=/dev/null 2>&1
 
 func.func @matmul(%arg0: memref<?xi8>, %M: index, %N: index, %K: index) {
   %c0 = arith.constant 0 : index
index 2f715c0..5183423 100644 (file)
@@ -2,7 +2,7 @@
 // RUN: mlir-opt %s -convert-linalg-to-parallel-loops | FileCheck --check-prefix=CHECKPARALLEL %s
 
 // Test that we can lower all the way to LLVM without crashing, don't check results here.
-// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm -o=/dev/null 2>&1
+// RUN: mlir-opt %s -convert-linalg-to-loops -convert-linalg-to-llvm='use-opaque-pointers=1' -o=/dev/null 2>&1
 
 // CHECK: #[[$stride1Dilation1:.*]] = affine_map<(d0, d1) -> (d0 + d1)>
 
index c665366..8bf5e5b 100644 (file)
@@ -4,7 +4,7 @@
 // TODO: Re-enable LLVM lowering test.
 //
 // Test that we can lower all the way to LLVM without crashing, don't check results here.
-// DISABLED: mlir-opt %s --convert-linalg-to-llvm -o=/dev/null 2>&1
+// DISABLED: mlir-opt %s --convert-linalg-to-llvm='use-opaque-pointers=1' -o=/dev/null 2>&1
 
 func.func @views(%arg0: index) {
   %c0 = arith.constant 0 : index