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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159078 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 8f3bd78..d1ecfec 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -496,6 +496,15 @@
     llvm_unreachable("unknown visibility!");
   }
 
+  static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S) {
+    return llvm::StringSwitch<llvm::GlobalVariable::ThreadLocalMode>(S)
+        .Case("global-dynamic", llvm::GlobalVariable::GeneralDynamicTLSModel)
+        .Case("local-dynamic", llvm::GlobalVariable::LocalDynamicTLSModel)
+        .Case("initial-exec", llvm::GlobalVariable::InitialExecTLSModel)
+        .Case("local-exec", llvm::GlobalVariable::LocalExecTLSModel)
+        .Default(llvm::GlobalVariable::NotThreadLocal);
+  }
+
   llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) {
     if (isa<CXXConstructorDecl>(GD.getDecl()))
       return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()),