13 #include "llvm/Option/ArgList.h" 14 #include "llvm/Support/TargetParser.h" 18 using namespace clang;
24 return Triple.isOSDarwin();
31 const llvm::Triple &Triple, Arg *&A) {
34 if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
35 StringRef Mcpu = A->getValue();
36 CPU = Mcpu.split(
"+").first.lower();
41 return llvm::sys::getHostCPUName();
47 if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
55 std::vector<StringRef> &Features) {
57 text.split(Split, StringRef(
"+"), -1,
false);
59 for (StringRef Feature : Split) {
60 StringRef FeatureName = llvm::AArch64::getArchExtFeature(Feature);
61 if (!FeatureName.empty())
62 Features.push_back(FeatureName);
63 else if (Feature ==
"neon" || Feature ==
"noneon")
64 D.
Diag(clang::diag::err_drv_no_neon_modifier);
74 std::vector<StringRef> &Features) {
75 std::pair<StringRef, StringRef>
Split = Mcpu.split(
"+");
79 CPU = llvm::sys::getHostCPUName();
81 if (CPU ==
"generic") {
82 Features.push_back(
"+neon");
84 llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseCPUArch(CPU);
85 if (!llvm::AArch64::getArchFeatures(ArchKind, Features))
88 unsigned Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind);
102 std::vector<StringRef> &Features) {
103 std::string MarchLowerCase = March.lower();
104 std::pair<StringRef, StringRef>
Split = StringRef(MarchLowerCase).split(
"+");
106 llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first);
107 if (ArchKind == llvm::AArch64::ArchKind::INVALID ||
108 !llvm::AArch64::getArchFeatures(ArchKind, Features) ||
118 std::vector<StringRef> &Features) {
120 std::string McpuLowerCase = Mcpu.lower();
130 std::vector<StringRef> &Features) {
131 std::string MtuneLowerCase = Mtune.lower();
133 std::vector<StringRef> MtuneFeatures;
139 if (MtuneLowerCase ==
"native")
140 MtuneLowerCase = llvm::sys::getHostCPUName();
141 if (MtuneLowerCase ==
"cyclone") {
142 Features.push_back(
"+zcm");
143 Features.push_back(
"+zcz");
151 std::vector<StringRef> &Features) {
153 std::vector<StringRef> DecodedFeature;
154 std::string McpuLowerCase = Mcpu.lower();
162 const llvm::Triple &Triple,
164 std::vector<StringRef> &Features) {
168 Features.push_back(
"+neon");
169 if ((A = Args.getLastArg(options::OPT_march_EQ)))
171 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
177 if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
180 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
189 D.
Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
191 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
192 Features.push_back(
"-fp-armv8");
193 Features.push_back(
"-crypto");
194 Features.push_back(
"-neon");
197 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
198 StringRef Mtp = A->getValue();
200 Features.push_back(
"+tpidr-el3");
201 else if (Mtp ==
"el2")
202 Features.push_back(
"+tpidr-el2");
203 else if (Mtp ==
"el1")
204 Features.push_back(
"+tpidr-el1");
205 else if (Mtp !=
"el0")
206 D.
Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
210 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
211 if (A->getOption().matches(options::OPT_mcrc))
212 Features.push_back(
"+crc");
214 Features.push_back(
"-crc");
220 const auto ItRNoFullFP16 = std::find(Features.rbegin(), Features.rend(),
"-fullfp16");
221 const auto ItRFP16FML = std::find(Features.rbegin(), Features.rend(),
"+fp16fml");
222 if (llvm::is_contained(Features,
"+v8.4a")) {
223 const auto ItRFullFP16 = std::find(Features.rbegin(), Features.rend(),
"+fullfp16");
224 if (ItRFullFP16 < ItRNoFullFP16 && ItRFullFP16 < ItRFP16FML) {
227 if (std::find(Features.rbegin(), ItRFullFP16,
"-fp16fml") == ItRFullFP16)
228 Features.push_back(
"+fp16fml");
231 goto fp16_fml_fallthrough;
233 fp16_fml_fallthrough:
236 if (ItRNoFullFP16 < ItRFP16FML)
237 Features.push_back(
"-fp16fml");
238 else if (ItRNoFullFP16 > ItRFP16FML)
239 Features.push_back(
"+fullfp16");
247 const auto ItBegin = Features.begin();
248 const auto ItEnd = Features.end();
249 const auto ItRBegin = Features.rbegin();
250 const auto ItREnd = Features.rend();
251 const auto ItRCrypto = std::find(ItRBegin, ItREnd,
"+crypto");
252 const auto ItRNoCrypto = std::find(ItRBegin, ItREnd,
"-crypto");
253 const auto HasCrypto = ItRCrypto != ItREnd;
254 const auto HasNoCrypto = ItRNoCrypto != ItREnd;
255 const ptrdiff_t PosCrypto = ItRCrypto - ItRBegin;
256 const ptrdiff_t PosNoCrypto = ItRNoCrypto - ItRBegin;
258 bool NoCrypto =
false;
259 if (HasCrypto && HasNoCrypto) {
260 if (PosNoCrypto < PosCrypto)
264 if (std::find(ItBegin, ItEnd,
"+v8.4a") != ItEnd) {
265 if (HasCrypto && !NoCrypto) {
269 const bool HasSM4 = (std::find(ItBegin, ItEnd,
"-sm4") == ItEnd);
270 const bool HasSHA3 = (std::find(ItBegin, ItEnd,
"-sha3") == ItEnd);
271 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"-sha2") == ItEnd);
272 const bool HasAES = (std::find(ItBegin, ItEnd,
"-aes") == ItEnd);
274 Features.push_back(
"+sm4");
276 Features.push_back(
"+sha3");
278 Features.push_back(
"+sha2");
280 Features.push_back(
"+aes");
281 }
else if (HasNoCrypto) {
285 const bool HasSM4 = (std::find(ItBegin, ItEnd,
"+sm4") != ItEnd);
286 const bool HasSHA3 = (std::find(ItBegin, ItEnd,
"+sha3") != ItEnd);
287 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"+sha2") != ItEnd);
288 const bool HasAES = (std::find(ItBegin, ItEnd,
"+aes") != ItEnd);
290 Features.push_back(
"-sm4");
292 Features.push_back(
"-sha3");
294 Features.push_back(
"-sha2");
296 Features.push_back(
"-aes");
299 if (HasCrypto && !NoCrypto) {
300 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"-sha2") == ItEnd);
301 const bool HasAES = (std::find(ItBegin, ItEnd,
"-aes") == ItEnd);
303 Features.push_back(
"+sha2");
305 Features.push_back(
"+aes");
306 }
else if (HasNoCrypto) {
307 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"+sha2") != ItEnd);
308 const bool HasAES = (std::find(ItBegin, ItEnd,
"+aes") != ItEnd);
309 const bool HasV82a = (std::find(ItBegin, ItEnd,
"+v8.2a") != ItEnd);
310 const bool HasV83a = (std::find(ItBegin, ItEnd,
"+v8.3a") != ItEnd);
311 const bool HasV84a = (std::find(ItBegin, ItEnd,
"+v8.4a") != ItEnd);
313 Features.push_back(
"-sha2");
315 Features.push_back(
"-aes");
316 if (HasV82a || HasV83a || HasV84a) {
317 Features.push_back(
"-sm4");
318 Features.push_back(
"-sha3");
323 if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
324 options::OPT_munaligned_access))
325 if (A->getOption().matches(options::OPT_mno_unaligned_access))
326 Features.push_back(
"+strict-align");
328 if (Args.hasArg(options::OPT_ffixed_x1))
329 Features.push_back(
"+reserve-x1");
331 if (Args.hasArg(options::OPT_ffixed_x2))
332 Features.push_back(
"+reserve-x2");
334 if (Args.hasArg(options::OPT_ffixed_x3))
335 Features.push_back(
"+reserve-x3");
337 if (Args.hasArg(options::OPT_ffixed_x4))
338 Features.push_back(
"+reserve-x4");
340 if (Args.hasArg(options::OPT_ffixed_x5))
341 Features.push_back(
"+reserve-x5");
343 if (Args.hasArg(options::OPT_ffixed_x6))
344 Features.push_back(
"+reserve-x6");
346 if (Args.hasArg(options::OPT_ffixed_x7))
347 Features.push_back(
"+reserve-x7");
349 if (Args.hasArg(options::OPT_ffixed_x9))
350 Features.push_back(
"+reserve-x9");
352 if (Args.hasArg(options::OPT_ffixed_x10))
353 Features.push_back(
"+reserve-x10");
355 if (Args.hasArg(options::OPT_ffixed_x11))
356 Features.push_back(
"+reserve-x11");
358 if (Args.hasArg(options::OPT_ffixed_x12))
359 Features.push_back(
"+reserve-x12");
361 if (Args.hasArg(options::OPT_ffixed_x13))
362 Features.push_back(
"+reserve-x13");
364 if (Args.hasArg(options::OPT_ffixed_x14))
365 Features.push_back(
"+reserve-x14");
367 if (Args.hasArg(options::OPT_ffixed_x15))
368 Features.push_back(
"+reserve-x15");
370 if (Args.hasArg(options::OPT_ffixed_x18))
371 Features.push_back(
"+reserve-x18");
373 if (Args.hasArg(options::OPT_ffixed_x20))
374 Features.push_back(
"+reserve-x20");
376 if (Args.hasArg(options::OPT_ffixed_x21))
377 Features.push_back(
"+reserve-x21");
379 if (Args.hasArg(options::OPT_ffixed_x22))
380 Features.push_back(
"+reserve-x22");
382 if (Args.hasArg(options::OPT_ffixed_x23))
383 Features.push_back(
"+reserve-x23");
385 if (Args.hasArg(options::OPT_ffixed_x24))
386 Features.push_back(
"+reserve-x24");
388 if (Args.hasArg(options::OPT_ffixed_x25))
389 Features.push_back(
"+reserve-x25");
391 if (Args.hasArg(options::OPT_ffixed_x26))
392 Features.push_back(
"+reserve-x26");
394 if (Args.hasArg(options::OPT_ffixed_x27))
395 Features.push_back(
"+reserve-x27");
397 if (Args.hasArg(options::OPT_ffixed_x28))
398 Features.push_back(
"+reserve-x28");
400 if (Args.hasArg(options::OPT_fcall_saved_x8))
401 Features.push_back(
"+call-saved-x8");
403 if (Args.hasArg(options::OPT_fcall_saved_x9))
404 Features.push_back(
"+call-saved-x9");
406 if (Args.hasArg(options::OPT_fcall_saved_x10))
407 Features.push_back(
"+call-saved-x10");
409 if (Args.hasArg(options::OPT_fcall_saved_x11))
410 Features.push_back(
"+call-saved-x11");
412 if (Args.hasArg(options::OPT_fcall_saved_x12))
413 Features.push_back(
"+call-saved-x12");
415 if (Args.hasArg(options::OPT_fcall_saved_x13))
416 Features.push_back(
"+call-saved-x13");
418 if (Args.hasArg(options::OPT_fcall_saved_x14))
419 Features.push_back(
"+call-saved-x14");
421 if (Args.hasArg(options::OPT_fcall_saved_x15))
422 Features.push_back(
"+call-saved-x15");
424 if (Args.hasArg(options::OPT_fcall_saved_x18))
425 Features.push_back(
"+call-saved-x18");
427 if (Args.hasArg(options::OPT_mno_neg_immediates))
428 Features.push_back(
"+no-neg-immediates");
DiagnosticBuilder Diag(unsigned DiagID) const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Dataflow Directional Tag Classes.
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.