blob: 0b8e9a66856810a8b92592ebcf11e1e76511b708 [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";
25 case hexagon: return "hexagon";
26 case mips: return "mips";
27 case mipsel: return "mipsel";
28 case mips64: return "mips64";
29 case mips64el: return "mips64el";
30 case msp430: return "msp430";
31 case ppc64: return "powerpc64";
32 case ppc64le: return "powerpc64le";
33 case ppc: return "powerpc";
34 case r600: return "r600";
35 case sparc: return "sparc";
36 case sparcv9: return "sparcv9";
37 case systemz: return "s390x";
38 case tce: return "tce";
39 case thumb: return "thumb";
40 case x86: return "i386";
41 case x86_64: return "x86_64";
42 case xcore: return "xcore";
43 case nvptx: return "nvptx";
44 case nvptx64: return "nvptx64";
45 case le32: return "le32";
46 case amdil: return "amdil";
47 case spir: return "spir";
48 case spir64: return "spir64";
Daniel Dunbar4abd5662009-04-01 21:53:23 +000049 }
50
David Blaikie46a9f012012-01-20 21:51:11 +000051 llvm_unreachable("Invalid ArchType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +000052}
53
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000054const char *Triple::getArchTypePrefix(ArchType Kind) {
55 switch (Kind) {
56 default:
57 return 0;
58
Christian Pirker6c2f4d42014-02-24 11:34:50 +000059 case aarch64:
60 case aarch64_be: return "aarch64";
Tim Northovere0e3aef2013-01-31 12:12:40 +000061
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000062 case arm:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000063 case thumb: return "arm";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000064
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000065 case ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +000066 case ppc64le:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000067 case ppc: return "ppc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000068
Benjamin Kramerae3c3002012-06-28 19:09:53 +000069 case mips:
70 case mipsel:
71 case mips64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000072 case mips64el: return "mips";
Benjamin Kramerae3c3002012-06-28 19:09:53 +000073
Christian Pirker6c2f4d42014-02-24 11:34:50 +000074 case hexagon: return "hexagon";
Tony Linthicum1213a7a2011-12-12 21:14:40 +000075
Christian Pirker6c2f4d42014-02-24 11:34:50 +000076 case r600: return "r600";
Anton Korobeynikovf32638d2012-03-09 10:09:36 +000077
Chris Lattner8228b112010-02-04 06:34:01 +000078 case sparcv9:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000079 case sparc: return "sparc";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000080
Christian Pirker6c2f4d42014-02-24 11:34:50 +000081 case systemz: return "systemz";
Richard Sandiforda238c5e2013-05-03 11:05:17 +000082
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000083 case x86:
Christian Pirker6c2f4d42014-02-24 11:34:50 +000084 case x86_64: return "x86";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000085
Christian Pirker6c2f4d42014-02-24 11:34:50 +000086 case xcore: return "xcore";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000087
Christian Pirker6c2f4d42014-02-24 11:34:50 +000088 case nvptx: return "nvptx";
89 case nvptx64: return "nvptx";
90 case le32: return "le32";
91 case amdil: return "amdil";
92 case spir: return "spir";
93 case spir64: return "spir";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000094 }
95}
96
Daniel Dunbar4abd5662009-04-01 21:53:23 +000097const char *Triple::getVendorTypeName(VendorType Kind) {
98 switch (Kind) {
99 case UnknownVendor: return "unknown";
100
101 case Apple: return "apple";
Chris Lattner07921952009-08-14 18:48:13 +0000102 case PC: return "pc";
John Thompsond0332e42011-03-15 21:51:56 +0000103 case SCEI: return "scei";
Hal Finkelf208af02012-04-02 18:31:33 +0000104 case BGP: return "bgp";
105 case BGQ: return "bgq";
Hal Finkelb5d177e2012-08-28 02:10:30 +0000106 case Freescale: return "fsl";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000107 case IBM: return "ibm";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000108 case NVIDIA: return "nvidia";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000109 }
110
David Blaikie46a9f012012-01-20 21:51:11 +0000111 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000112}
113
114const char *Triple::getOSTypeName(OSType Kind) {
115 switch (Kind) {
116 case UnknownOS: return "unknown";
117
Duncan Sands0de39b42009-06-19 14:40:01 +0000118 case AuroraUX: return "auroraux";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000119 case Cygwin: return "cygwin";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000120 case Darwin: return "darwin";
Daniel Dunbare3384c42009-05-22 02:24:11 +0000121 case DragonFly: return "dragonfly";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000122 case FreeBSD: return "freebsd";
Daniel Dunbard74bac72011-04-19 20:19:27 +0000123 case IOS: return "ios";
Duncan Sandsfe44f672011-07-26 15:30:04 +0000124 case KFreeBSD: return "kfreebsd";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000125 case Linux: return "linux";
Edward O'Callaghanba993b82009-11-19 11:59:00 +0000126 case Lv2: return "lv2";
Daniel Dunbar0854f342011-04-19 23:34:12 +0000127 case MacOSX: return "macosx";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000128 case MinGW32: return "mingw32";
Chris Lattner01218d52009-07-13 20:22:23 +0000129 case NetBSD: return "netbsd";
Duncan Sands14814d42009-06-29 13:36:13 +0000130 case OpenBSD: return "openbsd";
Daniel Dunbar781f94d2009-08-18 04:43:27 +0000131 case Solaris: return "solaris";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000132 case Win32: return "win32";
Chris Lattner27f20492009-10-16 02:06:30 +0000133 case Haiku: return "haiku";
Chris Lattnerca97c922010-07-07 15:52:27 +0000134 case Minix: return "minix";
Douglas Gregorde3c9262011-07-01 22:41:06 +0000135 case RTEMS: return "rtems";
Eli Benderskyabe54632012-12-04 18:37:26 +0000136 case NaCl: return "nacl";
Hal Finkelf208af02012-04-02 18:31:33 +0000137 case CNK: return "cnk";
Eric Christopher22738d02012-08-06 20:52:18 +0000138 case Bitrig: return "bitrig";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000139 case AIX: return "aix";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000140 case CUDA: return "cuda";
141 case NVCL: return "nvcl";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000142 }
143
David Blaikie46a9f012012-01-20 21:51:11 +0000144 llvm_unreachable("Invalid OSType");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000145}
146
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000147const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
148 switch (Kind) {
149 case UnknownEnvironment: return "unknown";
Renato Golin83758d5c2011-01-21 18:25:47 +0000150 case GNU: return "gnu";
Rafael Espindolaf5e78fa2012-01-18 23:35:29 +0000151 case GNUEABIHF: return "gnueabihf";
Renato Golin83758d5c2011-01-21 18:25:47 +0000152 case GNUEABI: return "gnueabi";
Eli Bendersky0893e102013-01-22 18:02:49 +0000153 case GNUX32: return "gnux32";
David Woodhouse71d15ed2014-01-20 12:02:25 +0000154 case CODE16: return "code16";
Renato Golin83758d5c2011-01-21 18:25:47 +0000155 case EABI: return "eabi";
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000156 case EABIHF: return "eabihf";
Logan Chien9ab55b82012-09-02 09:29:46 +0000157 case Android: return "android";
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000158 }
159
David Blaikie46a9f012012-01-20 21:51:11 +0000160 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000161}
162
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000163Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruthff6f3562012-02-12 09:27:38 +0000164 return StringSwitch<Triple::ArchType>(Name)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000165 .Case("aarch64", aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000166 .Case("aarch64_be", aarch64_be)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000167 .Case("arm", arm)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000168 .Case("mips", mips)
169 .Case("mipsel", mipsel)
170 .Case("mips64", mips64)
171 .Case("mips64el", mips64el)
172 .Case("msp430", msp430)
173 .Case("ppc64", ppc64)
174 .Case("ppc32", ppc)
175 .Case("ppc", ppc)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000176 .Case("ppc64le", ppc64le)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000177 .Case("r600", r600)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000178 .Case("hexagon", hexagon)
179 .Case("sparc", sparc)
180 .Case("sparcv9", sparcv9)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000181 .Case("systemz", systemz)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000182 .Case("tce", tce)
183 .Case("thumb", thumb)
184 .Case("x86", x86)
185 .Case("x86-64", x86_64)
186 .Case("xcore", xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000187 .Case("nvptx", nvptx)
188 .Case("nvptx64", nvptx64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000189 .Case("le32", le32)
190 .Case("amdil", amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000191 .Case("spir", spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000192 .Case("spir64", spir64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000193 .Default(UnknownArch);
Daniel Dunbar0f16ea52009-08-03 04:03:51 +0000194}
195
Duncan Sands8712da32010-03-24 09:05:14 +0000196// Returns architecture name that is understood by the target assembler.
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000197const char *Triple::getArchNameForAssembler() {
Daniel Dunbar163a0962011-04-19 21:12:05 +0000198 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000199 return NULL;
200
Chandler Carruthff6f3562012-02-12 09:27:38 +0000201 return StringSwitch<const char*>(getArchName())
202 .Case("i386", "i386")
203 .Case("x86_64", "x86_64")
204 .Case("powerpc", "ppc")
205 .Case("powerpc64", "ppc64")
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000206 .Case("powerpc64le", "ppc64le")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000207 .Case("arm", "arm")
208 .Cases("armv4t", "thumbv4t", "armv4t")
209 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
210 .Cases("armv6", "thumbv6", "armv6")
211 .Cases("armv7", "thumbv7", "armv7")
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000212 .Case("r600", "r600")
Justin Holewinskiae556d32012-05-04 20:18:50 +0000213 .Case("nvptx", "nvptx")
214 .Case("nvptx64", "nvptx64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000215 .Case("le32", "le32")
216 .Case("amdil", "amdil")
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000217 .Case("spir", "spir")
Guy Benyeia4d31a32012-11-15 10:35:47 +0000218 .Case("spir64", "spir64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000219 .Default(NULL);
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000220}
221
Chandler Carruthaec97082012-02-21 08:53:32 +0000222static Triple::ArchType parseArch(StringRef ArchName) {
223 return StringSwitch<Triple::ArchType>(ArchName)
224 .Cases("i386", "i486", "i586", "i686", Triple::x86)
225 // FIXME: Do we need to support these?
226 .Cases("i786", "i886", "i986", Triple::x86)
Jim Grosbach664d1482013-11-16 00:52:57 +0000227 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000228 .Case("powerpc", Triple::ppc)
229 .Cases("powerpc64", "ppu", Triple::ppc64)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000230 .Case("powerpc64le", Triple::ppc64le)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000231 .Case("aarch64", Triple::aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000232 .Case("aarch64_be", Triple::aarch64_be)
Chandler Carruthaec97082012-02-21 08:53:32 +0000233 .Cases("arm", "xscale", Triple::arm)
Chandler Carruthb54950b2012-02-18 04:34:17 +0000234 // FIXME: It would be good to replace these with explicit names for all the
235 // various suffixes supported.
Chandler Carruthaec97082012-02-21 08:53:32 +0000236 .StartsWith("armv", Triple::arm)
237 .Case("thumb", Triple::thumb)
238 .StartsWith("thumbv", Triple::thumb)
Chandler Carruthaec97082012-02-21 08:53:32 +0000239 .Case("msp430", Triple::msp430)
240 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruth0c7a7cc2012-02-22 11:32:54 +0000241 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruthaec97082012-02-21 08:53:32 +0000242 .Cases("mips64", "mips64eb", Triple::mips64)
243 .Case("mips64el", Triple::mips64el)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000244 .Case("r600", Triple::r600)
Chandler Carruthaec97082012-02-21 08:53:32 +0000245 .Case("hexagon", Triple::hexagon)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000246 .Case("s390x", Triple::systemz)
Chandler Carruthaec97082012-02-21 08:53:32 +0000247 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenabc3d232013-05-14 17:47:27 +0000248 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruthaec97082012-02-21 08:53:32 +0000249 .Case("tce", Triple::tce)
250 .Case("xcore", Triple::xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000251 .Case("nvptx", Triple::nvptx)
252 .Case("nvptx64", Triple::nvptx64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000253 .Case("le32", Triple::le32)
254 .Case("amdil", Triple::amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000255 .Case("spir", Triple::spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000256 .Case("spir64", Triple::spir64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000257 .Default(Triple::UnknownArch);
Duncan Sands501dff72010-08-12 11:31:39 +0000258}
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000259
Chandler Carruthaec97082012-02-21 08:53:32 +0000260static Triple::VendorType parseVendor(StringRef VendorName) {
261 return StringSwitch<Triple::VendorType>(VendorName)
262 .Case("apple", Triple::Apple)
263 .Case("pc", Triple::PC)
264 .Case("scei", Triple::SCEI)
Hal Finkelf208af02012-04-02 18:31:33 +0000265 .Case("bgp", Triple::BGP)
266 .Case("bgq", Triple::BGQ)
Hal Finkelb5d177e2012-08-28 02:10:30 +0000267 .Case("fsl", Triple::Freescale)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000268 .Case("ibm", Triple::IBM)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000269 .Case("nvidia", Triple::NVIDIA)
Chandler Carruthaec97082012-02-21 08:53:32 +0000270 .Default(Triple::UnknownVendor);
Duncan Sands501dff72010-08-12 11:31:39 +0000271}
272
Chandler Carruthaec97082012-02-21 08:53:32 +0000273static Triple::OSType parseOS(StringRef OSName) {
274 return StringSwitch<Triple::OSType>(OSName)
275 .StartsWith("auroraux", Triple::AuroraUX)
276 .StartsWith("cygwin", Triple::Cygwin)
277 .StartsWith("darwin", Triple::Darwin)
278 .StartsWith("dragonfly", Triple::DragonFly)
279 .StartsWith("freebsd", Triple::FreeBSD)
280 .StartsWith("ios", Triple::IOS)
281 .StartsWith("kfreebsd", Triple::KFreeBSD)
282 .StartsWith("linux", Triple::Linux)
283 .StartsWith("lv2", Triple::Lv2)
284 .StartsWith("macosx", Triple::MacOSX)
285 .StartsWith("mingw32", Triple::MinGW32)
286 .StartsWith("netbsd", Triple::NetBSD)
287 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruthaec97082012-02-21 08:53:32 +0000288 .StartsWith("solaris", Triple::Solaris)
289 .StartsWith("win32", Triple::Win32)
290 .StartsWith("haiku", Triple::Haiku)
291 .StartsWith("minix", Triple::Minix)
292 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyabe54632012-12-04 18:37:26 +0000293 .StartsWith("nacl", Triple::NaCl)
Hal Finkelf208af02012-04-02 18:31:33 +0000294 .StartsWith("cnk", Triple::CNK)
Eric Christopher22738d02012-08-06 20:52:18 +0000295 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000296 .StartsWith("aix", Triple::AIX)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000297 .StartsWith("cuda", Triple::CUDA)
298 .StartsWith("nvcl", Triple::NVCL)
Chandler Carruthaec97082012-02-21 08:53:32 +0000299 .Default(Triple::UnknownOS);
Duncan Sands501dff72010-08-12 11:31:39 +0000300}
301
Chandler Carruthaec97082012-02-21 08:53:32 +0000302static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
303 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000304 .StartsWith("eabihf", Triple::EABIHF)
Chandler Carruthaec97082012-02-21 08:53:32 +0000305 .StartsWith("eabi", Triple::EABI)
306 .StartsWith("gnueabihf", Triple::GNUEABIHF)
307 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky0893e102013-01-22 18:02:49 +0000308 .StartsWith("gnux32", Triple::GNUX32)
David Woodhouse71d15ed2014-01-20 12:02:25 +0000309 .StartsWith("code16", Triple::CODE16)
Chandler Carruthaec97082012-02-21 08:53:32 +0000310 .StartsWith("gnu", Triple::GNU)
Logan Chien9ab55b82012-09-02 09:29:46 +0000311 .StartsWith("android", Triple::Android)
Chandler Carruthaec97082012-02-21 08:53:32 +0000312 .Default(Triple::UnknownEnvironment);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000313}
314
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000315static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
316 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
317 .EndsWith("coff", Triple::COFF)
318 .EndsWith("elf", Triple::ELF)
319 .EndsWith("macho", Triple::MachO)
320 .Default(Triple::UnknownObjectFormat);
321}
322
323static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
324 switch (Kind) {
325 case Triple::UnknownObjectFormat: return "";
326 case Triple::COFF: return "coff";
327 case Triple::ELF: return "elf";
328 case Triple::MachO: return "macho";
329 }
330 llvm_unreachable("unknown object format type");
331}
332
333static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
334 if (T.isOSDarwin())
335 return Triple::MachO;
336 else if (T.isOSWindows())
337 return Triple::COFF;
338 return Triple::ELF;
339}
340
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000341/// \brief Construct a triple from the string representation provided.
342///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000343/// This stores the string representation and parses the various pieces into
344/// enum members.
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000345Triple::Triple(const Twine &Str)
346 : Data(Str.str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000347 Arch(parseArch(getArchName())),
348 Vendor(parseVendor(getVendorName())),
349 OS(parseOS(getOSName())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000350 Environment(parseEnvironment(getEnvironmentName())),
351 ObjectFormat(parseFormat(getEnvironmentName())) {
352 if (ObjectFormat == Triple::UnknownObjectFormat)
353 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000354}
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000355
356/// \brief Construct a triple from string representations of the architecture,
357/// vendor, and OS.
358///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000359/// This joins each argument into a canonical string representation and parses
360/// them into enum members. It leaves the environment unknown and omits it from
361/// the string representation.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000362Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
363 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000364 Arch(parseArch(ArchStr.str())),
365 Vendor(parseVendor(VendorStr.str())),
366 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000367 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
368 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000369}
370
371/// \brief Construct a triple from string representations of the architecture,
372/// vendor, OS, and environment.
373///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000374/// This joins each argument into a canonical string representation and parses
375/// them into enum members.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000376Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
377 const Twine &EnvironmentStr)
378 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
379 EnvironmentStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000380 Arch(parseArch(ArchStr.str())),
381 Vendor(parseVendor(VendorStr.str())),
382 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000383 Environment(parseEnvironment(EnvironmentStr.str())),
384 ObjectFormat(parseFormat(EnvironmentStr.str())) {
385 if (ObjectFormat == Triple::UnknownObjectFormat)
386 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000387}
388
Duncan Sands501dff72010-08-12 11:31:39 +0000389std::string Triple::normalize(StringRef Str) {
390 // Parse into components.
391 SmallVector<StringRef, 4> Components;
Chandler Carruth6ea6de72012-02-21 09:12:48 +0000392 Str.split(Components, "-");
Duncan Sands501dff72010-08-12 11:31:39 +0000393
394 // If the first component corresponds to a known architecture, preferentially
395 // use it for the architecture. If the second component corresponds to a
396 // known vendor, preferentially use it for the vendor, etc. This avoids silly
397 // component movement when a component parses as (eg) both a valid arch and a
398 // valid os.
399 ArchType Arch = UnknownArch;
400 if (Components.size() > 0)
Chandler Carruthaec97082012-02-21 08:53:32 +0000401 Arch = parseArch(Components[0]);
Duncan Sands501dff72010-08-12 11:31:39 +0000402 VendorType Vendor = UnknownVendor;
403 if (Components.size() > 1)
Chandler Carruthaec97082012-02-21 08:53:32 +0000404 Vendor = parseVendor(Components[1]);
Duncan Sands501dff72010-08-12 11:31:39 +0000405 OSType OS = UnknownOS;
406 if (Components.size() > 2)
Chandler Carruthaec97082012-02-21 08:53:32 +0000407 OS = parseOS(Components[2]);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000408 EnvironmentType Environment = UnknownEnvironment;
409 if (Components.size() > 3)
Chandler Carruthaec97082012-02-21 08:53:32 +0000410 Environment = parseEnvironment(Components[3]);
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000411 ObjectFormatType ObjectFormat = UnknownObjectFormat;
Duncan Sands501dff72010-08-12 11:31:39 +0000412
413 // Note which components are already in their final position. These will not
414 // be moved.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000415 bool Found[4];
Duncan Sands501dff72010-08-12 11:31:39 +0000416 Found[0] = Arch != UnknownArch;
417 Found[1] = Vendor != UnknownVendor;
418 Found[2] = OS != UnknownOS;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000419 Found[3] = Environment != UnknownEnvironment;
Duncan Sands501dff72010-08-12 11:31:39 +0000420
421 // If they are not there already, permute the components into their canonical
422 // positions by seeing if they parse as a valid architecture, and if so moving
423 // the component to the architecture position etc.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000424 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands501dff72010-08-12 11:31:39 +0000425 if (Found[Pos])
426 continue; // Already in the canonical position.
427
428 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
429 // Do not reparse any components that already matched.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000430 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands501dff72010-08-12 11:31:39 +0000431 continue;
432
433 // Does this component parse as valid for the target position?
434 bool Valid = false;
435 StringRef Comp = Components[Idx];
436 switch (Pos) {
Craig Toppera2886c22012-02-07 05:05:23 +0000437 default: llvm_unreachable("unexpected component type!");
Duncan Sands501dff72010-08-12 11:31:39 +0000438 case 0:
Chandler Carruthaec97082012-02-21 08:53:32 +0000439 Arch = parseArch(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000440 Valid = Arch != UnknownArch;
441 break;
442 case 1:
Chandler Carruthaec97082012-02-21 08:53:32 +0000443 Vendor = parseVendor(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000444 Valid = Vendor != UnknownVendor;
445 break;
446 case 2:
Chandler Carruthaec97082012-02-21 08:53:32 +0000447 OS = parseOS(Comp);
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000448 Valid = OS != UnknownOS;
Duncan Sands501dff72010-08-12 11:31:39 +0000449 break;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000450 case 3:
Chandler Carruthaec97082012-02-21 08:53:32 +0000451 Environment = parseEnvironment(Comp);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000452 Valid = Environment != UnknownEnvironment;
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000453 if (!Valid) {
454 ObjectFormat = parseFormat(Comp);
455 Valid = ObjectFormat != UnknownObjectFormat;
456 }
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000457 break;
Duncan Sands501dff72010-08-12 11:31:39 +0000458 }
459 if (!Valid)
460 continue; // Nope, try the next component.
461
462 // Move the component to the target position, pushing any non-fixed
463 // components that are in the way to the right. This tends to give
464 // good results in the common cases of a forgotten vendor component
465 // or a wrongly positioned environment.
466 if (Pos < Idx) {
467 // Insert left, pushing the existing components to the right. For
468 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
469 StringRef CurrentComponent(""); // The empty component.
470 // Replace the component we are moving with an empty component.
471 std::swap(CurrentComponent, Components[Idx]);
472 // Insert the component being moved at Pos, displacing any existing
473 // components to the right.
474 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
475 // Skip over any fixed components.
Chandler Carruth362087b2012-02-21 09:29:14 +0000476 while (i < array_lengthof(Found) && Found[i])
477 ++i;
Duncan Sands501dff72010-08-12 11:31:39 +0000478 // Place the component at the new position, getting the component
479 // that was at this position - it will be moved right.
480 std::swap(CurrentComponent, Components[i]);
481 }
482 } else if (Pos > Idx) {
483 // Push right by inserting empty components until the component at Idx
484 // reaches the target position Pos. For example, pc-a -> -pc-a when
485 // moving pc to the second position.
486 do {
487 // Insert one empty component at Idx.
488 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000489 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands501dff72010-08-12 11:31:39 +0000490 // Place the component at the new position, getting the component
491 // that was at this position - it will be moved right.
492 std::swap(CurrentComponent, Components[i]);
493 // If it was placed on top of an empty component then we are done.
494 if (CurrentComponent.empty())
495 break;
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000496 // Advance to the next component, skipping any fixed components.
Anders Carlsson630125a2011-02-05 18:19:35 +0000497 while (++i < array_lengthof(Found) && Found[i])
498 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000499 }
500 // The last component was pushed off the end - append it.
501 if (!CurrentComponent.empty())
502 Components.push_back(CurrentComponent);
503
504 // Advance Idx to the component's new position.
Chandler Carruth362087b2012-02-21 09:29:14 +0000505 while (++Idx < array_lengthof(Found) && Found[Idx])
506 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000507 } while (Idx < Pos); // Add more until the final position is reached.
508 }
509 assert(Pos < Components.size() && Components[Pos] == Comp &&
510 "Component moved wrong!");
511 Found[Pos] = true;
512 break;
513 }
514 }
515
516 // Special case logic goes here. At this point Arch, Vendor and OS have the
517 // correct values for the computed components.
518
519 // Stick the corrected components back together to form the normalized string.
520 std::string Normalized;
521 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
522 if (i) Normalized += '-';
523 Normalized += Components[i];
524 }
525 return Normalized;
526}
527
Daniel Dunbar19e70762009-07-26 03:31:47 +0000528StringRef Triple::getArchName() const {
529 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000530}
531
Daniel Dunbar19e70762009-07-26 03:31:47 +0000532StringRef Triple::getVendorName() const {
533 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
534 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000535}
536
Daniel Dunbar19e70762009-07-26 03:31:47 +0000537StringRef Triple::getOSName() const {
538 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
539 Tmp = Tmp.split('-').second; // Strip second component
540 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000541}
542
Daniel Dunbar19e70762009-07-26 03:31:47 +0000543StringRef Triple::getEnvironmentName() const {
544 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
545 Tmp = Tmp.split('-').second; // Strip second component
546 return Tmp.split('-').second; // Strip third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000547}
548
Daniel Dunbar19e70762009-07-26 03:31:47 +0000549StringRef Triple::getOSAndEnvironmentName() const {
550 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
551 return Tmp.split('-').second; // Strip second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000552}
553
Chris Lattner553c9f32009-08-12 06:19:40 +0000554static unsigned EatNumber(StringRef &Str) {
555 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000556 unsigned Result = 0;
Jim Grosbachf638b262010-12-17 02:10:59 +0000557
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000558 do {
559 // Consume the leading digit.
Chris Lattner553c9f32009-08-12 06:19:40 +0000560 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000561
Chris Lattner553c9f32009-08-12 06:19:40 +0000562 // Eat the digit.
563 Str = Str.substr(1);
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000564 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbachf638b262010-12-17 02:10:59 +0000565
Chris Lattner553c9f32009-08-12 06:19:40 +0000566 return Result;
567}
568
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000569void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
570 unsigned &Micro) const {
Chris Lattner553c9f32009-08-12 06:19:40 +0000571 StringRef OSName = getOSName();
Jim Grosbachf638b262010-12-17 02:10:59 +0000572
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000573 // Assume that the OS portion of the triple starts with the canonical name.
574 StringRef OSTypeName = getOSTypeName(getOS());
575 if (OSName.startswith(OSTypeName))
576 OSName = OSName.substr(OSTypeName.size());
Jim Grosbachf638b262010-12-17 02:10:59 +0000577
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000578 // Any unset version defaults to 0.
579 Major = Minor = Micro = 0;
Chris Lattner553c9f32009-08-12 06:19:40 +0000580
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000581 // Parse up to three components.
582 unsigned *Components[3] = { &Major, &Minor, &Micro };
583 for (unsigned i = 0; i != 3; ++i) {
584 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
585 break;
Chris Lattner553c9f32009-08-12 06:19:40 +0000586
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000587 // Consume the leading number.
588 *Components[i] = EatNumber(OSName);
Jim Grosbachf638b262010-12-17 02:10:59 +0000589
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000590 // Consume the separator, if present.
591 if (OSName.startswith("."))
592 OSName = OSName.substr(1);
593 }
Chris Lattner553c9f32009-08-12 06:19:40 +0000594}
595
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000596bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
597 unsigned &Micro) const {
598 getOSVersion(Major, Minor, Micro);
599
600 switch (getOS()) {
Craig Toppera2886c22012-02-07 05:05:23 +0000601 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000602 case Darwin:
603 // Default to darwin8, i.e., MacOSX 10.4.
604 if (Major == 0)
605 Major = 8;
606 // Darwin version numbers are skewed from OS X versions.
607 if (Major < 4)
608 return false;
609 Micro = 0;
610 Minor = Major - 4;
611 Major = 10;
612 break;
613 case MacOSX:
614 // Default to 10.4.
615 if (Major == 0) {
616 Major = 10;
617 Minor = 4;
618 }
619 if (Major != 10)
620 return false;
621 break;
622 case IOS:
623 // Ignore the version from the triple. This is only handled because the
624 // the clang driver combines OS X and IOS support into a common Darwin
625 // toolchain that wants to know the OS X version number even when targeting
626 // IOS.
627 Major = 10;
628 Minor = 4;
629 Micro = 0;
630 break;
631 }
632 return true;
633}
634
Chad Rosierd84eaac2012-05-09 17:23:48 +0000635void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
636 unsigned &Micro) const {
637 switch (getOS()) {
638 default: llvm_unreachable("unexpected OS for Darwin triple");
639 case Darwin:
640 case MacOSX:
641 // Ignore the version from the triple. This is only handled because the
642 // the clang driver combines OS X and IOS support into a common Darwin
643 // toolchain that wants to know the iOS version number even when targeting
644 // OS X.
Tim Northover3e8df692013-12-10 11:53:16 +0000645 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000646 Minor = 0;
647 Micro = 0;
Chad Rosier2778cbc2012-05-09 17:38:47 +0000648 break;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000649 case IOS:
650 getOSVersion(Major, Minor, Micro);
Tim Northover3e8df692013-12-10 11:53:16 +0000651 // Default to 5.0.
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000652 if (Major == 0)
Tim Northover3e8df692013-12-10 11:53:16 +0000653 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000654 break;
655 }
656}
657
Daniel Dunbar19e70762009-07-26 03:31:47 +0000658void Triple::setTriple(const Twine &Str) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000659 *this = Triple(Str);
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000660}
661
662void Triple::setArch(ArchType Kind) {
663 setArchName(getArchTypeName(Kind));
664}
665
666void Triple::setVendor(VendorType Kind) {
667 setVendorName(getVendorTypeName(Kind));
668}
669
670void Triple::setOS(OSType Kind) {
671 setOSName(getOSTypeName(Kind));
672}
673
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000674void Triple::setEnvironment(EnvironmentType Kind) {
675 setEnvironmentName(getEnvironmentTypeName(Kind));
676}
677
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000678void Triple::setObjectFormat(ObjectFormatType Kind) {
679 setEnvironmentName(getObjectFormatTypeName(Kind));
680}
681
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000682void Triple::setArchName(StringRef Str) {
Jeffrey Yasskine2595b52009-10-06 21:45:26 +0000683 // Work around a miscompilation bug for Twines in gcc 4.0.3.
684 SmallString<64> Triple;
685 Triple += Str;
686 Triple += "-";
687 Triple += getVendorName();
688 Triple += "-";
689 Triple += getOSAndEnvironmentName();
690 setTriple(Triple.str());
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000691}
692
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000693void Triple::setVendorName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000694 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
695}
696
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000697void Triple::setOSName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000698 if (hasEnvironment())
699 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
700 "-" + getEnvironmentName());
701 else
702 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
703}
704
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000705void Triple::setEnvironmentName(StringRef Str) {
706 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000707 "-" + Str);
708}
709
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000710void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000711 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
712}
Chandler Carruthb90c1022012-01-31 04:52:32 +0000713
714static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
715 switch (Arch) {
716 case llvm::Triple::UnknownArch:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000717 return 0;
718
719 case llvm::Triple::msp430:
720 return 16;
721
722 case llvm::Triple::amdil:
723 case llvm::Triple::arm:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000724 case llvm::Triple::hexagon:
725 case llvm::Triple::le32:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000726 case llvm::Triple::mips:
727 case llvm::Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000728 case llvm::Triple::nvptx:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000729 case llvm::Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000730 case llvm::Triple::r600:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000731 case llvm::Triple::sparc:
732 case llvm::Triple::tce:
733 case llvm::Triple::thumb:
734 case llvm::Triple::x86:
735 case llvm::Triple::xcore:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000736 case llvm::Triple::spir:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000737 return 32;
738
Tim Northovere0e3aef2013-01-31 12:12:40 +0000739 case llvm::Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000740 case llvm::Triple::aarch64_be:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000741 case llvm::Triple::mips64:
742 case llvm::Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000743 case llvm::Triple::nvptx64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000744 case llvm::Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000745 case llvm::Triple::ppc64le:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000746 case llvm::Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000747 case llvm::Triple::systemz:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000748 case llvm::Triple::x86_64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000749 case llvm::Triple::spir64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000750 return 64;
751 }
752 llvm_unreachable("Invalid architecture value");
753}
754
755bool Triple::isArch64Bit() const {
756 return getArchPointerBitWidth(getArch()) == 64;
757}
758
759bool Triple::isArch32Bit() const {
760 return getArchPointerBitWidth(getArch()) == 32;
761}
762
763bool Triple::isArch16Bit() const {
764 return getArchPointerBitWidth(getArch()) == 16;
765}
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000766
767Triple Triple::get32BitArchVariant() const {
768 Triple T(*this);
769 switch (getArch()) {
770 case Triple::UnknownArch:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000771 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000772 case Triple::aarch64_be:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000773 case Triple::msp430:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000774 case Triple::systemz:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000775 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000776 T.setArch(UnknownArch);
777 break;
778
779 case Triple::amdil:
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000780 case Triple::spir:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000781 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000782 case Triple::hexagon:
783 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000784 case Triple::mips:
785 case Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000786 case Triple::nvptx:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000787 case Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000788 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000789 case Triple::sparc:
790 case Triple::tce:
791 case Triple::thumb:
792 case Triple::x86:
793 case Triple::xcore:
794 // Already 32-bit.
795 break;
796
797 case Triple::mips64: T.setArch(Triple::mips); break;
798 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000799 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Bob Wilsona2790b12014-03-09 23:17:28 +0000800 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000801 case Triple::sparcv9: T.setArch(Triple::sparc); break;
802 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000803 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000804 }
805 return T;
806}
807
808Triple Triple::get64BitArchVariant() const {
809 Triple T(*this);
810 switch (getArch()) {
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000811 case Triple::UnknownArch:
812 case Triple::amdil:
813 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000814 case Triple::hexagon:
815 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000816 case Triple::msp430:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000817 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000818 case Triple::tce:
819 case Triple::thumb:
820 case Triple::xcore:
821 T.setArch(UnknownArch);
822 break;
823
Tim Northovere0e3aef2013-01-31 12:12:40 +0000824 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000825 case Triple::aarch64_be:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000826 case Triple::spir64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000827 case Triple::mips64:
828 case Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000829 case Triple::nvptx64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000830 case Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000831 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000832 case Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000833 case Triple::systemz:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000834 case Triple::x86_64:
835 // Already 64-bit.
836 break;
837
838 case Triple::mips: T.setArch(Triple::mips64); break;
839 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000840 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000841 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000842 case Triple::sparc: T.setArch(Triple::sparcv9); break;
843 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000844 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000845 }
846 return T;
847}