blob: b1cbc23f8140bd42ffa0b8bcc13fe24e70469b43 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Anton Korobeynikova7c47172009-05-03 13:42:53 +000010// This file implements construction of a TargetInfo object from a
Ted Kremenekbbced582007-12-12 18:05:32 +000011// target triple.
Reid Spencer5f016e22007-07-11 17:01:13 +000012//
13//===----------------------------------------------------------------------===//
14
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/Basic/TargetInfo.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000016#include "clang/Basic/Builtins.h"
17#include "clang/Basic/Diagnostic.h"
Chris Lattner8fc4dfb2008-12-04 22:54:33 +000018#include "clang/Basic/LangOptions.h"
Chandler Carruth103b71c2010-01-20 06:13:02 +000019#include "clang/Basic/MacroBuilder.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000020#include "clang/Basic/TargetBuiltins.h"
21#include "clang/Basic/TargetOptions.h"
Eli Friedman25531262008-05-20 14:27:34 +000022#include "llvm/ADT/APFloat.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000023#include "llvm/ADT/OwningPtr.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000024#include "llvm/ADT/STLExtras.h"
Daniel Dunbar77659342009-08-19 20:04:03 +000025#include "llvm/ADT/StringRef.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000026#include "llvm/ADT/StringSwitch.h"
Chris Lattner4c28b1c2009-08-12 06:24:27 +000027#include "llvm/ADT/Triple.h"
Chandler Carruth3b844ba2013-01-02 11:45:17 +000028#include "llvm/IR/Type.h"
Chris Lattner797c3c42009-08-10 19:03:04 +000029#include "llvm/MC/MCSectionMachO.h"
David Blaikie9fe8c742011-09-23 05:35:21 +000030#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer48725082010-01-09 18:20:57 +000031#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000032using namespace clang;
33
Reid Spencer5f016e22007-07-11 17:01:13 +000034//===----------------------------------------------------------------------===//
35// Common code shared among targets.
36//===----------------------------------------------------------------------===//
37
Chris Lattnerca45cff2009-03-20 16:06:38 +000038/// DefineStd - Define a macro name and standard variants. For example if
39/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
40/// when in GNU mode.
Chris Lattner5f9e2722011-07-23 10:55:15 +000041static void DefineStd(MacroBuilder &Builder, StringRef MacroName,
Chris Lattnerca45cff2009-03-20 16:06:38 +000042 const LangOptions &Opts) {
43 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000044
Chris Lattnerca45cff2009-03-20 16:06:38 +000045 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
46 // in the user's namespace.
47 if (Opts.GNUMode)
Benjamin Kramera9992772010-01-09 17:55:51 +000048 Builder.defineMacro(MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000049
Chris Lattnerca45cff2009-03-20 16:06:38 +000050 // Define __unix.
Benjamin Kramera9992772010-01-09 17:55:51 +000051 Builder.defineMacro("__" + MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000052
Chris Lattnerca45cff2009-03-20 16:06:38 +000053 // Define __unix__.
Benjamin Kramera9992772010-01-09 17:55:51 +000054 Builder.defineMacro("__" + MacroName + "__");
Chris Lattnerca45cff2009-03-20 16:06:38 +000055}
56
Benjamin Kramer448f68d2012-01-10 11:50:09 +000057static void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName,
58 bool Tuning = true) {
59 Builder.defineMacro("__" + CPUName);
60 Builder.defineMacro("__" + CPUName + "__");
61 if (Tuning)
62 Builder.defineMacro("__tune_" + CPUName + "__");
63}
64
Chris Lattnerd29b6302008-10-05 21:50:58 +000065//===----------------------------------------------------------------------===//
66// Defines specific to certain operating systems.
67//===----------------------------------------------------------------------===//
Chris Lattner797c3c42009-08-10 19:03:04 +000068
Torok Edwin5f6c1942009-06-30 17:10:35 +000069namespace {
Douglas Gregora3844922009-07-01 15:12:53 +000070template<typename TgtInfo>
71class OSTargetInfo : public TgtInfo {
Torok Edwin5f6c1942009-06-30 17:10:35 +000072protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +000073 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +000074 MacroBuilder &Builder) const=0;
Torok Edwin5f6c1942009-06-30 17:10:35 +000075public:
Benjamin Kramer9df08232013-06-29 16:37:14 +000076 OSTargetInfo(const llvm::Triple &Triple) : TgtInfo(Triple) {}
Torok Edwin5f6c1942009-06-30 17:10:35 +000077 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +000078 MacroBuilder &Builder) const {
79 TgtInfo::getTargetDefines(Opts, Builder);
80 getOSDefines(Opts, TgtInfo::getTriple(), Builder);
Torok Edwinb0a5b242009-06-30 17:00:25 +000081 }
Torok Edwin5f6c1942009-06-30 17:10:35 +000082
83};
Chris Lattner4c28b1c2009-08-12 06:24:27 +000084} // end anonymous namespace
Torok Edwinb0a5b242009-06-30 17:00:25 +000085
Chris Lattner797c3c42009-08-10 19:03:04 +000086
Daniel Dunbar21ae3192010-01-26 01:44:04 +000087static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000088 const llvm::Triple &Triple,
Chris Lattner5f9e2722011-07-23 10:55:15 +000089 StringRef &PlatformName,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000090 VersionTuple &PlatformMinVersion) {
Bob Wilsond588f5c2013-08-19 20:23:37 +000091 Builder.defineMacro("__APPLE_CC__", "6000");
Benjamin Kramera9992772010-01-09 17:55:51 +000092 Builder.defineMacro("__APPLE__");
93 Builder.defineMacro("__MACH__");
94 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Alexander Potapenko087c65f2012-09-20 10:10:01 +000095 // AddressSanitizer doesn't play well with source fortification, which is on
96 // by default on Darwin.
Will Dietz4f45bc02013-01-18 11:30:38 +000097 if (Opts.Sanitize.Address) Builder.defineMacro("_FORTIFY_SOURCE", "0");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000098
John McCall098df7f2011-06-16 00:03:19 +000099 if (!Opts.ObjCAutoRefCount) {
John McCallf85e1932011-06-15 23:02:42 +0000100 // __weak is always defined, for use in blocks and with objc pointers.
101 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000102
John McCallf85e1932011-06-15 23:02:42 +0000103 // Darwin defines __strong even in C mode (just to nothing).
Douglas Gregore289d812011-09-13 17:21:33 +0000104 if (Opts.getGC() != LangOptions::NonGC)
John McCallf85e1932011-06-15 23:02:42 +0000105 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
106 else
107 Builder.defineMacro("__strong", "");
Eric Christopher7c9adf92011-07-07 22:55:26 +0000108
John McCallf85e1932011-06-15 23:02:42 +0000109 // __unsafe_unretained is defined to nothing in non-ARC mode. We even
110 // allow this in C, since one might have block pointers in structs that
111 // are used in pure C code and in Objective-C ARC.
112 Builder.defineMacro("__unsafe_unretained", "");
John McCallf85e1932011-06-15 23:02:42 +0000113 }
Eric Christopher7c9adf92011-07-07 22:55:26 +0000114
Eli Friedman2de4fee2009-06-04 23:00:29 +0000115 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +0000116 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +0000117 else
Benjamin Kramera9992772010-01-09 17:55:51 +0000118 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000119
120 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000121 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000122
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000123 // Get the platform type and version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000124 unsigned Maj, Min, Rev;
Bob Wilson48b68a02012-01-31 23:52:58 +0000125 if (Triple.isMacOSX()) {
126 Triple.getMacOSXVersion(Maj, Min, Rev);
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000127 PlatformName = "macosx";
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000128 } else {
Bob Wilson48b68a02012-01-31 23:52:58 +0000129 Triple.getOSVersion(Maj, Min, Rev);
130 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000131 }
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000132
Sebastian Pop9ec60df2012-01-20 22:01:23 +0000133 // If -target arch-pc-win32-macho option specified, we're
Eric Christopher895d4222011-07-29 21:20:35 +0000134 // generating code for Win32 ABI. No need to emit
Chad Rosierd9259f32011-07-19 20:00:06 +0000135 // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__.
136 if (PlatformName == "win32") {
137 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
138 return;
139 }
140
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000141 // Set the appropriate OS version define.
Bob Wilson48b68a02012-01-31 23:52:58 +0000142 if (Triple.getOS() == llvm::Triple::IOS) {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000143 assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000144 char Str[6];
145 Str[0] = '0' + Maj;
146 Str[1] = '0' + (Min / 10);
147 Str[2] = '0' + (Min % 10);
148 Str[3] = '0' + (Rev / 10);
149 Str[4] = '0' + (Rev % 10);
150 Str[5] = '\0';
151 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
152 } else {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000153 // Note that the Driver allows versions which aren't representable in the
154 // define (because we only get a single digit for the minor and micro
155 // revision numbers). So, we limit them to the maximum representable
156 // version.
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000157 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000158 assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000159 char Str[5];
160 Str[0] = '0' + (Maj / 10);
161 Str[1] = '0' + (Maj % 10);
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000162 Str[2] = '0' + std::min(Min, 9U);
163 Str[3] = '0' + std::min(Rev, 9U);
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000164 Str[4] = '\0';
165 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000166 }
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000167
168 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
Eli Friedman618234a2008-08-20 02:34:37 +0000169}
Reid Spencer5f016e22007-07-11 17:01:13 +0000170
Chris Lattner797c3c42009-08-10 19:03:04 +0000171namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000172template<typename Target>
173class DarwinTargetInfo : public OSTargetInfo<Target> {
174protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000175 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000176 MacroBuilder &Builder) const {
Eric Christopher7c9adf92011-07-07 22:55:26 +0000177 getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000178 this->PlatformMinVersion);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000179 }
Mike Stump1eb44332009-09-09 15:08:12 +0000180
Torok Edwin5f6c1942009-06-30 17:10:35 +0000181public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000182 DarwinTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
183 this->TLSSupported = Triple.isMacOSX() && !Triple.isMacOSXVersionLT(10, 7);
184 this->MCountName = "\01mcount";
185 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000186
Chris Lattner5f9e2722011-07-23 10:55:15 +0000187 virtual std::string isValidSectionSpecifier(StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000188 // Let MCSectionMachO validate this.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000189 StringRef Segment, Section;
Chris Lattner797c3c42009-08-10 19:03:04 +0000190 unsigned TAA, StubSize;
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000191 bool HasTAA;
Chris Lattner797c3c42009-08-10 19:03:04 +0000192 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000193 TAA, HasTAA, StubSize);
Chris Lattner797c3c42009-08-10 19:03:04 +0000194 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000195
Anders Carlsson18af3682010-06-08 22:47:50 +0000196 virtual const char *getStaticInitSectionSpecifier() const {
197 // FIXME: We should return 0 when building kexts.
198 return "__TEXT,__StaticInit,regular,pure_instructions";
199 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000200
John McCall41887602012-01-29 01:20:30 +0000201 /// Darwin does not support protected visibility. Darwin's "default"
202 /// is very similar to ELF's "protected"; Darwin requires a "weak"
203 /// attribute on declarations that can be dynamically replaced.
204 virtual bool hasProtectedVisibility() const {
205 return false;
206 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000207};
208
Chris Lattner797c3c42009-08-10 19:03:04 +0000209
Torok Edwin5f6c1942009-06-30 17:10:35 +0000210// DragonFlyBSD Target
211template<typename Target>
212class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
213protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000214 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000215 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000216 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000217 Builder.defineMacro("__DragonFly__");
218 Builder.defineMacro("__DragonFly_cc_version", "100001");
219 Builder.defineMacro("__ELF__");
220 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
221 Builder.defineMacro("__tune_i386__");
222 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000223 }
224public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000225 DragonFlyBSDTargetInfo(const llvm::Triple &Triple)
226 : OSTargetInfo<Target>(Triple) {
227 this->UserLabelPrefix = "";
Eli Friedmanb089c4d2012-02-10 23:02:29 +0000228
Benjamin Kramer9df08232013-06-29 16:37:14 +0000229 switch (Triple.getArch()) {
230 default:
231 case llvm::Triple::x86:
232 case llvm::Triple::x86_64:
233 this->MCountName = ".mcount";
234 break;
235 }
Eli Friedmanb089c4d2012-02-10 23:02:29 +0000236 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000237};
238
239// FreeBSD Target
240template<typename Target>
241class FreeBSDTargetInfo : public OSTargetInfo<Target> {
242protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000243 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000244 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000245 // FreeBSD defines; list based off of gcc output
246
Benjamin Kramer474202f2011-10-18 10:10:08 +0000247 unsigned Release = Triple.getOSMajorVersion();
248 if (Release == 0U)
249 Release = 8;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000250
Benjamin Kramer474202f2011-10-18 10:10:08 +0000251 Builder.defineMacro("__FreeBSD__", Twine(Release));
252 Builder.defineMacro("__FreeBSD_cc_version", Twine(Release * 100000U + 1U));
Benjamin Kramera9992772010-01-09 17:55:51 +0000253 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
254 DefineStd(Builder, "unix", Opts);
255 Builder.defineMacro("__ELF__");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000256 }
257public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000258 FreeBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
259 this->UserLabelPrefix = "";
Roman Divackybe4c8702011-02-10 16:52:03 +0000260
Benjamin Kramer9df08232013-06-29 16:37:14 +0000261 switch (Triple.getArch()) {
262 default:
263 case llvm::Triple::x86:
264 case llvm::Triple::x86_64:
265 this->MCountName = ".mcount";
266 break;
267 case llvm::Triple::mips:
268 case llvm::Triple::mipsel:
269 case llvm::Triple::ppc:
270 case llvm::Triple::ppc64:
Bill Schmidtea7fb0c2013-07-26 01:36:11 +0000271 case llvm::Triple::ppc64le:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000272 this->MCountName = "_mcount";
273 break;
274 case llvm::Triple::arm:
275 this->MCountName = "__mcount";
276 break;
Duncan Sands1e90faf2009-07-08 13:55:08 +0000277 }
Benjamin Kramer9df08232013-06-29 16:37:14 +0000278 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000279};
280
Sylvestre Ledru3309a782013-09-05 13:47:07 +0000281// GNU/kFreeBSD Target
282template<typename Target>
283class KFreeBSDTargetInfo : public OSTargetInfo<Target> {
284protected:
285 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
286 MacroBuilder &Builder) const {
287 // GNU/kFreeBSD defines; list based off of gcc output
288
289 DefineStd(Builder, "unix", Opts);
290 Builder.defineMacro("__FreeBSD_kernel__");
291 Builder.defineMacro("__GLIBC__");
292 Builder.defineMacro("__ELF__");
293 if (Opts.POSIXThreads)
294 Builder.defineMacro("_REENTRANT");
295 if (Opts.CPlusPlus)
296 Builder.defineMacro("_GNU_SOURCE");
297 }
298public:
Sylvestre Ledrudeb77992013-09-05 13:58:07 +0000299 KFreeBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
Sylvestre Ledru3309a782013-09-05 13:47:07 +0000300 this->UserLabelPrefix = "";
301 }
302};
303
Chris Lattner38e317d2010-07-07 16:01:42 +0000304// Minix Target
305template<typename Target>
306class MinixTargetInfo : public OSTargetInfo<Target> {
307protected:
308 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
309 MacroBuilder &Builder) const {
310 // Minix defines
311
312 Builder.defineMacro("__minix", "3");
313 Builder.defineMacro("_EM_WSIZE", "4");
314 Builder.defineMacro("_EM_PSIZE", "4");
315 Builder.defineMacro("_EM_SSIZE", "2");
316 Builder.defineMacro("_EM_LSIZE", "4");
317 Builder.defineMacro("_EM_FSIZE", "4");
318 Builder.defineMacro("_EM_DSIZE", "8");
Eli Friedman6d402dc2011-12-08 23:54:21 +0000319 Builder.defineMacro("__ELF__");
Chris Lattner38e317d2010-07-07 16:01:42 +0000320 DefineStd(Builder, "unix", Opts);
321 }
322public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000323 MinixTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
324 this->UserLabelPrefix = "";
325 }
Chris Lattner38e317d2010-07-07 16:01:42 +0000326};
327
Torok Edwin5f6c1942009-06-30 17:10:35 +0000328// Linux target
329template<typename Target>
330class LinuxTargetInfo : public OSTargetInfo<Target> {
331protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000332 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000333 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000334 // Linux defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000335 DefineStd(Builder, "unix", Opts);
336 DefineStd(Builder, "linux", Opts);
337 Builder.defineMacro("__gnu_linux__");
338 Builder.defineMacro("__ELF__");
Logan Chien94a71422012-09-02 09:30:11 +0000339 if (Triple.getEnvironment() == llvm::Triple::Android)
Evgeniy Stepanov32064032012-04-26 12:08:09 +0000340 Builder.defineMacro("__ANDROID__", "1");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000341 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000342 Builder.defineMacro("_REENTRANT");
Douglas Gregor2b003fd2010-04-21 05:52:38 +0000343 if (Opts.CPlusPlus)
344 Builder.defineMacro("_GNU_SOURCE");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000345 }
346public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000347 LinuxTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000348 this->UserLabelPrefix = "";
Douglas Gregor12e84642011-01-12 21:19:25 +0000349 this->WIntType = TargetInfo::UnsignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000350 }
Benjamin Kramer86d18c52011-10-15 17:53:33 +0000351
352 virtual const char *getStaticInitSectionSpecifier() const {
353 return ".text.startup";
354 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000355};
356
Chris Lattnerb62bb282009-07-13 20:29:08 +0000357// NetBSD Target
358template<typename Target>
359class NetBSDTargetInfo : public OSTargetInfo<Target> {
360protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000361 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000362 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000363 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000364 Builder.defineMacro("__NetBSD__");
365 Builder.defineMacro("__unix__");
366 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000367 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000368 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000369 }
370public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000371 NetBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
372 this->UserLabelPrefix = "";
373 }
Chris Lattnerb62bb282009-07-13 20:29:08 +0000374};
375
Torok Edwin5f6c1942009-06-30 17:10:35 +0000376// OpenBSD Target
377template<typename Target>
378class OpenBSDTargetInfo : public OSTargetInfo<Target> {
379protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000380 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000381 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000382 // OpenBSD defines; list based off of gcc output
383
Benjamin Kramera9992772010-01-09 17:55:51 +0000384 Builder.defineMacro("__OpenBSD__");
385 DefineStd(Builder, "unix", Opts);
386 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000387 if (Opts.POSIXThreads)
Chris Lattner4ddcf3b2012-04-25 06:12:24 +0000388 Builder.defineMacro("_REENTRANT");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000389 }
390public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000391 OpenBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
392 this->UserLabelPrefix = "";
393 this->TLSSupported = false;
Eli Friedman62d829a2011-12-15 02:15:56 +0000394
Eli Friedman62d829a2011-12-15 02:15:56 +0000395 switch (Triple.getArch()) {
396 default:
397 case llvm::Triple::x86:
398 case llvm::Triple::x86_64:
399 case llvm::Triple::arm:
Eric Christopher825d3862012-11-14 22:08:59 +0000400 case llvm::Triple::sparc:
Eli Friedman62d829a2011-12-15 02:15:56 +0000401 this->MCountName = "__mcount";
402 break;
403 case llvm::Triple::mips64:
404 case llvm::Triple::mips64el:
405 case llvm::Triple::ppc:
Eric Christopher825d3862012-11-14 22:08:59 +0000406 case llvm::Triple::sparcv9:
Eli Friedman62d829a2011-12-15 02:15:56 +0000407 this->MCountName = "_mcount";
408 break;
409 }
410 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000411};
412
Eli Friedman42f74f22012-08-08 23:57:20 +0000413// Bitrig Target
414template<typename Target>
415class BitrigTargetInfo : public OSTargetInfo<Target> {
416protected:
417 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
418 MacroBuilder &Builder) const {
419 // Bitrig defines; list based off of gcc output
420
421 Builder.defineMacro("__Bitrig__");
422 DefineStd(Builder, "unix", Opts);
423 Builder.defineMacro("__ELF__");
424 if (Opts.POSIXThreads)
425 Builder.defineMacro("_REENTRANT");
426 }
427public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000428 BitrigTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
429 this->UserLabelPrefix = "";
430 this->TLSSupported = false;
431 this->MCountName = "__mcount";
Eli Friedman42f74f22012-08-08 23:57:20 +0000432 }
433};
434
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000435// PSP Target
436template<typename Target>
437class PSPTargetInfo : public OSTargetInfo<Target> {
438protected:
439 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000440 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000441 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000442 Builder.defineMacro("PSP");
443 Builder.defineMacro("_PSP");
444 Builder.defineMacro("__psp__");
445 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000446 }
447public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000448 PSPTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000449 this->UserLabelPrefix = "";
450 }
451};
452
John Thompson3f6918a2009-11-19 17:18:50 +0000453// PS3 PPU Target
454template<typename Target>
455class PS3PPUTargetInfo : public OSTargetInfo<Target> {
456protected:
457 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000458 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000459 // PS3 PPU defines.
John Thompsonfb457972010-03-25 16:18:32 +0000460 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000461 Builder.defineMacro("__PPU__");
462 Builder.defineMacro("__CELLOS_LV2__");
463 Builder.defineMacro("__ELF__");
464 Builder.defineMacro("__LP32__");
John Thompson8e6065a2010-06-24 22:44:13 +0000465 Builder.defineMacro("_ARCH_PPC64");
466 Builder.defineMacro("__powerpc64__");
John Thompson3f6918a2009-11-19 17:18:50 +0000467 }
468public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000469 PS3PPUTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
John Thompson3f6918a2009-11-19 17:18:50 +0000470 this->UserLabelPrefix = "";
Nick Lewycky99520702011-12-16 22:32:39 +0000471 this->LongWidth = this->LongAlign = 32;
472 this->PointerWidth = this->PointerAlign = 32;
John Thompson8e6065a2010-06-24 22:44:13 +0000473 this->IntMaxType = TargetInfo::SignedLongLong;
474 this->UIntMaxType = TargetInfo::UnsignedLongLong;
475 this->Int64Type = TargetInfo::SignedLongLong;
John Thompsonec387af2009-12-18 14:21:08 +0000476 this->SizeType = TargetInfo::UnsignedInt;
John Thompson8e6065a2010-06-24 22:44:13 +0000477 this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Nick Lewycky99520702011-12-16 22:32:39 +0000478 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
John Thompson3f6918a2009-11-19 17:18:50 +0000479 }
480};
481
482// FIXME: Need a real SPU target.
483// PS3 SPU Target
484template<typename Target>
485class PS3SPUTargetInfo : public OSTargetInfo<Target> {
486protected:
487 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000488 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000489 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000490 Builder.defineMacro("__SPU__");
491 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000492 }
493public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000494 PS3SPUTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
John Thompson3f6918a2009-11-19 17:18:50 +0000495 this->UserLabelPrefix = "";
496 }
497};
498
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000499// AuroraUX target
500template<typename Target>
501class AuroraUXTargetInfo : public OSTargetInfo<Target> {
502protected:
503 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000504 MacroBuilder &Builder) const {
505 DefineStd(Builder, "sun", Opts);
506 DefineStd(Builder, "unix", Opts);
507 Builder.defineMacro("__ELF__");
508 Builder.defineMacro("__svr4__");
509 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000510 }
511public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000512 AuroraUXTargetInfo(const llvm::Triple &Triple)
513 : OSTargetInfo<Target>(Triple) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000514 this->UserLabelPrefix = "";
515 this->WCharType = this->SignedLong;
516 // FIXME: WIntType should be SignedLong
517 }
518};
519
Torok Edwin5f6c1942009-06-30 17:10:35 +0000520// Solaris target
521template<typename Target>
522class SolarisTargetInfo : public OSTargetInfo<Target> {
523protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000524 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000525 MacroBuilder &Builder) const {
526 DefineStd(Builder, "sun", Opts);
527 DefineStd(Builder, "unix", Opts);
528 Builder.defineMacro("__ELF__");
529 Builder.defineMacro("__svr4__");
530 Builder.defineMacro("__SVR4");
David Chisnall165329c2012-02-28 17:10:04 +0000531 // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
532 // newer, but to 500 for everything else. feature_test.h has a check to
533 // ensure that you are not using C99 with an old version of X/Open or C89
534 // with a new version.
535 if (Opts.C99 || Opts.C11)
536 Builder.defineMacro("_XOPEN_SOURCE", "600");
537 else
538 Builder.defineMacro("_XOPEN_SOURCE", "500");
David Chisnallb4f0bd62012-03-02 10:49:52 +0000539 if (Opts.CPlusPlus)
David Chisnall165329c2012-02-28 17:10:04 +0000540 Builder.defineMacro("__C99FEATURES__");
David Chisnall48fad492012-02-17 18:35:11 +0000541 Builder.defineMacro("_LARGEFILE_SOURCE");
542 Builder.defineMacro("_LARGEFILE64_SOURCE");
543 Builder.defineMacro("__EXTENSIONS__");
David Chisnall165329c2012-02-28 17:10:04 +0000544 Builder.defineMacro("_REENTRANT");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000545 }
546public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000547 SolarisTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000548 this->UserLabelPrefix = "";
David Chisnallfb027842012-03-28 18:04:14 +0000549 this->WCharType = this->SignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000550 // FIXME: WIntType should be SignedLong
551 }
552};
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000553
554// Windows target
555template<typename Target>
556class WindowsTargetInfo : public OSTargetInfo<Target> {
557protected:
558 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
559 MacroBuilder &Builder) const {
Michael J. Spencera764e832010-10-21 08:22:51 +0000560 Builder.defineMacro("_WIN32");
561 }
562 void getVisualStudioDefines(const LangOptions &Opts,
563 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000564 if (Opts.CPlusPlus) {
565 if (Opts.RTTI)
566 Builder.defineMacro("_CPPRTTI");
567
568 if (Opts.Exceptions)
569 Builder.defineMacro("_CPPUNWIND");
570 }
571
572 if (!Opts.CharIsSigned)
573 Builder.defineMacro("_CHAR_UNSIGNED");
574
575 // FIXME: POSIXThreads isn't exactly the option this should be defined for,
576 // but it works for now.
577 if (Opts.POSIXThreads)
578 Builder.defineMacro("_MT");
Michael J. Spencera764e832010-10-21 08:22:51 +0000579
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000580 if (Opts.MSCVersion != 0)
Chris Lattner5f9e2722011-07-23 10:55:15 +0000581 Builder.defineMacro("_MSC_VER", Twine(Opts.MSCVersion));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000582
Francois Pichet62ec1f22011-09-17 17:15:52 +0000583 if (Opts.MicrosoftExt) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000584 Builder.defineMacro("_MSC_EXTENSIONS");
585
Richard Smith80ad52f2013-01-02 11:42:31 +0000586 if (Opts.CPlusPlus11) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000587 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
588 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
589 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
590 }
591 }
592
593 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000594 }
595
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000596public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000597 WindowsTargetInfo(const llvm::Triple &Triple)
598 : OSTargetInfo<Target>(Triple) {}
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000599};
600
Derek Schuff7da46f92012-10-11 16:55:58 +0000601template <typename Target>
602class NaClTargetInfo : public OSTargetInfo<Target> {
Benjamin Kramer9df08232013-06-29 16:37:14 +0000603protected:
Derek Schuff7da46f92012-10-11 16:55:58 +0000604 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
605 MacroBuilder &Builder) const {
606 if (Opts.POSIXThreads)
607 Builder.defineMacro("_REENTRANT");
608 if (Opts.CPlusPlus)
609 Builder.defineMacro("_GNU_SOURCE");
610
611 DefineStd(Builder, "unix", Opts);
612 Builder.defineMacro("__ELF__");
613 Builder.defineMacro("__native_client__");
614 }
Benjamin Kramer9df08232013-06-29 16:37:14 +0000615
616public:
617 NaClTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
Derek Schuff7da46f92012-10-11 16:55:58 +0000618 this->UserLabelPrefix = "";
619 this->LongAlign = 32;
620 this->LongWidth = 32;
621 this->PointerAlign = 32;
622 this->PointerWidth = 32;
623 this->IntMaxType = TargetInfo::SignedLongLong;
624 this->UIntMaxType = TargetInfo::UnsignedLongLong;
625 this->Int64Type = TargetInfo::SignedLongLong;
626 this->DoubleAlign = 64;
627 this->LongDoubleWidth = 64;
628 this->LongDoubleAlign = 64;
629 this->SizeType = TargetInfo::UnsignedInt;
630 this->PtrDiffType = TargetInfo::SignedInt;
631 this->IntPtrType = TargetInfo::SignedInt;
Eli Benderskyc0783dc2013-04-08 21:31:01 +0000632 // RegParmMax is inherited from the underlying architecture
Derek Schuff7da46f92012-10-11 16:55:58 +0000633 this->LongDoubleFormat = &llvm::APFloat::IEEEdouble;
634 this->DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
635 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
636 }
Derek Schuff263366f2012-10-16 22:30:41 +0000637 virtual typename Target::CallingConvCheckResult checkCallingConvention(
638 CallingConv CC) const {
639 return CC == CC_PnaclCall ? Target::CCCR_OK :
640 Target::checkCallingConvention(CC);
641 }
Derek Schuff7da46f92012-10-11 16:55:58 +0000642};
Mike Stump1eb44332009-09-09 15:08:12 +0000643} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000644
Chris Lattnerd29b6302008-10-05 21:50:58 +0000645//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000646// Specific target implementations.
647//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000648
Eli Friedmane4277982008-08-20 23:11:40 +0000649namespace {
650// PPC abstract base class
651class PPCTargetInfo : public TargetInfo {
652 static const Builtin::Info BuiltinInfo[];
653 static const char * const GCCRegNames[];
654 static const TargetInfo::GCCRegAlias GCCRegAliases[];
Hal Finkel02a84272012-06-11 22:35:19 +0000655 std::string CPU;
Eli Friedmane4277982008-08-20 23:11:40 +0000656public:
Benjamin Kramer9df08232013-06-29 16:37:14 +0000657 PPCTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Bill Schmidtea7fb0c2013-07-26 01:36:11 +0000658 BigEndian = (Triple.getArch() != llvm::Triple::ppc64le);
Nico Weber6e1d2ea2012-01-31 02:07:33 +0000659 LongDoubleWidth = LongDoubleAlign = 128;
660 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble;
661 }
Eli Friedman15b91762009-06-05 07:05:05 +0000662
Hal Finkel39d5fa12012-07-03 16:51:04 +0000663 /// \brief Flags for architecture specific defines.
664 typedef enum {
665 ArchDefineNone = 0,
666 ArchDefineName = 1 << 0, // <name> is substituted for arch name.
667 ArchDefinePpcgr = 1 << 1,
668 ArchDefinePpcsq = 1 << 2,
669 ArchDefine440 = 1 << 3,
670 ArchDefine603 = 1 << 4,
671 ArchDefine604 = 1 << 5,
672 ArchDefinePwr4 = 1 << 6,
Bill Schmidt2821e182013-02-01 20:23:10 +0000673 ArchDefinePwr5 = 1 << 7,
674 ArchDefinePwr5x = 1 << 8,
675 ArchDefinePwr6 = 1 << 9,
676 ArchDefinePwr6x = 1 << 10,
677 ArchDefinePwr7 = 1 << 11,
678 ArchDefineA2 = 1 << 12,
679 ArchDefineA2q = 1 << 13
Hal Finkel39d5fa12012-07-03 16:51:04 +0000680 } ArchDefineTypes;
681
Bill Schmidt2821e182013-02-01 20:23:10 +0000682 // Note: GCC recognizes the following additional cpus:
683 // 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,
684 // 821, 823, 8540, 8548, e300c2, e300c3, e500mc64, e6500, 860, cell,
685 // titan, rs64.
Hal Finkel02a84272012-06-11 22:35:19 +0000686 virtual bool setCPU(const std::string &Name) {
687 bool CPUKnown = llvm::StringSwitch<bool>(Name)
688 .Case("generic", true)
689 .Case("440", true)
690 .Case("450", true)
691 .Case("601", true)
692 .Case("602", true)
693 .Case("603", true)
694 .Case("603e", true)
695 .Case("603ev", true)
696 .Case("604", true)
697 .Case("604e", true)
698 .Case("620", true)
Bill Schmidt2821e182013-02-01 20:23:10 +0000699 .Case("630", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000700 .Case("g3", true)
701 .Case("7400", true)
702 .Case("g4", true)
703 .Case("7450", true)
704 .Case("g4+", true)
705 .Case("750", true)
706 .Case("970", true)
707 .Case("g5", true)
708 .Case("a2", true)
Hal Finkel5ccd3d02013-02-01 05:53:33 +0000709 .Case("a2q", true)
Hal Finkel7de32962012-09-18 22:25:03 +0000710 .Case("e500mc", true)
711 .Case("e5500", true)
Bill Schmidt2821e182013-02-01 20:23:10 +0000712 .Case("power3", true)
713 .Case("pwr3", true)
714 .Case("power4", true)
715 .Case("pwr4", true)
716 .Case("power5", true)
717 .Case("pwr5", true)
718 .Case("power5x", true)
719 .Case("pwr5x", true)
720 .Case("power6", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000721 .Case("pwr6", true)
Bill Schmidt2821e182013-02-01 20:23:10 +0000722 .Case("power6x", true)
723 .Case("pwr6x", true)
724 .Case("power7", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000725 .Case("pwr7", true)
Bill Schmidt2821e182013-02-01 20:23:10 +0000726 .Case("powerpc", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000727 .Case("ppc", true)
Bill Schmidt2821e182013-02-01 20:23:10 +0000728 .Case("powerpc64", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000729 .Case("ppc64", true)
Bill Schmidtea7fb0c2013-07-26 01:36:11 +0000730 .Case("powerpc64le", true)
731 .Case("ppc64le", true)
Hal Finkel02a84272012-06-11 22:35:19 +0000732 .Default(false);
733
734 if (CPUKnown)
735 CPU = Name;
736
737 return CPUKnown;
738 }
739
Eli Friedmane4277982008-08-20 23:11:40 +0000740 virtual void getTargetBuiltins(const Builtin::Info *&Records,
741 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000742 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000743 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000744 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000745
Bob Wilson9f1c49c2012-01-28 18:02:29 +0000746 virtual bool isCLZForZeroUndef() const { return false; }
747
Chris Lattner33328642009-03-20 15:52:06 +0000748 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000749 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000750
Bill Schmidt199402b2013-02-01 02:14:03 +0000751 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const;
752
Douglas Gregore727d212012-01-30 06:38:25 +0000753 virtual bool hasFeature(StringRef Feature) const;
754
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000755 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000756 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000757 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000758 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000759 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000760 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000761 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000762 default: return false;
763 case 'O': // Zero
John Thompson8e6065a2010-06-24 22:44:13 +0000764 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000765 case 'b': // Base register
766 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000767 Info.setAllowsRegister();
John Thompson8e6065a2010-06-24 22:44:13 +0000768 break;
769 // FIXME: The following are added to allow parsing.
770 // I just took a guess at what the actions should be.
771 // Also, is more specific checking needed? I.e. specific registers?
Michael J. Spencer20249a12010-10-21 03:16:25 +0000772 case 'd': // Floating point register (containing 64-bit value)
John Thompson8e6065a2010-06-24 22:44:13 +0000773 case 'v': // Altivec vector register
774 Info.setAllowsRegister();
775 break;
776 case 'w':
777 switch (Name[1]) {
Michael J. Spencer20249a12010-10-21 03:16:25 +0000778 case 'd':// VSX vector register to hold vector double data
779 case 'f':// VSX vector register to hold vector float data
780 case 's':// VSX vector register to hold scalar float data
781 case 'a':// Any VSX register
John Thompson8e6065a2010-06-24 22:44:13 +0000782 break;
783 default:
784 return false;
785 }
786 Info.setAllowsRegister();
787 Name++; // Skip over 'w'.
788 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000789 case 'h': // `MQ', `CTR', or `LINK' register
790 case 'q': // `MQ' register
791 case 'c': // `CTR' register
792 case 'l': // `LINK' register
793 case 'x': // `CR' register (condition register) number 0
794 case 'y': // `CR' register (condition register)
795 case 'z': // `XER[CA]' carry bit (part of the XER register)
John Thompson8e6065a2010-06-24 22:44:13 +0000796 Info.setAllowsRegister();
797 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000798 case 'I': // Signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000799 case 'J': // Unsigned 16-bit constant shifted left 16 bits
Michael J. Spencer20249a12010-10-21 03:16:25 +0000800 // (use `L' instead for SImode constants)
801 case 'K': // Unsigned 16-bit constant
802 case 'L': // Signed 16-bit constant shifted left 16 bits
803 case 'M': // Constant larger than 31
804 case 'N': // Exact power of 2
805 case 'P': // Constant whose negation is a signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000806 case 'G': // Floating point constant that can be loaded into a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000807 // register with one instruction per word
John Thompson8e6065a2010-06-24 22:44:13 +0000808 case 'H': // Integer/Floating point constant that can be loaded
Michael J. Spencer20249a12010-10-21 03:16:25 +0000809 // into a register using three instructions
John Thompson8e6065a2010-06-24 22:44:13 +0000810 break;
811 case 'm': // Memory operand. Note that on PowerPC targets, m can
812 // include addresses that update the base register. It
813 // is therefore only safe to use `m' in an asm statement
814 // if that asm statement accesses the operand exactly once.
815 // The asm statement must also use `%U<opno>' as a
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000816 // placeholder for the "update" flag in the corresponding
Michael J. Spencer20249a12010-10-21 03:16:25 +0000817 // load or store instruction. For example:
John Thompson8e6065a2010-06-24 22:44:13 +0000818 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
Michael J. Spencer20249a12010-10-21 03:16:25 +0000819 // is correct but:
John Thompson8e6065a2010-06-24 22:44:13 +0000820 // asm ("st %1,%0" : "=m" (mem) : "r" (val));
821 // is not. Use es rather than m if you don't want the base
Michael J. Spencer20249a12010-10-21 03:16:25 +0000822 // register to be updated.
823 case 'e':
John Thompson56b6eca2010-06-25 00:02:05 +0000824 if (Name[1] != 's')
825 return false;
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000826 // es: A "stable" memory operand; that is, one which does not
John Thompson8e6065a2010-06-24 22:44:13 +0000827 // include any automodification of the base register. Unlike
828 // `m', this constraint can be used in asm statements that
829 // might access the operand several times, or that might not
John Thompson56b6eca2010-06-25 00:02:05 +0000830 // access it at all.
John Thompson8e6065a2010-06-24 22:44:13 +0000831 Info.setAllowsMemory();
John Thompson56b6eca2010-06-25 00:02:05 +0000832 Name++; // Skip over 'e'.
John Thompson8e6065a2010-06-24 22:44:13 +0000833 break;
834 case 'Q': // Memory operand that is an offset from a register (it is
Michael J. Spencer20249a12010-10-21 03:16:25 +0000835 // usually better to use `m' or `es' in asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000836 case 'Z': // Memory operand that is an indexed or indirect from a
837 // register (it is usually better to use `m' or `es' in
Michael J. Spencer20249a12010-10-21 03:16:25 +0000838 // asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000839 Info.setAllowsMemory();
840 Info.setAllowsRegister();
841 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000842 case 'R': // AIX TOC entry
John Thompson8e6065a2010-06-24 22:44:13 +0000843 case 'a': // Address operand that is an indexed or indirect from a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000844 // register (`p' is preferable for asm statements)
845 case 'S': // Constant suitable as a 64-bit mask operand
846 case 'T': // Constant suitable as a 32-bit mask operand
847 case 'U': // System V Release 4 small data area reference
John Thompson8e6065a2010-06-24 22:44:13 +0000848 case 't': // AND masks that can be performed by two rldic{l, r}
Michael J. Spencer20249a12010-10-21 03:16:25 +0000849 // instructions
850 case 'W': // Vector constant that does not require memory
851 case 'j': // Vector constant that is all zeros.
John Thompson8e6065a2010-06-24 22:44:13 +0000852 break;
853 // End FIXME.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000854 }
John Thompson8e6065a2010-06-24 22:44:13 +0000855 return true;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000856 }
Eli Friedmane4277982008-08-20 23:11:40 +0000857 virtual const char *getClobbers() const {
858 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000859 }
Adhemerval Zanellab0fc94c2013-01-22 20:02:45 +0000860 int getEHDataRegisterNumber(unsigned RegNo) const {
861 if (RegNo == 0) return 3;
862 if (RegNo == 1) return 4;
863 return -1;
864 }
Eli Friedmane4277982008-08-20 23:11:40 +0000865};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000866
Eli Friedmane4277982008-08-20 23:11:40 +0000867const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +0000868#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000869#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +0000870 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000871#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000872};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000873
874
Chris Lattnerc0f59212009-03-02 22:27:17 +0000875/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
876/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000877void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000878 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000879 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000880 Builder.defineMacro("__ppc__");
Chandler Carruthc6fa1152013-06-25 11:13:47 +0000881 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000882 Builder.defineMacro("_ARCH_PPC");
Chris Lattnere03ae302010-02-16 18:14:57 +0000883 Builder.defineMacro("__powerpc__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000884 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000885 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000886 Builder.defineMacro("_ARCH_PPC64");
Chris Lattnere03ae302010-02-16 18:14:57 +0000887 Builder.defineMacro("__powerpc64__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000888 Builder.defineMacro("__ppc64__");
Chandler Carruthc6fa1152013-06-25 11:13:47 +0000889 Builder.defineMacro("__PPC64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000890 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000891
Chris Lattnerc0f59212009-03-02 22:27:17 +0000892 // Target properties.
Bill Schmidtea7fb0c2013-07-26 01:36:11 +0000893 if (getTriple().getArch() == llvm::Triple::ppc64le) {
894 Builder.defineMacro("_LITTLE_ENDIAN");
895 Builder.defineMacro("__LITTLE_ENDIAN__");
896 } else {
897 if (getTriple().getOS() != llvm::Triple::NetBSD &&
898 getTriple().getOS() != llvm::Triple::OpenBSD)
899 Builder.defineMacro("_BIG_ENDIAN");
900 Builder.defineMacro("__BIG_ENDIAN__");
901 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000902
Chris Lattnerc0f59212009-03-02 22:27:17 +0000903 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000904 Builder.defineMacro("__NATURAL_ALIGNMENT__");
905 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000906
Chris Lattnerc0f59212009-03-02 22:27:17 +0000907 // FIXME: Should be controlled by command line option.
Roman Divackyb2f6f472013-07-03 19:45:54 +0000908 if (LongDoubleWidth == 128)
909 Builder.defineMacro("__LONG_DOUBLE_128__");
Michael J. Spencer20249a12010-10-21 03:16:25 +0000910
John Thompson3f6918a2009-11-19 17:18:50 +0000911 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000912 Builder.defineMacro("__VEC__", "10206");
913 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000914 }
Hal Finkel02a84272012-06-11 22:35:19 +0000915
916 // CPU identification.
Hal Finkel39d5fa12012-07-03 16:51:04 +0000917 ArchDefineTypes defs = (ArchDefineTypes)llvm::StringSwitch<int>(CPU)
918 .Case("440", ArchDefineName)
919 .Case("450", ArchDefineName | ArchDefine440)
920 .Case("601", ArchDefineName)
921 .Case("602", ArchDefineName | ArchDefinePpcgr)
922 .Case("603", ArchDefineName | ArchDefinePpcgr)
923 .Case("603e", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
924 .Case("603ev", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
925 .Case("604", ArchDefineName | ArchDefinePpcgr)
926 .Case("604e", ArchDefineName | ArchDefine604 | ArchDefinePpcgr)
927 .Case("620", ArchDefineName | ArchDefinePpcgr)
Bill Schmidt2821e182013-02-01 20:23:10 +0000928 .Case("630", ArchDefineName | ArchDefinePpcgr)
Hal Finkel39d5fa12012-07-03 16:51:04 +0000929 .Case("7400", ArchDefineName | ArchDefinePpcgr)
930 .Case("7450", ArchDefineName | ArchDefinePpcgr)
931 .Case("750", ArchDefineName | ArchDefinePpcgr)
932 .Case("970", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr
933 | ArchDefinePpcsq)
Hal Finkel5ccd3d02013-02-01 05:53:33 +0000934 .Case("a2", ArchDefineA2)
935 .Case("a2q", ArchDefineName | ArchDefineA2 | ArchDefineA2q)
Bill Schmidt2821e182013-02-01 20:23:10 +0000936 .Case("pwr3", ArchDefinePpcgr)
937 .Case("pwr4", ArchDefineName | ArchDefinePpcgr | ArchDefinePpcsq)
938 .Case("pwr5", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr
939 | ArchDefinePpcsq)
940 .Case("pwr5x", ArchDefineName | ArchDefinePwr5 | ArchDefinePwr4
941 | ArchDefinePpcgr | ArchDefinePpcsq)
942 .Case("pwr6", ArchDefineName | ArchDefinePwr5x | ArchDefinePwr5
943 | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
944 .Case("pwr6x", ArchDefineName | ArchDefinePwr6 | ArchDefinePwr5x
945 | ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
946 | ArchDefinePpcsq)
947 .Case("pwr7", ArchDefineName | ArchDefinePwr6x | ArchDefinePwr6
948 | ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
949 | ArchDefinePwr6 | ArchDefinePpcgr | ArchDefinePpcsq)
950 .Case("power3", ArchDefinePpcgr)
951 .Case("power4", ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
952 .Case("power5", ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
953 | ArchDefinePpcsq)
954 .Case("power5x", ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
955 | ArchDefinePpcgr | ArchDefinePpcsq)
956 .Case("power6", ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5
957 | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
958 .Case("power6x", ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x
959 | ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
960 | ArchDefinePpcsq)
961 .Case("power7", ArchDefinePwr7 | ArchDefinePwr6x | ArchDefinePwr6
962 | ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
963 | ArchDefinePwr6 | ArchDefinePpcgr | ArchDefinePpcsq)
Hal Finkel39d5fa12012-07-03 16:51:04 +0000964 .Default(ArchDefineNone);
965
966 if (defs & ArchDefineName)
967 Builder.defineMacro(Twine("_ARCH_", StringRef(CPU).upper()));
968 if (defs & ArchDefinePpcgr)
969 Builder.defineMacro("_ARCH_PPCGR");
970 if (defs & ArchDefinePpcsq)
971 Builder.defineMacro("_ARCH_PPCSQ");
972 if (defs & ArchDefine440)
Hal Finkel02a84272012-06-11 22:35:19 +0000973 Builder.defineMacro("_ARCH_440");
Hal Finkel39d5fa12012-07-03 16:51:04 +0000974 if (defs & ArchDefine603)
975 Builder.defineMacro("_ARCH_603");
976 if (defs & ArchDefine604)
977 Builder.defineMacro("_ARCH_604");
Bill Schmidt2821e182013-02-01 20:23:10 +0000978 if (defs & ArchDefinePwr4)
Hal Finkel39d5fa12012-07-03 16:51:04 +0000979 Builder.defineMacro("_ARCH_PWR4");
Bill Schmidt2821e182013-02-01 20:23:10 +0000980 if (defs & ArchDefinePwr5)
Hal Finkel39d5fa12012-07-03 16:51:04 +0000981 Builder.defineMacro("_ARCH_PWR5");
Bill Schmidt2821e182013-02-01 20:23:10 +0000982 if (defs & ArchDefinePwr5x)
983 Builder.defineMacro("_ARCH_PWR5X");
984 if (defs & ArchDefinePwr6)
Hal Finkel02a84272012-06-11 22:35:19 +0000985 Builder.defineMacro("_ARCH_PWR6");
Bill Schmidt2821e182013-02-01 20:23:10 +0000986 if (defs & ArchDefinePwr6x)
987 Builder.defineMacro("_ARCH_PWR6X");
988 if (defs & ArchDefinePwr7)
989 Builder.defineMacro("_ARCH_PWR7");
Hal Finkel5ccd3d02013-02-01 05:53:33 +0000990 if (defs & ArchDefineA2)
991 Builder.defineMacro("_ARCH_A2");
992 if (defs & ArchDefineA2q) {
993 Builder.defineMacro("_ARCH_A2Q");
994 Builder.defineMacro("_ARCH_QP");
995 }
996
997 if (getTriple().getVendor() == llvm::Triple::BGQ) {
998 Builder.defineMacro("__bg__");
999 Builder.defineMacro("__THW_BLUEGENE__");
1000 Builder.defineMacro("__bgq__");
1001 Builder.defineMacro("__TOS_BGQ__");
1002 }
Bill Schmidt2821e182013-02-01 20:23:10 +00001003
1004 // FIXME: The following are not yet generated here by Clang, but are
1005 // generated by GCC:
1006 //
1007 // _SOFT_FLOAT_
1008 // __RECIP_PRECISION__
1009 // __APPLE_ALTIVEC__
1010 // __VSX__
1011 // __RECIP__
1012 // __RECIPF__
1013 // __RSQRTE__
1014 // __RSQRTEF__
1015 // _SOFT_DOUBLE_
1016 // __NO_LWSYNC__
1017 // __HAVE_BSWAP__
1018 // __LONGDOUBLE128
1019 // __CMODEL_MEDIUM__
1020 // __CMODEL_LARGE__
1021 // _CALL_SYSV
1022 // _CALL_DARWIN
1023 // __NO_FPRS__
Bill Schmidt199402b2013-02-01 02:14:03 +00001024}
1025
1026void PPCTargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
1027 Features["altivec"] = llvm::StringSwitch<bool>(CPU)
1028 .Case("7400", true)
1029 .Case("g4", true)
1030 .Case("7450", true)
1031 .Case("g4+", true)
1032 .Case("970", true)
1033 .Case("g5", true)
1034 .Case("pwr6", true)
1035 .Case("pwr7", true)
1036 .Case("ppc64", true)
Bill Schmidtea7fb0c2013-07-26 01:36:11 +00001037 .Case("ppc64le", true)
Bill Schmidt199402b2013-02-01 02:14:03 +00001038 .Default(false);
Hal Finkel3c6aaeb2013-02-01 18:44:19 +00001039
1040 Features["qpx"] = (CPU == "a2q");
Bill Schmidt199402b2013-02-01 02:14:03 +00001041}
1042
Douglas Gregore727d212012-01-30 06:38:25 +00001043bool PPCTargetInfo::hasFeature(StringRef Feature) const {
1044 return Feature == "powerpc";
1045}
Chris Lattner393ff042008-04-21 18:56:49 +00001046
Douglas Gregore727d212012-01-30 06:38:25 +00001047
Eli Friedmane4277982008-08-20 23:11:40 +00001048const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +00001049 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1050 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1051 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1052 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
1053 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
1054 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
1055 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
1056 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +00001057 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +00001058 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +00001059 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +00001060 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
1061 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
1062 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
1063 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +00001064 "vrsave", "vscr",
1065 "spe_acc", "spefscr",
1066 "sfp"
1067};
Reid Spencer5f016e22007-07-11 17:01:13 +00001068
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001069void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +00001070 unsigned &NumNames) const {
1071 Names = GCCRegNames;
1072 NumNames = llvm::array_lengthof(GCCRegNames);
1073}
Reid Spencer5f016e22007-07-11 17:01:13 +00001074
Eli Friedmane4277982008-08-20 23:11:40 +00001075const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
1076 // While some of these aliases do map to different registers
1077 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001078 { { "0" }, "r0" },
1079 { { "1"}, "r1" },
1080 { { "2" }, "r2" },
1081 { { "3" }, "r3" },
1082 { { "4" }, "r4" },
1083 { { "5" }, "r5" },
1084 { { "6" }, "r6" },
1085 { { "7" }, "r7" },
1086 { { "8" }, "r8" },
1087 { { "9" }, "r9" },
1088 { { "10" }, "r10" },
1089 { { "11" }, "r11" },
1090 { { "12" }, "r12" },
1091 { { "13" }, "r13" },
1092 { { "14" }, "r14" },
1093 { { "15" }, "r15" },
1094 { { "16" }, "r16" },
1095 { { "17" }, "r17" },
1096 { { "18" }, "r18" },
1097 { { "19" }, "r19" },
1098 { { "20" }, "r20" },
1099 { { "21" }, "r21" },
1100 { { "22" }, "r22" },
1101 { { "23" }, "r23" },
1102 { { "24" }, "r24" },
1103 { { "25" }, "r25" },
1104 { { "26" }, "r26" },
1105 { { "27" }, "r27" },
1106 { { "28" }, "r28" },
1107 { { "29" }, "r29" },
1108 { { "30" }, "r30" },
1109 { { "31" }, "r31" },
1110 { { "fr0" }, "f0" },
1111 { { "fr1" }, "f1" },
1112 { { "fr2" }, "f2" },
1113 { { "fr3" }, "f3" },
1114 { { "fr4" }, "f4" },
1115 { { "fr5" }, "f5" },
1116 { { "fr6" }, "f6" },
1117 { { "fr7" }, "f7" },
1118 { { "fr8" }, "f8" },
1119 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +00001120 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001121 { { "fr11" }, "f11" },
1122 { { "fr12" }, "f12" },
1123 { { "fr13" }, "f13" },
1124 { { "fr14" }, "f14" },
1125 { { "fr15" }, "f15" },
1126 { { "fr16" }, "f16" },
1127 { { "fr17" }, "f17" },
1128 { { "fr18" }, "f18" },
1129 { { "fr19" }, "f19" },
1130 { { "fr20" }, "f20" },
1131 { { "fr21" }, "f21" },
1132 { { "fr22" }, "f22" },
1133 { { "fr23" }, "f23" },
1134 { { "fr24" }, "f24" },
1135 { { "fr25" }, "f25" },
1136 { { "fr26" }, "f26" },
1137 { { "fr27" }, "f27" },
1138 { { "fr28" }, "f28" },
1139 { { "fr29" }, "f29" },
1140 { { "fr30" }, "f30" },
1141 { { "fr31" }, "f31" },
1142 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +00001143};
1144
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001145void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +00001146 unsigned &NumAliases) const {
1147 Aliases = GCCRegAliases;
1148 NumAliases = llvm::array_lengthof(GCCRegAliases);
1149}
1150} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00001151
1152namespace {
Eli Friedmane4277982008-08-20 23:11:40 +00001153class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001154public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001155 PPC32TargetInfo(const llvm::Triple &Triple) : PPCTargetInfo(Triple) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001156 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001157 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Chris Lattnere03ae302010-02-16 18:14:57 +00001158
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +00001159 switch (getTriple().getOS()) {
Nico Weber6e1d2ea2012-01-31 02:07:33 +00001160 case llvm::Triple::Linux:
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +00001161 case llvm::Triple::FreeBSD:
1162 case llvm::Triple::NetBSD:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +00001163 SizeType = UnsignedInt;
Hal Finkel178a9b82012-03-02 20:54:36 +00001164 PtrDiffType = SignedInt;
1165 IntPtrType = SignedInt;
Joerg Sonnenberger78542df2011-07-05 14:54:41 +00001166 break;
Joerg Sonnenberger1a83b432011-07-04 23:11:58 +00001167 default:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +00001168 break;
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +00001169 }
Roman Divackye3d175d2012-03-13 16:53:54 +00001170
Roman Divackyefe9c0d2012-03-13 19:20:17 +00001171 if (getTriple().getOS() == llvm::Triple::FreeBSD) {
1172 LongDoubleWidth = LongDoubleAlign = 64;
Roman Divackye3d175d2012-03-13 16:53:54 +00001173 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Roman Divackyefe9c0d2012-03-13 19:20:17 +00001174 }
Benjamin Kramer7baa7112012-11-17 17:30:55 +00001175
1176 // PPC32 supports atomics up to 4 bytes.
1177 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
Roman Divackyc81f2a22011-01-06 08:27:10 +00001178 }
1179
Meador Ingec5613b22012-06-16 03:34:49 +00001180 virtual BuiltinVaListKind getBuiltinVaListKind() const {
Roman Divackyc81f2a22011-01-06 08:27:10 +00001181 // This is the ELF definition, and is overridden by the Darwin sub-target
Meador Ingec5613b22012-06-16 03:34:49 +00001182 return TargetInfo::PowerABIBuiltinVaList;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001183 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001184};
1185} // end anonymous namespace.
1186
Bill Schmidtea7fb0c2013-07-26 01:36:11 +00001187// Note: ABI differences may eventually require us to have a separate
1188// TargetInfo for little endian.
Reid Spencer5f016e22007-07-11 17:01:13 +00001189namespace {
Eli Friedmane4277982008-08-20 23:11:40 +00001190class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001191public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001192 PPC64TargetInfo(const llvm::Triple &Triple) : PPCTargetInfo(Triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001193 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001194 IntMaxType = SignedLong;
1195 UIntMaxType = UnsignedLong;
1196 Int64Type = SignedLong;
Roman Divackye3d175d2012-03-13 16:53:54 +00001197
Roman Divackyefe9c0d2012-03-13 19:20:17 +00001198 if (getTriple().getOS() == llvm::Triple::FreeBSD) {
1199 LongDoubleWidth = LongDoubleAlign = 64;
Roman Divackye3d175d2012-03-13 16:53:54 +00001200 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Bill Schmidtdbaf4bc2012-10-29 14:59:24 +00001201 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Bill Schmidtb1baad62013-07-03 21:03:06 +00001202 "i64:64:64-f32:32:32-f64:64:64-"
Bill Schmidtdbaf4bc2012-10-29 14:59:24 +00001203 "v128:128:128-n32:64";
1204 } else
1205 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1206 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
1207 "v128:128:128-n32:64";
Benjamin Kramer7baa7112012-11-17 17:30:55 +00001208
1209 // PPC64 supports atomics up to 8 bytes.
1210 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Chris Lattnerf291b102008-05-09 06:17:04 +00001211 }
Meador Ingec5613b22012-06-16 03:34:49 +00001212 virtual BuiltinVaListKind getBuiltinVaListKind() const {
1213 return TargetInfo::CharPtrBuiltinVaList;
Roman Divackyc81f2a22011-01-06 08:27:10 +00001214 }
Eli Friedmane4277982008-08-20 23:11:40 +00001215};
1216} // end anonymous namespace.
1217
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001218
1219namespace {
Roman Divackyc81f2a22011-01-06 08:27:10 +00001220class DarwinPPC32TargetInfo :
1221 public DarwinTargetInfo<PPC32TargetInfo> {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001222public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001223 DarwinPPC32TargetInfo(const llvm::Triple &Triple)
1224 : DarwinTargetInfo<PPC32TargetInfo>(Triple) {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001225 HasAlignMac68kSupport = true;
Roman Divackyc81f2a22011-01-06 08:27:10 +00001226 BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool?
David Fangb5afadd2013-05-16 17:51:48 +00001227 PtrDiffType = SignedInt; // for http://llvm.org/bugs/show_bug.cgi?id=15726
Anton Yartsev9bc23ba2012-01-17 22:40:00 +00001228 LongLongAlign = 32;
Nick Lewycky9bddf432011-12-21 04:25:47 +00001229 SuitableAlign = 128;
Anton Yartsev9bc23ba2012-01-17 22:40:00 +00001230 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1231 "i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32";
Roman Divackyc81f2a22011-01-06 08:27:10 +00001232 }
Meador Ingec5613b22012-06-16 03:34:49 +00001233 virtual BuiltinVaListKind getBuiltinVaListKind() const {
1234 return TargetInfo::CharPtrBuiltinVaList;
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001235 }
1236};
1237
1238class DarwinPPC64TargetInfo :
1239 public DarwinTargetInfo<PPC64TargetInfo> {
1240public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001241 DarwinPPC64TargetInfo(const llvm::Triple &Triple)
1242 : DarwinTargetInfo<PPC64TargetInfo>(Triple) {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001243 HasAlignMac68kSupport = true;
Nick Lewycky9bddf432011-12-21 04:25:47 +00001244 SuitableAlign = 128;
Bill Schmidtdbaf4bc2012-10-29 14:59:24 +00001245 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1246 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00001247 }
1248};
1249} // end anonymous namespace.
1250
Reid Spencer5f016e22007-07-11 17:01:13 +00001251namespace {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001252 static const unsigned NVPTXAddrSpaceMap[] = {
1253 1, // opencl_global
1254 3, // opencl_local
1255 4, // opencl_constant
1256 1, // cuda_device
1257 4, // cuda_constant
1258 3, // cuda_shared
1259 };
1260 class NVPTXTargetInfo : public TargetInfo {
1261 static const char * const GCCRegNames[];
Justin Holewinski2c585b92012-05-24 17:43:12 +00001262 static const Builtin::Info BuiltinInfo[];
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001263 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001264 NVPTXTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001265 BigEndian = false;
1266 TLSSupported = false;
1267 LongWidth = LongAlign = 64;
1268 AddrSpaceMap = &NVPTXAddrSpaceMap;
David Tweed1eef8522013-09-13 12:04:22 +00001269 UseAddrSpaceMapMangling = true;
Justin Holewinski2c585b92012-05-24 17:43:12 +00001270 // Define available target features
1271 // These must be defined in sorted order!
Justin Holewinski9903e942012-07-11 15:34:55 +00001272 NoAsmVariants = true;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001273 }
1274 virtual void getTargetDefines(const LangOptions &Opts,
1275 MacroBuilder &Builder) const {
1276 Builder.defineMacro("__PTX__");
Justin Holewinski2c585b92012-05-24 17:43:12 +00001277 Builder.defineMacro("__NVPTX__");
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001278 }
1279 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1280 unsigned &NumRecords) const {
Justin Holewinski2c585b92012-05-24 17:43:12 +00001281 Records = BuiltinInfo;
1282 NumRecords = clang::NVPTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001283 }
1284 virtual bool hasFeature(StringRef Feature) const {
Justin Holewinski2c585b92012-05-24 17:43:12 +00001285 return Feature == "ptx" || Feature == "nvptx";
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001286 }
1287
1288 virtual void getGCCRegNames(const char * const *&Names,
1289 unsigned &NumNames) const;
1290 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1291 unsigned &NumAliases) const {
1292 // No aliases.
1293 Aliases = 0;
1294 NumAliases = 0;
1295 }
1296 virtual bool validateAsmConstraint(const char *&Name,
Justin Holewinski0ac428e2013-06-21 18:51:24 +00001297 TargetInfo::ConstraintInfo &Info) const {
1298 switch (*Name) {
1299 default: return false;
1300 case 'c':
1301 case 'h':
1302 case 'r':
1303 case 'l':
1304 case 'f':
1305 case 'd':
1306 Info.setAllowsRegister();
1307 return true;
1308 }
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001309 }
1310 virtual const char *getClobbers() const {
1311 // FIXME: Is this really right?
1312 return "";
1313 }
Meador Ingec5613b22012-06-16 03:34:49 +00001314 virtual BuiltinVaListKind getBuiltinVaListKind() const {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001315 // FIXME: implement
Meador Ingec5613b22012-06-16 03:34:49 +00001316 return TargetInfo::CharPtrBuiltinVaList;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001317 }
1318 virtual bool setCPU(const std::string &Name) {
Justin Holewinskiaffa3af2013-03-30 14:38:26 +00001319 bool Valid = llvm::StringSwitch<bool>(Name)
1320 .Case("sm_20", true)
1321 .Case("sm_21", true)
1322 .Case("sm_30", true)
1323 .Case("sm_35", true)
1324 .Default(false);
1325
1326 return Valid;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001327 }
Justin Holewinski2c585b92012-05-24 17:43:12 +00001328 };
1329
1330 const Builtin::Info NVPTXTargetInfo::BuiltinInfo[] = {
1331#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
1332#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
1333 ALL_LANGUAGES },
1334#include "clang/Basic/BuiltinsNVPTX.def"
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001335 };
1336
1337 const char * const NVPTXTargetInfo::GCCRegNames[] = {
1338 "r0"
1339 };
1340
1341 void NVPTXTargetInfo::getGCCRegNames(const char * const *&Names,
1342 unsigned &NumNames) const {
1343 Names = GCCRegNames;
1344 NumNames = llvm::array_lengthof(GCCRegNames);
1345 }
1346
1347 class NVPTX32TargetInfo : public NVPTXTargetInfo {
1348 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001349 NVPTX32TargetInfo(const llvm::Triple &Triple) : NVPTXTargetInfo(Triple) {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001350 PointerWidth = PointerAlign = 32;
Justin Holewinski2c585b92012-05-24 17:43:12 +00001351 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001352 DescriptionString
1353 = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
1354 "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-"
1355 "n16:32:64";
Justin Holewinski2c585b92012-05-24 17:43:12 +00001356 }
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001357 };
1358
1359 class NVPTX64TargetInfo : public NVPTXTargetInfo {
1360 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001361 NVPTX64TargetInfo(const llvm::Triple &Triple) : NVPTXTargetInfo(Triple) {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001362 PointerWidth = PointerAlign = 64;
Justin Holewinski2c585b92012-05-24 17:43:12 +00001363 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001364 DescriptionString
1365 = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
1366 "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-"
1367 "n16:32:64";
Justin Holewinski2c585b92012-05-24 17:43:12 +00001368 }
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001369 };
1370}
1371
1372namespace {
Eli Friedman6505a292012-10-12 23:32:00 +00001373
1374static const unsigned R600AddrSpaceMap[] = {
1375 1, // opencl_global
1376 3, // opencl_local
1377 2, // opencl_constant
1378 1, // cuda_device
1379 2, // cuda_constant
1380 3 // cuda_shared
1381};
1382
Tom Stellardfd075912013-03-04 17:40:53 +00001383static const char *DescriptionStringR600 =
1384 "e"
1385 "-p:32:32:32"
1386 "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32"
1387 "-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128"
1388 "-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-v2048:2048:2048"
1389 "-n32:64";
1390
1391static const char *DescriptionStringR600DoubleOps =
1392 "e"
1393 "-p:32:32:32"
1394 "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64"
1395 "-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128"
1396 "-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-v2048:2048:2048"
1397 "-n32:64";
1398
1399static const char *DescriptionStringSI =
1400 "e"
1401 "-p:64:64:64"
Tom Stellard9a3d2bd2013-08-27 00:55:26 +00001402 "-p3:32:32:32"
Tom Stellardfd075912013-03-04 17:40:53 +00001403 "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64"
1404 "-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128"
1405 "-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-v2048:2048:2048"
1406 "-n32:64";
1407
Eli Friedman6505a292012-10-12 23:32:00 +00001408class R600TargetInfo : public TargetInfo {
Tom Stellardfd075912013-03-04 17:40:53 +00001409 /// \brief The GPU profiles supported by the R600 target.
1410 enum GPUKind {
1411 GK_NONE,
1412 GK_R600,
1413 GK_R600_DOUBLE_OPS,
1414 GK_R700,
1415 GK_R700_DOUBLE_OPS,
1416 GK_EVERGREEN,
1417 GK_EVERGREEN_DOUBLE_OPS,
1418 GK_NORTHERN_ISLANDS,
1419 GK_CAYMAN,
1420 GK_SOUTHERN_ISLANDS
1421 } GPU;
1422
Eli Friedman6505a292012-10-12 23:32:00 +00001423public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001424 R600TargetInfo(const llvm::Triple &Triple)
1425 : TargetInfo(Triple), GPU(GK_R600) {
Tom Stellardfd075912013-03-04 17:40:53 +00001426 DescriptionString = DescriptionStringR600;
Eli Friedman6505a292012-10-12 23:32:00 +00001427 AddrSpaceMap = &R600AddrSpaceMap;
David Tweed1eef8522013-09-13 12:04:22 +00001428 UseAddrSpaceMapMangling = true;
Eli Friedman6505a292012-10-12 23:32:00 +00001429 }
1430
1431 virtual const char * getClobbers() const {
1432 return "";
1433 }
1434
1435 virtual void getGCCRegNames(const char * const *&Names,
1436 unsigned &numNames) const {
1437 Names = NULL;
1438 numNames = 0;
1439 }
1440
1441 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1442 unsigned &NumAliases) const {
1443 Aliases = NULL;
1444 NumAliases = 0;
1445 }
1446
1447 virtual bool validateAsmConstraint(const char *&Name,
1448 TargetInfo::ConstraintInfo &info) const {
1449 return true;
1450 }
1451
1452 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1453 unsigned &NumRecords) const {
1454 Records = NULL;
1455 NumRecords = 0;
1456 }
1457
1458
1459 virtual void getTargetDefines(const LangOptions &Opts,
1460 MacroBuilder &Builder) const {
1461 Builder.defineMacro("__R600__");
1462 }
1463
1464 virtual BuiltinVaListKind getBuiltinVaListKind() const {
1465 return TargetInfo::CharPtrBuiltinVaList;
1466 }
1467
Tom Stellardfd075912013-03-04 17:40:53 +00001468 virtual bool setCPU(const std::string &Name) {
1469 GPU = llvm::StringSwitch<GPUKind>(Name)
1470 .Case("r600" , GK_R600)
1471 .Case("rv610", GK_R600)
1472 .Case("rv620", GK_R600)
1473 .Case("rv630", GK_R600)
1474 .Case("rv635", GK_R600)
1475 .Case("rs780", GK_R600)
1476 .Case("rs880", GK_R600)
1477 .Case("rv670", GK_R600_DOUBLE_OPS)
1478 .Case("rv710", GK_R700)
1479 .Case("rv730", GK_R700)
1480 .Case("rv740", GK_R700_DOUBLE_OPS)
1481 .Case("rv770", GK_R700_DOUBLE_OPS)
1482 .Case("palm", GK_EVERGREEN)
1483 .Case("cedar", GK_EVERGREEN)
1484 .Case("sumo", GK_EVERGREEN)
1485 .Case("sumo2", GK_EVERGREEN)
1486 .Case("redwood", GK_EVERGREEN)
1487 .Case("juniper", GK_EVERGREEN)
1488 .Case("hemlock", GK_EVERGREEN_DOUBLE_OPS)
1489 .Case("cypress", GK_EVERGREEN_DOUBLE_OPS)
1490 .Case("barts", GK_NORTHERN_ISLANDS)
1491 .Case("turks", GK_NORTHERN_ISLANDS)
1492 .Case("caicos", GK_NORTHERN_ISLANDS)
1493 .Case("cayman", GK_CAYMAN)
1494 .Case("aruba", GK_CAYMAN)
Tom Stellard3b848ec2013-04-01 20:56:49 +00001495 .Case("tahiti", GK_SOUTHERN_ISLANDS)
Tom Stellardfd075912013-03-04 17:40:53 +00001496 .Case("pitcairn", GK_SOUTHERN_ISLANDS)
1497 .Case("verde", GK_SOUTHERN_ISLANDS)
1498 .Case("oland", GK_SOUTHERN_ISLANDS)
1499 .Default(GK_NONE);
1500
1501 if (GPU == GK_NONE) {
1502 return false;
1503 }
1504
1505 // Set the correct data layout
1506 switch (GPU) {
1507 case GK_NONE:
1508 case GK_R600:
1509 case GK_R700:
1510 case GK_EVERGREEN:
1511 case GK_NORTHERN_ISLANDS:
1512 DescriptionString = DescriptionStringR600;
1513 break;
1514 case GK_R600_DOUBLE_OPS:
1515 case GK_R700_DOUBLE_OPS:
1516 case GK_EVERGREEN_DOUBLE_OPS:
1517 case GK_CAYMAN:
1518 DescriptionString = DescriptionStringR600DoubleOps;
1519 break;
1520 case GK_SOUTHERN_ISLANDS:
1521 DescriptionString = DescriptionStringSI;
1522 break;
1523 }
1524
1525 return true;
1526 }
Eli Friedman6505a292012-10-12 23:32:00 +00001527};
1528
1529} // end anonymous namespace
1530
1531namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001532// Namespace for x86 abstract base class
1533const Builtin::Info BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00001534#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00001535#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00001536 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +00001537#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +00001538};
Eli Friedman61538a72008-05-20 14:21:01 +00001539
Nuno Lopes2550d702009-12-23 17:49:57 +00001540static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +00001541 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
1542 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Eric Christopher7c9adf92011-07-07 22:55:26 +00001543 "argp", "flags", "fpcr", "fpsr", "dirflag", "frame",
Eli Friedman618234a2008-08-20 02:34:37 +00001544 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
1545 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
1546 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
Eric Christophercfd323d2011-06-21 00:05:20 +00001547 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
Eric Christopherc5f9a012011-12-02 02:12:16 +00001548 "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7",
1549 "ymm8", "ymm9", "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15",
Eli Friedman618234a2008-08-20 02:34:37 +00001550};
1551
Eric Christophercfd323d2011-06-21 00:05:20 +00001552const TargetInfo::AddlRegName AddlRegNames[] = {
1553 { { "al", "ah", "eax", "rax" }, 0 },
1554 { { "bl", "bh", "ebx", "rbx" }, 3 },
1555 { { "cl", "ch", "ecx", "rcx" }, 2 },
1556 { { "dl", "dh", "edx", "rdx" }, 1 },
1557 { { "esi", "rsi" }, 4 },
1558 { { "edi", "rdi" }, 5 },
1559 { { "esp", "rsp" }, 7 },
1560 { { "ebp", "rbp" }, 6 },
Eli Friedman618234a2008-08-20 02:34:37 +00001561};
1562
1563// X86 target abstract base class; x86-32 and x86-64 are very close, so
1564// most of the implementation can be shared.
1565class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +00001566 enum X86SSEEnum {
Craig Topperb7a95d22013-08-21 03:59:22 +00001567 NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
Chris Lattner84f0ea82009-03-02 22:40:39 +00001568 } SSELevel;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001569 enum MMX3DNowEnum {
1570 NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon
1571 } MMX3DNowLevel;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00001572 enum XOPEnum {
1573 NoXOP,
1574 SSE4A,
1575 FMA4,
1576 XOP
1577 } XOPLevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001578
Eric Christophereea12d12010-04-02 23:50:19 +00001579 bool HasAES;
Craig Topper3c0bc152012-05-31 05:18:48 +00001580 bool HasPCLMUL;
Craig Topper31ceea02011-12-25 05:06:45 +00001581 bool HasLZCNT;
Benjamin Kramer84f30802012-07-07 09:39:18 +00001582 bool HasRDRND;
Craig Topper31ceea02011-12-25 05:06:45 +00001583 bool HasBMI;
1584 bool HasBMI2;
Craig Toppere14e08b2011-12-29 16:10:46 +00001585 bool HasPOPCNT;
Michael Liao463eb892012-11-10 05:17:46 +00001586 bool HasRTM;
Michael Liao72339a02013-03-26 17:52:08 +00001587 bool HasPRFCHW;
Michael Liao1bfc28c2013-03-29 05:17:55 +00001588 bool HasRDSEED;
Craig Topper2ae95072012-06-03 21:46:30 +00001589 bool HasFMA;
Manman Ren146e5a42012-10-11 00:59:55 +00001590 bool HasF16C;
Craig Topperbca2c4f2013-08-21 05:29:10 +00001591 bool HasAVX512CD, HasAVX512ER, HasAVX512PF;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001592
Chandler Carruth499d9722011-09-28 08:55:34 +00001593 /// \brief Enumeration of all of the X86 CPUs supported by Clang.
1594 ///
1595 /// Each enumeration represents a particular CPU supported by Clang. These
1596 /// loosely correspond to the options passed to '-march' or '-mtune' flags.
1597 enum CPUKind {
1598 CK_Generic,
1599
1600 /// \name i386
1601 /// i386-generation processors.
1602 //@{
1603 CK_i386,
1604 //@}
1605
1606 /// \name i486
1607 /// i486-generation processors.
1608 //@{
1609 CK_i486,
1610 CK_WinChipC6,
1611 CK_WinChip2,
1612 CK_C3,
1613 //@}
1614
1615 /// \name i586
1616 /// i586-generation processors, P5 microarchitecture based.
1617 //@{
1618 CK_i586,
1619 CK_Pentium,
1620 CK_PentiumMMX,
1621 //@}
1622
1623 /// \name i686
1624 /// i686-generation processors, P6 / Pentium M microarchitecture based.
1625 //@{
1626 CK_i686,
1627 CK_PentiumPro,
1628 CK_Pentium2,
1629 CK_Pentium3,
1630 CK_Pentium3M,
1631 CK_PentiumM,
1632 CK_C3_2,
1633
1634 /// This enumerator is a bit odd, as GCC no longer accepts -march=yonah.
1635 /// Clang however has some logic to suport this.
1636 // FIXME: Warn, deprecate, and potentially remove this.
1637 CK_Yonah,
1638 //@}
1639
1640 /// \name Netburst
Chandler Carruth83450aa2011-09-28 18:17:30 +00001641 /// Netburst microarchitecture based processors.
Chandler Carruth499d9722011-09-28 08:55:34 +00001642 //@{
1643 CK_Pentium4,
1644 CK_Pentium4M,
1645 CK_Prescott,
1646 CK_Nocona,
1647 //@}
1648
1649 /// \name Core
1650 /// Core microarchitecture based processors.
1651 //@{
1652 CK_Core2,
1653
1654 /// This enumerator, like \see CK_Yonah, is a bit odd. It is another
1655 /// codename which GCC no longer accepts as an option to -march, but Clang
1656 /// has some logic for recognizing it.
1657 // FIXME: Warn, deprecate, and potentially remove this.
1658 CK_Penryn,
1659 //@}
1660
1661 /// \name Atom
1662 /// Atom processors
1663 //@{
1664 CK_Atom,
Benjamin Kramerb98ce372013-08-30 14:05:34 +00001665 CK_SLM,
Chandler Carruth499d9722011-09-28 08:55:34 +00001666 //@}
1667
1668 /// \name Nehalem
1669 /// Nehalem microarchitecture based processors.
1670 //@{
1671 CK_Corei7,
1672 CK_Corei7AVX,
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001673 CK_CoreAVXi,
Craig Topper2b03bb02011-12-17 19:55:21 +00001674 CK_CoreAVX2,
Chandler Carruth499d9722011-09-28 08:55:34 +00001675 //@}
1676
Craig Topper10c2c682013-08-20 07:09:39 +00001677 /// \name Knights Landing
1678 /// Knights Landing processor.
1679 CK_KNL,
1680
Chandler Carruth499d9722011-09-28 08:55:34 +00001681 /// \name K6
1682 /// K6 architecture processors.
1683 //@{
1684 CK_K6,
1685 CK_K6_2,
1686 CK_K6_3,
1687 //@}
1688
1689 /// \name K7
1690 /// K7 architecture processors.
1691 //@{
1692 CK_Athlon,
1693 CK_AthlonThunderbird,
1694 CK_Athlon4,
1695 CK_AthlonXP,
1696 CK_AthlonMP,
1697 //@}
1698
1699 /// \name K8
1700 /// K8 architecture processors.
1701 //@{
1702 CK_Athlon64,
1703 CK_Athlon64SSE3,
1704 CK_AthlonFX,
1705 CK_K8,
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001706 CK_K8SSE3,
Chandler Carruth499d9722011-09-28 08:55:34 +00001707 CK_Opteron,
1708 CK_OpteronSSE3,
Roman Divacky01c770d2011-10-30 07:48:46 +00001709 CK_AMDFAM10,
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001710 //@}
Chandler Carruth499d9722011-09-28 08:55:34 +00001711
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001712 /// \name Bobcat
1713 /// Bobcat architecture processors.
1714 //@{
1715 CK_BTVER1,
Benjamin Kramer63063f52013-05-03 10:47:15 +00001716 CK_BTVER2,
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001717 //@}
1718
1719 /// \name Bulldozer
1720 /// Bulldozer architecture processors.
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001721 //@{
1722 CK_BDVER1,
1723 CK_BDVER2,
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001724 //@}
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001725
Chandler Carruth499d9722011-09-28 08:55:34 +00001726 /// This specification is deprecated and will be removed in the future.
1727 /// Users should prefer \see CK_K8.
1728 // FIXME: Warn on this when the CPU is set to it.
1729 CK_x86_64,
1730 //@}
1731
1732 /// \name Geode
1733 /// Geode processors.
1734 //@{
1735 CK_Geode
1736 //@}
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001737 } CPU;
Chandler Carruth499d9722011-09-28 08:55:34 +00001738
Rafael Espindola5389b842013-08-21 21:59:03 +00001739 enum FPMathKind {
1740 FP_Default,
1741 FP_SSE,
1742 FP_387
1743 } FPMath;
1744
Eli Friedman618234a2008-08-20 02:34:37 +00001745public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00001746 X86TargetInfo(const llvm::Triple &Triple)
1747 : TargetInfo(Triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00001748 XOPLevel(NoXOP), HasAES(false), HasPCLMUL(false), HasLZCNT(false),
1749 HasRDRND(false), HasBMI(false), HasBMI2(false), HasPOPCNT(false),
1750 HasRTM(false), HasPRFCHW(false), HasRDSEED(false), HasFMA(false),
Craig Topperbca2c4f2013-08-21 05:29:10 +00001751 HasF16C(false), HasAVX512CD(false), HasAVX512ER(false),
Rafael Espindola5389b842013-08-21 21:59:03 +00001752 HasAVX512PF(false), CPU(CK_Generic), FPMath(FP_Default) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00001753 BigEndian = false;
Eli Friedman618234a2008-08-20 02:34:37 +00001754 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +00001755 }
Benjamin Kramerb4066692011-12-28 15:47:06 +00001756 virtual unsigned getFloatEvalMethod() const {
1757 // X87 evaluates with 80 bits "long double" precision.
1758 return SSELevel == NoSSE ? 2 : 0;
1759 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001760 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1761 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001762 Records = BuiltinInfo;
1763 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +00001764 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001765 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +00001766 unsigned &NumNames) const {
1767 Names = GCCRegNames;
1768 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +00001769 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001770 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +00001771 unsigned &NumAliases) const {
Eric Christophercfd323d2011-06-21 00:05:20 +00001772 Aliases = 0;
1773 NumAliases = 0;
1774 }
1775 virtual void getGCCAddlRegNames(const AddlRegName *&Names,
Eric Christopher825d3862012-11-14 22:08:59 +00001776 unsigned &NumNames) const {
Eric Christophercfd323d2011-06-21 00:05:20 +00001777 Names = AddlRegNames;
1778 NumNames = llvm::array_lengthof(AddlRegNames);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001779 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001780 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +00001781 TargetInfo::ConstraintInfo &info) const;
Stuart Hastings002333f2011-06-07 23:45:05 +00001782 virtual std::string convertConstraint(const char *&Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +00001783 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +00001784 return "~{dirflag},~{fpsr},~{flags}";
1785 }
Chris Lattner33328642009-03-20 15:52:06 +00001786 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001787 MacroBuilder &Builder) const;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00001788 void setSSELevel(llvm::StringMap<bool> &Features, X86SSEEnum Level,
1789 bool Enabled) const;
1790 void setMMXLevel(llvm::StringMap<bool> &Features, MMX3DNowEnum Level,
1791 bool Enabled) const;
1792 void setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
1793 bool Enabled) const;
Rafael Espindolaade7cd42013-08-20 15:30:32 +00001794 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00001795 StringRef Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001796 bool Enabled) const;
Chandler Carruthc3a2e652011-09-28 05:56:05 +00001797 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const;
Douglas Gregore727d212012-01-30 06:38:25 +00001798 virtual bool hasFeature(StringRef Feature) const;
Rafael Espindola5389b842013-08-21 21:59:03 +00001799 virtual bool HandleTargetFeatures(std::vector<std::string> &Features,
1800 DiagnosticsEngine &Diags);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001801 virtual const char* getABI() const {
Derek Schuffbabaf312012-10-11 15:52:22 +00001802 if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX)
Eli Friedmanee1ad992011-12-02 00:11:43 +00001803 return "avx";
Derek Schuffbabaf312012-10-11 15:52:22 +00001804 else if (getTriple().getArch() == llvm::Triple::x86 &&
1805 MMX3DNowLevel == NoMMX3DNow)
Eli Friedmanee1ad992011-12-02 00:11:43 +00001806 return "no-mmx";
1807 return "";
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001808 }
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001809 virtual bool setCPU(const std::string &Name) {
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001810 CPU = llvm::StringSwitch<CPUKind>(Name)
1811 .Case("i386", CK_i386)
1812 .Case("i486", CK_i486)
1813 .Case("winchip-c6", CK_WinChipC6)
1814 .Case("winchip2", CK_WinChip2)
1815 .Case("c3", CK_C3)
1816 .Case("i586", CK_i586)
1817 .Case("pentium", CK_Pentium)
1818 .Case("pentium-mmx", CK_PentiumMMX)
1819 .Case("i686", CK_i686)
1820 .Case("pentiumpro", CK_PentiumPro)
1821 .Case("pentium2", CK_Pentium2)
1822 .Case("pentium3", CK_Pentium3)
1823 .Case("pentium3m", CK_Pentium3M)
1824 .Case("pentium-m", CK_PentiumM)
1825 .Case("c3-2", CK_C3_2)
1826 .Case("yonah", CK_Yonah)
1827 .Case("pentium4", CK_Pentium4)
1828 .Case("pentium4m", CK_Pentium4M)
1829 .Case("prescott", CK_Prescott)
1830 .Case("nocona", CK_Nocona)
1831 .Case("core2", CK_Core2)
1832 .Case("penryn", CK_Penryn)
1833 .Case("atom", CK_Atom)
Benjamin Kramerb98ce372013-08-30 14:05:34 +00001834 .Case("slm", CK_SLM)
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001835 .Case("corei7", CK_Corei7)
1836 .Case("corei7-avx", CK_Corei7AVX)
1837 .Case("core-avx-i", CK_CoreAVXi)
Craig Topper2b03bb02011-12-17 19:55:21 +00001838 .Case("core-avx2", CK_CoreAVX2)
Craig Topper10c2c682013-08-20 07:09:39 +00001839 .Case("knl", CK_KNL)
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001840 .Case("k6", CK_K6)
1841 .Case("k6-2", CK_K6_2)
1842 .Case("k6-3", CK_K6_3)
1843 .Case("athlon", CK_Athlon)
1844 .Case("athlon-tbird", CK_AthlonThunderbird)
1845 .Case("athlon-4", CK_Athlon4)
1846 .Case("athlon-xp", CK_AthlonXP)
1847 .Case("athlon-mp", CK_AthlonMP)
1848 .Case("athlon64", CK_Athlon64)
1849 .Case("athlon64-sse3", CK_Athlon64SSE3)
1850 .Case("athlon-fx", CK_AthlonFX)
1851 .Case("k8", CK_K8)
1852 .Case("k8-sse3", CK_K8SSE3)
1853 .Case("opteron", CK_Opteron)
1854 .Case("opteron-sse3", CK_OpteronSSE3)
Roman Divacky01c770d2011-10-30 07:48:46 +00001855 .Case("amdfam10", CK_AMDFAM10)
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001856 .Case("btver1", CK_BTVER1)
Benjamin Kramer63063f52013-05-03 10:47:15 +00001857 .Case("btver2", CK_BTVER2)
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001858 .Case("bdver1", CK_BDVER1)
1859 .Case("bdver2", CK_BDVER2)
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001860 .Case("x86-64", CK_x86_64)
1861 .Case("geode", CK_Geode)
1862 .Default(CK_Generic);
1863
Chandler Carruth26a39142011-09-28 09:45:08 +00001864 // Perform any per-CPU checks necessary to determine if this CPU is
1865 // acceptable.
1866 // FIXME: This results in terrible diagnostics. Clang just says the CPU is
1867 // invalid without explaining *why*.
1868 switch (CPU) {
1869 case CK_Generic:
1870 // No processor selected!
1871 return false;
1872
1873 case CK_i386:
1874 case CK_i486:
1875 case CK_WinChipC6:
1876 case CK_WinChip2:
1877 case CK_C3:
1878 case CK_i586:
1879 case CK_Pentium:
1880 case CK_PentiumMMX:
1881 case CK_i686:
1882 case CK_PentiumPro:
1883 case CK_Pentium2:
1884 case CK_Pentium3:
1885 case CK_Pentium3M:
1886 case CK_PentiumM:
1887 case CK_Yonah:
1888 case CK_C3_2:
1889 case CK_Pentium4:
1890 case CK_Pentium4M:
1891 case CK_Prescott:
1892 case CK_K6:
1893 case CK_K6_2:
1894 case CK_K6_3:
1895 case CK_Athlon:
1896 case CK_AthlonThunderbird:
1897 case CK_Athlon4:
1898 case CK_AthlonXP:
1899 case CK_AthlonMP:
1900 case CK_Geode:
1901 // Only accept certain architectures when compiling in 32-bit mode.
Derek Schuffbabaf312012-10-11 15:52:22 +00001902 if (getTriple().getArch() != llvm::Triple::x86)
Chandler Carruth26a39142011-09-28 09:45:08 +00001903 return false;
1904
1905 // Fallthrough
1906 case CK_Nocona:
1907 case CK_Core2:
1908 case CK_Penryn:
1909 case CK_Atom:
Benjamin Kramerb98ce372013-08-30 14:05:34 +00001910 case CK_SLM:
Chandler Carruth26a39142011-09-28 09:45:08 +00001911 case CK_Corei7:
1912 case CK_Corei7AVX:
1913 case CK_CoreAVXi:
Craig Topper2b03bb02011-12-17 19:55:21 +00001914 case CK_CoreAVX2:
Craig Topper10c2c682013-08-20 07:09:39 +00001915 case CK_KNL:
Chandler Carruth26a39142011-09-28 09:45:08 +00001916 case CK_Athlon64:
1917 case CK_Athlon64SSE3:
1918 case CK_AthlonFX:
1919 case CK_K8:
1920 case CK_K8SSE3:
1921 case CK_Opteron:
1922 case CK_OpteronSSE3:
Roman Divacky01c770d2011-10-30 07:48:46 +00001923 case CK_AMDFAM10:
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001924 case CK_BTVER1:
Benjamin Kramer63063f52013-05-03 10:47:15 +00001925 case CK_BTVER2:
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001926 case CK_BDVER1:
1927 case CK_BDVER2:
Chandler Carruth26a39142011-09-28 09:45:08 +00001928 case CK_x86_64:
1929 return true;
1930 }
Chandler Carruth5b7803d2011-09-28 10:49:06 +00001931 llvm_unreachable("Unhandled CPU kind");
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001932 }
Aaron Ballman82bfa192012-10-02 14:26:08 +00001933
Rafael Espindola5389b842013-08-21 21:59:03 +00001934 virtual bool setFPMath(StringRef Name);
1935
Aaron Ballman82bfa192012-10-02 14:26:08 +00001936 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1937 // We accept all non-ARM calling conventions
1938 return (CC == CC_X86ThisCall ||
1939 CC == CC_X86FastCall ||
Peter Collingbourne7728cdd2013-02-23 00:06:18 +00001940 CC == CC_X86StdCall ||
1941 CC == CC_C ||
Guy Benyei38980082012-12-25 08:53:55 +00001942 CC == CC_X86Pascal ||
1943 CC == CC_IntelOclBicc) ? CCCR_OK : CCCR_Warning;
Aaron Ballman82bfa192012-10-02 14:26:08 +00001944 }
1945
Aaron Ballmanfff32482012-12-09 17:45:41 +00001946 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
1947 return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
Aaron Ballman82bfa192012-10-02 14:26:08 +00001948 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001949};
Chris Lattner3daed522009-03-02 22:20:04 +00001950
Rafael Espindola5389b842013-08-21 21:59:03 +00001951bool X86TargetInfo::setFPMath(StringRef Name) {
1952 if (Name == "387") {
1953 FPMath = FP_387;
1954 return true;
1955 }
1956 if (Name == "sse") {
1957 FPMath = FP_SSE;
1958 return true;
1959 }
1960 return false;
1961}
1962
Chandler Carruthc3a2e652011-09-28 05:56:05 +00001963void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001964 // FIXME: This *really* should not be here.
1965
1966 // X86_64 always has SSE2.
Derek Schuffbabaf312012-10-11 15:52:22 +00001967 if (getTriple().getArch() == llvm::Triple::x86_64)
Eli Friedman612db2a2012-11-17 01:16:19 +00001968 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001969
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001970 switch (CPU) {
1971 case CK_Generic:
1972 case CK_i386:
1973 case CK_i486:
1974 case CK_i586:
1975 case CK_Pentium:
1976 case CK_i686:
1977 case CK_PentiumPro:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001978 break;
1979 case CK_PentiumMMX:
1980 case CK_Pentium2:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001981 setFeatureEnabled(Features, "mmx", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001982 break;
1983 case CK_Pentium3:
1984 case CK_Pentium3M:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001985 setFeatureEnabled(Features, "sse", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001986 break;
1987 case CK_PentiumM:
1988 case CK_Pentium4:
1989 case CK_Pentium4M:
1990 case CK_x86_64:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001991 setFeatureEnabled(Features, "sse2", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001992 break;
1993 case CK_Yonah:
1994 case CK_Prescott:
1995 case CK_Nocona:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001996 setFeatureEnabled(Features, "sse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001997 break;
1998 case CK_Core2:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001999 setFeatureEnabled(Features, "ssse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002000 break;
2001 case CK_Penryn:
Benjamin Kramerb3453a82012-01-04 14:36:57 +00002002 setFeatureEnabled(Features, "sse4.1", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002003 break;
2004 case CK_Atom:
Chandler Carruth49defe62011-09-28 10:36:46 +00002005 setFeatureEnabled(Features, "ssse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002006 break;
2007 case CK_Corei7:
Benjamin Kramerb98ce372013-08-30 14:05:34 +00002008 case CK_SLM:
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002009 setFeatureEnabled(Features, "sse4.2", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002010 break;
2011 case CK_Corei7AVX:
Benjamin Kramer84f30802012-07-07 09:39:18 +00002012 setFeatureEnabled(Features, "avx", true);
2013 setFeatureEnabled(Features, "aes", true);
2014 setFeatureEnabled(Features, "pclmul", true);
2015 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002016 case CK_CoreAVXi:
Craig Topperfd936302012-04-26 07:31:30 +00002017 setFeatureEnabled(Features, "avx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00002018 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00002019 setFeatureEnabled(Features, "pclmul", true);
Benjamin Kramer84f30802012-07-07 09:39:18 +00002020 setFeatureEnabled(Features, "rdrnd", true);
Eli Friedmanfaf35382012-11-17 01:43:10 +00002021 setFeatureEnabled(Features, "f16c", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002022 break;
Craig Topper2b03bb02011-12-17 19:55:21 +00002023 case CK_CoreAVX2:
Craig Topperfd936302012-04-26 07:31:30 +00002024 setFeatureEnabled(Features, "avx2", true);
Craig Topper2b03bb02011-12-17 19:55:21 +00002025 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00002026 setFeatureEnabled(Features, "pclmul", true);
Craig Topper31ceea02011-12-25 05:06:45 +00002027 setFeatureEnabled(Features, "lzcnt", true);
Benjamin Kramer84f30802012-07-07 09:39:18 +00002028 setFeatureEnabled(Features, "rdrnd", true);
Eli Friedmanfaf35382012-11-17 01:43:10 +00002029 setFeatureEnabled(Features, "f16c", true);
Craig Topper31ceea02011-12-25 05:06:45 +00002030 setFeatureEnabled(Features, "bmi", true);
2031 setFeatureEnabled(Features, "bmi2", true);
Michael Liao463eb892012-11-10 05:17:46 +00002032 setFeatureEnabled(Features, "rtm", true);
Craig Topper2ae95072012-06-03 21:46:30 +00002033 setFeatureEnabled(Features, "fma", true);
Craig Topper2b03bb02011-12-17 19:55:21 +00002034 break;
Craig Topper10c2c682013-08-20 07:09:39 +00002035 case CK_KNL:
Craig Topperbca2c4f2013-08-21 05:29:10 +00002036 setFeatureEnabled(Features, "avx512f", true);
2037 setFeatureEnabled(Features, "avx512cd", true);
2038 setFeatureEnabled(Features, "avx512er", true);
2039 setFeatureEnabled(Features, "avx512pf", true);
Craig Topper10c2c682013-08-20 07:09:39 +00002040 setFeatureEnabled(Features, "aes", true);
2041 setFeatureEnabled(Features, "pclmul", true);
2042 setFeatureEnabled(Features, "lzcnt", true);
2043 setFeatureEnabled(Features, "rdrnd", true);
2044 setFeatureEnabled(Features, "f16c", true);
2045 setFeatureEnabled(Features, "bmi", true);
2046 setFeatureEnabled(Features, "bmi2", true);
2047 setFeatureEnabled(Features, "rtm", true);
2048 setFeatureEnabled(Features, "fma", true);
2049 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002050 case CK_K6:
2051 case CK_WinChipC6:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00002052 setFeatureEnabled(Features, "mmx", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002053 break;
2054 case CK_K6_2:
2055 case CK_K6_3:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002056 case CK_WinChip2:
2057 case CK_C3:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00002058 setFeatureEnabled(Features, "3dnow", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002059 break;
Chandler Carruth49defe62011-09-28 10:36:46 +00002060 case CK_Athlon:
2061 case CK_AthlonThunderbird:
2062 case CK_Geode:
2063 setFeatureEnabled(Features, "3dnowa", true);
2064 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002065 case CK_Athlon4:
2066 case CK_AthlonXP:
2067 case CK_AthlonMP:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00002068 setFeatureEnabled(Features, "sse", true);
2069 setFeatureEnabled(Features, "3dnowa", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002070 break;
2071 case CK_K8:
2072 case CK_Opteron:
2073 case CK_Athlon64:
2074 case CK_AthlonFX:
Mike Stump1eb44332009-09-09 15:08:12 +00002075 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00002076 setFeatureEnabled(Features, "3dnowa", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002077 break;
2078 case CK_K8SSE3:
2079 case CK_OpteronSSE3:
2080 case CK_Athlon64SSE3:
Roman Divacky80b32b82011-10-30 13:47:56 +00002081 setFeatureEnabled(Features, "sse3", true);
2082 setFeatureEnabled(Features, "3dnowa", true);
2083 break;
Roman Divacky01c770d2011-10-30 07:48:46 +00002084 case CK_AMDFAM10:
Roman Divackyc8b09a12010-12-29 13:28:29 +00002085 setFeatureEnabled(Features, "sse3", true);
Roman Divacky80b32b82011-10-30 13:47:56 +00002086 setFeatureEnabled(Features, "sse4a", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00002087 setFeatureEnabled(Features, "3dnowa", true);
Eli Friedmanfaf35382012-11-17 01:43:10 +00002088 setFeatureEnabled(Features, "lzcnt", true);
2089 setFeatureEnabled(Features, "popcnt", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002090 break;
Benjamin Kramer5660aa62012-01-10 11:50:18 +00002091 case CK_BTVER1:
2092 setFeatureEnabled(Features, "ssse3", true);
2093 setFeatureEnabled(Features, "sse4a", true);
Eli Friedmanfaf35382012-11-17 01:43:10 +00002094 setFeatureEnabled(Features, "lzcnt", true);
2095 setFeatureEnabled(Features, "popcnt", true);
Craig Topper90ea0362012-05-30 05:54:54 +00002096 break;
Benjamin Kramer63063f52013-05-03 10:47:15 +00002097 case CK_BTVER2:
2098 setFeatureEnabled(Features, "avx", true);
2099 setFeatureEnabled(Features, "sse4a", true);
2100 setFeatureEnabled(Features, "lzcnt", true);
2101 setFeatureEnabled(Features, "aes", true);
2102 setFeatureEnabled(Features, "pclmul", true);
2103 setFeatureEnabled(Features, "bmi", true);
2104 setFeatureEnabled(Features, "f16c", true);
2105 break;
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002106 case CK_BDVER1:
Craig Topperb6af69e2012-06-09 22:24:14 +00002107 setFeatureEnabled(Features, "xop", true);
Eli Friedmanfaf35382012-11-17 01:43:10 +00002108 setFeatureEnabled(Features, "lzcnt", true);
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002109 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00002110 setFeatureEnabled(Features, "pclmul", true);
Eli Friedmanf5824992012-11-26 21:57:28 +00002111 break;
Eli Friedmanfaf35382012-11-17 01:43:10 +00002112 case CK_BDVER2:
2113 setFeatureEnabled(Features, "xop", true);
2114 setFeatureEnabled(Features, "lzcnt", true);
2115 setFeatureEnabled(Features, "aes", true);
2116 setFeatureEnabled(Features, "pclmul", true);
2117 setFeatureEnabled(Features, "bmi", true);
2118 setFeatureEnabled(Features, "fma", true);
2119 setFeatureEnabled(Features, "f16c", true);
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002120 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002121 case CK_C3_2:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00002122 setFeatureEnabled(Features, "sse", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002123 break;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002124 }
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00002125}
2126
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002127void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
2128 X86SSEEnum Level, bool Enabled) const {
2129 if (Enabled) {
2130 switch (Level) {
Craig Topperb7a95d22013-08-21 03:59:22 +00002131 case AVX512F:
2132 Features["avx512f"] = true;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002133 case AVX2:
2134 Features["avx2"] = true;
2135 case AVX:
2136 Features["avx"] = true;
2137 case SSE42:
Craig Topper89a5e792013-09-10 06:55:47 +00002138 Features["sse4.2"] = true;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002139 case SSE41:
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002140 Features["sse4.1"] = true;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002141 case SSSE3:
2142 Features["ssse3"] = true;
2143 case SSE3:
2144 Features["sse3"] = true;
2145 case SSE2:
2146 Features["sse2"] = true;
2147 case SSE1:
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002148 Features["sse"] = true;
2149 case NoSSE:
2150 break;
2151 }
2152 return;
2153 }
2154
2155 switch (Level) {
2156 case NoSSE:
2157 case SSE1:
2158 Features["sse"] = false;
2159 case SSE2:
2160 Features["sse2"] = false;
2161 case SSE3:
2162 Features["sse3"] = false;
2163 setXOPLevel(Features, NoXOP, false);
2164 case SSSE3:
2165 Features["ssse3"] = false;
2166 case SSE41:
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002167 Features["sse4.1"] = false;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002168 case SSE42:
Craig Topper89a5e792013-09-10 06:55:47 +00002169 Features["sse4.2"] = false;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002170 case AVX:
2171 Features["fma"] = Features["avx"] = false;
Rafael Espindola29f26de2013-08-21 13:28:02 +00002172 setXOPLevel(Features, FMA4, false);
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002173 case AVX2:
2174 Features["avx2"] = false;
Craig Topperb7a95d22013-08-21 03:59:22 +00002175 case AVX512F:
Craig Topperbca2c4f2013-08-21 05:29:10 +00002176 Features["avx512f"] = Features["avx512cd"] = Features["avx512er"] =
2177 Features["avx512pf"] = false;
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002178 }
2179}
2180
2181void X86TargetInfo::setMMXLevel(llvm::StringMap<bool> &Features,
2182 MMX3DNowEnum Level, bool Enabled) const {
2183 if (Enabled) {
2184 switch (Level) {
2185 case AMD3DNowAthlon:
2186 Features["3dnowa"] = true;
2187 case AMD3DNow:
2188 Features["3dnow"] = true;
2189 case MMX:
2190 Features["mmx"] = true;
2191 case NoMMX3DNow:
2192 break;
2193 }
2194 return;
2195 }
2196
2197 switch (Level) {
2198 case NoMMX3DNow:
2199 case MMX:
2200 Features["mmx"] = false;
2201 case AMD3DNow:
2202 Features["3dnow"] = false;
2203 case AMD3DNowAthlon:
2204 Features["3dnowa"] = false;
2205 }
2206}
2207
2208void X86TargetInfo::setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
2209 bool Enabled) const {
2210 if (Enabled) {
2211 switch (Level) {
2212 case XOP:
2213 Features["xop"] = true;
2214 case FMA4:
2215 Features["fma4"] = true;
2216 setSSELevel(Features, AVX, true);
2217 case SSE4A:
2218 Features["sse4a"] = true;
2219 setSSELevel(Features, SSE3, true);
2220 case NoXOP:
2221 break;
2222 }
2223 return;
2224 }
2225
2226 switch (Level) {
2227 case NoXOP:
2228 case SSE4A:
2229 Features["sse4a"] = false;
2230 case FMA4:
2231 Features["fma4"] = false;
2232 case XOP:
2233 Features["xop"] = false;
2234 }
2235}
2236
Rafael Espindolaade7cd42013-08-20 15:30:32 +00002237void X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00002238 StringRef Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00002239 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00002240 // FIXME: This *really* should not be here. We need some way of translating
2241 // options into llvm subtarget features.
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002242 if (Name == "sse4")
2243 Name = "sse4.2";
Daniel Dunbar17ca3632009-05-06 21:07:50 +00002244
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002245 Features[Name] = Enabled;
Rafael Espindola53ac3d82011-11-27 20:00:43 +00002246
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002247 if (Name == "mmx")
2248 setMMXLevel(Features, MMX, Enabled);
2249 else if (Name == "sse")
2250 setSSELevel(Features, SSE1, Enabled);
2251 else if (Name == "sse2")
2252 setSSELevel(Features, SSE2, Enabled);
2253 else if (Name == "sse3")
2254 setSSELevel(Features, SSE3, Enabled);
2255 else if (Name == "ssse3")
2256 setSSELevel(Features, SSSE3, Enabled);
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002257 else if (Name == "sse4.2")
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002258 setSSELevel(Features, SSE42, Enabled);
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002259 else if (Name == "sse4.1")
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002260 setSSELevel(Features, SSE41, Enabled);
2261 else if (Name == "3dnow")
2262 setMMXLevel(Features, AMD3DNow, Enabled);
2263 else if (Name == "3dnowa")
2264 setMMXLevel(Features, AMD3DNowAthlon, Enabled);
2265 else if (Name == "aes") {
2266 if (Enabled)
2267 setSSELevel(Features, SSE2, Enabled);
2268 } else if (Name == "pclmul") {
2269 if (Enabled)
2270 setSSELevel(Features, SSE2, Enabled);
2271 } else if (Name == "avx")
2272 setSSELevel(Features, AVX, Enabled);
2273 else if (Name == "avx2")
2274 setSSELevel(Features, AVX2, Enabled);
Craig Topperbca2c4f2013-08-21 05:29:10 +00002275 else if (Name == "avx512f")
Craig Topperb7a95d22013-08-21 03:59:22 +00002276 setSSELevel(Features, AVX512F, Enabled);
Craig Topperbca2c4f2013-08-21 05:29:10 +00002277 else if (Name == "avx512cd" || Name == "avx512er" || Name == "avx512pf") {
2278 if (Enabled)
2279 setSSELevel(Features, AVX512F, Enabled);
2280 } else if (Name == "fma") {
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002281 if (Enabled)
2282 setSSELevel(Features, AVX, Enabled);
2283 } else if (Name == "fma4") {
2284 setXOPLevel(Features, FMA4, Enabled);
2285 } else if (Name == "xop") {
2286 setXOPLevel(Features, XOP, Enabled);
2287 } else if (Name == "sse4a") {
2288 setXOPLevel(Features, SSE4A, Enabled);
Daniel Dunbar17ca3632009-05-06 21:07:50 +00002289 }
Daniel Dunbar17ca3632009-05-06 21:07:50 +00002290}
2291
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00002292/// HandleTargetOptions - Perform initialization based on the user
2293/// configured set of features.
Rafael Espindola5389b842013-08-21 21:59:03 +00002294bool X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features,
2295 DiagnosticsEngine &Diags) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002296 // Remember the maximum enabled sselevel.
2297 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
2298 // Ignore disabled features.
2299 if (Features[i][0] == '-')
2300 continue;
2301
Benjamin Kramer713575a2012-03-05 15:10:44 +00002302 StringRef Feature = StringRef(Features[i]).substr(1);
2303
2304 if (Feature == "aes") {
Eric Christophereea12d12010-04-02 23:50:19 +00002305 HasAES = true;
2306 continue;
2307 }
2308
Craig Topper3c0bc152012-05-31 05:18:48 +00002309 if (Feature == "pclmul") {
2310 HasPCLMUL = true;
2311 continue;
2312 }
2313
Benjamin Kramer713575a2012-03-05 15:10:44 +00002314 if (Feature == "lzcnt") {
Craig Topper31ceea02011-12-25 05:06:45 +00002315 HasLZCNT = true;
2316 continue;
2317 }
2318
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002319 if (Feature == "rdrnd") {
Benjamin Kramer84f30802012-07-07 09:39:18 +00002320 HasRDRND = true;
2321 continue;
2322 }
2323
Benjamin Kramer713575a2012-03-05 15:10:44 +00002324 if (Feature == "bmi") {
Craig Topper31ceea02011-12-25 05:06:45 +00002325 HasBMI = true;
2326 continue;
2327 }
2328
Benjamin Kramer713575a2012-03-05 15:10:44 +00002329 if (Feature == "bmi2") {
Craig Topper31ceea02011-12-25 05:06:45 +00002330 HasBMI2 = true;
2331 continue;
2332 }
2333
Benjamin Kramer713575a2012-03-05 15:10:44 +00002334 if (Feature == "popcnt") {
Craig Toppere14e08b2011-12-29 16:10:46 +00002335 HasPOPCNT = true;
2336 continue;
2337 }
2338
Michael Liao463eb892012-11-10 05:17:46 +00002339 if (Feature == "rtm") {
2340 HasRTM = true;
2341 continue;
2342 }
2343
Michael Liao72339a02013-03-26 17:52:08 +00002344 if (Feature == "prfchw") {
2345 HasPRFCHW = true;
2346 continue;
2347 }
2348
Michael Liao1bfc28c2013-03-29 05:17:55 +00002349 if (Feature == "rdseed") {
2350 HasRDSEED = true;
2351 continue;
2352 }
2353
Craig Topper2ae95072012-06-03 21:46:30 +00002354 if (Feature == "fma") {
2355 HasFMA = true;
2356 continue;
2357 }
2358
Manman Ren146e5a42012-10-11 00:59:55 +00002359 if (Feature == "f16c") {
2360 HasF16C = true;
2361 continue;
2362 }
2363
Craig Topperbca2c4f2013-08-21 05:29:10 +00002364 if (Feature == "avx512cd") {
2365 HasAVX512CD = true;
2366 continue;
2367 }
2368
2369 if (Feature == "avx512er") {
2370 HasAVX512ER = true;
2371 continue;
2372 }
2373
2374 if (Feature == "avx512pf") {
2375 HasAVX512PF = true;
2376 continue;
2377 }
2378
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002379 assert(Features[i][0] == '+' && "Invalid target feature!");
Benjamin Kramer713575a2012-03-05 15:10:44 +00002380 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
Craig Topperbca2c4f2013-08-21 05:29:10 +00002381 .Case("avx512f", AVX512F)
Craig Topper05fe4b52012-01-09 09:19:09 +00002382 .Case("avx2", AVX2)
2383 .Case("avx", AVX)
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002384 .Case("sse4.2", SSE42)
2385 .Case("sse4.1", SSE41)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002386 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00002387 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002388 .Case("sse2", SSE2)
2389 .Case("sse", SSE1)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002390 .Default(NoSSE);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002391 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00002392
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002393 MMX3DNowEnum ThreeDNowLevel =
Benjamin Kramer713575a2012-03-05 15:10:44 +00002394 llvm::StringSwitch<MMX3DNowEnum>(Feature)
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002395 .Case("3dnowa", AMD3DNowAthlon)
2396 .Case("3dnow", AMD3DNow)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002397 .Case("mmx", MMX)
2398 .Default(NoMMX3DNow);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002399 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002400
2401 XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
2402 .Case("xop", XOP)
2403 .Case("fma4", FMA4)
2404 .Case("sse4a", SSE4A)
2405 .Default(NoXOP);
2406 XOPLevel = std::max(XOPLevel, XLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00002407 }
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002408
Craig Topper89a5e792013-09-10 06:55:47 +00002409 // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
2410 // Can't do this earlier because we need to be able to explicitly enable
2411 // popcnt and still disable sse4.2.
2412 if (!HasPOPCNT && SSELevel >= SSE42 &&
2413 std::find(Features.begin(), Features.end(), "-popcnt") == Features.end()){
2414 HasPOPCNT = true;
2415 Features.push_back("+popcnt");
2416 }
2417
Rafael Espindola5389b842013-08-21 21:59:03 +00002418 // LLVM doesn't have a separate switch for fpmath, so only accept it if it
2419 // matches the selected sse level.
2420 if (FPMath == FP_SSE && SSELevel < SSE1) {
2421 Diags.Report(diag::err_target_unsupported_fpmath) << "sse";
2422 return false;
2423 } else if (FPMath == FP_387 && SSELevel >= SSE1) {
2424 Diags.Report(diag::err_target_unsupported_fpmath) << "387";
2425 return false;
2426 }
2427
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002428 // Don't tell the backend if we're turning off mmx; it will end up disabling
2429 // SSE, which we don't want.
Craig Topper56bed972013-09-11 06:48:53 +00002430 // Additionally, if SSE is enabled and mmx is not explicitly disabled,
2431 // then enable MMX.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002432 std::vector<std::string>::iterator it;
2433 it = std::find(Features.begin(), Features.end(), "-mmx");
2434 if (it != Features.end())
2435 Features.erase(it);
Craig Topper56bed972013-09-11 06:48:53 +00002436 else if (SSELevel > NoSSE)
2437 MMX3DNowLevel = std::max(MMX3DNowLevel, MMX);
Rafael Espindola5389b842013-08-21 21:59:03 +00002438 return true;
Chris Lattner3daed522009-03-02 22:20:04 +00002439}
Chris Lattnerc0f59212009-03-02 22:27:17 +00002440
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002441/// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
2442/// definitions for this particular subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00002443void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002444 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00002445 // Target identification.
Derek Schuffbabaf312012-10-11 15:52:22 +00002446 if (getTriple().getArch() == llvm::Triple::x86_64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00002447 Builder.defineMacro("__amd64__");
2448 Builder.defineMacro("__amd64");
2449 Builder.defineMacro("__x86_64");
2450 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00002451 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00002452 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00002453 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002454
Chris Lattnerc0f59212009-03-02 22:27:17 +00002455 // Subtarget options.
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002456 // FIXME: We are hard-coding the tune parameters based on the CPU, but they
2457 // truly should be based on -mtune options.
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002458 switch (CPU) {
2459 case CK_Generic:
2460 break;
2461 case CK_i386:
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002462 // The rest are coming from the i386 define above.
2463 Builder.defineMacro("__tune_i386__");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002464 break;
2465 case CK_i486:
2466 case CK_WinChipC6:
2467 case CK_WinChip2:
2468 case CK_C3:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002469 defineCPUMacros(Builder, "i486");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002470 break;
Chandler Carruthf17ba332011-09-28 09:45:05 +00002471 case CK_PentiumMMX:
2472 Builder.defineMacro("__pentium_mmx__");
2473 Builder.defineMacro("__tune_pentium_mmx__");
2474 // Fallthrough
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002475 case CK_i586:
2476 case CK_Pentium:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002477 defineCPUMacros(Builder, "i586");
2478 defineCPUMacros(Builder, "pentium");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002479 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002480 case CK_Pentium3:
2481 case CK_Pentium3M:
2482 case CK_PentiumM:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002483 Builder.defineMacro("__tune_pentium3__");
2484 // Fallthrough
2485 case CK_Pentium2:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002486 case CK_C3_2:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002487 Builder.defineMacro("__tune_pentium2__");
2488 // Fallthrough
2489 case CK_PentiumPro:
2490 Builder.defineMacro("__tune_i686__");
2491 Builder.defineMacro("__tune_pentiumpro__");
2492 // Fallthrough
2493 case CK_i686:
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002494 Builder.defineMacro("__i686");
2495 Builder.defineMacro("__i686__");
2496 // Strangely, __tune_i686__ isn't defined by GCC when CPU == i686.
2497 Builder.defineMacro("__pentiumpro");
2498 Builder.defineMacro("__pentiumpro__");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002499 break;
2500 case CK_Pentium4:
2501 case CK_Pentium4M:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002502 defineCPUMacros(Builder, "pentium4");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002503 break;
2504 case CK_Yonah:
2505 case CK_Prescott:
2506 case CK_Nocona:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002507 defineCPUMacros(Builder, "nocona");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002508 break;
2509 case CK_Core2:
2510 case CK_Penryn:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002511 defineCPUMacros(Builder, "core2");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002512 break;
2513 case CK_Atom:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002514 defineCPUMacros(Builder, "atom");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002515 break;
Benjamin Kramerb98ce372013-08-30 14:05:34 +00002516 case CK_SLM:
2517 defineCPUMacros(Builder, "slm");
2518 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002519 case CK_Corei7:
2520 case CK_Corei7AVX:
2521 case CK_CoreAVXi:
Craig Topper2b03bb02011-12-17 19:55:21 +00002522 case CK_CoreAVX2:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002523 defineCPUMacros(Builder, "corei7");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002524 break;
Craig Topper10c2c682013-08-20 07:09:39 +00002525 case CK_KNL:
2526 defineCPUMacros(Builder, "knl");
2527 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002528 case CK_K6_2:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002529 Builder.defineMacro("__k6_2__");
2530 Builder.defineMacro("__tune_k6_2__");
2531 // Fallthrough
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002532 case CK_K6_3:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002533 if (CPU != CK_K6_2) { // In case of fallthrough
2534 // FIXME: GCC may be enabling these in cases where some other k6
2535 // architecture is specified but -m3dnow is explicitly provided. The
2536 // exact semantics need to be determined and emulated here.
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002537 Builder.defineMacro("__k6_3__");
2538 Builder.defineMacro("__tune_k6_3__");
2539 }
Chandler Carruthf17ba332011-09-28 09:45:05 +00002540 // Fallthrough
2541 case CK_K6:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002542 defineCPUMacros(Builder, "k6");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002543 break;
2544 case CK_Athlon:
2545 case CK_AthlonThunderbird:
2546 case CK_Athlon4:
2547 case CK_AthlonXP:
2548 case CK_AthlonMP:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002549 defineCPUMacros(Builder, "athlon");
Chandler Carruth53bf4f92011-09-28 09:54:11 +00002550 if (SSELevel != NoSSE) {
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002551 Builder.defineMacro("__athlon_sse__");
Chandler Carruth53bf4f92011-09-28 09:54:11 +00002552 Builder.defineMacro("__tune_athlon_sse__");
2553 }
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002554 break;
2555 case CK_K8:
2556 case CK_K8SSE3:
2557 case CK_x86_64:
2558 case CK_Opteron:
2559 case CK_OpteronSSE3:
2560 case CK_Athlon64:
2561 case CK_Athlon64SSE3:
2562 case CK_AthlonFX:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002563 defineCPUMacros(Builder, "k8");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002564 break;
Roman Divacky01c770d2011-10-30 07:48:46 +00002565 case CK_AMDFAM10:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002566 defineCPUMacros(Builder, "amdfam10");
Roman Divacky01c770d2011-10-30 07:48:46 +00002567 break;
Benjamin Kramer5660aa62012-01-10 11:50:18 +00002568 case CK_BTVER1:
2569 defineCPUMacros(Builder, "btver1");
2570 break;
Benjamin Kramer63063f52013-05-03 10:47:15 +00002571 case CK_BTVER2:
2572 defineCPUMacros(Builder, "btver2");
2573 break;
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002574 case CK_BDVER1:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002575 defineCPUMacros(Builder, "bdver1");
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002576 break;
2577 case CK_BDVER2:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002578 defineCPUMacros(Builder, "bdver2");
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002579 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002580 case CK_Geode:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002581 defineCPUMacros(Builder, "geode");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002582 break;
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002583 }
Chris Lattner84f0ea82009-03-02 22:40:39 +00002584
Chandler Carruth88c75b02011-09-28 09:54:07 +00002585 // Target properties.
2586 Builder.defineMacro("__LITTLE_ENDIAN__");
2587 Builder.defineMacro("__REGISTER_PREFIX__", "");
2588
Chris Lattner54175442009-04-19 17:32:33 +00002589 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
2590 // functions in glibc header files that use FP Stack inline asm which the
2591 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00002592 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002593
Chandler Carruth88c75b02011-09-28 09:54:07 +00002594 if (HasAES)
2595 Builder.defineMacro("__AES__");
2596
Craig Topper3c0bc152012-05-31 05:18:48 +00002597 if (HasPCLMUL)
2598 Builder.defineMacro("__PCLMUL__");
2599
Craig Topper31ceea02011-12-25 05:06:45 +00002600 if (HasLZCNT)
2601 Builder.defineMacro("__LZCNT__");
2602
Benjamin Kramer84f30802012-07-07 09:39:18 +00002603 if (HasRDRND)
2604 Builder.defineMacro("__RDRND__");
2605
Craig Topper31ceea02011-12-25 05:06:45 +00002606 if (HasBMI)
2607 Builder.defineMacro("__BMI__");
2608
2609 if (HasBMI2)
2610 Builder.defineMacro("__BMI2__");
2611
Craig Toppere14e08b2011-12-29 16:10:46 +00002612 if (HasPOPCNT)
2613 Builder.defineMacro("__POPCNT__");
2614
Michael Liao463eb892012-11-10 05:17:46 +00002615 if (HasRTM)
2616 Builder.defineMacro("__RTM__");
2617
Michael Liao72339a02013-03-26 17:52:08 +00002618 if (HasPRFCHW)
2619 Builder.defineMacro("__PRFCHW__");
2620
Michael Liao1bfc28c2013-03-29 05:17:55 +00002621 if (HasRDSEED)
2622 Builder.defineMacro("__RDSEED__");
2623
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002624 switch (XOPLevel) {
2625 case XOP:
2626 Builder.defineMacro("__XOP__");
2627 case FMA4:
Craig Topper6a511e12011-12-30 07:33:42 +00002628 Builder.defineMacro("__FMA4__");
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002629 case SSE4A:
2630 Builder.defineMacro("__SSE4A__");
2631 case NoXOP:
2632 break;
2633 }
Craig Topper6a511e12011-12-30 07:33:42 +00002634
Craig Topper2ae95072012-06-03 21:46:30 +00002635 if (HasFMA)
2636 Builder.defineMacro("__FMA__");
2637
Manman Ren146e5a42012-10-11 00:59:55 +00002638 if (HasF16C)
2639 Builder.defineMacro("__F16C__");
2640
Craig Topperbca2c4f2013-08-21 05:29:10 +00002641 if (HasAVX512CD)
2642 Builder.defineMacro("__AVX512CD__");
2643 if (HasAVX512ER)
2644 Builder.defineMacro("__AVX512ER__");
2645 if (HasAVX512PF)
2646 Builder.defineMacro("__AVX512PF__");
2647
Chris Lattner84f0ea82009-03-02 22:40:39 +00002648 // Each case falls through to the previous one here.
2649 switch (SSELevel) {
Craig Topperb7a95d22013-08-21 03:59:22 +00002650 case AVX512F:
Craig Topper42f98732013-08-20 07:39:54 +00002651 Builder.defineMacro("__AVX512F__");
Craig Topper05fe4b52012-01-09 09:19:09 +00002652 case AVX2:
2653 Builder.defineMacro("__AVX2__");
2654 case AVX:
2655 Builder.defineMacro("__AVX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002656 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00002657 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002658 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00002659 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002660 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00002661 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002662 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00002663 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002664 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00002665 Builder.defineMacro("__SSE2__");
2666 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00002667 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00002668 Builder.defineMacro("__SSE__");
2669 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002670 case NoSSE:
Chris Lattner84f0ea82009-03-02 22:40:39 +00002671 break;
2672 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00002673
Derek Schuffbabaf312012-10-11 15:52:22 +00002674 if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002675 switch (SSELevel) {
Craig Topperb7a95d22013-08-21 03:59:22 +00002676 case AVX512F:
Craig Topper05fe4b52012-01-09 09:19:09 +00002677 case AVX2:
2678 case AVX:
Michael J. Spencera764e832010-10-21 08:22:51 +00002679 case SSE42:
2680 case SSE41:
2681 case SSSE3:
2682 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002683 case SSE2:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002684 Builder.defineMacro("_M_IX86_FP", Twine(2));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002685 break;
2686 case SSE1:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002687 Builder.defineMacro("_M_IX86_FP", Twine(1));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002688 break;
2689 default:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002690 Builder.defineMacro("_M_IX86_FP", Twine(0));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002691 }
2692 }
2693
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002694 // Each case falls through to the previous one here.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002695 switch (MMX3DNowLevel) {
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002696 case AMD3DNowAthlon:
2697 Builder.defineMacro("__3dNOW_A__");
2698 case AMD3DNow:
2699 Builder.defineMacro("__3dNOW__");
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002700 case MMX:
2701 Builder.defineMacro("__MMX__");
2702 case NoMMX3DNow:
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002703 break;
2704 }
Michael J. Spencerd1b33942013-04-04 23:53:43 +00002705
2706 if (CPU >= CK_i486) {
2707 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
2708 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
2709 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
2710 }
2711 if (CPU >= CK_i586)
2712 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
Chris Lattnerc0f59212009-03-02 22:27:17 +00002713}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002714
Douglas Gregore727d212012-01-30 06:38:25 +00002715bool X86TargetInfo::hasFeature(StringRef Feature) const {
2716 return llvm::StringSwitch<bool>(Feature)
2717 .Case("aes", HasAES)
2718 .Case("avx", SSELevel >= AVX)
2719 .Case("avx2", SSELevel >= AVX2)
Craig Topperb7a95d22013-08-21 03:59:22 +00002720 .Case("avx512f", SSELevel >= AVX512F)
Craig Topperbca2c4f2013-08-21 05:29:10 +00002721 .Case("avx512cd", HasAVX512CD)
2722 .Case("avx512er", HasAVX512ER)
2723 .Case("avx512pf", HasAVX512PF)
Douglas Gregore727d212012-01-30 06:38:25 +00002724 .Case("bmi", HasBMI)
2725 .Case("bmi2", HasBMI2)
Craig Topper2ae95072012-06-03 21:46:30 +00002726 .Case("fma", HasFMA)
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002727 .Case("fma4", XOPLevel >= FMA4)
Douglas Gregore727d212012-01-30 06:38:25 +00002728 .Case("lzcnt", HasLZCNT)
Benjamin Kramer84f30802012-07-07 09:39:18 +00002729 .Case("rdrnd", HasRDRND)
Douglas Gregore727d212012-01-30 06:38:25 +00002730 .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
2731 .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
2732 .Case("mmx", MMX3DNowLevel >= MMX)
Craig Topper3c0bc152012-05-31 05:18:48 +00002733 .Case("pclmul", HasPCLMUL)
Douglas Gregore727d212012-01-30 06:38:25 +00002734 .Case("popcnt", HasPOPCNT)
Michael Liao463eb892012-11-10 05:17:46 +00002735 .Case("rtm", HasRTM)
Michael Liao72339a02013-03-26 17:52:08 +00002736 .Case("prfchw", HasPRFCHW)
Michael Liao1bfc28c2013-03-29 05:17:55 +00002737 .Case("rdseed", HasRDSEED)
Douglas Gregore727d212012-01-30 06:38:25 +00002738 .Case("sse", SSELevel >= SSE1)
2739 .Case("sse2", SSELevel >= SSE2)
2740 .Case("sse3", SSELevel >= SSE3)
2741 .Case("ssse3", SSELevel >= SSSE3)
Rafael Espindola81cde9e2013-08-23 20:21:37 +00002742 .Case("sse4.1", SSELevel >= SSE41)
2743 .Case("sse4.2", SSELevel >= SSE42)
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002744 .Case("sse4a", XOPLevel >= SSE4A)
Douglas Gregore727d212012-01-30 06:38:25 +00002745 .Case("x86", true)
Derek Schuffbabaf312012-10-11 15:52:22 +00002746 .Case("x86_32", getTriple().getArch() == llvm::Triple::x86)
2747 .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64)
Rafael Espindolaf6fe72b2013-08-20 13:44:29 +00002748 .Case("xop", XOPLevel >= XOP)
Manman Ren146e5a42012-10-11 00:59:55 +00002749 .Case("f16c", HasF16C)
Douglas Gregore727d212012-01-30 06:38:25 +00002750 .Default(false);
2751}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002752
Eli Friedman618234a2008-08-20 02:34:37 +00002753bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002754X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00002755 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002756 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00002757 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00002758 case 'Y': // first letter of a pair:
2759 switch (*(Name+1)) {
2760 default: return false;
2761 case '0': // First SSE register.
2762 case 't': // Any SSE register, when SSE2 is enabled.
2763 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
2764 case 'm': // any MMX register, when inter-unit moves enabled.
2765 break; // falls through to setAllowsRegister.
2766 }
Eli Friedman618234a2008-08-20 02:34:37 +00002767 case 'a': // eax.
2768 case 'b': // ebx.
2769 case 'c': // ecx.
2770 case 'd': // edx.
2771 case 'S': // esi.
2772 case 'D': // edi.
2773 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00002774 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00002775 case 't': // top of floating point stack.
2776 case 'u': // second from top of floating point stack.
2777 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00002778 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00002779 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00002780 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00002781 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
2782 case 'l': // "Index" registers: any general register that can be used as an
2783 // index in a base+index memory access.
2784 Info.setAllowsRegister();
2785 return true;
2786 case 'C': // SSE floating point constant.
2787 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002788 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00002789 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002790 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00002791 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00002792 return true;
2793 }
2794}
2795
Dale Johannesenf6e2c202010-10-29 23:12:32 +00002796
Eli Friedman618234a2008-08-20 02:34:37 +00002797std::string
Stuart Hastings002333f2011-06-07 23:45:05 +00002798X86TargetInfo::convertConstraint(const char *&Constraint) const {
2799 switch (*Constraint) {
Eli Friedman618234a2008-08-20 02:34:37 +00002800 case 'a': return std::string("{ax}");
2801 case 'b': return std::string("{bx}");
2802 case 'c': return std::string("{cx}");
2803 case 'd': return std::string("{dx}");
2804 case 'S': return std::string("{si}");
2805 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00002806 case 'p': // address
2807 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00002808 case 't': // top of floating point stack.
2809 return std::string("{st}");
2810 case 'u': // second from top of floating point stack.
2811 return std::string("{st(1)}"); // second from top of floating point stack.
2812 default:
Stuart Hastings002333f2011-06-07 23:45:05 +00002813 return std::string(1, *Constraint);
Eli Friedman618234a2008-08-20 02:34:37 +00002814 }
2815}
Eli Friedman618234a2008-08-20 02:34:37 +00002816} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00002817
2818namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00002819// X86-32 generic target
2820class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00002821public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002822 X86_32TargetInfo(const llvm::Triple &Triple) : X86TargetInfo(Triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00002823 DoubleAlign = LongLongAlign = 32;
2824 LongDoubleWidth = 96;
2825 LongDoubleAlign = 32;
Nick Lewycky9bddf432011-12-21 04:25:47 +00002826 SuitableAlign = 128;
Eli Friedmaned855cb2008-08-21 00:13:15 +00002827 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2828 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Lang Hames567c6002011-10-11 00:52:51 +00002829 "a0:0:64-f80:32:32-n8:16:32-S128";
Eli Friedman1afabd92009-03-29 20:31:09 +00002830 SizeType = UnsignedInt;
2831 PtrDiffType = SignedInt;
2832 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00002833 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00002834
2835 // Use fpret for all types.
2836 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
2837 (1 << TargetInfo::Double) |
2838 (1 << TargetInfo::LongDouble));
Eli Friedman2be46072011-10-14 20:59:01 +00002839
2840 // x86-32 has atomics up to 8 bytes
2841 // FIXME: Check that we actually have cmpxchg8b before setting
2842 // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.)
2843 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Eli Friedman618234a2008-08-20 02:34:37 +00002844 }
Meador Ingec5613b22012-06-16 03:34:49 +00002845 virtual BuiltinVaListKind getBuiltinVaListKind() const {
2846 return TargetInfo::CharPtrBuiltinVaList;
Eli Friedman618234a2008-08-20 02:34:37 +00002847 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00002848
Chris Lattner21fb98e2009-09-23 06:06:36 +00002849 int getEHDataRegisterNumber(unsigned RegNo) const {
2850 if (RegNo == 0) return 0;
2851 if (RegNo == 1) return 2;
2852 return -1;
2853 }
Bill Wendling68fd6082012-11-12 06:42:51 +00002854 virtual bool validateInputSize(StringRef Constraint,
2855 unsigned Size) const {
2856 switch (Constraint[0]) {
2857 default: break;
2858 case 'a':
2859 case 'b':
2860 case 'c':
2861 case 'd':
Bill Wendlingf634bdf2012-11-12 18:52:32 +00002862 return Size <= 32;
Bill Wendling68fd6082012-11-12 06:42:51 +00002863 }
2864
2865 return true;
2866 }
Eli Friedman618234a2008-08-20 02:34:37 +00002867};
2868} // end anonymous namespace
2869
2870namespace {
Joerg Sonnenberger42378be2012-01-06 18:32:26 +00002871class NetBSDI386TargetInfo : public NetBSDTargetInfo<X86_32TargetInfo> {
2872public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002873 NetBSDI386TargetInfo(const llvm::Triple &Triple)
2874 : NetBSDTargetInfo<X86_32TargetInfo>(Triple) {}
Joerg Sonnenberger42378be2012-01-06 18:32:26 +00002875
2876 virtual unsigned getFloatEvalMethod() const {
2877 // NetBSD defaults to "double" rounding
2878 return 1;
2879 }
2880};
2881} // end anonymous namespace
2882
2883namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00002884class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
2885public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002886 OpenBSDI386TargetInfo(const llvm::Triple &Triple)
2887 : OpenBSDTargetInfo<X86_32TargetInfo>(Triple) {
Eli Friedman624c1462009-07-05 18:47:56 +00002888 SizeType = UnsignedLong;
2889 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00002890 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00002891 }
2892};
2893} // end anonymous namespace
2894
2895namespace {
Eli Friedman42f74f22012-08-08 23:57:20 +00002896class BitrigI386TargetInfo : public BitrigTargetInfo<X86_32TargetInfo> {
2897public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002898 BitrigI386TargetInfo(const llvm::Triple &Triple)
2899 : BitrigTargetInfo<X86_32TargetInfo>(Triple) {
Eli Friedman42f74f22012-08-08 23:57:20 +00002900 SizeType = UnsignedLong;
2901 IntPtrType = SignedLong;
2902 PtrDiffType = SignedLong;
2903 }
2904};
2905} // end anonymous namespace
2906
2907namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00002908class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00002909public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002910 DarwinI386TargetInfo(const llvm::Triple &Triple)
2911 : DarwinTargetInfo<X86_32TargetInfo>(Triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00002912 LongDoubleWidth = 128;
2913 LongDoubleAlign = 128;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00002914 SuitableAlign = 128;
Chad Rosierf9e9af72012-07-13 23:57:43 +00002915 MaxVectorAlign = 256;
Eli Friedman1afabd92009-03-29 20:31:09 +00002916 SizeType = UnsignedLong;
2917 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00002918 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2919 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002920 "a0:0:64-f80:128:128-n8:16:32-S128";
Daniel Dunbar613fd672010-05-27 00:35:16 +00002921 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00002922 }
2923
Eli Friedman618234a2008-08-20 02:34:37 +00002924};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00002925} // end anonymous namespace
2926
2927namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00002928// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002929class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00002930public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002931 WindowsX86_32TargetInfo(const llvm::Triple &Triple)
2932 : WindowsTargetInfo<X86_32TargetInfo>(Triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00002933 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00002934 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00002935 DoubleAlign = LongLongAlign = 64;
2936 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Anton Korobeynikovb3814412009-12-19 02:05:07 +00002937 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002938 "v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32";
Eli Friedman29a30502008-08-21 01:40:19 +00002939 }
Michael J. Spencera764e832010-10-21 08:22:51 +00002940 virtual void getTargetDefines(const LangOptions &Opts,
2941 MacroBuilder &Builder) const {
2942 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
2943 }
2944};
2945} // end anonymous namespace
2946
2947namespace {
2948
2949// x86-32 Windows Visual Studio target
2950class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
2951public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002952 VisualStudioWindowsX86_32TargetInfo(const llvm::Triple &Triple)
2953 : WindowsX86_32TargetInfo(Triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00002954 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00002955 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
2956 }
2957 virtual void getTargetDefines(const LangOptions &Opts,
2958 MacroBuilder &Builder) const {
2959 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
2960 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
2961 // The value of the following reflects processor type.
2962 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
2963 // We lost the original triple, so we use the default.
2964 Builder.defineMacro("_M_IX86", "600");
2965 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002966};
2967} // end anonymous namespace
2968
2969namespace {
2970// x86-32 MinGW target
2971class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
2972public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00002973 MinGWX86_32TargetInfo(const llvm::Triple &Triple)
2974 : WindowsX86_32TargetInfo(Triple) {}
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002975 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002976 MacroBuilder &Builder) const {
2977 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00002978 DefineStd(Builder, "WIN32", Opts);
2979 DefineStd(Builder, "WINNT", Opts);
2980 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00002981 Builder.defineMacro("__MSVCRT__");
2982 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002983
2984 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
2985 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00002986 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002987 // Provide "as-is" __declspec.
2988 Builder.defineMacro("__declspec", "__declspec");
2989 else
2990 // Provide alias of __attribute__ like mingw32-gcc.
2991 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002992 }
2993};
2994} // end anonymous namespace
2995
2996namespace {
2997// x86-32 Cygwin target
2998class CygwinX86_32TargetInfo : public X86_32TargetInfo {
2999public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003000 CygwinX86_32TargetInfo(const llvm::Triple &Triple)
3001 : X86_32TargetInfo(Triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003002 TLSSupported = false;
3003 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003004 DoubleAlign = LongLongAlign = 64;
3005 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
3006 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003007 "a0:0:64-f80:32:32-n8:16:32-S32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003008 }
3009 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003010 MacroBuilder &Builder) const {
3011 X86_32TargetInfo::getTargetDefines(Opts, Builder);
NAKAMURA Takumie72f4d92012-12-14 10:17:26 +00003012 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00003013 Builder.defineMacro("__CYGWIN__");
3014 Builder.defineMacro("__CYGWIN32__");
3015 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00003016 if (Opts.CPlusPlus)
3017 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00003018 }
Eli Friedman29a30502008-08-21 01:40:19 +00003019};
3020} // end anonymous namespace
3021
3022namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00003023// x86-32 Haiku target
3024class HaikuX86_32TargetInfo : public X86_32TargetInfo {
3025public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003026 HaikuX86_32TargetInfo(const llvm::Triple &Triple) : X86_32TargetInfo(Triple) {
Chris Lattner86ed3a32010-04-11 19:29:39 +00003027 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00003028 IntPtrType = SignedLong;
3029 PtrDiffType = SignedLong;
Eli Friedman6902e412012-11-27 02:58:24 +00003030 ProcessIDType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00003031 this->UserLabelPrefix = "";
Benjamin Krameref7bcea2012-11-08 12:59:15 +00003032 this->TLSSupported = false;
Eli Friedmana7e68452010-08-22 01:00:03 +00003033 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00003034 virtual void getTargetDefines(const LangOptions &Opts,
3035 MacroBuilder &Builder) const {
3036 X86_32TargetInfo::getTargetDefines(Opts, Builder);
3037 Builder.defineMacro("__INTEL__");
3038 Builder.defineMacro("__HAIKU__");
3039 }
3040};
3041} // end anonymous namespace
3042
Douglas Gregordca52262011-07-01 22:41:14 +00003043// RTEMS Target
3044template<typename Target>
3045class RTEMSTargetInfo : public OSTargetInfo<Target> {
3046protected:
3047 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
3048 MacroBuilder &Builder) const {
3049 // RTEMS defines; list based off of gcc output
3050
Douglas Gregordca52262011-07-01 22:41:14 +00003051 Builder.defineMacro("__rtems__");
3052 Builder.defineMacro("__ELF__");
3053 }
Benjamin Kramer9df08232013-06-29 16:37:14 +00003054
Douglas Gregordca52262011-07-01 22:41:14 +00003055public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003056 RTEMSTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
3057 this->UserLabelPrefix = "";
Douglas Gregordca52262011-07-01 22:41:14 +00003058
Benjamin Kramer9df08232013-06-29 16:37:14 +00003059 switch (Triple.getArch()) {
3060 default:
3061 case llvm::Triple::x86:
3062 // this->MCountName = ".mcount";
3063 break;
3064 case llvm::Triple::mips:
3065 case llvm::Triple::mipsel:
3066 case llvm::Triple::ppc:
3067 case llvm::Triple::ppc64:
Bill Schmidtea7fb0c2013-07-26 01:36:11 +00003068 case llvm::Triple::ppc64le:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003069 // this->MCountName = "_mcount";
3070 break;
3071 case llvm::Triple::arm:
3072 // this->MCountName = "__mcount";
3073 break;
Douglas Gregordca52262011-07-01 22:41:14 +00003074 }
Benjamin Kramer9df08232013-06-29 16:37:14 +00003075 }
Douglas Gregordca52262011-07-01 22:41:14 +00003076};
3077
3078namespace {
3079// x86-32 RTEMS target
3080class RTEMSX86_32TargetInfo : public X86_32TargetInfo {
3081public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003082 RTEMSX86_32TargetInfo(const llvm::Triple &Triple) : X86_32TargetInfo(Triple) {
Douglas Gregordca52262011-07-01 22:41:14 +00003083 SizeType = UnsignedLong;
3084 IntPtrType = SignedLong;
3085 PtrDiffType = SignedLong;
3086 this->UserLabelPrefix = "";
3087 }
3088 virtual void getTargetDefines(const LangOptions &Opts,
3089 MacroBuilder &Builder) const {
3090 X86_32TargetInfo::getTargetDefines(Opts, Builder);
3091 Builder.defineMacro("__INTEL__");
3092 Builder.defineMacro("__rtems__");
3093 }
3094};
3095} // end anonymous namespace
3096
Chris Lattner86ed3a32010-04-11 19:29:39 +00003097namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00003098// x86-64 generic target
3099class X86_64TargetInfo : public X86TargetInfo {
3100public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003101 X86_64TargetInfo(const llvm::Triple &Triple) : X86TargetInfo(Triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00003102 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00003103 LongDoubleWidth = 128;
3104 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00003105 LargeArrayMinWidth = 128;
3106 LargeArrayAlign = 128;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00003107 SuitableAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00003108 IntMaxType = SignedLong;
3109 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00003110 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00003111 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00003112
Eli Friedmaned855cb2008-08-21 00:13:15 +00003113 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
3114 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003115 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00003116
3117 // Use fpret only for long double.
3118 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Eli Friedman2be46072011-10-14 20:59:01 +00003119
Anders Carlssoneea64802011-10-31 16:27:11 +00003120 // Use fp2ret for _Complex long double.
3121 ComplexLongDoubleUsesFP2Ret = true;
3122
Eli Friedman2be46072011-10-14 20:59:01 +00003123 // x86-64 has atomics up to 16 bytes.
3124 // FIXME: Once the backend is fixed, increase MaxAtomicInlineWidth to 128
3125 // on CPUs with cmpxchg16b
3126 MaxAtomicPromoteWidth = 128;
3127 MaxAtomicInlineWidth = 64;
Reid Spencer5f016e22007-07-11 17:01:13 +00003128 }
Meador Ingec5613b22012-06-16 03:34:49 +00003129 virtual BuiltinVaListKind getBuiltinVaListKind() const {
3130 return TargetInfo::X86_64ABIBuiltinVaList;
Anders Carlsson3346ae62007-11-24 23:38:12 +00003131 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00003132
Chris Lattner21fb98e2009-09-23 06:06:36 +00003133 int getEHDataRegisterNumber(unsigned RegNo) const {
3134 if (RegNo == 0) return 0;
3135 if (RegNo == 1) return 1;
3136 return -1;
3137 }
Aaron Ballman82bfa192012-10-02 14:26:08 +00003138
3139 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
Charles Davise8519c32013-08-30 04:39:01 +00003140 return (CC == CC_C ||
3141 CC == CC_IntelOclBicc ||
3142 CC == CC_X86_64Win64) ? CCCR_OK : CCCR_Warning;
Aaron Ballman82bfa192012-10-02 14:26:08 +00003143 }
3144
Aaron Ballmanfff32482012-12-09 17:45:41 +00003145 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
3146 return CC_C;
Aaron Ballman82bfa192012-10-02 14:26:08 +00003147 }
3148
Eli Friedman618234a2008-08-20 02:34:37 +00003149};
3150} // end anonymous namespace
3151
3152namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003153// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00003154class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003155public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003156 WindowsX86_64TargetInfo(const llvm::Triple &Triple)
3157 : WindowsTargetInfo<X86_64TargetInfo>(Triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003158 TLSSupported = false;
3159 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00003160 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00003161 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00003162 IntMaxType = SignedLongLong;
3163 UIntMaxType = UnsignedLongLong;
3164 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00003165 SizeType = UnsignedLongLong;
3166 PtrDiffType = SignedLongLong;
3167 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00003168 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003169 }
3170 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003171 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00003172 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00003173 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00003174 }
Meador Ingec5613b22012-06-16 03:34:49 +00003175 virtual BuiltinVaListKind getBuiltinVaListKind() const {
3176 return TargetInfo::CharPtrBuiltinVaList;
NAKAMURA Takumi79521992011-01-17 22:56:23 +00003177 }
Charles Davise8519c32013-08-30 04:39:01 +00003178 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
3179 return (CC == CC_C ||
3180 CC == CC_IntelOclBicc ||
3181 CC == CC_X86_64SysV) ? CCCR_OK : CCCR_Warning;
3182 }
Michael J. Spencera764e832010-10-21 08:22:51 +00003183};
3184} // end anonymous namespace
3185
3186namespace {
3187// x86-64 Windows Visual Studio target
3188class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
3189public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003190 VisualStudioWindowsX86_64TargetInfo(const llvm::Triple &Triple)
3191 : WindowsX86_64TargetInfo(Triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00003192 LongDoubleWidth = LongDoubleAlign = 64;
3193 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00003194 }
3195 virtual void getTargetDefines(const LangOptions &Opts,
3196 MacroBuilder &Builder) const {
3197 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
3198 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00003199 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00003200 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003201 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003202};
3203} // end anonymous namespace
3204
3205namespace {
3206// x86-64 MinGW target
3207class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
3208public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003209 MinGWX86_64TargetInfo(const llvm::Triple &Triple)
3210 : WindowsX86_64TargetInfo(Triple) {}
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003211 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003212 MacroBuilder &Builder) const {
3213 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00003214 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00003215 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00003216 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00003217 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00003218
3219 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
3220 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00003221 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00003222 // Provide "as-is" __declspec.
3223 Builder.defineMacro("__declspec", "__declspec");
3224 else
3225 // Provide alias of __attribute__ like mingw32-gcc.
3226 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003227 }
3228};
3229} // end anonymous namespace
3230
3231namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00003232class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
3233public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003234 DarwinX86_64TargetInfo(const llvm::Triple &Triple)
3235 : DarwinTargetInfo<X86_64TargetInfo>(Triple) {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00003236 Int64Type = SignedLongLong;
Chad Rosierf9e9af72012-07-13 23:57:43 +00003237 MaxVectorAlign = 256;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00003238 }
3239};
3240} // end anonymous namespace
3241
3242namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00003243class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
3244public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003245 OpenBSDX86_64TargetInfo(const llvm::Triple &Triple)
3246 : OpenBSDTargetInfo<X86_64TargetInfo>(Triple) {
Eli Friedman6036ebe2009-07-05 22:31:18 +00003247 IntMaxType = SignedLongLong;
3248 UIntMaxType = UnsignedLongLong;
3249 Int64Type = SignedLongLong;
3250 }
3251};
3252} // end anonymous namespace
3253
3254namespace {
Eli Friedman42f74f22012-08-08 23:57:20 +00003255class BitrigX86_64TargetInfo : public BitrigTargetInfo<X86_64TargetInfo> {
3256public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003257 BitrigX86_64TargetInfo(const llvm::Triple &Triple)
3258 : BitrigTargetInfo<X86_64TargetInfo>(Triple) {
3259 IntMaxType = SignedLongLong;
3260 UIntMaxType = UnsignedLongLong;
3261 Int64Type = SignedLongLong;
Eli Friedman42f74f22012-08-08 23:57:20 +00003262 }
3263};
Tim Northoverc264e162013-01-31 12:13:10 +00003264}
3265
3266namespace {
3267class AArch64TargetInfo : public TargetInfo {
3268 static const char * const GCCRegNames[];
3269 static const TargetInfo::GCCRegAlias GCCRegAliases[];
Tim Northoverff920ee2013-05-04 07:15:13 +00003270
Tim Northoverb793f0d2013-08-01 09:23:19 +00003271 enum FPUModeEnum {
3272 FPUMode,
3273 NeonMode
3274 };
3275
3276 unsigned FPU;
Tim Northoverff920ee2013-05-04 07:15:13 +00003277 static const Builtin::Info BuiltinInfo[];
Tim Northoverb793f0d2013-08-01 09:23:19 +00003278
Tim Northoverc264e162013-01-31 12:13:10 +00003279public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003280 AArch64TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Tim Northoverc264e162013-01-31 12:13:10 +00003281 BigEndian = false;
3282 LongWidth = LongAlign = 64;
3283 LongDoubleWidth = LongDoubleAlign = 128;
3284 PointerWidth = PointerAlign = 64;
3285 SuitableAlign = 128;
3286 DescriptionString = "e-p:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
3287 "i64:64:64-i128:128:128-f32:32:32-f64:64:64-"
3288 "f128:128:128-n32:64-S128";
3289
3290 WCharType = UnsignedInt;
3291 LongDoubleFormat = &llvm::APFloat::IEEEquad;
3292
Tim Northover6a93c862013-02-18 12:11:32 +00003293 // AArch64 backend supports 64-bit operations at the moment. In principle
3294 // 128-bit is possible if register-pairs are used.
3295 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
3296
Tim Northoverc264e162013-01-31 12:13:10 +00003297 TheCXXABI.set(TargetCXXABI::GenericAArch64);
3298 }
3299 virtual void getTargetDefines(const LangOptions &Opts,
3300 MacroBuilder &Builder) const {
3301 // GCC defines theses currently
3302 Builder.defineMacro("__aarch64__");
3303 Builder.defineMacro("__AARCH64EL__");
3304
3305 // ACLE predefines. Many can only have one possible value on v8 AArch64.
3306
3307 // FIXME: these were written based on an unreleased version of a 32-bit ACLE
3308 // which was intended to be compatible with a 64-bit implementation. They
3309 // will need updating when a real 64-bit ACLE exists. Particularly pressing
Tim Northoverdabcbf92013-04-05 14:08:55 +00003310 // instances are: __ARM_ARCH_ISA_ARM, __ARM_ARCH_ISA_THUMB, __ARM_PCS.
3311 Builder.defineMacro("__ARM_ACLE", "101");
3312 Builder.defineMacro("__ARM_ARCH", "8");
3313 Builder.defineMacro("__ARM_ARCH_PROFILE", "'A'");
Tim Northoverc264e162013-01-31 12:13:10 +00003314
Tim Northoverdabcbf92013-04-05 14:08:55 +00003315 Builder.defineMacro("__ARM_FEATURE_UNALIGNED");
3316 Builder.defineMacro("__ARM_FEATURE_CLZ");
3317 Builder.defineMacro("__ARM_FEATURE_FMA");
Tim Northoverc264e162013-01-31 12:13:10 +00003318
3319 // FIXME: ACLE 1.1 reserves bit 4. Will almost certainly come to mean
3320 // 128-bit LDXP present, at which point this becomes 0x1f.
Tim Northoverdabcbf92013-04-05 14:08:55 +00003321 Builder.defineMacro("__ARM_FEATURE_LDREX", "0xf");
Tim Northoverc264e162013-01-31 12:13:10 +00003322
3323 // 0xe implies support for half, single and double precision operations.
Tim Northoverdabcbf92013-04-05 14:08:55 +00003324 Builder.defineMacro("__ARM_FP", "0xe");
Tim Northoverc264e162013-01-31 12:13:10 +00003325
3326 // PCS specifies this for SysV variants, which is all we support. Other ABIs
Tim Northoverdabcbf92013-04-05 14:08:55 +00003327 // may choose __ARM_FP16_FORMAT_ALTERNATIVE.
3328 Builder.defineMacro("__ARM_FP16_FORMAT_IEEE");
Tim Northoverc264e162013-01-31 12:13:10 +00003329
3330 if (Opts.FastMath || Opts.FiniteMathOnly)
Tim Northoverdabcbf92013-04-05 14:08:55 +00003331 Builder.defineMacro("__ARM_FP_FAST");
Tim Northoverc264e162013-01-31 12:13:10 +00003332
3333 if ((Opts.C99 || Opts.C11) && !Opts.Freestanding)
Tim Northoverdabcbf92013-04-05 14:08:55 +00003334 Builder.defineMacro("__ARM_FP_FENV_ROUNDING");
Tim Northoverc264e162013-01-31 12:13:10 +00003335
Tim Northoverdabcbf92013-04-05 14:08:55 +00003336 Builder.defineMacro("__ARM_SIZEOF_WCHAR_T",
Tim Northoverc264e162013-01-31 12:13:10 +00003337 Opts.ShortWChar ? "2" : "4");
3338
Tim Northoverdabcbf92013-04-05 14:08:55 +00003339 Builder.defineMacro("__ARM_SIZEOF_MINIMAL_ENUM",
Tim Northoverc264e162013-01-31 12:13:10 +00003340 Opts.ShortEnums ? "1" : "4");
3341
3342 if (BigEndian)
Tim Northoverb793f0d2013-08-01 09:23:19 +00003343 Builder.defineMacro("__AARCH_BIG_ENDIAN");
3344
3345 if (FPU == NeonMode) {
3346 Builder.defineMacro("__AARCH_FEATURE_ADVSIMD");
3347
3348 // 64-bit NEON supports half, single and double precision operations.
3349 Builder.defineMacro("__AARCH_ADVSIMD_FP", "0xe");
3350 }
Tim Northoverc264e162013-01-31 12:13:10 +00003351 }
3352 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3353 unsigned &NumRecords) const {
Tim Northoverff920ee2013-05-04 07:15:13 +00003354 Records = BuiltinInfo;
3355 NumRecords = clang::AArch64::LastTSBuiltin-Builtin::FirstTSBuiltin;
Tim Northoverc264e162013-01-31 12:13:10 +00003356 }
3357 virtual bool hasFeature(StringRef Feature) const {
Tim Northoverb793f0d2013-08-01 09:23:19 +00003358 return Feature == "aarch64" || (Feature == "neon" && FPU == NeonMode);
Tim Northoverc264e162013-01-31 12:13:10 +00003359 }
Tim Northoverb793f0d2013-08-01 09:23:19 +00003360
Rafael Espindola5389b842013-08-21 21:59:03 +00003361 virtual bool HandleTargetFeatures(std::vector<std::string> &Features,
3362 DiagnosticsEngine &Diags) {
Tim Northoverb793f0d2013-08-01 09:23:19 +00003363 FPU = FPUMode;
3364 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
3365 if (Features[i] == "+neon")
3366 FPU = NeonMode;
3367 }
Rafael Espindola5389b842013-08-21 21:59:03 +00003368 return true;
Tim Northoverb793f0d2013-08-01 09:23:19 +00003369 }
3370
3371 virtual void getGCCRegNames(const char *const *&Names,
Tim Northoverc264e162013-01-31 12:13:10 +00003372 unsigned &NumNames) const;
3373 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3374 unsigned &NumAliases) const;
3375
3376 virtual bool isCLZForZeroUndef() const { return false; }
3377
3378 virtual bool validateAsmConstraint(const char *&Name,
3379 TargetInfo::ConstraintInfo &Info) const {
3380 switch (*Name) {
3381 default: return false;
3382 case 'w': // An FP/SIMD vector register
3383 Info.setAllowsRegister();
3384 return true;
3385 case 'I': // Constant that can be used with an ADD instruction
3386 case 'J': // Constant that can be used with a SUB instruction
3387 case 'K': // Constant that can be used with a 32-bit logical instruction
3388 case 'L': // Constant that can be used with a 64-bit logical instruction
3389 case 'M': // Constant that can be used as a 32-bit MOV immediate
3390 case 'N': // Constant that can be used as a 64-bit MOV immediate
3391 case 'Y': // Floating point constant zero
3392 case 'Z': // Integer constant zero
3393 return true;
3394 case 'Q': // A memory reference with base register and no offset
3395 Info.setAllowsMemory();
3396 return true;
3397 case 'S': // A symbolic address
3398 Info.setAllowsRegister();
3399 return true;
3400 case 'U':
3401 // Ump: A memory address suitable for ldp/stp in SI, DI, SF and DF modes, whatever they may be
3402 // Utf: A memory address suitable for ldp/stp in TF mode, whatever it may be
3403 // Usa: An absolute symbolic address
3404 // Ush: The high part (bits 32:12) of a pc-relative symbolic address
3405 llvm_unreachable("FIXME: Unimplemented support for bizarre constraints");
3406 }
3407 }
3408
3409 virtual const char *getClobbers() const {
3410 // There are no AArch64 clobbers shared by all asm statements.
3411 return "";
3412 }
3413
3414 virtual BuiltinVaListKind getBuiltinVaListKind() const {
3415 return TargetInfo::AArch64ABIBuiltinVaList;
3416 }
3417};
3418
3419const char * const AArch64TargetInfo::GCCRegNames[] = {
3420 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7",
3421 "w8", "w9", "w10", "w11", "w12", "w13", "w14", "w15",
3422 "w16", "w17", "w18", "w19", "w20", "w21", "w22", "w23",
3423 "w24", "w25", "w26", "w27", "w28", "w29", "w30", "wsp", "wzr",
3424
3425 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
3426 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
3427 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
3428 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", "xzr",
3429
3430 "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7",
3431 "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15",
3432 "b16", "b17", "b18", "b19", "b20", "b21", "b22", "b23",
3433 "b24", "b25", "b26", "b27", "b28", "b29", "b30", "b31",
3434
3435 "h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7",
3436 "h8", "h9", "h10", "h11", "h12", "h13", "h14", "h15",
3437 "h16", "h17", "h18", "h19", "h20", "h21", "h22", "h23",
3438 "h24", "h25", "h26", "h27", "h28", "h29", "h30", "h31",
3439
3440 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
3441 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
3442 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
3443 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
3444
3445 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
3446 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
3447 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
3448 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
3449
3450 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
3451 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15",
3452 "q16", "q17", "q18", "q19", "q20", "q21", "q22", "q23",
3453 "q24", "q25", "q26", "q27", "q28", "q29", "q30", "q31"
3454};
3455
3456void AArch64TargetInfo::getGCCRegNames(const char * const *&Names,
3457 unsigned &NumNames) const {
3458 Names = GCCRegNames;
3459 NumNames = llvm::array_lengthof(GCCRegNames);
3460}
3461
3462const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
3463 { { "x16" }, "ip0"},
3464 { { "x17" }, "ip1"},
3465 { { "x29" }, "fp" },
3466 { { "x30" }, "lr" }
3467};
3468
3469void AArch64TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3470 unsigned &NumAliases) const {
3471 Aliases = GCCRegAliases;
3472 NumAliases = llvm::array_lengthof(GCCRegAliases);
3473
3474}
Tim Northoverff920ee2013-05-04 07:15:13 +00003475
3476const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
3477#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
3478#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
3479 ALL_LANGUAGES },
3480#include "clang/Basic/BuiltinsAArch64.def"
3481};
3482
Eli Friedman42f74f22012-08-08 23:57:20 +00003483} // end anonymous namespace
3484
3485namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00003486class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00003487 // Possible FPU choices.
3488 enum FPUMode {
Bob Wilsoncfaab002012-09-29 23:52:52 +00003489 VFP2FPU = (1 << 0),
3490 VFP3FPU = (1 << 1),
3491 VFP4FPU = (1 << 2),
3492 NeonFPU = (1 << 3)
Daniel Dunbara91320b2009-12-21 23:28:17 +00003493 };
3494
3495 static bool FPUModeIsVFP(FPUMode Mode) {
Bob Wilsoncfaab002012-09-29 23:52:52 +00003496 return Mode & (VFP2FPU | VFP3FPU | VFP4FPU | NeonFPU);
Daniel Dunbara91320b2009-12-21 23:28:17 +00003497 }
3498
3499 static const TargetInfo::GCCRegAlias GCCRegAliases[];
3500 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003501
Daniel Dunbareac7c532009-12-18 18:42:37 +00003502 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00003503
Rafael Espindola5389b842013-08-21 21:59:03 +00003504 enum {
3505 FP_Default,
3506 FP_VFP,
3507 FP_Neon
3508 } FPMath;
3509
Bob Wilsoncfaab002012-09-29 23:52:52 +00003510 unsigned FPU : 4;
Daniel Dunbara91320b2009-12-21 23:28:17 +00003511
Logan Chieneae5a8202012-10-10 06:56:20 +00003512 unsigned IsAAPCS : 1;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003513 unsigned IsThumb : 1;
3514
3515 // Initialized via features.
3516 unsigned SoftFloat : 1;
3517 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00003518
Chris Lattner2752c012010-03-03 19:03:45 +00003519 static const Builtin::Info BuiltinInfo[];
3520
Rafael Espindola620c0af2013-05-13 20:09:47 +00003521 static bool shouldUseInlineAtomic(const llvm::Triple &T) {
3522 // On linux, binaries targeting old cpus call functions in libgcc to
3523 // perform atomic operations. The implementation in libgcc then calls into
3524 // the kernel which on armv6 and newer uses ldrex and strex. The net result
3525 // is that if we assume the kernel is at least as recent as the hardware,
3526 // it is safe to use atomic instructions on armv6 and newer.
Rafael Espindolae1e03422013-06-17 20:00:15 +00003527 if (T.getOS() != llvm::Triple::Linux &&
3528 T.getOS() != llvm::Triple::FreeBSD &&
3529 T.getOS() != llvm::Triple::Bitrig)
Ed Schouten04491632013-06-15 09:40:14 +00003530 return false;
Rafael Espindola620c0af2013-05-13 20:09:47 +00003531 StringRef ArchName = T.getArchName();
Rafael Espindola69db5552013-05-14 00:44:24 +00003532 if (T.getArch() == llvm::Triple::arm) {
3533 if (!ArchName.startswith("armv"))
3534 return false;
3535 StringRef VersionStr = ArchName.substr(4);
3536 unsigned Version;
3537 if (VersionStr.getAsInteger(10, Version))
3538 return false;
3539 return Version >= 6;
3540 }
3541 assert(T.getArch() == llvm::Triple::thumb);
3542 if (!ArchName.startswith("thumbv"))
3543 return false;
3544 StringRef VersionStr = ArchName.substr(6);
3545 unsigned Version;
3546 if (VersionStr.getAsInteger(10, Version))
3547 return false;
3548 return Version >= 7;
Rafael Espindola620c0af2013-05-13 20:09:47 +00003549 }
3550
Chris Lattner393ff042008-04-21 18:56:49 +00003551public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00003552 ARMTargetInfo(const llvm::Triple &Triple)
3553 : TargetInfo(Triple), ABI("aapcs-linux"), CPU("arm1136j-s"),
Rafael Espindola5389b842013-08-21 21:59:03 +00003554 FPMath(FP_Default), IsAAPCS(true) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003555 BigEndian = false;
Daniel Dunbara2a41612009-09-14 00:02:24 +00003556 SizeType = UnsignedInt;
3557 PtrDiffType = SignedInt;
James Molloya6d81f92011-11-23 13:35:08 +00003558 // AAPCS 7.1.1, ARM-Linux ABI 2.4: type of wchar_t is unsigned int.
3559 WCharType = UnsignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00003560
Chris Lattner9bffb072010-04-23 16:29:58 +00003561 // {} in inline assembly are neon specifiers, not assembly variant
3562 // specifiers.
3563 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00003564
Daniel Dunbareac7c532009-12-18 18:42:37 +00003565 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00003566 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003567 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00003568 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
3569 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003570 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
3571 "i64:64:64-f32:32:32-f64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003572 "v64:64:64-v128:64:128-a0:0:32-n32-S64");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003573 } else {
3574 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
3575 "i64:64:64-f32:32:32-f64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003576 "v64:64:64-v128:64:128-a0:0:64-n32-S64");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003577 }
John McCallee79a4c2010-08-21 22:46:04 +00003578
3579 // ARM targets default to using the ARM C++ ABI.
John McCallb8b2c9d2013-01-25 22:30:49 +00003580 TheCXXABI.set(TargetCXXABI::GenericARM);
Eli Friedman2be46072011-10-14 20:59:01 +00003581
3582 // ARM has atomics up to 8 bytes
Eli Friedman2be46072011-10-14 20:59:01 +00003583 MaxAtomicPromoteWidth = 64;
Rafael Espindola620c0af2013-05-13 20:09:47 +00003584 if (shouldUseInlineAtomic(getTriple()))
3585 MaxAtomicInlineWidth = 64;
James Molloye45b9b72012-03-12 09:14:10 +00003586
3587 // Do force alignment of members that follow zero length bitfields. If
3588 // the alignment of the zero-length bitfield is greater than the member
3589 // that follows it, `bar', `bar' will be aligned as the type of the
3590 // zero length bitfield.
3591 UseZeroLengthBitfieldAlignment = true;
Eli Friedman61538a72008-05-20 14:21:01 +00003592 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00003593 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00003594 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00003595 ABI = Name;
3596
Daniel Dunbara2a41612009-09-14 00:02:24 +00003597 // The defaults (above) are for AAPCS, check if we need to change them.
3598 //
3599 // FIXME: We need support for -meabi... we could just mangle it into the
3600 // name.
3601 if (Name == "apcs-gnu") {
Nick Lewycky7ec59c72011-12-16 22:34:14 +00003602 DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32;
Rafael Espindola27fa2362012-12-13 04:17:14 +00003603 // size_t is unsigned int on FreeBSD.
3604 if (getTriple().getOS() != llvm::Triple::FreeBSD)
3605 SizeType = UnsignedLong;
Daniel Dunbara2a41612009-09-14 00:02:24 +00003606
James Molloya6d81f92011-11-23 13:35:08 +00003607 // Revert to using SignedInt on apcs-gnu to comply with existing behaviour.
3608 WCharType = SignedInt;
3609
Daniel Dunbar684de632010-04-22 16:14:54 +00003610 // Do not respect the alignment of bit-field types when laying out
3611 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
3612 UseBitFieldTypeAlignment = false;
3613
Chad Rosier61a62212011-08-04 01:21:14 +00003614 /// gcc forces the alignment to 4 bytes, regardless of the type of the
Chad Rosier6e43f3f2011-08-04 17:52:43 +00003615 /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in
3616 /// gcc.
Chad Rosier61a62212011-08-04 01:21:14 +00003617 ZeroLengthBitfieldBoundary = 32;
3618
Logan Chieneae5a8202012-10-10 06:56:20 +00003619 IsAAPCS = false;
3620
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003621 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00003622 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
3623 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003624 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
Bob Wilson949fd1a2011-06-29 16:09:20 +00003625 "i64:32:64-f32:32:32-f64:32:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003626 "v64:32:64-v128:32:128-a0:0:32-n32-S32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003627 } else {
3628 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00003629 "i64:32:64-f32:32:32-f64:32:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00003630 "v64:32:64-v128:32:128-a0:0:32-n32-S32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00003631 }
3632
Chad Rosier9f1210c2011-07-26 07:03:04 +00003633 // FIXME: Override "preferred align" for double and long long.
David Tweedb16abb12012-10-25 13:33:01 +00003634 } else if (Name == "aapcs" || Name == "aapcs-vfp") {
Bob Wilsone4bce7a2013-06-18 05:36:04 +00003635 // size_t is unsigned long on Darwin.
3636 if (getTriple().isOSDarwin())
3637 SizeType = UnsignedLong;
Logan Chieneae5a8202012-10-10 06:56:20 +00003638 IsAAPCS = true;
Daniel Dunbara2a41612009-09-14 00:02:24 +00003639 // FIXME: Enumerated types are variable width in straight AAPCS.
3640 } else if (Name == "aapcs-linux") {
Logan Chieneae5a8202012-10-10 06:56:20 +00003641 IsAAPCS = true;
Daniel Dunbara2a41612009-09-14 00:02:24 +00003642 } else
3643 return false;
3644
3645 return true;
3646 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003647
Chandler Carruthc3a2e652011-09-28 05:56:05 +00003648 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00003649 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
3650 Features["vfp2"] = true;
Bob Wilsoncfaab002012-09-29 23:52:52 +00003651 else if (CPU == "cortex-a8" || CPU == "cortex-a15" ||
3652 CPU == "cortex-a9" || CPU == "cortex-a9-mp")
Daniel Dunbara91320b2009-12-21 23:28:17 +00003653 Features["neon"] = true;
Bob Wilsonfc553452013-03-04 22:37:46 +00003654 else if (CPU == "swift" || CPU == "cortex-a7") {
Bob Wilsoncfaab002012-09-29 23:52:52 +00003655 Features["vfp4"] = true;
3656 Features["neon"] = true;
3657 }
Daniel Dunbara91320b2009-12-21 23:28:17 +00003658 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00003659
Rafael Espindola5389b842013-08-21 21:59:03 +00003660 virtual bool HandleTargetFeatures(std::vector<std::string> &Features,
3661 DiagnosticsEngine &Diags) {
Bob Wilsoncfaab002012-09-29 23:52:52 +00003662 FPU = 0;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003663 SoftFloat = SoftFloatABI = false;
3664 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
3665 if (Features[i] == "+soft-float")
3666 SoftFloat = true;
3667 else if (Features[i] == "+soft-float-abi")
3668 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00003669 else if (Features[i] == "+vfp2")
Bob Wilsoncfaab002012-09-29 23:52:52 +00003670 FPU |= VFP2FPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00003671 else if (Features[i] == "+vfp3")
Bob Wilsoncfaab002012-09-29 23:52:52 +00003672 FPU |= VFP3FPU;
3673 else if (Features[i] == "+vfp4")
3674 FPU |= VFP4FPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00003675 else if (Features[i] == "+neon")
Bob Wilsoncfaab002012-09-29 23:52:52 +00003676 FPU |= NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003677 }
3678
Rafael Espindola5389b842013-08-21 21:59:03 +00003679 if (!(FPU & NeonFPU) && FPMath == FP_Neon) {
3680 Diags.Report(diag::err_target_unsupported_fpmath) << "neon";
3681 return false;
3682 }
3683
3684 if (FPMath == FP_Neon)
3685 Features.push_back("+neonfp");
3686 else if (FPMath == FP_VFP)
3687 Features.push_back("-neonfp");
3688
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003689 // Remove front-end specific options which the backend handles differently.
3690 std::vector<std::string>::iterator it;
3691 it = std::find(Features.begin(), Features.end(), "+soft-float");
3692 if (it != Features.end())
3693 Features.erase(it);
3694 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
3695 if (it != Features.end())
3696 Features.erase(it);
Rafael Espindola5389b842013-08-21 21:59:03 +00003697 return true;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003698 }
3699
Douglas Gregore727d212012-01-30 06:38:25 +00003700 virtual bool hasFeature(StringRef Feature) const {
3701 return llvm::StringSwitch<bool>(Feature)
3702 .Case("arm", true)
3703 .Case("softfloat", SoftFloat)
3704 .Case("thumb", IsThumb)
3705 .Case("neon", FPU == NeonFPU && !SoftFloat &&
3706 StringRef(getCPUDefineSuffix(CPU)).startswith("7"))
3707 .Default(false);
3708 }
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003709 // FIXME: Should we actually have some table instead of these switches?
Chris Lattner5f9e2722011-07-23 10:55:15 +00003710 static const char *getCPUDefineSuffix(StringRef Name) {
Daniel Dunbareac7c532009-12-18 18:42:37 +00003711 return llvm::StringSwitch<const char*>(Name)
3712 .Cases("arm8", "arm810", "4")
3713 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
3714 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
3715 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
3716 .Case("ep9312", "4T")
3717 .Cases("arm10tdmi", "arm1020t", "5T")
3718 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
3719 .Case("arm926ej-s", "5TEJ")
3720 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
3721 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00003722 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00003723 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00003724 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00003725 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
Bob Wilsonfc553452013-03-04 22:37:46 +00003726 .Cases("cortex-a5", "cortex-a7", "cortex-a8", "7A")
3727 .Cases("cortex-a9", "cortex-a15", "7A")
Quentin Colombetab137512012-12-21 17:57:47 +00003728 .Case("cortex-r5", "7R")
Bob Wilson336bfa32012-09-29 23:52:50 +00003729 .Case("cortex-a9-mp", "7F")
3730 .Case("swift", "7S")
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003731 .Cases("cortex-m3", "cortex-m4", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00003732 .Case("cortex-m0", "6M")
Joey Gouly4ec8d5b2013-06-26 17:19:48 +00003733 .Case("cortex-a53", "8A")
Daniel Dunbareac7c532009-12-18 18:42:37 +00003734 .Default(0);
3735 }
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003736 static const char *getCPUProfile(StringRef Name) {
3737 return llvm::StringSwitch<const char*>(Name)
3738 .Cases("cortex-a8", "cortex-a9", "A")
3739 .Cases("cortex-m3", "cortex-m4", "cortex-m0", "M")
Quentin Colombetab137512012-12-21 17:57:47 +00003740 .Case("cortex-r5", "R")
Anton Korobeynikov8b0703d2012-09-08 08:22:13 +00003741 .Default("");
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003742 }
Daniel Dunbareac7c532009-12-18 18:42:37 +00003743 virtual bool setCPU(const std::string &Name) {
3744 if (!getCPUDefineSuffix(Name))
3745 return false;
3746
3747 CPU = Name;
3748 return true;
3749 }
Rafael Espindola5389b842013-08-21 21:59:03 +00003750 virtual bool setFPMath(StringRef Name);
Chris Lattner33328642009-03-20 15:52:06 +00003751 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003752 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00003753 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00003754 Builder.defineMacro("__arm");
3755 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003756
Chris Lattnerc0f59212009-03-02 22:27:17 +00003757 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00003758 Builder.defineMacro("__ARMEL__");
3759 Builder.defineMacro("__LITTLE_ENDIAN__");
3760 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00003761
Chris Lattner5f9e2722011-07-23 10:55:15 +00003762 StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00003763 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003764 Builder.defineMacro("__ARM_ARCH", CPUArch.substr(0, 1));
3765 StringRef CPUProfile = getCPUProfile(CPU);
3766 if (!CPUProfile.empty())
3767 Builder.defineMacro("__ARM_ARCH_PROFILE", CPUProfile);
3768
Mike Stump437bb4b2009-04-08 02:07:04 +00003769 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00003770
Daniel Dunbareac7c532009-12-18 18:42:37 +00003771 // FIXME: It's more complicated than this and we don't really support
3772 // interworking.
3773 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00003774 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00003775
David Tweedb16abb12012-10-25 13:33:01 +00003776 if (ABI == "aapcs" || ABI == "aapcs-linux" || ABI == "aapcs-vfp") {
Daniel Dunbar849289e2012-10-22 18:51:13 +00003777 // M-class CPUs on Darwin follow AAPCS, but not EABI.
Daniel Dunbar4d3ee9b2012-10-22 18:56:43 +00003778 if (!(getTriple().isOSDarwin() && CPUProfile == "M"))
Daniel Dunbar849289e2012-10-22 18:51:13 +00003779 Builder.defineMacro("__ARM_EABI__");
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003780 Builder.defineMacro("__ARM_PCS", "1");
3781
David Tweedb16abb12012-10-25 13:33:01 +00003782 if ((!SoftFloat && !SoftFloatABI) || ABI == "aapcs-vfp")
Anton Korobeynikov70a5cca2012-09-08 08:08:27 +00003783 Builder.defineMacro("__ARM_PCS_VFP", "1");
3784 }
Daniel Dunbareac7c532009-12-18 18:42:37 +00003785
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00003786 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00003787 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00003788
3789 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00003790 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00003791
Bob Wilson84f95cf2011-05-13 18:56:03 +00003792 bool IsARMv7 = CPUArch.startswith("7");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00003793 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00003794 Builder.defineMacro("__THUMBEL__");
3795 Builder.defineMacro("__thumb__");
Bob Wilson84f95cf2011-05-13 18:56:03 +00003796 if (CPUArch == "6T2" || IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00003797 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00003798 }
3799
3800 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00003801 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00003802
Bob Wilsoncfaab002012-09-29 23:52:52 +00003803 if (FPUModeIsVFP((FPUMode) FPU)) {
Benjamin Kramera9992772010-01-09 17:55:51 +00003804 Builder.defineMacro("__VFP_FP__");
Bob Wilsoncfaab002012-09-29 23:52:52 +00003805 if (FPU & VFP2FPU)
3806 Builder.defineMacro("__ARM_VFPV2__");
3807 if (FPU & VFP3FPU)
3808 Builder.defineMacro("__ARM_VFPV3__");
3809 if (FPU & VFP4FPU)
3810 Builder.defineMacro("__ARM_VFPV4__");
3811 }
3812
Daniel Dunbara91320b2009-12-21 23:28:17 +00003813 // This only gets set when Neon instructions are actually available, unlike
3814 // the VFP define, hence the soft float and arch check. This is subtly
3815 // different from gcc, we follow the intent which was that it should be set
3816 // when Neon instructions are actually available.
Bob Wilsoncfaab002012-09-29 23:52:52 +00003817 if ((FPU & NeonFPU) && !SoftFloat && IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00003818 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00003819 }
3820 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3821 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00003822 Records = BuiltinInfo;
3823 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00003824 }
Bob Wilson8b30a932012-01-26 22:14:27 +00003825 virtual bool isCLZForZeroUndef() const { return false; }
Meador Ingec5613b22012-06-16 03:34:49 +00003826 virtual BuiltinVaListKind getBuiltinVaListKind() const {
Logan Chieneae5a8202012-10-10 06:56:20 +00003827 return IsAAPCS ? AAPCSABIBuiltinVaList : TargetInfo::VoidPtrBuiltinVaList;
Chris Lattner393ff042008-04-21 18:56:49 +00003828 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003829 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003830 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003831 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003832 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00003833 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00003834 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00003835 switch (*Name) {
Eric Christophera0dfca12012-08-16 23:50:41 +00003836 default: break;
Nate Begemanad487f42008-04-22 05:03:19 +00003837 case 'l': // r0-r7
3838 case 'h': // r8-r15
3839 case 'w': // VFP Floating point register single precision
3840 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00003841 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00003842 return true;
Eric Christopher895d4222011-07-29 21:20:35 +00003843 case 'Q': // A memory address that is a single base register.
3844 Info.setAllowsMemory();
3845 return true;
Stuart Hastings002333f2011-06-07 23:45:05 +00003846 case 'U': // a memory reference...
3847 switch (Name[1]) {
3848 case 'q': // ...ARMV4 ldrsb
3849 case 'v': // ...VFP load/store (reg+constant offset)
3850 case 'y': // ...iWMMXt load/store
Eric Christopherdda231a2011-06-17 01:40:49 +00003851 case 't': // address valid for load/store opaque types wider
Eric Christopher825d3862012-11-14 22:08:59 +00003852 // than 128-bits
Eric Christopherdda231a2011-06-17 01:40:49 +00003853 case 'n': // valid address for Neon doubleword vector load/store
3854 case 'm': // valid address for Neon element and structure load/store
3855 case 's': // valid address for non-offset loads/stores of quad-word
Eric Christopher825d3862012-11-14 22:08:59 +00003856 // values in four ARM registers
Stuart Hastings002333f2011-06-07 23:45:05 +00003857 Info.setAllowsMemory();
3858 Name++;
3859 return true;
3860 }
Nate Begemanad487f42008-04-22 05:03:19 +00003861 }
Chris Lattner393ff042008-04-21 18:56:49 +00003862 return false;
3863 }
Evan Cheng8bfa2572011-06-16 19:13:15 +00003864 virtual std::string convertConstraint(const char *&Constraint) const {
Stuart Hastings002333f2011-06-07 23:45:05 +00003865 std::string R;
3866 switch (*Constraint) {
3867 case 'U': // Two-character constraint; add "^" hint for later parsing.
Stuart Hastings6ce33d62011-06-08 16:06:31 +00003868 R = std::string("^") + std::string(Constraint, 2);
Stuart Hastings002333f2011-06-07 23:45:05 +00003869 Constraint++;
3870 break;
Eric Christopher283f4472011-06-17 00:40:18 +00003871 case 'p': // 'p' should be translated to 'r' by default.
3872 R = std::string("r");
3873 break;
Stuart Hastings002333f2011-06-07 23:45:05 +00003874 default:
3875 return std::string(1, *Constraint);
3876 }
3877 return R;
3878 }
Bill Wendling50d46ca2012-10-25 23:28:48 +00003879 virtual bool validateConstraintModifier(StringRef Constraint,
3880 const char Modifier,
3881 unsigned Size) const {
Bill Wendlinge2dbaa92012-11-30 23:18:12 +00003882 bool isOutput = (Constraint[0] == '=');
Bill Wendling6e6330c2012-11-30 23:46:56 +00003883 bool isInOut = (Constraint[0] == '+');
Bill Wendlinge2dbaa92012-11-30 23:18:12 +00003884
Bill Wendling50d46ca2012-10-25 23:28:48 +00003885 // Strip off constraint modifiers.
3886 while (Constraint[0] == '=' ||
3887 Constraint[0] == '+' ||
3888 Constraint[0] == '&')
3889 Constraint = Constraint.substr(1);
3890
3891 switch (Constraint[0]) {
3892 default: break;
3893 case 'r': {
3894 switch (Modifier) {
3895 default:
Bob Wilson221a8902013-06-03 23:57:13 +00003896 return (isInOut || isOutput || Size <= 32);
Bill Wendling50d46ca2012-10-25 23:28:48 +00003897 case 'q':
3898 // A register of size 32 cannot fit a vector type.
3899 return false;
3900 }
3901 }
3902 }
3903
3904 return true;
3905 }
Chris Lattner393ff042008-04-21 18:56:49 +00003906 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00003907 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00003908 return "";
3909 }
Aaron Ballman82bfa192012-10-02 14:26:08 +00003910
3911 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
3912 return (CC == CC_AAPCS || CC == CC_AAPCS_VFP) ? CCCR_OK : CCCR_Warning;
3913 }
Logan Chiena8f7a972013-02-23 04:24:36 +00003914
3915 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
3916 if (RegNo == 0) return 0;
3917 if (RegNo == 1) return 1;
3918 return -1;
3919 }
Chris Lattner393ff042008-04-21 18:56:49 +00003920};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003921
Rafael Espindola5389b842013-08-21 21:59:03 +00003922bool ARMTargetInfo::setFPMath(StringRef Name) {
3923 if (Name == "neon") {
3924 FPMath = FP_Neon;
3925 return true;
3926 } else if (Name == "vfp" || Name == "vfp2" || Name == "vfp3" ||
3927 Name == "vfp4") {
3928 FPMath = FP_VFP;
3929 return true;
3930 }
3931 return false;
3932}
3933
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003934const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00003935 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003936 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00003937 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
3938
3939 // Float registers
3940 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
3941 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
3942 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003943 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00003944
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003945 // Double registers
3946 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
3947 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00003948 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
3949 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003950
3951 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00003952 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
3953 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003954};
3955
3956void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00003957 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003958 Names = GCCRegNames;
3959 NumNames = llvm::array_lengthof(GCCRegNames);
3960}
3961
3962const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003963 { { "a1" }, "r0" },
3964 { { "a2" }, "r1" },
3965 { { "a3" }, "r2" },
3966 { { "a4" }, "r3" },
3967 { { "v1" }, "r4" },
3968 { { "v2" }, "r5" },
3969 { { "v3" }, "r6" },
3970 { { "v4" }, "r7" },
3971 { { "v5" }, "r8" },
3972 { { "v6", "rfp" }, "r9" },
3973 { { "sl" }, "r10" },
3974 { { "fp" }, "r11" },
3975 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00003976 { { "r13" }, "sp" },
3977 { { "r14" }, "lr" },
3978 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003979 // The S, D and Q registers overlap, but aren't really aliases; we
3980 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003981};
3982
3983void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3984 unsigned &NumAliases) const {
3985 Aliases = GCCRegAliases;
3986 NumAliases = llvm::array_lengthof(GCCRegAliases);
3987}
Chris Lattner2752c012010-03-03 19:03:45 +00003988
3989const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00003990#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00003991#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00003992 ALL_LANGUAGES },
Chris Lattner2752c012010-03-03 19:03:45 +00003993#include "clang/Basic/BuiltinsARM.def"
3994};
Chris Lattner393ff042008-04-21 18:56:49 +00003995} // end anonymous namespace.
3996
Eli Friedmana9f54962008-08-20 07:44:10 +00003997namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00003998class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00003999 public DarwinTargetInfo<ARMTargetInfo> {
4000protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00004001 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00004002 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00004003 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00004004 }
Eli Friedmana9f54962008-08-20 07:44:10 +00004005
Torok Edwin5f6c1942009-06-30 17:10:35 +00004006public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004007 DarwinARMTargetInfo(const llvm::Triple &Triple)
4008 : DarwinTargetInfo<ARMTargetInfo>(Triple) {
Daniel Dunbar350b9f32010-05-27 07:00:26 +00004009 HasAlignMac68kSupport = true;
Eli Friedman2be46072011-10-14 20:59:01 +00004010 // iOS always has 64-bit atomic instructions.
4011 // FIXME: This should be based off of the target features in ARMTargetInfo.
4012 MaxAtomicInlineWidth = 64;
John McCallb8b2c9d2013-01-25 22:30:49 +00004013
4014 // Darwin on iOS uses a variant of the ARM C++ ABI.
4015 TheCXXABI.set(TargetCXXABI::iOS);
Daniel Dunbar350b9f32010-05-27 07:00:26 +00004016 }
Eli Friedmana9f54962008-08-20 07:44:10 +00004017};
4018} // end anonymous namespace.
4019
Tony Linthicum96319392011-12-12 21:14:55 +00004020
4021namespace {
4022// Hexagon abstract base class
4023class HexagonTargetInfo : public TargetInfo {
4024 static const Builtin::Info BuiltinInfo[];
4025 static const char * const GCCRegNames[];
4026 static const TargetInfo::GCCRegAlias GCCRegAliases[];
4027 std::string CPU;
4028public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004029 HexagonTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00004030 BigEndian = false;
Tony Linthicum96319392011-12-12 21:14:55 +00004031 DescriptionString = ("e-p:32:32:32-"
Anshuman Dasgupta1a090f12013-01-02 21:25:57 +00004032 "i64:64:64-i32:32:32-i16:16:16-i1:32:32-"
Sirish Pande5f9688b2012-05-10 20:19:54 +00004033 "f64:64:64-f32:32:32-a0:0-n32");
Tony Linthicum96319392011-12-12 21:14:55 +00004034
4035 // {} in inline assembly are packet specifiers, not assembly variant
4036 // specifiers.
4037 NoAsmVariants = true;
4038 }
4039
4040 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4041 unsigned &NumRecords) const {
4042 Records = BuiltinInfo;
4043 NumRecords = clang::Hexagon::LastTSBuiltin-Builtin::FirstTSBuiltin;
4044 }
4045
4046 virtual bool validateAsmConstraint(const char *&Name,
4047 TargetInfo::ConstraintInfo &Info) const {
4048 return true;
4049 }
4050
4051 virtual void getTargetDefines(const LangOptions &Opts,
4052 MacroBuilder &Builder) const;
4053
Douglas Gregore727d212012-01-30 06:38:25 +00004054 virtual bool hasFeature(StringRef Feature) const {
4055 return Feature == "hexagon";
4056 }
4057
Meador Ingec5613b22012-06-16 03:34:49 +00004058 virtual BuiltinVaListKind getBuiltinVaListKind() const {
4059 return TargetInfo::CharPtrBuiltinVaList;
Tony Linthicum96319392011-12-12 21:14:55 +00004060 }
4061 virtual void getGCCRegNames(const char * const *&Names,
4062 unsigned &NumNames) const;
4063 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4064 unsigned &NumAliases) const;
4065 virtual const char *getClobbers() const {
4066 return "";
4067 }
Sebastian Pop43115d42012-01-13 20:37:10 +00004068
4069 static const char *getHexagonCPUSuffix(StringRef Name) {
4070 return llvm::StringSwitch<const char*>(Name)
Sebastian Pop43115d42012-01-13 20:37:10 +00004071 .Case("hexagonv4", "4")
Sirish Pande5f9688b2012-05-10 20:19:54 +00004072 .Case("hexagonv5", "5")
Sebastian Pop43115d42012-01-13 20:37:10 +00004073 .Default(0);
4074 }
4075
Tony Linthicum96319392011-12-12 21:14:55 +00004076 virtual bool setCPU(const std::string &Name) {
Sebastian Pop43115d42012-01-13 20:37:10 +00004077 if (!getHexagonCPUSuffix(Name))
4078 return false;
4079
Tony Linthicum96319392011-12-12 21:14:55 +00004080 CPU = Name;
4081 return true;
4082 }
4083};
4084
4085void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
4086 MacroBuilder &Builder) const {
4087 Builder.defineMacro("qdsp6");
4088 Builder.defineMacro("__qdsp6", "1");
4089 Builder.defineMacro("__qdsp6__", "1");
4090
4091 Builder.defineMacro("hexagon");
4092 Builder.defineMacro("__hexagon", "1");
4093 Builder.defineMacro("__hexagon__", "1");
4094
4095 if(CPU == "hexagonv1") {
4096 Builder.defineMacro("__HEXAGON_V1__");
4097 Builder.defineMacro("__HEXAGON_ARCH__", "1");
4098 if(Opts.HexagonQdsp6Compat) {
4099 Builder.defineMacro("__QDSP6_V1__");
4100 Builder.defineMacro("__QDSP6_ARCH__", "1");
4101 }
4102 }
4103 else if(CPU == "hexagonv2") {
4104 Builder.defineMacro("__HEXAGON_V2__");
4105 Builder.defineMacro("__HEXAGON_ARCH__", "2");
4106 if(Opts.HexagonQdsp6Compat) {
4107 Builder.defineMacro("__QDSP6_V2__");
4108 Builder.defineMacro("__QDSP6_ARCH__", "2");
4109 }
4110 }
4111 else if(CPU == "hexagonv3") {
4112 Builder.defineMacro("__HEXAGON_V3__");
4113 Builder.defineMacro("__HEXAGON_ARCH__", "3");
4114 if(Opts.HexagonQdsp6Compat) {
4115 Builder.defineMacro("__QDSP6_V3__");
4116 Builder.defineMacro("__QDSP6_ARCH__", "3");
4117 }
4118 }
4119 else if(CPU == "hexagonv4") {
4120 Builder.defineMacro("__HEXAGON_V4__");
4121 Builder.defineMacro("__HEXAGON_ARCH__", "4");
4122 if(Opts.HexagonQdsp6Compat) {
4123 Builder.defineMacro("__QDSP6_V4__");
4124 Builder.defineMacro("__QDSP6_ARCH__", "4");
4125 }
4126 }
Sirish Pande5f9688b2012-05-10 20:19:54 +00004127 else if(CPU == "hexagonv5") {
4128 Builder.defineMacro("__HEXAGON_V5__");
4129 Builder.defineMacro("__HEXAGON_ARCH__", "5");
4130 if(Opts.HexagonQdsp6Compat) {
4131 Builder.defineMacro("__QDSP6_V5__");
4132 Builder.defineMacro("__QDSP6_ARCH__", "5");
4133 }
4134 }
Tony Linthicum96319392011-12-12 21:14:55 +00004135}
4136
4137const char * const HexagonTargetInfo::GCCRegNames[] = {
4138 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
4139 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
4140 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
4141 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
4142 "p0", "p1", "p2", "p3",
4143 "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp"
4144};
4145
4146void HexagonTargetInfo::getGCCRegNames(const char * const *&Names,
4147 unsigned &NumNames) const {
4148 Names = GCCRegNames;
4149 NumNames = llvm::array_lengthof(GCCRegNames);
4150}
4151
4152
4153const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
4154 { { "sp" }, "r29" },
4155 { { "fp" }, "r30" },
4156 { { "lr" }, "r31" },
4157 };
4158
4159void HexagonTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
4160 unsigned &NumAliases) const {
4161 Aliases = GCCRegAliases;
4162 NumAliases = llvm::array_lengthof(GCCRegAliases);
4163}
4164
4165
4166const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
4167#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
4168#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
4169 ALL_LANGUAGES },
4170#include "clang/Basic/BuiltinsHexagon.def"
4171};
4172}
4173
4174
Reid Spencer5f016e22007-07-11 17:01:13 +00004175namespace {
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004176// Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
4177class SparcTargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00004178 static const TargetInfo::GCCRegAlias GCCRegAliases[];
4179 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00004180 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00004181public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004182 SparcTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {}
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004183
Rafael Espindola5389b842013-08-21 21:59:03 +00004184 virtual bool HandleTargetFeatures(std::vector<std::string> &Features,
4185 DiagnosticsEngine &Diags) {
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00004186 SoftFloat = false;
4187 for (unsigned i = 0, e = Features.size(); i != e; ++i)
4188 if (Features[i] == "+soft-float")
4189 SoftFloat = true;
Rafael Espindola5389b842013-08-21 21:59:03 +00004190 return true;
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00004191 }
Chris Lattner33328642009-03-20 15:52:06 +00004192 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00004193 MacroBuilder &Builder) const {
4194 DefineStd(Builder, "sparc", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00004195 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00004196
4197 if (SoftFloat)
4198 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00004199 }
Douglas Gregore727d212012-01-30 06:38:25 +00004200
4201 virtual bool hasFeature(StringRef Feature) const {
4202 return llvm::StringSwitch<bool>(Feature)
4203 .Case("softfloat", SoftFloat)
4204 .Case("sparc", true)
4205 .Default(false);
4206 }
4207
Gabor Greif26658672008-02-21 16:29:08 +00004208 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4209 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00004210 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00004211 }
Meador Ingec5613b22012-06-16 03:34:49 +00004212 virtual BuiltinVaListKind getBuiltinVaListKind() const {
4213 return TargetInfo::VoidPtrBuiltinVaList;
Gabor Greif26658672008-02-21 16:29:08 +00004214 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00004215 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00004216 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00004217 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00004218 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00004219 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00004220 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00004221 // FIXME: Implement!
4222 return false;
Gabor Greif26658672008-02-21 16:29:08 +00004223 }
4224 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00004225 // FIXME: Implement!
4226 return "";
Gabor Greif26658672008-02-21 16:29:08 +00004227 }
4228};
4229
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004230const char * const SparcTargetInfo::GCCRegNames[] = {
Chris Lattnere957f532009-01-27 01:58:38 +00004231 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
4232 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
4233 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
4234 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
4235};
4236
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004237void SparcTargetInfo::getGCCRegNames(const char * const *&Names,
4238 unsigned &NumNames) const {
Chris Lattnere957f532009-01-27 01:58:38 +00004239 Names = GCCRegNames;
4240 NumNames = llvm::array_lengthof(GCCRegNames);
4241}
4242
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004243const TargetInfo::GCCRegAlias SparcTargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00004244 { { "g0" }, "r0" },
4245 { { "g1" }, "r1" },
4246 { { "g2" }, "r2" },
4247 { { "g3" }, "r3" },
4248 { { "g4" }, "r4" },
4249 { { "g5" }, "r5" },
4250 { { "g6" }, "r6" },
4251 { { "g7" }, "r7" },
4252 { { "o0" }, "r8" },
4253 { { "o1" }, "r9" },
4254 { { "o2" }, "r10" },
4255 { { "o3" }, "r11" },
4256 { { "o4" }, "r12" },
4257 { { "o5" }, "r13" },
4258 { { "o6", "sp" }, "r14" },
4259 { { "o7" }, "r15" },
4260 { { "l0" }, "r16" },
4261 { { "l1" }, "r17" },
4262 { { "l2" }, "r18" },
4263 { { "l3" }, "r19" },
4264 { { "l4" }, "r20" },
4265 { { "l5" }, "r21" },
4266 { { "l6" }, "r22" },
4267 { { "l7" }, "r23" },
4268 { { "i0" }, "r24" },
4269 { { "i1" }, "r25" },
4270 { { "i2" }, "r26" },
4271 { { "i3" }, "r27" },
4272 { { "i4" }, "r28" },
4273 { { "i5" }, "r29" },
4274 { { "i6", "fp" }, "r30" },
4275 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00004276};
4277
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004278void SparcTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
4279 unsigned &NumAliases) const {
Chris Lattnere957f532009-01-27 01:58:38 +00004280 Aliases = GCCRegAliases;
4281 NumAliases = llvm::array_lengthof(GCCRegAliases);
4282}
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004283
4284// SPARC v8 is the 32-bit mode selected by Triple::sparc.
4285class SparcV8TargetInfo : public SparcTargetInfo {
4286public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004287 SparcV8TargetInfo(const llvm::Triple &Triple) : SparcTargetInfo(Triple) {
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004288 // FIXME: Support Sparc quad-precision long double?
4289 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
4290 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32-S64";
4291 }
4292
4293 virtual void getTargetDefines(const LangOptions &Opts,
4294 MacroBuilder &Builder) const {
4295 SparcTargetInfo::getTargetDefines(Opts, Builder);
4296 Builder.defineMacro("__sparcv8");
4297 }
4298};
4299
4300// SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
4301class SparcV9TargetInfo : public SparcTargetInfo {
4302public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004303 SparcV9TargetInfo(const llvm::Triple &Triple) : SparcTargetInfo(Triple) {
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004304 // FIXME: Support Sparc quad-precision long double?
4305 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
4306 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32:64-S128";
Jakob Stoklund Olesenfcec0c92013-05-15 03:22:33 +00004307 // This is an LP64 platform.
4308 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Jakob Stoklund Olesen5ac8c4f2013-05-19 17:53:37 +00004309
4310 // OpenBSD uses long long for int64_t and intmax_t.
4311 if (getTriple().getOS() == llvm::Triple::OpenBSD) {
4312 IntMaxType = SignedLongLong;
4313 UIntMaxType = UnsignedLongLong;
4314 } else {
4315 IntMaxType = SignedLong;
4316 UIntMaxType = UnsignedLong;
4317 }
4318 Int64Type = IntMaxType;
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004319 }
4320
4321 virtual void getTargetDefines(const LangOptions &Opts,
4322 MacroBuilder &Builder) const {
4323 SparcTargetInfo::getTargetDefines(Opts, Builder);
4324 Builder.defineMacro("__sparcv9");
Jakob Stoklund Olesen44f72d32013-04-24 04:36:38 +00004325 Builder.defineMacro("__arch64__");
4326 // Solaris and its derivative AuroraUX don't need these variants, but the
4327 // BSDs do.
4328 if (getTriple().getOS() != llvm::Triple::Solaris &&
4329 getTriple().getOS() != llvm::Triple::AuroraUX) {
4330 Builder.defineMacro("__sparc64__");
4331 Builder.defineMacro("__sparc_v9__");
4332 Builder.defineMacro("__sparcv9__");
4333 }
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00004334 }
4335};
4336
Gabor Greif26658672008-02-21 16:29:08 +00004337} // end anonymous namespace.
4338
Eli Friedman01b86682008-08-20 07:28:14 +00004339namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00004340class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
4341public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004342 AuroraUXSparcV8TargetInfo(const llvm::Triple &Triple)
4343 : AuroraUXTargetInfo<SparcV8TargetInfo>(Triple) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00004344 SizeType = UnsignedInt;
4345 PtrDiffType = SignedInt;
4346 }
4347};
Torok Edwin5f6c1942009-06-30 17:10:35 +00004348class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00004349public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004350 SolarisSparcV8TargetInfo(const llvm::Triple &Triple)
4351 : SolarisTargetInfo<SparcV8TargetInfo>(Triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00004352 SizeType = UnsignedInt;
4353 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00004354 }
4355};
4356} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00004357
Chris Lattner2621fd12008-05-08 05:58:21 +00004358namespace {
Ulrich Weigandb8409212013-05-06 16:26:41 +00004359 class SystemZTargetInfo : public TargetInfo {
4360 static const char *const GCCRegNames[];
4361
4362 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004363 SystemZTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Ulrich Weigandb8409212013-05-06 16:26:41 +00004364 TLSSupported = true;
4365 IntWidth = IntAlign = 32;
4366 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
4367 PointerWidth = PointerAlign = 64;
4368 LongDoubleWidth = 128;
4369 LongDoubleAlign = 64;
4370 LongDoubleFormat = &llvm::APFloat::IEEEquad;
4371 MinGlobalAlign = 16;
4372 DescriptionString = "E-p:64:64:64-i1:8:16-i8:8:16-i16:16-i32:32-i64:64"
4373 "-f32:32-f64:64-f128:64-a0:8:16-n32:64";
4374 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
4375 }
4376 virtual void getTargetDefines(const LangOptions &Opts,
4377 MacroBuilder &Builder) const {
4378 Builder.defineMacro("__s390__");
4379 Builder.defineMacro("__s390x__");
4380 Builder.defineMacro("__zarch__");
4381 Builder.defineMacro("__LONG_DOUBLE_128__");
4382 }
4383 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4384 unsigned &NumRecords) const {
4385 // FIXME: Implement.
4386 Records = 0;
4387 NumRecords = 0;
4388 }
4389
4390 virtual void getGCCRegNames(const char *const *&Names,
4391 unsigned &NumNames) const;
4392 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4393 unsigned &NumAliases) const {
4394 // No aliases.
4395 Aliases = 0;
4396 NumAliases = 0;
4397 }
4398 virtual bool validateAsmConstraint(const char *&Name,
4399 TargetInfo::ConstraintInfo &info) const;
4400 virtual const char *getClobbers() const {
4401 // FIXME: Is this really right?
4402 return "";
4403 }
4404 virtual BuiltinVaListKind getBuiltinVaListKind() const {
4405 return TargetInfo::SystemZBuiltinVaList;
4406 }
Richard Sandiford5c92b9a2013-07-19 16:51:51 +00004407 virtual bool setCPU(const std::string &Name) {
4408 bool CPUKnown = llvm::StringSwitch<bool>(Name)
4409 .Case("z10", true)
4410 .Case("z196", true)
4411 .Case("zEC12", true)
4412 .Default(false);
4413
4414 // No need to store the CPU yet. There aren't any CPU-specific
4415 // macros to define.
4416 return CPUKnown;
4417 }
Ulrich Weigandb8409212013-05-06 16:26:41 +00004418 };
4419
4420 const char *const SystemZTargetInfo::GCCRegNames[] = {
4421 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
4422 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
4423 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
4424 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15"
4425 };
4426
4427 void SystemZTargetInfo::getGCCRegNames(const char *const *&Names,
4428 unsigned &NumNames) const {
4429 Names = GCCRegNames;
4430 NumNames = llvm::array_lengthof(GCCRegNames);
4431 }
4432
4433 bool SystemZTargetInfo::
4434 validateAsmConstraint(const char *&Name,
4435 TargetInfo::ConstraintInfo &Info) const {
4436 switch (*Name) {
4437 default:
4438 return false;
4439
4440 case 'a': // Address register
4441 case 'd': // Data register (equivalent to 'r')
4442 case 'f': // Floating-point register
4443 Info.setAllowsRegister();
4444 return true;
4445
4446 case 'I': // Unsigned 8-bit constant
4447 case 'J': // Unsigned 12-bit constant
4448 case 'K': // Signed 16-bit constant
4449 case 'L': // Signed 20-bit displacement (on all targets we support)
4450 case 'M': // 0x7fffffff
4451 return true;
4452
4453 case 'Q': // Memory with base and unsigned 12-bit displacement
4454 case 'R': // Likewise, plus an index
4455 case 'S': // Memory with base and signed 20-bit displacement
4456 case 'T': // Likewise, plus an index
4457 Info.setAllowsMemory();
4458 return true;
4459 }
4460 }
4461}
4462
4463namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004464 class MSP430TargetInfo : public TargetInfo {
4465 static const char * const GCCRegNames[];
4466 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004467 MSP430TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00004468 BigEndian = false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004469 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00004470 IntWidth = 16; IntAlign = 16;
4471 LongWidth = 32; LongLongWidth = 64;
4472 LongAlign = LongLongAlign = 16;
4473 PointerWidth = 16; PointerAlign = 16;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00004474 SuitableAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004475 SizeType = UnsignedInt;
Anton Korobeynikov18a295d2013-07-01 19:42:40 +00004476 IntMaxType = SignedLongLong;
4477 UIntMaxType = UnsignedLongLong;
4478 IntPtrType = SignedInt;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004479 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00004480 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00004481 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004482 }
4483 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00004484 MacroBuilder &Builder) const {
4485 Builder.defineMacro("MSP430");
4486 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004487 // FIXME: defines for different 'flavours' of MCU
4488 }
4489 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4490 unsigned &NumRecords) const {
4491 // FIXME: Implement.
4492 Records = 0;
4493 NumRecords = 0;
4494 }
Douglas Gregore727d212012-01-30 06:38:25 +00004495 virtual bool hasFeature(StringRef Feature) const {
4496 return Feature == "msp430";
4497 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004498 virtual void getGCCRegNames(const char * const *&Names,
4499 unsigned &NumNames) const;
4500 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4501 unsigned &NumAliases) const {
4502 // No aliases.
4503 Aliases = 0;
4504 NumAliases = 0;
4505 }
4506 virtual bool validateAsmConstraint(const char *&Name,
4507 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00004508 // No target constraints for now.
4509 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004510 }
4511 virtual const char *getClobbers() const {
4512 // FIXME: Is this really right?
4513 return "";
4514 }
Meador Ingec5613b22012-06-16 03:34:49 +00004515 virtual BuiltinVaListKind getBuiltinVaListKind() const {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004516 // FIXME: implement
Meador Ingec5613b22012-06-16 03:34:49 +00004517 return TargetInfo::CharPtrBuiltinVaList;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00004518 }
4519 };
4520
4521 const char * const MSP430TargetInfo::GCCRegNames[] = {
4522 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
4523 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
4524 };
4525
4526 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
4527 unsigned &NumNames) const {
4528 Names = GCCRegNames;
4529 NumNames = llvm::array_lengthof(GCCRegNames);
4530 }
4531}
4532
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00004533namespace {
Eli Friedmanb63decf2009-08-19 20:47:07 +00004534
Mike Stump1eb44332009-09-09 15:08:12 +00004535 // LLVM and Clang cannot be used directly to output native binaries for
4536 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00004537 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00004538 //
4539 // TCE uses the llvm bitcode as input and uses it for generating customized
4540 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00004541 // publicly available in http://tce.cs.tut.fi
4542
Eli Friedman209f5bb2011-10-07 19:51:42 +00004543 static const unsigned TCEOpenCLAddrSpaceMap[] = {
4544 3, // opencl_global
4545 4, // opencl_local
Peter Collingbourne4dc34eb2012-05-20 21:08:35 +00004546 5, // opencl_constant
4547 0, // cuda_device
4548 0, // cuda_constant
4549 0 // cuda_shared
Eli Friedman209f5bb2011-10-07 19:51:42 +00004550 };
4551
Eli Friedmanb63decf2009-08-19 20:47:07 +00004552 class TCETargetInfo : public TargetInfo{
4553 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004554 TCETargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Eli Friedmanb63decf2009-08-19 20:47:07 +00004555 TLSSupported = false;
4556 IntWidth = 32;
4557 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00004558 PointerWidth = 32;
4559 IntAlign = 32;
4560 LongAlign = LongLongAlign = 32;
4561 PointerAlign = 32;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00004562 SuitableAlign = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00004563 SizeType = UnsignedInt;
4564 IntMaxType = SignedLong;
4565 UIntMaxType = UnsignedLong;
4566 IntPtrType = SignedInt;
4567 PtrDiffType = SignedInt;
4568 FloatWidth = 32;
4569 FloatAlign = 32;
4570 DoubleWidth = 32;
4571 DoubleAlign = 32;
4572 LongDoubleWidth = 32;
4573 LongDoubleAlign = 32;
4574 FloatFormat = &llvm::APFloat::IEEEsingle;
4575 DoubleFormat = &llvm::APFloat::IEEEsingle;
4576 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00004577 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
4578 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00004579 "f32:32:32-f64:32:32-v64:32:32-"
4580 "v128:32:32-a0:0:32-n32";
Eli Friedman209f5bb2011-10-07 19:51:42 +00004581 AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
David Tweed1eef8522013-09-13 12:04:22 +00004582 UseAddrSpaceMapMangling = true;
Eli Friedmanb63decf2009-08-19 20:47:07 +00004583 }
4584
4585 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00004586 MacroBuilder &Builder) const {
4587 DefineStd(Builder, "tce", Opts);
4588 Builder.defineMacro("__TCE__");
4589 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00004590 }
Douglas Gregore727d212012-01-30 06:38:25 +00004591 virtual bool hasFeature(StringRef Feature) const {
4592 return Feature == "tce";
4593 }
4594
Eli Friedmanb63decf2009-08-19 20:47:07 +00004595 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4596 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00004597 virtual const char *getClobbers() const {
4598 return "";
4599 }
Meador Ingec5613b22012-06-16 03:34:49 +00004600 virtual BuiltinVaListKind getBuiltinVaListKind() const {
4601 return TargetInfo::VoidPtrBuiltinVaList;
Eli Friedmanb63decf2009-08-19 20:47:07 +00004602 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00004603 virtual void getGCCRegNames(const char * const *&Names,
4604 unsigned &NumNames) const {}
4605 virtual bool validateAsmConstraint(const char *&Name,
4606 TargetInfo::ConstraintInfo &info) const {
4607 return true;
4608 }
4609 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4610 unsigned &NumAliases) const {}
4611 };
4612}
4613
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004614namespace {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004615class MipsTargetInfoBase : public TargetInfo {
Simon Atanasyanfbf70052012-06-28 18:23:16 +00004616 static const Builtin::Info BuiltinInfo[];
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004617 std::string CPU;
Simon Atanasyan1176bcd2012-07-05 16:06:06 +00004618 bool IsMips16;
Simon Atanasyan321ae792013-04-14 14:07:51 +00004619 bool IsMicromips;
Simon Atanasyand96e3152013-04-14 14:07:30 +00004620 bool IsSingleFloat;
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004621 enum MipsFloatABI {
Simon Atanasyand96e3152013-04-14 14:07:30 +00004622 HardFloat, SoftFloat
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004623 } FloatABI;
Simon Atanasyana1b62272012-07-05 20:16:22 +00004624 enum DspRevEnum {
4625 NoDSP, DSP1, DSP2
4626 } DspRev;
Jack Carterc613b672013-08-12 17:20:29 +00004627 bool HasMSA;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004628
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004629protected:
4630 std::string ABI;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004631
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004632public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004633 MipsTargetInfoBase(const llvm::Triple &Triple, const std::string &ABIStr,
4634 const std::string &CPUStr)
4635 : TargetInfo(Triple), CPU(CPUStr), IsMips16(false), IsMicromips(false),
Jack Carterc613b672013-08-12 17:20:29 +00004636 IsSingleFloat(false), FloatABI(HardFloat), DspRev(NoDSP),
4637 HasMSA(false), ABI(ABIStr) {}
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004638
Eric Christophered734732010-03-02 02:41:08 +00004639 virtual const char *getABI() const { return ABI.c_str(); }
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004640 virtual bool setABI(const std::string &Name) = 0;
Eric Christophered734732010-03-02 02:41:08 +00004641 virtual bool setCPU(const std::string &Name) {
4642 CPU = Name;
4643 return true;
4644 }
Chandler Carruthc3a2e652011-09-28 05:56:05 +00004645 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Eric Christophered734732010-03-02 02:41:08 +00004646 Features[ABI] = true;
4647 Features[CPU] = true;
4648 }
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004649
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00004650 virtual void getTargetDefines(const LangOptions &Opts,
4651 MacroBuilder &Builder) const {
Simon Atanasyand4935a02012-08-29 19:14:58 +00004652 DefineStd(Builder, "mips", Opts);
4653 Builder.defineMacro("_mips");
4654 Builder.defineMacro("__REGISTER_PREFIX__", "");
4655
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004656 switch (FloatABI) {
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004657 case HardFloat:
Simon Atanasyan3dbcc882012-06-05 13:06:56 +00004658 Builder.defineMacro("__mips_hard_float", Twine(1));
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004659 break;
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004660 case SoftFloat:
4661 Builder.defineMacro("__mips_soft_float", Twine(1));
4662 break;
Simon Atanasyan3dbcc882012-06-05 13:06:56 +00004663 }
Simon Atanasyan90913892012-04-05 19:28:31 +00004664
Simon Atanasyand96e3152013-04-14 14:07:30 +00004665 if (IsSingleFloat)
4666 Builder.defineMacro("__mips_single_float", Twine(1));
4667
Simon Atanasyan1176bcd2012-07-05 16:06:06 +00004668 if (IsMips16)
4669 Builder.defineMacro("__mips16", Twine(1));
4670
Simon Atanasyan321ae792013-04-14 14:07:51 +00004671 if (IsMicromips)
4672 Builder.defineMacro("__mips_micromips", Twine(1));
4673
Simon Atanasyana1b62272012-07-05 20:16:22 +00004674 switch (DspRev) {
4675 default:
4676 break;
4677 case DSP1:
4678 Builder.defineMacro("__mips_dsp_rev", Twine(1));
4679 Builder.defineMacro("__mips_dsp", Twine(1));
4680 break;
4681 case DSP2:
4682 Builder.defineMacro("__mips_dsp_rev", Twine(2));
4683 Builder.defineMacro("__mips_dspr2", Twine(1));
4684 Builder.defineMacro("__mips_dsp", Twine(1));
4685 break;
4686 }
4687
Jack Carterc613b672013-08-12 17:20:29 +00004688 if (HasMSA)
4689 Builder.defineMacro("__mips_msa", Twine(1));
4690
Simon Atanasyan90913892012-04-05 19:28:31 +00004691 Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
4692 Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
4693 Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
Simon Atanasyan260e5062012-08-29 15:17:29 +00004694
4695 Builder.defineMacro("_MIPS_ARCH", "\"" + CPU + "\"");
4696 Builder.defineMacro("_MIPS_ARCH_" + StringRef(CPU).upper());
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004697 }
4698
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004699 virtual void getTargetBuiltins(const Builtin::Info *&Records,
4700 unsigned &NumRecords) const {
Simon Atanasyanfbf70052012-06-28 18:23:16 +00004701 Records = BuiltinInfo;
4702 NumRecords = clang::Mips::LastTSBuiltin - Builtin::FirstTSBuiltin;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004703 }
Douglas Gregore727d212012-01-30 06:38:25 +00004704 virtual bool hasFeature(StringRef Feature) const {
4705 return Feature == "mips";
4706 }
Meador Ingec5613b22012-06-16 03:34:49 +00004707 virtual BuiltinVaListKind getBuiltinVaListKind() const {
4708 return TargetInfo::VoidPtrBuiltinVaList;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004709 }
4710 virtual void getGCCRegNames(const char * const *&Names,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004711 unsigned &NumNames) const {
4712 static const char * const GCCRegNames[] = {
Eric Christopherd1f853d2012-03-27 19:56:11 +00004713 // CPU register names
4714 // Must match second column of GCCRegAliases
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004715 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
4716 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
4717 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
Eric Christopherd1f853d2012-03-27 19:56:11 +00004718 "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31",
4719 // Floating point register names
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004720 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
4721 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
4722 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
4723 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
Eric Christopherd1f853d2012-03-27 19:56:11 +00004724 // Hi/lo and condition register names
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004725 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
4726 "$fcc5","$fcc6","$fcc7"
4727 };
4728 Names = GCCRegNames;
4729 NumNames = llvm::array_lengthof(GCCRegNames);
4730 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004731 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004732 unsigned &NumAliases) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004733 virtual bool validateAsmConstraint(const char *&Name,
4734 TargetInfo::ConstraintInfo &Info) const {
4735 switch (*Name) {
4736 default:
Douglas Gregor21a25162011-11-02 20:52:01 +00004737 return false;
4738
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004739 case 'r': // CPU registers.
4740 case 'd': // Equivalent to "r" unless generating MIPS16 code.
4741 case 'y': // Equivalent to "r", backwards compatibility only.
4742 case 'f': // floating-point registers.
Eric Christopher0ea61642012-04-03 01:16:32 +00004743 case 'c': // $25 for indirect jumps
4744 case 'l': // lo register
4745 case 'x': // hilo register pair
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004746 Info.setAllowsRegister();
4747 return true;
Jack Carter97102302013-03-05 19:10:54 +00004748 case 'R': // An address that can be used in a non-macro load or store
Jack Carterd2ab6d32013-03-04 21:36:11 +00004749 Info.setAllowsMemory();
4750 return true;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004751 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004752 }
4753
4754 virtual const char *getClobbers() const {
4755 // FIXME: Implement!
4756 return "";
4757 }
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004758
Rafael Espindola5389b842013-08-21 21:59:03 +00004759 virtual bool HandleTargetFeatures(std::vector<std::string> &Features,
4760 DiagnosticsEngine &Diags) {
Simon Atanasyan1176bcd2012-07-05 16:06:06 +00004761 IsMips16 = false;
Simon Atanasyan321ae792013-04-14 14:07:51 +00004762 IsMicromips = false;
Simon Atanasyand96e3152013-04-14 14:07:30 +00004763 IsSingleFloat = false;
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004764 FloatABI = HardFloat;
Simon Atanasyana1b62272012-07-05 20:16:22 +00004765 DspRev = NoDSP;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004766
4767 for (std::vector<std::string>::iterator it = Features.begin(),
4768 ie = Features.end(); it != ie; ++it) {
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004769 if (*it == "+single-float")
Simon Atanasyand96e3152013-04-14 14:07:30 +00004770 IsSingleFloat = true;
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004771 else if (*it == "+soft-float")
4772 FloatABI = SoftFloat;
Simon Atanasyan1176bcd2012-07-05 16:06:06 +00004773 else if (*it == "+mips16")
4774 IsMips16 = true;
Simon Atanasyan321ae792013-04-14 14:07:51 +00004775 else if (*it == "+micromips")
4776 IsMicromips = true;
Simon Atanasyana1b62272012-07-05 20:16:22 +00004777 else if (*it == "+dsp")
4778 DspRev = std::max(DspRev, DSP1);
4779 else if (*it == "+dspr2")
4780 DspRev = std::max(DspRev, DSP2);
Jack Carterc613b672013-08-12 17:20:29 +00004781 else if (*it == "+msa")
4782 HasMSA = true;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004783 }
Simon Atanasyanbbd99162012-07-05 15:32:46 +00004784
4785 // Remove front-end specific option.
4786 std::vector<std::string>::iterator it =
4787 std::find(Features.begin(), Features.end(), "+soft-float");
4788 if (it != Features.end())
4789 Features.erase(it);
Rafael Espindola5389b842013-08-21 21:59:03 +00004790
4791 return true;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004792 }
Logan Chiena8f7a972013-02-23 04:24:36 +00004793
4794 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
4795 if (RegNo == 0) return 4;
4796 if (RegNo == 1) return 5;
4797 return -1;
4798 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004799};
4800
Simon Atanasyanfbf70052012-06-28 18:23:16 +00004801const Builtin::Info MipsTargetInfoBase::BuiltinInfo[] = {
4802#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
4803#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
4804 ALL_LANGUAGES },
4805#include "clang/Basic/BuiltinsMips.def"
4806};
4807
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004808class Mips32TargetInfoBase : public MipsTargetInfoBase {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004809public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004810 Mips32TargetInfoBase(const llvm::Triple &Triple)
4811 : MipsTargetInfoBase(Triple, "o32", "mips32") {
Akira Hatanaka148735e2011-11-05 01:48:34 +00004812 SizeType = UnsignedInt;
4813 PtrDiffType = SignedInt;
Akira Hatanakadbee9492013-01-18 21:58:11 +00004814 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
Akira Hatanaka148735e2011-11-05 01:48:34 +00004815 }
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004816 virtual bool setABI(const std::string &Name) {
4817 if ((Name == "o32") || (Name == "eabi")) {
4818 ABI = Name;
4819 return true;
Simon Atanasyane9616a42013-02-27 14:55:49 +00004820 } else if (Name == "32") {
4821 ABI = "o32";
4822 return true;
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004823 } else
4824 return false;
4825 }
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00004826 virtual void getTargetDefines(const LangOptions &Opts,
4827 MacroBuilder &Builder) const {
4828 MipsTargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004829
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004830 if (ABI == "o32") {
4831 Builder.defineMacro("__mips_o32");
4832 Builder.defineMacro("_ABIO32", "1");
4833 Builder.defineMacro("_MIPS_SIM", "_ABIO32");
4834 }
4835 else if (ABI == "eabi")
4836 Builder.defineMacro("__mips_eabi");
4837 else
David Blaikieb219cfc2011-09-23 05:06:16 +00004838 llvm_unreachable("Invalid ABI for Mips32.");
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004839 }
4840 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4841 unsigned &NumAliases) const {
4842 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
4843 { { "at" }, "$1" },
4844 { { "v0" }, "$2" },
4845 { { "v1" }, "$3" },
4846 { { "a0" }, "$4" },
4847 { { "a1" }, "$5" },
4848 { { "a2" }, "$6" },
4849 { { "a3" }, "$7" },
4850 { { "t0" }, "$8" },
4851 { { "t1" }, "$9" },
4852 { { "t2" }, "$10" },
4853 { { "t3" }, "$11" },
4854 { { "t4" }, "$12" },
4855 { { "t5" }, "$13" },
4856 { { "t6" }, "$14" },
4857 { { "t7" }, "$15" },
4858 { { "s0" }, "$16" },
4859 { { "s1" }, "$17" },
4860 { { "s2" }, "$18" },
4861 { { "s3" }, "$19" },
4862 { { "s4" }, "$20" },
4863 { { "s5" }, "$21" },
4864 { { "s6" }, "$22" },
4865 { { "s7" }, "$23" },
4866 { { "t8" }, "$24" },
4867 { { "t9" }, "$25" },
4868 { { "k0" }, "$26" },
4869 { { "k1" }, "$27" },
4870 { { "gp" }, "$28" },
Eric Christopherd1f853d2012-03-27 19:56:11 +00004871 { { "sp","$sp" }, "$29" },
4872 { { "fp","$fp" }, "$30" },
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004873 { { "ra" }, "$31" }
4874 };
4875 Aliases = GCCRegAliases;
4876 NumAliases = llvm::array_lengthof(GCCRegAliases);
4877 }
4878};
4879
4880class Mips32EBTargetInfo : public Mips32TargetInfoBase {
4881public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004882 Mips32EBTargetInfo(const llvm::Triple &Triple)
4883 : Mips32TargetInfoBase(Triple) {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004884 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00004885 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32-S64";
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004886 }
4887 virtual void getTargetDefines(const LangOptions &Opts,
4888 MacroBuilder &Builder) const {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004889 DefineStd(Builder, "MIPSEB", Opts);
4890 Builder.defineMacro("_MIPSEB");
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00004891 Mips32TargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004892 }
4893};
4894
4895class Mips32ELTargetInfo : public Mips32TargetInfoBase {
4896public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004897 Mips32ELTargetInfo(const llvm::Triple &Triple)
4898 : Mips32TargetInfoBase(Triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00004899 BigEndian = false;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004900 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00004901 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32-S64";
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004902 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004903 virtual void getTargetDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004904 MacroBuilder &Builder) const {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004905 DefineStd(Builder, "MIPSEL", Opts);
4906 Builder.defineMacro("_MIPSEL");
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00004907 Mips32TargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004908 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004909};
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004910
4911class Mips64TargetInfoBase : public MipsTargetInfoBase {
4912 virtual void SetDescriptionString(const std::string &Name) = 0;
4913public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00004914 Mips64TargetInfoBase(const llvm::Triple &Triple)
4915 : MipsTargetInfoBase(Triple, "n64", "mips64") {
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00004916 LongWidth = LongAlign = 64;
4917 PointerWidth = PointerAlign = 64;
4918 LongDoubleWidth = LongDoubleAlign = 128;
4919 LongDoubleFormat = &llvm::APFloat::IEEEquad;
David Chisnall6e399b42012-12-08 09:06:08 +00004920 if (getTriple().getOS() == llvm::Triple::FreeBSD) {
4921 LongDoubleWidth = LongDoubleAlign = 64;
4922 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
4923 }
Nick Lewycky7ec59c72011-12-16 22:34:14 +00004924 SuitableAlign = 128;
Akira Hatanakadbee9492013-01-18 21:58:11 +00004925 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00004926 }
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004927 virtual bool setABI(const std::string &Name) {
4928 SetDescriptionString(Name);
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00004929 if (Name == "n32") {
4930 LongWidth = LongAlign = 32;
4931 PointerWidth = PointerAlign = 32;
Simon Atanasyane9616a42013-02-27 14:55:49 +00004932 ABI = Name;
4933 return true;
4934 } else if (Name == "n64") {
4935 ABI = Name;
4936 return true;
4937 } else if (Name == "64") {
4938 ABI = "n64";
4939 return true;
4940 } else
4941 return false;
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004942 }
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00004943 virtual void getTargetDefines(const LangOptions &Opts,
4944 MacroBuilder &Builder) const {
4945 MipsTargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00004946
Simon Atanasyan600a5132012-08-29 20:50:11 +00004947 Builder.defineMacro("__mips64");
4948 Builder.defineMacro("__mips64__");
4949
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004950 if (ABI == "n32") {
4951 Builder.defineMacro("__mips_n32");
4952 Builder.defineMacro("_ABIN32", "2");
4953 Builder.defineMacro("_MIPS_SIM", "_ABIN32");
4954 }
4955 else if (ABI == "n64") {
4956 Builder.defineMacro("__mips_n64");
4957 Builder.defineMacro("_ABI64", "3");
4958 Builder.defineMacro("_MIPS_SIM", "_ABI64");
4959 }
4960 else
David Blaikieb219cfc2011-09-23 05:06:16 +00004961 llvm_unreachable("Invalid ABI for Mips64.");
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004962 }
4963 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
4964 unsigned &NumAliases) const {
4965 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
4966 { { "at" }, "$1" },
4967 { { "v0" }, "$2" },
4968 { { "v1" }, "$3" },
4969 { { "a0" }, "$4" },
4970 { { "a1" }, "$5" },
4971 { { "a2" }, "$6" },
4972 { { "a3" }, "$7" },
4973 { { "a4" }, "$8" },
4974 { { "a5" }, "$9" },
4975 { { "a6" }, "$10" },
4976 { { "a7" }, "$11" },
4977 { { "t0" }, "$12" },
4978 { { "t1" }, "$13" },
4979 { { "t2" }, "$14" },
4980 { { "t3" }, "$15" },
4981 { { "s0" }, "$16" },
4982 { { "s1" }, "$17" },
4983 { { "s2" }, "$18" },
4984 { { "s3" }, "$19" },
4985 { { "s4" }, "$20" },
4986 { { "s5" }, "$21" },
4987 { { "s6" }, "$22" },
4988 { { "s7" }, "$23" },
4989 { { "t8" }, "$24" },
4990 { { "t9" }, "$25" },
4991 { { "k0" }, "$26" },
4992 { { "k1" }, "$27" },
4993 { { "gp" }, "$28" },
Eric Christopherd1f853d2012-03-27 19:56:11 +00004994 { { "sp","$sp" }, "$29" },
4995 { { "fp","$fp" }, "$30" },
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004996 { { "ra" }, "$31" }
4997 };
4998 Aliases = GCCRegAliases;
4999 NumAliases = llvm::array_lengthof(GCCRegAliases);
5000 }
5001};
5002
5003class Mips64EBTargetInfo : public Mips64TargetInfoBase {
5004 virtual void SetDescriptionString(const std::string &Name) {
5005 // Change DescriptionString only if ABI is n32.
5006 if (Name == "n32")
5007 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00005008 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00005009 "v64:64:64-n32:64-S128";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005010 }
5011public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005012 Mips64EBTargetInfo(const llvm::Triple &Triple)
5013 : Mips64TargetInfoBase(Triple) {
5014 // Default ABI is n64.
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005015 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00005016 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00005017 "v64:64:64-n32:64-S128";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005018 }
5019 virtual void getTargetDefines(const LangOptions &Opts,
5020 MacroBuilder &Builder) const {
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005021 DefineStd(Builder, "MIPSEB", Opts);
5022 Builder.defineMacro("_MIPSEB");
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00005023 Mips64TargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005024 }
5025};
5026
5027class Mips64ELTargetInfo : public Mips64TargetInfoBase {
5028 virtual void SetDescriptionString(const std::string &Name) {
5029 // Change DescriptionString only if ABI is n32.
5030 if (Name == "n32")
5031 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00005032 "i64:64:64-f32:32:32-f64:64:64-f128:128:128"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00005033 "-v64:64:64-n32:64-S128";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005034 }
5035public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005036 Mips64ELTargetInfo(const llvm::Triple &Triple)
5037 : Mips64TargetInfoBase(Triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00005038 // Default ABI is n64.
5039 BigEndian = false;
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005040 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00005041 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
Akira Hatanaka390a70f2013-01-05 02:04:34 +00005042 "v64:64:64-n32:64-S128";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005043 }
5044 virtual void getTargetDefines(const LangOptions &Opts,
5045 MacroBuilder &Builder) const {
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005046 DefineStd(Builder, "MIPSEL", Opts);
5047 Builder.defineMacro("_MIPSEL");
Simon Atanasyan1d8ae1d2012-08-29 19:59:32 +00005048 Mips64TargetInfoBase::getTargetDefines(Opts, Builder);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005049 }
5050};
Edward O'Callaghan84423a82009-11-15 10:22:07 +00005051} // end anonymous namespace.
5052
Ivan Krasinef05abd2011-08-24 20:22:22 +00005053namespace {
5054class PNaClTargetInfo : public TargetInfo {
5055public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005056 PNaClTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00005057 BigEndian = false;
Ivan Krasinef05abd2011-08-24 20:22:22 +00005058 this->UserLabelPrefix = "";
5059 this->LongAlign = 32;
5060 this->LongWidth = 32;
5061 this->PointerAlign = 32;
5062 this->PointerWidth = 32;
5063 this->IntMaxType = TargetInfo::SignedLongLong;
5064 this->UIntMaxType = TargetInfo::UnsignedLongLong;
5065 this->Int64Type = TargetInfo::SignedLongLong;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00005066 this->DoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00005067 this->LongDoubleWidth = 64;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00005068 this->LongDoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00005069 this->SizeType = TargetInfo::UnsignedInt;
5070 this->PtrDiffType = TargetInfo::SignedInt;
5071 this->IntPtrType = TargetInfo::SignedInt;
Eli Benderskyc0783dc2013-04-08 21:31:01 +00005072 this->RegParmMax = 0; // Disallow regparm
Ivan Krasinef05abd2011-08-24 20:22:22 +00005073 DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
5074 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
5075 }
5076
Chandler Carruthc3a2e652011-09-28 05:56:05 +00005077 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Ivan Krasinef05abd2011-08-24 20:22:22 +00005078 }
5079 virtual void getArchDefines(const LangOptions &Opts,
5080 MacroBuilder &Builder) const {
5081 Builder.defineMacro("__le32__");
5082 Builder.defineMacro("__pnacl__");
5083 }
5084 virtual void getTargetDefines(const LangOptions &Opts,
5085 MacroBuilder &Builder) const {
Jan Wen Voungdde3bdb2012-03-29 00:05:59 +00005086 Builder.defineMacro("__LITTLE_ENDIAN__");
Ivan Krasinef05abd2011-08-24 20:22:22 +00005087 getArchDefines(Opts, Builder);
5088 }
Douglas Gregore727d212012-01-30 06:38:25 +00005089 virtual bool hasFeature(StringRef Feature) const {
5090 return Feature == "pnacl";
5091 }
Ivan Krasinef05abd2011-08-24 20:22:22 +00005092 virtual void getTargetBuiltins(const Builtin::Info *&Records,
5093 unsigned &NumRecords) const {
5094 }
Meador Ingec5613b22012-06-16 03:34:49 +00005095 virtual BuiltinVaListKind getBuiltinVaListKind() const {
5096 return TargetInfo::PNaClABIBuiltinVaList;
Ivan Krasinef05abd2011-08-24 20:22:22 +00005097 }
5098 virtual void getGCCRegNames(const char * const *&Names,
5099 unsigned &NumNames) const;
5100 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
5101 unsigned &NumAliases) const;
5102 virtual bool validateAsmConstraint(const char *&Name,
5103 TargetInfo::ConstraintInfo &Info) const {
5104 return false;
5105 }
5106
5107 virtual const char *getClobbers() const {
5108 return "";
5109 }
5110};
5111
5112void PNaClTargetInfo::getGCCRegNames(const char * const *&Names,
5113 unsigned &NumNames) const {
5114 Names = NULL;
5115 NumNames = 0;
5116}
5117
5118void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
5119 unsigned &NumAliases) const {
5120 Aliases = NULL;
5121 NumAliases = 0;
5122}
5123} // end anonymous namespace.
5124
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005125namespace {
5126 static const unsigned SPIRAddrSpaceMap[] = {
5127 1, // opencl_global
5128 3, // opencl_local
5129 2, // opencl_constant
5130 0, // cuda_device
5131 0, // cuda_constant
5132 0 // cuda_shared
5133 };
5134 class SPIRTargetInfo : public TargetInfo {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005135 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005136 SPIRTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005137 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
5138 "SPIR target must use unknown OS");
5139 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
5140 "SPIR target must use unknown environment type");
5141 BigEndian = false;
5142 TLSSupported = false;
5143 LongWidth = LongAlign = 64;
5144 AddrSpaceMap = &SPIRAddrSpaceMap;
David Tweed1eef8522013-09-13 12:04:22 +00005145 UseAddrSpaceMapMangling = true;
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005146 // Define available target features
5147 // These must be defined in sorted order!
5148 NoAsmVariants = true;
5149 }
5150 virtual void getTargetDefines(const LangOptions &Opts,
5151 MacroBuilder &Builder) const {
5152 DefineStd(Builder, "SPIR", Opts);
5153 }
5154 virtual bool hasFeature(StringRef Feature) const {
5155 return Feature == "spir";
5156 }
5157
5158 virtual void getTargetBuiltins(const Builtin::Info *&Records,
5159 unsigned &NumRecords) const {}
5160 virtual const char *getClobbers() const {
5161 return "";
5162 }
5163 virtual void getGCCRegNames(const char * const *&Names,
5164 unsigned &NumNames) const {}
5165 virtual bool validateAsmConstraint(const char *&Name,
5166 TargetInfo::ConstraintInfo &info) const {
5167 return true;
5168 }
5169 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
5170 unsigned &NumAliases) const {}
5171 virtual BuiltinVaListKind getBuiltinVaListKind() const {
5172 return TargetInfo::VoidPtrBuiltinVaList;
5173 }
5174 };
5175
5176
5177 class SPIR32TargetInfo : public SPIRTargetInfo {
5178 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005179 SPIR32TargetInfo(const llvm::Triple &Triple) : SPIRTargetInfo(Triple) {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005180 PointerWidth = PointerAlign = 32;
5181 SizeType = TargetInfo::UnsignedInt;
5182 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
5183 DescriptionString
Guy Benyeif3ddf632013-03-07 13:06:10 +00005184 = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005185 "f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-"
5186 "v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-"
5187 "v512:512:512-v1024:1024:1024";
Guy Benyeif3ddf632013-03-07 13:06:10 +00005188 }
5189 virtual void getTargetDefines(const LangOptions &Opts,
5190 MacroBuilder &Builder) const {
5191 DefineStd(Builder, "SPIR32", Opts);
5192 }
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005193 };
5194
5195 class SPIR64TargetInfo : public SPIRTargetInfo {
5196 public:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005197 SPIR64TargetInfo(const llvm::Triple &Triple) : SPIRTargetInfo(Triple) {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005198 PointerWidth = PointerAlign = 64;
5199 SizeType = TargetInfo::UnsignedLong;
5200 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
5201 DescriptionString
Guy Benyeif3ddf632013-03-07 13:06:10 +00005202 = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005203 "f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-"
5204 "v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-"
5205 "v512:512:512-v1024:1024:1024";
Guy Benyeif3ddf632013-03-07 13:06:10 +00005206 }
5207 virtual void getTargetDefines(const LangOptions &Opts,
5208 MacroBuilder &Builder) const {
5209 DefineStd(Builder, "SPIR64", Opts);
5210 }
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005211 };
5212}
5213
Robert Lytton5f15f4d2013-08-13 09:43:10 +00005214namespace {
5215class XCoreTargetInfo : public TargetInfo {
5216 static const Builtin::Info BuiltinInfo[];
5217public:
5218 XCoreTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
5219 BigEndian = false;
5220 NoAsmVariants = true;
5221 LongLongAlign = 32;
5222 SuitableAlign = 32;
5223 DoubleAlign = LongDoubleAlign = 32;
5224 UseZeroLengthBitfieldAlignment = true;
5225 DescriptionString = "e-p:32:32:32-a0:0:32-n32"
5226 "-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32"
5227 "-f16:16:32-f32:32:32-f64:32:32";
5228 }
5229 virtual void getTargetDefines(const LangOptions &Opts,
5230 MacroBuilder &Builder) const {
5231 Builder.defineMacro("__XS1B__");
5232 }
5233 virtual void getTargetBuiltins(const Builtin::Info *&Records,
5234 unsigned &NumRecords) const {
5235 Records = BuiltinInfo;
5236 NumRecords = clang::XCore::LastTSBuiltin-Builtin::FirstTSBuiltin;
5237 }
5238 virtual BuiltinVaListKind getBuiltinVaListKind() const {
5239 return TargetInfo::VoidPtrBuiltinVaList;
5240 }
5241 virtual const char *getClobbers() const {
5242 return "";
5243 }
5244 virtual void getGCCRegNames(const char * const *&Names,
5245 unsigned &NumNames) const {
5246 static const char * const GCCRegNames[] = {
5247 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
5248 "r8", "r9", "r10", "r11", "cp", "dp", "sp", "lr"
5249 };
5250 Names = GCCRegNames;
5251 NumNames = llvm::array_lengthof(GCCRegNames);
5252 }
5253 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
5254 unsigned &NumAliases) const {
5255 Aliases = NULL;
5256 NumAliases = 0;
5257 }
5258 virtual bool validateAsmConstraint(const char *&Name,
5259 TargetInfo::ConstraintInfo &Info) const {
5260 return false;
5261 }
5262};
5263
5264const Builtin::Info XCoreTargetInfo::BuiltinInfo[] = {
5265#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
5266#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
5267 ALL_LANGUAGES },
5268#include "clang/Basic/BuiltinsXCore.def"
5269};
5270} // end anonymous namespace.
5271
Ivan Krasinef05abd2011-08-24 20:22:22 +00005272
Reid Spencer5f016e22007-07-11 17:01:13 +00005273//===----------------------------------------------------------------------===//
5274// Driver code
5275//===----------------------------------------------------------------------===//
5276
Benjamin Kramer9df08232013-06-29 16:37:14 +00005277static TargetInfo *AllocateTarget(const llvm::Triple &Triple) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005278 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00005279
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005280 switch (Triple.getArch()) {
5281 default:
5282 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00005283
Robert Lytton5f15f4d2013-08-13 09:43:10 +00005284 case llvm::Triple::xcore:
5285 return new XCoreTargetInfo(Triple);
5286
Tony Linthicum96319392011-12-12 21:14:55 +00005287 case llvm::Triple::hexagon:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005288 return new HexagonTargetInfo(Triple);
Tony Linthicum96319392011-12-12 21:14:55 +00005289
Tim Northoverc264e162013-01-31 12:13:10 +00005290 case llvm::Triple::aarch64:
5291 switch (os) {
5292 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005293 return new LinuxTargetInfo<AArch64TargetInfo>(Triple);
Tim Northoverc264e162013-01-31 12:13:10 +00005294 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005295 return new AArch64TargetInfo(Triple);
Tim Northoverc264e162013-01-31 12:13:10 +00005296 }
5297
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005298 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00005299 case llvm::Triple::thumb:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005300 if (Triple.isOSDarwin())
Benjamin Kramer9df08232013-06-29 16:37:14 +00005301 return new DarwinARMTargetInfo(Triple);
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005302
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005303 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00005304 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005305 return new LinuxTargetInfo<ARMTargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005306 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005307 return new FreeBSDTargetInfo<ARMTargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005308 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005309 return new NetBSDTargetInfo<ARMTargetInfo>(Triple);
Hans Wennborg5e601dc2012-08-02 13:45:48 +00005310 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005311 return new OpenBSDTargetInfo<ARMTargetInfo>(Triple);
Eli Friedman42f74f22012-08-08 23:57:20 +00005312 case llvm::Triple::Bitrig:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005313 return new BitrigTargetInfo<ARMTargetInfo>(Triple);
Douglas Gregordca52262011-07-01 22:41:14 +00005314 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005315 return new RTEMSTargetInfo<ARMTargetInfo>(Triple);
Eli Bendersky441d9f72012-12-04 18:38:10 +00005316 case llvm::Triple::NaCl:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005317 return new NaClTargetInfo<ARMTargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005318 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005319 return new ARMTargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005320 }
Eli Friedman61538a72008-05-20 14:21:01 +00005321
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005322 case llvm::Triple::msp430:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005323 return new MSP430TargetInfo(Triple);
Eli Friedman61538a72008-05-20 14:21:01 +00005324
Edward O'Callaghan84423a82009-11-15 10:22:07 +00005325 case llvm::Triple::mips:
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005326 switch (os) {
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005327 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005328 return new LinuxTargetInfo<Mips32EBTargetInfo>(Triple);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005329 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005330 return new RTEMSTargetInfo<Mips32EBTargetInfo>(Triple);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005331 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005332 return new FreeBSDTargetInfo<Mips32EBTargetInfo>(Triple);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005333 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005334 return new NetBSDTargetInfo<Mips32EBTargetInfo>(Triple);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005335 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005336 return new Mips32EBTargetInfo(Triple);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00005337 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00005338
5339 case llvm::Triple::mipsel:
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005340 switch (os) {
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005341 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005342 return new LinuxTargetInfo<Mips32ELTargetInfo>(Triple);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005343 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005344 return new RTEMSTargetInfo<Mips32ELTargetInfo>(Triple);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005345 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005346 return new FreeBSDTargetInfo<Mips32ELTargetInfo>(Triple);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005347 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005348 return new NetBSDTargetInfo<Mips32ELTargetInfo>(Triple);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005349 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005350 return new Mips32ELTargetInfo(Triple);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00005351 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00005352
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005353 case llvm::Triple::mips64:
5354 switch (os) {
5355 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005356 return new LinuxTargetInfo<Mips64EBTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005357 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005358 return new RTEMSTargetInfo<Mips64EBTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005359 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005360 return new FreeBSDTargetInfo<Mips64EBTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005361 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005362 return new NetBSDTargetInfo<Mips64EBTargetInfo>(Triple);
Hans Wennborg5e601dc2012-08-02 13:45:48 +00005363 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005364 return new OpenBSDTargetInfo<Mips64EBTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005365 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005366 return new Mips64EBTargetInfo(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005367 }
5368
5369 case llvm::Triple::mips64el:
5370 switch (os) {
5371 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005372 return new LinuxTargetInfo<Mips64ELTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005373 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005374 return new RTEMSTargetInfo<Mips64ELTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005375 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005376 return new FreeBSDTargetInfo<Mips64ELTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005377 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005378 return new NetBSDTargetInfo<Mips64ELTargetInfo>(Triple);
Hans Wennborg5e601dc2012-08-02 13:45:48 +00005379 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005380 return new OpenBSDTargetInfo<Mips64ELTargetInfo>(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005381 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005382 return new Mips64ELTargetInfo(Triple);
Akira Hatanakabf5851a2011-09-20 19:21:49 +00005383 }
5384
Ivan Krasinef05abd2011-08-24 20:22:22 +00005385 case llvm::Triple::le32:
5386 switch (os) {
Eli Bendersky441d9f72012-12-04 18:38:10 +00005387 case llvm::Triple::NaCl:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005388 return new NaClTargetInfo<PNaClTargetInfo>(Triple);
Ivan Krasinef05abd2011-08-24 20:22:22 +00005389 default:
5390 return NULL;
5391 }
5392
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005393 case llvm::Triple::ppc:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005394 if (Triple.isOSDarwin())
Benjamin Kramer9df08232013-06-29 16:37:14 +00005395 return new DarwinPPC32TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005396 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00005397 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005398 return new LinuxTargetInfo<PPC32TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005399 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005400 return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005401 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005402 return new NetBSDTargetInfo<PPC32TargetInfo>(Triple);
Hans Wennborg5e601dc2012-08-02 13:45:48 +00005403 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005404 return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005405 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005406 return new RTEMSTargetInfo<PPC32TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005407 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005408 return new PPC32TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005409 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005410
5411 case llvm::Triple::ppc64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005412 if (Triple.isOSDarwin())
Benjamin Kramer9df08232013-06-29 16:37:14 +00005413 return new DarwinPPC64TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005414 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00005415 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005416 return new LinuxTargetInfo<PPC64TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005417 case llvm::Triple::Lv2:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005418 return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005419 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005420 return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005421 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005422 return new NetBSDTargetInfo<PPC64TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005423 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005424 return new PPC64TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005425 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005426
Bill Schmidtea7fb0c2013-07-26 01:36:11 +00005427 case llvm::Triple::ppc64le:
5428 switch (os) {
5429 case llvm::Triple::Linux:
5430 return new LinuxTargetInfo<PPC64TargetInfo>(Triple);
5431 default:
5432 return new PPC64TargetInfo(Triple);
5433 }
5434
Peter Collingbourneedb66f32012-05-20 23:28:41 +00005435 case llvm::Triple::nvptx:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005436 return new NVPTX32TargetInfo(Triple);
Peter Collingbourneedb66f32012-05-20 23:28:41 +00005437 case llvm::Triple::nvptx64:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005438 return new NVPTX64TargetInfo(Triple);
Peter Collingbourneedb66f32012-05-20 23:28:41 +00005439
Eli Friedman6505a292012-10-12 23:32:00 +00005440 case llvm::Triple::r600:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005441 return new R600TargetInfo(Triple);
Eli Friedman6505a292012-10-12 23:32:00 +00005442
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005443 case llvm::Triple::sparc:
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005444 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00005445 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005446 return new LinuxTargetInfo<SparcV8TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005447 case llvm::Triple::AuroraUX:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005448 return new AuroraUXSparcV8TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005449 case llvm::Triple::Solaris:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005450 return new SolarisSparcV8TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005451 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005452 return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple);
Hans Wennborg5e601dc2012-08-02 13:45:48 +00005453 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005454 return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005455 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005456 return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005457 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005458 return new SparcV8TargetInfo(Triple);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00005459 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005460
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005461 case llvm::Triple::sparcv9:
5462 switch (os) {
5463 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005464 return new LinuxTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005465 case llvm::Triple::AuroraUX:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005466 return new AuroraUXTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005467 case llvm::Triple::Solaris:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005468 return new SolarisTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005469 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005470 return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005471 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005472 return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005473 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005474 return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005475 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005476 return new SparcV9TargetInfo(Triple);
Jakob Stoklund Olesen56e1f1f2013-04-16 15:17:49 +00005477 }
5478
Ulrich Weigandb8409212013-05-06 16:26:41 +00005479 case llvm::Triple::systemz:
5480 switch (os) {
5481 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005482 return new LinuxTargetInfo<SystemZTargetInfo>(Triple);
Ulrich Weigandb8409212013-05-06 16:26:41 +00005483 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005484 return new SystemZTargetInfo(Triple);
Ulrich Weigandb8409212013-05-06 16:26:41 +00005485 }
5486
Eli Friedmanb63decf2009-08-19 20:47:07 +00005487 case llvm::Triple::tce:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005488 return new TCETargetInfo(Triple);
Eli Friedmanb63decf2009-08-19 20:47:07 +00005489
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005490 case llvm::Triple::x86:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005491 if (Triple.isOSDarwin())
Benjamin Kramer9df08232013-06-29 16:37:14 +00005492 return new DarwinI386TargetInfo(Triple);
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005493
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005494 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00005495 case llvm::Triple::AuroraUX:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005496 return new AuroraUXTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005497 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005498 return new LinuxTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005499 case llvm::Triple::DragonFly:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005500 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005501 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005502 return new NetBSDI386TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005503 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005504 return new OpenBSDI386TargetInfo(Triple);
Eli Friedman42f74f22012-08-08 23:57:20 +00005505 case llvm::Triple::Bitrig:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005506 return new BitrigI386TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005507 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005508 return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple);
Sylvestre Ledru3309a782013-09-05 13:47:07 +00005509 case llvm::Triple::KFreeBSD:
5510 return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple);
Chris Lattner38e317d2010-07-07 16:01:42 +00005511 case llvm::Triple::Minix:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005512 return new MinixTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005513 case llvm::Triple::Solaris:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005514 return new SolarisTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005515 case llvm::Triple::Cygwin:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005516 return new CygwinX86_32TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005517 case llvm::Triple::MinGW32:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005518 return new MinGWX86_32TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005519 case llvm::Triple::Win32:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005520 return new VisualStudioWindowsX86_32TargetInfo(Triple);
Chris Lattner86ed3a32010-04-11 19:29:39 +00005521 case llvm::Triple::Haiku:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005522 return new HaikuX86_32TargetInfo(Triple);
Douglas Gregordca52262011-07-01 22:41:14 +00005523 case llvm::Triple::RTEMS:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005524 return new RTEMSX86_32TargetInfo(Triple);
Eli Bendersky441d9f72012-12-04 18:38:10 +00005525 case llvm::Triple::NaCl:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005526 return new NaClTargetInfo<X86_32TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005527 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005528 return new X86_32TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005529 }
5530
5531 case llvm::Triple::x86_64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005532 if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO)
Benjamin Kramer9df08232013-06-29 16:37:14 +00005533 return new DarwinX86_64TargetInfo(Triple);
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00005534
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005535 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00005536 case llvm::Triple::AuroraUX:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005537 return new AuroraUXTargetInfo<X86_64TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005538 case llvm::Triple::Linux:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005539 return new LinuxTargetInfo<X86_64TargetInfo>(Triple);
Chris Lattner7a7ca282010-01-09 05:41:14 +00005540 case llvm::Triple::DragonFly:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005541 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005542 case llvm::Triple::NetBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005543 return new NetBSDTargetInfo<X86_64TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005544 case llvm::Triple::OpenBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005545 return new OpenBSDX86_64TargetInfo(Triple);
Eli Friedman42f74f22012-08-08 23:57:20 +00005546 case llvm::Triple::Bitrig:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005547 return new BitrigX86_64TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005548 case llvm::Triple::FreeBSD:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005549 return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple);
Sylvestre Ledru3309a782013-09-05 13:47:07 +00005550 case llvm::Triple::KFreeBSD:
5551 return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005552 case llvm::Triple::Solaris:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005553 return new SolarisTargetInfo<X86_64TargetInfo>(Triple);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00005554 case llvm::Triple::MinGW32:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005555 return new MinGWX86_64TargetInfo(Triple);
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00005556 case llvm::Triple::Win32: // This is what Triple.h supports now.
Benjamin Kramer9df08232013-06-29 16:37:14 +00005557 return new VisualStudioWindowsX86_64TargetInfo(Triple);
Eli Bendersky441d9f72012-12-04 18:38:10 +00005558 case llvm::Triple::NaCl:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005559 return new NaClTargetInfo<X86_64TargetInfo>(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005560 default:
Benjamin Kramer9df08232013-06-29 16:37:14 +00005561 return new X86_64TargetInfo(Triple);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005562 }
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005563
5564 case llvm::Triple::spir: {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005565 if (Triple.getOS() != llvm::Triple::UnknownOS ||
Benjamin Kramer9df08232013-06-29 16:37:14 +00005566 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005567 return NULL;
Benjamin Kramer9df08232013-06-29 16:37:14 +00005568 return new SPIR32TargetInfo(Triple);
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005569 }
5570 case llvm::Triple::spir64: {
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005571 if (Triple.getOS() != llvm::Triple::UnknownOS ||
Benjamin Kramer9df08232013-06-29 16:37:14 +00005572 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005573 return NULL;
Benjamin Kramer9df08232013-06-29 16:37:14 +00005574 return new SPIR64TargetInfo(Triple);
Guy Benyeibd5da3c2012-12-11 21:38:14 +00005575 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00005576 }
Reid Spencer5f016e22007-07-11 17:01:13 +00005577}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005578
5579/// CreateTargetInfo - Return the target info object for the specified target
5580/// triple.
David Blaikied6471f72011-09-25 23:23:43 +00005581TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
Douglas Gregor49a87542012-11-16 04:24:59 +00005582 TargetOptions *Opts) {
5583 llvm::Triple Triple(Opts->Triple);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005584
5585 // Construct the target
Benjamin Kramer9df08232013-06-29 16:37:14 +00005586 OwningPtr<TargetInfo> Target(AllocateTarget(Triple));
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005587 if (!Target) {
5588 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
5589 return 0;
5590 }
Douglas Gregor9a022bb2012-10-15 16:45:32 +00005591 Target->setTargetOpts(Opts);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005592
Daniel Dunbareac7c532009-12-18 18:42:37 +00005593 // Set the target CPU if specified.
Douglas Gregor49a87542012-11-16 04:24:59 +00005594 if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
5595 Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
Daniel Dunbareac7c532009-12-18 18:42:37 +00005596 return 0;
5597 }
5598
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005599 // Set the target ABI if specified.
Douglas Gregor49a87542012-11-16 04:24:59 +00005600 if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
5601 Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005602 return 0;
5603 }
5604
Charles Davis98b7c5c2010-06-11 01:06:47 +00005605 // Set the target C++ ABI.
Douglas Gregor49a87542012-11-16 04:24:59 +00005606 if (!Opts->CXXABI.empty() && !Target->setCXXABI(Opts->CXXABI)) {
5607 Diags.Report(diag::err_target_unknown_cxxabi) << Opts->CXXABI;
Charles Davis98b7c5c2010-06-11 01:06:47 +00005608 return 0;
5609 }
5610
Rafael Espindola5389b842013-08-21 21:59:03 +00005611 // Set the fp math unit.
5612 if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
5613 Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
5614 return 0;
5615 }
5616
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005617 // Compute the default target features, we need the target to handle this
5618 // because features may have dependencies on one another.
5619 llvm::StringMap<bool> Features;
Chandler Carruthc3a2e652011-09-28 05:56:05 +00005620 Target->getDefaultFeatures(Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005621
Rafael Espindolac84ed542013-08-20 18:57:55 +00005622 // Apply the user specified deltas.
5623 for (unsigned I = 0, N = Opts->FeaturesAsWritten.size();
5624 I < N; ++I) {
5625 const char *Name = Opts->FeaturesAsWritten[I].c_str();
Rafael Espindola53ac3d82011-11-27 20:00:43 +00005626 // Apply the feature via the target.
Rafael Espindolac84ed542013-08-20 18:57:55 +00005627 bool Enabled = Name[0] == '+';
5628 Target->setFeatureEnabled(Features, Name + 1, Enabled);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005629 }
5630
5631 // Add the features to the compile options.
5632 //
5633 // FIXME: If we are completely confident that we have the right set, we only
5634 // need to pass the minuses.
Douglas Gregor49a87542012-11-16 04:24:59 +00005635 Opts->Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005636 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
5637 ie = Features.end(); it != ie; ++it)
Douglas Gregor49a87542012-11-16 04:24:59 +00005638 Opts->Features.push_back((it->second ? "+" : "-") + it->first().str());
Rafael Espindola5389b842013-08-21 21:59:03 +00005639 if (!Target->HandleTargetFeatures(Opts->Features, Diags))
5640 return 0;
Daniel Dunbard58c03f2009-11-15 06:48:46 +00005641
5642 return Target.take();
5643}