[flang-commits] [flang] 408d4e1 - [flang][NFC] Expose FIR to LLVM patterns (#83492)
via flang-commits
flang-commits at lists.llvm.org
Mon Mar 4 00:12:02 PST 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-03-04T09:11:59+01:00
New Revision: 408d4e131ef7b30c3bc419f5219f7ca20ca9ac1d
URL: https://github.com/llvm/llvm-project/commit/408d4e131ef7b30c3bc419f5219f7ca20ca9ac1d
DIFF: https://github.com/llvm/llvm-project/commit/408d4e131ef7b30c3bc419f5219f7ca20ca9ac1d.diff
LOG: [flang][NFC] Expose FIR to LLVM patterns (#83492)
The FIR dialect has been initiated before many interfaces have been
introduced to MLIR. This patch expose the FIR to LLVM patterns in a
`populateFIRToLLVMConversionPatterns` function. The idea is to be able
to add the `ConvertToLLVMPatternInterface`. This is not directly
possible since the FIR dialect does not currently use the table
infrastructure for its definition.
Follow up patches will move the FIR dialect definition to table gen and
then implement the interface.
Added:
Modified:
flang/include/flang/Optimizer/CodeGen/CodeGen.h
flang/lib/Optimizer/CodeGen/CodeGen.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/CodeGen/CodeGen.h b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
index 5ea96c900bc630..cbf02ec3912363 100644
--- a/flang/include/flang/Optimizer/CodeGen/CodeGen.h
+++ b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
@@ -18,6 +18,8 @@
namespace fir {
+class LLVMTypeConverter;
+
struct NameUniquer;
#define GEN_PASS_DECL_FIRTOLLVMLOWERING
@@ -80,6 +82,11 @@ std::unique_ptr<mlir::Pass> createLLVMDialectToLLVMPass(
std::unique_ptr<mlir::Pass> createBoxedProcedurePass();
std::unique_ptr<mlir::Pass> createBoxedProcedurePass(bool useThunks);
+/// Populate the given list with patterns that convert from FIR to LLVM.
+void populateFIRToLLVMConversionPatterns(fir::LLVMTypeConverter &converter,
+ mlir::RewritePatternSet &patterns,
+ fir::FIRToLLVMPassOptions &options);
+
// declarative passes
#define GEN_PASS_REGISTRATION
#include "flang/Optimizer/CodeGen/CGPasses.h.inc"
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 7fdf39a1af731c..f81a08388da722 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3937,30 +3937,7 @@ class FIRToLLVMLowering
options.applyTBAA || applyTBAA,
options.forceUnifiedTBAATree, *dl};
mlir::RewritePatternSet pattern(context);
- pattern.insert<
- AbsentOpConversion, AddcOpConversion, AddrOfOpConversion,
- AllocaOpConversion, AllocMemOpConversion, BoxAddrOpConversion,
- BoxCharLenOpConversion, BoxDimsOpConversion, BoxEleSizeOpConversion,
- BoxIsAllocOpConversion, BoxIsArrayOpConversion, BoxIsPtrOpConversion,
- BoxOffsetOpConversion, BoxProcHostOpConversion, BoxRankOpConversion,
- BoxTypeCodeOpConversion, BoxTypeDescOpConversion, CallOpConversion,
- CmpcOpConversion, ConstcOpConversion, ConvertOpConversion,
- CoordinateOpConversion, DTEntryOpConversion, DivcOpConversion,
- EmboxOpConversion, EmboxCharOpConversion, EmboxProcOpConversion,
- ExtractValueOpConversion, FieldIndexOpConversion, FirEndOpConversion,
- FreeMemOpConversion, GlobalLenOpConversion, GlobalOpConversion,
- HasValueOpConversion, InsertOnRangeOpConversion,
- InsertValueOpConversion, IsPresentOpConversion,
- LenParamIndexOpConversion, LoadOpConversion, MulcOpConversion,
- NegcOpConversion, NoReassocOpConversion, SelectCaseOpConversion,
- SelectOpConversion, SelectRankOpConversion, SelectTypeOpConversion,
- ShapeOpConversion, ShapeShiftOpConversion, ShiftOpConversion,
- SliceOpConversion, StoreOpConversion, StringLitOpConversion,
- SubcOpConversion, TypeDescOpConversion, TypeInfoOpConversion,
- UnboxCharOpConversion, UnboxProcOpConversion, UndefOpConversion,
- UnreachableOpConversion, UnrealizedConversionCastOpConversion,
- XArrayCoorOpConversion, XEmboxOpConversion, XReboxOpConversion,
- ZeroOpConversion>(typeConverter, options);
+ fir::populateFIRToLLVMConversionPatterns(typeConverter, pattern, options);
mlir::populateFuncToLLVMConversionPatterns(typeConverter, pattern);
mlir::populateOpenMPToLLVMConversionPatterns(typeConverter, pattern);
mlir::arith::populateArithToLLVMConversionPatterns(typeConverter, pattern);
@@ -4072,3 +4049,32 @@ fir::createLLVMDialectToLLVMPass(llvm::raw_ostream &output,
fir::LLVMIRLoweringPrinter printer) {
return std::make_unique<LLVMIRLoweringPass>(output, printer);
}
+
+void fir::populateFIRToLLVMConversionPatterns(
+ fir::LLVMTypeConverter &converter, mlir::RewritePatternSet &patterns,
+ fir::FIRToLLVMPassOptions &options) {
+ patterns.insert<
+ AbsentOpConversion, AddcOpConversion, AddrOfOpConversion,
+ AllocaOpConversion, AllocMemOpConversion, BoxAddrOpConversion,
+ BoxCharLenOpConversion, BoxDimsOpConversion, BoxEleSizeOpConversion,
+ BoxIsAllocOpConversion, BoxIsArrayOpConversion, BoxIsPtrOpConversion,
+ BoxOffsetOpConversion, BoxProcHostOpConversion, BoxRankOpConversion,
+ BoxTypeCodeOpConversion, BoxTypeDescOpConversion, CallOpConversion,
+ CmpcOpConversion, ConstcOpConversion, ConvertOpConversion,
+ CoordinateOpConversion, DTEntryOpConversion, DivcOpConversion,
+ EmboxOpConversion, EmboxCharOpConversion, EmboxProcOpConversion,
+ ExtractValueOpConversion, FieldIndexOpConversion, FirEndOpConversion,
+ FreeMemOpConversion, GlobalLenOpConversion, GlobalOpConversion,
+ HasValueOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion,
+ IsPresentOpConversion, LenParamIndexOpConversion, LoadOpConversion,
+ MulcOpConversion, NegcOpConversion, NoReassocOpConversion,
+ SelectCaseOpConversion, SelectOpConversion, SelectRankOpConversion,
+ SelectTypeOpConversion, ShapeOpConversion, ShapeShiftOpConversion,
+ ShiftOpConversion, SliceOpConversion, StoreOpConversion,
+ StringLitOpConversion, SubcOpConversion, TypeDescOpConversion,
+ TypeInfoOpConversion, UnboxCharOpConversion, UnboxProcOpConversion,
+ UndefOpConversion, UnreachableOpConversion,
+ UnrealizedConversionCastOpConversion, XArrayCoorOpConversion,
+ XEmboxOpConversion, XReboxOpConversion, ZeroOpConversion>(converter,
+ options);
+}
More information about the flang-commits
mailing list