1//===--- SystemZ.cpp - SystemZ Helpers for Tools ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "SystemZ.h"
10#include "clang/Driver/Options.h"
11#include "llvm/Option/ArgList.h"
12#include "llvm/Support/Host.h"
13
14using namespace clang::driver;
15using namespace clang::driver::tools;
16using namespace clang;
17using namespace llvm::opt;
18
19std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
20  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
21    llvm::StringRef CPUName = A->getValue();
22
23    if (CPUName == "native") {
24      std::string CPU = llvm::sys::getHostCPUName();
25      if (!CPU.empty() && CPU != "generic")
26        return CPU;
27      else
28        return "";
29    }
30
31    return CPUName;
32  }
33  return "z10";
34}
35
36void systemz::getSystemZTargetFeatures(const ArgList &Args,
37                                       std::vector<llvm::StringRef> &Features) {
38  // -m(no-)htm overrides use of the transactional-execution facility.
39  if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) {
40    if (A->getOption().matches(options::OPT_mhtm))
41      Features.push_back("+transactional-execution");
42    else
43      Features.push_back("-transactional-execution");
44  }
45  // -m(no-)vx overrides use of the vector facility.
46  if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) {
47    if (A->getOption().matches(options::OPT_mvx))
48      Features.push_back("+vector");
49    else
50      Features.push_back("-vector");
51  }
52}
53