[flang-commits] [flang] [flang] Register LLVMTranslationDialectInterface for FIR. (PR #81668)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Feb 13 13:39:46 PST 2024
https://github.com/vzakhari created https://github.com/llvm/llvm-project/pull/81668
Register the LLVM IR translation interface for FIR to avoid
warnings about "Unhandled parameter attribute" after #78228.
>From 53d0a0a76b38c7f6d7796dcfa14e8c8b5f1e2e3a Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Tue, 13 Feb 2024 13:36:16 -0800
Subject: [PATCH] [flang] Register LLVMTranslationDialectInterface for FIR.
Register the LLVM IR translation interface for FIR to avoid
warnings about "Unhandled parameter attribute" after #78228.
---
.../flang/Optimizer/Dialect/FIRDialect.h | 3 +++
flang/include/flang/Optimizer/Support/InitFIR.h | 1 +
flang/lib/Optimizer/Dialect/FIRDialect.cpp | 17 +++++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.h b/flang/include/flang/Optimizer/Dialect/FIRDialect.h
index 440fe77059a4a7..238385505dbff7 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRDialect.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.h
@@ -70,6 +70,9 @@ bool canLegallyInline(mlir::Operation *, mlir::Operation *, bool);
// Register the FIRInlinerInterface to FIROpsDialect
void addFIRInlinerExtension(mlir::DialectRegistry ®istry);
+// Register implementation of LLVMTranslationDialectInterface.
+void addFIRToLLVMIRExtension(mlir::DialectRegistry ®istry);
+
} // namespace fir
#endif // FORTRAN_OPTIMIZER_DIALECT_FIRDIALECT_H
diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h
index f376840afd842a..9f4c4ed28a4aec 100644
--- a/flang/include/flang/Optimizer/Support/InitFIR.h
+++ b/flang/include/flang/Optimizer/Support/InitFIR.h
@@ -58,6 +58,7 @@ inline void addFIRExtensions(mlir::DialectRegistry ®istry,
bool addFIRInlinerInterface = true) {
if (addFIRInlinerInterface)
addFIRInlinerExtension(registry);
+ addFIRToLLVMIRExtension(registry);
}
inline void loadNonCodegenDialects(mlir::MLIRContext &context) {
diff --git a/flang/lib/Optimizer/Dialect/FIRDialect.cpp b/flang/lib/Optimizer/Dialect/FIRDialect.cpp
index f4589fda184587..850b6120b2a00e 100644
--- a/flang/lib/Optimizer/Dialect/FIRDialect.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRDialect.cpp
@@ -15,6 +15,7 @@
#include "flang/Optimizer/Dialect/FIROps.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "mlir/Transforms/InliningUtils.h"
using namespace fir;
@@ -77,6 +78,22 @@ void fir::addFIRInlinerExtension(mlir::DialectRegistry ®istry) {
});
}
+// We do not provide LLVMTranslationDialectInterface implementation
+// for FIR dialect, since at the point of translation to LLVM IR
+// there should not be any FIR operations (the CodeGen converts
+// them to LLVMIR dialect operations).
+// Here we register the default implementation of
+// LLVMTranslationDialectInterface that will drop all FIR dialect
+// attributes - this helps to avoid warnings about unhandled attributes.
+// We can provide our own implementation of the interface,
+// when more sophisticated translation is required.
+void fir::addFIRToLLVMIRExtension(mlir::DialectRegistry ®istry) {
+ registry.addExtension(
+ +[](mlir::MLIRContext *ctx, fir::FIROpsDialect *dialect) {
+ dialect->addInterface<mlir::LLVMTranslationDialectInterface>();
+ });
+}
+
// anchor the class vtable to this compilation unit
fir::FIROpsDialect::~FIROpsDialect() {
// do nothing
More information about the flang-commits
mailing list