r344603 - [driver][mips] Adjust target triple's environment accordingly to provided ABI name

Simon Atanasyan via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 16 03:19:06 PDT 2018


Author: atanasyan
Date: Tue Oct 16 03:19:06 2018
New Revision: 344603

URL: http://llvm.org/viewvc/llvm-project?rev=344603&view=rev
Log:
[driver][mips] Adjust target triple's environment accordingly to provided ABI name

For MIPS we need to adjust not only architecture name accordingly to ABI
provided by the `-mabi` command line option, but also modify triple's
environment. For example, for `mips-linux-gnu` triple and `-mabi=n32`
option a correct final triple is `mips64-linux-gnuabin32`.

Modified:
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/test/Driver/mips-abi.c

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=344603&r1=344602&r2=344603&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Oct 16 03:19:06 2018
@@ -486,12 +486,25 @@ static llvm::Triple computeTargetTriple(
   // If target is MIPS adjust the target triple
   // accordingly to provided ABI name.
   A = Args.getLastArg(options::OPT_mabi_EQ);
-  if (A && Target.isMIPS())
-    Target = llvm::StringSwitch<llvm::Triple>(A->getValue())
-                 .Case("32", Target.get32BitArchVariant())
-                 .Case("n32", Target.get64BitArchVariant())
-                 .Case("64", Target.get64BitArchVariant())
-                 .Default(Target);
+  if (A && Target.isMIPS()) {
+    StringRef ABIName = A->getValue();
+    if (ABIName == "32") {
+      Target = Target.get32BitArchVariant();
+      if (Target.getEnvironment() == llvm::Triple::GNUABI64 ||
+          Target.getEnvironment() == llvm::Triple::GNUABIN32)
+        Target.setEnvironment(llvm::Triple::GNU);
+    } else if (ABIName == "n32") {
+      Target = Target.get64BitArchVariant();
+      if (Target.getEnvironment() == llvm::Triple::GNU ||
+          Target.getEnvironment() == llvm::Triple::GNUABI64)
+        Target.setEnvironment(llvm::Triple::GNUABIN32);
+    } else if (ABIName == "64") {
+      Target = Target.get64BitArchVariant();
+      if (Target.getEnvironment() == llvm::Triple::GNU ||
+          Target.getEnvironment() == llvm::Triple::GNUABIN32)
+        Target.setEnvironment(llvm::Triple::GNUABI64);
+    }
+  }
 
   return Target;
 }

Modified: cfe/trunk/test/Driver/mips-abi.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-abi.c?rev=344603&r1=344602&r2=344603&view=diff
==============================================================================
--- cfe/trunk/test/Driver/mips-abi.c (original)
+++ cfe/trunk/test/Driver/mips-abi.c Tue Oct 16 03:19:06 2018
@@ -164,7 +164,7 @@
 // MIPS-ARCH-UNKNOWN: error: unknown target CPU 'unknown'
 
 // Check adjusting of target triple accordingly to `-mabi` option.
-// RUN: %clang -target mips64-linux-gnu -mabi=32 -### %s 2>&1 \
+// RUN: %clang -target mips64-linux-gnuabi64 -mabi=32 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=TARGET-O32 %s
 // TARGET-O32: "-triple" "mips-unknown-linux-gnu"
 // TARGET-O32: "-target-cpu" "mips32r2"
@@ -174,7 +174,7 @@
 
 // RUN: %clang -target mips-linux-gnu -mabi=n32 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=TARGET-N32 %s
-// TARGET-N32: "-triple" "mips64-unknown-linux-gnu"
+// TARGET-N32: "-triple" "mips64-unknown-linux-gnuabin32"
 // TARGET-N32: "-target-cpu" "mips64r2"
 // TARGET-N32: "-target-abi" "n32"
 // TARGET-N32: ld{{(.exe)?}}"
@@ -182,7 +182,7 @@
 
 // RUN: %clang -target mips-linux-gnu -mabi=64 -### %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=TARGET-N64 %s
-// TARGET-N64: "-triple" "mips64-unknown-linux-gnu"
+// TARGET-N64: "-triple" "mips64-unknown-linux-gnuabi64"
 // TARGET-N64: "-target-cpu" "mips64r2"
 // TARGET-N64: "-target-abi" "n64"
 // TARGET-N64: ld{{(.exe)?}}"




More information about the cfe-commits mailing list