blob: 3b1bff92130243dcfa6022c8ed4f2a04c49fc301 [file] [log] [blame]
Daniel Dunbar23e97b02009-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 Carruthd04a8d42012-12-03 16:50:05 +000011#include "llvm/ADT/STLExtras.h"
Jeffrey Yasskin0b228732009-10-06 21:45:26 +000012#include "llvm/ADT/SmallString.h"
Chandler Carruth06accda2012-02-12 09:27:38 +000013#include "llvm/ADT/StringSwitch.h"
David Blaikie4d6ccb52012-01-20 21:51:11 +000014#include "llvm/Support/ErrorHandling.h"
Mikhail Glushenkov70748752009-04-02 01:11:37 +000015#include <cstring>
Daniel Dunbar23e97b02009-04-01 21:53:23 +000016using namespace llvm;
17
Daniel Dunbar23e97b02009-04-01 21:53:23 +000018const char *Triple::getArchTypeName(ArchType Kind) {
19 switch (Kind) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +000020 case UnknownArch: return "unknown";
Jim Grosbache509aa92010-12-17 02:10:59 +000021
Tim Northover72062f52013-01-31 12:12:40 +000022 case aarch64: return "aarch64";
Daniel Dunbar6337f152009-07-26 04:23:03 +000023 case arm: return "arm";
Tony Linthicumb4b54152011-12-12 21:14:40 +000024 case hexagon: return "hexagon";
Daniel Dunbar6337f152009-07-26 04:23:03 +000025 case mips: return "mips";
26 case mipsel: return "mipsel";
Akira Hatanaka70303682011-09-20 18:09:37 +000027 case mips64: return "mips64";
28 case mips64el:return "mips64el";
Daniel Dunbar6337f152009-07-26 04:23:03 +000029 case msp430: return "msp430";
Daniel Dunbar8c2f1d72009-07-26 04:52:45 +000030 case ppc64: return "powerpc64";
31 case ppc: return "powerpc";
Anton Korobeynikov74156592012-03-09 10:09:36 +000032 case r600: return "r600";
Daniel Dunbar6337f152009-07-26 04:23:03 +000033 case sparc: return "sparc";
Chris Lattner87c06d62010-02-04 06:34:01 +000034 case sparcv9: return "sparcv9";
Richard Sandiford05129102013-05-03 11:05:17 +000035 case systemz: return "s390x";
Eli Friedman74db89e2009-08-19 20:46:03 +000036 case tce: return "tce";
Daniel Dunbar6337f152009-07-26 04:23:03 +000037 case thumb: return "thumb";
38 case x86: return "i386";
39 case x86_64: return "x86_64";
Daniel Dunbar8c2f1d72009-07-26 04:52:45 +000040 case xcore: return "xcore";
Wesley Pecka70f28c2010-02-23 19:15:24 +000041 case mblaze: return "mblaze";
Justin Holewinski49683f32012-05-04 20:18:50 +000042 case nvptx: return "nvptx";
43 case nvptx64: return "nvptx64";
Ivan Krasin38fb2db2011-08-23 16:59:00 +000044 case le32: return "le32";
Tobias Grosser05d71382011-08-29 15:44:55 +000045 case amdil: return "amdil";
Micah Villmowe53d6052012-10-01 17:01:31 +000046 case spir: return "spir";
Guy Benyeiac39a032012-11-15 10:35:47 +000047 case spir64: return "spir64";
Daniel Dunbar23e97b02009-04-01 21:53:23 +000048 }
49
David Blaikie4d6ccb52012-01-20 21:51:11 +000050 llvm_unreachable("Invalid ArchType!");
Daniel Dunbar23e97b02009-04-01 21:53:23 +000051}
52
Daniel Dunbar688b55b2009-08-24 09:53:06 +000053const char *Triple::getArchTypePrefix(ArchType Kind) {
54 switch (Kind) {
55 default:
56 return 0;
57
Tim Northover72062f52013-01-31 12:12:40 +000058 case aarch64: return "aarch64";
59
Daniel Dunbar688b55b2009-08-24 09:53:06 +000060 case arm:
61 case thumb: return "arm";
62
Daniel Dunbar688b55b2009-08-24 09:53:06 +000063 case ppc64:
64 case ppc: return "ppc";
65
Wesley Pecka70f28c2010-02-23 19:15:24 +000066 case mblaze: return "mblaze";
67
Benjamin Kramerd5dbc8c2012-06-28 19:09:53 +000068 case mips:
69 case mipsel:
70 case mips64:
71 case mips64el:return "mips";
72
73 case hexagon: return "hexagon";
Tony Linthicumb4b54152011-12-12 21:14:40 +000074
Anton Korobeynikov74156592012-03-09 10:09:36 +000075 case r600: return "r600";
76
Chris Lattner87c06d62010-02-04 06:34:01 +000077 case sparcv9:
Daniel Dunbar688b55b2009-08-24 09:53:06 +000078 case sparc: return "sparc";
79
Richard Sandiford05129102013-05-03 11:05:17 +000080 case systemz: return "systemz";
81
Daniel Dunbar688b55b2009-08-24 09:53:06 +000082 case x86:
83 case x86_64: return "x86";
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000084
Daniel Dunbar688b55b2009-08-24 09:53:06 +000085 case xcore: return "xcore";
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000086
Justin Holewinski49683f32012-05-04 20:18:50 +000087 case nvptx: return "nvptx";
88 case nvptx64: return "nvptx";
Ivan Krasin38fb2db2011-08-23 16:59:00 +000089 case le32: return "le32";
Tobias Grosser05d71382011-08-29 15:44:55 +000090 case amdil: return "amdil";
Micah Villmowe53d6052012-10-01 17:01:31 +000091 case spir: return "spir";
Guy Benyeiac39a032012-11-15 10:35:47 +000092 case spir64: return "spir";
Daniel Dunbar688b55b2009-08-24 09:53:06 +000093 }
94}
95
Daniel Dunbar23e97b02009-04-01 21:53:23 +000096const char *Triple::getVendorTypeName(VendorType Kind) {
97 switch (Kind) {
98 case UnknownVendor: return "unknown";
99
100 case Apple: return "apple";
Chris Lattner56ce0f42009-08-14 18:48:13 +0000101 case PC: return "pc";
John Thompson6046cff2011-03-15 21:51:56 +0000102 case SCEI: return "scei";
Hal Finkela47406c2012-04-02 18:31:33 +0000103 case BGP: return "bgp";
104 case BGQ: return "bgq";
Hal Finkeld939cd62012-08-28 02:10:30 +0000105 case Freescale: return "fsl";
Duncan Sands2e522d02012-10-12 11:08:57 +0000106 case IBM: return "ibm";
Justin Holewinski0ff42872013-06-21 18:51:49 +0000107 case NVIDIA: return "nvidia";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000108 }
109
David Blaikie4d6ccb52012-01-20 21:51:11 +0000110 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000111}
112
113const char *Triple::getOSTypeName(OSType Kind) {
114 switch (Kind) {
115 case UnknownOS: return "unknown";
116
Duncan Sands852cd112009-06-19 14:40:01 +0000117 case AuroraUX: return "auroraux";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000118 case Cygwin: return "cygwin";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000119 case Darwin: return "darwin";
Daniel Dunbar7eaf0572009-05-22 02:24:11 +0000120 case DragonFly: return "dragonfly";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000121 case FreeBSD: return "freebsd";
Daniel Dunbar0dde4c02011-04-19 20:19:27 +0000122 case IOS: return "ios";
Duncan Sands652b48b2011-07-26 15:30:04 +0000123 case KFreeBSD: return "kfreebsd";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000124 case Linux: return "linux";
Edward O'Callaghancc9fa812009-11-19 11:59:00 +0000125 case Lv2: return "lv2";
Daniel Dunbar1af39472011-04-19 23:34:12 +0000126 case MacOSX: return "macosx";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000127 case MinGW32: return "mingw32";
Chris Lattnerb8ac8412009-07-13 20:22:23 +0000128 case NetBSD: return "netbsd";
Duncan Sandscd1267d2009-06-29 13:36:13 +0000129 case OpenBSD: return "openbsd";
Daniel Dunbarfdb0b7b2009-08-18 04:43:27 +0000130 case Solaris: return "solaris";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000131 case Win32: return "win32";
Chris Lattnera43fc342009-10-16 02:06:30 +0000132 case Haiku: return "haiku";
Chris Lattner29269d02010-07-07 15:52:27 +0000133 case Minix: return "minix";
Douglas Gregor6ced1d12011-07-01 22:41:06 +0000134 case RTEMS: return "rtems";
Eli Benderskyf659c0d2012-12-04 18:37:26 +0000135 case NaCl: return "nacl";
Hal Finkela47406c2012-04-02 18:31:33 +0000136 case CNK: return "cnk";
Eric Christopherb0f67592012-08-06 20:52:18 +0000137 case Bitrig: return "bitrig";
Duncan Sands2e522d02012-10-12 11:08:57 +0000138 case AIX: return "aix";
Justin Holewinski0ff42872013-06-21 18:51:49 +0000139 case CUDA: return "cuda";
140 case NVCL: return "nvcl";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000141 }
142
David Blaikie4d6ccb52012-01-20 21:51:11 +0000143 llvm_unreachable("Invalid OSType");
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000144}
145
Duncan Sands5754a452010-09-16 08:25:48 +0000146const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
147 switch (Kind) {
148 case UnknownEnvironment: return "unknown";
Renato Golin859f8182011-01-21 18:25:47 +0000149 case GNU: return "gnu";
Rafael Espindola8887a0f2012-01-18 23:35:29 +0000150 case GNUEABIHF: return "gnueabihf";
Renato Golin859f8182011-01-21 18:25:47 +0000151 case GNUEABI: return "gnueabi";
Eli Bendersky9dd2a3b2013-01-22 18:02:49 +0000152 case GNUX32: return "gnux32";
Renato Golin859f8182011-01-21 18:25:47 +0000153 case EABI: return "eabi";
Evan Cheng2bffee22011-02-01 01:14:13 +0000154 case MachO: return "macho";
Logan Chien43bf7092012-09-02 09:29:46 +0000155 case Android: return "android";
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000156 case ELF: return "elf";
Duncan Sands5754a452010-09-16 08:25:48 +0000157 }
158
David Blaikie4d6ccb52012-01-20 21:51:11 +0000159 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands5754a452010-09-16 08:25:48 +0000160}
161
Daniel Dunbar2928c832009-11-06 10:58:06 +0000162Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruth06accda2012-02-12 09:27:38 +0000163 return StringSwitch<Triple::ArchType>(Name)
Tim Northover72062f52013-01-31 12:12:40 +0000164 .Case("aarch64", aarch64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000165 .Case("arm", arm)
Chandler Carruth06accda2012-02-12 09:27:38 +0000166 .Case("mips", mips)
167 .Case("mipsel", mipsel)
168 .Case("mips64", mips64)
169 .Case("mips64el", mips64el)
170 .Case("msp430", msp430)
171 .Case("ppc64", ppc64)
172 .Case("ppc32", ppc)
173 .Case("ppc", ppc)
174 .Case("mblaze", mblaze)
Anton Korobeynikov74156592012-03-09 10:09:36 +0000175 .Case("r600", r600)
Chandler Carruth06accda2012-02-12 09:27:38 +0000176 .Case("hexagon", hexagon)
177 .Case("sparc", sparc)
178 .Case("sparcv9", sparcv9)
Richard Sandiford05129102013-05-03 11:05:17 +0000179 .Case("systemz", systemz)
Chandler Carruth06accda2012-02-12 09:27:38 +0000180 .Case("tce", tce)
181 .Case("thumb", thumb)
182 .Case("x86", x86)
183 .Case("x86-64", x86_64)
184 .Case("xcore", xcore)
Justin Holewinski49683f32012-05-04 20:18:50 +0000185 .Case("nvptx", nvptx)
186 .Case("nvptx64", nvptx64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000187 .Case("le32", le32)
188 .Case("amdil", amdil)
Micah Villmowe53d6052012-10-01 17:01:31 +0000189 .Case("spir", spir)
Guy Benyeiac39a032012-11-15 10:35:47 +0000190 .Case("spir64", spir64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000191 .Default(UnknownArch);
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000192}
193
Duncan Sandsbbdca3f2010-03-24 09:05:14 +0000194// Returns architecture name that is understood by the target assembler.
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000195const char *Triple::getArchNameForAssembler() {
Daniel Dunbare1fe09f2011-04-19 21:12:05 +0000196 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000197 return NULL;
198
Chandler Carruth06accda2012-02-12 09:27:38 +0000199 return StringSwitch<const char*>(getArchName())
200 .Case("i386", "i386")
201 .Case("x86_64", "x86_64")
202 .Case("powerpc", "ppc")
203 .Case("powerpc64", "ppc64")
204 .Cases("mblaze", "microblaze", "mblaze")
205 .Case("arm", "arm")
206 .Cases("armv4t", "thumbv4t", "armv4t")
207 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
208 .Cases("armv6", "thumbv6", "armv6")
209 .Cases("armv7", "thumbv7", "armv7")
Anton Korobeynikov74156592012-03-09 10:09:36 +0000210 .Case("r600", "r600")
Justin Holewinski49683f32012-05-04 20:18:50 +0000211 .Case("nvptx", "nvptx")
212 .Case("nvptx64", "nvptx64")
Chandler Carruth06accda2012-02-12 09:27:38 +0000213 .Case("le32", "le32")
214 .Case("amdil", "amdil")
Micah Villmowe53d6052012-10-01 17:01:31 +0000215 .Case("spir", "spir")
Guy Benyeiac39a032012-11-15 10:35:47 +0000216 .Case("spir64", "spir64")
Chandler Carruth06accda2012-02-12 09:27:38 +0000217 .Default(NULL);
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000218}
219
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000220static Triple::ArchType parseArch(StringRef ArchName) {
221 return StringSwitch<Triple::ArchType>(ArchName)
222 .Cases("i386", "i486", "i586", "i686", Triple::x86)
223 // FIXME: Do we need to support these?
224 .Cases("i786", "i886", "i986", Triple::x86)
225 .Cases("amd64", "x86_64", Triple::x86_64)
226 .Case("powerpc", Triple::ppc)
227 .Cases("powerpc64", "ppu", Triple::ppc64)
228 .Case("mblaze", Triple::mblaze)
Tim Northover72062f52013-01-31 12:12:40 +0000229 .Case("aarch64", Triple::aarch64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000230 .Cases("arm", "xscale", Triple::arm)
Chandler Carruth0a857712012-02-18 04:34:17 +0000231 // FIXME: It would be good to replace these with explicit names for all the
232 // various suffixes supported.
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000233 .StartsWith("armv", Triple::arm)
234 .Case("thumb", Triple::thumb)
235 .StartsWith("thumbv", Triple::thumb)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000236 .Case("msp430", Triple::msp430)
237 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruthfdf0dc92012-02-22 11:32:54 +0000238 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000239 .Cases("mips64", "mips64eb", Triple::mips64)
240 .Case("mips64el", Triple::mips64el)
Anton Korobeynikov74156592012-03-09 10:09:36 +0000241 .Case("r600", Triple::r600)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000242 .Case("hexagon", Triple::hexagon)
Richard Sandiford05129102013-05-03 11:05:17 +0000243 .Case("s390x", Triple::systemz)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000244 .Case("sparc", Triple::sparc)
Jakob Stoklund Olesenbc3db032013-05-14 17:47:27 +0000245 .Cases("sparcv9", "sparc64", Triple::sparcv9)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000246 .Case("tce", Triple::tce)
247 .Case("xcore", Triple::xcore)
Justin Holewinski49683f32012-05-04 20:18:50 +0000248 .Case("nvptx", Triple::nvptx)
249 .Case("nvptx64", Triple::nvptx64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000250 .Case("le32", Triple::le32)
251 .Case("amdil", Triple::amdil)
Micah Villmowe53d6052012-10-01 17:01:31 +0000252 .Case("spir", Triple::spir)
Guy Benyeiac39a032012-11-15 10:35:47 +0000253 .Case("spir64", Triple::spir64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000254 .Default(Triple::UnknownArch);
Duncan Sands335db222010-08-12 11:31:39 +0000255}
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000256
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000257static Triple::VendorType parseVendor(StringRef VendorName) {
258 return StringSwitch<Triple::VendorType>(VendorName)
259 .Case("apple", Triple::Apple)
260 .Case("pc", Triple::PC)
261 .Case("scei", Triple::SCEI)
Hal Finkela47406c2012-04-02 18:31:33 +0000262 .Case("bgp", Triple::BGP)
263 .Case("bgq", Triple::BGQ)
Hal Finkeld939cd62012-08-28 02:10:30 +0000264 .Case("fsl", Triple::Freescale)
Duncan Sands2e522d02012-10-12 11:08:57 +0000265 .Case("ibm", Triple::IBM)
Justin Holewinski0ff42872013-06-21 18:51:49 +0000266 .Case("nvidia", Triple::NVIDIA)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000267 .Default(Triple::UnknownVendor);
Duncan Sands335db222010-08-12 11:31:39 +0000268}
269
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000270static Triple::OSType parseOS(StringRef OSName) {
271 return StringSwitch<Triple::OSType>(OSName)
272 .StartsWith("auroraux", Triple::AuroraUX)
273 .StartsWith("cygwin", Triple::Cygwin)
274 .StartsWith("darwin", Triple::Darwin)
275 .StartsWith("dragonfly", Triple::DragonFly)
276 .StartsWith("freebsd", Triple::FreeBSD)
277 .StartsWith("ios", Triple::IOS)
278 .StartsWith("kfreebsd", Triple::KFreeBSD)
279 .StartsWith("linux", Triple::Linux)
280 .StartsWith("lv2", Triple::Lv2)
281 .StartsWith("macosx", Triple::MacOSX)
282 .StartsWith("mingw32", Triple::MinGW32)
283 .StartsWith("netbsd", Triple::NetBSD)
284 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000285 .StartsWith("solaris", Triple::Solaris)
286 .StartsWith("win32", Triple::Win32)
287 .StartsWith("haiku", Triple::Haiku)
288 .StartsWith("minix", Triple::Minix)
289 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyf659c0d2012-12-04 18:37:26 +0000290 .StartsWith("nacl", Triple::NaCl)
Hal Finkela47406c2012-04-02 18:31:33 +0000291 .StartsWith("cnk", Triple::CNK)
Eric Christopherb0f67592012-08-06 20:52:18 +0000292 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sands2e522d02012-10-12 11:08:57 +0000293 .StartsWith("aix", Triple::AIX)
Justin Holewinski0ff42872013-06-21 18:51:49 +0000294 .StartsWith("cuda", Triple::CUDA)
295 .StartsWith("nvcl", Triple::NVCL)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000296 .Default(Triple::UnknownOS);
Duncan Sands335db222010-08-12 11:31:39 +0000297}
298
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000299static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
300 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
301 .StartsWith("eabi", Triple::EABI)
302 .StartsWith("gnueabihf", Triple::GNUEABIHF)
303 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky9dd2a3b2013-01-22 18:02:49 +0000304 .StartsWith("gnux32", Triple::GNUX32)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000305 .StartsWith("gnu", Triple::GNU)
306 .StartsWith("macho", Triple::MachO)
Logan Chien43bf7092012-09-02 09:29:46 +0000307 .StartsWith("android", Triple::Android)
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000308 .StartsWith("elf", Triple::ELF)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000309 .Default(Triple::UnknownEnvironment);
Duncan Sands5754a452010-09-16 08:25:48 +0000310}
311
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000312/// \brief Construct a triple from the string representation provided.
313///
Chandler Carruth0523f412012-02-21 08:31:18 +0000314/// This stores the string representation and parses the various pieces into
315/// enum members.
Chandler Carruth124e51c2012-02-21 03:39:36 +0000316Triple::Triple(const Twine &Str)
317 : Data(Str.str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000318 Arch(parseArch(getArchName())),
319 Vendor(parseVendor(getVendorName())),
320 OS(parseOS(getOSName())),
321 Environment(parseEnvironment(getEnvironmentName())) {
Chandler Carruth124e51c2012-02-21 03:39:36 +0000322}
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000323
324/// \brief Construct a triple from string representations of the architecture,
325/// vendor, and OS.
326///
Chandler Carruth0523f412012-02-21 08:31:18 +0000327/// This joins each argument into a canonical string representation and parses
328/// them into enum members. It leaves the environment unknown and omits it from
329/// the string representation.
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000330Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
331 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000332 Arch(parseArch(ArchStr.str())),
333 Vendor(parseVendor(VendorStr.str())),
334 OS(parseOS(OSStr.str())),
Chandler Carruth124e51c2012-02-21 03:39:36 +0000335 Environment() {
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000336}
337
338/// \brief Construct a triple from string representations of the architecture,
339/// vendor, OS, and environment.
340///
Chandler Carruth0523f412012-02-21 08:31:18 +0000341/// This joins each argument into a canonical string representation and parses
342/// them into enum members.
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000343Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
344 const Twine &EnvironmentStr)
345 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
346 EnvironmentStr).str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000347 Arch(parseArch(ArchStr.str())),
348 Vendor(parseVendor(VendorStr.str())),
349 OS(parseOS(OSStr.str())),
350 Environment(parseEnvironment(EnvironmentStr.str())) {
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000351}
352
Duncan Sands335db222010-08-12 11:31:39 +0000353std::string Triple::normalize(StringRef Str) {
354 // Parse into components.
355 SmallVector<StringRef, 4> Components;
Chandler Carruthdac3d362012-02-21 09:12:48 +0000356 Str.split(Components, "-");
Duncan Sands335db222010-08-12 11:31:39 +0000357
358 // If the first component corresponds to a known architecture, preferentially
359 // use it for the architecture. If the second component corresponds to a
360 // known vendor, preferentially use it for the vendor, etc. This avoids silly
361 // component movement when a component parses as (eg) both a valid arch and a
362 // valid os.
363 ArchType Arch = UnknownArch;
364 if (Components.size() > 0)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000365 Arch = parseArch(Components[0]);
Duncan Sands335db222010-08-12 11:31:39 +0000366 VendorType Vendor = UnknownVendor;
367 if (Components.size() > 1)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000368 Vendor = parseVendor(Components[1]);
Duncan Sands335db222010-08-12 11:31:39 +0000369 OSType OS = UnknownOS;
370 if (Components.size() > 2)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000371 OS = parseOS(Components[2]);
Duncan Sands5754a452010-09-16 08:25:48 +0000372 EnvironmentType Environment = UnknownEnvironment;
373 if (Components.size() > 3)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000374 Environment = parseEnvironment(Components[3]);
Duncan Sands335db222010-08-12 11:31:39 +0000375
376 // Note which components are already in their final position. These will not
377 // be moved.
Duncan Sands5754a452010-09-16 08:25:48 +0000378 bool Found[4];
Duncan Sands335db222010-08-12 11:31:39 +0000379 Found[0] = Arch != UnknownArch;
380 Found[1] = Vendor != UnknownVendor;
381 Found[2] = OS != UnknownOS;
Duncan Sands5754a452010-09-16 08:25:48 +0000382 Found[3] = Environment != UnknownEnvironment;
Duncan Sands335db222010-08-12 11:31:39 +0000383
384 // If they are not there already, permute the components into their canonical
385 // positions by seeing if they parse as a valid architecture, and if so moving
386 // the component to the architecture position etc.
Duncan Sands5754a452010-09-16 08:25:48 +0000387 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands335db222010-08-12 11:31:39 +0000388 if (Found[Pos])
389 continue; // Already in the canonical position.
390
391 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
392 // Do not reparse any components that already matched.
Duncan Sands5754a452010-09-16 08:25:48 +0000393 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands335db222010-08-12 11:31:39 +0000394 continue;
395
396 // Does this component parse as valid for the target position?
397 bool Valid = false;
398 StringRef Comp = Components[Idx];
399 switch (Pos) {
Craig Topper85814382012-02-07 05:05:23 +0000400 default: llvm_unreachable("unexpected component type!");
Duncan Sands335db222010-08-12 11:31:39 +0000401 case 0:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000402 Arch = parseArch(Comp);
Duncan Sands335db222010-08-12 11:31:39 +0000403 Valid = Arch != UnknownArch;
404 break;
405 case 1:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000406 Vendor = parseVendor(Comp);
Duncan Sands335db222010-08-12 11:31:39 +0000407 Valid = Vendor != UnknownVendor;
408 break;
409 case 2:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000410 OS = parseOS(Comp);
Duncan Sandsae200c62011-02-02 10:08:38 +0000411 Valid = OS != UnknownOS;
Duncan Sands335db222010-08-12 11:31:39 +0000412 break;
Duncan Sands5754a452010-09-16 08:25:48 +0000413 case 3:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000414 Environment = parseEnvironment(Comp);
Duncan Sands5754a452010-09-16 08:25:48 +0000415 Valid = Environment != UnknownEnvironment;
416 break;
Duncan Sands335db222010-08-12 11:31:39 +0000417 }
418 if (!Valid)
419 continue; // Nope, try the next component.
420
421 // Move the component to the target position, pushing any non-fixed
422 // components that are in the way to the right. This tends to give
423 // good results in the common cases of a forgotten vendor component
424 // or a wrongly positioned environment.
425 if (Pos < Idx) {
426 // Insert left, pushing the existing components to the right. For
427 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
428 StringRef CurrentComponent(""); // The empty component.
429 // Replace the component we are moving with an empty component.
430 std::swap(CurrentComponent, Components[Idx]);
431 // Insert the component being moved at Pos, displacing any existing
432 // components to the right.
433 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
434 // Skip over any fixed components.
Chandler Carruthc5f18d32012-02-21 09:29:14 +0000435 while (i < array_lengthof(Found) && Found[i])
436 ++i;
Duncan Sands335db222010-08-12 11:31:39 +0000437 // Place the component at the new position, getting the component
438 // that was at this position - it will be moved right.
439 std::swap(CurrentComponent, Components[i]);
440 }
441 } else if (Pos > Idx) {
442 // Push right by inserting empty components until the component at Idx
443 // reaches the target position Pos. For example, pc-a -> -pc-a when
444 // moving pc to the second position.
445 do {
446 // Insert one empty component at Idx.
447 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsae200c62011-02-02 10:08:38 +0000448 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands335db222010-08-12 11:31:39 +0000449 // Place the component at the new position, getting the component
450 // that was at this position - it will be moved right.
451 std::swap(CurrentComponent, Components[i]);
452 // If it was placed on top of an empty component then we are done.
453 if (CurrentComponent.empty())
454 break;
Duncan Sandsae200c62011-02-02 10:08:38 +0000455 // Advance to the next component, skipping any fixed components.
Anders Carlsson15ec6952011-02-05 18:19:35 +0000456 while (++i < array_lengthof(Found) && Found[i])
457 ;
Duncan Sands335db222010-08-12 11:31:39 +0000458 }
459 // The last component was pushed off the end - append it.
460 if (!CurrentComponent.empty())
461 Components.push_back(CurrentComponent);
462
463 // Advance Idx to the component's new position.
Chandler Carruthc5f18d32012-02-21 09:29:14 +0000464 while (++Idx < array_lengthof(Found) && Found[Idx])
465 ;
Duncan Sands335db222010-08-12 11:31:39 +0000466 } while (Idx < Pos); // Add more until the final position is reached.
467 }
468 assert(Pos < Components.size() && Components[Pos] == Comp &&
469 "Component moved wrong!");
470 Found[Pos] = true;
471 break;
472 }
473 }
474
475 // Special case logic goes here. At this point Arch, Vendor and OS have the
476 // correct values for the computed components.
477
478 // Stick the corrected components back together to form the normalized string.
479 std::string Normalized;
480 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
481 if (i) Normalized += '-';
482 Normalized += Components[i];
483 }
484 return Normalized;
485}
486
Daniel Dunbara14d2252009-07-26 03:31:47 +0000487StringRef Triple::getArchName() const {
488 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000489}
490
Daniel Dunbara14d2252009-07-26 03:31:47 +0000491StringRef Triple::getVendorName() const {
492 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
493 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000494}
495
Daniel Dunbara14d2252009-07-26 03:31:47 +0000496StringRef Triple::getOSName() const {
497 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
498 Tmp = Tmp.split('-').second; // Strip second component
499 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000500}
501
Daniel Dunbara14d2252009-07-26 03:31:47 +0000502StringRef Triple::getEnvironmentName() const {
503 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
504 Tmp = Tmp.split('-').second; // Strip second component
505 return Tmp.split('-').second; // Strip third component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000506}
507
Daniel Dunbara14d2252009-07-26 03:31:47 +0000508StringRef Triple::getOSAndEnvironmentName() const {
509 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
510 return Tmp.split('-').second; // Strip second component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000511}
512
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000513static unsigned EatNumber(StringRef &Str) {
514 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000515 unsigned Result = 0;
Jim Grosbache509aa92010-12-17 02:10:59 +0000516
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000517 do {
518 // Consume the leading digit.
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000519 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000520
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000521 // Eat the digit.
522 Str = Str.substr(1);
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000523 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbache509aa92010-12-17 02:10:59 +0000524
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000525 return Result;
526}
527
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000528void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
529 unsigned &Micro) const {
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000530 StringRef OSName = getOSName();
Jim Grosbache509aa92010-12-17 02:10:59 +0000531
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000532 // Assume that the OS portion of the triple starts with the canonical name.
533 StringRef OSTypeName = getOSTypeName(getOS());
534 if (OSName.startswith(OSTypeName))
535 OSName = OSName.substr(OSTypeName.size());
Jim Grosbache509aa92010-12-17 02:10:59 +0000536
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000537 // Any unset version defaults to 0.
538 Major = Minor = Micro = 0;
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000539
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000540 // Parse up to three components.
541 unsigned *Components[3] = { &Major, &Minor, &Micro };
542 for (unsigned i = 0; i != 3; ++i) {
543 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
544 break;
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000545
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000546 // Consume the leading number.
547 *Components[i] = EatNumber(OSName);
Jim Grosbache509aa92010-12-17 02:10:59 +0000548
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000549 // Consume the separator, if present.
550 if (OSName.startswith("."))
551 OSName = OSName.substr(1);
552 }
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000553}
554
Bob Wilsonbda59fd2012-01-31 22:32:29 +0000555bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
556 unsigned &Micro) const {
557 getOSVersion(Major, Minor, Micro);
558
559 switch (getOS()) {
Craig Topper85814382012-02-07 05:05:23 +0000560 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonbda59fd2012-01-31 22:32:29 +0000561 case Darwin:
562 // Default to darwin8, i.e., MacOSX 10.4.
563 if (Major == 0)
564 Major = 8;
565 // Darwin version numbers are skewed from OS X versions.
566 if (Major < 4)
567 return false;
568 Micro = 0;
569 Minor = Major - 4;
570 Major = 10;
571 break;
572 case MacOSX:
573 // Default to 10.4.
574 if (Major == 0) {
575 Major = 10;
576 Minor = 4;
577 }
578 if (Major != 10)
579 return false;
580 break;
581 case IOS:
582 // Ignore the version from the triple. This is only handled because the
583 // the clang driver combines OS X and IOS support into a common Darwin
584 // toolchain that wants to know the OS X version number even when targeting
585 // IOS.
586 Major = 10;
587 Minor = 4;
588 Micro = 0;
589 break;
590 }
591 return true;
592}
593
Chad Rosierecee47e2012-05-09 17:23:48 +0000594void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
595 unsigned &Micro) const {
596 switch (getOS()) {
597 default: llvm_unreachable("unexpected OS for Darwin triple");
598 case Darwin:
599 case MacOSX:
600 // Ignore the version from the triple. This is only handled because the
601 // the clang driver combines OS X and IOS support into a common Darwin
602 // toolchain that wants to know the iOS version number even when targeting
603 // OS X.
Chad Rosier537c2f52012-05-09 18:23:00 +0000604 Major = 3;
Chad Rosierecee47e2012-05-09 17:23:48 +0000605 Minor = 0;
606 Micro = 0;
Chad Rosier26bbdee2012-05-09 17:38:47 +0000607 break;
Chad Rosierecee47e2012-05-09 17:23:48 +0000608 case IOS:
609 getOSVersion(Major, Minor, Micro);
Chad Rosier537c2f52012-05-09 18:23:00 +0000610 // Default to 3.0.
611 if (Major == 0)
612 Major = 3;
Chad Rosierecee47e2012-05-09 17:23:48 +0000613 break;
614 }
615}
616
Daniel Dunbara14d2252009-07-26 03:31:47 +0000617void Triple::setTriple(const Twine &Str) {
Chandler Carruth124e51c2012-02-21 03:39:36 +0000618 *this = Triple(Str);
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000619}
620
621void Triple::setArch(ArchType Kind) {
622 setArchName(getArchTypeName(Kind));
623}
624
625void Triple::setVendor(VendorType Kind) {
626 setVendorName(getVendorTypeName(Kind));
627}
628
629void Triple::setOS(OSType Kind) {
630 setOSName(getOSTypeName(Kind));
631}
632
Duncan Sands5754a452010-09-16 08:25:48 +0000633void Triple::setEnvironment(EnvironmentType Kind) {
634 setEnvironmentName(getEnvironmentTypeName(Kind));
635}
636
Daniel Dunbar2928c832009-11-06 10:58:06 +0000637void Triple::setArchName(StringRef Str) {
Jeffrey Yasskin0b228732009-10-06 21:45:26 +0000638 // Work around a miscompilation bug for Twines in gcc 4.0.3.
639 SmallString<64> Triple;
640 Triple += Str;
641 Triple += "-";
642 Triple += getVendorName();
643 Triple += "-";
644 Triple += getOSAndEnvironmentName();
645 setTriple(Triple.str());
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000646}
647
Daniel Dunbar2928c832009-11-06 10:58:06 +0000648void Triple::setVendorName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000649 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
650}
651
Daniel Dunbar2928c832009-11-06 10:58:06 +0000652void Triple::setOSName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000653 if (hasEnvironment())
654 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
655 "-" + getEnvironmentName());
656 else
657 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
658}
659
Daniel Dunbar2928c832009-11-06 10:58:06 +0000660void Triple::setEnvironmentName(StringRef Str) {
661 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000662 "-" + Str);
663}
664
Daniel Dunbar2928c832009-11-06 10:58:06 +0000665void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000666 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
667}
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000668
669static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
670 switch (Arch) {
671 case llvm::Triple::UnknownArch:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000672 return 0;
673
674 case llvm::Triple::msp430:
675 return 16;
676
677 case llvm::Triple::amdil:
678 case llvm::Triple::arm:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000679 case llvm::Triple::hexagon:
680 case llvm::Triple::le32:
681 case llvm::Triple::mblaze:
682 case llvm::Triple::mips:
683 case llvm::Triple::mipsel:
Justin Holewinski49683f32012-05-04 20:18:50 +0000684 case llvm::Triple::nvptx:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000685 case llvm::Triple::ppc:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000686 case llvm::Triple::r600:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000687 case llvm::Triple::sparc:
688 case llvm::Triple::tce:
689 case llvm::Triple::thumb:
690 case llvm::Triple::x86:
691 case llvm::Triple::xcore:
Guy Benyeiac39a032012-11-15 10:35:47 +0000692 case llvm::Triple::spir:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000693 return 32;
694
Tim Northover72062f52013-01-31 12:12:40 +0000695 case llvm::Triple::aarch64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000696 case llvm::Triple::mips64:
697 case llvm::Triple::mips64el:
Justin Holewinski49683f32012-05-04 20:18:50 +0000698 case llvm::Triple::nvptx64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000699 case llvm::Triple::ppc64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000700 case llvm::Triple::sparcv9:
Richard Sandiford05129102013-05-03 11:05:17 +0000701 case llvm::Triple::systemz:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000702 case llvm::Triple::x86_64:
Guy Benyeiac39a032012-11-15 10:35:47 +0000703 case llvm::Triple::spir64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000704 return 64;
705 }
706 llvm_unreachable("Invalid architecture value");
707}
708
709bool Triple::isArch64Bit() const {
710 return getArchPointerBitWidth(getArch()) == 64;
711}
712
713bool Triple::isArch32Bit() const {
714 return getArchPointerBitWidth(getArch()) == 32;
715}
716
717bool Triple::isArch16Bit() const {
718 return getArchPointerBitWidth(getArch()) == 16;
719}
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000720
721Triple Triple::get32BitArchVariant() const {
722 Triple T(*this);
723 switch (getArch()) {
724 case Triple::UnknownArch:
Tim Northover72062f52013-01-31 12:12:40 +0000725 case Triple::aarch64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000726 case Triple::msp430:
Richard Sandiford05129102013-05-03 11:05:17 +0000727 case Triple::systemz:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000728 T.setArch(UnknownArch);
729 break;
730
731 case Triple::amdil:
Micah Villmowe53d6052012-10-01 17:01:31 +0000732 case Triple::spir:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000733 case Triple::arm:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000734 case Triple::hexagon:
735 case Triple::le32:
736 case Triple::mblaze:
737 case Triple::mips:
738 case Triple::mipsel:
Justin Holewinski49683f32012-05-04 20:18:50 +0000739 case Triple::nvptx:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000740 case Triple::ppc:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000741 case Triple::r600:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000742 case Triple::sparc:
743 case Triple::tce:
744 case Triple::thumb:
745 case Triple::x86:
746 case Triple::xcore:
747 // Already 32-bit.
748 break;
749
750 case Triple::mips64: T.setArch(Triple::mips); break;
751 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinski49683f32012-05-04 20:18:50 +0000752 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000753 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000754 case Triple::sparcv9: T.setArch(Triple::sparc); break;
755 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeiac39a032012-11-15 10:35:47 +0000756 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000757 }
758 return T;
759}
760
761Triple Triple::get64BitArchVariant() const {
762 Triple T(*this);
763 switch (getArch()) {
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000764 case Triple::UnknownArch:
765 case Triple::amdil:
766 case Triple::arm:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000767 case Triple::hexagon:
768 case Triple::le32:
769 case Triple::mblaze:
770 case Triple::msp430:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000771 case Triple::r600:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000772 case Triple::tce:
773 case Triple::thumb:
774 case Triple::xcore:
775 T.setArch(UnknownArch);
776 break;
777
Tim Northover72062f52013-01-31 12:12:40 +0000778 case Triple::aarch64:
Guy Benyeiac39a032012-11-15 10:35:47 +0000779 case Triple::spir64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000780 case Triple::mips64:
781 case Triple::mips64el:
Justin Holewinski49683f32012-05-04 20:18:50 +0000782 case Triple::nvptx64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000783 case Triple::ppc64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000784 case Triple::sparcv9:
Richard Sandiford05129102013-05-03 11:05:17 +0000785 case Triple::systemz:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000786 case Triple::x86_64:
787 // Already 64-bit.
788 break;
789
790 case Triple::mips: T.setArch(Triple::mips64); break;
791 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinski49683f32012-05-04 20:18:50 +0000792 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000793 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000794 case Triple::sparc: T.setArch(Triple::sparcv9); break;
795 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeiac39a032012-11-15 10:35:47 +0000796 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000797 }
798 return T;
799}