From e5655c5e05361433981270ac2b401b79db7339a1 Mon Sep 17 00:00:00 2001 From: kai Date: Wed, 10 Jul 2013 07:52:48 +0200 Subject: [PATCH] Add command line option for the thread model. On Linux/PPC, just ignore the provided model. Only local-exec is supported. --- gen/llvmhelpers.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 8c01cd7b..d47dbed4 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -35,6 +35,24 @@ #include "llvm/Transforms/Utils/ModuleUtils.h" #include +#if LDC_LLVM_VER >= 302 +#include "llvm/Support/CommandLine.h" + +llvm::cl::opt clThreadModel("fthread-model", + llvm::cl::desc("Thread model"), + llvm::cl::init(llvm::GlobalVariable::GeneralDynamicTLSModel), + llvm::cl::values( + clEnumValN(llvm::GlobalVariable::GeneralDynamicTLSModel, "global-dynamic", + "Global dynamic TLS model (default)"), + clEnumValN(llvm::GlobalVariable::LocalDynamicTLSModel, "local-dynamic", + "Local dynamic TLS model"), + clEnumValN(llvm::GlobalVariable::InitialExecTLSModel, "initial-exec", + "Initial exec TLS model"), + clEnumValN(llvm::GlobalVariable::LocalExecTLSModel, "local-exec", + "Local exec TLS model"), + clEnumValEnd)); +#endif + /****************************************************************************************/ /*//////////////////////////////////////////////////////////////////////////////////////// // DYNAMIC MEMORY HELPERS @@ -2027,10 +2045,15 @@ llvm::GlobalVariable* getOrCreateGlobal(Loc loc, llvm::Module& module, } #if LDC_LLVM_VER >= 302 - // FIXME: clang uses a command line option for the thread model + // Use a command line option for the thread model. + // On PPC there is only local-exec available - in this case just ignore the + // command line. const llvm::GlobalVariable::ThreadLocalMode tlsModel = - isThreadLocal ? llvm::GlobalVariable::GeneralDynamicTLSModel - : llvm::GlobalVariable::NotThreadLocal; + isThreadLocal + ? (global.params.targetTriple.getArch() == llvm::Triple::ppc + ? llvm::GlobalVariable::LocalExecTLSModel + : clThreadModel.getValue()) + : llvm::GlobalVariable::NotThreadLocal; return new llvm::GlobalVariable(module, type, isConstant, linkage, init, name, 0, tlsModel); #else