16#include "llvm/Option/ArgList.h"
17#include "llvm/Support/Error.h"
18#include "llvm/Support/raw_ostream.h"
19#include "llvm/TargetParser/Host.h"
20#include "llvm/TargetParser/RISCVISAInfo.h"
21#include "llvm/TargetParser/RISCVTargetParser.h"
30 std::vector<StringRef> &Features,
31 const ArgList &Args) {
32 bool EnableExperimentalExtensions =
33 Args.hasArg(options::OPT_menable_experimental_extensions);
35 llvm::RISCVISAInfo::parseArchString(Arch, EnableExperimentalExtensions);
37 handleAllErrors(ISAInfo.takeError(), [&](llvm::StringError &ErrMsg) {
38 D.Diag(diag::err_drv_invalid_riscv_arch_name)
39 << Arch << ErrMsg.getMessage();
45 for (
const std::string &Str : (*ISAInfo)->toFeatures(
true,
47 Features.push_back(Args.MakeArgString(Str));
49 if (EnableExperimentalExtensions)
50 Features.push_back(Args.MakeArgString(
"+experimental"));
57 const llvm::Triple &Triple,
59 std::vector<StringRef> &Features) {
60 bool Is64Bit = Triple.isRISCV64();
61 if (!llvm::RISCV::parseCPU(Mcpu, Is64Bit)) {
63 if (llvm::RISCV::parseCPU(Mcpu, !Is64Bit))
64 D.Diag(clang::diag::err_drv_invalid_riscv_cpu_name_for_target)
67 D.Diag(clang::diag::err_drv_unsupported_option_argument)
68 << A->getSpelling() << Mcpu;
74 std::vector<StringRef> &Features) {
80 bool CPUFastScalarUnaligned =
false;
81 bool CPUFastVectorUnaligned =
false;
85 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
86 StringRef CPU = A->getValue();
88 CPU = llvm::sys::getHostCPUName();
92 if (llvm::RISCV::hasFastScalarUnalignedAccess(CPU))
93 CPUFastScalarUnaligned =
true;
94 if (llvm::RISCV::hasFastVectorUnalignedAccess(CPU))
95 CPUFastVectorUnaligned =
true;
99#define RESERVE_REG(REG) \
100 if (Args.hasArg(options::OPT_ffixed_##REG)) \
101 Features.push_back("+reserve-" #REG);
136 if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax,
true)) {
137 Features.push_back(
"+relax");
142 D.Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation)
143 << A->getAsString(Args);
145 Features.push_back(
"-relax");
152 if (
const Arg *A = Args.getLastArg(
153 options::OPT_mno_strict_align, options::OPT_mscalar_strict_align,
154 options::OPT_mstrict_align, options::OPT_mno_scalar_strict_align)) {
155 if (A->getOption().matches(options::OPT_mno_strict_align) ||
156 A->getOption().matches(options::OPT_mno_scalar_strict_align)) {
157 Features.push_back(
"+unaligned-scalar-mem");
159 Features.push_back(
"-unaligned-scalar-mem");
161 }
else if (CPUFastScalarUnaligned || Triple.isAndroid()) {
162 Features.push_back(
"+unaligned-scalar-mem");
169 if (
const Arg *A = Args.getLastArg(
170 options::OPT_mno_strict_align, options::OPT_mvector_strict_align,
171 options::OPT_mstrict_align, options::OPT_mno_vector_strict_align)) {
172 if (A->getOption().matches(options::OPT_mno_strict_align) ||
173 A->getOption().matches(options::OPT_mno_vector_strict_align)) {
174 Features.push_back(
"+unaligned-vector-mem");
176 Features.push_back(
"-unaligned-vector-mem");
178 }
else if (CPUFastVectorUnaligned || Triple.isAndroid()) {
179 Features.push_back(
"+unaligned-vector-mem");
185 options::OPT_m_riscv_Features_Group);
189 assert(Triple.isRISCV() &&
"Unexpected triple");
212 if (
const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
213 return A->getValue();
225 auto ParseResult = llvm::RISCVISAInfo::parseArchString(
228 if (!llvm::errorToBool(ParseResult.takeError()))
229 return (*ParseResult)->computeDefaultABI();
236 if (Triple.isRISCV32()) {
237 if (Triple.getOS() == llvm::Triple::UnknownOS)
242 if (Triple.getOS() == llvm::Triple::UnknownOS)
250 const llvm::Triple &Triple) {
251 assert(Triple.isRISCV() &&
"Unexpected triple");
280 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
281 return A->getValue();
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 else if (MABI.equals_insensitive(
"lp64e"))
323 else if (MABI.starts_with_insensitive(
"ilp32"))
325 else if (MABI.starts_with_insensitive(
"lp64")) {
326 if (Triple.isAndroid())
327 return "rv64imafdcv_zba_zbb_zbs";
338 if (Triple.isRISCV32()) {
339 if (Triple.getOS() == llvm::Triple::UnknownOS)
344 if (Triple.getOS() == llvm::Triple::UnknownOS)
346 else if (Triple.isAndroid())
347 return "rv64imafdcv_zba_zbb_zbs";
354 const llvm::Triple &Triple) {
357 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
362 CPU = llvm::sys::getHostCPUName();
367 return Triple.isRISCV64() ?
"generic-rv64" :
"generic-rv32";
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
The JSON file list parser is used to communicate input to InstallAPI.