45#include "llvm/ADT/StringExtras.h"
46#include "llvm/TargetParser/Triple.h"
61 assert(MacroName[0] !=
'_' &&
"Identifier should be in the user's namespace");
66 Builder.defineMacro(MacroName);
69 Builder.defineMacro(
"__" + MacroName);
72 Builder.defineMacro(
"__" + MacroName +
"__");
76 Builder.defineMacro(
"__" + CPUName);
77 Builder.defineMacro(
"__" + CPUName +
"__");
79 Builder.defineMacro(
"__tune_" + CPUName +
"__");
87 if (Opts.DeclSpecKeyword)
88 Builder.defineMacro(
"__declspec",
"__declspec");
90 Builder.defineMacro(
"__declspec(a)",
"__attribute__((a))");
92 if (!Opts.MicrosoftExt) {
96 const char *CCs[] = {
"cdecl",
"stdcall",
"fastcall",
"thiscall",
"pascal"};
97 for (
const char *CC : CCs) {
98 std::string GCCSpelling =
"__attribute__((__";
100 GCCSpelling +=
"__))";
101 Builder.defineMacro(Twine(
"_") + CC, GCCSpelling);
102 Builder.defineMacro(Twine(
"__") + CC, GCCSpelling);
113 llvm::Triple::OSType os = Triple.getOS();
115 switch (Triple.getArch()) {
119 case llvm::Triple::arc:
120 return std::make_unique<ARCTargetInfo>(Triple, Opts);
122 case llvm::Triple::xcore:
123 return std::make_unique<XCoreTargetInfo>(Triple, Opts);
125 case llvm::Triple::hexagon:
126 if (os == llvm::Triple::Linux &&
127 Triple.getEnvironment() == llvm::Triple::Musl)
128 return std::make_unique<LinuxTargetInfo<HexagonTargetInfo>>(Triple, Opts);
129 return std::make_unique<HexagonTargetInfo>(Triple, Opts);
131 case llvm::Triple::lanai:
132 return std::make_unique<LanaiTargetInfo>(Triple, Opts);
134 case llvm::Triple::aarch64_32:
135 if (Triple.isOSDarwin())
136 return std::make_unique<DarwinAArch64TargetInfo>(Triple, Opts);
139 case llvm::Triple::aarch64:
140 if (Triple.isOSDarwin())
141 return std::make_unique<DarwinAArch64TargetInfo>(Triple, Opts);
144 case llvm::Triple::FreeBSD:
145 return std::make_unique<FreeBSDTargetInfo<AArch64leTargetInfo>>(Triple,
147 case llvm::Triple::Fuchsia:
148 return std::make_unique<FuchsiaTargetInfo<AArch64leTargetInfo>>(Triple,
150 case llvm::Triple::Haiku:
151 return std::make_unique<HaikuTargetInfo<AArch64leTargetInfo>>(Triple,
153 case llvm::Triple::Linux:
154 switch (Triple.getEnvironment()) {
156 return std::make_unique<LinuxTargetInfo<AArch64leTargetInfo>>(Triple,
158 case llvm::Triple::OpenHOS:
159 return std::make_unique<OHOSTargetInfo<AArch64leTargetInfo>>(Triple,
162 case llvm::Triple::NetBSD:
163 return std::make_unique<NetBSDTargetInfo<AArch64leTargetInfo>>(Triple,
165 case llvm::Triple::OpenBSD:
166 return std::make_unique<OpenBSDTargetInfo<AArch64leTargetInfo>>(Triple,
168 case llvm::Triple::Win32:
169 switch (Triple.getEnvironment()) {
170 case llvm::Triple::GNU:
171 return std::make_unique<MinGWARM64TargetInfo>(Triple, Opts);
172 case llvm::Triple::MSVC:
174 return std::make_unique<MicrosoftARM64TargetInfo>(Triple, Opts);
177 return std::make_unique<AArch64leTargetInfo>(Triple, Opts);
180 case llvm::Triple::aarch64_be:
182 case llvm::Triple::FreeBSD:
183 return std::make_unique<FreeBSDTargetInfo<AArch64beTargetInfo>>(Triple,
185 case llvm::Triple::Fuchsia:
186 return std::make_unique<FuchsiaTargetInfo<AArch64beTargetInfo>>(Triple,
188 case llvm::Triple::Linux:
189 return std::make_unique<LinuxTargetInfo<AArch64beTargetInfo>>(Triple,
191 case llvm::Triple::NetBSD:
192 return std::make_unique<NetBSDTargetInfo<AArch64beTargetInfo>>(Triple,
195 return std::make_unique<AArch64beTargetInfo>(Triple, Opts);
198 case llvm::Triple::arm:
199 case llvm::Triple::thumb:
200 if (Triple.isOSBinFormatMachO())
201 return std::make_unique<DarwinARMTargetInfo>(Triple, Opts);
204 case llvm::Triple::Linux:
205 switch (Triple.getEnvironment()) {
207 return std::make_unique<LinuxTargetInfo<ARMleTargetInfo>>(Triple, Opts);
208 case llvm::Triple::OpenHOS:
209 return std::make_unique<OHOSTargetInfo<ARMleTargetInfo>>(Triple, Opts);
211 case llvm::Triple::LiteOS:
212 return std::make_unique<OHOSTargetInfo<ARMleTargetInfo>>(Triple, Opts);
213 case llvm::Triple::FreeBSD:
214 return std::make_unique<FreeBSDTargetInfo<ARMleTargetInfo>>(Triple, Opts);
215 case llvm::Triple::NetBSD:
216 return std::make_unique<NetBSDTargetInfo<ARMleTargetInfo>>(Triple, Opts);
217 case llvm::Triple::OpenBSD:
218 return std::make_unique<OpenBSDTargetInfo<ARMleTargetInfo>>(Triple, Opts);
219 case llvm::Triple::RTEMS:
220 return std::make_unique<RTEMSTargetInfo<ARMleTargetInfo>>(Triple, Opts);
221 case llvm::Triple::Haiku:
222 return std::make_unique<HaikuTargetInfo<ARMleTargetInfo>>(Triple, Opts);
223 case llvm::Triple::NaCl:
224 return std::make_unique<NaClTargetInfo<ARMleTargetInfo>>(Triple, Opts);
225 case llvm::Triple::Win32:
226 switch (Triple.getEnvironment()) {
227 case llvm::Triple::Cygnus:
228 return std::make_unique<CygwinARMTargetInfo>(Triple, Opts);
229 case llvm::Triple::GNU:
230 return std::make_unique<MinGWARMTargetInfo>(Triple, Opts);
231 case llvm::Triple::Itanium:
232 return std::make_unique<ItaniumWindowsARMleTargetInfo>(Triple, Opts);
233 case llvm::Triple::MSVC:
235 return std::make_unique<MicrosoftARMleTargetInfo>(Triple, Opts);
238 return std::make_unique<ARMleTargetInfo>(Triple, Opts);
241 case llvm::Triple::armeb:
242 case llvm::Triple::thumbeb:
243 if (Triple.isOSDarwin())
244 return std::make_unique<DarwinARMTargetInfo>(Triple, Opts);
247 case llvm::Triple::Linux:
248 return std::make_unique<LinuxTargetInfo<ARMbeTargetInfo>>(Triple, Opts);
249 case llvm::Triple::NetBSD:
250 return std::make_unique<NetBSDTargetInfo<ARMbeTargetInfo>>(Triple, Opts);
251 case llvm::Triple::RTEMS:
252 return std::make_unique<RTEMSTargetInfo<ARMbeTargetInfo>>(Triple, Opts);
253 case llvm::Triple::NaCl:
254 return std::make_unique<NaClTargetInfo<ARMbeTargetInfo>>(Triple, Opts);
256 return std::make_unique<ARMbeTargetInfo>(Triple, Opts);
259 case llvm::Triple::avr:
260 return std::make_unique<AVRTargetInfo>(Triple, Opts);
261 case llvm::Triple::bpfeb:
262 case llvm::Triple::bpfel:
263 return std::make_unique<BPFTargetInfo>(Triple, Opts);
265 case llvm::Triple::msp430:
266 return std::make_unique<MSP430TargetInfo>(Triple, Opts);
268 case llvm::Triple::mips:
270 case llvm::Triple::Linux:
271 return std::make_unique<LinuxTargetInfo<MipsTargetInfo>>(Triple, Opts);
272 case llvm::Triple::RTEMS:
273 return std::make_unique<RTEMSTargetInfo<MipsTargetInfo>>(Triple, Opts);
274 case llvm::Triple::FreeBSD:
275 return std::make_unique<FreeBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
276 case llvm::Triple::NetBSD:
277 return std::make_unique<NetBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
279 return std::make_unique<MipsTargetInfo>(Triple, Opts);
282 case llvm::Triple::mipsel:
284 case llvm::Triple::Linux:
285 switch (Triple.getEnvironment()) {
287 return std::make_unique<LinuxTargetInfo<MipsTargetInfo>>(Triple, Opts);
288 case llvm::Triple::OpenHOS:
289 return std::make_unique<OHOSTargetInfo<MipsTargetInfo>>(Triple, Opts);
291 case llvm::Triple::RTEMS:
292 return std::make_unique<RTEMSTargetInfo<MipsTargetInfo>>(Triple, Opts);
293 case llvm::Triple::FreeBSD:
294 return std::make_unique<FreeBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
295 case llvm::Triple::NetBSD:
296 return std::make_unique<NetBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
297 case llvm::Triple::NaCl:
298 return std::make_unique<NaClTargetInfo<NaClMips32TargetInfo>>(Triple,
301 return std::make_unique<MipsTargetInfo>(Triple, Opts);
304 case llvm::Triple::mips64:
306 case llvm::Triple::Linux:
307 return std::make_unique<LinuxTargetInfo<MipsTargetInfo>>(Triple, Opts);
308 case llvm::Triple::RTEMS:
309 return std::make_unique<RTEMSTargetInfo<MipsTargetInfo>>(Triple, Opts);
310 case llvm::Triple::FreeBSD:
311 return std::make_unique<FreeBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
312 case llvm::Triple::NetBSD:
313 return std::make_unique<NetBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
314 case llvm::Triple::OpenBSD:
315 return std::make_unique<OpenBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
317 return std::make_unique<MipsTargetInfo>(Triple, Opts);
320 case llvm::Triple::mips64el:
322 case llvm::Triple::Linux:
323 return std::make_unique<LinuxTargetInfo<MipsTargetInfo>>(Triple, Opts);
324 case llvm::Triple::RTEMS:
325 return std::make_unique<RTEMSTargetInfo<MipsTargetInfo>>(Triple, Opts);
326 case llvm::Triple::FreeBSD:
327 return std::make_unique<FreeBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
328 case llvm::Triple::NetBSD:
329 return std::make_unique<NetBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
330 case llvm::Triple::OpenBSD:
331 return std::make_unique<OpenBSDTargetInfo<MipsTargetInfo>>(Triple, Opts);
333 return std::make_unique<MipsTargetInfo>(Triple, Opts);
336 case llvm::Triple::m68k:
338 case llvm::Triple::Linux:
339 return std::make_unique<LinuxTargetInfo<M68kTargetInfo>>(Triple, Opts);
340 case llvm::Triple::NetBSD:
341 return std::make_unique<NetBSDTargetInfo<M68kTargetInfo>>(Triple, Opts);
343 return std::make_unique<M68kTargetInfo>(Triple, Opts);
346 case llvm::Triple::ppc:
348 case llvm::Triple::Linux:
349 return std::make_unique<LinuxTargetInfo<PPC32TargetInfo>>(Triple, Opts);
350 case llvm::Triple::FreeBSD:
351 return std::make_unique<FreeBSDTargetInfo<PPC32TargetInfo>>(Triple, Opts);
352 case llvm::Triple::NetBSD:
353 return std::make_unique<NetBSDTargetInfo<PPC32TargetInfo>>(Triple, Opts);
354 case llvm::Triple::OpenBSD:
355 return std::make_unique<OpenBSDTargetInfo<PPC32TargetInfo>>(Triple, Opts);
356 case llvm::Triple::RTEMS:
357 return std::make_unique<RTEMSTargetInfo<PPC32TargetInfo>>(Triple, Opts);
358 case llvm::Triple::AIX:
359 return std::make_unique<AIXPPC32TargetInfo>(Triple, Opts);
361 return std::make_unique<PPC32TargetInfo>(Triple, Opts);
364 case llvm::Triple::ppcle:
366 case llvm::Triple::Linux:
367 return std::make_unique<LinuxTargetInfo<PPC32TargetInfo>>(Triple, Opts);
368 case llvm::Triple::FreeBSD:
369 return std::make_unique<FreeBSDTargetInfo<PPC32TargetInfo>>(Triple, Opts);
371 return std::make_unique<PPC32TargetInfo>(Triple, Opts);
374 case llvm::Triple::ppc64:
376 case llvm::Triple::Linux:
377 return std::make_unique<LinuxTargetInfo<PPC64TargetInfo>>(Triple, Opts);
378 case llvm::Triple::Lv2:
379 return std::make_unique<PS3PPUTargetInfo<PPC64TargetInfo>>(Triple, Opts);
380 case llvm::Triple::FreeBSD:
381 return std::make_unique<FreeBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
382 case llvm::Triple::NetBSD:
383 return std::make_unique<NetBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
384 case llvm::Triple::OpenBSD:
385 return std::make_unique<OpenBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
386 case llvm::Triple::AIX:
387 return std::make_unique<AIXPPC64TargetInfo>(Triple, Opts);
389 return std::make_unique<PPC64TargetInfo>(Triple, Opts);
392 case llvm::Triple::ppc64le:
394 case llvm::Triple::Linux:
395 return std::make_unique<LinuxTargetInfo<PPC64TargetInfo>>(Triple, Opts);
396 case llvm::Triple::FreeBSD:
397 return std::make_unique<FreeBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
398 case llvm::Triple::NetBSD:
399 return std::make_unique<NetBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
400 case llvm::Triple::OpenBSD:
401 return std::make_unique<OpenBSDTargetInfo<PPC64TargetInfo>>(Triple, Opts);
403 return std::make_unique<PPC64TargetInfo>(Triple, Opts);
406 case llvm::Triple::nvptx:
407 return std::make_unique<NVPTXTargetInfo>(Triple, Opts,
409 case llvm::Triple::nvptx64:
410 return std::make_unique<NVPTXTargetInfo>(Triple, Opts,
413 case llvm::Triple::amdgcn:
414 case llvm::Triple::r600:
415 return std::make_unique<AMDGPUTargetInfo>(Triple, Opts);
417 case llvm::Triple::riscv32:
419 case llvm::Triple::NetBSD:
420 return std::make_unique<NetBSDTargetInfo<RISCV32TargetInfo>>(Triple,
422 case llvm::Triple::Linux:
423 return std::make_unique<LinuxTargetInfo<RISCV32TargetInfo>>(Triple, Opts);
425 return std::make_unique<RISCV32TargetInfo>(Triple, Opts);
428 case llvm::Triple::riscv64:
430 case llvm::Triple::FreeBSD:
431 return std::make_unique<FreeBSDTargetInfo<RISCV64TargetInfo>>(Triple,
433 case llvm::Triple::NetBSD:
434 return std::make_unique<NetBSDTargetInfo<RISCV64TargetInfo>>(Triple,
436 case llvm::Triple::OpenBSD:
437 return std::make_unique<OpenBSDTargetInfo<RISCV64TargetInfo>>(Triple,
439 case llvm::Triple::Fuchsia:
440 return std::make_unique<FuchsiaTargetInfo<RISCV64TargetInfo>>(Triple,
442 case llvm::Triple::Haiku:
443 return std::make_unique<HaikuTargetInfo<RISCV64TargetInfo>>(Triple,
445 case llvm::Triple::Linux:
446 switch (Triple.getEnvironment()) {
448 return std::make_unique<LinuxTargetInfo<RISCV64TargetInfo>>(Triple,
450 case llvm::Triple::OpenHOS:
451 return std::make_unique<OHOSTargetInfo<RISCV64TargetInfo>>(Triple,
455 return std::make_unique<RISCV64TargetInfo>(Triple, Opts);
458 case llvm::Triple::sparc:
460 case llvm::Triple::Linux:
461 return std::make_unique<LinuxTargetInfo<SparcV8TargetInfo>>(Triple, Opts);
462 case llvm::Triple::Solaris:
463 return std::make_unique<SolarisTargetInfo<SparcV8TargetInfo>>(Triple,
465 case llvm::Triple::NetBSD:
466 return std::make_unique<NetBSDTargetInfo<SparcV8TargetInfo>>(Triple,
468 case llvm::Triple::RTEMS:
469 return std::make_unique<RTEMSTargetInfo<SparcV8TargetInfo>>(Triple, Opts);
471 return std::make_unique<SparcV8TargetInfo>(Triple, Opts);
474 case llvm::Triple::sparcel:
476 case llvm::Triple::Linux:
477 return std::make_unique<LinuxTargetInfo<SparcV8elTargetInfo>>(Triple,
479 case llvm::Triple::RTEMS:
480 return std::make_unique<RTEMSTargetInfo<SparcV8elTargetInfo>>(Triple,
483 return std::make_unique<SparcV8elTargetInfo>(Triple, Opts);
486 case llvm::Triple::sparcv9:
488 case llvm::Triple::Linux:
489 return std::make_unique<LinuxTargetInfo<SparcV9TargetInfo>>(Triple, Opts);
490 case llvm::Triple::Solaris:
491 return std::make_unique<SolarisTargetInfo<SparcV9TargetInfo>>(Triple,
493 case llvm::Triple::NetBSD:
494 return std::make_unique<NetBSDTargetInfo<SparcV9TargetInfo>>(Triple,
496 case llvm::Triple::OpenBSD:
497 return std::make_unique<OpenBSDTargetInfo<SparcV9TargetInfo>>(Triple,
499 case llvm::Triple::FreeBSD:
500 return std::make_unique<FreeBSDTargetInfo<SparcV9TargetInfo>>(Triple,
503 return std::make_unique<SparcV9TargetInfo>(Triple, Opts);
506 case llvm::Triple::systemz:
508 case llvm::Triple::Linux:
509 return std::make_unique<LinuxTargetInfo<SystemZTargetInfo>>(Triple, Opts);
510 case llvm::Triple::ZOS:
511 return std::make_unique<ZOSTargetInfo<SystemZTargetInfo>>(Triple, Opts);
513 return std::make_unique<SystemZTargetInfo>(Triple, Opts);
516 case llvm::Triple::tce:
517 return std::make_unique<TCETargetInfo>(Triple, Opts);
519 case llvm::Triple::tcele:
520 return std::make_unique<TCELETargetInfo>(Triple, Opts);
522 case llvm::Triple::x86:
523 if (Triple.isOSDarwin())
524 return std::make_unique<DarwinI386TargetInfo>(Triple, Opts);
527 case llvm::Triple::Linux: {
528 switch (Triple.getEnvironment()) {
530 return std::make_unique<LinuxTargetInfo<X86_32TargetInfo>>(Triple,
532 case llvm::Triple::Android:
533 return std::make_unique<AndroidX86_32TargetInfo>(Triple, Opts);
536 case llvm::Triple::DragonFly:
537 return std::make_unique<DragonFlyBSDTargetInfo<X86_32TargetInfo>>(Triple,
539 case llvm::Triple::NetBSD:
540 return std::make_unique<NetBSDI386TargetInfo>(Triple, Opts);
541 case llvm::Triple::OpenBSD:
542 return std::make_unique<OpenBSDI386TargetInfo>(Triple, Opts);
543 case llvm::Triple::FreeBSD:
544 return std::make_unique<FreeBSDTargetInfo<X86_32TargetInfo>>(Triple,
546 case llvm::Triple::Fuchsia:
547 return std::make_unique<FuchsiaTargetInfo<X86_32TargetInfo>>(Triple,
549 case llvm::Triple::KFreeBSD:
550 return std::make_unique<KFreeBSDTargetInfo<X86_32TargetInfo>>(Triple,
552 case llvm::Triple::Solaris:
553 return std::make_unique<SolarisTargetInfo<X86_32TargetInfo>>(Triple,
555 case llvm::Triple::Win32: {
556 switch (Triple.getEnvironment()) {
557 case llvm::Triple::Cygnus:
558 return std::make_unique<CygwinX86_32TargetInfo>(Triple, Opts);
559 case llvm::Triple::GNU:
560 return std::make_unique<MinGWX86_32TargetInfo>(Triple, Opts);
561 case llvm::Triple::Itanium:
562 case llvm::Triple::MSVC:
564 return std::make_unique<MicrosoftX86_32TargetInfo>(Triple, Opts);
567 case llvm::Triple::Haiku:
568 return std::make_unique<HaikuX86_32TargetInfo>(Triple, Opts);
569 case llvm::Triple::RTEMS:
570 return std::make_unique<RTEMSX86_32TargetInfo>(Triple, Opts);
571 case llvm::Triple::NaCl:
572 return std::make_unique<NaClTargetInfo<X86_32TargetInfo>>(Triple, Opts);
573 case llvm::Triple::ELFIAMCU:
574 return std::make_unique<MCUX86_32TargetInfo>(Triple, Opts);
575 case llvm::Triple::Hurd:
576 return std::make_unique<HurdTargetInfo<X86_32TargetInfo>>(Triple, Opts);
578 return std::make_unique<X86_32TargetInfo>(Triple, Opts);
581 case llvm::Triple::x86_64:
582 if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
583 return std::make_unique<DarwinX86_64TargetInfo>(Triple, Opts);
586 case llvm::Triple::Linux: {
587 switch (Triple.getEnvironment()) {
589 return std::make_unique<LinuxTargetInfo<X86_64TargetInfo>>(Triple,
591 case llvm::Triple::Android:
592 return std::make_unique<AndroidX86_64TargetInfo>(Triple, Opts);
593 case llvm::Triple::OpenHOS:
594 return std::make_unique<OHOSX86_64TargetInfo>(Triple, Opts);
597 case llvm::Triple::DragonFly:
598 return std::make_unique<DragonFlyBSDTargetInfo<X86_64TargetInfo>>(Triple,
600 case llvm::Triple::NetBSD:
601 return std::make_unique<NetBSDTargetInfo<X86_64TargetInfo>>(Triple, Opts);
602 case llvm::Triple::OpenBSD:
603 return std::make_unique<OpenBSDX86_64TargetInfo>(Triple, Opts);
604 case llvm::Triple::FreeBSD:
605 return std::make_unique<FreeBSDTargetInfo<X86_64TargetInfo>>(Triple,
607 case llvm::Triple::Fuchsia:
608 return std::make_unique<FuchsiaTargetInfo<X86_64TargetInfo>>(Triple,
610 case llvm::Triple::KFreeBSD:
611 return std::make_unique<KFreeBSDTargetInfo<X86_64TargetInfo>>(Triple,
613 case llvm::Triple::Solaris:
614 return std::make_unique<SolarisTargetInfo<X86_64TargetInfo>>(Triple,
616 case llvm::Triple::Win32: {
617 switch (Triple.getEnvironment()) {
618 case llvm::Triple::Cygnus:
619 return std::make_unique<CygwinX86_64TargetInfo>(Triple, Opts);
620 case llvm::Triple::GNU:
621 return std::make_unique<MinGWX86_64TargetInfo>(Triple, Opts);
622 case llvm::Triple::MSVC:
624 return std::make_unique<MicrosoftX86_64TargetInfo>(Triple, Opts);
627 case llvm::Triple::Haiku:
628 return std::make_unique<HaikuTargetInfo<X86_64TargetInfo>>(Triple, Opts);
629 case llvm::Triple::NaCl:
630 return std::make_unique<NaClTargetInfo<X86_64TargetInfo>>(Triple, Opts);
631 case llvm::Triple::PS4:
632 return std::make_unique<PS4OSTargetInfo<X86_64TargetInfo>>(Triple, Opts);
633 case llvm::Triple::PS5:
634 return std::make_unique<PS5OSTargetInfo<X86_64TargetInfo>>(Triple, Opts);
635 case llvm::Triple::Hurd:
636 return std::make_unique<HurdTargetInfo<X86_64TargetInfo>>(Triple, Opts);
638 return std::make_unique<X86_64TargetInfo>(Triple, Opts);
641 case llvm::Triple::spir: {
642 if (os != llvm::Triple::UnknownOS ||
643 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
645 return std::make_unique<SPIR32TargetInfo>(Triple, Opts);
647 case llvm::Triple::spir64: {
648 if (os != llvm::Triple::UnknownOS ||
649 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
651 return std::make_unique<SPIR64TargetInfo>(Triple, Opts);
653 case llvm::Triple::spirv: {
654 return std::make_unique<SPIRVTargetInfo>(Triple, Opts);
656 case llvm::Triple::spirv32: {
657 if (os != llvm::Triple::UnknownOS ||
658 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
660 return std::make_unique<SPIRV32TargetInfo>(Triple, Opts);
662 case llvm::Triple::spirv64: {
663 if (os != llvm::Triple::UnknownOS ||
664 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
665 if (os == llvm::Triple::OSType::AMDHSA)
666 return std::make_unique<SPIRV64AMDGCNTargetInfo>(Triple, Opts);
669 return std::make_unique<SPIRV64TargetInfo>(Triple, Opts);
671 case llvm::Triple::wasm32:
672 if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
673 Triple.getVendor() != llvm::Triple::UnknownVendor ||
674 !Triple.isOSBinFormatWasm())
677 case llvm::Triple::WASI:
678 return std::make_unique<WASITargetInfo<WebAssembly32TargetInfo>>(Triple,
680 case llvm::Triple::Emscripten:
681 return std::make_unique<EmscriptenTargetInfo<WebAssembly32TargetInfo>>(
683 case llvm::Triple::UnknownOS:
684 return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>>(
689 case llvm::Triple::wasm64:
690 if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
691 Triple.getVendor() != llvm::Triple::UnknownVendor ||
692 !Triple.isOSBinFormatWasm())
695 case llvm::Triple::WASI:
696 return std::make_unique<WASITargetInfo<WebAssembly64TargetInfo>>(Triple,
698 case llvm::Triple::Emscripten:
699 return std::make_unique<EmscriptenTargetInfo<WebAssembly64TargetInfo>>(
701 case llvm::Triple::UnknownOS:
702 return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>>(
708 case llvm::Triple::dxil:
709 return std::make_unique<DirectXTargetInfo>(Triple, Opts);
710 case llvm::Triple::renderscript32:
711 return std::make_unique<LinuxTargetInfo<RenderScript32TargetInfo>>(Triple,
713 case llvm::Triple::renderscript64:
714 return std::make_unique<LinuxTargetInfo<RenderScript64TargetInfo>>(Triple,
717 case llvm::Triple::ve:
718 return std::make_unique<LinuxTargetInfo<VETargetInfo>>(Triple, Opts);
720 case llvm::Triple::csky:
722 case llvm::Triple::Linux:
723 return std::make_unique<LinuxTargetInfo<CSKYTargetInfo>>(Triple, Opts);
725 return std::make_unique<CSKYTargetInfo>(Triple, Opts);
727 case llvm::Triple::loongarch32:
729 case llvm::Triple::Linux:
730 return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
733 return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
735 case llvm::Triple::loongarch64:
737 case llvm::Triple::Linux:
738 return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
741 return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
753 const std::shared_ptr<TargetOptions> &Opts) {
754 llvm::Triple Triple(llvm::Triple::normalize(Opts->Triple));
759 Diags.
Report(diag::err_target_unknown_triple) << Triple.str();
762 Target->TargetOpts = Opts;
765 if (!Opts->CPU.empty() && !
Target->setCPU(Opts->CPU)) {
766 Diags.
Report(diag::err_target_unknown_cpu) << Opts->CPU;
768 Target->fillValidCPUList(ValidList);
769 if (!ValidList.empty())
770 Diags.
Report(diag::note_valid_options) << llvm::join(ValidList,
", ");
775 if (!Opts->TuneCPU.empty() &&
776 !
Target->isValidTuneCPUName(Opts->TuneCPU)) {
777 Diags.
Report(diag::err_target_unknown_cpu) << Opts->TuneCPU;
779 Target->fillValidTuneCPUList(ValidList);
780 if (!ValidList.empty())
781 Diags.
Report(diag::note_valid_options) << llvm::join(ValidList,
", ");
786 if (!Opts->ABI.empty() && !
Target->setABI(Opts->ABI)) {
787 Diags.
Report(diag::err_target_unknown_abi) << Opts->ABI;
792 if (!Opts->FPMath.empty() && !
Target->setFPMath(Opts->FPMath)) {
793 Diags.
Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
799 llvm::erase_if(Opts->FeaturesAsWritten, [&](StringRef Name) {
800 if (Target->isReadOnlyFeature(Name.substr(1))) {
801 Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
806 if (!
Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
807 Opts->FeaturesAsWritten))
811 Opts->Features.clear();
812 for (
const auto &F : Opts->FeatureMap)
813 Opts->Features.push_back((F.getValue() ?
"+" :
"-") + F.getKey().str());
816 llvm::sort(Opts->Features);
818 if (!
Target->handleTargetFeatures(Opts->Features, Diags))
821 Target->setSupportedOpenCLOpts();
822 Target->setCommandLineOpenCLOpts();
823 Target->setMaxAtomicWidth();
825 if (!Opts->DarwinTargetVariantTriple.empty())
826 Target->DarwinTargetVariantTriple =
827 llvm::Triple(Opts->DarwinTargetVariantTriple);
829 if (!
Target->validateTarget(Diags))
832 Target->CheckFixedPointBits();
842 auto diagnoseNotSupportedCore = [&](llvm::StringRef Name,
auto... OptArgs) {
845 Diags.
Report(diag::warn_opencl_unsupported_core_feature)
846 << Name << Opts.OpenCLCPlusPlus
849#define OPENCL_GENERIC_EXTENSION(Ext, ...) \
850 diagnoseNotSupportedCore(#Ext, __VA_ARGS__);
851#include "clang/Basic/OpenCLExtensions.def"
Defines the Diagnostic-related interfaces.
llvm::MachO::Target Target
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
static bool diagnoseUnsupportedFeatureDependencies(const TargetInfo &TI, DiagnosticsEngine &Diags)
static bool diagnoseFeatureExtensionDifferences(const TargetInfo &TI, DiagnosticsEngine &Diags)
static bool isOpenCLOptionCoreIn(const LangOptions &LO, Args &&... args)
Exposes information about the current target.
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
virtual bool validateOpenCLTarget(const LangOptions &Opts, DiagnosticsEngine &Diags) const
Check that OpenCL target has valid options setting based on OpenCL version.
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
Options for controlling the target.
void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, bool Tuning)
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
std::unique_ptr< TargetInfo > AllocateTarget(const llvm::Triple &Triple, const TargetOptions &Opts)
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
The JSON file list parser is used to communicate input to InstallAPI.