[ExecutionEngine] After a heroic dev-meeting hack session, the JIT supports TLS.

Turns on EmulatedTLS support by default in EngineBuilder. ;)

llvm-svn: 316200
diff --git a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
index 70ee843..77c23b4 100644
--- a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
+++ b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -541,6 +541,7 @@
   SmallVector<std::string, 4> MAttrs;
   bool VerifyModules;
   bool UseOrcMCJITReplacement;
+  bool EmulatedTLS = true;
 
 public:
   /// Default constructor for EngineBuilder.
@@ -641,6 +642,10 @@
     this->UseOrcMCJITReplacement = UseOrcMCJITReplacement;
   }
 
+  void setEmulatedTLS(bool EmulatedTLS) {
+    this->EmulatedTLS = EmulatedTLS;
+  }
+  
   TargetMachine *selectTarget();
 
   /// selectTarget - Pick a target either via -march or by guessing the native
diff --git a/llvm/lib/ExecutionEngine/TargetSelect.cpp b/llvm/lib/ExecutionEngine/TargetSelect.cpp
index 5df5e1e..18dfa4e 100644
--- a/llvm/lib/ExecutionEngine/TargetSelect.cpp
+++ b/llvm/lib/ExecutionEngine/TargetSelect.cpp
@@ -95,7 +95,8 @@
   TargetMachine *Target =
       TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr,
                                      Options, RelocModel, CMModel, OptLevel,
-                                     /*JIT*/ true);
+				     /*JIT*/ true);
+  Target->Options.EmulatedTLS = EmulatedTLS;
   assert(Target && "Could not allocate target machine!");
   return Target;
 }
diff --git a/llvm/test/ExecutionEngine/MCJIT/tlvtest.ll b/llvm/test/ExecutionEngine/MCJIT/tlvtest.ll
new file mode 100644
index 0000000..2596dab
--- /dev/null
+++ b/llvm/test/ExecutionEngine/MCJIT/tlvtest.ll
@@ -0,0 +1,10 @@
+; RUN: %lli %s > /dev/null
+
+@x = thread_local local_unnamed_addr global i32 0
+
+define i32 @main() {
+entry:
+  store i32 42, i32* @x
+  ret i32 0
+}
+
diff --git a/llvm/test/ExecutionEngine/OrcMCJIT/tlvtest.ll b/llvm/test/ExecutionEngine/OrcMCJIT/tlvtest.ll
new file mode 100644
index 0000000..2596dab
--- /dev/null
+++ b/llvm/test/ExecutionEngine/OrcMCJIT/tlvtest.ll
@@ -0,0 +1,10 @@
+; RUN: %lli %s > /dev/null
+
+@x = thread_local local_unnamed_addr global i32 0
+
+define i32 @main() {
+entry:
+  store i32 42, i32* @x
+  ret i32 0
+}
+