[flang-commits] [flang] [flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls (PR #109465)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Fri Sep 20 22:03:38 PDT 2024


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/109465

>From 7f10e7ac0e341db522cd6f99f3ad2cc92e62c64b Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 20 Sep 2024 13:05:16 -0700
Subject: [PATCH 1/4] [flang][cuda] Expose conversion patterns from CUF to FIR
 calls

Expose conversion patterns so they can be reused outside of this pass.
---
 flang/lib/Optimizer/Transforms/CufOpConversion.cpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
index ac796e83b07078..f8ace2dd96a0d8 100644
--- a/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/CufOpConversion.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "flang/Optimizer/Transforms/CufOpConversion.h"
 #include "flang/Common/Fortran.h"
 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
 #include "flang/Optimizer/CodeGen/TypeConverter.h"
@@ -473,9 +474,7 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
                  !mlir::isa<fir::BaseBoxType>(dstTy);
         });
     target.addLegalDialect<fir::FIROpsDialect, mlir::arith::ArithDialect>();
-    patterns.insert<CufAllocOpConversion>(ctx, &*dl, &typeConverter);
-    patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,
-                    CufFreeOpConversion, CufDataTransferOpConversion>(ctx);
+    cuf::populateCUFToFIRConversionPatterns(typeConverter, *dl, patterns);
     if (mlir::failed(mlir::applyPartialConversion(getOperation(), target,
                                                   std::move(patterns)))) {
       mlir::emitError(mlir::UnknownLoc::get(ctx),
@@ -485,3 +484,12 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
   }
 };
 } // namespace
+
+void cuf::populateCUFToFIRConversionPatterns(
+    fir::LLVMTypeConverter &converter, mlir::DataLayout &dl,
+    mlir::RewritePatternSet &patterns) {
+  patterns.insert<CufAllocOpConversion>(patterns.getContext(), &dl, &converter);
+  patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,
+                  CufFreeOpConversion, CufDataTransferOpConversion>(
+      patterns.getContext());
+}

>From 4f3bc7300132e0d3a89adaf38c7c43239d4e07b7 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 20 Sep 2024 13:06:40 -0700
Subject: [PATCH 2/4] Add header file

---
 .../Optimizer/Transforms/CufOpConversion.h    | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 flang/include/flang/Optimizer/Transforms/CufOpConversion.h

diff --git a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
new file mode 100644
index 00000000000000..1a0f943b20237f
--- /dev/null
+++ b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
@@ -0,0 +1,26 @@
+//===------- Optimizer/Transforms/CufOpConversion.h -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_
+#define FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_
+
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassRegistry.h"
+
+namespace fir {
+class LLVMTypeConverter;
+}
+
+namespace cuf {
+
+void populateCUFToFIRConversionPatterns(fir::LLVMTypeConverter &converter,
+    mlir::DataLayout &dl, mlir::RewritePatternSet &patterns);
+
+} // namespace cuf
+
+#endif // FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_

>From 2e5dc05bb5999076f4b5255689a1de02d1ee647e Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 20 Sep 2024 13:12:42 -0700
Subject: [PATCH 3/4] clang-format

---
 flang/include/flang/Optimizer/Transforms/CufOpConversion.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
index 1a0f943b20237f..9f4e41522408dc 100644
--- a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
+++ b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
@@ -19,7 +19,8 @@ class LLVMTypeConverter;
 namespace cuf {
 
 void populateCUFToFIRConversionPatterns(fir::LLVMTypeConverter &converter,
-    mlir::DataLayout &dl, mlir::RewritePatternSet &patterns);
+                                        mlir::DataLayout &dl,
+                                        mlir::RewritePatternSet &patterns);
 
 } // namespace cuf
 

>From 4a5ecb5d7fff5b15473b4bb70459d62a171e13d7 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 20 Sep 2024 22:03:19 -0700
Subject: [PATCH 4/4] Add forward decl

---
 flang/include/flang/Optimizer/Transforms/CufOpConversion.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
index 9f4e41522408dc..3e13c72cc0e3e4 100644
--- a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
+++ b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
@@ -16,6 +16,10 @@ namespace fir {
 class LLVMTypeConverter;
 }
 
+namespace mlir {
+class DataLayout;
+}
+
 namespace cuf {
 
 void populateCUFToFIRConversionPatterns(fir::LLVMTypeConverter &converter,



More information about the flang-commits mailing list