[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/Emitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Nov 15 15:20:18 PST 2004



Changes in directory llvm/lib/ExecutionEngine/JIT:

Emitter.cpp updated: 1.46 -> 1.47
---
Log message:

Now that we have ghost linkage, we can force resolution of external symbols
immediately instead of lazily.

In this program, for example:

int main() {
  printf("hello world\n");
  printf("hello world\n");
  printf("hello world\n");
  printf("hello world\n");
}

We used to have to go through compilation callback 4 times (once for each
call to printf), now we don't go to it at all.

Thanks to Misha for noticing this, and for adding the initial ghost linkage
patches.



---
Diffs of the changes:  (+8 -3)

Index: llvm/lib/ExecutionEngine/JIT/Emitter.cpp
diff -u llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.46 llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.47
--- llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.46	Fri Oct 29 13:22:45 2004
+++ llvm/lib/ExecutionEngine/JIT/Emitter.cpp	Mon Nov 15 17:20:04 2004
@@ -213,9 +213,14 @@
 uint64_t Emitter::getGlobalValueAddress(GlobalValue *V) {
   // Try looking up the function to see if it is already compiled, if not return
   // 0.
-  if (isa<Function>(V))
-    return (intptr_t)TheJIT->getPointerToGlobalIfAvailable(V);
-  else {
+  if (Function *F = dyn_cast<Function>(V)) {
+    void *Addr = TheJIT->getPointerToGlobalIfAvailable(F);
+    if (Addr == 0 && F->hasExternalLinkage()) {
+      // Do not output stubs for external functions.
+      Addr = TheJIT->getPointerToFunction(F);
+    }
+    return (intptr_t)Addr;
+  } else {
     return (intptr_t)TheJIT->getOrEmitGlobalVariable(cast<GlobalVariable>(V));
   }
 }






More information about the llvm-commits mailing list