2003-12-20 02:46:27 +01:00
|
|
|
//===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-12-20 02:46:27 +01:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-12-20 02:46:27 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-07-11 10:24:02 +02: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 02:46:27 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "JIT.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/ModuleProvider.h"
|
2009-01-16 08:02:28 +01:00
|
|
|
#include "llvm/Support/RegistryParser.h"
|
2008-05-23 22:40:06 +02:00
|
|
|
#include "llvm/Support/Streams.h"
|
2005-09-01 23:38:21 +02:00
|
|
|
#include "llvm/Target/SubtargetFeature.h"
|
2003-12-20 02:46:27 +01:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2004-07-11 06:02:06 +02:00
|
|
|
#include "llvm/Target/TargetMachineRegistry.h"
|
2003-12-20 02:46:27 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2007-10-17 23:28:48 +02:00
|
|
|
static cl::opt<const TargetMachineRegistry::entry*, false,
|
2009-01-16 08:02:28 +01:00
|
|
|
RegistryParser<TargetMachine> >
|
2004-07-11 06:02:06 +02:00
|
|
|
MArch("march", cl::desc("Architecture to generate assembly for:"));
|
2003-12-20 02:46:27 +01:00
|
|
|
|
2005-09-01 23:38:21 +02:00
|
|
|
static cl::opt<std::string>
|
2009-01-16 07:53:46 +01:00
|
|
|
MCPU("mcpu",
|
2005-10-24 00:39:01 +02:00
|
|
|
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
|
2005-09-01 23:38:21 +02:00
|
|
|
cl::value_desc("cpu-name"),
|
|
|
|
cl::init(""));
|
|
|
|
|
|
|
|
static cl::list<std::string>
|
2009-01-16 07:53:46 +01:00
|
|
|
MAttrs("mattr",
|
2005-09-01 23:38:21 +02:00
|
|
|
cl::CommaSeparated,
|
2005-10-24 00:39:01 +02:00
|
|
|
cl::desc("Target specific attributes (-mattr=help for details)"),
|
|
|
|
cl::value_desc("a1,+a2,-a3,..."));
|
2005-09-01 23:38:21 +02:00
|
|
|
|
2007-12-06 02:34:04 +01:00
|
|
|
/// createInternal - Create an return a new JIT compiler if there is one
|
|
|
|
/// available for the current target. Otherwise, return null.
|
2003-12-20 02:46:27 +01:00
|
|
|
///
|
2007-12-06 02:34:04 +01:00
|
|
|
ExecutionEngine *JIT::createJIT(ModuleProvider *MP, std::string *ErrorStr,
|
2009-04-30 01:29:43 +02:00
|
|
|
JITMemoryManager *JMM,
|
2009-07-08 23:59:57 +02:00
|
|
|
CodeGenOpt::Level OptLevel,
|
|
|
|
bool AllocateGVsWithCode) {
|
2007-10-17 23:28:48 +02:00
|
|
|
const TargetMachineRegistry::entry *TheArch = MArch;
|
2007-04-21 00:57:20 +02:00
|
|
|
if (TheArch == 0) {
|
2004-07-11 06:02:06 +02:00
|
|
|
std::string Error;
|
2007-04-21 00:57:20 +02:00
|
|
|
TheArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
|
|
|
|
if (TheArch == 0) {
|
2007-03-03 19:19:18 +01:00
|
|
|
if (ErrorStr)
|
|
|
|
*ErrorStr = Error;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-04-21 00:57:20 +02:00
|
|
|
} else if (TheArch->JITMatchQualityFn() == 0) {
|
2006-12-07 21:04:42 +01: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 02:46:27 +01:00
|
|
|
}
|
|
|
|
|
2005-09-01 23:38:21 +02:00
|
|
|
// Package up features to be passed to target/subtarget
|
|
|
|
std::string FeaturesStr;
|
2008-07-07 19:52:43 +02:00
|
|
|
if (!MCPU.empty() || !MAttrs.empty()) {
|
2005-09-01 23:38:21 +02:00
|
|
|
SubtargetFeatures Features;
|
|
|
|
Features.setCPU(MCPU);
|
|
|
|
for (unsigned i = 0; i != MAttrs.size(); ++i)
|
|
|
|
Features.AddFeature(MAttrs[i]);
|
|
|
|
FeaturesStr = Features.getString();
|
|
|
|
}
|
|
|
|
|
2003-12-20 02:46:27 +01:00
|
|
|
// Allocate a target...
|
2007-04-21 00:57:20 +02:00
|
|
|
TargetMachine *Target = TheArch->CtorFn(*MP->getModule(), FeaturesStr);
|
2003-12-20 02:46:27 +01: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-07-08 23:59:57 +02:00
|
|
|
return new JIT(MP, *Target, *TJ, JMM, OptLevel, AllocateGVsWithCode);
|
2007-03-03 19:19:18 +01:00
|
|
|
|
|
|
|
if (ErrorStr)
|
|
|
|
*ErrorStr = "target does not support JIT code generation";
|
2003-12-20 02:46:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|