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"
|
|
|
|
#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
|
|
|
|
|
|
|
/// 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
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a target...
|
2004-07-11 04:02:06 +00:00
|
|
|
TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL);
|
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;
|
|
|
|
}
|