Factor commonality in triple match routines into helper template for registering

classes, and migrate existing targets over.

llvm-svn: 77126
This commit is contained in:
Daniel Dunbar 2009-07-26 05:03:33 +00:00
parent bd481a119c
commit ee01b242e8
14 changed files with 46 additions and 233 deletions

View File

@ -19,6 +19,7 @@
#ifndef LLVM_TARGET_TARGETREGISTRY_H
#define LLVM_TARGET_TARGETREGISTRY_H
#include "llvm/ADT/Triple.h"
// FIXME: We shouldn't need this header, but we need it until there is a
// different interface to get the TargetAsmInfo.
#include "llvm/Target/TargetMachine.h"
@ -281,23 +282,22 @@ namespace llvm {
///
/// Target TheFooTarget; // The global target instance.
///
/// namespace {
/// struct FooInfo {
/// static const bool HasJIT = ...;
///
/// static unsigned getTripleMatchQuality(const std::string &) { ... }
/// };
/// }
///
/// extern "C" void LLVMInitializeFooTargetInfo() {
/// RegisterTarget<FooAsmPrinter> X(TheFooTarget, "foo", "Foo description");
/// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
/// }
template<class TargetInfoImpl>
template<Triple::ArchType TargetArchType = Triple::InvalidArch,
bool HasJIT = false>
struct RegisterTarget {
RegisterTarget(Target &T, const char *Name, const char *Desc) {
TargetRegistry::RegisterTarget(T, Name, Desc,
&TargetInfoImpl::getTripleMatchQuality,
TargetInfoImpl::HasJIT);
&getTripleMatchQuality,
HasJIT);
}
static unsigned getTripleMatchQuality(const std::string &TT) {
if (Triple(TT.c_str()).getArch() == TargetArchType)
return 20;
return 0;
}
};

View File

