diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1001,6 +1001,7 @@ StrAttr:$sym_name, Linkage:$linkage, UnitAttr:$dso_local, + UnitAttr:$thr_local, OptionalAttr:$value, OptionalAttr:$alignment, DefaultValuedAttr, "0">:$addr_space, diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -661,7 +661,10 @@ auto *var = new llvm::GlobalVariable( *llvmModule, type, op.getConstant(), linkage, cst, op.getSymName(), - /*InsertBefore=*/nullptr, llvm::GlobalValue::NotThreadLocal, addrSpace); + /*InsertBefore=*/nullptr, + op.getThrLocal() ? llvm::GlobalValue::GeneralDynamicTLSModel + : llvm::GlobalValue::NotThreadLocal, + addrSpace); if (op.getUnnamedAddr().hasValue()) var->setUnnamedAddr(convertUnnamedAddrToLLVM(*op.getUnnamedAddr())); diff --git a/mlir/test/Dialect/LLVMIR/global.mlir b/mlir/test/Dialect/LLVMIR/global.mlir --- a/mlir/test/Dialect/LLVMIR/global.mlir +++ b/mlir/test/Dialect/LLVMIR/global.mlir @@ -57,6 +57,10 @@ llvm.mlir.global linkonce_odr @linkonce_odr() : i64 // CHECK: llvm.mlir.global weak_odr llvm.mlir.global weak_odr @weak_odr() : i64 +// CHECK: llvm.mlir.global external @has_thr_local(42 : i64) {thr_local} : i64 +llvm.mlir.global external @has_thr_local(42 : i64) {thr_local} : i64 +// CHECK: llvm.mlir.global external @has_dso_local(42 : i64) {dso_local} : i64 +llvm.mlir.global external @has_dso_local(42 : i64) {dso_local} : i64 // CHECK-LABEL: references func @references() { diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir --- a/mlir/test/Target/LLVMIR/llvmir.mlir +++ b/mlir/test/Target/LLVMIR/llvmir.mlir @@ -128,6 +128,13 @@ llvm.mlir.global @has_dso_local(42 : i64) {dso_local} : i64 // CHECK: @has_dso_local = dso_local global i64 42 +// +// thr_local attribute. +// + +llvm.mlir.global @has_thr_local(42 : i64) {thr_local} : i64 +// CHECK: @has_thr_local = thread_local global i64 42 + // // Section attribute. //