1 //===--- SystemZ.cpp - SystemZ Helpers for Tools ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #include "clang/Config/config.h"
11 #include "clang/Driver/DriverDiagnostic.h"
12 #include "clang/Driver/Options.h"
13 #include "llvm/Option/ArgList.h"
14 #include "llvm/TargetParser/Host.h"
16 using namespace clang::driver
;
17 using namespace clang::driver::tools
;
18 using namespace clang
;
19 using namespace llvm::opt
;
21 systemz::FloatABI
systemz::getSystemZFloatABI(const Driver
&D
,
22 const ArgList
&Args
) {
23 // Hard float is the default.
24 systemz::FloatABI ABI
= systemz::FloatABI::Hard
;
25 if (Args
.hasArg(options::OPT_mfloat_abi_EQ
))
26 D
.Diag(diag::err_drv_unsupported_opt
)
27 << Args
.getLastArg(options::OPT_mfloat_abi_EQ
)->getAsString(Args
);
29 if (Arg
*A
= Args
.getLastArg(clang::driver::options::OPT_msoft_float
,
30 options::OPT_mhard_float
))
31 if (A
->getOption().matches(clang::driver::options::OPT_msoft_float
))
32 ABI
= systemz::FloatABI::Soft
;
37 std::string
systemz::getSystemZTargetCPU(const ArgList
&Args
,
38 const llvm::Triple
&T
) {
39 if (const Arg
*A
= Args
.getLastArg(clang::driver::options::OPT_march_EQ
)) {
40 llvm::StringRef CPUName
= A
->getValue();
42 if (CPUName
== "native") {
43 std::string CPU
= std::string(llvm::sys::getHostCPUName());
44 if (!CPU
.empty() && CPU
!= "generic")
50 return std::string(CPUName
);
54 return CLANG_SYSTEMZ_DEFAULT_ARCH
;
57 void systemz::getSystemZTargetFeatures(const Driver
&D
, const ArgList
&Args
,
58 std::vector
<llvm::StringRef
> &Features
) {
59 // -m(no-)htm overrides use of the transactional-execution facility.
60 if (Arg
*A
= Args
.getLastArg(options::OPT_mhtm
, options::OPT_mno_htm
)) {
61 if (A
->getOption().matches(options::OPT_mhtm
))
62 Features
.push_back("+transactional-execution");
64 Features
.push_back("-transactional-execution");
66 // -m(no-)vx overrides use of the vector facility.
67 if (Arg
*A
= Args
.getLastArg(options::OPT_mvx
, options::OPT_mno_vx
)) {
68 if (A
->getOption().matches(options::OPT_mvx
))
69 Features
.push_back("+vector");
71 Features
.push_back("-vector");
74 systemz::FloatABI FloatABI
= systemz::getSystemZFloatABI(D
, Args
);
75 if (FloatABI
== systemz::FloatABI::Soft
)
76 Features
.push_back("+soft-float");
78 if (const Arg
*A
= Args
.getLastArg(options::OPT_munaligned_symbols
,
79 options::OPT_mno_unaligned_symbols
)) {
80 if (A
->getOption().matches(options::OPT_munaligned_symbols
))
81 Features
.push_back("+unaligned-symbols");
83 Features
.push_back("-unaligned-symbols");