summaryrefslogtreecommitdiff
path: root/unittests/ExecutionEngine
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2009-11-12 03:12:18 +0000
committerEric Christopher <echristo@apple.com>2009-11-12 03:12:18 +0000
commit116664a697f9c2cdccc0df46c53f65c9f6bb22fe (patch)
treeab644f43aea3a4594c08c4abf8b1cb173b493975 /unittests/ExecutionEngine
parentdfa9261f6835f728d9009f16fa51cff25cf20aa9 (diff)
downloadllvm-116664a697f9c2cdccc0df46c53f65c9f6bb22fe.tar.gz
llvm-116664a697f9c2cdccc0df46c53f65c9f6bb22fe.tar.bz2
llvm-116664a697f9c2cdccc0df46c53f65c9f6bb22fe.tar.xz
Use stubs when we have them, otherwise use code we already have,
otherwise create a stub. Add a test to make sure we don't create extraneous stubs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86941 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ExecutionEngine')
-rw-r--r--unittests/ExecutionEngine/JIT/JITTest.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp
index 5b8d299f58..5dc6721fab 100644
--- a/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -61,6 +61,7 @@ class RecordingJITMemoryManager : public JITMemoryManager {
public:
RecordingJITMemoryManager()
: Base(JITMemoryManager::CreateDefaultMemManager()) {
+ stubsAllocated = 0;
}
virtual void setMemoryWritable() { Base->setMemoryWritable(); }
@@ -88,8 +89,10 @@ public:
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 {
@@ -455,6 +458,44 @@ TEST_F(JITTest, ModuleDeletion) {
NumTablesDeallocated);
}
+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.