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
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file 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"
|
2009-01-16 07:02:28 +00:00
|
|
|
#include "llvm/Support/RegistryParser.h"
|
2008-05-23 20:40:06 +00:00
|
|
|
#include "llvm/Support/Streams.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,
|
2009-01-16 07:02:28 +00:00
|
|
|
RegistryParser<TargetMachine> >
|
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>
|
2009-01-16 06:53:46 +00:00
|
|
|
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>
|
2009-01-16 06:53:46 +00:00
|
|
|
MAttrs("mattr",
|
2005-09-01 21:38:21 +00:00
|
|
|
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,
|
2009-04-29 00:32:19 +00:00
|
|
|
JITMemoryManager *JMM, unsigned OptLevel) {
|
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;
|
2008-07-07 17:52:43 +00:00
|
|
|
if (!MCPU.empty() || !MAttrs.empty()) {
|
2005-09-01 21:38:21 +00:00
|
|
|
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())
|
2009-04-29 00:32:19 +00:00
|
|
|
return new JIT(MP, *Target, *TJ, JMM, OptLevel);
|
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;
|
|
|
|
}
|