blob: 904bd29cd6ff9f6d7415592cbf897e12cc9f3b99 [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";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000026 case hexagon: return "hexagon";
27 case mips: return "mips";
28 case mipsel: return "mipsel";
29 case mips64: return "mips64";
30 case mips64el: return "mips64el";
31 case msp430: return "msp430";
32 case ppc64: return "powerpc64";
33 case ppc64le: return "powerpc64le";
34 case ppc: return "powerpc";
35 case r600: return "r600";
36 case sparc: return "sparc";
37 case sparcv9: return "sparcv9";
38 case systemz: return "s390x";
39 case tce: return "tce";
40 case thumb: return "thumb";
Christian Pirker2a111602014-03-28 14:35:30 +000041 case thumbeb: return "thumbeb";
Christian Pirker6c2f4d42014-02-24 11:34:50 +000042 case x86: return "i386";
43 case x86_64: return "x86_64";
44 case xcore: return "xcore";
45 case nvptx: return "nvptx";
46 case nvptx64: return "nvptx64";
47 case le32: return "le32";
48 case amdil: return "amdil";
49 case spir: return "spir";
50 case spir64: return "spir64";
Daniel Dunbar4abd5662009-04-01 21:53:23 +000051 }
52
David Blaikie46a9f012012-01-20 21:51:11 +000053 llvm_unreachable("Invalid ArchType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +000054}
55
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000056const char *Triple::getArchTypePrefix(ArchType Kind) {
57 switch (Kind) {
58 default:
59 return 0;
60
Christian Pirker6c2f4d42014-02-24 11:34:50 +000061 case aarch64:
62 case aarch64_be: return "aarch64";
Tim Northovere0e3aef2013-01-31 12:12:40 +000063
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000064 case arm:
Christian Pirker2a111602014-03-28 14:35:30 +000065 case armeb:
66 case thumb:
67 case thumbeb: return "arm";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000068
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000069 case ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +000070 case ppc64le:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000071 case ppc: return "ppc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000072
Benjamin Kramerae3c3002012-06-28 19:09:53 +000073 case mips:
74 case mipsel:
75 case mips64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000076 case mips64el: return "mips";
Benjamin Kramerae3c3002012-06-28 19:09:53 +000077
Christian Pirker6c2f4d42014-02-24 11:34:50 +000078 case hexagon: return "hexagon";
Tony Linthicum1213a7a2011-12-12 21:14:40 +000079
Christian Pirker6c2f4d42014-02-24 11:34:50 +000080 case r600: return "r600";
Anton Korobeynikovf32638d2012-03-09 10:09:36 +000081
Chris Lattner8228b112010-02-04 06:34:01 +000082 case sparcv9:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000083 case sparc: return "sparc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000084
Christian Pirker6c2f4d42014-02-24 11:34:50 +000085 case systemz: return "systemz";
Richard Sandiforda238c5e2013-05-03 11:05:17 +000086
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000087 case x86:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000088 case x86_64: return "x86";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000089
Christian Pirker6c2f4d42014-02-24 11:34:50 +000090 case xcore: return "xcore";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000091
Christian Pirker6c2f4d42014-02-24 11:34:50 +000092 case nvptx: return "nvptx";
93 case nvptx64: return "nvptx";
94 case le32: return "le32";
95 case amdil: return "amdil";
96 case spir: return "spir";
97 case spir64: return "spir";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000098 }
99}
100
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000101const char *Triple::getVendorTypeName(VendorType Kind) {
102 switch (Kind) {
103 case UnknownVendor: return "unknown";
104
105 case Apple: return "apple";
Chris Lattner07921952009-08-14 18:48:13 +0000106 case PC: return "pc";
John Thompsond0332e42011-03-15 21:51:56 +0000107 case SCEI: return "scei";
Hal Finkelf208af02012-04-02 18:31:33 +0000108 case BGP: return "bgp";
109 case BGQ: return "bgq";
Hal Finkelb5d177e2012-08-28 02:10:30 +0000110 case Freescale: return "fsl";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000111 case IBM: return "ibm";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000112 case NVIDIA: return "nvidia";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000113 }
114
David Blaikie46a9f012012-01-20 21:51:11 +0000115 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000116}
117
118const char *Triple::getOSTypeName(OSType Kind) {
119 switch (Kind) {
120 case UnknownOS: return "unknown";
121
Duncan Sands0de39b42009-06-19 14:40:01 +0000122 case AuroraUX: return "auroraux";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000123 case Cygwin: return "cygwin";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000124 case Darwin: return "darwin";
Daniel Dunbare3384c42009-05-22 02:24:11 +0000125 case DragonFly: return "dragonfly";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000126 case FreeBSD: return "freebsd";
Daniel Dunbard74bac72011-04-19 20:19:27 +0000127 case IOS: return "ios";
Duncan Sandsfe44f672011-07-26 15:30:04 +0000128 case KFreeBSD: return "kfreebsd";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000129 case Linux: return "linux";
Edward O'Callaghanba993b82009-11-19 11:59:00 +0000130 case Lv2: return "lv2";
Daniel Dunbar0854f342011-04-19 23:34:12 +0000131 case MacOSX: return "macosx";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000132 case MinGW32: return "mingw32";
Chris Lattner01218d52009-07-13 20:22:23 +0000133 case NetBSD: return "netbsd";
Duncan Sands14814d42009-06-29 13:36:13 +0000134 case OpenBSD: return "openbsd";
Daniel Dunbar781f94d2009-08-18 04:43:27 +0000135 case Solaris: return "solaris";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000136 case Win32: return "windows";
Chris Lattner27f20492009-10-16 02:06:30 +0000137 case Haiku: return "haiku";
Chris Lattnerca97c922010-07-07 15:52:27 +0000138 case Minix: return "minix";
Douglas Gregorde3c9262011-07-01 22:41:06 +0000139 case RTEMS: return "rtems";
Eli Benderskyabe54632012-12-04 18:37:26 +0000140 case NaCl: return "nacl";
Hal Finkelf208af02012-04-02 18:31:33 +0000141 case CNK: return "cnk";
Eric Christopher22738d02012-08-06 20:52:18 +0000142 case Bitrig: return "bitrig";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000143 case AIX: return "aix";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000144 case CUDA: return "cuda";
145 case NVCL: return "nvcl";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000146 }
147
David Blaikie46a9f012012-01-20 21:51:11 +0000148 llvm_unreachable("Invalid OSType");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000149}
150
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000151const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
152 switch (Kind) {
153 case UnknownEnvironment: return "unknown";
Renato Golin83758d5c2011-01-21 18:25:47 +0000154 case GNU: return "gnu";
Rafael Espindolaf5e78fa2012-01-18 23:35:29 +0000155 case GNUEABIHF: return "gnueabihf";
Renato Golin83758d5c2011-01-21 18:25:47 +0000156 case GNUEABI: return "gnueabi";
Eli Bendersky0893e102013-01-22 18:02:49 +0000157 case GNUX32: return "gnux32";
David Woodhouse71d15ed2014-01-20 12:02:25 +0000158 case CODE16: return "code16";
Renato Golin83758d5c2011-01-21 18:25:47 +0000159 case EABI: return "eabi";
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000160 case EABIHF: return "eabihf";
Logan Chien9ab55b82012-09-02 09:29:46 +0000161 case Android: return "android";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000162 case MSVC: return "msvc";
163 case Itanium: return "itanium";
164 case Cygnus: return "cygnus";
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000165 }
166
David Blaikie46a9f012012-01-20 21:51:11 +0000167 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000168}
169
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000170Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruthff6f3562012-02-12 09:27:38 +0000171 return StringSwitch<Triple::ArchType>(Name)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000172 .Case("aarch64", aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000173 .Case("aarch64_be", aarch64_be)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000174 .Case("arm", arm)
Christian Pirker2a111602014-03-28 14:35:30 +0000175 .Case("armeb", armeb)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000176 .Case("mips", mips)
177 .Case("mipsel", mipsel)
178 .Case("mips64", mips64)
179 .Case("mips64el", mips64el)
180 .Case("msp430", msp430)
181 .Case("ppc64", ppc64)
182 .Case("ppc32", ppc)
183 .Case("ppc", ppc)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000184 .Case("ppc64le", ppc64le)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000185 .Case("r600", r600)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000186 .Case("hexagon", hexagon)
187 .Case("sparc", sparc)
188 .Case("sparcv9", sparcv9)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000189 .Case("systemz", systemz)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000190 .Case("tce", tce)
191 .Case("thumb", thumb)
Christian Pirker2a111602014-03-28 14:35:30 +0000192 .Case("thumbeb", thumbeb)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000193 .Case("x86", x86)
194 .Case("x86-64", x86_64)
195 .Case("xcore", xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000196 .Case("nvptx", nvptx)
197 .Case("nvptx64", nvptx64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000198 .Case("le32", le32)
199 .Case("amdil", amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000200 .Case("spir", spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000201 .Case("spir64", spir64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000202 .Default(UnknownArch);
Daniel Dunbar0f16ea52009-08-03 04:03:51 +0000203}
204
Duncan Sands8712da32010-03-24 09:05:14 +0000205// Returns architecture name that is understood by the target assembler.
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000206const char *Triple::getArchNameForAssembler() {
Daniel Dunbar163a0962011-04-19 21:12:05 +0000207 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000208 return NULL;
209
Chandler Carruthff6f3562012-02-12 09:27:38 +0000210 return StringSwitch<const char*>(getArchName())
211 .Case("i386", "i386")
212 .Case("x86_64", "x86_64")
213 .Case("powerpc", "ppc")
214 .Case("powerpc64", "ppc64")
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000215 .Case("powerpc64le", "ppc64le")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000216 .Case("arm", "arm")
217 .Cases("armv4t", "thumbv4t", "armv4t")
218 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
219 .Cases("armv6", "thumbv6", "armv6")
220 .Cases("armv7", "thumbv7", "armv7")
Christian Pirker2a111602014-03-28 14:35:30 +0000221 .Case("armeb", "armeb")
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000222 .Case("r600", "r600")
Justin Holewinskiae556d32012-05-04 20:18:50 +0000223 .Case("nvptx", "nvptx")
224 .Case("nvptx64", "nvptx64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000225 .Case("le32", "le32")
226 .Case("amdil", "amdil")
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000227 .Case("spir", "spir")
Guy Benyeia4d31a32012-11-15 10:35:47 +0000228 .Case("spir64", "spir64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000229 .Default(NULL);
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000230}
231
Chandler Carruthaec97082012-02-21 08:53:32 +0000232static Triple::ArchType parseArch(StringRef ArchName) {
233 return StringSwitch<Triple::ArchType>(ArchName)
234 .Cases("i386", "i486", "i586", "i686", Triple::x86)
235 // FIXME: Do we need to support these?
236 .Cases("i786", "i886", "i986", Triple::x86)
Jim Grosbach664d1482013-11-16 00:52:57 +0000237 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000238 .Case("powerpc", Triple::ppc)
239 .Cases("powerpc64", "ppu", Triple::ppc64)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000240 .Case("powerpc64le", Triple::ppc64le)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000241 .Case("aarch64", Triple::aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000242 .Case("aarch64_be", Triple::aarch64_be)
Chandler Carruthaec97082012-02-21 08:53:32 +0000243 .Cases("arm", "xscale", Triple::arm)
Chandler Carruthb54950b2012-02-18 04:34:17 +0000244 // FIXME: It would be good to replace these with explicit names for all the
245 // various suffixes supported.
Chandler Carruthaec97082012-02-21 08:53:32 +0000246 .StartsWith("armv", Triple::arm)
Christian Pirker2a111602014-03-28 14:35:30 +0000247 .Case("armeb", Triple::armeb)
248 .StartsWith("armebv", Triple::armeb)
Chandler Carruthaec97082012-02-21 08:53:32 +0000249 .Case("thumb", Triple::thumb)
250 .StartsWith("thumbv", Triple::thumb)
Christian Pirker2a111602014-03-28 14:35:30 +0000251 .Case("thumbeb", Triple::thumbeb)
252 .StartsWith("thumbebv", Triple::thumbeb)
Chandler Carruthaec97082012-02-21 08:53:32 +0000253 .Case("msp430", Triple::msp430)
254 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruth0c7a7cc2012-02-22 11:32:54 +0000255 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruthaec97082012-02-21 08:53:32 +0000256 .Cases("mips64", "mips64eb", Triple::mips64)
257 .Case("mips64el", Triple::mips64el)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000258 .Case("r600", Triple::r600)
Chandler Carruthaec97082012-02-21 08:53:32 +0000259 .Case("hexagon", Triple::hexagon)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000260 .Case("s390x", Triple::systemz)
Chandler Carruthaec97082012-02-21 08:53:32 +0000261 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenabc3d232013-05-14 17:47:27 +0000262 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruthaec97082012-02-21 08:53:32 +0000263 .Case("tce", Triple::tce)
264 .Case("xcore", Triple::xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000265 .Case("nvptx", Triple::nvptx)
266 .Case("nvptx64", Triple::nvptx64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000267 .Case("le32", Triple::le32)
268 .Case("amdil", Triple::amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000269 .Case("spir", Triple::spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000270 .Case("spir64", Triple::spir64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000271 .Default(Triple::UnknownArch);
Duncan Sands501dff72010-08-12 11:31:39 +0000272}
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000273
Chandler Carruthaec97082012-02-21 08:53:32 +0000274static Triple::VendorType parseVendor(StringRef VendorName) {
275 return StringSwitch<Triple::VendorType>(VendorName)
276 .Case("apple", Triple::Apple)
277 .Case("pc", Triple::PC)
278 .Case("scei", Triple::SCEI)
Hal Finkelf208af02012-04-02 18:31:33 +0000279 .Case("bgp", Triple::BGP)
280 .Case("bgq", Triple::BGQ)
Hal Finkelb5d177e2012-08-28 02:10:30 +0000281 .Case("fsl", Triple::Freescale)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000282 .Case("ibm", Triple::IBM)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000283 .Case("nvidia", Triple::NVIDIA)
Chandler Carruthaec97082012-02-21 08:53:32 +0000284 .Default(Triple::UnknownVendor);
Duncan Sands501dff72010-08-12 11:31:39 +0000285}
286
Chandler Carruthaec97082012-02-21 08:53:32 +0000287static Triple::OSType parseOS(StringRef OSName) {
288 return StringSwitch<Triple::OSType>(OSName)
289 .StartsWith("auroraux", Triple::AuroraUX)
290 .StartsWith("cygwin", Triple::Cygwin)
291 .StartsWith("darwin", Triple::Darwin)
292 .StartsWith("dragonfly", Triple::DragonFly)
293 .StartsWith("freebsd", Triple::FreeBSD)
294 .StartsWith("ios", Triple::IOS)
295 .StartsWith("kfreebsd", Triple::KFreeBSD)
296 .StartsWith("linux", Triple::Linux)
297 .StartsWith("lv2", Triple::Lv2)
298 .StartsWith("macosx", Triple::MacOSX)
299 .StartsWith("mingw32", Triple::MinGW32)
300 .StartsWith("netbsd", Triple::NetBSD)
301 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruthaec97082012-02-21 08:53:32 +0000302 .StartsWith("solaris", Triple::Solaris)
303 .StartsWith("win32", Triple::Win32)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000304 .StartsWith("windows", Triple::Win32)
Chandler Carruthaec97082012-02-21 08:53:32 +0000305 .StartsWith("haiku", Triple::Haiku)
306 .StartsWith("minix", Triple::Minix)
307 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyabe54632012-12-04 18:37:26 +0000308 .StartsWith("nacl", Triple::NaCl)
Hal Finkelf208af02012-04-02 18:31:33 +0000309 .StartsWith("cnk", Triple::CNK)
Eric Christopher22738d02012-08-06 20:52:18 +0000310 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000311 .StartsWith("aix", Triple::AIX)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000312 .StartsWith("cuda", Triple::CUDA)
313 .StartsWith("nvcl", Triple::NVCL)
Chandler Carruthaec97082012-02-21 08:53:32 +0000314 .Default(Triple::UnknownOS);
Duncan Sands501dff72010-08-12 11:31:39 +0000315}
316
Chandler Carruthaec97082012-02-21 08:53:32 +0000317static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
318 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000319 .StartsWith("eabihf", Triple::EABIHF)
Chandler Carruthaec97082012-02-21 08:53:32 +0000320 .StartsWith("eabi", Triple::EABI)
321 .StartsWith("gnueabihf", Triple::GNUEABIHF)
322 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky0893e102013-01-22 18:02:49 +0000323 .StartsWith("gnux32", Triple::GNUX32)
David Woodhouse71d15ed2014-01-20 12:02:25 +0000324 .StartsWith("code16", Triple::CODE16)
Chandler Carruthaec97082012-02-21 08:53:32 +0000325 .StartsWith("gnu", Triple::GNU)
Logan Chien9ab55b82012-09-02 09:29:46 +0000326 .StartsWith("android", Triple::Android)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000327 .StartsWith("msvc", Triple::MSVC)
328 .StartsWith("itanium", Triple::Itanium)
329 .StartsWith("cygnus", Triple::Cygnus)
Chandler Carruthaec97082012-02-21 08:53:32 +0000330 .Default(Triple::UnknownEnvironment);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000331}
332
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000333static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
334 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
335 .EndsWith("coff", Triple::COFF)
336 .EndsWith("elf", Triple::ELF)
337 .EndsWith("macho", Triple::MachO)
338 .Default(Triple::UnknownObjectFormat);
339}
340
341static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
342 switch (Kind) {
343 case Triple::UnknownObjectFormat: return "";
344 case Triple::COFF: return "coff";
345 case Triple::ELF: return "elf";
346 case Triple::MachO: return "macho";
347 }
348 llvm_unreachable("unknown object format type");
349}
350
351static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
352 if (T.isOSDarwin())
353 return Triple::MachO;
354 else if (T.isOSWindows())
355 return Triple::COFF;
356 return Triple::ELF;
357}
358
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000359/// \brief Construct a triple from the string representation provided.
360///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000361/// This stores the string representation and parses the various pieces into
362/// enum members.
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000363Triple::Triple(const Twine &Str)
364 : Data(Str.str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000365 Arch(parseArch(getArchName())),
366 Vendor(parseVendor(getVendorName())),
367 OS(parseOS(getOSName())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000368 Environment(parseEnvironment(getEnvironmentName())),
369 ObjectFormat(parseFormat(getEnvironmentName())) {
370 if (ObjectFormat == Triple::UnknownObjectFormat)
371 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000372}
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000373
374/// \brief Construct a triple from string representations of the architecture,
375/// vendor, and OS.
376///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000377/// This joins each argument into a canonical string representation and parses
378/// them into enum members. It leaves the environment unknown and omits it from
379/// the string representation.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000380Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
381 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000382 Arch(parseArch(ArchStr.str())),
383 Vendor(parseVendor(VendorStr.str())),
384 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000385 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
386 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000387}
388
389/// \brief Construct a triple from string representations of the architecture,
390/// vendor, OS, and environment.
391///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000392/// This joins each argument into a canonical string representation and parses
393/// them into enum members.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000394Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
395 const Twine &EnvironmentStr)
396 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
397 EnvironmentStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000398 Arch(parseArch(ArchStr.str())),
399 Vendor(parseVendor(VendorStr.str())),
400 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000401 Environment(parseEnvironment(EnvironmentStr.str())),
402 ObjectFormat(parseFormat(EnvironmentStr.str())) {
403 if (ObjectFormat == Triple::UnknownObjectFormat)
404 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000405}
406
Duncan Sands501dff72010-08-12 11:31:39 +0000407std::string Triple::normalize(StringRef Str) {
408 // Parse into components.
409 SmallVector<StringRef, 4> Components;
Chandler Carruth6ea6de72012-02-21 09:12:48 +0000410 Str.split(Components, "-");
Duncan Sands501dff72010-08-12 11:31:39 +0000411
412 // If the first component corresponds to a known architecture, preferentially
413 // use it for the architecture. If the second component corresponds to a
414 // known vendor, preferentially use it for the vendor, etc. This avoids silly
415 // component movement when a component parses as (eg) both a valid arch and a
416 // valid os.
417 ArchType Arch = UnknownArch;
418 if (Components.size() > 0)
Chandler Carruthaec97082012-02-21 08:53:32 +0000419 Arch = parseArch(Components[0]);
Duncan Sands501dff72010-08-12 11:31:39 +0000420 VendorType Vendor = UnknownVendor;
421 if (Components.size() > 1)
Chandler Carruthaec97082012-02-21 08:53:32 +0000422 Vendor = parseVendor(Components[1]);
Duncan Sands501dff72010-08-12 11:31:39 +0000423 OSType OS = UnknownOS;
424 if (Components.size() > 2)
Chandler Carruthaec97082012-02-21 08:53:32 +0000425 OS = parseOS(Components[2]);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000426 EnvironmentType Environment = UnknownEnvironment;
427 if (Components.size() > 3)
Chandler Carruthaec97082012-02-21 08:53:32 +0000428 Environment = parseEnvironment(Components[3]);
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000429 ObjectFormatType ObjectFormat = UnknownObjectFormat;
Duncan Sands501dff72010-08-12 11:31:39 +0000430
431 // Note which components are already in their final position. These will not
432 // be moved.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000433 bool Found[4];
Duncan Sands501dff72010-08-12 11:31:39 +0000434 Found[0] = Arch != UnknownArch;
435 Found[1] = Vendor != UnknownVendor;
436 Found[2] = OS != UnknownOS;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000437 Found[3] = Environment != UnknownEnvironment;
Duncan Sands501dff72010-08-12 11:31:39 +0000438
439 // If they are not there already, permute the components into their canonical
440 // positions by seeing if they parse as a valid architecture, and if so moving
441 // the component to the architecture position etc.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000442 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands501dff72010-08-12 11:31:39 +0000443 if (Found[Pos])
444 continue; // Already in the canonical position.
445
446 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
447 // Do not reparse any components that already matched.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000448 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands501dff72010-08-12 11:31:39 +0000449 continue;
450
451 // Does this component parse as valid for the target position?
452 bool Valid = false;
453 StringRef Comp = Components[Idx];
454 switch (Pos) {
Craig Toppera2886c22012-02-07 05:05:23 +0000455 default: llvm_unreachable("unexpected component type!");
Duncan Sands501dff72010-08-12 11:31:39 +0000456 case 0:
Chandler Carruthaec97082012-02-21 08:53:32 +0000457 Arch = parseArch(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000458 Valid = Arch != UnknownArch;
459 break;
460 case 1:
Chandler Carruthaec97082012-02-21 08:53:32 +0000461 Vendor = parseVendor(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000462 Valid = Vendor != UnknownVendor;
463 break;
464 case 2:
Chandler Carruthaec97082012-02-21 08:53:32 +0000465 OS = parseOS(Comp);
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000466 Valid = OS != UnknownOS;
Duncan Sands501dff72010-08-12 11:31:39 +0000467 break;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000468 case 3:
Chandler Carruthaec97082012-02-21 08:53:32 +0000469 Environment = parseEnvironment(Comp);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000470 Valid = Environment != UnknownEnvironment;
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000471 if (!Valid) {
472 ObjectFormat = parseFormat(Comp);
473 Valid = ObjectFormat != UnknownObjectFormat;
474 }
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000475 break;
Duncan Sands501dff72010-08-12 11:31:39 +0000476 }
477 if (!Valid)
478 continue; // Nope, try the next component.
479
480 // Move the component to the target position, pushing any non-fixed
481 // components that are in the way to the right. This tends to give
482 // good results in the common cases of a forgotten vendor component
483 // or a wrongly positioned environment.
484 if (Pos < Idx) {
485 // Insert left, pushing the existing components to the right. For
486 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
487 StringRef CurrentComponent(""); // The empty component.
488 // Replace the component we are moving with an empty component.
489 std::swap(CurrentComponent, Components[Idx]);
490 // Insert the component being moved at Pos, displacing any existing
491 // components to the right.
492 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
493 // Skip over any fixed components.
Chandler Carruth362087b2012-02-21 09:29:14 +0000494 while (i < array_lengthof(Found) && Found[i])
495 ++i;
Duncan Sands501dff72010-08-12 11:31:39 +0000496 // Place the component at the new position, getting the component
497 // that was at this position - it will be moved right.
498 std::swap(CurrentComponent, Components[i]);
499 }
500 } else if (Pos > Idx) {
501 // Push right by inserting empty components until the component at Idx
502 // reaches the target position Pos. For example, pc-a -> -pc-a when
503 // moving pc to the second position.
504 do {
505 // Insert one empty component at Idx.
506 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000507 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands501dff72010-08-12 11:31:39 +0000508 // Place the component at the new position, getting the component
509 // that was at this position - it will be moved right.
510 std::swap(CurrentComponent, Components[i]);
511 // If it was placed on top of an empty component then we are done.
512 if (CurrentComponent.empty())
513 break;
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000514 // Advance to the next component, skipping any fixed components.
Anders Carlsson630125a2011-02-05 18:19:35 +0000515 while (++i < array_lengthof(Found) && Found[i])
516 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000517 }
518 // The last component was pushed off the end - append it.
519 if (!CurrentComponent.empty())
520 Components.push_back(CurrentComponent);
521
522 // Advance Idx to the component's new position.
Chandler Carruth362087b2012-02-21 09:29:14 +0000523 while (++Idx < array_lengthof(Found) && Found[Idx])
524 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000525 } while (Idx < Pos); // Add more until the final position is reached.
526 }
527 assert(Pos < Components.size() && Components[Pos] == Comp &&
528 "Component moved wrong!");
529 Found[Pos] = true;
530 break;
531 }
532 }
533
534 // Special case logic goes here. At this point Arch, Vendor and OS have the
535 // correct values for the computed components.
536
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000537 if (OS == Triple::Win32) {
538 Components.resize(4);
539 Components[2] = "windows";
540 if (Environment == UnknownEnvironment && ObjectFormat == UnknownObjectFormat)
541 Components[3] = "msvc";
542 } else if (OS == Triple::MinGW32) {
543 Components.resize(4);
544 Components[2] = "windows";
545 Components[3] = (ObjectFormat == Triple::ELF) ? "gnuelf" : "gnu";
546 } else if (OS == Triple::Cygwin) {
547 Components.resize(4);
548 Components[2] = "windows";
549 Components[3] = "cygnus";
550 }
551
Duncan Sands501dff72010-08-12 11:31:39 +0000552 // Stick the corrected components back together to form the normalized string.
553 std::string Normalized;
554 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
555 if (i) Normalized += '-';
556 Normalized += Components[i];
557 }
558 return Normalized;
559}
560
Daniel Dunbar19e70762009-07-26 03:31:47 +0000561StringRef Triple::getArchName() const {
562 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000563}
564
Daniel Dunbar19e70762009-07-26 03:31:47 +0000565StringRef Triple::getVendorName() const {
566 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
567 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000568}
569
Daniel Dunbar19e70762009-07-26 03:31:47 +0000570StringRef Triple::getOSName() const {
571 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
572 Tmp = Tmp.split('-').second; // Strip second component
573 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000574}
575
Daniel Dunbar19e70762009-07-26 03:31:47 +0000576StringRef Triple::getEnvironmentName() const {
577 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
578 Tmp = Tmp.split('-').second; // Strip second component
579 return Tmp.split('-').second; // Strip third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000580}
581
Daniel Dunbar19e70762009-07-26 03:31:47 +0000582StringRef Triple::getOSAndEnvironmentName() const {
583 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
584 return Tmp.split('-').second; // Strip second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000585}
586
Chris Lattner553c9f32009-08-12 06:19:40 +0000587static unsigned EatNumber(StringRef &Str) {
588 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000589 unsigned Result = 0;
Jim Grosbachf638b262010-12-17 02:10:59 +0000590
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000591 do {
592 // Consume the leading digit.
Chris Lattner553c9f32009-08-12 06:19:40 +0000593 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000594
Chris Lattner553c9f32009-08-12 06:19:40 +0000595 // Eat the digit.
596 Str = Str.substr(1);
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000597 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbachf638b262010-12-17 02:10:59 +0000598
Chris Lattner553c9f32009-08-12 06:19:40 +0000599 return Result;
600}
601
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000602void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
603 unsigned &Micro) const {
Chris Lattner553c9f32009-08-12 06:19:40 +0000604 StringRef OSName = getOSName();
Jim Grosbachf638b262010-12-17 02:10:59 +0000605
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000606 // Assume that the OS portion of the triple starts with the canonical name.
607 StringRef OSTypeName = getOSTypeName(getOS());
608 if (OSName.startswith(OSTypeName))
609 OSName = OSName.substr(OSTypeName.size());
Jim Grosbachf638b262010-12-17 02:10:59 +0000610
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000611 // Any unset version defaults to 0.
612 Major = Minor = Micro = 0;
Chris Lattner553c9f32009-08-12 06:19:40 +0000613
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000614 // Parse up to three components.
615 unsigned *Components[3] = { &Major, &Minor, &Micro };
616 for (unsigned i = 0; i != 3; ++i) {
617 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
618 break;
Chris Lattner553c9f32009-08-12 06:19:40 +0000619
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000620 // Consume the leading number.
621 *Components[i] = EatNumber(OSName);
Jim Grosbachf638b262010-12-17 02:10:59 +0000622
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000623 // Consume the separator, if present.
624 if (OSName.startswith("."))
625 OSName = OSName.substr(1);
626 }
Chris Lattner553c9f32009-08-12 06:19:40 +0000627}
628
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000629bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
630 unsigned &Micro) const {
631 getOSVersion(Major, Minor, Micro);
632
633 switch (getOS()) {
Craig Toppera2886c22012-02-07 05:05:23 +0000634 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000635 case Darwin:
636 // Default to darwin8, i.e., MacOSX 10.4.
637 if (Major == 0)
638 Major = 8;
639 // Darwin version numbers are skewed from OS X versions.
640 if (Major < 4)
641 return false;
642 Micro = 0;
643 Minor = Major - 4;
644 Major = 10;
645 break;
646 case MacOSX:
647 // Default to 10.4.
648 if (Major == 0) {
649 Major = 10;
650 Minor = 4;
651 }
652 if (Major != 10)
653 return false;
654 break;
655 case IOS:
656 // Ignore the version from the triple. This is only handled because the
657 // the clang driver combines OS X and IOS support into a common Darwin
658 // toolchain that wants to know the OS X version number even when targeting
659 // IOS.
660 Major = 10;
661 Minor = 4;
662 Micro = 0;
663 break;
664 }
665 return true;
666}
667
Chad Rosierd84eaac2012-05-09 17:23:48 +0000668void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
669 unsigned &Micro) const {
670 switch (getOS()) {
671 default: llvm_unreachable("unexpected OS for Darwin triple");
672 case Darwin:
673 case MacOSX:
674 // Ignore the version from the triple. This is only handled because the
675 // the clang driver combines OS X and IOS support into a common Darwin
676 // toolchain that wants to know the iOS version number even when targeting
677 // OS X.
Tim Northover3e8df692013-12-10 11:53:16 +0000678 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000679 Minor = 0;
680 Micro = 0;
Chad Rosier2778cbc2012-05-09 17:38:47 +0000681 break;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000682 case IOS:
683 getOSVersion(Major, Minor, Micro);
Tim Northover3e8df692013-12-10 11:53:16 +0000684 // Default to 5.0.
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000685 if (Major == 0)
Tim Northover3e8df692013-12-10 11:53:16 +0000686 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000687 break;
688 }
689}
690
Daniel Dunbar19e70762009-07-26 03:31:47 +0000691void Triple::setTriple(const Twine &Str) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000692 *this = Triple(Str);
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000693}
694
695void Triple::setArch(ArchType Kind) {
696 setArchName(getArchTypeName(Kind));
697}
698
699void Triple::setVendor(VendorType Kind) {
700 setVendorName(getVendorTypeName(Kind));
701}
702
703void Triple::setOS(OSType Kind) {
704 setOSName(getOSTypeName(Kind));
705}
706
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000707void Triple::setEnvironment(EnvironmentType Kind) {
708 setEnvironmentName(getEnvironmentTypeName(Kind));
709}
710
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000711void Triple::setObjectFormat(ObjectFormatType Kind) {
712 setEnvironmentName(getObjectFormatTypeName(Kind));
713}
714
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000715void Triple::setArchName(StringRef Str) {
Jeffrey Yasskine2595b52009-10-06 21:45:26 +0000716 // Work around a miscompilation bug for Twines in gcc 4.0.3.
717 SmallString<64> Triple;
718 Triple += Str;
719 Triple += "-";
720 Triple += getVendorName();
721 Triple += "-";
722 Triple += getOSAndEnvironmentName();
723 setTriple(Triple.str());
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000724}
725
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000726void Triple::setVendorName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000727 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
728}
729
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000730void Triple::setOSName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000731 if (hasEnvironment())
732 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
733 "-" + getEnvironmentName());
734 else
735 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
736}
737
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000738void Triple::setEnvironmentName(StringRef Str) {
739 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000740 "-" + Str);
741}
742
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000743void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000744 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
745}
Chandler Carruthb90c1022012-01-31 04:52:32 +0000746
747static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
748 switch (Arch) {
749 case llvm::Triple::UnknownArch:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000750 return 0;
751
752 case llvm::Triple::msp430:
753 return 16;
754
755 case llvm::Triple::amdil:
756 case llvm::Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000757 case llvm::Triple::armeb:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000758 case llvm::Triple::hexagon:
759 case llvm::Triple::le32:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000760 case llvm::Triple::mips:
761 case llvm::Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000762 case llvm::Triple::nvptx:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000763 case llvm::Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000764 case llvm::Triple::r600:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000765 case llvm::Triple::sparc:
766 case llvm::Triple::tce:
767 case llvm::Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000768 case llvm::Triple::thumbeb:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000769 case llvm::Triple::x86:
770 case llvm::Triple::xcore:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000771 case llvm::Triple::spir:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000772 return 32;
773
Tim Northovere0e3aef2013-01-31 12:12:40 +0000774 case llvm::Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000775 case llvm::Triple::aarch64_be:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000776 case llvm::Triple::mips64:
777 case llvm::Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000778 case llvm::Triple::nvptx64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000779 case llvm::Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000780 case llvm::Triple::ppc64le:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000781 case llvm::Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000782 case llvm::Triple::systemz:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000783 case llvm::Triple::x86_64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000784 case llvm::Triple::spir64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000785 return 64;
786 }
787 llvm_unreachable("Invalid architecture value");
788}
789
790bool Triple::isArch64Bit() const {
791 return getArchPointerBitWidth(getArch()) == 64;
792}
793
794bool Triple::isArch32Bit() const {
795 return getArchPointerBitWidth(getArch()) == 32;
796}
797
798bool Triple::isArch16Bit() const {
799 return getArchPointerBitWidth(getArch()) == 16;
800}
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000801
802Triple Triple::get32BitArchVariant() const {
803 Triple T(*this);
804 switch (getArch()) {
805 case Triple::UnknownArch:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000806 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000807 case Triple::aarch64_be:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000808 case Triple::msp430:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000809 case Triple::systemz:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000810 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000811 T.setArch(UnknownArch);
812 break;
813
814 case Triple::amdil:
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000815 case Triple::spir:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000816 case Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000817 case Triple::armeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000818 case Triple::hexagon:
819 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000820 case Triple::mips:
821 case Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000822 case Triple::nvptx:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000823 case Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000824 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000825 case Triple::sparc:
826 case Triple::tce:
827 case Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000828 case Triple::thumbeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000829 case Triple::x86:
830 case Triple::xcore:
831 // Already 32-bit.
832 break;
833
834 case Triple::mips64: T.setArch(Triple::mips); break;
835 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000836 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Bob Wilsona2790b12014-03-09 23:17:28 +0000837 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000838 case Triple::sparcv9: T.setArch(Triple::sparc); break;
839 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000840 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000841 }
842 return T;
843}
844
845Triple Triple::get64BitArchVariant() const {
846 Triple T(*this);
847 switch (getArch()) {
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000848 case Triple::UnknownArch:
849 case Triple::amdil:
850 case Triple::arm:
Christian Pirker2a111602014-03-28 14:35:30 +0000851 case Triple::armeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000852 case Triple::hexagon:
853 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000854 case Triple::msp430:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000855 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000856 case Triple::tce:
857 case Triple::thumb:
Christian Pirker2a111602014-03-28 14:35:30 +0000858 case Triple::thumbeb:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000859 case Triple::xcore:
860 T.setArch(UnknownArch);
861 break;
862
Tim Northovere0e3aef2013-01-31 12:12:40 +0000863 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000864 case Triple::aarch64_be:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000865 case Triple::spir64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000866 case Triple::mips64:
867 case Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000868 case Triple::nvptx64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000869 case Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000870 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000871 case Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000872 case Triple::systemz:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000873 case Triple::x86_64:
874 // Already 64-bit.
875 break;
876
877 case Triple::mips: T.setArch(Triple::mips64); break;
878 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000879 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000880 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000881 case Triple::sparc: T.setArch(Triple::sparcv9); break;
882 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000883 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000884 }
885 return T;
886}