[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
//===-------- OrcMCJITReplacement.cpp - Orc-based MCJIT replacement -------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "OrcMCJITReplacement.h"
|
|
|
|
#include "llvm/ExecutionEngine/GenericValue.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static struct RegisterJIT {
|
2015-02-22 04:44:36 +08:00
|
|
|
RegisterJIT() { llvm::orc::OrcMCJITReplacement::Register(); }
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
} JITRegistrator;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-24 05:49:12 +08:00
|
|
|
extern "C" void LLVMLinkInOrcMCJITReplacement() {}
|
|
|
|
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
namespace llvm {
|
2015-02-22 04:44:36 +08:00
|
|
|
namespace orc {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
|
|
|
|
GenericValue
|
|
|
|
OrcMCJITReplacement::runFunction(Function *F,
|
2015-06-14 03:50:29 +08:00
|
|
|
ArrayRef<GenericValue> ArgValues) {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
assert(F && "Function *F was null at entry to run()");
|
|
|
|
|
|
|
|
void *FPtr = getPointerToFunction(F);
|
|
|
|
assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
|
|
|
|
FunctionType *FTy = F->getFunctionType();
|
|
|
|
Type *RetTy = FTy->getReturnType();
|
|
|
|
|
|
|
|
assert((FTy->getNumParams() == ArgValues.size() ||
|
|
|
|
(FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) &&
|
|
|
|
"Wrong number of arguments passed into function!");
|
|
|
|
assert(FTy->getNumParams() == ArgValues.size() &&
|
|
|
|
"This doesn't support passing arguments through varargs (yet)!");
|
|
|
|
|
|
|
|
// Handle some common cases first. These cases correspond to common `main'
|
|
|
|
// prototypes.
|
|
|
|
if (RetTy->isIntegerTy(32) || RetTy->isVoidTy()) {
|
|
|
|
switch (ArgValues.size()) {
|
|
|
|
case 3:
|
|
|
|
if (FTy->getParamType(0)->isIntegerTy(32) &&
|
|
|
|
FTy->getParamType(1)->isPointerTy() &&
|
|
|
|
FTy->getParamType(2)->isPointerTy()) {
|
|
|
|
int (*PF)(int, char **, const char **) =
|
|
|
|
(int (*)(int, char **, const char **))(intptr_t)FPtr;
|
|
|
|
|
|
|
|
// Call the function.
|
|
|
|
GenericValue rv;
|
|
|
|
rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
|
|
|
|
(char **)GVTOP(ArgValues[1]),
|
|
|
|
(const char **)GVTOP(ArgValues[2])));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (FTy->getParamType(0)->isIntegerTy(32) &&
|
|
|
|
FTy->getParamType(1)->isPointerTy()) {
|
|
|
|
int (*PF)(int, char **) = (int (*)(int, char **))(intptr_t)FPtr;
|
|
|
|
|
|
|
|
// Call the function.
|
|
|
|
GenericValue rv;
|
|
|
|
rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
|
|
|
|
(char **)GVTOP(ArgValues[1])));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (FTy->getNumParams() == 1 && FTy->getParamType(0)->isIntegerTy(32)) {
|
|
|
|
GenericValue rv;
|
|
|
|
int (*PF)(int) = (int (*)(int))(intptr_t)FPtr;
|
|
|
|
rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue()));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle cases where no arguments are passed first.
|
|
|
|
if (ArgValues.empty()) {
|
|
|
|
GenericValue rv;
|
|
|
|
switch (RetTy->getTypeID()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown return type for function call!");
|
|
|
|
case Type::IntegerTyID: {
|
|
|
|
unsigned BitWidth = cast<IntegerType>(RetTy)->getBitWidth();
|
|
|
|
if (BitWidth == 1)
|
|
|
|
rv.IntVal = APInt(BitWidth, ((bool (*)())(intptr_t)FPtr)());
|
|
|
|
else if (BitWidth <= 8)
|
|
|
|
rv.IntVal = APInt(BitWidth, ((char (*)())(intptr_t)FPtr)());
|
|
|
|
else if (BitWidth <= 16)
|
|
|
|
rv.IntVal = APInt(BitWidth, ((short (*)())(intptr_t)FPtr)());
|
|
|
|
else if (BitWidth <= 32)
|
|
|
|
rv.IntVal = APInt(BitWidth, ((int (*)())(intptr_t)FPtr)());
|
|
|
|
else if (BitWidth <= 64)
|
|
|
|
rv.IntVal = APInt(BitWidth, ((int64_t (*)())(intptr_t)FPtr)());
|
|
|
|
else
|
|
|
|
llvm_unreachable("Integer types > 64 bits not supported");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
case Type::VoidTyID:
|
|
|
|
rv.IntVal = APInt(32, ((int (*)())(intptr_t)FPtr)());
|
|
|
|
return rv;
|
|
|
|
case Type::FloatTyID:
|
|
|
|
rv.FloatVal = ((float (*)())(intptr_t)FPtr)();
|
|
|
|
return rv;
|
|
|
|
case Type::DoubleTyID:
|
|
|
|
rv.DoubleVal = ((double (*)())(intptr_t)FPtr)();
|
|
|
|
return rv;
|
|
|
|
case Type::X86_FP80TyID:
|
|
|
|
case Type::FP128TyID:
|
|
|
|
case Type::PPC_FP128TyID:
|
|
|
|
llvm_unreachable("long double not supported yet");
|
|
|
|
case Type::PointerTyID:
|
|
|
|
return PTOGV(((void *(*)())(intptr_t)FPtr)());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Full-featured argument passing not supported yet!");
|
|
|
|
}
|
2015-02-22 04:44:36 +08:00
|
|
|
|
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|