Implement PR135, lazy emission of global variables


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10549 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 50b3610..8da5091 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -248,7 +248,11 @@
 uint64_t Emitter::getGlobalValueAddress(GlobalValue *V) {
   // Try looking up the function to see if it is already compiled, if not return
   // 0.
-  return (intptr_t)TheJIT->getPointerToGlobalIfAvailable(V);
+  if (isa<Function>(V))
+    return (intptr_t)TheJIT->getPointerToGlobalIfAvailable(V);
+  else {
+    return (intptr_t)TheJIT->getOrEmitGlobalVariable(cast<GlobalVariable>(V));
+  }
 }
 uint64_t Emitter::getGlobalValueAddress(const std::string &Name) {
   return (intptr_t)TheJIT->getPointerToNamedFunction(Name);