[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 02:15:22 PDT 2025
https://github.com/ysbaddaden created https://github.com/llvm/llvm-project/pull/161155
Adds a couple functions to LLVM-C to expose the Thread Local Storage options that are only available though the C++ API for now:
- `LLVMTargetMachineOptionsSetEmulatedTLS`
- `LLVMTargetMachineOptionsSetEnableTLSDESC`
We plan to use these options in @crystal-lang to reliably compile and cross compile to some targets regardless of downstream patches in OpenBSD or MingGW for example.
>From f052645ad7310f50ee5a99d6d5835d0c8a7305f0 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/include/llvm-c/TargetMachine.h | 8 ++++++++
llvm/lib/Target/TargetMachineC.cpp | 14 ++++++++++++++
llvm/unittests/Target/TargetMachineOptionsTest.cpp | 2 ++
3 files changed, 24 insertions(+)
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