mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-04 18:24:38 +00:00
CodeModel: It's now possible to create an MCJIT instance with any CodeModel you like. Previously it was only possible to create an MCJIT that used CodeModel::JITDefault. EnableFastISel: It's now possible to turn on the fast instruction selector. The CodeModel option required some trickery. The problem is that previously, we were ensuring future binary compatibility in the MCJITCompilerOptions by mandating that the user bzero's the options struct and passes the sizeof() that he saw; the bindings then bzero the remaining bits. This works great but assumes that the bitwise zero equivalent of any field is a sensible default value. But this is not the case for LLVMCodeModel, or its internal equivalent, llvm::CodeModel::Model. In both of those, the default for a JIT is CodeModel::JITDefault (or LLVMCodeModelJITDefault), which is not bitwise zero. Hence this change introduces LLVMInitializeMCJITCompilerOptions(), which will initialize the user's options struct with defaults. The user will use this in the same way that they would have previously used memset() or bzero(). MCJITCAPITest.cpp illustrates the change, as does the comment in ExecutionEngine.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180893 91177308-0d34-0410-b5e6-96231b3b80d8
96 lines
3.0 KiB
C++
96 lines
3.0 KiB
C++
//===- MCJITTest.cpp - Unit tests for the MCJIT ---------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This test suite verifies basic MCJIT functionality when invoked form the C
|
|
// API.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm-c/Analysis.h"
|
|
#include "llvm-c/Core.h"
|
|
#include "llvm-c/ExecutionEngine.h"
|
|
#include "llvm-c/Target.h"
|
|
#include "llvm-c/Transforms/Scalar.h"
|
|
#include "llvm/Support/Host.h"
|
|
#include "MCJITTestAPICommon.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
class MCJITCAPITest : public testing::Test, public MCJITTestAPICommon {
|
|
protected:
|
|
MCJITCAPITest() {
|
|
// The architectures below are known to be compatible with MCJIT as they
|
|
// are copied from test/ExecutionEngine/MCJIT/lit.local.cfg and should be
|
|
// kept in sync.
|
|
SupportedArchs.push_back(Triple::arm);
|
|
SupportedArchs.push_back(Triple::mips);
|
|
SupportedArchs.push_back(Triple::x86);
|
|
SupportedArchs.push_back(Triple::x86_64);
|
|
|
|
// The operating systems below are known to be sufficiently incompatible
|
|
// that they will fail the MCJIT C API tests.
|
|
UnsupportedOSs.push_back(Triple::Cygwin);
|
|
}
|
|
};
|
|
|
|
TEST_F(MCJITCAPITest, simple_function) {
|
|
SKIP_UNSUPPORTED_PLATFORM;
|
|
|
|
char *error = 0;
|
|
|
|
// Creates a function that returns 42, compiles it, and runs it.
|
|
|
|
LLVMModuleRef module = LLVMModuleCreateWithName("simple_module");
|
|
|
|
LLVMValueRef 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);
|
|
|
|
LLVMMCJITCompilerOptions options;
|
|
LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
|
|
options.OptLevel = 2;
|
|
|
|
// Just ensure that this field still exists.
|
|
options.NoFramePointerElim = false;
|
|
|
|
LLVMExecutionEngineRef engine;
|
|
ASSERT_EQ(
|
|
0, LLVMCreateMCJITCompilerForModule(&engine, module, &options,
|
|
sizeof(options), &error));
|
|
|
|
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);
|
|
|
|
EXPECT_EQ(42, functionPointer.usable());
|
|
|
|
LLVMDisposeExecutionEngine(engine);
|
|
}
|
|
|