Using ARMTargetParser in Clang

This is a starting point for using the TargetParser in Clang, in a simple
enough part of the code that can be used without disrupting the crazy
platform support that we need to be compatible with other toolchains.

Also adding a few FIXME on obvious places that need replacing, but those
cases will indeed break a few of the platform assumptions, as arch/cpu names
change multiple times in the driver.

Finally, I'm changing the "neon-vfpv3" behaviour to match standard NEON, since
-mfpu=neon implies vfpv3 by default in both Clang and LLVM. That option
string is still supported as an alias to "neon".

llvm-svn: 236901
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 88e4221..186f08e 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -543,75 +544,77 @@
                               std::vector<const char *> &Features) {
   StringRef FPU = A->getValue();
 
-  // Set the target features based on the FPU.
-  if (FPU == "fpa" || FPU == "fpe2" || FPU == "fpe3" || FPU == "maverick") {
-    // Disable any default FPU support.
-    Features.push_back("-vfp2");
-    Features.push_back("-vfp3");
-    Features.push_back("-neon");
-  } else if (FPU == "vfp") {
-    Features.push_back("+vfp2");
-    Features.push_back("-neon");
-  } else if (FPU == "vfp3-d16" || FPU == "vfpv3-d16") {
-    Features.push_back("+vfp3");
-    Features.push_back("+d16");
-    Features.push_back("-neon");
-  } else if (FPU == "vfp3" || FPU == "vfpv3") {
-    Features.push_back("+vfp3");
-    Features.push_back("-neon");
-  } else if (FPU == "vfp4-d16" || FPU == "vfpv4-d16") {
-    Features.push_back("+vfp4");
-    Features.push_back("+d16");
-    Features.push_back("-neon");
-  } else if (FPU == "vfp4" || FPU == "vfpv4") {
-    Features.push_back("+vfp4");
-    Features.push_back("-neon");
-  } else if (FPU == "fp4-sp-d16" || FPU == "fpv4-sp-d16") {
-    Features.push_back("+vfp4");
-    Features.push_back("+d16");
-    Features.push_back("+fp-only-sp");
-    Features.push_back("-neon");
-  } else if (FPU == "fp5-sp-d16" || FPU == "fpv5-sp-d16") {
-    Features.push_back("+fp-armv8");
-    Features.push_back("+fp-only-sp");
-    Features.push_back("+d16");
-    Features.push_back("-neon");
-    Features.push_back("-crypto");
-  } else if (FPU == "fp5-dp-d16" || FPU == "fpv5-dp-d16" ||
-             FPU == "fp5-d16" || FPU == "fpv5-d16") {
-    Features.push_back("+fp-armv8");
-    Features.push_back("+d16");
-    Features.push_back("-neon");
-    Features.push_back("-crypto");
-  } else if (FPU == "fp-armv8") {
-    Features.push_back("+fp-armv8");
-    Features.push_back("-neon");
-    Features.push_back("-crypto");
-  } else if (FPU == "neon-fp-armv8") {
-    Features.push_back("+fp-armv8");
-    Features.push_back("+neon");
-    Features.push_back("-crypto");
-  } else if (FPU == "crypto-neon-fp-armv8") {
-    Features.push_back("+fp-armv8");
-    Features.push_back("+neon");
-    Features.push_back("+crypto");
-  } else if (FPU == "neon") {
-    Features.push_back("+neon");
-  } else if (FPU == "neon-vfpv3") {
-    Features.push_back("+vfp3");
-    Features.push_back("+neon");
-  } else if (FPU == "neon-vfpv4") {
-    Features.push_back("+neon");
-    Features.push_back("+vfp4");
-  } else if (FPU == "none") {
+  // FIXME: Why does "none" disable more than "invalid"?
+  if (FPU == "none") {
     Features.push_back("-vfp2");
     Features.push_back("-vfp3");
     Features.push_back("-vfp4");
     Features.push_back("-fp-armv8");
     Features.push_back("-crypto");
     Features.push_back("-neon");
-  } else
+    return;
+  }
+
+  // FIXME: Make sure we differentiate sp-only.
+  if (FPU.find("-sp-") != StringRef::npos) {
+    Features.push_back("+fp-only-sp");
+  }
+
+  // All other FPU types, valid or invalid.
+  switch(llvm::ARMTargetParser::parseFPU(FPU)) {
+  case llvm::ARM::INVALID_FPU:
+  case llvm::ARM::SOFTVFP:
+    Features.push_back("-vfp2");
+    Features.push_back("-vfp3");
+    Features.push_back("-neon");
+    break;
+  case llvm::ARM::VFP:
+  case llvm::ARM::VFPV2:
+    Features.push_back("+vfp2");
+    Features.push_back("-neon");
+    break;
+  case llvm::ARM::VFPV3_D16:
+    Features.push_back("+d16");
+    // fall-through
+  case llvm::ARM::VFPV3:
+    Features.push_back("+vfp3");
+    Features.push_back("-neon");
+    break;
+  case llvm::ARM::VFPV4_D16:
+    Features.push_back("+d16");
+    // fall-through
+  case llvm::ARM::VFPV4:
+    Features.push_back("+vfp4");
+    Features.push_back("-neon");
+    break;
+  case llvm::ARM::FPV5_D16:
+    Features.push_back("+d16");
+    // fall-through
+  case llvm::ARM::FP_ARMV8:
+    Features.push_back("+fp-armv8");
+    Features.push_back("-neon");
+    Features.push_back("-crypto");
+    break;
+  case llvm::ARM::NEON_FP_ARMV8:
+    Features.push_back("+fp-armv8");
+    Features.push_back("+neon");
+    Features.push_back("-crypto");
+    break;
+  case llvm::ARM::CRYPTO_NEON_FP_ARMV8:
+    Features.push_back("+fp-armv8");
+    Features.push_back("+neon");
+    Features.push_back("+crypto");
+    break;
+  case llvm::ARM::NEON:
+    Features.push_back("+neon");
+    break;
+  case llvm::ARM::NEON_VFPV4:
+    Features.push_back("+neon");
+    Features.push_back("+vfp4");
+    break;
+  default:
     D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
+  }
 }
 
 // Select the float ABI as determined by -msoft-float, -mhard-float, and
@@ -5657,6 +5660,7 @@
 //
 // FIXME: This is redundant with -mcpu, why does LLVM use this.
 // FIXME: tblgen this, or kill it!
+// FIXME: Use ARMTargetParser.
 const char *arm::getLLVMArchSuffixForARM(StringRef CPU) {
   return llvm::StringSwitch<const char *>(CPU)
     .Case("strongarm", "v4")