[llvm-branch-commits] [llvm-branch] r86944 - in /llvm/branches/Apple/Leela-M1: lib/ExecutionEngine/JIT/JITEmitter.cpp unittests/ExecutionEngine/JIT/JITTest.cpp
Eric Christopher
echristo at apple.com
Wed Nov 11 19:23:46 PST 2009
Author: echristo
Date: Wed Nov 11 21:23:46 2009
New Revision: 86944
URL: http://llvm.org/viewvc/llvm-project?rev=86944&view=rev
Log:
Merge in here too.. fixes 7369388.
Modified:
llvm/branches/Apple/Leela-M1/lib/ExecutionEngine/JIT/JITEmitter.cpp
llvm/branches/Apple/Leela-M1/unittests/ExecutionEngine/JIT/JITTest.cpp
Modified: llvm/branches/Apple/Leela-M1/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela-M1/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=86944&r1=86943&r2=86944&view=diff
==============================================================================
--- llvm/branches/Apple/Leela-M1/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/branches/Apple/Leela-M1/lib/ExecutionEngine/JIT/JITEmitter.cpp Wed Nov 11 21:23:46 2009
@@ -747,15 +747,18 @@
// If we have already compiled the function, return a pointer to its body.
Function *F = cast<Function>(V);
- void *ResultPtr;
- if (!DoesntNeedStub) {
- // Return the function stub if it's already created.
- ResultPtr = Resolver.getFunctionStubIfAvailable(F);
- if (ResultPtr)
- AddStubToCurrentFunction(ResultPtr);
- } else {
- ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F);
+
+ void *FnStub = Resolver.getFunctionStubIfAvailable(F);
+ if (FnStub) {
+ // Return the function stub if it's already created. We do this first
+ // so that we're returning the same address for the function as any
+ // previous call.
+ AddStubToCurrentFunction(FnStub);
+ return FnStub;
}
+
+ // Otherwise if we have code, go ahead and return that.
+ void *ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F);
if (ResultPtr) return ResultPtr;
// If this is an external function pointer, we can force the JIT to
Modified: llvm/branches/Apple/Leela-M1/unittests/ExecutionEngine/JIT/JITTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela-M1/unittests/ExecutionEngine/JIT/JITTest.cpp?rev=86944&r1=86943&r2=86944&view=diff
==============================================================================
--- llvm/branches/Apple/Leela-M1/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
+++ llvm/branches/Apple/Leela-M1/unittests/ExecutionEngine/JIT/JITTest.cpp Wed Nov 11 21:23:46 2009
@@ -61,6 +61,7 @@
public:
RecordingJITMemoryManager()
: Base(JITMemoryManager::CreateDefaultMemManager()) {
+ stubsAllocated = 0;
}
virtual void setMemoryWritable() { Base->setMemoryWritable(); }
@@ -90,8 +91,10 @@
StartFunctionBodyCall(Result, F, InitialActualSize, ActualSize));
return Result;
}
+ int stubsAllocated;
virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
unsigned Alignment) {
+ stubsAllocated++;
return Base->allocateStub(F, StubSize, Alignment);
}
struct EndFunctionBodyCall {
@@ -452,6 +455,44 @@
RJMM->deallocateExceptionTableCalls.size());
}
+typedef int (*FooPtr) ();
+
+TEST_F(JITTest, NoStubs) {
+ LoadAssembly("define void @bar() {"
+ "entry: "
+ "ret void"
+ "}"
+ " "
+ "define i32 @foo() {"
+ "entry:"
+ "call void @bar()"
+ "ret i32 undef"
+ "}"
+ " "
+ "define i32 @main() {"
+ "entry:"
+ "%0 = call i32 @foo()"
+ "call void @bar()"
+ "ret i32 undef"
+ "}");
+ Function *foo = M->getFunction("foo");
+ uintptr_t tmp = (uintptr_t)(TheJIT->getPointerToFunction(foo));
+ FooPtr ptr = (FooPtr)(tmp);
+
+ (ptr)();
+
+ // We should now allocate no more stubs, we have the code to foo
+ // and the existing stub for bar.
+ int stubsBefore = RJMM->stubsAllocated;
+ Function *func = M->getFunction("main");
+ TheJIT->getPointerToFunction(func);
+
+ Function *bar = M->getFunction("bar");
+ TheJIT->getPointerToFunction(bar);
+
+ ASSERT_EQ(stubsBefore, RJMM->stubsAllocated);
+}
+
// This code is copied from JITEventListenerTest, but it only runs once for all
// the tests in this directory. Everything seems fine, but that's strange
// behavior.
More information about the llvm-branch-commits
mailing list