[flang-commits] [flang] [flang] Register LLVMTranslationDialectInterface for FIR. (PR #81668)
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 13 13:40:12 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Slava Zakharin (vzakhari)
<details>
<summary>Changes</summary>
Register the LLVM IR translation interface for FIR to avoid
warnings about "Unhandled parameter attribute" after #<!-- -->78228.
---
Full diff: https://github.com/llvm/llvm-project/pull/81668.diff
3 Files Affected:
- (modified) flang/include/flang/Optimizer/Dialect/FIRDialect.h (+3)
- (modified) flang/include/flang/Optimizer/Support/InitFIR.h (+1)
- (modified) flang/lib/Optimizer/Dialect/FIRDialect.cpp (+17)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/81668
More information about the flang-commits
mailing list