diff options
author | Stephen Hines <srhines@google.com> | 2014-04-23 16:57:46 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-04-24 15:53:16 -0700 |
commit | 36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch) | |
tree | e6cfb69fbbd937f450eeb83bfb83b9da3b01275a /unittests/ExecutionEngine | |
parent | 69a8640022b04415ae9fac62f8ab090601d8f889 (diff) | |
download | external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2 |
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'unittests/ExecutionEngine')
18 files changed, 418 insertions, 159 deletions
diff --git a/unittests/ExecutionEngine/CMakeLists.txt b/unittests/ExecutionEngine/CMakeLists.txt index 4eefc1e..7ef509b 100644 --- a/unittests/ExecutionEngine/CMakeLists.txt +++ b/unittests/ExecutionEngine/CMakeLists.txt @@ -1,5 +1,8 @@ set(LLVM_LINK_COMPONENTS - interpreter + Core + ExecutionEngine + Interpreter + Support ) add_llvm_unittest(ExecutionEngineTests diff --git a/unittests/ExecutionEngine/ExecutionEngineTest.cpp b/unittests/ExecutionEngine/ExecutionEngineTest.cpp index 3e304e7..e6f07dc 100644 --- a/unittests/ExecutionEngine/ExecutionEngineTest.cpp +++ b/unittests/ExecutionEngine/ExecutionEngineTest.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/Interpreter.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LLVMContext.h" @@ -38,7 +37,7 @@ protected: Module *const M; std::string Error; - const OwningPtr<ExecutionEngine> Engine; + const std::unique_ptr<ExecutionEngine> Engine; }; TEST_F(ExecutionEngineTest, ForwardGlobalMapping) { diff --git a/unittests/ExecutionEngine/JIT/CMakeLists.txt b/unittests/ExecutionEngine/JIT/CMakeLists.txt index ef37026..72c1df7 100644 --- a/unittests/ExecutionEngine/JIT/CMakeLists.txt +++ b/unittests/ExecutionEngine/JIT/CMakeLists.txt @@ -1,8 +1,11 @@ set(LLVM_LINK_COMPONENTS - asmparser - bitreader - bitwriter - jit + AsmParser + BitReader + BitWriter + Core + ExecutionEngine + JIT + Support nativecodegen ) @@ -48,6 +51,9 @@ if(MSVC) list(APPEND JITTestsSources JITTests.def) endif() +# The JIT tests need to dlopen things. +set(LLVM_NO_DEAD_STRIP 1) + add_llvm_unittest(JITTests ${JITTestsSources} ) diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index 87f4824..175b9fb 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/JITEventListener.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/IR/Instructions.h" @@ -21,8 +20,6 @@ using namespace llvm; -int dummy; - namespace { struct FunctionEmittedEvent { @@ -71,11 +68,11 @@ class JITEventListenerTest : public testing::Test { } Module *M; - const OwningPtr<ExecutionEngine> EE; + const std::unique_ptr<ExecutionEngine> EE; }; // Tests on SystemZ disabled as we're running the old JIT -#if !defined(__s390__) +#if !defined(__s390__) && !defined(__aarch64__) Function *buildFunction(Module *M) { Function *Result = Function::Create( TypeBuilder<int32_t(int32_t), false>::get(getGlobalContext()), diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h index d1c2124..61220f5 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTestCommon.h @@ -12,10 +12,10 @@ #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/Config/config.h" -#include "llvm/DIBuilder.h" -#include "llvm/DebugInfo.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/JITEventListener.h" +#include "llvm/IR/DIBuilder.h" +#include "llvm/IR/DebugInfo.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" @@ -53,8 +53,8 @@ inline const char* getFilename() { template<typename WrapperT> class JITEventListenerTestBase : public testing::Test { protected: - llvm::OwningPtr<WrapperT> MockWrapper; - llvm::OwningPtr<llvm::JITEventListener> Listener; + std::unique_ptr<WrapperT> MockWrapper; + std::unique_ptr<llvm::JITEventListener> Listener; public: llvm::Module* M; diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index 731f780..ab30884 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -9,7 +9,6 @@ #include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -31,27 +30,27 @@ Function *makeFakeFunction() { // the code in the case that we don't have to allocate more memory to store the // function bodies. TEST(JITMemoryManagerTest, NoAllocations) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); uintptr_t size; std::string Error; // Allocate the functions. - OwningPtr<Function> F1(makeFakeFunction()); + std::unique_ptr<Function> F1(makeFakeFunction()); size = 1024; uint8_t *FunctionBody1 = MemMgr->startFunctionBody(F1.get(), size); memset(FunctionBody1, 0xFF, 1024); MemMgr->endFunctionBody(F1.get(), FunctionBody1, FunctionBody1 + 1024); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F2(makeFakeFunction()); + std::unique_ptr<Function> F2(makeFakeFunction()); size = 1024; uint8_t *FunctionBody2 = MemMgr->startFunctionBody(F2.get(), size); memset(FunctionBody2, 0xFF, 1024); MemMgr->endFunctionBody(F2.get(), FunctionBody2, FunctionBody2 + 1024); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F3(makeFakeFunction()); + std::unique_ptr<Function> F3(makeFakeFunction()); size = 1024; uint8_t *FunctionBody3 = MemMgr->startFunctionBody(F3.get(), size); memset(FunctionBody3, 0xFF, 1024); @@ -70,7 +69,7 @@ TEST(JITMemoryManagerTest, NoAllocations) { // Make three large functions that take up most of the space in the slab. Then // try allocating three smaller functions that don't require additional slabs. TEST(JITMemoryManagerTest, TestCodeAllocation) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); uintptr_t size; std::string Error; @@ -81,7 +80,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { smallFuncSize * 2); // Allocate big functions - OwningPtr<Function> F1(makeFakeFunction()); + std::unique_ptr<Function> F1(makeFakeFunction()); size = bigFuncSize; uint8_t *FunctionBody1 = MemMgr->startFunctionBody(F1.get(), size); ASSERT_LE(bigFuncSize, size); @@ -89,7 +88,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { MemMgr->endFunctionBody(F1.get(), FunctionBody1, FunctionBody1 + bigFuncSize); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F2(makeFakeFunction()); + std::unique_ptr<Function> F2(makeFakeFunction()); size = bigFuncSize; uint8_t *FunctionBody2 = MemMgr->startFunctionBody(F2.get(), size); ASSERT_LE(bigFuncSize, size); @@ -97,7 +96,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { MemMgr->endFunctionBody(F2.get(), FunctionBody2, FunctionBody2 + bigFuncSize); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F3(makeFakeFunction()); + std::unique_ptr<Function> F3(makeFakeFunction()); size = bigFuncSize; uint8_t *FunctionBody3 = MemMgr->startFunctionBody(F3.get(), size); ASSERT_LE(bigFuncSize, size); @@ -109,7 +108,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { EXPECT_EQ(3U, MemMgr->GetNumCodeSlabs()); // Allocate small functions - OwningPtr<Function> F4(makeFakeFunction()); + std::unique_ptr<Function> F4(makeFakeFunction()); size = smallFuncSize; uint8_t *FunctionBody4 = MemMgr->startFunctionBody(F4.get(), size); ASSERT_LE(smallFuncSize, size); @@ -118,7 +117,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { FunctionBody4 + smallFuncSize); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F5(makeFakeFunction()); + std::unique_ptr<Function> F5(makeFakeFunction()); size = smallFuncSize; uint8_t *FunctionBody5 = MemMgr->startFunctionBody(F5.get(), size); ASSERT_LE(smallFuncSize, size); @@ -127,7 +126,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { FunctionBody5 + smallFuncSize); EXPECT_TRUE(MemMgr->CheckInvariants(Error)) << Error; - OwningPtr<Function> F6(makeFakeFunction()); + std::unique_ptr<Function> F6(makeFakeFunction()); size = smallFuncSize; uint8_t *FunctionBody6 = MemMgr->startFunctionBody(F6.get(), size); ASSERT_LE(smallFuncSize, size); @@ -157,7 +156,7 @@ TEST(JITMemoryManagerTest, TestCodeAllocation) { // Allocate five global ints of varying widths and alignment, and check their // alignment and overlap. TEST(JITMemoryManagerTest, TestSmallGlobalInts) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); uint8_t *a = (uint8_t *)MemMgr->allocateGlobal(8, 0); uint16_t *b = (uint16_t*)MemMgr->allocateGlobal(16, 2); @@ -204,7 +203,7 @@ TEST(JITMemoryManagerTest, TestSmallGlobalInts) { // Allocate a small global, a big global, and a third global, and make sure we // only use two slabs for that. TEST(JITMemoryManagerTest, TestLargeGlobalArray) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); size_t Size = 4 * MemMgr->GetDefaultDataSlabSize(); uint64_t *a = (uint64_t*)MemMgr->allocateGlobal(64, 8); @@ -234,7 +233,7 @@ TEST(JITMemoryManagerTest, TestLargeGlobalArray) { // Allocate lots of medium globals so that we can test moving the bump allocator // to a new slab. TEST(JITMemoryManagerTest, TestManyGlobals) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); size_t SlabSize = MemMgr->GetDefaultDataSlabSize(); size_t Size = 128; @@ -257,7 +256,7 @@ TEST(JITMemoryManagerTest, TestManyGlobals) { // Allocate lots of function stubs so that we can test moving the stub bump // allocator to a new slab. TEST(JITMemoryManagerTest, TestManyStubs) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); size_t SlabSize = MemMgr->GetDefaultStubSlabSize(); size_t Size = 128; @@ -279,7 +278,7 @@ TEST(JITMemoryManagerTest, TestManyStubs) { // Check section allocation and alignment TEST(JITMemoryManagerTest, AllocateSection) { - OwningPtr<JITMemoryManager> MemMgr( + std::unique_ptr<JITMemoryManager> MemMgr( JITMemoryManager::CreateDefaultMemManager()); uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, StringRef()); uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, StringRef(), true); diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 4c7b1e2..9e65fee 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -8,9 +8,8 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/JIT.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallPtrSet.h" -#include "llvm/Assembly/Parser.h" +#include "llvm/AsmParser/Parser.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/IR/BasicBlock.h" @@ -52,7 +51,8 @@ extern "C" int32_t JITTest_AvailableExternallyFunction() { namespace { // Tests on ARM, PowerPC and SystemZ disabled as we're running the old jit -#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__) +#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__) \ + && !defined(__aarch64__) Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) { std::vector<Type*> params; @@ -76,7 +76,8 @@ std::string DumpFunction(const Function *F) { } class RecordingJITMemoryManager : public JITMemoryManager { - const OwningPtr<JITMemoryManager> Base; + const std::unique_ptr<JITMemoryManager> Base; + public: RecordingJITMemoryManager() : Base(JITMemoryManager::CreateDefaultMemManager()) { @@ -202,7 +203,7 @@ class JITTest : public testing::Test { LLVMContext Context; Module *M; // Owned by ExecutionEngine. RecordingJITMemoryManager *RJMM; - OwningPtr<ExecutionEngine> TheJIT; + std::unique_ptr<ExecutionEngine> TheJIT; }; // Regression test for a bug. The JIT used to allocate globals inside the same @@ -219,13 +220,13 @@ TEST(JIT, GlobalInFunction) { // memory is more easily tested. MemMgr->setPoisonMemory(true); std::string Error; - OwningPtr<ExecutionEngine> JIT(EngineBuilder(M) - .setEngineKind(EngineKind::JIT) - .setErrorStr(&Error) - .setJITMemoryManager(MemMgr) - // The next line enables the fix: - .setAllocateGVsWithCode(false) - .create()); + std::unique_ptr<ExecutionEngine> JIT(EngineBuilder(M) + .setEngineKind(EngineKind::JIT) + .setErrorStr(&Error) + .setJITMemoryManager(MemMgr) + // The next line enables the fix: + .setAllocateGVsWithCode(false) + .create()); ASSERT_EQ(Error, ""); // Create a global variable. @@ -438,7 +439,7 @@ TEST_F(JITTest, ModuleDeletion) { // too far away to call directly. This #if can probably be removed when // http://llvm.org/PR5201 is fixed. #if !defined(__arm__) && !defined(__mips__) && \ - !defined(__powerpc__) && !defined(__ppc__) + !defined(__powerpc__) && !defined(__ppc__) && !defined(__aarch64__) typedef int (*FooPtr) (); TEST_F(JITTest, NoStubs) { @@ -514,7 +515,7 @@ TEST_F(JITTest, FunctionPointersOutliveTheirCreator) { // ARM does not have an implementation of replaceMachineCodeForFunction(), // so recompileAndRelinkFunction doesn't work. -#if !defined(__arm__) +#if !defined(__arm__) && !defined(__aarch64__) TEST_F(JITTest, FunctionIsRecompiledAndRelinked) { Function *F = Function::Create(TypeBuilder<int(void), false>::get(Context), GlobalValue::ExternalLinkage, "test", M); @@ -631,13 +632,14 @@ ExecutionEngine *getJITFromBitcode( // c_str() is null-terminated like MemoryBuffer::getMemBuffer requires. MemoryBuffer *BitcodeBuffer = MemoryBuffer::getMemBuffer(Bitcode, "Bitcode for test"); - std::string errMsg; - M = getLazyBitcodeModule(BitcodeBuffer, Context, &errMsg); - if (M == NULL) { - ADD_FAILURE() << errMsg; + ErrorOr<Module*> ModuleOrErr = getLazyBitcodeModule(BitcodeBuffer, Context); + if (error_code EC = ModuleOrErr.getError()) { + ADD_FAILURE() << EC.message(); delete BitcodeBuffer; return NULL; } + M = ModuleOrErr.get(); + std::string errMsg; ExecutionEngine *TheJIT = EngineBuilder(M) .setEngineKind(EngineKind::JIT) .setErrorStr(&errMsg) @@ -667,7 +669,8 @@ TEST(LazyLoadedJITTest, MaterializableAvailableExternallyFunctionIsntCompiled) { "} "); ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; Module *M; - OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); + std::unique_ptr<ExecutionEngine> TheJIT( + getJITFromBitcode(Context, Bitcode, M)); ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; TheJIT->DisableLazyCompilation(true); @@ -706,7 +709,8 @@ TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { "} "); ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; Module *M; - OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); + std::unique_ptr<ExecutionEngine> TheJIT( + getJITFromBitcode(Context, Bitcode, M)); ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; TheJIT->DisableLazyCompilation(true); diff --git a/unittests/ExecutionEngine/JIT/Makefile b/unittests/ExecutionEngine/JIT/Makefile index ef8b827..d86c03b 100644 --- a/unittests/ExecutionEngine/JIT/Makefile +++ b/unittests/ExecutionEngine/JIT/Makefile @@ -11,6 +11,9 @@ LEVEL = ../../.. TESTNAME = JIT LINK_COMPONENTS := asmparser bitreader bitwriter jit native +# The JIT tests need to dlopen things. +NO_DEAD_STRIP := 1 + include $(LEVEL)/Makefile.config SOURCES := JITEventListenerTest.cpp JITMemoryManagerTest.cpp JITTest.cpp MultiJITTest.cpp diff --git a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp index 4018cd5..5016532 100644 --- a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp +++ b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/JIT.h" -#include "llvm/Assembly/Parser.h" +#include "llvm/AsmParser/Parser.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -21,7 +21,8 @@ using namespace llvm; namespace { // ARM, PowerPC and SystemZ tests disabled pending fix for PR10783. -#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__) +#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__) \ + && !defined(__aarch64__) bool LoadAssemblyInto(Module *M, const char *assembly) { SMDiagnostic Error; @@ -80,9 +81,9 @@ TEST(MultiJitTest, EagerMode) { createModule2(Context2, M2, FooF2); // Now we create the JIT in eager mode - OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create()); EE1->DisableLazyCompilation(true); - OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create()); EE2->DisableLazyCompilation(true); // Call the `foo' function with no arguments: @@ -110,9 +111,9 @@ TEST(MultiJitTest, LazyMode) { createModule2(Context2, M2, FooF2); // Now we create the JIT in lazy mode - OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create()); EE1->DisableLazyCompilation(false); - OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create()); EE2->DisableLazyCompilation(false); // Call the `foo' function with no arguments: @@ -144,8 +145,8 @@ TEST(MultiJitTest, JitPool) { createModule2(Context2, M2, FooF2); // Now we create two JITs - OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); - OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create()); Function *F1 = EE1->FindFunctionNamed("foo1"); void *foo1 = EE1->getPointerToFunction(F1); @@ -173,6 +174,14 @@ TEST(MultiJitTest, JitPool) { EXPECT_TRUE(fa != 0); fa = *(intptr_t *)fa; // Bound value of IAT } +#elif defined(__x86_64__) + // getPointerToNamedFunction might be indirect jump + // on Win32 x64 --enable-shared. + // FF 25 <pcrel32>: jmp *(RIP + pointer to IAT) + if (sa != fa && memcmp((char *)fa, "\xFF\x25", 2) == 0) { + fa += *(int32_t *)(fa + 2) + 6; // Address to IAT(RIP) + fa = *(intptr_t *)fa; // Bound value of IAT + } #endif EXPECT_TRUE(sa == fa); } diff --git a/unittests/ExecutionEngine/MCJIT/CMakeLists.txt b/unittests/ExecutionEngine/MCJIT/CMakeLists.txt index ed43099..afa3f2a 100644 --- a/unittests/ExecutionEngine/MCJIT/CMakeLists.txt +++ b/unittests/ExecutionEngine/MCJIT/CMakeLists.txt @@ -1,8 +1,13 @@ set(LLVM_LINK_COMPONENTS - asmparser - bitreader - bitwriter - mcjit + Analysis + Core + ExecutionEngine + IPO + JIT + MCJIT + ScalarOpts + Support + Target nativecodegen ) diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index 46d6d9b..3813d59 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -13,18 +13,21 @@ //===----------------------------------------------------------------------===// #include "llvm-c/Analysis.h" +#include "MCJITTestAPICommon.h" #include "llvm-c/Core.h" #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Target.h" +#include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm-c/Transforms/Scalar.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/Host.h" -#include "MCJITTestAPICommon.h" #include "gtest/gtest.h" using namespace llvm; static bool didCallAllocateCodeSection; +static bool didAllocateCompactUnwindSection; static uint8_t *roundTripAllocateCodeSection(void *object, uintptr_t size, unsigned alignment, @@ -40,6 +43,8 @@ static uint8_t *roundTripAllocateDataSection(void *object, uintptr_t size, unsigned sectionID, const char *sectionName, LLVMBool isReadOnly) { + if (!strcmp(sectionName, "__compact_unwind")) + didAllocateCompactUnwindSection = true; return static_cast<SectionMemoryManager*>(object)->allocateDataSection( size, alignment, sectionID, sectionName, isReadOnly); } @@ -60,6 +65,54 @@ static void roundTripDestroy(void *object) { } namespace { + +// memory manager to test reserve allocation space callback +class TestReserveAllocationSpaceMemoryManager: public SectionMemoryManager { +public: + uintptr_t ReservedCodeSize; + uintptr_t UsedCodeSize; + uintptr_t ReservedDataSizeRO; + uintptr_t UsedDataSizeRO; + uintptr_t ReservedDataSizeRW; + uintptr_t UsedDataSizeRW; + + TestReserveAllocationSpaceMemoryManager() : + ReservedCodeSize(0), UsedCodeSize(0), ReservedDataSizeRO(0), + UsedDataSizeRO(0), ReservedDataSizeRW(0), UsedDataSizeRW(0) { + } + + virtual bool needsToReserveAllocationSpace() { + return true; + } + + virtual void reserveAllocationSpace( + uintptr_t CodeSize, uintptr_t DataSizeRO, uintptr_t DataSizeRW) { + ReservedCodeSize = CodeSize; + ReservedDataSizeRO = DataSizeRO; + ReservedDataSizeRW = DataSizeRW; + } + + void useSpace(uintptr_t* UsedSize, uintptr_t Size, unsigned Alignment) { + uintptr_t AlignedSize = (Size + Alignment - 1) / Alignment * Alignment; + uintptr_t AlignedBegin = (*UsedSize + Alignment - 1) / Alignment * Alignment; + *UsedSize = AlignedBegin + AlignedSize; + } + + virtual uint8_t* allocateDataSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID, StringRef SectionName, bool IsReadOnly) { + useSpace(IsReadOnly ? &UsedDataSizeRO : &UsedDataSizeRW, Size, Alignment); + return SectionMemoryManager::allocateDataSection(Size, Alignment, + SectionID, SectionName, IsReadOnly); + } + + uint8_t* allocateCodeSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID, StringRef SectionName) { + useSpace(&UsedCodeSize, Size, Alignment); + return SectionMemoryManager::allocateCodeSection(Size, Alignment, + SectionID, SectionName); + } +}; + class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon { protected: MCJITCAPITest() { @@ -82,10 +135,13 @@ protected: // The operating systems below are known to be sufficiently incompatible // that they will fail the MCJIT C API tests. UnsupportedOSs.push_back(Triple::Cygwin); + + UnsupportedEnvironments.push_back(Triple::Cygnus); } virtual void SetUp() { didCallAllocateCodeSection = false; + didAllocateCompactUnwindSection = false; Module = 0; Function = 0; Engine = 0; @@ -119,6 +175,84 @@ protected: LLVMDisposeBuilder(builder); } + void buildFunctionThatUsesStackmap() { + Module = LLVMModuleCreateWithName("simple_module"); + + LLVMSetTarget(Module, HostTriple.c_str()); + + LLVMTypeRef stackmapParamTypes[] = { LLVMInt64Type(), LLVMInt32Type() }; + LLVMValueRef stackmap = LLVMAddFunction( + Module, "llvm.experimental.stackmap", + LLVMFunctionType(LLVMVoidType(), stackmapParamTypes, 2, 1)); + LLVMSetLinkage(stackmap, LLVMExternalLinkage); + + Function = LLVMAddFunction( + Module, "simple_function", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + + LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry"); + LLVMBuilderRef builder = LLVMCreateBuilder(); + LLVMPositionBuilderAtEnd(builder, entry); + LLVMValueRef stackmapArgs[] = { + LLVMConstInt(LLVMInt64Type(), 0, 0), LLVMConstInt(LLVMInt32Type(), 5, 0), + LLVMConstInt(LLVMInt32Type(), 42, 0) + }; + LLVMBuildCall(builder, stackmap, stackmapArgs, 3, ""); + LLVMBuildRet(builder, LLVMConstInt(LLVMInt32Type(), 42, 0)); + + LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error); + LLVMDisposeMessage(Error); + + LLVMDisposeBuilder(builder); + } + + void buildModuleWithCodeAndData() { + Module = LLVMModuleCreateWithName("simple_module"); + + LLVMSetTarget(Module, HostTriple.c_str()); + + // build a global int32 variable initialized to 42. + LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "intVal"); + LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0)); + + { + Function = LLVMAddFunction( + Module, "getGlobal", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + LLVMSetFunctionCallConv(Function, LLVMCCallConv); + + LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "entry"); + LLVMBuilderRef Builder = LLVMCreateBuilder(); + LLVMPositionBuilderAtEnd(Builder, Entry); + + LLVMValueRef IntVal = LLVMBuildLoad(Builder, GlobalVar, "intVal"); + LLVMBuildRet(Builder, IntVal); + + LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error); + LLVMDisposeMessage(Error); + + LLVMDisposeBuilder(Builder); + } + + { + LLVMTypeRef ParamTypes[] = { LLVMInt32Type() }; + Function2 = LLVMAddFunction( + Module, "setGlobal", LLVMFunctionType(LLVMVoidType(), ParamTypes, 1, 0)); + LLVMSetFunctionCallConv(Function2, LLVMCCallConv); + + LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function2, "entry"); + LLVMBuilderRef Builder = LLVMCreateBuilder(); + LLVMPositionBuilderAtEnd(Builder, Entry); + + LLVMValueRef Arg = LLVMGetParam(Function2, 0); + LLVMBuildStore(Builder, Arg, GlobalVar); + LLVMBuildRetVoid(Builder); + + LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error); + LLVMDisposeMessage(Error); + + LLVMDisposeBuilder(Builder); + } + } + void buildMCJITOptions() { LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options)); Options.OptLevel = 2; @@ -135,7 +269,7 @@ protected: roundTripFinalizeMemory, roundTripDestroy); } - + void buildMCJITEngine() { ASSERT_EQ( 0, LLVMCreateMCJITCompilerForModule(&Engine, Module, &Options, @@ -151,8 +285,41 @@ protected: LLVMDisposePassManager(pass); } + void buildAndRunOptPasses() { + LLVMPassManagerBuilderRef passBuilder; + + passBuilder = LLVMPassManagerBuilderCreate(); + LLVMPassManagerBuilderSetOptLevel(passBuilder, 2); + LLVMPassManagerBuilderSetSizeLevel(passBuilder, 0); + + LLVMPassManagerRef functionPasses = + LLVMCreateFunctionPassManagerForModule(Module); + LLVMPassManagerRef modulePasses = + LLVMCreatePassManager(); + + LLVMAddTargetData(LLVMGetExecutionEngineTargetData(Engine), modulePasses); + + LLVMPassManagerBuilderPopulateFunctionPassManager(passBuilder, + functionPasses); + LLVMPassManagerBuilderPopulateModulePassManager(passBuilder, modulePasses); + + LLVMPassManagerBuilderDispose(passBuilder); + + LLVMInitializeFunctionPassManager(functionPasses); + for (LLVMValueRef value = LLVMGetFirstFunction(Module); + value; value = LLVMGetNextFunction(value)) + LLVMRunFunctionPassManager(functionPasses, value); + LLVMFinalizeFunctionPassManager(functionPasses); + + LLVMRunPassManager(modulePasses, Module); + + LLVMDisposePassManager(functionPasses); + LLVMDisposePassManager(modulePasses); + } + LLVMModuleRef Module; LLVMValueRef Function; + LLVMValueRef Function2; LLVMMCJITCompilerOptions Options; LLVMExecutionEngineRef Engine; char *Error; @@ -194,3 +361,71 @@ TEST_F(MCJITCAPITest, custom_memory_manager) { EXPECT_EQ(42, functionPointer.usable()); EXPECT_TRUE(didCallAllocateCodeSection); } + +TEST_F(MCJITCAPITest, stackmap_creates_compact_unwind_on_darwin) { + SKIP_UNSUPPORTED_PLATFORM; + + // This test is also not supported on non-x86 platforms. + if (Triple(HostTriple).getArch() != Triple::x86_64) + return; + + buildFunctionThatUsesStackmap(); + buildMCJITOptions(); + useRoundTripSectionMemoryManager(); + buildMCJITEngine(); + buildAndRunOptPasses(); + + union { + void *raw; + int (*usable)(); + } functionPointer; + functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function); + + EXPECT_EQ(42, functionPointer.usable()); + EXPECT_TRUE(didCallAllocateCodeSection); + + // Up to this point, the test is specific only to X86-64. But this next + // expectation is only valid on Darwin because it assumes that unwind + // data is made available only through compact_unwind. It would be + // worthwhile to extend this to handle non-Darwin platforms, in which + // case you'd want to look for an eh_frame or something. + // + // FIXME: Currently, MCJIT relies on a configure-time check to determine which + // sections to emit. The JIT client should have runtime control over this. + EXPECT_TRUE( + Triple(HostTriple).getOS() != Triple::Darwin || + Triple(HostTriple).isMacOSXVersionLT(10, 7) || + didAllocateCompactUnwindSection); +} + +TEST_F(MCJITCAPITest, reserve_allocation_space) { + SKIP_UNSUPPORTED_PLATFORM; + + TestReserveAllocationSpaceMemoryManager* MM = new TestReserveAllocationSpaceMemoryManager(); + + buildModuleWithCodeAndData(); + buildMCJITOptions(); + Options.MCJMM = wrap(MM); + buildMCJITEngine(); + buildAndRunPasses(); + + union { + void *raw; + int (*usable)(); + } GetGlobalFct; + GetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function); + + union { + void *raw; + void (*usable)(int); + } SetGlobalFct; + SetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function2); + + SetGlobalFct.usable(789); + EXPECT_EQ(789, GetGlobalFct.usable()); + EXPECT_LE(MM->UsedCodeSize, MM->ReservedCodeSize); + EXPECT_LE(MM->UsedDataSizeRO, MM->ReservedDataSizeRO); + EXPECT_LE(MM->UsedDataSizeRW, MM->ReservedDataSizeRW); + EXPECT_TRUE(MM->UsedCodeSize > 0); + EXPECT_TRUE(MM->UsedDataSizeRW > 0); +} diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp index c24346d..f862999 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/SectionMemoryManager.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ExecutionEngine/JIT.h" #include "gtest/gtest.h" @@ -17,7 +16,7 @@ using namespace llvm; namespace { TEST(MCJITMemoryManagerTest, BasicAllocations) { - OwningPtr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); + std::unique_ptr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, ""); uint8_t *data1 = MemMgr->allocateDataSection(256, 0, 2, "", true); @@ -50,7 +49,7 @@ TEST(MCJITMemoryManagerTest, BasicAllocations) { } TEST(MCJITMemoryManagerTest, LargeAllocations) { - OwningPtr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); + std::unique_ptr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); uint8_t *code1 = MemMgr->allocateCodeSection(0x100000, 0, 1, ""); uint8_t *data1 = MemMgr->allocateDataSection(0x100000, 0, 2, "", true); @@ -83,7 +82,7 @@ TEST(MCJITMemoryManagerTest, LargeAllocations) { } TEST(MCJITMemoryManagerTest, ManyAllocations) { - OwningPtr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); + std::unique_ptr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); uint8_t* code[10000]; uint8_t* data[10000]; @@ -118,7 +117,7 @@ TEST(MCJITMemoryManagerTest, ManyAllocations) { } TEST(MCJITMemoryManagerTest, ManyVariedAllocations) { - OwningPtr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); + std::unique_ptr<SectionMemoryManager> MemMgr(new SectionMemoryManager()); uint8_t* code[10000]; uint8_t* data[10000]; diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp index 7c3239e..c5ca36e 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp @@ -90,12 +90,12 @@ TEST_F(MCJITMultipleModuleTest, multiple_empty_modules) { TEST_F(MCJITMultipleModuleTest, two_module_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB; createTwoModuleCase(A, FA, B, FB); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str()); checkAdd(ptr); @@ -110,12 +110,12 @@ TEST_F(MCJITMultipleModuleTest, two_module_case) { TEST_F(MCJITMultipleModuleTest, two_module_reverse_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB; createTwoModuleCase(A, FA, B, FB); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str()); TheJIT->finalizeObject(); @@ -131,12 +131,12 @@ TEST_F(MCJITMultipleModuleTest, two_module_reverse_case) { TEST_F(MCJITMultipleModuleTest, two_module_extern_reverse_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB; createTwoModuleExternCase(A, FA, B, FB); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str()); TheJIT->finalizeObject(); @@ -152,12 +152,12 @@ TEST_F(MCJITMultipleModuleTest, two_module_extern_reverse_case) { TEST_F(MCJITMultipleModuleTest, two_module_extern_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB; createTwoModuleExternCase(A, FA, B, FB); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str()); checkAdd(ptr); @@ -172,13 +172,13 @@ TEST_F(MCJITMultipleModuleTest, two_module_extern_case) { TEST_F(MCJITMultipleModuleTest, two_module_consecutive_call_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA1, *FA2, *FB; createTwoModuleExternCase(A, FA1, B, FB); FA2 = insertSimpleCallFunction<int32_t(int32_t, int32_t)>(A.get(), FA1); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str()); TheJIT->finalizeObject(); @@ -199,7 +199,7 @@ TEST_F(MCJITMultipleModuleTest, two_module_consecutive_call_case) { TEST_F(MCJITMultipleModuleTest, two_module_global_variables_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB; GlobalVariable *GVA, *GVB; A.reset(createEmptyModule("A")); @@ -213,8 +213,8 @@ TEST_F(MCJITMultipleModuleTest, two_module_global_variables_case) { FB = startFunction<int32_t(void)>(B.get(), "FB"); endFunctionWithRet(FB, Builder.CreateLoad(GVB)); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t FBPtr = TheJIT->getFunctionAddress(FB->getName().str()); TheJIT->finalizeObject(); @@ -237,13 +237,13 @@ TEST_F(MCJITMultipleModuleTest, two_module_global_variables_case) { TEST_F(MCJITMultipleModuleTest, three_module_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B, C; + std::unique_ptr<Module> A, B, C; Function *FA, *FB, *FC; createThreeModuleCase(A, FA, B, FB, C, FC); - createJIT(A.take()); - TheJIT->addModule(B.take()); - TheJIT->addModule(C.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); + TheJIT->addModule(C.release()); uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str()); checkAdd(ptr); @@ -262,13 +262,13 @@ TEST_F(MCJITMultipleModuleTest, three_module_case) { TEST_F(MCJITMultipleModuleTest, three_module_case_reverse_order) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B, C; + std::unique_ptr<Module> A, B, C; Function *FA, *FB, *FC; createThreeModuleCase(A, FA, B, FB, C, FC); - createJIT(A.take()); - TheJIT->addModule(B.take()); - TheJIT->addModule(C.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); + TheJIT->addModule(C.release()); uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str()); checkAdd(ptr); @@ -287,13 +287,13 @@ TEST_F(MCJITMultipleModuleTest, three_module_case_reverse_order) { TEST_F(MCJITMultipleModuleTest, three_module_chain_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B, C; + std::unique_ptr<Module> A, B, C; Function *FA, *FB, *FC; createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC); - createJIT(A.take()); - TheJIT->addModule(B.take()); - TheJIT->addModule(C.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); + TheJIT->addModule(C.release()); uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str()); checkAdd(ptr); @@ -312,13 +312,13 @@ TEST_F(MCJITMultipleModuleTest, three_module_chain_case) { TEST_F(MCJITMultipleModuleTest, three_modules_chain_case_reverse_order) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B, C; + std::unique_ptr<Module> A, B, C; Function *FA, *FB, *FC; createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC); - createJIT(A.take()); - TheJIT->addModule(B.take()); - TheJIT->addModule(C.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); + TheJIT->addModule(C.release()); uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str()); checkAdd(ptr); @@ -337,12 +337,12 @@ TEST_F(MCJITMultipleModuleTest, three_modules_chain_case_reverse_order) { TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB1, *FB2; createCrossModuleRecursiveCase(A, FA, B, FB1, FB2); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str()); checkAccumulate(ptr); @@ -358,12 +358,12 @@ TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case) { TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case_reverse_order) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB1, *FB2; createCrossModuleRecursiveCase(A, FA, B, FB1, FB2); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str()); checkAccumulate(ptr); @@ -379,12 +379,12 @@ TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case_reverse_order) { TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case3) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<Module> A, B; + std::unique_ptr<Module> A, B; Function *FA, *FB1, *FB2; createCrossModuleRecursiveCase(A, FA, B, FB1, FB2); - createJIT(A.take()); - TheJIT->addModule(B.take()); + createJIT(A.release()); + TheJIT->addModule(B.release()); uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str()); checkAccumulate(ptr); diff --git a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 7073a52..46847d3 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/OwningPtr.h" +#include "MCJITTestBase.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" @@ -15,7 +15,6 @@ #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/ObjectCache.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" -#include "MCJITTestBase.h" #include "gtest/gtest.h" using namespace llvm; @@ -101,7 +100,7 @@ protected: void compileAndRun(int ExpectedRC = OriginalRC) { // This function shouldn't be called until after SetUp. - ASSERT_TRUE(TheJIT.isValid()); + ASSERT_TRUE(bool(TheJIT)); ASSERT_TRUE(0 != Main); // We may be using a null cache, so ensure compilation is valid. @@ -122,7 +121,7 @@ protected: TEST_F(MCJITObjectCacheTest, SetNullObjectCache) { SKIP_UNSUPPORTED_PLATFORM; - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(NULL); @@ -133,12 +132,12 @@ TEST_F(MCJITObjectCacheTest, SetNullObjectCache) { TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<TestObjectCache> Cache(new TestObjectCache); + std::unique_ptr<TestObjectCache> Cache(new TestObjectCache); // Save a copy of the module pointer before handing it off to MCJIT. const Module * SavedModulePointer = M.get(); - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); @@ -162,10 +161,10 @@ TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<TestObjectCache> Cache(new TestObjectCache); + std::unique_ptr<TestObjectCache> Cache(new TestObjectCache); // Compile this module with an MCJIT engine - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); TheJIT->finalizeObject(); @@ -182,7 +181,7 @@ TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { const Module * SecondModulePointer = M.get(); // Create a new MCJIT instance to load this module then execute it. - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); compileAndRun(); @@ -196,10 +195,10 @@ TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr<TestObjectCache> Cache(new TestObjectCache); + std::unique_ptr<TestObjectCache> Cache(new TestObjectCache); // Compile this module with an MCJIT engine - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); TheJIT->finalizeObject(); @@ -217,7 +216,7 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { const Module * SecondModulePointer = M.get(); // Create a new MCJIT instance to load this module then execute it. - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); // Verify that our object cache does not contain the module yet. diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp index fab8155..a439508 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp @@ -49,7 +49,7 @@ TEST_F(MCJITTest, global_variable) { int initialValue = 5; GlobalValue *Global = insertGlobalInt32(M.get(), "test_global", initialValue); - createJIT(M.take()); + createJIT(M.release()); void *globalPtr = TheJIT->getPointerToGlobal(Global); EXPECT_TRUE(0 != globalPtr) << "Unable to get pointer to global value from JIT"; @@ -62,7 +62,7 @@ TEST_F(MCJITTest, add_function) { SKIP_UNSUPPORTED_PLATFORM; Function *F = insertAddFunction(M.get()); - createJIT(M.take()); + createJIT(M.release()); uint64_t addPtr = TheJIT->getFunctionAddress(F->getName().str()); EXPECT_TRUE(0 != addPtr) << "Unable to get pointer to function from JIT"; @@ -83,7 +83,7 @@ TEST_F(MCJITTest, run_main) { int rc = 6; Function *Main = insertMainFunction(M.get(), 6); - createJIT(M.take()); + createJIT(M.release()); uint64_t ptr = TheJIT->getFunctionAddress(Main->getName().str()); EXPECT_TRUE(0 != ptr) << "Unable to get pointer to main() from JIT"; @@ -104,7 +104,7 @@ TEST_F(MCJITTest, return_global) { Value *ReadGlobal = Builder.CreateLoad(GV); endFunctionWithRet(ReturnGlobal, ReadGlobal); - createJIT(M.take()); + createJIT(M.release()); uint64_t rgvPtr = TheJIT->getFunctionAddress(ReturnGlobal->getName().str()); EXPECT_TRUE(0 != rgvPtr); @@ -175,7 +175,7 @@ TEST_F(MCJITTest, multiple_functions) { Inner = Outer; } - createJIT(M.take()); + createJIT(M.release()); uint64_t ptr = TheJIT->getFunctionAddress(Outer->getName().str()); EXPECT_TRUE(0 != ptr) << "Unable to get pointer to outer function from JIT"; diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h b/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h index 7b6e39f..a48c071 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h +++ b/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h @@ -71,10 +71,15 @@ protected: /// Returns true if the host OS is known to support MCJIT bool OSSupportsMCJIT() { Triple Host(HostTriple); + + if (std::find(UnsupportedEnvironments.begin(), UnsupportedEnvironments.end(), + Host.getEnvironment()) != UnsupportedEnvironments.end()) + return false; + if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS()) - == UnsupportedOSs.end()) { + == UnsupportedOSs.end()) return true; - } + return false; } @@ -83,6 +88,7 @@ protected: SmallVector<Triple::ArchType, 1> HasSubArchs; SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory SmallVector<Triple::OSType, 4> UnsupportedOSs; + SmallVector<Triple::EnvironmentType, 1> UnsupportedEnvironments; }; } // namespace llvm diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h index b42a9c0..25de312 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h +++ b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h @@ -17,6 +17,7 @@ #ifndef MCJIT_TEST_BASE_H #define MCJIT_TEST_BASE_H +#include "MCJITTestAPICommon.h" #include "llvm/Config/config.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -26,7 +27,6 @@ #include "llvm/IR/Module.h" #include "llvm/IR/TypeBuilder.h" #include "llvm/Support/CodeGen.h" -#include "MCJITTestAPICommon.h" namespace llvm { @@ -185,11 +185,9 @@ protected: // Populates Modules A and B: // Module A { Extern FB1, Function FA which calls FB1 }, // Module B { Extern FA, Function FB1, Function FB2 which calls FA }, - void createCrossModuleRecursiveCase(OwningPtr<Module> &A, - Function *&FA, - OwningPtr<Module> &B, - Function *&FB1, - Function *&FB2) { + void createCrossModuleRecursiveCase(std::unique_ptr<Module> &A, Function *&FA, + std::unique_ptr<Module> &B, + Function *&FB1, Function *&FB2) { // Define FB1 in B. B.reset(createEmptyModule("B")); FB1 = insertAccumulateFunction(B.get(), 0, "FB1"); @@ -211,12 +209,10 @@ protected: // Module A { Function FA }, // Module B { Extern FA, Function FB which calls FA }, // Module C { Extern FB, Function FC which calls FB }, - void createThreeModuleChainedCallsCase(OwningPtr<Module> &A, - Function *&FA, - OwningPtr<Module> &B, - Function *&FB, - OwningPtr<Module> &C, - Function *&FC) { + void + createThreeModuleChainedCallsCase(std::unique_ptr<Module> &A, Function *&FA, + std::unique_ptr<Module> &B, Function *&FB, + std::unique_ptr<Module> &C, Function *&FC) { A.reset(createEmptyModule("A")); FA = insertAddFunction(A.get()); @@ -233,8 +229,8 @@ protected: // Module A { Function FA }, // Populates Modules A and B: // Module B { Function FB } - void createTwoModuleCase(OwningPtr<Module> &A, Function *&FA, - OwningPtr<Module> &B, Function *&FB) { + void createTwoModuleCase(std::unique_ptr<Module> &A, Function *&FA, + std::unique_ptr<Module> &B, Function *&FB) { A.reset(createEmptyModule("A")); FA = insertAddFunction(A.get()); @@ -244,8 +240,8 @@ protected: // Module A { Function FA }, // Module B { Extern FA, Function FB which calls FA } - void createTwoModuleExternCase(OwningPtr<Module> &A, Function *&FA, - OwningPtr<Module> &B, Function *&FB) { + void createTwoModuleExternCase(std::unique_ptr<Module> &A, Function *&FA, + std::unique_ptr<Module> &B, Function *&FB) { A.reset(createEmptyModule("A")); FA = insertAddFunction(A.get()); @@ -258,12 +254,9 @@ protected: // Module A { Function FA }, // Module B { Extern FA, Function FB which calls FA }, // Module C { Extern FB, Function FC which calls FA }, - void createThreeModuleCase(OwningPtr<Module> &A, - Function *&FA, - OwningPtr<Module> &B, - Function *&FB, - OwningPtr<Module> &C, - Function *&FC) { + void createThreeModuleCase(std::unique_ptr<Module> &A, Function *&FA, + std::unique_ptr<Module> &B, Function *&FB, + std::unique_ptr<Module> &C, Function *&FC) { A.reset(createEmptyModule("A")); FA = insertAddFunction(A.get()); @@ -311,6 +304,8 @@ protected: // should be kept in sync. UnsupportedOSs.push_back(Triple::Cygwin); UnsupportedOSs.push_back(Triple::Darwin); + + UnsupportedEnvironments.push_back(Triple::Cygnus); } void createJIT(Module *M) { @@ -342,10 +337,10 @@ protected: CodeModel::Model CodeModel; StringRef MArch; SmallVector<std::string, 1> MAttrs; - OwningPtr<ExecutionEngine> TheJIT; + std::unique_ptr<ExecutionEngine> TheJIT; RTDyldMemoryManager *MM; - OwningPtr<Module> M; + std::unique_ptr<Module> M; }; } // namespace llvm diff --git a/unittests/ExecutionEngine/MCJIT/Makefile b/unittests/ExecutionEngine/MCJIT/Makefile index 33b043b..c4dd740 100644 --- a/unittests/ExecutionEngine/MCJIT/Makefile +++ b/unittests/ExecutionEngine/MCJIT/Makefile @@ -9,7 +9,7 @@ LEVEL = ../../.. TESTNAME = MCJIT -LINK_COMPONENTS := core mcjit native support +LINK_COMPONENTS := core ipo jit mcjit native support include $(LEVEL)/Makefile.config include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest |