llvm.org GIT mirror llvm / 8977d08
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 Daniel Dunbar 11 years ago
14 changed file(s) with 54 addition(s) and 241 deletion(s). Raw diff Collapse all Expand all
1818 #ifndef LLVM_TARGET_TARGETREGISTRY_H
1919 #define LLVM_TARGET_TARGETREGISTRY_H
2020
21 #include "llvm/ADT/Triple.h"
2122 // FIXME: We shouldn't need this header, but we need it until there is a
2223 // different interface to get the TargetAsmInfo.
2324 #include "llvm/Target/TargetMachine.h"
280281 ///
281282 /// Target TheFooTarget; // The global target instance.
282283 ///
283 /// namespace {
284 /// struct FooInfo {
285 /// static const bool HasJIT = ...;
286 ///
287 /// static unsigned getTripleMatchQuality(const std::string &) { ... }
288 /// };
284 /// extern "C" void LLVMInitializeFooTargetInfo() {
285 /// RegisterTarget X(TheFooTarget, "foo", "Foo description");
289286 /// }
290 ///
291 /// extern "C" void LLVMInitializeFooTargetInfo() {
292 /// RegisterTarget X(TheFooTarget, "foo", "Foo description");
293 /// }
294 template<class TargetInfoImpl>
287 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
288 bool HasJIT = false>
295289 struct RegisterTarget {
296290 RegisterTarget(Target &T, const char *Name, const char *Desc) {
297291 TargetRegistry::RegisterTarget(T, Name, Desc,
298 &TargetInfoImpl::getTripleMatchQuality,
299 TargetInfoImpl::HasJIT);
292 &getTripleMatchQuality,
293 HasJIT);
294 }
295
296 static unsigned getTripleMatchQuality(const std::string &TT) {
297 if (Triple(TT.c_str()).getArch() == TargetArchType)
298 return 20;
299 return 0;
300300 }
301301 };
302302
1111 #include "llvm/Target/TargetRegistry.h"
1212 using namespace llvm;
1313
14 Target llvm::TheARMTarget;
15
16 static unsigned ARM_TripleMatchQuality(const std::string &TT) {
17 // Match arm-foo-bar, as well as things like armv5blah-*
18 if (TT.size() >= 4 &&
19 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
20 return 20;
21
22 return 0;
23 }
24
25 Target llvm::TheThumbTarget;
26
27 static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
28 // Match thumb-foo-bar, as well as things like thumbv5blah-*
29 if (TT.size() >= 6 &&
30 (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
31 return 20;
32
33 return 0;
34 }
14 Target llvm::TheARMTarget, llvm::TheThumbTarget;
3515
3616 extern "C" void LLVMInitializeARMTargetInfo() {
37 TargetRegistry::RegisterTarget(TheARMTarget, "arm",
38 "ARM",
39 &ARM_TripleMatchQuality,
40 /*HasJIT=*/true);
17 RegisterTarget
18 X(TheARMTarget, "arm", "ARM");
4119
42 TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
43 "Thumb",
44 &Thumb_TripleMatchQuality,
45 /*HasJIT=*/true);
20 RegisterTarget
21 Y(TheThumbTarget, "thumb", "Thumb");
4622 }
1313
1414 llvm::Target llvm::TheAlphaTarget;
1515
16 static unsigned Alpha_TripleMatchQuality(const std::string &TT) {
17 // We strongly match "alpha*".
18 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' &&
19 TT[3] == 'h' && TT[4] == 'a')
20 return 20;
21
22 return 0;
16 extern "C" void LLVMInitializeAlphaTargetInfo() {
17 RegisterTarget
18 X(TheAlphaTarget, "alpha", "Alpha [experimental]");
2319 }
24
25 extern "C" void LLVMInitializeAlphaTargetInfo() {
26 TargetRegistry::RegisterTarget(TheAlphaTarget, "alpha",
27 "Alpha [experimental]",
28 &Alpha_TripleMatchQuality,
29 /*HasJIT=*/true);
30 }
1313
1414 Target llvm::TheCBackendTarget;
1515
16 static unsigned CBackend_TripleMatchQuality(const std::string &TT) {
17 // This class always works, but must be requested explicitly on
18 // llc command line.
19 return 0;
16 extern "C" void LLVMInitializeCBackendTargetInfo() {
17 RegisterTarget<> X(TheCBackendTarget, "c", "C backend");
2018 }
21
22 extern "C" void LLVMInitializeCBackendTargetInfo() {
23 TargetRegistry::RegisterTarget(TheCBackendTarget, "c",
24 "C backend",
25 &CBackend_TripleMatchQuality);
26 }
1313
1414 Target llvm::TheCellSPUTarget;
1515
16 static unsigned CellSPU_TripleMatchQuality(const std::string &TT) {
17 // We strongly match "spu-*" or "cellspu-*".
18 if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu") ||
19 (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu") ||
20 (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-") ||
21 (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-"))
22 return 20;
23
24 return 0;
16 extern "C" void LLVMInitializeCellSPUTargetInfo() {
17 RegisterTarget
18 X(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
2519 }
26
27 extern "C" void LLVMInitializeCellSPUTargetInfo() {
28 TargetRegistry::RegisterTarget(TheCellSPUTarget, "cellspu",
29 "STI CBEA Cell SPU [experimental]",
30 &CellSPU_TripleMatchQuality);
31 }
1313
1414 Target llvm::TheMSP430Target;
1515
16 static unsigned MSP430_TripleMatchQuality(const std::string &TT) {
17 // We strongly match msp430
18 if (TT.size() >= 6 && TT[0] == 'm' && TT[1] == 's' && TT[2] == 'p' &&
19 TT[3] == '4' && TT[4] == '3' && TT[5] == '0')
20 return 20;
21
22 return 0;
16 extern "C" void LLVMInitializeMSP430TargetInfo() {
17 RegisterTarget
18 X(TheMSP430Target, "msp430", "MSP430 [experimental]");
2319 }
24
25 extern "C" void LLVMInitializeMSP430TargetInfo() {
26 TargetRegistry::RegisterTarget(TheMSP430Target, "msp430",
27 "MSP430 [experimental]",
28 &MSP430_TripleMatchQuality);
29 }
1111 #include "llvm/Target/TargetRegistry.h"
1212 using namespace llvm;
1313
14 Target llvm::TheMipsTarget;
15
16 static unsigned Mips_TripleMatchQuality(const std::string &TT) {
17 // We strongly match "mips*-*".
18 if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
19 return 20;
20
21 if (TT.size() >= 13 && std::string(TT.begin(),
22 TT.begin()+13) == "mipsallegrex-")
23 return 20;
24
25 return 0;
26 }
27
28 Target llvm::TheMipselTarget;
29
30 static unsigned Mipsel_TripleMatchQuality(const std::string &TT) {
31 // We strongly match "mips*el-*".
32 if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-")
33 return 20;
34
35 if (TT.size() >= 15 && std::string(TT.begin(),
36 TT.begin()+15) == "mipsallegrexel-")
37 return 20;
38
39 if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp")
40 return 20;
41
42 return 0;
43 }
14 Target llvm::TheMipsTarget, llvm::TheMipselTarget;
4415
4516 extern "C" void LLVMInitializeMipsTargetInfo() {
46 TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
47 "Mips",
48 &Mips_TripleMatchQuality);
17 RegisterTarget X(TheMipsTarget, "mips", "Mips");
4918
50 TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
51 "Mipsel",
52 &Mipsel_TripleMatchQuality);
19 RegisterTarget Y(TheMipselTarget, "mipsel", "Mipsel");
5320 }
1111 #include "llvm/Target/TargetRegistry.h"
1212 using namespace llvm;
1313
14 Target llvm::ThePIC16Target;
15
16 static unsigned PIC16_TripleMatchQuality(const std::string &TT) {
17 return 0;
18 }
19
20 Target llvm::TheCooperTarget;
21
22 static unsigned Cooper_TripleMatchQuality(const std::string &TT) {
23 return 0;
24 }
14 Target llvm::ThePIC16Target, llvm::TheCooperTarget;
2515
2616 extern "C" void LLVMInitializePIC16TargetInfo() {
27 TargetRegistry::RegisterTarget(ThePIC16Target, "pic16",
28 "PIC16 14-bit [experimental]",
29 &PIC16_TripleMatchQuality);
17 RegisterTarget<> X(ThePIC16Target, "pic16", "PIC16 14-bit [experimental]");
3018
31 TargetRegistry::RegisterTarget(TheCooperTarget, "cooper",
32 "PIC16 Cooper [experimental]",
33 &Cooper_TripleMatchQuality);
19 RegisterTarget<> Y(TheCooperTarget, "cooper", "PIC16 Cooper [experimental]");
3420 }
1111 #include "llvm/Target/TargetRegistry.h"
1212 using namespace llvm;
1313
14 Target llvm::ThePPC32Target;
15
16 static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
17 // We strongly match "powerpc-*".
18 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
19 return 20;
20
21 return 0;
22 }
23
24 Target llvm::ThePPC64Target;
25
26 static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
27 // We strongly match "powerpc64-*".
28 if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
29 return 20;
30
31 return 0;
32 }
14 Target llvm::ThePPC32Target, llvm::ThePPC64Target;
3315
3416 extern "C" void LLVMInitializePowerPCTargetInfo() {
35 TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
36 "PowerPC 32",
37 &PPC32_TripleMatchQuality,
38 /*HasJIT=*/true);
17 RegisterTarget
18 X(ThePPC32Target, "ppc32", "PowerPC 32");
3919
40 TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
41 "PowerPC 64",
42 &PPC64_TripleMatchQuality,
43 /*HasJIT=*/true);
20 RegisterTarget
21 Y(ThePPC64Target, "ppc64", "PowerPC 64");
4422 }
1313
1414 Target llvm::TheSparcTarget;
1515
16 static unsigned Sparc_TripleMatchQuality(const std::string &TT) {
17 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
18 return 20;
19
20 return 0;
16 extern "C" void LLVMInitializeSparcTargetInfo() {
17 RegisterTarget (TheSparcTarget, "sparc", "Sparc");
2118 }
22
23 extern "C" void LLVMInitializeSparcTargetInfo() {
24 TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
25 "Sparc",
26 &Sparc_TripleMatchQuality);
27 }
1313
1414 Target llvm::TheSystemZTarget;
1515
16 static unsigned SystemZ_TripleMatchQuality(const std::string &TT) {
17 // We strongly match s390x
18 if (TT.size() >= 5 && TT[0] == 's' && TT[1] == '3' && TT[2] == '9' &&
19 TT[3] == '0' && TT[4] == 'x')
20 return 20;
21
22 return 0;
16 extern "C" void LLVMInitializeSystemZTargetInfo() {
17 RegisterTarget X(TheSystemZTarget, "systemz", "SystemZ");
2318 }
24
25 extern "C" void LLVMInitializeSystemZTargetInfo() {
26 TargetRegistry::RegisterTarget(TheSystemZTarget, "systemz",
27 "SystemZ",
28 &SystemZ_TripleMatchQuality);
29 }
1111 #include "llvm/Target/TargetRegistry.h"
1212 using namespace llvm;
1313
14 Target llvm::TheX86_32Target;
15
16 static unsigned X86_32_TripleMatchQuality(const std::string &TT) {
17 // We strongly match "i[3-9]86-*".
18 if (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
19 TT[4] == '-' && TT[1] - '3' < 6)
20 return 20;
21
22 return 0;
23 }
24
25 Target llvm::TheX86_64Target;
26
27 static unsigned X86_64_TripleMatchQuality(const std::string &TT) {
28 // We strongly match "x86_64-*".
29 if (TT.size() >= 7 && TT[0] == 'x' && TT[1] == '8' && TT[2] == '6' &&
30 TT[3] == '_' && TT[4] == '6' && TT[5] == '4' && TT[6] == '-')
31 return 20;
32
33 return 0;
34 }
14 Target llvm::TheX86_32Target, llvm::TheX86_64Target;
3515
3616 extern "C" void LLVMInitializeX86TargetInfo() {
37 TargetRegistry::RegisterTarget(TheX86_32Target, "x86",
38 "32-bit X86: Pentium-Pro and above",
39 &X86_32_TripleMatchQuality,
40 /*HasJIT=*/true);
17 RegisterTarget
18 X(TheX86_32Target, "x86", "32-bit X86: Pentium-Pro and above");
4119
42 TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
43 "64-bit X86: EM64T and AMD64",
44 &X86_64_TripleMatchQuality,
45 /*HasJIT=*/true);
20 RegisterTarget
21 Y(TheX86_64Target, "x86-64", "64-bit X86: EM64T and AMD64");
4622 }
1313
1414 Target llvm::TheXCoreTarget;
1515
16 static unsigned XCore_TripleMatchQuality(const std::string &TT) {
17 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
18 return 20;
19
20 return 0;
16 extern "C" void LLVMInitializeXCoreTargetInfo() {
17 RegisterTarget X(TheXCoreTarget, "xcore", "XCore");
2118 }
22
23 extern "C" void LLVMInitializeXCoreTargetInfo() {
24 TargetRegistry::RegisterTarget(TheXCoreTarget, "xcore",
25 "XCore",
26 &XCore_TripleMatchQuality);
27 }
3838 cl::value_desc("directory"), cl::Prefix);
3939
4040 static cl::opt
41 Triple("triple", cl::desc("Target triple to assemble for,"
41 TripleName("triple", cl::desc("Target triple to assemble for,"
4242 "see -version for available targets"),
4343 cl::init(LLVM_HOSTTRIPLE));
4444
146146 // Get the target specific parser.
147147 std::string Error;
148148 const Target *TheTarget =
149 TargetRegistry::lookupTarget(Triple,
149 TargetRegistry::lookupTarget(TripleName,
150150 /*FallbackToHost=*/true,
151151 /*RequireJIT=*/false,
152152 Error);
153153 if (TheTarget == 0) {
154 errs() << ProgName << ": error: unable to get target for '" << Triple
154 errs() << ProgName << ": error: unable to get target for '" << TripleName
155155 << "', see --version and --triple.\n";
156156 return 1;
157157 }