diff options
author | Jean Perier <jperier@nvidia.com> | 2022-03-14 12:24:17 +0300 |
---|---|---|
committer | Jean Perier <jperier@nvidia.com> | 2022-03-14 12:24:44 +0300 |
commit | 30a0fbf51f4f826a47766c276bd493f71cfeeacc (patch) | |
tree | adc6ac215c38e09d9b78f407f8224ee49341aa29 /flang | |
parent | d22ce769999da6cd77b7cb753564a11e674b4f14 (diff) |
[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
Diffstat (limited to 'flang')
-rw-r--r-- | flang/include/flang/Optimizer/Builder/FIRBuilder.h | 4 | ||||
-rw-r--r-- | flang/lib/Optimizer/CodeGen/CodeGen.cpp | 2 | ||||
-rw-r--r-- | flang/lib/Optimizer/Dialect/FIROps.cpp | 3 | ||||
-rw-r--r-- | flang/test/Fir/fir-ops.fir | 9 |
4 files changed, 17 insertions, 1 deletions
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index 3f4236e1c0d3..032c881fb195 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 507b11fdfaed..55da2d93d3c1 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2647,6 +2647,8 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> { 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 2333dfc66aaf..1f3cabc5accc 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 38ec7ffe02cd..541dabdf8b61 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<minez(f:i32)> { fir.has_value %0 : !fir.type<minez> } +// 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: } |