blob: abfd0a762534ecea822f55b83ddcf3d145ea88f0 [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"
Dale Johannesen1e592cb2010-10-29 23:24:33 +000029#include "llvm/Type.h"
Benjamin Kramer48725082010-01-09 18:20:57 +000030#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000031using namespace clang;
32
Reid Spencer5f016e22007-07-11 17:01:13 +000033//===----------------------------------------------------------------------===//
34// Common code shared among targets.
35//===----------------------------------------------------------------------===//
36
Chris Lattnerca45cff2009-03-20 16:06:38 +000037/// DefineStd - Define a macro name and standard variants. For example if
38/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
39/// when in GNU mode.
Chris Lattner5f9e2722011-07-23 10:55:15 +000040static void DefineStd(MacroBuilder &Builder, StringRef MacroName,
Chris Lattnerca45cff2009-03-20 16:06:38 +000041 const LangOptions &Opts) {
42 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000043
Chris Lattnerca45cff2009-03-20 16:06:38 +000044 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
45 // in the user's namespace.
46 if (Opts.GNUMode)
Benjamin Kramera9992772010-01-09 17:55:51 +000047 Builder.defineMacro(MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000048
Chris Lattnerca45cff2009-03-20 16:06:38 +000049 // Define __unix.
Benjamin Kramera9992772010-01-09 17:55:51 +000050 Builder.defineMacro("__" + MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000051
Chris Lattnerca45cff2009-03-20 16:06:38 +000052 // Define __unix__.
Benjamin Kramera9992772010-01-09 17:55:51 +000053 Builder.defineMacro("__" + MacroName + "__");
Chris Lattnerca45cff2009-03-20 16:06:38 +000054}
55
Chris Lattnerd29b6302008-10-05 21:50:58 +000056//===----------------------------------------------------------------------===//
57// Defines specific to certain operating systems.
58//===----------------------------------------------------------------------===//
Chris Lattner797c3c42009-08-10 19:03:04 +000059
Torok Edwin5f6c1942009-06-30 17:10:35 +000060namespace {
Douglas Gregora3844922009-07-01 15:12:53 +000061template<typename TgtInfo>
62class OSTargetInfo : public TgtInfo {
Torok Edwin5f6c1942009-06-30 17:10:35 +000063protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +000064 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +000065 MacroBuilder &Builder) const=0;
Torok Edwin5f6c1942009-06-30 17:10:35 +000066public:
Douglas Gregora3844922009-07-01 15:12:53 +000067 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {}
Torok Edwin5f6c1942009-06-30 17:10:35 +000068 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +000069 MacroBuilder &Builder) const {
70 TgtInfo::getTargetDefines(Opts, Builder);
71 getOSDefines(Opts, TgtInfo::getTriple(), Builder);
Torok Edwinb0a5b242009-06-30 17:00:25 +000072 }
Torok Edwin5f6c1942009-06-30 17:10:35 +000073
74};
Chris Lattner4c28b1c2009-08-12 06:24:27 +000075} // end anonymous namespace
Torok Edwinb0a5b242009-06-30 17:00:25 +000076
Chris Lattner797c3c42009-08-10 19:03:04 +000077
Daniel Dunbar21ae3192010-01-26 01:44:04 +000078static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000079 const llvm::Triple &Triple,
Chris Lattner5f9e2722011-07-23 10:55:15 +000080 StringRef &PlatformName,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000081 VersionTuple &PlatformMinVersion) {
Benjamin Kramera9992772010-01-09 17:55:51 +000082 Builder.defineMacro("__APPLE_CC__", "5621");
83 Builder.defineMacro("__APPLE__");
84 Builder.defineMacro("__MACH__");
85 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000086
John McCall098df7f2011-06-16 00:03:19 +000087 if (!Opts.ObjCAutoRefCount) {
John McCallf85e1932011-06-15 23:02:42 +000088 // __weak is always defined, for use in blocks and with objc pointers.
89 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000090
John McCallf85e1932011-06-15 23:02:42 +000091 // Darwin defines __strong even in C mode (just to nothing).
Douglas Gregore289d812011-09-13 17:21:33 +000092 if (Opts.getGC() != LangOptions::NonGC)
John McCallf85e1932011-06-15 23:02:42 +000093 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
94 else
95 Builder.defineMacro("__strong", "");
Eric Christopher7c9adf92011-07-07 22:55:26 +000096
John McCallf85e1932011-06-15 23:02:42 +000097 // __unsafe_unretained is defined to nothing in non-ARC mode. We even
98 // allow this in C, since one might have block pointers in structs that
99 // are used in pure C code and in Objective-C ARC.
100 Builder.defineMacro("__unsafe_unretained", "");
Eric Christopher7c9adf92011-07-07 22:55:26 +0000101
John McCallf85e1932011-06-15 23:02:42 +0000102 // The Objective-C bridged cast keywords are defined to nothing in non-ARC
103 // mode; then they become normal, C-style casts.
104 Builder.defineMacro("__bridge", "");
105 Builder.defineMacro("__bridge_transfer", "");
106 Builder.defineMacro("__bridge_retained", "");
John McCall18164422011-06-17 21:23:37 +0000107 Builder.defineMacro("__bridge_retain", "");
John McCallf85e1932011-06-15 23:02:42 +0000108 }
Eric Christopher7c9adf92011-07-07 22:55:26 +0000109
Eli Friedman2de4fee2009-06-04 23:00:29 +0000110 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +0000111 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +0000112 else
Benjamin Kramera9992772010-01-09 17:55:51 +0000113 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000114
115 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000116 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000117
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000118 // Get the platform type and version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000119 unsigned Maj, Min, Rev;
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000121 // If no version was given, default to to 10.4.0, for simplifying tests.
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000122 if (Triple.getOSName() == "darwin" || Triple.getOSName() == "osx") {
123 PlatformName = "macosx";
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000124 Min = Rev = 0;
125 Maj = 8;
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000126 } else {
127 // Otherwise, honor all three triple forms ("-darwinNNN[-iphoneos]",
128 // "-osxNNN", and "-iosNNN").
129
130 if (Triple.getOS() == llvm::Triple::Darwin) {
131 // For historical reasons that make little sense, the version passed here
132 // is the "darwin" version, which drops the 10 and offsets by 4.
133 Triple.getOSVersion(Maj, Min, Rev);
134
135 if (Triple.getEnvironmentName() == "iphoneos") {
136 PlatformName = "ios";
137 } else {
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000138 PlatformName = "macosx";
139 Rev = Min;
140 Min = Maj - 4;
141 Maj = 10;
142 }
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000143 } else {
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000144 Triple.getOSVersion(Maj, Min, Rev);
Daniel Dunbara4ff6482011-04-19 23:34:21 +0000145 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000146 }
147 }
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000148
Chad Rosierd9259f32011-07-19 20:00:06 +0000149 // If -ccc-host-triple arch-pc-win32-macho option specified, we're
Eric Christopher895d4222011-07-29 21:20:35 +0000150 // generating code for Win32 ABI. No need to emit
Chad Rosierd9259f32011-07-19 20:00:06 +0000151 // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__.
152 if (PlatformName == "win32") {
153 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
154 return;
155 }
156
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000157 // Set the appropriate OS version define.
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000158 if (PlatformName == "ios") {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000159 assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000160 char Str[6];
161 Str[0] = '0' + Maj;
162 Str[1] = '0' + (Min / 10);
163 Str[2] = '0' + (Min % 10);
164 Str[3] = '0' + (Rev / 10);
165 Str[4] = '0' + (Rev % 10);
166 Str[5] = '\0';
167 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
168 } else {
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000169 // Note that the Driver allows versions which aren't representable in the
170 // define (because we only get a single digit for the minor and micro
171 // revision numbers). So, we limit them to the maximum representable
172 // version.
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000173 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000174 assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000175 char Str[5];
176 Str[0] = '0' + (Maj / 10);
177 Str[1] = '0' + (Maj % 10);
Daniel Dunbar8a3a7f32011-04-21 21:27:33 +0000178 Str[2] = '0' + std::min(Min, 9U);
179 Str[3] = '0' + std::min(Rev, 9U);
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000180 Str[4] = '\0';
181 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000182 }
Daniel Dunbar0d027ba2011-04-19 21:40:34 +0000183
184 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
Eli Friedman618234a2008-08-20 02:34:37 +0000185}
Reid Spencer5f016e22007-07-11 17:01:13 +0000186
Chris Lattner797c3c42009-08-10 19:03:04 +0000187namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000188template<typename Target>
189class DarwinTargetInfo : public OSTargetInfo<Target> {
190protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000191 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000192 MacroBuilder &Builder) const {
Eric Christopher7c9adf92011-07-07 22:55:26 +0000193 getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000194 this->PlatformMinVersion);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000195 }
Mike Stump1eb44332009-09-09 15:08:12 +0000196
Torok Edwin5f6c1942009-06-30 17:10:35 +0000197public:
198 DarwinTargetInfo(const std::string& triple) :
199 OSTargetInfo<Target>(triple) {
Eric Christopheraa7333c2011-07-02 00:20:22 +0000200 llvm::Triple T = llvm::Triple(triple);
201 this->TLSSupported = T.isMacOSX() && !T.isMacOSXVersionLT(10,7);
Daniel Dunbare177d3b2011-02-21 23:12:51 +0000202 this->MCountName = "\01mcount";
Torok Edwin5f6c1942009-06-30 17:10:35 +0000203 }
204
Chris Lattner5f9e2722011-07-23 10:55:15 +0000205 virtual std::string isValidSectionSpecifier(StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000206 // Let MCSectionMachO validate this.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000207 StringRef Segment, Section;
Chris Lattner797c3c42009-08-10 19:03:04 +0000208 unsigned TAA, StubSize;
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000209 bool HasTAA;
Chris Lattner797c3c42009-08-10 19:03:04 +0000210 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000211 TAA, HasTAA, StubSize);
Chris Lattner797c3c42009-08-10 19:03:04 +0000212 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000213
Anders Carlsson18af3682010-06-08 22:47:50 +0000214 virtual const char *getStaticInitSectionSpecifier() const {
215 // FIXME: We should return 0 when building kexts.
216 return "__TEXT,__StaticInit,regular,pure_instructions";
217 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000218
Torok Edwin5f6c1942009-06-30 17:10:35 +0000219};
220
Chris Lattner797c3c42009-08-10 19:03:04 +0000221
Torok Edwin5f6c1942009-06-30 17:10:35 +0000222// DragonFlyBSD Target
223template<typename Target>
224class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
225protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000226 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000227 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000228 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000229 Builder.defineMacro("__DragonFly__");
230 Builder.defineMacro("__DragonFly_cc_version", "100001");
231 Builder.defineMacro("__ELF__");
232 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
233 Builder.defineMacro("__tune_i386__");
234 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000235 }
236public:
Mike Stump1eb44332009-09-09 15:08:12 +0000237 DragonFlyBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000238 : OSTargetInfo<Target>(triple) {}
239};
240
241// FreeBSD Target
242template<typename Target>
243class FreeBSDTargetInfo : public OSTargetInfo<Target> {
244protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000245 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000246 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000247 // FreeBSD defines; list based off of gcc output
248
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000249 // FIXME: Move version number handling to llvm::Triple.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000250 StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000251
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000252 Builder.defineMacro("__FreeBSD__", Release);
253 Builder.defineMacro("__FreeBSD_cc_version", Release + "00001");
Benjamin Kramera9992772010-01-09 17:55:51 +0000254 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
255 DefineStd(Builder, "unix", Opts);
256 Builder.defineMacro("__ELF__");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000257 }
258public:
Mike Stump1eb44332009-09-09 15:08:12 +0000259 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000260 : OSTargetInfo<Target>(triple) {
261 this->UserLabelPrefix = "";
Roman Divackybe4c8702011-02-10 16:52:03 +0000262
263 llvm::Triple Triple(triple);
264 switch (Triple.getArch()) {
265 default:
266 case llvm::Triple::x86:
267 case llvm::Triple::x86_64:
268 this->MCountName = ".mcount";
269 break;
270 case llvm::Triple::mips:
271 case llvm::Triple::mipsel:
272 case llvm::Triple::ppc:
273 case llvm::Triple::ppc64:
274 this->MCountName = "_mcount";
275 break;
276 case llvm::Triple::arm:
277 this->MCountName = "__mcount";
278 break;
279 }
280
Duncan Sands1e90faf2009-07-08 13:55:08 +0000281 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000282};
283
Chris Lattner38e317d2010-07-07 16:01:42 +0000284// Minix Target
285template<typename Target>
286class MinixTargetInfo : public OSTargetInfo<Target> {
287protected:
288 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
289 MacroBuilder &Builder) const {
290 // Minix defines
291
292 Builder.defineMacro("__minix", "3");
293 Builder.defineMacro("_EM_WSIZE", "4");
294 Builder.defineMacro("_EM_PSIZE", "4");
295 Builder.defineMacro("_EM_SSIZE", "2");
296 Builder.defineMacro("_EM_LSIZE", "4");
297 Builder.defineMacro("_EM_FSIZE", "4");
298 Builder.defineMacro("_EM_DSIZE", "8");
299 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__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000319 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000320 Builder.defineMacro("_REENTRANT");
Douglas Gregor2b003fd2010-04-21 05:52:38 +0000321 if (Opts.CPlusPlus)
322 Builder.defineMacro("_GNU_SOURCE");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000323 }
324public:
Mike Stump1eb44332009-09-09 15:08:12 +0000325 LinuxTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000326 : OSTargetInfo<Target>(triple) {
327 this->UserLabelPrefix = "";
Douglas Gregor12e84642011-01-12 21:19:25 +0000328 this->WIntType = TargetInfo::UnsignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000329 }
330};
331
Chris Lattnerb62bb282009-07-13 20:29:08 +0000332// NetBSD Target
333template<typename Target>
334class NetBSDTargetInfo : public OSTargetInfo<Target> {
335protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000336 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000337 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000338 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000339 Builder.defineMacro("__NetBSD__");
340 Builder.defineMacro("__unix__");
341 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000342 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000343 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000344 }
345public:
Mike Stump1eb44332009-09-09 15:08:12 +0000346 NetBSDTargetInfo(const std::string &triple)
Chris Lattnerb62bb282009-07-13 20:29:08 +0000347 : OSTargetInfo<Target>(triple) {
348 this->UserLabelPrefix = "";
349 }
350};
351
Torok Edwin5f6c1942009-06-30 17:10:35 +0000352// OpenBSD Target
353template<typename Target>
354class OpenBSDTargetInfo : public OSTargetInfo<Target> {
355protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000356 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000357 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000358 // OpenBSD defines; list based off of gcc output
359
Benjamin Kramera9992772010-01-09 17:55:51 +0000360 Builder.defineMacro("__OpenBSD__");
361 DefineStd(Builder, "unix", Opts);
362 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000363 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000364 Builder.defineMacro("_POSIX_THREADS");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000365 }
366public:
Mike Stump1eb44332009-09-09 15:08:12 +0000367 OpenBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000368 : OSTargetInfo<Target>(triple) {}
369};
370
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000371// PSP Target
372template<typename Target>
373class PSPTargetInfo : public OSTargetInfo<Target> {
374protected:
375 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000376 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000377 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000378 Builder.defineMacro("PSP");
379 Builder.defineMacro("_PSP");
380 Builder.defineMacro("__psp__");
381 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000382 }
383public:
384 PSPTargetInfo(const std::string& triple)
385 : OSTargetInfo<Target>(triple) {
386 this->UserLabelPrefix = "";
387 }
388};
389
John Thompson3f6918a2009-11-19 17:18:50 +0000390// PS3 PPU Target
391template<typename Target>
392class PS3PPUTargetInfo : public OSTargetInfo<Target> {
393protected:
394 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000395 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000396 // PS3 PPU defines.
John Thompsonfb457972010-03-25 16:18:32 +0000397 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000398 Builder.defineMacro("__PPU__");
399 Builder.defineMacro("__CELLOS_LV2__");
400 Builder.defineMacro("__ELF__");
401 Builder.defineMacro("__LP32__");
John Thompson8e6065a2010-06-24 22:44:13 +0000402 Builder.defineMacro("_ARCH_PPC64");
403 Builder.defineMacro("__powerpc64__");
John Thompson3f6918a2009-11-19 17:18:50 +0000404 }
405public:
406 PS3PPUTargetInfo(const std::string& triple)
407 : OSTargetInfo<Target>(triple) {
408 this->UserLabelPrefix = "";
John Thompsonec387af2009-12-18 14:21:08 +0000409 this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32;
John Thompson8e6065a2010-06-24 22:44:13 +0000410 this->IntMaxType = TargetInfo::SignedLongLong;
411 this->UIntMaxType = TargetInfo::UnsignedLongLong;
412 this->Int64Type = TargetInfo::SignedLongLong;
John Thompsonec387af2009-12-18 14:21:08 +0000413 this->SizeType = TargetInfo::UnsignedInt;
John Thompson8e6065a2010-06-24 22:44:13 +0000414 this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
415 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
John Thompson3f6918a2009-11-19 17:18:50 +0000416 }
417};
418
419// FIXME: Need a real SPU target.
420// PS3 SPU Target
421template<typename Target>
422class PS3SPUTargetInfo : public OSTargetInfo<Target> {
423protected:
424 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000425 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000426 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000427 Builder.defineMacro("__SPU__");
428 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000429 }
430public:
431 PS3SPUTargetInfo(const std::string& triple)
432 : OSTargetInfo<Target>(triple) {
433 this->UserLabelPrefix = "";
434 }
435};
436
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000437// AuroraUX target
438template<typename Target>
439class AuroraUXTargetInfo : public OSTargetInfo<Target> {
440protected:
441 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000442 MacroBuilder &Builder) const {
443 DefineStd(Builder, "sun", Opts);
444 DefineStd(Builder, "unix", Opts);
445 Builder.defineMacro("__ELF__");
446 Builder.defineMacro("__svr4__");
447 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000448 }
449public:
450 AuroraUXTargetInfo(const std::string& triple)
451 : OSTargetInfo<Target>(triple) {
452 this->UserLabelPrefix = "";
453 this->WCharType = this->SignedLong;
454 // FIXME: WIntType should be SignedLong
455 }
456};
457
Torok Edwin5f6c1942009-06-30 17:10:35 +0000458// Solaris target
459template<typename Target>
460class SolarisTargetInfo : public OSTargetInfo<Target> {
461protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000462 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000463 MacroBuilder &Builder) const {
464 DefineStd(Builder, "sun", Opts);
465 DefineStd(Builder, "unix", Opts);
466 Builder.defineMacro("__ELF__");
467 Builder.defineMacro("__svr4__");
468 Builder.defineMacro("__SVR4");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000469 }
470public:
Mike Stump1eb44332009-09-09 15:08:12 +0000471 SolarisTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000472 : OSTargetInfo<Target>(triple) {
473 this->UserLabelPrefix = "";
474 this->WCharType = this->SignedLong;
475 // FIXME: WIntType should be SignedLong
476 }
477};
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000478
479// Windows target
480template<typename Target>
481class WindowsTargetInfo : public OSTargetInfo<Target> {
482protected:
483 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
484 MacroBuilder &Builder) const {
Michael J. Spencera764e832010-10-21 08:22:51 +0000485 Builder.defineMacro("_WIN32");
486 }
487 void getVisualStudioDefines(const LangOptions &Opts,
488 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000489 if (Opts.CPlusPlus) {
490 if (Opts.RTTI)
491 Builder.defineMacro("_CPPRTTI");
492
493 if (Opts.Exceptions)
494 Builder.defineMacro("_CPPUNWIND");
495 }
496
497 if (!Opts.CharIsSigned)
498 Builder.defineMacro("_CHAR_UNSIGNED");
499
500 // FIXME: POSIXThreads isn't exactly the option this should be defined for,
501 // but it works for now.
502 if (Opts.POSIXThreads)
503 Builder.defineMacro("_MT");
Michael J. Spencera764e832010-10-21 08:22:51 +0000504
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000505 if (Opts.MSCVersion != 0)
Chris Lattner5f9e2722011-07-23 10:55:15 +0000506 Builder.defineMacro("_MSC_VER", Twine(Opts.MSCVersion));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000507
Francois Pichet62ec1f22011-09-17 17:15:52 +0000508 if (Opts.MicrosoftExt) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000509 Builder.defineMacro("_MSC_EXTENSIONS");
510
511 if (Opts.CPlusPlus0x) {
512 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
513 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
514 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
515 }
516 }
517
518 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000519 }
520
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000521public:
522 WindowsTargetInfo(const std::string &triple)
523 : OSTargetInfo<Target>(triple) {}
524};
525
Mike Stump1eb44332009-09-09 15:08:12 +0000526} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000527
Chris Lattnerd29b6302008-10-05 21:50:58 +0000528//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000529// Specific target implementations.
530//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000531
Eli Friedmane4277982008-08-20 23:11:40 +0000532namespace {
533// PPC abstract base class
534class PPCTargetInfo : public TargetInfo {
535 static const Builtin::Info BuiltinInfo[];
536 static const char * const GCCRegNames[];
537 static const TargetInfo::GCCRegAlias GCCRegAliases[];
Eli Friedmane4277982008-08-20 23:11:40 +0000538public:
Eli Friedman15b91762009-06-05 07:05:05 +0000539 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
540
Eli Friedmane4277982008-08-20 23:11:40 +0000541 virtual void getTargetBuiltins(const Builtin::Info *&Records,
542 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000543 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000544 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000545 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000546
Chris Lattner33328642009-03-20 15:52:06 +0000547 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000548 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000549
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000550 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000551 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000552 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000553 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000554 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000555 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000556 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000557 default: return false;
558 case 'O': // Zero
John Thompson8e6065a2010-06-24 22:44:13 +0000559 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000560 case 'b': // Base register
561 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000562 Info.setAllowsRegister();
John Thompson8e6065a2010-06-24 22:44:13 +0000563 break;
564 // FIXME: The following are added to allow parsing.
565 // I just took a guess at what the actions should be.
566 // Also, is more specific checking needed? I.e. specific registers?
Michael J. Spencer20249a12010-10-21 03:16:25 +0000567 case 'd': // Floating point register (containing 64-bit value)
John Thompson8e6065a2010-06-24 22:44:13 +0000568 case 'v': // Altivec vector register
569 Info.setAllowsRegister();
570 break;
571 case 'w':
572 switch (Name[1]) {
Michael J. Spencer20249a12010-10-21 03:16:25 +0000573 case 'd':// VSX vector register to hold vector double data
574 case 'f':// VSX vector register to hold vector float data
575 case 's':// VSX vector register to hold scalar float data
576 case 'a':// Any VSX register
John Thompson8e6065a2010-06-24 22:44:13 +0000577 break;
578 default:
579 return false;
580 }
581 Info.setAllowsRegister();
582 Name++; // Skip over 'w'.
583 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000584 case 'h': // `MQ', `CTR', or `LINK' register
585 case 'q': // `MQ' register
586 case 'c': // `CTR' register
587 case 'l': // `LINK' register
588 case 'x': // `CR' register (condition register) number 0
589 case 'y': // `CR' register (condition register)
590 case 'z': // `XER[CA]' carry bit (part of the XER register)
John Thompson8e6065a2010-06-24 22:44:13 +0000591 Info.setAllowsRegister();
592 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000593 case 'I': // Signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000594 case 'J': // Unsigned 16-bit constant shifted left 16 bits
Michael J. Spencer20249a12010-10-21 03:16:25 +0000595 // (use `L' instead for SImode constants)
596 case 'K': // Unsigned 16-bit constant
597 case 'L': // Signed 16-bit constant shifted left 16 bits
598 case 'M': // Constant larger than 31
599 case 'N': // Exact power of 2
600 case 'P': // Constant whose negation is a signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000601 case 'G': // Floating point constant that can be loaded into a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000602 // register with one instruction per word
John Thompson8e6065a2010-06-24 22:44:13 +0000603 case 'H': // Integer/Floating point constant that can be loaded
Michael J. Spencer20249a12010-10-21 03:16:25 +0000604 // into a register using three instructions
John Thompson8e6065a2010-06-24 22:44:13 +0000605 break;
606 case 'm': // Memory operand. Note that on PowerPC targets, m can
607 // include addresses that update the base register. It
608 // is therefore only safe to use `m' in an asm statement
609 // if that asm statement accesses the operand exactly once.
610 // The asm statement must also use `%U<opno>' as a
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000611 // placeholder for the "update" flag in the corresponding
Michael J. Spencer20249a12010-10-21 03:16:25 +0000612 // load or store instruction. For example:
John Thompson8e6065a2010-06-24 22:44:13 +0000613 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
Michael J. Spencer20249a12010-10-21 03:16:25 +0000614 // is correct but:
John Thompson8e6065a2010-06-24 22:44:13 +0000615 // asm ("st %1,%0" : "=m" (mem) : "r" (val));
616 // is not. Use es rather than m if you don't want the base
Michael J. Spencer20249a12010-10-21 03:16:25 +0000617 // register to be updated.
618 case 'e':
John Thompson56b6eca2010-06-25 00:02:05 +0000619 if (Name[1] != 's')
620 return false;
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000621 // es: A "stable" memory operand; that is, one which does not
John Thompson8e6065a2010-06-24 22:44:13 +0000622 // include any automodification of the base register. Unlike
623 // `m', this constraint can be used in asm statements that
624 // might access the operand several times, or that might not
John Thompson56b6eca2010-06-25 00:02:05 +0000625 // access it at all.
John Thompson8e6065a2010-06-24 22:44:13 +0000626 Info.setAllowsMemory();
John Thompson56b6eca2010-06-25 00:02:05 +0000627 Name++; // Skip over 'e'.
John Thompson8e6065a2010-06-24 22:44:13 +0000628 break;
629 case 'Q': // Memory operand that is an offset from a register (it is
Michael J. Spencer20249a12010-10-21 03:16:25 +0000630 // usually better to use `m' or `es' in asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000631 case 'Z': // Memory operand that is an indexed or indirect from a
632 // register (it is usually better to use `m' or `es' in
Michael J. Spencer20249a12010-10-21 03:16:25 +0000633 // asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000634 Info.setAllowsMemory();
635 Info.setAllowsRegister();
636 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000637 case 'R': // AIX TOC entry
John Thompson8e6065a2010-06-24 22:44:13 +0000638 case 'a': // Address operand that is an indexed or indirect from a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000639 // register (`p' is preferable for asm statements)
640 case 'S': // Constant suitable as a 64-bit mask operand
641 case 'T': // Constant suitable as a 32-bit mask operand
642 case 'U': // System V Release 4 small data area reference
John Thompson8e6065a2010-06-24 22:44:13 +0000643 case 't': // AND masks that can be performed by two rldic{l, r}
Michael J. Spencer20249a12010-10-21 03:16:25 +0000644 // instructions
645 case 'W': // Vector constant that does not require memory
646 case 'j': // Vector constant that is all zeros.
John Thompson8e6065a2010-06-24 22:44:13 +0000647 break;
648 // End FIXME.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000649 }
John Thompson8e6065a2010-06-24 22:44:13 +0000650 return true;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000651 }
Eli Friedmane4277982008-08-20 23:11:40 +0000652 virtual const char *getClobbers() const {
653 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000654 }
Eli Friedmane4277982008-08-20 23:11:40 +0000655};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000656
Eli Friedmane4277982008-08-20 23:11:40 +0000657const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +0000658#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000659#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +0000660 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000661#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000662};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000663
664
Chris Lattnerc0f59212009-03-02 22:27:17 +0000665/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
666/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000667void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000668 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000669 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000670 Builder.defineMacro("__ppc__");
671 Builder.defineMacro("_ARCH_PPC");
Chris Lattnere03ae302010-02-16 18:14:57 +0000672 Builder.defineMacro("__powerpc__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000673 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000674 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000675 Builder.defineMacro("_ARCH_PPC64");
676 Builder.defineMacro("_LP64");
677 Builder.defineMacro("__LP64__");
Chris Lattnere03ae302010-02-16 18:14:57 +0000678 Builder.defineMacro("__powerpc64__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000679 Builder.defineMacro("__ppc64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000680 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000681 Builder.defineMacro("__ppc__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000682 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000683
Chris Lattnerc0f59212009-03-02 22:27:17 +0000684 // Target properties.
Joerg Sonnenberger7cd1de52011-07-05 14:56:12 +0000685 if (getTriple().getOS() != llvm::Triple::NetBSD)
686 Builder.defineMacro("_BIG_ENDIAN");
Benjamin Kramera9992772010-01-09 17:55:51 +0000687 Builder.defineMacro("__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000688
Chris Lattnerc0f59212009-03-02 22:27:17 +0000689 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000690 Builder.defineMacro("__NATURAL_ALIGNMENT__");
691 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000692
Chris Lattnerc0f59212009-03-02 22:27:17 +0000693 // FIXME: Should be controlled by command line option.
Benjamin Kramera9992772010-01-09 17:55:51 +0000694 Builder.defineMacro("__LONG_DOUBLE_128__");
Michael J. Spencer20249a12010-10-21 03:16:25 +0000695
John Thompson3f6918a2009-11-19 17:18:50 +0000696 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000697 Builder.defineMacro("__VEC__", "10206");
698 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000699 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000700}
701
Chris Lattner393ff042008-04-21 18:56:49 +0000702
Eli Friedmane4277982008-08-20 23:11:40 +0000703const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +0000704 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
705 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
706 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
707 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
708 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
709 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
710 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
711 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +0000712 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000713 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +0000714 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000715 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
716 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
717 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
718 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +0000719 "vrsave", "vscr",
720 "spe_acc", "spefscr",
721 "sfp"
722};
Reid Spencer5f016e22007-07-11 17:01:13 +0000723
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000724void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000725 unsigned &NumNames) const {
726 Names = GCCRegNames;
727 NumNames = llvm::array_lengthof(GCCRegNames);
728}
Reid Spencer5f016e22007-07-11 17:01:13 +0000729
Eli Friedmane4277982008-08-20 23:11:40 +0000730const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
731 // While some of these aliases do map to different registers
732 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000733 { { "0" }, "r0" },
734 { { "1"}, "r1" },
735 { { "2" }, "r2" },
736 { { "3" }, "r3" },
737 { { "4" }, "r4" },
738 { { "5" }, "r5" },
739 { { "6" }, "r6" },
740 { { "7" }, "r7" },
741 { { "8" }, "r8" },
742 { { "9" }, "r9" },
743 { { "10" }, "r10" },
744 { { "11" }, "r11" },
745 { { "12" }, "r12" },
746 { { "13" }, "r13" },
747 { { "14" }, "r14" },
748 { { "15" }, "r15" },
749 { { "16" }, "r16" },
750 { { "17" }, "r17" },
751 { { "18" }, "r18" },
752 { { "19" }, "r19" },
753 { { "20" }, "r20" },
754 { { "21" }, "r21" },
755 { { "22" }, "r22" },
756 { { "23" }, "r23" },
757 { { "24" }, "r24" },
758 { { "25" }, "r25" },
759 { { "26" }, "r26" },
760 { { "27" }, "r27" },
761 { { "28" }, "r28" },
762 { { "29" }, "r29" },
763 { { "30" }, "r30" },
764 { { "31" }, "r31" },
765 { { "fr0" }, "f0" },
766 { { "fr1" }, "f1" },
767 { { "fr2" }, "f2" },
768 { { "fr3" }, "f3" },
769 { { "fr4" }, "f4" },
770 { { "fr5" }, "f5" },
771 { { "fr6" }, "f6" },
772 { { "fr7" }, "f7" },
773 { { "fr8" }, "f8" },
774 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +0000775 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000776 { { "fr11" }, "f11" },
777 { { "fr12" }, "f12" },
778 { { "fr13" }, "f13" },
779 { { "fr14" }, "f14" },
780 { { "fr15" }, "f15" },
781 { { "fr16" }, "f16" },
782 { { "fr17" }, "f17" },
783 { { "fr18" }, "f18" },
784 { { "fr19" }, "f19" },
785 { { "fr20" }, "f20" },
786 { { "fr21" }, "f21" },
787 { { "fr22" }, "f22" },
788 { { "fr23" }, "f23" },
789 { { "fr24" }, "f24" },
790 { { "fr25" }, "f25" },
791 { { "fr26" }, "f26" },
792 { { "fr27" }, "f27" },
793 { { "fr28" }, "f28" },
794 { { "fr29" }, "f29" },
795 { { "fr30" }, "f30" },
796 { { "fr31" }, "f31" },
797 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +0000798};
799
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000800void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000801 unsigned &NumAliases) const {
802 Aliases = GCCRegAliases;
803 NumAliases = llvm::array_lengthof(GCCRegAliases);
804}
805} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000806
807namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000808class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000809public:
Chris Lattnere03ae302010-02-16 18:14:57 +0000810 PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) {
Eli Friedmaned855cb2008-08-21 00:13:15 +0000811 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 +0000812 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Chris Lattnere03ae302010-02-16 18:14:57 +0000813
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +0000814 switch (getTriple().getOS()) {
815 case llvm::Triple::FreeBSD:
816 case llvm::Triple::NetBSD:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +0000817 SizeType = UnsignedInt;
818 break;
Joerg Sonnenberger1a83b432011-07-04 23:11:58 +0000819 default:
Joerg Sonnenberger78542df2011-07-05 14:54:41 +0000820 break;
Joerg Sonnenberger6ac26fa2011-07-04 21:57:55 +0000821 }
Roman Divackyc81f2a22011-01-06 08:27:10 +0000822 }
823
824 virtual const char *getVAListDeclaration() const {
825 // This is the ELF definition, and is overridden by the Darwin sub-target
826 return "typedef struct __va_list_tag {"
827 " unsigned char gpr;"
828 " unsigned char fpr;"
829 " unsigned short reserved;"
830 " void* overflow_arg_area;"
831 " void* reg_save_area;"
832 "} __builtin_va_list[1];";
Eli Friedmaned855cb2008-08-21 00:13:15 +0000833 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000834};
835} // end anonymous namespace.
836
837namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000838class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000839public:
Eli Friedmane4277982008-08-20 23:11:40 +0000840 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000841 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000842 IntMaxType = SignedLong;
843 UIntMaxType = UnsignedLong;
844 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000845 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 +0000846 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Chris Lattnerf291b102008-05-09 06:17:04 +0000847 }
Roman Divackyc81f2a22011-01-06 08:27:10 +0000848 virtual const char *getVAListDeclaration() const {
849 return "typedef char* __builtin_va_list;";
850 }
Eli Friedmane4277982008-08-20 23:11:40 +0000851};
852} // end anonymous namespace.
853
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000854
855namespace {
Roman Divackyc81f2a22011-01-06 08:27:10 +0000856class DarwinPPC32TargetInfo :
857 public DarwinTargetInfo<PPC32TargetInfo> {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000858public:
Roman Divackyc81f2a22011-01-06 08:27:10 +0000859 DarwinPPC32TargetInfo(const std::string& triple)
860 : DarwinTargetInfo<PPC32TargetInfo>(triple) {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000861 HasAlignMac68kSupport = true;
Roman Divackyc81f2a22011-01-06 08:27:10 +0000862 BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool?
863 }
864 virtual const char *getVAListDeclaration() const {
865 return "typedef char* __builtin_va_list;";
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000866 }
867};
868
869class DarwinPPC64TargetInfo :
870 public DarwinTargetInfo<PPC64TargetInfo> {
871public:
872 DarwinPPC64TargetInfo(const std::string& triple)
873 : DarwinTargetInfo<PPC64TargetInfo>(triple) {
874 HasAlignMac68kSupport = true;
875 }
876};
877} // end anonymous namespace.
878
Reid Spencer5f016e22007-07-11 17:01:13 +0000879namespace {
Justin Holewinski285dc652011-04-20 19:34:15 +0000880 class PTXTargetInfo : public TargetInfo {
881 static const char * const GCCRegNames[];
882 static const Builtin::Info BuiltinInfo[];
Justin Holewinskid8e0fe62011-09-22 17:57:40 +0000883 std::vector<llvm::StringRef> AvailableFeatures;
Justin Holewinski285dc652011-04-20 19:34:15 +0000884 public:
885 PTXTargetInfo(const std::string& triple) : TargetInfo(triple) {
886 TLSSupported = false;
887 LongWidth = LongAlign = 64;
Justin Holewinskid8e0fe62011-09-22 17:57:40 +0000888 // Define available target features
889 // These must be defined in sorted order!
890 AvailableFeatures.push_back("compute10");
891 AvailableFeatures.push_back("compute11");
892 AvailableFeatures.push_back("compute12");
893 AvailableFeatures.push_back("compute13");
894 AvailableFeatures.push_back("compute20");
895 AvailableFeatures.push_back("double");
896 AvailableFeatures.push_back("no-fma");
897 AvailableFeatures.push_back("ptx20");
898 AvailableFeatures.push_back("ptx21");
899 AvailableFeatures.push_back("ptx22");
900 AvailableFeatures.push_back("ptx23");
901 AvailableFeatures.push_back("sm10");
902 AvailableFeatures.push_back("sm11");
903 AvailableFeatures.push_back("sm12");
904 AvailableFeatures.push_back("sm13");
905 AvailableFeatures.push_back("sm20");
906 AvailableFeatures.push_back("sm21");
907 AvailableFeatures.push_back("sm22");
908 AvailableFeatures.push_back("sm23");
Justin Holewinski285dc652011-04-20 19:34:15 +0000909 }
910 virtual void getTargetDefines(const LangOptions &Opts,
911 MacroBuilder &Builder) const {
912 Builder.defineMacro("__PTX__");
913 }
914 virtual void getTargetBuiltins(const Builtin::Info *&Records,
915 unsigned &NumRecords) const {
916 Records = BuiltinInfo;
917 NumRecords = clang::PTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
918 }
919
920 virtual void getGCCRegNames(const char * const *&Names,
921 unsigned &NumNames) const;
922 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
923 unsigned &NumAliases) const {
924 // No aliases.
925 Aliases = 0;
926 NumAliases = 0;
927 }
928 virtual bool validateAsmConstraint(const char *&Name,
929 TargetInfo::ConstraintInfo &info) const {
930 // FIXME: implement
931 return true;
932 }
933 virtual const char *getClobbers() const {
934 // FIXME: Is this really right?
935 return "";
936 }
937 virtual const char *getVAListDeclaration() const {
938 // FIXME: implement
939 return "typedef char* __builtin_va_list;";
940 }
Justin Holewinski808ef662011-09-15 12:13:38 +0000941
942 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
943 const std::string &Name,
944 bool Enabled) const;
Justin Holewinski285dc652011-04-20 19:34:15 +0000945 };
946
947 const Builtin::Info PTXTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +0000948#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Justin Holewinski285dc652011-04-20 19:34:15 +0000949#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +0000950 ALL_LANGUAGES },
Justin Holewinski285dc652011-04-20 19:34:15 +0000951#include "clang/Basic/BuiltinsPTX.def"
952 };
953
954 const char * const PTXTargetInfo::GCCRegNames[] = {
955 "r0"
956 };
957
958 void PTXTargetInfo::getGCCRegNames(const char * const *&Names,
959 unsigned &NumNames) const {
960 Names = GCCRegNames;
961 NumNames = llvm::array_lengthof(GCCRegNames);
962 }
963
Justin Holewinski808ef662011-09-15 12:13:38 +0000964 bool PTXTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
965 const std::string &Name,
966 bool Enabled) const {
Justin Holewinskid8e0fe62011-09-22 17:57:40 +0000967 if(std::binary_search(AvailableFeatures.begin(), AvailableFeatures.end(),
968 Name)) {
969 Features[Name] = Enabled;
970 return true;
Justin Holewinski808ef662011-09-15 12:13:38 +0000971 } else {
Justin Holewinskid8e0fe62011-09-22 17:57:40 +0000972 return false;
Justin Holewinski808ef662011-09-15 12:13:38 +0000973 }
Justin Holewinski808ef662011-09-15 12:13:38 +0000974 }
Justin Holewinski285dc652011-04-20 19:34:15 +0000975
976 class PTX32TargetInfo : public PTXTargetInfo {
977 public:
978 PTX32TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
979 PointerWidth = PointerAlign = 32;
980 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt;
981 DescriptionString
982 = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64";
983 }
984 };
985
986 class PTX64TargetInfo : public PTXTargetInfo {
987 public:
988 PTX64TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
989 PointerWidth = PointerAlign = 64;
990 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong;
991 DescriptionString
992 = "e-p:64:64-i64:64:64-f64:64:64-n1:8:16:32:64";
993 }
994 };
995}
996
997namespace {
Chris Lattner9cbeb632010-03-06 21:21:27 +0000998// MBlaze abstract base class
999class MBlazeTargetInfo : public TargetInfo {
1000 static const char * const GCCRegNames[];
1001 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1002
1003public:
1004 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) {
Wesley Pecka48fa4b2010-12-12 20:56:47 +00001005 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16";
Chris Lattner9cbeb632010-03-06 21:21:27 +00001006 }
1007
1008 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1009 unsigned &NumRecords) const {
1010 // FIXME: Implement.
1011 Records = 0;
1012 NumRecords = 0;
1013 }
1014
1015 virtual void getTargetDefines(const LangOptions &Opts,
1016 MacroBuilder &Builder) const;
1017
1018 virtual const char *getVAListDeclaration() const {
1019 return "typedef char* __builtin_va_list;";
1020 }
1021 virtual const char *getTargetPrefix() const {
1022 return "mblaze";
1023 }
1024 virtual void getGCCRegNames(const char * const *&Names,
1025 unsigned &NumNames) const;
1026 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1027 unsigned &NumAliases) const;
1028 virtual bool validateAsmConstraint(const char *&Name,
1029 TargetInfo::ConstraintInfo &Info) const {
1030 switch (*Name) {
1031 default: return false;
1032 case 'O': // Zero
1033 return true;
1034 case 'b': // Base register
1035 case 'f': // Floating point register
1036 Info.setAllowsRegister();
1037 return true;
1038 }
1039 }
1040 virtual const char *getClobbers() const {
1041 return "";
1042 }
1043};
1044
1045/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific
1046/// #defines that are not tied to a specific subtarget.
1047void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts,
1048 MacroBuilder &Builder) const {
1049 // Target identification.
1050 Builder.defineMacro("__microblaze__");
1051 Builder.defineMacro("_ARCH_MICROBLAZE");
1052 Builder.defineMacro("__MICROBLAZE__");
1053
1054 // Target properties.
1055 Builder.defineMacro("_BIG_ENDIAN");
1056 Builder.defineMacro("__BIG_ENDIAN__");
1057
1058 // Subtarget options.
1059 Builder.defineMacro("__REGISTER_PREFIX__", "");
1060}
1061
1062
1063const char * const MBlazeTargetInfo::GCCRegNames[] = {
1064 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1065 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1066 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1067 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
1068 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
1069 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
1070 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
1071 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
1072 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4",
1073 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp"
1074};
1075
1076void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names,
1077 unsigned &NumNames) const {
1078 Names = GCCRegNames;
1079 NumNames = llvm::array_lengthof(GCCRegNames);
1080}
1081
1082const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = {
1083 { {"f0"}, "r0" },
1084 { {"f1"}, "r1" },
1085 { {"f2"}, "r2" },
1086 { {"f3"}, "r3" },
1087 { {"f4"}, "r4" },
1088 { {"f5"}, "r5" },
1089 { {"f6"}, "r6" },
1090 { {"f7"}, "r7" },
1091 { {"f8"}, "r8" },
1092 { {"f9"}, "r9" },
1093 { {"f10"}, "r10" },
1094 { {"f11"}, "r11" },
1095 { {"f12"}, "r12" },
1096 { {"f13"}, "r13" },
1097 { {"f14"}, "r14" },
1098 { {"f15"}, "r15" },
1099 { {"f16"}, "r16" },
1100 { {"f17"}, "r17" },
1101 { {"f18"}, "r18" },
1102 { {"f19"}, "r19" },
1103 { {"f20"}, "r20" },
1104 { {"f21"}, "r21" },
1105 { {"f22"}, "r22" },
1106 { {"f23"}, "r23" },
1107 { {"f24"}, "r24" },
1108 { {"f25"}, "r25" },
1109 { {"f26"}, "r26" },
1110 { {"f27"}, "r27" },
1111 { {"f28"}, "r28" },
1112 { {"f29"}, "r29" },
1113 { {"f30"}, "r30" },
1114 { {"f31"}, "r31" },
1115};
1116
1117void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
1118 unsigned &NumAliases) const {
1119 Aliases = GCCRegAliases;
1120 NumAliases = llvm::array_lengthof(GCCRegAliases);
1121}
1122} // end anonymous namespace.
1123
1124namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001125// Namespace for x86 abstract base class
1126const Builtin::Info BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00001127#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00001128#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00001129 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +00001130#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +00001131};
Eli Friedman61538a72008-05-20 14:21:01 +00001132
Nuno Lopes2550d702009-12-23 17:49:57 +00001133static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +00001134 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
1135 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Eric Christopher7c9adf92011-07-07 22:55:26 +00001136 "argp", "flags", "fpcr", "fpsr", "dirflag", "frame",
Eli Friedman618234a2008-08-20 02:34:37 +00001137 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
1138 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
1139 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
Eric Christophercfd323d2011-06-21 00:05:20 +00001140 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
Eli Friedman618234a2008-08-20 02:34:37 +00001141};
1142
Eric Christophercfd323d2011-06-21 00:05:20 +00001143const TargetInfo::AddlRegName AddlRegNames[] = {
1144 { { "al", "ah", "eax", "rax" }, 0 },
1145 { { "bl", "bh", "ebx", "rbx" }, 3 },
1146 { { "cl", "ch", "ecx", "rcx" }, 2 },
1147 { { "dl", "dh", "edx", "rdx" }, 1 },
1148 { { "esi", "rsi" }, 4 },
1149 { { "edi", "rdi" }, 5 },
1150 { { "esp", "rsp" }, 7 },
1151 { { "ebp", "rbp" }, 6 },
Eli Friedman618234a2008-08-20 02:34:37 +00001152};
1153
1154// X86 target abstract base class; x86-32 and x86-64 are very close, so
1155// most of the implementation can be shared.
1156class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +00001157 enum X86SSEEnum {
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001158 NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
Chris Lattner84f0ea82009-03-02 22:40:39 +00001159 } SSELevel;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001160 enum MMX3DNowEnum {
1161 NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon
1162 } MMX3DNowLevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001163
Eric Christophereea12d12010-04-02 23:50:19 +00001164 bool HasAES;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001165 bool HasAVX;
1166
Eli Friedman618234a2008-08-20 02:34:37 +00001167public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001168 X86TargetInfo(const std::string& triple)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001169 : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001170 HasAES(false), HasAVX(false) {
Eli Friedman618234a2008-08-20 02:34:37 +00001171 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +00001172 }
1173 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1174 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001175 Records = BuiltinInfo;
1176 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +00001177 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001178 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +00001179 unsigned &NumNames) const {
1180 Names = GCCRegNames;
1181 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +00001182 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001183 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +00001184 unsigned &NumAliases) const {
Eric Christophercfd323d2011-06-21 00:05:20 +00001185 Aliases = 0;
1186 NumAliases = 0;
1187 }
1188 virtual void getGCCAddlRegNames(const AddlRegName *&Names,
1189 unsigned &NumNames) const {
1190 Names = AddlRegNames;
1191 NumNames = llvm::array_lengthof(AddlRegNames);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001192 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001193 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +00001194 TargetInfo::ConstraintInfo &info) const;
Stuart Hastings002333f2011-06-07 23:45:05 +00001195 virtual std::string convertConstraint(const char *&Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +00001196 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +00001197 return "~{dirflag},~{fpsr},~{flags}";
1198 }
Chris Lattner33328642009-03-20 15:52:06 +00001199 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001200 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001201 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1202 const std::string &Name,
1203 bool Enabled) const;
Mike Stump1eb44332009-09-09 15:08:12 +00001204 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001205 llvm::StringMap<bool> &Features) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001206 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001207 virtual const char* getABI() const {
1208 return MMX3DNowLevel == NoMMX3DNow ? "no-mmx" : "";
1209 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001210};
Chris Lattner3daed522009-03-02 22:20:04 +00001211
Mike Stump1eb44332009-09-09 15:08:12 +00001212void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001213 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001214 // FIXME: This should not be here.
1215 Features["3dnow"] = false;
1216 Features["3dnowa"] = false;
1217 Features["mmx"] = false;
1218 Features["sse"] = false;
1219 Features["sse2"] = false;
1220 Features["sse3"] = false;
1221 Features["ssse3"] = false;
1222 Features["sse41"] = false;
1223 Features["sse42"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001224 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001225 Features["avx"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001226
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001227 // LLVM does not currently recognize this.
1228 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001229
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001230 // FIXME: This *really* should not be here.
1231
1232 // X86_64 always has SSE2.
1233 if (PointerWidth == 64)
1234 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
1235
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001236 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
1237 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
1238 ;
1239 else if (CPU == "pentium-mmx" || CPU == "pentium2")
1240 setFeatureEnabled(Features, "mmx", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001241 else if (CPU == "pentium3") {
1242 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001243 setFeatureEnabled(Features, "sse", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001244 } else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") {
1245 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001246 setFeatureEnabled(Features, "sse2", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001247 } else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") {
1248 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001249 setFeatureEnabled(Features, "sse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001250 } else if (CPU == "core2") {
1251 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001252 setFeatureEnabled(Features, "ssse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001253 } else if (CPU == "penryn") {
1254 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001255 setFeatureEnabled(Features, "sse4", true);
1256 Features["sse42"] = false;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001257 } else if (CPU == "atom") {
1258 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001259 setFeatureEnabled(Features, "sse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001260 } else if (CPU == "corei7") {
1261 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001262 setFeatureEnabled(Features, "sse4", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001263 setFeatureEnabled(Features, "aes", true);
Benjamin Kramerb65b6722011-05-20 15:11:23 +00001264 } else if (CPU == "corei7-avx") {
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001265 setFeatureEnabled(Features, "mmx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001266 setFeatureEnabled(Features, "sse4", true);
1267 setFeatureEnabled(Features, "aes", true);
Bruno Cardoso Lopese02d3912011-07-11 23:33:46 +00001268 //setFeatureEnabled(Features, "avx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001269 } else if (CPU == "k6" || CPU == "winchip-c6")
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001270 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +00001271 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001272 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001273 setFeatureEnabled(Features, "3dnow", true);
1274 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
1275 setFeatureEnabled(Features, "sse", true);
1276 setFeatureEnabled(Features, "3dnowa", true);
1277 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
1278 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +00001279 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001280 setFeatureEnabled(Features, "3dnowa", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00001281 } else if (CPU == "k8-sse3") {
1282 setFeatureEnabled(Features, "sse3", true);
1283 setFeatureEnabled(Features, "3dnowa", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001284 } else if (CPU == "c3-2") {
1285 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001286 setFeatureEnabled(Features, "sse", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001287 }
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001288}
1289
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001290bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +00001291 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001292 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001293 // FIXME: This *really* should not be here. We need some way of translating
1294 // options into llvm subtarget features.
1295 if (!Features.count(Name) &&
1296 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001297 return false;
1298
1299 if (Enabled) {
1300 if (Name == "mmx")
1301 Features["mmx"] = true;
1302 else if (Name == "sse")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001303 Features["sse"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001304 else if (Name == "sse2")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001305 Features["sse"] = Features["sse2"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001306 else if (Name == "sse3")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001307 Features["sse"] = Features["sse2"] = Features["sse3"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001308 else if (Name == "ssse3")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001309 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001310 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001311 else if (Name == "sse4" || Name == "sse4.2")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001312 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001313 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001314 else if (Name == "sse4.1")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001315 Features["sse"] = Features["sse2"] = Features["sse3"] =
Eric Christopherd39ebe22010-03-04 02:26:37 +00001316 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001317 else if (Name == "3dnow")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001318 Features["mmx"] = Features["3dnow"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001319 else if (Name == "3dnowa")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001320 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001321 else if (Name == "aes")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001322 Features["aes"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001323 else if (Name == "avx")
Bruno Cardoso Lopes292772c2011-08-18 00:07:03 +00001324 Features["avx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1325 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001326 } else {
1327 if (Name == "mmx")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001328 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001329 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001330 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001331 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001332 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001333 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001334 Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001335 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001336 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001337 Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001338 else if (Name == "ssse3")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001339 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
Michael J. Spencerb24bac92011-04-17 19:22:03 +00001340 else if (Name == "sse4" || Name == "sse4.1")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001341 Features["sse41"] = Features["sse42"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001342 else if (Name == "sse4.2")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001343 Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001344 else if (Name == "3dnow")
1345 Features["3dnow"] = Features["3dnowa"] = false;
1346 else if (Name == "3dnowa")
1347 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001348 else if (Name == "aes")
1349 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001350 else if (Name == "avx")
1351 Features["avx"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001352 }
1353
1354 return true;
1355}
1356
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001357/// HandleTargetOptions - Perform initialization based on the user
1358/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001359void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001360 // Remember the maximum enabled sselevel.
1361 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1362 // Ignore disabled features.
1363 if (Features[i][0] == '-')
1364 continue;
1365
Eric Christophereea12d12010-04-02 23:50:19 +00001366 if (Features[i].substr(1) == "aes") {
1367 HasAES = true;
1368 continue;
1369 }
1370
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001371 // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
1372 // For now let it be enabled together with other SSE levels.
1373 if (Features[i].substr(1) == "avx") {
1374 HasAVX = true;
1375 continue;
1376 }
1377
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001378 assert(Features[i][0] == '+' && "Invalid target feature!");
1379 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
1380 .Case("sse42", SSE42)
1381 .Case("sse41", SSE41)
1382 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001383 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001384 .Case("sse2", SSE2)
1385 .Case("sse", SSE1)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001386 .Default(NoSSE);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001387 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001388
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001389 MMX3DNowEnum ThreeDNowLevel =
1390 llvm::StringSwitch<MMX3DNowEnum>(Features[i].substr(1))
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001391 .Case("3dnowa", AMD3DNowAthlon)
1392 .Case("3dnow", AMD3DNow)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001393 .Case("mmx", MMX)
1394 .Default(NoMMX3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001395
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001396 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001397 }
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001398
1399 // Don't tell the backend if we're turning off mmx; it will end up disabling
1400 // SSE, which we don't want.
1401 std::vector<std::string>::iterator it;
1402 it = std::find(Features.begin(), Features.end(), "-mmx");
1403 if (it != Features.end())
1404 Features.erase(it);
Chris Lattner3daed522009-03-02 22:20:04 +00001405}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001406
1407/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
1408/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001409void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001410 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001411 // Target identification.
1412 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001413 Builder.defineMacro("_LP64");
1414 Builder.defineMacro("__LP64__");
1415 Builder.defineMacro("__amd64__");
1416 Builder.defineMacro("__amd64");
1417 Builder.defineMacro("__x86_64");
1418 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001419 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001420 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001421 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001422
Eric Christophereea12d12010-04-02 23:50:19 +00001423 if (HasAES)
1424 Builder.defineMacro("__AES__");
1425
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001426 if (HasAVX)
1427 Builder.defineMacro("__AVX__");
1428
Chris Lattnerc0f59212009-03-02 22:27:17 +00001429 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001430 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001431
Chris Lattnerc0f59212009-03-02 22:27:17 +00001432 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +00001433 Builder.defineMacro("__nocona");
1434 Builder.defineMacro("__nocona__");
1435 Builder.defineMacro("__tune_nocona__");
1436 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001437
Chris Lattner54175442009-04-19 17:32:33 +00001438 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
1439 // functions in glibc header files that use FP Stack inline asm which the
1440 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00001441 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001442
Chris Lattner84f0ea82009-03-02 22:40:39 +00001443 // Each case falls through to the previous one here.
1444 switch (SSELevel) {
1445 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00001446 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001447 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00001448 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001449 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001450 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001451 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001452 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001453 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00001454 Builder.defineMacro("__SSE2__");
1455 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001456 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00001457 Builder.defineMacro("__SSE__");
1458 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001459 case NoSSE:
Chris Lattner84f0ea82009-03-02 22:40:39 +00001460 break;
1461 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001462
Francois Pichet62ec1f22011-09-17 17:15:52 +00001463 if (Opts.MicrosoftExt && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001464 switch (SSELevel) {
Michael J. Spencera764e832010-10-21 08:22:51 +00001465 case SSE42:
1466 case SSE41:
1467 case SSSE3:
1468 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001469 case SSE2:
Chris Lattner5f9e2722011-07-23 10:55:15 +00001470 Builder.defineMacro("_M_IX86_FP", Twine(2));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001471 break;
1472 case SSE1:
Chris Lattner5f9e2722011-07-23 10:55:15 +00001473 Builder.defineMacro("_M_IX86_FP", Twine(1));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001474 break;
1475 default:
Chris Lattner5f9e2722011-07-23 10:55:15 +00001476 Builder.defineMacro("_M_IX86_FP", Twine(0));
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001477 }
1478 }
1479
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001480 // Each case falls through to the previous one here.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001481 switch (MMX3DNowLevel) {
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001482 case AMD3DNowAthlon:
1483 Builder.defineMacro("__3dNOW_A__");
1484 case AMD3DNow:
1485 Builder.defineMacro("__3dNOW__");
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001486 case MMX:
1487 Builder.defineMacro("__MMX__");
1488 case NoMMX3DNow:
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001489 break;
1490 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001491}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001492
1493
Eli Friedman618234a2008-08-20 02:34:37 +00001494bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001495X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001496 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001497 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00001498 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00001499 case 'Y': // first letter of a pair:
1500 switch (*(Name+1)) {
1501 default: return false;
1502 case '0': // First SSE register.
1503 case 't': // Any SSE register, when SSE2 is enabled.
1504 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1505 case 'm': // any MMX register, when inter-unit moves enabled.
1506 break; // falls through to setAllowsRegister.
1507 }
Eli Friedman618234a2008-08-20 02:34:37 +00001508 case 'a': // eax.
1509 case 'b': // ebx.
1510 case 'c': // ecx.
1511 case 'd': // edx.
1512 case 'S': // esi.
1513 case 'D': // edi.
1514 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00001515 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00001516 case 't': // top of floating point stack.
1517 case 'u': // second from top of floating point stack.
1518 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00001519 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00001520 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00001521 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00001522 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1523 case 'l': // "Index" registers: any general register that can be used as an
1524 // index in a base+index memory access.
1525 Info.setAllowsRegister();
1526 return true;
1527 case 'C': // SSE floating point constant.
1528 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001529 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001530 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001531 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001532 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00001533 return true;
1534 }
Dale Johannesen545be512010-08-24 22:33:12 +00001535 return false;
Eli Friedman618234a2008-08-20 02:34:37 +00001536}
1537
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001538
Eli Friedman618234a2008-08-20 02:34:37 +00001539std::string
Stuart Hastings002333f2011-06-07 23:45:05 +00001540X86TargetInfo::convertConstraint(const char *&Constraint) const {
1541 switch (*Constraint) {
Eli Friedman618234a2008-08-20 02:34:37 +00001542 case 'a': return std::string("{ax}");
1543 case 'b': return std::string("{bx}");
1544 case 'c': return std::string("{cx}");
1545 case 'd': return std::string("{dx}");
1546 case 'S': return std::string("{si}");
1547 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00001548 case 'p': // address
1549 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00001550 case 't': // top of floating point stack.
1551 return std::string("{st}");
1552 case 'u': // second from top of floating point stack.
1553 return std::string("{st(1)}"); // second from top of floating point stack.
1554 default:
Stuart Hastings002333f2011-06-07 23:45:05 +00001555 return std::string(1, *Constraint);
Eli Friedman618234a2008-08-20 02:34:37 +00001556 }
1557}
Eli Friedman618234a2008-08-20 02:34:37 +00001558} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00001559
1560namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001561// X86-32 generic target
1562class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001563public:
Eli Friedman618234a2008-08-20 02:34:37 +00001564 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
1565 DoubleAlign = LongLongAlign = 32;
1566 LongDoubleWidth = 96;
1567 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001568 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1569 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001570 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +00001571 SizeType = UnsignedInt;
1572 PtrDiffType = SignedInt;
1573 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001574 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001575
1576 // Use fpret for all types.
1577 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
1578 (1 << TargetInfo::Double) |
1579 (1 << TargetInfo::LongDouble));
Eli Friedman618234a2008-08-20 02:34:37 +00001580 }
1581 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001582 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00001583 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001584
Chris Lattner21fb98e2009-09-23 06:06:36 +00001585 int getEHDataRegisterNumber(unsigned RegNo) const {
1586 if (RegNo == 0) return 0;
1587 if (RegNo == 1) return 2;
1588 return -1;
1589 }
Eli Friedman618234a2008-08-20 02:34:37 +00001590};
1591} // end anonymous namespace
1592
1593namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00001594class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
1595public:
1596 OpenBSDI386TargetInfo(const std::string& triple) :
1597 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
1598 SizeType = UnsignedLong;
1599 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00001600 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00001601 }
1602};
1603} // end anonymous namespace
1604
1605namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001606class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00001607public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00001608 DarwinI386TargetInfo(const std::string& triple) :
1609 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00001610 LongDoubleWidth = 128;
1611 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00001612 SizeType = UnsignedLong;
1613 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001614 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1615 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001616 "a0:0:64-f80:128:128-n8:16:32";
Daniel Dunbar613fd672010-05-27 00:35:16 +00001617 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00001618 }
1619
Eli Friedman618234a2008-08-20 02:34:37 +00001620};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001621} // end anonymous namespace
1622
1623namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00001624// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001625class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00001626public:
1627 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001628 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001629 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00001630 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00001631 DoubleAlign = LongLongAlign = 64;
1632 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 +00001633 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
1634 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +00001635 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001636 virtual void getTargetDefines(const LangOptions &Opts,
1637 MacroBuilder &Builder) const {
1638 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
1639 }
1640};
1641} // end anonymous namespace
1642
1643namespace {
1644
1645// x86-32 Windows Visual Studio target
1646class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1647public:
1648 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1649 : WindowsX86_32TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001650 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00001651 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
1652 }
1653 virtual void getTargetDefines(const LangOptions &Opts,
1654 MacroBuilder &Builder) const {
1655 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1656 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
1657 // The value of the following reflects processor type.
1658 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1659 // We lost the original triple, so we use the default.
1660 Builder.defineMacro("_M_IX86", "600");
1661 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001662};
1663} // end anonymous namespace
1664
1665namespace {
1666// x86-32 MinGW target
1667class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1668public:
1669 MinGWX86_32TargetInfo(const std::string& triple)
1670 : WindowsX86_32TargetInfo(triple) {
1671 }
1672 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001673 MacroBuilder &Builder) const {
1674 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001675 DefineStd(Builder, "WIN32", Opts);
1676 DefineStd(Builder, "WINNT", Opts);
1677 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00001678 Builder.defineMacro("__MSVCRT__");
1679 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001680
1681 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1682 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00001683 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001684 // Provide "as-is" __declspec.
1685 Builder.defineMacro("__declspec", "__declspec");
1686 else
1687 // Provide alias of __attribute__ like mingw32-gcc.
1688 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001689 }
1690};
1691} // end anonymous namespace
1692
1693namespace {
1694// x86-32 Cygwin target
1695class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1696public:
1697 CygwinX86_32TargetInfo(const std::string& triple)
1698 : X86_32TargetInfo(triple) {
1699 TLSSupported = false;
1700 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001701 DoubleAlign = LongLongAlign = 64;
1702 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1703 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001704 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001705 }
1706 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001707 MacroBuilder &Builder) const {
1708 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1709 Builder.defineMacro("__CYGWIN__");
1710 Builder.defineMacro("__CYGWIN32__");
1711 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00001712 if (Opts.CPlusPlus)
1713 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00001714 }
Eli Friedman29a30502008-08-21 01:40:19 +00001715};
1716} // end anonymous namespace
1717
1718namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00001719// x86-32 Haiku target
1720class HaikuX86_32TargetInfo : public X86_32TargetInfo {
1721public:
1722 HaikuX86_32TargetInfo(const std::string& triple)
1723 : X86_32TargetInfo(triple) {
1724 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00001725 IntPtrType = SignedLong;
1726 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00001727 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00001728 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00001729 virtual void getTargetDefines(const LangOptions &Opts,
1730 MacroBuilder &Builder) const {
1731 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1732 Builder.defineMacro("__INTEL__");
1733 Builder.defineMacro("__HAIKU__");
1734 }
1735};
1736} // end anonymous namespace
1737
Douglas Gregordca52262011-07-01 22:41:14 +00001738// RTEMS Target
1739template<typename Target>
1740class RTEMSTargetInfo : public OSTargetInfo<Target> {
1741protected:
1742 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
1743 MacroBuilder &Builder) const {
1744 // RTEMS defines; list based off of gcc output
1745
Douglas Gregordca52262011-07-01 22:41:14 +00001746 Builder.defineMacro("__rtems__");
1747 Builder.defineMacro("__ELF__");
1748 }
1749public:
1750 RTEMSTargetInfo(const std::string &triple)
1751 : OSTargetInfo<Target>(triple) {
1752 this->UserLabelPrefix = "";
1753
1754 llvm::Triple Triple(triple);
1755 switch (Triple.getArch()) {
1756 default:
1757 case llvm::Triple::x86:
1758 // this->MCountName = ".mcount";
1759 break;
1760 case llvm::Triple::mips:
1761 case llvm::Triple::mipsel:
1762 case llvm::Triple::ppc:
1763 case llvm::Triple::ppc64:
1764 // this->MCountName = "_mcount";
1765 break;
1766 case llvm::Triple::arm:
1767 // this->MCountName = "__mcount";
1768 break;
1769 }
1770
1771 }
1772};
1773
1774namespace {
1775// x86-32 RTEMS target
1776class RTEMSX86_32TargetInfo : public X86_32TargetInfo {
1777public:
1778 RTEMSX86_32TargetInfo(const std::string& triple)
1779 : X86_32TargetInfo(triple) {
1780 SizeType = UnsignedLong;
1781 IntPtrType = SignedLong;
1782 PtrDiffType = SignedLong;
1783 this->UserLabelPrefix = "";
1784 }
1785 virtual void getTargetDefines(const LangOptions &Opts,
1786 MacroBuilder &Builder) const {
1787 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1788 Builder.defineMacro("__INTEL__");
1789 Builder.defineMacro("__rtems__");
1790 }
1791};
1792} // end anonymous namespace
1793
Chris Lattner86ed3a32010-04-11 19:29:39 +00001794namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001795// x86-64 generic target
1796class X86_64TargetInfo : public X86TargetInfo {
1797public:
Chris Lattner33328642009-03-20 15:52:06 +00001798 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001799 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001800 LongDoubleWidth = 128;
1801 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00001802 LargeArrayMinWidth = 128;
1803 LargeArrayAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001804 IntMaxType = SignedLong;
1805 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001806 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001807 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001808
Eli Friedmaned855cb2008-08-21 00:13:15 +00001809 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1810 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001811 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001812
1813 // Use fpret only for long double.
1814 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Reid Spencer5f016e22007-07-11 17:01:13 +00001815 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001816 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001817 return "typedef struct __va_list_tag {"
1818 " unsigned gp_offset;"
1819 " unsigned fp_offset;"
1820 " void* overflow_arg_area;"
1821 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00001822 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00001823 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001824 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001825
Chris Lattner21fb98e2009-09-23 06:06:36 +00001826 int getEHDataRegisterNumber(unsigned RegNo) const {
1827 if (RegNo == 0) return 0;
1828 if (RegNo == 1) return 1;
1829 return -1;
1830 }
Eli Friedman618234a2008-08-20 02:34:37 +00001831};
1832} // end anonymous namespace
1833
1834namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001835// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001836class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001837public:
1838 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001839 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001840 TLSSupported = false;
1841 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001842 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00001843 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00001844 IntMaxType = SignedLongLong;
1845 UIntMaxType = UnsignedLongLong;
1846 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00001847 SizeType = UnsignedLongLong;
1848 PtrDiffType = SignedLongLong;
1849 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00001850 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001851 }
1852 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001853 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001854 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001855 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00001856 }
NAKAMURA Takumi79521992011-01-17 22:56:23 +00001857 virtual const char *getVAListDeclaration() const {
1858 return "typedef char* __builtin_va_list;";
1859 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001860};
1861} // end anonymous namespace
1862
1863namespace {
1864// x86-64 Windows Visual Studio target
1865class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1866public:
1867 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1868 : WindowsX86_64TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001869 LongDoubleWidth = LongDoubleAlign = 64;
1870 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00001871 }
1872 virtual void getTargetDefines(const LangOptions &Opts,
1873 MacroBuilder &Builder) const {
1874 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1875 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00001876 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001877 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001878 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001879};
1880} // end anonymous namespace
1881
1882namespace {
1883// x86-64 MinGW target
1884class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1885public:
1886 MinGWX86_64TargetInfo(const std::string& triple)
1887 : WindowsX86_64TargetInfo(triple) {
1888 }
1889 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001890 MacroBuilder &Builder) const {
1891 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001892 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00001893 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00001894 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00001895 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001896
1897 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1898 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
Francois Pichet62ec1f22011-09-17 17:15:52 +00001899 if (Opts.MicrosoftExt)
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001900 // Provide "as-is" __declspec.
1901 Builder.defineMacro("__declspec", "__declspec");
1902 else
1903 // Provide alias of __attribute__ like mingw32-gcc.
1904 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001905 }
1906};
1907} // end anonymous namespace
1908
1909namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001910class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1911public:
Mike Stump1eb44332009-09-09 15:08:12 +00001912 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001913 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1914 Int64Type = SignedLongLong;
1915 }
1916};
1917} // end anonymous namespace
1918
1919namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001920class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1921public:
Mike Stump1eb44332009-09-09 15:08:12 +00001922 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001923 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1924 IntMaxType = SignedLongLong;
1925 UIntMaxType = UnsignedLongLong;
1926 Int64Type = SignedLongLong;
1927 }
1928};
1929} // end anonymous namespace
1930
1931namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001932class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001933 // Possible FPU choices.
1934 enum FPUMode {
1935 NoFPU,
1936 VFP2FPU,
1937 VFP3FPU,
1938 NeonFPU
1939 };
1940
1941 static bool FPUModeIsVFP(FPUMode Mode) {
1942 return Mode >= VFP2FPU && Mode <= NeonFPU;
1943 }
1944
1945 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1946 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001947
Daniel Dunbareac7c532009-12-18 18:42:37 +00001948 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001949
1950 unsigned FPU : 3;
1951
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001952 unsigned IsThumb : 1;
1953
1954 // Initialized via features.
1955 unsigned SoftFloat : 1;
1956 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001957
Chris Lattner2752c012010-03-03 19:03:45 +00001958 static const Builtin::Info BuiltinInfo[];
1959
Chris Lattner393ff042008-04-21 18:56:49 +00001960public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001961 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001962 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001963 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001964 SizeType = UnsignedInt;
1965 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001966
Chris Lattner9bffb072010-04-23 16:29:58 +00001967 // {} in inline assembly are neon specifiers, not assembly variant
1968 // specifiers.
1969 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00001970
Daniel Dunbareac7c532009-12-18 18:42:37 +00001971 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001972 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001973 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001974 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1975 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001976 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1977 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001978 "v64:64:64-v128:64:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001979 } else {
1980 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1981 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001982 "v64:64:64-v128:64:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001983 }
John McCallee79a4c2010-08-21 22:46:04 +00001984
1985 // ARM targets default to using the ARM C++ ABI.
1986 CXXABI = CXXABI_ARM;
Eli Friedman61538a72008-05-20 14:21:01 +00001987 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001988 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001989 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001990 ABI = Name;
1991
Daniel Dunbara2a41612009-09-14 00:02:24 +00001992 // The defaults (above) are for AAPCS, check if we need to change them.
1993 //
1994 // FIXME: We need support for -meabi... we could just mangle it into the
1995 // name.
1996 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001997 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001998 SizeType = UnsignedLong;
1999
Daniel Dunbar684de632010-04-22 16:14:54 +00002000 // Do not respect the alignment of bit-field types when laying out
2001 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
2002 UseBitFieldTypeAlignment = false;
2003
Chad Rosier61a62212011-08-04 01:21:14 +00002004 /// Do force alignment of members that follow zero length bitfields. If
2005 /// the alignment of the zero-length bitfield is greater than the member
2006 /// that follows it, `bar', `bar' will be aligned as the type of the
2007 /// zero length bitfield.
2008 UseZeroLengthBitfieldAlignment = true;
2009
2010 /// gcc forces the alignment to 4 bytes, regardless of the type of the
Chad Rosier6e43f3f2011-08-04 17:52:43 +00002011 /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in
2012 /// gcc.
Chad Rosier61a62212011-08-04 01:21:14 +00002013 ZeroLengthBitfieldBoundary = 32;
2014
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002015 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00002016 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
2017 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002018 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 +00002019 "i64:32:64-f32:32:32-f64:32:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00002020 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002021 } else {
2022 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 +00002023 "i64:32:64-f32:32:32-f64:32:64-"
2024 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00002025 }
2026
Chad Rosier9f1210c2011-07-26 07:03:04 +00002027 // FIXME: Override "preferred align" for double and long long.
Daniel Dunbara2a41612009-09-14 00:02:24 +00002028 } else if (Name == "aapcs") {
2029 // FIXME: Enumerated types are variable width in straight AAPCS.
2030 } else if (Name == "aapcs-linux") {
Chad Rosier9f1210c2011-07-26 07:03:04 +00002031 ;
Daniel Dunbara2a41612009-09-14 00:02:24 +00002032 } else
2033 return false;
2034
2035 return true;
2036 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002037
Daniel Dunbara91320b2009-12-21 23:28:17 +00002038 void getDefaultFeatures(const std::string &CPU,
2039 llvm::StringMap<bool> &Features) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002040 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
2041 Features["vfp2"] = true;
2042 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
2043 Features["neon"] = true;
2044 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00002045
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002046 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2047 const std::string &Name,
2048 bool Enabled) const {
Evan Chengf972b262011-07-08 06:40:11 +00002049 if (Name == "soft-float" || Name == "soft-float-abi" ||
2050 Name == "vfp2" || Name == "vfp3" || Name == "neon") {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002051 Features[Name] = Enabled;
2052 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002053 return false;
2054
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002055 return true;
2056 }
2057
2058 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002059 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002060 SoftFloat = SoftFloatABI = false;
2061 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
2062 if (Features[i] == "+soft-float")
2063 SoftFloat = true;
2064 else if (Features[i] == "+soft-float-abi")
2065 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00002066 else if (Features[i] == "+vfp2")
2067 FPU = VFP2FPU;
2068 else if (Features[i] == "+vfp3")
2069 FPU = VFP3FPU;
2070 else if (Features[i] == "+neon")
2071 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002072 }
2073
2074 // Remove front-end specific options which the backend handles differently.
2075 std::vector<std::string>::iterator it;
2076 it = std::find(Features.begin(), Features.end(), "+soft-float");
2077 if (it != Features.end())
2078 Features.erase(it);
2079 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
2080 if (it != Features.end())
2081 Features.erase(it);
2082 }
2083
Chris Lattner5f9e2722011-07-23 10:55:15 +00002084 static const char *getCPUDefineSuffix(StringRef Name) {
Daniel Dunbareac7c532009-12-18 18:42:37 +00002085 return llvm::StringSwitch<const char*>(Name)
2086 .Cases("arm8", "arm810", "4")
2087 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
2088 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
2089 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
2090 .Case("ep9312", "4T")
2091 .Cases("arm10tdmi", "arm1020t", "5T")
2092 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
2093 .Case("arm926ej-s", "5TEJ")
2094 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
2095 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002096 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002097 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002098 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002099 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
2100 .Cases("cortex-a8", "cortex-a9", "7A")
Bob Wilson06f45632011-01-06 16:57:20 +00002101 .Case("cortex-m3", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00002102 .Case("cortex-m0", "6M")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002103 .Default(0);
2104 }
2105 virtual bool setCPU(const std::string &Name) {
2106 if (!getCPUDefineSuffix(Name))
2107 return false;
2108
2109 CPU = Name;
2110 return true;
2111 }
Chris Lattner33328642009-03-20 15:52:06 +00002112 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002113 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00002114 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00002115 Builder.defineMacro("__arm");
2116 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002117
Chris Lattnerc0f59212009-03-02 22:27:17 +00002118 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00002119 Builder.defineMacro("__ARMEL__");
2120 Builder.defineMacro("__LITTLE_ENDIAN__");
2121 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002122
Chris Lattner5f9e2722011-07-23 10:55:15 +00002123 StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00002124 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002125
Mike Stump437bb4b2009-04-08 02:07:04 +00002126 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002127
Daniel Dunbareac7c532009-12-18 18:42:37 +00002128 // FIXME: It's more complicated than this and we don't really support
2129 // interworking.
2130 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00002131 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002132
Daniel Dunbareac7c532009-12-18 18:42:37 +00002133 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00002134 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002135
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002136 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00002137 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002138
2139 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00002140 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002141
Bob Wilson84f95cf2011-05-13 18:56:03 +00002142 bool IsARMv7 = CPUArch.startswith("7");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002143 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00002144 Builder.defineMacro("__THUMBEL__");
2145 Builder.defineMacro("__thumb__");
Bob Wilson84f95cf2011-05-13 18:56:03 +00002146 if (CPUArch == "6T2" || IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002147 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002148 }
2149
2150 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00002151 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002152
2153 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00002154 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002155
2156 // This only gets set when Neon instructions are actually available, unlike
2157 // the VFP define, hence the soft float and arch check. This is subtly
2158 // different from gcc, we follow the intent which was that it should be set
2159 // when Neon instructions are actually available.
Bob Wilson84f95cf2011-05-13 18:56:03 +00002160 if (FPU == NeonFPU && !SoftFloat && IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002161 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00002162 }
2163 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2164 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00002165 Records = BuiltinInfo;
2166 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00002167 }
2168 virtual const char *getVAListDeclaration() const {
John McCall0e9972c2011-05-09 02:19:37 +00002169 return "typedef void* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00002170 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002171 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002172 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002173 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002174 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002175 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00002176 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002177 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002178 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00002179 default:
Nate Begemanad487f42008-04-22 05:03:19 +00002180 case 'l': // r0-r7
2181 case 'h': // r8-r15
2182 case 'w': // VFP Floating point register single precision
2183 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00002184 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00002185 return true;
Eric Christopher895d4222011-07-29 21:20:35 +00002186 case 'Q': // A memory address that is a single base register.
2187 Info.setAllowsMemory();
2188 return true;
Stuart Hastings002333f2011-06-07 23:45:05 +00002189 case 'U': // a memory reference...
2190 switch (Name[1]) {
2191 case 'q': // ...ARMV4 ldrsb
2192 case 'v': // ...VFP load/store (reg+constant offset)
2193 case 'y': // ...iWMMXt load/store
Eric Christopherdda231a2011-06-17 01:40:49 +00002194 case 't': // address valid for load/store opaque types wider
2195 // than 128-bits
2196 case 'n': // valid address for Neon doubleword vector load/store
2197 case 'm': // valid address for Neon element and structure load/store
2198 case 's': // valid address for non-offset loads/stores of quad-word
2199 // values in four ARM registers
Stuart Hastings002333f2011-06-07 23:45:05 +00002200 Info.setAllowsMemory();
2201 Name++;
2202 return true;
2203 }
Nate Begemanad487f42008-04-22 05:03:19 +00002204 }
Chris Lattner393ff042008-04-21 18:56:49 +00002205 return false;
2206 }
Evan Cheng8bfa2572011-06-16 19:13:15 +00002207 virtual std::string convertConstraint(const char *&Constraint) const {
Stuart Hastings002333f2011-06-07 23:45:05 +00002208 std::string R;
2209 switch (*Constraint) {
2210 case 'U': // Two-character constraint; add "^" hint for later parsing.
Stuart Hastings6ce33d62011-06-08 16:06:31 +00002211 R = std::string("^") + std::string(Constraint, 2);
Stuart Hastings002333f2011-06-07 23:45:05 +00002212 Constraint++;
2213 break;
Eric Christopher283f4472011-06-17 00:40:18 +00002214 case 'p': // 'p' should be translated to 'r' by default.
2215 R = std::string("r");
2216 break;
Stuart Hastings002333f2011-06-07 23:45:05 +00002217 default:
2218 return std::string(1, *Constraint);
2219 }
2220 return R;
2221 }
Chris Lattner393ff042008-04-21 18:56:49 +00002222 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002223 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00002224 return "";
2225 }
2226};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002227
2228const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002229 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002230 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002231 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
2232
2233 // Float registers
2234 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
2235 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
2236 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002237 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002238
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002239 // Double registers
2240 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
2241 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00002242 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
2243 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002244
2245 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00002246 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
2247 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002248};
2249
2250void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00002251 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002252 Names = GCCRegNames;
2253 NumNames = llvm::array_lengthof(GCCRegNames);
2254}
2255
2256const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002257 { { "a1" }, "r0" },
2258 { { "a2" }, "r1" },
2259 { { "a3" }, "r2" },
2260 { { "a4" }, "r3" },
2261 { { "v1" }, "r4" },
2262 { { "v2" }, "r5" },
2263 { { "v3" }, "r6" },
2264 { { "v4" }, "r7" },
2265 { { "v5" }, "r8" },
2266 { { "v6", "rfp" }, "r9" },
2267 { { "sl" }, "r10" },
2268 { { "fp" }, "r11" },
2269 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00002270 { { "r13" }, "sp" },
2271 { { "r14" }, "lr" },
2272 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002273 // The S, D and Q registers overlap, but aren't really aliases; we
2274 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002275};
2276
2277void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2278 unsigned &NumAliases) const {
2279 Aliases = GCCRegAliases;
2280 NumAliases = llvm::array_lengthof(GCCRegAliases);
2281}
Chris Lattner2752c012010-03-03 19:03:45 +00002282
2283const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00002284#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00002285#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00002286 ALL_LANGUAGES },
Chris Lattner2752c012010-03-03 19:03:45 +00002287#include "clang/Basic/BuiltinsARM.def"
2288};
Chris Lattner393ff042008-04-21 18:56:49 +00002289} // end anonymous namespace.
2290
Eli Friedmana9f54962008-08-20 07:44:10 +00002291
2292namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00002293class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002294 public DarwinTargetInfo<ARMTargetInfo> {
2295protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002296 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00002297 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00002298 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00002299 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002300
Torok Edwin5f6c1942009-06-30 17:10:35 +00002301public:
Mike Stump1eb44332009-09-09 15:08:12 +00002302 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00002303 : DarwinTargetInfo<ARMTargetInfo>(triple) {
2304 HasAlignMac68kSupport = true;
2305 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002306};
2307} // end anonymous namespace.
2308
Reid Spencer5f016e22007-07-11 17:01:13 +00002309namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00002310class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00002311 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2312 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002313 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00002314public:
Eli Friedman01b86682008-08-20 07:28:14 +00002315 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
2316 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00002317 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 +00002318 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00002319 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002320 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2321 const std::string &Name,
2322 bool Enabled) const {
2323 if (Name == "soft-float")
2324 Features[Name] = Enabled;
2325 else
2326 return false;
2327
2328 return true;
2329 }
2330 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
2331 SoftFloat = false;
2332 for (unsigned i = 0, e = Features.size(); i != e; ++i)
2333 if (Features[i] == "+soft-float")
2334 SoftFloat = true;
2335 }
Chris Lattner33328642009-03-20 15:52:06 +00002336 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002337 MacroBuilder &Builder) const {
2338 DefineStd(Builder, "sparc", Opts);
2339 Builder.defineMacro("__sparcv8");
2340 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002341
2342 if (SoftFloat)
2343 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00002344 }
2345 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2346 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002347 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00002348 }
2349 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002350 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00002351 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002352 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002353 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002354 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002355 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002356 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00002357 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002358 // FIXME: Implement!
2359 return false;
Gabor Greif26658672008-02-21 16:29:08 +00002360 }
2361 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002362 // FIXME: Implement!
2363 return "";
Gabor Greif26658672008-02-21 16:29:08 +00002364 }
2365};
2366
Chris Lattnere957f532009-01-27 01:58:38 +00002367const char * const SparcV8TargetInfo::GCCRegNames[] = {
2368 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2369 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2370 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2371 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
2372};
2373
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002374void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002375 unsigned &NumNames) const {
2376 Names = GCCRegNames;
2377 NumNames = llvm::array_lengthof(GCCRegNames);
2378}
2379
2380const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002381 { { "g0" }, "r0" },
2382 { { "g1" }, "r1" },
2383 { { "g2" }, "r2" },
2384 { { "g3" }, "r3" },
2385 { { "g4" }, "r4" },
2386 { { "g5" }, "r5" },
2387 { { "g6" }, "r6" },
2388 { { "g7" }, "r7" },
2389 { { "o0" }, "r8" },
2390 { { "o1" }, "r9" },
2391 { { "o2" }, "r10" },
2392 { { "o3" }, "r11" },
2393 { { "o4" }, "r12" },
2394 { { "o5" }, "r13" },
2395 { { "o6", "sp" }, "r14" },
2396 { { "o7" }, "r15" },
2397 { { "l0" }, "r16" },
2398 { { "l1" }, "r17" },
2399 { { "l2" }, "r18" },
2400 { { "l3" }, "r19" },
2401 { { "l4" }, "r20" },
2402 { { "l5" }, "r21" },
2403 { { "l6" }, "r22" },
2404 { { "l7" }, "r23" },
2405 { { "i0" }, "r24" },
2406 { { "i1" }, "r25" },
2407 { { "i2" }, "r26" },
2408 { { "i3" }, "r27" },
2409 { { "i4" }, "r28" },
2410 { { "i5" }, "r29" },
2411 { { "i6", "fp" }, "r30" },
2412 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00002413};
2414
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002415void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002416 unsigned &NumAliases) const {
2417 Aliases = GCCRegAliases;
2418 NumAliases = llvm::array_lengthof(GCCRegAliases);
2419}
Gabor Greif26658672008-02-21 16:29:08 +00002420} // end anonymous namespace.
2421
Eli Friedman01b86682008-08-20 07:28:14 +00002422namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002423class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
2424public:
2425 AuroraUXSparcV8TargetInfo(const std::string& triple) :
2426 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
2427 SizeType = UnsignedInt;
2428 PtrDiffType = SignedInt;
2429 }
2430};
Torok Edwin5f6c1942009-06-30 17:10:35 +00002431class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00002432public:
2433 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002434 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00002435 SizeType = UnsignedInt;
2436 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00002437 }
2438};
2439} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00002440
Chris Lattner2621fd12008-05-08 05:58:21 +00002441namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002442 class MSP430TargetInfo : public TargetInfo {
2443 static const char * const GCCRegNames[];
2444 public:
2445 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
2446 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00002447 IntWidth = 16; IntAlign = 16;
2448 LongWidth = 32; LongLongWidth = 64;
2449 LongAlign = LongLongAlign = 16;
2450 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002451 SizeType = UnsignedInt;
2452 IntMaxType = SignedLong;
2453 UIntMaxType = UnsignedLong;
2454 IntPtrType = SignedShort;
2455 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00002456 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00002457 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002458 }
2459 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002460 MacroBuilder &Builder) const {
2461 Builder.defineMacro("MSP430");
2462 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002463 // FIXME: defines for different 'flavours' of MCU
2464 }
2465 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2466 unsigned &NumRecords) const {
2467 // FIXME: Implement.
2468 Records = 0;
2469 NumRecords = 0;
2470 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002471 virtual void getGCCRegNames(const char * const *&Names,
2472 unsigned &NumNames) const;
2473 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2474 unsigned &NumAliases) const {
2475 // No aliases.
2476 Aliases = 0;
2477 NumAliases = 0;
2478 }
2479 virtual bool validateAsmConstraint(const char *&Name,
2480 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00002481 // No target constraints for now.
2482 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002483 }
2484 virtual const char *getClobbers() const {
2485 // FIXME: Is this really right?
2486 return "";
2487 }
2488 virtual const char *getVAListDeclaration() const {
2489 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00002490 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002491 }
2492 };
2493
2494 const char * const MSP430TargetInfo::GCCRegNames[] = {
2495 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2496 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2497 };
2498
2499 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
2500 unsigned &NumNames) const {
2501 Names = GCCRegNames;
2502 NumNames = llvm::array_lengthof(GCCRegNames);
2503 }
2504}
2505
2506
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002507namespace {
2508 class SystemZTargetInfo : public TargetInfo {
2509 static const char * const GCCRegNames[];
2510 public:
2511 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
2512 TLSSupported = false;
2513 IntWidth = IntAlign = 32;
2514 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
2515 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00002516 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
2517 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002518 }
2519 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002520 MacroBuilder &Builder) const {
2521 Builder.defineMacro("__s390__");
2522 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002523 }
2524 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2525 unsigned &NumRecords) const {
2526 // FIXME: Implement.
2527 Records = 0;
2528 NumRecords = 0;
2529 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002530
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002531 virtual void getGCCRegNames(const char * const *&Names,
2532 unsigned &NumNames) const;
2533 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2534 unsigned &NumAliases) const {
2535 // No aliases.
2536 Aliases = 0;
2537 NumAliases = 0;
2538 }
2539 virtual bool validateAsmConstraint(const char *&Name,
2540 TargetInfo::ConstraintInfo &info) const {
2541 // FIXME: implement
2542 return true;
2543 }
2544 virtual const char *getClobbers() const {
2545 // FIXME: Is this really right?
2546 return "";
2547 }
2548 virtual const char *getVAListDeclaration() const {
2549 // FIXME: implement
2550 return "typedef char* __builtin_va_list;";
2551 }
2552 };
2553
2554 const char * const SystemZTargetInfo::GCCRegNames[] = {
2555 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2556 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2557 };
2558
2559 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
2560 unsigned &NumNames) const {
2561 Names = GCCRegNames;
2562 NumNames = llvm::array_lengthof(GCCRegNames);
2563 }
2564}
2565
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002566namespace {
2567 class BlackfinTargetInfo : public TargetInfo {
2568 static const char * const GCCRegNames[];
2569 public:
2570 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
2571 TLSSupported = false;
2572 DoubleAlign = 32;
2573 LongLongAlign = 32;
2574 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00002575 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002576 }
2577
2578 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002579 MacroBuilder &Builder) const {
2580 DefineStd(Builder, "bfin", Opts);
2581 DefineStd(Builder, "BFIN", Opts);
2582 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002583 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00002584 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002585 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
2586 }
2587
2588 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2589 unsigned &NumRecords) const {
2590 // FIXME: Implement.
2591 Records = 0;
2592 NumRecords = 0;
2593 }
2594
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002595 virtual void getGCCRegNames(const char * const *&Names,
2596 unsigned &NumNames) const;
2597
2598 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2599 unsigned &NumAliases) const {
2600 // No aliases.
2601 Aliases = 0;
2602 NumAliases = 0;
2603 }
2604
2605 virtual bool validateAsmConstraint(const char *&Name,
2606 TargetInfo::ConstraintInfo &Info) const {
2607 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
2608 Info.setAllowsRegister();
2609 return true;
2610 }
2611 return false;
2612 }
2613
2614 virtual const char *getClobbers() const {
2615 return "";
2616 }
2617
2618 virtual const char *getVAListDeclaration() const {
2619 return "typedef char* __builtin_va_list;";
2620 }
2621 };
2622
2623 const char * const BlackfinTargetInfo::GCCRegNames[] = {
2624 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2625 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
2626 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
2627 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
2628 "a0", "a1", "cc",
2629 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
2630 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
2631 };
2632
2633 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
2634 unsigned &NumNames) const {
2635 Names = GCCRegNames;
2636 NumNames = llvm::array_lengthof(GCCRegNames);
2637 }
2638}
2639
Eli Friedmanb63decf2009-08-19 20:47:07 +00002640namespace {
2641
Mike Stump1eb44332009-09-09 15:08:12 +00002642 // LLVM and Clang cannot be used directly to output native binaries for
2643 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00002644 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00002645 //
2646 // TCE uses the llvm bitcode as input and uses it for generating customized
2647 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00002648 // publicly available in http://tce.cs.tut.fi
2649
2650 class TCETargetInfo : public TargetInfo{
2651 public:
2652 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
2653 TLSSupported = false;
2654 IntWidth = 32;
2655 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00002656 PointerWidth = 32;
2657 IntAlign = 32;
2658 LongAlign = LongLongAlign = 32;
2659 PointerAlign = 32;
2660 SizeType = UnsignedInt;
2661 IntMaxType = SignedLong;
2662 UIntMaxType = UnsignedLong;
2663 IntPtrType = SignedInt;
2664 PtrDiffType = SignedInt;
2665 FloatWidth = 32;
2666 FloatAlign = 32;
2667 DoubleWidth = 32;
2668 DoubleAlign = 32;
2669 LongDoubleWidth = 32;
2670 LongDoubleAlign = 32;
2671 FloatFormat = &llvm::APFloat::IEEEsingle;
2672 DoubleFormat = &llvm::APFloat::IEEEsingle;
2673 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00002674 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
2675 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00002676 "f32:32:32-f64:32:32-v64:32:32-"
2677 "v128:32:32-a0:0:32-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00002678 }
2679
2680 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002681 MacroBuilder &Builder) const {
2682 DefineStd(Builder, "tce", Opts);
2683 Builder.defineMacro("__TCE__");
2684 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00002685 }
2686 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2687 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00002688 virtual const char *getClobbers() const {
2689 return "";
2690 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002691 virtual const char *getVAListDeclaration() const {
2692 return "typedef void* __builtin_va_list;";
2693 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002694 virtual void getGCCRegNames(const char * const *&Names,
2695 unsigned &NumNames) const {}
2696 virtual bool validateAsmConstraint(const char *&Name,
2697 TargetInfo::ConstraintInfo &info) const {
2698 return true;
2699 }
2700 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2701 unsigned &NumAliases) const {}
2702 };
2703}
2704
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002705namespace {
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002706class MipsTargetInfoBase : public TargetInfo {
2707 std::string CPU;
2708protected:
2709 std::string ABI;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002710public:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002711 MipsTargetInfoBase(const std::string& triple, const std::string& ABIStr)
2712 : TargetInfo(triple), ABI(ABIStr) {
Akira Hatanaka619e8872011-06-02 00:09:17 +00002713 SizeType = UnsignedInt;
2714 PtrDiffType = SignedInt;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002715 }
Eric Christophered734732010-03-02 02:41:08 +00002716 virtual const char *getABI() const { return ABI.c_str(); }
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002717 virtual bool setABI(const std::string &Name) = 0;
Eric Christophered734732010-03-02 02:41:08 +00002718 virtual bool setCPU(const std::string &Name) {
2719 CPU = Name;
2720 return true;
2721 }
2722 void getDefaultFeatures(const std::string &CPU,
2723 llvm::StringMap<bool> &Features) const {
2724 Features[ABI] = true;
2725 Features[CPU] = true;
2726 }
2727 virtual void getArchDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002728 MacroBuilder &Builder) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002729 virtual void getTargetDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002730 MacroBuilder &Builder) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002731 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2732 unsigned &NumRecords) const {
2733 // FIXME: Implement!
2734 }
2735 virtual const char *getVAListDeclaration() const {
2736 return "typedef void* __builtin_va_list;";
2737 }
2738 virtual void getGCCRegNames(const char * const *&Names,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002739 unsigned &NumNames) const {
2740 static const char * const GCCRegNames[] = {
2741 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
2742 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2743 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
2744 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
2745 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
2746 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
2747 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
2748 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
2749 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
2750 "$fcc5","$fcc6","$fcc7"
2751 };
2752 Names = GCCRegNames;
2753 NumNames = llvm::array_lengthof(GCCRegNames);
2754 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002755 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002756 unsigned &NumAliases) const = 0;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002757 virtual bool validateAsmConstraint(const char *&Name,
2758 TargetInfo::ConstraintInfo &Info) const {
2759 switch (*Name) {
2760 default:
2761 case 'r': // CPU registers.
2762 case 'd': // Equivalent to "r" unless generating MIPS16 code.
2763 case 'y': // Equivalent to "r", backwards compatibility only.
2764 case 'f': // floating-point registers.
2765 Info.setAllowsRegister();
2766 return true;
2767 }
2768 return false;
2769 }
2770
2771 virtual const char *getClobbers() const {
2772 // FIXME: Implement!
2773 return "";
2774 }
2775};
2776
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002777class Mips32TargetInfoBase : public MipsTargetInfoBase {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002778public:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002779 Mips32TargetInfoBase(const std::string& triple) :
2780 MipsTargetInfoBase(triple, "o32") {}
2781 virtual bool setABI(const std::string &Name) {
2782 if ((Name == "o32") || (Name == "eabi")) {
2783 ABI = Name;
2784 return true;
2785 } else
2786 return false;
2787 }
2788 virtual void getArchDefines(const LangOptions &Opts,
2789 MacroBuilder &Builder) const {
2790 if (ABI == "o32") {
2791 Builder.defineMacro("__mips_o32");
2792 Builder.defineMacro("_ABIO32", "1");
2793 Builder.defineMacro("_MIPS_SIM", "_ABIO32");
2794 }
2795 else if (ABI == "eabi")
2796 Builder.defineMacro("__mips_eabi");
2797 else
David Blaikieb219cfc2011-09-23 05:06:16 +00002798 llvm_unreachable("Invalid ABI for Mips32.");
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002799 }
2800 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2801 unsigned &NumAliases) const {
2802 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
2803 { { "at" }, "$1" },
2804 { { "v0" }, "$2" },
2805 { { "v1" }, "$3" },
2806 { { "a0" }, "$4" },
2807 { { "a1" }, "$5" },
2808 { { "a2" }, "$6" },
2809 { { "a3" }, "$7" },
2810 { { "t0" }, "$8" },
2811 { { "t1" }, "$9" },
2812 { { "t2" }, "$10" },
2813 { { "t3" }, "$11" },
2814 { { "t4" }, "$12" },
2815 { { "t5" }, "$13" },
2816 { { "t6" }, "$14" },
2817 { { "t7" }, "$15" },
2818 { { "s0" }, "$16" },
2819 { { "s1" }, "$17" },
2820 { { "s2" }, "$18" },
2821 { { "s3" }, "$19" },
2822 { { "s4" }, "$20" },
2823 { { "s5" }, "$21" },
2824 { { "s6" }, "$22" },
2825 { { "s7" }, "$23" },
2826 { { "t8" }, "$24" },
2827 { { "t9" }, "$25" },
2828 { { "k0" }, "$26" },
2829 { { "k1" }, "$27" },
2830 { { "gp" }, "$28" },
2831 { { "sp" }, "$29" },
2832 { { "fp" }, "$30" },
2833 { { "ra" }, "$31" }
2834 };
2835 Aliases = GCCRegAliases;
2836 NumAliases = llvm::array_lengthof(GCCRegAliases);
2837 }
2838};
2839
2840class Mips32EBTargetInfo : public Mips32TargetInfoBase {
2841public:
2842 Mips32EBTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) {
2843 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2844 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2845 }
2846 virtual void getTargetDefines(const LangOptions &Opts,
2847 MacroBuilder &Builder) const {
2848 DefineStd(Builder, "mips", Opts);
2849 Builder.defineMacro("_mips");
2850 DefineStd(Builder, "MIPSEB", Opts);
2851 Builder.defineMacro("_MIPSEB");
2852 Builder.defineMacro("__REGISTER_PREFIX__", "");
2853 getArchDefines(Opts, Builder);
2854 }
2855};
2856
2857class Mips32ELTargetInfo : public Mips32TargetInfoBase {
2858public:
2859 Mips32ELTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002860 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 +00002861 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002862 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002863 virtual void getTargetDefines(const LangOptions &Opts,
Akira Hatanakab6a37b32011-09-20 19:00:23 +00002864 MacroBuilder &Builder) const {
2865 DefineStd(Builder, "mips", Opts);
2866 Builder.defineMacro("_mips");
2867 DefineStd(Builder, "MIPSEL", Opts);
2868 Builder.defineMacro("_MIPSEL");
2869 Builder.defineMacro("__REGISTER_PREFIX__", "");
2870 getArchDefines(Opts, Builder);
2871 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002872};
Akira Hatanakabf5851a2011-09-20 19:21:49 +00002873
2874class Mips64TargetInfoBase : public MipsTargetInfoBase {
2875 virtual void SetDescriptionString(const std::string &Name) = 0;
2876public:
2877 Mips64TargetInfoBase(const std::string& triple) :
2878 MipsTargetInfoBase(triple, "n64") {}
2879 virtual bool setABI(const std::string &Name) {
2880 SetDescriptionString(Name);
2881 if ((Name == "n32") || (Name == "n64")) {
2882 ABI = Name;
2883 return true;
2884 } else
2885 return false;
2886 }
2887 virtual void getArchDefines(const LangOptions &Opts,
2888 MacroBuilder &Builder) const {
2889 if (ABI == "n32") {
2890 Builder.defineMacro("__mips_n32");
2891 Builder.defineMacro("_ABIN32", "2");
2892 Builder.defineMacro("_MIPS_SIM", "_ABIN32");
2893 }
2894 else if (ABI == "n64") {
2895 Builder.defineMacro("__mips_n64");
2896 Builder.defineMacro("_ABI64", "3");
2897 Builder.defineMacro("_MIPS_SIM", "_ABI64");
2898 }
2899 else
David Blaikieb219cfc2011-09-23 05:06:16 +00002900 llvm_unreachable("Invalid ABI for Mips64.");
Akira Hatanakabf5851a2011-09-20 19:21:49 +00002901 }
2902 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2903 unsigned &NumAliases) const {
2904 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
2905 { { "at" }, "$1" },
2906 { { "v0" }, "$2" },
2907 { { "v1" }, "$3" },
2908 { { "a0" }, "$4" },
2909 { { "a1" }, "$5" },
2910 { { "a2" }, "$6" },
2911 { { "a3" }, "$7" },
2912 { { "a4" }, "$8" },
2913 { { "a5" }, "$9" },
2914 { { "a6" }, "$10" },
2915 { { "a7" }, "$11" },
2916 { { "t0" }, "$12" },
2917 { { "t1" }, "$13" },
2918 { { "t2" }, "$14" },
2919 { { "t3" }, "$15" },
2920 { { "s0" }, "$16" },
2921 { { "s1" }, "$17" },
2922 { { "s2" }, "$18" },
2923 { { "s3" }, "$19" },
2924 { { "s4" }, "$20" },
2925 { { "s5" }, "$21" },
2926 { { "s6" }, "$22" },
2927 { { "s7" }, "$23" },
2928 { { "t8" }, "$24" },
2929 { { "t9" }, "$25" },
2930 { { "k0" }, "$26" },
2931 { { "k1" }, "$27" },
2932 { { "gp" }, "$28" },
2933 { { "sp" }, "$29" },
2934 { { "fp" }, "$30" },
2935 { { "ra" }, "$31" }
2936 };
2937 Aliases = GCCRegAliases;
2938 NumAliases = llvm::array_lengthof(GCCRegAliases);
2939 }
2940};
2941
2942class Mips64EBTargetInfo : public Mips64TargetInfoBase {
2943 virtual void SetDescriptionString(const std::string &Name) {
2944 // Change DescriptionString only if ABI is n32.
2945 if (Name == "n32")
2946 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2947 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2948 }
2949public:
2950 Mips64EBTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) {
2951 // Default ABI is n64.
2952 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2953 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2954 }
2955 virtual void getTargetDefines(const LangOptions &Opts,
2956 MacroBuilder &Builder) const {
2957 DefineStd(Builder, "mips", Opts);
2958 Builder.defineMacro("_mips");
2959 DefineStd(Builder, "MIPSEB", Opts);
2960 Builder.defineMacro("_MIPSEB");
2961 Builder.defineMacro("__REGISTER_PREFIX__", "");
2962 getArchDefines(Opts, Builder);
2963 }
2964};
2965
2966class Mips64ELTargetInfo : public Mips64TargetInfoBase {
2967 virtual void SetDescriptionString(const std::string &Name) {
2968 // Change DescriptionString only if ABI is n32.
2969 if (Name == "n32")
2970 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2971 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2972 }
2973public:
2974 Mips64ELTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) {
2975 // Default ABI is n64.
2976 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2977 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2978 }
2979 virtual void getTargetDefines(const LangOptions &Opts,
2980 MacroBuilder &Builder) const {
2981 DefineStd(Builder, "mips", Opts);
2982 Builder.defineMacro("_mips");
2983 DefineStd(Builder, "MIPSEL", Opts);
2984 Builder.defineMacro("_MIPSEL");
2985 Builder.defineMacro("__REGISTER_PREFIX__", "");
2986 getArchDefines(Opts, Builder);
2987 }
2988};
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002989} // end anonymous namespace.
2990
Ivan Krasinef05abd2011-08-24 20:22:22 +00002991namespace {
2992class PNaClTargetInfo : public TargetInfo {
2993public:
2994 PNaClTargetInfo(const std::string& triple) : TargetInfo(triple) {
2995 this->UserLabelPrefix = "";
2996 this->LongAlign = 32;
2997 this->LongWidth = 32;
2998 this->PointerAlign = 32;
2999 this->PointerWidth = 32;
3000 this->IntMaxType = TargetInfo::SignedLongLong;
3001 this->UIntMaxType = TargetInfo::UnsignedLongLong;
3002 this->Int64Type = TargetInfo::SignedLongLong;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00003003 this->DoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00003004 this->LongDoubleWidth = 64;
Ivan Krasinf619cdc2011-08-29 22:39:12 +00003005 this->LongDoubleAlign = 64;
Ivan Krasin68018db2011-09-20 14:56:54 +00003006 this->SizeType = TargetInfo::UnsignedInt;
3007 this->PtrDiffType = TargetInfo::SignedInt;
3008 this->IntPtrType = TargetInfo::SignedInt;
Ivan Krasinef05abd2011-08-24 20:22:22 +00003009 DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
3010 "f32:32:32-f64:64:64-p:32:32:32-v128:32:32";
3011 }
3012
3013 void getDefaultFeatures(const std::string &CPU,
3014 llvm::StringMap<bool> &Features) const {
3015 }
3016 virtual void getArchDefines(const LangOptions &Opts,
3017 MacroBuilder &Builder) const {
3018 Builder.defineMacro("__le32__");
3019 Builder.defineMacro("__pnacl__");
3020 }
3021 virtual void getTargetDefines(const LangOptions &Opts,
3022 MacroBuilder &Builder) const {
Ivan Krasin089ee112011-08-25 23:49:20 +00003023 DefineStd(Builder, "unix", Opts);
3024 Builder.defineMacro("__ELF__");
3025 if (Opts.POSIXThreads)
3026 Builder.defineMacro("_REENTRANT");
3027 if (Opts.CPlusPlus)
3028 Builder.defineMacro("_GNU_SOURCE");
3029
Ivan Krasinef05abd2011-08-24 20:22:22 +00003030 Builder.defineMacro("__native_client__");
3031 getArchDefines(Opts, Builder);
3032 }
3033 virtual void getTargetBuiltins(const Builtin::Info *&Records,
3034 unsigned &NumRecords) const {
3035 }
3036 virtual const char *getVAListDeclaration() const {
Ivan Krasin68018db2011-09-20 14:56:54 +00003037 return "typedef int __builtin_va_list[4];";
Ivan Krasinef05abd2011-08-24 20:22:22 +00003038 }
3039 virtual void getGCCRegNames(const char * const *&Names,
3040 unsigned &NumNames) const;
3041 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
3042 unsigned &NumAliases) const;
3043 virtual bool validateAsmConstraint(const char *&Name,
3044 TargetInfo::ConstraintInfo &Info) const {
3045 return false;
3046 }
3047
3048 virtual const char *getClobbers() const {
3049 return "";
3050 }
3051};
3052
3053void PNaClTargetInfo::getGCCRegNames(const char * const *&Names,
3054 unsigned &NumNames) const {
3055 Names = NULL;
3056 NumNames = 0;
3057}
3058
3059void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
3060 unsigned &NumAliases) const {
3061 Aliases = NULL;
3062 NumAliases = 0;
3063}
3064} // end anonymous namespace.
3065
3066
Reid Spencer5f016e22007-07-11 17:01:13 +00003067//===----------------------------------------------------------------------===//
3068// Driver code
3069//===----------------------------------------------------------------------===//
3070
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003071static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003072 llvm::Triple Triple(T);
3073 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00003074
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003075 switch (Triple.getArch()) {
3076 default:
3077 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00003078
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003079 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00003080 case llvm::Triple::thumb:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003081 if (Triple.isOSDarwin())
3082 return new DarwinARMTargetInfo(T);
3083
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003084 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00003085 case llvm::Triple::Linux:
3086 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003087 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00003088 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003089 case llvm::Triple::NetBSD:
3090 return new NetBSDTargetInfo<ARMTargetInfo>(T);
Douglas Gregordca52262011-07-01 22:41:14 +00003091 case llvm::Triple::RTEMS:
3092 return new RTEMSTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003093 default:
3094 return new ARMTargetInfo(T);
3095 }
Eli Friedman61538a72008-05-20 14:21:01 +00003096
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003097 case llvm::Triple::bfin:
Douglas Gregordca52262011-07-01 22:41:14 +00003098 if ( os == llvm::Triple::RTEMS )
3099 return new RTEMSTargetInfo<BlackfinTargetInfo>(T);
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00003100 return new BlackfinTargetInfo(T);
3101
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003102 case llvm::Triple::msp430:
3103 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00003104
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003105 case llvm::Triple::mips:
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003106 switch (os) {
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003107 case llvm::Triple::Linux:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003108 return new LinuxTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003109 case llvm::Triple::RTEMS:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003110 return new RTEMSTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003111 case llvm::Triple::FreeBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003112 return new FreeBSDTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003113 case llvm::Triple::NetBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003114 return new NetBSDTargetInfo<Mips32EBTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003115 default:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003116 return new Mips32EBTargetInfo(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00003117 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003118
3119 case llvm::Triple::mipsel:
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003120 switch (os) {
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003121 case llvm::Triple::Linux:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003122 return new LinuxTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003123 case llvm::Triple::RTEMS:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003124 return new RTEMSTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003125 case llvm::Triple::FreeBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003126 return new FreeBSDTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003127 case llvm::Triple::NetBSD:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003128 return new NetBSDTargetInfo<Mips32ELTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003129 default:
Akira Hatanakab6a37b32011-09-20 19:00:23 +00003130 return new Mips32ELTargetInfo(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00003131 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00003132
Akira Hatanakabf5851a2011-09-20 19:21:49 +00003133 case llvm::Triple::mips64:
3134 switch (os) {
3135 case llvm::Triple::Linux:
3136 return new LinuxTargetInfo<Mips64EBTargetInfo>(T);
3137 case llvm::Triple::RTEMS:
3138 return new RTEMSTargetInfo<Mips64EBTargetInfo>(T);
3139 case llvm::Triple::FreeBSD:
3140 return new FreeBSDTargetInfo<Mips64EBTargetInfo>(T);
3141 case llvm::Triple::NetBSD:
3142 return new NetBSDTargetInfo<Mips64EBTargetInfo>(T);
3143 default:
3144 return new Mips64EBTargetInfo(T);
3145 }
3146
3147 case llvm::Triple::mips64el:
3148 switch (os) {
3149 case llvm::Triple::Linux:
3150 return new LinuxTargetInfo<Mips64ELTargetInfo>(T);
3151 case llvm::Triple::RTEMS:
3152 return new RTEMSTargetInfo<Mips64ELTargetInfo>(T);
3153 case llvm::Triple::FreeBSD:
3154 return new FreeBSDTargetInfo<Mips64ELTargetInfo>(T);
3155 case llvm::Triple::NetBSD:
3156 return new NetBSDTargetInfo<Mips64ELTargetInfo>(T);
3157 default:
3158 return new Mips64ELTargetInfo(T);
3159 }
3160
Ivan Krasinef05abd2011-08-24 20:22:22 +00003161 case llvm::Triple::le32:
3162 switch (os) {
3163 case llvm::Triple::NativeClient:
3164 return new PNaClTargetInfo(T);
3165 default:
3166 return NULL;
3167 }
3168
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003169 case llvm::Triple::ppc:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003170 if (Triple.isOSDarwin())
Roman Divackyc81f2a22011-01-06 08:27:10 +00003171 return new DarwinPPC32TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003172 switch (os) {
3173 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00003174 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003175 case llvm::Triple::NetBSD:
3176 return new NetBSDTargetInfo<PPC32TargetInfo>(T);
3177 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00003178 return new RTEMSTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003179 default:
3180 return new PPC32TargetInfo(T);
3181 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003182
3183 case llvm::Triple::ppc64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003184 if (Triple.isOSDarwin())
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00003185 return new DarwinPPC64TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003186 switch (os) {
3187 case llvm::Triple::Lv2:
John Thompson3f6918a2009-11-19 17:18:50 +00003188 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003189 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00003190 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003191 case llvm::Triple::NetBSD:
3192 return new NetBSDTargetInfo<PPC64TargetInfo>(T);
3193 default:
3194 return new PPC64TargetInfo(T);
3195 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003196
Justin Holewinski285dc652011-04-20 19:34:15 +00003197 case llvm::Triple::ptx32:
3198 return new PTX32TargetInfo(T);
3199 case llvm::Triple::ptx64:
3200 return new PTX64TargetInfo(T);
3201
Chris Lattner9cbeb632010-03-06 21:21:27 +00003202 case llvm::Triple::mblaze:
3203 return new MBlazeTargetInfo(T);
3204
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003205 case llvm::Triple::sparc:
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003206 switch (os) {
3207 case llvm::Triple::AuroraUX:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00003208 return new AuroraUXSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003209 case llvm::Triple::Solaris:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003210 return new SolarisSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003211 case llvm::Triple::NetBSD:
3212 return new NetBSDTargetInfo<SparcV8TargetInfo>(T);
3213 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00003214 return new RTEMSTargetInfo<SparcV8TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00003215 default:
3216 return new SparcV8TargetInfo(T);
3217 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003218
John Thompson3f6918a2009-11-19 17:18:50 +00003219 // FIXME: Need a real SPU target.
3220 case llvm::Triple::cellspu:
3221 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
3222
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003223 case llvm::Triple::systemz:
3224 return new SystemZTargetInfo(T);
3225
Eli Friedmanb63decf2009-08-19 20:47:07 +00003226 case llvm::Triple::tce:
3227 return new TCETargetInfo(T);
3228
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003229 case llvm::Triple::x86:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003230 if (Triple.isOSDarwin())
3231 return new DarwinI386TargetInfo(T);
3232
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003233 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00003234 case llvm::Triple::AuroraUX:
3235 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003236 case llvm::Triple::Linux:
3237 return new LinuxTargetInfo<X86_32TargetInfo>(T);
3238 case llvm::Triple::DragonFly:
3239 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
3240 case llvm::Triple::NetBSD:
3241 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
3242 case llvm::Triple::OpenBSD:
3243 return new OpenBSDI386TargetInfo(T);
3244 case llvm::Triple::FreeBSD:
3245 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00003246 case llvm::Triple::Minix:
3247 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003248 case llvm::Triple::Solaris:
3249 return new SolarisTargetInfo<X86_32TargetInfo>(T);
3250 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003251 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003252 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003253 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003254 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00003255 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00003256 case llvm::Triple::Haiku:
3257 return new HaikuX86_32TargetInfo(T);
Douglas Gregordca52262011-07-01 22:41:14 +00003258 case llvm::Triple::RTEMS:
3259 return new RTEMSX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003260 default:
3261 return new X86_32TargetInfo(T);
3262 }
3263
3264 case llvm::Triple::x86_64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003265 if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO)
3266 return new DarwinX86_64TargetInfo(T);
3267
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003268 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00003269 case llvm::Triple::AuroraUX:
3270 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003271 case llvm::Triple::Linux:
3272 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00003273 case llvm::Triple::DragonFly:
3274 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003275 case llvm::Triple::NetBSD:
3276 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
3277 case llvm::Triple::OpenBSD:
3278 return new OpenBSDX86_64TargetInfo(T);
3279 case llvm::Triple::FreeBSD:
3280 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
3281 case llvm::Triple::Solaris:
3282 return new SolarisTargetInfo<X86_64TargetInfo>(T);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00003283 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003284 return new MinGWX86_64TargetInfo(T);
3285 case llvm::Triple::Win32: // This is what Triple.h supports now.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003286 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003287 default:
3288 return new X86_64TargetInfo(T);
3289 }
3290 }
Reid Spencer5f016e22007-07-11 17:01:13 +00003291}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003292
3293/// CreateTargetInfo - Return the target info object for the specified target
3294/// triple.
3295TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003296 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003297 llvm::Triple Triple(Opts.Triple);
3298
3299 // Construct the target
3300 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
3301 if (!Target) {
3302 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
3303 return 0;
3304 }
3305
Daniel Dunbareac7c532009-12-18 18:42:37 +00003306 // Set the target CPU if specified.
3307 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
3308 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
3309 return 0;
3310 }
3311
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003312 // Set the target ABI if specified.
3313 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
3314 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
3315 return 0;
3316 }
3317
Charles Davis98b7c5c2010-06-11 01:06:47 +00003318 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00003319 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00003320 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
3321 return 0;
3322 }
3323
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003324 // Compute the default target features, we need the target to handle this
3325 // because features may have dependencies on one another.
3326 llvm::StringMap<bool> Features;
3327 Target->getDefaultFeatures(Opts.CPU, Features);
3328
3329 // Apply the user specified deltas.
3330 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
3331 ie = Opts.Features.end(); it != ie; ++it) {
3332 const char *Name = it->c_str();
3333
3334 // Apply the feature via the target.
3335 if ((Name[0] != '-' && Name[0] != '+') ||
3336 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
3337 Diags.Report(diag::err_target_invalid_feature) << Name;
3338 return 0;
3339 }
3340 }
3341
3342 // Add the features to the compile options.
3343 //
3344 // FIXME: If we are completely confident that we have the right set, we only
3345 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003346 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003347 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
3348 ie = Features.end(); it != ie; ++it)
Chris Lattner1e5f83b2011-07-14 18:24:21 +00003349 Opts.Features.push_back(std::string(it->second ? "+" : "-") +
Chris Lattner48b78bd2011-07-14 18:45:41 +00003350 it->first().str());
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003351 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003352
3353 return Target.take();
3354}