diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2010-01-27 20:34:15 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2010-01-27 20:34:15 +0000 |
commit | 62de4e7b460f8ffbe0ee71a5a09503790102943f (patch) | |
tree | b93c54de2473a5a87afd13ebccdd234b509b6b72 /unittests | |
parent | 5c594c8ee90b90dba12a349265b89ced14d7d2ef (diff) | |
download | external_llvm-62de4e7b460f8ffbe0ee71a5a09503790102943f.zip external_llvm-62de4e7b460f8ffbe0ee71a5a09503790102943f.tar.gz external_llvm-62de4e7b460f8ffbe0ee71a5a09503790102943f.tar.bz2 |
Kill ModuleProvider and ghost linkage by inverting the relationship between
Modules and ModuleProviders. Because the "ModuleProvider" simply materializes
GlobalValues now, and doesn't provide modules, it's renamed to
"GVMaterializer". Code that used to need a ModuleProvider to materialize
Functions can now materialize the Functions directly. Functions no longer use a
magic linkage to record that they're materializable; they simply ask the
GVMaterializer.
Because the C ABI must never change, we can't remove LLVMModuleProviderRef or
the functions that refer to it. Instead, because Module now exposes the same
functionality ModuleProvider used to, we store a Module* in any
LLVMModuleProviderRef and translate in the wrapper methods. The bindings to
other languages still use the ModuleProvider concept. It would probably be
worth some time to update them to follow the C++ more closely, but I don't
intend to do it.
Fixes http://llvm.org/PR5737 and http://llvm.org/PR5735.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94686 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp | 1 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 74 |
2 files changed, 52 insertions, 23 deletions
diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index c3bb858..a36ec3b 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -12,7 +12,6 @@ #include "llvm/LLVMContext.h" #include "llvm/Instructions.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 7f75afa..84ee0e3 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -23,7 +23,6 @@ #include "llvm/GlobalVariable.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" #include "llvm/Support/IRBuilder.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -194,11 +193,10 @@ class JITTest : public testing::Test { protected: virtual void SetUp() { M = new Module("<main>", Context); - MP = new ExistingModuleProvider(M); RJMM = new RecordingJITMemoryManager; RJMM->setPoisonMemory(true); std::string Error; - TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT) + TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT) .setJITMemoryManager(RJMM) .setErrorStr(&Error).create()); ASSERT_TRUE(TheJIT.get() != NULL) << Error; @@ -209,8 +207,7 @@ class JITTest : public testing::Test { } LLVMContext Context; - Module *M; // Owned by MP. - ModuleProvider *MP; // Owned by ExecutionEngine. + Module *M; // Owned by ExecutionEngine. RecordingJITMemoryManager *RJMM; OwningPtr<ExecutionEngine> TheJIT; }; @@ -223,14 +220,13 @@ class JITTest : public testing::Test { TEST(JIT, GlobalInFunction) { LLVMContext context; Module *M = new Module("<main>", context); - ExistingModuleProvider *MP = new ExistingModuleProvider(M); JITMemoryManager *MemMgr = JITMemoryManager::CreateDefaultMemManager(); // Tell the memory manager to poison freed memory so that accessing freed // memory is more easily tested. MemMgr->setPoisonMemory(true); std::string Error; - OwningPtr<ExecutionEngine> JIT(EngineBuilder(MP) + OwningPtr<ExecutionEngine> JIT(EngineBuilder(M) .setEngineKind(EngineKind::JIT) .setErrorStr(&Error) .setJITMemoryManager(MemMgr) @@ -428,7 +424,8 @@ TEST_F(JITTest, ModuleDeletion) { "} "); Function *func = M->getFunction("main"); TheJIT->getPointerToFunction(func); - TheJIT->deleteModuleProvider(MP); + TheJIT->removeModule(M); + delete M; SmallPtrSet<const void*, 2> FunctionsDeallocated; for (unsigned i = 0, e = RJMM->deallocateFunctionBodyCalls.size(); @@ -647,36 +644,70 @@ std::string AssembleToBitcode(LLVMContext &Context, const char *Assembly) { } // Returns a newly-created ExecutionEngine that reads the bitcode in 'Bitcode' -// lazily. The associated ModuleProvider (owned by the ExecutionEngine) is -// returned in MP. Both will be NULL on an error. Bitcode must live at least -// as long as the ExecutionEngine. +// lazily. The associated Module (owned by the ExecutionEngine) is returned in +// M. Both will be NULL on an error. Bitcode must live at least as long as the +// ExecutionEngine. ExecutionEngine *getJITFromBitcode( - LLVMContext &Context, const std::string &Bitcode, ModuleProvider *&MP) { + LLVMContext &Context, const std::string &Bitcode, Module *&M) { // c_str() is null-terminated like MemoryBuffer::getMemBuffer requires. MemoryBuffer *BitcodeBuffer = MemoryBuffer::getMemBuffer(Bitcode.c_str(), Bitcode.c_str() + Bitcode.size(), "Bitcode for test"); std::string errMsg; - MP = getBitcodeModuleProvider(BitcodeBuffer, Context, &errMsg); - if (MP == NULL) { + M = getLazyBitcodeModule(BitcodeBuffer, Context, &errMsg); + if (M == NULL) { ADD_FAILURE() << errMsg; delete BitcodeBuffer; return NULL; } - ExecutionEngine *TheJIT = EngineBuilder(MP) + ExecutionEngine *TheJIT = EngineBuilder(M) .setEngineKind(EngineKind::JIT) .setErrorStr(&errMsg) .create(); if (TheJIT == NULL) { ADD_FAILURE() << errMsg; - delete MP; - MP = NULL; + delete M; + M = NULL; return NULL; } return TheJIT; } +TEST(LazyLoadedJITTest, MaterializableAvailableExternallyFunctionIsntCompiled) { + LLVMContext Context; + const std::string Bitcode = + AssembleToBitcode(Context, + "define available_externally i32 " + " @JITTest_AvailableExternallyFunction() { " + " ret i32 7 " + "} " + " " + "define i32 @func() { " + " %result = tail call i32 " + " @JITTest_AvailableExternallyFunction() " + " ret i32 %result " + "} "); + ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; + Module *M; + OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); + ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; + TheJIT->DisableLazyCompilation(true); + + Function *funcIR = M->getFunction("func"); + Function *availableFunctionIR = + M->getFunction("JITTest_AvailableExternallyFunction"); + + // Double-check that the available_externally function is still unmaterialized + // when getPointerToFunction needs to find out if it's available_externally. + EXPECT_TRUE(availableFunctionIR->isMaterializable()); + + int32_t (*func)() = reinterpret_cast<int32_t(*)()>( + (intptr_t)TheJIT->getPointerToFunction(funcIR)); + EXPECT_EQ(42, func()) << "func should return 42 from the static version," + << " not 7 from the IR version."; +} + TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { LLVMContext Context; const std::string Bitcode = @@ -697,16 +728,15 @@ TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { " ret i32 %result " "} "); ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; - ModuleProvider *MP; - OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, MP)); + Module *M; + OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; TheJIT->DisableLazyCompilation(true); - Module *M = MP->getModule(); Function *recur1IR = M->getFunction("recur1"); Function *recur2IR = M->getFunction("recur2"); - EXPECT_TRUE(recur1IR->hasNotBeenReadFromBitcode()); - EXPECT_TRUE(recur2IR->hasNotBeenReadFromBitcode()); + EXPECT_TRUE(recur1IR->isMaterializable()); + EXPECT_TRUE(recur2IR->isMaterializable()); int32_t (*recur1)(int32_t) = reinterpret_cast<int32_t(*)(int32_t)>( (intptr_t)TheJIT->getPointerToFunction(recur1IR)); |