Skip to content

Commit 89af2d5

Browse files
committed
Implement the ExecutionEngine::getPointerToFunctionOrStub by forwarding the
request on to the TargetMachine if it supports the getJITStubForFunction method llvm-svn: 10431
1 parent 2e7416c commit 89af2d5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/lib/ExecutionEngine/JIT/VM.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ void *VM::getPointerToFunction(Function *F) {
7777
return Addr;
7878
}
7979

80+
// getPointerToFunctionOrStub - If the specified function has been
81+
// code-gen'd, return a pointer to the function. If not, compile it, or use
82+
// a stub to implement lazy compilation if available.
83+
//
84+
void *VM::getPointerToFunctionOrStub(Function *F) {
85+
// If we have already code generated the function, just return the address.
86+
std::map<const GlobalValue*, void *>::iterator I = GlobalAddress.find(F);
87+
if (I != GlobalAddress.end()) return I->second;
88+
89+
// If the target supports "stubs" for functions, get a stub now.
90+
if (void *Ptr = TM.getJITStubForFunction(F, *MCE))
91+
return Ptr;
92+
93+
// Otherwise, if the target doesn't support it, just codegen the function.
94+
return getPointerToFunction(F);
95+
}
96+
8097
/// recompileAndRelinkFunction - This method is used to force a function
8198
/// which has already been compiled, to be compiled again, possibly
8299
/// after it has been modified. Then the entry to the old copy is overwritten

llvm/lib/ExecutionEngine/JIT/VM.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class VM : public ExecutionEngine {
6666
///
6767
void *getPointerToFunction(Function *F);
6868

69+
/// getPointerToFunctionOrStub - If the specified function has been
70+
/// code-gen'd, return a pointer to the function. If not, compile it, or use
71+
/// a stub to implement lazy compilation if available.
72+
///
73+
void *getPointerToFunctionOrStub(Function *F);
74+
6975
/// recompileAndRelinkFunction - This method is used to force a function
7076
/// which has already been compiled, to be compiled again, possibly
7177
/// after it has been modified. Then the entry to the old copy is overwritten

0 commit comments

Comments
 (0)