13 #include "llvm/Option/ArgList.h" 14 #include "llvm/Support/TargetParser.h" 15 #include "llvm/Support/Host.h" 19 using namespace clang;
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();
42 return llvm::sys::getHostCPUName();
48 if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
49 return Triple.getArch() == llvm::Triple::aarch64_32 ?
"apple-s4" 57 std::vector<StringRef> &Features) {
59 text.split(Split, StringRef(
"+"), -1,
false);
61 for (StringRef Feature : Split) {
62 StringRef FeatureName = llvm::AArch64::getArchExtFeature(Feature);
63 if (!FeatureName.empty())
64 Features.push_back(FeatureName);
65 else if (Feature ==
"neon" || Feature ==
"noneon")
66 D.
Diag(clang::diag::err_drv_no_neon_modifier);
76 std::vector<StringRef> &Features) {
77 std::pair<StringRef, StringRef>
Split = Mcpu.split(
"+");
81 CPU = llvm::sys::getHostCPUName();
83 if (CPU ==
"generic") {
84 Features.push_back(
"+neon");
86 llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseCPUArch(CPU);
90 unsigned Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind);
104 std::vector<StringRef> &Features) {
105 std::string MarchLowerCase = March.lower();
106 std::pair<StringRef, StringRef>
Split = StringRef(MarchLowerCase).split(
"+");
108 llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first);
109 if (ArchKind == llvm::AArch64::ArchKind::INVALID ||
120 std::vector<StringRef> &Features) {
122 std::string McpuLowerCase = Mcpu.lower();
132 std::vector<StringRef> &Features) {
133 std::string MtuneLowerCase = Mtune.lower();
135 std::vector<StringRef> MtuneFeatures;
141 if (MtuneLowerCase ==
"native")
142 MtuneLowerCase = llvm::sys::getHostCPUName();
143 if (MtuneLowerCase ==
"cyclone" || MtuneLowerCase.find(
"apple") == 0) {
144 Features.push_back(
"+zcm");
145 Features.push_back(
"+zcz");
153 std::vector<StringRef> &Features) {
155 std::vector<StringRef> DecodedFeature;
156 std::string McpuLowerCase = Mcpu.lower();
164 const llvm::Triple &Triple,
166 std::vector<StringRef> &Features) {
170 Features.push_back(
"+neon");
171 if ((A = Args.getLastArg(options::OPT_march_EQ)))
173 else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
179 if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
182 else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
191 D.
Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
193 if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
194 Features.push_back(
"-fp-armv8");
195 Features.push_back(
"-crypto");
196 Features.push_back(
"-neon");
199 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
200 StringRef Mtp = A->getValue();
202 Features.push_back(
"+tpidr-el3");
203 else if (Mtp ==
"el2")
204 Features.push_back(
"+tpidr-el2");
205 else if (Mtp ==
"el1")
206 Features.push_back(
"+tpidr-el1");
207 else if (Mtp !=
"el0")
208 D.
Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
212 if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) {
213 if (A->getOption().matches(options::OPT_mcrc))
214 Features.push_back(
"+crc");
216 Features.push_back(
"-crc");
222 const auto ItRNoFullFP16 = std::find(Features.rbegin(), Features.rend(),
"-fullfp16");
223 const auto ItRFP16FML = std::find(Features.rbegin(), Features.rend(),
"+fp16fml");
224 if (llvm::is_contained(Features,
"+v8.4a")) {
225 const auto ItRFullFP16 = std::find(Features.rbegin(), Features.rend(),
"+fullfp16");
226 if (ItRFullFP16 < ItRNoFullFP16 && ItRFullFP16 < ItRFP16FML) {
229 if (std::find(Features.rbegin(), ItRFullFP16,
"-fp16fml") == ItRFullFP16)
230 Features.push_back(
"+fp16fml");
233 goto fp16_fml_fallthrough;
235 fp16_fml_fallthrough:
238 if (ItRNoFullFP16 < ItRFP16FML)
239 Features.push_back(
"-fp16fml");
240 else if (ItRNoFullFP16 > ItRFP16FML)
241 Features.push_back(
"+fullfp16");
249 const auto ItBegin = Features.begin();
250 const auto ItEnd = Features.end();
251 const auto ItRBegin = Features.rbegin();
252 const auto ItREnd = Features.rend();
253 const auto ItRCrypto = std::find(ItRBegin, ItREnd,
"+crypto");
254 const auto ItRNoCrypto = std::find(ItRBegin, ItREnd,
"-crypto");
255 const auto HasCrypto = ItRCrypto != ItREnd;
256 const auto HasNoCrypto = ItRNoCrypto != ItREnd;
257 const ptrdiff_t PosCrypto = ItRCrypto - ItRBegin;
258 const ptrdiff_t PosNoCrypto = ItRNoCrypto - ItRBegin;
260 bool NoCrypto =
false;
261 if (HasCrypto && HasNoCrypto) {
262 if (PosNoCrypto < PosCrypto)
266 if (std::find(ItBegin, ItEnd,
"+v8.4a") != ItEnd) {
267 if (HasCrypto && !NoCrypto) {
271 const bool HasSM4 = (std::find(ItBegin, ItEnd,
"-sm4") == ItEnd);
272 const bool HasSHA3 = (std::find(ItBegin, ItEnd,
"-sha3") == ItEnd);
273 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"-sha2") == ItEnd);
274 const bool HasAES = (std::find(ItBegin, ItEnd,
"-aes") == ItEnd);
276 Features.push_back(
"+sm4");
278 Features.push_back(
"+sha3");
280 Features.push_back(
"+sha2");
282 Features.push_back(
"+aes");
283 }
else if (HasNoCrypto) {
287 const bool HasSM4 = (std::find(ItBegin, ItEnd,
"+sm4") != ItEnd);
288 const bool HasSHA3 = (std::find(ItBegin, ItEnd,
"+sha3") != ItEnd);
289 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"+sha2") != ItEnd);
290 const bool HasAES = (std::find(ItBegin, ItEnd,
"+aes") != ItEnd);
292 Features.push_back(
"-sm4");
294 Features.push_back(
"-sha3");
296 Features.push_back(
"-sha2");
298 Features.push_back(
"-aes");
301 if (HasCrypto && !NoCrypto) {
302 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"-sha2") == ItEnd);
303 const bool HasAES = (std::find(ItBegin, ItEnd,
"-aes") == ItEnd);
305 Features.push_back(
"+sha2");
307 Features.push_back(
"+aes");
308 }
else if (HasNoCrypto) {
309 const bool HasSHA2 = (std::find(ItBegin, ItEnd,
"+sha2") != ItEnd);
310 const bool HasAES = (std::find(ItBegin, ItEnd,
"+aes") != ItEnd);
311 const bool HasV82a = (std::find(ItBegin, ItEnd,
"+v8.2a") != ItEnd);
312 const bool HasV83a = (std::find(ItBegin, ItEnd,
"+v8.3a") != ItEnd);
313 const bool HasV84a = (std::find(ItBegin, ItEnd,
"+v8.4a") != ItEnd);
315 Features.push_back(
"-sha2");
317 Features.push_back(
"-aes");
318 if (HasV82a || HasV83a || HasV84a) {
319 Features.push_back(
"-sm4");
320 Features.push_back(
"-sha3");
325 if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
326 options::OPT_munaligned_access))
327 if (A->getOption().matches(options::OPT_mno_unaligned_access))
328 Features.push_back(
"+strict-align");
330 if (Args.hasArg(options::OPT_ffixed_x1))
331 Features.push_back(
"+reserve-x1");
333 if (Args.hasArg(options::OPT_ffixed_x2))
334 Features.push_back(
"+reserve-x2");
336 if (Args.hasArg(options::OPT_ffixed_x3))
337 Features.push_back(
"+reserve-x3");
339 if (Args.hasArg(options::OPT_ffixed_x4))
340 Features.push_back(
"+reserve-x4");
342 if (Args.hasArg(options::OPT_ffixed_x5))
343 Features.push_back(
"+reserve-x5");
345 if (Args.hasArg(options::OPT_ffixed_x6))
346 Features.push_back(
"+reserve-x6");
348 if (Args.hasArg(options::OPT_ffixed_x7))
349 Features.push_back(
"+reserve-x7");
351 if (Args.hasArg(options::OPT_ffixed_x9))
352 Features.push_back(
"+reserve-x9");
354 if (Args.hasArg(options::OPT_ffixed_x10))
355 Features.push_back(
"+reserve-x10");
357 if (Args.hasArg(options::OPT_ffixed_x11))
358 Features.push_back(
"+reserve-x11");
360 if (Args.hasArg(options::OPT_ffixed_x12))
361 Features.push_back(
"+reserve-x12");
363 if (Args.hasArg(options::OPT_ffixed_x13))
364 Features.push_back(
"+reserve-x13");
366 if (Args.hasArg(options::OPT_ffixed_x14))
367 Features.push_back(
"+reserve-x14");
369 if (Args.hasArg(options::OPT_ffixed_x15))
370 Features.push_back(
"+reserve-x15");
372 if (Args.hasArg(options::OPT_ffixed_x18))
373 Features.push_back(
"+reserve-x18");
375 if (Args.hasArg(options::OPT_ffixed_x20))
376 Features.push_back(
"+reserve-x20");
378 if (Args.hasArg(options::OPT_ffixed_x21))
379 Features.push_back(
"+reserve-x21");
381 if (Args.hasArg(options::OPT_ffixed_x22))
382 Features.push_back(
"+reserve-x22");
384 if (Args.hasArg(options::OPT_ffixed_x23))
385 Features.push_back(
"+reserve-x23");
387 if (Args.hasArg(options::OPT_ffixed_x24))
388 Features.push_back(
"+reserve-x24");
390 if (Args.hasArg(options::OPT_ffixed_x25))
391 Features.push_back(
"+reserve-x25");
393 if (Args.hasArg(options::OPT_ffixed_x26))
394 Features.push_back(
"+reserve-x26");
396 if (Args.hasArg(options::OPT_ffixed_x27))
397 Features.push_back(
"+reserve-x27");
399 if (Args.hasArg(options::OPT_ffixed_x28))
400 Features.push_back(
"+reserve-x28");
402 if (Args.hasArg(options::OPT_fcall_saved_x8))
403 Features.push_back(
"+call-saved-x8");
405 if (Args.hasArg(options::OPT_fcall_saved_x9))
406 Features.push_back(
"+call-saved-x9");
408 if (Args.hasArg(options::OPT_fcall_saved_x10))
409 Features.push_back(
"+call-saved-x10");
411 if (Args.hasArg(options::OPT_fcall_saved_x11))
412 Features.push_back(
"+call-saved-x11");
414 if (Args.hasArg(options::OPT_fcall_saved_x12))
415 Features.push_back(
"+call-saved-x12");
417 if (Args.hasArg(options::OPT_fcall_saved_x13))
418 Features.push_back(
"+call-saved-x13");
420 if (Args.hasArg(options::OPT_fcall_saved_x14))
421 Features.push_back(
"+call-saved-x14");
423 if (Args.hasArg(options::OPT_fcall_saved_x15))
424 Features.push_back(
"+call-saved-x15");
426 if (Args.hasArg(options::OPT_fcall_saved_x18))
427 Features.push_back(
"+call-saved-x18");
429 if (Args.hasArg(options::OPT_mno_neg_immediates))
430 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.