blob: e74b23ca0cacf7a697b4bcd7759f1f98d7b4efe6 [file] [log] [blame]
Daniel Dunbar4abd5662009-04-01 21:53:23 +00001//===--- Triple.cpp - Target triple helper class --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ADT/Triple.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "llvm/ADT/STLExtras.h"
Jeffrey Yasskine2595b52009-10-06 21:45:26 +000012#include "llvm/ADT/SmallString.h"
Chandler Carruthff6f3562012-02-12 09:27:38 +000013#include "llvm/ADT/StringSwitch.h"
David Blaikie46a9f012012-01-20 21:51:11 +000014#include "llvm/Support/ErrorHandling.h"
Mikhail Glushenkov12062ba2009-04-02 01:11:37 +000015#include <cstring>
Daniel Dunbar4abd5662009-04-01 21:53:23 +000016using namespace llvm;
17
Daniel Dunbar4abd5662009-04-01 21:53:23 +000018const char *Triple::getArchTypeName(ArchType Kind) {
19 switch (Kind) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +000020 case UnknownArch: return "unknown";
Jim Grosbachf638b262010-12-17 02:10:59 +000021
Christian Pirker6c2f4d42014-02-24 11:34:50 +000022 case aarch64: return "aarch64";
23 case aarch64_be: return "aarch64_be";
24 case arm: return "arm";
Christian Pirker2a111602014-03-28 14:35:30 +000025 case armeb: return "armeb";
Alexei Starovoitove4c8c802015-01-24 17:51:26 +000026 case bpf: return "bpf";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000027 case hexagon: return "hexagon";
28 case mips: return "mips";
29 case mipsel: return "mipsel";
30 case mips64: return "mips64";
31 case mips64el: return "mips64el";
32 case msp430: return "msp430";
33 case ppc64: return "powerpc64";
34 case ppc64le: return "powerpc64le";
35 case ppc: return "powerpc";
36 case r600: return "r600";
Tom Stellard07f11602015-01-06 18:00:00 +000037 case amdgcn: return "amdgcn";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000038 case sparc: return "sparc";
39 case sparcv9: return "sparcv9";
40 case systemz: return "s390x";
41 case tce: return "tce";
42 case thumb: return "thumb";
Christian Pirker2a111602014-03-28 14:35:30 +000043 case thumbeb: return "thumbeb";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000044 case x86: return "i386";
45 case x86_64: return "x86_64";
46 case xcore: return "xcore";
47 case nvptx: return "nvptx";
48 case nvptx64: return "nvptx64";
49 case le32: return "le32";
JF Bastien32972ef2014-09-12 17:54:17 +000050 case le64: return "le64";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000051 case amdil: return "amdil";
Matt Arsenault3f9b0212014-09-19 19:52:11 +000052 case amdil64: return "amdil64";
53 case hsail: return "hsail";
54 case hsail64: return "hsail64";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000055 case spir: return "spir";
56 case spir64: return "spir64";
Eric Christopher54fe1b22014-07-10 17:26:54 +000057 case kalimba: return "kalimba";
Daniel Dunbar4abd5662009-04-01 21:53:23 +000058 }
59
David Blaikie46a9f012012-01-20 21:51:11 +000060 llvm_unreachable("Invalid ArchType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +000061}
62
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000063const char *Triple::getArchTypePrefix(ArchType Kind) {
64 switch (Kind) {
65 default:
Craig Topperc10719f2014-04-07 04:17:22 +000066 return nullptr;
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000067
Christian Pirker6c2f4d42014-02-24 11:34:50 +000068 case aarch64:
69 case aarch64_be: return "aarch64";
Tim Northovere0e3aef2013-01-31 12:12:40 +000070
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000071 case arm:
Christian Pirker2a111602014-03-28 14:35:30 +000072 case armeb:
73 case thumb:
74 case thumbeb: return "arm";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000075
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000076 case ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +000077 case ppc64le:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000078 case ppc: return "ppc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000079
Benjamin Kramerae3c3002012-06-28 19:09:53 +000080 case mips:
81 case mipsel:
82 case mips64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000083 case mips64el: return "mips";
Benjamin Kramerae3c3002012-06-28 19:09:53 +000084
Christian Pirker6c2f4d42014-02-24 11:34:50 +000085 case hexagon: return "hexagon";
Tony Linthicum1213a7a2011-12-12 21:14:40 +000086
Tom Stellard07f11602015-01-06 18:00:00 +000087 case amdgcn:
88 case r600: return "amdgpu";
Anton Korobeynikovf32638d2012-03-09 10:09:36 +000089
Alexei Starovoitove4c8c802015-01-24 17:51:26 +000090 case bpf: return "bpf";
91
Chris Lattner8228b112010-02-04 06:34:01 +000092 case sparcv9:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000093 case sparc: return "sparc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000094
Christian Pirker6c2f4d42014-02-24 11:34:50 +000095 case systemz: return "systemz";
Richard Sandiforda238c5e2013-05-03 11:05:17 +000096
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000097 case x86:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000098 case x86_64: return "x86";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000099
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000100 case xcore: return "xcore";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +0000101
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000102 case nvptx: return "nvptx";
103 case nvptx64: return "nvptx";
Tim Northover00ed9962014-03-29 10:18:08 +0000104
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000105 case le32: return "le32";
JF Bastien32972ef2014-09-12 17:54:17 +0000106 case le64: return "le64";
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000107
108 case amdil:
109 case amdil64: return "amdil";
110
111 case hsail:
112 case hsail64: return "hsail";
113
114 case spir:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000115 case spir64: return "spir";
Eric Christopher54fe1b22014-07-10 17:26:54 +0000116 case kalimba: return "kalimba";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +0000117 }
118}
119
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000120const char *Triple::getVendorTypeName(VendorType Kind) {
121 switch (Kind) {
122 case UnknownVendor: return "unknown";
123
124 case Apple: return "apple";
Chris Lattner07921952009-08-14 18:48:13 +0000125 case PC: return "pc";
John Thompsond0332e42011-03-15 21:51:56 +0000126 case SCEI: return "scei";
Hal Finkelf208af02012-04-02 18:31:33 +0000127 case BGP: return "bgp";
128 case BGQ: return "bgq";
Hal Finkelb5d177e2012-08-28 02:10:30 +0000129 case Freescale: return "fsl";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000130 case IBM: return "ibm";
Daniel Sandersc5626f42014-07-09 16:03:10 +0000131 case ImaginationTechnologies: return "img";
Daniel Sandersdc6a9412014-07-18 14:28:19 +0000132 case MipsTechnologies: return "mti";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000133 case NVIDIA: return "nvidia";
Eric Christopher54fe1b22014-07-10 17:26:54 +0000134 case CSR: return "csr";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000135 }
136
David Blaikie46a9f012012-01-20 21:51:11 +0000137 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000138}
139
140const char *Triple::getOSTypeName(OSType Kind) {
141 switch (Kind) {
142 case UnknownOS: return "unknown";
143
144 case Darwin: return "darwin";
Daniel Dunbare3384c42009-05-22 02:24:11 +0000145 case DragonFly: return "dragonfly";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000146 case FreeBSD: return "freebsd";
Daniel Dunbard74bac72011-04-19 20:19:27 +0000147 case IOS: return "ios";
Duncan Sandsfe44f672011-07-26 15:30:04 +0000148 case KFreeBSD: return "kfreebsd";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000149 case Linux: return "linux";
Edward O'Callaghanba993b82009-11-19 11:59:00 +0000150 case Lv2: return "lv2";
Daniel Dunbar0854f342011-04-19 23:34:12 +0000151 case MacOSX: return "macosx";
Chris Lattner01218d52009-07-13 20:22:23 +0000152 case NetBSD: return "netbsd";
Duncan Sands14814d42009-06-29 13:36:13 +0000153 case OpenBSD: return "openbsd";
Daniel Dunbar781f94d2009-08-18 04:43:27 +0000154 case Solaris: return "solaris";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000155 case Win32: return "windows";
Chris Lattner27f20492009-10-16 02:06:30 +0000156 case Haiku: return "haiku";
Chris Lattnerca97c922010-07-07 15:52:27 +0000157 case Minix: return "minix";
Douglas Gregorde3c9262011-07-01 22:41:06 +0000158 case RTEMS: return "rtems";
Eli Benderskyabe54632012-12-04 18:37:26 +0000159 case NaCl: return "nacl";
Hal Finkelf208af02012-04-02 18:31:33 +0000160 case CNK: return "cnk";
Eric Christopher22738d02012-08-06 20:52:18 +0000161 case Bitrig: return "bitrig";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000162 case AIX: return "aix";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000163 case CUDA: return "cuda";
164 case NVCL: return "nvcl";
Tom Stellard4082a6c2014-12-02 16:45:47 +0000165 case AMDHSA: return "amdhsa";
Alex Rosenberg38babd12015-01-25 22:46:59 +0000166 case PS4: return "ps4";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000167 }
168
David Blaikie46a9f012012-01-20 21:51:11 +0000169 llvm_unreachable("Invalid OSType");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000170}
171
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000172const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
173 switch (Kind) {
174 case UnknownEnvironment: return "unknown";
Renato Golin83758d5c2011-01-21 18:25:47 +0000175 case GNU: return "gnu";
Rafael Espindolaf5e78fa2012-01-18 23:35:29 +0000176 case GNUEABIHF: return "gnueabihf";
Renato Golin83758d5c2011-01-21 18:25:47 +0000177 case GNUEABI: return "gnueabi";
Eli Bendersky0893e102013-01-22 18:02:49 +0000178 case GNUX32: return "gnux32";
David Woodhouse71d15ed2014-01-20 12:02:25 +0000179 case CODE16: return "code16";
Renato Golin83758d5c2011-01-21 18:25:47 +0000180 case EABI: return "eabi";
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000181 case EABIHF: return "eabihf";
Logan Chien9ab55b82012-09-02 09:29:46 +0000182 case Android: return "android";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000183 case MSVC: return "msvc";
184 case Itanium: return "itanium";
185 case Cygnus: return "cygnus";
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000186 }
187
David Blaikie46a9f012012-01-20 21:51:11 +0000188 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000189}
190
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000191Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruthff6f3562012-02-12 09:27:38 +0000192 return StringSwitch<Triple::ArchType>(Name)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000193 .Case("aarch64", aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000194 .Case("aarch64_be", aarch64_be)
Tim Northovere19bed72014-07-23 12:32:47 +0000195 .Case("arm64", aarch64) // "arm64" is an alias for "aarch64"
Chandler Carruthff6f3562012-02-12 09:27:38 +0000196 .Case("arm", arm)
Christian Pirker2a111602014-03-28 14:35:30 +0000197 .Case("armeb", armeb)
Alexei Starovoitove4c8c802015-01-24 17:51:26 +0000198 .Case("bpf", bpf)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000199 .Case("mips", mips)
200 .Case("mipsel", mipsel)
201 .Case("mips64", mips64)
202 .Case("mips64el", mips64el)
203 .Case("msp430", msp430)
204 .Case("ppc64", ppc64)
205 .Case("ppc32", ppc)
206 .Case("ppc", ppc)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000207 .Case("ppc64le", ppc64le)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000208 .Case("r600", r600)
Tom Stellard07f11602015-01-06 18:00:00 +0000209 .Case("amdgcn", amdgcn)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000210 .Case("hexagon", hexagon)
211 .Case("sparc", sparc)
212 .Case("sparcv9", sparcv9)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000213 .Case("systemz", systemz)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000214 .Case("tce", tce)
215 .Case("thumb", thumb)
Christian Pirker2a111602014-03-28 14:35:30 +0000216 .Case("thumbeb", thumbeb)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000217 .Case("x86", x86)
218 .Case("x86-64", x86_64)
219 .Case("xcore", xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000220 .Case("nvptx", nvptx)
221 .Case("nvptx64", nvptx64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000222 .Case("le32", le32)
JF Bastien32972ef2014-09-12 17:54:17 +0000223 .Case("le64", le64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000224 .Case("amdil", amdil)
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000225 .Case("amdil64", amdil64)
226 .Case("hsail", hsail)
227 .Case("hsail64", hsail64)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000228 .Case("spir", spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000229 .Case("spir64", spir64)
Eric Christopher54fe1b22014-07-10 17:26:54 +0000230 .Case("kalimba", kalimba)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000231 .Default(UnknownArch);
Daniel Dunbar0f16ea52009-08-03 04:03:51 +0000232}
233
Renato Golin609bf922014-11-17 14:08:57 +0000234static Triple::ArchType parseARMArch(StringRef ArchName) {
235 size_t offset = StringRef::npos;
236 Triple::ArchType arch = Triple::UnknownArch;
237 bool isThumb = ArchName.startswith("thumb");
238
239 if (ArchName.equals("arm"))
240 return Triple::arm;
241 if (ArchName.equals("armeb"))
242 return Triple::armeb;
243 if (ArchName.equals("thumb"))
244 return Triple::thumb;
245 if (ArchName.equals("thumbeb"))
246 return Triple::thumbeb;
247 if (ArchName.equals("arm64") || ArchName.equals("aarch64"))
248 return Triple::aarch64;
249 if (ArchName.equals("aarch64_be"))
250 return Triple::aarch64_be;
251
252 if (ArchName.startswith("armv")) {
253 offset = 3;
Joerg Sonnenberger429edc12015-01-26 11:41:48 +0000254 if (ArchName.endswith("eb")) {
255 arch = Triple::armeb;
256 ArchName = ArchName.substr(0, ArchName.size() - 2);
257 } else
258 arch = Triple::arm;
Renato Golin609bf922014-11-17 14:08:57 +0000259 } else if (ArchName.startswith("armebv")) {
260 offset = 5;
261 arch = Triple::armeb;
262 } else if (ArchName.startswith("thumbv")) {
263 offset = 5;
Joerg Sonnenberger429edc12015-01-26 11:41:48 +0000264 if (ArchName.endswith("eb")) {
265 arch = Triple::thumbeb;
266 ArchName = ArchName.substr(0, ArchName.size() - 2);
267 } else
268 arch = Triple::thumb;
Renato Golin609bf922014-11-17 14:08:57 +0000269 } else if (ArchName.startswith("thumbebv")) {
270 offset = 7;
271 arch = Triple::thumbeb;
272 }
273 return StringSwitch<Triple::ArchType>(ArchName.substr(offset))
274 .Cases("v2", "v2a", isThumb ? Triple::UnknownArch : arch)
275 .Cases("v3", "v3m", isThumb ? Triple::UnknownArch : arch)
276 .Cases("v4", "v4t", arch)
277 .Cases("v5", "v5e", "v5t", "v5te", "v5tej", arch)
Bradley Smithe997b452015-02-10 15:15:08 +0000278 .Cases("v6", "v6j", "v6k", "v6m", "v6sm", arch)
Renato Golin609bf922014-11-17 14:08:57 +0000279 .Cases("v6t2", "v6z", "v6zk", arch)
280 .Cases("v7", "v7a", "v7em", "v7l", arch)
281 .Cases("v7m", "v7r", "v7s", arch)
282 .Cases("v8", "v8a", arch)
283 .Default(Triple::UnknownArch);
284}
285
Chandler Carruthaec97082012-02-21 08:53:32 +0000286static Triple::ArchType parseArch(StringRef ArchName) {
Joerg Sonnenberger429edc12015-01-26 11:41:48 +0000287 Triple::ArchType ARMArch(parseARMArch(ArchName));
288
Chandler Carruthaec97082012-02-21 08:53:32 +0000289 return StringSwitch<Triple::ArchType>(ArchName)
290 .Cases("i386", "i486", "i586", "i686", Triple::x86)
291 // FIXME: Do we need to support these?
292 .Cases("i786", "i886", "i986", Triple::x86)
Jim Grosbach664d1482013-11-16 00:52:57 +0000293 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000294 .Case("powerpc", Triple::ppc)
295 .Cases("powerpc64", "ppu", Triple::ppc64)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000296 .Case("powerpc64le", Triple::ppc64le)
Renato Golin609bf922014-11-17 14:08:57 +0000297 .Case("xscale", Triple::arm)
Joerg Sonnenberger429edc12015-01-26 11:41:48 +0000298 .Case("xscaleeb", Triple::armeb)
299 .StartsWith("arm", ARMArch)
300 .StartsWith("thumb", ARMArch)
301 .StartsWith("aarch64", ARMArch)
Chandler Carruthaec97082012-02-21 08:53:32 +0000302 .Case("msp430", Triple::msp430)
303 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruth0c7a7cc2012-02-22 11:32:54 +0000304 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruthaec97082012-02-21 08:53:32 +0000305 .Cases("mips64", "mips64eb", Triple::mips64)
306 .Case("mips64el", Triple::mips64el)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000307 .Case("r600", Triple::r600)
Tom Stellard07f11602015-01-06 18:00:00 +0000308 .Case("amdgcn", Triple::amdgcn)
Alexei Starovoitove4c8c802015-01-24 17:51:26 +0000309 .Case("bpf", Triple::bpf)
Chandler Carruthaec97082012-02-21 08:53:32 +0000310 .Case("hexagon", Triple::hexagon)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000311 .Case("s390x", Triple::systemz)
Chandler Carruthaec97082012-02-21 08:53:32 +0000312 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenabc3d232013-05-14 17:47:27 +0000313 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruthaec97082012-02-21 08:53:32 +0000314 .Case("tce", Triple::tce)
315 .Case("xcore", Triple::xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000316 .Case("nvptx", Triple::nvptx)
317 .Case("nvptx64", Triple::nvptx64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000318 .Case("le32", Triple::le32)
JF Bastien32972ef2014-09-12 17:54:17 +0000319 .Case("le64", Triple::le64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000320 .Case("amdil", Triple::amdil)
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000321 .Case("amdil64", Triple::amdil64)
322 .Case("hsail", Triple::hsail)
323 .Case("hsail64", Triple::hsail64)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000324 .Case("spir", Triple::spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000325 .Case("spir64", Triple::spir64)
Matthew Gardiner3b15a892014-09-05 06:46:43 +0000326 .StartsWith("kalimba", Triple::kalimba)
Chandler Carruthaec97082012-02-21 08:53:32 +0000327 .Default(Triple::UnknownArch);
Duncan Sands501dff72010-08-12 11:31:39 +0000328}
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000329
Chandler Carruthaec97082012-02-21 08:53:32 +0000330static Triple::VendorType parseVendor(StringRef VendorName) {
331 return StringSwitch<Triple::VendorType>(VendorName)
332 .Case("apple", Triple::Apple)
333 .Case("pc", Triple::PC)
334 .Case("scei", Triple::SCEI)
Hal Finkelf208af02012-04-02 18:31:33 +0000335 .Case("bgp", Triple::BGP)
336 .Case("bgq", Triple::BGQ)
Hal Finkelb5d177e2012-08-28 02:10:30 +0000337 .Case("fsl", Triple::Freescale)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000338 .Case("ibm", Triple::IBM)
Daniel Sandersc5626f42014-07-09 16:03:10 +0000339 .Case("img", Triple::ImaginationTechnologies)
Daniel Sandersdc6a9412014-07-18 14:28:19 +0000340 .Case("mti", Triple::MipsTechnologies)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000341 .Case("nvidia", Triple::NVIDIA)
Eric Christopher54fe1b22014-07-10 17:26:54 +0000342 .Case("csr", Triple::CSR)
Chandler Carruthaec97082012-02-21 08:53:32 +0000343 .Default(Triple::UnknownVendor);
Duncan Sands501dff72010-08-12 11:31:39 +0000344}
345
Chandler Carruthaec97082012-02-21 08:53:32 +0000346static Triple::OSType parseOS(StringRef OSName) {
347 return StringSwitch<Triple::OSType>(OSName)
Chandler Carruthaec97082012-02-21 08:53:32 +0000348 .StartsWith("darwin", Triple::Darwin)
349 .StartsWith("dragonfly", Triple::DragonFly)
350 .StartsWith("freebsd", Triple::FreeBSD)
351 .StartsWith("ios", Triple::IOS)
352 .StartsWith("kfreebsd", Triple::KFreeBSD)
353 .StartsWith("linux", Triple::Linux)
354 .StartsWith("lv2", Triple::Lv2)
355 .StartsWith("macosx", Triple::MacOSX)
Chandler Carruthaec97082012-02-21 08:53:32 +0000356 .StartsWith("netbsd", Triple::NetBSD)
357 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruthaec97082012-02-21 08:53:32 +0000358 .StartsWith("solaris", Triple::Solaris)
359 .StartsWith("win32", Triple::Win32)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000360 .StartsWith("windows", Triple::Win32)
Chandler Carruthaec97082012-02-21 08:53:32 +0000361 .StartsWith("haiku", Triple::Haiku)
362 .StartsWith("minix", Triple::Minix)
363 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyabe54632012-12-04 18:37:26 +0000364 .StartsWith("nacl", Triple::NaCl)
Hal Finkelf208af02012-04-02 18:31:33 +0000365 .StartsWith("cnk", Triple::CNK)
Eric Christopher22738d02012-08-06 20:52:18 +0000366 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000367 .StartsWith("aix", Triple::AIX)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000368 .StartsWith("cuda", Triple::CUDA)
369 .StartsWith("nvcl", Triple::NVCL)
Tom Stellard4082a6c2014-12-02 16:45:47 +0000370 .StartsWith("amdhsa", Triple::AMDHSA)
Alex Rosenberg38babd12015-01-25 22:46:59 +0000371 .StartsWith("ps4", Triple::PS4)
Chandler Carruthaec97082012-02-21 08:53:32 +0000372 .Default(Triple::UnknownOS);
Duncan Sands501dff72010-08-12 11:31:39 +0000373}
374
Chandler Carruthaec97082012-02-21 08:53:32 +0000375static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
376 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000377 .StartsWith("eabihf", Triple::EABIHF)
Chandler Carruthaec97082012-02-21 08:53:32 +0000378 .StartsWith("eabi", Triple::EABI)
379 .StartsWith("gnueabihf", Triple::GNUEABIHF)
380 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky0893e102013-01-22 18:02:49 +0000381 .StartsWith("gnux32", Triple::GNUX32)
David Woodhouse71d15ed2014-01-20 12:02:25 +0000382 .StartsWith("code16", Triple::CODE16)
Chandler Carruthaec97082012-02-21 08:53:32 +0000383 .StartsWith("gnu", Triple::GNU)
Logan Chien9ab55b82012-09-02 09:29:46 +0000384 .StartsWith("android", Triple::Android)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000385 .StartsWith("msvc", Triple::MSVC)
386 .StartsWith("itanium", Triple::Itanium)
387 .StartsWith("cygnus", Triple::Cygnus)
Chandler Carruthaec97082012-02-21 08:53:32 +0000388 .Default(Triple::UnknownEnvironment);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000389}
390
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000391static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
392 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
393 .EndsWith("coff", Triple::COFF)
394 .EndsWith("elf", Triple::ELF)
395 .EndsWith("macho", Triple::MachO)
396 .Default(Triple::UnknownObjectFormat);
397}
398
Renato Golinc17a07b2014-07-18 12:00:48 +0000399static Triple::SubArchType parseSubArch(StringRef SubArchName) {
Joerg Sonnenberger429edc12015-01-26 11:41:48 +0000400 if (SubArchName.endswith("eb"))
401 SubArchName = SubArchName.substr(0, SubArchName.size() - 2);
402
Renato Golinc17a07b2014-07-18 12:00:48 +0000403 return StringSwitch<Triple::SubArchType>(SubArchName)
404 .EndsWith("v8", Triple::ARMSubArch_v8)
405 .EndsWith("v8a", Triple::ARMSubArch_v8)
406 .EndsWith("v7", Triple::ARMSubArch_v7)
407 .EndsWith("v7a", Triple::ARMSubArch_v7)
408 .EndsWith("v7em", Triple::ARMSubArch_v7em)
409 .EndsWith("v7l", Triple::ARMSubArch_v7)
410 .EndsWith("v7m", Triple::ARMSubArch_v7m)
411 .EndsWith("v7r", Triple::ARMSubArch_v7)
412 .EndsWith("v7s", Triple::ARMSubArch_v7s)
413 .EndsWith("v6", Triple::ARMSubArch_v6)
414 .EndsWith("v6m", Triple::ARMSubArch_v6m)
Bradley Smithe997b452015-02-10 15:15:08 +0000415 .EndsWith("v6sm", Triple::ARMSubArch_v6m)
Renato Golinc17a07b2014-07-18 12:00:48 +0000416 .EndsWith("v6t2", Triple::ARMSubArch_v6t2)
417 .EndsWith("v5", Triple::ARMSubArch_v5)
418 .EndsWith("v5e", Triple::ARMSubArch_v5)
419 .EndsWith("v5t", Triple::ARMSubArch_v5)
420 .EndsWith("v5te", Triple::ARMSubArch_v5te)
421 .EndsWith("v4t", Triple::ARMSubArch_v4t)
Matthew Gardiner3b15a892014-09-05 06:46:43 +0000422 .EndsWith("kalimba3", Triple::KalimbaSubArch_v3)
423 .EndsWith("kalimba4", Triple::KalimbaSubArch_v4)
424 .EndsWith("kalimba5", Triple::KalimbaSubArch_v5)
Renato Golinc17a07b2014-07-18 12:00:48 +0000425 .Default(Triple::NoSubArch);
426}
427
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000428static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
429 switch (Kind) {
430 case Triple::UnknownObjectFormat: return "";
431 case Triple::COFF: return "coff";
432 case Triple::ELF: return "elf";
433 case Triple::MachO: return "macho";
434 }
435 llvm_unreachable("unknown object format type");
436}
437
438static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
439 if (T.isOSDarwin())
440 return Triple::MachO;
441 else if (T.isOSWindows())
442 return Triple::COFF;
443 return Triple::ELF;
444}
445
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000446/// \brief Construct a triple from the string representation provided.
447///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000448/// This stores the string representation and parses the various pieces into
449/// enum members.
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000450Triple::Triple(const Twine &Str)
451 : Data(Str.str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000452 Arch(parseArch(getArchName())),
Renato Golinc17a07b2014-07-18 12:00:48 +0000453 SubArch(parseSubArch(getArchName())),
Chandler Carruthaec97082012-02-21 08:53:32 +0000454 Vendor(parseVendor(getVendorName())),
455 OS(parseOS(getOSName())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000456 Environment(parseEnvironment(getEnvironmentName())),
457 ObjectFormat(parseFormat(getEnvironmentName())) {
458 if (ObjectFormat == Triple::UnknownObjectFormat)
459 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000460}
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000461
462/// \brief Construct a triple from string representations of the architecture,
463/// vendor, and OS.
464///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000465/// This joins each argument into a canonical string representation and parses
466/// them into enum members. It leaves the environment unknown and omits it from
467/// the string representation.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000468Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
469 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000470 Arch(parseArch(ArchStr.str())),
Renato Golinc17a07b2014-07-18 12:00:48 +0000471 SubArch(parseSubArch(ArchStr.str())),
Chandler Carruthaec97082012-02-21 08:53:32 +0000472 Vendor(parseVendor(VendorStr.str())),
473 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000474 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
475 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000476}
477
478/// \brief Construct a triple from string representations of the architecture,
479/// vendor, OS, and environment.
480///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000481/// This joins each argument into a canonical string representation and parses
482/// them into enum members.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000483Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
484 const Twine &EnvironmentStr)
485 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
486 EnvironmentStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000487 Arch(parseArch(ArchStr.str())),
Renato Golinc17a07b2014-07-18 12:00:48 +0000488 SubArch(parseSubArch(ArchStr.str())),
Chandler Carruthaec97082012-02-21 08:53:32 +0000489 Vendor(parseVendor(VendorStr.str())),
490 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000491 Environment(parseEnvironment(EnvironmentStr.str())),
492 ObjectFormat(parseFormat(EnvironmentStr.str())) {
493 if (ObjectFormat == Triple::UnknownObjectFormat)
494 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000495}
496
Duncan Sands501dff72010-08-12 11:31:39 +0000497std::string Triple::normalize(StringRef Str) {
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000498 bool IsMinGW32 = false;
499 bool IsCygwin = false;
500
Duncan Sands501dff72010-08-12 11:31:39 +0000501 // Parse into components.
502 SmallVector<StringRef, 4> Components;
Chandler Carruth6ea6de72012-02-21 09:12:48 +0000503 Str.split(Components, "-");
Duncan Sands501dff72010-08-12 11:31:39 +0000504
505 // If the first component corresponds to a known architecture, preferentially
506 // use it for the architecture. If the second component corresponds to a
507 // known vendor, preferentially use it for the vendor, etc. This avoids silly
508 // component movement when a component parses as (eg) both a valid arch and a
509 // valid os.
510 ArchType Arch = UnknownArch;
511 if (Components.size() > 0)
Chandler Carruthaec97082012-02-21 08:53:32 +0000512 Arch = parseArch(Components[0]);
Duncan Sands501dff72010-08-12 11:31:39 +0000513 VendorType Vendor = UnknownVendor;
514 if (Components.size() > 1)
Chandler Carruthaec97082012-02-21 08:53:32 +0000515 Vendor = parseVendor(Components[1]);
Duncan Sands501dff72010-08-12 11:31:39 +0000516 OSType OS = UnknownOS;
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000517 if (Components.size() > 2) {
Chandler Carruthaec97082012-02-21 08:53:32 +0000518 OS = parseOS(Components[2]);
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000519 IsCygwin = Components[2].startswith("cygwin");
520 IsMinGW32 = Components[2].startswith("mingw");
521 }
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000522 EnvironmentType Environment = UnknownEnvironment;
523 if (Components.size() > 3)
Chandler Carruthaec97082012-02-21 08:53:32 +0000524 Environment = parseEnvironment(Components[3]);
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000525 ObjectFormatType ObjectFormat = UnknownObjectFormat;
Saleem Abdulrasoolf80b49b2014-03-30 07:19:31 +0000526 if (Components.size() > 4)
527 ObjectFormat = parseFormat(Components[4]);
Duncan Sands501dff72010-08-12 11:31:39 +0000528
529 // Note which components are already in their final position. These will not
530 // be moved.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000531 bool Found[4];
Duncan Sands501dff72010-08-12 11:31:39 +0000532 Found[0] = Arch != UnknownArch;
533 Found[1] = Vendor != UnknownVendor;
534 Found[2] = OS != UnknownOS;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000535 Found[3] = Environment != UnknownEnvironment;
Duncan Sands501dff72010-08-12 11:31:39 +0000536
537 // If they are not there already, permute the components into their canonical
538 // positions by seeing if they parse as a valid architecture, and if so moving
539 // the component to the architecture position etc.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000540 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands501dff72010-08-12 11:31:39 +0000541 if (Found[Pos])
542 continue; // Already in the canonical position.
543
544 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
545 // Do not reparse any components that already matched.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000546 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands501dff72010-08-12 11:31:39 +0000547 continue;
548
549 // Does this component parse as valid for the target position?
550 bool Valid = false;
551 StringRef Comp = Components[Idx];
552 switch (Pos) {
Craig Toppera2886c22012-02-07 05:05:23 +0000553 default: llvm_unreachable("unexpected component type!");
Duncan Sands501dff72010-08-12 11:31:39 +0000554 case 0:
Chandler Carruthaec97082012-02-21 08:53:32 +0000555 Arch = parseArch(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000556 Valid = Arch != UnknownArch;
557 break;
558 case 1:
Chandler Carruthaec97082012-02-21 08:53:32 +0000559 Vendor = parseVendor(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000560 Valid = Vendor != UnknownVendor;
561 break;
562 case 2:
Chandler Carruthaec97082012-02-21 08:53:32 +0000563 OS = parseOS(Comp);
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000564 IsCygwin = Comp.startswith("cygwin");
565 IsMinGW32 = Comp.startswith("mingw");
566 Valid = OS != UnknownOS || IsCygwin || IsMinGW32;
Duncan Sands501dff72010-08-12 11:31:39 +0000567 break;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000568 case 3:
Chandler Carruthaec97082012-02-21 08:53:32 +0000569 Environment = parseEnvironment(Comp);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000570 Valid = Environment != UnknownEnvironment;
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000571 if (!Valid) {
572 ObjectFormat = parseFormat(Comp);
573 Valid = ObjectFormat != UnknownObjectFormat;
574 }
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000575 break;
Duncan Sands501dff72010-08-12 11:31:39 +0000576 }
577 if (!Valid)
578 continue; // Nope, try the next component.
579
580 // Move the component to the target position, pushing any non-fixed
581 // components that are in the way to the right. This tends to give
582 // good results in the common cases of a forgotten vendor component
583 // or a wrongly positioned environment.
584 if (Pos < Idx) {
585 // Insert left, pushing the existing components to the right. For
586 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
587 StringRef CurrentComponent(""); // The empty component.
588 // Replace the component we are moving with an empty component.
589 std::swap(CurrentComponent, Components[Idx]);
590 // Insert the component being moved at Pos, displacing any existing
591 // components to the right.
592 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
593 // Skip over any fixed components.
Chandler Carruth362087b2012-02-21 09:29:14 +0000594 while (i < array_lengthof(Found) && Found[i])
595 ++i;
Duncan Sands501dff72010-08-12 11:31:39 +0000596 // Place the component at the new position, getting the component
597 // that was at this position - it will be moved right.
598 std::swap(CurrentComponent, Components[i]);
599 }
600 } else if (Pos > Idx) {
601 // Push right by inserting empty components until the component at Idx
602 // reaches the target position Pos. For example, pc-a -> -pc-a when
603 // moving pc to the second position.
604 do {
605 // Insert one empty component at Idx.
606 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000607 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands501dff72010-08-12 11:31:39 +0000608 // Place the component at the new position, getting the component
609 // that was at this position - it will be moved right.
610 std::swap(CurrentComponent, Components[i]);
611 // If it was placed on top of an empty component then we are done.
612 if (CurrentComponent.empty())
613 break;
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000614 // Advance to the next component, skipping any fixed components.
Anders Carlsson630125a2011-02-05 18:19:35 +0000615 while (++i < array_lengthof(Found) && Found[i])
616 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000617 }
618 // The last component was pushed off the end - append it.
619 if (!CurrentComponent.empty())
620 Components.push_back(CurrentComponent);
621
622 // Advance Idx to the component's new position.
Chandler Carruth362087b2012-02-21 09:29:14 +0000623 while (++Idx < array_lengthof(Found) && Found[Idx])
624 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000625 } while (Idx < Pos); // Add more until the final position is reached.
626 }
627 assert(Pos < Components.size() && Components[Pos] == Comp &&
628 "Component moved wrong!");
629 Found[Pos] = true;
630 break;
631 }
632 }
633
634 // Special case logic goes here. At this point Arch, Vendor and OS have the
635 // correct values for the computed components.
636
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000637 if (OS == Triple::Win32) {
638 Components.resize(4);
639 Components[2] = "windows";
Saleem Abdulrasoolf80b49b2014-03-30 07:19:31 +0000640 if (Environment == UnknownEnvironment) {
Saleem Abdulrasool28b82bc2014-03-31 16:34:41 +0000641 if (ObjectFormat == UnknownObjectFormat || ObjectFormat == Triple::COFF)
Saleem Abdulrasoolf80b49b2014-03-30 07:19:31 +0000642 Components[3] = "msvc";
643 else
644 Components[3] = getObjectFormatTypeName(ObjectFormat);
Saleem Abdulrasoolf80b49b2014-03-30 07:19:31 +0000645 }
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000646 } else if (IsMinGW32) {
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000647 Components.resize(4);
648 Components[2] = "windows";
Saleem Abdulrasool28b82bc2014-03-31 16:34:41 +0000649 Components[3] = "gnu";
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000650 } else if (IsCygwin) {
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000651 Components.resize(4);
652 Components[2] = "windows";
653 Components[3] = "cygnus";
654 }
Saleem Abdulrasool0e1b31c2014-08-09 23:12:20 +0000655 if (IsMinGW32 || IsCygwin ||
Saleem Abdulrasool28b82bc2014-03-31 16:34:41 +0000656 (OS == Triple::Win32 && Environment != UnknownEnvironment)) {
657 if (ObjectFormat != UnknownObjectFormat && ObjectFormat != Triple::COFF) {
658 Components.resize(5);
659 Components[4] = getObjectFormatTypeName(ObjectFormat);
660 }
661 }
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000662
Duncan Sands501dff72010-08-12 11:31:39 +0000663 // Stick the corrected components back together to form the normalized string.
664 std::string Normalized;
665 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
666 if (i) Normalized += '-';
667 Normalized += Components[i];
668 }
669 return Normalized;
670}
671
Daniel Dunbar19e70762009-07-26 03:31:47 +0000672StringRef Triple::getArchName() const {
673 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000674}
675
Daniel Dunbar19e70762009-07-26 03:31:47 +0000676StringRef Triple::getVendorName() const {
677 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
678 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000679}
680
Daniel Dunbar19e70762009-07-26 03:31:47 +0000681StringRef Triple::getOSName() const {
682 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
683 Tmp = Tmp.split('-').second; // Strip second component
684 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000685}
686
Daniel Dunbar19e70762009-07-26 03:31:47 +0000687StringRef Triple::getEnvironmentName() const {
688 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
689 Tmp = Tmp.split('-').second; // Strip second component
690 return Tmp.split('-').second; // Strip third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000691}
692
Daniel Dunbar19e70762009-07-26 03:31:47 +0000693StringRef Triple::getOSAndEnvironmentName() const {
694 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
695 return Tmp.split('-').second; // Strip second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000696}
697
Chris Lattner553c9f32009-08-12 06:19:40 +0000698static unsigned EatNumber(StringRef &Str) {
699 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000700 unsigned Result = 0;
Jim Grosbachf638b262010-12-17 02:10:59 +0000701
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000702 do {
703 // Consume the leading digit.
Chris Lattner553c9f32009-08-12 06:19:40 +0000704 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000705
Chris Lattner553c9f32009-08-12 06:19:40 +0000706 // Eat the digit.
707 Str = Str.substr(1);
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000708 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbachf638b262010-12-17 02:10:59 +0000709
Chris Lattner553c9f32009-08-12 06:19:40 +0000710 return Result;
711}
712
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000713void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
714 unsigned &Micro) const {
Chris Lattner553c9f32009-08-12 06:19:40 +0000715 StringRef OSName = getOSName();
Jim Grosbachf638b262010-12-17 02:10:59 +0000716
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000717 // Assume that the OS portion of the triple starts with the canonical name.
718 StringRef OSTypeName = getOSTypeName(getOS());
719 if (OSName.startswith(OSTypeName))
720 OSName = OSName.substr(OSTypeName.size());
Jim Grosbachf638b262010-12-17 02:10:59 +0000721
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000722 // Any unset version defaults to 0.
723 Major = Minor = Micro = 0;
Chris Lattner553c9f32009-08-12 06:19:40 +0000724
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000725 // Parse up to three components.
726 unsigned *Components[3] = { &Major, &Minor, &Micro };
727 for (unsigned i = 0; i != 3; ++i) {
728 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
729 break;
Chris Lattner553c9f32009-08-12 06:19:40 +0000730
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000731 // Consume the leading number.
732 *Components[i] = EatNumber(OSName);
Jim Grosbachf638b262010-12-17 02:10:59 +0000733
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000734 // Consume the separator, if present.
735 if (OSName.startswith("."))
736 OSName = OSName.substr(1);
737 }
Chris Lattner553c9f32009-08-12 06:19:40 +0000738}
739
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000740bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
741 unsigned &Micro) const {
742 getOSVersion(Major, Minor, Micro);
743
744 switch (getOS()) {
Craig Toppera2886c22012-02-07 05:05:23 +0000745 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000746 case Darwin:
747 // Default to darwin8, i.e., MacOSX 10.4.
748 if (Major == 0)
749 Major = 8;
750 // Darwin version numbers are skewed from OS X versions.
751 if (Major < 4)
752 return false;
753 Micro = 0;
754 Minor = Major - 4;
755 Major = 10;
756 break;
757 case MacOSX:
758 // Default to 10.4.
759 if (Major == 0) {
760 Major = 10;
761 Minor = 4;
762 }
763 if (Major != 10)
764 return false;
765 break;
766 case IOS:
767 // Ignore the version from the triple. This is only handled because the
768 // the clang driver combines OS X and IOS support into a common Darwin
769 // toolchain that wants to know the OS X version number even when targeting
770 // IOS.
771 Major = 10;
772 Minor = 4;
773 Micro = 0;
774 break;
775 }
776 return true;
777}
778
Chad Rosierd84eaac2012-05-09 17:23:48 +0000779void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
780 unsigned &Micro) const {
781 switch (getOS()) {
782 default: llvm_unreachable("unexpected OS for Darwin triple");
783 case Darwin:
784 case MacOSX:
785 // Ignore the version from the triple. This is only handled because the
786 // the clang driver combines OS X and IOS support into a common Darwin
787 // toolchain that wants to know the iOS version number even when targeting
788 // OS X.
Tim Northover3e8df692013-12-10 11:53:16 +0000789 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000790 Minor = 0;
791 Micro = 0;
Chad Rosier2778cbc2012-05-09 17:38:47 +0000792 break;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000793 case IOS:
794 getOSVersion(Major, Minor, Micro);
Tim Northover00ed9962014-03-29 10:18:08 +0000795 // Default to 5.0 (or 7.0 for arm64).
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000796 if (Major == 0)
Tim Northovere19bed72014-07-23 12:32:47 +0000797 Major = (getArch() == aarch64) ? 7 : 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000798 break;
799 }
800}
801
Daniel Dunbar19e70762009-07-26 03:31:47 +0000802void Triple::setTriple(const Twine &Str) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000803 *this = Triple(Str);
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000804}
805
806void Triple::setArch(ArchType Kind) {
807 setArchName(getArchTypeName(Kind));
808}
809
810void Triple::setVendor(VendorType Kind) {
811 setVendorName(getVendorTypeName(Kind));
812}
813
814void Triple::setOS(OSType Kind) {
815 setOSName(getOSTypeName(Kind));
816}
817
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000818void Triple::setEnvironment(EnvironmentType Kind) {
Reid Kleckner5fe405d2015-02-13 22:05:50 +0000819 if (ObjectFormat == getDefaultFormat(*this))
820 return setEnvironmentName(getEnvironmentTypeName(Kind));
821
822 setEnvironmentName((getEnvironmentTypeName(Kind) + Twine("-") +
823 getObjectFormatTypeName(ObjectFormat)).str());
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000824}
825
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000826void Triple::setObjectFormat(ObjectFormatType Kind) {
Saleem Abdulrasool28b82bc2014-03-31 16:34:41 +0000827 if (Environment == UnknownEnvironment)
828 return setEnvironmentName(getObjectFormatTypeName(Kind));
829
Benjamin Kramercccdadc2014-07-08 14:55:06 +0000830 setEnvironmentName((getEnvironmentTypeName(Environment) + Twine("-") +
831 getObjectFormatTypeName(Kind)).str());
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000832}
833
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000834void Triple::setArchName(StringRef Str) {
Jeffrey Yasskine2595b52009-10-06 21:45:26 +0000835 // Work around a miscompilation bug for Twines in gcc 4.0.3.
836 SmallString<64> Triple;
837 Triple += Str;
838 Triple += "-";
839 Triple += getVendorName();
840 Triple += "-";
841 Triple += getOSAndEnvironmentName();
842 setTriple(Triple.str());
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000843}
844
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000845void Triple::setVendorName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000846 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
847}
848
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000849void Triple::setOSName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000850 if (hasEnvironment())
851 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
852 "-" + getEnvironmentName());
853 else
854 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
855}
856
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000857void Triple::setEnvironmentName(StringRef Str) {
858 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000859 "-" + Str);
860}
861
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000862void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000863 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
864}
Chandler Carruthb90c1022012-01-31 04:52:32 +0000865
866static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
867 switch (Arch) {
868 case llvm::Triple::UnknownArch:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000869 return 0;
870
871 case llvm::Triple::msp430:
872 return 16;
873
Chandler Carruthb90c1022012-01-31 04:52:32 +0000874 case llvm::Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000875 case llvm::Triple::armeb:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000876 case llvm::Triple::hexagon:
877 case llvm::Triple::le32:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000878 case llvm::Triple::mips:
879 case llvm::Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000880 case llvm::Triple::nvptx:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000881 case llvm::Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000882 case llvm::Triple::r600:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000883 case llvm::Triple::sparc:
884 case llvm::Triple::tce:
885 case llvm::Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000886 case llvm::Triple::thumbeb:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000887 case llvm::Triple::x86:
888 case llvm::Triple::xcore:
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000889 case llvm::Triple::amdil:
890 case llvm::Triple::hsail:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000891 case llvm::Triple::spir:
Eric Christopher54fe1b22014-07-10 17:26:54 +0000892 case llvm::Triple::kalimba:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000893 return 32;
894
Tim Northovere0e3aef2013-01-31 12:12:40 +0000895 case llvm::Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000896 case llvm::Triple::aarch64_be:
Tom Stellard07f11602015-01-06 18:00:00 +0000897 case llvm::Triple::amdgcn:
Alexei Starovoitove4c8c802015-01-24 17:51:26 +0000898 case llvm::Triple::bpf:
JF Bastien32972ef2014-09-12 17:54:17 +0000899 case llvm::Triple::le64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000900 case llvm::Triple::mips64:
901 case llvm::Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000902 case llvm::Triple::nvptx64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000903 case llvm::Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000904 case llvm::Triple::ppc64le:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000905 case llvm::Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000906 case llvm::Triple::systemz:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000907 case llvm::Triple::x86_64:
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000908 case llvm::Triple::amdil64:
909 case llvm::Triple::hsail64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000910 case llvm::Triple::spir64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000911 return 64;
912 }
913 llvm_unreachable("Invalid architecture value");
914}
915
916bool Triple::isArch64Bit() const {
917 return getArchPointerBitWidth(getArch()) == 64;
918}
919
920bool Triple::isArch32Bit() const {
921 return getArchPointerBitWidth(getArch()) == 32;
922}
923
924bool Triple::isArch16Bit() const {
925 return getArchPointerBitWidth(getArch()) == 16;
926}
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000927
928Triple Triple::get32BitArchVariant() const {
929 Triple T(*this);
930 switch (getArch()) {
931 case Triple::UnknownArch:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000932 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000933 case Triple::aarch64_be:
Tom Stellard07f11602015-01-06 18:00:00 +0000934 case Triple::amdgcn:
Alexei Starovoitove4c8c802015-01-24 17:51:26 +0000935 case Triple::bpf:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000936 case Triple::msp430:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000937 case Triple::systemz:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000938 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000939 T.setArch(UnknownArch);
940 break;
941
942 case Triple::amdil:
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000943 case Triple::hsail:
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000944 case Triple::spir:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000945 case Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000946 case Triple::armeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000947 case Triple::hexagon:
Eric Christopher54fe1b22014-07-10 17:26:54 +0000948 case Triple::kalimba:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000949 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000950 case Triple::mips:
951 case Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000952 case Triple::nvptx:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000953 case Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000954 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000955 case Triple::sparc:
956 case Triple::tce:
957 case Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000958 case Triple::thumbeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000959 case Triple::x86:
960 case Triple::xcore:
961 // Already 32-bit.
962 break;
963
JF Bastien32972ef2014-09-12 17:54:17 +0000964 case Triple::le64: T.setArch(Triple::le32); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000965 case Triple::mips64: T.setArch(Triple::mips); break;
966 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000967 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Bob Wilsona2790b12014-03-09 23:17:28 +0000968 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000969 case Triple::sparcv9: T.setArch(Triple::sparc); break;
970 case Triple::x86_64: T.setArch(Triple::x86); break;
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000971 case Triple::amdil64: T.setArch(Triple::amdil); break;
972 case Triple::hsail64: T.setArch(Triple::hsail); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000973 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000974 }
975 return T;
976}
977
978Triple Triple::get64BitArchVariant() const {
979 Triple T(*this);
980 switch (getArch()) {
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000981 case Triple::UnknownArch:
Tim Northoveraf6bfb22014-03-30 07:25:23 +0000982 case Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000983 case Triple::armeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000984 case Triple::hexagon:
Eric Christopher54fe1b22014-07-10 17:26:54 +0000985 case Triple::kalimba:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000986 case Triple::msp430:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000987 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000988 case Triple::tce:
989 case Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000990 case Triple::thumbeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000991 case Triple::xcore:
992 T.setArch(UnknownArch);
993 break;
994
Tim Northovere0e3aef2013-01-31 12:12:40 +0000995 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000996 case Triple::aarch64_be:
Alexei Starovoitove4c8c802015-01-24 17:51:26 +0000997 case Triple::bpf:
JF Bastien32972ef2014-09-12 17:54:17 +0000998 case Triple::le64:
Matt Arsenault3f9b0212014-09-19 19:52:11 +0000999 case Triple::amdil64:
Tom Stellard07f11602015-01-06 18:00:00 +00001000 case Triple::amdgcn:
Matt Arsenault3f9b0212014-09-19 19:52:11 +00001001 case Triple::hsail64:
1002 case Triple::spir64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001003 case Triple::mips64:
1004 case Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +00001005 case Triple::nvptx64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001006 case Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +00001007 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001008 case Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +00001009 case Triple::systemz:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001010 case Triple::x86_64:
1011 // Already 64-bit.
1012 break;
1013
JF Bastien32972ef2014-09-12 17:54:17 +00001014 case Triple::le32: T.setArch(Triple::le64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001015 case Triple::mips: T.setArch(Triple::mips64); break;
1016 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +00001017 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001018 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001019 case Triple::sparc: T.setArch(Triple::sparcv9); break;
1020 case Triple::x86: T.setArch(Triple::x86_64); break;
Matt Arsenault3f9b0212014-09-19 19:52:11 +00001021 case Triple::amdil: T.setArch(Triple::amdil64); break;
1022 case Triple::hsail: T.setArch(Triple::hsail64); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +00001023 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +00001024 }
1025 return T;
1026}
Argyrios Kyrtzidis730abd22014-07-11 21:44:54 +00001027
1028// FIXME: tblgen this.
1029const char *Triple::getARMCPUForArch(StringRef MArch) const {
1030 if (MArch.empty())
1031 MArch = getArchName();
1032
1033 switch (getOS()) {
Ed Masteea0257a2014-09-09 17:47:24 +00001034 case llvm::Triple::FreeBSD:
Argyrios Kyrtzidis730abd22014-07-11 21:44:54 +00001035 case llvm::Triple::NetBSD:
1036 if (MArch == "armv6")
1037 return "arm1176jzf-s";
1038 break;
1039 case llvm::Triple::Win32:
1040 // FIXME: this is invalid for WindowsCE
1041 return "cortex-a9";
1042 default:
1043 break;
1044 }
1045
1046 const char *result = nullptr;
1047 size_t offset = StringRef::npos;
1048 if (MArch.startswith("arm"))
1049 offset = 3;
1050 if (MArch.startswith("thumb"))
1051 offset = 5;
1052 if (offset != StringRef::npos && MArch.substr(offset, 2) == "eb")
1053 offset += 2;
Joerg Sonnenberger429edc12015-01-26 11:41:48 +00001054 if (MArch.endswith("eb"))
1055 MArch = MArch.substr(0, MArch.size() - 2);
Argyrios Kyrtzidis730abd22014-07-11 21:44:54 +00001056 if (offset != StringRef::npos)
1057 result = llvm::StringSwitch<const char *>(MArch.substr(offset))
1058 .Cases("v2", "v2a", "arm2")
1059 .Case("v3", "arm6")
1060 .Case("v3m", "arm7m")
1061 .Case("v4", "strongarm")
1062 .Case("v4t", "arm7tdmi")
1063 .Cases("v5", "v5t", "arm10tdmi")
1064 .Cases("v5e", "v5te", "arm1022e")
1065 .Case("v5tej", "arm926ej-s")
1066 .Cases("v6", "v6k", "arm1136jf-s")
1067 .Case("v6j", "arm1136j-s")
1068 .Cases("v6z", "v6zk", "arm1176jzf-s")
1069 .Case("v6t2", "arm1156t2-s")
Bradley Smithe997b452015-02-10 15:15:08 +00001070 .Cases("v6m", "v6-m", "v6sm", "v6s-m", "cortex-m0")
Argyrios Kyrtzidis730abd22014-07-11 21:44:54 +00001071 .Cases("v7", "v7a", "v7-a", "v7l", "v7-l", "cortex-a8")
1072 .Cases("v7s", "v7-s", "swift")
1073 .Cases("v7r", "v7-r", "cortex-r4")
1074 .Cases("v7m", "v7-m", "cortex-m3")
1075 .Cases("v7em", "v7e-m", "cortex-m4")
1076 .Cases("v8", "v8a", "v8-a", "cortex-a53")
1077 .Default(nullptr);
1078 else
1079 result = llvm::StringSwitch<const char *>(MArch)
1080 .Case("ep9312", "ep9312")
1081 .Case("iwmmxt", "iwmmxt")
1082 .Case("xscale", "xscale")
1083 .Default(nullptr);
1084
1085 if (result)
1086 return result;
1087
1088 // If all else failed, return the most base CPU with thumb interworking
1089 // supported by LLVM.
1090 // FIXME: Should warn once that we're falling back.
1091 switch (getOS()) {
1092 case llvm::Triple::NetBSD:
1093 switch (getEnvironment()) {
1094 case llvm::Triple::GNUEABIHF:
1095 case llvm::Triple::GNUEABI:
1096 case llvm::Triple::EABIHF:
1097 case llvm::Triple::EABI:
1098 return "arm926ej-s";
1099 default:
1100 return "strongarm";
1101 }
1102 default:
1103 switch (getEnvironment()) {
1104 case llvm::Triple::EABIHF:
1105 case llvm::Triple::GNUEABIHF:
1106 return "arm1176jzf-s";
1107 default:
1108 return "arm7tdmi";
1109 }
1110 }
1111}