Enable multi-threaded Quick compilation

Reuse thread-local copies of llvm context data for Quick compiler
(while continuing to regenerate fresh ones per method for Portable).
This is a transitional CL - the upcoming compiler driver change
is expected to pass pass a thread context structure to each compiler
worker thread rather than use the pthread_key mechanism.

Change-Id: I277920a5c2705748c3a9f37ceace53c903747ec2
diff --git a/src/compiler.cc b/src/compiler.cc
index 7bec994..b0d373b 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -322,6 +322,8 @@
   }
   VLOG(compiler) << "dlopen(\"" << compiler_so_name << "\", RTLD_LAZY) returned " << compiler_library_;
 
+  CHECK_PTHREAD_CALL(pthread_key_create, (&tls_key_, NULL), "compiler tls key");
+
 #if defined(ART_USE_LLVM_COMPILER) || defined(ART_USE_GREENLAND_COMPILER)
   // Initialize compiler_context_
   typedef void (*InitCompilerContextFn)(Compiler&);
@@ -431,6 +433,16 @@
   }
 }
 
+CompilerTls* Compiler::GetTls() {
+  // Lazily create thread-local storage
+  CompilerTls* res = static_cast<CompilerTls*>(pthread_getspecific(tls_key_));
+  if (res == NULL) {
+    res = new CompilerTls();
+    CHECK_PTHREAD_CALL(pthread_setspecific, (tls_key_, res), "compiler tls");
+  }
+  return res;
+}
+
 ByteArray* Compiler::CreateResolutionStub(InstructionSet instruction_set,
                                           Runtime::TrampolineType type) {
   switch (instruction_set) {