From a34f9da4b40be2650575c24a9b849515222809bc Mon Sep 17 00:00:00 2001
From: Chris Lattner <sabre@nondot.org>
Date: Sun, 5 Dec 2004 07:19:16 +0000
Subject: [PATCH] Properly implement a fix for PR475

llvm-svn: 18537
---
 llvm/lib/ExecutionEngine/JIT/JIT.cpp        | 13 -------------
 llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
index 537ca56e0248..2bab9e735b5d 100644
--- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
@@ -265,19 +265,6 @@ void *JIT::getPointerToFunction(Function *F) {
   return Addr;
 }
 
-// getPointerToFunctionOrStub - If the specified function has been
-// code-gen'd, return a pointer to the function.  If not, compile it, or use
-// a stub to implement lazy compilation if available.
-//
-void *JIT::getPointerToFunctionOrStub(Function *F) {
-  // If we have already code generated the function, just return the address.
-  if (void *Addr = getPointerToGlobalIfAvailable(F))
-    return Addr;
-
-  // Otherwise, if the target doesn't support it, just codegen the function.
-  return getPointerToFunction(F);
-}
-
 /// getOrEmitGlobalVariable - Return the address of the specified global
 /// variable, possibly emitting it to memory if needed.  This is used by the
 /// Emitter.
diff --git a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
index e5cdc92b7542..eff24de89e39 100644
--- a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -208,6 +208,21 @@ void *JITResolver::JITCompilerFn(void *Stub) {
 }
 
 
+// getPointerToFunctionOrStub - If the specified function has been
+// code-gen'd, return a pointer to the function.  If not, compile it, or use
+// a stub to implement lazy compilation if available.
+//
+void *JIT::getPointerToFunctionOrStub(Function *F) {
+  // If we have already code generated the function, just return the address.
+  if (void *Addr = getPointerToGlobalIfAvailable(F))
+    return Addr;
+
+  // Get a stub if the target supports it
+  return getJITResolver(MCE).getFunctionStub(F);
+}
+
+
+
 //===----------------------------------------------------------------------===//
 // JITEmitter code.
 //