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