blob: 85a3422bb7c42722a0b36bd1c5b5e900904d8a46 [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";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000132 case Win32: return "windows";
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";
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000158 case MSVC: return "msvc";
159 case Itanium: return "itanium";
160 case Cygnus: return "cygnus";
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000161 }
162
David Blaikie46a9f012012-01-20 21:51:11 +0000163 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000164}
165
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000166Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruthff6f3562012-02-12 09:27:38 +0000167 return StringSwitch<Triple::ArchType>(Name)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000168 .Case("aarch64", aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000169 .Case("aarch64_be", aarch64_be)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000170 .Case("arm", arm)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000171 .Case("mips", mips)
172 .Case("mipsel", mipsel)
173 .Case("mips64", mips64)
174 .Case("mips64el", mips64el)
175 .Case("msp430", msp430)
176 .Case("ppc64", ppc64)
177 .Case("ppc32", ppc)
178 .Case("ppc", ppc)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000179 .Case("ppc64le", ppc64le)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000180 .Case("r600", r600)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000181 .Case("hexagon", hexagon)
182 .Case("sparc", sparc)
183 .Case("sparcv9", sparcv9)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000184 .Case("systemz", systemz)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000185 .Case("tce", tce)
186 .Case("thumb", thumb)
187 .Case("x86", x86)
188 .Case("x86-64", x86_64)
189 .Case("xcore", xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000190 .Case("nvptx", nvptx)
191 .Case("nvptx64", nvptx64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000192 .Case("le32", le32)
193 .Case("amdil", amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000194 .Case("spir", spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000195 .Case("spir64", spir64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000196 .Default(UnknownArch);
Daniel Dunbar0f16ea52009-08-03 04:03:51 +0000197}
198
Duncan Sands8712da32010-03-24 09:05:14 +0000199// Returns architecture name that is understood by the target assembler.
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000200const char *Triple::getArchNameForAssembler() {
Daniel Dunbar163a0962011-04-19 21:12:05 +0000201 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000202 return NULL;
203
Chandler Carruthff6f3562012-02-12 09:27:38 +0000204 return StringSwitch<const char*>(getArchName())
205 .Case("i386", "i386")
206 .Case("x86_64", "x86_64")
207 .Case("powerpc", "ppc")
208 .Case("powerpc64", "ppc64")
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000209 .Case("powerpc64le", "ppc64le")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000210 .Case("arm", "arm")
211 .Cases("armv4t", "thumbv4t", "armv4t")
212 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
213 .Cases("armv6", "thumbv6", "armv6")
214 .Cases("armv7", "thumbv7", "armv7")
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000215 .Case("r600", "r600")
Justin Holewinskiae556d32012-05-04 20:18:50 +0000216 .Case("nvptx", "nvptx")
217 .Case("nvptx64", "nvptx64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000218 .Case("le32", "le32")
219 .Case("amdil", "amdil")
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000220 .Case("spir", "spir")
Guy Benyeia4d31a32012-11-15 10:35:47 +0000221 .Case("spir64", "spir64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000222 .Default(NULL);
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000223}
224
Chandler Carruthaec97082012-02-21 08:53:32 +0000225static Triple::ArchType parseArch(StringRef ArchName) {
226 return StringSwitch<Triple::ArchType>(ArchName)
227 .Cases("i386", "i486", "i586", "i686", Triple::x86)
228 // FIXME: Do we need to support these?
229 .Cases("i786", "i886", "i986", Triple::x86)
Jim Grosbach664d1482013-11-16 00:52:57 +0000230 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000231 .Case("powerpc", Triple::ppc)
232 .Cases("powerpc64", "ppu", Triple::ppc64)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000233 .Case("powerpc64le", Triple::ppc64le)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000234 .Case("aarch64", Triple::aarch64)
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000235 .Case("aarch64_be", Triple::aarch64_be)
Chandler Carruthaec97082012-02-21 08:53:32 +0000236 .Cases("arm", "xscale", Triple::arm)
Chandler Carruthb54950b2012-02-18 04:34:17 +0000237 // FIXME: It would be good to replace these with explicit names for all the
238 // various suffixes supported.
Chandler Carruthaec97082012-02-21 08:53:32 +0000239 .StartsWith("armv", Triple::arm)
240 .Case("thumb", Triple::thumb)
241 .StartsWith("thumbv", Triple::thumb)
Chandler Carruthaec97082012-02-21 08:53:32 +0000242 .Case("msp430", Triple::msp430)
243 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruth0c7a7cc2012-02-22 11:32:54 +0000244 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruthaec97082012-02-21 08:53:32 +0000245 .Cases("mips64", "mips64eb", Triple::mips64)
246 .Case("mips64el", Triple::mips64el)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000247 .Case("r600", Triple::r600)
Chandler Carruthaec97082012-02-21 08:53:32 +0000248 .Case("hexagon", Triple::hexagon)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000249 .Case("s390x", Triple::systemz)
Chandler Carruthaec97082012-02-21 08:53:32 +0000250 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenabc3d232013-05-14 17:47:27 +0000251 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruthaec97082012-02-21 08:53:32 +0000252 .Case("tce", Triple::tce)
253 .Case("xcore", Triple::xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000254 .Case("nvptx", Triple::nvptx)
255 .Case("nvptx64", Triple::nvptx64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000256 .Case("le32", Triple::le32)
257 .Case("amdil", Triple::amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000258 .Case("spir", Triple::spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000259 .Case("spir64", Triple::spir64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000260 .Default(Triple::UnknownArch);
Duncan Sands501dff72010-08-12 11:31:39 +0000261}
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000262
Chandler Carruthaec97082012-02-21 08:53:32 +0000263static Triple::VendorType parseVendor(StringRef VendorName) {
264 return StringSwitch<Triple::VendorType>(VendorName)
265 .Case("apple", Triple::Apple)
266 .Case("pc", Triple::PC)
267 .Case("scei", Triple::SCEI)
Hal Finkelf208af02012-04-02 18:31:33 +0000268 .Case("bgp", Triple::BGP)
269 .Case("bgq", Triple::BGQ)
Hal Finkelb5d177e2012-08-28 02:10:30 +0000270 .Case("fsl", Triple::Freescale)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000271 .Case("ibm", Triple::IBM)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000272 .Case("nvidia", Triple::NVIDIA)
Chandler Carruthaec97082012-02-21 08:53:32 +0000273 .Default(Triple::UnknownVendor);
Duncan Sands501dff72010-08-12 11:31:39 +0000274}
275
Chandler Carruthaec97082012-02-21 08:53:32 +0000276static Triple::OSType parseOS(StringRef OSName) {
277 return StringSwitch<Triple::OSType>(OSName)
278 .StartsWith("auroraux", Triple::AuroraUX)
279 .StartsWith("cygwin", Triple::Cygwin)
280 .StartsWith("darwin", Triple::Darwin)
281 .StartsWith("dragonfly", Triple::DragonFly)
282 .StartsWith("freebsd", Triple::FreeBSD)
283 .StartsWith("ios", Triple::IOS)
284 .StartsWith("kfreebsd", Triple::KFreeBSD)
285 .StartsWith("linux", Triple::Linux)
286 .StartsWith("lv2", Triple::Lv2)
287 .StartsWith("macosx", Triple::MacOSX)
288 .StartsWith("mingw32", Triple::MinGW32)
289 .StartsWith("netbsd", Triple::NetBSD)
290 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruthaec97082012-02-21 08:53:32 +0000291 .StartsWith("solaris", Triple::Solaris)
292 .StartsWith("win32", Triple::Win32)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000293 .StartsWith("windows", Triple::Win32)
Chandler Carruthaec97082012-02-21 08:53:32 +0000294 .StartsWith("haiku", Triple::Haiku)
295 .StartsWith("minix", Triple::Minix)
296 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyabe54632012-12-04 18:37:26 +0000297 .StartsWith("nacl", Triple::NaCl)
Hal Finkelf208af02012-04-02 18:31:33 +0000298 .StartsWith("cnk", Triple::CNK)
Eric Christopher22738d02012-08-06 20:52:18 +0000299 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000300 .StartsWith("aix", Triple::AIX)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000301 .StartsWith("cuda", Triple::CUDA)
302 .StartsWith("nvcl", Triple::NVCL)
Chandler Carruthaec97082012-02-21 08:53:32 +0000303 .Default(Triple::UnknownOS);
Duncan Sands501dff72010-08-12 11:31:39 +0000304}
305
Chandler Carruthaec97082012-02-21 08:53:32 +0000306static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
307 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
Joerg Sonnenberger8fe41b72013-12-16 18:51:28 +0000308 .StartsWith("eabihf", Triple::EABIHF)
Chandler Carruthaec97082012-02-21 08:53:32 +0000309 .StartsWith("eabi", Triple::EABI)
310 .StartsWith("gnueabihf", Triple::GNUEABIHF)
311 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky0893e102013-01-22 18:02:49 +0000312 .StartsWith("gnux32", Triple::GNUX32)
David Woodhouse71d15ed2014-01-20 12:02:25 +0000313 .StartsWith("code16", Triple::CODE16)
Chandler Carruthaec97082012-02-21 08:53:32 +0000314 .StartsWith("gnu", Triple::GNU)
Logan Chien9ab55b82012-09-02 09:29:46 +0000315 .StartsWith("android", Triple::Android)
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000316 .StartsWith("msvc", Triple::MSVC)
317 .StartsWith("itanium", Triple::Itanium)
318 .StartsWith("cygnus", Triple::Cygnus)
Chandler Carruthaec97082012-02-21 08:53:32 +0000319 .Default(Triple::UnknownEnvironment);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000320}
321
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000322static Triple::ObjectFormatType parseFormat(StringRef EnvironmentName) {
323 return StringSwitch<Triple::ObjectFormatType>(EnvironmentName)
324 .EndsWith("coff", Triple::COFF)
325 .EndsWith("elf", Triple::ELF)
326 .EndsWith("macho", Triple::MachO)
327 .Default(Triple::UnknownObjectFormat);
328}
329
330static const char *getObjectFormatTypeName(Triple::ObjectFormatType Kind) {
331 switch (Kind) {
332 case Triple::UnknownObjectFormat: return "";
333 case Triple::COFF: return "coff";
334 case Triple::ELF: return "elf";
335 case Triple::MachO: return "macho";
336 }
337 llvm_unreachable("unknown object format type");
338}
339
340static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
341 if (T.isOSDarwin())
342 return Triple::MachO;
343 else if (T.isOSWindows())
344 return Triple::COFF;
345 return Triple::ELF;
346}
347
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000348/// \brief Construct a triple from the string representation provided.
349///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000350/// This stores the string representation and parses the various pieces into
351/// enum members.
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000352Triple::Triple(const Twine &Str)
353 : Data(Str.str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000354 Arch(parseArch(getArchName())),
355 Vendor(parseVendor(getVendorName())),
356 OS(parseOS(getOSName())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000357 Environment(parseEnvironment(getEnvironmentName())),
358 ObjectFormat(parseFormat(getEnvironmentName())) {
359 if (ObjectFormat == Triple::UnknownObjectFormat)
360 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000361}
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000362
363/// \brief Construct a triple from string representations of the architecture,
364/// vendor, and OS.
365///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000366/// This joins each argument into a canonical string representation and parses
367/// them into enum members. It leaves the environment unknown and omits it from
368/// the string representation.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000369Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
370 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000371 Arch(parseArch(ArchStr.str())),
372 Vendor(parseVendor(VendorStr.str())),
373 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000374 Environment(), ObjectFormat(Triple::UnknownObjectFormat) {
375 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000376}
377
378/// \brief Construct a triple from string representations of the architecture,
379/// vendor, OS, and environment.
380///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000381/// This joins each argument into a canonical string representation and parses
382/// them into enum members.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000383Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
384 const Twine &EnvironmentStr)
385 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
386 EnvironmentStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000387 Arch(parseArch(ArchStr.str())),
388 Vendor(parseVendor(VendorStr.str())),
389 OS(parseOS(OSStr.str())),
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000390 Environment(parseEnvironment(EnvironmentStr.str())),
391 ObjectFormat(parseFormat(EnvironmentStr.str())) {
392 if (ObjectFormat == Triple::UnknownObjectFormat)
393 ObjectFormat = getDefaultFormat(*this);
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000394}
395
Duncan Sands501dff72010-08-12 11:31:39 +0000396std::string Triple::normalize(StringRef Str) {
397 // Parse into components.
398 SmallVector<StringRef, 4> Components;
Chandler Carruth6ea6de72012-02-21 09:12:48 +0000399 Str.split(Components, "-");
Duncan Sands501dff72010-08-12 11:31:39 +0000400
401 // If the first component corresponds to a known architecture, preferentially
402 // use it for the architecture. If the second component corresponds to a
403 // known vendor, preferentially use it for the vendor, etc. This avoids silly
404 // component movement when a component parses as (eg) both a valid arch and a
405 // valid os.
406 ArchType Arch = UnknownArch;
407 if (Components.size() > 0)
Chandler Carruthaec97082012-02-21 08:53:32 +0000408 Arch = parseArch(Components[0]);
Duncan Sands501dff72010-08-12 11:31:39 +0000409 VendorType Vendor = UnknownVendor;
410 if (Components.size() > 1)
Chandler Carruthaec97082012-02-21 08:53:32 +0000411 Vendor = parseVendor(Components[1]);
Duncan Sands501dff72010-08-12 11:31:39 +0000412 OSType OS = UnknownOS;
413 if (Components.size() > 2)
Chandler Carruthaec97082012-02-21 08:53:32 +0000414 OS = parseOS(Components[2]);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000415 EnvironmentType Environment = UnknownEnvironment;
416 if (Components.size() > 3)
Chandler Carruthaec97082012-02-21 08:53:32 +0000417 Environment = parseEnvironment(Components[3]);
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000418 ObjectFormatType ObjectFormat = UnknownObjectFormat;
Duncan Sands501dff72010-08-12 11:31:39 +0000419
420 // Note which components are already in their final position. These will not
421 // be moved.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000422 bool Found[4];
Duncan Sands501dff72010-08-12 11:31:39 +0000423 Found[0] = Arch != UnknownArch;
424 Found[1] = Vendor != UnknownVendor;
425 Found[2] = OS != UnknownOS;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000426 Found[3] = Environment != UnknownEnvironment;
Duncan Sands501dff72010-08-12 11:31:39 +0000427
428 // If they are not there already, permute the components into their canonical
429 // positions by seeing if they parse as a valid architecture, and if so moving
430 // the component to the architecture position etc.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000431 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands501dff72010-08-12 11:31:39 +0000432 if (Found[Pos])
433 continue; // Already in the canonical position.
434
435 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
436 // Do not reparse any components that already matched.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000437 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands501dff72010-08-12 11:31:39 +0000438 continue;
439
440 // Does this component parse as valid for the target position?
441 bool Valid = false;
442 StringRef Comp = Components[Idx];
443 switch (Pos) {
Craig Toppera2886c22012-02-07 05:05:23 +0000444 default: llvm_unreachable("unexpected component type!");
Duncan Sands501dff72010-08-12 11:31:39 +0000445 case 0:
Chandler Carruthaec97082012-02-21 08:53:32 +0000446 Arch = parseArch(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000447 Valid = Arch != UnknownArch;
448 break;
449 case 1:
Chandler Carruthaec97082012-02-21 08:53:32 +0000450 Vendor = parseVendor(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000451 Valid = Vendor != UnknownVendor;
452 break;
453 case 2:
Chandler Carruthaec97082012-02-21 08:53:32 +0000454 OS = parseOS(Comp);
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000455 Valid = OS != UnknownOS;
Duncan Sands501dff72010-08-12 11:31:39 +0000456 break;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000457 case 3:
Chandler Carruthaec97082012-02-21 08:53:32 +0000458 Environment = parseEnvironment(Comp);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000459 Valid = Environment != UnknownEnvironment;
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000460 if (!Valid) {
461 ObjectFormat = parseFormat(Comp);
462 Valid = ObjectFormat != UnknownObjectFormat;
463 }
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000464 break;
Duncan Sands501dff72010-08-12 11:31:39 +0000465 }
466 if (!Valid)
467 continue; // Nope, try the next component.
468
469 // Move the component to the target position, pushing any non-fixed
470 // components that are in the way to the right. This tends to give
471 // good results in the common cases of a forgotten vendor component
472 // or a wrongly positioned environment.
473 if (Pos < Idx) {
474 // Insert left, pushing the existing components to the right. For
475 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
476 StringRef CurrentComponent(""); // The empty component.
477 // Replace the component we are moving with an empty component.
478 std::swap(CurrentComponent, Components[Idx]);
479 // Insert the component being moved at Pos, displacing any existing
480 // components to the right.
481 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
482 // Skip over any fixed components.
Chandler Carruth362087b2012-02-21 09:29:14 +0000483 while (i < array_lengthof(Found) && Found[i])
484 ++i;
Duncan Sands501dff72010-08-12 11:31:39 +0000485 // Place the component at the new position, getting the component
486 // that was at this position - it will be moved right.
487 std::swap(CurrentComponent, Components[i]);
488 }
489 } else if (Pos > Idx) {
490 // Push right by inserting empty components until the component at Idx
491 // reaches the target position Pos. For example, pc-a -> -pc-a when
492 // moving pc to the second position.
493 do {
494 // Insert one empty component at Idx.
495 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000496 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands501dff72010-08-12 11:31:39 +0000497 // Place the component at the new position, getting the component
498 // that was at this position - it will be moved right.
499 std::swap(CurrentComponent, Components[i]);
500 // If it was placed on top of an empty component then we are done.
501 if (CurrentComponent.empty())
502 break;
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000503 // Advance to the next component, skipping any fixed components.
Anders Carlsson630125a2011-02-05 18:19:35 +0000504 while (++i < array_lengthof(Found) && Found[i])
505 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000506 }
507 // The last component was pushed off the end - append it.
508 if (!CurrentComponent.empty())
509 Components.push_back(CurrentComponent);
510
511 // Advance Idx to the component's new position.
Chandler Carruth362087b2012-02-21 09:29:14 +0000512 while (++Idx < array_lengthof(Found) && Found[Idx])
513 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000514 } while (Idx < Pos); // Add more until the final position is reached.
515 }
516 assert(Pos < Components.size() && Components[Pos] == Comp &&
517 "Component moved wrong!");
518 Found[Pos] = true;
519 break;
520 }
521 }
522
523 // Special case logic goes here. At this point Arch, Vendor and OS have the
524 // correct values for the computed components.
525
Saleem Abdulrasooledbdd2e2014-03-27 22:50:05 +0000526 if (OS == Triple::Win32) {
527 Components.resize(4);
528 Components[2] = "windows";
529 if (Environment == UnknownEnvironment && ObjectFormat == UnknownObjectFormat)
530 Components[3] = "msvc";
531 } else if (OS == Triple::MinGW32) {
532 Components.resize(4);
533 Components[2] = "windows";
534 Components[3] = (ObjectFormat == Triple::ELF) ? "gnuelf" : "gnu";
535 } else if (OS == Triple::Cygwin) {
536 Components.resize(4);
537 Components[2] = "windows";
538 Components[3] = "cygnus";
539 }
540
Duncan Sands501dff72010-08-12 11:31:39 +0000541 // Stick the corrected components back together to form the normalized string.
542 std::string Normalized;
543 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
544 if (i) Normalized += '-';
545 Normalized += Components[i];
546 }
547 return Normalized;
548}
549
Daniel Dunbar19e70762009-07-26 03:31:47 +0000550StringRef Triple::getArchName() const {
551 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000552}
553
Daniel Dunbar19e70762009-07-26 03:31:47 +0000554StringRef Triple::getVendorName() const {
555 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
556 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000557}
558
Daniel Dunbar19e70762009-07-26 03:31:47 +0000559StringRef Triple::getOSName() const {
560 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
561 Tmp = Tmp.split('-').second; // Strip second component
562 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000563}
564
Daniel Dunbar19e70762009-07-26 03:31:47 +0000565StringRef Triple::getEnvironmentName() const {
566 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
567 Tmp = Tmp.split('-').second; // Strip second component
568 return Tmp.split('-').second; // Strip third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000569}
570
Daniel Dunbar19e70762009-07-26 03:31:47 +0000571StringRef Triple::getOSAndEnvironmentName() const {
572 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
573 return Tmp.split('-').second; // Strip second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000574}
575
Chris Lattner553c9f32009-08-12 06:19:40 +0000576static unsigned EatNumber(StringRef &Str) {
577 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000578 unsigned Result = 0;
Jim Grosbachf638b262010-12-17 02:10:59 +0000579
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000580 do {
581 // Consume the leading digit.
Chris Lattner553c9f32009-08-12 06:19:40 +0000582 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000583
Chris Lattner553c9f32009-08-12 06:19:40 +0000584 // Eat the digit.
585 Str = Str.substr(1);
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000586 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbachf638b262010-12-17 02:10:59 +0000587
Chris Lattner553c9f32009-08-12 06:19:40 +0000588 return Result;
589}
590
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000591void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
592 unsigned &Micro) const {
Chris Lattner553c9f32009-08-12 06:19:40 +0000593 StringRef OSName = getOSName();
Jim Grosbachf638b262010-12-17 02:10:59 +0000594
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000595 // Assume that the OS portion of the triple starts with the canonical name.
596 StringRef OSTypeName = getOSTypeName(getOS());
597 if (OSName.startswith(OSTypeName))
598 OSName = OSName.substr(OSTypeName.size());
Jim Grosbachf638b262010-12-17 02:10:59 +0000599
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000600 // Any unset version defaults to 0.
601 Major = Minor = Micro = 0;
Chris Lattner553c9f32009-08-12 06:19:40 +0000602
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000603 // Parse up to three components.
604 unsigned *Components[3] = { &Major, &Minor, &Micro };
605 for (unsigned i = 0; i != 3; ++i) {
606 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
607 break;
Chris Lattner553c9f32009-08-12 06:19:40 +0000608
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000609 // Consume the leading number.
610 *Components[i] = EatNumber(OSName);
Jim Grosbachf638b262010-12-17 02:10:59 +0000611
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000612 // Consume the separator, if present.
613 if (OSName.startswith("."))
614 OSName = OSName.substr(1);
615 }
Chris Lattner553c9f32009-08-12 06:19:40 +0000616}
617
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000618bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
619 unsigned &Micro) const {
620 getOSVersion(Major, Minor, Micro);
621
622 switch (getOS()) {
Craig Toppera2886c22012-02-07 05:05:23 +0000623 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000624 case Darwin:
625 // Default to darwin8, i.e., MacOSX 10.4.
626 if (Major == 0)
627 Major = 8;
628 // Darwin version numbers are skewed from OS X versions.
629 if (Major < 4)
630 return false;
631 Micro = 0;
632 Minor = Major - 4;
633 Major = 10;
634 break;
635 case MacOSX:
636 // Default to 10.4.
637 if (Major == 0) {
638 Major = 10;
639 Minor = 4;
640 }
641 if (Major != 10)
642 return false;
643 break;
644 case IOS:
645 // Ignore the version from the triple. This is only handled because the
646 // the clang driver combines OS X and IOS support into a common Darwin
647 // toolchain that wants to know the OS X version number even when targeting
648 // IOS.
649 Major = 10;
650 Minor = 4;
651 Micro = 0;
652 break;
653 }
654 return true;
655}
656
Chad Rosierd84eaac2012-05-09 17:23:48 +0000657void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
658 unsigned &Micro) const {
659 switch (getOS()) {
660 default: llvm_unreachable("unexpected OS for Darwin triple");
661 case Darwin:
662 case MacOSX:
663 // Ignore the version from the triple. This is only handled because the
664 // the clang driver combines OS X and IOS support into a common Darwin
665 // toolchain that wants to know the iOS version number even when targeting
666 // OS X.
Tim Northover3e8df692013-12-10 11:53:16 +0000667 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000668 Minor = 0;
669 Micro = 0;
Chad Rosier2778cbc2012-05-09 17:38:47 +0000670 break;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000671 case IOS:
672 getOSVersion(Major, Minor, Micro);
Tim Northover3e8df692013-12-10 11:53:16 +0000673 // Default to 5.0.
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000674 if (Major == 0)
Tim Northover3e8df692013-12-10 11:53:16 +0000675 Major = 5;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000676 break;
677 }
678}
679
Daniel Dunbar19e70762009-07-26 03:31:47 +0000680void Triple::setTriple(const Twine &Str) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000681 *this = Triple(Str);
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000682}
683
684void Triple::setArch(ArchType Kind) {
685 setArchName(getArchTypeName(Kind));
686}
687
688void Triple::setVendor(VendorType Kind) {
689 setVendorName(getVendorTypeName(Kind));
690}
691
692void Triple::setOS(OSType Kind) {
693 setOSName(getOSTypeName(Kind));
694}
695
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000696void Triple::setEnvironment(EnvironmentType Kind) {
697 setEnvironmentName(getEnvironmentTypeName(Kind));
698}
699
Saleem Abdulrasool35476332014-03-06 20:47:11 +0000700void Triple::setObjectFormat(ObjectFormatType Kind) {
701 setEnvironmentName(getObjectFormatTypeName(Kind));
702}
703
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000704void Triple::setArchName(StringRef Str) {
Jeffrey Yasskine2595b52009-10-06 21:45:26 +0000705 // Work around a miscompilation bug for Twines in gcc 4.0.3.
706 SmallString<64> Triple;
707 Triple += Str;
708 Triple += "-";
709 Triple += getVendorName();
710 Triple += "-";
711 Triple += getOSAndEnvironmentName();
712 setTriple(Triple.str());
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000713}
714
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000715void Triple::setVendorName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000716 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
717}
718
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000719void Triple::setOSName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000720 if (hasEnvironment())
721 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
722 "-" + getEnvironmentName());
723 else
724 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
725}
726
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000727void Triple::setEnvironmentName(StringRef Str) {
728 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000729 "-" + Str);
730}
731
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000732void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000733 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
734}
Chandler Carruthb90c1022012-01-31 04:52:32 +0000735
736static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
737 switch (Arch) {
738 case llvm::Triple::UnknownArch:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000739 return 0;
740
741 case llvm::Triple::msp430:
742 return 16;
743
744 case llvm::Triple::amdil:
745 case llvm::Triple::arm:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000746 case llvm::Triple::hexagon:
747 case llvm::Triple::le32:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000748 case llvm::Triple::mips:
749 case llvm::Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000750 case llvm::Triple::nvptx:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000751 case llvm::Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000752 case llvm::Triple::r600:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000753 case llvm::Triple::sparc:
754 case llvm::Triple::tce:
755 case llvm::Triple::thumb:
756 case llvm::Triple::x86:
757 case llvm::Triple::xcore:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000758 case llvm::Triple::spir:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000759 return 32;
760
Tim Northovere0e3aef2013-01-31 12:12:40 +0000761 case llvm::Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000762 case llvm::Triple::aarch64_be:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000763 case llvm::Triple::mips64:
764 case llvm::Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000765 case llvm::Triple::nvptx64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000766 case llvm::Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000767 case llvm::Triple::ppc64le:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000768 case llvm::Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000769 case llvm::Triple::systemz:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000770 case llvm::Triple::x86_64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000771 case llvm::Triple::spir64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000772 return 64;
773 }
774 llvm_unreachable("Invalid architecture value");
775}
776
777bool Triple::isArch64Bit() const {
778 return getArchPointerBitWidth(getArch()) == 64;
779}
780
781bool Triple::isArch32Bit() const {
782 return getArchPointerBitWidth(getArch()) == 32;
783}
784
785bool Triple::isArch16Bit() const {
786 return getArchPointerBitWidth(getArch()) == 16;
787}
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000788
789Triple Triple::get32BitArchVariant() const {
790 Triple T(*this);
791 switch (getArch()) {
792 case Triple::UnknownArch:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000793 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000794 case Triple::aarch64_be:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000795 case Triple::msp430:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000796 case Triple::systemz:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000797 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000798 T.setArch(UnknownArch);
799 break;
800
801 case Triple::amdil:
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000802 case Triple::spir:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000803 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000804 case Triple::hexagon:
805 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000806 case Triple::mips:
807 case Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000808 case Triple::nvptx:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000809 case Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000810 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000811 case Triple::sparc:
812 case Triple::tce:
813 case Triple::thumb:
814 case Triple::x86:
815 case Triple::xcore:
816 // Already 32-bit.
817 break;
818
819 case Triple::mips64: T.setArch(Triple::mips); break;
820 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000821 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Bob Wilsona2790b12014-03-09 23:17:28 +0000822 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000823 case Triple::sparcv9: T.setArch(Triple::sparc); break;
824 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000825 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000826 }
827 return T;
828}
829
830Triple Triple::get64BitArchVariant() const {
831 Triple T(*this);
832 switch (getArch()) {
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000833 case Triple::UnknownArch:
834 case Triple::amdil:
835 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000836 case Triple::hexagon:
837 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000838 case Triple::msp430:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000839 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000840 case Triple::tce:
841 case Triple::thumb:
842 case Triple::xcore:
843 T.setArch(UnknownArch);
844 break;
845
Tim Northovere0e3aef2013-01-31 12:12:40 +0000846 case Triple::aarch64:
Christian Pirker6c2f4d42014-02-24 11:34:50 +0000847 case Triple::aarch64_be:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000848 case Triple::spir64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000849 case Triple::mips64:
850 case Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000851 case Triple::nvptx64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000852 case Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000853 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000854 case Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000855 case Triple::systemz:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000856 case Triple::x86_64:
857 // Already 64-bit.
858 break;
859
860 case Triple::mips: T.setArch(Triple::mips64); break;
861 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000862 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000863 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000864 case Triple::sparc: T.setArch(Triple::sparcv9); break;
865 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000866 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000867 }
868 return T;
869}