Factor commonality in triple match routines into helper template for registering
authorDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 05:03:33 +0000 (05:03 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 26 Jul 2009 05:03:33 +0000 (05:03 +0000)
classes, and migrate existing targets over.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77126 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/llvm/Target/TargetRegistry.h
lib/Target/ARM/TargetInfo/ARMTargetInfo.cpp
lib/Target/Alpha/TargetInfo/AlphaTargetInfo.cpp
lib/Target/CBackend/TargetInfo/CBackendTargetInfo.cpp
lib/Target/CellSPU/TargetInfo/CellSPUTargetInfo.cpp
lib/Target/MSP430/TargetInfo/MSP430TargetInfo.cpp
lib/Target/Mips/TargetInfo/MipsTargetInfo.cpp
lib/Target/PIC16/TargetInfo/PIC16TargetInfo.cpp
lib/Target/PowerPC/TargetInfo/PowerPCTargetInfo.cpp
lib/Target/Sparc/TargetInfo/SparcTargetInfo.cpp
lib/Target/SystemZ/TargetInfo/SystemZTargetInfo.cpp
lib/Target/X86/TargetInfo/X86TargetInfo.cpp
lib/Target/XCore/TargetInfo/XCoreTargetInfo.cpp
tools/llvm-mc/llvm-mc.cpp

index a21618664567db04b033fd66eb041496edaf585f..9c651f2ae1e281346f308e6a60d36583ca683484 100644 (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;
     }
   };
 
index a975a1c6e9027f19e8957d0fea3b5a3ab8b7dfaa..163a0a987584995e5f0b6c46860e2e463fbdf0ae 100644 (file)
 #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");
 }
index 1e4db94ef0d359bdf32b3d849e821177faa6d604..f7099b9ae975367f36e90915fbda41519dbdbca0 100644 (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]");
 }
index c30c84d069fcfd09349732ba7b438b90f8c37d2f..f7e8ff254848e512aeb9c7403ece6e80f33b4224 100644 (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");
 }
index ea3b8f9059c0609f833a64dca212ae3f2568c08d..049ea236e99229a258c74f086fd12a13fd98b0ba 100644 (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]");
 }
index e2a71238d941f0fdd08882b2f79a4d2e3d4b68a1..f9ca5c49c979016d3e008f8619d30078c6160b1b 100644 (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]");
 }
index 4f075456032d3fa48b5151b740449edd71cc6117..cc3d61e4e71d38acb3758b3d27c61940957ce431 100644 (file)
 #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");
 }
index 87341b20e219fa13d27f898662db4c62dd420573..46cc81967ebdd3d59e972d097a8d942c059a3037 100644 (file)
 #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]");
 }
index 7fc73c139a12575bd09707a8e8d5678e2dbd7d23..ad607d0ade6abfaaae35b91fd0cfa14530b8edd9 100644 (file)
 #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");
 }
index 451a86419b5bedb56a8acb5d0d15f385adb62635..75200ab3ebf47753115354f95305d249ae9eec2e 100644 (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");
 }
index e063a911d0d80312dab4bd0169ed13a2763a8678..8272b1188201cce7970252223d81739e61ef12d6 100644 (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");
 }
index d371bced71f61757eee01085dafa8e3759c282bd..08d4d84f8a8adbd3c6dcbc22f0f727bff60adab7 100644 (file)
 #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");
 }
index 17acb3266f8847c3d0054cdb1e720acd22ff1cfa..7aa8965c4ac68574180d97cb6768673bd5fbe656 100644 (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");
 }
index 5212ab1936eb4ca214788be507d18d3027088b6c..dcbe47454af36ca4e54b7bf645f59da09b7d1797 100644 (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;
   }