blob: 2f75743e21793ef5a7795992e63499b3302d802c [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"
Chris Lattner797c3c42009-08-10 19:03:04 +000028#include "llvm/MC/MCSectionMachO.h"
David Blaikie9fe8c742011-09-23 05:35:21 +000029#include "llvm/Support/ErrorHandling.h"
Dale Johannesen1e592cb2010-10-29 23:24:33 +000030#include "llvm/Type.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:
Douglas Gregora3844922009-07-01 15:12:53 +000076 OSTargetInfo(const std::string& 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) {
Benjamin Kramera9992772010-01-09 17:55:51 +000091 Builder.defineMacro("__APPLE_CC__", "5621");
92 Builder.defineMacro("__APPLE__");
93 Builder.defineMacro("__MACH__");
94 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000095
John McCall098df7f2011-06-16 00:03:19 +000096 if (!Opts.ObjCAutoRefCount) {
John McCallf85e1932011-06-15 23:02:42 +000097 // __weak is always defined, for use in blocks and with objc pointers.
98 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000099
John McCallf85e1932011-06-15 23:02:42 +0000100 // Darwin defines __strong even in C mode (just to nothing).
Douglas Gregore289d812011-09-13 17:21:33 +0000101 if (Opts.getGC() != LangOptions::NonGC)
John McCallf85e1932011-06-15 23:02:42 +0000102 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
103 else
104 Builder.defineMacro("__strong", "");
Eric Christopher7c9adf92011-07-07 22:55:26 +0000105
John McCallf85e1932011-06-15 23:02:42 +0000106 // __unsafe_unretained is defined to nothing in non-ARC mode. We even
107 // allow this in C, since one might have block pointers in structs that
108 // are used in pure C code and in Objective-C ARC.
109 Builder.defineMacro("__unsafe_unretained", "");
John McCallf85e1932011-06-15 23:02:42 +0000110 }
Eric Christopher7c9adf92011-07-07 22:55:26 +0000111
Eli Friedman2de4fee2009-06-04 23:00:29 +0000112 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +0000113 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +0000114 else
Benjamin Kramera9992772010-01-09 17:55:51 +0000115 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000116
117 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000118 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000119
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000120 // Get the platform type and version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000121 unsigned Maj, Min, Rev;
Bob Wilson48b68a02012-01-31 23:52:58 +0000122 if (Triple.isMacOSX()) {
123 Triple.getMacOSXVersion(Maj, Min, Rev);
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000124 PlatformName = "macosx";
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000125 } else {
Bob Wilson48b68a02012-01-31 23:52:58 +0000126 Triple.getOSVersion(Maj, Min, Rev);
127 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000128 }
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000129
Sebastian Pop9ec60df2012-01-20 22:01:23 +0000130 // If -target arch-pc-win32-macho option specified, we're
Eric Christopher895d4222011-07-29 21:20:35 +0000131 // generating code for Win32 ABI. No need to emit
Chad Rosierd9259f32011-07-19 20:00:06 +0000132 // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__.
133 if (PlatformName == "win32") {
134 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
135 return;
136 }
137
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000138 // Set the appropriate OS version define.
Bob Wilson48b68a02012-01-31 23:52:58 +0000139 if (Triple.getOS() == llvm::Triple::IOS) {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000140 assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000141 char Str[6];
142 Str[0] = '0' + Maj;
143 Str[1] = '0' + (Min / 10);
144 Str[2] = '0' + (Min % 10);
145 Str[3] = '0' + (Rev / 10);
146 Str[4] = '0' + (Rev % 10);
147 Str[5] = '\0';
148 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
149 } else {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000150 // Note that the Driver allows versions which aren't representable in the
151 // define (because we only get a single digit for the minor and micro
152 // revision numbers). So, we limit them to the maximum representable
153 // version.
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000154 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000155 assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000156 char Str[5];
157 Str[0] = '0' + (Maj / 10);
158 Str[1] = '0' + (Maj % 10);
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000159 Str[2] = '0' + std::min(Min, 9U);
160 Str[3] = '0' + std::min(Rev, 9U);
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000161 Str[4] = '\0';
162 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000163 }
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000164
165 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
Eli Friedman618234a2008-08-20 02:34:37 +0000166}
Reid Spencer5f016e22007-07-11 17:01:13 +0000167
Chris Lattner797c3c42009-08-10 19:03:04 +0000168namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000169template<typename Target>
170class DarwinTargetInfo : public OSTargetInfo<Target> {
171protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000172 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000173 MacroBuilder &Builder) const {
Eric Christopher7c9adf92011-07-07 22:55:26 +0000174 getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000175 this->PlatformMinVersion);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Torok Edwin5f6c1942009-06-30 17:10:35 +0000178public:
179 DarwinTargetInfo(const std::string& triple) :
180 OSTargetInfo<Target>(triple) {
Eric Christopheraa7333c2011-07-02 00:20:22 +0000181 llvm::Triple T = llvm::Triple(triple);
182 this->TLSSupported = T.isMacOSX() && !T.isMacOSXVersionLT(10,7);
Daniel Dunbare177d3b2011-02-21 23:12:51 +0000183 this->MCountName = "\01mcount";
Torok Edwin5f6c1942009-06-30 17:10:35 +0000184 }
185
Chris Lattner5f9e2722011-07-23 10:55:15 +0000186 virtual std::string isValidSectionSpecifier(StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000187 // Let MCSectionMachO validate this.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000188 StringRef Segment, Section;
Chris Lattner797c3c42009-08-10 19:03:04 +0000189 unsigned TAA, StubSize;
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000190 bool HasTAA;
Chris Lattner797c3c42009-08-10 19:03:04 +0000191 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000192 TAA, HasTAA, StubSize);
Chris Lattner797c3c42009-08-10 19:03:04 +0000193 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000194
Anders Carlsson18af3682010-06-08 22:47:50 +0000195 virtual const char *getStaticInitSectionSpecifier() const {
196 // FIXME: We should return 0 when building kexts.
197 return "__TEXT,__StaticInit,regular,pure_instructions";
198 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000199
John McCall41887602012-01-29 01:20:30 +0000200 /// Darwin does not support protected visibility. Darwin's "default"
201 /// is very similar to ELF's "protected"; Darwin requires a "weak"
202 /// attribute on declarations that can be dynamically replaced.
203 virtual bool hasProtectedVisibility() const {
204 return false;
205 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000206};
207
Chris Lattner797c3c42009-08-10 19:03:04 +0000208
Torok Edwin5f6c1942009-06-30 17:10:35 +0000209// DragonFlyBSD Target
210template<typename Target>
211class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
212protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000213 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000214 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000215 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000216 Builder.defineMacro("__DragonFly__");
217 Builder.defineMacro("__DragonFly_cc_version", "100001");
218 Builder.defineMacro("__ELF__");
219 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
220 Builder.defineMacro("__tune_i386__");
221 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000222 }
223public:
Mike Stump1eb44332009-09-09 15:08:12 +0000224 DragonFlyBSDTargetInfo(const std::string &triple)
Eli Friedmanb089c4d2012-02-10 23:02:29 +0000225 : OSTargetInfo<Target>(triple) {
226 this->UserLabelPrefix = "";
227
228 llvm::Triple Triple(triple);
229 switch (Triple.getArch()) {
230 default:
231 case llvm::Triple::x86:
232 case llvm::Triple::x86_64:
233 this->MCountName = ".mcount";
234 break;
235 }
236 }
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:
Mike Stump1eb44332009-09-09 15:08:12 +0000258 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000259 : OSTargetInfo<Target>(triple) {
260 this->UserLabelPrefix = "";
Roman Divackybe4c8702011-02-10 16:52:03 +0000261
262 llvm::Triple Triple(triple);
263 switch (Triple.getArch()) {
264 default:
265 case llvm::Triple::x86:
266 case llvm::Triple::x86_64:
267 this->MCountName = ".mcount";
268 break;
269 case llvm::Triple::mips:
270 case llvm::Triple::mipsel:
271 case llvm::Triple::ppc:
272 case llvm::Triple::ppc64:
273 this->MCountName = "_mcount";
274 break;
275 case llvm::Triple::arm:
276 this->MCountName = "__mcount";
277 break;
278 }
279
Duncan Sands1e90faf2009-07-08 13:55:08 +0000280 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000281};
282
Chris Lattner38e317d2010-07-07 16:01:42 +0000283// Minix Target
284template<typename Target>
285class MinixTargetInfo : public OSTargetInfo<Target> {
286protected:
287 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
288 MacroBuilder &Builder) const {
289 // Minix defines
290
291 Builder.defineMacro("__minix", "3");
292 Builder.defineMacro("_EM_WSIZE", "4");
293 Builder.defineMacro("_EM_PSIZE", "4");
294 Builder.defineMacro("_EM_SSIZE", "2");
295 Builder.defineMacro("_EM_LSIZE", "4");
296 Builder.defineMacro("_EM_FSIZE", "4");
297 Builder.defineMacro("_EM_DSIZE", "8");
Eli Friedman6d402dc2011-12-08 23:54:21 +0000298 Builder.defineMacro("__ELF__");
Chris Lattner38e317d2010-07-07 16:01:42 +0000299 DefineStd(Builder, "unix", Opts);
300 }
301public:
302 MinixTargetInfo(const std::string &triple)
303 : OSTargetInfo<Target>(triple) {
304 this->UserLabelPrefix = "";
305 }
306};
307
Torok Edwin5f6c1942009-06-30 17:10:35 +0000308// Linux target
309template<typename Target>
310class LinuxTargetInfo : public OSTargetInfo<Target> {
311protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000312 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000313 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000314 // Linux defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000315 DefineStd(Builder, "unix", Opts);
316 DefineStd(Builder, "linux", Opts);
317 Builder.defineMacro("__gnu_linux__");
318 Builder.defineMacro("__ELF__");
Evgeniy Stepanov32064032012-04-26 12:08:09 +0000319 if (Triple.getEnvironment() == llvm::Triple::ANDROIDEABI)
320 Builder.defineMacro("__ANDROID__", "1");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000321 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000322 Builder.defineMacro("_REENTRANT");
Douglas Gregor2b003fd2010-04-21 05:52:38 +0000323 if (Opts.CPlusPlus)
324 Builder.defineMacro("_GNU_SOURCE");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000325 }
326public:
Mike Stump1eb44332009-09-09 15:08:12 +0000327 LinuxTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000328 : OSTargetInfo<Target>(triple) {
329 this->UserLabelPrefix = "";
Douglas Gregor12e84642011-01-12 21:19:25 +0000330 this->WIntType = TargetInfo::UnsignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000331 }
Benjamin Kramer86d18c52011-10-15 17:53:33 +0000332
333 virtual const char *getStaticInitSectionSpecifier() const {
334 return ".text.startup";
335 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000336};
337
Chris Lattnerb62bb282009-07-13 20:29:08 +0000338// NetBSD Target
339template<typename Target>
340class NetBSDTargetInfo : public OSTargetInfo<Target> {
341protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000342 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000343 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000344 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000345 Builder.defineMacro("__NetBSD__");
346 Builder.defineMacro("__unix__");
347 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000348 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000349 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000350 }
351public:
Mike Stump1eb44332009-09-09 15:08:12 +0000352 NetBSDTargetInfo(const std::string &triple)
Chris Lattnerb62bb282009-07-13 20:29:08 +0000353 : OSTargetInfo<Target>(triple) {
354 this->UserLabelPrefix = "";
355 }
356};
357
Torok Edwin5f6c1942009-06-30 17:10:35 +0000358// OpenBSD Target
359template<typename Target>
360class OpenBSDTargetInfo : public OSTargetInfo<Target> {
361protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000362 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000363 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000364 // OpenBSD defines; list based off of gcc output
365
Benjamin Kramera9992772010-01-09 17:55:51 +0000366 Builder.defineMacro("__OpenBSD__");
367 DefineStd(Builder, "unix", Opts);
368 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000369 if (Opts.POSIXThreads)
Chris Lattner4ddcf3b2012-04-25 06:12:24 +0000370 Builder.defineMacro("_REENTRANT");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000371 }
372public:
Mike Stump1eb44332009-09-09 15:08:12 +0000373 OpenBSDTargetInfo(const std::string &triple)
Eli Friedman62d829a2011-12-15 02:15:56 +0000374 : OSTargetInfo<Target>(triple) {
375 this->UserLabelPrefix = "";
376
377 llvm::Triple Triple(triple);
378 switch (Triple.getArch()) {
379 default:
380 case llvm::Triple::x86:
381 case llvm::Triple::x86_64:
382 case llvm::Triple::arm:
383 case llvm::Triple::sparc:
384 this->MCountName = "__mcount";
385 break;
386 case llvm::Triple::mips64:
387 case llvm::Triple::mips64el:
388 case llvm::Triple::ppc:
389 case llvm::Triple::sparcv9:
390 this->MCountName = "_mcount";
391 break;
392 }
393 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000394};
395
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000396// PSP Target
397template<typename Target>
398class PSPTargetInfo : public OSTargetInfo<Target> {
399protected:
400 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000401 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000402 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000403 Builder.defineMacro("PSP");
404 Builder.defineMacro("_PSP");
405 Builder.defineMacro("__psp__");
406 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000407 }
408public:
409 PSPTargetInfo(const std::string& triple)
410 : OSTargetInfo<Target>(triple) {
411 this->UserLabelPrefix = "";
412 }
413};
414
John Thompson3f6918a2009-11-19 17:18:50 +0000415// PS3 PPU Target
416template<typename Target>
417class PS3PPUTargetInfo : public OSTargetInfo<Target> {
418protected:
419 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000420 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000421 // PS3 PPU defines.
John Thompsonfb457972010-03-25 16:18:32 +0000422 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000423 Builder.defineMacro("__PPU__");
424 Builder.defineMacro("__CELLOS_LV2__");
425 Builder.defineMacro("__ELF__");
426 Builder.defineMacro("__LP32__");
John Thompson8e6065a2010-06-24 22:44:13 +0000427 Builder.defineMacro("_ARCH_PPC64");
428 Builder.defineMacro("__powerpc64__");
John Thompson3f6918a2009-11-19 17:18:50 +0000429 }
430public:
431 PS3PPUTargetInfo(const std::string& triple)
432 : OSTargetInfo<Target>(triple) {
433 this->UserLabelPrefix = "";
Nick Lewycky99520702011-12-16 22:32:39 +0000434 this->LongWidth = this->LongAlign = 32;
435 this->PointerWidth = this->PointerAlign = 32;
John Thompson8e6065a2010-06-24 22:44:13 +0000436 this->IntMaxType = TargetInfo::SignedLongLong;
437 this->UIntMaxType = TargetInfo::UnsignedLongLong;
438 this->Int64Type = TargetInfo::SignedLongLong;
John Thompsonec387af2009-12-18 14:21:08 +0000439 this->SizeType = TargetInfo::UnsignedInt;
John Thompson8e6065a2010-06-24 22:44:13 +0000440 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 +0000441 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
John Thompson3f6918a2009-11-19 17:18:50 +0000442 }
443};
444
445// FIXME: Need a real SPU target.
446// PS3 SPU Target
447template<typename Target>
448class PS3SPUTargetInfo : public OSTargetInfo<Target> {
449protected:
450 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000451 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000452 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000453 Builder.defineMacro("__SPU__");
454 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000455 }
456public:
457 PS3SPUTargetInfo(const std::string& triple)
458 : OSTargetInfo<Target>(triple) {
459 this->UserLabelPrefix = "";
460 }
461};
462
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000463// AuroraUX target
464template<typename Target>
465class AuroraUXTargetInfo : public OSTargetInfo<Target> {
466protected:
467 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000468 MacroBuilder &Builder) const {
469 DefineStd(Builder, "sun", Opts);
470 DefineStd(Builder, "unix", Opts);
471 Builder.defineMacro("__ELF__");
472 Builder.defineMacro("__svr4__");
473 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000474 }
475public:
476 AuroraUXTargetInfo(const std::string& triple)
477 : OSTargetInfo<Target>(triple) {
478 this->UserLabelPrefix = "";
479 this->WCharType = this->SignedLong;
480 // FIXME: WIntType should be SignedLong
481 }
482};
483
Torok Edwin5f6c1942009-06-30 17:10:35 +0000484// Solaris target
485template<typename Target>
486class SolarisTargetInfo : public OSTargetInfo<Target> {
487protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000488 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000489 MacroBuilder &Builder) const {
490 DefineStd(Builder, "sun", Opts);
491 DefineStd(Builder, "unix", Opts);
492 Builder.defineMacro("__ELF__");
493 Builder.defineMacro("__svr4__");
494 Builder.defineMacro("__SVR4");
David Chisnall165329c2012-02-28 17:10:04 +0000495 // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
496 // newer, but to 500 for everything else. feature_test.h has a check to
497 // ensure that you are not using C99 with an old version of X/Open or C89
498 // with a new version.
499 if (Opts.C99 || Opts.C11)
500 Builder.defineMacro("_XOPEN_SOURCE", "600");
501 else
502 Builder.defineMacro("_XOPEN_SOURCE", "500");
David Chisnallb4f0bd62012-03-02 10:49:52 +0000503 if (Opts.CPlusPlus)
David Chisnall165329c2012-02-28 17:10:04 +0000504 Builder.defineMacro("__C99FEATURES__");
David Chisnall48fad492012-02-17 18:35:11 +0000505 Builder.defineMacro("_LARGEFILE_SOURCE");
506 Builder.defineMacro("_LARGEFILE64_SOURCE");
507 Builder.defineMacro("__EXTENSIONS__");
David Chisnall165329c2012-02-28 17:10:04 +0000508 Builder.defineMacro("_REENTRANT");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000509 }
510public:
Mike Stump1eb44332009-09-09 15:08:12 +0000511 SolarisTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000512 : OSTargetInfo<Target>(triple) {
513 this->UserLabelPrefix = "";
David Chisnallfb027842012-03-28 18:04:14 +0000514 this->WCharType = this->SignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000515 // FIXME: WIntType should be SignedLong
516 }
517};
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000518
519// Windows target
520template<typename Target>
521class WindowsTargetInfo : public OSTargetInfo<Target> {
522protected:
523 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
524 MacroBuilder &Builder) const {
Michael J. Spencera764e832010-10-21 08:22:51 +0000525 Builder.defineMacro("_WIN32");
526 }
527 void getVisualStudioDefines(const LangOptions &Opts,
528 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000529 if (Opts.CPlusPlus) {
530 if (Opts.RTTI)
531 Builder.defineMacro("_CPPRTTI");
532
533 if (Opts.Exceptions)
534 Builder.defineMacro("_CPPUNWIND");
535 }
536
537 if (!Opts.CharIsSigned)
538 Builder.defineMacro("_CHAR_UNSIGNED");
539
540 // FIXME: POSIXThreads isn't exactly the option this should be defined for,
541 // but it works for now.
542 if (Opts.POSIXThreads)
543 Builder.defineMacro("_MT");
Michael J. Spencera764e832010-10-21 08:22:51 +0000544
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000545 if (Opts.MSCVersion != 0)
Chris Lattner5f9e2722011-07-23 10:55:15 +0000546 Builder.defineMacro("_MSC_VER", Twine(Opts.MSCVersion));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000547
Francois Pichet62ec1f22011-09-17 17:15:52 +0000548 if (Opts.MicrosoftExt) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000549 Builder.defineMacro("_MSC_EXTENSIONS");
550
551 if (Opts.CPlusPlus0x) {
552 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
553 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
554 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
555 }
556 }
557
558 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000559 }
560
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000561public:
562 WindowsTargetInfo(const std::string &triple)
563 : OSTargetInfo<Target>(triple) {}
564};
565
Mike Stump1eb44332009-09-09 15:08:12 +0000566} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000567
Chris Lattnerd29b6302008-10-05 21:50:58 +0000568//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000569// Specific target implementations.
570//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000571
Eli Friedmane4277982008-08-20 23:11:40 +0000572namespace {
573// PPC abstract base class
574class PPCTargetInfo : public TargetInfo {
575 static const Builtin::Info BuiltinInfo[];
576 static const char * const GCCRegNames[];
577 static const TargetInfo::GCCRegAlias GCCRegAliases[];
Eli Friedmane4277982008-08-20 23:11:40 +0000578public:
Nico Weber6e1d2ea2012-01-31 02:07:33 +0000579 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {
580 LongDoubleWidth = LongDoubleAlign = 128;
581 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble;
582 }
Eli Friedman15b91762009-06-05 07:05:05 +0000583
Eli Friedmane4277982008-08-20 23:11:40 +0000584 virtual void getTargetBuiltins(const Builtin::Info *&Records,
585 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000586 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000587 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000588 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000589
Bob Wilson9f1c49c2012-01-28 18:02:29 +0000590 virtual bool isCLZForZeroUndef() const { return false; }
591
Chris Lattner33328642009-03-20 15:52:06 +0000592 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000593 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000594
Douglas Gregore727d212012-01-30 06:38:25 +0000595 virtual bool hasFeature(StringRef Feature) const;
596
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000597 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000598 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000599 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000600 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000601 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000602 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000603 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000604 default: return false;
605 case 'O': // Zero
John Thompson8e6065a2010-06-24 22:44:13 +0000606 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000607 case 'b': // Base register
608 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000609 Info.setAllowsRegister();
John Thompson8e6065a2010-06-24 22:44:13 +0000610 break;
611 // FIXME: The following are added to allow parsing.
612 // I just took a guess at what the actions should be.
613 // Also, is more specific checking needed? I.e. specific registers?
Michael J. Spencer20249a12010-10-21 03:16:25 +0000614 case 'd': // Floating point register (containing 64-bit value)
John Thompson8e6065a2010-06-24 22:44:13 +0000615 case 'v': // Altivec vector register
616 Info.setAllowsRegister();
617 break;
618 case 'w':
619 switch (Name[1]) {
Michael J. Spencer20249a12010-10-21 03:16:25 +0000620 case 'd':// VSX vector register to hold vector double data
621 case 'f':// VSX vector register to hold vector float data
622 case 's':// VSX vector register to hold scalar float data
623 case 'a':// Any VSX register
John Thompson8e6065a2010-06-24 22:44:13 +0000624 break;
625 default:
626 return false;
627 }
628 Info.setAllowsRegister();
629 Name++; // Skip over 'w'.
630 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000631 case 'h': // `MQ', `CTR', or `LINK' register
632 case 'q': // `MQ' register
633 case 'c': // `CTR' register
634 case 'l': // `LINK' register
635 case 'x': // `CR' register (condition register) number 0
636 case 'y': // `CR' register (condition register)
637 case 'z': // `XER[CA]' carry bit (part of the XER register)
John Thompson8e6065a2010-06-24 22:44:13 +0000638 Info.setAllowsRegister();
639 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000640 case 'I': // Signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000641 case 'J': // Unsigned 16-bit constant shifted left 16 bits
Michael J. Spencer20249a12010-10-21 03:16:25 +0000642 // (use `L' instead for SImode constants)
643 case 'K': // Unsigned 16-bit constant
644 case 'L': // Signed 16-bit constant shifted left 16 bits
645 case 'M': // Constant larger than 31
646 case 'N': // Exact power of 2
647 case 'P': // Constant whose negation is a signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000648 case 'G': // Floating point constant that can be loaded into a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000649 // register with one instruction per word
John Thompson8e6065a2010-06-24 22:44:13 +0000650 case 'H': // Integer/Floating point constant that can be loaded
Michael J. Spencer20249a12010-10-21 03:16:25 +0000651 // into a register using three instructions
John Thompson8e6065a2010-06-24 22:44:13 +0000652 break;
653 case 'm': // Memory operand. Note that on PowerPC targets, m can
654 // include addresses that update the base register. It
655 // is therefore only safe to use `m' in an asm statement
656 // if that asm statement accesses the operand exactly once.
657 // The asm statement must also use `%U<opno>' as a
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000658 // placeholder for the "update" flag in the corresponding
Michael J. Spencer20249a12010-10-21 03:16:25 +0000659 // load or store instruction. For example:
John Thompson8e6065a2010-06-24 22:44:13 +0000660 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
Michael J. Spencer20249a12010-10-21 03:16:25 +0000661 // is correct but:
John Thompson8e6065a2010-06-24 22:44:13 +0000662 // asm ("st %1,%0" : "=m" (mem) : "r" (val));
663 // is not. Use es rather than m if you don't want the base
Michael J. Spencer20249a12010-10-21 03:16:25 +0000664 // register to be updated.
665 case 'e':
John Thompson56b6eca2010-06-25 00:02:05 +0000666 if (Name[1] != 's')
667 return false;
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000668 // es: A "stable" memory operand; that is, one which does not
John Thompson8e6065a2010-06-24 22:44:13 +0000669 // include any automodification of the base register. Unlike
670 // `m', this constraint can be used in asm statements that
671 // might access the operand several times, or that might not
John Thompson56b6eca2010-06-25 00:02:05 +0000672 // access it at all.
John Thompson8e6065a2010-06-24 22:44:13 +0000673 Info.setAllowsMemory();
John Thompson56b6eca2010-06-25 00:02:05 +0000674 Name++; // Skip over 'e'.
John Thompson8e6065a2010-06-24 22:44:13 +0000675 break;
676 case 'Q': // Memory operand that is an offset from a register (it is
Michael J. Spencer20249a12010-10-21 03:16:25 +0000677 // usually better to use `m' or `es' in asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000678 case 'Z': // Memory operand that is an indexed or indirect from a
679 // register (it is usually better to use `m' or `es' in
Michael J. Spencer20249a12010-10-21 03:16:25 +0000680 // asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000681 Info.setAllowsMemory();
682 Info.setAllowsRegister();
683 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000684 case 'R': // AIX TOC entry
John Thompson8e6065a2010-06-24 22:44:13 +0000685 case 'a': // Address operand that is an indexed or indirect from a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000686 // register (`p' is preferable for asm statements)
687 case 'S': // Constant suitable as a 64-bit mask operand
688 case 'T': // Constant suitable as a 32-bit mask operand
689 case 'U': // System V Release 4 small data area reference
John Thompson8e6065a2010-06-24 22:44:13 +0000690 case 't': // AND masks that can be performed by two rldic{l, r}
Michael J. Spencer20249a12010-10-21 03:16:25 +0000691 // instructions
692 case 'W': // Vector constant that does not require memory
693 case 'j': // Vector constant that is all zeros.
John Thompson8e6065a2010-06-24 22:44:13 +0000694 break;
695 // End FIXME.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000696 }
John Thompson8e6065a2010-06-24 22:44:13 +0000697 return true;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000698 }
Eli Friedmane4277982008-08-20 23:11:40 +0000699 virtual const char *getClobbers() const {
700 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000701 }
Eli Friedmane4277982008-08-20 23:11:40 +0000702};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000703
Eli Friedmane4277982008-08-20 23:11:40 +0000704const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +0000705#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000706#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +0000707 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000708#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000709};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000710
711
Chris Lattnerc0f59212009-03-02 22:27:17 +0000712/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
713/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000714void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000715 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000716 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000717 Builder.defineMacro("__ppc__");
718 Builder.defineMacro("_ARCH_PPC");
Chris Lattnere03ae302010-02-16 18:14:57 +0000719 Builder.defineMacro("__powerpc__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000720 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000721 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000722 Builder.defineMacro("_ARCH_PPC64");
723 Builder.defineMacro("_LP64");
724 Builder.defineMacro("__LP64__");
Chris Lattnere03ae302010-02-16 18:14:57 +0000725 Builder.defineMacro("__powerpc64__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000726 Builder.defineMacro("__ppc64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000727 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000728 Builder.defineMacro("__ppc__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000729 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000730
Chris Lattnerc0f59212009-03-02 22:27:17 +0000731 // Target properties.
Joerg Sonnenberger7cd1de52011-07-05 14:56:12 +0000732 if (getTriple().getOS() != llvm::Triple::NetBSD)
733 Builder.defineMacro("_BIG_ENDIAN");
Benjamin Kramera9992772010-01-09 17:55:51 +0000734 Builder.defineMacro("__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000735
Chris Lattnerc0f59212009-03-02 22:27:17 +0000736 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000737 Builder.defineMacro("__NATURAL_ALIGNMENT__");
738 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000739
Chris Lattnerc0f59212009-03-02 22:27:17 +0000740 // FIXME: Should be controlled by command line option.
Benjamin Kramera9992772010-01-09 17:55:51 +0000741 Builder.defineMacro("__LONG_DOUBLE_128__");
Michael J. Spencer20249a12010-10-21 03:16:25 +0000742
John Thompson3f6918a2009-11-19 17:18:50 +0000743 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000744 Builder.defineMacro("__VEC__", "10206");
745 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000746 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000747}
748
Douglas Gregore727d212012-01-30 06:38:25 +0000749bool PPCTargetInfo::hasFeature(StringRef Feature) const {
750 return Feature == "powerpc";
751}
Chris Lattner393ff042008-04-21 18:56:49 +0000752
Douglas Gregore727d212012-01-30 06:38:25 +0000753
Eli Friedmane4277982008-08-20 23:11:40 +0000754const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +0000755 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
756 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
757 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
758 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
759 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
760 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
761 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
762 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +0000763 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000764 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +0000765 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000766 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
767 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
768 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
769 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +0000770 "vrsave", "vscr",
771 "spe_acc", "spefscr",
772 "sfp"
773};
Reid Spencer5f016e22007-07-11 17:01:13 +0000774
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000775void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000776 unsigned &NumNames) const {
777 Names = GCCRegNames;
778 NumNames = llvm::array_lengthof(GCCRegNames);
779}
Reid Spencer5f016e22007-07-11 17:01:13 +0000780
Eli Friedmane4277982008-08-20 23:11:40 +0000781const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
782 // While some of these aliases do map to different registers
783 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000784 { { "0" }, "r0" },
785 { { "1"}, "r1" },
786 { { "2" }, "r2" },
787 { { "3" }, "r3" },
788 { { "4" }, "r4" },
789 { { "5" }, "r5" },
790 { { "6" }, "r6" },
791 { { "7" }, "r7" },
792 { { "8" }, "r8" },
793 { { "9" }, "r9" },
794 { { "10" }, "r10" },
795 { { "11" }, "r11" },
796 { { "12" }, "r12" },
797 { { "13" }, "r13" },
798 { { "14" }, "r14" },
799 { { "15" }, "r15" },
800 { { "16" }, "r16" },
801 { { "17" }, "r17" },
802 { { "18" }, "r18" },
803 { { "19" }, "r19" },
804 { { "20" }, "r20" },
805 { { "21" }, "r21" },
806 { { "22" }, "r22" },
807 { { "23" }, "r23" },
808 { { "24" }, "r24" },
809 { { "25" }, "r25" },
810 { { "26" }, "r26" },
811 { { "27" }, "r27" },
812 { { "28" }, "r28" },
813 { { "29" }, "r29" },
814 { { "30" }, "r30" },
815 { { "31" }, "r31" },
816 { { "fr0" }, "f0" },
817 { { "fr1" }, "f1" },
818 { { "fr2" }, "f2" },
819 { { "fr3" }, "f3" },
820 { { "fr4" }, "f4" },
821 { { "fr5" }, "f5" },
822 { { "fr6" }, "f6" },
823 { { "fr7" }, "f7" },
824 { { "fr8" }, "f8" },
825 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +0000826 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000827 { { "fr11" }, "f11" },
828 { { "fr12" }, "f12" },
829 { { "fr13" }, "f13" },
830 { { "fr14" }, "f14" },
831 { { "fr15" }, "f15" },
832 { { "fr16" }, "f16" },
833 { { "fr17" }, "f17" },
834 { { "fr18" }, "f18" },
835 { { "fr19" }, "f19" },
836 { { "fr20" }, "f20" },
837 { { "fr21" }, "f21" },
838 { { "fr22" }, "f22" },
839 { { "fr23" }, "f23" },
840 { { "fr24" }, "f24" },
841 { { "fr25" }, "f25" },
842 { { "fr26" }, "f26" },
843 { { "fr27" }, "f27" },
844 { { "fr28" }, "f28" },
845 { { "fr29" }, "f29" },
846 { { "fr30" }, "f30" },
847 { { "fr31" }, "f31" },
848 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +0000849};
850
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000851void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000852 unsigned &NumAliases) const {
853 Aliases = GCCRegAliases;
854 NumAliases = llvm::array_lengthof(GCCRegAliases);
855}
856} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000857
858namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000859class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000860public:
Chris Lattnere03ae302010-02-16 18:14:57 +0000861 PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) {
Eli Friedmaned855cb2008-08-21 00:13:15 +0000862 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 +0000863 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Chris Lattnere03ae302010-02-16 18:14:57 +0000864
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +0000865 switch (getTriple().getOS()) {
Nico Weber6e1d2ea2012-01-31 02:07:33 +0000866 case llvm::Triple::Linux:
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +0000867 case llvm::Triple::FreeBSD:
868 case llvm::Triple::NetBSD:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +0000869 SizeType = UnsignedInt;
Hal Finkel178a9b82012-03-02 20:54:36 +0000870 PtrDiffType = SignedInt;
871 IntPtrType = SignedInt;
Joerg Sonnenberger78542df2011-07-05 14:54:41 +0000872 break;
Joerg Sonnenberger1a83b432011-07-04 23:11:58 +0000873 default:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +0000874 break;
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +0000875 }
Roman Divackye3d175d2012-03-13 16:53:54 +0000876
Roman Divackyefe9c0d2012-03-13 19:20:17 +0000877 if (getTriple().getOS() == llvm::Triple::FreeBSD) {
878 LongDoubleWidth = LongDoubleAlign = 64;
Roman Divackye3d175d2012-03-13 16:53:54 +0000879 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Roman Divackyefe9c0d2012-03-13 19:20:17 +0000880 }
Roman Divackyc81f2a22011-01-06 08:27:10 +0000881 }
882
883 virtual const char *getVAListDeclaration() const {
884 // This is the ELF definition, and is overridden by the Darwin sub-target
885 return "typedef struct __va_list_tag {"
886 " unsigned char gpr;"
887 " unsigned char fpr;"
888 " unsigned short reserved;"
889 " void* overflow_arg_area;"
890 " void* reg_save_area;"
891 "} __builtin_va_list[1];";
Eli Friedmaned855cb2008-08-21 00:13:15 +0000892 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000893};
894} // end anonymous namespace.
895
896namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000897class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000898public:
Eli Friedmane4277982008-08-20 23:11:40 +0000899 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000900 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000901 IntMaxType = SignedLong;
902 UIntMaxType = UnsignedLong;
903 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000904 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +0000905 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Roman Divackye3d175d2012-03-13 16:53:54 +0000906
Roman Divackyefe9c0d2012-03-13 19:20:17 +0000907 if (getTriple().getOS() == llvm::Triple::FreeBSD) {
908 LongDoubleWidth = LongDoubleAlign = 64;
Roman Divackye3d175d2012-03-13 16:53:54 +0000909 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Roman Divackyefe9c0d2012-03-13 19:20:17 +0000910 }
Chris Lattnerf291b102008-05-09 06:17:04 +0000911 }
Roman Divackyc81f2a22011-01-06 08:27:10 +0000912 virtual const char *getVAListDeclaration() const {
913 return "typedef char* __builtin_va_list;";
914 }
Eli Friedmane4277982008-08-20 23:11:40 +0000915};
916} // end anonymous namespace.
917
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000918
919namespace {
Roman Divackyc81f2a22011-01-06 08:27:10 +0000920class DarwinPPC32TargetInfo :
921 public DarwinTargetInfo<PPC32TargetInfo> {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000922public:
Roman Divackyc81f2a22011-01-06 08:27:10 +0000923 DarwinPPC32TargetInfo(const std::string& triple)
924 : DarwinTargetInfo<PPC32TargetInfo>(triple) {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000925 HasAlignMac68kSupport = true;
Roman Divackyc81f2a22011-01-06 08:27:10 +0000926 BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool?
Anton Yartsev9bc23ba2012-01-17 22:40:00 +0000927 LongLongAlign = 32;
Nick Lewycky9bddf432011-12-21 04:25:47 +0000928 SuitableAlign = 128;
Anton Yartsev9bc23ba2012-01-17 22:40:00 +0000929 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
930 "i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32";
Roman Divackyc81f2a22011-01-06 08:27:10 +0000931 }
932 virtual const char *getVAListDeclaration() const {
933 return "typedef char* __builtin_va_list;";
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000934 }
935};
936
937class DarwinPPC64TargetInfo :
938 public DarwinTargetInfo<PPC64TargetInfo> {
939public:
940 DarwinPPC64TargetInfo(const std::string& triple)
941 : DarwinTargetInfo<PPC64TargetInfo>(triple) {
942 HasAlignMac68kSupport = true;
Nick Lewycky9bddf432011-12-21 04:25:47 +0000943 SuitableAlign = 128;
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000944 }
945};
946} // end anonymous namespace.
947
Reid Spencer5f016e22007-07-11 17:01:13 +0000948namespace {
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000949 static const unsigned NVPTXAddrSpaceMap[] = {
950 1, // opencl_global
951 3, // opencl_local
952 4, // opencl_constant
953 1, // cuda_device
954 4, // cuda_constant
955 3, // cuda_shared
956 };
957 class NVPTXTargetInfo : public TargetInfo {
958 static const char * const GCCRegNames[];
Justin Holewinski2c585b92012-05-24 17:43:12 +0000959 static const Builtin::Info BuiltinInfo[];
960 std::vector<llvm::StringRef> AvailableFeatures;
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000961 public:
962 NVPTXTargetInfo(const std::string& triple) : TargetInfo(triple) {
963 BigEndian = false;
964 TLSSupported = false;
965 LongWidth = LongAlign = 64;
966 AddrSpaceMap = &NVPTXAddrSpaceMap;
Justin Holewinski2c585b92012-05-24 17:43:12 +0000967 // Define available target features
968 // These must be defined in sorted order!
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000969 }
970 virtual void getTargetDefines(const LangOptions &Opts,
971 MacroBuilder &Builder) const {
972 Builder.defineMacro("__PTX__");
Justin Holewinski2c585b92012-05-24 17:43:12 +0000973 Builder.defineMacro("__NVPTX__");
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000974 }
975 virtual void getTargetBuiltins(const Builtin::Info *&Records,
976 unsigned &NumRecords) const {
Justin Holewinski2c585b92012-05-24 17:43:12 +0000977 Records = BuiltinInfo;
978 NumRecords = clang::NVPTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000979 }
980 virtual bool hasFeature(StringRef Feature) const {
Justin Holewinski2c585b92012-05-24 17:43:12 +0000981 return Feature == "ptx" || Feature == "nvptx";
Peter Collingbourneedb66f32012-05-20 23:28:41 +0000982 }
983
984 virtual void getGCCRegNames(const char * const *&Names,
985 unsigned &NumNames) const;
986 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
987 unsigned &NumAliases) const {
988 // No aliases.
989 Aliases = 0;
990 NumAliases = 0;
991 }
992 virtual bool validateAsmConstraint(const char *&Name,
993 TargetInfo::ConstraintInfo &info) const {
994 // FIXME: implement
995 return true;
996 }
997 virtual const char *getClobbers() const {
998 // FIXME: Is this really right?
999 return "";
1000 }
1001 virtual const char *getVAListDeclaration() const {
1002 // FIXME: implement
1003 return "typedef char* __builtin_va_list;";
1004 }
1005 virtual bool setCPU(const std::string &Name) {
Justin Holewinski2c585b92012-05-24 17:43:12 +00001006 return Name == "sm_10" || Name == "sm_13" || Name == "sm_20";
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001007 }
Justin Holewinski2c585b92012-05-24 17:43:12 +00001008 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1009 StringRef Name,
1010 bool Enabled) const;
1011 };
1012
1013 const Builtin::Info NVPTXTargetInfo::BuiltinInfo[] = {
1014#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
1015#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
1016 ALL_LANGUAGES },
1017#include "clang/Basic/BuiltinsNVPTX.def"
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001018 };
1019
1020 const char * const NVPTXTargetInfo::GCCRegNames[] = {
1021 "r0"
1022 };
1023
1024 void NVPTXTargetInfo::getGCCRegNames(const char * const *&Names,
1025 unsigned &NumNames) const {
1026 Names = GCCRegNames;
1027 NumNames = llvm::array_lengthof(GCCRegNames);
1028 }
1029
Justin Holewinski2c585b92012-05-24 17:43:12 +00001030 bool NVPTXTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
1031 StringRef Name,
1032 bool Enabled) const {
1033 if(std::binary_search(AvailableFeatures.begin(), AvailableFeatures.end(),
1034 Name)) {
1035 Features[Name] = Enabled;
1036 return true;
1037 } else {
1038 return false;
1039 }
1040 }
1041
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001042 class NVPTX32TargetInfo : public NVPTXTargetInfo {
1043 public:
Justin Holewinski2c585b92012-05-24 17:43:12 +00001044 NVPTX32TargetInfo(const std::string& triple) : NVPTXTargetInfo(triple) {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001045 PointerWidth = PointerAlign = 32;
Justin Holewinski2c585b92012-05-24 17:43:12 +00001046 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001047 DescriptionString
1048 = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
1049 "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-"
1050 "n16:32:64";
Justin Holewinski2c585b92012-05-24 17:43:12 +00001051 }
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001052 };
1053
1054 class NVPTX64TargetInfo : public NVPTXTargetInfo {
1055 public:
Justin Holewinski2c585b92012-05-24 17:43:12 +00001056 NVPTX64TargetInfo(const std::string& triple) : NVPTXTargetInfo(triple) {
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001057 PointerWidth = PointerAlign = 64;
Justin Holewinski2c585b92012-05-24 17:43:12 +00001058 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong;
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001059 DescriptionString
1060 = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
1061 "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-"
1062 "n16:32:64";
Justin Holewinski2c585b92012-05-24 17:43:12 +00001063 }
Peter Collingbourneedb66f32012-05-20 23:28:41 +00001064 };
1065}
1066
1067namespace {
Chris Lattner9cbeb632010-03-06 21:21:27 +00001068// MBlaze abstract base class
1069class MBlazeTargetInfo : public TargetInfo {
1070 static const char * const GCCRegNames[];
1071 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1072
1073public:
1074 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) {
Wesley Pecka48fa4b2010-12-12 20:56:47 +00001075 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16";
Chris Lattner9cbeb632010-03-06 21:21:27 +00001076 }
1077
1078 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1079 unsigned &NumRecords) const {
1080 // FIXME: Implement.
1081 Records = 0;
1082 NumRecords = 0;
1083 }
1084
1085 virtual void getTargetDefines(const LangOptions &Opts,
1086 MacroBuilder &Builder) const;
1087
Douglas Gregore727d212012-01-30 06:38:25 +00001088 virtual bool hasFeature(StringRef Feature) const {
1089 return Feature == "mblaze";
1090 }
1091
Chris Lattner9cbeb632010-03-06 21:21:27 +00001092 virtual const char *getVAListDeclaration() const {
1093 return "typedef char* __builtin_va_list;";
1094 }
1095 virtual const char *getTargetPrefix() const {
1096 return "mblaze";
1097 }
1098 virtual void getGCCRegNames(const char * const *&Names,
1099 unsigned &NumNames) const;
1100 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1101 unsigned &NumAliases) const;
1102 virtual bool validateAsmConstraint(const char *&Name,
1103 TargetInfo::ConstraintInfo &Info) const {
1104 switch (*Name) {
1105 default: return false;
1106 case 'O': // Zero
1107 return true;
1108 case 'b': // Base register
1109 case 'f': // Floating point register
1110 Info.setAllowsRegister();
1111 return true;
1112 }
1113 }
1114 virtual const char *getClobbers() const {
1115 return "";
1116 }
1117};
1118
1119/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific
1120/// #defines that are not tied to a specific subtarget.
1121void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts,
1122 MacroBuilder &Builder) const {
1123 // Target identification.
1124 Builder.defineMacro("__microblaze__");
1125 Builder.defineMacro("_ARCH_MICROBLAZE");
1126 Builder.defineMacro("__MICROBLAZE__");
1127
1128 // Target properties.
1129 Builder.defineMacro("_BIG_ENDIAN");
1130 Builder.defineMacro("__BIG_ENDIAN__");
1131
1132 // Subtarget options.
1133 Builder.defineMacro("__REGISTER_PREFIX__", "");
1134}
1135
1136
1137const char * const MBlazeTargetInfo::GCCRegNames[] = {
1138 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1139 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1140 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1141 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
1142 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
1143 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
1144 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
1145 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
1146 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4",
1147 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp"
1148};
1149
1150void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names,
1151 unsigned &NumNames) const {
1152 Names = GCCRegNames;
1153 NumNames = llvm::array_lengthof(GCCRegNames);
1154}
1155
1156const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = {
1157 { {"f0"}, "r0" },
1158 { {"f1"}, "r1" },
1159 { {"f2"}, "r2" },
1160 { {"f3"}, "r3" },
1161 { {"f4"}, "r4" },
1162 { {"f5"}, "r5" },
1163 { {"f6"}, "r6" },
1164 { {"f7"}, "r7" },
1165 { {"f8"}, "r8" },
1166 { {"f9"}, "r9" },
1167 { {"f10"}, "r10" },
1168 { {"f11"}, "r11" },
1169 { {"f12"}, "r12" },
1170 { {"f13"}, "r13" },
1171 { {"f14"}, "r14" },
1172 { {"f15"}, "r15" },
1173 { {"f16"}, "r16" },
1174 { {"f17"}, "r17" },
1175 { {"f18"}, "r18" },
1176 { {"f19"}, "r19" },
1177 { {"f20"}, "r20" },
1178 { {"f21"}, "r21" },
1179 { {"f22"}, "r22" },
1180 { {"f23"}, "r23" },
1181 { {"f24"}, "r24" },
1182 { {"f25"}, "r25" },
1183 { {"f26"}, "r26" },
1184 { {"f27"}, "r27" },
1185 { {"f28"}, "r28" },
1186 { {"f29"}, "r29" },
1187 { {"f30"}, "r30" },
1188 { {"f31"}, "r31" },
1189};
1190
1191void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
1192 unsigned &NumAliases) const {
1193 Aliases = GCCRegAliases;
1194 NumAliases = llvm::array_lengthof(GCCRegAliases);
1195}
1196} // end anonymous namespace.
1197
1198namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001199// Namespace for x86 abstract base class
1200const Builtin::Info BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00001201#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00001202#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00001203 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +00001204#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +00001205};
Eli Friedman61538a72008-05-20 14:21:01 +00001206
Nuno Lopes2550d702009-12-23 17:49:57 +00001207static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +00001208 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
1209 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Eric Christopher7c9adf92011-07-07 22:55:26 +00001210 "argp", "flags", "fpcr", "fpsr", "dirflag", "frame",
Eli Friedman618234a2008-08-20 02:34:37 +00001211 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
1212 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
1213 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
Eric Christophercfd323d2011-06-21 00:05:20 +00001214 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
Eric Christopherc5f9a012011-12-02 02:12:16 +00001215 "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7",
1216 "ymm8", "ymm9", "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15",
Eli Friedman618234a2008-08-20 02:34:37 +00001217};
1218
Eric Christophercfd323d2011-06-21 00:05:20 +00001219const TargetInfo::AddlRegName AddlRegNames[] = {
1220 { { "al", "ah", "eax", "rax" }, 0 },
1221 { { "bl", "bh", "ebx", "rbx" }, 3 },
1222 { { "cl", "ch", "ecx", "rcx" }, 2 },
1223 { { "dl", "dh", "edx", "rdx" }, 1 },
1224 { { "esi", "rsi" }, 4 },
1225 { { "edi", "rdi" }, 5 },
1226 { { "esp", "rsp" }, 7 },
1227 { { "ebp", "rbp" }, 6 },
Eli Friedman618234a2008-08-20 02:34:37 +00001228};
1229
1230// X86 target abstract base class; x86-32 and x86-64 are very close, so
1231// most of the implementation can be shared.
1232class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +00001233 enum X86SSEEnum {
Craig Topper05fe4b52012-01-09 09:19:09 +00001234 NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2
Chris Lattner84f0ea82009-03-02 22:40:39 +00001235 } SSELevel;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001236 enum MMX3DNowEnum {
1237 NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon
1238 } MMX3DNowLevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001239
Eric Christophereea12d12010-04-02 23:50:19 +00001240 bool HasAES;
Craig Topper3c0bc152012-05-31 05:18:48 +00001241 bool HasPCLMUL;
Craig Topper31ceea02011-12-25 05:06:45 +00001242 bool HasLZCNT;
1243 bool HasBMI;
1244 bool HasBMI2;
Craig Toppere14e08b2011-12-29 16:10:46 +00001245 bool HasPOPCNT;
Benjamin Kramer4dfa5ad2012-05-29 17:48:39 +00001246 bool HasSSE4a;
Craig Topper6a511e12011-12-30 07:33:42 +00001247 bool HasFMA4;
Craig Topper2ae95072012-06-03 21:46:30 +00001248 bool HasFMA;
Craig Topperb6af69e2012-06-09 22:24:14 +00001249 bool HasXOP;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001250
Chandler Carruth499d9722011-09-28 08:55:34 +00001251 /// \brief Enumeration of all of the X86 CPUs supported by Clang.
1252 ///
1253 /// Each enumeration represents a particular CPU supported by Clang. These
1254 /// loosely correspond to the options passed to '-march' or '-mtune' flags.
1255 enum CPUKind {
1256 CK_Generic,
1257
1258 /// \name i386
1259 /// i386-generation processors.
1260 //@{
1261 CK_i386,
1262 //@}
1263
1264 /// \name i486
1265 /// i486-generation processors.
1266 //@{
1267 CK_i486,
1268 CK_WinChipC6,
1269 CK_WinChip2,
1270 CK_C3,
1271 //@}
1272
1273 /// \name i586
1274 /// i586-generation processors, P5 microarchitecture based.
1275 //@{
1276 CK_i586,
1277 CK_Pentium,
1278 CK_PentiumMMX,
1279 //@}
1280
1281 /// \name i686
1282 /// i686-generation processors, P6 / Pentium M microarchitecture based.
1283 //@{
1284 CK_i686,
1285 CK_PentiumPro,
1286 CK_Pentium2,
1287 CK_Pentium3,
1288 CK_Pentium3M,
1289 CK_PentiumM,
1290 CK_C3_2,
1291
1292 /// This enumerator is a bit odd, as GCC no longer accepts -march=yonah.
1293 /// Clang however has some logic to suport this.
1294 // FIXME: Warn, deprecate, and potentially remove this.
1295 CK_Yonah,
1296 //@}
1297
1298 /// \name Netburst
Chandler Carruth83450aa2011-09-28 18:17:30 +00001299 /// Netburst microarchitecture based processors.
Chandler Carruth499d9722011-09-28 08:55:34 +00001300 //@{
1301 CK_Pentium4,
1302 CK_Pentium4M,
1303 CK_Prescott,
1304 CK_Nocona,
1305 //@}
1306
1307 /// \name Core
1308 /// Core microarchitecture based processors.
1309 //@{
1310 CK_Core2,
1311
1312 /// This enumerator, like \see CK_Yonah, is a bit odd. It is another
1313 /// codename which GCC no longer accepts as an option to -march, but Clang
1314 /// has some logic for recognizing it.
1315 // FIXME: Warn, deprecate, and potentially remove this.
1316 CK_Penryn,
1317 //@}
1318
1319 /// \name Atom
1320 /// Atom processors
1321 //@{
1322 CK_Atom,
1323 //@}
1324
1325 /// \name Nehalem
1326 /// Nehalem microarchitecture based processors.
1327 //@{
1328 CK_Corei7,
1329 CK_Corei7AVX,
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001330 CK_CoreAVXi,
Craig Topper2b03bb02011-12-17 19:55:21 +00001331 CK_CoreAVX2,
Chandler Carruth499d9722011-09-28 08:55:34 +00001332 //@}
1333
1334 /// \name K6
1335 /// K6 architecture processors.
1336 //@{
1337 CK_K6,
1338 CK_K6_2,
1339 CK_K6_3,
1340 //@}
1341
1342 /// \name K7
1343 /// K7 architecture processors.
1344 //@{
1345 CK_Athlon,
1346 CK_AthlonThunderbird,
1347 CK_Athlon4,
1348 CK_AthlonXP,
1349 CK_AthlonMP,
1350 //@}
1351
1352 /// \name K8
1353 /// K8 architecture processors.
1354 //@{
1355 CK_Athlon64,
1356 CK_Athlon64SSE3,
1357 CK_AthlonFX,
1358 CK_K8,
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001359 CK_K8SSE3,
Chandler Carruth499d9722011-09-28 08:55:34 +00001360 CK_Opteron,
1361 CK_OpteronSSE3,
Roman Divacky01c770d2011-10-30 07:48:46 +00001362 CK_AMDFAM10,
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001363 //@}
Chandler Carruth499d9722011-09-28 08:55:34 +00001364
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001365 /// \name Bobcat
1366 /// Bobcat architecture processors.
1367 //@{
1368 CK_BTVER1,
1369 //@}
1370
1371 /// \name Bulldozer
1372 /// Bulldozer architecture processors.
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001373 //@{
1374 CK_BDVER1,
1375 CK_BDVER2,
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001376 //@}
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001377
Chandler Carruth499d9722011-09-28 08:55:34 +00001378 /// This specification is deprecated and will be removed in the future.
1379 /// Users should prefer \see CK_K8.
1380 // FIXME: Warn on this when the CPU is set to it.
1381 CK_x86_64,
1382 //@}
1383
1384 /// \name Geode
1385 /// Geode processors.
1386 //@{
1387 CK_Geode
1388 //@}
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001389 } CPU;
Chandler Carruth499d9722011-09-28 08:55:34 +00001390
Eli Friedman618234a2008-08-20 02:34:37 +00001391public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001392 X86TargetInfo(const std::string& triple)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001393 : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
Craig Topper3c0bc152012-05-31 05:18:48 +00001394 HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasBMI(false),
1395 HasBMI2(false), HasPOPCNT(false), HasSSE4a(false), HasFMA4(false),
Craig Topperb6af69e2012-06-09 22:24:14 +00001396 HasFMA(false), HasXOP(false), CPU(CK_Generic) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00001397 BigEndian = false;
Eli Friedman618234a2008-08-20 02:34:37 +00001398 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +00001399 }
Benjamin Kramerb4066692011-12-28 15:47:06 +00001400 virtual unsigned getFloatEvalMethod() const {
1401 // X87 evaluates with 80 bits "long double" precision.
1402 return SSELevel == NoSSE ? 2 : 0;
1403 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001404 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1405 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001406 Records = BuiltinInfo;
1407 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +00001408 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001409 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +00001410 unsigned &NumNames) const {
1411 Names = GCCRegNames;
1412 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +00001413 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001414 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +00001415 unsigned &NumAliases) const {
Eric Christophercfd323d2011-06-21 00:05:20 +00001416 Aliases = 0;
1417 NumAliases = 0;
1418 }
1419 virtual void getGCCAddlRegNames(const AddlRegName *&Names,
1420 unsigned &NumNames) const {
1421 Names = AddlRegNames;
1422 NumNames = llvm::array_lengthof(AddlRegNames);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001423 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001424 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +00001425 TargetInfo::ConstraintInfo &info) const;
Stuart Hastings002333f2011-06-07 23:45:05 +00001426 virtual std::string convertConstraint(const char *&Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +00001427 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +00001428 return "~{dirflag},~{fpsr},~{flags}";
1429 }
Chris Lattner33328642009-03-20 15:52:06 +00001430 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001431 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001432 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00001433 StringRef Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001434 bool Enabled) const;
Chandler Carruthc3a2e652011-09-28 05:56:05 +00001435 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const;
Douglas Gregore727d212012-01-30 06:38:25 +00001436 virtual bool hasFeature(StringRef Feature) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001437 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001438 virtual const char* getABI() const {
Craig Topper05fe4b52012-01-09 09:19:09 +00001439 if (PointerWidth == 64 && SSELevel >= AVX)
Eli Friedmanee1ad992011-12-02 00:11:43 +00001440 return "avx";
1441 else if (PointerWidth == 32 && MMX3DNowLevel == NoMMX3DNow)
1442 return "no-mmx";
1443 return "";
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001444 }
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001445 virtual bool setCPU(const std::string &Name) {
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001446 CPU = llvm::StringSwitch<CPUKind>(Name)
1447 .Case("i386", CK_i386)
1448 .Case("i486", CK_i486)
1449 .Case("winchip-c6", CK_WinChipC6)
1450 .Case("winchip2", CK_WinChip2)
1451 .Case("c3", CK_C3)
1452 .Case("i586", CK_i586)
1453 .Case("pentium", CK_Pentium)
1454 .Case("pentium-mmx", CK_PentiumMMX)
1455 .Case("i686", CK_i686)
1456 .Case("pentiumpro", CK_PentiumPro)
1457 .Case("pentium2", CK_Pentium2)
1458 .Case("pentium3", CK_Pentium3)
1459 .Case("pentium3m", CK_Pentium3M)
1460 .Case("pentium-m", CK_PentiumM)
1461 .Case("c3-2", CK_C3_2)
1462 .Case("yonah", CK_Yonah)
1463 .Case("pentium4", CK_Pentium4)
1464 .Case("pentium4m", CK_Pentium4M)
1465 .Case("prescott", CK_Prescott)
1466 .Case("nocona", CK_Nocona)
1467 .Case("core2", CK_Core2)
1468 .Case("penryn", CK_Penryn)
1469 .Case("atom", CK_Atom)
1470 .Case("corei7", CK_Corei7)
1471 .Case("corei7-avx", CK_Corei7AVX)
1472 .Case("core-avx-i", CK_CoreAVXi)
Craig Topper2b03bb02011-12-17 19:55:21 +00001473 .Case("core-avx2", CK_CoreAVX2)
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001474 .Case("k6", CK_K6)
1475 .Case("k6-2", CK_K6_2)
1476 .Case("k6-3", CK_K6_3)
1477 .Case("athlon", CK_Athlon)
1478 .Case("athlon-tbird", CK_AthlonThunderbird)
1479 .Case("athlon-4", CK_Athlon4)
1480 .Case("athlon-xp", CK_AthlonXP)
1481 .Case("athlon-mp", CK_AthlonMP)
1482 .Case("athlon64", CK_Athlon64)
1483 .Case("athlon64-sse3", CK_Athlon64SSE3)
1484 .Case("athlon-fx", CK_AthlonFX)
1485 .Case("k8", CK_K8)
1486 .Case("k8-sse3", CK_K8SSE3)
1487 .Case("opteron", CK_Opteron)
1488 .Case("opteron-sse3", CK_OpteronSSE3)
Roman Divacky01c770d2011-10-30 07:48:46 +00001489 .Case("amdfam10", CK_AMDFAM10)
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001490 .Case("btver1", CK_BTVER1)
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001491 .Case("bdver1", CK_BDVER1)
1492 .Case("bdver2", CK_BDVER2)
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001493 .Case("x86-64", CK_x86_64)
1494 .Case("geode", CK_Geode)
1495 .Default(CK_Generic);
1496
Chandler Carruth26a39142011-09-28 09:45:08 +00001497 // Perform any per-CPU checks necessary to determine if this CPU is
1498 // acceptable.
1499 // FIXME: This results in terrible diagnostics. Clang just says the CPU is
1500 // invalid without explaining *why*.
1501 switch (CPU) {
1502 case CK_Generic:
1503 // No processor selected!
1504 return false;
1505
1506 case CK_i386:
1507 case CK_i486:
1508 case CK_WinChipC6:
1509 case CK_WinChip2:
1510 case CK_C3:
1511 case CK_i586:
1512 case CK_Pentium:
1513 case CK_PentiumMMX:
1514 case CK_i686:
1515 case CK_PentiumPro:
1516 case CK_Pentium2:
1517 case CK_Pentium3:
1518 case CK_Pentium3M:
1519 case CK_PentiumM:
1520 case CK_Yonah:
1521 case CK_C3_2:
1522 case CK_Pentium4:
1523 case CK_Pentium4M:
1524 case CK_Prescott:
1525 case CK_K6:
1526 case CK_K6_2:
1527 case CK_K6_3:
1528 case CK_Athlon:
1529 case CK_AthlonThunderbird:
1530 case CK_Athlon4:
1531 case CK_AthlonXP:
1532 case CK_AthlonMP:
1533 case CK_Geode:
1534 // Only accept certain architectures when compiling in 32-bit mode.
1535 if (PointerWidth != 32)
1536 return false;
1537
1538 // Fallthrough
1539 case CK_Nocona:
1540 case CK_Core2:
1541 case CK_Penryn:
1542 case CK_Atom:
1543 case CK_Corei7:
1544 case CK_Corei7AVX:
1545 case CK_CoreAVXi:
Craig Topper2b03bb02011-12-17 19:55:21 +00001546 case CK_CoreAVX2:
Chandler Carruth26a39142011-09-28 09:45:08 +00001547 case CK_Athlon64:
1548 case CK_Athlon64SSE3:
1549 case CK_AthlonFX:
1550 case CK_K8:
1551 case CK_K8SSE3:
1552 case CK_Opteron:
1553 case CK_OpteronSSE3:
Roman Divacky01c770d2011-10-30 07:48:46 +00001554 case CK_AMDFAM10:
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001555 case CK_BTVER1:
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001556 case CK_BDVER1:
1557 case CK_BDVER2:
Chandler Carruth26a39142011-09-28 09:45:08 +00001558 case CK_x86_64:
1559 return true;
1560 }
Chandler Carruth5b7803d2011-09-28 10:49:06 +00001561 llvm_unreachable("Unhandled CPU kind");
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001562 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001563};
Chris Lattner3daed522009-03-02 22:20:04 +00001564
Chandler Carruthc3a2e652011-09-28 05:56:05 +00001565void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001566 // FIXME: This should not be here.
1567 Features["3dnow"] = false;
1568 Features["3dnowa"] = false;
1569 Features["mmx"] = false;
1570 Features["sse"] = false;
1571 Features["sse2"] = false;
1572 Features["sse3"] = false;
1573 Features["ssse3"] = false;
1574 Features["sse41"] = false;
1575 Features["sse42"] = false;
Roman Divacky80b32b82011-10-30 13:47:56 +00001576 Features["sse4a"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001577 Features["aes"] = false;
Craig Topper3c0bc152012-05-31 05:18:48 +00001578 Features["pclmul"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001579 Features["avx"] = false;
Craig Topper2b03bb02011-12-17 19:55:21 +00001580 Features["avx2"] = false;
Craig Topper31ceea02011-12-25 05:06:45 +00001581 Features["lzcnt"] = false;
1582 Features["bmi"] = false;
1583 Features["bmi2"] = false;
Craig Toppere14e08b2011-12-29 16:10:46 +00001584 Features["popcnt"] = false;
Craig Topper6a511e12011-12-30 07:33:42 +00001585 Features["fma4"] = false;
Craig Topper2ae95072012-06-03 21:46:30 +00001586 Features["fma"] = false;
Craig Topperb6af69e2012-06-09 22:24:14 +00001587 Features["xop"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001588
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001589 // FIXME: This *really* should not be here.
1590
1591 // X86_64 always has SSE2.
1592 if (PointerWidth == 64)
1593 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
1594
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001595 switch (CPU) {
1596 case CK_Generic:
1597 case CK_i386:
1598 case CK_i486:
1599 case CK_i586:
1600 case CK_Pentium:
1601 case CK_i686:
1602 case CK_PentiumPro:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001603 break;
1604 case CK_PentiumMMX:
1605 case CK_Pentium2:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001606 setFeatureEnabled(Features, "mmx", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001607 break;
1608 case CK_Pentium3:
1609 case CK_Pentium3M:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001610 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001611 setFeatureEnabled(Features, "sse", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001612 break;
1613 case CK_PentiumM:
1614 case CK_Pentium4:
1615 case CK_Pentium4M:
1616 case CK_x86_64:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001617 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001618 setFeatureEnabled(Features, "sse2", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001619 break;
1620 case CK_Yonah:
1621 case CK_Prescott:
1622 case CK_Nocona:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001623 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001624 setFeatureEnabled(Features, "sse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001625 break;
1626 case CK_Core2:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001627 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001628 setFeatureEnabled(Features, "ssse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001629 break;
1630 case CK_Penryn:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001631 setFeatureEnabled(Features, "mmx", true);
Benjamin Kramerb3453a82012-01-04 14:36:57 +00001632 setFeatureEnabled(Features, "sse4.1", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001633 break;
1634 case CK_Atom:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001635 setFeatureEnabled(Features, "mmx", true);
Chandler Carruth49defe62011-09-28 10:36:46 +00001636 setFeatureEnabled(Features, "ssse3", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001637 break;
1638 case CK_Corei7:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001639 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001640 setFeatureEnabled(Features, "sse4", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001641 break;
1642 case CK_Corei7AVX:
1643 case CK_CoreAVXi:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001644 setFeatureEnabled(Features, "mmx", true);
Craig Topperfd936302012-04-26 07:31:30 +00001645 setFeatureEnabled(Features, "avx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001646 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00001647 setFeatureEnabled(Features, "pclmul", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001648 break;
Craig Topper2b03bb02011-12-17 19:55:21 +00001649 case CK_CoreAVX2:
1650 setFeatureEnabled(Features, "mmx", true);
Craig Topperfd936302012-04-26 07:31:30 +00001651 setFeatureEnabled(Features, "avx2", true);
Craig Topper2b03bb02011-12-17 19:55:21 +00001652 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00001653 setFeatureEnabled(Features, "pclmul", true);
Craig Topper31ceea02011-12-25 05:06:45 +00001654 setFeatureEnabled(Features, "lzcnt", true);
1655 setFeatureEnabled(Features, "bmi", true);
1656 setFeatureEnabled(Features, "bmi2", true);
Craig Topper2ae95072012-06-03 21:46:30 +00001657 setFeatureEnabled(Features, "fma", true);
Craig Topper2b03bb02011-12-17 19:55:21 +00001658 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001659 case CK_K6:
1660 case CK_WinChipC6:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001661 setFeatureEnabled(Features, "mmx", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001662 break;
1663 case CK_K6_2:
1664 case CK_K6_3:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001665 case CK_WinChip2:
1666 case CK_C3:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001667 setFeatureEnabled(Features, "3dnow", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001668 break;
Chandler Carruth49defe62011-09-28 10:36:46 +00001669 case CK_Athlon:
1670 case CK_AthlonThunderbird:
1671 case CK_Geode:
1672 setFeatureEnabled(Features, "3dnowa", true);
1673 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001674 case CK_Athlon4:
1675 case CK_AthlonXP:
1676 case CK_AthlonMP:
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001677 setFeatureEnabled(Features, "sse", true);
1678 setFeatureEnabled(Features, "3dnowa", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001679 break;
1680 case CK_K8:
1681 case CK_Opteron:
1682 case CK_Athlon64:
1683 case CK_AthlonFX:
Mike Stump1eb44332009-09-09 15:08:12 +00001684 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001685 setFeatureEnabled(Features, "3dnowa", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001686 break;
1687 case CK_K8SSE3:
1688 case CK_OpteronSSE3:
1689 case CK_Athlon64SSE3:
Roman Divacky80b32b82011-10-30 13:47:56 +00001690 setFeatureEnabled(Features, "sse3", true);
1691 setFeatureEnabled(Features, "3dnowa", true);
1692 break;
Roman Divacky01c770d2011-10-30 07:48:46 +00001693 case CK_AMDFAM10:
Roman Divackyc8b09a12010-12-29 13:28:29 +00001694 setFeatureEnabled(Features, "sse3", true);
Roman Divacky80b32b82011-10-30 13:47:56 +00001695 setFeatureEnabled(Features, "sse4a", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00001696 setFeatureEnabled(Features, "3dnowa", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001697 break;
Benjamin Kramer5660aa62012-01-10 11:50:18 +00001698 case CK_BTVER1:
1699 setFeatureEnabled(Features, "ssse3", true);
1700 setFeatureEnabled(Features, "sse4a", true);
Craig Topper90ea0362012-05-30 05:54:54 +00001701 break;
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001702 case CK_BDVER1:
1703 case CK_BDVER2:
Craig Topper70d9b162012-05-01 07:18:03 +00001704 setFeatureEnabled(Features, "avx", true);
Craig Topperb6af69e2012-06-09 22:24:14 +00001705 setFeatureEnabled(Features, "xop", true);
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001706 setFeatureEnabled(Features, "aes", true);
Craig Topper3c0bc152012-05-31 05:18:48 +00001707 setFeatureEnabled(Features, "pclmul", true);
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00001708 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001709 case CK_C3_2:
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001710 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001711 setFeatureEnabled(Features, "sse", true);
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001712 break;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001713 }
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001714}
1715
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001716bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00001717 StringRef Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001718 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001719 // FIXME: This *really* should not be here. We need some way of translating
1720 // options into llvm subtarget features.
1721 if (!Features.count(Name) &&
1722 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001723 return false;
1724
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001725 // FIXME: this should probably use a switch with fall through.
1726
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001727 if (Enabled) {
1728 if (Name == "mmx")
1729 Features["mmx"] = true;
1730 else if (Name == "sse")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001731 Features["mmx"] = Features["sse"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001732 else if (Name == "sse2")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001733 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001734 else if (Name == "sse3")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001735 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1736 true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001737 else if (Name == "ssse3")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001738 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001739 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001740 else if (Name == "sse4" || Name == "sse4.2")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001741 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Craig Toppere14e08b2011-12-29 16:10:46 +00001742 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
1743 Features["popcnt"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001744 else if (Name == "sse4.1")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001745 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Eric Christopherd39ebe22010-03-04 02:26:37 +00001746 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001747 else if (Name == "3dnow")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001748 Features["mmx"] = Features["3dnow"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001749 else if (Name == "3dnowa")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001750 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001751 else if (Name == "aes")
Craig Toppera7463c32012-06-03 21:56:22 +00001752 Features["sse"] = Features["sse2"] = Features["aes"] = true;
Craig Topper3c0bc152012-05-31 05:18:48 +00001753 else if (Name == "pclmul")
Craig Toppera7463c32012-06-03 21:56:22 +00001754 Features["sse"] = Features["sse2"] = Features["pclmul"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001755 else if (Name == "avx")
Rafael Espindola53ac3d82011-11-27 20:00:43 +00001756 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1757 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
Craig Toppere14e08b2011-12-29 16:10:46 +00001758 Features["popcnt"] = Features["avx"] = true;
Craig Topper2b03bb02011-12-17 19:55:21 +00001759 else if (Name == "avx2")
1760 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1761 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
Craig Toppere14e08b2011-12-29 16:10:46 +00001762 Features["popcnt"] = Features["avx"] = Features["avx2"] = true;
Craig Topper2ae95072012-06-03 21:46:30 +00001763 else if (Name == "fma")
1764 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1765 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
1766 Features["popcnt"] = Features["avx"] = Features["fma"] = true;
Craig Topper6a511e12011-12-30 07:33:42 +00001767 else if (Name == "fma4")
1768 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1769 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
Craig Topper90ea0362012-05-30 05:54:54 +00001770 Features["popcnt"] = Features["avx"] = Features["sse4a"] =
1771 Features["fma4"] = true;
Craig Topperb6af69e2012-06-09 22:24:14 +00001772 else if (Name == "xop")
1773 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1774 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
1775 Features["popcnt"] = Features["avx"] = Features["sse4a"] =
1776 Features["fma4"] = Features["xop"] = true;
Roman Divacky80b32b82011-10-30 13:47:56 +00001777 else if (Name == "sse4a")
Craig Topper6a511e12011-12-30 07:33:42 +00001778 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Craig Topper90ea0362012-05-30 05:54:54 +00001779 Features["sse4a"] = true;
Craig Topper31ceea02011-12-25 05:06:45 +00001780 else if (Name == "lzcnt")
1781 Features["lzcnt"] = true;
1782 else if (Name == "bmi")
1783 Features["bmi"] = true;
1784 else if (Name == "bmi2")
1785 Features["bmi2"] = true;
Craig Toppere14e08b2011-12-29 16:10:46 +00001786 else if (Name == "popcnt")
1787 Features["popcnt"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001788 } else {
1789 if (Name == "mmx")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001790 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001791 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001792 Features["sse"] = Features["sse2"] = Features["sse3"] =
Craig Topper6a511e12011-12-30 07:33:42 +00001793 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
Craig Topper31380fb2012-06-03 22:23:42 +00001794 Features["sse4a"] = Features["avx"] = Features["avx2"] =
1795 Features["fma"] = Features["fma4"] = Features["aes"] =
Craig Topperb6af69e2012-06-09 22:24:14 +00001796 Features["pclmul"] = Features["xop"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001797 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001798 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Craig Toppera7463c32012-06-03 21:56:22 +00001799 Features["sse41"] = Features["sse42"] = Features["sse4a"] =
Craig Topper31380fb2012-06-03 22:23:42 +00001800 Features["avx"] = Features["avx2"] = Features["fma"] =
Craig Topperb6af69e2012-06-09 22:24:14 +00001801 Features["fma4"] = Features["aes"] = Features["pclmul"] =
1802 Features["xop"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001803 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001804 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Craig Topper31380fb2012-06-03 22:23:42 +00001805 Features["sse42"] = Features["sse4a"] = Features["avx"] =
Craig Topperb6af69e2012-06-09 22:24:14 +00001806 Features["avx2"] = Features["fma"] = Features["fma4"] =
1807 Features["xop"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001808 else if (Name == "ssse3")
Craig Topper31380fb2012-06-03 22:23:42 +00001809 Features["ssse3"] = Features["sse41"] = Features["sse42"] =
1810 Features["avx"] = Features["avx2"] = Features["fma"] = false;
Michael J. Spencerb24bac92011-04-17 19:22:03 +00001811 else if (Name == "sse4" || Name == "sse4.1")
Craig Topper31380fb2012-06-03 22:23:42 +00001812 Features["sse41"] = Features["sse42"] = Features["avx"] =
1813 Features["avx2"] = Features["fma"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001814 else if (Name == "sse4.2")
Craig Topper31380fb2012-06-03 22:23:42 +00001815 Features["sse42"] = Features["avx"] = Features["avx2"] =
1816 Features["fma"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001817 else if (Name == "3dnow")
1818 Features["3dnow"] = Features["3dnowa"] = false;
1819 else if (Name == "3dnowa")
1820 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001821 else if (Name == "aes")
1822 Features["aes"] = false;
Craig Topper3c0bc152012-05-31 05:18:48 +00001823 else if (Name == "pclmul")
1824 Features["pclmul"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001825 else if (Name == "avx")
Craig Topper2ae95072012-06-03 21:46:30 +00001826 Features["avx"] = Features["avx2"] = Features["fma"] =
Craig Topperb6af69e2012-06-09 22:24:14 +00001827 Features["fma4"] = Features["xop"] = false;
Craig Topper2b03bb02011-12-17 19:55:21 +00001828 else if (Name == "avx2")
1829 Features["avx2"] = false;
Craig Topper2ae95072012-06-03 21:46:30 +00001830 else if (Name == "fma")
1831 Features["fma"] = false;
Roman Divacky80b32b82011-10-30 13:47:56 +00001832 else if (Name == "sse4a")
Craig Topperb6af69e2012-06-09 22:24:14 +00001833 Features["sse4a"] = Features["fma4"] = Features["xop"] = false;
Craig Topper31ceea02011-12-25 05:06:45 +00001834 else if (Name == "lzcnt")
1835 Features["lzcnt"] = false;
1836 else if (Name == "bmi")
1837 Features["bmi"] = false;
1838 else if (Name == "bmi2")
1839 Features["bmi2"] = false;
Craig Toppere14e08b2011-12-29 16:10:46 +00001840 else if (Name == "popcnt")
1841 Features["popcnt"] = false;
Craig Topper6a511e12011-12-30 07:33:42 +00001842 else if (Name == "fma4")
Craig Topperb6af69e2012-06-09 22:24:14 +00001843 Features["fma4"] = Features["xop"] = false;
1844 else if (Name == "xop")
1845 Features["xop"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001846 }
1847
1848 return true;
1849}
1850
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001851/// HandleTargetOptions - Perform initialization based on the user
1852/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001853void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001854 // Remember the maximum enabled sselevel.
1855 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1856 // Ignore disabled features.
1857 if (Features[i][0] == '-')
1858 continue;
1859
Benjamin Kramer713575a2012-03-05 15:10:44 +00001860 StringRef Feature = StringRef(Features[i]).substr(1);
1861
1862 if (Feature == "aes") {
Eric Christophereea12d12010-04-02 23:50:19 +00001863 HasAES = true;
1864 continue;
1865 }
1866
Craig Topper3c0bc152012-05-31 05:18:48 +00001867 if (Feature == "pclmul") {
1868 HasPCLMUL = true;
1869 continue;
1870 }
1871
Benjamin Kramer713575a2012-03-05 15:10:44 +00001872 if (Feature == "lzcnt") {
Craig Topper31ceea02011-12-25 05:06:45 +00001873 HasLZCNT = true;
1874 continue;
1875 }
1876
Benjamin Kramer713575a2012-03-05 15:10:44 +00001877 if (Feature == "bmi") {
Craig Topper31ceea02011-12-25 05:06:45 +00001878 HasBMI = true;
1879 continue;
1880 }
1881
Benjamin Kramer713575a2012-03-05 15:10:44 +00001882 if (Feature == "bmi2") {
Craig Topper31ceea02011-12-25 05:06:45 +00001883 HasBMI2 = true;
1884 continue;
1885 }
1886
Benjamin Kramer713575a2012-03-05 15:10:44 +00001887 if (Feature == "popcnt") {
Craig Toppere14e08b2011-12-29 16:10:46 +00001888 HasPOPCNT = true;
1889 continue;
1890 }
1891
Benjamin Kramer4dfa5ad2012-05-29 17:48:39 +00001892 if (Feature == "sse4a") {
1893 HasSSE4a = true;
1894 continue;
1895 }
1896
Benjamin Kramer713575a2012-03-05 15:10:44 +00001897 if (Feature == "fma4") {
Craig Topper6a511e12011-12-30 07:33:42 +00001898 HasFMA4 = true;
1899 continue;
1900 }
1901
Craig Topper2ae95072012-06-03 21:46:30 +00001902 if (Feature == "fma") {
1903 HasFMA = true;
1904 continue;
1905 }
1906
Craig Topperb6af69e2012-06-09 22:24:14 +00001907 if (Feature == "xop") {
1908 HasXOP = true;
1909 continue;
1910 }
1911
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001912 assert(Features[i][0] == '+' && "Invalid target feature!");
Benjamin Kramer713575a2012-03-05 15:10:44 +00001913 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
Craig Topper05fe4b52012-01-09 09:19:09 +00001914 .Case("avx2", AVX2)
1915 .Case("avx", AVX)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001916 .Case("sse42", SSE42)
1917 .Case("sse41", SSE41)
1918 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001919 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001920 .Case("sse2", SSE2)
1921 .Case("sse", SSE1)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001922 .Default(NoSSE);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001923 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001924
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001925 MMX3DNowEnum ThreeDNowLevel =
Benjamin Kramer713575a2012-03-05 15:10:44 +00001926 llvm::StringSwitch<MMX3DNowEnum>(Feature)
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001927 .Case("3dnowa", AMD3DNowAthlon)
1928 .Case("3dnow", AMD3DNow)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001929 .Case("mmx", MMX)
1930 .Default(NoMMX3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001931
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001932 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001933 }
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001934
1935 // Don't tell the backend if we're turning off mmx; it will end up disabling
1936 // SSE, which we don't want.
1937 std::vector<std::string>::iterator it;
1938 it = std::find(Features.begin(), Features.end(), "-mmx");
1939 if (it != Features.end())
1940 Features.erase(it);
Chris Lattner3daed522009-03-02 22:20:04 +00001941}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001942
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001943/// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
1944/// definitions for this particular subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001945void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001946 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001947 // Target identification.
1948 if (PointerWidth == 64) {
Aaron Ballmanc0765a02012-03-14 20:50:57 +00001949 if (getLongWidth() == 64) {
1950 Builder.defineMacro("_LP64");
1951 Builder.defineMacro("__LP64__");
1952 }
Benjamin Kramera9992772010-01-09 17:55:51 +00001953 Builder.defineMacro("__amd64__");
1954 Builder.defineMacro("__amd64");
1955 Builder.defineMacro("__x86_64");
1956 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001957 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001958 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001959 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001960
Chris Lattnerc0f59212009-03-02 22:27:17 +00001961 // Subtarget options.
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001962 // FIXME: We are hard-coding the tune parameters based on the CPU, but they
1963 // truly should be based on -mtune options.
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001964 switch (CPU) {
1965 case CK_Generic:
1966 break;
1967 case CK_i386:
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00001968 // The rest are coming from the i386 define above.
1969 Builder.defineMacro("__tune_i386__");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001970 break;
1971 case CK_i486:
1972 case CK_WinChipC6:
1973 case CK_WinChip2:
1974 case CK_C3:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00001975 defineCPUMacros(Builder, "i486");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001976 break;
Chandler Carruthf17ba332011-09-28 09:45:05 +00001977 case CK_PentiumMMX:
1978 Builder.defineMacro("__pentium_mmx__");
1979 Builder.defineMacro("__tune_pentium_mmx__");
1980 // Fallthrough
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001981 case CK_i586:
1982 case CK_Pentium:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00001983 defineCPUMacros(Builder, "i586");
1984 defineCPUMacros(Builder, "pentium");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001985 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001986 case CK_Pentium3:
1987 case CK_Pentium3M:
1988 case CK_PentiumM:
Chandler Carruthf17ba332011-09-28 09:45:05 +00001989 Builder.defineMacro("__tune_pentium3__");
1990 // Fallthrough
1991 case CK_Pentium2:
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00001992 case CK_C3_2:
Chandler Carruthf17ba332011-09-28 09:45:05 +00001993 Builder.defineMacro("__tune_pentium2__");
1994 // Fallthrough
1995 case CK_PentiumPro:
1996 Builder.defineMacro("__tune_i686__");
1997 Builder.defineMacro("__tune_pentiumpro__");
1998 // Fallthrough
1999 case CK_i686:
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002000 Builder.defineMacro("__i686");
2001 Builder.defineMacro("__i686__");
2002 // Strangely, __tune_i686__ isn't defined by GCC when CPU == i686.
2003 Builder.defineMacro("__pentiumpro");
2004 Builder.defineMacro("__pentiumpro__");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002005 break;
2006 case CK_Pentium4:
2007 case CK_Pentium4M:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002008 defineCPUMacros(Builder, "pentium4");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002009 break;
2010 case CK_Yonah:
2011 case CK_Prescott:
2012 case CK_Nocona:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002013 defineCPUMacros(Builder, "nocona");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002014 break;
2015 case CK_Core2:
2016 case CK_Penryn:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002017 defineCPUMacros(Builder, "core2");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002018 break;
2019 case CK_Atom:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002020 defineCPUMacros(Builder, "atom");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002021 break;
2022 case CK_Corei7:
2023 case CK_Corei7AVX:
2024 case CK_CoreAVXi:
Craig Topper2b03bb02011-12-17 19:55:21 +00002025 case CK_CoreAVX2:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002026 defineCPUMacros(Builder, "corei7");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002027 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002028 case CK_K6_2:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002029 Builder.defineMacro("__k6_2__");
2030 Builder.defineMacro("__tune_k6_2__");
2031 // Fallthrough
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002032 case CK_K6_3:
Chandler Carruthf17ba332011-09-28 09:45:05 +00002033 if (CPU != CK_K6_2) { // In case of fallthrough
2034 // FIXME: GCC may be enabling these in cases where some other k6
2035 // architecture is specified but -m3dnow is explicitly provided. The
2036 // exact semantics need to be determined and emulated here.
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002037 Builder.defineMacro("__k6_3__");
2038 Builder.defineMacro("__tune_k6_3__");
2039 }
Chandler Carruthf17ba332011-09-28 09:45:05 +00002040 // Fallthrough
2041 case CK_K6:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002042 defineCPUMacros(Builder, "k6");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002043 break;
2044 case CK_Athlon:
2045 case CK_AthlonThunderbird:
2046 case CK_Athlon4:
2047 case CK_AthlonXP:
2048 case CK_AthlonMP:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002049 defineCPUMacros(Builder, "athlon");
Chandler Carruth53bf4f92011-09-28 09:54:11 +00002050 if (SSELevel != NoSSE) {
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002051 Builder.defineMacro("__athlon_sse__");
Chandler Carruth53bf4f92011-09-28 09:54:11 +00002052 Builder.defineMacro("__tune_athlon_sse__");
2053 }
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002054 break;
2055 case CK_K8:
2056 case CK_K8SSE3:
2057 case CK_x86_64:
2058 case CK_Opteron:
2059 case CK_OpteronSSE3:
2060 case CK_Athlon64:
2061 case CK_Athlon64SSE3:
2062 case CK_AthlonFX:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002063 defineCPUMacros(Builder, "k8");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002064 break;
Roman Divacky01c770d2011-10-30 07:48:46 +00002065 case CK_AMDFAM10:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002066 defineCPUMacros(Builder, "amdfam10");
Roman Divacky01c770d2011-10-30 07:48:46 +00002067 break;
Benjamin Kramer5660aa62012-01-10 11:50:18 +00002068 case CK_BTVER1:
2069 defineCPUMacros(Builder, "btver1");
2070 break;
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002071 case CK_BDVER1:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002072 defineCPUMacros(Builder, "bdver1");
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002073 break;
2074 case CK_BDVER2:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002075 defineCPUMacros(Builder, "bdver2");
Benjamin Kramer61ea4fe2011-12-01 18:23:59 +00002076 break;
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002077 case CK_Geode:
Benjamin Kramer448f68d2012-01-10 11:50:09 +00002078 defineCPUMacros(Builder, "geode");
Chandler Carruthd9d3ddf2011-09-28 08:55:37 +00002079 break;
Chandler Carruthf6cf1c22011-09-28 02:59:25 +00002080 }
Chris Lattner84f0ea82009-03-02 22:40:39 +00002081
Chandler Carruth88c75b02011-09-28 09:54:07 +00002082 // Target properties.
2083 Builder.defineMacro("__LITTLE_ENDIAN__");
2084 Builder.defineMacro("__REGISTER_PREFIX__", "");
2085
Chris Lattner54175442009-04-19 17:32:33 +00002086 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
2087 // functions in glibc header files that use FP Stack inline asm which the
2088 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00002089 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002090
Chandler Carruth88c75b02011-09-28 09:54:07 +00002091 if (HasAES)
2092 Builder.defineMacro("__AES__");
2093
Craig Topper3c0bc152012-05-31 05:18:48 +00002094 if (HasPCLMUL)
2095 Builder.defineMacro("__PCLMUL__");
2096
Craig Topper31ceea02011-12-25 05:06:45 +00002097 if (HasLZCNT)
2098 Builder.defineMacro("__LZCNT__");
2099
2100 if (HasBMI)
2101 Builder.defineMacro("__BMI__");
2102
2103 if (HasBMI2)
2104 Builder.defineMacro("__BMI2__");
2105
Craig Toppere14e08b2011-12-29 16:10:46 +00002106 if (HasPOPCNT)
2107 Builder.defineMacro("__POPCNT__");
2108
Benjamin Kramer4dfa5ad2012-05-29 17:48:39 +00002109 if (HasSSE4a)
2110 Builder.defineMacro("__SSE4A__");
2111
Craig Topper6a511e12011-12-30 07:33:42 +00002112 if (HasFMA4)
2113 Builder.defineMacro("__FMA4__");
2114
Craig Topper2ae95072012-06-03 21:46:30 +00002115 if (HasFMA)
2116 Builder.defineMacro("__FMA__");
2117
Craig Topperb6af69e2012-06-09 22:24:14 +00002118 if (HasXOP)
2119 Builder.defineMacro("__XOP__");
2120
Chris Lattner84f0ea82009-03-02 22:40:39 +00002121 // Each case falls through to the previous one here.
2122 switch (SSELevel) {
Craig Topper05fe4b52012-01-09 09:19:09 +00002123 case AVX2:
2124 Builder.defineMacro("__AVX2__");
2125 case AVX:
2126 Builder.defineMacro("__AVX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002127 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00002128 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002129 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00002130 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002131 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00002132 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002133 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00002134 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00002135 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00002136 Builder.defineMacro("__SSE2__");
2137 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00002138 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00002139 Builder.defineMacro("__SSE__");
2140 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002141 case NoSSE:
Chris Lattner84f0ea82009-03-02 22:40:39 +00002142 break;
2143 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00002144
Francois Pichet62ec1f22011-09-17 17:15:52 +00002145 if (Opts.MicrosoftExt && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002146 switch (SSELevel) {
Craig Topper05fe4b52012-01-09 09:19:09 +00002147 case AVX2:
2148 case AVX:
Michael J. Spencera764e832010-10-21 08:22:51 +00002149 case SSE42:
2150 case SSE41:
2151 case SSSE3:
2152 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002153 case SSE2:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002154 Builder.defineMacro("_M_IX86_FP", Twine(2));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002155 break;
2156 case SSE1:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002157 Builder.defineMacro("_M_IX86_FP", Twine(1));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002158 break;
2159 default:
Chris Lattner5f9e2722011-07-23 10:55:15 +00002160 Builder.defineMacro("_M_IX86_FP", Twine(0));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002161 }
2162 }
2163
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002164 // Each case falls through to the previous one here.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002165 switch (MMX3DNowLevel) {
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002166 case AMD3DNowAthlon:
2167 Builder.defineMacro("__3dNOW_A__");
2168 case AMD3DNow:
2169 Builder.defineMacro("__3dNOW__");
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00002170 case MMX:
2171 Builder.defineMacro("__MMX__");
2172 case NoMMX3DNow:
Anders Carlsson9b0fb622010-01-27 03:47:49 +00002173 break;
2174 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00002175}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002176
Douglas Gregore727d212012-01-30 06:38:25 +00002177bool X86TargetInfo::hasFeature(StringRef Feature) const {
2178 return llvm::StringSwitch<bool>(Feature)
2179 .Case("aes", HasAES)
2180 .Case("avx", SSELevel >= AVX)
2181 .Case("avx2", SSELevel >= AVX2)
2182 .Case("bmi", HasBMI)
2183 .Case("bmi2", HasBMI2)
Craig Topper2ae95072012-06-03 21:46:30 +00002184 .Case("fma", HasFMA)
Douglas Gregore727d212012-01-30 06:38:25 +00002185 .Case("fma4", HasFMA4)
2186 .Case("lzcnt", HasLZCNT)
2187 .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
2188 .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
2189 .Case("mmx", MMX3DNowLevel >= MMX)
Craig Topper3c0bc152012-05-31 05:18:48 +00002190 .Case("pclmul", HasPCLMUL)
Douglas Gregore727d212012-01-30 06:38:25 +00002191 .Case("popcnt", HasPOPCNT)
2192 .Case("sse", SSELevel >= SSE1)
2193 .Case("sse2", SSELevel >= SSE2)
2194 .Case("sse3", SSELevel >= SSE3)
2195 .Case("ssse3", SSELevel >= SSSE3)
2196 .Case("sse41", SSELevel >= SSE41)
2197 .Case("sse42", SSELevel >= SSE42)
Craig Topper3c0bc152012-05-31 05:18:48 +00002198 .Case("sse4a", HasSSE4a)
Douglas Gregore727d212012-01-30 06:38:25 +00002199 .Case("x86", true)
2200 .Case("x86_32", PointerWidth == 32)
2201 .Case("x86_64", PointerWidth == 64)
Craig Topperb6af69e2012-06-09 22:24:14 +00002202 .Case("xop", HasXOP)
Douglas Gregore727d212012-01-30 06:38:25 +00002203 .Default(false);
2204}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002205
Eli Friedman618234a2008-08-20 02:34:37 +00002206bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002207X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00002208 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002209 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00002210 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00002211 case 'Y': // first letter of a pair:
2212 switch (*(Name+1)) {
2213 default: return false;
2214 case '0': // First SSE register.
2215 case 't': // Any SSE register, when SSE2 is enabled.
2216 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
2217 case 'm': // any MMX register, when inter-unit moves enabled.
2218 break; // falls through to setAllowsRegister.
2219 }
Eli Friedman618234a2008-08-20 02:34:37 +00002220 case 'a': // eax.
2221 case 'b': // ebx.
2222 case 'c': // ecx.
2223 case 'd': // edx.
2224 case 'S': // esi.
2225 case 'D': // edi.
2226 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00002227 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00002228 case 't': // top of floating point stack.
2229 case 'u': // second from top of floating point stack.
2230 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00002231 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00002232 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00002233 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00002234 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
2235 case 'l': // "Index" registers: any general register that can be used as an
2236 // index in a base+index memory access.
2237 Info.setAllowsRegister();
2238 return true;
2239 case 'C': // SSE floating point constant.
2240 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002241 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00002242 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002243 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00002244 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00002245 return true;
2246 }
2247}
2248
Dale Johannesenf6e2c202010-10-29 23:12:32 +00002249
Eli Friedman618234a2008-08-20 02:34:37 +00002250std::string
Stuart Hastings002333f2011-06-07 23:45:05 +00002251X86TargetInfo::convertConstraint(const char *&Constraint) const {
2252 switch (*Constraint) {
Eli Friedman618234a2008-08-20 02:34:37 +00002253 case 'a': return std::string("{ax}");
2254 case 'b': return std::string("{bx}");
2255 case 'c': return std::string("{cx}");
2256 case 'd': return std::string("{dx}");
2257 case 'S': return std::string("{si}");
2258 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00002259 case 'p': // address
2260 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00002261 case 't': // top of floating point stack.
2262 return std::string("{st}");
2263 case 'u': // second from top of floating point stack.
2264 return std::string("{st(1)}"); // second from top of floating point stack.
2265 default:
Stuart Hastings002333f2011-06-07 23:45:05 +00002266 return std::string(1, *Constraint);
Eli Friedman618234a2008-08-20 02:34:37 +00002267 }
2268}
Eli Friedman618234a2008-08-20 02:34:37 +00002269} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00002270
2271namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00002272// X86-32 generic target
2273class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00002274public:
Eli Friedman618234a2008-08-20 02:34:37 +00002275 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
2276 DoubleAlign = LongLongAlign = 32;
2277 LongDoubleWidth = 96;
2278 LongDoubleAlign = 32;
Nick Lewycky9bddf432011-12-21 04:25:47 +00002279 SuitableAlign = 128;
Eli Friedmaned855cb2008-08-21 00:13:15 +00002280 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2281 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Lang Hames567c6002011-10-11 00:52:51 +00002282 "a0:0:64-f80:32:32-n8:16:32-S128";
Eli Friedman1afabd92009-03-29 20:31:09 +00002283 SizeType = UnsignedInt;
2284 PtrDiffType = SignedInt;
2285 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00002286 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00002287
2288 // Use fpret for all types.
2289 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
2290 (1 << TargetInfo::Double) |
2291 (1 << TargetInfo::LongDouble));
Eli Friedman2be46072011-10-14 20:59:01 +00002292
2293 // x86-32 has atomics up to 8 bytes
2294 // FIXME: Check that we actually have cmpxchg8b before setting
2295 // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.)
2296 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
Eli Friedman618234a2008-08-20 02:34:37 +00002297 }
2298 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002299 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00002300 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00002301
Chris Lattner21fb98e2009-09-23 06:06:36 +00002302 int getEHDataRegisterNumber(unsigned RegNo) const {
2303 if (RegNo == 0) return 0;
2304 if (RegNo == 1) return 2;
2305 return -1;
2306 }
Eli Friedman618234a2008-08-20 02:34:37 +00002307};
2308} // end anonymous namespace
2309
2310namespace {
Joerg Sonnenberger42378be2012-01-06 18:32:26 +00002311class NetBSDI386TargetInfo : public NetBSDTargetInfo<X86_32TargetInfo> {
2312public:
2313 NetBSDI386TargetInfo(const std::string &triple) :
2314 NetBSDTargetInfo<X86_32TargetInfo>(triple) {
2315 }
2316
2317 virtual unsigned getFloatEvalMethod() const {
2318 // NetBSD defaults to "double" rounding
2319 return 1;
2320 }
2321};
2322} // end anonymous namespace
2323
2324namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00002325class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
2326public:
2327 OpenBSDI386TargetInfo(const std::string& triple) :
2328 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
2329 SizeType = UnsignedLong;
2330 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00002331 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00002332 }
2333};
2334} // end anonymous namespace
2335
2336namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00002337class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00002338public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002339 DarwinI386TargetInfo(const std::string& triple) :
2340 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00002341 LongDoubleWidth = 128;
2342 LongDoubleAlign = 128;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00002343 SuitableAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00002344 SizeType = UnsignedLong;
2345 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00002346 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2347 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002348 "a0:0:64-f80:128:128-n8:16:32-S128";
Daniel Dunbar613fd672010-05-27 00:35:16 +00002349 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00002350 }
2351
Eli Friedman618234a2008-08-20 02:34:37 +00002352};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00002353} // end anonymous namespace
2354
2355namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00002356// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002357class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00002358public:
2359 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002360 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00002361 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00002362 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00002363 DoubleAlign = LongLongAlign = 64;
2364 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 +00002365 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002366 "v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32";
Eli Friedman29a30502008-08-21 01:40:19 +00002367 }
Michael J. Spencera764e832010-10-21 08:22:51 +00002368 virtual void getTargetDefines(const LangOptions &Opts,
2369 MacroBuilder &Builder) const {
2370 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
2371 }
2372};
2373} // end anonymous namespace
2374
2375namespace {
2376
2377// x86-32 Windows Visual Studio target
2378class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
2379public:
2380 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
2381 : WindowsX86_32TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00002382 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00002383 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
2384 }
2385 virtual void getTargetDefines(const LangOptions &Opts,
2386 MacroBuilder &Builder) const {
2387 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
2388 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
2389 // The value of the following reflects processor type.
2390 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
2391 // We lost the original triple, so we use the default.
2392 Builder.defineMacro("_M_IX86", "600");
2393 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002394};
2395} // end anonymous namespace
2396
2397namespace {
2398// x86-32 MinGW target
2399class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
2400public:
2401 MinGWX86_32TargetInfo(const std::string& triple)
2402 : WindowsX86_32TargetInfo(triple) {
2403 }
2404 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002405 MacroBuilder &Builder) const {
2406 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00002407 DefineStd(Builder, "WIN32", Opts);
2408 DefineStd(Builder, "WINNT", Opts);
2409 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00002410 Builder.defineMacro("__MSVCRT__");
2411 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002412
2413 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
2414 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00002415 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002416 // Provide "as-is" __declspec.
2417 Builder.defineMacro("__declspec", "__declspec");
2418 else
2419 // Provide alias of __attribute__ like mingw32-gcc.
2420 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002421 }
2422};
2423} // end anonymous namespace
2424
2425namespace {
2426// x86-32 Cygwin target
2427class CygwinX86_32TargetInfo : public X86_32TargetInfo {
2428public:
2429 CygwinX86_32TargetInfo(const std::string& triple)
2430 : X86_32TargetInfo(triple) {
2431 TLSSupported = false;
2432 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002433 DoubleAlign = LongLongAlign = 64;
2434 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2435 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002436 "a0:0:64-f80:32:32-n8:16:32-S32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002437 }
2438 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002439 MacroBuilder &Builder) const {
2440 X86_32TargetInfo::getTargetDefines(Opts, Builder);
2441 Builder.defineMacro("__CYGWIN__");
2442 Builder.defineMacro("__CYGWIN32__");
2443 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00002444 if (Opts.CPlusPlus)
2445 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00002446 }
Eli Friedman29a30502008-08-21 01:40:19 +00002447};
2448} // end anonymous namespace
2449
2450namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00002451// x86-32 Haiku target
2452class HaikuX86_32TargetInfo : public X86_32TargetInfo {
2453public:
2454 HaikuX86_32TargetInfo(const std::string& triple)
2455 : X86_32TargetInfo(triple) {
2456 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00002457 IntPtrType = SignedLong;
2458 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00002459 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00002460 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00002461 virtual void getTargetDefines(const LangOptions &Opts,
2462 MacroBuilder &Builder) const {
2463 X86_32TargetInfo::getTargetDefines(Opts, Builder);
2464 Builder.defineMacro("__INTEL__");
2465 Builder.defineMacro("__HAIKU__");
2466 }
2467};
2468} // end anonymous namespace
2469
Douglas Gregordca52262011-07-01 22:41:14 +00002470// RTEMS Target
2471template<typename Target>
2472class RTEMSTargetInfo : public OSTargetInfo<Target> {
2473protected:
2474 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
2475 MacroBuilder &Builder) const {
2476 // RTEMS defines; list based off of gcc output
2477
Douglas Gregordca52262011-07-01 22:41:14 +00002478 Builder.defineMacro("__rtems__");
2479 Builder.defineMacro("__ELF__");
2480 }
2481public:
2482 RTEMSTargetInfo(const std::string &triple)
2483 : OSTargetInfo<Target>(triple) {
2484 this->UserLabelPrefix = "";
2485
2486 llvm::Triple Triple(triple);
2487 switch (Triple.getArch()) {
2488 default:
2489 case llvm::Triple::x86:
2490 // this->MCountName = ".mcount";
2491 break;
2492 case llvm::Triple::mips:
2493 case llvm::Triple::mipsel:
2494 case llvm::Triple::ppc:
2495 case llvm::Triple::ppc64:
2496 // this->MCountName = "_mcount";
2497 break;
2498 case llvm::Triple::arm:
2499 // this->MCountName = "__mcount";
2500 break;
2501 }
2502
2503 }
2504};
2505
2506namespace {
2507// x86-32 RTEMS target
2508class RTEMSX86_32TargetInfo : public X86_32TargetInfo {
2509public:
2510 RTEMSX86_32TargetInfo(const std::string& triple)
2511 : X86_32TargetInfo(triple) {
2512 SizeType = UnsignedLong;
2513 IntPtrType = SignedLong;
2514 PtrDiffType = SignedLong;
2515 this->UserLabelPrefix = "";
2516 }
2517 virtual void getTargetDefines(const LangOptions &Opts,
2518 MacroBuilder &Builder) const {
2519 X86_32TargetInfo::getTargetDefines(Opts, Builder);
2520 Builder.defineMacro("__INTEL__");
2521 Builder.defineMacro("__rtems__");
2522 }
2523};
2524} // end anonymous namespace
2525
Chris Lattner86ed3a32010-04-11 19:29:39 +00002526namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00002527// x86-64 generic target
2528class X86_64TargetInfo : public X86TargetInfo {
2529public:
Chris Lattner33328642009-03-20 15:52:06 +00002530 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00002531 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00002532 LongDoubleWidth = 128;
2533 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00002534 LargeArrayMinWidth = 128;
2535 LargeArrayAlign = 128;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00002536 SuitableAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00002537 IntMaxType = SignedLong;
2538 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00002539 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00002540 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00002541
Eli Friedmaned855cb2008-08-21 00:13:15 +00002542 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2543 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002544 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00002545
2546 // Use fpret only for long double.
2547 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Eli Friedman2be46072011-10-14 20:59:01 +00002548
Anders Carlssoneea64802011-10-31 16:27:11 +00002549 // Use fp2ret for _Complex long double.
2550 ComplexLongDoubleUsesFP2Ret = true;
2551
Eli Friedman2be46072011-10-14 20:59:01 +00002552 // x86-64 has atomics up to 16 bytes.
2553 // FIXME: Once the backend is fixed, increase MaxAtomicInlineWidth to 128
2554 // on CPUs with cmpxchg16b
2555 MaxAtomicPromoteWidth = 128;
2556 MaxAtomicInlineWidth = 64;
Reid Spencer5f016e22007-07-11 17:01:13 +00002557 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00002558 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002559 return "typedef struct __va_list_tag {"
2560 " unsigned gp_offset;"
2561 " unsigned fp_offset;"
2562 " void* overflow_arg_area;"
2563 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00002564 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00002565 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00002566 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00002567
Chris Lattner21fb98e2009-09-23 06:06:36 +00002568 int getEHDataRegisterNumber(unsigned RegNo) const {
2569 if (RegNo == 0) return 0;
2570 if (RegNo == 1) return 1;
2571 return -1;
2572 }
Eli Friedman618234a2008-08-20 02:34:37 +00002573};
2574} // end anonymous namespace
2575
2576namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002577// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002578class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002579public:
2580 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002581 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002582 TLSSupported = false;
2583 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00002584 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00002585 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00002586 IntMaxType = SignedLongLong;
2587 UIntMaxType = UnsignedLongLong;
2588 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00002589 SizeType = UnsignedLongLong;
2590 PtrDiffType = SignedLongLong;
2591 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00002592 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002593 }
2594 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002595 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002596 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002597 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00002598 }
NAKAMURA Takumi79521992011-01-17 22:56:23 +00002599 virtual const char *getVAListDeclaration() const {
2600 return "typedef char* __builtin_va_list;";
2601 }
Michael J. Spencera764e832010-10-21 08:22:51 +00002602};
2603} // end anonymous namespace
2604
2605namespace {
2606// x86-64 Windows Visual Studio target
2607class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
2608public:
2609 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
2610 : WindowsX86_64TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00002611 LongDoubleWidth = LongDoubleAlign = 64;
2612 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00002613 }
2614 virtual void getTargetDefines(const LangOptions &Opts,
2615 MacroBuilder &Builder) const {
2616 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
2617 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00002618 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00002619 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002620 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002621};
2622} // end anonymous namespace
2623
2624namespace {
2625// x86-64 MinGW target
2626class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
2627public:
2628 MinGWX86_64TargetInfo(const std::string& triple)
2629 : WindowsX86_64TargetInfo(triple) {
2630 }
2631 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002632 MacroBuilder &Builder) const {
2633 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00002634 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00002635 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00002636 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00002637 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002638
2639 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
2640 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00002641 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00002642 // Provide "as-is" __declspec.
2643 Builder.defineMacro("__declspec", "__declspec");
2644 else
2645 // Provide alias of __attribute__ like mingw32-gcc.
2646 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002647 }
2648};
2649} // end anonymous namespace
2650
2651namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00002652class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
2653public:
Mike Stump1eb44332009-09-09 15:08:12 +00002654 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00002655 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
2656 Int64Type = SignedLongLong;
2657 }
2658};
2659} // end anonymous namespace
2660
2661namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00002662class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
2663public:
Mike Stump1eb44332009-09-09 15:08:12 +00002664 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00002665 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
2666 IntMaxType = SignedLongLong;
2667 UIntMaxType = UnsignedLongLong;
2668 Int64Type = SignedLongLong;
2669 }
2670};
2671} // end anonymous namespace
2672
2673namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00002674class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002675 // Possible FPU choices.
2676 enum FPUMode {
2677 NoFPU,
2678 VFP2FPU,
2679 VFP3FPU,
2680 NeonFPU
2681 };
2682
2683 static bool FPUModeIsVFP(FPUMode Mode) {
2684 return Mode >= VFP2FPU && Mode <= NeonFPU;
2685 }
2686
2687 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2688 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002689
Daniel Dunbareac7c532009-12-18 18:42:37 +00002690 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00002691
2692 unsigned FPU : 3;
2693
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002694 unsigned IsThumb : 1;
2695
2696 // Initialized via features.
2697 unsigned SoftFloat : 1;
2698 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00002699
Chris Lattner2752c012010-03-03 19:03:45 +00002700 static const Builtin::Info BuiltinInfo[];
2701
Chris Lattner393ff042008-04-21 18:56:49 +00002702public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002703 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00002704 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00002705 {
Eli Friedmane6a24e82011-12-22 03:51:45 +00002706 BigEndian = false;
Daniel Dunbara2a41612009-09-14 00:02:24 +00002707 SizeType = UnsignedInt;
2708 PtrDiffType = SignedInt;
James Molloya6d81f92011-11-23 13:35:08 +00002709 // AAPCS 7.1.1, ARM-Linux ABI 2.4: type of wchar_t is unsigned int.
2710 WCharType = UnsignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002711
Chris Lattner9bffb072010-04-23 16:29:58 +00002712 // {} in inline assembly are neon specifiers, not assembly variant
2713 // specifiers.
2714 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00002715
Daniel Dunbareac7c532009-12-18 18:42:37 +00002716 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00002717 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002718 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00002719 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
2720 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002721 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
2722 "i64:64:64-f32:32:32-f64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002723 "v64:64:64-v128:64:128-a0:0:32-n32-S64");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002724 } else {
2725 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
2726 "i64:64:64-f32:32:32-f64:64:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002727 "v64:64:64-v128:64:128-a0:0:64-n32-S64");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002728 }
John McCallee79a4c2010-08-21 22:46:04 +00002729
2730 // ARM targets default to using the ARM C++ ABI.
2731 CXXABI = CXXABI_ARM;
Eli Friedman2be46072011-10-14 20:59:01 +00002732
2733 // ARM has atomics up to 8 bytes
2734 // FIXME: Set MaxAtomicInlineWidth if we have the feature v6e
2735 MaxAtomicPromoteWidth = 64;
James Molloye45b9b72012-03-12 09:14:10 +00002736
2737 // Do force alignment of members that follow zero length bitfields. If
2738 // the alignment of the zero-length bitfield is greater than the member
2739 // that follows it, `bar', `bar' will be aligned as the type of the
2740 // zero length bitfield.
2741 UseZeroLengthBitfieldAlignment = true;
Eli Friedman61538a72008-05-20 14:21:01 +00002742 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00002743 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00002744 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00002745 ABI = Name;
2746
Daniel Dunbara2a41612009-09-14 00:02:24 +00002747 // The defaults (above) are for AAPCS, check if we need to change them.
2748 //
2749 // FIXME: We need support for -meabi... we could just mangle it into the
2750 // name.
2751 if (Name == "apcs-gnu") {
Nick Lewycky7ec59c72011-12-16 22:34:14 +00002752 DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00002753 SizeType = UnsignedLong;
2754
James Molloya6d81f92011-11-23 13:35:08 +00002755 // Revert to using SignedInt on apcs-gnu to comply with existing behaviour.
2756 WCharType = SignedInt;
2757
Daniel Dunbar684de632010-04-22 16:14:54 +00002758 // Do not respect the alignment of bit-field types when laying out
2759 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
2760 UseBitFieldTypeAlignment = false;
2761
Chad Rosier61a62212011-08-04 01:21:14 +00002762 /// gcc forces the alignment to 4 bytes, regardless of the type of the
Chad Rosier6e43f3f2011-08-04 17:52:43 +00002763 /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in
2764 /// gcc.
Chad Rosier61a62212011-08-04 01:21:14 +00002765 ZeroLengthBitfieldBoundary = 32;
2766
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002767 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00002768 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
2769 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002770 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 +00002771 "i64:32:64-f32:32:32-f64:32:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002772 "v64:32:64-v128:32:128-a0:0:32-n32-S32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002773 } else {
2774 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 +00002775 "i64:32:64-f32:32:32-f64:32:64-"
Lang Hamesf4f50032011-10-10 23:44:43 +00002776 "v64:32:64-v128:32:128-a0:0:32-n32-S32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002777 }
2778
Chad Rosier9f1210c2011-07-26 07:03:04 +00002779 // FIXME: Override "preferred align" for double and long long.
Daniel Dunbara2a41612009-09-14 00:02:24 +00002780 } else if (Name == "aapcs") {
2781 // FIXME: Enumerated types are variable width in straight AAPCS.
2782 } else if (Name == "aapcs-linux") {
Chad Rosier9f1210c2011-07-26 07:03:04 +00002783 ;
Daniel Dunbara2a41612009-09-14 00:02:24 +00002784 } else
2785 return false;
2786
2787 return true;
2788 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002789
Chandler Carruthc3a2e652011-09-28 05:56:05 +00002790 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002791 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
2792 Features["vfp2"] = true;
2793 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
2794 Features["neon"] = true;
2795 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00002796
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002797 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00002798 StringRef Name,
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002799 bool Enabled) const {
Evan Chengf972b262011-07-08 06:40:11 +00002800 if (Name == "soft-float" || Name == "soft-float-abi" ||
Chad Rosier7a938fa2012-04-04 20:39:32 +00002801 Name == "vfp2" || Name == "vfp3" || Name == "neon" || Name == "d16" ||
2802 Name == "neonfp") {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002803 Features[Name] = Enabled;
2804 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002805 return false;
2806
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002807 return true;
2808 }
2809
2810 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002811 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002812 SoftFloat = SoftFloatABI = false;
2813 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
2814 if (Features[i] == "+soft-float")
2815 SoftFloat = true;
2816 else if (Features[i] == "+soft-float-abi")
2817 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00002818 else if (Features[i] == "+vfp2")
2819 FPU = VFP2FPU;
2820 else if (Features[i] == "+vfp3")
2821 FPU = VFP3FPU;
2822 else if (Features[i] == "+neon")
2823 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002824 }
2825
2826 // Remove front-end specific options which the backend handles differently.
2827 std::vector<std::string>::iterator it;
2828 it = std::find(Features.begin(), Features.end(), "+soft-float");
2829 if (it != Features.end())
2830 Features.erase(it);
2831 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
2832 if (it != Features.end())
2833 Features.erase(it);
2834 }
2835
Douglas Gregore727d212012-01-30 06:38:25 +00002836 virtual bool hasFeature(StringRef Feature) const {
2837 return llvm::StringSwitch<bool>(Feature)
2838 .Case("arm", true)
2839 .Case("softfloat", SoftFloat)
2840 .Case("thumb", IsThumb)
2841 .Case("neon", FPU == NeonFPU && !SoftFloat &&
2842 StringRef(getCPUDefineSuffix(CPU)).startswith("7"))
2843 .Default(false);
2844 }
Chris Lattner5f9e2722011-07-23 10:55:15 +00002845 static const char *getCPUDefineSuffix(StringRef Name) {
Daniel Dunbareac7c532009-12-18 18:42:37 +00002846 return llvm::StringSwitch<const char*>(Name)
2847 .Cases("arm8", "arm810", "4")
2848 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
2849 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
2850 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
2851 .Case("ep9312", "4T")
2852 .Cases("arm10tdmi", "arm1020t", "5T")
2853 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
2854 .Case("arm926ej-s", "5TEJ")
2855 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
2856 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002857 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002858 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002859 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002860 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
2861 .Cases("cortex-a8", "cortex-a9", "7A")
Bob Wilson06f45632011-01-06 16:57:20 +00002862 .Case("cortex-m3", "7M")
Jim Grosbach69033132012-03-29 19:53:34 +00002863 .Case("cortex-m4", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00002864 .Case("cortex-m0", "6M")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002865 .Default(0);
2866 }
2867 virtual bool setCPU(const std::string &Name) {
2868 if (!getCPUDefineSuffix(Name))
2869 return false;
2870
2871 CPU = Name;
2872 return true;
2873 }
Chris Lattner33328642009-03-20 15:52:06 +00002874 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002875 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00002876 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00002877 Builder.defineMacro("__arm");
2878 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002879
Chris Lattnerc0f59212009-03-02 22:27:17 +00002880 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00002881 Builder.defineMacro("__ARMEL__");
2882 Builder.defineMacro("__LITTLE_ENDIAN__");
2883 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002884
Chris Lattner5f9e2722011-07-23 10:55:15 +00002885 StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00002886 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002887
Mike Stump437bb4b2009-04-08 02:07:04 +00002888 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002889
Daniel Dunbareac7c532009-12-18 18:42:37 +00002890 // FIXME: It's more complicated than this and we don't really support
2891 // interworking.
2892 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00002893 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002894
Daniel Dunbareac7c532009-12-18 18:42:37 +00002895 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00002896 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002897
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002898 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00002899 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002900
2901 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00002902 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002903
Bob Wilson84f95cf2011-05-13 18:56:03 +00002904 bool IsARMv7 = CPUArch.startswith("7");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002905 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00002906 Builder.defineMacro("__THUMBEL__");
2907 Builder.defineMacro("__thumb__");
Bob Wilson84f95cf2011-05-13 18:56:03 +00002908 if (CPUArch == "6T2" || IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002909 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002910 }
2911
2912 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00002913 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002914
2915 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00002916 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002917
2918 // This only gets set when Neon instructions are actually available, unlike
2919 // the VFP define, hence the soft float and arch check. This is subtly
2920 // different from gcc, we follow the intent which was that it should be set
2921 // when Neon instructions are actually available.
Bob Wilson84f95cf2011-05-13 18:56:03 +00002922 if (FPU == NeonFPU && !SoftFloat && IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002923 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00002924 }
2925 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2926 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00002927 Records = BuiltinInfo;
2928 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00002929 }
Bob Wilson8b30a932012-01-26 22:14:27 +00002930 virtual bool isCLZForZeroUndef() const { return false; }
Chris Lattner393ff042008-04-21 18:56:49 +00002931 virtual const char *getVAListDeclaration() const {
John McCall0e9972c2011-05-09 02:19:37 +00002932 return "typedef void* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00002933 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002934 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002935 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002936 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002937 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002938 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00002939 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002940 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002941 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00002942 default:
Nate Begemanad487f42008-04-22 05:03:19 +00002943 case 'l': // r0-r7
2944 case 'h': // r8-r15
2945 case 'w': // VFP Floating point register single precision
2946 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00002947 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00002948 return true;
Eric Christopher895d4222011-07-29 21:20:35 +00002949 case 'Q': // A memory address that is a single base register.
2950 Info.setAllowsMemory();
2951 return true;
Stuart Hastings002333f2011-06-07 23:45:05 +00002952 case 'U': // a memory reference...
2953 switch (Name[1]) {
2954 case 'q': // ...ARMV4 ldrsb
2955 case 'v': // ...VFP load/store (reg+constant offset)
2956 case 'y': // ...iWMMXt load/store
Eric Christopherdda231a2011-06-17 01:40:49 +00002957 case 't': // address valid for load/store opaque types wider
2958 // than 128-bits
2959 case 'n': // valid address for Neon doubleword vector load/store
2960 case 'm': // valid address for Neon element and structure load/store
2961 case 's': // valid address for non-offset loads/stores of quad-word
2962 // values in four ARM registers
Stuart Hastings002333f2011-06-07 23:45:05 +00002963 Info.setAllowsMemory();
2964 Name++;
2965 return true;
2966 }
Nate Begemanad487f42008-04-22 05:03:19 +00002967 }
Chris Lattner393ff042008-04-21 18:56:49 +00002968 return false;
2969 }
Evan Cheng8bfa2572011-06-16 19:13:15 +00002970 virtual std::string convertConstraint(const char *&Constraint) const {
Stuart Hastings002333f2011-06-07 23:45:05 +00002971 std::string R;
2972 switch (*Constraint) {
2973 case 'U': // Two-character constraint; add "^" hint for later parsing.
Stuart Hastings6ce33d62011-06-08 16:06:31 +00002974 R = std::string("^") + std::string(Constraint, 2);
Stuart Hastings002333f2011-06-07 23:45:05 +00002975 Constraint++;
2976 break;
Eric Christopher283f4472011-06-17 00:40:18 +00002977 case 'p': // 'p' should be translated to 'r' by default.
2978 R = std::string("r");
2979 break;
Stuart Hastings002333f2011-06-07 23:45:05 +00002980 default:
2981 return std::string(1, *Constraint);
2982 }
2983 return R;
2984 }
Chris Lattner393ff042008-04-21 18:56:49 +00002985 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002986 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00002987 return "";
2988 }
2989};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002990
2991const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002992 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002993 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002994 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
2995
2996 // Float registers
2997 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
2998 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
2999 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003000 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00003001
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003002 // Double registers
3003 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
3004 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00003005 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
3006 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003007
3008 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00003009 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
3010 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003011};
3012
3013void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00003014 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003015 Names = GCCRegNames;
3016 NumNames = llvm::array_lengthof(GCCRegNames);
3017}
3018
3019const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003020 { { "a1" }, "r0" },
3021 { { "a2" }, "r1" },
3022 { { "a3" }, "r2" },
3023 { { "a4" }, "r3" },
3024 { { "v1" }, "r4" },
3025 { { "v2" }, "r5" },
3026 { { "v3" }, "r6" },
3027 { { "v4" }, "r7" },
3028 { { "v5" }, "r8" },
3029 { { "v6", "rfp" }, "r9" },
3030 { { "sl" }, "r10" },
3031 { { "fp" }, "r11" },
3032 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00003033 { { "r13" }, "sp" },
3034 { { "r14" }, "lr" },
3035 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00003036 // The S, D and Q registers overlap, but aren't really aliases; we
3037 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00003038};
3039
3040void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3041 unsigned &NumAliases) const {
3042 Aliases = GCCRegAliases;
3043 NumAliases = llvm::array_lengthof(GCCRegAliases);
3044}
Chris Lattner2752c012010-03-03 19:03:45 +00003045
3046const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00003047#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00003048#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00003049 ALL_LANGUAGES },
Chris Lattner2752c012010-03-03 19:03:45 +00003050#include "clang/Basic/BuiltinsARM.def"
3051};
Chris Lattner393ff042008-04-21 18:56:49 +00003052} // end anonymous namespace.
3053
Eli Friedmana9f54962008-08-20 07:44:10 +00003054namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00003055class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00003056 public DarwinTargetInfo<ARMTargetInfo> {
3057protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00003058 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00003059 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00003060 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00003061 }
Eli Friedmana9f54962008-08-20 07:44:10 +00003062
Torok Edwin5f6c1942009-06-30 17:10:35 +00003063public:
Mike Stump1eb44332009-09-09 15:08:12 +00003064 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00003065 : DarwinTargetInfo<ARMTargetInfo>(triple) {
3066 HasAlignMac68kSupport = true;
Eli Friedman2be46072011-10-14 20:59:01 +00003067 // iOS always has 64-bit atomic instructions.
3068 // FIXME: This should be based off of the target features in ARMTargetInfo.
3069 MaxAtomicInlineWidth = 64;
Daniel Dunbar350b9f32010-05-27 07:00:26 +00003070 }
Eli Friedmana9f54962008-08-20 07:44:10 +00003071};
3072} // end anonymous namespace.
3073
Tony Linthicum96319392011-12-12 21:14:55 +00003074
3075namespace {
3076// Hexagon abstract base class
3077class HexagonTargetInfo : public TargetInfo {
3078 static const Builtin::Info BuiltinInfo[];
3079 static const char * const GCCRegNames[];
3080 static const TargetInfo::GCCRegAlias GCCRegAliases[];
3081 std::string CPU;
3082public:
3083 HexagonTargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003084 BigEndian = false;
Tony Linthicum96319392011-12-12 21:14:55 +00003085 DescriptionString = ("e-p:32:32:32-"
Sirish Pande5f9688b2012-05-10 20:19:54 +00003086 "i64:64:64-i32:32:32-i16:16:16-i1:32:32"
3087 "f64:64:64-f32:32:32-a0:0-n32");
Tony Linthicum96319392011-12-12 21:14:55 +00003088
3089 // {} in inline assembly are packet specifiers, not assembly variant
3090 // specifiers.
3091 NoAsmVariants = true;
3092 }
3093
3094 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3095 unsigned &NumRecords) const {
3096 Records = BuiltinInfo;
3097 NumRecords = clang::Hexagon::LastTSBuiltin-Builtin::FirstTSBuiltin;
3098 }
3099
3100 virtual bool validateAsmConstraint(const char *&Name,
3101 TargetInfo::ConstraintInfo &Info) const {
3102 return true;
3103 }
3104
3105 virtual void getTargetDefines(const LangOptions &Opts,
3106 MacroBuilder &Builder) const;
3107
Douglas Gregore727d212012-01-30 06:38:25 +00003108 virtual bool hasFeature(StringRef Feature) const {
3109 return Feature == "hexagon";
3110 }
3111
Tony Linthicum96319392011-12-12 21:14:55 +00003112 virtual const char *getVAListDeclaration() const {
3113 return "typedef char* __builtin_va_list;";
3114 }
3115 virtual void getGCCRegNames(const char * const *&Names,
3116 unsigned &NumNames) const;
3117 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3118 unsigned &NumAliases) const;
3119 virtual const char *getClobbers() const {
3120 return "";
3121 }
Sebastian Pop43115d42012-01-13 20:37:10 +00003122
3123 static const char *getHexagonCPUSuffix(StringRef Name) {
3124 return llvm::StringSwitch<const char*>(Name)
3125 .Case("hexagonv2", "2")
3126 .Case("hexagonv3", "3")
3127 .Case("hexagonv4", "4")
Sirish Pande5f9688b2012-05-10 20:19:54 +00003128 .Case("hexagonv5", "5")
Sebastian Pop43115d42012-01-13 20:37:10 +00003129 .Default(0);
3130 }
3131
Tony Linthicum96319392011-12-12 21:14:55 +00003132 virtual bool setCPU(const std::string &Name) {
Sebastian Pop43115d42012-01-13 20:37:10 +00003133 if (!getHexagonCPUSuffix(Name))
3134 return false;
3135
Tony Linthicum96319392011-12-12 21:14:55 +00003136 CPU = Name;
3137 return true;
3138 }
3139};
3140
3141void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
3142 MacroBuilder &Builder) const {
3143 Builder.defineMacro("qdsp6");
3144 Builder.defineMacro("__qdsp6", "1");
3145 Builder.defineMacro("__qdsp6__", "1");
3146
3147 Builder.defineMacro("hexagon");
3148 Builder.defineMacro("__hexagon", "1");
3149 Builder.defineMacro("__hexagon__", "1");
3150
3151 if(CPU == "hexagonv1") {
3152 Builder.defineMacro("__HEXAGON_V1__");
3153 Builder.defineMacro("__HEXAGON_ARCH__", "1");
3154 if(Opts.HexagonQdsp6Compat) {
3155 Builder.defineMacro("__QDSP6_V1__");
3156 Builder.defineMacro("__QDSP6_ARCH__", "1");
3157 }
3158 }
3159 else if(CPU == "hexagonv2") {
3160 Builder.defineMacro("__HEXAGON_V2__");
3161 Builder.defineMacro("__HEXAGON_ARCH__", "2");
3162 if(Opts.HexagonQdsp6Compat) {
3163 Builder.defineMacro("__QDSP6_V2__");
3164 Builder.defineMacro("__QDSP6_ARCH__", "2");
3165 }
3166 }
3167 else if(CPU == "hexagonv3") {
3168 Builder.defineMacro("__HEXAGON_V3__");
3169 Builder.defineMacro("__HEXAGON_ARCH__", "3");
3170 if(Opts.HexagonQdsp6Compat) {
3171 Builder.defineMacro("__QDSP6_V3__");
3172 Builder.defineMacro("__QDSP6_ARCH__", "3");
3173 }
3174 }
3175 else if(CPU == "hexagonv4") {
3176 Builder.defineMacro("__HEXAGON_V4__");
3177 Builder.defineMacro("__HEXAGON_ARCH__", "4");
3178 if(Opts.HexagonQdsp6Compat) {
3179 Builder.defineMacro("__QDSP6_V4__");
3180 Builder.defineMacro("__QDSP6_ARCH__", "4");
3181 }
3182 }
Sirish Pande5f9688b2012-05-10 20:19:54 +00003183 else if(CPU == "hexagonv5") {
3184 Builder.defineMacro("__HEXAGON_V5__");
3185 Builder.defineMacro("__HEXAGON_ARCH__", "5");
3186 if(Opts.HexagonQdsp6Compat) {
3187 Builder.defineMacro("__QDSP6_V5__");
3188 Builder.defineMacro("__QDSP6_ARCH__", "5");
3189 }
3190 }
Tony Linthicum96319392011-12-12 21:14:55 +00003191}
3192
3193const char * const HexagonTargetInfo::GCCRegNames[] = {
3194 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
3195 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
3196 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
3197 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
3198 "p0", "p1", "p2", "p3",
3199 "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp"
3200};
3201
3202void HexagonTargetInfo::getGCCRegNames(const char * const *&Names,
3203 unsigned &NumNames) const {
3204 Names = GCCRegNames;
3205 NumNames = llvm::array_lengthof(GCCRegNames);
3206}
3207
3208
3209const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
3210 { { "sp" }, "r29" },
3211 { { "fp" }, "r30" },
3212 { { "lr" }, "r31" },
3213 };
3214
3215void HexagonTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3216 unsigned &NumAliases) const {
3217 Aliases = GCCRegAliases;
3218 NumAliases = llvm::array_lengthof(GCCRegAliases);
3219}
3220
3221
3222const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
3223#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
3224#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
3225 ALL_LANGUAGES },
3226#include "clang/Basic/BuiltinsHexagon.def"
3227};
3228}
3229
3230
Reid Spencer5f016e22007-07-11 17:01:13 +00003231namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00003232class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00003233 static const TargetInfo::GCCRegAlias GCCRegAliases[];
3234 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00003235 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00003236public:
Eli Friedman01b86682008-08-20 07:28:14 +00003237 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
3238 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00003239 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 +00003240 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00003241 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00003242 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
Benjamin Kramer713575a2012-03-05 15:10:44 +00003243 StringRef Name,
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00003244 bool Enabled) const {
3245 if (Name == "soft-float")
3246 Features[Name] = Enabled;
3247 else
3248 return false;
3249
3250 return true;
3251 }
3252 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
3253 SoftFloat = false;
3254 for (unsigned i = 0, e = Features.size(); i != e; ++i)
3255 if (Features[i] == "+soft-float")
3256 SoftFloat = true;
3257 }
Chris Lattner33328642009-03-20 15:52:06 +00003258 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003259 MacroBuilder &Builder) const {
3260 DefineStd(Builder, "sparc", Opts);
3261 Builder.defineMacro("__sparcv8");
3262 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00003263
3264 if (SoftFloat)
3265 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00003266 }
Douglas Gregore727d212012-01-30 06:38:25 +00003267
3268 virtual bool hasFeature(StringRef Feature) const {
3269 return llvm::StringSwitch<bool>(Feature)
3270 .Case("softfloat", SoftFloat)
3271 .Case("sparc", true)
3272 .Default(false);
3273 }
3274
Gabor Greif26658672008-02-21 16:29:08 +00003275 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3276 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00003277 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00003278 }
3279 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00003280 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00003281 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003282 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00003283 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003284 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00003285 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00003286 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00003287 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00003288 // FIXME: Implement!
3289 return false;
Gabor Greif26658672008-02-21 16:29:08 +00003290 }
3291 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00003292 // FIXME: Implement!
3293 return "";
Gabor Greif26658672008-02-21 16:29:08 +00003294 }
3295};
3296
Chris Lattnere957f532009-01-27 01:58:38 +00003297const char * const SparcV8TargetInfo::GCCRegNames[] = {
3298 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
3299 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
3300 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
3301 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
3302};
3303
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003304void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00003305 unsigned &NumNames) const {
3306 Names = GCCRegNames;
3307 NumNames = llvm::array_lengthof(GCCRegNames);
3308}
3309
3310const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003311 { { "g0" }, "r0" },
3312 { { "g1" }, "r1" },
3313 { { "g2" }, "r2" },
3314 { { "g3" }, "r3" },
3315 { { "g4" }, "r4" },
3316 { { "g5" }, "r5" },
3317 { { "g6" }, "r6" },
3318 { { "g7" }, "r7" },
3319 { { "o0" }, "r8" },
3320 { { "o1" }, "r9" },
3321 { { "o2" }, "r10" },
3322 { { "o3" }, "r11" },
3323 { { "o4" }, "r12" },
3324 { { "o5" }, "r13" },
3325 { { "o6", "sp" }, "r14" },
3326 { { "o7" }, "r15" },
3327 { { "l0" }, "r16" },
3328 { { "l1" }, "r17" },
3329 { { "l2" }, "r18" },
3330 { { "l3" }, "r19" },
3331 { { "l4" }, "r20" },
3332 { { "l5" }, "r21" },
3333 { { "l6" }, "r22" },
3334 { { "l7" }, "r23" },
3335 { { "i0" }, "r24" },
3336 { { "i1" }, "r25" },
3337 { { "i2" }, "r26" },
3338 { { "i3" }, "r27" },
3339 { { "i4" }, "r28" },
3340 { { "i5" }, "r29" },
3341 { { "i6", "fp" }, "r30" },
3342 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00003343};
3344
Anton Korobeynikova7c47172009-05-03 13:42:53 +00003345void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00003346 unsigned &NumAliases) const {
3347 Aliases = GCCRegAliases;
3348 NumAliases = llvm::array_lengthof(GCCRegAliases);
3349}
Gabor Greif26658672008-02-21 16:29:08 +00003350} // end anonymous namespace.
3351
Eli Friedman01b86682008-08-20 07:28:14 +00003352namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00003353class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
3354public:
3355 AuroraUXSparcV8TargetInfo(const std::string& triple) :
3356 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
3357 SizeType = UnsignedInt;
3358 PtrDiffType = SignedInt;
3359 }
3360};
Torok Edwin5f6c1942009-06-30 17:10:35 +00003361class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00003362public:
3363 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00003364 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00003365 SizeType = UnsignedInt;
3366 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00003367 }
3368};
3369} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00003370
Chris Lattner2621fd12008-05-08 05:58:21 +00003371namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003372 class MSP430TargetInfo : public TargetInfo {
3373 static const char * const GCCRegNames[];
3374 public:
3375 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003376 BigEndian = false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003377 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00003378 IntWidth = 16; IntAlign = 16;
3379 LongWidth = 32; LongLongWidth = 64;
3380 LongAlign = LongLongAlign = 16;
3381 PointerWidth = 16; PointerAlign = 16;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00003382 SuitableAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003383 SizeType = UnsignedInt;
3384 IntMaxType = SignedLong;
3385 UIntMaxType = UnsignedLong;
3386 IntPtrType = SignedShort;
3387 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00003388 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00003389 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003390 }
3391 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003392 MacroBuilder &Builder) const {
3393 Builder.defineMacro("MSP430");
3394 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003395 // FIXME: defines for different 'flavours' of MCU
3396 }
3397 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3398 unsigned &NumRecords) const {
3399 // FIXME: Implement.
3400 Records = 0;
3401 NumRecords = 0;
3402 }
Douglas Gregore727d212012-01-30 06:38:25 +00003403 virtual bool hasFeature(StringRef Feature) const {
3404 return Feature == "msp430";
3405 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003406 virtual void getGCCRegNames(const char * const *&Names,
3407 unsigned &NumNames) const;
3408 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3409 unsigned &NumAliases) const {
3410 // No aliases.
3411 Aliases = 0;
3412 NumAliases = 0;
3413 }
3414 virtual bool validateAsmConstraint(const char *&Name,
3415 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00003416 // No target constraints for now.
3417 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003418 }
3419 virtual const char *getClobbers() const {
3420 // FIXME: Is this really right?
3421 return "";
3422 }
3423 virtual const char *getVAListDeclaration() const {
3424 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00003425 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00003426 }
3427 };
3428
3429 const char * const MSP430TargetInfo::GCCRegNames[] = {
3430 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
3431 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
3432 };
3433
3434 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
3435 unsigned &NumNames) const {
3436 Names = GCCRegNames;
3437 NumNames = llvm::array_lengthof(GCCRegNames);
3438 }
3439}
3440
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00003441namespace {
Eli Friedmanb63decf2009-08-19 20:47:07 +00003442
Mike Stump1eb44332009-09-09 15:08:12 +00003443 // LLVM and Clang cannot be used directly to output native binaries for
3444 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00003445 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00003446 //
3447 // TCE uses the llvm bitcode as input and uses it for generating customized
3448 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00003449 // publicly available in http://tce.cs.tut.fi
3450
Eli Friedman209f5bb2011-10-07 19:51:42 +00003451 static const unsigned TCEOpenCLAddrSpaceMap[] = {
3452 3, // opencl_global
3453 4, // opencl_local
Peter Collingbourne4dc34eb2012-05-20 21:08:35 +00003454 5, // opencl_constant
3455 0, // cuda_device
3456 0, // cuda_constant
3457 0 // cuda_shared
Eli Friedman209f5bb2011-10-07 19:51:42 +00003458 };
3459
Eli Friedmanb63decf2009-08-19 20:47:07 +00003460 class TCETargetInfo : public TargetInfo{
3461 public:
3462 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
3463 TLSSupported = false;
3464 IntWidth = 32;
3465 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00003466 PointerWidth = 32;
3467 IntAlign = 32;
3468 LongAlign = LongLongAlign = 32;
3469 PointerAlign = 32;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00003470 SuitableAlign = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00003471 SizeType = UnsignedInt;
3472 IntMaxType = SignedLong;
3473 UIntMaxType = UnsignedLong;
3474 IntPtrType = SignedInt;
3475 PtrDiffType = SignedInt;
3476 FloatWidth = 32;
3477 FloatAlign = 32;
3478 DoubleWidth = 32;
3479 DoubleAlign = 32;
3480 LongDoubleWidth = 32;
3481 LongDoubleAlign = 32;
3482 FloatFormat = &llvm::APFloat::IEEEsingle;
3483 DoubleFormat = &llvm::APFloat::IEEEsingle;
3484 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00003485 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
3486 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00003487 "f32:32:32-f64:32:32-v64:32:32-"
3488 "v128:32:32-a0:0:32-n32";
Eli Friedman209f5bb2011-10-07 19:51:42 +00003489 AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
Eli Friedmanb63decf2009-08-19 20:47:07 +00003490 }
3491
3492 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00003493 MacroBuilder &Builder) const {
3494 DefineStd(Builder, "tce", Opts);
3495 Builder.defineMacro("__TCE__");
3496 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00003497 }
Douglas Gregore727d212012-01-30 06:38:25 +00003498 virtual bool hasFeature(StringRef Feature) const {
3499 return Feature == "tce";
3500 }
3501
Eli Friedmanb63decf2009-08-19 20:47:07 +00003502 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3503 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00003504 virtual const char *getClobbers() const {
3505 return "";
3506 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00003507 virtual const char *getVAListDeclaration() const {
3508 return "typedef void* __builtin_va_list;";
3509 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00003510 virtual void getGCCRegNames(const char * const *&Names,
3511 unsigned &NumNames) const {}
3512 virtual bool validateAsmConstraint(const char *&Name,
3513 TargetInfo::ConstraintInfo &info) const {
3514 return true;
3515 }
3516 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3517 unsigned &NumAliases) const {}
3518 };
3519}
3520
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003521namespace {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003522class MipsTargetInfoBase : public TargetInfo {
3523 std::string CPU;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003524 bool SoftFloat;
3525 bool SingleFloat;
3526
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003527protected:
3528 std::string ABI;
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003529
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003530public:
Simon Atanasyan10e1629d2012-04-12 19:59:24 +00003531 MipsTargetInfoBase(const std::string& triple,
3532 const std::string& ABIStr,
3533 const std::string& CPUStr)
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003534 : TargetInfo(triple),
Simon Atanasyan10e1629d2012-04-12 19:59:24 +00003535 CPU(CPUStr),
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003536 SoftFloat(false), SingleFloat(false),
3537 ABI(ABIStr)
3538 {}
3539
Eric Christophered734732010-03-02 02:41:08 +00003540 virtual const char *getABI() const { return ABI.c_str(); }
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003541 virtual bool setABI(const std::string &Name) = 0;
Eric Christophered734732010-03-02 02:41:08 +00003542 virtual bool setCPU(const std::string &Name) {
3543 CPU = Name;
3544 return true;
3545 }
Chandler Carruthc3a2e652011-09-28 05:56:05 +00003546 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Eric Christophered734732010-03-02 02:41:08 +00003547 Features[ABI] = true;
3548 Features[CPU] = true;
3549 }
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003550
Eric Christophered734732010-03-02 02:41:08 +00003551 virtual void getArchDefines(const LangOptions &Opts,
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003552 MacroBuilder &Builder) const {
Simon Atanasyan3dbcc882012-06-05 13:06:56 +00003553 if (SoftFloat && SingleFloat)
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003554 llvm_unreachable("Invalid float ABI for Mips.");
Simon Atanasyan3dbcc882012-06-05 13:06:56 +00003555 else if (SoftFloat)
3556 Builder.defineMacro("__mips_soft_float", Twine(1));
3557 else {
3558 Builder.defineMacro("__mips_hard_float", Twine(1));
3559 if (SingleFloat)
3560 Builder.defineMacro("__mips_single_float", Twine(1));
3561 }
Simon Atanasyan90913892012-04-05 19:28:31 +00003562
3563 Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
3564 Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
3565 Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003566 }
3567
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003568 virtual void getTargetDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003569 MacroBuilder &Builder) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003570 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3571 unsigned &NumRecords) const {
3572 // FIXME: Implement!
3573 }
Douglas Gregore727d212012-01-30 06:38:25 +00003574 virtual bool hasFeature(StringRef Feature) const {
3575 return Feature == "mips";
3576 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003577 virtual const char *getVAListDeclaration() const {
3578 return "typedef void* __builtin_va_list;";
3579 }
3580 virtual void getGCCRegNames(const char * const *&Names,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003581 unsigned &NumNames) const {
3582 static const char * const GCCRegNames[] = {
Eric Christopherd1f853d2012-03-27 19:56:11 +00003583 // CPU register names
3584 // Must match second column of GCCRegAliases
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003585 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
3586 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
3587 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
Eric Christopherd1f853d2012-03-27 19:56:11 +00003588 "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31",
3589 // Floating point register names
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003590 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
3591 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
3592 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
3593 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
Eric Christopherd1f853d2012-03-27 19:56:11 +00003594 // Hi/lo and condition register names
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003595 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
3596 "$fcc5","$fcc6","$fcc7"
3597 };
3598 Names = GCCRegNames;
3599 NumNames = llvm::array_lengthof(GCCRegNames);
3600 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003601 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003602 unsigned &NumAliases) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003603 virtual bool validateAsmConstraint(const char *&Name,
3604 TargetInfo::ConstraintInfo &Info) const {
3605 switch (*Name) {
3606 default:
Douglas Gregor21a25162011-11-02 20:52:01 +00003607 return false;
3608
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003609 case 'r': // CPU registers.
3610 case 'd': // Equivalent to "r" unless generating MIPS16 code.
3611 case 'y': // Equivalent to "r", backwards compatibility only.
3612 case 'f': // floating-point registers.
Eric Christopher0ea61642012-04-03 01:16:32 +00003613 case 'c': // $25 for indirect jumps
3614 case 'l': // lo register
3615 case 'x': // hilo register pair
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003616 Info.setAllowsRegister();
3617 return true;
3618 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003619 }
3620
3621 virtual const char *getClobbers() const {
3622 // FIXME: Implement!
3623 return "";
3624 }
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003625
3626 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
3627 StringRef Name,
3628 bool Enabled) const {
Simon Atanasyan8b2a5d22012-04-18 12:00:11 +00003629 if (Name == "soft-float" || Name == "single-float" ||
3630 Name == "o32" || Name == "n32" || Name == "n64" || Name == "eabi" ||
3631 Name == "mips32" || Name == "mips32r2" ||
3632 Name == "mips64" || Name == "mips64r2") {
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003633 Features[Name] = Enabled;
3634 return true;
3635 }
3636 return false;
3637 }
3638
3639 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
3640 SoftFloat = false;
3641 SingleFloat = false;
3642
3643 for (std::vector<std::string>::iterator it = Features.begin(),
3644 ie = Features.end(); it != ie; ++it) {
3645 if (*it == "+single-float") {
3646 SingleFloat = true;
3647 break;
3648 }
3649
3650 if (*it == "+soft-float") {
3651 SoftFloat = true;
3652 // This option is front-end specific.
3653 // Do not need to pass it to the backend.
3654 Features.erase(it);
3655 break;
3656 }
3657 }
3658 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003659};
3660
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003661class Mips32TargetInfoBase : public MipsTargetInfoBase {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003662public:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003663 Mips32TargetInfoBase(const std::string& triple) :
Simon Atanasyan10e1629d2012-04-12 19:59:24 +00003664 MipsTargetInfoBase(triple, "o32", "mips32") {
Akira Hatanaka148735e2011-11-05 01:48:34 +00003665 SizeType = UnsignedInt;
3666 PtrDiffType = SignedInt;
3667 }
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003668 virtual bool setABI(const std::string &Name) {
3669 if ((Name == "o32") || (Name == "eabi")) {
3670 ABI = Name;
3671 return true;
3672 } else
3673 return false;
3674 }
3675 virtual void getArchDefines(const LangOptions &Opts,
3676 MacroBuilder &Builder) const {
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003677 MipsTargetInfoBase::getArchDefines(Opts, Builder);
3678
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003679 if (ABI == "o32") {
3680 Builder.defineMacro("__mips_o32");
3681 Builder.defineMacro("_ABIO32", "1");
3682 Builder.defineMacro("_MIPS_SIM", "_ABIO32");
3683 }
3684 else if (ABI == "eabi")
3685 Builder.defineMacro("__mips_eabi");
3686 else
David Blaikieb219cfc2011-09-23 05:06:16 +00003687 llvm_unreachable("Invalid ABI for Mips32.");
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003688 }
3689 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3690 unsigned &NumAliases) const {
3691 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
3692 { { "at" }, "$1" },
3693 { { "v0" }, "$2" },
3694 { { "v1" }, "$3" },
3695 { { "a0" }, "$4" },
3696 { { "a1" }, "$5" },
3697 { { "a2" }, "$6" },
3698 { { "a3" }, "$7" },
3699 { { "t0" }, "$8" },
3700 { { "t1" }, "$9" },
3701 { { "t2" }, "$10" },
3702 { { "t3" }, "$11" },
3703 { { "t4" }, "$12" },
3704 { { "t5" }, "$13" },
3705 { { "t6" }, "$14" },
3706 { { "t7" }, "$15" },
3707 { { "s0" }, "$16" },
3708 { { "s1" }, "$17" },
3709 { { "s2" }, "$18" },
3710 { { "s3" }, "$19" },
3711 { { "s4" }, "$20" },
3712 { { "s5" }, "$21" },
3713 { { "s6" }, "$22" },
3714 { { "s7" }, "$23" },
3715 { { "t8" }, "$24" },
3716 { { "t9" }, "$25" },
3717 { { "k0" }, "$26" },
3718 { { "k1" }, "$27" },
3719 { { "gp" }, "$28" },
Eric Christopherd1f853d2012-03-27 19:56:11 +00003720 { { "sp","$sp" }, "$29" },
3721 { { "fp","$fp" }, "$30" },
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003722 { { "ra" }, "$31" }
3723 };
3724 Aliases = GCCRegAliases;
3725 NumAliases = llvm::array_lengthof(GCCRegAliases);
3726 }
3727};
3728
3729class Mips32EBTargetInfo : public Mips32TargetInfoBase {
3730public:
3731 Mips32EBTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) {
3732 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
3733 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
3734 }
3735 virtual void getTargetDefines(const LangOptions &Opts,
3736 MacroBuilder &Builder) const {
3737 DefineStd(Builder, "mips", Opts);
3738 Builder.defineMacro("_mips");
3739 DefineStd(Builder, "MIPSEB", Opts);
3740 Builder.defineMacro("_MIPSEB");
3741 Builder.defineMacro("__REGISTER_PREFIX__", "");
3742 getArchDefines(Opts, Builder);
3743 }
3744};
3745
3746class Mips32ELTargetInfo : public Mips32TargetInfoBase {
3747public:
3748 Mips32ELTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003749 BigEndian = false;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003750 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
Akira Hatanaka619e8872011-06-02 00:09:17 +00003751 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003752 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003753 virtual void getTargetDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003754 MacroBuilder &Builder) const {
3755 DefineStd(Builder, "mips", Opts);
3756 Builder.defineMacro("_mips");
3757 DefineStd(Builder, "MIPSEL", Opts);
3758 Builder.defineMacro("_MIPSEL");
3759 Builder.defineMacro("__REGISTER_PREFIX__", "");
3760 getArchDefines(Opts, Builder);
3761 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003762};
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003763
3764class Mips64TargetInfoBase : public MipsTargetInfoBase {
3765 virtual void SetDescriptionString(const std::string &Name) = 0;
3766public:
3767 Mips64TargetInfoBase(const std::string& triple) :
Simon Atanasyan10e1629d2012-04-12 19:59:24 +00003768 MipsTargetInfoBase(triple, "n64", "mips64") {
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00003769 LongWidth = LongAlign = 64;
3770 PointerWidth = PointerAlign = 64;
3771 LongDoubleWidth = LongDoubleAlign = 128;
3772 LongDoubleFormat = &llvm::APFloat::IEEEquad;
Nick Lewycky7ec59c72011-12-16 22:34:14 +00003773 SuitableAlign = 128;
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00003774 }
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003775 virtual bool setABI(const std::string &Name) {
3776 SetDescriptionString(Name);
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00003777
3778 if (Name != "n32" && Name != "n64")
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003779 return false;
Akira Hatanakac7d0ab12011-10-22 00:07:27 +00003780
3781 ABI = Name;
3782
3783 if (Name == "n32") {
3784 LongWidth = LongAlign = 32;
3785 PointerWidth = PointerAlign = 32;
3786 }
3787
3788 return true;
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003789 }
3790 virtual void getArchDefines(const LangOptions &Opts,
3791 MacroBuilder &Builder) const {
Akira Hatanakaad8d8a32012-03-23 23:07:09 +00003792 MipsTargetInfoBase::getArchDefines(Opts, Builder);
3793
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003794 if (ABI == "n32") {
3795 Builder.defineMacro("__mips_n32");
3796 Builder.defineMacro("_ABIN32", "2");
3797 Builder.defineMacro("_MIPS_SIM", "_ABIN32");
3798 }
3799 else if (ABI == "n64") {
3800 Builder.defineMacro("__mips_n64");
3801 Builder.defineMacro("_ABI64", "3");
3802 Builder.defineMacro("_MIPS_SIM", "_ABI64");
3803 }
3804 else
David Blaikieb219cfc2011-09-23 05:06:16 +00003805 llvm_unreachable("Invalid ABI for Mips64.");
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003806 }
3807 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3808 unsigned &NumAliases) const {
3809 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
3810 { { "at" }, "$1" },
3811 { { "v0" }, "$2" },
3812 { { "v1" }, "$3" },
3813 { { "a0" }, "$4" },
3814 { { "a1" }, "$5" },
3815 { { "a2" }, "$6" },
3816 { { "a3" }, "$7" },
3817 { { "a4" }, "$8" },
3818 { { "a5" }, "$9" },
3819 { { "a6" }, "$10" },
3820 { { "a7" }, "$11" },
3821 { { "t0" }, "$12" },
3822 { { "t1" }, "$13" },
3823 { { "t2" }, "$14" },
3824 { { "t3" }, "$15" },
3825 { { "s0" }, "$16" },
3826 { { "s1" }, "$17" },
3827 { { "s2" }, "$18" },
3828 { { "s3" }, "$19" },
3829 { { "s4" }, "$20" },
3830 { { "s5" }, "$21" },
3831 { { "s6" }, "$22" },
3832 { { "s7" }, "$23" },
3833 { { "t8" }, "$24" },
3834 { { "t9" }, "$25" },
3835 { { "k0" }, "$26" },
3836 { { "k1" }, "$27" },
3837 { { "gp" }, "$28" },
Eric Christopherd1f853d2012-03-27 19:56:11 +00003838 { { "sp","$sp" }, "$29" },
3839 { { "fp","$fp" }, "$30" },
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003840 { { "ra" }, "$31" }
3841 };
3842 Aliases = GCCRegAliases;
3843 NumAliases = llvm::array_lengthof(GCCRegAliases);
3844 }
3845};
3846
3847class Mips64EBTargetInfo : public Mips64TargetInfoBase {
3848 virtual void SetDescriptionString(const std::string &Name) {
3849 // Change DescriptionString only if ABI is n32.
3850 if (Name == "n32")
3851 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 +00003852 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
3853 "v64:64:64-n32";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003854 }
3855public:
3856 Mips64EBTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) {
3857 // Default ABI is n64.
3858 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 +00003859 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
3860 "v64:64:64-n32";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003861 }
3862 virtual void getTargetDefines(const LangOptions &Opts,
3863 MacroBuilder &Builder) const {
3864 DefineStd(Builder, "mips", Opts);
3865 Builder.defineMacro("_mips");
3866 DefineStd(Builder, "MIPSEB", Opts);
3867 Builder.defineMacro("_MIPSEB");
3868 Builder.defineMacro("__REGISTER_PREFIX__", "");
3869 getArchDefines(Opts, Builder);
3870 }
3871};
3872
3873class Mips64ELTargetInfo : public Mips64TargetInfoBase {
3874 virtual void SetDescriptionString(const std::string &Name) {
3875 // Change DescriptionString only if ABI is n32.
3876 if (Name == "n32")
3877 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 +00003878 "i64:64:64-f32:32:32-f64:64:64-f128:128:128"
3879 "-v64:64:64-n32";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003880 }
3881public:
3882 Mips64ELTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003883 // Default ABI is n64.
3884 BigEndian = false;
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003885 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 +00003886 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-"
3887 "v64:64:64-n32";
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003888 }
3889 virtual void getTargetDefines(const LangOptions &Opts,
3890 MacroBuilder &Builder) const {
3891 DefineStd(Builder, "mips", Opts);
3892 Builder.defineMacro("_mips");
3893 DefineStd(Builder, "MIPSEL", Opts);
3894 Builder.defineMacro("_MIPSEL");
3895 Builder.defineMacro("__REGISTER_PREFIX__", "");
3896 getArchDefines(Opts, Builder);
3897 }
3898};
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003899} // end anonymous namespace.
3900
Ivan Krasinef05abd2011-08-24 20:22:22 +00003901namespace {
3902class PNaClTargetInfo : public TargetInfo {
3903public:
3904 PNaClTargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmane6a24e82011-12-22 03:51:45 +00003905 BigEndian = false;
Ivan Krasinef05abd2011-08-24 20:22:22 +00003906 this->UserLabelPrefix = "";
3907 this->LongAlign = 32;
3908 this->LongWidth = 32;
3909 this->PointerAlign = 32;
3910 this->PointerWidth = 32;
3911 this->IntMaxType = TargetInfo::SignedLongLong;
3912 this->UIntMaxType = TargetInfo::UnsignedLongLong;
3913 this->Int64Type = TargetInfo::SignedLongLong;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00003914 this->DoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00003915 this->LongDoubleWidth = 64;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00003916 this->LongDoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00003917 this->SizeType = TargetInfo::UnsignedInt;
3918 this->PtrDiffType = TargetInfo::SignedInt;
3919 this->IntPtrType = TargetInfo::SignedInt;
David Meyerdd4a8892011-10-11 03:12:01 +00003920 this->RegParmMax = 2;
Ivan Krasinef05abd2011-08-24 20:22:22 +00003921 DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
3922 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
3923 }
3924
Chandler Carruthc3a2e652011-09-28 05:56:05 +00003925 void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
Ivan Krasinef05abd2011-08-24 20:22:22 +00003926 }
3927 virtual void getArchDefines(const LangOptions &Opts,
3928 MacroBuilder &Builder) const {
3929 Builder.defineMacro("__le32__");
3930 Builder.defineMacro("__pnacl__");
3931 }
3932 virtual void getTargetDefines(const LangOptions &Opts,
3933 MacroBuilder &Builder) const {
Ivan Krasin089ee112011-08-25 23:49:20 +00003934 DefineStd(Builder, "unix", Opts);
3935 Builder.defineMacro("__ELF__");
3936 if (Opts.POSIXThreads)
3937 Builder.defineMacro("_REENTRANT");
3938 if (Opts.CPlusPlus)
3939 Builder.defineMacro("_GNU_SOURCE");
3940
Jan Wen Voungdde3bdb2012-03-29 00:05:59 +00003941 Builder.defineMacro("__LITTLE_ENDIAN__");
Ivan Krasinef05abd2011-08-24 20:22:22 +00003942 Builder.defineMacro("__native_client__");
3943 getArchDefines(Opts, Builder);
3944 }
Douglas Gregore727d212012-01-30 06:38:25 +00003945 virtual bool hasFeature(StringRef Feature) const {
3946 return Feature == "pnacl";
3947 }
Ivan Krasinef05abd2011-08-24 20:22:22 +00003948 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3949 unsigned &NumRecords) const {
3950 }
3951 virtual const char *getVAListDeclaration() const {
Ivan Krasin68018db2011-09-20 14:56:54 +00003952 return "typedef int __builtin_va_list[4];";
Ivan Krasinef05abd2011-08-24 20:22:22 +00003953 }
3954 virtual void getGCCRegNames(const char * const *&Names,
3955 unsigned &NumNames) const;
3956 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3957 unsigned &NumAliases) const;
3958 virtual bool validateAsmConstraint(const char *&Name,
3959 TargetInfo::ConstraintInfo &Info) const {
3960 return false;
3961 }
3962
3963 virtual const char *getClobbers() const {
3964 return "";
3965 }
3966};
3967
3968void PNaClTargetInfo::getGCCRegNames(const char * const *&Names,
3969 unsigned &NumNames) const {
3970 Names = NULL;
3971 NumNames = 0;
3972}
3973
3974void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3975 unsigned &NumAliases) const {
3976 Aliases = NULL;
3977 NumAliases = 0;
3978}
3979} // end anonymous namespace.
3980
3981
Reid Spencer5f016e22007-07-11 17:01:13 +00003982//===----------------------------------------------------------------------===//
3983// Driver code
3984//===----------------------------------------------------------------------===//
3985
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003986static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003987 llvm::Triple Triple(T);
3988 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00003989
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003990 switch (Triple.getArch()) {
3991 default:
3992 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00003993
Tony Linthicum96319392011-12-12 21:14:55 +00003994 case llvm::Triple::hexagon:
3995 return new HexagonTargetInfo(T);
3996
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003997 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00003998 case llvm::Triple::thumb:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003999 if (Triple.isOSDarwin())
4000 return new DarwinARMTargetInfo(T);
4001
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004002 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00004003 case llvm::Triple::Linux:
4004 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004005 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00004006 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004007 case llvm::Triple::NetBSD:
4008 return new NetBSDTargetInfo<ARMTargetInfo>(T);
Douglas Gregordca52262011-07-01 22:41:14 +00004009 case llvm::Triple::RTEMS:
4010 return new RTEMSTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004011 default:
4012 return new ARMTargetInfo(T);
4013 }
Eli Friedman61538a72008-05-20 14:21:01 +00004014
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004015 case llvm::Triple::msp430:
4016 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00004017
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004018 case llvm::Triple::mips:
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004019 switch (os) {
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004020 case llvm::Triple::Linux:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004021 return new LinuxTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004022 case llvm::Triple::RTEMS:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004023 return new RTEMSTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004024 case llvm::Triple::FreeBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004025 return new FreeBSDTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004026 case llvm::Triple::NetBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004027 return new NetBSDTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004028 default:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004029 return new Mips32EBTargetInfo(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00004030 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004031
4032 case llvm::Triple::mipsel:
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004033 switch (os) {
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004034 case llvm::Triple::Linux:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004035 return new LinuxTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004036 case llvm::Triple::RTEMS:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004037 return new RTEMSTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004038 case llvm::Triple::FreeBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004039 return new FreeBSDTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004040 case llvm::Triple::NetBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004041 return new NetBSDTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004042 default:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00004043 return new Mips32ELTargetInfo(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00004044 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00004045
Akira Hatanakabf5851a2011-09-20 19:21:49 +00004046 case llvm::Triple::mips64:
4047 switch (os) {
4048 case llvm::Triple::Linux:
4049 return new LinuxTargetInfo<Mips64EBTargetInfo>(T);
4050 case llvm::Triple::RTEMS:
4051 return new RTEMSTargetInfo<Mips64EBTargetInfo>(T);
4052 case llvm::Triple::FreeBSD:
4053 return new FreeBSDTargetInfo<Mips64EBTargetInfo>(T);
4054 case llvm::Triple::NetBSD:
4055 return new NetBSDTargetInfo<Mips64EBTargetInfo>(T);
4056 default:
4057 return new Mips64EBTargetInfo(T);
4058 }
4059
4060 case llvm::Triple::mips64el:
4061 switch (os) {
4062 case llvm::Triple::Linux:
4063 return new LinuxTargetInfo<Mips64ELTargetInfo>(T);
4064 case llvm::Triple::RTEMS:
4065 return new RTEMSTargetInfo<Mips64ELTargetInfo>(T);
4066 case llvm::Triple::FreeBSD:
4067 return new FreeBSDTargetInfo<Mips64ELTargetInfo>(T);
4068 case llvm::Triple::NetBSD:
4069 return new NetBSDTargetInfo<Mips64ELTargetInfo>(T);
4070 default:
4071 return new Mips64ELTargetInfo(T);
4072 }
4073
Ivan Krasinef05abd2011-08-24 20:22:22 +00004074 case llvm::Triple::le32:
4075 switch (os) {
4076 case llvm::Triple::NativeClient:
4077 return new PNaClTargetInfo(T);
4078 default:
4079 return NULL;
4080 }
4081
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004082 case llvm::Triple::ppc:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00004083 if (Triple.isOSDarwin())
Roman Divackyc81f2a22011-01-06 08:27:10 +00004084 return new DarwinPPC32TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004085 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00004086 case llvm::Triple::Linux:
4087 return new LinuxTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004088 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00004089 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004090 case llvm::Triple::NetBSD:
4091 return new NetBSDTargetInfo<PPC32TargetInfo>(T);
4092 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00004093 return new RTEMSTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004094 default:
4095 return new PPC32TargetInfo(T);
4096 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004097
4098 case llvm::Triple::ppc64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00004099 if (Triple.isOSDarwin())
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00004100 return new DarwinPPC64TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004101 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00004102 case llvm::Triple::Linux:
4103 return new LinuxTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004104 case llvm::Triple::Lv2:
John Thompson3f6918a2009-11-19 17:18:50 +00004105 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004106 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00004107 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004108 case llvm::Triple::NetBSD:
4109 return new NetBSDTargetInfo<PPC64TargetInfo>(T);
4110 default:
4111 return new PPC64TargetInfo(T);
4112 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004113
Peter Collingbourneedb66f32012-05-20 23:28:41 +00004114 case llvm::Triple::nvptx:
4115 return new NVPTX32TargetInfo(T);
4116 case llvm::Triple::nvptx64:
4117 return new NVPTX64TargetInfo(T);
4118
Chris Lattner9cbeb632010-03-06 21:21:27 +00004119 case llvm::Triple::mblaze:
4120 return new MBlazeTargetInfo(T);
4121
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004122 case llvm::Triple::sparc:
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004123 switch (os) {
Anton Korobeynikov7e1812f2011-10-12 09:30:58 +00004124 case llvm::Triple::Linux:
4125 return new LinuxTargetInfo<SparcV8TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004126 case llvm::Triple::AuroraUX:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00004127 return new AuroraUXSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004128 case llvm::Triple::Solaris:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004129 return new SolarisSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004130 case llvm::Triple::NetBSD:
4131 return new NetBSDTargetInfo<SparcV8TargetInfo>(T);
4132 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00004133 return new RTEMSTargetInfo<SparcV8TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00004134 default:
4135 return new SparcV8TargetInfo(T);
4136 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004137
John Thompson3f6918a2009-11-19 17:18:50 +00004138 // FIXME: Need a real SPU target.
4139 case llvm::Triple::cellspu:
4140 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
4141
Eli Friedmanb63decf2009-08-19 20:47:07 +00004142 case llvm::Triple::tce:
4143 return new TCETargetInfo(T);
4144
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004145 case llvm::Triple::x86:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00004146 if (Triple.isOSDarwin())
4147 return new DarwinI386TargetInfo(T);
4148
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004149 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00004150 case llvm::Triple::AuroraUX:
4151 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004152 case llvm::Triple::Linux:
4153 return new LinuxTargetInfo<X86_32TargetInfo>(T);
4154 case llvm::Triple::DragonFly:
4155 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
4156 case llvm::Triple::NetBSD:
Joerg Sonnenberger42378be2012-01-06 18:32:26 +00004157 return new NetBSDI386TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004158 case llvm::Triple::OpenBSD:
4159 return new OpenBSDI386TargetInfo(T);
4160 case llvm::Triple::FreeBSD:
4161 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00004162 case llvm::Triple::Minix:
4163 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004164 case llvm::Triple::Solaris:
4165 return new SolarisTargetInfo<X86_32TargetInfo>(T);
4166 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00004167 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004168 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00004169 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004170 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00004171 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00004172 case llvm::Triple::Haiku:
4173 return new HaikuX86_32TargetInfo(T);
Douglas Gregordca52262011-07-01 22:41:14 +00004174 case llvm::Triple::RTEMS:
4175 return new RTEMSX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004176 default:
4177 return new X86_32TargetInfo(T);
4178 }
4179
4180 case llvm::Triple::x86_64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00004181 if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO)
4182 return new DarwinX86_64TargetInfo(T);
4183
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004184 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00004185 case llvm::Triple::AuroraUX:
4186 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004187 case llvm::Triple::Linux:
4188 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00004189 case llvm::Triple::DragonFly:
4190 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004191 case llvm::Triple::NetBSD:
4192 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
4193 case llvm::Triple::OpenBSD:
4194 return new OpenBSDX86_64TargetInfo(T);
4195 case llvm::Triple::FreeBSD:
4196 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
4197 case llvm::Triple::Solaris:
4198 return new SolarisTargetInfo<X86_64TargetInfo>(T);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00004199 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00004200 return new MinGWX86_64TargetInfo(T);
4201 case llvm::Triple::Win32: // This is what Triple.h supports now.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00004202 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00004203 default:
4204 return new X86_64TargetInfo(T);
4205 }
4206 }
Reid Spencer5f016e22007-07-11 17:01:13 +00004207}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004208
4209/// CreateTargetInfo - Return the target info object for the specified target
4210/// triple.
David Blaikied6471f72011-09-25 23:23:43 +00004211TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00004212 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004213 llvm::Triple Triple(Opts.Triple);
4214
4215 // Construct the target
Dylan Noblesmith6f42b622012-02-05 02:12:40 +00004216 OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004217 if (!Target) {
4218 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
4219 return 0;
4220 }
4221
Daniel Dunbareac7c532009-12-18 18:42:37 +00004222 // Set the target CPU if specified.
4223 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
4224 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
4225 return 0;
4226 }
4227
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004228 // Set the target ABI if specified.
4229 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
4230 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
4231 return 0;
4232 }
4233
Charles Davis98b7c5c2010-06-11 01:06:47 +00004234 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00004235 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00004236 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
4237 return 0;
4238 }
4239
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004240 // Compute the default target features, we need the target to handle this
4241 // because features may have dependencies on one another.
4242 llvm::StringMap<bool> Features;
Chandler Carruthc3a2e652011-09-28 05:56:05 +00004243 Target->getDefaultFeatures(Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004244
4245 // Apply the user specified deltas.
Rafael Espindola53ac3d82011-11-27 20:00:43 +00004246 // First the enables.
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004247 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
4248 ie = Opts.Features.end(); it != ie; ++it) {
4249 const char *Name = it->c_str();
4250
Rafael Espindola53ac3d82011-11-27 20:00:43 +00004251 if (Name[0] != '+')
4252 continue;
4253
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004254 // Apply the feature via the target.
Rafael Espindola53ac3d82011-11-27 20:00:43 +00004255 if (!Target->setFeatureEnabled(Features, Name + 1, true)) {
4256 Diags.Report(diag::err_target_invalid_feature) << Name;
4257 return 0;
4258 }
4259 }
4260
4261 // Then the disables.
4262 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
4263 ie = Opts.Features.end(); it != ie; ++it) {
4264 const char *Name = it->c_str();
4265
4266 if (Name[0] == '+')
4267 continue;
4268
4269 // Apply the feature via the target.
4270 if (Name[0] != '-' ||
4271 !Target->setFeatureEnabled(Features, Name + 1, false)) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004272 Diags.Report(diag::err_target_invalid_feature) << Name;
4273 return 0;
4274 }
4275 }
4276
4277 // Add the features to the compile options.
4278 //
4279 // FIXME: If we are completely confident that we have the right set, we only
4280 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00004281 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004282 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
4283 ie = Features.end(); it != ie; ++it)
Benjamin Kramer713575a2012-03-05 15:10:44 +00004284 Opts.Features.push_back((it->second ? "+" : "-") + it->first().str());
Daniel Dunbarb93292a2009-12-19 03:30:57 +00004285 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00004286
4287 return Target.take();
4288}