LLVM 20.0.0git
Triple.cpp
Go to the documentation of this file.
1//===--- Triple.cpp - Target triple helper class --------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/DenseMap.h"
20#include <cassert>
21#include <cstring>
22using namespace llvm;
23
25 switch (Kind) {
26 case UnknownArch: return "unknown";
27
28 case aarch64: return "aarch64";
29 case aarch64_32: return "aarch64_32";
30 case aarch64_be: return "aarch64_be";
31 case amdgcn: return "amdgcn";
32 case amdil64: return "amdil64";
33 case amdil: return "amdil";
34 case arc: return "arc";
35 case arm: return "arm";
36 case armeb: return "armeb";
37 case avr: return "avr";
38 case bpfeb: return "bpfeb";
39 case bpfel: return "bpfel";
40 case csky: return "csky";
41 case dxil: return "dxil";
42 case hexagon: return "hexagon";
43 case hsail64: return "hsail64";
44 case hsail: return "hsail";
45 case kalimba: return "kalimba";
46 case lanai: return "lanai";
47 case loongarch32: return "loongarch32";
48 case loongarch64: return "loongarch64";
49 case m68k: return "m68k";
50 case mips64: return "mips64";
51 case mips64el: return "mips64el";
52 case mips: return "mips";
53 case mipsel: return "mipsel";
54 case msp430: return "msp430";
55 case nvptx64: return "nvptx64";
56 case nvptx: return "nvptx";
57 case ppc64: return "powerpc64";
58 case ppc64le: return "powerpc64le";
59 case ppc: return "powerpc";
60 case ppcle: return "powerpcle";
61 case r600: return "r600";
62 case renderscript32: return "renderscript32";
63 case renderscript64: return "renderscript64";
64 case riscv32: return "riscv32";
65 case riscv64: return "riscv64";
66 case shave: return "shave";
67 case sparc: return "sparc";
68 case sparcel: return "sparcel";
69 case sparcv9: return "sparcv9";
70 case spir64: return "spir64";
71 case spir: return "spir";
72 case spirv: return "spirv";
73 case spirv32: return "spirv32";
74 case spirv64: return "spirv64";
75 case systemz: return "s390x";
76 case tce: return "tce";
77 case tcele: return "tcele";
78 case thumb: return "thumb";
79 case thumbeb: return "thumbeb";
80 case ve: return "ve";
81 case wasm32: return "wasm32";
82 case wasm64: return "wasm64";
83 case x86: return "i386";
84 case x86_64: return "x86_64";
85 case xcore: return "xcore";
86 case xtensa: return "xtensa";
87 }
88
89 llvm_unreachable("Invalid ArchType!");
90}
91
93 switch (Kind) {
94 case Triple::mips:
95 if (SubArch == MipsSubArch_r6)
96 return "mipsisa32r6";
97 break;
98 case Triple::mipsel:
99 if (SubArch == MipsSubArch_r6)
100 return "mipsisa32r6el";
101 break;
102 case Triple::mips64:
103 if (SubArch == MipsSubArch_r6)
104 return "mipsisa64r6";
105 break;
106 case Triple::mips64el:
107 if (SubArch == MipsSubArch_r6)
108 return "mipsisa64r6el";
109 break;
110 case Triple::aarch64:
111 if (SubArch == AArch64SubArch_arm64ec)
112 return "arm64ec";
113 if (SubArch == AArch64SubArch_arm64e)
114 return "arm64e";
115 break;
116 case Triple::spirv:
117 switch (SubArch) {
119 return "spirv1.0";
121 return "spirv1.1";
123 return "spirv1.2";
125 return "spirv1.3";
127 return "spirv1.4";
129 return "spirv1.5";
131 return "spirv1.6";
132 default:
133 break;
134 }
135 break;
136 case Triple::dxil:
137 switch (SubArch) {
140 return "dxilv1.0";
142 return "dxilv1.1";
144 return "dxilv1.2";
146 return "dxilv1.3";
148 return "dxilv1.4";
150 return "dxilv1.5";
152 return "dxilv1.6";
154 return "dxilv1.7";
156 return "dxilv1.8";
157 default:
158 break;
159 }
160 break;
161 default:
162 break;
163 }
164 return getArchTypeName(Kind);
165}
166
168 switch (Kind) {
169 default:
170 return StringRef();
171
172 case aarch64:
173 case aarch64_be:
174 case aarch64_32: return "aarch64";
175
176 case arc: return "arc";
177
178 case arm:
179 case armeb:
180 case thumb:
181 case thumbeb: return "arm";
182
183 case avr: return "avr";
184
185 case ppc64:
186 case ppc64le:
187 case ppc:
188 case ppcle: return "ppc";
189
190 case m68k: return "m68k";
191
192 case mips:
193 case mipsel:
194 case mips64:
195 case mips64el: return "mips";
196
197 case hexagon: return "hexagon";
198
199 case amdgcn: return "amdgcn";
200 case r600: return "r600";
201
202 case bpfel:
203 case bpfeb: return "bpf";
204
205 case sparcv9:
206 case sparcel:
207 case sparc: return "sparc";
208
209 case systemz: return "s390";
210
211 case x86:
212 case x86_64: return "x86";
213
214 case xcore: return "xcore";
215
216 // NVPTX intrinsics are namespaced under nvvm.
217 case nvptx: return "nvvm";
218 case nvptx64: return "nvvm";
219
220 case amdil:
221 case amdil64: return "amdil";
222
223 case hsail:
224 case hsail64: return "hsail";
225
226 case spir:
227 case spir64: return "spir";
228
229 case spirv:
230 case spirv32:
231 case spirv64: return "spv";
232
233 case kalimba: return "kalimba";
234 case lanai: return "lanai";
235 case shave: return "shave";
236 case wasm32:
237 case wasm64: return "wasm";
238
239 case riscv32:
240 case riscv64: return "riscv";
241
242 case ve: return "ve";
243 case csky: return "csky";
244
245 case loongarch32:
246 case loongarch64: return "loongarch";
247
248 case dxil: return "dx";
249
250 case xtensa: return "xtensa";
251 }
252}
253
255 switch (Kind) {
256 case UnknownVendor: return "unknown";
257
258 case AMD: return "amd";
259 case Apple: return "apple";
260 case CSR: return "csr";
261 case Freescale: return "fsl";
262 case IBM: return "ibm";
263 case ImaginationTechnologies: return "img";
264 case Intel:
265 return "intel";
266 case Mesa: return "mesa";
267 case MipsTechnologies: return "mti";
268 case NVIDIA: return "nvidia";
269 case OpenEmbedded: return "oe";
270 case PC: return "pc";
271 case SCEI: return "scei";
272 case SUSE: return "suse";
273 }
274
275 llvm_unreachable("Invalid VendorType!");
276}
277
279 switch (Kind) {
280 case UnknownOS: return "unknown";
281
282 case AIX: return "aix";
283 case AMDHSA: return "amdhsa";
284 case AMDPAL: return "amdpal";
285 case BridgeOS: return "bridgeos";
286 case CUDA: return "cuda";
287 case Darwin: return "darwin";
288 case DragonFly: return "dragonfly";
289 case DriverKit: return "driverkit";
290 case ELFIAMCU: return "elfiamcu";
291 case Emscripten: return "emscripten";
292 case FreeBSD: return "freebsd";
293 case Fuchsia: return "fuchsia";
294 case Haiku: return "haiku";
295 case HermitCore: return "hermit";
296 case Hurd: return "hurd";
297 case IOS: return "ios";
298 case KFreeBSD: return "kfreebsd";
299 case Linux: return "linux";
300 case Lv2: return "lv2";
301 case MacOSX: return "macosx";
302 case Mesa3D: return "mesa3d";
303 case NVCL: return "nvcl";
304 case NaCl: return "nacl";
305 case NetBSD: return "netbsd";
306 case OpenBSD: return "openbsd";
307 case PS4: return "ps4";
308 case PS5: return "ps5";
309 case RTEMS: return "rtems";
310 case Solaris: return "solaris";
311 case Serenity: return "serenity";
312 case TvOS: return "tvos";
313 case UEFI: return "uefi";
314 case WASI: return "wasi";
315 case WatchOS: return "watchos";
316 case Win32: return "windows";
317 case ZOS: return "zos";
318 case ShaderModel: return "shadermodel";
319 case LiteOS: return "liteos";
320 case XROS: return "xros";
321 case Vulkan: return "vulkan";
322 }
323
324 llvm_unreachable("Invalid OSType");
325}
326
328 switch (Kind) {
329 case UnknownEnvironment: return "unknown";
330 case Android: return "android";
331 case CODE16: return "code16";
332 case CoreCLR: return "coreclr";
333 case Cygnus: return "cygnus";
334 case EABI: return "eabi";
335 case EABIHF: return "eabihf";
336 case GNU: return "gnu";
337 case GNUT64: return "gnut64";
338 case GNUABI64: return "gnuabi64";
339 case GNUABIN32: return "gnuabin32";
340 case GNUEABI: return "gnueabi";
341 case GNUEABIT64: return "gnueabit64";
342 case GNUEABIHF: return "gnueabihf";
343 case GNUEABIHFT64: return "gnueabihft64";
344 case GNUF32: return "gnuf32";
345 case GNUF64: return "gnuf64";
346 case GNUSF: return "gnusf";
347 case GNUX32: return "gnux32";
348 case GNUILP32: return "gnu_ilp32";
349 case Itanium: return "itanium";
350 case MSVC: return "msvc";
351 case MacABI: return "macabi";
352 case Musl: return "musl";
353 case MuslABIN32:
354 return "muslabin32";
355 case MuslABI64:
356 return "muslabi64";
357 case MuslEABI: return "musleabi";
358 case MuslEABIHF: return "musleabihf";
359 case MuslF32:
360 return "muslf32";
361 case MuslSF:
362 return "muslsf";
363 case MuslX32: return "muslx32";
364 case Simulator: return "simulator";
365 case Pixel: return "pixel";
366 case Vertex: return "vertex";
367 case Geometry: return "geometry";
368 case Hull: return "hull";
369 case Domain: return "domain";
370 case Compute: return "compute";
371 case Library: return "library";
372 case RayGeneration: return "raygeneration";
373 case Intersection: return "intersection";
374 case AnyHit: return "anyhit";
375 case ClosestHit: return "closesthit";
376 case Miss: return "miss";
377 case Callable: return "callable";
378 case Mesh: return "mesh";
379 case Amplification: return "amplification";
380 case OpenCL:
381 return "opencl";
382 case OpenHOS: return "ohos";
383 case PAuthTest:
384 return "pauthtest";
385 case LLVM:
386 return "llvm";
387 }
388
389 llvm_unreachable("Invalid EnvironmentType!");
390}
391
393 switch (Kind) {
394 case UnknownObjectFormat: return "";
395 case COFF: return "coff";
396 case ELF: return "elf";
397 case GOFF: return "goff";
398 case MachO: return "macho";
399 case Wasm: return "wasm";
400 case XCOFF: return "xcoff";
401 case DXContainer: return "dxcontainer";
402 case SPIRV: return "spirv";
403 }
404 llvm_unreachable("unknown object format type");
405}
406
408 if (ArchName == "bpf") {
410 return Triple::bpfel;
411 else
412 return Triple::bpfeb;
413 } else if (ArchName == "bpf_be" || ArchName == "bpfeb") {
414 return Triple::bpfeb;
415 } else if (ArchName == "bpf_le" || ArchName == "bpfel") {
416 return Triple::bpfel;
417 } else {
418 return Triple::UnknownArch;
419 }
420}
421
425 .Case("aarch64", aarch64)
426 .Case("aarch64_be", aarch64_be)
427 .Case("aarch64_32", aarch64_32)
428 .Case("arc", arc)
429 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
430 .Case("arm64_32", aarch64_32)
431 .Case("arm", arm)
432 .Case("armeb", armeb)
433 .Case("avr", avr)
434 .StartsWith("bpf", BPFArch)
435 .Case("m68k", m68k)
436 .Case("mips", mips)
437 .Case("mipsel", mipsel)
438 .Case("mips64", mips64)
439 .Case("mips64el", mips64el)
440 .Case("msp430", msp430)
441 .Case("ppc64", ppc64)
442 .Case("ppc32", ppc)
443 .Case("ppc", ppc)
444 .Case("ppc32le", ppcle)
445 .Case("ppcle", ppcle)
446 .Case("ppc64le", ppc64le)
447 .Case("r600", r600)
448 .Case("amdgcn", amdgcn)
449 .Case("riscv32", riscv32)
450 .Case("riscv64", riscv64)
451 .Case("hexagon", hexagon)
452 .Case("sparc", sparc)
453 .Case("sparcel", sparcel)
454 .Case("sparcv9", sparcv9)
455 .Case("s390x", systemz)
456 .Case("systemz", systemz)
457 .Case("tce", tce)
458 .Case("tcele", tcele)
459 .Case("thumb", thumb)
460 .Case("thumbeb", thumbeb)
461 .Case("x86", x86)
462 .Case("i386", x86)
463 .Case("x86-64", x86_64)
464 .Case("xcore", xcore)
465 .Case("nvptx", nvptx)
466 .Case("nvptx64", nvptx64)
467 .Case("amdil", amdil)
468 .Case("amdil64", amdil64)
469 .Case("hsail", hsail)
470 .Case("hsail64", hsail64)
471 .Case("spir", spir)
472 .Case("spir64", spir64)
473 .Case("spirv", spirv)
474 .Case("spirv32", spirv32)
475 .Case("spirv64", spirv64)
476 .Case("kalimba", kalimba)
477 .Case("lanai", lanai)
478 .Case("shave", shave)
479 .Case("wasm32", wasm32)
480 .Case("wasm64", wasm64)
481 .Case("renderscript32", renderscript32)
482 .Case("renderscript64", renderscript64)
483 .Case("ve", ve)
484 .Case("csky", csky)
485 .Case("loongarch32", loongarch32)
486 .Case("loongarch64", loongarch64)
487 .Case("dxil", dxil)
488 .Case("xtensa", xtensa)
490}
491
493 ARM::ISAKind ISA = ARM::parseArchISA(ArchName);
494 ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName);
495
497 switch (ENDIAN) {
499 switch (ISA) {
501 arch = Triple::arm;
502 break;
504 arch = Triple::thumb;
505 break;
507 arch = Triple::aarch64;
508 break;
510 break;
511 }
512 break;
513 }
515 switch (ISA) {
517 arch = Triple::armeb;
518 break;
520 arch = Triple::thumbeb;
521 break;
523 arch = Triple::aarch64_be;
524 break;
526 break;
527 }
528 break;
529 }
531 break;
532 }
533 }
534
535 ArchName = ARM::getCanonicalArchName(ArchName);
536 if (ArchName.empty())
537 return Triple::UnknownArch;
538
539 // Thumb only exists in v4+
540 if (ISA == ARM::ISAKind::THUMB &&
541 (ArchName.starts_with("v2") || ArchName.starts_with("v3")))
542 return Triple::UnknownArch;
543
544 // Thumb only for v6m
546 unsigned Version = ARM::parseArchVersion(ArchName);
547 if (Profile == ARM::ProfileKind::M && Version == 6) {
548 if (ENDIAN == ARM::EndianKind::BIG)
549 return Triple::thumbeb;
550 else
551 return Triple::thumb;
552 }
553
554 return arch;
555}
556
558 auto AT =
560 .Cases("i386", "i486", "i586", "i686", Triple::x86)
561 // FIXME: Do we need to support these?
562 .Cases("i786", "i886", "i986", Triple::x86)
563 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
564 .Cases("powerpc", "powerpcspe", "ppc", "ppc32", Triple::ppc)
565 .Cases("powerpcle", "ppcle", "ppc32le", Triple::ppcle)
566 .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64)
567 .Cases("powerpc64le", "ppc64le", Triple::ppc64le)
568 .Case("xscale", Triple::arm)
569 .Case("xscaleeb", Triple::armeb)
570 .Case("aarch64", Triple::aarch64)
571 .Case("aarch64_be", Triple::aarch64_be)
572 .Case("aarch64_32", Triple::aarch64_32)
573 .Case("arc", Triple::arc)
574 .Case("arm64", Triple::aarch64)
575 .Case("arm64_32", Triple::aarch64_32)
576 .Case("arm64e", Triple::aarch64)
577 .Case("arm64ec", Triple::aarch64)
578 .Case("arm", Triple::arm)
579 .Case("armeb", Triple::armeb)
580 .Case("thumb", Triple::thumb)
581 .Case("thumbeb", Triple::thumbeb)
582 .Case("avr", Triple::avr)
583 .Case("m68k", Triple::m68k)
584 .Case("msp430", Triple::msp430)
585 .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6", "mipsr6",
587 .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el",
589 .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6", "mips64r6",
590 "mipsn32r6", Triple::mips64)
591 .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el",
592 "mipsn32r6el", Triple::mips64el)
593 .Case("r600", Triple::r600)
594 .Case("amdgcn", Triple::amdgcn)
595 .Case("riscv32", Triple::riscv32)
596 .Case("riscv64", Triple::riscv64)
597 .Case("hexagon", Triple::hexagon)
598 .Cases("s390x", "systemz", Triple::systemz)
599 .Case("sparc", Triple::sparc)
600 .Case("sparcel", Triple::sparcel)
601 .Cases("sparcv9", "sparc64", Triple::sparcv9)
602 .Case("tce", Triple::tce)
603 .Case("tcele", Triple::tcele)
604 .Case("xcore", Triple::xcore)
605 .Case("nvptx", Triple::nvptx)
606 .Case("nvptx64", Triple::nvptx64)
607 .Case("amdil", Triple::amdil)
608 .Case("amdil64", Triple::amdil64)
609 .Case("hsail", Triple::hsail)
610 .Case("hsail64", Triple::hsail64)
611 .Case("spir", Triple::spir)
612 .Case("spir64", Triple::spir64)
613 .Cases("spirv", "spirv1.5", "spirv1.6", Triple::spirv)
614 .Cases("spirv32", "spirv32v1.0", "spirv32v1.1", "spirv32v1.2",
615 "spirv32v1.3", "spirv32v1.4", "spirv32v1.5",
616 "spirv32v1.6", Triple::spirv32)
617 .Cases("spirv64", "spirv64v1.0", "spirv64v1.1", "spirv64v1.2",
618 "spirv64v1.3", "spirv64v1.4", "spirv64v1.5",
619 "spirv64v1.6", Triple::spirv64)
620 .StartsWith("kalimba", Triple::kalimba)
621 .Case("lanai", Triple::lanai)
622 .Case("renderscript32", Triple::renderscript32)
623 .Case("renderscript64", Triple::renderscript64)
624 .Case("shave", Triple::shave)
625 .Case("ve", Triple::ve)
626 .Case("wasm32", Triple::wasm32)
627 .Case("wasm64", Triple::wasm64)
628 .Case("csky", Triple::csky)
629 .Case("loongarch32", Triple::loongarch32)
630 .Case("loongarch64", Triple::loongarch64)
631 .Cases("dxil", "dxilv1.0", "dxilv1.1", "dxilv1.2", "dxilv1.3",
632 "dxilv1.4", "dxilv1.5", "dxilv1.6", "dxilv1.7", "dxilv1.8",
634 .Case("xtensa", Triple::xtensa)
636
637 // Some architectures require special parsing logic just to compute the
638 // ArchType result.
639 if (AT == Triple::UnknownArch) {
640 if (ArchName.starts_with("arm") || ArchName.starts_with("thumb") ||
641 ArchName.starts_with("aarch64"))
642 return parseARMArch(ArchName);
643 if (ArchName.starts_with("bpf"))
644 return parseBPFArch(ArchName);
645 }
646
647 return AT;
648}
649
651 return StringSwitch<Triple::VendorType>(VendorName)
652 .Case("apple", Triple::Apple)
653 .Case("pc", Triple::PC)
654 .Case("scei", Triple::SCEI)
655 .Case("sie", Triple::SCEI)
656 .Case("fsl", Triple::Freescale)
657 .Case("ibm", Triple::IBM)
660 .Case("nvidia", Triple::NVIDIA)
661 .Case("csr", Triple::CSR)
662 .Case("amd", Triple::AMD)
663 .Case("mesa", Triple::Mesa)
664 .Case("suse", Triple::SUSE)
666 .Case("intel", Triple::Intel)
668}
669
671 return StringSwitch<Triple::OSType>(OSName)
672 .StartsWith("darwin", Triple::Darwin)
673 .StartsWith("dragonfly", Triple::DragonFly)
674 .StartsWith("freebsd", Triple::FreeBSD)
675 .StartsWith("fuchsia", Triple::Fuchsia)
676 .StartsWith("ios", Triple::IOS)
677 .StartsWith("kfreebsd", Triple::KFreeBSD)
678 .StartsWith("linux", Triple::Linux)
679 .StartsWith("lv2", Triple::Lv2)
680 .StartsWith("macos", Triple::MacOSX)
681 .StartsWith("netbsd", Triple::NetBSD)
682 .StartsWith("openbsd", Triple::OpenBSD)
683 .StartsWith("solaris", Triple::Solaris)
684 .StartsWith("uefi", Triple::UEFI)
685 .StartsWith("win32", Triple::Win32)
686 .StartsWith("windows", Triple::Win32)
687 .StartsWith("zos", Triple::ZOS)
688 .StartsWith("haiku", Triple::Haiku)
689 .StartsWith("rtems", Triple::RTEMS)
690 .StartsWith("nacl", Triple::NaCl)
691 .StartsWith("aix", Triple::AIX)
692 .StartsWith("cuda", Triple::CUDA)
693 .StartsWith("nvcl", Triple::NVCL)
694 .StartsWith("amdhsa", Triple::AMDHSA)
695 .StartsWith("ps4", Triple::PS4)
696 .StartsWith("ps5", Triple::PS5)
697 .StartsWith("elfiamcu", Triple::ELFIAMCU)
698 .StartsWith("tvos", Triple::TvOS)
699 .StartsWith("watchos", Triple::WatchOS)
700 .StartsWith("bridgeos", Triple::BridgeOS)
701 .StartsWith("driverkit", Triple::DriverKit)
702 .StartsWith("xros", Triple::XROS)
703 .StartsWith("visionos", Triple::XROS)
704 .StartsWith("mesa3d", Triple::Mesa3D)
705 .StartsWith("amdpal", Triple::AMDPAL)
707 .StartsWith("hurd", Triple::Hurd)
708 .StartsWith("wasi", Triple::WASI)
709 .StartsWith("emscripten", Triple::Emscripten)
710 .StartsWith("shadermodel", Triple::ShaderModel)
711 .StartsWith("liteos", Triple::LiteOS)
712 .StartsWith("serenity", Triple::Serenity)
713 .StartsWith("vulkan", Triple::Vulkan)
715}
716
718 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
719 .StartsWith("eabihf", Triple::EABIHF)
720 .StartsWith("eabi", Triple::EABI)
721 .StartsWith("gnuabin32", Triple::GNUABIN32)
722 .StartsWith("gnuabi64", Triple::GNUABI64)
723 .StartsWith("gnueabihft64", Triple::GNUEABIHFT64)
724 .StartsWith("gnueabihf", Triple::GNUEABIHF)
725 .StartsWith("gnueabit64", Triple::GNUEABIT64)
726 .StartsWith("gnueabi", Triple::GNUEABI)
727 .StartsWith("gnuf32", Triple::GNUF32)
728 .StartsWith("gnuf64", Triple::GNUF64)
729 .StartsWith("gnusf", Triple::GNUSF)
730 .StartsWith("gnux32", Triple::GNUX32)
731 .StartsWith("gnu_ilp32", Triple::GNUILP32)
732 .StartsWith("code16", Triple::CODE16)
733 .StartsWith("gnut64", Triple::GNUT64)
734 .StartsWith("gnu", Triple::GNU)
735 .StartsWith("android", Triple::Android)
736 .StartsWith("muslabin32", Triple::MuslABIN32)
737 .StartsWith("muslabi64", Triple::MuslABI64)
738 .StartsWith("musleabihf", Triple::MuslEABIHF)
739 .StartsWith("musleabi", Triple::MuslEABI)
740 .StartsWith("muslf32", Triple::MuslF32)
741 .StartsWith("muslsf", Triple::MuslSF)
742 .StartsWith("muslx32", Triple::MuslX32)
743 .StartsWith("musl", Triple::Musl)
744 .StartsWith("msvc", Triple::MSVC)
745 .StartsWith("itanium", Triple::Itanium)
746 .StartsWith("cygnus", Triple::Cygnus)
747 .StartsWith("coreclr", Triple::CoreCLR)
748 .StartsWith("simulator", Triple::Simulator)
749 .StartsWith("macabi", Triple::MacABI)
750 .StartsWith("pixel", Triple::Pixel)
751 .StartsWith("vertex", Triple::Vertex)
752 .StartsWith("geometry", Triple::Geometry)
753 .StartsWith("hull", Triple::Hull)
754 .StartsWith("domain", Triple::Domain)
755 .StartsWith("compute", Triple::Compute)
756 .StartsWith("library", Triple::Library)
757 .StartsWith("raygeneration", Triple::RayGeneration)
758 .StartsWith("intersection", Triple::Intersection)
759 .StartsWith("anyhit", Triple::AnyHit)
760 .StartsWith("closesthit", Triple::ClosestHit)
761 .StartsWith("miss", Triple::Miss)
762 .StartsWith("callable", Triple::Callable)
763 .StartsWith("mesh", Triple::Mesh)
764 .StartsWith("amplification", Triple::Amplification)
765 .StartsWith("opencl", Triple::OpenCL)
767 .StartsWith("pauthtest", Triple::PAuthTest)
768 .StartsWith("llvm", Triple::LLVM)
770}
771
773 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
774 // "xcoff" must come before "coff" because of the order-dependendent
775 // pattern matching.
776 .EndsWith("xcoff", Triple::XCOFF)
777 .EndsWith("coff", Triple::COFF)
778 .EndsWith("elf", Triple::ELF)
779 .EndsWith("goff", Triple::GOFF)
780 .EndsWith("macho", Triple::MachO)
781 .EndsWith("wasm", Triple::Wasm)
782 .EndsWith("spirv", Triple::SPIRV)
784}
785
787 if (SubArchName.starts_with("mips") &&
788 (SubArchName.ends_with("r6el") || SubArchName.ends_with("r6")))
790
791 if (SubArchName == "powerpcspe")
793
794 if (SubArchName == "arm64e")
796
797 if (SubArchName == "arm64ec")
799
800 if (SubArchName.starts_with("spirv"))
801 return StringSwitch<Triple::SubArchType>(SubArchName)
810
811 if (SubArchName.starts_with("dxil"))
812 return StringSwitch<Triple::SubArchType>(SubArchName)
823
824 StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
825
826 // For now, this is the small part. Early return.
827 if (ARMSubArch.empty())
828 return StringSwitch<Triple::SubArchType>(SubArchName)
833
834 // ARM sub arch.
835 switch(ARM::parseArch(ARMSubArch)) {
836 case ARM::ArchKind::ARMV4:
837 return Triple::NoSubArch;
838 case ARM::ArchKind::ARMV4T:
840 case ARM::ArchKind::ARMV5T:
842 case ARM::ArchKind::ARMV5TE:
843 case ARM::ArchKind::IWMMXT:
844 case ARM::ArchKind::IWMMXT2:
845 case ARM::ArchKind::XSCALE:
846 case ARM::ArchKind::ARMV5TEJ:
848 case ARM::ArchKind::ARMV6:
850 case ARM::ArchKind::ARMV6K:
851 case ARM::ArchKind::ARMV6KZ:
853 case ARM::ArchKind::ARMV6T2:
855 case ARM::ArchKind::ARMV6M:
857 case ARM::ArchKind::ARMV7A:
858 case ARM::ArchKind::ARMV7R:
860 case ARM::ArchKind::ARMV7VE:
862 case ARM::ArchKind::ARMV7K:
864 case ARM::ArchKind::ARMV7M:
866 case ARM::ArchKind::ARMV7S:
868 case ARM::ArchKind::ARMV7EM:
870 case ARM::ArchKind::ARMV8A:
872 case ARM::ArchKind::ARMV8_1A:
874 case ARM::ArchKind::ARMV8_2A:
876 case ARM::ArchKind::ARMV8_3A:
878 case ARM::ArchKind::ARMV8_4A:
880 case ARM::ArchKind::ARMV8_5A:
882 case ARM::ArchKind::ARMV8_6A:
884 case ARM::ArchKind::ARMV8_7A:
886 case ARM::ArchKind::ARMV8_8A:
888 case ARM::ArchKind::ARMV8_9A:
890 case ARM::ArchKind::ARMV9A:
892 case ARM::ArchKind::ARMV9_1A:
894 case ARM::ArchKind::ARMV9_2A:
896 case ARM::ArchKind::ARMV9_3A:
898 case ARM::ArchKind::ARMV9_4A:
900 case ARM::ArchKind::ARMV9_5A:
902 case ARM::ArchKind::ARMV9_6A:
904 case ARM::ArchKind::ARMV8R:
906 case ARM::ArchKind::ARMV8MBaseline:
908 case ARM::ArchKind::ARMV8MMainline:
910 case ARM::ArchKind::ARMV8_1MMainline:
912 default:
913 return Triple::NoSubArch;
914 }
915}
916
918 switch (T.getArch()) {
920 case Triple::aarch64:
922 case Triple::arm:
923 case Triple::thumb:
924 case Triple::x86:
925 case Triple::x86_64:
926 switch (T.getOS()) {
927 case Triple::Win32:
928 case Triple::UEFI:
929 return Triple::COFF;
930 default:
931 return T.isOSDarwin() ? Triple::MachO : Triple::ELF;
932 }
934 case Triple::amdgcn:
935 case Triple::amdil64:
936 case Triple::amdil:
937 case Triple::arc:
938 case Triple::armeb:
939 case Triple::avr:
940 case Triple::bpfeb:
941 case Triple::bpfel:
942 case Triple::csky:
943 case Triple::hexagon:
944 case Triple::hsail64:
945 case Triple::hsail:
946 case Triple::kalimba:
947 case Triple::lanai:
950 case Triple::m68k:
951 case Triple::mips64:
952 case Triple::mips64el:
953 case Triple::mips:
954 case Triple::msp430:
955 case Triple::nvptx64:
956 case Triple::nvptx:
957 case Triple::ppc64le:
958 case Triple::ppcle:
959 case Triple::r600:
962 case Triple::riscv32:
963 case Triple::riscv64:
964 case Triple::shave:
965 case Triple::sparc:
966 case Triple::sparcel:
967 case Triple::sparcv9:
968 case Triple::spir64:
969 case Triple::spir:
970 case Triple::tce:
971 case Triple::tcele:
972 case Triple::thumbeb:
973 case Triple::ve:
974 case Triple::xcore:
975 case Triple::xtensa:
976 return Triple::ELF;
977
978 case Triple::mipsel:
979 if (T.isOSWindows())
980 return Triple::COFF;
981 return Triple::ELF;
982
983 case Triple::ppc64:
984 case Triple::ppc:
985 if (T.isOSAIX())
986 return Triple::XCOFF;
987 if (T.isOSDarwin())
988 return Triple::MachO;
989 return Triple::ELF;
990
991 case Triple::systemz:
992 if (T.isOSzOS())
993 return Triple::GOFF;
994 return Triple::ELF;
995
996 case Triple::wasm32:
997 case Triple::wasm64:
998 return Triple::Wasm;
999
1000 case Triple::spirv:
1001 case Triple::spirv32:
1002 case Triple::spirv64:
1003 return Triple::SPIRV;
1004
1005 case Triple::dxil:
1006 return Triple::DXContainer;
1007 }
1008 llvm_unreachable("unknown architecture");
1009}
1010
1011/// Construct a triple from the string representation provided.
1012///
1013/// This stores the string representation and parses the various pieces into
1014/// enum members.
1016 : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
1017 Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
1018 ObjectFormat(UnknownObjectFormat) {
1019 // Do minimal parsing by hand here.
1020 SmallVector<StringRef, 4> Components;
1021 StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
1022 if (Components.size() > 0) {
1023 Arch = parseArch(Components[0]);
1024 SubArch = parseSubArch(Components[0]);
1025 if (Components.size() > 1) {
1026 Vendor = parseVendor(Components[1]);
1027 if (Components.size() > 2) {
1028 OS = parseOS(Components[2]);
1029 if (Components.size() > 3) {
1030 Environment = parseEnvironment(Components[3]);
1031 ObjectFormat = parseFormat(Components[3]);
1032 }
1033 }
1034 } else {
1035 Environment =
1037 .StartsWith("mipsn32", Triple::GNUABIN32)
1038 .StartsWith("mips64", Triple::GNUABI64)
1039 .StartsWith("mipsisa64", Triple::GNUABI64)
1040 .StartsWith("mipsisa32", Triple::GNU)
1041 .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU)
1043 }
1044 }
1045 if (ObjectFormat == UnknownObjectFormat)
1046 ObjectFormat = getDefaultFormat(*this);
1047}
1048
1049/// Construct a triple from string representations of the architecture,
1050/// vendor, and OS.
1051///
1052/// This joins each argument into a canonical string representation and parses
1053/// them into enum members. It leaves the environment unknown and omits it from
1054/// the string representation.
1055Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
1056 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
1057 Arch(parseArch(ArchStr.str())),
1058 SubArch(parseSubArch(ArchStr.str())),
1059 Vendor(parseVendor(VendorStr.str())),
1060 OS(parseOS(OSStr.str())),
1061 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
1062 ObjectFormat = getDefaultFormat(*this);
1063}
1064
1065/// Construct a triple from string representations of the architecture,
1066/// vendor, OS, and environment.
1067///
1068/// This joins each argument into a canonical string representation and parses
1069/// them into enum members.
1070Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
1071 const Twine &EnvironmentStr)
1072 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
1073 EnvironmentStr).str()),
1074 Arch(parseArch(ArchStr.str())),
1075 SubArch(parseSubArch(ArchStr.str())),
1076 Vendor(parseVendor(VendorStr.str())),
1077 OS(parseOS(OSStr.str())),
1078 Environment(parseEnvironment(EnvironmentStr.str())),
1079 ObjectFormat(parseFormat(EnvironmentStr.str())) {
1080 if (ObjectFormat == Triple::UnknownObjectFormat)
1081 ObjectFormat = getDefaultFormat(*this);
1082}
1083
1085
1087 VersionTuple Ver =
1088 parseVersionFromName(ShaderModelStr.drop_front(strlen("shadermodel")));
1089 // Default DXIL minor version when Shader Model version is anything other
1090 // than 6.[0...8] or 6.x (which translates to latest current SM version)
1091 const unsigned SMMajor = 6;
1092 if (!Ver.empty()) {
1093 if (Ver.getMajor() == SMMajor) {
1094 if (std::optional<unsigned> SMMinor = Ver.getMinor()) {
1095 switch (*SMMinor) {
1096 case 0:
1098 case 1:
1100 case 2:
1102 case 3:
1104 case 4:
1106 case 5:
1108 case 6:
1110 case 7:
1112 case 8:
1114 default:
1115 report_fatal_error("Unsupported Shader Model version", false);
1116 }
1117 }
1118 }
1119 } else {
1120 // Special case: DXIL minor version is set to LatestCurrentDXILMinor for
1121 // shadermodel6.x is
1122 if (ShaderModelStr == "shadermodel6.x") {
1124 }
1125 }
1126 // DXIL version corresponding to Shader Model version other than 6.Minor
1127 // is 1.0
1129}
1130
1132 bool IsMinGW32 = false;
1133 bool IsCygwin = false;
1134
1135 // Parse into components.
1136 SmallVector<StringRef, 4> Components;
1137 Str.split(Components, '-');
1138
1139 // If the first component corresponds to a known architecture, preferentially
1140 // use it for the architecture. If the second component corresponds to a
1141 // known vendor, preferentially use it for the vendor, etc. This avoids silly
1142 // component movement when a component parses as (eg) both a valid arch and a
1143 // valid os.
1144 ArchType Arch = UnknownArch;
1145 if (Components.size() > 0)
1146 Arch = parseArch(Components[0]);
1147 VendorType Vendor = UnknownVendor;
1148 if (Components.size() > 1)
1149 Vendor = parseVendor(Components[1]);
1150 OSType OS = UnknownOS;
1151 if (Components.size() > 2) {
1152 OS = parseOS(Components[2]);
1153 IsCygwin = Components[2].starts_with("cygwin");
1154 IsMinGW32 = Components[2].starts_with("mingw");
1155 }
1156 EnvironmentType Environment = UnknownEnvironment;
1157 if (Components.size() > 3)
1158 Environment = parseEnvironment(Components[3]);
1160 if (Components.size() > 4)
1161 ObjectFormat = parseFormat(Components[4]);
1162
1163 // Note which components are already in their final position. These will not
1164 // be moved.
1165 bool Found[4];
1166 Found[0] = Arch != UnknownArch;
1167 Found[1] = Vendor != UnknownVendor;
1168 Found[2] = OS != UnknownOS;
1169 Found[3] = Environment != UnknownEnvironment;
1170
1171 // If they are not there already, permute the components into their canonical
1172 // positions by seeing if they parse as a valid architecture, and if so moving
1173 // the component to the architecture position etc.
1174 for (unsigned Pos = 0; Pos != std::size(Found); ++Pos) {
1175 if (Found[Pos])
1176 continue; // Already in the canonical position.
1177
1178 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
1179 // Do not reparse any components that already matched.
1180 if (Idx < std::size(Found) && Found[Idx])
1181 continue;
1182
1183 // Does this component parse as valid for the target position?
1184 bool Valid = false;
1185 StringRef Comp = Components[Idx];
1186 switch (Pos) {
1187 default: llvm_unreachable("unexpected component type!");
1188 case 0:
1189 Arch = parseArch(Comp);
1190 Valid = Arch != UnknownArch;
1191 break;
1192 case 1:
1193 Vendor = parseVendor(Comp);
1194 Valid = Vendor != UnknownVendor;
1195 break;
1196 case 2:
1197 OS = parseOS(Comp);
1198 IsCygwin = Comp.starts_with("cygwin");
1199 IsMinGW32 = Comp.starts_with("mingw");
1200 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
1201 break;
1202 case 3:
1203 Environment = parseEnvironment(Comp);
1204 Valid = Environment != UnknownEnvironment;
1205 if (!Valid) {
1206 ObjectFormat = parseFormat(Comp);
1207 Valid = ObjectFormat != UnknownObjectFormat;
1208 }
1209 break;
1210 }
1211 if (!Valid)
1212 continue; // Nope, try the next component.
1213
1214 // Move the component to the target position, pushing any non-fixed
1215 // components that are in the way to the right. This tends to give
1216 // good results in the common cases of a forgotten vendor component
1217 // or a wrongly positioned environment.
1218 if (Pos < Idx) {
1219 // Insert left, pushing the existing components to the right. For
1220 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
1221 StringRef CurrentComponent(""); // The empty component.
1222 // Replace the component we are moving with an empty component.
1223 std::swap(CurrentComponent, Components[Idx]);
1224 // Insert the component being moved at Pos, displacing any existing
1225 // components to the right.
1226 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
1227 // Skip over any fixed components.
1228 while (i < std::size(Found) && Found[i])
1229 ++i;
1230 // Place the component at the new position, getting the component
1231 // that was at this position - it will be moved right.
1232 std::swap(CurrentComponent, Components[i]);
1233 }
1234 } else if (Pos > Idx) {
1235 // Push right by inserting empty components until the component at Idx
1236 // reaches the target position Pos. For example, pc-a -> -pc-a when
1237 // moving pc to the second position.
1238 do {
1239 // Insert one empty component at Idx.
1240 StringRef CurrentComponent(""); // The empty component.
1241 for (unsigned i = Idx; i < Components.size();) {
1242 // Place the component at the new position, getting the component
1243 // that was at this position - it will be moved right.
1244 std::swap(CurrentComponent, Components[i]);
1245 // If it was placed on top of an empty component then we are done.
1246 if (CurrentComponent.empty())
1247 break;
1248 // Advance to the next component, skipping any fixed components.
1249 while (++i < std::size(Found) && Found[i])
1250 ;
1251 }
1252 // The last component was pushed off the end - append it.
1253 if (!CurrentComponent.empty())
1254 Components.push_back(CurrentComponent);
1255
1256 // Advance Idx to the component's new position.
1257 while (++Idx < std::size(Found) && Found[Idx])
1258 ;
1259 } while (Idx < Pos); // Add more until the final position is reached.
1260 }
1261 assert(Pos < Components.size() && Components[Pos] == Comp &&
1262 "Component moved wrong!");
1263 Found[Pos] = true;
1264 break;
1265 }
1266 }
1267
1268 // If "none" is in the middle component in a three-component triple, treat it
1269 // as the OS (Components[2]) instead of the vendor (Components[1]).
1270 if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
1271 Components[1] == "none" && Components[2].empty())
1272 std::swap(Components[1], Components[2]);
1273
1274 // Replace empty components with "unknown" value.
1275 for (StringRef &C : Components)
1276 if (C.empty())
1277 C = "unknown";
1278
1279 // Special case logic goes here. At this point Arch, Vendor and OS have the
1280 // correct values for the computed components.
1281 std::string NormalizedEnvironment;
1282 if (Environment == Triple::Android &&
1283 Components[3].starts_with("androideabi")) {
1284 StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi"));
1285 if (AndroidVersion.empty()) {
1286 Components[3] = "android";
1287 } else {
1288 NormalizedEnvironment = Twine("android", AndroidVersion).str();
1289 Components[3] = NormalizedEnvironment;
1290 }
1291 }
1292
1293 // SUSE uses "gnueabi" to mean "gnueabihf"
1294 if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI)
1295 Components[3] = "gnueabihf";
1296
1297 if (OS == Triple::Win32) {
1298 Components.resize(4);
1299 Components[2] = "windows";
1300 if (Environment == UnknownEnvironment) {
1301 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
1302 Components[3] = "msvc";
1303 else
1304 Components[3] = getObjectFormatTypeName(ObjectFormat);
1305 }
1306 } else if (IsMinGW32) {
1307 Components.resize(4);
1308 Components[2] = "windows";
1309 Components[3] = "gnu";
1310 } else if (IsCygwin) {
1311 Components.resize(4);
1312 Components[2] = "windows";
1313 Components[3] = "cygnus";
1314 }
1315 if (IsMinGW32 || IsCygwin ||
1316 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
1317 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
1318 Components.resize(5);
1319 Components[4] = getObjectFormatTypeName(ObjectFormat);
1320 }
1321 }
1322
1323 // Normalize DXIL triple if it does not include DXIL version number.
1324 // Determine DXIL version number using the minor version number of Shader
1325 // Model version specified in target triple, if any. Prior to decoupling DXIL
1326 // version numbering from that of Shader Model DXIL version 1.Y corresponds to
1327 // SM 6.Y. E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
1328 if (Components[0] == "dxil") {
1329 if (Components.size() > 4) {
1330 Components.resize(4);
1331 }
1332 // Add DXIL version only if shadermodel is specified in the triple
1333 if (OS == Triple::ShaderModel) {
1334 Components[0] = getDXILArchNameFromShaderModel(Components[2]);
1335 }
1336 }
1337 // Stick the corrected components back together to form the normalized string.
1338 return join(Components, "-");
1339}
1340
1342 return StringRef(Data).split('-').first; // Isolate first component
1343}
1344
1346 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1347 return Tmp.split('-').first; // Isolate second component
1348}
1349
1351 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1352 Tmp = Tmp.split('-').second; // Strip second component
1353 return Tmp.split('-').first; // Isolate third component
1354}
1355
1357 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1358 Tmp = Tmp.split('-').second; // Strip second component
1359 return Tmp.split('-').second; // Strip third component
1360}
1361
1363 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
1364 return Tmp.split('-').second; // Strip second component
1365}
1366
1369 Version.tryParse(Name);
1370 return Version.withoutBuild();
1371}
1372
1375}
1376
1378 StringRef EnvironmentName = getEnvironmentName();
1379
1380 // none is a valid environment type - it basically amounts to a freestanding
1381 // environment.
1382 if (EnvironmentName == "none")
1383 return "";
1384
1385 StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1386 EnvironmentName.consume_front(EnvironmentTypeName);
1387
1388 if (EnvironmentName.contains("-")) {
1389 // -obj is the suffix
1391 StringRef ObjectFormatTypeName =
1393 const std::string tmp = (Twine("-") + ObjectFormatTypeName).str();
1394 EnvironmentName.consume_back(tmp);
1395 }
1396 }
1397 return EnvironmentName;
1398}
1399
1401 StringRef OSName = getOSName();
1402 // Assume that the OS portion of the triple starts with the canonical name.
1403 StringRef OSTypeName = getOSTypeName(getOS());
1404 if (OSName.starts_with(OSTypeName))
1405 OSName = OSName.substr(OSTypeName.size());
1406 else if (getOS() == MacOSX)
1407 OSName.consume_front("macos");
1408 else if (OSName.starts_with("visionos"))
1409 OSName.consume_front("visionos");
1410
1411 return parseVersionFromName(OSName);
1412}
1413
1416
1417 switch (getOS()) {
1418 default: llvm_unreachable("unexpected OS for Darwin triple");
1419 case Darwin:
1420 // Default to darwin8, i.e., MacOSX 10.4.
1421 if (Version.getMajor() == 0)
1422 Version = VersionTuple(8);
1423 // Darwin version numbers are skewed from OS X versions.
1424 if (Version.getMajor() < 4) {
1425 return false;
1426 }
1427 if (Version.getMajor() <= 19) {
1428 Version = VersionTuple(10, Version.getMajor() - 4);
1429 } else {
1430 // darwin20+ corresponds to macOS 11+.
1431 Version = VersionTuple(11 + Version.getMajor() - 20);
1432 }
1433 break;
1434 case MacOSX:
1435 // Default to 10.4.
1436 if (Version.getMajor() == 0) {
1437 Version = VersionTuple(10, 4);
1438 } else if (Version.getMajor() < 10) {
1439 return false;
1440 }
1441 break;
1442 case IOS:
1443 case TvOS:
1444 case WatchOS:
1445 // Ignore the version from the triple. This is only handled because the
1446 // the clang driver combines OS X and IOS support into a common Darwin
1447 // toolchain that wants to know the OS X version number even when targeting
1448 // IOS.
1449 Version = VersionTuple(10, 4);
1450 break;
1451 case XROS:
1452 llvm_unreachable("OSX version isn't relevant for xrOS");
1453 case DriverKit:
1454 llvm_unreachable("OSX version isn't relevant for DriverKit");
1455 }
1456 return true;
1457}
1458
1460 switch (getOS()) {
1461 default: llvm_unreachable("unexpected OS for Darwin triple");
1462 case Darwin:
1463 case MacOSX:
1464 // Ignore the version from the triple. This is only handled because the
1465 // the clang driver combines OS X and IOS support into a common Darwin
1466 // toolchain that wants to know the iOS version number even when targeting
1467 // OS X.
1468 return VersionTuple(5);
1469 case IOS:
1470 case TvOS: {
1472 // Default to 5.0 (or 7.0 for arm64).
1473 if (Version.getMajor() == 0)
1474 return (getArch() == aarch64) ? VersionTuple(7) : VersionTuple(5);
1475 return Version;
1476 }
1477 case XROS: {
1478 // xrOS 1 is aligned with iOS 17.
1480 return Version.withMajorReplaced(Version.getMajor() + 16);
1481 }
1482 case WatchOS:
1483 llvm_unreachable("conflicting triple info");
1484 case DriverKit:
1485 llvm_unreachable("DriverKit doesn't have an iOS version");
1486 }
1487}
1488
1490 switch (getOS()) {
1491 default: llvm_unreachable("unexpected OS for Darwin triple");
1492 case Darwin:
1493 case MacOSX:
1494 // Ignore the version from the triple. This is only handled because the
1495 // the clang driver combines OS X and IOS support into a common Darwin
1496 // toolchain that wants to know the iOS version number even when targeting
1497 // OS X.
1498 return VersionTuple(2);
1499 case WatchOS: {
1501 if (Version.getMajor() == 0)
1502 return VersionTuple(2);
1503 return Version;
1504 }
1505 case IOS:
1506 llvm_unreachable("conflicting triple info");
1507 case XROS:
1508 llvm_unreachable("watchOS version isn't relevant for xrOS");
1509 case DriverKit:
1510 llvm_unreachable("DriverKit doesn't have a WatchOS version");
1511 }
1512}
1513
1515 switch (getOS()) {
1516 default:
1517 llvm_unreachable("unexpected OS for Darwin triple");
1518 case DriverKit:
1520 if (Version.getMajor() == 0)
1521 return Version.withMajorReplaced(19);
1522 return Version;
1523 }
1524}
1525
1527 if (getArch() != spirv || getOS() != Vulkan)
1528 llvm_unreachable("invalid Vulkan SPIR-V triple");
1529
1530 VersionTuple VulkanVersion = getOSVersion();
1531 SubArchType SpirvVersion = getSubArch();
1532
1534 // Vulkan 1.2 -> SPIR-V 1.5.
1536 // Vulkan 1.3 -> SPIR-V 1.6.
1538
1539 // If Vulkan version is unset, default to 1.2.
1540 if (VulkanVersion == VersionTuple(0))
1541 VulkanVersion = VersionTuple(1, 2);
1542
1543 if (ValidVersionMap.contains(VulkanVersion) &&
1544 (ValidVersionMap.lookup(VulkanVersion) == SpirvVersion ||
1545 SpirvVersion == NoSubArch))
1546 return VulkanVersion;
1547
1548 return VersionTuple(0);
1549}
1550
1552 if (getArch() != dxil || getOS() != ShaderModel)
1553 llvm_unreachable("invalid DXIL triple");
1554 StringRef Arch = getArchName();
1555 if (getSubArch() == NoSubArch)
1557 Arch.consume_front("dxilv");
1558 VersionTuple DXILVersion = parseVersionFromName(Arch);
1559 // FIXME: validate DXIL version against Shader Model version.
1560 // Tracked by https://github.com/llvm/llvm-project/issues/91388
1561 return DXILVersion;
1562}
1563
1564void Triple::setTriple(const Twine &Str) {
1565 *this = Triple(Str);
1566}
1567
1569 setArchName(getArchName(Kind, SubArch));
1570}
1571
1574}
1575
1577 setOSName(getOSTypeName(Kind));
1578}
1579
1581 if (ObjectFormat == getDefaultFormat(*this))
1583
1585 getObjectFormatTypeName(ObjectFormat)).str());
1586}
1587
1589 if (Environment == UnknownEnvironment)
1591
1592 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
1593 getObjectFormatTypeName(Kind)).str());
1594}
1595
1597 // Work around a miscompilation bug for Twines in gcc 4.0.3.
1599 Triple += Str;
1600 Triple += "-";
1601 Triple += getVendorName();
1602 Triple += "-";
1605}
1606
1608 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
1609}
1610
1612 if (hasEnvironment())
1613 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
1614 "-" + getEnvironmentName());
1615 else
1616 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1617}
1618
1620 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
1621 "-" + Str);
1622}
1623
1625 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
1626}
1627
1629 switch (Arch) {
1631 return 0;
1632
1633 case llvm::Triple::avr:
1635 return 16;
1636
1639 case llvm::Triple::arc:
1640 case llvm::Triple::arm:
1642 case llvm::Triple::csky:
1643 case llvm::Triple::dxil:
1649 case llvm::Triple::m68k:
1650 case llvm::Triple::mips:
1653 case llvm::Triple::ppc:
1655 case llvm::Triple::r600:
1661 case llvm::Triple::spir:
1663 case llvm::Triple::tce:
1668 case llvm::Triple::x86:
1671 return 32;
1672
1693 case llvm::Triple::ve:
1696 return 64;
1697 }
1698 llvm_unreachable("Invalid architecture value");
1699}
1700
1702 return getArchPointerBitWidth(getArch()) == 64;
1703}
1704
1706 return getArchPointerBitWidth(getArch()) == 32;
1707}
1708
1710 return getArchPointerBitWidth(getArch()) == 16;
1711}
1712
1714 Triple T(*this);
1715 switch (getArch()) {
1717 case Triple::amdgcn:
1718 case Triple::avr:
1719 case Triple::bpfeb:
1720 case Triple::bpfel:
1721 case Triple::msp430:
1722 case Triple::systemz:
1723 case Triple::ve:
1724 T.setArch(UnknownArch);
1725 break;
1726
1727 case Triple::aarch64_32:
1728 case Triple::amdil:
1729 case Triple::arc:
1730 case Triple::arm:
1731 case Triple::armeb:
1732 case Triple::csky:
1733 case Triple::dxil:
1734 case Triple::hexagon:
1735 case Triple::hsail:
1736 case Triple::kalimba:
1737 case Triple::lanai:
1739 case Triple::m68k:
1740 case Triple::mips:
1741 case Triple::mipsel:
1742 case Triple::nvptx:
1743 case Triple::ppc:
1744 case Triple::ppcle:
1745 case Triple::r600:
1747 case Triple::riscv32:
1748 case Triple::shave:
1749 case Triple::sparc:
1750 case Triple::sparcel:
1751 case Triple::spir:
1752 case Triple::spirv32:
1753 case Triple::tce:
1754 case Triple::tcele:
1755 case Triple::thumb:
1756 case Triple::thumbeb:
1757 case Triple::wasm32:
1758 case Triple::x86:
1759 case Triple::xcore:
1760 case Triple::xtensa:
1761 // Already 32-bit.
1762 break;
1763
1764 case Triple::aarch64: T.setArch(Triple::arm); break;
1765 case Triple::aarch64_be: T.setArch(Triple::armeb); break;
1766 case Triple::amdil64: T.setArch(Triple::amdil); break;
1767 case Triple::hsail64: T.setArch(Triple::hsail); break;
1768 case Triple::loongarch64: T.setArch(Triple::loongarch32); break;
1769 case Triple::mips64:
1770 T.setArch(Triple::mips, getSubArch());
1771 break;
1772 case Triple::mips64el:
1773 T.setArch(Triple::mipsel, getSubArch());
1774 break;
1775 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
1776 case Triple::ppc64: T.setArch(Triple::ppc); break;
1777 case Triple::ppc64le: T.setArch(Triple::ppcle); break;
1778 case Triple::renderscript64: T.setArch(Triple::renderscript32); break;
1779 case Triple::riscv64: T.setArch(Triple::riscv32); break;
1780 case Triple::sparcv9: T.setArch(Triple::sparc); break;
1781 case Triple::spir64: T.setArch(Triple::spir); break;
1782 case Triple::spirv:
1783 case Triple::spirv64:
1784 T.setArch(Triple::spirv32, getSubArch());
1785 break;
1786 case Triple::wasm64: T.setArch(Triple::wasm32); break;
1787 case Triple::x86_64: T.setArch(Triple::x86); break;
1788 }
1789 return T;
1790}
1791
1793 Triple T(*this);
1794 switch (getArch()) {
1796 case Triple::arc:
1797 case Triple::avr:
1798 case Triple::csky:
1799 case Triple::dxil:
1800 case Triple::hexagon:
1801 case Triple::kalimba:
1802 case Triple::lanai:
1803 case Triple::m68k:
1804 case Triple::msp430:
1805 case Triple::r600:
1806 case Triple::shave:
1807 case Triple::sparcel:
1808 case Triple::tce:
1809 case Triple::tcele:
1810 case Triple::xcore:
1811 case Triple::xtensa:
1812 T.setArch(UnknownArch);
1813 break;
1814
1815 case Triple::aarch64:
1816 case Triple::aarch64_be:
1817 case Triple::amdgcn:
1818 case Triple::amdil64:
1819 case Triple::bpfeb:
1820 case Triple::bpfel:
1821 case Triple::hsail64:
1823 case Triple::mips64:
1824 case Triple::mips64el:
1825 case Triple::nvptx64:
1826 case Triple::ppc64:
1827 case Triple::ppc64le:
1829 case Triple::riscv64:
1830 case Triple::sparcv9:
1831 case Triple::spir64:
1832 case Triple::spirv64:
1833 case Triple::systemz:
1834 case Triple::ve:
1835 case Triple::wasm64:
1836 case Triple::x86_64:
1837 // Already 64-bit.
1838 break;
1839
1840 case Triple::aarch64_32: T.setArch(Triple::aarch64); break;
1841 case Triple::amdil: T.setArch(Triple::amdil64); break;
1842 case Triple::arm: T.setArch(Triple::aarch64); break;
1843 case Triple::armeb: T.setArch(Triple::aarch64_be); break;
1844 case Triple::hsail: T.setArch(Triple::hsail64); break;
1845 case Triple::loongarch32: T.setArch(Triple::loongarch64); break;
1846 case Triple::mips:
1847 T.setArch(Triple::mips64, getSubArch());
1848 break;
1849 case Triple::mipsel:
1850 T.setArch(Triple::mips64el, getSubArch());
1851 break;
1852 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
1853 case Triple::ppc: T.setArch(Triple::ppc64); break;
1854 case Triple::ppcle: T.setArch(Triple::ppc64le); break;
1855 case Triple::renderscript32: T.setArch(Triple::renderscript64); break;
1856 case Triple::riscv32: T.setArch(Triple::riscv64); break;
1857 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1858 case Triple::spir: T.setArch(Triple::spir64); break;
1859 case Triple::spirv:
1860 case Triple::spirv32:
1861 T.setArch(Triple::spirv64, getSubArch());
1862 break;
1863 case Triple::thumb: T.setArch(Triple::aarch64); break;
1864 case Triple::thumbeb: T.setArch(Triple::aarch64_be); break;
1865 case Triple::wasm32: T.setArch(Triple::wasm64); break;
1866 case Triple::x86: T.setArch(Triple::x86_64); break;
1867 }
1868 return T;
1869}
1870
1872 Triple T(*this);
1873 // Already big endian.
1874 if (!isLittleEndian())
1875 return T;
1876 switch (getArch()) {
1878 case Triple::amdgcn:
1879 case Triple::amdil64:
1880 case Triple::amdil:
1881 case Triple::avr:
1882 case Triple::dxil:
1883 case Triple::hexagon:
1884 case Triple::hsail64:
1885 case Triple::hsail:
1886 case Triple::kalimba:
1889 case Triple::msp430:
1890 case Triple::nvptx64:
1891 case Triple::nvptx:
1892 case Triple::r600:
1895 case Triple::riscv32:
1896 case Triple::riscv64:
1897 case Triple::shave:
1898 case Triple::spir64:
1899 case Triple::spir:
1900 case Triple::spirv:
1901 case Triple::spirv32:
1902 case Triple::spirv64:
1903 case Triple::wasm32:
1904 case Triple::wasm64:
1905 case Triple::x86:
1906 case Triple::x86_64:
1907 case Triple::xcore:
1908 case Triple::ve:
1909 case Triple::csky:
1910 case Triple::xtensa:
1911
1912 // ARM is intentionally unsupported here, changing the architecture would
1913 // drop any arch suffixes.
1914 case Triple::arm:
1915 case Triple::thumb:
1916 T.setArch(UnknownArch);
1917 break;
1918
1919 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1920 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1921 case Triple::mips64el:
1922 T.setArch(Triple::mips64, getSubArch());
1923 break;
1924 case Triple::mipsel:
1925 T.setArch(Triple::mips, getSubArch());
1926 break;
1927 case Triple::ppcle: T.setArch(Triple::ppc); break;
1928 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1929 case Triple::sparcel: T.setArch(Triple::sparc); break;
1930 case Triple::tcele: T.setArch(Triple::tce); break;
1931 default:
1932 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
1933 }
1934 return T;
1935}
1936
1938 Triple T(*this);
1939 if (isLittleEndian())
1940 return T;
1941
1942 switch (getArch()) {
1944 case Triple::lanai:
1945 case Triple::sparcv9:
1946 case Triple::systemz:
1947 case Triple::m68k:
1948
1949 // ARM is intentionally unsupported here, changing the architecture would
1950 // drop any arch suffixes.
1951 case Triple::armeb:
1952 case Triple::thumbeb:
1953 T.setArch(UnknownArch);
1954 break;
1955
1956 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1957 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1958 case Triple::mips64:
1959 T.setArch(Triple::mips64el, getSubArch());
1960 break;
1961 case Triple::mips:
1962 T.setArch(Triple::mipsel, getSubArch());
1963 break;
1964 case Triple::ppc: T.setArch(Triple::ppcle); break;
1965 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1966 case Triple::sparc: T.setArch(Triple::sparcel); break;
1967 case Triple::tce: T.setArch(Triple::tcele); break;
1968 default:
1969 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1970 }
1971 return T;
1972}
1973
1975 switch (getArch()) {
1976 case Triple::aarch64:
1977 case Triple::aarch64_32:
1978 case Triple::amdgcn:
1979 case Triple::amdil64:
1980 case Triple::amdil:
1981 case Triple::arm:
1982 case Triple::avr:
1983 case Triple::bpfel:
1984 case Triple::csky:
1985 case Triple::dxil:
1986 case Triple::hexagon:
1987 case Triple::hsail64:
1988 case Triple::hsail:
1989 case Triple::kalimba:
1992 case Triple::mips64el:
1993 case Triple::mipsel:
1994 case Triple::msp430:
1995 case Triple::nvptx64:
1996 case Triple::nvptx:
1997 case Triple::ppcle:
1998 case Triple::ppc64le:
1999 case Triple::r600:
2002 case Triple::riscv32:
2003 case Triple::riscv64:
2004 case Triple::shave:
2005 case Triple::sparcel:
2006 case Triple::spir64:
2007 case Triple::spir:
2008 case Triple::spirv:
2009 case Triple::spirv32:
2010 case Triple::spirv64:
2011 case Triple::tcele:
2012 case Triple::thumb:
2013 case Triple::ve:
2014 case Triple::wasm32:
2015 case Triple::wasm64:
2016 case Triple::x86:
2017 case Triple::x86_64:
2018 case Triple::xcore:
2019 case Triple::xtensa:
2020 return true;
2021 default:
2022 return false;
2023 }
2024}
2025
2027 // ARM and Thumb triples are compatible, if subarch, vendor and OS match.
2028 if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) ||
2029 (getArch() == Triple::arm && Other.getArch() == Triple::thumb) ||
2030 (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) ||
2031 (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) {
2032 if (getVendor() == Triple::Apple)
2033 return getSubArch() == Other.getSubArch() &&
2034 getVendor() == Other.getVendor() && getOS() == Other.getOS();
2035 else
2036 return getSubArch() == Other.getSubArch() &&
2037 getVendor() == Other.getVendor() && getOS() == Other.getOS() &&
2038 getEnvironment() == Other.getEnvironment() &&
2039 getObjectFormat() == Other.getObjectFormat();
2040 }
2041
2042 // If vendor is apple, ignore the version number.
2043 if (getVendor() == Triple::Apple)
2044 return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() &&
2045 getVendor() == Other.getVendor() && getOS() == Other.getOS();
2046
2047 return *this == Other;
2048}
2049
2050std::string Triple::merge(const Triple &Other) const {
2051 // If vendor is apple, pick the triple with the larger version number.
2052 if (getVendor() == Triple::Apple)
2053 if (Other.isOSVersionLT(*this))
2054 return str();
2055
2056 return Other.str();
2057}
2058
2059bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
2060 unsigned Micro) const {
2061 assert(isMacOSX() && "Not an OS X triple!");
2062
2063 // If this is OS X, expect a sane version number.
2064 if (getOS() == Triple::MacOSX)
2065 return isOSVersionLT(Major, Minor, Micro);
2066
2067 // Otherwise, compare to the "Darwin" number.
2068 if (Major == 10) {
2069 return isOSVersionLT(Minor + 4, Micro, 0);
2070 } else {
2071 assert(Major >= 11 && "Unexpected major version");
2072 return isOSVersionLT(Major - 11 + 20, Minor, Micro);
2073 }
2074}
2075
2078 return VersionTuple();
2079 switch (getOS()) {
2080 case Triple::MacOSX:
2081 // ARM64 slice is supported starting from macOS 11.0+.
2082 return VersionTuple(11, 0, 0);
2083 case Triple::IOS:
2084 // ARM64 slice is supported starting from Mac Catalyst 14 (macOS 11).
2085 // ARM64 simulators are supported for iOS 14+.
2087 return VersionTuple(14, 0, 0);
2088 // ARM64e slice is supported starting from iOS 14.
2089 if (isArm64e())
2090 return VersionTuple(14, 0, 0);
2091 break;
2092 case Triple::TvOS:
2093 // ARM64 simulators are supported for tvOS 14+.
2095 return VersionTuple(14, 0, 0);
2096 break;
2097 case Triple::WatchOS:
2098 // ARM64 simulators are supported for watchOS 7+.
2100 return VersionTuple(7, 0, 0);
2101 break;
2102 case Triple::DriverKit:
2103 return VersionTuple(20, 0, 0);
2104 default:
2105 break;
2106 }
2107 return VersionTuple();
2108}
2109
2111 const VersionTuple &Version) {
2112 switch (OSKind) {
2113 case MacOSX:
2114 // macOS 10.16 is canonicalized to macOS 11.
2115 if (Version == VersionTuple(10, 16))
2116 return VersionTuple(11, 0);
2117 [[fallthrough]];
2118 default:
2119 return Version;
2120 }
2121}
2122
2123// HLSL triple environment orders are relied on in the front end
2124static_assert(Triple::Vertex - Triple::Pixel == 1,
2125 "incorrect HLSL stage order");
2126static_assert(Triple::Geometry - Triple::Pixel == 2,
2127 "incorrect HLSL stage order");
2128static_assert(Triple::Hull - Triple::Pixel == 3,
2129 "incorrect HLSL stage order");
2130static_assert(Triple::Domain - Triple::Pixel == 4,
2131 "incorrect HLSL stage order");
2132static_assert(Triple::Compute - Triple::Pixel == 5,
2133 "incorrect HLSL stage order");
2134static_assert(Triple::Library - Triple::Pixel == 6,
2135 "incorrect HLSL stage order");
2136static_assert(Triple::RayGeneration - Triple::Pixel == 7,
2137 "incorrect HLSL stage order");
2138static_assert(Triple::Intersection - Triple::Pixel == 8,
2139 "incorrect HLSL stage order");
2140static_assert(Triple::AnyHit - Triple::Pixel == 9,
2141 "incorrect HLSL stage order");
2142static_assert(Triple::ClosestHit - Triple::Pixel == 10,
2143 "incorrect HLSL stage order");
2144static_assert(Triple::Miss - Triple::Pixel == 11,
2145 "incorrect HLSL stage order");
2146static_assert(Triple::Callable - Triple::Pixel == 12,
2147 "incorrect HLSL stage order");
2148static_assert(Triple::Mesh - Triple::Pixel == 13,
2149 "incorrect HLSL stage order");
2150static_assert(Triple::Amplification - Triple::Pixel == 14,
2151 "incorrect HLSL stage order");
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
std::string Name
Load MIR Sample Profile
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file defines the SmallString class.
This file contains some functions that are useful when dealing with strings.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
DEMANGLE_NAMESPACE_BEGIN bool starts_with(std::string_view self, char C) noexcept
static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName)
Definition: Triple.cpp:717
static VersionTuple parseVersionFromName(StringRef Name)
Definition: Triple.cpp:1367
static Triple::ObjectFormatType getDefaultFormat(const Triple &T)
Definition: Triple.cpp:917
static Triple::ArchType parseARMArch(StringRef ArchName)
Definition: Triple.cpp:492
static Triple::OSType parseOS(StringRef OSName)
Definition: Triple.cpp:670
static StringRef getDXILArchNameFromShaderModel(StringRef ShaderModelStr)
Definition: Triple.cpp:1086
static Triple::ArchType parseBPFArch(StringRef ArchName)
Definition: Triple.cpp:407
static Triple::SubArchType parseSubArch(StringRef SubArchName)
Definition: Triple.cpp:786
static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName)
Definition: Triple.cpp:772
static Triple::ArchType parseArch(StringRef ArchName)
Definition: Triple.cpp:557
static Triple::VendorType parseVendor(StringRef VendorName)
Definition: Triple.cpp:650
Defines the llvm::VersionTuple class, which represents a version in the form major[....
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition: DenseMap.h:147
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
size_t size() const
Definition: SmallVector.h:78
void resize(size_type N)
Definition: SmallVector.h:638
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:700
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:655
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:571
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:265
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:609
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:424
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:635
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:277
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
StringSwitch & StartsWith(StringLiteral S, T Value)
Definition: StringSwitch.h:83
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Definition: StringSwitch.h:90
StringSwitch & EndsWith(StringLiteral S, T Value)
Definition: StringSwitch.h:76
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isMacOSXVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
Comparison function for checking OS X version compatibility, which handles supporting skewed version ...
Definition: Triple.cpp:2059
VersionTuple getOSVersion() const
Parse the version number from the OS name component of the triple, if present.
Definition: Triple.cpp:1400
StringRef getVendorName() const
Get the vendor (second) component of the triple.
Definition: Triple.cpp:1345
VersionTuple getWatchOSVersion() const
Parse the version number as with getOSVersion.
Definition: Triple.cpp:1489
void setArchName(StringRef Str)
Set the architecture (first) component of the triple by name.
Definition: Triple.cpp:1596
void setObjectFormat(ObjectFormatType Kind)
Set the object file format.
Definition: Triple.cpp:1588
llvm::Triple get32BitArchVariant() const
Form a triple with a 32-bit variant of the current architecture.
Definition: Triple.cpp:1713
Triple()=default
Default constructor is the same as an empty string and leaves all triple fields unknown.
@ MuslABIN32
Definition: Triple.h:265
@ RayGeneration
Definition: Triple.h:292
@ GNUEABIT64
Definition: Triple.h:252
@ UnknownEnvironment
Definition: Triple.h:245
@ ClosestHit
Definition: Triple.h:295
@ MuslEABIHF
Definition: Triple.h:268
@ Amplification
Definition: Triple.h:299
@ Intersection
Definition: Triple.h:293
@ GNUEABIHFT64
Definition: Triple.h:254
std::string normalize() const
Return the normalized form of this triple's string.
Definition: Triple.h:376
unsigned getArchPointerBitWidth() const
Returns the pointer width of this architecture.
Definition: Triple.h:485
llvm::Triple getLittleEndianArchVariant() const
Form a triple with a little endian variant of the current architecture.
Definition: Triple.cpp:1937
static StringRef getVendorTypeName(VendorType Kind)
Get the canonical name for the Kind vendor.
Definition: Triple.cpp:254
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
Definition: Triple.h:409
SubArchType getSubArch() const
get the parsed subarchitecture type for this triple.
Definition: Triple.h:386
bool isArm64e() const
Tests whether the target is the Apple "arm64e" AArch64 subarch.
Definition: Triple.h:1056
void setVendorName(StringRef Str)
Set the vendor (second) component of the triple by name.
Definition: Triple.cpp:1607
@ HermitCore
Definition: Triple.h:234
@ ShaderModel
Definition: Triple.h:238
@ Emscripten
Definition: Triple.h:237
void setOSAndEnvironmentName(StringRef Str)
Set the operating system and optional environment components with a single string.
Definition: Triple.cpp:1624
llvm::Triple get64BitArchVariant() const
Form a triple with a 64-bit variant of the current architecture.
Definition: Triple.cpp:1792
bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition: Triple.cpp:1974
void setEnvironment(EnvironmentType Kind)
Set the environment (fourth) component of the triple to a known type.
Definition: Triple.cpp:1580
StringRef getOSName() const
Get the operating system (third) component of the triple.
Definition: Triple.cpp:1350
@ loongarch32
Definition: Triple.h:61
@ renderscript64
Definition: Triple.h:106
@ UnknownArch
Definition: Triple.h:47
@ aarch64_be
Definition: Triple.h:52
@ loongarch64
Definition: Triple.h:62
@ renderscript32
Definition: Triple.h:105
@ mips64el
Definition: Triple.h:67
@ aarch64_32
Definition: Triple.h:53
void setTriple(const Twine &Str)
Set all components to the new triple Str.
Definition: Triple.cpp:1564
OSType getOS() const
Get the parsed operating system type of this triple.
Definition: Triple.h:392
VersionTuple getEnvironmentVersion() const
Parse the version number from the OS name component of the triple, if present.
Definition: Triple.cpp:1373
static ArchType getArchTypeForLLVMName(StringRef Str)
The canonical type for the given LLVM architecture name (e.g., "x86").
Definition: Triple.cpp:422
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:383
StringRef getEnvironmentName() const
Get the optional environment (fourth) component of the triple, or "" if empty.
Definition: Triple.cpp:1356
bool isSimulatorEnvironment() const
Definition: Triple.h:577
VersionTuple getDXILVersion() const
Parse the DXIL version number from the OSVersion and DXIL version (SubArch).
Definition: Triple.cpp:1551
const std::string & str() const
Definition: Triple.h:450
EnvironmentType getEnvironment() const
Get the parsed environment type of this triple.
Definition: Triple.h:400
VersionTuple getVulkanVersion() const
Parse the Vulkan version number from the OSVersion and SPIR-V version (SubArch).
Definition: Triple.cpp:1526
VersionTuple getDriverKitVersion() const
Parse the version number as with getOSVersion.
Definition: Triple.cpp:1514
static StringRef getArchTypeName(ArchType Kind)
Get the canonical name for the Kind architecture.
Definition: Triple.cpp:24
static StringRef getOSTypeName(OSType Kind)
Get the canonical name for the Kind operating system.
Definition: Triple.cpp:278
ObjectFormatType
Definition: Triple.h:307
@ DXContainer
Definition: Triple.h:311
@ UnknownObjectFormat
Definition: Triple.h:308
std::string merge(const Triple &Other) const
Merge target triples.
Definition: Triple.cpp:2050
@ UnknownVendor
Definition: Triple.h:181
@ OpenEmbedded
Definition: Triple.h:195
@ ImaginationTechnologies
Definition: Triple.h:188
@ MipsTechnologies
Definition: Triple.h:189
VersionTuple getMinimumSupportedOSVersion() const
Some platforms have different minimum supported OS versions that varies by the architecture specified...
Definition: Triple.cpp:2076
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1701
StringRef getOSAndEnvironmentName() const
Get the operating system and optional environment components as a single string (separated by a '-' i...
Definition: Triple.cpp:1362
@ ARMSubArch_v6t2
Definition: Triple.h:143
@ MipsSubArch_r6
Definition: Triple.h:155
@ DXILSubArch_v1_2
Definition: Triple.h:171
@ ARMSubArch_v7
Definition: Triple.h:134
@ ARMSubArch_v8m_mainline
Definition: Triple.h:132
@ ARMSubArch_v9_6a
Definition: Triple.h:113
@ ARMSubArch_v8r
Definition: Triple.h:130
@ ARMSubArch_v9_1a
Definition: Triple.h:118
@ DXILSubArch_v1_1
Definition: Triple.h:170
@ LatestDXILSubArch
Definition: Triple.h:178
@ SPIRVSubArch_v10
Definition: Triple.h:160
@ SPIRVSubArch_v13
Definition: Triple.h:163
@ ARMSubArch_v7k
Definition: Triple.h:138
@ ARMSubArch_v8_7a
Definition: Triple.h:122
@ ARMSubArch_v8
Definition: Triple.h:129
@ SPIRVSubArch_v16
Definition: Triple.h:166
@ ARMSubArch_v8_1a
Definition: Triple.h:128
@ ARMSubArch_v9_2a
Definition: Triple.h:117
@ DXILSubArch_v1_3
Definition: Triple.h:172
@ SPIRVSubArch_v15
Definition: Triple.h:165
@ ARMSubArch_v7m
Definition: Triple.h:136
@ ARMSubArch_v6k
Definition: Triple.h:142
@ ARMSubArch_v5
Definition: Triple.h:144
@ AArch64SubArch_arm64e
Definition: Triple.h:148
@ ARMSubArch_v6
Definition: Triple.h:140
@ ARMSubArch_v9_5a
Definition: Triple.h:114
@ ARMSubArch_v7ve
Definition: Triple.h:139
@ ARMSubArch_v8m_baseline
Definition: Triple.h:131
@ ARMSubArch_v8_8a
Definition: Triple.h:121
@ ARMSubArch_v8_2a
Definition: Triple.h:127
@ ARMSubArch_v7s
Definition: Triple.h:137
@ DXILSubArch_v1_0
Definition: Triple.h:169
@ DXILSubArch_v1_7
Definition: Triple.h:176
@ KalimbaSubArch_v3
Definition: Triple.h:151
@ DXILSubArch_v1_5
Definition: Triple.h:174
@ ARMSubArch_v8_4a
Definition: Triple.h:125
@ ARMSubArch_v8_9a
Definition: Triple.h:120
@ ARMSubArch_v7em
Definition: Triple.h:135
@ SPIRVSubArch_v12
Definition: Triple.h:162
@ SPIRVSubArch_v14
Definition: Triple.h:164
@ KalimbaSubArch_v4
Definition: Triple.h:152
@ ARMSubArch_v8_1m_mainline
Definition: Triple.h:133
@ ARMSubArch_v8_3a
Definition: Triple.h:126
@ AArch64SubArch_arm64ec
Definition: Triple.h:149
@ ARMSubArch_v8_6a
Definition: Triple.h:123
@ ARMSubArch_v5te
Definition: Triple.h:145
@ KalimbaSubArch_v5
Definition: Triple.h:153
@ ARMSubArch_v4t
Definition: Triple.h:146
@ DXILSubArch_v1_6
Definition: Triple.h:175
@ DXILSubArch_v1_8
Definition: Triple.h:177
@ ARMSubArch_v9_4a
Definition: Triple.h:115
@ ARMSubArch_v8_5a
Definition: Triple.h:124
@ ARMSubArch_v6m
Definition: Triple.h:141
@ ARMSubArch_v9_3a
Definition: Triple.h:116
@ ARMSubArch_v9
Definition: Triple.h:119
@ DXILSubArch_v1_4
Definition: Triple.h:173
@ SPIRVSubArch_v11
Definition: Triple.h:161
@ PPCSubArch_spe
Definition: Triple.h:157
bool getMacOSXVersion(VersionTuple &Version) const
Parse the version number as with getOSVersion and then translate generic "darwin" versions to the cor...
Definition: Triple.cpp:1414
bool isMacOSX() const
Is this a Mac OS X triple.
Definition: Triple.h:532
void setEnvironmentName(StringRef Str)
Set the optional environment (fourth) component of the triple by name.
Definition: Triple.cpp:1619
void setOS(OSType Kind)
Set the operating system (third) component of the triple to a known type.
Definition: Triple.cpp:1576
void setOSName(StringRef Str)
Set the operating system (third) component of the triple by name.
Definition: Triple.cpp:1611
VendorType getVendor() const
Get the parsed vendor type of this triple.
Definition: Triple.h:389
static StringRef getEnvironmentTypeName(EnvironmentType Kind)
Get the canonical name for the Kind environment.
Definition: Triple.cpp:327
bool isOSVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
Helper function for doing comparisons against version numbers included in the target triple.
Definition: Triple.h:510
static VersionTuple getCanonicalVersionForOS(OSType OSKind, const VersionTuple &Version)
Returns a canonicalized OS version number for the specified OS.
Definition: Triple.cpp:2110
StringRef getArchName() const
Get the architecture (first) component of the triple.
Definition: Triple.cpp:1341
bool isMacCatalystEnvironment() const
Definition: Triple.h:581
static StringRef getObjectFormatTypeName(ObjectFormatType ObjectFormat)
Get the name for the Object format.
Definition: Triple.cpp:392
bool isArch16Bit() const
Test whether the architecture is 16-bit.
Definition: Triple.cpp:1709
llvm::Triple getBigEndianArchVariant() const
Form a triple with a big endian variant of the current architecture.
Definition: Triple.cpp:1871
VersionTuple getiOSVersion() const
Parse the version number as with getOSVersion.
Definition: Triple.cpp:1459
StringRef getEnvironmentVersionString() const
Get the version component of the environment component as a single string (the version after the envi...
Definition: Triple.cpp:1377
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1705
bool isCompatibleWith(const Triple &Other) const
Test whether target triples are compatible.
Definition: Triple.cpp:2026
bool hasEnvironment() const
Does this triple have the optional environment (fourth) component?
Definition: Triple.h:395
static StringRef getArchTypePrefix(ArchType Kind)
Get the "prefix" canonical name for the Kind architecture.
Definition: Triple.cpp:167
void setArch(ArchType Kind, SubArchType SubArch=NoSubArch)
Set the architecture (first) component of the triple to a known type.
Definition: Triple.cpp:1568
void setVendor(VendorType Kind)
Set the vendor (second) component of the triple to a known type.
Definition: Triple.cpp:1572
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:71
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero).
Definition: VersionTuple.h:66
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:74
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef getCanonicalArchName(StringRef Arch)
MArch is expected to be of the form (arm|thumb)?(eb)?(v.
ISAKind parseArchISA(StringRef Arch)
ArchKind parseArch(StringRef Arch)
ProfileKind parseArchProfile(StringRef Arch)
unsigned parseArchVersion(StringRef Arch)
EndianKind parseArchEndian(StringRef Arch)
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
static const bool IsLittleEndianHost
Definition: SwapByteOrder.h:29
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
@ Other
Any other memory.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860