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