blob: 6c978a0244bc33462740621bd2c3789fa21562b3 [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
Tim Northovere0e3aef2013-01-31 12:12:40 +000022 case aarch64: return "aarch64";
Daniel Dunbar172649b2009-07-26 04:23:03 +000023 case arm: return "arm";
Tony Linthicum1213a7a2011-12-12 21:14:40 +000024 case hexagon: return "hexagon";
Daniel Dunbar172649b2009-07-26 04:23:03 +000025 case mips: return "mips";
26 case mipsel: return "mipsel";
Akira Hatanaka6c3ad652011-09-20 18:09:37 +000027 case mips64: return "mips64";
28 case mips64el:return "mips64el";
Daniel Dunbar172649b2009-07-26 04:23:03 +000029 case msp430: return "msp430";
Daniel Dunbarbd481a12009-07-26 04:52:45 +000030 case ppc64: return "powerpc64";
Bill Schmidt0a9170d2013-07-26 01:35:43 +000031 case ppc64le: return "powerpc64le";
Daniel Dunbarbd481a12009-07-26 04:52:45 +000032 case ppc: return "powerpc";
Anton Korobeynikovf32638d2012-03-09 10:09:36 +000033 case r600: return "r600";
Daniel Dunbar172649b2009-07-26 04:23:03 +000034 case sparc: return "sparc";
Chris Lattner8228b112010-02-04 06:34:01 +000035 case sparcv9: return "sparcv9";
Richard Sandiforda238c5e2013-05-03 11:05:17 +000036 case systemz: return "s390x";
Eli Friedman28c7bbf2009-08-19 20:46:03 +000037 case tce: return "tce";
Daniel Dunbar172649b2009-07-26 04:23:03 +000038 case thumb: return "thumb";
39 case x86: return "i386";
40 case x86_64: return "x86_64";
Daniel Dunbarbd481a12009-07-26 04:52:45 +000041 case xcore: return "xcore";
Justin Holewinskiae556d32012-05-04 20:18:50 +000042 case nvptx: return "nvptx";
43 case nvptx64: return "nvptx64";
Ivan Krasin771ef8c2011-08-23 16:59:00 +000044 case le32: return "le32";
Tobias Grosser516dbb22011-08-29 15:44:55 +000045 case amdil: return "amdil";
Micah Villmow48c8ddc2012-10-01 17:01:31 +000046 case spir: return "spir";
Guy Benyeia4d31a32012-11-15 10:35:47 +000047 case spir64: return "spir64";
Daniel Dunbar4abd5662009-04-01 21:53:23 +000048 }
49
David Blaikie46a9f012012-01-20 21:51:11 +000050 llvm_unreachable("Invalid ArchType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +000051}
52
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000053const char *Triple::getArchTypePrefix(ArchType Kind) {
54 switch (Kind) {
55 default:
56 return 0;
57
Tim Northovere0e3aef2013-01-31 12:12:40 +000058 case aarch64: return "aarch64";
59
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000060 case arm:
61 case thumb: return "arm";
62
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000063 case ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +000064 case ppc64le:
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000065 case ppc: return "ppc";
66
Benjamin Kramerae3c3002012-06-28 19:09:53 +000067 case mips:
68 case mipsel:
69 case mips64:
70 case mips64el:return "mips";
71
72 case hexagon: return "hexagon";
Tony Linthicum1213a7a2011-12-12 21:14:40 +000073
Anton Korobeynikovf32638d2012-03-09 10:09:36 +000074 case r600: return "r600";
75
Chris Lattner8228b112010-02-04 06:34:01 +000076 case sparcv9:
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000077 case sparc: return "sparc";
78
Richard Sandiforda238c5e2013-05-03 11:05:17 +000079 case systemz: return "systemz";
80
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000081 case x86:
82 case x86_64: return "x86";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000083
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000084 case xcore: return "xcore";
Nick Lewycky4c82c6c2010-09-07 18:14:24 +000085
Justin Holewinskiae556d32012-05-04 20:18:50 +000086 case nvptx: return "nvptx";
87 case nvptx64: return "nvptx";
Ivan Krasin771ef8c2011-08-23 16:59:00 +000088 case le32: return "le32";
Tobias Grosser516dbb22011-08-29 15:44:55 +000089 case amdil: return "amdil";
Micah Villmow48c8ddc2012-10-01 17:01:31 +000090 case spir: return "spir";
Guy Benyeia4d31a32012-11-15 10:35:47 +000091 case spir64: return "spir";
Daniel Dunbarb8dc4ea2009-08-24 09:53:06 +000092 }
93}
94
Daniel Dunbar4abd5662009-04-01 21:53:23 +000095const char *Triple::getVendorTypeName(VendorType Kind) {
96 switch (Kind) {
97 case UnknownVendor: return "unknown";
98
99 case Apple: return "apple";
Chris Lattner07921952009-08-14 18:48:13 +0000100 case PC: return "pc";
John Thompsond0332e42011-03-15 21:51:56 +0000101 case SCEI: return "scei";
Hal Finkelf208af02012-04-02 18:31:33 +0000102 case BGP: return "bgp";
103 case BGQ: return "bgq";
Hal Finkelb5d177e2012-08-28 02:10:30 +0000104 case Freescale: return "fsl";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000105 case IBM: return "ibm";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000106 case NVIDIA: return "nvidia";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000107 }
108
David Blaikie46a9f012012-01-20 21:51:11 +0000109 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000110}
111
112const char *Triple::getOSTypeName(OSType Kind) {
113 switch (Kind) {
114 case UnknownOS: return "unknown";
115
Duncan Sands0de39b42009-06-19 14:40:01 +0000116 case AuroraUX: return "auroraux";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000117 case Cygwin: return "cygwin";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000118 case Darwin: return "darwin";
Daniel Dunbare3384c42009-05-22 02:24:11 +0000119 case DragonFly: return "dragonfly";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000120 case FreeBSD: return "freebsd";
Daniel Dunbard74bac72011-04-19 20:19:27 +0000121 case IOS: return "ios";
Duncan Sandsfe44f672011-07-26 15:30:04 +0000122 case KFreeBSD: return "kfreebsd";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000123 case Linux: return "linux";
Edward O'Callaghanba993b82009-11-19 11:59:00 +0000124 case Lv2: return "lv2";
Daniel Dunbar0854f342011-04-19 23:34:12 +0000125 case MacOSX: return "macosx";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000126 case MinGW32: return "mingw32";
Chris Lattner01218d52009-07-13 20:22:23 +0000127 case NetBSD: return "netbsd";
Duncan Sands14814d42009-06-29 13:36:13 +0000128 case OpenBSD: return "openbsd";
Daniel Dunbar781f94d2009-08-18 04:43:27 +0000129 case Solaris: return "solaris";
Daniel Dunbar172649b2009-07-26 04:23:03 +0000130 case Win32: return "win32";
Chris Lattner27f20492009-10-16 02:06:30 +0000131 case Haiku: return "haiku";
Chris Lattnerca97c922010-07-07 15:52:27 +0000132 case Minix: return "minix";
Douglas Gregorde3c9262011-07-01 22:41:06 +0000133 case RTEMS: return "rtems";
Eli Benderskyabe54632012-12-04 18:37:26 +0000134 case NaCl: return "nacl";
Hal Finkelf208af02012-04-02 18:31:33 +0000135 case CNK: return "cnk";
Eric Christopher22738d02012-08-06 20:52:18 +0000136 case Bitrig: return "bitrig";
Duncan Sandsd5772de2012-10-12 11:08:57 +0000137 case AIX: return "aix";
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000138 case CUDA: return "cuda";
139 case NVCL: return "nvcl";
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000140 }
141
David Blaikie46a9f012012-01-20 21:51:11 +0000142 llvm_unreachable("Invalid OSType");
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000143}
144
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000145const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
146 switch (Kind) {
147 case UnknownEnvironment: return "unknown";
Renato Golin83758d5c2011-01-21 18:25:47 +0000148 case GNU: return "gnu";
Rafael Espindolaf5e78fa2012-01-18 23:35:29 +0000149 case GNUEABIHF: return "gnueabihf";
Renato Golin83758d5c2011-01-21 18:25:47 +0000150 case GNUEABI: return "gnueabi";
Eli Bendersky0893e102013-01-22 18:02:49 +0000151 case GNUX32: return "gnux32";
Renato Golin83758d5c2011-01-21 18:25:47 +0000152 case EABI: return "eabi";
Evan Chengd22a4a12011-02-01 01:14:13 +0000153 case MachO: return "macho";
Logan Chien9ab55b82012-09-02 09:29:46 +0000154 case Android: return "android";
Andrew Kaylorfeb805f2012-10-02 18:38:34 +0000155 case ELF: return "elf";
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000156 }
157
David Blaikie46a9f012012-01-20 21:51:11 +0000158 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000159}
160
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000161Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruthff6f3562012-02-12 09:27:38 +0000162 return StringSwitch<Triple::ArchType>(Name)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000163 .Case("aarch64", aarch64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000164 .Case("arm", arm)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000165 .Case("mips", mips)
166 .Case("mipsel", mipsel)
167 .Case("mips64", mips64)
168 .Case("mips64el", mips64el)
169 .Case("msp430", msp430)
170 .Case("ppc64", ppc64)
171 .Case("ppc32", ppc)
172 .Case("ppc", ppc)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000173 .Case("ppc64le", ppc64le)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000174 .Case("r600", r600)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000175 .Case("hexagon", hexagon)
176 .Case("sparc", sparc)
177 .Case("sparcv9", sparcv9)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000178 .Case("systemz", systemz)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000179 .Case("tce", tce)
180 .Case("thumb", thumb)
181 .Case("x86", x86)
182 .Case("x86-64", x86_64)
183 .Case("xcore", xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000184 .Case("nvptx", nvptx)
185 .Case("nvptx64", nvptx64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000186 .Case("le32", le32)
187 .Case("amdil", amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000188 .Case("spir", spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000189 .Case("spir64", spir64)
Chandler Carruthff6f3562012-02-12 09:27:38 +0000190 .Default(UnknownArch);
Daniel Dunbar0f16ea52009-08-03 04:03:51 +0000191}
192
Duncan Sands8712da32010-03-24 09:05:14 +0000193// Returns architecture name that is understood by the target assembler.
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000194const char *Triple::getArchNameForAssembler() {
Daniel Dunbar163a0962011-04-19 21:12:05 +0000195 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000196 return NULL;
197
Chandler Carruthff6f3562012-02-12 09:27:38 +0000198 return StringSwitch<const char*>(getArchName())
199 .Case("i386", "i386")
200 .Case("x86_64", "x86_64")
201 .Case("powerpc", "ppc")
202 .Case("powerpc64", "ppc64")
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000203 .Case("powerpc64le", "ppc64le")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000204 .Case("arm", "arm")
205 .Cases("armv4t", "thumbv4t", "armv4t")
206 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
207 .Cases("armv6", "thumbv6", "armv6")
208 .Cases("armv7", "thumbv7", "armv7")
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000209 .Case("r600", "r600")
Justin Holewinskiae556d32012-05-04 20:18:50 +0000210 .Case("nvptx", "nvptx")
211 .Case("nvptx64", "nvptx64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000212 .Case("le32", "le32")
213 .Case("amdil", "amdil")
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000214 .Case("spir", "spir")
Guy Benyeia4d31a32012-11-15 10:35:47 +0000215 .Case("spir64", "spir64")
Chandler Carruthff6f3562012-02-12 09:27:38 +0000216 .Default(NULL);
Viktor Kutuzovdafdd882009-11-17 18:48:27 +0000217}
218
Chandler Carruthaec97082012-02-21 08:53:32 +0000219static Triple::ArchType parseArch(StringRef ArchName) {
220 return StringSwitch<Triple::ArchType>(ArchName)
221 .Cases("i386", "i486", "i586", "i686", Triple::x86)
222 // FIXME: Do we need to support these?
223 .Cases("i786", "i886", "i986", Triple::x86)
Jim Grosbach664d1482013-11-16 00:52:57 +0000224 .Cases("amd64", "x86_64", "x86_64h", Triple::x86_64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000225 .Case("powerpc", Triple::ppc)
226 .Cases("powerpc64", "ppu", Triple::ppc64)
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000227 .Case("powerpc64le", Triple::ppc64le)
Tim Northovere0e3aef2013-01-31 12:12:40 +0000228 .Case("aarch64", Triple::aarch64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000229 .Cases("arm", "xscale", Triple::arm)
Chandler Carruthb54950b2012-02-18 04:34:17 +0000230 // FIXME: It would be good to replace these with explicit names for all the
231 // various suffixes supported.
Chandler Carruthaec97082012-02-21 08:53:32 +0000232 .StartsWith("armv", Triple::arm)
233 .Case("thumb", Triple::thumb)
234 .StartsWith("thumbv", Triple::thumb)
Chandler Carruthaec97082012-02-21 08:53:32 +0000235 .Case("msp430", Triple::msp430)
236 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruth0c7a7cc2012-02-22 11:32:54 +0000237 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruthaec97082012-02-21 08:53:32 +0000238 .Cases("mips64", "mips64eb", Triple::mips64)
239 .Case("mips64el", Triple::mips64el)
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000240 .Case("r600", Triple::r600)
Chandler Carruthaec97082012-02-21 08:53:32 +0000241 .Case("hexagon", Triple::hexagon)
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000242 .Case("s390x", Triple::systemz)
Chandler Carruthaec97082012-02-21 08:53:32 +0000243 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenabc3d232013-05-14 17:47:27 +0000244 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruthaec97082012-02-21 08:53:32 +0000245 .Case("tce", Triple::tce)
246 .Case("xcore", Triple::xcore)
Justin Holewinskiae556d32012-05-04 20:18:50 +0000247 .Case("nvptx", Triple::nvptx)
248 .Case("nvptx64", Triple::nvptx64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000249 .Case("le32", Triple::le32)
250 .Case("amdil", Triple::amdil)
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000251 .Case("spir", Triple::spir)
Guy Benyeia4d31a32012-11-15 10:35:47 +0000252 .Case("spir64", Triple::spir64)
Chandler Carruthaec97082012-02-21 08:53:32 +0000253 .Default(Triple::UnknownArch);
Duncan Sands501dff72010-08-12 11:31:39 +0000254}
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000255
Chandler Carruthaec97082012-02-21 08:53:32 +0000256static Triple::VendorType parseVendor(StringRef VendorName) {
257 return StringSwitch<Triple::VendorType>(VendorName)
258 .Case("apple", Triple::Apple)
259 .Case("pc", Triple::PC)
260 .Case("scei", Triple::SCEI)
Hal Finkelf208af02012-04-02 18:31:33 +0000261 .Case("bgp", Triple::BGP)
262 .Case("bgq", Triple::BGQ)
Hal Finkelb5d177e2012-08-28 02:10:30 +0000263 .Case("fsl", Triple::Freescale)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000264 .Case("ibm", Triple::IBM)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000265 .Case("nvidia", Triple::NVIDIA)
Chandler Carruthaec97082012-02-21 08:53:32 +0000266 .Default(Triple::UnknownVendor);
Duncan Sands501dff72010-08-12 11:31:39 +0000267}
268
Chandler Carruthaec97082012-02-21 08:53:32 +0000269static Triple::OSType parseOS(StringRef OSName) {
270 return StringSwitch<Triple::OSType>(OSName)
271 .StartsWith("auroraux", Triple::AuroraUX)
272 .StartsWith("cygwin", Triple::Cygwin)
273 .StartsWith("darwin", Triple::Darwin)
274 .StartsWith("dragonfly", Triple::DragonFly)
275 .StartsWith("freebsd", Triple::FreeBSD)
276 .StartsWith("ios", Triple::IOS)
277 .StartsWith("kfreebsd", Triple::KFreeBSD)
278 .StartsWith("linux", Triple::Linux)
279 .StartsWith("lv2", Triple::Lv2)
280 .StartsWith("macosx", Triple::MacOSX)
281 .StartsWith("mingw32", Triple::MinGW32)
282 .StartsWith("netbsd", Triple::NetBSD)
283 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruthaec97082012-02-21 08:53:32 +0000284 .StartsWith("solaris", Triple::Solaris)
285 .StartsWith("win32", Triple::Win32)
286 .StartsWith("haiku", Triple::Haiku)
287 .StartsWith("minix", Triple::Minix)
288 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyabe54632012-12-04 18:37:26 +0000289 .StartsWith("nacl", Triple::NaCl)
Hal Finkelf208af02012-04-02 18:31:33 +0000290 .StartsWith("cnk", Triple::CNK)
Eric Christopher22738d02012-08-06 20:52:18 +0000291 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sandsd5772de2012-10-12 11:08:57 +0000292 .StartsWith("aix", Triple::AIX)
Justin Holewinskib6e6cd32013-06-21 18:51:49 +0000293 .StartsWith("cuda", Triple::CUDA)
294 .StartsWith("nvcl", Triple::NVCL)
Chandler Carruthaec97082012-02-21 08:53:32 +0000295 .Default(Triple::UnknownOS);
Duncan Sands501dff72010-08-12 11:31:39 +0000296}
297
Chandler Carruthaec97082012-02-21 08:53:32 +0000298static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
299 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
300 .StartsWith("eabi", Triple::EABI)
301 .StartsWith("gnueabihf", Triple::GNUEABIHF)
302 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky0893e102013-01-22 18:02:49 +0000303 .StartsWith("gnux32", Triple::GNUX32)
Chandler Carruthaec97082012-02-21 08:53:32 +0000304 .StartsWith("gnu", Triple::GNU)
305 .StartsWith("macho", Triple::MachO)
Logan Chien9ab55b82012-09-02 09:29:46 +0000306 .StartsWith("android", Triple::Android)
Andrew Kaylorfeb805f2012-10-02 18:38:34 +0000307 .StartsWith("elf", Triple::ELF)
Chandler Carruthaec97082012-02-21 08:53:32 +0000308 .Default(Triple::UnknownEnvironment);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000309}
310
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000311/// \brief Construct a triple from the string representation provided.
312///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000313/// This stores the string representation and parses the various pieces into
314/// enum members.
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000315Triple::Triple(const Twine &Str)
316 : Data(Str.str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000317 Arch(parseArch(getArchName())),
318 Vendor(parseVendor(getVendorName())),
319 OS(parseOS(getOSName())),
320 Environment(parseEnvironment(getEnvironmentName())) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000321}
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000322
323/// \brief Construct a triple from string representations of the architecture,
324/// vendor, and OS.
325///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000326/// This joins each argument into a canonical string representation and parses
327/// them into enum members. It leaves the environment unknown and omits it from
328/// the string representation.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000329Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
330 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000331 Arch(parseArch(ArchStr.str())),
332 Vendor(parseVendor(VendorStr.str())),
333 OS(parseOS(OSStr.str())),
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000334 Environment() {
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000335}
336
337/// \brief Construct a triple from string representations of the architecture,
338/// vendor, OS, and environment.
339///
Chandler Carruth1f3325a2012-02-21 08:31:18 +0000340/// This joins each argument into a canonical string representation and parses
341/// them into enum members.
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000342Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
343 const Twine &EnvironmentStr)
344 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
345 EnvironmentStr).str()),
Chandler Carruthaec97082012-02-21 08:53:32 +0000346 Arch(parseArch(ArchStr.str())),
347 Vendor(parseVendor(VendorStr.str())),
348 OS(parseOS(OSStr.str())),
349 Environment(parseEnvironment(EnvironmentStr.str())) {
Chandler Carruth0d887dd2012-02-20 00:02:47 +0000350}
351
Duncan Sands501dff72010-08-12 11:31:39 +0000352std::string Triple::normalize(StringRef Str) {
353 // Parse into components.
354 SmallVector<StringRef, 4> Components;
Chandler Carruth6ea6de72012-02-21 09:12:48 +0000355 Str.split(Components, "-");
Duncan Sands501dff72010-08-12 11:31:39 +0000356
357 // If the first component corresponds to a known architecture, preferentially
358 // use it for the architecture. If the second component corresponds to a
359 // known vendor, preferentially use it for the vendor, etc. This avoids silly
360 // component movement when a component parses as (eg) both a valid arch and a
361 // valid os.
362 ArchType Arch = UnknownArch;
363 if (Components.size() > 0)
Chandler Carruthaec97082012-02-21 08:53:32 +0000364 Arch = parseArch(Components[0]);
Duncan Sands501dff72010-08-12 11:31:39 +0000365 VendorType Vendor = UnknownVendor;
366 if (Components.size() > 1)
Chandler Carruthaec97082012-02-21 08:53:32 +0000367 Vendor = parseVendor(Components[1]);
Duncan Sands501dff72010-08-12 11:31:39 +0000368 OSType OS = UnknownOS;
369 if (Components.size() > 2)
Chandler Carruthaec97082012-02-21 08:53:32 +0000370 OS = parseOS(Components[2]);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000371 EnvironmentType Environment = UnknownEnvironment;
372 if (Components.size() > 3)
Chandler Carruthaec97082012-02-21 08:53:32 +0000373 Environment = parseEnvironment(Components[3]);
Duncan Sands501dff72010-08-12 11:31:39 +0000374
375 // Note which components are already in their final position. These will not
376 // be moved.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000377 bool Found[4];
Duncan Sands501dff72010-08-12 11:31:39 +0000378 Found[0] = Arch != UnknownArch;
379 Found[1] = Vendor != UnknownVendor;
380 Found[2] = OS != UnknownOS;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000381 Found[3] = Environment != UnknownEnvironment;
Duncan Sands501dff72010-08-12 11:31:39 +0000382
383 // If they are not there already, permute the components into their canonical
384 // positions by seeing if they parse as a valid architecture, and if so moving
385 // the component to the architecture position etc.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000386 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands501dff72010-08-12 11:31:39 +0000387 if (Found[Pos])
388 continue; // Already in the canonical position.
389
390 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
391 // Do not reparse any components that already matched.
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000392 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands501dff72010-08-12 11:31:39 +0000393 continue;
394
395 // Does this component parse as valid for the target position?
396 bool Valid = false;
397 StringRef Comp = Components[Idx];
398 switch (Pos) {
Craig Toppera2886c22012-02-07 05:05:23 +0000399 default: llvm_unreachable("unexpected component type!");
Duncan Sands501dff72010-08-12 11:31:39 +0000400 case 0:
Chandler Carruthaec97082012-02-21 08:53:32 +0000401 Arch = parseArch(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000402 Valid = Arch != UnknownArch;
403 break;
404 case 1:
Chandler Carruthaec97082012-02-21 08:53:32 +0000405 Vendor = parseVendor(Comp);
Duncan Sands501dff72010-08-12 11:31:39 +0000406 Valid = Vendor != UnknownVendor;
407 break;
408 case 2:
Chandler Carruthaec97082012-02-21 08:53:32 +0000409 OS = parseOS(Comp);
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000410 Valid = OS != UnknownOS;
Duncan Sands501dff72010-08-12 11:31:39 +0000411 break;
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000412 case 3:
Chandler Carruthaec97082012-02-21 08:53:32 +0000413 Environment = parseEnvironment(Comp);
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000414 Valid = Environment != UnknownEnvironment;
415 break;
Duncan Sands501dff72010-08-12 11:31:39 +0000416 }
417 if (!Valid)
418 continue; // Nope, try the next component.
419
420 // Move the component to the target position, pushing any non-fixed
421 // components that are in the way to the right. This tends to give
422 // good results in the common cases of a forgotten vendor component
423 // or a wrongly positioned environment.
424 if (Pos < Idx) {
425 // Insert left, pushing the existing components to the right. For
426 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
427 StringRef CurrentComponent(""); // The empty component.
428 // Replace the component we are moving with an empty component.
429 std::swap(CurrentComponent, Components[Idx]);
430 // Insert the component being moved at Pos, displacing any existing
431 // components to the right.
432 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
433 // Skip over any fixed components.
Chandler Carruth362087b2012-02-21 09:29:14 +0000434 while (i < array_lengthof(Found) && Found[i])
435 ++i;
Duncan Sands501dff72010-08-12 11:31:39 +0000436 // Place the component at the new position, getting the component
437 // that was at this position - it will be moved right.
438 std::swap(CurrentComponent, Components[i]);
439 }
440 } else if (Pos > Idx) {
441 // Push right by inserting empty components until the component at Idx
442 // reaches the target position Pos. For example, pc-a -> -pc-a when
443 // moving pc to the second position.
444 do {
445 // Insert one empty component at Idx.
446 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000447 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands501dff72010-08-12 11:31:39 +0000448 // Place the component at the new position, getting the component
449 // that was at this position - it will be moved right.
450 std::swap(CurrentComponent, Components[i]);
451 // If it was placed on top of an empty component then we are done.
452 if (CurrentComponent.empty())
453 break;
Duncan Sandsfdfdbd02011-02-02 10:08:38 +0000454 // Advance to the next component, skipping any fixed components.
Anders Carlsson630125a2011-02-05 18:19:35 +0000455 while (++i < array_lengthof(Found) && Found[i])
456 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000457 }
458 // The last component was pushed off the end - append it.
459 if (!CurrentComponent.empty())
460 Components.push_back(CurrentComponent);
461
462 // Advance Idx to the component's new position.
Chandler Carruth362087b2012-02-21 09:29:14 +0000463 while (++Idx < array_lengthof(Found) && Found[Idx])
464 ;
Duncan Sands501dff72010-08-12 11:31:39 +0000465 } while (Idx < Pos); // Add more until the final position is reached.
466 }
467 assert(Pos < Components.size() && Components[Pos] == Comp &&
468 "Component moved wrong!");
469 Found[Pos] = true;
470 break;
471 }
472 }
473
474 // Special case logic goes here. At this point Arch, Vendor and OS have the
475 // correct values for the computed components.
476
477 // Stick the corrected components back together to form the normalized string.
478 std::string Normalized;
479 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
480 if (i) Normalized += '-';
481 Normalized += Components[i];
482 }
483 return Normalized;
484}
485
Daniel Dunbar19e70762009-07-26 03:31:47 +0000486StringRef Triple::getArchName() const {
487 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000488}
489
Daniel Dunbar19e70762009-07-26 03:31:47 +0000490StringRef Triple::getVendorName() const {
491 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
492 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000493}
494
Daniel Dunbar19e70762009-07-26 03:31:47 +0000495StringRef Triple::getOSName() const {
496 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
497 Tmp = Tmp.split('-').second; // Strip second component
498 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000499}
500
Daniel Dunbar19e70762009-07-26 03:31:47 +0000501StringRef Triple::getEnvironmentName() const {
502 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
503 Tmp = Tmp.split('-').second; // Strip second component
504 return Tmp.split('-').second; // Strip third component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000505}
506
Daniel Dunbar19e70762009-07-26 03:31:47 +0000507StringRef Triple::getOSAndEnvironmentName() const {
508 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
509 return Tmp.split('-').second; // Strip second component
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000510}
511
Chris Lattner553c9f32009-08-12 06:19:40 +0000512static unsigned EatNumber(StringRef &Str) {
513 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000514 unsigned Result = 0;
Jim Grosbachf638b262010-12-17 02:10:59 +0000515
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000516 do {
517 // Consume the leading digit.
Chris Lattner553c9f32009-08-12 06:19:40 +0000518 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000519
Chris Lattner553c9f32009-08-12 06:19:40 +0000520 // Eat the digit.
521 Str = Str.substr(1);
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000522 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbachf638b262010-12-17 02:10:59 +0000523
Chris Lattner553c9f32009-08-12 06:19:40 +0000524 return Result;
525}
526
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000527void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
528 unsigned &Micro) const {
Chris Lattner553c9f32009-08-12 06:19:40 +0000529 StringRef OSName = getOSName();
Jim Grosbachf638b262010-12-17 02:10:59 +0000530
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000531 // Assume that the OS portion of the triple starts with the canonical name.
532 StringRef OSTypeName = getOSTypeName(getOS());
533 if (OSName.startswith(OSTypeName))
534 OSName = OSName.substr(OSTypeName.size());
Jim Grosbachf638b262010-12-17 02:10:59 +0000535
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000536 // Any unset version defaults to 0.
537 Major = Minor = Micro = 0;
Chris Lattner553c9f32009-08-12 06:19:40 +0000538
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000539 // Parse up to three components.
540 unsigned *Components[3] = { &Major, &Minor, &Micro };
541 for (unsigned i = 0; i != 3; ++i) {
542 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
543 break;
Chris Lattner553c9f32009-08-12 06:19:40 +0000544
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000545 // Consume the leading number.
546 *Components[i] = EatNumber(OSName);
Jim Grosbachf638b262010-12-17 02:10:59 +0000547
Daniel Dunbar99f904c2011-04-19 20:24:34 +0000548 // Consume the separator, if present.
549 if (OSName.startswith("."))
550 OSName = OSName.substr(1);
551 }
Chris Lattner553c9f32009-08-12 06:19:40 +0000552}
553
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000554bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
555 unsigned &Micro) const {
556 getOSVersion(Major, Minor, Micro);
557
558 switch (getOS()) {
Craig Toppera2886c22012-02-07 05:05:23 +0000559 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonaa30aff2012-01-31 22:32:29 +0000560 case Darwin:
561 // Default to darwin8, i.e., MacOSX 10.4.
562 if (Major == 0)
563 Major = 8;
564 // Darwin version numbers are skewed from OS X versions.
565 if (Major < 4)
566 return false;
567 Micro = 0;
568 Minor = Major - 4;
569 Major = 10;
570 break;
571 case MacOSX:
572 // Default to 10.4.
573 if (Major == 0) {
574 Major = 10;
575 Minor = 4;
576 }
577 if (Major != 10)
578 return false;
579 break;
580 case IOS:
581 // Ignore the version from the triple. This is only handled because the
582 // the clang driver combines OS X and IOS support into a common Darwin
583 // toolchain that wants to know the OS X version number even when targeting
584 // IOS.
585 Major = 10;
586 Minor = 4;
587 Micro = 0;
588 break;
589 }
590 return true;
591}
592
Chad Rosierd84eaac2012-05-09 17:23:48 +0000593void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
594 unsigned &Micro) const {
595 switch (getOS()) {
596 default: llvm_unreachable("unexpected OS for Darwin triple");
597 case Darwin:
598 case MacOSX:
599 // Ignore the version from the triple. This is only handled because the
600 // the clang driver combines OS X and IOS support into a common Darwin
601 // toolchain that wants to know the iOS version number even when targeting
602 // OS X.
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000603 Major = 3;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000604 Minor = 0;
605 Micro = 0;
Chad Rosier2778cbc2012-05-09 17:38:47 +0000606 break;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000607 case IOS:
608 getOSVersion(Major, Minor, Micro);
Chad Rosier9d7b1ce2012-05-09 18:23:00 +0000609 // Default to 3.0.
610 if (Major == 0)
611 Major = 3;
Chad Rosierd84eaac2012-05-09 17:23:48 +0000612 break;
613 }
614}
615
Daniel Dunbar19e70762009-07-26 03:31:47 +0000616void Triple::setTriple(const Twine &Str) {
Chandler Carruth2d27b0f2012-02-21 03:39:36 +0000617 *this = Triple(Str);
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000618}
619
620void Triple::setArch(ArchType Kind) {
621 setArchName(getArchTypeName(Kind));
622}
623
624void Triple::setVendor(VendorType Kind) {
625 setVendorName(getVendorTypeName(Kind));
626}
627
628void Triple::setOS(OSType Kind) {
629 setOSName(getOSTypeName(Kind));
630}
631
Duncan Sands84a3bdd2010-09-16 08:25:48 +0000632void Triple::setEnvironment(EnvironmentType Kind) {
633 setEnvironmentName(getEnvironmentTypeName(Kind));
634}
635
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000636void Triple::setArchName(StringRef Str) {
Jeffrey Yasskine2595b52009-10-06 21:45:26 +0000637 // Work around a miscompilation bug for Twines in gcc 4.0.3.
638 SmallString<64> Triple;
639 Triple += Str;
640 Triple += "-";
641 Triple += getVendorName();
642 Triple += "-";
643 Triple += getOSAndEnvironmentName();
644 setTriple(Triple.str());
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000645}
646
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000647void Triple::setVendorName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000648 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
649}
650
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000651void Triple::setOSName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000652 if (hasEnvironment())
653 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
654 "-" + getEnvironmentName());
655 else
656 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
657}
658
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000659void Triple::setEnvironmentName(StringRef Str) {
660 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000661 "-" + Str);
662}
663
Daniel Dunbarad36e8a2009-11-06 10:58:06 +0000664void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar4abd5662009-04-01 21:53:23 +0000665 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
666}
Chandler Carruthb90c1022012-01-31 04:52:32 +0000667
668static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
669 switch (Arch) {
670 case llvm::Triple::UnknownArch:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000671 return 0;
672
673 case llvm::Triple::msp430:
674 return 16;
675
676 case llvm::Triple::amdil:
677 case llvm::Triple::arm:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000678 case llvm::Triple::hexagon:
679 case llvm::Triple::le32:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000680 case llvm::Triple::mips:
681 case llvm::Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000682 case llvm::Triple::nvptx:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000683 case llvm::Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000684 case llvm::Triple::r600:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000685 case llvm::Triple::sparc:
686 case llvm::Triple::tce:
687 case llvm::Triple::thumb:
688 case llvm::Triple::x86:
689 case llvm::Triple::xcore:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000690 case llvm::Triple::spir:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000691 return 32;
692
Tim Northovere0e3aef2013-01-31 12:12:40 +0000693 case llvm::Triple::aarch64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000694 case llvm::Triple::mips64:
695 case llvm::Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000696 case llvm::Triple::nvptx64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000697 case llvm::Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000698 case llvm::Triple::ppc64le:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000699 case llvm::Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000700 case llvm::Triple::systemz:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000701 case llvm::Triple::x86_64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000702 case llvm::Triple::spir64:
Chandler Carruthb90c1022012-01-31 04:52:32 +0000703 return 64;
704 }
705 llvm_unreachable("Invalid architecture value");
706}
707
708bool Triple::isArch64Bit() const {
709 return getArchPointerBitWidth(getArch()) == 64;
710}
711
712bool Triple::isArch32Bit() const {
713 return getArchPointerBitWidth(getArch()) == 32;
714}
715
716bool Triple::isArch16Bit() const {
717 return getArchPointerBitWidth(getArch()) == 16;
718}
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000719
720Triple Triple::get32BitArchVariant() const {
721 Triple T(*this);
722 switch (getArch()) {
723 case Triple::UnknownArch:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000724 case Triple::aarch64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000725 case Triple::msp430:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000726 case Triple::systemz:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000727 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000728 T.setArch(UnknownArch);
729 break;
730
731 case Triple::amdil:
Micah Villmow48c8ddc2012-10-01 17:01:31 +0000732 case Triple::spir:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000733 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000734 case Triple::hexagon:
735 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000736 case Triple::mips:
737 case Triple::mipsel:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000738 case Triple::nvptx:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000739 case Triple::ppc:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000740 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000741 case Triple::sparc:
742 case Triple::tce:
743 case Triple::thumb:
744 case Triple::x86:
745 case Triple::xcore:
746 // Already 32-bit.
747 break;
748
749 case Triple::mips64: T.setArch(Triple::mips); break;
750 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000751 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000752 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000753 case Triple::sparcv9: T.setArch(Triple::sparc); break;
754 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000755 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000756 }
757 return T;
758}
759
760Triple Triple::get64BitArchVariant() const {
761 Triple T(*this);
762 switch (getArch()) {
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000763 case Triple::UnknownArch:
764 case Triple::amdil:
765 case Triple::arm:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000766 case Triple::hexagon:
767 case Triple::le32:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000768 case Triple::msp430:
Anton Korobeynikovf32638d2012-03-09 10:09:36 +0000769 case Triple::r600:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000770 case Triple::tce:
771 case Triple::thumb:
772 case Triple::xcore:
773 T.setArch(UnknownArch);
774 break;
775
Tim Northovere0e3aef2013-01-31 12:12:40 +0000776 case Triple::aarch64:
Guy Benyeia4d31a32012-11-15 10:35:47 +0000777 case Triple::spir64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000778 case Triple::mips64:
779 case Triple::mips64el:
Justin Holewinskiae556d32012-05-04 20:18:50 +0000780 case Triple::nvptx64:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000781 case Triple::ppc64:
Bill Schmidt0a9170d2013-07-26 01:35:43 +0000782 case Triple::ppc64le:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000783 case Triple::sparcv9:
Richard Sandiforda238c5e2013-05-03 11:05:17 +0000784 case Triple::systemz:
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000785 case Triple::x86_64:
786 // Already 64-bit.
787 break;
788
789 case Triple::mips: T.setArch(Triple::mips64); break;
790 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinskiae556d32012-05-04 20:18:50 +0000791 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000792 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000793 case Triple::sparc: T.setArch(Triple::sparcv9); break;
794 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeia4d31a32012-11-15 10:35:47 +0000795 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth07cfb4b2012-02-06 20:46:33 +0000796 }
797 return T;
798}