From 30a0fbf51f4f826a47766c276bd493f71cfeeacc Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Mon, 14 Mar 2022 10:24:17 +0100 Subject: [PATCH] [flang] Add support for linkonce_odr in FIR Add support for parsing and converting linkonce_odr in FIR. Differential Revision: https://reviews.llvm.org/D121471 --- flang/include/flang/Optimizer/Builder/FIRBuilder.h | 4 ++++ flang/lib/Optimizer/CodeGen/CodeGen.cpp | 2 ++ flang/lib/Optimizer/Dialect/FIROps.cpp | 3 ++- flang/test/Fir/fir-ops.fir | 9 +++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index 3f4236e..032c881 100644 --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -212,6 +212,10 @@ public: mlir::StringAttr createLinkOnceLinkage() { return getStringAttr("linkonce"); } + mlir::StringAttr createLinkOnceODRLinkage() { + return getStringAttr("linkonce_odr"); + } + mlir::StringAttr createWeakLinkage() { return getStringAttr("weak"); } /// Get a function by name. If the function exists in the current module, it diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 507b11f..55da2d9 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2647,6 +2647,8 @@ struct GlobalOpConversion : public FIROpConversion { return mlir::LLVM::Linkage::Internal; if (name == "linkonce") return mlir::LLVM::Linkage::Linkonce; + if (name == "linkonce_odr") + return mlir::LLVM::Linkage::LinkonceODR; if (name == "common") return mlir::LLVM::Linkage::Common; if (name == "weak") diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 2333dfc..1f3cabc 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -1321,7 +1321,8 @@ void fir::GlobalOp::build(mlir::OpBuilder &builder, OperationState &result, mlir::ParseResult fir::GlobalOp::verifyValidLinkage(StringRef linkage) { // Supporting only a subset of the LLVM linkage types for now - static const char *validNames[] = {"common", "internal", "linkonce", "weak"}; + static const char *validNames[] = {"common", "internal", "linkonce", + "linkonce_odr", "weak"}; return mlir::success(llvm::is_contained(validNames, linkage)); } diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir index 38ec7ff..541dabd 100644 --- a/flang/test/Fir/fir-ops.fir +++ b/flang/test/Fir/fir-ops.fir @@ -432,6 +432,15 @@ fir.global @global_derived : !fir.type { fir.has_value %0 : !fir.type } +// CHECK-LABEL: fir.global linkonce_odr @global_linkonce_odr : i32 { +// CHECK: [[VAL_130:%.*]] = arith.constant 1 : i32 +// CHECK: fir.has_value [[VAL_130]] : i32 +// CHECK: } +fir.global linkonce_odr @global_linkonce_odr : i32 { + %0 = arith.constant 1 : i32 + fir.has_value %0 : i32 +} + // CHECK-LABEL: fir.dispatch_table @dispatch_tbl { // CHECK: fir.dt_entry "method", @method_impl // CHECK: } -- 2.7.4