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

via flang-commits flang-commits at lists.llvm.org
Fri Sep 20 13:07:04 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

Expose conversion patterns so they can be reused outside of this pass.

---
Full diff: https://github.com/llvm/llvm-project/pull/109465.diff


2 Files Affected:

- (added) flang/include/flang/Optimizer/Transforms/CufOpConversion.h (+26) 
- (modified) flang/lib/Optimizer/Transforms/CufOpConversion.cpp (+11-3) 


``````````diff
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_
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());
+}

``````````

</details>


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


More information about the flang-commits mailing list