mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
Factor commonality in triple match routines into helper template for registering
classes, and migrate existing targets over. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77126 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#ifndef LLVM_TARGET_TARGETREGISTRY_H
|
#ifndef LLVM_TARGET_TARGETREGISTRY_H
|
||||||
#define 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
|
// FIXME: We shouldn't need this header, but we need it until there is a
|
||||||
// different interface to get the TargetAsmInfo.
|
// different interface to get the TargetAsmInfo.
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
@@ -281,23 +282,22 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
/// Target TheFooTarget; // The global target instance.
|
/// Target TheFooTarget; // The global target instance.
|
||||||
///
|
///
|
||||||
/// namespace {
|
|
||||||
/// struct FooInfo {
|
|
||||||
/// static const bool HasJIT = ...;
|
|
||||||
///
|
|
||||||
/// static unsigned getTripleMatchQuality(const std::string &) { ... }
|
|
||||||
/// };
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// extern "C" void LLVMInitializeFooTargetInfo() {
|
/// 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 {
|
struct RegisterTarget {
|
||||||
RegisterTarget(Target &T, const char *Name, const char *Desc) {
|
RegisterTarget(Target &T, const char *Name, const char *Desc) {
|
||||||
TargetRegistry::RegisterTarget(T, Name, Desc,
|
TargetRegistry::RegisterTarget(T, Name, Desc,
|
||||||
&TargetInfoImpl::getTripleMatchQuality,
|
&getTripleMatchQuality,
|
||||||
TargetInfoImpl::HasJIT);
|
HasJIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned getTripleMatchQuality(const std::string &TT) {
|
||||||
|
if (Triple(TT.c_str()).getArch() == TargetArchType)
|
||||||
|
return 20;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -12,36 +12,12 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Target llvm::TheARMTarget;
|
Target llvm::TheARMTarget, llvm::TheThumbTarget;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMInitializeARMTargetInfo() {
|
extern "C" void LLVMInitializeARMTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheARMTarget, "arm",
|
RegisterTarget<Triple::arm, /*HasJIT=*/true>
|
||||||
"ARM",
|
X(TheARMTarget, "arm", "ARM");
|
||||||
&ARM_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
|
|
||||||
TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
|
RegisterTarget<Triple::thumb, /*HasJIT=*/true>
|
||||||
"Thumb",
|
Y(TheThumbTarget, "thumb", "Thumb");
|
||||||
&Thumb_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,18 +14,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
llvm::Target llvm::TheAlphaTarget;
|
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() {
|
extern "C" void LLVMInitializeAlphaTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheAlphaTarget, "alpha",
|
RegisterTarget<Triple::alpha, /*HasJIT=*/true>
|
||||||
"Alpha [experimental]",
|
X(TheAlphaTarget, "alpha", "Alpha [experimental]");
|
||||||
&Alpha_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,14 +14,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheCBackendTarget;
|
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() {
|
extern "C" void LLVMInitializeCBackendTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheCBackendTarget, "c",
|
RegisterTarget<> X(TheCBackendTarget, "c", "C backend");
|
||||||
"C backend",
|
|
||||||
&CBackend_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,19 +14,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheCellSPUTarget;
|
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() {
|
extern "C" void LLVMInitializeCellSPUTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheCellSPUTarget, "cellspu",
|
RegisterTarget<Triple::cellspu>
|
||||||
"STI CBEA Cell SPU [experimental]",
|
X(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
|
||||||
&CellSPU_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,17 +14,7 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheMSP430Target;
|
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() {
|
extern "C" void LLVMInitializeMSP430TargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheMSP430Target, "msp430",
|
RegisterTarget<Triple::msp430>
|
||||||
"MSP430 [experimental]",
|
X(TheMSP430Target, "msp430", "MSP430 [experimental]");
|
||||||
&MSP430_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -12,43 +12,10 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Target llvm::TheMipsTarget;
|
Target llvm::TheMipsTarget, llvm::TheMipselTarget;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMInitializeMipsTargetInfo() {
|
extern "C" void LLVMInitializeMipsTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
|
RegisterTarget<Triple::mips> X(TheMipsTarget, "mips", "Mips");
|
||||||
"Mips",
|
|
||||||
&Mips_TripleMatchQuality);
|
|
||||||
|
|
||||||
TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
|
RegisterTarget<Triple::mipsel> Y(TheMipselTarget, "mipsel", "Mipsel");
|
||||||
"Mipsel",
|
|
||||||
&Mipsel_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -12,24 +12,10 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Target llvm::ThePIC16Target;
|
Target llvm::ThePIC16Target, llvm::TheCooperTarget;
|
||||||
|
|
||||||
static unsigned PIC16_TripleMatchQuality(const std::string &TT) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Target llvm::TheCooperTarget;
|
|
||||||
|
|
||||||
static unsigned Cooper_TripleMatchQuality(const std::string &TT) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMInitializePIC16TargetInfo() {
|
extern "C" void LLVMInitializePIC16TargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(ThePIC16Target, "pic16",
|
RegisterTarget<> X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental]");
|
||||||
"PIC16 14-bit [experimental]",
|
|
||||||
&PIC16_TripleMatchQuality);
|
|
||||||
|
|
||||||
TargetRegistry::RegisterTarget(TheCooperTarget, "cooper",
|
RegisterTarget<> Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental]");
|
||||||
"PIC16 Cooper [experimental]",
|
|
||||||
&Cooper_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -12,34 +12,12 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Target llvm::ThePPC32Target;
|
Target llvm::ThePPC32Target, llvm::ThePPC64Target;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMInitializePowerPCTargetInfo() {
|
extern "C" void LLVMInitializePowerPCTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
|
RegisterTarget<Triple::ppc, /*HasJIT=*/true>
|
||||||
"PowerPC 32",
|
X(ThePPC32Target, "ppc32", "PowerPC 32");
|
||||||
&PPC32_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
|
|
||||||
TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
|
RegisterTarget<Triple::ppc64, /*HasJIT=*/true>
|
||||||
"PowerPC 64",
|
Y(ThePPC64Target, "ppc64", "PowerPC 64");
|
||||||
&PPC64_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,15 +14,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheSparcTarget;
|
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() {
|
extern "C" void LLVMInitializeSparcTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
|
RegisterTarget<Triple::sparc> (TheSparcTarget, "sparc", "Sparc");
|
||||||
"Sparc",
|
|
||||||
&Sparc_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,17 +14,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheSystemZTarget;
|
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() {
|
extern "C" void LLVMInitializeSystemZTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheSystemZTarget, "systemz",
|
RegisterTarget<Triple::systemz> X(TheSystemZTarget, "systemz", "SystemZ");
|
||||||
"SystemZ",
|
|
||||||
&SystemZ_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -12,36 +12,12 @@
|
|||||||
#include "llvm/Target/TargetRegistry.h"
|
#include "llvm/Target/TargetRegistry.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
Target llvm::TheX86_32Target;
|
Target llvm::TheX86_32Target, llvm::TheX86_64Target;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMInitializeX86TargetInfo() {
|
extern "C" void LLVMInitializeX86TargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheX86_32Target, "x86",
|
RegisterTarget<Triple::x86, /*HasJIT=*/true>
|
||||||
"32-bit X86: Pentium-Pro and above",
|
X(TheX86_32Target, "x86", "32-bit X86: Pentium-Pro and above");
|
||||||
&X86_32_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
|
|
||||||
TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
|
RegisterTarget<Triple::x86_64, /*HasJIT=*/true>
|
||||||
"64-bit X86: EM64T and AMD64",
|
Y(TheX86_64Target, "x86-64", "64-bit X86: EM64T and AMD64");
|
||||||
&X86_64_TripleMatchQuality,
|
|
||||||
/*HasJIT=*/true);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,15 +14,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
Target llvm::TheXCoreTarget;
|
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() {
|
extern "C" void LLVMInitializeXCoreTargetInfo() {
|
||||||
TargetRegistry::RegisterTarget(TheXCoreTarget, "xcore",
|
RegisterTarget<Triple::xcore> X(TheXCoreTarget, "xcore", "XCore");
|
||||||
"XCore",
|
|
||||||
&XCore_TripleMatchQuality);
|
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ IncludeDirs("I", cl::desc("Directory of include files"),
|
|||||||
cl::value_desc("directory"), cl::Prefix);
|
cl::value_desc("directory"), cl::Prefix);
|
||||||
|
|
||||||
static cl::opt<std::string>
|
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"),
|
"see -version for available targets"),
|
||||||
cl::init(LLVM_HOSTTRIPLE));
|
cl::init(LLVM_HOSTTRIPLE));
|
||||||
|
|
||||||
@@ -147,12 +147,12 @@ static int AssembleInput(const char *ProgName) {
|
|||||||
// Get the target specific parser.
|
// Get the target specific parser.
|
||||||
std::string Error;
|
std::string Error;
|
||||||
const Target *TheTarget =
|
const Target *TheTarget =
|
||||||
TargetRegistry::lookupTarget(Triple,
|
TargetRegistry::lookupTarget(TripleName,
|
||||||
/*FallbackToHost=*/true,
|
/*FallbackToHost=*/true,
|
||||||
/*RequireJIT=*/false,
|
/*RequireJIT=*/false,
|
||||||
Error);
|
Error);
|
||||||
if (TheTarget == 0) {
|
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";
|
<< "', see --version and --triple.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user