@ -12,36 +12,12 @@
#include "llvm/Target/TargetRegistry.h"
using namespace llvm;
Target llvm::TheARMTarget;
static unsigned ARM_TripleMatchQuality(const std::string &TT) {
// Match arm-foo-bar, as well as things like armv5blah-*
if (TT.size() >= 4 &&
(TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
return 20;
return 0;
}
Target llvm::TheThumbTarget;
static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
// Match thumb-foo-bar, as well as things like thumbv5blah-*
if (TT.size() >= 6 &&
(TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
return 20;
return 0;
}
Target llvm::TheARMTarget, llvm::TheThumbTarget;
extern "C" void LLVMInitializeARMTargetInfo() {
TargetRegistry::RegisterTarget(TheARMTarget, "arm",
"ARM",
&ARM_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::arm, /*HasJIT=*/true>
X(TheARMTarget, "arm", "ARM");
TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
"Thumb",
&Thumb_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::thumb, /*HasJIT=*/true>
Y(TheThumbTarget, "thumb", "Thumb");
}

View File

@ -14,18 +14,7 @@ using namespace llvm;
llvm::Target llvm::TheAlphaTarget;
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' &&
TT[3] == 'h' && TT[4] == 'a')
return 20;
return 0;
}
extern "C" void LLVMInitializeAlphaTargetInfo() {
TargetRegistry::RegisterTarget(TheAlphaTarget, "alpha",
"Alpha [experimental]",
&Alpha_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::alpha, /*HasJIT=*/true>
X(TheAlphaTarget, "alpha", "Alpha [experimental]");
}

View File

@ -14,14 +14,6 @@ using namespace llvm;
Target llvm::TheCBackendTarget;
static unsigned CBackend_TripleMatchQuality(const std::string &TT) {
// This class always works, but must be requested explicitly on
// llc command line.
return 0;
}
extern "C" void LLVMInitializeCBackendTargetInfo() {
TargetRegistry::RegisterTarget(TheCBackendTarget, "c",
"C backend",
&CBackend_TripleMatchQuality);
RegisterTarget<> X(TheCBackendTarget, "c", "C backend");
}

View File

@ -14,19 +14,7 @@ using namespace llvm;
Target llvm::TheCellSPUTarget;
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") ||
(TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu") ||
(TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-") ||
(TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-"))
return 20;
return 0;
}
extern "C" void LLVMInitializeCellSPUTargetInfo() {
TargetRegistry::RegisterTarget(TheCellSPUTarget, "cellspu",
"STI CBEA Cell SPU [experimental]",
&CellSPU_TripleMatchQuality);
RegisterTarget<Triple::cellspu>
X(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
}

View File

@ -14,17 +14,7 @@ using namespace llvm;
Target llvm::TheMSP430Target;
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' &&
TT[3] == '4' && TT[4] == '3' && TT[5] == '0')
return 20;
return 0;
}
extern "C" void LLVMInitializeMSP430TargetInfo() {
TargetRegistry::RegisterTarget(TheMSP430Target, "msp430",
"MSP430 [experimental]",
&MSP430_TripleMatchQuality);
RegisterTarget<Triple::msp430>
X(TheMSP430Target, "msp430", "MSP430 [experimental]");
}

View File

@ -12,43 +12,10 @@
#include "llvm/Target/TargetRegistry.h"
using namespace llvm;
Target llvm::TheMipsTarget;
static unsigned Mips_TripleMatchQuality(const std::string &TT) {
// We strongly match "mips*-*".
if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
return 20;
if (TT.size() >= 13 && std::string(TT.begin(),
TT.begin()+13) == "mipsallegrex-")
return 20;
return 0;
}
Target llvm::TheMipselTarget;
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-")
return 20;
if (TT.size() >= 15 && std::string(TT.begin(),
TT.begin()+15) == "mipsallegrexel-")
return 20;
if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp")
return 20;
return 0;
}
Target llvm::TheMipsTarget, llvm::TheMipselTarget;
extern "C" void LLVMInitializeMipsTargetInfo() {
TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
"Mips",
&Mips_TripleMatchQuality);
RegisterTarget<Triple::mips> X(TheMipsTarget, "mips", "Mips");
TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
"Mipsel",
&Mipsel_TripleMatchQuality);
RegisterTarget<Triple::mipsel> Y(TheMipselTarget, "mipsel", "Mipsel");
}

View File

@ -12,24 +12,10 @@
#include "llvm/Target/TargetRegistry.h"
using namespace llvm;
Target llvm::ThePIC16Target;
static unsigned PIC16_TripleMatchQuality(const std::string &TT) {
return 0;
}
Target llvm::TheCooperTarget;
static unsigned Cooper_TripleMatchQuality(const std::string &TT) {
return 0;
}
Target llvm::ThePIC16Target, llvm::TheCooperTarget;
extern "C" void LLVMInitializePIC16TargetInfo() {
TargetRegistry::RegisterTarget(ThePIC16Target, "pic16",
"PIC16 14-bit [experimental]",
&PIC16_TripleMatchQuality);
RegisterTarget<> X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental]");
TargetRegistry::RegisterTarget(TheCooperTarget, "cooper",
"PIC16 Cooper [experimental]",
&Cooper_TripleMatchQuality);
RegisterTarget<> Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental]");
}

View File

@ -12,34 +12,12 @@
#include "llvm/Target/TargetRegistry.h"
using namespace llvm;
Target llvm::ThePPC32Target;
static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
// We strongly match "powerpc-*".
if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
return 20;
return 0;
}
Target llvm::ThePPC64Target;
static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
// We strongly match "powerpc64-*".
if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
return 20;
return 0;
}
Target llvm::ThePPC32Target, llvm::ThePPC64Target;
extern "C" void LLVMInitializePowerPCTargetInfo() {
TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
"PowerPC 32",
&PPC32_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::ppc, /*HasJIT=*/true>
X(ThePPC32Target, "ppc32", "PowerPC 32");
TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
"PowerPC 64",
&PPC64_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::ppc64, /*HasJIT=*/true>
Y(ThePPC64Target, "ppc64", "PowerPC 64");
}

