[llvm] [llvm-c] Add EmulatedTLS and EnableTLSDESC to LLVMTargetMachineOptions (PR #161155)
Julien Portalier via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 03:10:41 PDT 2025
https://github.com/ysbaddaden updated https://github.com/llvm/llvm-project/pull/161155
>From 13b625f8406bca99022e318a09f24ae182fe6baf Mon Sep 17 00:00:00 2001
From: Julien Portalier <julien at portalier.com>
Date: Sun, 28 Sep 2025 22:28:20 +0200
Subject: [PATCH] [llvm-c] Add LLVMTargetMachineOptionsSetEmulatedTLS and
LLVMTargetMachineOptionsSetEnableTLSDESC
---
llvm/docs/ReleaseNotes.md | 5 +++++
llvm/include/llvm-c/TargetMachine.h | 8 ++++++++
llvm/lib/Target/TargetMachineC.cpp | 14 ++++++++++++++
llvm/unittests/Target/TargetMachineOptionsTest.cpp | 2 ++
4 files changed, 29 insertions(+)
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 85c16b9c33f10..c3f75facd7994 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -146,6 +146,11 @@ Changes to the Python bindings
Changes to the C API
--------------------
+* Added the following helper functions to configure thread local storage
+ settings for `LLVMCreateTargetMachineWithOptions`:
+ * `LLVMTargetMachineOptionsSetEmulatedTLS`
+ * `LLVMTargetMachineOptionsSetEnableTLSDESC`
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/TargetMachine.h b/llvm/include/llvm-c/TargetMachine.h
index 1c2d1ed9bfff8..a5dbe33cbae1b 100644
--- a/llvm/include/llvm-c/TargetMachine.h
+++ b/llvm/include/llvm-c/TargetMachine.h
@@ -151,6 +151,14 @@ LLVM_C_ABI void
LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options,
LLVMCodeModel CodeModel);
+LLVM_C_ABI void
+LLVMTargetMachineOptionsSetEmulatedTLS(LLVMTargetMachineOptionsRef Options,
+ LLVMBool EmulatedTLS);
+
+LLVM_C_ABI void
+LLVMTargetMachineOptionsSetEnableTLSDESC(LLVMTargetMachineOptionsRef Options,
+ LLVMBool EnableTLSDESC);
+
/**
* Create a new llvm::TargetMachine.
*
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index aba6ea436e767..c696f43b2b391 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -40,6 +40,8 @@ struct LLVMTargetMachineOptions {
std::optional<Reloc::Model> RM;
std::optional<CodeModel::Model> CM;
bool JIT;
+ bool EmulatedTLS;
+ bool EnableTLSDESC;
};
} // namespace llvm
@@ -197,12 +199,24 @@ void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options,
unwrap(Options)->CM = CM;
}
+void LLVMTargetMachineOptionsSetEmulatedTLS(LLVMTargetMachineOptionsRef Options,
+ LLVMBool EmulatedTLS) {
+ unwrap(Options)->EmulatedTLS = EmulatedTLS;
+}
+
+void LLVMTargetMachineOptionsSetEnableTLSDESC(
+ LLVMTargetMachineOptionsRef Options, LLVMBool EnableTLSDESC) {
+ unwrap(Options)->EnableTLSDESC = EnableTLSDESC;
+}
+
LLVMTargetMachineRef
LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *TripleStr,
LLVMTargetMachineOptionsRef Options) {
auto *Opt = unwrap(Options);
TargetOptions TO;
TO.MCOptions.ABIName = Opt->ABI;
+ TO.EmulatedTLS = Opt->EmulatedTLS;
+ TO.EnableTLSDESC = Opt->EnableTLSDESC;
return wrap(unwrap(T)->createTargetMachine(Triple(TripleStr), Opt->CPU,
Opt->Features, TO, Opt->RM,
Opt->CM, Opt->OL, Opt->JIT));
diff --git a/llvm/unittests/Target/TargetMachineOptionsTest.cpp b/llvm/unittests/Target/TargetMachineOptionsTest.cpp
index 27f8855b47551..6daed5a550366 100644
--- a/llvm/unittests/Target/TargetMachineOptionsTest.cpp
+++ b/llvm/unittests/Target/TargetMachineOptionsTest.cpp
@@ -29,6 +29,8 @@ TEST(TargetMachineCTest, TargetMachineOptions) {
LLVMTargetMachineOptionsSetCodeGenOptLevel(Options, LLVMCodeGenLevelNone);
LLVMTargetMachineOptionsSetRelocMode(Options, LLVMRelocStatic);
LLVMTargetMachineOptionsSetCodeModel(Options, LLVMCodeModelKernel);
+ LLVMTargetMachineOptionsSetEmulatedTLS(Options, true);
+ LLVMTargetMachineOptionsSetEnableTLSDESC(Options, true);
LLVMDisposeTargetMachineOptions(Options);
}
More information about the llvm-commits
mailing list