Path: blob/main/contrib/llvm-project/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
35294 views
//===--- Sparc.cpp - Tools Implementations ----------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "Sparc.h"9#include "clang/Driver/Driver.h"10#include "clang/Driver/DriverDiagnostic.h"11#include "clang/Driver/Options.h"12#include "llvm/ADT/StringSwitch.h"13#include "llvm/Option/ArgList.h"14#include "llvm/TargetParser/Host.h"1516using namespace clang::driver;17using namespace clang::driver::tools;18using namespace clang;19using namespace llvm::opt;2021const char *sparc::getSparcAsmModeForCPU(StringRef Name,22const llvm::Triple &Triple) {23if (Triple.getArch() == llvm::Triple::sparcv9) {24const char *DefV9CPU;2526if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())27DefV9CPU = "-Av9a";28else29DefV9CPU = "-Av9";3031return llvm::StringSwitch<const char *>(Name)32.Case("niagara", "-Av9b")33.Case("niagara2", "-Av9b")34.Case("niagara3", "-Av9d")35.Case("niagara4", "-Av9d")36.Default(DefV9CPU);37} else {38return llvm::StringSwitch<const char *>(Name)39.Case("v8", "-Av8")40.Case("supersparc", "-Av8")41.Case("sparclite", "-Asparclite")42.Case("f934", "-Asparclite")43.Case("hypersparc", "-Av8")44.Case("sparclite86x", "-Asparclite")45.Case("sparclet", "-Asparclet")46.Case("tsc701", "-Asparclet")47.Case("v9", "-Av8plus")48.Case("ultrasparc", "-Av8plus")49.Case("ultrasparc3", "-Av8plus")50.Case("niagara", "-Av8plusb")51.Case("niagara2", "-Av8plusb")52.Case("niagara3", "-Av8plusd")53.Case("niagara4", "-Av8plusd")54.Case("ma2100", "-Aleon")55.Case("ma2150", "-Aleon")56.Case("ma2155", "-Aleon")57.Case("ma2450", "-Aleon")58.Case("ma2455", "-Aleon")59.Case("ma2x5x", "-Aleon")60.Case("ma2080", "-Aleon")61.Case("ma2085", "-Aleon")62.Case("ma2480", "-Aleon")63.Case("ma2485", "-Aleon")64.Case("ma2x8x", "-Aleon")65.Case("leon2", "-Av8")66.Case("at697e", "-Av8")67.Case("at697f", "-Av8")68.Case("leon3", "-Aleon")69.Case("ut699", "-Av8")70.Case("gr712rc", "-Aleon")71.Case("leon4", "-Aleon")72.Case("gr740", "-Aleon")73.Default("-Av8");74}75}7677sparc::FloatABI sparc::getSparcFloatABI(const Driver &D,78const ArgList &Args) {79sparc::FloatABI ABI = sparc::FloatABI::Invalid;80if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,81options::OPT_mhard_float, options::OPT_mfpu,82options::OPT_mfloat_abi_EQ)) {83if (A->getOption().matches(options::OPT_msoft_float) ||84A->getOption().matches(options::OPT_mno_fpu))85ABI = sparc::FloatABI::Soft;86else if (A->getOption().matches(options::OPT_mhard_float) ||87A->getOption().matches(options::OPT_mfpu))88ABI = sparc::FloatABI::Hard;89else {90ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())91.Case("soft", sparc::FloatABI::Soft)92.Case("hard", sparc::FloatABI::Hard)93.Default(sparc::FloatABI::Invalid);94if (ABI == sparc::FloatABI::Invalid &&95!StringRef(A->getValue()).empty()) {96D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);97ABI = sparc::FloatABI::Hard;98}99}100}101102// If unspecified, choose the default based on the platform.103// Only the hard-float ABI on Sparc is standardized, and it is the104// default. GCC also supports a nonstandard soft-float ABI mode, also105// implemented in LLVM. However as this is not standard we set the default106// to be hard-float.107if (ABI == sparc::FloatABI::Invalid) {108ABI = sparc::FloatABI::Hard;109}110111return ABI;112}113114std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,115const llvm::Triple &Triple) {116if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {117StringRef CPUName = A->getValue();118if (CPUName == "native") {119std::string CPU = std::string(llvm::sys::getHostCPUName());120if (!CPU.empty() && CPU != "generic")121return CPU;122return "";123}124return std::string(CPUName);125}126127if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())128return "v9";129return "";130}131132void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,133std::vector<StringRef> &Features) {134sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);135if (FloatABI == sparc::FloatABI::Soft)136Features.push_back("+soft-float");137138if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {139if (A->getOption().matches(options::OPT_mfsmuld))140Features.push_back("+fsmuld");141else142Features.push_back("-fsmuld");143}144145if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {146if (A->getOption().matches(options::OPT_mpopc))147Features.push_back("+popc");148else149Features.push_back("-popc");150}151152if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {153if (A->getOption().matches(options::OPT_mvis))154Features.push_back("+vis");155else156Features.push_back("-vis");157}158159if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {160if (A->getOption().matches(options::OPT_mvis2))161Features.push_back("+vis2");162else163Features.push_back("-vis2");164}165166if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {167if (A->getOption().matches(options::OPT_mvis3))168Features.push_back("+vis3");169else170Features.push_back("-vis3");171}172173if (Arg *A = Args.getLastArg(options::OPT_mhard_quad_float,174options::OPT_msoft_quad_float)) {175if (A->getOption().matches(options::OPT_mhard_quad_float))176Features.push_back("+hard-quad-float");177else178Features.push_back("-hard-quad-float");179}180181if (Args.hasArg(options::OPT_ffixed_g1))182Features.push_back("+reserve-g1");183184if (Args.hasArg(options::OPT_ffixed_g2))185Features.push_back("+reserve-g2");186187if (Args.hasArg(options::OPT_ffixed_g3))188Features.push_back("+reserve-g3");189190if (Args.hasArg(options::OPT_ffixed_g4))191Features.push_back("+reserve-g4");192193if (Args.hasArg(options::OPT_ffixed_g5))194Features.push_back("+reserve-g5");195196if (Args.hasArg(options::OPT_ffixed_g6))197Features.push_back("+reserve-g6");198199if (Args.hasArg(options::OPT_ffixed_g7))200Features.push_back("+reserve-g7");201202if (Args.hasArg(options::OPT_ffixed_o0))203Features.push_back("+reserve-o0");204205if (Args.hasArg(options::OPT_ffixed_o1))206Features.push_back("+reserve-o1");207208if (Args.hasArg(options::OPT_ffixed_o2))209Features.push_back("+reserve-o2");210211if (Args.hasArg(options::OPT_ffixed_o3))212Features.push_back("+reserve-o3");213214if (Args.hasArg(options::OPT_ffixed_o4))215Features.push_back("+reserve-o4");216217if (Args.hasArg(options::OPT_ffixed_o5))218Features.push_back("+reserve-o5");219220if (Args.hasArg(options::OPT_ffixed_l0))221Features.push_back("+reserve-l0");222223if (Args.hasArg(options::OPT_ffixed_l1))224Features.push_back("+reserve-l1");225226if (Args.hasArg(options::OPT_ffixed_l2))227Features.push_back("+reserve-l2");228229if (Args.hasArg(options::OPT_ffixed_l3))230Features.push_back("+reserve-l3");231232if (Args.hasArg(options::OPT_ffixed_l4))233Features.push_back("+reserve-l4");234235if (Args.hasArg(options::OPT_ffixed_l5))236Features.push_back("+reserve-l5");237238if (Args.hasArg(options::OPT_ffixed_l6))239Features.push_back("+reserve-l6");240241if (Args.hasArg(options::OPT_ffixed_l7))242Features.push_back("+reserve-l7");243244if (Args.hasArg(options::OPT_ffixed_i0))245Features.push_back("+reserve-i0");246247if (Args.hasArg(options::OPT_ffixed_i1))248Features.push_back("+reserve-i1");249250if (Args.hasArg(options::OPT_ffixed_i2))251Features.push_back("+reserve-i2");252253if (Args.hasArg(options::OPT_ffixed_i3))254Features.push_back("+reserve-i3");255256if (Args.hasArg(options::OPT_ffixed_i4))257Features.push_back("+reserve-i4");258259if (Args.hasArg(options::OPT_ffixed_i5))260Features.push_back("+reserve-i5");261}262263264