[Driver][Mips] If ABI name is not provided deduce it from the target triple
authorSimon Atanasyan <simon@atanasyan.com>
Wed, 2 Jul 2014 13:20:36 +0000 (13:20 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Wed, 2 Jul 2014 13:20:36 +0000 (13:20 +0000)
not from the CPU name. This approach is closer to the method used by gcc driver.

llvm-svn: 212176

clang/lib/Driver/Tools.cpp
clang/test/Driver/mips-abi.c

index 35affab..acb16bf 100644 (file)
@@ -947,22 +947,22 @@ static void getMipsCPUAndABI(const ArgList &Args,
     }
   }
 
-  if (!ABIName.empty()) {
+  if (ABIName.empty()) {
+    // Deduce ABI name from the target triple.
+    if (Triple.getArch() == llvm::Triple::mips ||
+        Triple.getArch() == llvm::Triple::mipsel)
+      ABIName = "o32";
+    else
+      ABIName = "n64";
+  }
+
+  if (CPUName.empty()) {
     // Deduce CPU name from ABI name.
     CPUName = llvm::StringSwitch<const char *>(ABIName)
       .Cases("o32", "eabi", DefMips32CPU)
       .Cases("n32", "n64", DefMips64CPU)
       .Default("");
   }
-  else if (!CPUName.empty()) {
-    // Deduce ABI name from CPU name.
-    ABIName = llvm::StringSwitch<const char *>(CPUName)
-      .Cases("mips32", "mips32r2", "o32")
-      .Cases("mips64", "mips64r2", "n64")
-      .Default("");
-  }
-
-  // FIXME: Warn on inconsistent cpu and abi usage.
 }
 
 // Convert ABI name to the GNU tools acceptable variant.
index ac86abe..8858e2b 100644 (file)
@@ -1,5 +1,15 @@
 // Check passing Mips ABI options to the backend.
 //
+// RUN: %clang -target mips-linux-gnu -### -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-DEF %s
+// MIPS-DEF: "-target-cpu" "mips32r2"
+// MIPS-DEF: "-target-abi" "o32"
+//
+// RUN: %clang -target mips64-linux-gnu -### -c %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS64-DEF %s
+// MIPS64-DEF: "-target-cpu" "mips64r2"
+// MIPS64-DEF: "-target-abi" "n64"
+//
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN:        -mabi=32 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-ABI-32 %s
 // RUN:        -mabi=unknown 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-ABI-UNKNOWN %s
 // MIPS-ABI-UNKNOWN: error: unknown target ABI 'unknown'
+//
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:        -march=mips32 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-32 %s
+// MIPS-ARCH-32: "-target-cpu" "mips32"
+// MIPS-ARCH-32: "-target-abi" "o32"
+//
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:        -march=mips32r2 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-32R2 %s
+// MIPS-ARCH-32R2: "-target-cpu" "mips32r2"
+// MIPS-ARCH-32R2: "-target-abi" "o32"
+//
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:        -march=mips64 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-3264 %s
+// MIPS-ARCH-3264: "-target-cpu" "mips64"
+// MIPS-ARCH-3264: "-target-abi" "o32"
+//
+// RUN: %clang -target mips64-linux-gnu -### -c %s \
+// RUN:        -march=mips64 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-64 %s
+// MIPS-ARCH-64: "-target-cpu" "mips64"
+// MIPS-ARCH-64: "-target-abi" "n64"
+//
+// RUN: %clang -target mips64-linux-gnu -### -c %s \
+// RUN:        -march=mips64r2 2>&1 \
+// RUN:   | FileCheck -check-prefix=MIPS-ARCH-64R2 %s
+// MIPS-ARCH-64R2: "-target-cpu" "mips64r2"
+// MIPS-ARCH-64R2: "-target-abi" "n64"