aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ExecutionEngine/MCJIT
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ExecutionEngine/MCJIT')
-rw-r--r--unittests/ExecutionEngine/MCJIT/CMakeLists.txt13
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp239
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp9
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp86
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp23
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITTest.cpp10
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h10
-rw-r--r--unittests/ExecutionEngine/MCJIT/MCJITTestBase.h43
-rw-r--r--unittests/ExecutionEngine/MCJIT/Makefile2
9 files changed, 337 insertions, 98 deletions
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