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

Chris Lattner lattner at cs.uiuc.edu
Sun Nov 21 23:25:00 PST 2004



Changes in directory llvm/lib/ExecutionEngine/JIT:

Emitter.cpp updated: 1.52 -> 1.53
---
Log message:

Support targets that require stubs for external functions better


---
Diffs of the changes:  (+18 -2)

Index: llvm/lib/ExecutionEngine/JIT/Emitter.cpp
diff -u llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.52 llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.53
--- llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.52	Sat Nov 20 21:44:32 2004
+++ llvm/lib/ExecutionEngine/JIT/Emitter.cpp	Mon Nov 22 01:24:43 2004
@@ -151,9 +151,22 @@
   void *&Stub = FunctionToStubMap[F];
   if (Stub) return Stub;
 
+  // Call the lazy resolver function unless we already KNOW it is an external
+  // function, in which case we just skip the lazy resolution step.
+  void *Actual = (void*)LazyResolverFn;
+  if (F->hasExternalLinkage())
+    Actual = TheJIT->getPointerToFunction(F);
+    
   // Otherwise, codegen a new stub.  For now, the stub will call the lazy
   // resolver function.
-  Stub = TheJIT->getJITInfo().emitFunctionStub((void*)LazyResolverFn, MCE);
+  Stub = TheJIT->getJITInfo().emitFunctionStub(Actual, MCE);
+
+  if (F->hasExternalLinkage()) {
+    // If we are getting the stub for an external function, we really want the
+    // address of the stub in the GlobalAddressMap for the JIT, not the address
+    // of the external function.
+    TheJIT->updateGlobalMapping(F, Stub);
+  }
 
   DEBUG(std::cerr << "JIT: Stub emitted at [" << Stub << "] for function '"
                   << F->getName() << "\n");
@@ -274,7 +287,10 @@
   if (F->hasExternalLinkage()) {
     // If this is an external function pointer, we can force the JIT to
     // 'compile' it, which really just adds it to the map.
-    return TheJIT->getPointerToFunction(F);
+    if (DoesntNeedStub)
+      return TheJIT->getPointerToFunction(F);
+
+    return getJITResolver(this).getFunctionStub(F);
   }
 
   // Okay, the function has not been compiled yet, if the target callback






More information about the llvm-commits mailing list