Skip to content

Commit

Permalink
Revert "Exposing MCJIT through C API"
Browse files Browse the repository at this point in the history
This reverts commit 8c31b29.

It looks like this commit broke some bots:

http://lab.llvm.org:8011/builders/llvm-ppc64-linux2/builds/5209

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180248 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Apr 25, 2013
1 parent 3d3cc32 commit 7467e5e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 249 deletions.
28 changes: 0 additions & 28 deletions include/llvm-c/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ extern "C" {
*/

void LLVMLinkInJIT(void);
void LLVMLinkInMCJIT(void);
void LLVMLinkInInterpreter(void);

typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef;
typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;

struct LLVMMCJITCompilerOptions {
unsigned OptLevel;
LLVMBool NoFramePointerElim;
};

/*===-- Operations on generic values --------------------------------------===*/

LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
Expand Down Expand Up @@ -81,28 +75,6 @@ LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
unsigned OptLevel,
char **OutError);

/**
* Create an MCJIT execution engine for a module, with the given options. It is
* the responsibility of the caller to ensure that all fields in Options up to
* the given SizeOfOptions are initialized. It is correct to pass a smaller value
* of SizeOfOptions that omits some fields, and it is also correct to set any
* field to zero. The canonical way of using this is:
*
* LLVMMCJITCompilerOptions options;
* memset(&options, 0, sizeof(options));
* ... fill in those options you care about
* LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options), &error);
*
* Note that this is also correct, though possibly suboptimal:
*
* LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
*/
LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
LLVMModuleRef M,
struct LLVMMCJITCompilerOptions *Options,
size_t SizeOfOptions,
char **OutError);

/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP,
Expand Down
48 changes: 0 additions & 48 deletions lib/ExecutionEngine/ExecutionEngineBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "llvm-c/ExecutionEngine.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/Support/ErrorHandling.h"
#include <cstring>

Expand Down Expand Up @@ -153,47 +152,6 @@ LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
return 1;
}

LLVMBool LLVMCreateMCJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
LLVMModuleRef M,
LLVMMCJITCompilerOptions *PassedOptions,
size_t SizeOfPassedOptions,
char **OutError) {
LLVMMCJITCompilerOptions options;
// If the user passed a larger sized options struct, then they were compiled
// against a newer LLVM. Tell them that something is wrong.
if (SizeOfPassedOptions > sizeof(options)) {
*OutError = strdup(
"Refusing to use options struct that is larger than my own; assuming LLVM "
"library mismatch.");
return 1;
}

// Defend against the user having an old version of the API by ensuring that
// any fields they didn't see are cleared. We must defend against fields being
// set to the bitwise equivalent of zero, and assume that this means "do the
// default" as if that option hadn't been available.
memset(&options, 0, sizeof(options));
memcpy(&options, PassedOptions, SizeOfPassedOptions);

TargetOptions targetOptions;
targetOptions.NoFramePointerElim = options.NoFramePointerElim;

std::string Error;
EngineBuilder builder(unwrap(M));
builder.setEngineKind(EngineKind::JIT)
.setErrorStr(&Error)
.setUseMCJIT(true)
.setOptLevel((CodeGenOpt::Level)options.OptLevel)
.setJITMemoryManager(new SectionMemoryManager())
.setTargetOptions(targetOptions);
if (ExecutionEngine *JIT = builder.create()) {
*OutJIT = wrap(JIT);
return 0;
}
*OutError = strdup(Error.c_str());
return 1;
}

LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP,
char **OutError) {
Expand Down Expand Up @@ -238,8 +196,6 @@ void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE) {
int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
unsigned ArgC, const char * const *ArgV,
const char * const *EnvP) {
unwrap(EE)->finalizeObject();

std::vector<std::string> ArgVec;
for (unsigned I = 0; I != ArgC; ++I)
ArgVec.push_back(ArgV[I]);
Expand All @@ -250,8 +206,6 @@ int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
unsigned NumArgs,
LLVMGenericValueRef *Args) {
unwrap(EE)->finalizeObject();

std::vector<GenericValue> ArgVec;
ArgVec.reserve(NumArgs);
for (unsigned I = 0; I != NumArgs; ++I)
Expand Down Expand Up @@ -314,7 +268,5 @@ void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
}

void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) {
unwrap(EE)->finalizeObject();

return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
}
1 change: 0 additions & 1 deletion unittests/ExecutionEngine/MCJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(LLVM_LINK_COMPONENTS

set(MCJITTestsSources
MCJITTest.cpp
MCJITCAPITest.cpp
MCJITMemoryManagerTest.cpp
MCJITObjectCacheTest.cpp
)
Expand Down
93 changes: 0 additions & 93 deletions unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h

This file was deleted.

50 changes: 48 additions & 2 deletions unittests/ExecutionEngine/MCJIT/MCJITTestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef MCJIT_TEST_BASE_H
#define MCJIT_TEST_BASE_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Config/config.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
Expand All @@ -26,11 +28,21 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/TypeBuilder.h"
#include "llvm/Support/CodeGen.h"
#include "MCJITTestAPICommon.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetSelect.h"

// Used to skip tests on unsupported architectures and operating systems.
// To skip a test, add this macro at the top of a test-case in a suite that
// inherits from MCJITTestBase. See MCJITTest.cpp for examples.
#define SKIP_UNSUPPORTED_PLATFORM \
do \
if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
return; \
while(0);

namespace llvm {

class MCJITTestBase : public MCJITTestAPICommon {
class MCJITTestBase {
protected:

MCJITTestBase()
Expand All @@ -40,7 +52,17 @@ class MCJITTestBase : public MCJITTestAPICommon {
, MArch("")
, Builder(Context)
, MM(new SectionMemoryManager)
, HostTriple(sys::getProcessTriple())
{
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();

#ifdef LLVM_ON_WIN32
// On Windows, generate ELF objects by specifying "-elf" in triple
HostTriple += "-elf";
#endif // LLVM_ON_WIN32
HostTriple = Triple::normalize(HostTriple);

// 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.
Expand All @@ -56,6 +78,26 @@ class MCJITTestBase : public MCJITTestAPICommon {
UnsupportedOSs.push_back(Triple::Darwin);
}

/// Returns true if the host architecture is known to support MCJIT
bool ArchSupportsMCJIT() {
Triple Host(HostTriple);
if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch())
== SupportedArchs.end()) {
return false;
}
return true;
}

/// Returns true if the host OS is known to support MCJIT
bool OSSupportsMCJIT() {
Triple Host(HostTriple);
if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS())
== UnsupportedOSs.end()) {
return true;
}
return false;
}

Module *createEmptyModule(StringRef Name) {
Module * M = new Module(Name, Context);
M->setTargetTriple(Triple::normalize(HostTriple));
Expand Down Expand Up @@ -190,6 +232,10 @@ class MCJITTestBase : public MCJITTestAPICommon {
IRBuilder<> Builder;
JITMemoryManager *MM;

std::string HostTriple;
SmallVector<Triple::ArchType, 4> SupportedArchs;
SmallVector<Triple::OSType, 4> UnsupportedOSs;

OwningPtr<Module> M;
};

Expand Down

0 comments on commit 7467e5e

Please sign in to comment.