[llvm-commits] [llvm] r59265 - /llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp

Evan Cheng evan.cheng at apple.com
Thu Nov 13 13:51:09 PST 2008


Author: evancheng
Date: Thu Nov 13 15:50:50 2008
New Revision: 59265

URL: http://llvm.org/viewvc/llvm-project?rev=59265&view=rev
Log:
Always emit a function pointer as a pointer to the function stub (if there is one). This makes it possible to compare function pointer values in lazy compilation mode. This fixes PR3043.

Modified:
    llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=59265&r1=59264&r2=59265&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Thu Nov 13 15:50:50 2008
@@ -115,6 +115,10 @@
       TheJITResolver = 0;
     }
 
+    /// getFunctionStubIfAvailable - This returns a pointer to a function stub
+    /// if it has already been created.
+    void *getFunctionStubIfAvailable(Function *F);
+
     /// getFunctionStub - This returns a pointer to a function stub, creating
     /// one on demand as needed.
     void *getFunctionStub(Function *F);
@@ -151,6 +155,16 @@
 
 JITResolver *JITResolver::TheJITResolver = 0;
 
+/// getFunctionStubIfAvailable - This returns a pointer to a function stub
+/// if it has already been created.
+void *JITResolver::getFunctionStubIfAvailable(Function *F) {
+  MutexGuard locked(TheJIT->lock);
+
+  // If we already have a stub for this function, recycle it.
+  void *&Stub = state.getFunctionToStubMap(locked)[F];
+  return Stub;
+}
+
 /// getFunctionStub - This returns a pointer to a function stub, creating
 /// one on demand as needed.
 void *JITResolver::getFunctionStub(Function *F) {
@@ -596,7 +610,12 @@
 
   // If we have already compiled the function, return a pointer to its body.
   Function *F = cast<Function>(V);
-  void *ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F);
+  void *ResultPtr;
+  if (!DoesntNeedStub)
+    // Return the function stub if it's already created.
+    ResultPtr = Resolver.getFunctionStubIfAvailable(F);
+  else
+    ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F);
   if (ResultPtr) return ResultPtr;
 
   if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode()) {





More information about the llvm-commits mailing list