mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
ExecutionEngine: refactor interface
The OptLevel is now redundant with the TargetMachine*. And selectTarget() isn't really JIT-specific and could probably get refactored into one of the lower level libraries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146355 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d93e4c3496
commit
9ea47179e6
@ -42,6 +42,7 @@ class MachineCodeInfo;
|
||||
class Module;
|
||||
class MutexGuard;
|
||||
class TargetData;
|
||||
class Triple;
|
||||
class Type;
|
||||
|
||||
/// \brief Helper class for helping synchronize access to the global address map
|
||||
@ -133,14 +134,12 @@ protected:
|
||||
Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM);
|
||||
static ExecutionEngine *(*MCJITCtor)(
|
||||
Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM);
|
||||
static ExecutionEngine *(*InterpCtor)(Module *M, std::string *ErrorStr);
|
||||
@ -584,7 +583,7 @@ public:
|
||||
|
||||
/// selectTarget - Pick a target either via -march or by guessing the native
|
||||
/// arch. Add any CPU features specified via -mcpu or -mattr.
|
||||
static TargetMachine *selectTarget(Module *M,
|
||||
static TargetMachine *selectTarget(const Triple &TargetTriple,
|
||||
StringRef MArch,
|
||||
StringRef MCPU,
|
||||
const SmallVectorImpl<std::string>& MAttrs,
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include <cmath>
|
||||
@ -41,14 +42,12 @@ ExecutionEngine *(*ExecutionEngine::JITCtor)(
|
||||
Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM) = 0;
|
||||
ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
|
||||
Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM) = 0;
|
||||
ExecutionEngine *(*ExecutionEngine::InterpCtor)(Module *M,
|
||||
@ -436,13 +435,14 @@ ExecutionEngine *ExecutionEngine::createJIT(Module *M,
|
||||
StringRef MCPU = "";
|
||||
SmallVector<std::string, 1> MAttrs;
|
||||
|
||||
Triple TT(M->getTargetTriple());
|
||||
// TODO: permit custom TargetOptions here
|
||||
TargetMachine *TM =
|
||||
EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, TargetOptions(), RM,
|
||||
EngineBuilder::selectTarget(TT, MArch, MCPU, MAttrs, TargetOptions(), RM,
|
||||
CMM, OL, ErrorStr);
|
||||
if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
|
||||
|
||||
return ExecutionEngine::JITCtor(M, ErrorStr, JMM, OL, GVsWithCode, TM);
|
||||
return ExecutionEngine::JITCtor(M, ErrorStr, JMM, GVsWithCode, TM);
|
||||
}
|
||||
|
||||
ExecutionEngine *EngineBuilder::create() {
|
||||
@ -467,18 +467,25 @@ ExecutionEngine *EngineBuilder::create() {
|
||||
// Unless the interpreter was explicitly selected or the JIT is not linked,
|
||||
// try making a JIT.
|
||||
if (WhichEngine & EngineKind::JIT) {
|
||||
if (TargetMachine *TM = EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs,
|
||||
Triple TT(M->getTargetTriple());
|
||||
if (TargetMachine *TM = EngineBuilder::selectTarget(TT, MArch, MCPU, MAttrs,
|
||||
Options,
|
||||
RelocModel, CMModel,
|
||||
OptLevel, ErrorStr)) {
|
||||
if (!TM->getTarget().hasJIT()) {
|
||||
errs() << "WARNING: This target JIT is not designed for the host"
|
||||
<< " you are running. If bad things happen, please choose"
|
||||
<< " a different -march switch.\n";
|
||||
}
|
||||
|
||||
if (UseMCJIT && ExecutionEngine::MCJITCtor) {
|
||||
ExecutionEngine *EE =
|
||||
ExecutionEngine::MCJITCtor(M, ErrorStr, JMM, OptLevel,
|
||||
ExecutionEngine::MCJITCtor(M, ErrorStr, JMM,
|
||||
AllocateGVsWithCode, TM);
|
||||
if (EE) return EE;
|
||||
} else if (ExecutionEngine::JITCtor) {
|
||||
ExecutionEngine *EE =
|
||||
ExecutionEngine::JITCtor(M, ErrorStr, JMM, OptLevel,
|
||||
ExecutionEngine::JITCtor(M, ErrorStr, JMM,
|
||||
AllocateGVsWithCode, TM);
|
||||
if (EE) return EE;
|
||||
}
|
||||
|
@ -206,7 +206,6 @@ void DarwinRegisterFrame(void* FrameBegin) {
|
||||
ExecutionEngine *JIT::createJIT(Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM) {
|
||||
// Try to register the program as a source of symbols to resolve against.
|
||||
@ -216,7 +215,7 @@ ExecutionEngine *JIT::createJIT(Module *M,
|
||||
|
||||
// If the target supports JIT code generation, create the JIT.
|
||||
if (TargetJITInfo *TJ = TM->getJITInfo()) {
|
||||
return new JIT(M, *TM, *TJ, JMM, OptLevel, GVsWithCode);
|
||||
return new JIT(M, *TM, *TJ, JMM, GVsWithCode);
|
||||
} else {
|
||||
if (ErrorStr)
|
||||
*ErrorStr = "target does not support JIT code generation";
|
||||
@ -268,7 +267,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
|
||||
JITMemoryManager *JMM, CodeGenOpt::Level OptLevel, bool GVsWithCode)
|
||||
JITMemoryManager *JMM, bool GVsWithCode)
|
||||
: ExecutionEngine(M), TM(tm), TJI(tji), AllocateGVsWithCode(GVsWithCode),
|
||||
isAlreadyCodeGenerating(false) {
|
||||
setTargetData(TM.getTargetData());
|
||||
|
@ -78,8 +78,7 @@ class JIT : public ExecutionEngine {
|
||||
|
||||
|
||||
JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
|
||||
JITMemoryManager *JMM, CodeGenOpt::Level OptLevel,
|
||||
bool AllocateGVsWithCode);
|
||||
JITMemoryManager *JMM, bool AllocateGVsWithCode);
|
||||
public:
|
||||
~JIT();
|
||||
|
||||
@ -185,7 +184,6 @@ public:
|
||||
static ExecutionEngine *createJIT(Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM);
|
||||
|
||||
|
@ -36,7 +36,6 @@ extern "C" void LLVMLinkInMCJIT() {
|
||||
ExecutionEngine *MCJIT::createJIT(Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM) {
|
||||
// Try to register the program as a source of symbols to resolve against.
|
||||
@ -46,8 +45,7 @@ ExecutionEngine *MCJIT::createJIT(Module *M,
|
||||
|
||||
// If the target supports JIT code generation, create the JIT.
|
||||
if (TargetJITInfo *TJ = TM->getJITInfo())
|
||||
return new MCJIT(M, TM, *TJ, new MCJITMemoryManager(JMM, M), OptLevel,
|
||||
GVsWithCode);
|
||||
return new MCJIT(M, TM, *TJ, new MCJITMemoryManager(JMM, M), GVsWithCode);
|
||||
|
||||
if (ErrorStr)
|
||||
*ErrorStr = "target does not support JIT code generation";
|
||||
@ -55,8 +53,7 @@ ExecutionEngine *MCJIT::createJIT(Module *M,
|
||||
}
|
||||
|
||||
MCJIT::MCJIT(Module *m, TargetMachine *tm, TargetJITInfo &tji,
|
||||
RTDyldMemoryManager *MM, CodeGenOpt::Level OptLevel,
|
||||
bool AllocateGVsWithCode)
|
||||
RTDyldMemoryManager *MM, bool AllocateGVsWithCode)
|
||||
: ExecutionEngine(m), TM(tm), MemMgr(MM), M(m), OS(Buffer), Dyld(MM) {
|
||||
|
||||
setTargetData(TM->getTargetData());
|
||||
|
@ -24,8 +24,7 @@ namespace llvm {
|
||||
|
||||
class MCJIT : public ExecutionEngine {
|
||||
MCJIT(Module *M, TargetMachine *tm, TargetJITInfo &tji,
|
||||
RTDyldMemoryManager *MemMgr, CodeGenOpt::Level OptLevel,
|
||||
bool AllocateGVsWithCode);
|
||||
RTDyldMemoryManager *MemMgr, bool AllocateGVsWithCode);
|
||||
|
||||
TargetMachine *TM;
|
||||
MCContext *Ctx;
|
||||
@ -79,7 +78,6 @@ public:
|
||||
static ExecutionEngine *createJIT(Module *M,
|
||||
std::string *ErrorStr,
|
||||
JITMemoryManager *JMM,
|
||||
CodeGenOpt::Level OptLevel,
|
||||
bool GVsWithCode,
|
||||
TargetMachine *TM);
|
||||
|
||||
|
@ -7,26 +7,26 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This just asks the TargetRegistry for the appropriate JIT to use, and allows
|
||||
// the user to specify a specific one on the commandline with -march=x. Clients
|
||||
// should initialize targets prior to calling createJIT.
|
||||
// This just asks the TargetRegistry for the appropriate target to use, and
|
||||
// allows the user to specify a specific one on the commandline with -march=x,
|
||||
// -mcpu=y, and -mattr=a,-b,+c. Clients should initialize targets prior to
|
||||
// calling selectTarget().
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/MC/SubtargetFeature.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
/// selectTarget - Pick a target either via -march or by guessing the native
|
||||
/// arch. Add any CPU features specified via -mcpu or -mattr.
|
||||
TargetMachine *EngineBuilder::selectTarget(Module *Mod,
|
||||
TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
|
||||
StringRef MArch,
|
||||
StringRef MCPU,
|
||||
const SmallVectorImpl<std::string>& MAttrs,
|
||||
@ -35,7 +35,7 @@ TargetMachine *EngineBuilder::selectTarget(Module *Mod,
|
||||
CodeModel::Model CM,
|
||||
CodeGenOpt::Level OL,
|
||||
std::string *ErrorStr) {
|
||||
Triple TheTriple(Mod->getTargetTriple());
|
||||
Triple TheTriple(TargetTriple);
|
||||
if (TheTriple.getTriple().empty())
|
||||
TheTriple.setTriple(sys::getDefaultTargetTriple());
|
||||
|
||||
@ -57,7 +57,7 @@ TargetMachine *EngineBuilder::selectTarget(Module *Mod,
|
||||
}
|
||||
|
||||
// Adjust the triple to match (if known), otherwise stick with the
|
||||
// module/host triple.
|
||||
// requested/host triple.
|
||||
Triple::ArchType Type = Triple::getArchTypeForLLVMName(MArch);
|
||||
if (Type != Triple::UnknownArch)
|
||||
TheTriple.setArch(Type);
|
||||
@ -71,12 +71,6 @@ TargetMachine *EngineBuilder::selectTarget(Module *Mod,
|
||||
}
|
||||
}
|
||||
|
||||
if (!TheTarget->hasJIT()) {
|
||||
errs() << "WARNING: This target JIT is not designed for the host you are"
|
||||
<< " running. If bad things happen, please choose a different "
|
||||
<< "-march switch.\n";
|
||||
}
|
||||
|
||||
// Package up features to be passed to target/subtarget
|
||||
std::string FeaturesStr;
|
||||
if (!MAttrs.empty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user