diff options
author | Filip Pizlo <fpizlo@apple.com> | 2013-05-21 20:03:01 +0000 |
---|---|---|
committer | Filip Pizlo <fpizlo@apple.com> | 2013-05-21 20:03:01 +0000 |
commit | 1441bf7a41b50075cf761cbc794ce3fd0b5762fc (patch) | |
tree | 7fab8692dbd8b536525b99af03b9653a328e0b3a /unittests | |
parent | 52755c472a738e48a9687240368e4c1f78c45711 (diff) | |
download | llvm-1441bf7a41b50075cf761cbc794ce3fd0b5762fc.tar.gz llvm-1441bf7a41b50075cf761cbc794ce3fd0b5762fc.tar.bz2 llvm-1441bf7a41b50075cf761cbc794ce3fd0b5762fc.tar.xz |
Roll out r182407 and r182408 because they broke builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182409 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp | 163 |
1 files changed, 38 insertions, 125 deletions
diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index c434a7c0b2..e49af05a23 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -17,46 +17,12 @@ #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Target.h" #include "llvm-c/Transforms/Scalar.h" -#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/Support/Host.h" #include "MCJITTestAPICommon.h" #include "gtest/gtest.h" using namespace llvm; -static bool didCallAllocateCodeSection; - -static uint8_t *roundTripAllocateCodeSection(void *object, uintptr_t size, - unsigned alignment, - unsigned sectionID) { - didCallAllocateCodeSection = true; - return static_cast<SectionMemoryManager*>(object)->allocateCodeSection( - size, alignment, sectionID); -} - -static uint8_t *roundTripAllocateDataSection(void *object, uintptr_t size, - unsigned alignment, - unsigned sectionID, - LLVMBool isReadOnly) { - return static_cast<SectionMemoryManager*>(object)->allocateDataSection( - size, alignment, sectionID, isReadOnly); -} - -static LLVMBool roundTripFinalizeMemory(void *object, char **errMsg) { - std::string errMsgString; - bool result = - static_cast<SectionMemoryManager*>(object)->finalizeMemory(&errMsgString); - if (result) { - *errMsg = LLVMCreateMessage(errMsgString.c_str()); - return 1; - } - return 0; -} - -static void roundTripDestroy(void *object) { - delete static_cast<SectionMemoryManager*>(object); -} - class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon { protected: MCJITCAPITest() { @@ -80,113 +46,60 @@ protected: // that they will fail the MCJIT C API tests. UnsupportedOSs.push_back(Triple::Cygwin); } +}; + +TEST_F(MCJITCAPITest, simple_function) { + SKIP_UNSUPPORTED_PLATFORM; - virtual void SetUp() { - didCallAllocateCodeSection = false; - Module = 0; - Function = 0; - Engine = 0; - Error = 0; - } - - virtual void TearDown() { - if (Engine) - LLVMDisposeExecutionEngine(Engine); - else if (Module) - LLVMDisposeModule(Module); - } + char *error = 0; - void buildSimpleFunction() { - Module = LLVMModuleCreateWithName("simple_module"); - - LLVMSetTarget(Module, HostTriple.c_str()); - - Function = LLVMAddFunction( - Module, "simple_function", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); - LLVMSetFunctionCallConv(Function, LLVMCCallConv); - - LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry"); - LLVMBuilderRef builder = LLVMCreateBuilder(); - LLVMPositionBuilderAtEnd(builder, entry); - LLVMBuildRet(builder, LLVMConstInt(LLVMInt32Type(), 42, 0)); - - LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error); - LLVMDisposeMessage(Error); - - LLVMDisposeBuilder(builder); - } + // Creates a function that returns 42, compiles it, and runs it. - void buildMCJITOptions() { - LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options)); - Options.OptLevel = 2; - - // Just ensure that this field still exists. - Options.NoFramePointerElim = false; - } + LLVMModuleRef module = LLVMModuleCreateWithName("simple_module"); + + LLVMSetTarget(module, HostTriple.c_str()); - void useRoundTripSectionMemoryManager() { - Options.MCJMM = LLVMCreateSimpleMCJITMemoryManager( - new SectionMemoryManager(), - roundTripAllocateCodeSection, - roundTripAllocateDataSection, - roundTripFinalizeMemory, - roundTripDestroy); - } + LLVMValueRef function = LLVMAddFunction( + module, "simple_function", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + LLVMSetFunctionCallConv(function, LLVMCCallConv); - void buildMCJITEngine() { - ASSERT_EQ( - 0, LLVMCreateMCJITCompilerForModule(&Engine, Module, &Options, - sizeof(Options), &Error)); - } + LLVMBasicBlockRef entry = LLVMAppendBasicBlock(function, "entry"); + LLVMBuilderRef builder = LLVMCreateBuilder(); + LLVMPositionBuilderAtEnd(builder, entry); + LLVMBuildRet(builder, LLVMConstInt(LLVMInt32Type(), 42, 0)); - void buildAndRunPasses() { - LLVMPassManagerRef pass = LLVMCreatePassManager(); - LLVMAddTargetData(LLVMGetExecutionEngineTargetData(Engine), pass); - LLVMAddConstantPropagationPass(pass); - LLVMAddInstructionCombiningPass(pass); - LLVMRunPassManager(pass, Module); - LLVMDisposePassManager(pass); - } + LLVMVerifyModule(module, LLVMAbortProcessAction, &error); + LLVMDisposeMessage(error); - LLVMModuleRef Module; - LLVMValueRef Function; - LLVMMCJITCompilerOptions Options; - LLVMExecutionEngineRef Engine; - char *Error; -}; - -TEST_F(MCJITCAPITest, simple_function) { - SKIP_UNSUPPORTED_PLATFORM; + LLVMDisposeBuilder(builder); - buildSimpleFunction(); - buildMCJITOptions(); - buildMCJITEngine(); - buildAndRunPasses(); + LLVMMCJITCompilerOptions options; + LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); + options.OptLevel = 2; - union { - void *raw; - int (*usable)(); - } functionPointer; - functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function); + // Just ensure that this field still exists. + options.NoFramePointerElim = false; - EXPECT_EQ(42, functionPointer.usable()); -} - -TEST_F(MCJITCAPITest, custom_memory_manager) { - SKIP_UNSUPPORTED_PLATFORM; + LLVMExecutionEngineRef engine; + ASSERT_EQ( + 0, LLVMCreateMCJITCompilerForModule(&engine, module, &options, + sizeof(options), &error)); - buildSimpleFunction(); - buildMCJITOptions(); - useRoundTripSectionMemoryManager(); - buildMCJITEngine(); - buildAndRunPasses(); + LLVMPassManagerRef pass = LLVMCreatePassManager(); + LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass); + LLVMAddConstantPropagationPass(pass); + LLVMAddInstructionCombiningPass(pass); + LLVMRunPassManager(pass, module); + LLVMDisposePassManager(pass); union { void *raw; int (*usable)(); } functionPointer; - functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function); + functionPointer.raw = LLVMGetPointerToGlobal(engine, function); EXPECT_EQ(42, functionPointer.usable()); - EXPECT_TRUE(didCallAllocateCodeSection); + + LLVMDisposeExecutionEngine(engine); } + |