1 //===--- Sparc.cpp - Tools Implementations ----------------------*- 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 "Sparc.h" 10 #include "clang/Driver/Driver.h" 11 #include "clang/Driver/DriverDiagnostic.h" 12 #include "clang/Driver/Options.h" 13 #include "llvm/ADT/StringSwitch.h" 14 #include "llvm/Option/ArgList.h" 15 #include "llvm/Support/Host.h" 16 17 using namespace clang::driver; 18 using namespace clang::driver::tools; 19 using namespace clang; 20 using namespace llvm::opt; 21 22 const char *sparc::getSparcAsmModeForCPU(StringRef Name, 23 const llvm::Triple &Triple) { 24 if (Triple.getArch() == llvm::Triple::sparcv9) { 25 const char *DefV9CPU; 26 27 if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD()) 28 DefV9CPU = "-Av9a"; 29 else 30 DefV9CPU = "-Av9"; 31 32 return llvm::StringSwitch<const char *>(Name) 33 .Case("niagara", "-Av9b") 34 .Case("niagara2", "-Av9b") 35 .Case("niagara3", "-Av9d") 36 .Case("niagara4", "-Av9d") 37 .Default(DefV9CPU); 38 } else { 39 return llvm::StringSwitch<const char *>(Name) 40 .Case("v8", "-Av8") 41 .Case("supersparc", "-Av8") 42 .Case("sparclite", "-Asparclite") 43 .Case("f934", "-Asparclite") 44 .Case("hypersparc", "-Av8") 45 .Case("sparclite86x", "-Asparclite") 46 .Case("sparclet", "-Asparclet") 47 .Case("tsc701", "-Asparclet") 48 .Case("v9", "-Av8plus") 49 .Case("ultrasparc", "-Av8plus") 50 .Case("ultrasparc3", "-Av8plus") 51 .Case("niagara", "-Av8plusb") 52 .Case("niagara2", "-Av8plusb") 53 .Case("niagara3", "-Av8plusd") 54 .Case("niagara4", "-Av8plusd") 55 .Case("ma2100", "-Aleon") 56 .Case("ma2150", "-Aleon") 57 .Case("ma2155", "-Aleon") 58 .Case("ma2450", "-Aleon") 59 .Case("ma2455", "-Aleon") 60 .Case("ma2x5x", "-Aleon") 61 .Case("ma2080", "-Aleon") 62 .Case("ma2085", "-Aleon") 63 .Case("ma2480", "-Aleon") 64 .Case("ma2485", "-Aleon") 65 .Case("ma2x8x", "-Aleon") 66 .Case("myriad2", "-Aleon") 67 .Case("myriad2.1", "-Aleon") 68 .Case("myriad2.2", "-Aleon") 69 .Case("myriad2.3", "-Aleon") 70 .Case("leon2", "-Av8") 71 .Case("at697e", "-Av8") 72 .Case("at697f", "-Av8") 73 .Case("leon3", "-Aleon") 74 .Case("ut699", "-Av8") 75 .Case("gr712rc", "-Aleon") 76 .Case("leon4", "-Aleon") 77 .Case("gr740", "-Aleon") 78 .Default("-Av8"); 79 } 80 } 81 82 sparc::FloatABI sparc::getSparcFloatABI(const Driver &D, 83 const ArgList &Args) { 84 sparc::FloatABI ABI = sparc::FloatABI::Invalid; 85 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_msoft_float, 86 options::OPT_mhard_float, 87 options::OPT_mfloat_abi_EQ)) { 88 if (A->getOption().matches(clang::driver::options::OPT_msoft_float)) 89 ABI = sparc::FloatABI::Soft; 90 else if (A->getOption().matches(options::OPT_mhard_float)) 91 ABI = sparc::FloatABI::Hard; 92 else { 93 ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue()) 94 .Case("soft", sparc::FloatABI::Soft) 95 .Case("hard", sparc::FloatABI::Hard) 96 .Default(sparc::FloatABI::Invalid); 97 if (ABI == sparc::FloatABI::Invalid && 98 !StringRef(A->getValue()).empty()) { 99 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args); 100 ABI = sparc::FloatABI::Hard; 101 } 102 } 103 } 104 105 // If unspecified, choose the default based on the platform. 106 // Only the hard-float ABI on Sparc is standardized, and it is the 107 // default. GCC also supports a nonstandard soft-float ABI mode, also 108 // implemented in LLVM. However as this is not standard we set the default 109 // to be hard-float. 110 if (ABI == sparc::FloatABI::Invalid) { 111 ABI = sparc::FloatABI::Hard; 112 } 113 114 return ABI; 115 } 116 117 std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args, 118 const llvm::Triple &Triple) { 119 if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { 120 D.Diag(diag::err_drv_unsupported_opt_for_target) 121 << A->getSpelling() << Triple.getTriple(); 122 return ""; 123 } 124 125 if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { 126 StringRef CPUName = A->getValue(); 127 if (CPUName == "native") { 128 std::string CPU = std::string(llvm::sys::getHostCPUName()); 129 if (!CPU.empty() && CPU != "generic") 130 return CPU; 131 return ""; 132 } 133 return std::string(CPUName); 134 } 135 136 if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris()) 137 return "v9"; 138 return ""; 139 } 140 141 void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args, 142 std::vector<StringRef> &Features) { 143 sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args); 144 if (FloatABI == sparc::FloatABI::Soft) 145 Features.push_back("+soft-float"); 146 } 147