/// of a module.
ModuleMatchQualityFnTy ModuleMatchQualityFn;
- /// JITMatchQualityFn - The target function for rating the match quality
- /// with the host.
- JITMatchQualityFnTy JITMatchQualityFn;
-
/// Name - The target name.
const char *Name;
/// ShortDesc - A short description of the target.
const char *ShortDesc;
+ /// HasJIT - Whether this target supports the JIT.
+ bool HasJIT;
+
/// TargetMachineCtorFn - Construction function for this target's
/// TargetMachine, if registered.
TargetMachineCtorTy TargetMachineCtorFn;
/// getShortDescription - Get a short description of the target.
const char *getShortDescription() const { return ShortDesc; }
- /// getJITMatchQuality - Get the quality of this targets match for use as a
- /// JIT.
- unsigned getJITMatchQuality() const { return JITMatchQualityFn(); }
+ bool hasJIT() const { return HasJIT; }
/// hasTargetMachine - Check if this target supports code generation.
bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
/// this target.
/// @param MQualityFn - The module match quality computation function for
/// this target.
- /// @param JITMatchQualityFn - The JIT match quality computation function
- /// for this target.
+ /// @param HasJIT - Whether the target supports JIT code
+ /// generation.
static void RegisterTarget(Target &T,
const char *Name,
const char *ShortDesc,
Target::TripleMatchQualityFnTy TQualityFn,
Target::ModuleMatchQualityFnTy MQualityFn,
- Target::JITMatchQualityFnTy JITQualityFn);
+ bool HasJIT = false);
/// RegisterTargetMachine - Register a TargetMachine implementation for the
/// given target.
///
/// namespace {
/// struct FooInfo {
+ /// static const bool HasJIT = ...;
+ ///
/// static unsigned getJITMatchQuality() { ... }
/// static unsigned getTripleMatchQuality(const std::string &) { ... }
/// static unsigned getModuleMatchQuality(const Module &) { ... }
TargetRegistry::RegisterTarget(T, Name, Desc,
&TargetInfoImpl::getTripleMatchQuality,
&TargetInfoImpl::getModuleMatchQuality,
- &TargetInfoImpl::getJITMatchQuality);
+ TargetInfoImpl::HasJIT);
}
};
return 0;
}
- if (TheTarget->getJITMatchQuality() == 0) {
+ if (!TheTarget->hasJIT()) {
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";
//===----------------------------------------------------------------------===//
#include "llvm/Target/TargetRegistry.h"
+#include "llvm/System/Host.h"
#include <cassert>
using namespace llvm;
}
}
+ // FIXME: This is a hack to ignore super weak matches like msil, etc. and look
+ // by host instead. They will be found again via the triple.
+ if (Best && BestQuality == 1)
+ Best = EquallyBest = 0;
+
+ // If that failed, try looking up the host triple.
+ if (!Best)
+ Best = getClosestStaticTargetForTriple(sys::getHostTriple(), Error);
+
if (!Best) {
Error = "No available targets are compatible with this module";
- return 0;
+ return Best;
}
// Otherwise, take the best target, but make sure we don't have two equally
const Target *
TargetRegistry::getClosestTargetForJIT(std::string &Error) {
+ std::string Triple = sys::getHostTriple();
+
// Provide special warning when no targets are initialized.
if (begin() == end()) {
Error = "No JIT is available for this host (no targets are registered)";
const Target *Best = 0, *EquallyBest = 0;
unsigned BestQuality = 0;
for (iterator it = begin(), ie = end(); it != ie; ++it) {
- if (unsigned Qual = it->JITMatchQualityFn()) {
+ if (!it->hasJIT())
+ continue;
+
+ if (unsigned Qual = it->TripleMatchQualityFn(Triple)) {
if (!Best || Qual > BestQuality) {
Best = &*it;
EquallyBest = 0;
const char *ShortDesc,
Target::TripleMatchQualityFnTy TQualityFn,
Target::ModuleMatchQualityFnTy MQualityFn,
- Target::JITMatchQualityFnTy JITQualityFn) {
- assert(Name && ShortDesc && TQualityFn && MQualityFn && JITQualityFn &&
+ bool HasJIT) {
+ assert(Name && ShortDesc && TQualityFn && MQualityFn &&
"Missing required target information!");
// Check if this target has already been initialized, we allow this as a
T.ShortDesc = ShortDesc;
T.TripleMatchQualityFn = TQualityFn;
T.ModuleMatchQualityFn = MQualityFn;
- T.JITMatchQualityFn = JITQualityFn;
+ T.HasJIT = HasJIT;
}
Target llvm::TheARMTarget;
-static unsigned ARM_JITMatchQuality() {
-#if defined(__arm__)
- return 10;
-#endif
- return 0;
-}
-
static unsigned ARM_TripleMatchQuality(const std::string &TT) {
// Match arm-foo-bar, as well as things like armv5blah-*
if (TT.size() >= 4 &&
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return ARM_JITMatchQuality()/2;
+ return 0;
}
Target llvm::TheThumbTarget;
-static unsigned Thumb_JITMatchQuality() {
-#if defined(__thumb__)
- return 10;
-#endif
- return 0;
-}
-
static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
// Match thumb-foo-bar, as well as things like thumbv5blah-*
if (TT.size() >= 6 &&
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return Thumb_JITMatchQuality()/2;
+ return 0;
}
extern "C" void LLVMInitializeARMTargetInfo() {
"ARM",
&ARM_TripleMatchQuality,
&ARM_ModuleMatchQuality,
- &ARM_JITMatchQuality);
+ /*HasJIT=*/true);
TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
"Thumb",
&Thumb_TripleMatchQuality,
&Thumb_ModuleMatchQuality,
- &Thumb_JITMatchQuality);
+ /*HasJIT=*/true);
}
llvm::Target llvm::TheAlphaTarget;
-static unsigned Alpha_JITMatchQuality() {
-#ifdef __alpha
- return 10;
-#else
- return 0;
-#endif
-}
-
static unsigned Alpha_TripleMatchQuality(const std::string &TT) {
// We strongly match "alpha*".
if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return Alpha_JITMatchQuality()/2;
+ return 0;
}
extern "C" void LLVMInitializeAlphaTargetInfo() {
"Alpha [experimental]",
&Alpha_TripleMatchQuality,
&Alpha_ModuleMatchQuality,
- &Alpha_JITMatchQuality);
+ /*HasJIT=*/true);
}
Target llvm::TheCBackendTarget;
-static unsigned CBackend_JITMatchQuality() {
- return 0;
-}
-
static unsigned CBackend_TripleMatchQuality(const std::string &TT) {
// This class always works, but must be requested explicitly on
// llc command line.
TargetRegistry::RegisterTarget(TheCBackendTarget, "c",
"C backend",
&CBackend_TripleMatchQuality,
- &CBackend_ModuleMatchQuality,
- &CBackend_JITMatchQuality);
+ &CBackend_ModuleMatchQuality);
}
Target llvm::TheCellSPUTarget;
-static unsigned CellSPU_JITMatchQuality() {
- return 0;
-}
-
static unsigned CellSPU_TripleMatchQuality(const std::string &TT) {
// We strongly match "spu-*" or "cellspu-*".
if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu") ||
TargetRegistry::RegisterTarget(TheCellSPUTarget, "cellspu",
"STI CBEA Cell SPU [experimental]",
&CellSPU_TripleMatchQuality,
- &CellSPU_ModuleMatchQuality,
- &CellSPU_JITMatchQuality);
+ &CellSPU_ModuleMatchQuality);
}
Target llvm::TheCppBackendTarget;
-static unsigned CppBackend_JITMatchQuality() {
- return 0;
-}
-
static unsigned CppBackend_TripleMatchQuality(const std::string &TT) {
// This class always works, but shouldn't be the default in most cases.
return 1;
TargetRegistry::RegisterTarget(TheCppBackendTarget, "cpp",
"C++ backend",
&CppBackend_TripleMatchQuality,
- &CppBackend_ModuleMatchQuality,
- &CppBackend_JITMatchQuality);
+ &CppBackend_ModuleMatchQuality);
}
Target llvm::TheMSILTarget;
-static unsigned MSIL_JITMatchQuality() {
- return 0;
-}
-
static unsigned MSIL_TripleMatchQuality(const std::string &TT) {
// This class always works, but shouldn't be the default in most cases.
return 1;
TargetRegistry::RegisterTarget(TheMSILTarget, "msil",
"MSIL backend",
&MSIL_TripleMatchQuality,
- &MSIL_ModuleMatchQuality,
- &MSIL_JITMatchQuality);
+ &MSIL_ModuleMatchQuality);
}
Target llvm::TheMSP430Target;
-static unsigned MSP430_JITMatchQuality() {
- return 0;
-}
-
static unsigned MSP430_TripleMatchQuality(const std::string &TT) {
// We strongly match msp430
if (TT.size() >= 6 && TT[0] == 'm' && TT[1] == 's' && TT[2] == 'p' &&
TargetRegistry::RegisterTarget(TheMSP430Target, "msp430",
"MSP430 [experimental]",
&MSP430_TripleMatchQuality,
- &MSP430_ModuleMatchQuality,
- &MSP430_JITMatchQuality);
+ &MSP430_ModuleMatchQuality);
}
Target llvm::TheMipsTarget;
-static unsigned Mips_JITMatchQuality() {
- return 0;
-}
-
static unsigned Mips_TripleMatchQuality(const std::string &TT) {
// We strongly match "mips*-*".
if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
Target llvm::TheMipselTarget;
-static unsigned Mipsel_JITMatchQuality() {
- return 0;
-}
-
static unsigned Mipsel_TripleMatchQuality(const std::string &TT) {
// We strongly match "mips*el-*".
if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-")
TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
"Mips",
&Mips_TripleMatchQuality,
- &Mips_ModuleMatchQuality,
- &Mips_JITMatchQuality);
+ &Mips_ModuleMatchQuality);
TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
"Mipsel",
&Mipsel_TripleMatchQuality,
- &Mipsel_ModuleMatchQuality,
- &Mipsel_JITMatchQuality);
+ &Mipsel_ModuleMatchQuality);
}
Target llvm::ThePIC16Target;
-static unsigned PIC16_JITMatchQuality() {
- return 0;
-}
-
static unsigned PIC16_TripleMatchQuality(const std::string &TT) {
return 0;
}
Target llvm::TheCooperTarget;
-static unsigned Cooper_JITMatchQuality() {
- return 0;
-}
-
static unsigned Cooper_TripleMatchQuality(const std::string &TT) {
return 0;
}
TargetRegistry::RegisterTarget(ThePIC16Target, "pic16",
"PIC16 14-bit [experimental]",
&PIC16_TripleMatchQuality,
- &PIC16_ModuleMatchQuality,
- &PIC16_JITMatchQuality);
+ &PIC16_ModuleMatchQuality);
TargetRegistry::RegisterTarget(TheCooperTarget, "cooper",
"PIC16 Cooper [experimental]",
&Cooper_TripleMatchQuality,
- &Cooper_ModuleMatchQuality,
- &Cooper_JITMatchQuality);
+ &Cooper_ModuleMatchQuality);
}
Target llvm::ThePPC32Target;
-static unsigned PPC32_JITMatchQuality() {
-#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
- if (sizeof(void*) == 4)
- return 10;
-#endif
- return 0;
-}
-
static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
// We strongly match "powerpc-*".
if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return PPC32_JITMatchQuality()/2;
+ return 0;
}
Target llvm::ThePPC64Target;
-static unsigned PPC64_JITMatchQuality() {
-#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
- if (sizeof(void*) == 8)
- return 10;
-#endif
- return 0;
-}
-
static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
// We strongly match "powerpc64-*".
if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return PPC64_JITMatchQuality()/2;
+ return 0;
}
extern "C" void LLVMInitializePowerPCTargetInfo() {
"PowerPC 32",
&PPC32_TripleMatchQuality,
&PPC32_ModuleMatchQuality,
- &PPC32_JITMatchQuality);
+ /*HasJIT=*/true);
TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
"PowerPC 64",
&PPC64_TripleMatchQuality,
&PPC64_ModuleMatchQuality,
- &PPC64_JITMatchQuality);
+ /*HasJIT=*/true);
}
Target llvm::TheSparcTarget;
-static unsigned Sparc_JITMatchQuality() {
- return 0;
-}
-
static unsigned Sparc_TripleMatchQuality(const std::string &TT) {
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
return 20;
TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
"Sparc",
&Sparc_TripleMatchQuality,
- &Sparc_ModuleMatchQuality,
- &Sparc_JITMatchQuality);
+ &Sparc_ModuleMatchQuality);
}
-//===-- SystemZTargetInfo.cpp - SystemZ Target Implementation -----------------===//
+//===-- SystemZTargetInfo.cpp - SystemZ Target Implementation -------------===//
//
// The LLVM Compiler Infrastructure
//
Target llvm::TheSystemZTarget;
-static unsigned SystemZ_JITMatchQuality() {
- return 0;
-}
-
static unsigned SystemZ_TripleMatchQuality(const std::string &TT) {
// We strongly match s390x
if (TT.size() >= 5 && TT[0] == 's' && TT[1] == '3' && TT[2] == '9' &&
TargetRegistry::RegisterTarget(TheSystemZTarget, "systemz",
"SystemZ",
&SystemZ_TripleMatchQuality,
- &SystemZ_ModuleMatchQuality,
- &SystemZ_JITMatchQuality);
+ &SystemZ_ModuleMatchQuality);
}
Target llvm::TheX86_32Target;
-static unsigned X86_32_JITMatchQuality() {
-#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
- return 10;
-#endif
- return 0;
-}
-
static unsigned X86_32_TripleMatchQuality(const std::string &TT) {
// We strongly match "i[3-9]86-*".
if (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return X86_32_JITMatchQuality()/2;
+ return 0;
}
Target llvm::TheX86_64Target;
-static unsigned X86_64_JITMatchQuality() {
-#if defined(__x86_64__) || defined(_M_AMD64)
- return 10;
-#endif
- return 0;
-}
-
static unsigned X86_64_TripleMatchQuality(const std::string &TT) {
// We strongly match "x86_64-*".
if (TT.size() >= 7 && TT[0] == 'x' && TT[1] == '8' && TT[2] == '6' &&
M.getPointerSize() != Module::AnyPointerSize)
return 0; // Match for some other target
- return X86_64_JITMatchQuality()/2;
+ return 0;
}
extern "C" void LLVMInitializeX86TargetInfo() {
"32-bit X86: Pentium-Pro and above",
&X86_32_TripleMatchQuality,
&X86_32_ModuleMatchQuality,
- &X86_32_JITMatchQuality);
+ /*HasJIT=*/true);
TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
"64-bit X86: EM64T and AMD64",
&X86_64_TripleMatchQuality,
&X86_64_ModuleMatchQuality,
- &X86_64_JITMatchQuality);
+ /*HasJIT=*/true);
}
Target llvm::TheXCoreTarget;
-static unsigned XCore_JITMatchQuality() {
- return 0;
-}
-
static unsigned XCore_TripleMatchQuality(const std::string &TT) {
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
return 20;
TargetRegistry::RegisterTarget(TheXCoreTarget, "xcore",
"XCore",
&XCore_TripleMatchQuality,
- &XCore_ModuleMatchQuality,
- &XCore_JITMatchQuality);
+ &XCore_ModuleMatchQuality);
}