13#include "llvm/Option/ArgList.h"
14#include "llvm/TargetParser/AArch64TargetParser.h"
15#include "llvm/TargetParser/Host.h"
25 return Triple.isOSDarwin();
32 const llvm::Triple &Triple, Arg *&A) {
35 if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
36 StringRef Mcpu = A->getValue();
37 CPU = Mcpu.split(
"+").first.lower();
38 }
else if (
const Arg *MArch = Args.getLastArg(options::OPT_march_EQ)) {
40 StringRef MArchValue = MArch->getValue();
41 if (MArchValue.split(
"+").first.equals_insensitive(
"native"))
45 CPU = llvm::AArch64::resolveCPUAlias(CPU);
49 return std::string(llvm::sys::getHostCPUName());
54 if (Triple.isTargetMachineMac() &&
55 Triple.getArch() == llvm::Triple::aarch64) {
60 if (Triple.getOS() == llvm::Triple::IOS) {
61 assert(!Triple.isSimulatorEnvironment() &&
"iossim should be mac-like");
63 if (!Triple.isOSVersionLT(26))
66 if (!Triple.isOSVersionLT(18) && !Triple.isArm64e())
70 if (Triple.isWatchOS()) {
71 assert(!Triple.isSimulatorEnvironment() &&
"watchossim should be mac-like");
73 if (Triple.getArch() == llvm::Triple::aarch64_32 || Triple.isArm64e())
74 return Triple.isOSVersionLT(26) ?
"apple-s4" :
"apple-s6";
79 if (Triple.isXROS()) {
81 assert(!Triple.isSimulatorEnvironment() &&
"xrossim should be mac-like");
85 if (Triple.isArm64e())
89 if (Triple.isOSDarwin())
90 return Triple.getArch() == llvm::Triple::aarch64_32 ?
"apple-s4"
98 llvm::AArch64::ExtensionSet &Extensions) {
100 text.split(
Split, StringRef(
"+"), -1,
false);
104 D.
Diag(clang::diag::err_drv_no_neon_modifier);
107 if (!Extensions.parseModifier(
Feature))
115 llvm::StringMap<bool> HostFeatures = llvm::sys::getHostCPUFeatures();
117 for (
auto &[
Feature, Enabled] : HostFeatures) {
118 std::string F = (
"+" +
Feature).str();
119 if (
auto AE = llvm::AArch64::targetFeatureToExtension(F)) {
121 Extensions.enable(AE->ID);
123 Extensions.disable(AE->ID);
135 llvm::AArch64::ExtensionSet &Extensions) {
136 std::pair<StringRef, StringRef>
Split = Mcpu.split(
"+");
137 StringRef CPU =
Split.first;
138 const bool IsNative = CPU ==
"native";
141 CPU = llvm::sys::getHostCPUName();
143 const std::optional<llvm::AArch64::CpuInfo> CpuInfo =
144 llvm::AArch64::parseCpu(CPU);
148 Extensions.addCPUDefaults(*CpuInfo);
153 if (
Split.second.size() &&
163 llvm::AArch64::ExtensionSet &Extensions) {
164 std::string MarchLowerCase = March.lower();
165 std::pair<StringRef, StringRef>
Split = StringRef(MarchLowerCase).split(
"+");
167 if (
Split.first ==
"native")
170 const llvm::AArch64::ArchInfo *ArchInfo =
171 llvm::AArch64::parseArch(
Split.first);
175 Extensions.addArchDefaults(*ArchInfo);
177 if ((
Split.second.size() &&
187 llvm::AArch64::ExtensionSet &Extensions) {
188 std::string McpuLowerCase = Mcpu.lower();
194 const ArgList &Args) {
196 std::string MtuneLowerCase = Mtune.lower();
197 llvm::AArch64::ExtensionSet Extensions;
202 const ArgList &Args) {
207 const llvm::Triple &Triple,
209 std::vector<StringRef> &Features,
210 bool ForAS,
bool ForMultilib) {
213 llvm::StringRef WaMArch;
214 llvm::AArch64::ExtensionSet Extensions;
217 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
218 for (StringRef
Value : A->getValues())
219 if (
Value.starts_with(
"-march="))
220 WaMArch =
Value.substr(7);
224 if (!WaMArch.empty())
226 else if ((A = Args.getLastArg(options::OPT_march_EQ)))
229 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
239 if (success && (A = Args.getLastArg(options::OPT_mtune_EQ)))
241 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
248 auto Diag = D.
Diag(diag::err_drv_unsupported_option_argument);
251 if (!WaMArch.empty())
252 Diag <<
"-march=" << WaMArch;
254 Diag << A->getSpelling() << A->getValue();
258 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
259 Extensions.disable(llvm::AArch64::AEK_FP);
263 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
264 if (A->getOption().matches(options::OPT_mcrc))
265 Extensions.enable(llvm::AArch64::AEK_CRC);
267 Extensions.disable(llvm::AArch64::AEK_CRC);
272 Extensions.toLLVMFeatureList(Features);
274 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
275 StringRef Mtp = A->getValue();
276 if (Mtp ==
"el3" || Mtp ==
"tpidr_el3")
277 Features.push_back(
"+tpidr-el3");
278 else if (Mtp ==
"el2" || Mtp ==
"tpidr_el2")
279 Features.push_back(
"+tpidr-el2");
280 else if (Mtp ==
"el1" || Mtp ==
"tpidr_el1")
281 Features.push_back(
"+tpidr-el1");
282 else if (Mtp ==
"tpidrro_el0")
283 Features.push_back(
"+tpidrro-el0");
284 else if (Mtp !=
"el0" && Mtp !=
"tpidr_el0")
285 D.
Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
289 if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
290 StringRef
Scope = A->getValue();
291 bool EnableRetBr =
false;
292 bool EnableBlr =
false;
293 bool DisableComdat =
false;
294 if (
Scope !=
"none") {
296 Scope.split(Opts,
",");
297 for (
auto Opt : Opts) {
304 if (Opt ==
"retbr") {
312 if (Opt ==
"comdat") {
313 DisableComdat =
false;
316 if (Opt ==
"nocomdat") {
317 DisableComdat =
true;
320 D.
Diag(diag::err_drv_unsupported_option_argument)
321 << A->getSpelling() <<
Scope;
327 Features.push_back(
"+harden-sls-retbr");
329 Features.push_back(
"+harden-sls-blr");
331 Features.push_back(
"+harden-sls-nocomdat");
335 if (Arg *A = Args.getLastArg(
336 options::OPT_mstrict_align, options::OPT_mno_strict_align,
337 options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
338 if (A->getOption().matches(options::OPT_mstrict_align) ||
339 A->getOption().matches(options::OPT_mno_unaligned_access))
340 Features.push_back(
"+strict-align");
341 }
else if (Triple.isOSOpenBSD())
342 Features.push_back(
"+strict-align");
348 if (!ForAS && !ForMultilib) {
349 if (Arg *A = Args.getLastArg(options::OPT_mexecute_only,
350 options::OPT_mno_execute_only)) {
351 if (A->getOption().matches(options::OPT_mexecute_only)) {
352 Features.push_back(
"+execute-only");
357 if (Args.hasArg(options::OPT_ffixed_x1))
358 Features.push_back(
"+reserve-x1");
360 if (Args.hasArg(options::OPT_ffixed_x2))
361 Features.push_back(
"+reserve-x2");
363 if (Args.hasArg(options::OPT_ffixed_x3))
364 Features.push_back(
"+reserve-x3");
366 if (Args.hasArg(options::OPT_ffixed_x4))
367 Features.push_back(
"+reserve-x4");
369 if (Args.hasArg(options::OPT_ffixed_x5))
370 Features.push_back(
"+reserve-x5");
372 if (Args.hasArg(options::OPT_ffixed_x6))
373 Features.push_back(
"+reserve-x6");
375 if (Args.hasArg(options::OPT_ffixed_x7))
376 Features.push_back(
"+reserve-x7");
378 if (Args.hasArg(options::OPT_ffixed_x9))
379 Features.push_back(
"+reserve-x9");
381 if (Args.hasArg(options::OPT_ffixed_x10))
382 Features.push_back(
"+reserve-x10");
384 if (Args.hasArg(options::OPT_ffixed_x11))
385 Features.push_back(
"+reserve-x11");
387 if (Args.hasArg(options::OPT_ffixed_x12))
388 Features.push_back(
"+reserve-x12");
390 if (Args.hasArg(options::OPT_ffixed_x13))
391 Features.push_back(
"+reserve-x13");
393 if (Args.hasArg(options::OPT_ffixed_x14))
394 Features.push_back(
"+reserve-x14");
396 if (Args.hasArg(options::OPT_ffixed_x15))
397 Features.push_back(
"+reserve-x15");
399 if (Args.hasArg(options::OPT_ffixed_x18))
400 Features.push_back(
"+reserve-x18");
402 if (Args.hasArg(options::OPT_ffixed_x20))
403 Features.push_back(
"+reserve-x20");
405 if (Args.hasArg(options::OPT_ffixed_x21))
406 Features.push_back(
"+reserve-x21");
408 if (Args.hasArg(options::OPT_ffixed_x22))
409 Features.push_back(
"+reserve-x22");
411 if (Args.hasArg(options::OPT_ffixed_x23))
412 Features.push_back(
"+reserve-x23");
414 if (Args.hasArg(options::OPT_ffixed_x24))
415 Features.push_back(
"+reserve-x24");
417 if (Args.hasArg(options::OPT_ffixed_x25))
418 Features.push_back(
"+reserve-x25");
420 if (Args.hasArg(options::OPT_ffixed_x26))
421 Features.push_back(
"+reserve-x26");
423 if (Args.hasArg(options::OPT_ffixed_x27))
424 Features.push_back(
"+reserve-x27");
426 if (Args.hasArg(options::OPT_ffixed_x28))
427 Features.push_back(
"+reserve-x28");
429 if (Args.hasArg(options::OPT_mlr_for_calls_only))
430 Features.push_back(
"+reserve-lr-for-ra");
432 if (Args.hasArg(options::OPT_fcall_saved_x8))
433 Features.push_back(
"+call-saved-x8");
435 if (Args.hasArg(options::OPT_fcall_saved_x9))
436 Features.push_back(
"+call-saved-x9");
438 if (Args.hasArg(options::OPT_fcall_saved_x10))
439 Features.push_back(
"+call-saved-x10");
441 if (Args.hasArg(options::OPT_fcall_saved_x11))
442 Features.push_back(
"+call-saved-x11");
444 if (Args.hasArg(options::OPT_fcall_saved_x12))
445 Features.push_back(
"+call-saved-x12");
447 if (Args.hasArg(options::OPT_fcall_saved_x13))
448 Features.push_back(
"+call-saved-x13");
450 if (Args.hasArg(options::OPT_fcall_saved_x14))
451 Features.push_back(
"+call-saved-x14");
453 if (Args.hasArg(options::OPT_fcall_saved_x15))
454 Features.push_back(
"+call-saved-x15");
456 if (Args.hasArg(options::OPT_fcall_saved_x18))
457 Features.push_back(
"+call-saved-x18");
459 if (Args.hasArg(options::OPT_mno_neg_immediates))
460 Features.push_back(
"+no-neg-immediates");
462 if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769,
463 options::OPT_mno_fix_cortex_a53_835769)) {
464 if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769))
465 Features.push_back(
"+fix-cortex-a53-835769");
467 Features.push_back(
"-fix-cortex-a53-835769");
468 }
else if (Extensions.BaseArch &&
469 Extensions.BaseArch->Version.getMajor() == 8 &&
470 Extensions.BaseArch->Version.getMinor() == 0) {
471 if (Triple.isAndroid() || Triple.isOHOSFamily()) {
474 Features.push_back(
"+fix-cortex-a53-835769");
475 }
else if (Triple.isOSFuchsia()) {
477 if (
CPU.empty() || CPU ==
"generic" || CPU ==
"cortex-a53")
478 Features.push_back(
"+fix-cortex-a53-835769");
482 if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
483 Features.push_back(
"+no-bti-at-return-twice");
488 if (Triple.getArch() != llvm::Triple::aarch64 &&
489 Triple.getArch() != llvm::Triple::aarch64_be)
492 if (Triple.getVendor() != llvm::Triple::UnknownVendor)
495 if (Triple.getOS() != llvm::Triple::UnknownOS)
498 return Triple.getEnvironmentName() ==
"elf";
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...
DiagnosticBuilder Diag(unsigned DiagID) const
The JSON file list parser is used to communicate input to InstallAPI.