Skip to content

Commit f760db1

Browse files
authored
[flang][cuda][NFC] Expose conversion patterns from CUF to FIR calls (#109465)
Expose conversion patterns so they can be reused outside of this pass.
1 parent 0b08747 commit f760db1

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===------- Optimizer/Transforms/CufOpConversion.h -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_
10+
#define FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_
11+
12+
#include "mlir/Pass/Pass.h"
13+
#include "mlir/Pass/PassRegistry.h"
14+
15+
namespace fir {
16+
class LLVMTypeConverter;
17+
}
18+
19+
namespace mlir {
20+
class DataLayout;
21+
}
22+
23+
namespace cuf {
24+
25+
void populateCUFToFIRConversionPatterns(fir::LLVMTypeConverter &converter,
26+
mlir::DataLayout &dl,
27+
mlir::RewritePatternSet &patterns);
28+
29+
} // namespace cuf
30+
31+
#endif // FORTRAN_OPTIMIZER_TRANSFORMS_CUFOPCONVERSION_H_

flang/lib/Optimizer/Transforms/CufOpConversion.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "flang/Optimizer/Transforms/CufOpConversion.h"
910
#include "flang/Common/Fortran.h"
1011
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
1112
#include "flang/Optimizer/CodeGen/TypeConverter.h"
@@ -473,9 +474,7 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
473474
!mlir::isa<fir::BaseBoxType>(dstTy);
474475
});
475476
target.addLegalDialect<fir::FIROpsDialect, mlir::arith::ArithDialect>();
476-
patterns.insert<CufAllocOpConversion>(ctx, &*dl, &typeConverter);
477-
patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,
478-
CufFreeOpConversion, CufDataTransferOpConversion>(ctx);
477+
cuf::populateCUFToFIRConversionPatterns(typeConverter, *dl, patterns);
479478
if (mlir::failed(mlir::applyPartialConversion(getOperation(), target,
480479
std::move(patterns)))) {
481480
mlir::emitError(mlir::UnknownLoc::get(ctx),
@@ -485,3 +484,12 @@ class CufOpConversion : public fir::impl::CufOpConversionBase<CufOpConversion> {
485484
}
486485
};
487486
} // namespace
487+
488+
void cuf::populateCUFToFIRConversionPatterns(
489+
fir::LLVMTypeConverter &converter, mlir::DataLayout &dl,
490+
mlir::RewritePatternSet &patterns) {
491+
patterns.insert<CufAllocOpConversion>(patterns.getContext(), &dl, &converter);
492+
patterns.insert<CufAllocateOpConversion, CufDeallocateOpConversion,
493+
CufFreeOpConversion, CufDataTransferOpConversion>(
494+
patterns.getContext());
495+
}

0 commit comments

Comments
 (0)