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 if (CPU ==
"generic") {
102 Extensions.enable(llvm::AArch64::AEK_SIMD);
104 const std::optional<llvm::AArch64::CpuInfo> CpuInfo =
105 llvm::AArch64::parseCpu(CPU);
109 Extensions.addCPUDefaults(*CpuInfo);
112 if (
Split.second.size() &&
122 llvm::AArch64::ExtensionSet &Extensions) {
123 std::string MarchLowerCase = March.lower();
124 std::pair<StringRef, StringRef>
Split = StringRef(MarchLowerCase).split(
"+");
126 const llvm::AArch64::ArchInfo *ArchInfo =
127 llvm::AArch64::parseArch(
Split.first);
128 if (
Split.first ==
"native")
129 ArchInfo = llvm::AArch64::getArchForCpu(llvm::sys::getHostCPUName().str());
133 Extensions.addArchDefaults(*ArchInfo);
135 if ((
Split.second.size() &&
145 llvm::AArch64::ExtensionSet &Extensions) {
147 std::string McpuLowerCase = Mcpu.lower();
157 std::vector<StringRef> &Features) {
158 std::string MtuneLowerCase = Mtune.lower();
160 llvm::AArch64::ExtensionSet Extensions;
166 if (MtuneLowerCase ==
"native")
167 MtuneLowerCase = std::string(llvm::sys::getHostCPUName());
170 if (MtuneLowerCase ==
"cyclone" ||
171 StringRef(MtuneLowerCase).starts_with(
"apple")) {
172 Features.push_back(
"+zcm");
173 Features.push_back(
"+zcz");
182 std::vector<StringRef> &Features) {
185 llvm::AArch64::ExtensionSet DecodedFeature;
186 std::string McpuLowerCase = Mcpu.lower();
194 const llvm::Triple &Triple,
196 std::vector<StringRef> &Features,
200 llvm::StringRef WaMArch;
201 llvm::AArch64::ExtensionSet Extensions;
204 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler))
205 for (StringRef
Value : A->getValues())
206 if (
Value.starts_with(
"-march="))
207 WaMArch =
Value.substr(7);
211 if (!WaMArch.empty())
213 else if ((A = Args.getLastArg(options::OPT_march_EQ)))
216 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
226 if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
229 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
237 auto Diag = D.
Diag(diag::err_drv_unsupported_option_argument);
240 if (!WaMArch.empty())
241 Diag <<
"-march=" << WaMArch;
243 Diag << A->getSpelling() << A->getValue();
247 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
248 Extensions.disable(llvm::AArch64::AEK_FP);
252 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
253 if (A->getOption().matches(options::OPT_mcrc))
254 Extensions.enable(llvm::AArch64::AEK_CRC);
256 Extensions.disable(llvm::AArch64::AEK_CRC);
261 Extensions.toLLVMFeatureList(Features);
263 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
264 StringRef Mtp = A->getValue();
265 if (Mtp ==
"el3" || Mtp ==
"tpidr_el3")
266 Features.push_back(
"+tpidr-el3");
267 else if (Mtp ==
"el2" || Mtp ==
"tpidr_el2")
268 Features.push_back(
"+tpidr-el2");
269 else if (Mtp ==
"el1" || Mtp ==
"tpidr_el1")
270 Features.push_back(
"+tpidr-el1");
271 else if (Mtp ==
"tpidrro_el0")
272 Features.push_back(
"+tpidrro-el0");
273 else if (Mtp !=
"el0" && Mtp !=
"tpidr_el0")
274 D.
Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
278 if (Arg *A = Args.getLastArg(options::OPT_mharden_sls_EQ)) {
279 StringRef
Scope = A->getValue();
280 bool EnableRetBr =
false;
281 bool EnableBlr =
false;
282 bool DisableComdat =
false;
283 if (
Scope !=
"none") {
285 Scope.split(Opts,
",");
286 for (
auto Opt : Opts) {
293 if (Opt ==
"retbr") {
301 if (Opt ==
"comdat") {
302 DisableComdat =
false;
305 if (Opt ==
"nocomdat") {
306 DisableComdat =
true;
309 D.
Diag(diag::err_drv_unsupported_option_argument)
310 << A->getSpelling() <<
Scope;
316 Features.push_back(
"+harden-sls-retbr");
318 Features.push_back(
"+harden-sls-blr");
320 Features.push_back(
"+harden-sls-nocomdat");
324 if (Arg *A = Args.getLastArg(
325 options::OPT_mstrict_align, options::OPT_mno_strict_align,
326 options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
327 if (A->getOption().matches(options::OPT_mstrict_align) ||
328 A->getOption().matches(options::OPT_mno_unaligned_access))
329 Features.push_back(
"+strict-align");
330 }
else if (Triple.isOSOpenBSD())
331 Features.push_back(
"+strict-align");
333 if (Args.hasArg(options::OPT_ffixed_x1))
334 Features.push_back(
"+reserve-x1");
336 if (Args.hasArg(options::OPT_ffixed_x2))
337 Features.push_back(
"+reserve-x2");
339 if (Args.hasArg(options::OPT_ffixed_x3))
340 Features.push_back(
"+reserve-x3");
342 if (Args.hasArg(options::OPT_ffixed_x4))
343 Features.push_back(
"+reserve-x4");
345 if (Args.hasArg(options::OPT_ffixed_x5))
346 Features.push_back(
"+reserve-x5");
348 if (Args.hasArg(options::OPT_ffixed_x6))
349 Features.push_back(
"+reserve-x6");
351 if (Args.hasArg(options::OPT_ffixed_x7))
352 Features.push_back(
"+reserve-x7");
354 if (Args.hasArg(options::OPT_ffixed_x9))
355 Features.push_back(
"+reserve-x9");
357 if (Args.hasArg(options::OPT_ffixed_x10))
358 Features.push_back(
"+reserve-x10");
360 if (Args.hasArg(options::OPT_ffixed_x11))
361 Features.push_back(
"+reserve-x11");
363 if (Args.hasArg(options::OPT_ffixed_x12))
364 Features.push_back(
"+reserve-x12");
366 if (Args.hasArg(options::OPT_ffixed_x13))
367 Features.push_back(
"+reserve-x13");
369 if (Args.hasArg(options::OPT_ffixed_x14))
370 Features.push_back(
"+reserve-x14");
372 if (Args.hasArg(options::OPT_ffixed_x15))
373 Features.push_back(
"+reserve-x15");
375 if (Args.hasArg(options::OPT_ffixed_x18))
376 Features.push_back(
"+reserve-x18");
378 if (Args.hasArg(options::OPT_ffixed_x20))
379 Features.push_back(
"+reserve-x20");
381 if (Args.hasArg(options::OPT_ffixed_x21))
382 Features.push_back(
"+reserve-x21");
384 if (Args.hasArg(options::OPT_ffixed_x22))
385 Features.push_back(
"+reserve-x22");
387 if (Args.hasArg(options::OPT_ffixed_x23))
388 Features.push_back(
"+reserve-x23");
390 if (Args.hasArg(options::OPT_ffixed_x24))
391 Features.push_back(
"+reserve-x24");
393 if (Args.hasArg(options::OPT_ffixed_x25))
394 Features.push_back(
"+reserve-x25");
396 if (Args.hasArg(options::OPT_ffixed_x26))
397 Features.push_back(
"+reserve-x26");
399 if (Args.hasArg(options::OPT_ffixed_x27))
400 Features.push_back(
"+reserve-x27");
402 if (Args.hasArg(options::OPT_ffixed_x28))
403 Features.push_back(
"+reserve-x28");
405 if (Args.hasArg(options::OPT_fcall_saved_x8))
406 Features.push_back(
"+call-saved-x8");
408 if (Args.hasArg(options::OPT_fcall_saved_x9))
409 Features.push_back(
"+call-saved-x9");
411 if (Args.hasArg(options::OPT_fcall_saved_x10))
412 Features.push_back(
"+call-saved-x10");
414 if (Args.hasArg(options::OPT_fcall_saved_x11))
415 Features.push_back(
"+call-saved-x11");
417 if (Args.hasArg(options::OPT_fcall_saved_x12))
418 Features.push_back(
"+call-saved-x12");
420 if (Args.hasArg(options::OPT_fcall_saved_x13))
421 Features.push_back(
"+call-saved-x13");
423 if (Args.hasArg(options::OPT_fcall_saved_x14))
424 Features.push_back(
"+call-saved-x14");
426 if (Args.hasArg(options::OPT_fcall_saved_x15))
427 Features.push_back(
"+call-saved-x15");
429 if (Args.hasArg(options::OPT_fcall_saved_x18))
430 Features.push_back(
"+call-saved-x18");
432 if (Args.hasArg(options::OPT_mno_neg_immediates))
433 Features.push_back(
"+no-neg-immediates");
435 if (Arg *A = Args.getLastArg(options::OPT_mfix_cortex_a53_835769,
436 options::OPT_mno_fix_cortex_a53_835769)) {
437 if (A->getOption().matches(options::OPT_mfix_cortex_a53_835769))
438 Features.push_back(
"+fix-cortex-a53-835769");
440 Features.push_back(
"-fix-cortex-a53-835769");
441 }
else if (Triple.isAndroid() || Triple.isOHOSFamily()) {
443 Features.push_back(
"+fix-cortex-a53-835769");
444 }
else if (Triple.isOSFuchsia()) {
445 std::string CPU =
getCPUName(D, Args, Triple);
446 if (CPU.empty() || CPU ==
"generic" || CPU ==
"cortex-a53")
447 Features.push_back(
"+fix-cortex-a53-835769");
450 if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
451 Features.push_back(
"+no-bti-at-return-twice");
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.