/home/arjun/llvm-project/llvm/lib/Support/Triple.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
9 | | #include "llvm/ADT/Triple.h" |
10 | | #include "llvm/ADT/STLExtras.h" |
11 | | #include "llvm/ADT/SmallString.h" |
12 | | #include "llvm/ADT/StringExtras.h" |
13 | | #include "llvm/ADT/StringSwitch.h" |
14 | | #include "llvm/Support/ErrorHandling.h" |
15 | | #include "llvm/Support/Host.h" |
16 | | #include "llvm/Support/SwapByteOrder.h" |
17 | | #include "llvm/Support/TargetParser.h" |
18 | | #include <cassert> |
19 | | #include <cstring> |
20 | | using namespace llvm; |
21 | | |
22 | 0 | StringRef Triple::getArchTypeName(ArchType Kind) { |
23 | 0 | switch (Kind) { |
24 | 0 | case UnknownArch: return "unknown"; |
25 | 0 |
|
26 | 0 | case aarch64: return "aarch64"; |
27 | 0 | case aarch64_32: return "aarch64_32"; |
28 | 0 | case aarch64_be: return "aarch64_be"; |
29 | 0 | case amdgcn: return "amdgcn"; |
30 | 0 | case amdil64: return "amdil64"; |
31 | 0 | case amdil: return "amdil"; |
32 | 0 | case arc: return "arc"; |
33 | 0 | case arm: return "arm"; |
34 | 0 | case armeb: return "armeb"; |
35 | 0 | case avr: return "avr"; |
36 | 0 | case bpfeb: return "bpfeb"; |
37 | 0 | case bpfel: return "bpfel"; |
38 | 0 | case hexagon: return "hexagon"; |
39 | 0 | case hsail64: return "hsail64"; |
40 | 0 | case hsail: return "hsail"; |
41 | 0 | case kalimba: return "kalimba"; |
42 | 0 | case lanai: return "lanai"; |
43 | 0 | case le32: return "le32"; |
44 | 0 | case le64: return "le64"; |
45 | 0 | case mips64: return "mips64"; |
46 | 0 | case mips64el: return "mips64el"; |
47 | 0 | case mips: return "mips"; |
48 | 0 | case mipsel: return "mipsel"; |
49 | 0 | case msp430: return "msp430"; |
50 | 0 | case nvptx64: return "nvptx64"; |
51 | 0 | case nvptx: return "nvptx"; |
52 | 0 | case ppc64: return "powerpc64"; |
53 | 0 | case ppc64le: return "powerpc64le"; |
54 | 0 | case ppc: return "powerpc"; |
55 | 0 | case r600: return "r600"; |
56 | 0 | case renderscript32: return "renderscript32"; |
57 | 0 | case renderscript64: return "renderscript64"; |
58 | 0 | case riscv32: return "riscv32"; |
59 | 0 | case riscv64: return "riscv64"; |
60 | 0 | case shave: return "shave"; |
61 | 0 | case sparc: return "sparc"; |
62 | 0 | case sparcel: return "sparcel"; |
63 | 0 | case sparcv9: return "sparcv9"; |
64 | 0 | case spir64: return "spir64"; |
65 | 0 | case spir: return "spir"; |
66 | 0 | case systemz: return "s390x"; |
67 | 0 | case tce: return "tce"; |
68 | 0 | case tcele: return "tcele"; |
69 | 0 | case thumb: return "thumb"; |
70 | 0 | case thumbeb: return "thumbeb"; |
71 | 0 | case ve: return "ve"; |
72 | 0 | case wasm32: return "wasm32"; |
73 | 0 | case wasm64: return "wasm64"; |
74 | 0 | case x86: return "i386"; |
75 | 0 | case x86_64: return "x86_64"; |
76 | 0 | case xcore: return "xcore"; |
77 | 0 | } |
78 | 0 | |
79 | 0 | llvm_unreachable("Invalid ArchType!"); |
80 | 0 | } |
81 | | |
82 | | StringRef Triple::getArchTypePrefix(ArchType Kind) { |
83 | | switch (Kind) { |
84 | | default: |
85 | | return StringRef(); |
86 | | |
87 | | case aarch64: |
88 | | case aarch64_be: |
89 | | case aarch64_32: return "aarch64"; |
90 | | |
91 | | case arc: return "arc"; |
92 | | |
93 | | case arm: |
94 | | case armeb: |
95 | | case thumb: |
96 | | case thumbeb: return "arm"; |
97 | | |
98 | | case avr: return "avr"; |
99 | | |
100 | | case ppc64: |
101 | | case ppc64le: |
102 | | case ppc: return "ppc"; |
103 | | |
104 | | case mips: |
105 | | case mipsel: |
106 | | case mips64: |
107 | | case mips64el: return "mips"; |
108 | | |
109 | | case hexagon: return "hexagon"; |
110 | | |
111 | | case amdgcn: return "amdgcn"; |
112 | | case r600: return "r600"; |
113 | | |
114 | | case bpfel: |
115 | | case bpfeb: return "bpf"; |
116 | | |
117 | | case sparcv9: |
118 | | case sparcel: |
119 | | case sparc: return "sparc"; |
120 | | |
121 | | case systemz: return "s390"; |
122 | | |
123 | | case x86: |
124 | | case x86_64: return "x86"; |
125 | | |
126 | | case xcore: return "xcore"; |
127 | | |
128 | | // NVPTX intrinsics are namespaced under nvvm. |
129 | | case nvptx: return "nvvm"; |
130 | | case nvptx64: return "nvvm"; |
131 | | |
132 | | case le32: return "le32"; |
133 | | case le64: return "le64"; |
134 | | |
135 | | case amdil: |
136 | | case amdil64: return "amdil"; |
137 | | |
138 | | case hsail: |
139 | | case hsail64: return "hsail"; |
140 | | |
141 | | case spir: |
142 | | case spir64: return "spir"; |
143 | | case kalimba: return "kalimba"; |
144 | | case lanai: return "lanai"; |
145 | | case shave: return "shave"; |
146 | | case wasm32: |
147 | | case wasm64: return "wasm"; |
148 | | |
149 | | case riscv32: |
150 | | case riscv64: return "riscv"; |
151 | | |
152 | | case ve: return "ve"; |
153 | | } |
154 | | } |
155 | | |
156 | 0 | StringRef Triple::getVendorTypeName(VendorType Kind) { |
157 | 0 | switch (Kind) { |
158 | 0 | case UnknownVendor: return "unknown"; |
159 | 0 |
|
160 | 0 | case AMD: return "amd"; |
161 | 0 | case Apple: return "apple"; |
162 | 0 | case BGP: return "bgp"; |
163 | 0 | case BGQ: return "bgq"; |
164 | 0 | case CSR: return "csr"; |
165 | 0 | case Freescale: return "fsl"; |
166 | 0 | case IBM: return "ibm"; |
167 | 0 | case ImaginationTechnologies: return "img"; |
168 | 0 | case Mesa: return "mesa"; |
169 | 0 | case MipsTechnologies: return "mti"; |
170 | 0 | case Myriad: return "myriad"; |
171 | 0 | case NVIDIA: return "nvidia"; |
172 | 0 | case OpenEmbedded: return "oe"; |
173 | 0 | case PC: return "pc"; |
174 | 0 | case SCEI: return "scei"; |
175 | 0 | case SUSE: return "suse"; |
176 | 0 | } |
177 | 0 | |
178 | 0 | llvm_unreachable("Invalid VendorType!"); |
179 | 0 | } |
180 | | |
181 | 0 | StringRef Triple::getOSTypeName(OSType Kind) { |
182 | 0 | switch (Kind) { |
183 | 0 | case UnknownOS: return "unknown"; |
184 | 0 |
|
185 | 0 | case AIX: return "aix"; |
186 | 0 | case AMDHSA: return "amdhsa"; |
187 | 0 | case AMDPAL: return "amdpal"; |
188 | 0 | case Ananas: return "ananas"; |
189 | 0 | case CNK: return "cnk"; |
190 | 0 | case CUDA: return "cuda"; |
191 | 0 | case CloudABI: return "cloudabi"; |
192 | 0 | case Contiki: return "contiki"; |
193 | 0 | case Darwin: return "darwin"; |
194 | 0 | case DragonFly: return "dragonfly"; |
195 | 0 | case ELFIAMCU: return "elfiamcu"; |
196 | 0 | case Emscripten: return "emscripten"; |
197 | 0 | case FreeBSD: return "freebsd"; |
198 | 0 | case Fuchsia: return "fuchsia"; |
199 | 0 | case Haiku: return "haiku"; |
200 | 0 | case HermitCore: return "hermit"; |
201 | 0 | case Hurd: return "hurd"; |
202 | 0 | case IOS: return "ios"; |
203 | 0 | case KFreeBSD: return "kfreebsd"; |
204 | 0 | case Linux: return "linux"; |
205 | 0 | case Lv2: return "lv2"; |
206 | 0 | case MacOSX: return "macosx"; |
207 | 0 | case Mesa3D: return "mesa3d"; |
208 | 0 | case Minix: return "minix"; |
209 | 0 | case NVCL: return "nvcl"; |
210 | 0 | case NaCl: return "nacl"; |
211 | 0 | case NetBSD: return "netbsd"; |
212 | 0 | case OpenBSD: return "openbsd"; |
213 | 0 | case PS4: return "ps4"; |
214 | 0 | case RTEMS: return "rtems"; |
215 | 0 | case Solaris: return "solaris"; |
216 | 0 | case TvOS: return "tvos"; |
217 | 0 | case WASI: return "wasi"; |
218 | 0 | case WatchOS: return "watchos"; |
219 | 0 | case Win32: return "windows"; |
220 | 0 | } |
221 | 0 | |
222 | 0 | llvm_unreachable("Invalid OSType"); |
223 | 0 | } |
224 | | |
225 | 0 | StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) { |
226 | 0 | switch (Kind) { |
227 | 0 | case UnknownEnvironment: return "unknown"; |
228 | 0 | case Android: return "android"; |
229 | 0 | case CODE16: return "code16"; |
230 | 0 | case CoreCLR: return "coreclr"; |
231 | 0 | case Cygnus: return "cygnus"; |
232 | 0 | case EABI: return "eabi"; |
233 | 0 | case EABIHF: return "eabihf"; |
234 | 0 | case GNU: return "gnu"; |
235 | 0 | case GNUABI64: return "gnuabi64"; |
236 | 0 | case GNUABIN32: return "gnuabin32"; |
237 | 0 | case GNUEABI: return "gnueabi"; |
238 | 0 | case GNUEABIHF: return "gnueabihf"; |
239 | 0 | case GNUX32: return "gnux32"; |
240 | 0 | case Itanium: return "itanium"; |
241 | 0 | case MSVC: return "msvc"; |
242 | 0 | case MacABI: return "macabi"; |
243 | 0 | case Musl: return "musl"; |
244 | 0 | case MuslEABI: return "musleabi"; |
245 | 0 | case MuslEABIHF: return "musleabihf"; |
246 | 0 | case Simulator: return "simulator"; |
247 | 0 | } |
248 | 0 | |
249 | 0 | llvm_unreachable("Invalid EnvironmentType!"); |
250 | 0 | } |
251 | | |
252 | 0 | static Triple::ArchType parseBPFArch(StringRef ArchName) { |
253 | 0 | if (ArchName.equals("bpf")) { |
254 | 0 | if (sys::IsLittleEndianHost) |
255 | 0 | return Triple::bpfel; |
256 | 0 | else |
257 | 0 | return Triple::bpfeb; |
258 | 0 | } else if (ArchName.equals("bpf_be") || ArchName.equals("bpfeb")) { |
259 | 0 | return Triple::bpfeb; |
260 | 0 | } else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) { |
261 | 0 | return Triple::bpfel; |
262 | 0 | } else { |
263 | 0 | return Triple::UnknownArch; |
264 | 0 | } |
265 | 0 | } |
266 | | |
267 | 0 | Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) { |
268 | 0 | Triple::ArchType BPFArch(parseBPFArch(Name)); |
269 | 0 | return StringSwitch<Triple::ArchType>(Name) |
270 | 0 | .Case("aarch64", aarch64) |
271 | 0 | .Case("aarch64_be", aarch64_be) |
272 | 0 | .Case("aarch64_32", aarch64_32) |
273 | 0 | .Case("arc", arc) |
274 | 0 | .Case("arm64", aarch64) // "arm64" is an alias for "aarch64" |
275 | 0 | .Case("arm64_32", aarch64_32) |
276 | 0 | .Case("arm", arm) |
277 | 0 | .Case("armeb", armeb) |
278 | 0 | .Case("avr", avr) |
279 | 0 | .StartsWith("bpf", BPFArch) |
280 | 0 | .Case("mips", mips) |
281 | 0 | .Case("mipsel", mipsel) |
282 | 0 | .Case("mips64", mips64) |
283 | 0 | .Case("mips64el", mips64el) |
284 | 0 | .Case("msp430", msp430) |
285 | 0 | .Case("ppc64", ppc64) |
286 | 0 | .Case("ppc32", ppc) |
287 | 0 | .Case("ppc", ppc) |
288 | 0 | .Case("ppc64le", ppc64le) |
289 | 0 | .Case("r600", r600) |
290 | 0 | .Case("amdgcn", amdgcn) |
291 | 0 | .Case("riscv32", riscv32) |
292 | 0 | .Case("riscv64", riscv64) |
293 | 0 | .Case("hexagon", hexagon) |
294 | 0 | .Case("sparc", sparc) |
295 | 0 | .Case("sparcel", sparcel) |
296 | 0 | .Case("sparcv9", sparcv9) |
297 | 0 | .Case("systemz", systemz) |
298 | 0 | .Case("tce", tce) |
299 | 0 | .Case("tcele", tcele) |
300 | 0 | .Case("thumb", thumb) |
301 | 0 | .Case("thumbeb", thumbeb) |
302 | 0 | .Case("x86", x86) |
303 | 0 | .Case("x86-64", x86_64) |
304 | 0 | .Case("xcore", xcore) |
305 | 0 | .Case("nvptx", nvptx) |
306 | 0 | .Case("nvptx64", nvptx64) |
307 | 0 | .Case("le32", le32) |
308 | 0 | .Case("le64", le64) |
309 | 0 | .Case("amdil", amdil) |
310 | 0 | .Case("amdil64", amdil64) |
311 | 0 | .Case("hsail", hsail) |
312 | 0 | .Case("hsail64", hsail64) |
313 | 0 | .Case("spir", spir) |
314 | 0 | .Case("spir64", spir64) |
315 | 0 | .Case("kalimba", kalimba) |
316 | 0 | .Case("lanai", lanai) |
317 | 0 | .Case("shave", shave) |
318 | 0 | .Case("wasm32", wasm32) |
319 | 0 | .Case("wasm64", wasm64) |
320 | 0 | .Case("renderscript32", renderscript32) |
321 | 0 | .Case("renderscript64", renderscript64) |
322 | 0 | .Case("ve", ve) |
323 | 0 | .Default(UnknownArch); |
324 | 0 | } |
325 | | |
326 | 0 | static Triple::ArchType parseARMArch(StringRef ArchName) { |
327 | 0 | ARM::ISAKind ISA = ARM::parseArchISA(ArchName); |
328 | 0 | ARM::EndianKind ENDIAN = ARM::parseArchEndian(ArchName); |
329 | 0 |
|
330 | 0 | Triple::ArchType arch = Triple::UnknownArch; |
331 | 0 | switch (ENDIAN) { |
332 | 0 | case ARM::EndianKind::LITTLE: { |
333 | 0 | switch (ISA) { |
334 | 0 | case ARM::ISAKind::ARM: |
335 | 0 | arch = Triple::arm; |
336 | 0 | break; |
337 | 0 | case ARM::ISAKind::THUMB: |
338 | 0 | arch = Triple::thumb; |
339 | 0 | break; |
340 | 0 | case ARM::ISAKind::AARCH64: |
341 | 0 | arch = Triple::aarch64; |
342 | 0 | break; |
343 | 0 | case ARM::ISAKind::INVALID: |
344 | 0 | break; |
345 | 0 | } |
346 | 0 | break; |
347 | 0 | } |
348 | 0 | case ARM::EndianKind::BIG: { |
349 | 0 | switch (ISA) { |
350 | 0 | case ARM::ISAKind::ARM: |
351 | 0 | arch = Triple::armeb; |
352 | 0 | break; |
353 | 0 | case ARM::ISAKind::THUMB: |
354 | 0 | arch = Triple::thumbeb; |
355 | 0 | break; |
356 | 0 | case ARM::ISAKind::AARCH64: |
357 | 0 | arch = Triple::aarch64_be; |
358 | 0 | break; |
359 | 0 | case ARM::ISAKind::INVALID: |
360 | 0 | break; |
361 | 0 | } |
362 | 0 | break; |
363 | 0 | } |
364 | 0 | case ARM::EndianKind::INVALID: { |
365 | 0 | break; |
366 | 0 | } |
367 | 0 | } |
368 | 0 | |
369 | 0 | ArchName = ARM::getCanonicalArchName(ArchName); |
370 | 0 | if (ArchName.empty()) |
371 | 0 | return Triple::UnknownArch; |
372 | 0 | |
373 | 0 | // Thumb only exists in v4+ |
374 | 0 | if (ISA == ARM::ISAKind::THUMB && |
375 | 0 | (ArchName.startswith("v2") || ArchName.startswith("v3"))) |
376 | 0 | return Triple::UnknownArch; |
377 | 0 | |
378 | 0 | // Thumb only for v6m |
379 | 0 | ARM::ProfileKind Profile = ARM::parseArchProfile(ArchName); |
380 | 0 | unsigned Version = ARM::parseArchVersion(ArchName); |
381 | 0 | if (Profile == ARM::ProfileKind::M && Version == 6) { |
382 | 0 | if (ENDIAN == ARM::EndianKind::BIG) |
383 | 0 | return Triple::thumbeb; |
384 | 0 | else |
385 | 0 | return Triple::thumb; |
386 | 0 | } |
387 | 0 | |
388 | 0 | return arch; |
389 | 0 | } |
390 | | |
391 | 8 | static Triple::ArchType parseArch(StringRef ArchName) { |
392 | 8 | auto AT = StringSwitch<Triple::ArchType>(ArchName) |
393 | 8 | .Cases("i386", "i486", "i586", "i686", Triple::x86) |
394 | 8 | // FIXME: Do we need to support these? |
395 | 8 | .Cases("i786", "i886", "i986", Triple::x86) |
396 | 8 | .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64) |
397 | 8 | .Cases("powerpc", "powerpcspe", "ppc", "ppc32", Triple::ppc) |
398 | 8 | .Cases("powerpc64", "ppu", "ppc64", Triple::ppc64) |
399 | 8 | .Cases("powerpc64le", "ppc64le", Triple::ppc64le) |
400 | 8 | .Case("xscale", Triple::arm) |
401 | 8 | .Case("xscaleeb", Triple::armeb) |
402 | 8 | .Case("aarch64", Triple::aarch64) |
403 | 8 | .Case("aarch64_be", Triple::aarch64_be) |
404 | 8 | .Case("aarch64_32", Triple::aarch64_32) |
405 | 8 | .Case("arc", Triple::arc) |
406 | 8 | .Case("arm64", Triple::aarch64) |
407 | 8 | .Case("arm64_32", Triple::aarch64_32) |
408 | 8 | .Case("arm", Triple::arm) |
409 | 8 | .Case("armeb", Triple::armeb) |
410 | 8 | .Case("thumb", Triple::thumb) |
411 | 8 | .Case("thumbeb", Triple::thumbeb) |
412 | 8 | .Case("avr", Triple::avr) |
413 | 8 | .Case("msp430", Triple::msp430) |
414 | 8 | .Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6", |
415 | 8 | "mipsr6", Triple::mips) |
416 | 8 | .Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el", |
417 | 8 | Triple::mipsel) |
418 | 8 | .Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6", |
419 | 8 | "mips64r6", "mipsn32r6", Triple::mips64) |
420 | 8 | .Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el", |
421 | 8 | "mipsn32r6el", Triple::mips64el) |
422 | 8 | .Case("r600", Triple::r600) |
423 | 8 | .Case("amdgcn", Triple::amdgcn) |
424 | 8 | .Case("riscv32", Triple::riscv32) |
425 | 8 | .Case("riscv64", Triple::riscv64) |
426 | 8 | .Case("hexagon", Triple::hexagon) |
427 | 8 | .Cases("s390x", "systemz", Triple::systemz) |
428 | 8 | .Case("sparc", Triple::sparc) |
429 | 8 | .Case("sparcel", Triple::sparcel) |
430 | 8 | .Cases("sparcv9", "sparc64", Triple::sparcv9) |
431 | 8 | .Case("tce", Triple::tce) |
432 | 8 | .Case("tcele", Triple::tcele) |
433 | 8 | .Case("xcore", Triple::xcore) |
434 | 8 | .Case("nvptx", Triple::nvptx) |
435 | 8 | .Case("nvptx64", Triple::nvptx64) |
436 | 8 | .Case("le32", Triple::le32) |
437 | 8 | .Case("le64", Triple::le64) |
438 | 8 | .Case("amdil", Triple::amdil) |
439 | 8 | .Case("amdil64", Triple::amdil64) |
440 | 8 | .Case("hsail", Triple::hsail) |
441 | 8 | .Case("hsail64", Triple::hsail64) |
442 | 8 | .Case("spir", Triple::spir) |
443 | 8 | .Case("spir64", Triple::spir64) |
444 | 8 | .StartsWith("kalimba", Triple::kalimba) |
445 | 8 | .Case("lanai", Triple::lanai) |
446 | 8 | .Case("renderscript32", Triple::renderscript32) |
447 | 8 | .Case("renderscript64", Triple::renderscript64) |
448 | 8 | .Case("shave", Triple::shave) |
449 | 8 | .Case("ve", Triple::ve) |
450 | 8 | .Case("wasm32", Triple::wasm32) |
451 | 8 | .Case("wasm64", Triple::wasm64) |
452 | 8 | .Default(Triple::UnknownArch); |
453 | 8 | |
454 | 8 | // Some architectures require special parsing logic just to compute the |
455 | 8 | // ArchType result. |
456 | 8 | if (AT == Triple::UnknownArch) { |
457 | 0 | if (ArchName.startswith("arm") || ArchName.startswith("thumb") || |
458 | 0 | ArchName.startswith("aarch64")) |
459 | 0 | return parseARMArch(ArchName); |
460 | 0 | if (ArchName.startswith("bpf")) |
461 | 0 | return parseBPFArch(ArchName); |
462 | 8 | } |
463 | 8 | |
464 | 8 | return AT; |
465 | 8 | } |
466 | | |
467 | 10 | static Triple::VendorType parseVendor(StringRef VendorName) { |
468 | 10 | return StringSwitch<Triple::VendorType>(VendorName) |
469 | 10 | .Case("apple", Triple::Apple) |
470 | 10 | .Case("pc", Triple::PC) |
471 | 10 | .Case("scei", Triple::SCEI) |
472 | 10 | .Case("bgp", Triple::BGP) |
473 | 10 | .Case("bgq", Triple::BGQ) |
474 | 10 | .Case("fsl", Triple::Freescale) |
475 | 10 | .Case("ibm", Triple::IBM) |
476 | 10 | .Case("img", Triple::ImaginationTechnologies) |
477 | 10 | .Case("mti", Triple::MipsTechnologies) |
478 | 10 | .Case("nvidia", Triple::NVIDIA) |
479 | 10 | .Case("csr", Triple::CSR) |
480 | 10 | .Case("myriad", Triple::Myriad) |
481 | 10 | .Case("amd", Triple::AMD) |
482 | 10 | .Case("mesa", Triple::Mesa) |
483 | 10 | .Case("suse", Triple::SUSE) |
484 | 10 | .Case("oe", Triple::OpenEmbedded) |
485 | 10 | .Default(Triple::UnknownVendor); |
486 | 10 | } |
487 | | |
488 | 8 | static Triple::OSType parseOS(StringRef OSName) { |
489 | 8 | return StringSwitch<Triple::OSType>(OSName) |
490 | 8 | .StartsWith("ananas", Triple::Ananas) |
491 | 8 | .StartsWith("cloudabi", Triple::CloudABI) |
492 | 8 | .StartsWith("darwin", Triple::Darwin) |
493 | 8 | .StartsWith("dragonfly", Triple::DragonFly) |
494 | 8 | .StartsWith("freebsd", Triple::FreeBSD) |
495 | 8 | .StartsWith("fuchsia", Triple::Fuchsia) |
496 | 8 | .StartsWith("ios", Triple::IOS) |
497 | 8 | .StartsWith("kfreebsd", Triple::KFreeBSD) |
498 | 8 | .StartsWith("linux", Triple::Linux) |
499 | 8 | .StartsWith("lv2", Triple::Lv2) |
500 | 8 | .StartsWith("macos", Triple::MacOSX) |
501 | 8 | .StartsWith("netbsd", Triple::NetBSD) |
502 | 8 | .StartsWith("openbsd", Triple::OpenBSD) |
503 | 8 | .StartsWith("solaris", Triple::Solaris) |
504 | 8 | .StartsWith("win32", Triple::Win32) |
505 | 8 | .StartsWith("windows", Triple::Win32) |
506 | 8 | .StartsWith("haiku", Triple::Haiku) |
507 | 8 | .StartsWith("minix", Triple::Minix) |
508 | 8 | .StartsWith("rtems", Triple::RTEMS) |
509 | 8 | .StartsWith("nacl", Triple::NaCl) |
510 | 8 | .StartsWith("cnk", Triple::CNK) |
511 | 8 | .StartsWith("aix", Triple::AIX) |
512 | 8 | .StartsWith("cuda", Triple::CUDA) |
513 | 8 | .StartsWith("nvcl", Triple::NVCL) |
514 | 8 | .StartsWith("amdhsa", Triple::AMDHSA) |
515 | 8 | .StartsWith("ps4", Triple::PS4) |
516 | 8 | .StartsWith("elfiamcu", Triple::ELFIAMCU) |
517 | 8 | .StartsWith("tvos", Triple::TvOS) |
518 | 8 | .StartsWith("watchos", Triple::WatchOS) |
519 | 8 | .StartsWith("mesa3d", Triple::Mesa3D) |
520 | 8 | .StartsWith("contiki", Triple::Contiki) |
521 | 8 | .StartsWith("amdpal", Triple::AMDPAL) |
522 | 8 | .StartsWith("hermit", Triple::HermitCore) |
523 | 8 | .StartsWith("hurd", Triple::Hurd) |
524 | 8 | .StartsWith("wasi", Triple::WASI) |
525 | 8 | .StartsWith("emscripten", Triple::Emscripten) |
526 | 8 | .Default(Triple::UnknownOS); |
527 | 8 | } |
528 | | |
529 | 8 | static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { |
530 | 8 | return StringSwitch<Triple::EnvironmentType>(EnvironmentName) |
531 | 8 | .StartsWith("eabihf", Triple::EABIHF) |
532 | 8 | .StartsWith("eabi", Triple::EABI) |
533 | 8 | .StartsWith("gnuabin32", Triple::GNUABIN32) |
534 | 8 | .StartsWith("gnuabi64", Triple::GNUABI64) |
535 | 8 | .StartsWith("gnueabihf", Triple::GNUEABIHF) |
536 | 8 | .StartsWith("gnueabi", Triple::GNUEABI) |
537 | 8 | .StartsWith("gnux32", Triple::GNUX32) |
538 | 8 | .StartsWith("code16", Triple::CODE16) |
539 | 8 | .StartsWith("gnu", Triple::GNU) |
540 | 8 | .StartsWith("android", Triple::Android) |
541 | 8 | .StartsWith("musleabihf", Triple::MuslEABIHF) |
542 | 8 | .StartsWith("musleabi", Triple::MuslEABI) |
543 | 8 | .StartsWith("musl", Triple::Musl) |
544 | 8 | .StartsWith("msvc", Triple::MSVC) |
545 | 8 | .StartsWith("itanium", Triple::Itanium) |
546 | 8 | .StartsWith("cygnus", Triple::Cygnus) |
547 | 8 | .StartsWith("coreclr", Triple::CoreCLR) |
548 | 8 | .StartsWith("simulator", Triple::Simulator) |
549 | 8 | .StartsWith("macabi", Triple::MacABI) |
550 | 8 | .Default(Triple::UnknownEnvironment); |
551 | 8 | } |
552 | | |
553 | 6 | static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) { |
554 | 6 | return StringSwitch<Triple::ObjectFormatType>(EnvironmentName) |
555 | 6 | // "xcoff" must come before "coff" because of the order-dependendent |
556 | 6 | // pattern matching. |
557 | 6 | .EndsWith("xcoff", Triple::XCOFF) |
558 | 6 | .EndsWith("coff", Triple::COFF) |
559 | 6 | .EndsWith("elf", Triple::ELF) |
560 | 6 | .EndsWith("macho", Triple::MachO) |
561 | 6 | .EndsWith("wasm", Triple::Wasm) |
562 | 6 | .Default(Triple::UnknownObjectFormat); |
563 | 6 | } |
564 | | |
565 | 6 | static Triple::SubArchType parseSubArch(StringRef SubArchName) { |
566 | 6 | if (SubArchName.startswith("mips") && |
567 | 6 | (SubArchName.endswith("r6el") || SubArchName.endswith("r6"))) |
568 | 0 | return Triple::MipsSubArch_r6; |
569 | 6 | |
570 | 6 | if (SubArchName == "powerpcspe") |
571 | 0 | return Triple::PPCSubArch_spe; |
572 | 6 | |
573 | 6 | StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName); |
574 | 6 | |
575 | 6 | // For now, this is the small part. Early return. |
576 | 6 | if (ARMSubArch.empty()) |
577 | 0 | return StringSwitch<Triple::SubArchType>(SubArchName) |
578 | 0 | .EndsWith("kalimba3", Triple::KalimbaSubArch_v3) |
579 | 0 | .EndsWith("kalimba4", Triple::KalimbaSubArch_v4) |
580 | 0 | .EndsWith("kalimba5", Triple::KalimbaSubArch_v5) |
581 | 0 | .Default(Triple::NoSubArch); |
582 | 6 | |
583 | 6 | // ARM sub arch. |
584 | 6 | switch(ARM::parseArch(ARMSubArch)) { |
585 | 6 | case ARM::ArchKind::ARMV4: |
586 | 0 | return Triple::NoSubArch; |
587 | 6 | case ARM::ArchKind::ARMV4T: |
588 | 0 | return Triple::ARMSubArch_v4t; |
589 | 6 | case ARM::ArchKind::ARMV5T: |
590 | 0 | return Triple::ARMSubArch_v5; |
591 | 6 | case ARM::ArchKind::ARMV5TE: |
592 | 0 | case ARM::ArchKind::IWMMXT: |
593 | 0 | case ARM::ArchKind::IWMMXT2: |
594 | 0 | case ARM::ArchKind::XSCALE: |
595 | 0 | case ARM::ArchKind::ARMV5TEJ: |
596 | 0 | return Triple::ARMSubArch_v5te; |
597 | 0 | case ARM::ArchKind::ARMV6: |
598 | 0 | return Triple::ARMSubArch_v6; |
599 | 0 | case ARM::ArchKind::ARMV6K: |
600 | 0 | case ARM::ArchKind::ARMV6KZ: |
601 | 0 | return Triple::ARMSubArch_v6k; |
602 | 0 | case ARM::ArchKind::ARMV6T2: |
603 | 0 | return Triple::ARMSubArch_v6t2; |
604 | 0 | case ARM::ArchKind::ARMV6M: |
605 | 0 | return Triple::ARMSubArch_v6m; |
606 | 0 | case ARM::ArchKind::ARMV7A: |
607 | 0 | case ARM::ArchKind::ARMV7R: |
608 | 0 | return Triple::ARMSubArch_v7; |
609 | 0 | case ARM::ArchKind::ARMV7VE: |
610 | 0 | return Triple::ARMSubArch_v7ve; |
611 | 0 | case ARM::ArchKind::ARMV7K: |
612 | 0 | return Triple::ARMSubArch_v7k; |
613 | 0 | case ARM::ArchKind::ARMV7M: |
614 | 0 | return Triple::ARMSubArch_v7m; |
615 | 0 | case ARM::ArchKind::ARMV7S: |
616 | 0 | return Triple::ARMSubArch_v7s; |
617 | 0 | case ARM::ArchKind::ARMV7EM: |
618 | 0 | return Triple::ARMSubArch_v7em; |
619 | 0 | case ARM::ArchKind::ARMV8A: |
620 | 0 | return Triple::ARMSubArch_v8; |
621 | 0 | case ARM::ArchKind::ARMV8_1A: |
622 | 0 | return Triple::ARMSubArch_v8_1a; |
623 | 0 | case ARM::ArchKind::ARMV8_2A: |
624 | 0 | return Triple::ARMSubArch_v8_2a; |
625 | 0 | case ARM::ArchKind::ARMV8_3A: |
626 | 0 | return Triple::ARMSubArch_v8_3a; |
627 | 0 | case ARM::ArchKind::ARMV8_4A: |
628 | 0 | return Triple::ARMSubArch_v8_4a; |
629 | 0 | case ARM::ArchKind::ARMV8_5A: |
630 | 0 | return Triple::ARMSubArch_v8_5a; |
631 | 0 | case ARM::ArchKind::ARMV8_6A: |
632 | 0 | return Triple::ARMSubArch_v8_6a; |
633 | 0 | case ARM::ArchKind::ARMV8R: |
634 | 0 | return Triple::ARMSubArch_v8r; |
635 | 0 | case ARM::ArchKind::ARMV8MBaseline: |
636 | 0 | return Triple::ARMSubArch_v8m_baseline; |
637 | 0 | case ARM::ArchKind::ARMV8MMainline: |
638 | 0 | return Triple::ARMSubArch_v8m_mainline; |
639 | 0 | case ARM::ArchKind::ARMV8_1MMainline: |
640 | 0 | return Triple::ARMSubArch_v8_1m_mainline; |
641 | 6 | default: |
642 | 6 | return Triple::NoSubArch; |
643 | 6 | } |
644 | 6 | } |
645 | | |
646 | 0 | static StringRef getObjectFormatTypeName(Triple::ObjectFormatType Kind) { |
647 | 0 | switch (Kind) { |
648 | 0 | case Triple::UnknownObjectFormat: return ""; |
649 | 0 | case Triple::COFF: return "coff"; |
650 | 0 | case Triple::ELF: return "elf"; |
651 | 0 | case Triple::MachO: return "macho"; |
652 | 0 | case Triple::Wasm: return "wasm"; |
653 | 0 | case Triple::XCOFF: return "xcoff"; |
654 | 0 | } |
655 | 0 | llvm_unreachable("unknown object format type"); |
656 | 0 | } |
657 | | |
658 | 6 | static Triple::ObjectFormatType getDefaultFormat(const Triple &T) { |
659 | 6 | switch (T.getArch()) { |
660 | 6 | case Triple::UnknownArch: |
661 | 6 | case Triple::aarch64: |
662 | 6 | case Triple::aarch64_32: |
663 | 6 | case Triple::arm: |
664 | 6 | case Triple::thumb: |
665 | 6 | case Triple::x86: |
666 | 6 | case Triple::x86_64: |
667 | 6 | if (T.isOSDarwin()) |
668 | 0 | return Triple::MachO; |
669 | 6 | else if (T.isOSWindows()) |
670 | 0 | return Triple::COFF; |
671 | 6 | return Triple::ELF; |
672 | 6 | |
673 | 6 | case Triple::aarch64_be: |
674 | 0 | case Triple::amdgcn: |
675 | 0 | case Triple::amdil64: |
676 | 0 | case Triple::amdil: |
677 | 0 | case Triple::arc: |
678 | 0 | case Triple::armeb: |
679 | 0 | case Triple::avr: |
680 | 0 | case Triple::bpfeb: |
681 | 0 | case Triple::bpfel: |
682 | 0 | case Triple::hexagon: |
683 | 0 | case Triple::hsail64: |
684 | 0 | case Triple::hsail: |
685 | 0 | case Triple::kalimba: |
686 | 0 | case Triple::lanai: |
687 | 0 | case Triple::le32: |
688 | 0 | case Triple::le64: |
689 | 0 | case Triple::mips64: |
690 | 0 | case Triple::mips64el: |
691 | 0 | case Triple::mips: |
692 | 0 | case Triple::mipsel: |
693 | 0 | case Triple::msp430: |
694 | 0 | case Triple::nvptx64: |
695 | 0 | case Triple::nvptx: |
696 | 0 | case Triple::ppc64le: |
697 | 0 | case Triple::r600: |
698 | 0 | case Triple::renderscript32: |
699 | 0 | case Triple::renderscript64: |
700 | 0 | case Triple::riscv32: |
701 | 0 | case Triple::riscv64: |
702 | 0 | case Triple::shave: |
703 | 0 | case Triple::sparc: |
704 | 0 | case Triple::sparcel: |
705 | 0 | case Triple::sparcv9: |
706 | 0 | case Triple::spir64: |
707 | 0 | case Triple::spir: |
708 | 0 | case Triple::systemz: |
709 | 0 | case Triple::tce: |
710 | 0 | case Triple::tcele: |
711 | 0 | case Triple::thumbeb: |
712 | 0 | case Triple::ve: |
713 | 0 | case Triple::xcore: |
714 | 0 | return Triple::ELF; |
715 | 0 |
|
716 | 0 | case Triple::ppc64: |
717 | 0 | case Triple::ppc: |
718 | 0 | if (T.isOSAIX()) |
719 | 0 | return Triple::XCOFF; |
720 | 0 | return Triple::ELF; |
721 | 0 |
|
722 | 0 | case Triple::wasm32: |
723 | 0 | case Triple::wasm64: |
724 | 0 | return Triple::Wasm; |
725 | 0 | } |
726 | 0 | llvm_unreachable("unknown architecture"); |
727 | 0 | } |
728 | | |
729 | | /// Construct a triple from the string representation provided. |
730 | | /// |
731 | | /// This stores the string representation and parses the various pieces into |
732 | | /// enum members. |
733 | | Triple::Triple(const Twine &Str) |
734 | | : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch), |
735 | | Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment), |
736 | 6 | ObjectFormat(UnknownObjectFormat) { |
737 | 6 | // Do minimal parsing by hand here. |
738 | 6 | SmallVector<StringRef, 4> Components; |
739 | 6 | StringRef(Data).split(Components, '-', /*MaxSplit*/ 3); |
740 | 6 | if (Components.size() > 0) { |
741 | 6 | Arch = parseArch(Components[0]); |
742 | 6 | SubArch = parseSubArch(Components[0]); |
743 | 6 | if (Components.size() > 1) { |
744 | 6 | Vendor = parseVendor(Components[1]); |
745 | 6 | if (Components.size() > 2) { |
746 | 6 | OS = parseOS(Components[2]); |
747 | 6 | if (Components.size() > 3) { |
748 | 6 | Environment = parseEnvironment(Components[3]); |
749 | 6 | ObjectFormat = parseFormat(Components[3]); |
750 | 6 | } |
751 | 6 | } |
752 | 6 | } else { |
753 | 0 | Environment = |
754 | 0 | StringSwitch<Triple::EnvironmentType>(Components[0]) |
755 | 0 | .StartsWith("mipsn32", Triple::GNUABIN32) |
756 | 0 | .StartsWith("mips64", Triple::GNUABI64) |
757 | 0 | .StartsWith("mipsisa64", Triple::GNUABI64) |
758 | 0 | .StartsWith("mipsisa32", Triple::GNU) |
759 | 0 | .Cases("mips", "mipsel", "mipsr6", "mipsr6el", Triple::GNU) |
760 | 0 | .Default(UnknownEnvironment); |
761 | 0 | } |
762 | 6 | } |
763 | 6 | if (ObjectFormat == UnknownObjectFormat) |
764 | 6 | ObjectFormat = getDefaultFormat(*this); |
765 | 6 | } |
766 | | |
767 | | /// Construct a triple from string representations of the architecture, |
768 | | /// vendor, and OS. |
769 | | /// |
770 | | /// This joins each argument into a canonical string representation and parses |
771 | | /// them into enum members. It leaves the environment unknown and omits it from |
772 | | /// the string representation. |
773 | | Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr) |
774 | | : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()), |
775 | | Arch(parseArch(ArchStr.str())), |
776 | | SubArch(parseSubArch(ArchStr.str())), |
777 | | Vendor(parseVendor(VendorStr.str())), |
778 | | OS(parseOS(OSStr.str())), |
779 | 0 | Environment(), ObjectFormat(Triple::UnknownObjectFormat) { |
780 | 0 | ObjectFormat = getDefaultFormat(*this); |
781 | 0 | } |
782 | | |
783 | | /// Construct a triple from string representations of the architecture, |
784 | | /// vendor, OS, and environment. |
785 | | /// |
786 | | /// This joins each argument into a canonical string representation and parses |
787 | | /// them into enum members. |
788 | | Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr, |
789 | | const Twine &EnvironmentStr) |
790 | | : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') + |
791 | | EnvironmentStr).str()), |
792 | | Arch(parseArch(ArchStr.str())), |
793 | | SubArch(parseSubArch(ArchStr.str())), |
794 | | Vendor(parseVendor(VendorStr.str())), |
795 | | OS(parseOS(OSStr.str())), |
796 | | Environment(parseEnvironment(EnvironmentStr.str())), |
797 | 0 | ObjectFormat(parseFormat(EnvironmentStr.str())) { |
798 | 0 | if (ObjectFormat == Triple::UnknownObjectFormat) |
799 | 0 | ObjectFormat = getDefaultFormat(*this); |
800 | 0 | } |
801 | | |
802 | 2 | std::string Triple::normalize(StringRef Str) { |
803 | 2 | bool IsMinGW32 = false; |
804 | 2 | bool IsCygwin = false; |
805 | 2 | |
806 | 2 | // Parse into components. |
807 | 2 | SmallVector<StringRef, 4> Components; |
808 | 2 | Str.split(Components, '-'); |
809 | 2 | |
810 | 2 | // If the first component corresponds to a known architecture, preferentially |
811 | 2 | // use it for the architecture. If the second component corresponds to a |
812 | 2 | // known vendor, preferentially use it for the vendor, etc. This avoids silly |
813 | 2 | // component movement when a component parses as (eg) both a valid arch and a |
814 | 2 | // valid os. |
815 | 2 | ArchType Arch = UnknownArch; |
816 | 2 | if (Components.size() > 0) |
817 | 2 | Arch = parseArch(Components[0]); |
818 | 2 | VendorType Vendor = UnknownVendor; |
819 | 2 | if (Components.size() > 1) |
820 | 2 | Vendor = parseVendor(Components[1]); |
821 | 2 | OSType OS = UnknownOS; |
822 | 2 | if (Components.size() > 2) { |
823 | 2 | OS = parseOS(Components[2]); |
824 | 2 | IsCygwin = Components[2].startswith("cygwin"); |
825 | 2 | IsMinGW32 = Components[2].startswith("mingw"); |
826 | 2 | } |
827 | 2 | EnvironmentType Environment = UnknownEnvironment; |
828 | 2 | if (Components.size() > 3) |
829 | 2 | Environment = parseEnvironment(Components[3]); |
830 | 2 | ObjectFormatType ObjectFormat = UnknownObjectFormat; |
831 | 2 | if (Components.size() > 4) |
832 | 0 | ObjectFormat = parseFormat(Components[4]); |
833 | 2 | |
834 | 2 | // Note which components are already in their final position. These will not |
835 | 2 | // be moved. |
836 | 2 | bool Found[4]; |
837 | 2 | Found[0] = Arch != UnknownArch; |
838 | 2 | Found[1] = Vendor != UnknownVendor; |
839 | 2 | Found[2] = OS != UnknownOS; |
840 | 2 | Found[3] = Environment != UnknownEnvironment; |
841 | 2 | |
842 | 2 | // If they are not there already, permute the components into their canonical |
843 | 2 | // positions by seeing if they parse as a valid architecture, and if so moving |
844 | 2 | // the component to the architecture position etc. |
845 | 10 | for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) { |
846 | 8 | if (Found[Pos]) |
847 | 6 | continue; // Already in the canonical position. |
848 | 2 | |
849 | 10 | for (unsigned Idx = 0; Idx != Components.size(); ++Idx) { |
850 | 8 | // Do not reparse any components that already matched. |
851 | 8 | if (Idx < array_lengthof(Found) && Found[Idx]) |
852 | 6 | continue; |
853 | 2 | |
854 | 2 | // Does this component parse as valid for the target position? |
855 | 2 | bool Valid = false; |
856 | 2 | StringRef Comp = Components[Idx]; |
857 | 2 | switch (Pos) { |
858 | 2 | default: llvm_unreachable("unexpected component type!"); |
859 | 2 | case 0: |
860 | 0 | Arch = parseArch(Comp); |
861 | 0 | Valid = Arch != UnknownArch; |
862 | 0 | break; |
863 | 2 | case 1: |
864 | 2 | Vendor = parseVendor(Comp); |
865 | 2 | Valid = Vendor != UnknownVendor; |
866 | 2 | break; |
867 | 2 | case 2: |
868 | 0 | OS = parseOS(Comp); |
869 | 0 | IsCygwin = Comp.startswith("cygwin"); |
870 | 0 | IsMinGW32 = Comp.startswith("mingw"); |
871 | 0 | Valid = OS != UnknownOS || IsCygwin || IsMinGW32; |
872 | 0 | break; |
873 | 2 | case 3: |
874 | 0 | Environment = parseEnvironment(Comp); |
875 | 0 | Valid = Environment != UnknownEnvironment; |
876 | 0 | if (!Valid) { |
877 | 0 | ObjectFormat = parseFormat(Comp); |
878 | 0 | Valid = ObjectFormat != UnknownObjectFormat; |
879 | 0 | } |
880 | 0 | break; |
881 | 2 | } |
882 | 2 | if (!Valid) |
883 | 2 | continue; // Nope, try the next component. |
884 | 0 | |
885 | 0 | // Move the component to the target position, pushing any non-fixed |
886 | 0 | // components that are in the way to the right. This tends to give |
887 | 0 | // good results in the common cases of a forgotten vendor component |
888 | 0 | // or a wrongly positioned environment. |
889 | 0 | if (Pos < Idx) { |
890 | 0 | // Insert left, pushing the existing components to the right. For |
891 | 0 | // example, a-b-i386 -> i386-a-b when moving i386 to the front. |
892 | 0 | StringRef CurrentComponent(""); // The empty component. |
893 | 0 | // Replace the component we are moving with an empty component. |
894 | 0 | std::swap(CurrentComponent, Components[Idx]); |
895 | 0 | // Insert the component being moved at Pos, displacing any existing |
896 | 0 | // components to the right. |
897 | 0 | for (unsigned i = Pos; !CurrentComponent.empty(); ++i) { |
898 | 0 | // Skip over any fixed components. |
899 | 0 | while (i < array_lengthof(Found) && Found[i]) |
900 | 0 | ++i; |
901 | 0 | // Place the component at the new position, getting the component |
902 | 0 | // that was at this position - it will be moved right. |
903 | 0 | std::swap(CurrentComponent, Components[i]); |
904 | 0 | } |
905 | 0 | } else if (Pos > Idx) { |
906 | 0 | // Push right by inserting empty components until the component at Idx |
907 | 0 | // reaches the target position Pos. For example, pc-a -> -pc-a when |
908 | 0 | // moving pc to the second position. |
909 | 0 | do { |
910 | 0 | // Insert one empty component at Idx. |
911 | 0 | StringRef CurrentComponent(""); // The empty component. |
912 | 0 | for (unsigned i = Idx; i < Components.size();) { |
913 | 0 | // Place the component at the new position, getting the component |
914 | 0 | // that was at this position - it will be moved right. |
915 | 0 | std::swap(CurrentComponent, Components[i]); |
916 | 0 | // If it was placed on top of an empty component then we are done. |
917 | 0 | if (CurrentComponent.empty()) |
918 | 0 | break; |
919 | 0 | // Advance to the next component, skipping any fixed components. |
920 | 0 | while (++i < array_lengthof(Found) && Found[i]) |
921 | 0 | ; |
922 | 0 | } |
923 | 0 | // The last component was pushed off the end - append it. |
924 | 0 | if (!CurrentComponent.empty()) |
925 | 0 | Components.push_back(CurrentComponent); |
926 | 0 |
|
927 | 0 | // Advance Idx to the component's new position. |
928 | 0 | while (++Idx < array_lengthof(Found) && Found[Idx]) |
929 | 0 | ; |
930 | 0 | } while (Idx < Pos); // Add more until the final position is reached. |
931 | 0 | } |
932 | 0 | assert(Pos < Components.size() && Components[Pos] == Comp && |
933 | 0 | "Component moved wrong!"); |
934 | 0 | Found[Pos] = true; |
935 | 0 | break; |
936 | 0 | } |
937 | 2 | } |
938 | 2 | |
939 | 2 | // Replace empty components with "unknown" value. |
940 | 10 | for (unsigned i = 0, e = Components.size(); i < e; ++i) { |
941 | 8 | if (Components[i].empty()) |
942 | 0 | Components[i] = "unknown"; |
943 | 8 | } |
944 | 2 | |
945 | 2 | // Special case logic goes here. At this point Arch, Vendor and OS have the |
946 | 2 | // correct values for the computed components. |
947 | 2 | std::string NormalizedEnvironment; |
948 | 2 | if (Environment == Triple::Android && Components[3].startswith("androideabi")) { |
949 | 0 | StringRef AndroidVersion = Components[3].drop_front(strlen("androideabi")); |
950 | 0 | if (AndroidVersion.empty()) { |
951 | 0 | Components[3] = "android"; |
952 | 0 | } else { |
953 | 0 | NormalizedEnvironment = Twine("android", AndroidVersion).str(); |
954 | 0 | Components[3] = NormalizedEnvironment; |
955 | 0 | } |
956 | 0 | } |
957 | 2 | |
958 | 2 | // SUSE uses "gnueabi" to mean "gnueabihf" |
959 | 2 | if (Vendor == Triple::SUSE && Environment == llvm::Triple::GNUEABI) |
960 | 0 | Components[3] = "gnueabihf"; |
961 | 2 | |
962 | 2 | if (OS == Triple::Win32) { |
963 | 0 | Components.resize(4); |
964 | 0 | Components[2] = "windows"; |
965 | 0 | if (Environment == UnknownEnvironment) { |
966 | 0 | if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF) |
967 | 0 | Components[3] = "msvc"; |
968 | 0 | else |
969 | 0 | Components[3] = getObjectFormatTypeName(ObjectFormat); |
970 | 0 | } |
971 | 2 | } else if (IsMinGW32) { |
972 | 0 | Components.resize(4); |
973 | 0 | Components[2] = "windows"; |
974 | 0 | Components[3] = "gnu"; |
975 | 2 | } else if (IsCygwin) { |
976 | 0 | Components.resize(4); |
977 | 0 | Components[2] = "windows"; |
978 | 0 | Components[3] = "cygnus"; |
979 | 0 | } |
980 | 2 | if (IsMinGW32 || IsCygwin || |
981 | 2 | (OS == Triple::Win32 && Environment != UnknownEnvironment)) { |
982 | 0 | if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) { |
983 | 0 | Components.resize(5); |
984 | 0 | Components[4] = getObjectFormatTypeName(ObjectFormat); |
985 | 0 | } |
986 | 0 | } |
987 | 2 | |
988 | 2 | // Stick the corrected components back together to form the normalized string. |
989 | 2 | return join(Components, "-"); |
990 | 2 | } |
991 | | |
992 | 0 | StringRef Triple::getArchName() const { |
993 | 0 | return StringRef(Data).split('-').first; // Isolate first component |
994 | 0 | } |
995 | | |
996 | 0 | StringRef Triple::getVendorName() const { |
997 | 0 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
998 | 0 | return Tmp.split('-').first; // Isolate second component |
999 | 0 | } |
1000 | | |
1001 | 0 | StringRef Triple::getOSName() const { |
1002 | 0 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
1003 | 0 | Tmp = Tmp.split('-').second; // Strip second component |
1004 | 0 | return Tmp.split('-').first; // Isolate third component |
1005 | 0 | } |
1006 | | |
1007 | 0 | StringRef Triple::getEnvironmentName() const { |
1008 | 0 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
1009 | 0 | Tmp = Tmp.split('-').second; // Strip second component |
1010 | 0 | return Tmp.split('-').second; // Strip third component |
1011 | 0 | } |
1012 | | |
1013 | 0 | StringRef Triple::getOSAndEnvironmentName() const { |
1014 | 0 | StringRef Tmp = StringRef(Data).split('-').second; // Strip first component |
1015 | 0 | return Tmp.split('-').second; // Strip second component |
1016 | 0 | } |
1017 | | |
1018 | | static unsigned EatNumber(StringRef &Str) { |
1019 | | assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number"); |
1020 | | unsigned Result = 0; |
1021 | | |
1022 | | do { |
1023 | | // Consume the leading digit. |
1024 | | Result = Result*10 + (Str[0] - '0'); |
1025 | | |
1026 | | // Eat the digit. |
1027 | | Str = Str.substr(1); |
1028 | | } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9'); |
1029 | | |
1030 | | return Result; |
1031 | | } |
1032 | | |
1033 | | static void parseVersionFromName(StringRef Name, unsigned &Major, |
1034 | 0 | unsigned &Minor, unsigned &Micro) { |
1035 | 0 | // Any unset version defaults to 0. |
1036 | 0 | Major = Minor = Micro = 0; |
1037 | 0 |
|
1038 | 0 | // Parse up to three components. |
1039 | 0 | unsigned *Components[3] = {&Major, &Minor, &Micro}; |
1040 | 0 | for (unsigned i = 0; i != 3; ++i) { |
1041 | 0 | if (Name.empty() || Name[0] < '0' || Name[0] > '9') |
1042 | 0 | break; |
1043 | 0 | |
1044 | 0 | // Consume the leading number. |
1045 | 0 | *Components[i] = EatNumber(Name); |
1046 | 0 |
|
1047 | 0 | // Consume the separator, if present. |
1048 | 0 | if (Name.startswith(".")) |
1049 | 0 | Name = Name.substr(1); |
1050 | 0 | } |
1051 | 0 | } |
1052 | | |
1053 | | void Triple::getEnvironmentVersion(unsigned &Major, unsigned &Minor, |
1054 | 0 | unsigned &Micro) const { |
1055 | 0 | StringRef EnvironmentName = getEnvironmentName(); |
1056 | 0 | StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment()); |
1057 | 0 | if (EnvironmentName.startswith(EnvironmentTypeName)) |
1058 | 0 | EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size()); |
1059 | 0 |
|
1060 | 0 | parseVersionFromName(EnvironmentName, Major, Minor, Micro); |
1061 | 0 | } |
1062 | | |
1063 | | void Triple::getOSVersion(unsigned &Major, unsigned &Minor, |
1064 | 0 | unsigned &Micro) const { |
1065 | 0 | StringRef OSName = getOSName(); |
1066 | 0 | // Assume that the OS portion of the triple starts with the canonical name. |
1067 | 0 | StringRef OSTypeName = getOSTypeName(getOS()); |
1068 | 0 | if (OSName.startswith(OSTypeName)) |
1069 | 0 | OSName = OSName.substr(OSTypeName.size()); |
1070 | 0 | else if (getOS() == MacOSX) |
1071 | 0 | OSName.consume_front("macos"); |
1072 | 0 |
|
1073 | 0 | parseVersionFromName(OSName, Major, Minor, Micro); |
1074 | 0 | } |
1075 | | |
1076 | | bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor, |
1077 | 0 | unsigned &Micro) const { |
1078 | 0 | getOSVersion(Major, Minor, Micro); |
1079 | 0 |
|
1080 | 0 | switch (getOS()) { |
1081 | 0 | default: llvm_unreachable("unexpected OS for Darwin triple"); |
1082 | 0 | case Darwin: |
1083 | 0 | // Default to darwin8, i.e., MacOSX 10.4. |
1084 | 0 | if (Major == 0) |
1085 | 0 | Major = 8; |
1086 | 0 | // Darwin version numbers are skewed from OS X versions. |
1087 | 0 | if (Major < 4) |
1088 | 0 | return false; |
1089 | 0 | Micro = 0; |
1090 | 0 | Minor = Major - 4; |
1091 | 0 | Major = 10; |
1092 | 0 | break; |
1093 | 0 | case MacOSX: |
1094 | 0 | // Default to 10.4. |
1095 | 0 | if (Major == 0) { |
1096 | 0 | Major = 10; |
1097 | 0 | Minor = 4; |
1098 | 0 | } |
1099 | 0 | if (Major != 10) |
1100 | 0 | return false; |
1101 | 0 | break; |
1102 | 0 | case IOS: |
1103 | 0 | case TvOS: |
1104 | 0 | case WatchOS: |
1105 | 0 | // Ignore the version from the triple. This is only handled because the |
1106 | 0 | // the clang driver combines OS X and IOS support into a common Darwin |
1107 | 0 | // toolchain that wants to know the OS X version number even when targeting |
1108 | 0 | // IOS. |
1109 | 0 | Major = 10; |
1110 | 0 | Minor = 4; |
1111 | 0 | Micro = 0; |
1112 | 0 | break; |
1113 | 0 | } |
1114 | 0 | return true; |
1115 | 0 | } |
1116 | | |
1117 | | void Triple::getiOSVersion(unsigned &Major, unsigned &Minor, |
1118 | 0 | unsigned &Micro) const { |
1119 | 0 | switch (getOS()) { |
1120 | 0 | default: llvm_unreachable("unexpected OS for Darwin triple"); |
1121 | 0 | case Darwin: |
1122 | 0 | case MacOSX: |
1123 | 0 | // Ignore the version from the triple. This is only handled because the |
1124 | 0 | // the clang driver combines OS X and IOS support into a common Darwin |
1125 | 0 | // toolchain that wants to know the iOS version number even when targeting |
1126 | 0 | // OS X. |
1127 | 0 | Major = 5; |
1128 | 0 | Minor = 0; |
1129 | 0 | Micro = 0; |
1130 | 0 | break; |
1131 | 0 | case IOS: |
1132 | 0 | case TvOS: |
1133 | 0 | getOSVersion(Major, Minor, Micro); |
1134 | 0 | // Default to 5.0 (or 7.0 for arm64). |
1135 | 0 | if (Major == 0) |
1136 | 0 | Major = (getArch() == aarch64) ? 7 : 5; |
1137 | 0 | break; |
1138 | 0 | case WatchOS: |
1139 | 0 | llvm_unreachable("conflicting triple info"); |
1140 | 0 | } |
1141 | 0 | } |
1142 | | |
1143 | | void Triple::getWatchOSVersion(unsigned &Major, unsigned &Minor, |
1144 | 0 | unsigned &Micro) const { |
1145 | 0 | switch (getOS()) { |
1146 | 0 | default: llvm_unreachable("unexpected OS for Darwin triple"); |
1147 | 0 | case Darwin: |
1148 | 0 | case MacOSX: |
1149 | 0 | // Ignore the version from the triple. This is only handled because the |
1150 | 0 | // the clang driver combines OS X and IOS support into a common Darwin |
1151 | 0 | // toolchain that wants to know the iOS version number even when targeting |
1152 | 0 | // OS X. |
1153 | 0 | Major = 2; |
1154 | 0 | Minor = 0; |
1155 | 0 | Micro = 0; |
1156 | 0 | break; |
1157 | 0 | case WatchOS: |
1158 | 0 | getOSVersion(Major, Minor, Micro); |
1159 | 0 | if (Major == 0) |
1160 | 0 | Major = 2; |
1161 | 0 | break; |
1162 | 0 | case IOS: |
1163 | 0 | llvm_unreachable("conflicting triple info"); |
1164 | 0 | } |
1165 | 0 | } |
1166 | | |
1167 | 0 | void Triple::setTriple(const Twine &Str) { |
1168 | 0 | *this = Triple(Str); |
1169 | 0 | } |
1170 | | |
1171 | 0 | void Triple::setArch(ArchType Kind) { |
1172 | 0 | setArchName(getArchTypeName(Kind)); |
1173 | 0 | } |
1174 | | |
1175 | 0 | void Triple::setVendor(VendorType Kind) { |
1176 | 0 | setVendorName(getVendorTypeName(Kind)); |
1177 | 0 | } |
1178 | | |
1179 | 0 | void Triple::setOS(OSType Kind) { |
1180 | 0 | setOSName(getOSTypeName(Kind)); |
1181 | 0 | } |
1182 | | |
1183 | 0 | void Triple::setEnvironment(EnvironmentType Kind) { |
1184 | 0 | if (ObjectFormat == getDefaultFormat(*this)) |
1185 | 0 | return setEnvironmentName(getEnvironmentTypeName(Kind)); |
1186 | 0 | |
1187 | 0 | setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") + |
1188 | 0 | getObjectFormatTypeName(ObjectFormat)).str()); |
1189 | 0 | } |
1190 | | |
1191 | 0 | void Triple::setObjectFormat(ObjectFormatType Kind) { |
1192 | 0 | if (Environment == UnknownEnvironment) |
1193 | 0 | return setEnvironmentName(getObjectFormatTypeName(Kind)); |
1194 | 0 | |
1195 | 0 | setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") + |
1196 | 0 | getObjectFormatTypeName(Kind)).str()); |
1197 | 0 | } |
1198 | | |
1199 | 0 | void Triple::setArchName(StringRef Str) { |
1200 | 0 | // Work around a miscompilation bug for Twines in gcc 4.0.3. |
1201 | 0 | SmallString<64> Triple; |
1202 | 0 | Triple += Str; |
1203 | 0 | Triple += "-"; |
1204 | 0 | Triple += getVendorName(); |
1205 | 0 | Triple += "-"; |
1206 | 0 | Triple += getOSAndEnvironmentName(); |
1207 | 0 | setTriple(Triple); |
1208 | 0 | } |
1209 | | |
1210 | 0 | void Triple::setVendorName(StringRef Str) { |
1211 | 0 | setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName()); |
1212 | 0 | } |
1213 | | |
1214 | 0 | void Triple::setOSName(StringRef Str) { |
1215 | 0 | if (hasEnvironment()) |
1216 | 0 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str + |
1217 | 0 | "-" + getEnvironmentName()); |
1218 | 0 | else |
1219 | 0 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str); |
1220 | 0 | } |
1221 | | |
1222 | 0 | void Triple::setEnvironmentName(StringRef Str) { |
1223 | 0 | setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() + |
1224 | 0 | "-" + Str); |
1225 | 0 | } |
1226 | | |
1227 | 0 | void Triple::setOSAndEnvironmentName(StringRef Str) { |
1228 | 0 | setTriple(getArchName() + "-" + getVendorName() + "-" + Str); |
1229 | 0 | } |
1230 | | |
1231 | 2 | static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) { |
1232 | 2 | switch (Arch) { |
1233 | 2 | case llvm::Triple::UnknownArch: |
1234 | 0 | return 0; |
1235 | 2 | |
1236 | 2 | case llvm::Triple::avr: |
1237 | 0 | case llvm::Triple::msp430: |
1238 | 0 | return 16; |
1239 | 0 |
|
1240 | 0 | case llvm::Triple::aarch64_32: |
1241 | 0 | case llvm::Triple::amdil: |
1242 | 0 | case llvm::Triple::arc: |
1243 | 0 | case llvm::Triple::arm: |
1244 | 0 | case llvm::Triple::armeb: |
1245 | 0 | case llvm::Triple::hexagon: |
1246 | 0 | case llvm::Triple::hsail: |
1247 | 0 | case llvm::Triple::kalimba: |
1248 | 0 | case llvm::Triple::lanai: |
1249 | 0 | case llvm::Triple::le32: |
1250 | 0 | case llvm::Triple::mips: |
1251 | 0 | case llvm::Triple::mipsel: |
1252 | 0 | case llvm::Triple::nvptx: |
1253 | 0 | case llvm::Triple::ppc: |
1254 | 0 | case llvm::Triple::r600: |
1255 | 0 | case llvm::Triple::renderscript32: |
1256 | 0 | case llvm::Triple::riscv32: |
1257 | 0 | case llvm::Triple::shave: |
1258 | 0 | case llvm::Triple::sparc: |
1259 | 0 | case llvm::Triple::sparcel: |
1260 | 0 | case llvm::Triple::spir: |
1261 | 0 | case llvm::Triple::tce: |
1262 | 0 | case llvm::Triple::tcele: |
1263 | 0 | case llvm::Triple::thumb: |
1264 | 0 | case llvm::Triple::thumbeb: |
1265 | 0 | case llvm::Triple::wasm32: |
1266 | 0 | case llvm::Triple::x86: |
1267 | 0 | case llvm::Triple::xcore: |
1268 | 0 | return 32; |
1269 | 0 |
|
1270 | 2 | case llvm::Triple::aarch64: |
1271 | 2 | case llvm::Triple::aarch64_be: |
1272 | 2 | case llvm::Triple::amdgcn: |
1273 | 2 | case llvm::Triple::amdil64: |
1274 | 2 | case llvm::Triple::bpfeb: |
1275 | 2 | case llvm::Triple::bpfel: |
1276 | 2 | case llvm::Triple::hsail64: |
1277 | 2 | case llvm::Triple::le64: |
1278 | 2 | case llvm::Triple::mips64: |
1279 | 2 | case llvm::Triple::mips64el: |
1280 | 2 | case llvm::Triple::nvptx64: |
1281 | 2 | case llvm::Triple::ppc64: |
1282 | 2 | case llvm::Triple::ppc64le: |
1283 | 2 | case llvm::Triple::renderscript64: |
1284 | 2 | case llvm::Triple::riscv64: |
1285 | 2 | case llvm::Triple::sparcv9: |
1286 | 2 | case llvm::Triple::spir64: |
1287 | 2 | case llvm::Triple::systemz: |
1288 | 2 | case llvm::Triple::ve: |
1289 | 2 | case llvm::Triple::wasm64: |
1290 | 2 | case llvm::Triple::x86_64: |
1291 | 2 | return 64; |
1292 | 0 | } |
1293 | 0 | llvm_unreachable("Invalid architecture value"); |
1294 | 0 | } |
1295 | | |
1296 | 0 | bool Triple::isArch64Bit() const { |
1297 | 0 | return getArchPointerBitWidth(getArch()) == 64; |
1298 | 0 | } |
1299 | | |
1300 | 2 | bool Triple::isArch32Bit() const { |
1301 | 2 | return getArchPointerBitWidth(getArch()) == 32; |
1302 | 2 | } |
1303 | | |
1304 | 0 | bool Triple::isArch16Bit() const { |
1305 | 0 | return getArchPointerBitWidth(getArch()) == 16; |
1306 | 0 | } |
1307 | | |
1308 | 0 | Triple Triple::get32BitArchVariant() const { |
1309 | 0 | Triple T(*this); |
1310 | 0 | switch (getArch()) { |
1311 | 0 | case Triple::UnknownArch: |
1312 | 0 | case Triple::amdgcn: |
1313 | 0 | case Triple::avr: |
1314 | 0 | case Triple::bpfeb: |
1315 | 0 | case Triple::bpfel: |
1316 | 0 | case Triple::msp430: |
1317 | 0 | case Triple::ppc64le: |
1318 | 0 | case Triple::systemz: |
1319 | 0 | case Triple::ve: |
1320 | 0 | T.setArch(UnknownArch); |
1321 | 0 | break; |
1322 | 0 |
|
1323 | 0 | case Triple::aarch64_32: |
1324 | 0 | case Triple::amdil: |
1325 | 0 | case Triple::arc: |
1326 | 0 | case Triple::arm: |
1327 | 0 | case Triple::armeb: |
1328 | 0 | case Triple::hexagon: |
1329 | 0 | case Triple::hsail: |
1330 | 0 | case Triple::kalimba: |
1331 | 0 | case Triple::lanai: |
1332 | 0 | case Triple::le32: |
1333 | 0 | case Triple::mips: |
1334 | 0 | case Triple::mipsel: |
1335 | 0 | case Triple::nvptx: |
1336 | 0 | case Triple::ppc: |
1337 | 0 | case Triple::r600: |
1338 | 0 | case Triple::renderscript32: |
1339 | 0 | case Triple::riscv32: |
1340 | 0 | case Triple::shave: |
1341 | 0 | case Triple::sparc: |
1342 | 0 | case Triple::sparcel: |
1343 | 0 | case Triple::spir: |
1344 | 0 | case Triple::tce: |
1345 | 0 | case Triple::tcele: |
1346 | 0 | case Triple::thumb: |
1347 | 0 | case Triple::thumbeb: |
1348 | 0 | case Triple::wasm32: |
1349 | 0 | case Triple::x86: |
1350 | 0 | case Triple::xcore: |
1351 | 0 | // Already 32-bit. |
1352 | 0 | break; |
1353 | 0 |
|
1354 | 0 | case Triple::aarch64: T.setArch(Triple::arm); break; |
1355 | 0 | case Triple::aarch64_be: T.setArch(Triple::armeb); break; |
1356 | 0 | case Triple::amdil64: T.setArch(Triple::amdil); break; |
1357 | 0 | case Triple::hsail64: T.setArch(Triple::hsail); break; |
1358 | 0 | case Triple::le64: T.setArch(Triple::le32); break; |
1359 | 0 | case Triple::mips64: T.setArch(Triple::mips); break; |
1360 | 0 | case Triple::mips64el: T.setArch(Triple::mipsel); break; |
1361 | 0 | case Triple::nvptx64: T.setArch(Triple::nvptx); break; |
1362 | 0 | case Triple::ppc64: T.setArch(Triple::ppc); break; |
1363 | 0 | case Triple::renderscript64: T.setArch(Triple::renderscript32); break; |
1364 | 0 | case Triple::riscv64: T.setArch(Triple::riscv32); break; |
1365 | 0 | case Triple::sparcv9: T.setArch(Triple::sparc); break; |
1366 | 0 | case Triple::spir64: T.setArch(Triple::spir); break; |
1367 | 0 | case Triple::wasm64: T.setArch(Triple::wasm32); break; |
1368 | 0 | case Triple::x86_64: T.setArch(Triple::x86); break; |
1369 | 0 | } |
1370 | 0 | return T; |
1371 | 0 | } |
1372 | | |
1373 | 0 | Triple Triple::get64BitArchVariant() const { |
1374 | 0 | Triple T(*this); |
1375 | 0 | switch (getArch()) { |
1376 | 0 | case Triple::UnknownArch: |
1377 | 0 | case Triple::arc: |
1378 | 0 | case Triple::avr: |
1379 | 0 | case Triple::hexagon: |
1380 | 0 | case Triple::kalimba: |
1381 | 0 | case Triple::lanai: |
1382 | 0 | case Triple::msp430: |
1383 | 0 | case Triple::r600: |
1384 | 0 | case Triple::shave: |
1385 | 0 | case Triple::sparcel: |
1386 | 0 | case Triple::tce: |
1387 | 0 | case Triple::tcele: |
1388 | 0 | case Triple::xcore: |
1389 | 0 | T.setArch(UnknownArch); |
1390 | 0 | break; |
1391 | 0 |
|
1392 | 0 | case Triple::aarch64: |
1393 | 0 | case Triple::aarch64_be: |
1394 | 0 | case Triple::amdgcn: |
1395 | 0 | case Triple::amdil64: |
1396 | 0 | case Triple::bpfeb: |
1397 | 0 | case Triple::bpfel: |
1398 | 0 | case Triple::hsail64: |
1399 | 0 | case Triple::le64: |
1400 | 0 | case Triple::mips64: |
1401 | 0 | case Triple::mips64el: |
1402 | 0 | case Triple::nvptx64: |
1403 | 0 | case Triple::ppc64: |
1404 | 0 | case Triple::ppc64le: |
1405 | 0 | case Triple::renderscript64: |
1406 | 0 | case Triple::riscv64: |
1407 | 0 | case Triple::sparcv9: |
1408 | 0 | case Triple::spir64: |
1409 | 0 | case Triple::systemz: |
1410 | 0 | case Triple::ve: |
1411 | 0 | case Triple::wasm64: |
1412 | 0 | case Triple::x86_64: |
1413 | 0 | // Already 64-bit. |
1414 | 0 | break; |
1415 | 0 |
|
1416 | 0 | case Triple::aarch64_32: T.setArch(Triple::aarch64); break; |
1417 | 0 | case Triple::amdil: T.setArch(Triple::amdil64); break; |
1418 | 0 | case Triple::arm: T.setArch(Triple::aarch64); break; |
1419 | 0 | case Triple::armeb: T.setArch(Triple::aarch64_be); break; |
1420 | 0 | case Triple::hsail: T.setArch(Triple::hsail64); break; |
1421 | 0 | case Triple::le32: T.setArch(Triple::le64); break; |
1422 | 0 | case Triple::mips: T.setArch(Triple::mips64); break; |
1423 | 0 | case Triple::mipsel: T.setArch(Triple::mips64el); break; |
1424 | 0 | case Triple::nvptx: T.setArch(Triple::nvptx64); break; |
1425 | 0 | case Triple::ppc: T.setArch(Triple::ppc64); break; |
1426 | 0 | case Triple::renderscript32: T.setArch(Triple::renderscript64); break; |
1427 | 0 | case Triple::riscv32: T.setArch(Triple::riscv64); break; |
1428 | 0 | case Triple::sparc: T.setArch(Triple::sparcv9); break; |
1429 | 0 | case Triple::spir: T.setArch(Triple::spir64); break; |
1430 | 0 | case Triple::thumb: T.setArch(Triple::aarch64); break; |
1431 | 0 | case Triple::thumbeb: T.setArch(Triple::aarch64_be); break; |
1432 | 0 | case Triple::wasm32: T.setArch(Triple::wasm64); break; |
1433 | 0 | case Triple::x86: T.setArch(Triple::x86_64); break; |
1434 | 0 | } |
1435 | 0 | return T; |
1436 | 0 | } |
1437 | | |
1438 | 0 | Triple Triple::getBigEndianArchVariant() const { |
1439 | 0 | Triple T(*this); |
1440 | 0 | // Already big endian. |
1441 | 0 | if (!isLittleEndian()) |
1442 | 0 | return T; |
1443 | 0 | switch (getArch()) { |
1444 | 0 | case Triple::UnknownArch: |
1445 | 0 | case Triple::amdgcn: |
1446 | 0 | case Triple::amdil64: |
1447 | 0 | case Triple::amdil: |
1448 | 0 | case Triple::avr: |
1449 | 0 | case Triple::hexagon: |
1450 | 0 | case Triple::hsail64: |
1451 | 0 | case Triple::hsail: |
1452 | 0 | case Triple::kalimba: |
1453 | 0 | case Triple::le32: |
1454 | 0 | case Triple::le64: |
1455 | 0 | case Triple::msp430: |
1456 | 0 | case Triple::nvptx64: |
1457 | 0 | case Triple::nvptx: |
1458 | 0 | case Triple::r600: |
1459 | 0 | case Triple::renderscript32: |
1460 | 0 | case Triple::renderscript64: |
1461 | 0 | case Triple::riscv32: |
1462 | 0 | case Triple::riscv64: |
1463 | 0 | case Triple::shave: |
1464 | 0 | case Triple::spir64: |
1465 | 0 | case Triple::spir: |
1466 | 0 | case Triple::wasm32: |
1467 | 0 | case Triple::wasm64: |
1468 | 0 | case Triple::x86: |
1469 | 0 | case Triple::x86_64: |
1470 | 0 | case Triple::xcore: |
1471 | 0 | case Triple::ve: |
1472 | 0 |
|
1473 | 0 | // ARM is intentionally unsupported here, changing the architecture would |
1474 | 0 | // drop any arch suffixes. |
1475 | 0 | case Triple::arm: |
1476 | 0 | case Triple::thumb: |
1477 | 0 | T.setArch(UnknownArch); |
1478 | 0 | break; |
1479 | 0 |
|
1480 | 0 | case Triple::aarch64: T.setArch(Triple::aarch64_be); break; |
1481 | 0 | case Triple::bpfel: T.setArch(Triple::bpfeb); break; |
1482 | 0 | case Triple::mips64el:T.setArch(Triple::mips64); break; |
1483 | 0 | case Triple::mipsel: T.setArch(Triple::mips); break; |
1484 | 0 | case Triple::ppc64le: T.setArch(Triple::ppc64); break; |
1485 | 0 | case Triple::sparcel: T.setArch(Triple::sparc); break; |
1486 | 0 | case Triple::tcele: T.setArch(Triple::tce); break; |
1487 | 0 | default: |
1488 | 0 | llvm_unreachable("getBigEndianArchVariant: unknown triple."); |
1489 | 0 | } |
1490 | 0 | return T; |
1491 | 0 | } |
1492 | | |
1493 | 0 | Triple Triple::getLittleEndianArchVariant() const { |
1494 | 0 | Triple T(*this); |
1495 | 0 | if (isLittleEndian()) |
1496 | 0 | return T; |
1497 | 0 | |
1498 | 0 | switch (getArch()) { |
1499 | 0 | case Triple::UnknownArch: |
1500 | 0 | case Triple::lanai: |
1501 | 0 | case Triple::ppc: |
1502 | 0 | case Triple::sparcv9: |
1503 | 0 | case Triple::systemz: |
1504 | 0 |
|
1505 | 0 | // ARM is intentionally unsupported here, changing the architecture would |
1506 | 0 | // drop any arch suffixes. |
1507 | 0 | case Triple::armeb: |
1508 | 0 | case Triple::thumbeb: |
1509 | 0 | T.setArch(UnknownArch); |
1510 | 0 | break; |
1511 | 0 |
|
1512 | 0 | case Triple::aarch64_be: T.setArch(Triple::aarch64); break; |
1513 | 0 | case Triple::bpfeb: T.setArch(Triple::bpfel); break; |
1514 | 0 | case Triple::mips64: T.setArch(Triple::mips64el); break; |
1515 | 0 | case Triple::mips: T.setArch(Triple::mipsel); break; |
1516 | 0 | case Triple::ppc64: T.setArch(Triple::ppc64le); break; |
1517 | 0 | case Triple::sparc: T.setArch(Triple::sparcel); break; |
1518 | 0 | case Triple::tce: T.setArch(Triple::tcele); break; |
1519 | 0 | default: |
1520 | 0 | llvm_unreachable("getLittleEndianArchVariant: unknown triple."); |
1521 | 0 | } |
1522 | 0 | return T; |
1523 | 0 | } |
1524 | | |
1525 | | bool Triple::isLittleEndian() const { |
1526 | | switch (getArch()) { |
1527 | | case Triple::aarch64: |
1528 | | case Triple::aarch64_32: |
1529 | | case Triple::amdgcn: |
1530 | | case Triple::amdil64: |
1531 | | case Triple::amdil: |
1532 | | case Triple::arm: |
1533 | | case Triple::avr: |
1534 | | case Triple::bpfel: |
1535 | | case Triple::hexagon: |
1536 | | case Triple::hsail64: |
1537 | | case Triple::hsail: |
1538 | | case Triple::kalimba: |
1539 | | case Triple::le32: |
1540 | | case Triple::le64: |
1541 | | case Triple::mips64el: |
1542 | | case Triple::mipsel: |
1543 | | case Triple::msp430: |
1544 | | case Triple::nvptx64: |
1545 | | case Triple::nvptx: |
1546 | | case Triple::ppc64le: |
1547 | | case Triple::r600: |
1548 | | case Triple::renderscript32: |
1549 | | case Triple::renderscript64: |
1550 | | case Triple::riscv32: |
1551 | | case Triple::riscv64: |
1552 | | case Triple::shave: |
1553 | | case Triple::sparcel: |
1554 | | case Triple::spir64: |
1555 | | case Triple::spir: |
1556 | | case Triple::tcele: |
1557 | | case Triple::thumb: |
1558 | | case Triple::ve: |
1559 | | case Triple::wasm32: |
1560 | | case Triple::wasm64: |
1561 | | case Triple::x86: |
1562 | | case Triple::x86_64: |
1563 | | case Triple::xcore: |
1564 | | return true; |
1565 | | default: |
1566 | | return false; |
1567 | | } |
1568 | | } |
1569 | | |
1570 | 0 | bool Triple::isCompatibleWith(const Triple &Other) const { |
1571 | 0 | // ARM and Thumb triples are compatible, if subarch, vendor and OS match. |
1572 | 0 | if ((getArch() == Triple::thumb && Other.getArch() == Triple::arm) || |
1573 | 0 | (getArch() == Triple::arm && Other.getArch() == Triple::thumb) || |
1574 | 0 | (getArch() == Triple::thumbeb && Other.getArch() == Triple::armeb) || |
1575 | 0 | (getArch() == Triple::armeb && Other.getArch() == Triple::thumbeb)) { |
1576 | 0 | if (getVendor() == Triple::Apple) |
1577 | 0 | return getSubArch() == Other.getSubArch() && |
1578 | 0 | getVendor() == Other.getVendor() && getOS() == Other.getOS(); |
1579 | 0 | else |
1580 | 0 | return getSubArch() == Other.getSubArch() && |
1581 | 0 | getVendor() == Other.getVendor() && getOS() == Other.getOS() && |
1582 | 0 | getEnvironment() == Other.getEnvironment() && |
1583 | 0 | getObjectFormat() == Other.getObjectFormat(); |
1584 | 0 | } |
1585 | 0 | |
1586 | 0 | // If vendor is apple, ignore the version number. |
1587 | 0 | if (getVendor() == Triple::Apple) |
1588 | 0 | return getArch() == Other.getArch() && getSubArch() == Other.getSubArch() && |
1589 | 0 | getVendor() == Other.getVendor() && getOS() == Other.getOS(); |
1590 | 0 | |
1591 | 0 | return *this == Other; |
1592 | 0 | } |
1593 | | |
1594 | 0 | std::string Triple::merge(const Triple &Other) const { |
1595 | 0 | // If vendor is apple, pick the triple with the larger version number. |
1596 | 0 | if (getVendor() == Triple::Apple) |
1597 | 0 | if (Other.isOSVersionLT(*this)) |
1598 | 0 | return str(); |
1599 | 0 | |
1600 | 0 | return Other.str(); |
1601 | 0 | } |
1602 | | |
1603 | 0 | StringRef Triple::getARMCPUForArch(StringRef MArch) const { |
1604 | 0 | if (MArch.empty()) |
1605 | 0 | MArch = getArchName(); |
1606 | 0 | MArch = ARM::getCanonicalArchName(MArch); |
1607 | 0 |
|
1608 | 0 | // Some defaults are forced. |
1609 | 0 | switch (getOS()) { |
1610 | 0 | case llvm::Triple::FreeBSD: |
1611 | 0 | case llvm::Triple::NetBSD: |
1612 | 0 | if (!MArch.empty() && MArch == "v6") |
1613 | 0 | return "arm1176jzf-s"; |
1614 | 0 | break; |
1615 | 0 | case llvm::Triple::Win32: |
1616 | 0 | // FIXME: this is invalid for WindowsCE |
1617 | 0 | return "cortex-a9"; |
1618 | 0 | case llvm::Triple::IOS: |
1619 | 0 | case llvm::Triple::MacOSX: |
1620 | 0 | case llvm::Triple::TvOS: |
1621 | 0 | case llvm::Triple::WatchOS: |
1622 | 0 | if (MArch == "v7k") |
1623 | 0 | return "cortex-a7"; |
1624 | 0 | break; |
1625 | 0 | default: |
1626 | 0 | break; |
1627 | 0 | } |
1628 | 0 | |
1629 | 0 | if (MArch.empty()) |
1630 | 0 | return StringRef(); |
1631 | 0 | |
1632 | 0 | StringRef CPU = ARM::getDefaultCPU(MArch); |
1633 | 0 | if (!CPU.empty() && !CPU.equals("invalid")) |
1634 | 0 | return CPU; |
1635 | 0 | |
1636 | 0 | // If no specific architecture version is requested, return the minimum CPU |
1637 | 0 | // required by the OS and environment. |
1638 | 0 | switch (getOS()) { |
1639 | 0 | case llvm::Triple::NetBSD: |
1640 | 0 | switch (getEnvironment()) { |
1641 | 0 | case llvm::Triple::EABI: |
1642 | 0 | case llvm::Triple::EABIHF: |
1643 | 0 | case llvm::Triple::GNUEABI: |
1644 | 0 | case llvm::Triple::GNUEABIHF: |
1645 | 0 | return "arm926ej-s"; |
1646 | 0 | default: |
1647 | 0 | return "strongarm"; |
1648 | 0 | } |
1649 | 0 | case llvm::Triple::NaCl: |
1650 | 0 | case llvm::Triple::OpenBSD: |
1651 | 0 | return "cortex-a8"; |
1652 | 0 | default: |
1653 | 0 | switch (getEnvironment()) { |
1654 | 0 | case llvm::Triple::EABIHF: |
1655 | 0 | case llvm::Triple::GNUEABIHF: |
1656 | 0 | case llvm::Triple::MuslEABIHF: |
1657 | 0 | return "arm1176jzf-s"; |
1658 | 0 | default: |
1659 | 0 | return "arm7tdmi"; |
1660 | 0 | } |
1661 | 0 | } |
1662 | 0 | |
1663 | 0 | llvm_unreachable("invalid arch name"); |
1664 | 0 | } |