xref: /openbsd-src/gnu/llvm/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp (revision ec727ea710c91afd8ce4f788c5aaa8482b7b69b2)
1e5dd7070Spatrick //===--- SystemZ.cpp - SystemZ Helpers for Tools ----------------*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick 
9e5dd7070Spatrick #include "SystemZ.h"
10*ec727ea7Spatrick #include "clang/Config/config.h"
11*ec727ea7Spatrick #include "clang/Driver/DriverDiagnostic.h"
12e5dd7070Spatrick #include "clang/Driver/Options.h"
13e5dd7070Spatrick #include "llvm/Option/ArgList.h"
14e5dd7070Spatrick #include "llvm/Support/Host.h"
15e5dd7070Spatrick 
16e5dd7070Spatrick using namespace clang::driver;
17e5dd7070Spatrick using namespace clang::driver::tools;
18e5dd7070Spatrick using namespace clang;
19e5dd7070Spatrick using namespace llvm::opt;
20e5dd7070Spatrick 
getSystemZFloatABI(const Driver & D,const ArgList & Args)21*ec727ea7Spatrick systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
22*ec727ea7Spatrick                                               const ArgList &Args) {
23*ec727ea7Spatrick   // Hard float is the default.
24*ec727ea7Spatrick   systemz::FloatABI ABI = systemz::FloatABI::Hard;
25*ec727ea7Spatrick   if (Args.hasArg(options::OPT_mfloat_abi_EQ))
26*ec727ea7Spatrick     D.Diag(diag::err_drv_unsupported_opt)
27*ec727ea7Spatrick       << Args.getLastArg(options::OPT_mfloat_abi_EQ)->getAsString(Args);
28*ec727ea7Spatrick 
29*ec727ea7Spatrick   if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float,
30*ec727ea7Spatrick                                options::OPT_mhard_float))
31*ec727ea7Spatrick     if (A->getOption().matches(clang::driver::options::OPT_msoft_float))
32*ec727ea7Spatrick       ABI = systemz::FloatABI::Soft;
33*ec727ea7Spatrick 
34*ec727ea7Spatrick   return ABI;
35*ec727ea7Spatrick }
36*ec727ea7Spatrick 
getSystemZTargetCPU(const ArgList & Args)37e5dd7070Spatrick std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
38e5dd7070Spatrick   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
39e5dd7070Spatrick     llvm::StringRef CPUName = A->getValue();
40e5dd7070Spatrick 
41e5dd7070Spatrick     if (CPUName == "native") {
42*ec727ea7Spatrick       std::string CPU = std::string(llvm::sys::getHostCPUName());
43e5dd7070Spatrick       if (!CPU.empty() && CPU != "generic")
44e5dd7070Spatrick         return CPU;
45e5dd7070Spatrick       else
46e5dd7070Spatrick         return "";
47e5dd7070Spatrick     }
48e5dd7070Spatrick 
49*ec727ea7Spatrick     return std::string(CPUName);
50e5dd7070Spatrick   }
51*ec727ea7Spatrick   return CLANG_SYSTEMZ_DEFAULT_ARCH;
52e5dd7070Spatrick }
53e5dd7070Spatrick 
getSystemZTargetFeatures(const Driver & D,const ArgList & Args,std::vector<llvm::StringRef> & Features)54*ec727ea7Spatrick void systemz::getSystemZTargetFeatures(const Driver &D, const ArgList &Args,
55e5dd7070Spatrick                                        std::vector<llvm::StringRef> &Features) {
56e5dd7070Spatrick   // -m(no-)htm overrides use of the transactional-execution facility.
57e5dd7070Spatrick   if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) {
58e5dd7070Spatrick     if (A->getOption().matches(options::OPT_mhtm))
59e5dd7070Spatrick       Features.push_back("+transactional-execution");
60e5dd7070Spatrick     else
61e5dd7070Spatrick       Features.push_back("-transactional-execution");
62e5dd7070Spatrick   }
63e5dd7070Spatrick   // -m(no-)vx overrides use of the vector facility.
64e5dd7070Spatrick   if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) {
65e5dd7070Spatrick     if (A->getOption().matches(options::OPT_mvx))
66e5dd7070Spatrick       Features.push_back("+vector");
67e5dd7070Spatrick     else
68e5dd7070Spatrick       Features.push_back("-vector");
69e5dd7070Spatrick   }
70*ec727ea7Spatrick 
71*ec727ea7Spatrick   systemz::FloatABI FloatABI = systemz::getSystemZFloatABI(D, Args);
72*ec727ea7Spatrick   if (FloatABI == systemz::FloatABI::Soft)
73*ec727ea7Spatrick     Features.push_back("+soft-float");
74e5dd7070Spatrick }
75