2003-12-20 01:46:27 +00:00
|
|
|
//===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-12-20 01:46:27 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-12-20 01:46:27 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-07-11 08:24:02 +00:00
|
|
|
// This just asks the TargetMachineRegistry for the appropriate JIT to use, and
|
|
|
|
// allows the user to specify a specific one on the commandline with -march=x.
|
2003-12-20 01:46:27 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "JIT.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/ModuleProvider.h"
|
2005-09-01 21:38:21 +00:00
|
|
|
#include "llvm/Target/SubtargetFeature.h"
|
2003-12-20 01:46:27 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2004-07-11 04:02:06 +00:00
|
|
|
#include "llvm/Target/TargetMachineRegistry.h"
|
2003-12-20 01:46:27 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2007-10-17 21:28:48 +00:00
|
|
|
static cl::opt<const TargetMachineRegistry::entry*, false,
|
|
|
|
TargetMachineRegistry::Parser>
|
2004-07-11 04:02:06 +00:00
|
|
|
MArch("march", cl::desc("Architecture to generate assembly for:"));
|
2003-12-20 01:46:27 +00:00
|
|
|
|
2005-09-01 21:38:21 +00:00
|
|
|
static cl::opt<std::string>
|
|
|
|
MCPU("mcpu",
|
2005-10-23 22:39:01 +00:00
|
|
|
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
|
2005-09-01 21:38:21 +00:00
|
|
|
cl::value_desc("cpu-name"),
|
|
|
|
cl::init(""));
|
|
|
|
|
|
|
|
static cl::list<std::string>
|
|
|
|
MAttrs("mattr",
|
|
|
|
cl::CommaSeparated,
|
2005-10-23 22:39:01 +00:00
|
|
|
cl::desc("Target specific attributes (-mattr=help for details)"),
|
|
|
|
cl::value_desc("a1,+a2,-a3,..."));
|
2005-09-01 21:38:21 +00:00
|
|
|
|
2007-12-06 01:34:04 +00:00
|
|
|
/// createInternal - Create an return a new JIT compiler if there is one
|
|
|
|
/// available for the current target. Otherwise, return null.
|
2003-12-20 01:46:27 +00:00
|
|
|
///
|
2007-12-06 01:34:04 +00:00
|
|
|
ExecutionEngine *JIT::createJIT(ModuleProvider *MP, std::string *ErrorStr,
|
|
|
|
JITMemoryManager *JMM) {
|
2007-10-17 21:28:48 +00:00
|
|
|
const TargetMachineRegistry::entry *TheArch = MArch;
|
2007-04-20 22:57:20 +00:00
|
|
|
if (TheArch == 0) {
|
2004-07-11 04:02:06 +00:00
|
|
|
std::string Error;
|
2007-04-20 22:57:20 +00:00
|
|
|
TheArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
|
|
|
|
if (TheArch == 0) {
|
2007-03-03 18:19:18 +00:00
|
|
|
if (ErrorStr)
|
|
|
|
*ErrorStr = Error;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-04-20 22:57:20 +00:00
|
|
|
} else if (TheArch->JITMatchQualityFn() == 0) {
|
2006-12-07 20:04:42 +00:00
|
|
|
cerr << "WARNING: This target JIT is not designed for the host you are"
|
|
|
|
<< " running. If bad things happen, please choose a different "
|
|
|
|
<< "-march switch.\n";
|
2003-12-20 01:46:27 +00:00
|
|
|
}
|
|
|
|
|
2005-09-01 21:38:21 +00:00
|
|
|
// Package up features to be passed to target/subtarget
|
|
|
|
std::string FeaturesStr;
|
|
|
|
if (MCPU.size() || MAttrs.size()) {
|
|
|
|
SubtargetFeatures Features;
|
|
|
|
Features.setCPU(MCPU);
|
|
|
|
for (unsigned i = 0; i != MAttrs.size(); ++i)
|
|
|
|
Features.AddFeature(MAttrs[i]);
|
|
|
|
FeaturesStr = Features.getString();
|
|
|
|
}
|
|
|
|
|
2003-12-20 01:46:27 +00:00
|
|
|
// Allocate a target...
|
2007-04-20 22:57:20 +00:00
|
|
|
TargetMachine *Target = TheArch->CtorFn(*MP->getModule(), FeaturesStr);
|
2003-12-20 01:46:27 +00:00
|
|
|
assert(Target && "Could not allocate target machine!");
|
|
|
|
|
|
|
|
// If the target supports JIT code generation, return a new JIT now.
|
|
|
|
if (TargetJITInfo *TJ = Target->getJITInfo())
|
2007-12-06 01:34:04 +00:00
|
|
|
return new JIT(MP, *Target, *TJ, JMM);
|
2007-03-03 18:19:18 +00:00
|
|
|
|
|
|
|
if (ErrorStr)
|
|
|
|
*ErrorStr = "target does not support JIT code generation";
|
2003-12-20 01:46:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|