[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Apr 17 18:44:43 PDT 2005
Changes in directory llvm/lib/ExecutionEngine/JIT:
JITEmitter.cpp updated: 1.64 -> 1.65
---
Log message:
Add support for targets that require stubs for external functions.
---
Diffs of the changes: (+27 -2)
JITEmitter.cpp | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
Index: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
diff -u llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.64 llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.65
--- llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.64 Thu Mar 17 09:36:52 2005
+++ llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp Sun Apr 17 20:44:27 2005
@@ -138,6 +138,9 @@
// to.
std::map<void*, Function*> StubToFunctionMap;
+ /// ExternalFnToStubMap - This is the equivalent of FunctionToStubMap for
+ /// external functions.
+ std::map<void*, void*> ExternalFnToStubMap;
public:
JITResolver(MachineCodeEmitter &mce) : MCE(mce) {
LazyResolverFn =
@@ -148,6 +151,10 @@
/// one on demand as needed.
void *getFunctionStub(Function *F);
+ /// getExternalFunctionStub - Return a stub for the function at the
+ /// specified address, created lazily on demand.
+ void *getExternalFunctionStub(void *FnAddr);
+
/// AddCallbackAtLocation - If the target is capable of rewriting an
/// instruction without the use of a stub, record the location of the use so
/// we know which function is being used at the location.
@@ -204,6 +211,20 @@
return Stub;
}
+/// getExternalFunctionStub - Return a stub for the function at the
+/// specified address, created lazily on demand.
+void *JITResolver::getExternalFunctionStub(void *FnAddr) {
+ // If we already have a stub for this function, recycle it.
+ void *&Stub = ExternalFnToStubMap[FnAddr];
+ if (Stub) return Stub;
+
+ Stub = TheJIT->getJITInfo().emitFunctionStub(FnAddr, MCE);
+ DEBUG(std::cerr << "JIT: Stub emitted at [" << Stub
+ << "] for external function at '" << FnAddr << "'\n");
+ return Stub;
+}
+
+
/// JITCompilerFn - This function is called when a lazy compilation stub has
/// been entered. It looks up which function this stub corresponds to, compiles
/// it if necessary, then returns the resultant function pointer.
@@ -350,9 +371,13 @@
for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
MachineRelocation &MR = Relocations[i];
void *ResultPtr;
- if (MR.isString())
+ if (MR.isString()) {
ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
- else
+
+ // If the target REALLY wants a stub for this function, emit it now.
+ if (!MR.doesntNeedFunctionStub())
+ ResultPtr = getJITResolver(this).getExternalFunctionStub(ResultPtr);
+ } else
ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
CurBlock+MR.getMachineCodeOffset(),
MR.doesntNeedFunctionStub());
More information about the llvm-commits
mailing list