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/DriverDiagnostic.h"
11 #include "clang/Driver/Options.h"
12 #include "llvm/Option/ArgList.h"
13 #include "llvm/Support/Host.h"
14 
15 using namespace clang::driver;
16 using namespace clang::driver::tools;
17 using namespace clang;
18 using namespace llvm::opt;
19 
20 systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
21                                               const ArgList &Args) {
22   // Hard float is the default.
23   systemz::FloatABI ABI = systemz::FloatABI::Hard;
24   if (Args.hasArg(options::OPT_mfloat_abi_EQ))
25     D.Diag(diag::err_drv_unsupported_opt)
26       << Args.getLastArg(options::OPT_mfloat_abi_EQ)->getAsString(Args);
27 
28   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
29                                options::OPT_mhard_float))
30     if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
31       ABI = systemz::FloatABI::Soft;
32 
33   return ABI;
34 }
35 
36 std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
37   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
38     llvm::StringRef CPUName = A->getValue();
39 
40     if (CPUName == "native") {
41       std::string CPU = std::string(llvm::sys::getHostCPUName());
42       if (!CPU.empty() && CPU != "generic")
43         return CPU;
44       else
45         return "";
46     }
47 
48     return std::string(CPUName);
49   }
50   return "z10";
51 }
52 
53 void systemz::getSystemZTargetFeatures(const Driver &D, const ArgList &Args,
54                                        std::vector<llvm::StringRef> &Features) {
55   // -m(no-)htm overrides use of the transactional-execution facility.
56   if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) {
57     if (A->getOption().matches(options::OPT_mhtm))
58       Features.push_back("+transactional-execution");
59     else
60       Features.push_back("-transactional-execution");
61   }
62   // -m(no-)vx overrides use of the vector facility.
63   if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) {
64     if (A->getOption().matches(options::OPT_mvx))
65       Features.push_back("+vector");
66     else
67       Features.push_back("-vector");
68   }
69 
70   systemz::FloatABI FloatABI = systemz::getSystemZFloatABI(D, Args);
71   if (FloatABI == systemz::FloatABI::Soft)
72     Features.push_back("+soft-float");
73 }
74