[flang-commits] [flang] 30a0fbf - [flang] Add support for linkonce_odr in FIR
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Mon Mar 14 02:25:21 PDT 2022
Author: Jean Perier
Date: 2022-03-14T10:24:44+01:00
New Revision: 30a0fbf51f4f826a47766c276bd493f71cfeeacc
URL: https://github.com/llvm/llvm-project/commit/30a0fbf51f4f826a47766c276bd493f71cfeeacc
DIFF: https://github.com/llvm/llvm-project/commit/30a0fbf51f4f826a47766c276bd493f71cfeeacc.diff
LOG: [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
Added:
Modified:
flang/include/flang/Optimizer/Builder/FIRBuilder.h
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Fir/fir-ops.fir
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index 3f4236e1c0d3d..032c881fb195c 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -212,6 +212,10 @@ class FirOpBuilder : public mlir::OpBuilder {
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 507b11fdfaede..55da2d93d3c10 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 2333dfc66aaf9..1f3cabc5accc5 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 38ec7ffe02cd9..541dabdf8b612 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: }
More information about the flang-commits
mailing list