[Mlir-commits] [mlir] 80cd214 - [mlir][llvm] Add `externally_initialized` support to GlobalOp
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 5 06:49:57 PDT 2024
Author: Mogball
Date: 2024-09-05T14:49:39+01:00
New Revision: 80cd2141eb7f6e7be738a01348bc2ccd08b41cd6
URL: https://github.com/llvm/llvm-project/commit/80cd2141eb7f6e7be738a01348bc2ccd08b41cd6
DIFF: https://github.com/llvm/llvm-project/commit/80cd2141eb7f6e7be738a01348bc2ccd08b41cd6.diff
LOG: [mlir][llvm] Add `externally_initialized` support to GlobalOp
This maps the `externally_initialized` flag in `llvm::GlobalVariable` to
`GlobalOp` and adds exported support.
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Target/LLVMIR/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 46bf1c9640c174..86f6b3e6326c20 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1122,6 +1122,7 @@ def LLVM_GlobalOp : LLVM_Op<"mlir.global",
Linkage:$linkage,
UnitAttr:$dso_local,
UnitAttr:$thread_local_,
+ UnitAttr:$externally_initialized,
OptionalAttr<AnyAttr>:$value,
OptionalAttr<I64Attr>:$alignment,
DefaultValuedAttr<ConfinedAttr<I32Attr, [IntNonNegative]>, "0">:$addr_space,
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index bb23da039e21f1..fcb329eb7a92c1 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1021,7 +1021,6 @@ LogicalResult ModuleTranslation::convertGlobals() {
}
auto linkage = convertLinkageToLLVM(op.getLinkage());
- auto addrSpace = op.getAddrSpace();
// LLVM IR requires constant with linkage other than external or weak
// external to have initializers. If MLIR does not provide an initializer,
@@ -1037,7 +1036,7 @@ LogicalResult ModuleTranslation::convertGlobals() {
/*InsertBefore=*/nullptr,
op.getThreadLocal_() ? llvm::GlobalValue::GeneralDynamicTLSModel
: llvm::GlobalValue::NotThreadLocal,
- addrSpace);
+ op.getAddrSpace(), op.getExternallyInitialized());
if (std::optional<mlir::SymbolRefAttr> comdat = op.getComdat()) {
auto selectorOp = cast<ComdatSelectorOp>(
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index df61fef605fde0..d2cd0221e0ea7a 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -39,6 +39,9 @@ llvm.mlir.global internal constant @string_const("foobar") : !llvm.array<6 x i8>
// CHECK: @int_global_undef = internal global i64 undef
llvm.mlir.global internal @int_global_undef() : i64
+// CHECK: @externally_initialized_global = internal externally_initialized global i32 0
+llvm.mlir.global internal @externally_initialized_global(0 : i32) {externally_initialized} : i32
+
// CHECK: @f8E3M4_global_as_i8 = internal global i8 56
llvm.mlir.global internal @f8E3M4_global_as_i8(1.5 : f8E3M4) : i8
More information about the Mlir-commits
mailing list