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() &&
139 const Driver &
D, StringRef Mcpu,
const ArgList &Args,
140 llvm::AArch64::ExtensionSet &Extensions, std::vector<StringRef> &Features) {
142 std::string McpuLowerCase = Mcpu.lower();
146 if (Mcpu ==
"native") {
147 llvm::StringMap<bool> HostFeatures = llvm::sys::getHostCPUFeatures();
148 for (
auto &[Feature, Enabled] : HostFeatures) {
149 Features.push_back(Args.MakeArgString((Enabled ?
"+" :
"-") + Feature));
159 std::vector<StringRef> &Features) {
160 std::string MtuneLowerCase = Mtune.lower();
162 llvm::AArch64::ExtensionSet Extensions;
168 if (MtuneLowerCase ==
"native")
169 MtuneLowerCase = std::string(llvm::sys::getHostCPUName());
172 if (MtuneLowerCase ==
"cyclone" ||
173 StringRef(MtuneLowerCase).starts_with(
"apple")) {
174 Features.push_back(
"+zcm");
175 Features.push_back(
"+zcz");
184 std::vector<StringRef> &Features) {
187 llvm::AArch64::ExtensionSet DecodedFeature;
188 std::string McpuLowerCase = Mcpu.lower();
196 const llvm::Triple &Triple,
198 std::vector<StringRef> &Features,
202 llvm::StringRef WaMArch;
203 llvm::AArch64::ExtensionSet Extensions;
206 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
207 for (StringRef
Value : A->getValues())
208 if (
Value.starts_with(
"-march="))
209 WaMArch =
Value.substr(7);
213 if (!WaMArch.empty())
215 else if ((A = Args.getLastArg(options::OPT_march_EQ)))
218 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
228 if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
231 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
239 auto Diag =
D.Diag(diag::err_drv_unsupported_option_argument);
242 if (!WaMArch.empty())
243 Diag <<
"-march=" << WaMArch;
245 Diag << A->getSpelling() << A->getValue();
249 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
250 Extensions.disable(llvm::AArch64::AEK_FP);
254 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
255 if (A->getOption().matches(options::OPT_mcrc))
256 Extensions.enable(llvm::AArch64::AEK_CRC);
258 Extensions.disable(llvm::AArch64::AEK_CRC);
263 Extensions.toLLVMFeatureList(Features);
265 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
266 StringRef Mtp = A->getValue();
267 if (Mtp ==
"el3" || Mtp ==
"tpidr_el3")
268 Features.push_back(
"+tpidr-el3");
269 else if (Mtp ==
"el2" || Mtp ==
"tpidr_el2")
270 Features.push_back(
"+tpidr-el2");
271 else if (Mtp ==
"el1" || Mtp ==
"tpidr_el1")
272 Features.push_back(
"+tpidr-el1");
273 else if (Mtp ==
"tpidrro_el0")
274 Features.push_back(
"+tpidrro-el0");
275 else if (Mtp !=
"el0" && Mtp !=
"tpidr_el0")
276 D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
280 if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
281 StringRef
Scope = A->getValue();
282 bool EnableRetBr =
false;
283 bool EnableBlr =
false;
284 bool DisableComdat =
false;
285 if (
Scope !=
"none") {
287 Scope.split(Opts,
",");
288 for (
auto Opt : Opts) {
295 if (Opt ==
"retbr") {
303 if (Opt ==
"comdat") {
304 DisableComdat =
false;
307 if (Opt ==
"nocomdat") {
308 DisableComdat =
true;
311 D.Diag(diag::err_drv_unsupported_option_argument)
312 << A->getSpelling() <<
Scope;
318 Features.push_back(
"+harden-sls-retbr");
320 Features.push_back(
"+harden-sls-blr");
322 Features.push_back(
"+harden-sls-nocomdat");
326 if (Arg *A = Args.getLastArg(
327 options::OPT_mstrict_align, options::OPT_mno_strict_align,
328 options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
329 if (A->getOption().matches(options::OPT_mstrict_align) ||
330 A->getOption().matches(options::OPT_mno_unaligned_access))
331 Features.push_back(
"+strict-align");
332 }
else if (Triple.isOSOpenBSD())
333 Features.push_back(
"+strict-align");
335 if (Args.hasArg(options::OPT_ffixed_x1))
336 Features.push_back(
"+reserve-x1");
338 if (Args.hasArg(options::OPT_ffixed_x2))
339 Features.push_back(
"+reserve-x2");
341 if (Args.hasArg(options::OPT_ffixed_x3))
342 Features.push_back(
"+reserve-x3");
344 if (Args.hasArg(options::OPT_ffixed_x4))
345 Features.push_back(
"+reserve-x4");
347 if (Args.hasArg(options::OPT_ffixed_x5))
348 Features.push_back(
"+reserve-x5");
350 if (Args.hasArg(options::OPT_ffixed_x6))
351 Features.push_back(
"+reserve-x6");
353 if (Args.hasArg(options::OPT_ffixed_x7))
354 Features.push_back(
"+reserve-x7");
356 if (Args.hasArg(options::OPT_ffixed_x9))
357 Features.push_back(
"+reserve-x9");
359 if (Args.hasArg(options::OPT_ffixed_x10))
360 Features.push_back(
"+reserve-x10");
362 if (Args.hasArg(options::OPT_ffixed_x11))
363 Features.push_back(
"+reserve-x11");
365 if (Args.hasArg(options::OPT_ffixed_x12))
366 Features.push_back(
"+reserve-x12");
368 if (Args.hasArg(options::OPT_ffixed_x13))
369 Features.push_back(
"+reserve-x13");
371 if (Args.hasArg(options::OPT_ffixed_x14))
372 Features.push_back(
"+reserve-x14");
374 if (Args.hasArg(options::OPT_ffixed_x15))
375 Features.push_back(
"+reserve-x15");
377 if (Args.hasArg(options::OPT_ffixed_x18))
378 Features.push_back(
"+reserve-x18");
380 if (Args.hasArg(options::OPT_ffixed_x20))
381 Features.push_back(
"+reserve-x20");
383 if (Args.hasArg(options::OPT_ffixed_x21))
384 Features.push_back(
"+reserve-x21");
386 if (Args.hasArg(options::OPT_ffixed_x22))
387 Features.push_back(
"+reserve-x22");
389 if (Args.hasArg(options::OPT_ffixed_x23))
390 Features.push_back(
"+reserve-x23");
392 if (Args.hasArg(options::OPT_ffixed_x24))
393 Features.push_back(
"+reserve-x24");
395 if (Args.hasArg(options::OPT_ffixed_x25))
396 Features.push_back(
"+reserve-x25");
398 if (Args.hasArg(options::OPT_ffixed_x26))
399 Features.push_back(
"+reserve-x26");
401 if (Args.hasArg(options::OPT_ffixed_x27))
402 Features.push_back(
"+reserve-x27");
404 if (Args.hasArg(options::OPT_ffixed_x28))
405 Features.push_back(
"+reserve-x28");
407 if (Args.hasArg(options::OPT_mlr_for_calls_only))
408 Features.push_back(
"+reserve-lr-for-ra");
410 if (Args.hasArg(options::OPT_fcall_saved_x8))
411 Features.push_back(
"+call-saved-x8");
413 if (Args.hasArg(options::OPT_fcall_saved_x9))
414 Features.push_back(
"+call-saved-x9");
416 if (Args.hasArg(options::OPT_fcall_saved_x10))
417 Features.push_back(
"+call-saved-x10");
419 if (Args.hasArg(options::OPT_fcall_saved_x11))
420 Features.push_back(
"+call-saved-x11");
422 if (Args.hasArg(options::OPT_fcall_saved_x12))
423 Features.push_back(
"+call-saved-x12");
425 if (Args.hasArg(options::OPT_fcall_saved_x13))
426 Features.push_back(
"+call-saved-x13");
428 if (Args.hasArg(options::OPT_fcall_saved_x14))
429 Features.push_back(
"+call-saved-x14");
431 if (Args.hasArg(options::OPT_fcall_saved_x15))
432 Features.push_back(
"+call-saved-x15");
434 if (Args.hasArg(options::OPT_fcall_saved_x18))
435 Features.push_back(
"+call-saved-x18");
437 if (Args.hasArg(options::OPT_mno_neg_immediates))
438 Features.push_back(
"+no-neg-immediates");
440 if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769,
441 options::OPT_mno_fix_cortex_a53_835769)) {
442 if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769))
443 Features.push_back(
"+fix-cortex-a53-835769");
445 Features.push_back(
"-fix-cortex-a53-835769");
446 }
else if (Triple.isAndroid() || Triple.isOHOSFamily()) {
448 Features.push_back(
"+fix-cortex-a53-835769");
449 }
else if (Triple.isOSFuchsia()) {
451 if (CPU.empty() || CPU ==
"generic" || CPU ==
"cortex-a53")
452 Features.push_back(
"+fix-cortex-a53-835769");
455 if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
456 Features.push_back(
"+no-bti-at-return-twice");
460 llvm::Triple &Triple) {
461 Arg *ABIArg = Args.getLastArg(options::OPT_mabi_EQ);
463 ABIArg ? (StringRef(ABIArg->getValue()) ==
"pauthtest") :
false;
465 switch (Triple.getEnvironment()) {
466 case llvm::Triple::UnknownEnvironment:
468 Triple.setEnvironment(llvm::Triple::PAuthTest);
470 case llvm::Triple::PAuthTest:
474 D.Diag(diag::err_drv_unsupported_opt_for_target)
475 << 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.