blob: 412e34ccc596f17fbd89597b8041b94b42f379cd [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";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000107 }
108
David Blaikie4d6ccb52012-01-20 21:51:11 +0000109 llvm_unreachable("Invalid VendorType!");
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000110}
111
112const char *Triple::getOSTypeName(OSType Kind) {
113 switch (Kind) {
114 case UnknownOS: return "unknown";
115
Duncan Sands852cd112009-06-19 14:40:01 +0000116 case AuroraUX: return "auroraux";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000117 case Cygwin: return "cygwin";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000118 case Darwin: return "darwin";
Daniel Dunbar7eaf0572009-05-22 02:24:11 +0000119 case DragonFly: return "dragonfly";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000120 case FreeBSD: return "freebsd";
Daniel Dunbar0dde4c02011-04-19 20:19:27 +0000121 case IOS: return "ios";
Duncan Sands652b48b2011-07-26 15:30:04 +0000122 case KFreeBSD: return "kfreebsd";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000123 case Linux: return "linux";
Edward O'Callaghancc9fa812009-11-19 11:59:00 +0000124 case Lv2: return "lv2";
Daniel Dunbar1af39472011-04-19 23:34:12 +0000125 case MacOSX: return "macosx";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000126 case MinGW32: return "mingw32";
Chris Lattnerb8ac8412009-07-13 20:22:23 +0000127 case NetBSD: return "netbsd";
Duncan Sandscd1267d2009-06-29 13:36:13 +0000128 case OpenBSD: return "openbsd";
Daniel Dunbarfdb0b7b2009-08-18 04:43:27 +0000129 case Solaris: return "solaris";
Daniel Dunbar6337f152009-07-26 04:23:03 +0000130 case Win32: return "win32";
Chris Lattnera43fc342009-10-16 02:06:30 +0000131 case Haiku: return "haiku";
Chris Lattner29269d02010-07-07 15:52:27 +0000132 case Minix: return "minix";
Douglas Gregor6ced1d12011-07-01 22:41:06 +0000133 case RTEMS: return "rtems";
Eli Benderskyf659c0d2012-12-04 18:37:26 +0000134 case NaCl: return "nacl";
Hal Finkela47406c2012-04-02 18:31:33 +0000135 case CNK: return "cnk";
Eric Christopherb0f67592012-08-06 20:52:18 +0000136 case Bitrig: return "bitrig";
Duncan Sands2e522d02012-10-12 11:08:57 +0000137 case AIX: return "aix";
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000138 }
139
David Blaikie4d6ccb52012-01-20 21:51:11 +0000140 llvm_unreachable("Invalid OSType");
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000141}
142
Duncan Sands5754a452010-09-16 08:25:48 +0000143const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
144 switch (Kind) {
145 case UnknownEnvironment: return "unknown";
Renato Golin859f8182011-01-21 18:25:47 +0000146 case GNU: return "gnu";
Rafael Espindola8887a0f2012-01-18 23:35:29 +0000147 case GNUEABIHF: return "gnueabihf";
Renato Golin859f8182011-01-21 18:25:47 +0000148 case GNUEABI: return "gnueabi";
Eli Bendersky9dd2a3b2013-01-22 18:02:49 +0000149 case GNUX32: return "gnux32";
Renato Golin859f8182011-01-21 18:25:47 +0000150 case EABI: return "eabi";
Evan Cheng2bffee22011-02-01 01:14:13 +0000151 case MachO: return "macho";
Logan Chien43bf7092012-09-02 09:29:46 +0000152 case Android: return "android";
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000153 case ELF: return "elf";
Duncan Sands5754a452010-09-16 08:25:48 +0000154 }
155
David Blaikie4d6ccb52012-01-20 21:51:11 +0000156 llvm_unreachable("Invalid EnvironmentType!");
Duncan Sands5754a452010-09-16 08:25:48 +0000157}
158
Daniel Dunbar2928c832009-11-06 10:58:06 +0000159Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
Chandler Carruth06accda2012-02-12 09:27:38 +0000160 return StringSwitch<Triple::ArchType>(Name)
Tim Northover72062f52013-01-31 12:12:40 +0000161 .Case("aarch64", aarch64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000162 .Case("arm", arm)
Chandler Carruth06accda2012-02-12 09:27:38 +0000163 .Case("mips", mips)
164 .Case("mipsel", mipsel)
165 .Case("mips64", mips64)
166 .Case("mips64el", mips64el)
167 .Case("msp430", msp430)
168 .Case("ppc64", ppc64)
169 .Case("ppc32", ppc)
170 .Case("ppc", ppc)
171 .Case("mblaze", mblaze)
Anton Korobeynikov74156592012-03-09 10:09:36 +0000172 .Case("r600", r600)
Chandler Carruth06accda2012-02-12 09:27:38 +0000173 .Case("hexagon", hexagon)
174 .Case("sparc", sparc)
175 .Case("sparcv9", sparcv9)
Richard Sandiford05129102013-05-03 11:05:17 +0000176 .Case("systemz", systemz)
Chandler Carruth06accda2012-02-12 09:27:38 +0000177 .Case("tce", tce)
178 .Case("thumb", thumb)
179 .Case("x86", x86)
180 .Case("x86-64", x86_64)
181 .Case("xcore", xcore)
Justin Holewinski49683f32012-05-04 20:18:50 +0000182 .Case("nvptx", nvptx)
183 .Case("nvptx64", nvptx64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000184 .Case("le32", le32)
185 .Case("amdil", amdil)
Micah Villmowe53d6052012-10-01 17:01:31 +0000186 .Case("spir", spir)
Guy Benyeiac39a032012-11-15 10:35:47 +0000187 .Case("spir64", spir64)
Chandler Carruth06accda2012-02-12 09:27:38 +0000188 .Default(UnknownArch);
Daniel Dunbar3c2d4bf2009-08-03 04:03:51 +0000189}
190
Duncan Sandsbbdca3f2010-03-24 09:05:14 +0000191// Returns architecture name that is understood by the target assembler.
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000192const char *Triple::getArchNameForAssembler() {
Daniel Dunbare1fe09f2011-04-19 21:12:05 +0000193 if (!isOSDarwin() && getVendor() != Triple::Apple)
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000194 return NULL;
195
Chandler Carruth06accda2012-02-12 09:27:38 +0000196 return StringSwitch<const char*>(getArchName())
197 .Case("i386", "i386")
198 .Case("x86_64", "x86_64")
199 .Case("powerpc", "ppc")
200 .Case("powerpc64", "ppc64")
201 .Cases("mblaze", "microblaze", "mblaze")
202 .Case("arm", "arm")
203 .Cases("armv4t", "thumbv4t", "armv4t")
204 .Cases("armv5", "armv5e", "thumbv5", "thumbv5e", "armv5")
205 .Cases("armv6", "thumbv6", "armv6")
206 .Cases("armv7", "thumbv7", "armv7")
Anton Korobeynikov74156592012-03-09 10:09:36 +0000207 .Case("r600", "r600")
Justin Holewinski49683f32012-05-04 20:18:50 +0000208 .Case("nvptx", "nvptx")
209 .Case("nvptx64", "nvptx64")
Chandler Carruth06accda2012-02-12 09:27:38 +0000210 .Case("le32", "le32")
211 .Case("amdil", "amdil")
Micah Villmowe53d6052012-10-01 17:01:31 +0000212 .Case("spir", "spir")
Guy Benyeiac39a032012-11-15 10:35:47 +0000213 .Case("spir64", "spir64")
Chandler Carruth06accda2012-02-12 09:27:38 +0000214 .Default(NULL);
Viktor Kutuzov51cdac02009-11-17 18:48:27 +0000215}
216
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000217static Triple::ArchType parseArch(StringRef ArchName) {
218 return StringSwitch<Triple::ArchType>(ArchName)
219 .Cases("i386", "i486", "i586", "i686", Triple::x86)
220 // FIXME: Do we need to support these?
221 .Cases("i786", "i886", "i986", Triple::x86)
222 .Cases("amd64", "x86_64", Triple::x86_64)
223 .Case("powerpc", Triple::ppc)
224 .Cases("powerpc64", "ppu", Triple::ppc64)
225 .Case("mblaze", Triple::mblaze)
Tim Northover72062f52013-01-31 12:12:40 +0000226 .Case("aarch64", Triple::aarch64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000227 .Cases("arm", "xscale", Triple::arm)
Chandler Carruth0a857712012-02-18 04:34:17 +0000228 // FIXME: It would be good to replace these with explicit names for all the
229 // various suffixes supported.
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000230 .StartsWith("armv", Triple::arm)
231 .Case("thumb", Triple::thumb)
232 .StartsWith("thumbv", Triple::thumb)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000233 .Case("msp430", Triple::msp430)
234 .Cases("mips", "mipseb", "mipsallegrex", Triple::mips)
Chandler Carruthfdf0dc92012-02-22 11:32:54 +0000235 .Cases("mipsel", "mipsallegrexel", Triple::mipsel)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000236 .Cases("mips64", "mips64eb", Triple::mips64)
237 .Case("mips64el", Triple::mips64el)
Anton Korobeynikov74156592012-03-09 10:09:36 +0000238 .Case("r600", Triple::r600)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000239 .Case("hexagon", Triple::hexagon)
Richard Sandiford05129102013-05-03 11:05:17 +0000240 .Case("s390x", Triple::systemz)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000241 .Case("sparc", Triple::sparc)
242 .Case("sparcv9", Triple::sparcv9)
243 .Case("tce", Triple::tce)
244 .Case("xcore", Triple::xcore)
Justin Holewinski49683f32012-05-04 20:18:50 +0000245 .Case("nvptx", Triple::nvptx)
246 .Case("nvptx64", Triple::nvptx64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000247 .Case("le32", Triple::le32)
248 .Case("amdil", Triple::amdil)
Micah Villmowe53d6052012-10-01 17:01:31 +0000249 .Case("spir", Triple::spir)
Guy Benyeiac39a032012-11-15 10:35:47 +0000250 .Case("spir64", Triple::spir64)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000251 .Default(Triple::UnknownArch);
Duncan Sands335db222010-08-12 11:31:39 +0000252}
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000253
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000254static Triple::VendorType parseVendor(StringRef VendorName) {
255 return StringSwitch<Triple::VendorType>(VendorName)
256 .Case("apple", Triple::Apple)
257 .Case("pc", Triple::PC)
258 .Case("scei", Triple::SCEI)
Hal Finkela47406c2012-04-02 18:31:33 +0000259 .Case("bgp", Triple::BGP)
260 .Case("bgq", Triple::BGQ)
Hal Finkeld939cd62012-08-28 02:10:30 +0000261 .Case("fsl", Triple::Freescale)
Duncan Sands2e522d02012-10-12 11:08:57 +0000262 .Case("ibm", Triple::IBM)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000263 .Default(Triple::UnknownVendor);
Duncan Sands335db222010-08-12 11:31:39 +0000264}
265
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000266static Triple::OSType parseOS(StringRef OSName) {
267 return StringSwitch<Triple::OSType>(OSName)
268 .StartsWith("auroraux", Triple::AuroraUX)
269 .StartsWith("cygwin", Triple::Cygwin)
270 .StartsWith("darwin", Triple::Darwin)
271 .StartsWith("dragonfly", Triple::DragonFly)
272 .StartsWith("freebsd", Triple::FreeBSD)
273 .StartsWith("ios", Triple::IOS)
274 .StartsWith("kfreebsd", Triple::KFreeBSD)
275 .StartsWith("linux", Triple::Linux)
276 .StartsWith("lv2", Triple::Lv2)
277 .StartsWith("macosx", Triple::MacOSX)
278 .StartsWith("mingw32", Triple::MinGW32)
279 .StartsWith("netbsd", Triple::NetBSD)
280 .StartsWith("openbsd", Triple::OpenBSD)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000281 .StartsWith("solaris", Triple::Solaris)
282 .StartsWith("win32", Triple::Win32)
283 .StartsWith("haiku", Triple::Haiku)
284 .StartsWith("minix", Triple::Minix)
285 .StartsWith("rtems", Triple::RTEMS)
Eli Benderskyf659c0d2012-12-04 18:37:26 +0000286 .StartsWith("nacl", Triple::NaCl)
Hal Finkela47406c2012-04-02 18:31:33 +0000287 .StartsWith("cnk", Triple::CNK)
Eric Christopherb0f67592012-08-06 20:52:18 +0000288 .StartsWith("bitrig", Triple::Bitrig)
Duncan Sands2e522d02012-10-12 11:08:57 +0000289 .StartsWith("aix", Triple::AIX)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000290 .Default(Triple::UnknownOS);
Duncan Sands335db222010-08-12 11:31:39 +0000291}
292
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000293static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
294 return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
295 .StartsWith("eabi", Triple::EABI)
296 .StartsWith("gnueabihf", Triple::GNUEABIHF)
297 .StartsWith("gnueabi", Triple::GNUEABI)
Eli Bendersky9dd2a3b2013-01-22 18:02:49 +0000298 .StartsWith("gnux32", Triple::GNUX32)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000299 .StartsWith("gnu", Triple::GNU)
300 .StartsWith("macho", Triple::MachO)
Logan Chien43bf7092012-09-02 09:29:46 +0000301 .StartsWith("android", Triple::Android)
Andrew Kaylor7bbd6e32012-10-02 18:38:34 +0000302 .StartsWith("elf", Triple::ELF)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000303 .Default(Triple::UnknownEnvironment);
Duncan Sands5754a452010-09-16 08:25:48 +0000304}
305
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000306/// \brief Construct a triple from the string representation provided.
307///
Chandler Carruth0523f412012-02-21 08:31:18 +0000308/// This stores the string representation and parses the various pieces into
309/// enum members.
Chandler Carruth124e51c2012-02-21 03:39:36 +0000310Triple::Triple(const Twine &Str)
311 : Data(Str.str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000312 Arch(parseArch(getArchName())),
313 Vendor(parseVendor(getVendorName())),
314 OS(parseOS(getOSName())),
315 Environment(parseEnvironment(getEnvironmentName())) {
Chandler Carruth124e51c2012-02-21 03:39:36 +0000316}
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000317
318/// \brief Construct a triple from string representations of the architecture,
319/// vendor, and OS.
320///
Chandler Carruth0523f412012-02-21 08:31:18 +0000321/// This joins each argument into a canonical string representation and parses
322/// them into enum members. It leaves the environment unknown and omits it from
323/// the string representation.
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000324Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr)
325 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr).str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000326 Arch(parseArch(ArchStr.str())),
327 Vendor(parseVendor(VendorStr.str())),
328 OS(parseOS(OSStr.str())),
Chandler Carruth124e51c2012-02-21 03:39:36 +0000329 Environment() {
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000330}
331
332/// \brief Construct a triple from string representations of the architecture,
333/// vendor, OS, and environment.
334///
Chandler Carruth0523f412012-02-21 08:31:18 +0000335/// This joins each argument into a canonical string representation and parses
336/// them into enum members.
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000337Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
338 const Twine &EnvironmentStr)
339 : Data((ArchStr + Twine('-') + VendorStr + Twine('-') + OSStr + Twine('-') +
340 EnvironmentStr).str()),
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000341 Arch(parseArch(ArchStr.str())),
342 Vendor(parseVendor(VendorStr.str())),
343 OS(parseOS(OSStr.str())),
344 Environment(parseEnvironment(EnvironmentStr.str())) {
Chandler Carruthcceb8f42012-02-20 00:02:47 +0000345}
346
Duncan Sands335db222010-08-12 11:31:39 +0000347std::string Triple::normalize(StringRef Str) {
348 // Parse into components.
349 SmallVector<StringRef, 4> Components;
Chandler Carruthdac3d362012-02-21 09:12:48 +0000350 Str.split(Components, "-");
Duncan Sands335db222010-08-12 11:31:39 +0000351
352 // If the first component corresponds to a known architecture, preferentially
353 // use it for the architecture. If the second component corresponds to a
354 // known vendor, preferentially use it for the vendor, etc. This avoids silly
355 // component movement when a component parses as (eg) both a valid arch and a
356 // valid os.
357 ArchType Arch = UnknownArch;
358 if (Components.size() > 0)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000359 Arch = parseArch(Components[0]);
Duncan Sands335db222010-08-12 11:31:39 +0000360 VendorType Vendor = UnknownVendor;
361 if (Components.size() > 1)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000362 Vendor = parseVendor(Components[1]);
Duncan Sands335db222010-08-12 11:31:39 +0000363 OSType OS = UnknownOS;
364 if (Components.size() > 2)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000365 OS = parseOS(Components[2]);
Duncan Sands5754a452010-09-16 08:25:48 +0000366 EnvironmentType Environment = UnknownEnvironment;
367 if (Components.size() > 3)
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000368 Environment = parseEnvironment(Components[3]);
Duncan Sands335db222010-08-12 11:31:39 +0000369
370 // Note which components are already in their final position. These will not
371 // be moved.
Duncan Sands5754a452010-09-16 08:25:48 +0000372 bool Found[4];
Duncan Sands335db222010-08-12 11:31:39 +0000373 Found[0] = Arch != UnknownArch;
374 Found[1] = Vendor != UnknownVendor;
375 Found[2] = OS != UnknownOS;
Duncan Sands5754a452010-09-16 08:25:48 +0000376 Found[3] = Environment != UnknownEnvironment;
Duncan Sands335db222010-08-12 11:31:39 +0000377
378 // If they are not there already, permute the components into their canonical
379 // positions by seeing if they parse as a valid architecture, and if so moving
380 // the component to the architecture position etc.
Duncan Sands5754a452010-09-16 08:25:48 +0000381 for (unsigned Pos = 0; Pos != array_lengthof(Found); ++Pos) {
Duncan Sands335db222010-08-12 11:31:39 +0000382 if (Found[Pos])
383 continue; // Already in the canonical position.
384
385 for (unsigned Idx = 0; Idx != Components.size(); ++Idx) {
386 // Do not reparse any components that already matched.
Duncan Sands5754a452010-09-16 08:25:48 +0000387 if (Idx < array_lengthof(Found) && Found[Idx])
Duncan Sands335db222010-08-12 11:31:39 +0000388 continue;
389
390 // Does this component parse as valid for the target position?
391 bool Valid = false;
392 StringRef Comp = Components[Idx];
393 switch (Pos) {
Craig Topper85814382012-02-07 05:05:23 +0000394 default: llvm_unreachable("unexpected component type!");
Duncan Sands335db222010-08-12 11:31:39 +0000395 case 0:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000396 Arch = parseArch(Comp);
Duncan Sands335db222010-08-12 11:31:39 +0000397 Valid = Arch != UnknownArch;
398 break;
399 case 1:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000400 Vendor = parseVendor(Comp);
Duncan Sands335db222010-08-12 11:31:39 +0000401 Valid = Vendor != UnknownVendor;
402 break;
403 case 2:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000404 OS = parseOS(Comp);
Duncan Sandsae200c62011-02-02 10:08:38 +0000405 Valid = OS != UnknownOS;
Duncan Sands335db222010-08-12 11:31:39 +0000406 break;
Duncan Sands5754a452010-09-16 08:25:48 +0000407 case 3:
Chandler Carruth4fbf6582012-02-21 08:53:32 +0000408 Environment = parseEnvironment(Comp);
Duncan Sands5754a452010-09-16 08:25:48 +0000409 Valid = Environment != UnknownEnvironment;
410 break;
Duncan Sands335db222010-08-12 11:31:39 +0000411 }
412 if (!Valid)
413 continue; // Nope, try the next component.
414
415 // Move the component to the target position, pushing any non-fixed
416 // components that are in the way to the right. This tends to give
417 // good results in the common cases of a forgotten vendor component
418 // or a wrongly positioned environment.
419 if (Pos < Idx) {
420 // Insert left, pushing the existing components to the right. For
421 // example, a-b-i386 -> i386-a-b when moving i386 to the front.
422 StringRef CurrentComponent(""); // The empty component.
423 // Replace the component we are moving with an empty component.
424 std::swap(CurrentComponent, Components[Idx]);
425 // Insert the component being moved at Pos, displacing any existing
426 // components to the right.
427 for (unsigned i = Pos; !CurrentComponent.empty(); ++i) {
428 // Skip over any fixed components.
Chandler Carruthc5f18d32012-02-21 09:29:14 +0000429 while (i < array_lengthof(Found) && Found[i])
430 ++i;
Duncan Sands335db222010-08-12 11:31:39 +0000431 // Place the component at the new position, getting the component
432 // that was at this position - it will be moved right.
433 std::swap(CurrentComponent, Components[i]);
434 }
435 } else if (Pos > Idx) {
436 // Push right by inserting empty components until the component at Idx
437 // reaches the target position Pos. For example, pc-a -> -pc-a when
438 // moving pc to the second position.
439 do {
440 // Insert one empty component at Idx.
441 StringRef CurrentComponent(""); // The empty component.
Duncan Sandsae200c62011-02-02 10:08:38 +0000442 for (unsigned i = Idx; i < Components.size();) {
Duncan Sands335db222010-08-12 11:31:39 +0000443 // Place the component at the new position, getting the component
444 // that was at this position - it will be moved right.
445 std::swap(CurrentComponent, Components[i]);
446 // If it was placed on top of an empty component then we are done.
447 if (CurrentComponent.empty())
448 break;
Duncan Sandsae200c62011-02-02 10:08:38 +0000449 // Advance to the next component, skipping any fixed components.
Anders Carlsson15ec6952011-02-05 18:19:35 +0000450 while (++i < array_lengthof(Found) && Found[i])
451 ;
Duncan Sands335db222010-08-12 11:31:39 +0000452 }
453 // The last component was pushed off the end - append it.
454 if (!CurrentComponent.empty())
455 Components.push_back(CurrentComponent);
456
457 // Advance Idx to the component's new position.
Chandler Carruthc5f18d32012-02-21 09:29:14 +0000458 while (++Idx < array_lengthof(Found) && Found[Idx])
459 ;
Duncan Sands335db222010-08-12 11:31:39 +0000460 } while (Idx < Pos); // Add more until the final position is reached.
461 }
462 assert(Pos < Components.size() && Components[Pos] == Comp &&
463 "Component moved wrong!");
464 Found[Pos] = true;
465 break;
466 }
467 }
468
469 // Special case logic goes here. At this point Arch, Vendor and OS have the
470 // correct values for the computed components.
471
472 // Stick the corrected components back together to form the normalized string.
473 std::string Normalized;
474 for (unsigned i = 0, e = Components.size(); i != e; ++i) {
475 if (i) Normalized += '-';
476 Normalized += Components[i];
477 }
478 return Normalized;
479}
480
Daniel Dunbara14d2252009-07-26 03:31:47 +0000481StringRef Triple::getArchName() const {
482 return StringRef(Data).split('-').first; // Isolate first component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000483}
484
Daniel Dunbara14d2252009-07-26 03:31:47 +0000485StringRef Triple::getVendorName() const {
486 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
487 return Tmp.split('-').first; // Isolate second component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000488}
489
Daniel Dunbara14d2252009-07-26 03:31:47 +0000490StringRef Triple::getOSName() const {
491 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
492 Tmp = Tmp.split('-').second; // Strip second component
493 return Tmp.split('-').first; // Isolate third component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000494}
495
Daniel Dunbara14d2252009-07-26 03:31:47 +0000496StringRef Triple::getEnvironmentName() const {
497 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
498 Tmp = Tmp.split('-').second; // Strip second component
499 return Tmp.split('-').second; // Strip third component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000500}
501
Daniel Dunbara14d2252009-07-26 03:31:47 +0000502StringRef Triple::getOSAndEnvironmentName() const {
503 StringRef Tmp = StringRef(Data).split('-').second; // Strip first component
504 return Tmp.split('-').second; // Strip second component
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000505}
506
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000507static unsigned EatNumber(StringRef &Str) {
508 assert(!Str.empty() && Str[0] >= '0' && Str[0] <= '9' && "Not a number");
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000509 unsigned Result = 0;
Jim Grosbache509aa92010-12-17 02:10:59 +0000510
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000511 do {
512 // Consume the leading digit.
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000513 Result = Result*10 + (Str[0] - '0');
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000514
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000515 // Eat the digit.
516 Str = Str.substr(1);
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000517 } while (!Str.empty() && Str[0] >= '0' && Str[0] <= '9');
Jim Grosbache509aa92010-12-17 02:10:59 +0000518
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000519 return Result;
520}
521
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000522void Triple::getOSVersion(unsigned &Major, unsigned &Minor,
523 unsigned &Micro) const {
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000524 StringRef OSName = getOSName();
Jim Grosbache509aa92010-12-17 02:10:59 +0000525
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000526 // Assume that the OS portion of the triple starts with the canonical name.
527 StringRef OSTypeName = getOSTypeName(getOS());
528 if (OSName.startswith(OSTypeName))
529 OSName = OSName.substr(OSTypeName.size());
Jim Grosbache509aa92010-12-17 02:10:59 +0000530
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000531 // Any unset version defaults to 0.
532 Major = Minor = Micro = 0;
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000533
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000534 // Parse up to three components.
535 unsigned *Components[3] = { &Major, &Minor, &Micro };
536 for (unsigned i = 0; i != 3; ++i) {
537 if (OSName.empty() || OSName[0] < '0' || OSName[0] > '9')
538 break;
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000539
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000540 // Consume the leading number.
541 *Components[i] = EatNumber(OSName);
Jim Grosbache509aa92010-12-17 02:10:59 +0000542
Daniel Dunbar087d6a52011-04-19 20:24:34 +0000543 // Consume the separator, if present.
544 if (OSName.startswith("."))
545 OSName = OSName.substr(1);
546 }
Chris Lattnerdfc17f72009-08-12 06:19:40 +0000547}
548
Bob Wilsonbda59fd2012-01-31 22:32:29 +0000549bool Triple::getMacOSXVersion(unsigned &Major, unsigned &Minor,
550 unsigned &Micro) const {
551 getOSVersion(Major, Minor, Micro);
552
553 switch (getOS()) {
Craig Topper85814382012-02-07 05:05:23 +0000554 default: llvm_unreachable("unexpected OS for Darwin triple");
Bob Wilsonbda59fd2012-01-31 22:32:29 +0000555 case Darwin:
556 // Default to darwin8, i.e., MacOSX 10.4.
557 if (Major == 0)
558 Major = 8;
559 // Darwin version numbers are skewed from OS X versions.
560 if (Major < 4)
561 return false;
562 Micro = 0;
563 Minor = Major - 4;
564 Major = 10;
565 break;
566 case MacOSX:
567 // Default to 10.4.
568 if (Major == 0) {
569 Major = 10;
570 Minor = 4;
571 }
572 if (Major != 10)
573 return false;
574 break;
575 case IOS:
576 // Ignore the version from the triple. This is only handled because the
577 // the clang driver combines OS X and IOS support into a common Darwin
578 // toolchain that wants to know the OS X version number even when targeting
579 // IOS.
580 Major = 10;
581 Minor = 4;
582 Micro = 0;
583 break;
584 }
585 return true;
586}
587
Chad Rosierecee47e2012-05-09 17:23:48 +0000588void Triple::getiOSVersion(unsigned &Major, unsigned &Minor,
589 unsigned &Micro) const {
590 switch (getOS()) {
591 default: llvm_unreachable("unexpected OS for Darwin triple");
592 case Darwin:
593 case MacOSX:
594 // Ignore the version from the triple. This is only handled because the
595 // the clang driver combines OS X and IOS support into a common Darwin
596 // toolchain that wants to know the iOS version number even when targeting
597 // OS X.
Chad Rosier537c2f52012-05-09 18:23:00 +0000598 Major = 3;
Chad Rosierecee47e2012-05-09 17:23:48 +0000599 Minor = 0;
600 Micro = 0;
Chad Rosier26bbdee2012-05-09 17:38:47 +0000601 break;
Chad Rosierecee47e2012-05-09 17:23:48 +0000602 case IOS:
603 getOSVersion(Major, Minor, Micro);
Chad Rosier537c2f52012-05-09 18:23:00 +0000604 // Default to 3.0.
605 if (Major == 0)
606 Major = 3;
Chad Rosierecee47e2012-05-09 17:23:48 +0000607 break;
608 }
609}
610
Daniel Dunbara14d2252009-07-26 03:31:47 +0000611void Triple::setTriple(const Twine &Str) {
Chandler Carruth124e51c2012-02-21 03:39:36 +0000612 *this = Triple(Str);
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000613}
614
615void Triple::setArch(ArchType Kind) {
616 setArchName(getArchTypeName(Kind));
617}
618
619void Triple::setVendor(VendorType Kind) {
620 setVendorName(getVendorTypeName(Kind));
621}
622
623void Triple::setOS(OSType Kind) {
624 setOSName(getOSTypeName(Kind));
625}
626
Duncan Sands5754a452010-09-16 08:25:48 +0000627void Triple::setEnvironment(EnvironmentType Kind) {
628 setEnvironmentName(getEnvironmentTypeName(Kind));
629}
630
Daniel Dunbar2928c832009-11-06 10:58:06 +0000631void Triple::setArchName(StringRef Str) {
Jeffrey Yasskin0b228732009-10-06 21:45:26 +0000632 // Work around a miscompilation bug for Twines in gcc 4.0.3.
633 SmallString<64> Triple;
634 Triple += Str;
635 Triple += "-";
636 Triple += getVendorName();
637 Triple += "-";
638 Triple += getOSAndEnvironmentName();
639 setTriple(Triple.str());
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000640}
641
Daniel Dunbar2928c832009-11-06 10:58:06 +0000642void Triple::setVendorName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000643 setTriple(getArchName() + "-" + Str + "-" + getOSAndEnvironmentName());
644}
645
Daniel Dunbar2928c832009-11-06 10:58:06 +0000646void Triple::setOSName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000647 if (hasEnvironment())
648 setTriple(getArchName() + "-" + getVendorName() + "-" + Str +
649 "-" + getEnvironmentName());
650 else
651 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
652}
653
Daniel Dunbar2928c832009-11-06 10:58:06 +0000654void Triple::setEnvironmentName(StringRef Str) {
655 setTriple(getArchName() + "-" + getVendorName() + "-" + getOSName() +
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000656 "-" + Str);
657}
658
Daniel Dunbar2928c832009-11-06 10:58:06 +0000659void Triple::setOSAndEnvironmentName(StringRef Str) {
Daniel Dunbar23e97b02009-04-01 21:53:23 +0000660 setTriple(getArchName() + "-" + getVendorName() + "-" + Str);
661}
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000662
663static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
664 switch (Arch) {
665 case llvm::Triple::UnknownArch:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000666 return 0;
667
668 case llvm::Triple::msp430:
669 return 16;
670
671 case llvm::Triple::amdil:
672 case llvm::Triple::arm:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000673 case llvm::Triple::hexagon:
674 case llvm::Triple::le32:
675 case llvm::Triple::mblaze:
676 case llvm::Triple::mips:
677 case llvm::Triple::mipsel:
Justin Holewinski49683f32012-05-04 20:18:50 +0000678 case llvm::Triple::nvptx:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000679 case llvm::Triple::ppc:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000680 case llvm::Triple::r600:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000681 case llvm::Triple::sparc:
682 case llvm::Triple::tce:
683 case llvm::Triple::thumb:
684 case llvm::Triple::x86:
685 case llvm::Triple::xcore:
Guy Benyeiac39a032012-11-15 10:35:47 +0000686 case llvm::Triple::spir:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000687 return 32;
688
Tim Northover72062f52013-01-31 12:12:40 +0000689 case llvm::Triple::aarch64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000690 case llvm::Triple::mips64:
691 case llvm::Triple::mips64el:
Justin Holewinski49683f32012-05-04 20:18:50 +0000692 case llvm::Triple::nvptx64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000693 case llvm::Triple::ppc64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000694 case llvm::Triple::sparcv9:
Richard Sandiford05129102013-05-03 11:05:17 +0000695 case llvm::Triple::systemz:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000696 case llvm::Triple::x86_64:
Guy Benyeiac39a032012-11-15 10:35:47 +0000697 case llvm::Triple::spir64:
Chandler Carruth6f72ac42012-01-31 04:52:32 +0000698 return 64;
699 }
700 llvm_unreachable("Invalid architecture value");
701}
702
703bool Triple::isArch64Bit() const {
704 return getArchPointerBitWidth(getArch()) == 64;
705}
706
707bool Triple::isArch32Bit() const {
708 return getArchPointerBitWidth(getArch()) == 32;
709}
710
711bool Triple::isArch16Bit() const {
712 return getArchPointerBitWidth(getArch()) == 16;
713}
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000714
715Triple Triple::get32BitArchVariant() const {
716 Triple T(*this);
717 switch (getArch()) {
718 case Triple::UnknownArch:
Tim Northover72062f52013-01-31 12:12:40 +0000719 case Triple::aarch64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000720 case Triple::msp430:
Richard Sandiford05129102013-05-03 11:05:17 +0000721 case Triple::systemz:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000722 T.setArch(UnknownArch);
723 break;
724
725 case Triple::amdil:
Micah Villmowe53d6052012-10-01 17:01:31 +0000726 case Triple::spir:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000727 case Triple::arm:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000728 case Triple::hexagon:
729 case Triple::le32:
730 case Triple::mblaze:
731 case Triple::mips:
732 case Triple::mipsel:
Justin Holewinski49683f32012-05-04 20:18:50 +0000733 case Triple::nvptx:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000734 case Triple::ppc:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000735 case Triple::r600:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000736 case Triple::sparc:
737 case Triple::tce:
738 case Triple::thumb:
739 case Triple::x86:
740 case Triple::xcore:
741 // Already 32-bit.
742 break;
743
744 case Triple::mips64: T.setArch(Triple::mips); break;
745 case Triple::mips64el: T.setArch(Triple::mipsel); break;
Justin Holewinski49683f32012-05-04 20:18:50 +0000746 case Triple::nvptx64: T.setArch(Triple::nvptx); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000747 case Triple::ppc64: T.setArch(Triple::ppc); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000748 case Triple::sparcv9: T.setArch(Triple::sparc); break;
749 case Triple::x86_64: T.setArch(Triple::x86); break;
Guy Benyeiac39a032012-11-15 10:35:47 +0000750 case Triple::spir64: T.setArch(Triple::spir); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000751 }
752 return T;
753}
754
755Triple Triple::get64BitArchVariant() const {
756 Triple T(*this);
757 switch (getArch()) {
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000758 case Triple::UnknownArch:
759 case Triple::amdil:
760 case Triple::arm:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000761 case Triple::hexagon:
762 case Triple::le32:
763 case Triple::mblaze:
764 case Triple::msp430:
Anton Korobeynikov74156592012-03-09 10:09:36 +0000765 case Triple::r600:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000766 case Triple::tce:
767 case Triple::thumb:
768 case Triple::xcore:
769 T.setArch(UnknownArch);
770 break;
771
Tim Northover72062f52013-01-31 12:12:40 +0000772 case Triple::aarch64:
Guy Benyeiac39a032012-11-15 10:35:47 +0000773 case Triple::spir64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000774 case Triple::mips64:
775 case Triple::mips64el:
Justin Holewinski49683f32012-05-04 20:18:50 +0000776 case Triple::nvptx64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000777 case Triple::ppc64:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000778 case Triple::sparcv9:
Richard Sandiford05129102013-05-03 11:05:17 +0000779 case Triple::systemz:
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000780 case Triple::x86_64:
781 // Already 64-bit.
782 break;
783
784 case Triple::mips: T.setArch(Triple::mips64); break;
785 case Triple::mipsel: T.setArch(Triple::mips64el); break;
Justin Holewinski49683f32012-05-04 20:18:50 +0000786 case Triple::nvptx: T.setArch(Triple::nvptx64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000787 case Triple::ppc: T.setArch(Triple::ppc64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000788 case Triple::sparc: T.setArch(Triple::sparcv9); break;
789 case Triple::x86: T.setArch(Triple::x86_64); break;
Guy Benyeiac39a032012-11-15 10:35:47 +0000790 case Triple::spir: T.setArch(Triple::spir64); break;
Chandler Carruth7d5a2892012-02-06 20:46:33 +0000791 }
792 return T;
793}