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

via flang-commits flang-commits at lists.llvm.org
Fri Sep 20 22:28:14 PDT 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-09-20T22:28:10-07:00
New Revision: f760db124972a07ead0976d3c7b2cb309a0f6acb

URL: https://github.com/llvm/llvm-project/commit/f760db124972a07ead0976d3c7b2cb309a0f6acb
DIFF: https://github.com/llvm/llvm-project/commit/f760db124972a07ead0976d3c7b2cb309a0f6acb.diff

LOG: [flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls (#109465)

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

Added: 
    flang/include/flang/Optimizer/Transforms/CufOpConversion.h

Modified: 
    flang/lib/Optimizer/Transforms/CufOpConversion.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Transforms/CufOpConversion.h b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
new file mode 100644
index 00000000000000..3e13c72cc0e3e4
--- /dev/null
+++ b/flang/include/flang/Optimizer/Transforms/CufOpConversion.h
@@ -0,0 +1,31 @@
+//===------- 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 mlir {
+class DataLayout;
+}
+
+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());
+}


        


More information about the flang-commits mailing list