diff options
| author | Hans Wennborg <hans@hanshq.net> | 2012-06-23 11:51:46 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2012-06-23 11:51:46 +0000 |
| commit | d3b01bc7c6735a78ebdff0071647a15de5716bc7 (patch) | |
| tree | 1bea08b4886b9dac974ae24ea644795b8b2fd0f6 /clang/lib/CodeGen/CGDecl.cpp | |
| parent | cbe34b4cc98148b386a0c96cd195e7f62f52a6e3 (diff) | |
| download | bcm5719-llvm-d3b01bc7c6735a78ebdff0071647a15de5716bc7.tar.gz bcm5719-llvm-d3b01bc7c6735a78ebdff0071647a15de5716bc7.zip | |
Support the tls_model attribute (PR9788)
This adds support for the tls_model attribute. This allows the user to
choose a TLS model that is better than what LLVM would select by
default. For example, a variable might be declared as:
__thread int x __attribute__((tls_model("initial-exec")));
if it will not be used in a shared library that is dlopen'ed.
This depends on LLVM r159077.
llvm-svn: 159078
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index ff803c612fb..08a938254ba 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -183,12 +183,22 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, else Name = GetStaticDeclName(*this, D, Separator); + llvm::GlobalVariable::ThreadLocalMode TLM; + TLM = D.isThreadSpecified() ? llvm::GlobalVariable::GeneralDynamicTLSModel + : llvm::GlobalVariable::NotThreadLocal; + + // Set the TLS mode if it it's explicitly specified. + if (D.hasAttr<TLSModelAttr>()) { + assert(D.isThreadSpecified() && "Can't have TLS model on non-tls var."); + const TLSModelAttr *Attr = D.getAttr<TLSModelAttr>(); + TLM = CodeGenModule::GetLLVMTLSModel(Attr->getModel()); + } + llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); llvm::GlobalVariable *GV = new llvm::GlobalVariable(CGM.getModule(), LTy, Ty.isConstant(getContext()), Linkage, - CGM.EmitNullConstant(D.getType()), Name, 0, - D.isThreadSpecified(), + CGM.EmitNullConstant(D.getType()), Name, 0, TLM, CGM.getContext().getTargetAddressSpace(Ty)); GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); if (Linkage != llvm::GlobalValue::InternalLinkage) @@ -239,7 +249,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, OldGV->isConstant(), OldGV->getLinkage(), Init, "", /*InsertBefore*/ OldGV, - D.isThreadSpecified(), + OldGV->getThreadLocalMode(), CGM.getContext().getTargetAddressSpace(D.getType())); GV->setVisibility(OldGV->getVisibility()); @@ -1066,7 +1076,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) { llvm::GlobalVariable *GV = new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true, llvm::GlobalValue::PrivateLinkage, - constant, Name, 0, false, 0); + constant, Name); GV->setAlignment(alignment.getQuantity()); GV->setUnnamedAddr(true); |

