diff options
Diffstat (limited to 'unittests/ExecutionEngine')
-rw-r--r-- | unittests/ExecutionEngine/CMakeLists.txt | 4 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp | 32 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp | 19 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp | 4 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITTestBase.h | 4 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Makefile | 4 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Orc/CMakeLists.txt | 8 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp | 30 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Orc/Makefile | 16 |
10 files changed, 117 insertions, 5 deletions
diff --git a/unittests/ExecutionEngine/CMakeLists.txt b/unittests/ExecutionEngine/CMakeLists.txt index 783c9b5..302de99 100644 --- a/unittests/ExecutionEngine/CMakeLists.txt +++ b/unittests/ExecutionEngine/CMakeLists.txt @@ -3,6 +3,8 @@ set(LLVM_LINK_COMPONENTS ExecutionEngine Interpreter MC + OrcJIT + RuntimeDyld Support ) @@ -10,6 +12,8 @@ add_llvm_unittest(ExecutionEngineTests ExecutionEngineTest.cpp ) +add_subdirectory(Orc) + # Include MCJIT tests only if native arch is a built JIT target. list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" build_idx) list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" jit_idx) diff --git a/unittests/ExecutionEngine/MCJIT/CMakeLists.txt b/unittests/ExecutionEngine/MCJIT/CMakeLists.txt index b10cbb4..e29787f 100644 --- a/unittests/ExecutionEngine/MCJIT/CMakeLists.txt +++ b/unittests/ExecutionEngine/MCJIT/CMakeLists.txt @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS IPO MC MCJIT + RuntimeDyld ScalarOpts Support Target diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index c80b88b..f2a3000 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -347,6 +347,38 @@ TEST_F(MCJITCAPITest, simple_function) { EXPECT_EQ(42, functionPointer.usable()); } +TEST_F(MCJITCAPITest, gva) { + SKIP_UNSUPPORTED_PLATFORM; + + Module = LLVMModuleCreateWithName("simple_module"); + LLVMSetTarget(Module, HostTriple.c_str()); + LLVMValueRef GlobalVar = LLVMAddGlobal(Module, LLVMInt32Type(), "simple_value"); + LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0)); + + buildMCJITOptions(); + buildMCJITEngine(); + buildAndRunPasses(); + + uint64_t raw = LLVMGetGlobalValueAddress(Engine, "simple_value"); + int32_t *usable = (int32_t *) raw; + + EXPECT_EQ(42, *usable); +} + +TEST_F(MCJITCAPITest, gfa) { + SKIP_UNSUPPORTED_PLATFORM; + + buildSimpleFunction(); + buildMCJITOptions(); + buildMCJITEngine(); + buildAndRunPasses(); + + uint64_t raw = LLVMGetFunctionAddress(Engine, "simple_function"); + int (*usable)() = (int (*)()) raw; + + EXPECT_EQ(42, usable()); +} + TEST_F(MCJITCAPITest, custom_memory_manager) { SKIP_UNSUPPORTED_PLATFORM; diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp index b0d1bb3..da6e25a 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp @@ -392,4 +392,23 @@ TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case3) { ptr = TheJIT->getFunctionAddress(FB2->getName().str()); checkAccumulate(ptr); } + +// Test that FindFunctionNamed finds the definition of +// a function in the correct module. We check two functions +// in two different modules, to make sure that for at least +// one of them MCJIT had to ignore the extern declaration. +TEST_F(MCJITMultipleModuleTest, FindFunctionNamed_test) { + SKIP_UNSUPPORTED_PLATFORM; + + std::unique_ptr<Module> A, B; + Function *FA, *FB1, *FB2; + createCrossModuleRecursiveCase(A, FA, B, FB1, FB2); + + createJIT(std::move(A)); + TheJIT->addModule(std::move(B)); + + EXPECT_EQ(FA, TheJIT->FindFunctionNamed(FA->getName().data())); + EXPECT_EQ(FB1, TheJIT->FindFunctionNamed(FB1->getName().data())); +} + } diff --git a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 2736383..2e38dd8 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -163,7 +163,7 @@ TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { TheJIT.reset(); // Create a new memory manager. - MM = new SectionMemoryManager; + MM.reset(new SectionMemoryManager()); // Create a new module and save it. Use a different return code so we can // tell if MCJIT compiled this module or used the cache. @@ -197,7 +197,7 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { TheJIT.reset(); // Create a new memory manager. - MM = new SectionMemoryManager; + MM.reset(new SectionMemoryManager()); // Create a new module and save it. Use a different return code so we can // tell if MCJIT compiled this module or used the cache. Note that we use diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h index eea88bb..35af417 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h +++ b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h @@ -325,7 +325,7 @@ protected: EngineBuilder EB(std::move(M)); std::string Error; TheJIT.reset(EB.setEngineKind(EngineKind::JIT) - .setMCJITMemoryManager(MM) + .setMCJITMemoryManager(std::move(MM)) .setErrorStr(&Error) .setOptLevel(CodeGenOpt::None) .setCodeModel(CodeModel::JITDefault) @@ -344,7 +344,7 @@ protected: StringRef MArch; SmallVector<std::string, 1> MAttrs; std::unique_ptr<ExecutionEngine> TheJIT; - RTDyldMemoryManager *MM; + std::unique_ptr<RTDyldMemoryManager> MM; std::unique_ptr<Module> M; }; diff --git a/unittests/ExecutionEngine/Makefile b/unittests/ExecutionEngine/Makefile index 8ecb883..c19f8d6 100644 --- a/unittests/ExecutionEngine/Makefile +++ b/unittests/ExecutionEngine/Makefile @@ -13,8 +13,10 @@ LINK_COMPONENTS :=interpreter include $(LEVEL)/Makefile.config +PARALLEL_DIRS = Orc + ifeq ($(TARGET_HAS_JIT),1) - PARALLEL_DIRS = MCJIT + PARALLEL_DIRS += MCJIT endif include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/ExecutionEngine/Orc/CMakeLists.txt b/unittests/ExecutionEngine/Orc/CMakeLists.txt new file mode 100644 index 0000000..7bc13a1 --- /dev/null +++ b/unittests/ExecutionEngine/Orc/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + ) + +add_llvm_unittest(OrcJITTests + LazyEmittingLayerTest.cpp + ) diff --git a/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp new file mode 100644 index 0000000..b0ff127 --- /dev/null +++ b/unittests/ExecutionEngine/Orc/LazyEmittingLayerTest.cpp @@ -0,0 +1,30 @@ +//===- LazyEmittingLayerTest.cpp - Unit tests for the lazy emitting layer -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" +#include "gtest/gtest.h" + +namespace { + +struct MockBaseLayer { + typedef int ModuleSetHandleT; + ModuleSetHandleT addModuleSet(std::list<std::unique_ptr<llvm::Module>>, + std::unique_ptr<llvm::RTDyldMemoryManager> x) { + EXPECT_FALSE(x); + return 42; + } +}; + +TEST(LazyEmittingLayerTest, Empty) { + MockBaseLayer M; + llvm::orc::LazyEmittingLayer<MockBaseLayer> L(M); + L.addModuleSet(std::list<std::unique_ptr<llvm::Module>>(), nullptr); +} + +} diff --git a/unittests/ExecutionEngine/Orc/Makefile b/unittests/ExecutionEngine/Orc/Makefile new file mode 100644 index 0000000..c899728 --- /dev/null +++ b/unittests/ExecutionEngine/Orc/Makefile @@ -0,0 +1,16 @@ +##===- unittests/ExecutionEngine/Orc/Makefile --------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +TESTNAME = OrcJIT +LINK_COMPONENTS := core ipo mcjit orcjit native support + +include $(LEVEL)/Makefile.config +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest + |