13#include "llvm/ADT/StringSwitch.h"
14#include "llvm/Option/ArgList.h"
15#include "llvm/TargetParser/ARMTargetParser.h"
16#include "llvm/TargetParser/Host.h"
25 llvm::StringRef Arch = Triple.getArchName();
26 return llvm::ARM::parseArchVersion(Arch);
31 llvm::StringRef Arch = Triple.getArchName();
32 return llvm::ARM::parseArchProfile(Arch) == llvm::ARM::ProfileKind::M;
40 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
41 options::OPT_mbig_endian)) {
42 return !A->getOption().matches(options::OPT_mlittle_endian);
45 return Triple.getArch() == llvm::Triple::armeb ||
46 Triple.getArch() == llvm::Triple::thumbeb;
51 llvm::StringRef Arch = Triple.getArchName();
52 return llvm::ARM::parseArchProfile(Arch) == llvm::ARM::ProfileKind::A;
57 auto arch = Triple.getArch();
58 if (
arch != llvm::Triple::arm &&
arch != llvm::Triple::thumb &&
59 arch != llvm::Triple::armeb &&
arch != llvm::Triple::thumbeb)
62 if (Triple.getVendor() != llvm::Triple::UnknownVendor)
65 if (Triple.getOS() != llvm::Triple::UnknownOS)
68 if (Triple.getEnvironment() != llvm::Triple::EABI &&
69 Triple.getEnvironment() != llvm::Triple::EABIHF)
77 llvm::StringRef &CPU,
bool FromAs) {
78 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
80 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
86 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
89 for (StringRef
Value : A->getValues()) {
90 if (
Value.starts_with(
"-mcpu="))
91 CPU =
Value.substr(6);
92 if (
Value.starts_with(
"-march="))
93 Arch =
Value.substr(7);
101 const ArgList &Args, StringRef HWDiv,
102 std::vector<StringRef> &Features) {
103 uint64_t HWDivID = llvm::ARM::parseHWDiv(HWDiv);
104 if (!llvm::ARM::getHWDivFeatures(HWDivID, Features))
105 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
110 const ArgList &Args, StringRef FPU,
111 std::vector<StringRef> &Features) {
112 llvm::ARM::FPUKind FPUKind = llvm::ARM::parseFPU(FPU);
113 if (!llvm::ARM::getFPUFeatures(FPUKind, Features))
114 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
120 llvm::ARM::ArchKind ArchKind,
121 std::vector<StringRef> &Features,
122 llvm::ARM::FPUKind &ArgFPUKind) {
124 text.split(
Split, StringRef(
"+"), -1,
false);
126 for (StringRef Feature :
Split) {
127 if (!appendArchExtFeatures(CPU, ArchKind, Feature, Features, ArgFPUKind))
134 std::vector<StringRef> &Features) {
135 CPU = CPU.split(
"+").first;
136 if (CPU !=
"generic") {
137 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseCPUArch(CPU);
138 uint64_t Extension = llvm::ARM::getDefaultExtensions(CPU, ArchKind);
139 llvm::ARM::getExtensionFeatures(Extension, Features);
147 llvm::StringRef ArchName, llvm::StringRef CPUName,
148 std::vector<StringRef> &Features,
149 const llvm::Triple &Triple,
150 llvm::ARM::FPUKind &ArgFPUKind) {
151 std::pair<StringRef, StringRef>
Split = ArchName.split(
"+");
154 llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(MArch);
155 if (ArchKind == llvm::ARM::ArchKind::INVALID ||
156 (
Split.second.size() &&
159 D.Diag(clang::diag::err_drv_unsupported_option_argument)
160 << A->getSpelling() << A->getValue();
165 llvm::StringRef CPUName, llvm::StringRef ArchName,
166 std::vector<StringRef> &Features,
167 const llvm::Triple &Triple,
168 llvm::ARM::FPUKind &ArgFPUKind) {
169 std::pair<StringRef, StringRef>
Split = CPUName.split(
"+");
172 llvm::ARM::ArchKind ArchKind =
174 if (ArchKind == llvm::ARM::ArchKind::INVALID ||
176 Features, ArgFPUKind)))
177 D.Diag(clang::diag::err_drv_unsupported_option_argument)
178 << A->getSpelling() << A->getValue();
188 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
189 options::OPT_mfloat_abi_EQ);
190 if (A && (A->getOption().matches(options::OPT_mhard_float) ||
191 (A->getOption().matches(options::OPT_mfloat_abi_EQ) &&
192 A->getValue() == StringRef(
"hard"))))
193 D.Diag(clang::diag::warn_drv_no_floating_point_registers)
194 << A->getAsString(Args);
200 return T.getEnvironment() == llvm::Triple::EABI ||
201 T.getEnvironment() == llvm::Triple::EABIHF ||
210 llvm::ARM::ArchKind AK = llvm::ARM::parseArch(Triple.getArchName());
211 return Triple.isARM() || AK == llvm::ARM::ArchKind::ARMV6T2 ||
212 (Ver >= 7 && AK != llvm::ARM::ArchKind::ARMV8MBaseline);
217 const llvm::Triple &Triple,
bool ForAS) {
218 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
220 llvm::StringSwitch<arm::ReadTPMode>(A->getValue())
221 .Case(
"cp15", ReadTPMode::TPIDRURO)
222 .Case(
"tpidrurw", ReadTPMode::TPIDRURW)
223 .Case(
"tpidruro", ReadTPMode::TPIDRURO)
224 .Case(
"tpidrprw", ReadTPMode::TPIDRPRW)
225 .Case(
"soft", ReadTPMode::Soft)
226 .Default(ReadTPMode::Invalid);
227 if ((ThreadPointer == ReadTPMode::TPIDRURW ||
228 ThreadPointer == ReadTPMode::TPIDRURO ||
229 ThreadPointer == ReadTPMode::TPIDRPRW) &&
230 !isHardTPSupported(Triple) && !ForAS) {
231 D.Diag(diag::err_target_unsupported_tp_hard) << Triple.getArchName();
232 return ReadTPMode::Invalid;
234 if (ThreadPointer != ReadTPMode::Invalid)
235 return ThreadPointer;
236 if (StringRef(A->getValue()).empty())
237 D.Diag(diag::err_drv_missing_arg_mtp) << A->getAsString(Args);
239 D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
240 return ReadTPMode::Invalid;
242 return ReadTPMode::Soft;
246 types::ID InputType, llvm::Triple &Triple) {
247 StringRef MCPU, MArch;
248 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
249 MCPU = A->getValue();
250 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
251 MArch = A->getValue();
253 std::string CPU = Triple.isOSBinFormatMachO()
258 bool IsBigEndian = Triple.getArch() == llvm::Triple::armeb ||
259 Triple.getArch() == llvm::Triple::thumbeb;
262 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
263 options::OPT_mbig_endian)) {
264 IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian);
266 std::string ArchName = IsBigEndian ?
"armeb" :
"arm";
270 llvm::ARM::parseArchProfile(Suffix) == llvm::ARM::ProfileKind::M;
271 bool ThumbDefault = IsMProfile ||
273 (llvm::ARM::parseArchVersion(Suffix) == 7 &&
274 Triple.isOSBinFormatMachO()) ||
276 Triple.isOSWindows();
280 bool ARMModeRequested =
281 !Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault);
282 if (IsMProfile && ARMModeRequested) {
284 D.Diag(diag::err_cpu_unsupported_isa) << CPU <<
"ARM";
286 D.Diag(diag::err_arch_unsupported_isa)
293 bool IsThumb =
false;
294 if (InputType != types::TY_PP_Asm)
296 Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb, ThumbDefault);
301 llvm::StringRef WaMArch, WaMCPU;
303 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
304 for (StringRef
Value : A->getValues()) {
306 if (
Value ==
"-mthumb")
308 else if (
Value.starts_with(
"-march="))
309 WaMArch =
Value.substr(7);
310 else if (
Value.starts_with(
"-mcpu="))
311 WaMCPU =
Value.substr(6);
315 if (WaMCPU.size() || WaMArch.size()) {
325 if (IsThumb || IsMProfile || Triple.isOSWindows()) {
327 ArchName =
"thumbeb";
331 Triple.setArchName(ArchName + Suffix.str());
335 llvm::Triple &Triple) {
336 if (Triple.isOSLiteOS()) {
337 Triple.setEnvironment(llvm::Triple::OpenHOS);
344 switch (Triple.getEnvironment()) {
345 case llvm::Triple::GNUEABI:
346 case llvm::Triple::GNUEABIHF:
347 Triple.setEnvironment(isHardFloat ? llvm::Triple::GNUEABIHF
348 : llvm::Triple::GNUEABI);
350 case llvm::Triple::GNUEABIT64:
351 case llvm::Triple::GNUEABIHFT64:
352 Triple.setEnvironment(isHardFloat ? llvm::Triple::GNUEABIHFT64
353 : llvm::Triple::GNUEABIT64);
355 case llvm::Triple::EABI:
356 case llvm::Triple::EABIHF:
357 Triple.setEnvironment(isHardFloat ? llvm::Triple::EABIHF
358 : llvm::Triple::EABI);
360 case llvm::Triple::MuslEABI:
361 case llvm::Triple::MuslEABIHF:
362 Triple.setEnvironment(isHardFloat ? llvm::Triple::MuslEABIHF
363 : llvm::Triple::MuslEABI);
365 case llvm::Triple::OpenHOS:
369 if (DefaultABI != arm::FloatABI::Invalid &&
370 isHardFloat != (DefaultABI == arm::FloatABI::Hard)) {
372 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
373 options::OPT_mfloat_abi_EQ);
374 assert(ABIArg &&
"Non-default float abi expected to be from arg");
375 D.Diag(diag::err_drv_unsupported_opt_for_target)
376 << ABIArg->getAsString(Args) << Triple.getTriple();
389 switch (Triple.getOS()) {
390 case llvm::Triple::Darwin:
391 case llvm::Triple::MacOSX:
392 case llvm::Triple::IOS:
393 case llvm::Triple::TvOS:
394 case llvm::Triple::DriverKit:
395 case llvm::Triple::XROS:
397 if (Triple.isWatchABI())
398 return FloatABI::Hard;
400 return (SubArch == 6 || SubArch == 7) ? FloatABI::SoftFP : FloatABI::Soft;
402 case llvm::Triple::WatchOS:
403 return FloatABI::Hard;
406 case llvm::Triple::Win32:
410 return FloatABI::Soft;
411 return FloatABI::Hard;
413 case llvm::Triple::NetBSD:
414 switch (Triple.getEnvironment()) {
415 case llvm::Triple::EABIHF:
416 case llvm::Triple::GNUEABIHF:
417 return FloatABI::Hard;
419 return FloatABI::Soft;
423 case llvm::Triple::FreeBSD:
424 switch (Triple.getEnvironment()) {
425 case llvm::Triple::GNUEABIHF:
426 return FloatABI::Hard;
429 return FloatABI::Soft;
433 case llvm::Triple::Haiku:
434 case llvm::Triple::OpenBSD:
435 return FloatABI::SoftFP;
438 if (Triple.isOHOSFamily())
439 return FloatABI::Soft;
440 switch (Triple.getEnvironment()) {
441 case llvm::Triple::GNUEABIHF:
442 case llvm::Triple::GNUEABIHFT64:
443 case llvm::Triple::MuslEABIHF:
444 case llvm::Triple::EABIHF:
445 return FloatABI::Hard;
446 case llvm::Triple::GNUEABI:
447 case llvm::Triple::GNUEABIT64:
448 case llvm::Triple::MuslEABI:
449 case llvm::Triple::EABI:
451 return FloatABI::SoftFP;
452 case llvm::Triple::Android:
453 return (SubArch >= 7) ? FloatABI::SoftFP : FloatABI::Soft;
455 return FloatABI::Invalid;
458 return FloatABI::Invalid;
464 const ArgList &Args) {
467 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
468 options::OPT_mfloat_abi_EQ)) {
469 if (A->getOption().matches(options::OPT_msoft_float)) {
470 ABI = FloatABI::Soft;
471 }
else if (A->getOption().matches(options::OPT_mhard_float)) {
472 ABI = FloatABI::Hard;
474 ABI = llvm::StringSwitch<arm::FloatABI>(A->getValue())
475 .Case(
"soft", FloatABI::Soft)
476 .Case(
"softfp", FloatABI::SoftFP)
477 .Case(
"hard", FloatABI::Hard)
478 .Default(FloatABI::Invalid);
479 if (ABI == FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
480 D.Diag(diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
481 ABI = FloatABI::Soft;
487 if (ABI == FloatABI::Invalid)
490 if (ABI == FloatABI::Invalid) {
492 if (Triple.isOSBinFormatMachO() &&
493 Triple.getSubArch() == llvm::Triple::ARMSubArch_v7em)
494 ABI = FloatABI::Hard;
496 ABI = FloatABI::Soft;
498 if (Triple.getOS() != llvm::Triple::UnknownOS ||
499 !Triple.isOSBinFormatMachO())
500 D.Diag(diag::warn_drv_assuming_mfloat_abi_is) <<
"soft";
503 assert(ABI != FloatABI::Invalid &&
"must select an ABI");
508 auto MVE = llvm::find(llvm::reverse(F),
"+mve");
509 auto NoMVE = llvm::find(llvm::reverse(F),
"-mve");
510 return MVE != F.rend() &&
511 (NoMVE == F.rend() || std::distance(MVE, NoMVE) > 0);
515 const llvm::Triple &Triple,
517 std::vector<StringRef> &Features,
518 bool ForAS,
bool ForMultilib) {
520 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
522 std::optional<std::pair<const Arg *, StringRef>> WaCPU, WaFPU, WaHDiv, WaArch;
529 std::vector<StringRef> ExtensionFeatures;
545 if (ABI == arm::FloatABI::Soft)
546 Features.push_back(
"+soft-float");
549 if (ABI != arm::FloatABI::Hard)
550 Features.push_back(
"+soft-float-abi");
555 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
558 for (StringRef
Value : A->getValues()) {
559 if (
Value.starts_with(
"-mfpu=")) {
560 WaFPU = std::make_pair(A,
Value.substr(6));
561 }
else if (
Value.starts_with(
"-mcpu=")) {
562 WaCPU = std::make_pair(A,
Value.substr(6));
563 }
else if (
Value.starts_with(
"-mhwdiv=")) {
564 WaHDiv = std::make_pair(A,
Value.substr(8));
565 }
else if (
Value.starts_with(
"-march=")) {
566 WaArch = std::make_pair(A,
Value.substr(7));
574 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
575 A->ignoreTargetSpecific();
578 if (
getReadTPMode(
D, Args, Triple, ForAS) == ReadTPMode::TPIDRURW)
579 Features.push_back(
"+read-tp-tpidrurw");
580 if (
getReadTPMode(
D, Args, Triple, ForAS) == ReadTPMode::TPIDRURO)
581 Features.push_back(
"+read-tp-tpidruro");
582 if (
getReadTPMode(
D, Args, Triple, ForAS) == ReadTPMode::TPIDRPRW)
583 Features.push_back(
"+read-tp-tpidrprw");
585 const Arg *ArchArg = Args.getLastArg(options::OPT_march_EQ);
586 const Arg *CPUArg = Args.getLastArg(options::OPT_mcpu_EQ);
589 llvm::ARM::FPUKind ArchArgFPUKind = llvm::ARM::FK_INVALID;
590 llvm::ARM::FPUKind CPUArgFPUKind = llvm::ARM::FK_INVALID;
595 D.Diag(clang::diag::warn_drv_unused_argument)
596 << CPUArg->getAsString(Args);
597 CPUName = WaCPU->second;
598 CPUArg = WaCPU->first;
600 CPUName = CPUArg->getValue();
605 D.Diag(clang::diag::warn_drv_unused_argument)
606 << ArchArg->getAsString(Args);
607 ArchName = WaArch->second;
610 ExtensionFeatures, Triple, ArchArgFPUKind);
613 }
else if (ArchArg) {
614 ArchName = ArchArg->getValue();
616 Triple, ArchArgFPUKind);
620 if (CPUName ==
"native") {
621 for (
auto &F : llvm::sys::getHostCPUFeatures())
623 Args.MakeArgString((F.second ?
"+" :
"-") + F.first()));
624 }
else if (!CPUName.empty()) {
634 Triple, CPUArgFPUKind);
638 (void)Args.getLastArg(options::OPT_mtune_EQ);
641 llvm::ARM::FPUKind FPUKind = llvm::ARM::FK_INVALID;
642 const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
645 D.Diag(clang::diag::warn_drv_unused_argument)
646 << FPUArg->getAsString(Args);
651 const char *AndroidFPU =
"neon";
652 FPUKind = llvm::ARM::parseFPU(AndroidFPU);
653 if (!llvm::ARM::getFPUFeatures(FPUKind, Features))
654 D.Diag(clang::diag::err_drv_clang_unsupported)
655 << std::string(
"-mfpu=") + AndroidFPU;
656 }
else if (ArchArgFPUKind != llvm::ARM::FK_INVALID ||
657 CPUArgFPUKind != llvm::ARM::FK_INVALID) {
659 CPUArgFPUKind != llvm::ARM::FK_INVALID ? CPUArgFPUKind : ArchArgFPUKind;
660 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
664 llvm::ARM::ArchKind ArchKind =
666 FPUKind = llvm::ARM::getDefaultFPU(CPU, ArchKind);
667 (void)llvm::ARM::getFPUFeatures(FPUKind, Features);
674 Features.insert(std::end(Features),
675 std::begin(ExtensionFeatures), std::end(ExtensionFeatures));
678 const Arg *HDivArg = Args.getLastArg(options::OPT_mhwdiv_EQ);
681 D.Diag(clang::diag::warn_drv_unused_argument)
682 << HDivArg->getAsString(Args);
691 const auto ItRNoFullFP16 = std::find(Features.rbegin(), Features.rend(),
"-fullfp16");
692 const auto ItRFP16FML = std::find(Features.rbegin(), Features.rend(),
"+fp16fml");
693 if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8_4a) {
694 const auto ItRFullFP16 = std::find(Features.rbegin(), Features.rend(),
"+fullfp16");
695 if (ItRFullFP16 < ItRNoFullFP16 && ItRFullFP16 < ItRFP16FML) {
698 if (std::find(Features.rbegin(), ItRFullFP16,
"-fp16fml") == ItRFullFP16)
699 Features.push_back(
"+fp16fml");
702 goto fp16_fml_fallthrough;
708 if (ItRNoFullFP16 < ItRFP16FML)
709 Features.push_back(
"-fp16fml");
710 else if (ItRNoFullFP16 > ItRFP16FML)
711 Features.push_back(
"+fullfp16");
718 bool HasFPRegs =
true;
719 if (ABI == arm::FloatABI::Soft) {
720 llvm::ARM::getFPUFeatures(llvm::ARM::FK_NONE, Features);
724 Features.insert(Features.end(),
725 {
"-dotprod",
"-fp16fml",
"-bf16",
"-mve",
"-mve.fp"});
727 FPUKind = llvm::ARM::FK_NONE;
728 }
else if (FPUKind == llvm::ARM::FK_NONE ||
729 ArchArgFPUKind == llvm::ARM::FK_NONE ||
730 CPUArgFPUKind == llvm::ARM::FK_NONE) {
735 Features.insert(Features.end(),
736 {
"-dotprod",
"-fp16fml",
"-bf16",
"-mve.fp"});
738 FPUKind = llvm::ARM::FK_NONE;
741 Features.emplace_back(
"-fpregs");
744 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
745 if (A->getOption().matches(options::OPT_mcrc))
746 Features.push_back(
"+crc");
748 Features.push_back(
"-crc");
759 bool HasSHA2 =
false;
761 const auto ItCrypto =
762 llvm::find_if(llvm::reverse(Features), [](
const StringRef F) {
763 return F.contains(
"crypto");
766 llvm::find_if(llvm::reverse(Features), [](
const StringRef F) {
767 return F.contains(
"crypto") || F.contains(
"sha2");
770 llvm::find_if(llvm::reverse(Features), [](
const StringRef F) {
771 return F.contains(
"crypto") || F.contains(
"aes");
773 const bool FoundSHA2 = ItSHA2 != Features.rend();
774 const bool FoundAES = ItAES != Features.rend();
776 HasSHA2 = ItSHA2->take_front() ==
"+";
778 HasAES = ItAES->take_front() ==
"+";
779 if (ItCrypto != Features.rend()) {
780 if (HasSHA2 && HasAES)
781 Features.push_back(
"+crypto");
783 Features.push_back(
"-crypto");
785 Features.push_back(
"+sha2");
787 Features.push_back(
"-sha2");
789 Features.push_back(
"+aes");
791 Features.push_back(
"-aes");
794 if (HasSHA2 || HasAES) {
797 llvm::ARM::ProfileKind ArchProfile =
798 llvm::ARM::parseArchProfile(ArchSuffix);
799 if (!((llvm::ARM::parseArchVersion(ArchSuffix) >= 8) &&
800 (ArchProfile == llvm::ARM::ProfileKind::A ||
801 ArchProfile == llvm::ARM::ProfileKind::R))) {
803 D.Diag(clang::diag::warn_target_unsupported_extension)
805 << llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
807 D.Diag(clang::diag::warn_target_unsupported_extension)
809 << llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
815 if (!Args.hasArg(options::OPT_fno_integrated_as)) {
816 Features.push_back(
"-sha2");
817 Features.push_back(
"-aes");
823 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
824 StringRef FrameChainOption = A->getValue();
825 if (FrameChainOption.starts_with(
"aapcs"))
826 Features.push_back(
"+aapcs-frame-chain");
830 if (Args.getLastArg(options::OPT_mcmse))
831 Features.push_back(
"+8msecext");
833 if (Arg *A = Args.getLastArg(options::OPT_mfix_cmse_cve_2021_35465,
834 options::OPT_mno_fix_cmse_cve_2021_35465)) {
835 if (!Args.getLastArg(options::OPT_mcmse))
836 D.Diag(diag::err_opt_not_valid_without_opt)
837 << A->getOption().getName() <<
"-mcmse";
839 if (A->getOption().matches(options::OPT_mfix_cmse_cve_2021_35465))
840 Features.push_back(
"+fix-cmse-cve-2021-35465");
842 Features.push_back(
"-fix-cmse-cve-2021-35465");
846 if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a57_aes_1742098,
847 options::OPT_mno_fix_cortex_a57_aes_1742098)) {
848 if (A->getOption().matches(options::OPT_mfix_cortex_a57_aes_1742098)) {
849 Features.push_back(
"+fix-cortex-a57-aes-1742098");
851 Features.push_back(
"-fix-cortex-a57-aes-1742098");
858 if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
859 options::OPT_mno_long_calls)) {
860 if (A->getOption().matches(options::OPT_mlong_calls))
861 Features.push_back(
"+long-calls");
862 }
else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
863 !Triple.isWatchOS() && !Triple.isXROS()) {
864 Features.push_back(
"+long-calls");
871 if (!ForAS && !ForMultilib) {
874 if (Arg *A = Args.getLastArg(options::OPT_mexecute_only, options::OPT_mno_execute_only)) {
875 if (A->getOption().matches(options::OPT_mexecute_only)) {
877 llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2 &&
878 llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6M)
879 D.Diag(diag::err_target_unsupported_execute_only) << Triple.getArchName();
880 else if (llvm::ARM::parseArch(Triple.getArchName()) == llvm::ARM::ArchKind::ARMV6M) {
881 if (Arg *PIArg = Args.getLastArg(options::OPT_fropi, options::OPT_frwpi,
882 options::OPT_fpic, options::OPT_fpie,
883 options::OPT_fPIC, options::OPT_fPIE))
884 D.Diag(diag::err_opt_not_valid_with_opt_on_target)
885 << A->getAsString(Args) << PIArg->getAsString(Args) << Triple.getArchName();
886 }
else if (Arg *B = Args.getLastArg(options::OPT_mno_movt))
887 D.Diag(diag::err_opt_not_valid_with_opt)
888 << A->getAsString(Args) << B->getAsString(Args);
889 Features.push_back(
"+execute-only");
894 if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
895 options::OPT_munaligned_access,
896 options::OPT_mstrict_align,
897 options::OPT_mno_strict_align)) {
900 A->getOption().matches(options::OPT_mno_unaligned_access) ||
901 A->getOption().matches(options::OPT_mstrict_align)) {
902 Features.push_back(
"+strict-align");
905 if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
906 D.Diag(diag::err_target_unsupported_unaligned) <<
"v6m";
909 else if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
910 D.Diag(diag::err_target_unsupported_unaligned) <<
"v8m.base";
927 if (Triple.isOSDarwin() || Triple.isOSNetBSD()) {
928 if (VersionNum < 6 ||
929 Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
930 Features.push_back(
"+strict-align");
931 }
else if (Triple.getVendor() == llvm::Triple::Apple &&
932 Triple.isOSBinFormatMachO()) {
934 Features.push_back(
"+strict-align");
935 }
else if (VersionNum < 7 ||
936 Triple.getSubArch() ==
937 llvm::Triple::SubArchType::ARMSubArch_v6m ||
938 Triple.getSubArch() ==
939 llvm::Triple::SubArchType::ARMSubArch_v8m_baseline) {
940 Features.push_back(
"+strict-align");
947 if (Args.hasArg(options::OPT_ffixed_r9))
948 Features.push_back(
"+reserve-r9");
951 if (KernelOrKext || Args.hasArg(options::OPT_mno_movt))
952 Features.push_back(
"+no-movt");
954 if (Args.hasArg(options::OPT_mno_neg_immediates))
955 Features.push_back(
"+no-neg-immediates");
958 if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
959 StringRef
Scope = A->getValue();
960 bool EnableRetBr =
false;
961 bool EnableBlr =
false;
962 bool DisableComdat =
false;
963 if (
Scope !=
"none") {
965 Scope.split(Opts,
",");
966 for (
auto Opt : Opts) {
973 if (Opt ==
"retbr") {
981 if (Opt ==
"comdat") {
982 DisableComdat =
false;
985 if (Opt ==
"nocomdat") {
986 DisableComdat =
true;
989 D.Diag(diag::err_drv_unsupported_option_argument)
990 << A->getSpelling() <<
Scope;
995 if (EnableRetBr || EnableBlr)
997 D.Diag(diag::err_sls_hardening_arm_not_supported)
998 <<
Scope << A->getAsString(Args);
1001 Features.push_back(
"+harden-sls-retbr");
1003 Features.push_back(
"+harden-sls-blr");
1004 if (DisableComdat) {
1005 Features.push_back(
"+harden-sls-nocomdat");
1009 if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
1010 Features.push_back(
"+no-bti-at-return-twice");
1017std::string
arm::getARMArch(StringRef Arch,
const llvm::Triple &Triple) {
1020 MArch = std::string(Arch);
1022 MArch = std::string(Triple.getArchName());
1023 MArch = StringRef(MArch).split(
"+").first.lower();
1026 if (MArch ==
"native") {
1027 std::string CPU = std::string(llvm::sys::getHostCPUName());
1028 if (CPU !=
"generic") {
1036 MArch = std::string(
"arm") + Suffix.str();
1045 std::string MArch =
getARMArch(Arch, Triple);
1053 return llvm::ARM::getARMCPUForArch(Triple, MArch);
1058 const llvm::Triple &Triple) {
1062 std::string MCPU = StringRef(CPU).split(
"+").first.lower();
1064 if (MCPU ==
"native")
1065 return std::string(llvm::sys::getHostCPUName());
1078 const llvm::Triple &Triple) {
1079 llvm::ARM::ArchKind ArchKind;
1080 if (CPU ==
"generic" || CPU.empty()) {
1082 ArchKind = llvm::ARM::parseArch(ARMArch);
1083 if (ArchKind == llvm::ARM::ArchKind::INVALID)
1087 llvm::ARM::parseCPUArch(llvm::ARM::getARMCPUForArch(Triple, ARMArch));
1091 ArchKind = (Arch ==
"armv7k" || Arch ==
"thumbv7k")
1092 ? llvm::ARM::ArchKind::ARMV7K
1093 : llvm::ARM::parseCPUArch(CPU);
1102 const llvm::Triple &Triple) {
1103 llvm::ARM::ArchKind ArchKind = getLLVMArchKindForARM(CPU, Arch, Triple);
1104 if (ArchKind == llvm::ARM::ArchKind::INVALID)
1106 return llvm::ARM::getSubArch(ArchKind);
1110 const llvm::Triple &Triple) {
1111 if (Args.hasArg(options::OPT_r))
1117 CmdArgs.push_back(
"--be8");
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.
const FunctionProtoType * T