10#include "../CommonArgs.h"
14#include "llvm/Option/ArgList.h"
15#include "llvm/TargetParser/AArch64TargetParser.h"
16#include "llvm/TargetParser/Host.h"
26 return Triple.isOSDarwin();
33 const llvm::Triple &Triple, Arg *&A) {
36 if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
37 StringRef Mcpu = A->getValue();
38 CPU = Mcpu.split(
"+").first.lower();
41 CPU = llvm::AArch64::resolveCPUAlias(CPU);
45 return std::string(llvm::sys::getHostCPUName());
50 if (Triple.isTargetMachineMac() &&
51 Triple.getArch() == llvm::Triple::aarch64) {
56 if (Triple.isXROS()) {
58 assert(!Triple.isSimulatorEnvironment() &&
"xrossim should be mac-like");
62 if (Triple.isArm64e())
66 if (Triple.isOSDarwin())
67 return Triple.getArch() == llvm::Triple::aarch64_32 ?
"apple-s4"
75 llvm::AArch64::ExtensionSet &Extensions) {
77 text.split(
Split, StringRef(
"+"), -1,
false);
79 for (StringRef Feature :
Split) {
80 if (Feature ==
"neon" || Feature ==
"noneon") {
81 D.Diag(clang::diag::err_drv_no_neon_modifier);
84 if (!Extensions.parseModifier(Feature))
94 llvm::AArch64::ExtensionSet &Extensions) {
95 std::pair<StringRef, StringRef>
Split = Mcpu.split(
"+");
99 CPU = llvm::sys::getHostCPUName();
101 const std::optional<llvm::AArch64::CpuInfo> CpuInfo =
102 llvm::AArch64::parseCpu(CPU);
106 Extensions.addCPUDefaults(*CpuInfo);
108 if (
Split.second.size() &&
118 llvm::AArch64::ExtensionSet &Extensions) {
119 std::string MarchLowerCase = March.lower();
120 std::pair<StringRef, StringRef>
Split = StringRef(MarchLowerCase).split(
"+");
122 const llvm::AArch64::ArchInfo *ArchInfo =
123 llvm::AArch64::parseArch(
Split.first);
124 if (
Split.first ==
"native")
125 ArchInfo = llvm::AArch64::getArchForCpu(llvm::sys::getHostCPUName().str());
129 Extensions.addArchDefaults(*ArchInfo);
131 if ((
Split.second.size() &&
141 llvm::AArch64::ExtensionSet &Extensions) {
143 std::string McpuLowerCase = Mcpu.lower();
153 std::vector<StringRef> &Features) {
154 std::string MtuneLowerCase = Mtune.lower();
156 llvm::AArch64::ExtensionSet Extensions;
162 if (MtuneLowerCase ==
"native")
163 MtuneLowerCase = std::string(llvm::sys::getHostCPUName());
166 if (MtuneLowerCase ==
"cyclone" ||
167 StringRef(MtuneLowerCase).starts_with(
"apple")) {
168 Features.push_back(
"+zcm");
169 Features.push_back(
"+zcz");
178 std::vector<StringRef> &Features) {
181 llvm::AArch64::ExtensionSet DecodedFeature;
182 std::string McpuLowerCase = Mcpu.lower();
190 const llvm::Triple &Triple,
192 std::vector<StringRef> &Features,
196 llvm::StringRef WaMArch;
197 llvm::AArch64::ExtensionSet Extensions;
200 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
201 for (StringRef
Value : A->getValues())
202 if (
Value.starts_with(
"-march="))
203 WaMArch =
Value.substr(7);
207 if (!WaMArch.empty())
209 else if ((A = Args.getLastArg(options::OPT_march_EQ)))
212 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
222 if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
225 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
233 auto Diag =
D.Diag(diag::err_drv_unsupported_option_argument);
236 if (!WaMArch.empty())
237 Diag <<
"-march=" << WaMArch;
239 Diag << A->getSpelling() << A->getValue();
243 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
244 Extensions.disable(llvm::AArch64::AEK_FP);
248 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
249 if (A->getOption().matches(options::OPT_mcrc))
250 Extensions.enable(llvm::AArch64::AEK_CRC);
252 Extensions.disable(llvm::AArch64::AEK_CRC);
257 Extensions.toLLVMFeatureList(Features);
259 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
260 StringRef Mtp = A->getValue();
261 if (Mtp ==
"el3" || Mtp ==
"tpidr_el3")
262 Features.push_back(
"+tpidr-el3");
263 else if (Mtp ==
"el2" || Mtp ==
"tpidr_el2")
264 Features.push_back(
"+tpidr-el2");
265 else if (Mtp ==
"el1" || Mtp ==
"tpidr_el1")
266 Features.push_back(
"+tpidr-el1");
267 else if (Mtp ==
"tpidrro_el0")
268 Features.push_back(
"+tpidrro-el0");
269 else if (Mtp !=
"el0" && Mtp !=
"tpidr_el0")
270 D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
274 if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
275 StringRef
Scope = A->getValue();
276 bool EnableRetBr =
false;
277 bool EnableBlr =
false;
278 bool DisableComdat =
false;
279 if (
Scope !=
"none") {
281 Scope.split(Opts,
",");
282 for (
auto Opt : Opts) {
289 if (Opt ==
"retbr") {
297 if (Opt ==
"comdat") {
298 DisableComdat =
false;
301 if (Opt ==
"nocomdat") {
302 DisableComdat =
true;
305 D.Diag(diag::err_drv_unsupported_option_argument)
306 << A->getSpelling() <<
Scope;
312 Features.push_back(
"+harden-sls-retbr");
314 Features.push_back(
"+harden-sls-blr");
316 Features.push_back(
"+harden-sls-nocomdat");
320 if (Arg *A = Args.getLastArg(
321 options::OPT_mstrict_align, options::OPT_mno_strict_align,
322 options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
323 if (A->getOption().matches(options::OPT_mstrict_align) ||
324 A->getOption().matches(options::OPT_mno_unaligned_access))
325 Features.push_back(
"+strict-align");
326 }
else if (Triple.isOSOpenBSD())
327 Features.push_back(
"+strict-align");
329 if (Args.hasArg(options::OPT_ffixed_x1))
330 Features.push_back(
"+reserve-x1");
332 if (Args.hasArg(options::OPT_ffixed_x2))
333 Features.push_back(
"+reserve-x2");
335 if (Args.hasArg(options::OPT_ffixed_x3))
336 Features.push_back(
"+reserve-x3");
338 if (Args.hasArg(options::OPT_ffixed_x4))
339 Features.push_back(
"+reserve-x4");
341 if (Args.hasArg(options::OPT_ffixed_x5))
342 Features.push_back(
"+reserve-x5");
344 if (Args.hasArg(options::OPT_ffixed_x6))
345 Features.push_back(
"+reserve-x6");
347 if (Args.hasArg(options::OPT_ffixed_x7))
348 Features.push_back(
"+reserve-x7");
350 if (Args.hasArg(options::OPT_ffixed_x9))
351 Features.push_back(
"+reserve-x9");
353 if (Args.hasArg(options::OPT_ffixed_x10))
354 Features.push_back(
"+reserve-x10");
356 if (Args.hasArg(options::OPT_ffixed_x11))
357 Features.push_back(
"+reserve-x11");
359 if (Args.hasArg(options::OPT_ffixed_x12))
360 Features.push_back(
"+reserve-x12");
362 if (Args.hasArg(options::OPT_ffixed_x13))
363 Features.push_back(
"+reserve-x13");
365 if (Args.hasArg(options::OPT_ffixed_x14))
366 Features.push_back(
"+reserve-x14");
368 if (Args.hasArg(options::OPT_ffixed_x15))
369 Features.push_back(
"+reserve-x15");
371 if (Args.hasArg(options::OPT_ffixed_x18))
372 Features.push_back(
"+reserve-x18");
374 if (Args.hasArg(options::OPT_ffixed_x20))
375 Features.push_back(
"+reserve-x20");
377 if (Args.hasArg(options::OPT_ffixed_x21))
378 Features.push_back(
"+reserve-x21");
380 if (Args.hasArg(options::OPT_ffixed_x22))
381 Features.push_back(
"+reserve-x22");
383 if (Args.hasArg(options::OPT_ffixed_x23))
384 Features.push_back(
"+reserve-x23");
386 if (Args.hasArg(options::OPT_ffixed_x24))
387 Features.push_back(
"+reserve-x24");
389 if (Args.hasArg(options::OPT_ffixed_x25))
390 Features.push_back(
"+reserve-x25");
392 if (Args.hasArg(options::OPT_ffixed_x26))
393 Features.push_back(
"+reserve-x26");
395 if (Args.hasArg(options::OPT_ffixed_x27))
396 Features.push_back(
"+reserve-x27");
398 if (Args.hasArg(options::OPT_ffixed_x28))
399 Features.push_back(
"+reserve-x28");
401 if (Args.hasArg(options::OPT_mlr_for_calls_only))
402 Features.push_back(
"+reserve-lr-for-ra");
404 if (Args.hasArg(options::OPT_fcall_saved_x8))
405 Features.push_back(
"+call-saved-x8");
407 if (Args.hasArg(options::OPT_fcall_saved_x9))
408 Features.push_back(
"+call-saved-x9");
410 if (Args.hasArg(options::OPT_fcall_saved_x10))
411 Features.push_back(
"+call-saved-x10");
413 if (Args.hasArg(options::OPT_fcall_saved_x11))
414 Features.push_back(
"+call-saved-x11");
416 if (Args.hasArg(options::OPT_fcall_saved_x12))
417 Features.push_back(
"+call-saved-x12");
419 if (Args.hasArg(options::OPT_fcall_saved_x13))
420 Features.push_back(
"+call-saved-x13");
422 if (Args.hasArg(options::OPT_fcall_saved_x14))
423 Features.push_back(
"+call-saved-x14");
425 if (Args.hasArg(options::OPT_fcall_saved_x15))
426 Features.push_back(
"+call-saved-x15");
428 if (Args.hasArg(options::OPT_fcall_saved_x18))
429 Features.push_back(
"+call-saved-x18");
431 if (Args.hasArg(options::OPT_mno_neg_immediates))
432 Features.push_back(
"+no-neg-immediates");
434 if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769,
435 options::OPT_mno_fix_cortex_a53_835769)) {
436 if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769))
437 Features.push_back(
"+fix-cortex-a53-835769");
439 Features.push_back(
"-fix-cortex-a53-835769");
440 }
else if (Triple.isAndroid() || Triple.isOHOSFamily()) {
442 Features.push_back(
"+fix-cortex-a53-835769");
443 }
else if (Triple.isOSFuchsia()) {
445 if (CPU.empty() || CPU ==
"generic" || CPU ==
"cortex-a53")
446 Features.push_back(
"+fix-cortex-a53-835769");
449 if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
450 Features.push_back(
"+no-bti-at-return-twice");
454 llvm::Triple &Triple) {
455 Arg *ABIArg = Args.getLastArg(options::OPT_mabi_EQ);
457 ABIArg ? (StringRef(ABIArg->getValue()) ==
"pauthtest") :
false;
459 switch (Triple.getEnvironment()) {
460 case llvm::Triple::UnknownEnvironment:
462 Triple.setEnvironment(llvm::Triple::PAuthTest);
464 case llvm::Triple::PAuthTest:
468 D.Diag(diag::err_drv_unsupported_opt_for_target)
469 << ABIArg->getAsString(Args) << Triple.getTriple();
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Scope - A scope is a transient data structure that is used while parsing the program.
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.