Implement PR135, lazy emission of global variables
[oota-llvm.git] / lib / ExecutionEngine / JIT / JITEmitter.cpp
index 50b3610e518cf9a07ec72c539b29c0c59d21a8c7..8da50919fd3b2c50d9d4ba6737e288d97e799256 100644 (file)
@@ -248,7 +248,11 @@ void Emitter::emitWord(unsigned W) {
 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);