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