Skip to content

Commit 80cd214

Browse files
author
Mogball
committed
[mlir][llvm] Add externally_initialized support to GlobalOp
This maps the `externally_initialized` flag in `llvm::GlobalVariable` to `GlobalOp` and adds exported support.
1 parent 7f0c5b0 commit 80cd214

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ def LLVM_GlobalOp : LLVM_Op<"mlir.global",
11221122
Linkage:$linkage,
11231123
UnitAttr:$dso_local,
11241124
UnitAttr:$thread_local_,
1125+
UnitAttr:$externally_initialized,
11251126
OptionalAttr<AnyAttr>:$value,
11261127
OptionalAttr<I64Attr>:$alignment,
11271128
DefaultValuedAttr<ConfinedAttr<I32Attr, [IntNonNegative]>, "0">:$addr_space,

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ LogicalResult ModuleTranslation::convertGlobals() {
10211021
}
10221022

10231023
auto linkage = convertLinkageToLLVM(op.getLinkage());
1024-
auto addrSpace = op.getAddrSpace();
10251024

10261025
// LLVM IR requires constant with linkage other than external or weak
10271026
// external to have initializers. If MLIR does not provide an initializer,
@@ -1037,7 +1036,7 @@ LogicalResult ModuleTranslation::convertGlobals() {
10371036
/*InsertBefore=*/nullptr,
10381037
op.getThreadLocal_() ? llvm::GlobalValue::GeneralDynamicTLSModel
10391038
: llvm::GlobalValue::NotThreadLocal,
1040-
addrSpace);
1039+
op.getAddrSpace(), op.getExternallyInitialized());
10411040

10421041
if (std::optional<mlir::SymbolRefAttr> comdat = op.getComdat()) {
10431042
auto selectorOp = cast<ComdatSelectorOp>(

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ llvm.mlir.global internal constant @string_const("foobar") : !llvm.array<6 x i8>
3939
// CHECK: @int_global_undef = internal global i64 undef
4040
llvm.mlir.global internal @int_global_undef() : i64
4141

42+
// CHECK: @externally_initialized_global = internal externally_initialized global i32 0
43+
llvm.mlir.global internal @externally_initialized_global(0 : i32) {externally_initialized} : i32
44+
4245
// CHECK: @f8E3M4_global_as_i8 = internal global i8 56
4346
llvm.mlir.global internal @f8E3M4_global_as_i8(1.5 : f8E3M4) : i8
4447

0 commit comments

Comments
 (0)