14#include "llvm/Option/ArgList.h"
15#include "llvm/Support/Error.h"
16#include "llvm/TargetParser/Host.h"
17#include "llvm/TargetParser/RISCVISAInfo.h"
18#include "llvm/TargetParser/RISCVTargetParser.h"
27 std::vector<StringRef> &Features,
28 const ArgList &Args) {
29 bool EnableExperimentalExtensions =
30 Args.hasArg(options::OPT_menable_experimental_extensions);
32 llvm::RISCVISAInfo::parseArchString(
Arch, EnableExperimentalExtensions);
34 handleAllErrors(ISAInfo.takeError(), [&](llvm::StringError &ErrMsg) {
35 D.Diag(diag::err_drv_invalid_riscv_arch_name)
36 << Arch << ErrMsg.getMessage();
42 for (
const std::string &Str : (*ISAInfo)->toFeatures(
true,
44 Features.push_back(Args.MakeArgString(Str));
46 if (EnableExperimentalExtensions)
47 Features.push_back(Args.MakeArgString(
"+experimental"));
54 const llvm::Triple &Triple,
56 std::vector<StringRef> &Features) {
57 bool Is64Bit = Triple.isRISCV64();
58 if (!llvm::RISCV::parseCPU(Mcpu, Is64Bit)) {
60 if (llvm::RISCV::parseCPU(Mcpu, !Is64Bit))
61 D.
Diag(clang::diag::err_drv_invalid_riscv_cpu_name_for_target)
64 D.
Diag(clang::diag::err_drv_unsupported_option_argument)
65 << A->getSpelling() << Mcpu;
71 std::vector<StringRef> &Features) {
77 bool CPUFastScalarUnaligned =
false;
78 bool CPUFastVectorUnaligned =
false;
82 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
83 StringRef
CPU = A->getValue();
85 CPU = llvm::sys::getHostCPUName();
89 if (llvm::RISCV::hasFastScalarUnalignedAccess(CPU))
90 CPUFastScalarUnaligned =
true;
91 if (llvm::RISCV::hasFastVectorUnalignedAccess(CPU))
92 CPUFastVectorUnaligned =
true;
96#define RESERVE_REG(REG) \
97 if (Args.hasArg(options::OPT_ffixed_##REG)) \
98 Features.push_back("+reserve-" #REG);
133 if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax,
true)) {
134 Features.push_back(
"+relax");
139 D.
Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation)
140 << A->getAsString(Args);
142 Features.push_back(
"-relax");
149 if (
const Arg *A = Args.getLastArg(
150 options::OPT_mno_strict_align, options::OPT_mscalar_strict_align,
151 options::OPT_mstrict_align, options::OPT_mno_scalar_strict_align)) {
152 if (A->getOption().matches(options::OPT_mno_strict_align) ||
153 A->getOption().matches(options::OPT_mno_scalar_strict_align)) {
154 Features.push_back(
"+unaligned-scalar-mem");
156 Features.push_back(
"-unaligned-scalar-mem");
158 }
else if (CPUFastScalarUnaligned || Triple.isAndroid()) {
159 Features.push_back(
"+unaligned-scalar-mem");
166 if (
const Arg *A = Args.getLastArg(
167 options::OPT_mno_strict_align, options::OPT_mvector_strict_align,
168 options::OPT_mstrict_align, options::OPT_mno_vector_strict_align)) {
169 if (A->getOption().matches(options::OPT_mno_strict_align) ||
170 A->getOption().matches(options::OPT_mno_vector_strict_align)) {
171 Features.push_back(
"+unaligned-vector-mem");
173 Features.push_back(
"-unaligned-vector-mem");
175 }
else if (CPUFastVectorUnaligned || Triple.isAndroid()) {
176 Features.push_back(
"+unaligned-vector-mem");
182 options::OPT_m_riscv_Features_Group);
186 assert(Triple.isRISCV() &&
"Unexpected triple");
209 if (
const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
210 return A->getValue();
222 auto ParseResult = llvm::RISCVISAInfo::parseArchString(
225 if (!llvm::errorToBool(ParseResult.takeError()))
226 return (*ParseResult)->computeDefaultABI();
233 if (Triple.isRISCV32()) {
234 if (Triple.getOS() == llvm::Triple::UnknownOS)
239 if (Triple.getOS() == llvm::Triple::UnknownOS)
247 const llvm::Triple &Triple) {
248 assert(Triple.isRISCV() &&
"Unexpected triple");
277 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
278 StringRef MArch = A->getValue();
279 if (MArch !=
"unset")
284 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
285 StringRef CPU = A->getValue();
286 if (CPU ==
"native") {
287 CPU = llvm::sys::getHostCPUName();
289 if (CPU.starts_with(
"generic")) {
290 auto FeatureMap = llvm::sys::getHostCPUFeatures();
292 if (!FeatureMap.empty()) {
293 std::vector<std::string> Features;
294 for (
auto &F : FeatureMap)
295 Features.push_back(((F.second ?
"+" :
"-") + F.first()).str());
296 auto ParseResult = llvm::RISCVISAInfo::parseFeatures(
297 Triple.isRISCV32() ? 32 : 64, Features);
299 return (*ParseResult)->toString();
304 StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
316 if (
const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
317 StringRef MABI = A->getValue();
319 if (MABI.equals_insensitive(
"ilp32e"))
321 if (MABI.equals_insensitive(
"lp64e"))
323 if (MABI.starts_with_insensitive(
"ilp32"))
325 if (MABI.starts_with_insensitive(
"lp64")) {
326 if (Triple.isAndroid())
327 return "rv64imafdcv_zba_zbb_zbs";
328 if (Triple.isOSFuchsia())
339 if (Triple.isRISCV32()) {
340 if (Triple.getOS() == llvm::Triple::UnknownOS)
345 if (Triple.getOS() == llvm::Triple::UnknownOS)
347 if (Triple.isAndroid())
348 return "rv64imafdcv_zba_zbb_zbs";
349 if (Triple.isOSFuchsia())
355 const llvm::Triple &Triple) {
358 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
363 CPU = llvm::sys::getHostCPUName();
368 return Triple.isRISCV64() ?
"generic-rv64" :
"generic-rv32";
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
DiagnosticBuilder Diag(unsigned DiagID) const
The JSON file list parser is used to communicate input to InstallAPI.