]> granicus.if.org Git - clang/commitdiff
[RISCV] Make -march=rv{32,64}gc the default in RISC-V Linux
authorRoger Ferrer Ibanez <rofirrim@gmail.com>
Tue, 10 Sep 2019 08:16:24 +0000 (08:16 +0000)
committerRoger Ferrer Ibanez <rofirrim@gmail.com>
Tue, 10 Sep 2019 08:16:24 +0000 (08:16 +0000)
This is the logical follow-up of D65634.

Differential Revision: https://reviews.llvm.org/D66003

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

lib/Driver/ToolChains/Arch/RISCV.cpp
lib/Driver/ToolChains/Arch/RISCV.h
lib/Driver/ToolChains/Clang.cpp
test/Driver/riscv-features.c

index 0ba708ef746b197d9d06394aa0f2c12800d733d3..624788a5874e3bde801c215192cf663843577da8 100644 (file)
@@ -12,6 +12,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
 #include "ToolChains/CommonArgs.h"
@@ -353,14 +354,18 @@ static bool getArchFeatures(const Driver &D, StringRef MArch,
   return true;
 }
 
-void riscv::getRISCVTargetFeatures(const Driver &D, const ArgList &Args,
+void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                                   const ArgList &Args,
                                    std::vector<StringRef> &Features) {
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
-    StringRef MArch = A->getValue();
-
-    if (!getArchFeatures(D, MArch, Features, Args))
-      return;
-  }
+  llvm::Optional<StringRef> MArch;
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
+    MArch = A->getValue();
+  else if (Triple.getOS() == llvm::Triple::Linux)
+    // RISC-V Linux defaults to rv{32,64}gc.
+    MArch = Triple.getArch() == llvm::Triple::riscv32 ? "rv32gc" : "rv64gc";
+
+  if (MArch.hasValue() && !getArchFeatures(D, *MArch, Features, Args))
+    return;
 
   // -mrelax is default, unless -mno-relax is specified.
   if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
index 443526900aae00ae7cfa82e210c4119a3bc07ed0..10eaf3c897b68a93636d06d87fccb3bee984e07b 100644 (file)
@@ -19,7 +19,8 @@ namespace clang {
 namespace driver {
 namespace tools {
 namespace riscv {
-void getRISCVTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
+void getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                            const llvm::opt::ArgList &Args,
                             std::vector<llvm::StringRef> &Features);
 StringRef getRISCVABI(const llvm::opt::ArgList &Args,
                       const llvm::Triple &Triple);
index 92c76d3be34c6845904fc3519194779c47affa90..ce50efc54f9b1b3988fac9dc2e2959fb6cb1ba60 100644 (file)
@@ -336,7 +336,7 @@ static void getTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple,
     break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-    riscv::getRISCVTargetFeatures(D, Args, Features);
+    riscv::getRISCVTargetFeatures(D, Triple, Args, Features);
     break;
   case llvm::Triple::systemz:
     systemz::getSystemZTargetFeatures(Args, Features);
index 44fb59b2f92168464137510c34a5b256a3f070c6..2f2ae51e4716dd905edb64c18af1bbb5eb8cefed 100644 (file)
 
 // SAVE-RESTORE: warning: the clang compiler does not support '-msave-restore'
 // NO-SAVE-RESTORE-NOT: warning: the clang compiler does not support
-// DEFAULT-NOT: warning: the clang compiler does not support
\ No newline at end of file
+// DEFAULT-NOT: warning: the clang compiler does not support
+
+// RUN: %clang -target riscv32-linux -### %s -fsyntax-only 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
+// RUN: %clang -target riscv64-linux -### %s -fsyntax-only 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=DEFAULT-LINUX
+
+// DEFAULT-LINUX: "-target-feature" "+m"
+// DEFAULT-LINUX-SAME: "-target-feature" "+a"
+// DEFAULT-LINUX-SAME: "-target-feature" "+f"
+// DEFAULT-LINUX-SAME: "-target-feature" "+d"
+// DEFAULT-LINUX-SAME: "-target-feature" "+c"