[clang] 9f99aba - [clang][SystemZ] Add support for -march=native

Ulrich Weigand via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 07:13:05 PST 2019


Author: Ulrich Weigand
Date: 2019-12-16T16:11:32+01:00
New Revision: 9f99aba1cfeb603f368c45ef78ba9795bab16d47

URL: https://github.com/llvm/llvm-project/commit/9f99aba1cfeb603f368c45ef78ba9795bab16d47
DIFF: https://github.com/llvm/llvm-project/commit/9f99aba1cfeb603f368c45ef78ba9795bab16d47.diff

LOG: [clang][SystemZ] Add support for -march=native

Handle -march=native in systemz::getSystemZTargetCPU, similar to
how this is done on other platforms.  Also change the return type
to std::string instead of const char *.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
    clang/lib/Driver/ToolChains/Arch/SystemZ.h
    clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
index ca60b85cf8a0..2b77d59fdc66 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
@@ -9,15 +9,27 @@
 #include "SystemZ.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-const char *systemz::getSystemZTargetCPU(const ArgList &Args) {
-  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ))
-    return A->getValue();
+std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
+    llvm::StringRef CPUName = A->getValue();
+
+    if (CPUName == "native") {
+      std::string CPU = llvm::sys::getHostCPUName();
+      if (!CPU.empty() && CPU != "generic")
+        return CPU;
+      else
+        return "";
+    }
+
+    return CPUName;
+  }
   return "z10";
 }
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.h b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
index 11d77fa01cc8..77dcbc47be5c 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.h
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
@@ -11,6 +11,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Option/Option.h"
+#include <string>
 #include <vector>
 
 namespace clang {
@@ -18,7 +19,7 @@ namespace driver {
 namespace tools {
 namespace systemz {
 
-const char *getSystemZTargetCPU(const llvm::opt::ArgList &Args);
+std::string getSystemZTargetCPU(const llvm::opt::ArgList &Args);
 
 void getSystemZTargetFeatures(const llvm::opt::ArgList &Args,
                               std::vector<llvm::StringRef> &Features);

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 250e924fb84c..7c0bcdcaf074 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -862,7 +862,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
   case llvm::Triple::systemz: {
     // Always pass an -march option, since our default of z10 is later
     // than the GNU assembler's default.
-    StringRef CPUName = systemz::getSystemZTargetCPU(Args);
+    std::string CPUName = systemz::getSystemZTargetCPU(Args);
     CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
     break;
   }


        


More information about the cfe-commits mailing list