[Mips] Do not detect a used MIPS toolchain. Build a path suffix for FSF
toolchain first and check the path existence. If the path does not
exist build and check a path suffix for Code Sourcery toolchain.

llvm-svn: 195751
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
index b5f4c19..b9e97fd 100644
--- a/clang/lib/Driver/ToolChains.cpp
+++ b/clang/lib/Driver/ToolChains.cpp
@@ -1019,7 +1019,7 @@
 /// triple.
 Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(
     const Driver &D, const llvm::Triple &TargetTriple, const ArgList &Args)
-    : IsValid(false), D(D) {
+    : IsValid(false) {
   llvm::Triple BiarchVariantTriple =
       TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant()
                                  : TargetTriple.get32BitArchVariant();
@@ -1410,65 +1410,62 @@
   // /mips32
   //     /usr
   //       /lib  <= crt*.o files compiled with '-mips32'
-  //
-  // Unfortunately different toolchains use different and partially
-  // overlapped naming schemes. So we have to make a trick for detection
-  // of using toolchain. We lookup a path which unique for each toolchains.
 
-  bool IsMentorToolChain = hasCrtBeginObj(Path + "/mips16/soft-float");
-  bool IsFSFToolChain = hasCrtBeginObj(Path + "/mips32/mips16/sof");
+  // Check FSF Toolchain path
+  Suffix.clear();
+  if (TargetArch == llvm::Triple::mips ||
+      TargetArch == llvm::Triple::mipsel) {
+    if (isMicroMips(Args))
+      Suffix += "/micromips";
+    else if (isMips32r2(Args))
+      Suffix += "";
+    else
+      Suffix += "/mips32";
 
-  if (IsMentorToolChain && IsFSFToolChain)
-    D.Diag(diag::err_drv_unknown_toolchain);
-
-  if (IsMentorToolChain) {
     if (isMips16(Args))
       Suffix += "/mips16";
-    else if (isMicroMips(Args))
-      Suffix += "/micromips";
-
-    if (isSoftFloatABI(Args))
-      Suffix += "/soft-float";
-
-    if (TargetArch == llvm::Triple::mipsel ||
-        TargetArch == llvm::Triple::mips64el)
-      Suffix += "/el";
-  } else if (IsFSFToolChain) {
-    if (TargetArch == llvm::Triple::mips ||
-        TargetArch == llvm::Triple::mipsel) {
-      if (isMicroMips(Args))
-        Suffix += "/micromips";
-      else if (isMips32r2(Args))
-        Suffix += "";
-      else
-        Suffix += "/mips32";
-
-      if (isMips16(Args))
-        Suffix += "/mips16";
-    } else {
-      if (isMips64r2(Args))
-        Suffix += hasMipsN32ABIArg(Args) ? "/mips64r2" : "/mips64r2/64";
-      else
-        Suffix += hasMipsN32ABIArg(Args) ? "/mips64" : "/mips64/64";
-    }
-
-    if (TargetArch == llvm::Triple::mipsel ||
-        TargetArch == llvm::Triple::mips64el)
-      Suffix += "/el";
-
-    if (isSoftFloatABI(Args))
-      Suffix += "/sof";
-    else {
-      if (isMipsFP64(Args))
-        Suffix += "/fp64";
-
-      if (isMipsNan2008(Args))
-        Suffix += "/nan2008";
-    }
+  } else {
+    if (isMips64r2(Args))
+      Suffix += hasMipsN32ABIArg(Args) ? "/mips64r2" : "/mips64r2/64";
+    else
+      Suffix += hasMipsN32ABIArg(Args) ? "/mips64" : "/mips64/64";
   }
 
-  if (!hasCrtBeginObj(Path + Suffix))
-    Suffix.clear();
+  if (TargetArch == llvm::Triple::mipsel ||
+      TargetArch == llvm::Triple::mips64el)
+    Suffix += "/el";
+
+  if (isSoftFloatABI(Args))
+    Suffix += "/sof";
+  else {
+    if (isMipsFP64(Args))
+      Suffix += "/fp64";
+
+    if (isMipsNan2008(Args))
+      Suffix += "/nan2008";
+  }
+
+  if (hasCrtBeginObj(Path + Suffix))
+    return;
+
+  // Check Code Sourcery Toolchain path
+  Suffix.clear();
+  if (isMips16(Args))
+    Suffix += "/mips16";
+  else if (isMicroMips(Args))
+    Suffix += "/micromips";
+
+  if (isSoftFloatABI(Args))
+    Suffix += "/soft-float";
+
+  if (TargetArch == llvm::Triple::mipsel ||
+      TargetArch == llvm::Triple::mips64el)
+    Suffix += "/el";
+
+  if (hasCrtBeginObj(Path + Suffix))
+    return;
+
+  Suffix.clear();
 }
 
 void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(