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"
|
|
|
|
#include <iostream>
|
2003-12-20 01:46:27 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2004-07-11 04:02:06 +00:00
|
|
|
static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
|
|
|
|
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-09-02 19:27:43 +00:00
|
|
|
cl::desc("Target a specific cpu type (-mcpu=help for list of choices)"),
|
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-09-02 19:27:43 +00:00
|
|
|
cl::desc("Target specific attributes (-mattr=help for list of choices)"),
|
|
|
|
cl::value_desc("attr1,+attr2, ..., -attrN"));
|
2005-09-01 21:38:21 +00:00
|
|
|
|
2003-12-20 01:46:27 +00:00
|
|
|
/// create - Create an return a new JIT compiler if there is one available
|
|
|
|
/// for the current target. Otherwise, return null.
|
|
|
|
///
|
2003-12-28 09:44:37 +00:00
|
|
|
ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
|
2004-07-11 04:02:06 +00:00
|
|
|
if (MArch == 0) {
|
|
|
|
std::string Error;
|
|
|
|
MArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
|
|
|
|
if (MArch == 0) return 0;
|
|
|
|
} else if (MArch->JITMatchQualityFn() == 0) {
|
|
|
|
std::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...
|
2005-09-01 21:38:21 +00:00
|
|
|
TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL, 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())
|
|
|
|
return new JIT(MP, *Target, *TJ);
|
|
|
|
return 0;
|
|
|
|
}
|