View File

@ -14,15 +14,6 @@ using namespace llvm;
Target llvm::TheSparcTarget;
static unsigned Sparc_TripleMatchQuality(const std::string &TT) {
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
return 20;
return 0;
}
extern "C" void LLVMInitializeSparcTargetInfo() {
TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
"Sparc",
&Sparc_TripleMatchQuality);
RegisterTarget<Triple::sparc> (TheSparcTarget, "sparc", "Sparc");
}

View File

@ -14,17 +14,6 @@ using namespace llvm;
Target llvm::TheSystemZTarget;
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' &&
TT[3] == '0' && TT[4] == 'x')
return 20;
return 0;
}
extern "C" void LLVMInitializeSystemZTargetInfo() {
TargetRegistry::RegisterTarget(TheSystemZTarget, "systemz",
"SystemZ",
&SystemZ_TripleMatchQuality);
RegisterTarget<Triple::systemz> X(TheSystemZTarget, "systemz", "SystemZ");
}

View File

@ -12,36 +12,12 @@
#include "llvm/Target/TargetRegistry.h"
using namespace llvm;
Target llvm::TheX86_32Target;
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' &&
TT[4] == '-' && TT[1] - '3' < 6)
return 20;
return 0;
}
Target llvm::TheX86_64Target;
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' &&
TT[3] == '_' && TT[4] == '6' && TT[5] == '4' && TT[6] == '-')
return 20;
return 0;
}
Target llvm::TheX86_32Target, llvm::TheX86_64Target;
extern "C" void LLVMInitializeX86TargetInfo() {
TargetRegistry::RegisterTarget(TheX86_32Target, "x86",
"32-bit X86: Pentium-Pro and above",
&X86_32_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::x86, /*HasJIT=*/true>
X(TheX86_32Target, "x86", "32-bit X86: Pentium-Pro and above");
TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
"64-bit X86: EM64T and AMD64",
&X86_64_TripleMatchQuality,
/*HasJIT=*/true);
RegisterTarget<Triple::x86_64, /*HasJIT=*/true>
Y(TheX86_64Target, "x86-64", "64-bit X86: EM64T and AMD64");
}

View File

@ -14,15 +14,6 @@ using namespace llvm;
Target llvm::TheXCoreTarget;
static unsigned XCore_TripleMatchQuality(const std::string &TT) {
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
return 20;
return 0;
}
extern "C" void LLVMInitializeXCoreTargetInfo() {
TargetRegistry::RegisterTarget(TheXCoreTarget, "xcore",
"XCore",
&XCore_TripleMatchQuality);
RegisterTarget<Triple::xcore> X(TheXCoreTarget, "xcore", "XCore");
}

View File

@ -39,7 +39,7 @@ IncludeDirs("I", cl::desc("Directory of include files"),
cl::value_desc("directory"), cl::Prefix);
static cl::opt<std::string>
Triple("triple", cl::desc("Target triple to assemble for,"
TripleName("triple", cl::desc("Target triple to assemble for,"
"see -version for available targets"),
cl::init(LLVM_HOSTTRIPLE));
@ -147,12 +147,12 @@ static int AssembleInput(const char *ProgName) {
// Get the target specific parser.
std::string Error;
const Target *TheTarget =
TargetRegistry::lookupTarget(Triple,
TargetRegistry::lookupTarget(TripleName,
/*FallbackToHost=*/true,
/*RequireJIT=*/false,
Error);
if (TheTarget == 0) {
errs() << ProgName << ": error: unable to get target for '" << Triple
errs() << ProgName << ": error: unable to get target for '" << TripleName
<< "', see --version and --triple.\n";
return 1;
}