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/Config/config.h" |
11 | #include "clang/Driver/Options.h" |
12 | #include "llvm/Option/ArgList.h" |
13 | #include "llvm/TargetParser/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::DiagID: 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::ID: OPT_msoft_float)) |
31 | ABI = systemz::FloatABI::Soft; |
32 | |
33 | return ABI; |
34 | } |
35 | |
36 | std::string systemz::getSystemZTargetCPU(const ArgList &Args, |
37 | const llvm::Triple &T) { |
38 | if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { |
39 | llvm::StringRef CPUName = A->getValue(); |
40 | |
41 | if (CPUName == "native" ) { |
42 | std::string CPU = std::string(llvm::sys::getHostCPUName()); |
43 | if (!CPU.empty() && CPU != "generic" ) |
44 | return CPU; |
45 | else |
46 | return "" ; |
47 | } |
48 | |
49 | return std::string(CPUName); |
50 | } |
51 | if (T.isOSzOS()) |
52 | return "zEC12" ; |
53 | return CLANG_SYSTEMZ_DEFAULT_ARCH; |
54 | } |
55 | |
56 | void systemz::getSystemZTargetFeatures(const Driver &D, const ArgList &Args, |
57 | std::vector<llvm::StringRef> &Features) { |
58 | // -m(no-)htm overrides use of the transactional-execution facility. |
59 | if (Arg *A = Args.getLastArg(options::OPT_mhtm, options::OPT_mno_htm)) { |
60 | if (A->getOption().matches(options::ID: OPT_mhtm)) |
61 | Features.push_back(x: "+transactional-execution" ); |
62 | else |
63 | Features.push_back(x: "-transactional-execution" ); |
64 | } |
65 | // -m(no-)vx overrides use of the vector facility. |
66 | if (Arg *A = Args.getLastArg(options::OPT_mvx, options::OPT_mno_vx)) { |
67 | if (A->getOption().matches(options::ID: OPT_mvx)) |
68 | Features.push_back(x: "+vector" ); |
69 | else |
70 | Features.push_back(x: "-vector" ); |
71 | } |
72 | |
73 | systemz::FloatABI FloatABI = systemz::getSystemZFloatABI(D, Args); |
74 | if (FloatABI == systemz::FloatABI::Soft) |
75 | Features.push_back(x: "+soft-float" ); |
76 | |
77 | if (const Arg *A = Args.getLastArg(options::OPT_munaligned_symbols, |
78 | options::OPT_mno_unaligned_symbols)) { |
79 | if (A->getOption().matches(options::ID: OPT_munaligned_symbols)) |
80 | Features.push_back(x: "+unaligned-symbols" ); |
81 | else |
82 | Features.push_back(x: "-unaligned-symbols" ); |
83 | } |
84 | } |
85 | |