Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls #109465

Merged
merged 4 commits into from
Sep 21, 2024

Conversation

clementval
Copy link
Contributor

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

Expose conversion patterns so they can be reused outside of this pass.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Sep 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2024

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

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

Changes

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

Copy link

github-actions bot commented Sep 20, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

nit: it can be marked as NFC

@clementval clementval changed the title [flang][cuda] Expose conversion patterns from CUF to FIR calls [flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls Sep 20, 2024
@clementval clementval merged commit f760db1 into llvm:main Sep 21, 2024
8 checks passed
@clementval clementval deleted the cuf_conv_popuplate branch September 21, 2024 05:28
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Sep 26, 2024
…lvm#109465)

Expose conversion patterns so they can be reused outside of this pass.
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
…lvm#109465)

Expose conversion patterns so they can be reused outside of this pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants