Skip to content

Commit

Permalink
[clang][SystemZ] Add support for -march=native
Browse files Browse the repository at this point in the history
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 *.
  • Loading branch information
uweigand committed Dec 16, 2019
1 parent a0ff8cd commit 9f99aba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
18 changes: 15 additions & 3 deletions clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
Expand Up @@ -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";
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Arch/SystemZ.h
Expand Up @@ -11,14 +11,15 @@

#include "llvm/ADT/StringRef.h"
#include "llvm/Option/Option.h"
#include <string>
#include <vector>

namespace clang {
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);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Gnu.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9f99aba

Please sign in to comment.