blob: 1b17e2e9ed4d120310e84dbd96b2c164db5cc8a9 [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.
Benjamin Kramera9992772010-01-09 17:55:51 +000040static void DefineStd(MacroBuilder &Builder, llvm::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,
80 llvm::StringRef &PlatformName,
81 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).
92 if (Opts.getGCMode() != LangOptions::NonGC)
93 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
150 // generating code for Win32 ABI. No need to emit
151 // __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
Anders Carlssonf959fb52010-01-30 18:33:31 +0000205 virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000206 // Let MCSectionMachO validate this.
207 llvm::StringRef Segment, Section;
208 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.
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000250 llvm::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)
506 Builder.defineMacro("_MSC_VER", llvm::Twine(Opts.MSCVersion));
507
508 if (Opts.Microsoft) {
509 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[];
883 public:
884 PTXTargetInfo(const std::string& triple) : TargetInfo(triple) {
885 TLSSupported = false;
886 LongWidth = LongAlign = 64;
887 }
888 virtual void getTargetDefines(const LangOptions &Opts,
889 MacroBuilder &Builder) const {
890 Builder.defineMacro("__PTX__");
891 }
892 virtual void getTargetBuiltins(const Builtin::Info *&Records,
893 unsigned &NumRecords) const {
894 Records = BuiltinInfo;
895 NumRecords = clang::PTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
896 }
897
898 virtual void getGCCRegNames(const char * const *&Names,
899 unsigned &NumNames) const;
900 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
901 unsigned &NumAliases) const {
902 // No aliases.
903 Aliases = 0;
904 NumAliases = 0;
905 }
906 virtual bool validateAsmConstraint(const char *&Name,
907 TargetInfo::ConstraintInfo &info) const {
908 // FIXME: implement
909 return true;
910 }
911 virtual const char *getClobbers() const {
912 // FIXME: Is this really right?
913 return "";
914 }
915 virtual const char *getVAListDeclaration() const {
916 // FIXME: implement
917 return "typedef char* __builtin_va_list;";
918 }
919 };
920
921 const Builtin::Info PTXTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +0000922#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Justin Holewinski285dc652011-04-20 19:34:15 +0000923#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +0000924 ALL_LANGUAGES },
Justin Holewinski285dc652011-04-20 19:34:15 +0000925#include "clang/Basic/BuiltinsPTX.def"
926 };
927
928 const char * const PTXTargetInfo::GCCRegNames[] = {
929 "r0"
930 };
931
932 void PTXTargetInfo::getGCCRegNames(const char * const *&Names,
933 unsigned &NumNames) const {
934 Names = GCCRegNames;
935 NumNames = llvm::array_lengthof(GCCRegNames);
936 }
937
938
939 class PTX32TargetInfo : public PTXTargetInfo {
940 public:
941 PTX32TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
942 PointerWidth = PointerAlign = 32;
943 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt;
944 DescriptionString
945 = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64";
946 }
947 };
948
949 class PTX64TargetInfo : public PTXTargetInfo {
950 public:
951 PTX64TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
952 PointerWidth = PointerAlign = 64;
953 SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong;
954 DescriptionString
955 = "e-p:64:64-i64:64:64-f64:64:64-n1:8:16:32:64";
956 }
957 };
958}
959
960namespace {
Chris Lattner9cbeb632010-03-06 21:21:27 +0000961// MBlaze abstract base class
962class MBlazeTargetInfo : public TargetInfo {
963 static const char * const GCCRegNames[];
964 static const TargetInfo::GCCRegAlias GCCRegAliases[];
965
966public:
967 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) {
Wesley Pecka48fa4b2010-12-12 20:56:47 +0000968 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16";
Chris Lattner9cbeb632010-03-06 21:21:27 +0000969 }
970
971 virtual void getTargetBuiltins(const Builtin::Info *&Records,
972 unsigned &NumRecords) const {
973 // FIXME: Implement.
974 Records = 0;
975 NumRecords = 0;
976 }
977
978 virtual void getTargetDefines(const LangOptions &Opts,
979 MacroBuilder &Builder) const;
980
981 virtual const char *getVAListDeclaration() const {
982 return "typedef char* __builtin_va_list;";
983 }
984 virtual const char *getTargetPrefix() const {
985 return "mblaze";
986 }
987 virtual void getGCCRegNames(const char * const *&Names,
988 unsigned &NumNames) const;
989 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
990 unsigned &NumAliases) const;
991 virtual bool validateAsmConstraint(const char *&Name,
992 TargetInfo::ConstraintInfo &Info) const {
993 switch (*Name) {
994 default: return false;
995 case 'O': // Zero
996 return true;
997 case 'b': // Base register
998 case 'f': // Floating point register
999 Info.setAllowsRegister();
1000 return true;
1001 }
1002 }
1003 virtual const char *getClobbers() const {
1004 return "";
1005 }
1006};
1007
1008/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific
1009/// #defines that are not tied to a specific subtarget.
1010void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts,
1011 MacroBuilder &Builder) const {
1012 // Target identification.
1013 Builder.defineMacro("__microblaze__");
1014 Builder.defineMacro("_ARCH_MICROBLAZE");
1015 Builder.defineMacro("__MICROBLAZE__");
1016
1017 // Target properties.
1018 Builder.defineMacro("_BIG_ENDIAN");
1019 Builder.defineMacro("__BIG_ENDIAN__");
1020
1021 // Subtarget options.
1022 Builder.defineMacro("__REGISTER_PREFIX__", "");
1023}
1024
1025
1026const char * const MBlazeTargetInfo::GCCRegNames[] = {
1027 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1028 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1029 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1030 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
1031 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
1032 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
1033 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
1034 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
1035 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4",
1036 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp"
1037};
1038
1039void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names,
1040 unsigned &NumNames) const {
1041 Names = GCCRegNames;
1042 NumNames = llvm::array_lengthof(GCCRegNames);
1043}
1044
1045const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = {
1046 { {"f0"}, "r0" },
1047 { {"f1"}, "r1" },
1048 { {"f2"}, "r2" },
1049 { {"f3"}, "r3" },
1050 { {"f4"}, "r4" },
1051 { {"f5"}, "r5" },
1052 { {"f6"}, "r6" },
1053 { {"f7"}, "r7" },
1054 { {"f8"}, "r8" },
1055 { {"f9"}, "r9" },
1056 { {"f10"}, "r10" },
1057 { {"f11"}, "r11" },
1058 { {"f12"}, "r12" },
1059 { {"f13"}, "r13" },
1060 { {"f14"}, "r14" },
1061 { {"f15"}, "r15" },
1062 { {"f16"}, "r16" },
1063 { {"f17"}, "r17" },
1064 { {"f18"}, "r18" },
1065 { {"f19"}, "r19" },
1066 { {"f20"}, "r20" },
1067 { {"f21"}, "r21" },
1068 { {"f22"}, "r22" },
1069 { {"f23"}, "r23" },
1070 { {"f24"}, "r24" },
1071 { {"f25"}, "r25" },
1072 { {"f26"}, "r26" },
1073 { {"f27"}, "r27" },
1074 { {"f28"}, "r28" },
1075 { {"f29"}, "r29" },
1076 { {"f30"}, "r30" },
1077 { {"f31"}, "r31" },
1078};
1079
1080void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
1081 unsigned &NumAliases) const {
1082 Aliases = GCCRegAliases;
1083 NumAliases = llvm::array_lengthof(GCCRegAliases);
1084}
1085} // end anonymous namespace.
1086
1087namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001088// Namespace for x86 abstract base class
1089const Builtin::Info BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00001090#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00001091#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00001092 ALL_LANGUAGES },
Chris Lattner6b15cdc2009-06-14 01:05:48 +00001093#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +00001094};
Eli Friedman61538a72008-05-20 14:21:01 +00001095
Nuno Lopes2550d702009-12-23 17:49:57 +00001096static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +00001097 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
1098 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Eric Christopher7c9adf92011-07-07 22:55:26 +00001099 "argp", "flags", "fpcr", "fpsr", "dirflag", "frame",
Eli Friedman618234a2008-08-20 02:34:37 +00001100 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
1101 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
1102 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
Eric Christophercfd323d2011-06-21 00:05:20 +00001103 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
Eli Friedman618234a2008-08-20 02:34:37 +00001104};
1105
Eric Christophercfd323d2011-06-21 00:05:20 +00001106const TargetInfo::AddlRegName AddlRegNames[] = {
1107 { { "al", "ah", "eax", "rax" }, 0 },
1108 { { "bl", "bh", "ebx", "rbx" }, 3 },
1109 { { "cl", "ch", "ecx", "rcx" }, 2 },
1110 { { "dl", "dh", "edx", "rdx" }, 1 },
1111 { { "esi", "rsi" }, 4 },
1112 { { "edi", "rdi" }, 5 },
1113 { { "esp", "rsp" }, 7 },
1114 { { "ebp", "rbp" }, 6 },
Eli Friedman618234a2008-08-20 02:34:37 +00001115};
1116
1117// X86 target abstract base class; x86-32 and x86-64 are very close, so
1118// most of the implementation can be shared.
1119class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +00001120 enum X86SSEEnum {
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001121 NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
Chris Lattner84f0ea82009-03-02 22:40:39 +00001122 } SSELevel;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001123 enum MMX3DNowEnum {
1124 NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon
1125 } MMX3DNowLevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001126
Eric Christophereea12d12010-04-02 23:50:19 +00001127 bool HasAES;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001128 bool HasAVX;
1129
Eli Friedman618234a2008-08-20 02:34:37 +00001130public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001131 X86TargetInfo(const std::string& triple)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001132 : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001133 HasAES(false), HasAVX(false) {
Eli Friedman618234a2008-08-20 02:34:37 +00001134 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +00001135 }
1136 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1137 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001138 Records = BuiltinInfo;
1139 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +00001140 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001141 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +00001142 unsigned &NumNames) const {
1143 Names = GCCRegNames;
1144 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +00001145 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001146 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +00001147 unsigned &NumAliases) const {
Eric Christophercfd323d2011-06-21 00:05:20 +00001148 Aliases = 0;
1149 NumAliases = 0;
1150 }
1151 virtual void getGCCAddlRegNames(const AddlRegName *&Names,
1152 unsigned &NumNames) const {
1153 Names = AddlRegNames;
1154 NumNames = llvm::array_lengthof(AddlRegNames);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001155 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001156 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +00001157 TargetInfo::ConstraintInfo &info) const;
Stuart Hastings002333f2011-06-07 23:45:05 +00001158 virtual std::string convertConstraint(const char *&Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +00001159 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +00001160 return "~{dirflag},~{fpsr},~{flags}";
1161 }
Chris Lattner33328642009-03-20 15:52:06 +00001162 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001163 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001164 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1165 const std::string &Name,
1166 bool Enabled) const;
Mike Stump1eb44332009-09-09 15:08:12 +00001167 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001168 llvm::StringMap<bool> &Features) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001169 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001170 virtual const char* getABI() const {
1171 return MMX3DNowLevel == NoMMX3DNow ? "no-mmx" : "";
1172 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001173};
Chris Lattner3daed522009-03-02 22:20:04 +00001174
Mike Stump1eb44332009-09-09 15:08:12 +00001175void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001176 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001177 // FIXME: This should not be here.
1178 Features["3dnow"] = false;
1179 Features["3dnowa"] = false;
1180 Features["mmx"] = false;
1181 Features["sse"] = false;
1182 Features["sse2"] = false;
1183 Features["sse3"] = false;
1184 Features["ssse3"] = false;
1185 Features["sse41"] = false;
1186 Features["sse42"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001187 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001188 Features["avx"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001189
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001190 // LLVM does not currently recognize this.
1191 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001192
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001193 // FIXME: This *really* should not be here.
1194
1195 // X86_64 always has SSE2.
1196 if (PointerWidth == 64)
1197 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
1198
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001199 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
1200 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
1201 ;
1202 else if (CPU == "pentium-mmx" || CPU == "pentium2")
1203 setFeatureEnabled(Features, "mmx", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001204 else if (CPU == "pentium3") {
1205 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001206 setFeatureEnabled(Features, "sse", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001207 } else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") {
1208 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001209 setFeatureEnabled(Features, "sse2", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001210 } else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") {
1211 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001212 setFeatureEnabled(Features, "sse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001213 } else if (CPU == "core2") {
1214 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001215 setFeatureEnabled(Features, "ssse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001216 } else if (CPU == "penryn") {
1217 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001218 setFeatureEnabled(Features, "sse4", true);
1219 Features["sse42"] = false;
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001220 } else if (CPU == "atom") {
1221 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001222 setFeatureEnabled(Features, "sse3", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001223 } else if (CPU == "corei7") {
1224 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001225 setFeatureEnabled(Features, "sse4", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001226 setFeatureEnabled(Features, "aes", true);
Benjamin Kramerb65b6722011-05-20 15:11:23 +00001227 } else if (CPU == "corei7-avx") {
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001228 setFeatureEnabled(Features, "mmx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001229 setFeatureEnabled(Features, "sse4", true);
1230 setFeatureEnabled(Features, "aes", true);
Bruno Cardoso Lopese02d3912011-07-11 23:33:46 +00001231 //setFeatureEnabled(Features, "avx", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001232 } else if (CPU == "k6" || CPU == "winchip-c6")
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001233 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +00001234 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001235 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001236 setFeatureEnabled(Features, "3dnow", true);
1237 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
1238 setFeatureEnabled(Features, "sse", true);
1239 setFeatureEnabled(Features, "3dnowa", true);
1240 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
1241 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +00001242 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001243 setFeatureEnabled(Features, "3dnowa", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00001244 } else if (CPU == "k8-sse3") {
1245 setFeatureEnabled(Features, "sse3", true);
1246 setFeatureEnabled(Features, "3dnowa", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001247 } else if (CPU == "c3-2") {
1248 setFeatureEnabled(Features, "mmx", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001249 setFeatureEnabled(Features, "sse", true);
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001250 }
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001251}
1252
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001253bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +00001254 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001255 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001256 // FIXME: This *really* should not be here. We need some way of translating
1257 // options into llvm subtarget features.
1258 if (!Features.count(Name) &&
1259 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001260 return false;
1261
1262 if (Enabled) {
1263 if (Name == "mmx")
1264 Features["mmx"] = true;
1265 else if (Name == "sse")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001266 Features["sse"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001267 else if (Name == "sse2")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001268 Features["sse"] = Features["sse2"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001269 else if (Name == "sse3")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001270 Features["sse"] = Features["sse2"] = Features["sse3"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001271 else if (Name == "ssse3")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001272 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001273 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001274 else if (Name == "sse4" || Name == "sse4.2")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001275 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001276 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001277 else if (Name == "sse4.1")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001278 Features["sse"] = Features["sse2"] = Features["sse3"] =
Eric Christopherd39ebe22010-03-04 02:26:37 +00001279 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001280 else if (Name == "3dnow")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001281 Features["mmx"] = Features["3dnow"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001282 else if (Name == "3dnowa")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001283 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001284 else if (Name == "aes")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001285 Features["aes"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001286 else if (Name == "avx")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001287 Features["avx"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001288 } else {
1289 if (Name == "mmx")
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001290 Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001291 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001292 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001293 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001294 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001295 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001296 Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001297 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001298 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001299 Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001300 else if (Name == "ssse3")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001301 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
Michael J. Spencerb24bac92011-04-17 19:22:03 +00001302 else if (Name == "sse4" || Name == "sse4.1")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001303 Features["sse41"] = Features["sse42"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001304 else if (Name == "sse4.2")
Daniel Dunbarcb65de12011-05-03 15:34:01 +00001305 Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001306 else if (Name == "3dnow")
1307 Features["3dnow"] = Features["3dnowa"] = false;
1308 else if (Name == "3dnowa")
1309 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001310 else if (Name == "aes")
1311 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001312 else if (Name == "avx")
1313 Features["avx"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001314 }
1315
1316 return true;
1317}
1318
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001319/// HandleTargetOptions - Perform initialization based on the user
1320/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001321void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001322 // Remember the maximum enabled sselevel.
1323 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1324 // Ignore disabled features.
1325 if (Features[i][0] == '-')
1326 continue;
1327
Eric Christophereea12d12010-04-02 23:50:19 +00001328 if (Features[i].substr(1) == "aes") {
1329 HasAES = true;
1330 continue;
1331 }
1332
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001333 // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
1334 // For now let it be enabled together with other SSE levels.
1335 if (Features[i].substr(1) == "avx") {
1336 HasAVX = true;
1337 continue;
1338 }
1339
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001340 assert(Features[i][0] == '+' && "Invalid target feature!");
1341 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
1342 .Case("sse42", SSE42)
1343 .Case("sse41", SSE41)
1344 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001345 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001346 .Case("sse2", SSE2)
1347 .Case("sse", SSE1)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001348 .Default(NoSSE);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001349 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001350
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001351 MMX3DNowEnum ThreeDNowLevel =
1352 llvm::StringSwitch<MMX3DNowEnum>(Features[i].substr(1))
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001353 .Case("3dnowa", AMD3DNowAthlon)
1354 .Case("3dnow", AMD3DNow)
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001355 .Case("mmx", MMX)
1356 .Default(NoMMX3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001357
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001358 MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001359 }
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001360
1361 // Don't tell the backend if we're turning off mmx; it will end up disabling
1362 // SSE, which we don't want.
1363 std::vector<std::string>::iterator it;
1364 it = std::find(Features.begin(), Features.end(), "-mmx");
1365 if (it != Features.end())
1366 Features.erase(it);
Chris Lattner3daed522009-03-02 22:20:04 +00001367}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001368
1369/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
1370/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001371void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001372 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001373 // Target identification.
1374 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001375 Builder.defineMacro("_LP64");
1376 Builder.defineMacro("__LP64__");
1377 Builder.defineMacro("__amd64__");
1378 Builder.defineMacro("__amd64");
1379 Builder.defineMacro("__x86_64");
1380 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001381 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001382 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001383 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001384
Eric Christophereea12d12010-04-02 23:50:19 +00001385 if (HasAES)
1386 Builder.defineMacro("__AES__");
1387
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001388 if (HasAVX)
1389 Builder.defineMacro("__AVX__");
1390
Chris Lattnerc0f59212009-03-02 22:27:17 +00001391 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001392 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001393
Chris Lattnerc0f59212009-03-02 22:27:17 +00001394 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +00001395 Builder.defineMacro("__nocona");
1396 Builder.defineMacro("__nocona__");
1397 Builder.defineMacro("__tune_nocona__");
1398 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001399
Chris Lattner54175442009-04-19 17:32:33 +00001400 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
1401 // functions in glibc header files that use FP Stack inline asm which the
1402 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00001403 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001404
Chris Lattner84f0ea82009-03-02 22:40:39 +00001405 // Each case falls through to the previous one here.
1406 switch (SSELevel) {
1407 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00001408 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001409 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00001410 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001411 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001412 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001413 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001414 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001415 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00001416 Builder.defineMacro("__SSE2__");
1417 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001418 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00001419 Builder.defineMacro("__SSE__");
1420 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001421 case NoSSE:
Chris Lattner84f0ea82009-03-02 22:40:39 +00001422 break;
1423 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001424
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001425 if (Opts.Microsoft && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001426 switch (SSELevel) {
Michael J. Spencera764e832010-10-21 08:22:51 +00001427 case SSE42:
1428 case SSE41:
1429 case SSSE3:
1430 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001431 case SSE2:
1432 Builder.defineMacro("_M_IX86_FP", llvm::Twine(2));
1433 break;
1434 case SSE1:
1435 Builder.defineMacro("_M_IX86_FP", llvm::Twine(1));
1436 break;
1437 default:
1438 Builder.defineMacro("_M_IX86_FP", llvm::Twine(0));
1439 }
1440 }
1441
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001442 // Each case falls through to the previous one here.
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001443 switch (MMX3DNowLevel) {
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001444 case AMD3DNowAthlon:
1445 Builder.defineMacro("__3dNOW_A__");
1446 case AMD3DNow:
1447 Builder.defineMacro("__3dNOW__");
Eli Friedmanc3e0fb42011-07-08 23:31:17 +00001448 case MMX:
1449 Builder.defineMacro("__MMX__");
1450 case NoMMX3DNow:
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001451 break;
1452 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001453}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001454
1455
Eli Friedman618234a2008-08-20 02:34:37 +00001456bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001457X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001458 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001459 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00001460 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00001461 case 'Y': // first letter of a pair:
1462 switch (*(Name+1)) {
1463 default: return false;
1464 case '0': // First SSE register.
1465 case 't': // Any SSE register, when SSE2 is enabled.
1466 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1467 case 'm': // any MMX register, when inter-unit moves enabled.
1468 break; // falls through to setAllowsRegister.
1469 }
Eli Friedman618234a2008-08-20 02:34:37 +00001470 case 'a': // eax.
1471 case 'b': // ebx.
1472 case 'c': // ecx.
1473 case 'd': // edx.
1474 case 'S': // esi.
1475 case 'D': // edi.
1476 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00001477 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00001478 case 't': // top of floating point stack.
1479 case 'u': // second from top of floating point stack.
1480 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00001481 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00001482 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00001483 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00001484 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1485 case 'l': // "Index" registers: any general register that can be used as an
1486 // index in a base+index memory access.
1487 Info.setAllowsRegister();
1488 return true;
1489 case 'C': // SSE floating point constant.
1490 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001491 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001492 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001493 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001494 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00001495 return true;
1496 }
Dale Johannesen545be512010-08-24 22:33:12 +00001497 return false;
Eli Friedman618234a2008-08-20 02:34:37 +00001498}
1499
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001500
Eli Friedman618234a2008-08-20 02:34:37 +00001501std::string
Stuart Hastings002333f2011-06-07 23:45:05 +00001502X86TargetInfo::convertConstraint(const char *&Constraint) const {
1503 switch (*Constraint) {
Eli Friedman618234a2008-08-20 02:34:37 +00001504 case 'a': return std::string("{ax}");
1505 case 'b': return std::string("{bx}");
1506 case 'c': return std::string("{cx}");
1507 case 'd': return std::string("{dx}");
1508 case 'S': return std::string("{si}");
1509 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00001510 case 'p': // address
1511 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00001512 case 't': // top of floating point stack.
1513 return std::string("{st}");
1514 case 'u': // second from top of floating point stack.
1515 return std::string("{st(1)}"); // second from top of floating point stack.
1516 default:
Stuart Hastings002333f2011-06-07 23:45:05 +00001517 return std::string(1, *Constraint);
Eli Friedman618234a2008-08-20 02:34:37 +00001518 }
1519}
Eli Friedman618234a2008-08-20 02:34:37 +00001520} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00001521
1522namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001523// X86-32 generic target
1524class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001525public:
Eli Friedman618234a2008-08-20 02:34:37 +00001526 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
1527 DoubleAlign = LongLongAlign = 32;
1528 LongDoubleWidth = 96;
1529 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001530 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1531 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001532 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +00001533 SizeType = UnsignedInt;
1534 PtrDiffType = SignedInt;
1535 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001536 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001537
1538 // Use fpret for all types.
1539 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
1540 (1 << TargetInfo::Double) |
1541 (1 << TargetInfo::LongDouble));
Eli Friedman618234a2008-08-20 02:34:37 +00001542 }
1543 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001544 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00001545 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001546
Chris Lattner21fb98e2009-09-23 06:06:36 +00001547 int getEHDataRegisterNumber(unsigned RegNo) const {
1548 if (RegNo == 0) return 0;
1549 if (RegNo == 1) return 2;
1550 return -1;
1551 }
Eli Friedman618234a2008-08-20 02:34:37 +00001552};
1553} // end anonymous namespace
1554
1555namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00001556class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
1557public:
1558 OpenBSDI386TargetInfo(const std::string& triple) :
1559 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
1560 SizeType = UnsignedLong;
1561 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00001562 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00001563 }
1564};
1565} // end anonymous namespace
1566
1567namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001568class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00001569public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00001570 DarwinI386TargetInfo(const std::string& triple) :
1571 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00001572 LongDoubleWidth = 128;
1573 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00001574 SizeType = UnsignedLong;
1575 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001576 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1577 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001578 "a0:0:64-f80:128:128-n8:16:32";
Daniel Dunbar613fd672010-05-27 00:35:16 +00001579 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00001580 }
1581
Eli Friedman618234a2008-08-20 02:34:37 +00001582};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001583} // end anonymous namespace
1584
1585namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00001586// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001587class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00001588public:
1589 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001590 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001591 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00001592 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00001593 DoubleAlign = LongLongAlign = 64;
1594 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 +00001595 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
1596 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +00001597 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001598 virtual void getTargetDefines(const LangOptions &Opts,
1599 MacroBuilder &Builder) const {
1600 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
1601 }
1602};
1603} // end anonymous namespace
1604
1605namespace {
1606
1607// x86-32 Windows Visual Studio target
1608class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1609public:
1610 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1611 : WindowsX86_32TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001612 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00001613 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
1614 }
1615 virtual void getTargetDefines(const LangOptions &Opts,
1616 MacroBuilder &Builder) const {
1617 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1618 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
1619 // The value of the following reflects processor type.
1620 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1621 // We lost the original triple, so we use the default.
1622 Builder.defineMacro("_M_IX86", "600");
1623 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001624};
1625} // end anonymous namespace
1626
1627namespace {
1628// x86-32 MinGW target
1629class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1630public:
1631 MinGWX86_32TargetInfo(const std::string& triple)
1632 : WindowsX86_32TargetInfo(triple) {
1633 }
1634 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001635 MacroBuilder &Builder) const {
1636 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001637 DefineStd(Builder, "WIN32", Opts);
1638 DefineStd(Builder, "WINNT", Opts);
1639 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00001640 Builder.defineMacro("__MSVCRT__");
1641 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001642
1643 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1644 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1645 if (Opts.Microsoft)
1646 // Provide "as-is" __declspec.
1647 Builder.defineMacro("__declspec", "__declspec");
1648 else
1649 // Provide alias of __attribute__ like mingw32-gcc.
1650 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001651 }
1652};
1653} // end anonymous namespace
1654
1655namespace {
1656// x86-32 Cygwin target
1657class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1658public:
1659 CygwinX86_32TargetInfo(const std::string& triple)
1660 : X86_32TargetInfo(triple) {
1661 TLSSupported = false;
1662 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001663 DoubleAlign = LongLongAlign = 64;
1664 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1665 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001666 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001667 }
1668 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001669 MacroBuilder &Builder) const {
1670 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1671 Builder.defineMacro("__CYGWIN__");
1672 Builder.defineMacro("__CYGWIN32__");
1673 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00001674 if (Opts.CPlusPlus)
1675 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00001676 }
Eli Friedman29a30502008-08-21 01:40:19 +00001677};
1678} // end anonymous namespace
1679
1680namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00001681// x86-32 Haiku target
1682class HaikuX86_32TargetInfo : public X86_32TargetInfo {
1683public:
1684 HaikuX86_32TargetInfo(const std::string& triple)
1685 : X86_32TargetInfo(triple) {
1686 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00001687 IntPtrType = SignedLong;
1688 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00001689 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00001690 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00001691 virtual void getTargetDefines(const LangOptions &Opts,
1692 MacroBuilder &Builder) const {
1693 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1694 Builder.defineMacro("__INTEL__");
1695 Builder.defineMacro("__HAIKU__");
1696 }
1697};
1698} // end anonymous namespace
1699
Douglas Gregordca52262011-07-01 22:41:14 +00001700// RTEMS Target
1701template<typename Target>
1702class RTEMSTargetInfo : public OSTargetInfo<Target> {
1703protected:
1704 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
1705 MacroBuilder &Builder) const {
1706 // RTEMS defines; list based off of gcc output
1707
1708 // FIXME: Move version number handling to llvm::Triple.
1709 llvm::StringRef Release = Triple.getOSName().substr(strlen("rtems"), 1);
1710
1711 Builder.defineMacro("__rtems__");
1712 Builder.defineMacro("__ELF__");
1713 }
1714public:
1715 RTEMSTargetInfo(const std::string &triple)
1716 : OSTargetInfo<Target>(triple) {
1717 this->UserLabelPrefix = "";
1718
1719 llvm::Triple Triple(triple);
1720 switch (Triple.getArch()) {
1721 default:
1722 case llvm::Triple::x86:
1723 // this->MCountName = ".mcount";
1724 break;
1725 case llvm::Triple::mips:
1726 case llvm::Triple::mipsel:
1727 case llvm::Triple::ppc:
1728 case llvm::Triple::ppc64:
1729 // this->MCountName = "_mcount";
1730 break;
1731 case llvm::Triple::arm:
1732 // this->MCountName = "__mcount";
1733 break;
1734 }
1735
1736 }
1737};
1738
1739namespace {
1740// x86-32 RTEMS target
1741class RTEMSX86_32TargetInfo : public X86_32TargetInfo {
1742public:
1743 RTEMSX86_32TargetInfo(const std::string& triple)
1744 : X86_32TargetInfo(triple) {
1745 SizeType = UnsignedLong;
1746 IntPtrType = SignedLong;
1747 PtrDiffType = SignedLong;
1748 this->UserLabelPrefix = "";
1749 }
1750 virtual void getTargetDefines(const LangOptions &Opts,
1751 MacroBuilder &Builder) const {
1752 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1753 Builder.defineMacro("__INTEL__");
1754 Builder.defineMacro("__rtems__");
1755 }
1756};
1757} // end anonymous namespace
1758
Chris Lattner86ed3a32010-04-11 19:29:39 +00001759namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001760// x86-64 generic target
1761class X86_64TargetInfo : public X86TargetInfo {
1762public:
Chris Lattner33328642009-03-20 15:52:06 +00001763 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001764 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001765 LongDoubleWidth = 128;
1766 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00001767 LargeArrayMinWidth = 128;
1768 LargeArrayAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001769 IntMaxType = SignedLong;
1770 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001771 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001772 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001773
Eli Friedmaned855cb2008-08-21 00:13:15 +00001774 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1775 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001776 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001777
1778 // Use fpret only for long double.
1779 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Reid Spencer5f016e22007-07-11 17:01:13 +00001780 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001781 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001782 return "typedef struct __va_list_tag {"
1783 " unsigned gp_offset;"
1784 " unsigned fp_offset;"
1785 " void* overflow_arg_area;"
1786 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00001787 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00001788 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001789 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001790
Chris Lattner21fb98e2009-09-23 06:06:36 +00001791 int getEHDataRegisterNumber(unsigned RegNo) const {
1792 if (RegNo == 0) return 0;
1793 if (RegNo == 1) return 1;
1794 return -1;
1795 }
Eli Friedman618234a2008-08-20 02:34:37 +00001796};
1797} // end anonymous namespace
1798
1799namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001800// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001801class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001802public:
1803 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001804 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001805 TLSSupported = false;
1806 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001807 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00001808 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00001809 IntMaxType = SignedLongLong;
1810 UIntMaxType = UnsignedLongLong;
1811 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00001812 SizeType = UnsignedLongLong;
1813 PtrDiffType = SignedLongLong;
1814 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00001815 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001816 }
1817 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001818 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001819 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001820 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00001821 }
NAKAMURA Takumi79521992011-01-17 22:56:23 +00001822 virtual const char *getVAListDeclaration() const {
1823 return "typedef char* __builtin_va_list;";
1824 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001825};
1826} // end anonymous namespace
1827
1828namespace {
1829// x86-64 Windows Visual Studio target
1830class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1831public:
1832 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1833 : WindowsX86_64TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001834 LongDoubleWidth = LongDoubleAlign = 64;
1835 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00001836 }
1837 virtual void getTargetDefines(const LangOptions &Opts,
1838 MacroBuilder &Builder) const {
1839 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1840 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00001841 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001842 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001843 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001844};
1845} // end anonymous namespace
1846
1847namespace {
1848// x86-64 MinGW target
1849class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1850public:
1851 MinGWX86_64TargetInfo(const std::string& triple)
1852 : WindowsX86_64TargetInfo(triple) {
1853 }
1854 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001855 MacroBuilder &Builder) const {
1856 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001857 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00001858 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00001859 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00001860 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001861
1862 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1863 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1864 if (Opts.Microsoft)
1865 // Provide "as-is" __declspec.
1866 Builder.defineMacro("__declspec", "__declspec");
1867 else
1868 // Provide alias of __attribute__ like mingw32-gcc.
1869 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001870 }
1871};
1872} // end anonymous namespace
1873
1874namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001875class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1876public:
Mike Stump1eb44332009-09-09 15:08:12 +00001877 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001878 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1879 Int64Type = SignedLongLong;
1880 }
1881};
1882} // end anonymous namespace
1883
1884namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001885class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1886public:
Mike Stump1eb44332009-09-09 15:08:12 +00001887 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001888 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1889 IntMaxType = SignedLongLong;
1890 UIntMaxType = UnsignedLongLong;
1891 Int64Type = SignedLongLong;
1892 }
1893};
1894} // end anonymous namespace
1895
1896namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001897class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001898 // Possible FPU choices.
1899 enum FPUMode {
1900 NoFPU,
1901 VFP2FPU,
1902 VFP3FPU,
1903 NeonFPU
1904 };
1905
1906 static bool FPUModeIsVFP(FPUMode Mode) {
1907 return Mode >= VFP2FPU && Mode <= NeonFPU;
1908 }
1909
1910 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1911 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001912
Daniel Dunbareac7c532009-12-18 18:42:37 +00001913 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001914
1915 unsigned FPU : 3;
1916
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001917 unsigned IsThumb : 1;
1918
1919 // Initialized via features.
1920 unsigned SoftFloat : 1;
1921 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001922
Chris Lattner2752c012010-03-03 19:03:45 +00001923 static const Builtin::Info BuiltinInfo[];
1924
Chris Lattner393ff042008-04-21 18:56:49 +00001925public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001926 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001927 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001928 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001929 SizeType = UnsignedInt;
1930 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001931
Chris Lattner9bffb072010-04-23 16:29:58 +00001932 // {} in inline assembly are neon specifiers, not assembly variant
1933 // specifiers.
1934 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00001935
Daniel Dunbareac7c532009-12-18 18:42:37 +00001936 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001937 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001938 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001939 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1940 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001941 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1942 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001943 "v64:64:64-v128:64:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001944 } else {
1945 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1946 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001947 "v64:64:64-v128:64:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001948 }
John McCallee79a4c2010-08-21 22:46:04 +00001949
1950 // ARM targets default to using the ARM C++ ABI.
1951 CXXABI = CXXABI_ARM;
Eli Friedman61538a72008-05-20 14:21:01 +00001952 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001953 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001954 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001955 ABI = Name;
1956
Daniel Dunbara2a41612009-09-14 00:02:24 +00001957 // The defaults (above) are for AAPCS, check if we need to change them.
1958 //
1959 // FIXME: We need support for -meabi... we could just mangle it into the
1960 // name.
1961 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001962 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001963 SizeType = UnsignedLong;
1964
Daniel Dunbar684de632010-04-22 16:14:54 +00001965 // Do not respect the alignment of bit-field types when laying out
1966 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
1967 UseBitFieldTypeAlignment = false;
1968
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001969 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001970 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1971 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001972 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 +00001973 "i64:32:64-f32:32:32-f64:32:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001974 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001975 } else {
1976 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 +00001977 "i64:32:64-f32:32:32-f64:32:64-"
1978 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001979 }
1980
Daniel Dunbara2a41612009-09-14 00:02:24 +00001981 // FIXME: Override "preferred align" for double and long long.
1982 } else if (Name == "aapcs") {
1983 // FIXME: Enumerated types are variable width in straight AAPCS.
1984 } else if (Name == "aapcs-linux") {
1985 ;
1986 } else
1987 return false;
1988
1989 return true;
1990 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001991
Daniel Dunbara91320b2009-12-21 23:28:17 +00001992 void getDefaultFeatures(const std::string &CPU,
1993 llvm::StringMap<bool> &Features) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001994 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
1995 Features["vfp2"] = true;
1996 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
1997 Features["neon"] = true;
1998 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001999
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002000 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2001 const std::string &Name,
2002 bool Enabled) const {
Evan Chengf972b262011-07-08 06:40:11 +00002003 if (Name == "soft-float" || Name == "soft-float-abi" ||
2004 Name == "vfp2" || Name == "vfp3" || Name == "neon") {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002005 Features[Name] = Enabled;
2006 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002007 return false;
2008
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002009 return true;
2010 }
2011
2012 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00002013 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002014 SoftFloat = SoftFloatABI = false;
2015 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
2016 if (Features[i] == "+soft-float")
2017 SoftFloat = true;
2018 else if (Features[i] == "+soft-float-abi")
2019 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00002020 else if (Features[i] == "+vfp2")
2021 FPU = VFP2FPU;
2022 else if (Features[i] == "+vfp3")
2023 FPU = VFP3FPU;
2024 else if (Features[i] == "+neon")
2025 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002026 }
2027
2028 // Remove front-end specific options which the backend handles differently.
2029 std::vector<std::string>::iterator it;
2030 it = std::find(Features.begin(), Features.end(), "+soft-float");
2031 if (it != Features.end())
2032 Features.erase(it);
2033 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
2034 if (it != Features.end())
2035 Features.erase(it);
2036 }
2037
Daniel Dunbareac7c532009-12-18 18:42:37 +00002038 static const char *getCPUDefineSuffix(llvm::StringRef Name) {
2039 return llvm::StringSwitch<const char*>(Name)
2040 .Cases("arm8", "arm810", "4")
2041 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
2042 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
2043 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
2044 .Case("ep9312", "4T")
2045 .Cases("arm10tdmi", "arm1020t", "5T")
2046 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
2047 .Case("arm926ej-s", "5TEJ")
2048 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
2049 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002050 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002051 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00002052 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002053 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
2054 .Cases("cortex-a8", "cortex-a9", "7A")
Bob Wilson06f45632011-01-06 16:57:20 +00002055 .Case("cortex-m3", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00002056 .Case("cortex-m0", "6M")
Daniel Dunbareac7c532009-12-18 18:42:37 +00002057 .Default(0);
2058 }
2059 virtual bool setCPU(const std::string &Name) {
2060 if (!getCPUDefineSuffix(Name))
2061 return false;
2062
2063 CPU = Name;
2064 return true;
2065 }
Chris Lattner33328642009-03-20 15:52:06 +00002066 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002067 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00002068 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00002069 Builder.defineMacro("__arm");
2070 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002071
Chris Lattnerc0f59212009-03-02 22:27:17 +00002072 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00002073 Builder.defineMacro("__ARMEL__");
2074 Builder.defineMacro("__LITTLE_ENDIAN__");
2075 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002076
2077 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00002078 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002079
Mike Stump437bb4b2009-04-08 02:07:04 +00002080 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002081
Daniel Dunbareac7c532009-12-18 18:42:37 +00002082 // FIXME: It's more complicated than this and we don't really support
2083 // interworking.
2084 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00002085 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002086
Daniel Dunbareac7c532009-12-18 18:42:37 +00002087 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00002088 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002089
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00002090 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00002091 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00002092
2093 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00002094 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002095
Bob Wilson84f95cf2011-05-13 18:56:03 +00002096 bool IsARMv7 = CPUArch.startswith("7");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002097 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00002098 Builder.defineMacro("__THUMBEL__");
2099 Builder.defineMacro("__thumb__");
Bob Wilson84f95cf2011-05-13 18:56:03 +00002100 if (CPUArch == "6T2" || IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002101 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00002102 }
2103
2104 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00002105 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002106
2107 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00002108 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00002109
2110 // This only gets set when Neon instructions are actually available, unlike
2111 // the VFP define, hence the soft float and arch check. This is subtly
2112 // different from gcc, we follow the intent which was that it should be set
2113 // when Neon instructions are actually available.
Bob Wilson84f95cf2011-05-13 18:56:03 +00002114 if (FPU == NeonFPU && !SoftFloat && IsARMv7)
Benjamin Kramera9992772010-01-09 17:55:51 +00002115 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00002116 }
2117 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2118 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00002119 Records = BuiltinInfo;
2120 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00002121 }
2122 virtual const char *getVAListDeclaration() const {
John McCall0e9972c2011-05-09 02:19:37 +00002123 return "typedef void* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00002124 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002125 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002126 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002127 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002128 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002129 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00002130 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002131 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002132 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00002133 default:
Nate Begemanad487f42008-04-22 05:03:19 +00002134 case 'l': // r0-r7
2135 case 'h': // r8-r15
2136 case 'w': // VFP Floating point register single precision
2137 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00002138 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00002139 return true;
Stuart Hastings002333f2011-06-07 23:45:05 +00002140 case 'U': // a memory reference...
2141 switch (Name[1]) {
2142 case 'q': // ...ARMV4 ldrsb
2143 case 'v': // ...VFP load/store (reg+constant offset)
2144 case 'y': // ...iWMMXt load/store
Eric Christopherdda231a2011-06-17 01:40:49 +00002145 case 't': // address valid for load/store opaque types wider
2146 // than 128-bits
2147 case 'n': // valid address for Neon doubleword vector load/store
2148 case 'm': // valid address for Neon element and structure load/store
2149 case 's': // valid address for non-offset loads/stores of quad-word
2150 // values in four ARM registers
Stuart Hastings002333f2011-06-07 23:45:05 +00002151 Info.setAllowsMemory();
2152 Name++;
2153 return true;
2154 }
Nate Begemanad487f42008-04-22 05:03:19 +00002155 }
Chris Lattner393ff042008-04-21 18:56:49 +00002156 return false;
2157 }
Evan Cheng8bfa2572011-06-16 19:13:15 +00002158 virtual std::string convertConstraint(const char *&Constraint) const {
Stuart Hastings002333f2011-06-07 23:45:05 +00002159 std::string R;
2160 switch (*Constraint) {
2161 case 'U': // Two-character constraint; add "^" hint for later parsing.
Stuart Hastings6ce33d62011-06-08 16:06:31 +00002162 R = std::string("^") + std::string(Constraint, 2);
Stuart Hastings002333f2011-06-07 23:45:05 +00002163 Constraint++;
2164 break;
Eric Christopher283f4472011-06-17 00:40:18 +00002165 case 'p': // 'p' should be translated to 'r' by default.
2166 R = std::string("r");
2167 break;
Stuart Hastings002333f2011-06-07 23:45:05 +00002168 default:
2169 return std::string(1, *Constraint);
2170 }
2171 return R;
2172 }
Chris Lattner393ff042008-04-21 18:56:49 +00002173 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00002174 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00002175 return "";
2176 }
2177};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002178
2179const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002180 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002181 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002182 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
2183
2184 // Float registers
2185 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
2186 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
2187 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002188 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00002189
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002190 // Double registers
2191 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
2192 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00002193 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
2194 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002195
2196 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00002197 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
2198 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002199};
2200
2201void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00002202 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002203 Names = GCCRegNames;
2204 NumNames = llvm::array_lengthof(GCCRegNames);
2205}
2206
2207const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002208 { { "a1" }, "r0" },
2209 { { "a2" }, "r1" },
2210 { { "a3" }, "r2" },
2211 { { "a4" }, "r3" },
2212 { { "v1" }, "r4" },
2213 { { "v2" }, "r5" },
2214 { { "v3" }, "r6" },
2215 { { "v4" }, "r7" },
2216 { { "v5" }, "r8" },
2217 { { "v6", "rfp" }, "r9" },
2218 { { "sl" }, "r10" },
2219 { { "fp" }, "r11" },
2220 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00002221 { { "r13" }, "sp" },
2222 { { "r14" }, "lr" },
2223 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00002224 // The S, D and Q registers overlap, but aren't really aliases; we
2225 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002226};
2227
2228void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2229 unsigned &NumAliases) const {
2230 Aliases = GCCRegAliases;
2231 NumAliases = llvm::array_lengthof(GCCRegAliases);
2232}
Chris Lattner2752c012010-03-03 19:03:45 +00002233
2234const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Eli Friedmane7e66f72011-07-05 21:53:01 +00002235#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
Fariborz Jahanian67aba812010-11-30 17:35:24 +00002236#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
Eli Friedmane7e66f72011-07-05 21:53:01 +00002237 ALL_LANGUAGES },
Chris Lattner2752c012010-03-03 19:03:45 +00002238#include "clang/Basic/BuiltinsARM.def"
2239};
Chris Lattner393ff042008-04-21 18:56:49 +00002240} // end anonymous namespace.
2241
Eli Friedmana9f54962008-08-20 07:44:10 +00002242
2243namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00002244class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002245 public DarwinTargetInfo<ARMTargetInfo> {
2246protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002247 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00002248 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00002249 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00002250 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002251
Torok Edwin5f6c1942009-06-30 17:10:35 +00002252public:
Mike Stump1eb44332009-09-09 15:08:12 +00002253 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00002254 : DarwinTargetInfo<ARMTargetInfo>(triple) {
2255 HasAlignMac68kSupport = true;
2256 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002257};
2258} // end anonymous namespace.
2259
Reid Spencer5f016e22007-07-11 17:01:13 +00002260namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00002261class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00002262 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2263 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002264 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00002265public:
Eli Friedman01b86682008-08-20 07:28:14 +00002266 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
2267 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00002268 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 +00002269 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00002270 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002271 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2272 const std::string &Name,
2273 bool Enabled) const {
2274 if (Name == "soft-float")
2275 Features[Name] = Enabled;
2276 else
2277 return false;
2278
2279 return true;
2280 }
2281 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
2282 SoftFloat = false;
2283 for (unsigned i = 0, e = Features.size(); i != e; ++i)
2284 if (Features[i] == "+soft-float")
2285 SoftFloat = true;
2286 }
Chris Lattner33328642009-03-20 15:52:06 +00002287 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002288 MacroBuilder &Builder) const {
2289 DefineStd(Builder, "sparc", Opts);
2290 Builder.defineMacro("__sparcv8");
2291 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002292
2293 if (SoftFloat)
2294 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00002295 }
2296 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2297 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002298 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00002299 }
2300 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002301 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00002302 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002303 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002304 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002305 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002306 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002307 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00002308 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002309 // FIXME: Implement!
2310 return false;
Gabor Greif26658672008-02-21 16:29:08 +00002311 }
2312 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002313 // FIXME: Implement!
2314 return "";
Gabor Greif26658672008-02-21 16:29:08 +00002315 }
2316};
2317
Chris Lattnere957f532009-01-27 01:58:38 +00002318const char * const SparcV8TargetInfo::GCCRegNames[] = {
2319 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2320 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2321 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2322 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
2323};
2324
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002325void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002326 unsigned &NumNames) const {
2327 Names = GCCRegNames;
2328 NumNames = llvm::array_lengthof(GCCRegNames);
2329}
2330
2331const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002332 { { "g0" }, "r0" },
2333 { { "g1" }, "r1" },
2334 { { "g2" }, "r2" },
2335 { { "g3" }, "r3" },
2336 { { "g4" }, "r4" },
2337 { { "g5" }, "r5" },
2338 { { "g6" }, "r6" },
2339 { { "g7" }, "r7" },
2340 { { "o0" }, "r8" },
2341 { { "o1" }, "r9" },
2342 { { "o2" }, "r10" },
2343 { { "o3" }, "r11" },
2344 { { "o4" }, "r12" },
2345 { { "o5" }, "r13" },
2346 { { "o6", "sp" }, "r14" },
2347 { { "o7" }, "r15" },
2348 { { "l0" }, "r16" },
2349 { { "l1" }, "r17" },
2350 { { "l2" }, "r18" },
2351 { { "l3" }, "r19" },
2352 { { "l4" }, "r20" },
2353 { { "l5" }, "r21" },
2354 { { "l6" }, "r22" },
2355 { { "l7" }, "r23" },
2356 { { "i0" }, "r24" },
2357 { { "i1" }, "r25" },
2358 { { "i2" }, "r26" },
2359 { { "i3" }, "r27" },
2360 { { "i4" }, "r28" },
2361 { { "i5" }, "r29" },
2362 { { "i6", "fp" }, "r30" },
2363 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00002364};
2365
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002366void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002367 unsigned &NumAliases) const {
2368 Aliases = GCCRegAliases;
2369 NumAliases = llvm::array_lengthof(GCCRegAliases);
2370}
Gabor Greif26658672008-02-21 16:29:08 +00002371} // end anonymous namespace.
2372
Eli Friedman01b86682008-08-20 07:28:14 +00002373namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002374class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
2375public:
2376 AuroraUXSparcV8TargetInfo(const std::string& triple) :
2377 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
2378 SizeType = UnsignedInt;
2379 PtrDiffType = SignedInt;
2380 }
2381};
Torok Edwin5f6c1942009-06-30 17:10:35 +00002382class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00002383public:
2384 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002385 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00002386 SizeType = UnsignedInt;
2387 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00002388 }
2389};
2390} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00002391
Chris Lattner2621fd12008-05-08 05:58:21 +00002392namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002393 class MSP430TargetInfo : public TargetInfo {
2394 static const char * const GCCRegNames[];
2395 public:
2396 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
2397 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00002398 IntWidth = 16; IntAlign = 16;
2399 LongWidth = 32; LongLongWidth = 64;
2400 LongAlign = LongLongAlign = 16;
2401 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002402 SizeType = UnsignedInt;
2403 IntMaxType = SignedLong;
2404 UIntMaxType = UnsignedLong;
2405 IntPtrType = SignedShort;
2406 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00002407 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00002408 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002409 }
2410 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002411 MacroBuilder &Builder) const {
2412 Builder.defineMacro("MSP430");
2413 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002414 // FIXME: defines for different 'flavours' of MCU
2415 }
2416 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2417 unsigned &NumRecords) const {
2418 // FIXME: Implement.
2419 Records = 0;
2420 NumRecords = 0;
2421 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002422 virtual void getGCCRegNames(const char * const *&Names,
2423 unsigned &NumNames) const;
2424 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2425 unsigned &NumAliases) const {
2426 // No aliases.
2427 Aliases = 0;
2428 NumAliases = 0;
2429 }
2430 virtual bool validateAsmConstraint(const char *&Name,
2431 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00002432 // No target constraints for now.
2433 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002434 }
2435 virtual const char *getClobbers() const {
2436 // FIXME: Is this really right?
2437 return "";
2438 }
2439 virtual const char *getVAListDeclaration() const {
2440 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00002441 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002442 }
2443 };
2444
2445 const char * const MSP430TargetInfo::GCCRegNames[] = {
2446 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2447 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2448 };
2449
2450 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
2451 unsigned &NumNames) const {
2452 Names = GCCRegNames;
2453 NumNames = llvm::array_lengthof(GCCRegNames);
2454 }
2455}
2456
2457
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002458namespace {
2459 class SystemZTargetInfo : public TargetInfo {
2460 static const char * const GCCRegNames[];
2461 public:
2462 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
2463 TLSSupported = false;
2464 IntWidth = IntAlign = 32;
2465 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
2466 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00002467 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
2468 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002469 }
2470 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002471 MacroBuilder &Builder) const {
2472 Builder.defineMacro("__s390__");
2473 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002474 }
2475 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2476 unsigned &NumRecords) const {
2477 // FIXME: Implement.
2478 Records = 0;
2479 NumRecords = 0;
2480 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002481
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002482 virtual void getGCCRegNames(const char * const *&Names,
2483 unsigned &NumNames) const;
2484 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2485 unsigned &NumAliases) const {
2486 // No aliases.
2487 Aliases = 0;
2488 NumAliases = 0;
2489 }
2490 virtual bool validateAsmConstraint(const char *&Name,
2491 TargetInfo::ConstraintInfo &info) const {
2492 // FIXME: implement
2493 return true;
2494 }
2495 virtual const char *getClobbers() const {
2496 // FIXME: Is this really right?
2497 return "";
2498 }
2499 virtual const char *getVAListDeclaration() const {
2500 // FIXME: implement
2501 return "typedef char* __builtin_va_list;";
2502 }
2503 };
2504
2505 const char * const SystemZTargetInfo::GCCRegNames[] = {
2506 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2507 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2508 };
2509
2510 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
2511 unsigned &NumNames) const {
2512 Names = GCCRegNames;
2513 NumNames = llvm::array_lengthof(GCCRegNames);
2514 }
2515}
2516
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002517namespace {
2518 class BlackfinTargetInfo : public TargetInfo {
2519 static const char * const GCCRegNames[];
2520 public:
2521 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
2522 TLSSupported = false;
2523 DoubleAlign = 32;
2524 LongLongAlign = 32;
2525 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00002526 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002527 }
2528
2529 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002530 MacroBuilder &Builder) const {
2531 DefineStd(Builder, "bfin", Opts);
2532 DefineStd(Builder, "BFIN", Opts);
2533 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002534 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00002535 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002536 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
2537 }
2538
2539 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2540 unsigned &NumRecords) const {
2541 // FIXME: Implement.
2542 Records = 0;
2543 NumRecords = 0;
2544 }
2545
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002546 virtual void getGCCRegNames(const char * const *&Names,
2547 unsigned &NumNames) const;
2548
2549 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2550 unsigned &NumAliases) const {
2551 // No aliases.
2552 Aliases = 0;
2553 NumAliases = 0;
2554 }
2555
2556 virtual bool validateAsmConstraint(const char *&Name,
2557 TargetInfo::ConstraintInfo &Info) const {
2558 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
2559 Info.setAllowsRegister();
2560 return true;
2561 }
2562 return false;
2563 }
2564
2565 virtual const char *getClobbers() const {
2566 return "";
2567 }
2568
2569 virtual const char *getVAListDeclaration() const {
2570 return "typedef char* __builtin_va_list;";
2571 }
2572 };
2573
2574 const char * const BlackfinTargetInfo::GCCRegNames[] = {
2575 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2576 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
2577 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
2578 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
2579 "a0", "a1", "cc",
2580 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
2581 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
2582 };
2583
2584 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
2585 unsigned &NumNames) const {
2586 Names = GCCRegNames;
2587 NumNames = llvm::array_lengthof(GCCRegNames);
2588 }
2589}
2590
Eli Friedmanb63decf2009-08-19 20:47:07 +00002591namespace {
2592
Mike Stump1eb44332009-09-09 15:08:12 +00002593 // LLVM and Clang cannot be used directly to output native binaries for
2594 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00002595 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00002596 //
2597 // TCE uses the llvm bitcode as input and uses it for generating customized
2598 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00002599 // publicly available in http://tce.cs.tut.fi
2600
2601 class TCETargetInfo : public TargetInfo{
2602 public:
2603 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
2604 TLSSupported = false;
2605 IntWidth = 32;
2606 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00002607 PointerWidth = 32;
2608 IntAlign = 32;
2609 LongAlign = LongLongAlign = 32;
2610 PointerAlign = 32;
2611 SizeType = UnsignedInt;
2612 IntMaxType = SignedLong;
2613 UIntMaxType = UnsignedLong;
2614 IntPtrType = SignedInt;
2615 PtrDiffType = SignedInt;
2616 FloatWidth = 32;
2617 FloatAlign = 32;
2618 DoubleWidth = 32;
2619 DoubleAlign = 32;
2620 LongDoubleWidth = 32;
2621 LongDoubleAlign = 32;
2622 FloatFormat = &llvm::APFloat::IEEEsingle;
2623 DoubleFormat = &llvm::APFloat::IEEEsingle;
2624 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00002625 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
2626 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00002627 "f32:32:32-f64:32:32-v64:32:32-"
2628 "v128:32:32-a0:0:32-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00002629 }
2630
2631 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002632 MacroBuilder &Builder) const {
2633 DefineStd(Builder, "tce", Opts);
2634 Builder.defineMacro("__TCE__");
2635 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00002636 }
2637 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2638 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00002639 virtual const char *getClobbers() const {
2640 return "";
2641 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002642 virtual const char *getVAListDeclaration() const {
2643 return "typedef void* __builtin_va_list;";
2644 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002645 virtual void getGCCRegNames(const char * const *&Names,
2646 unsigned &NumNames) const {}
2647 virtual bool validateAsmConstraint(const char *&Name,
2648 TargetInfo::ConstraintInfo &info) const {
2649 return true;
2650 }
2651 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2652 unsigned &NumAliases) const {}
2653 };
2654}
2655
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002656namespace {
2657class MipsTargetInfo : public TargetInfo {
Eric Christophered734732010-03-02 02:41:08 +00002658 std::string ABI, CPU;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002659 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2660 static const char * const GCCRegNames[];
2661public:
Eric Christophered734732010-03-02 02:41:08 +00002662 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002663 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 +00002664 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
2665 SizeType = UnsignedInt;
2666 PtrDiffType = SignedInt;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002667 }
Eric Christophered734732010-03-02 02:41:08 +00002668 virtual const char *getABI() const { return ABI.c_str(); }
2669 virtual bool setABI(const std::string &Name) {
2670
2671 if ((Name == "o32") || (Name == "eabi")) {
2672 ABI = Name;
2673 return true;
2674 } else
2675 return false;
2676 }
2677 virtual bool setCPU(const std::string &Name) {
2678 CPU = Name;
2679 return true;
2680 }
2681 void getDefaultFeatures(const std::string &CPU,
2682 llvm::StringMap<bool> &Features) const {
2683 Features[ABI] = true;
2684 Features[CPU] = true;
2685 }
2686 virtual void getArchDefines(const LangOptions &Opts,
2687 MacroBuilder &Builder) const {
2688 if (ABI == "o32")
2689 Builder.defineMacro("__mips_o32");
2690 else if (ABI == "eabi")
2691 Builder.defineMacro("__mips_eabi");
2692 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002693 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002694 MacroBuilder &Builder) const {
2695 DefineStd(Builder, "mips", Opts);
2696 Builder.defineMacro("_mips");
2697 DefineStd(Builder, "MIPSEB", Opts);
2698 Builder.defineMacro("_MIPSEB");
2699 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002700 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002701 }
2702 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2703 unsigned &NumRecords) const {
2704 // FIXME: Implement!
2705 }
2706 virtual const char *getVAListDeclaration() const {
2707 return "typedef void* __builtin_va_list;";
2708 }
2709 virtual void getGCCRegNames(const char * const *&Names,
2710 unsigned &NumNames) const;
2711 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2712 unsigned &NumAliases) const;
2713 virtual bool validateAsmConstraint(const char *&Name,
2714 TargetInfo::ConstraintInfo &Info) const {
2715 switch (*Name) {
2716 default:
2717 case 'r': // CPU registers.
2718 case 'd': // Equivalent to "r" unless generating MIPS16 code.
2719 case 'y': // Equivalent to "r", backwards compatibility only.
2720 case 'f': // floating-point registers.
2721 Info.setAllowsRegister();
2722 return true;
2723 }
2724 return false;
2725 }
2726
2727 virtual const char *getClobbers() const {
2728 // FIXME: Implement!
2729 return "";
2730 }
2731};
2732
2733const char * const MipsTargetInfo::GCCRegNames[] = {
Michael J. Spencer20249a12010-10-21 03:16:25 +00002734 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002735 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2736 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
2737 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
2738 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
2739 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
2740 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
2741 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
2742 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
2743 "$fcc5","$fcc6","$fcc7"
2744};
2745
2746void MipsTargetInfo::getGCCRegNames(const char * const *&Names,
2747 unsigned &NumNames) const {
2748 Names = GCCRegNames;
2749 NumNames = llvm::array_lengthof(GCCRegNames);
2750}
2751
2752const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = {
2753 { { "at" }, "$1" },
2754 { { "v0" }, "$2" },
2755 { { "v1" }, "$3" },
2756 { { "a0" }, "$4" },
2757 { { "a1" }, "$5" },
2758 { { "a2" }, "$6" },
2759 { { "a3" }, "$7" },
2760 { { "t0" }, "$8" },
2761 { { "t1" }, "$9" },
2762 { { "t2" }, "$10" },
2763 { { "t3" }, "$11" },
2764 { { "t4" }, "$12" },
2765 { { "t5" }, "$13" },
2766 { { "t6" }, "$14" },
2767 { { "t7" }, "$15" },
2768 { { "s0" }, "$16" },
2769 { { "s1" }, "$17" },
2770 { { "s2" }, "$18" },
2771 { { "s3" }, "$19" },
2772 { { "s4" }, "$20" },
2773 { { "s5" }, "$21" },
2774 { { "s6" }, "$22" },
2775 { { "s7" }, "$23" },
2776 { { "t8" }, "$24" },
2777 { { "t9" }, "$25" },
2778 { { "k0" }, "$26" },
2779 { { "k1" }, "$27" },
2780 { { "gp" }, "$28" },
2781 { { "sp" }, "$29" },
2782 { { "fp" }, "$30" },
2783 { { "ra" }, "$31" }
2784};
2785
2786void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2787 unsigned &NumAliases) const {
2788 Aliases = GCCRegAliases;
2789 NumAliases = llvm::array_lengthof(GCCRegAliases);
2790}
2791} // end anonymous namespace.
2792
2793namespace {
2794class MipselTargetInfo : public MipsTargetInfo {
2795public:
2796 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) {
2797 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 +00002798 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002799 }
2800
2801 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002802 MacroBuilder &Builder) const;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002803};
2804
2805void MipselTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002806 MacroBuilder &Builder) const {
2807 DefineStd(Builder, "mips", Opts);
2808 Builder.defineMacro("_mips");
2809 DefineStd(Builder, "MIPSEL", Opts);
2810 Builder.defineMacro("_MIPSEL");
2811 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002812 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002813}
2814} // end anonymous namespace.
2815
Reid Spencer5f016e22007-07-11 17:01:13 +00002816//===----------------------------------------------------------------------===//
2817// Driver code
2818//===----------------------------------------------------------------------===//
2819
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002820static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002821 llvm::Triple Triple(T);
2822 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00002823
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002824 switch (Triple.getArch()) {
2825 default:
2826 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00002827
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002828 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00002829 case llvm::Triple::thumb:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00002830 if (Triple.isOSDarwin())
2831 return new DarwinARMTargetInfo(T);
2832
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002833 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00002834 case llvm::Triple::Linux:
2835 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002836 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002837 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002838 case llvm::Triple::NetBSD:
2839 return new NetBSDTargetInfo<ARMTargetInfo>(T);
Douglas Gregordca52262011-07-01 22:41:14 +00002840 case llvm::Triple::RTEMS:
2841 return new RTEMSTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002842 default:
2843 return new ARMTargetInfo(T);
2844 }
Eli Friedman61538a72008-05-20 14:21:01 +00002845
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002846 case llvm::Triple::bfin:
Douglas Gregordca52262011-07-01 22:41:14 +00002847 if ( os == llvm::Triple::RTEMS )
2848 return new RTEMSTargetInfo<BlackfinTargetInfo>(T);
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002849 return new BlackfinTargetInfo(T);
2850
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002851 case llvm::Triple::msp430:
2852 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00002853
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002854 case llvm::Triple::mips:
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00002855 switch (os) {
2856 case llvm::Triple::Psp:
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002857 return new PSPTargetInfo<MipsTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00002858 case llvm::Triple::Linux:
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002859 return new LinuxTargetInfo<MipsTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00002860 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00002861 return new RTEMSTargetInfo<MipsTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00002862 case llvm::Triple::FreeBSD:
Joerg Sonnenberger8e627062011-07-07 17:01:45 +00002863 return new FreeBSDTargetInfo<MipsTargetInfo>(T);
Joerg Sonnenbergerfa9772b2011-07-05 18:05:54 +00002864 case llvm::Triple::NetBSD:
2865 return new NetBSDTargetInfo<MipsTargetInfo>(T);
2866 default:
2867 return new MipsTargetInfo(T);
2868 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002869
2870 case llvm::Triple::mipsel:
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00002871 switch (os) {
2872 case llvm::Triple::Psp:
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002873 return new PSPTargetInfo<MipselTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00002874 case llvm::Triple::Linux:
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002875 return new LinuxTargetInfo<MipselTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00002876 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00002877 return new RTEMSTargetInfo<MipselTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00002878 case llvm::Triple::FreeBSD:
Joerg Sonnenbergercaf01c52011-07-06 11:00:56 +00002879 return new FreeBSDTargetInfo<MipselTargetInfo>(T);
Joerg Sonnenberger94c9ce52011-07-05 18:24:04 +00002880 case llvm::Triple::NetBSD:
2881 return new NetBSDTargetInfo<MipselTargetInfo>(T);
2882 default:
2883 return new MipsTargetInfo(T);
2884 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002885
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002886 case llvm::Triple::ppc:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00002887 if (Triple.isOSDarwin())
Roman Divackyc81f2a22011-01-06 08:27:10 +00002888 return new DarwinPPC32TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002889 switch (os) {
2890 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00002891 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002892 case llvm::Triple::NetBSD:
2893 return new NetBSDTargetInfo<PPC32TargetInfo>(T);
2894 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00002895 return new RTEMSTargetInfo<PPC32TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002896 default:
2897 return new PPC32TargetInfo(T);
2898 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002899
2900 case llvm::Triple::ppc64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00002901 if (Triple.isOSDarwin())
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00002902 return new DarwinPPC64TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002903 switch (os) {
2904 case llvm::Triple::Lv2:
John Thompson3f6918a2009-11-19 17:18:50 +00002905 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002906 case llvm::Triple::FreeBSD:
Chris Lattnere03ae302010-02-16 18:14:57 +00002907 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002908 case llvm::Triple::NetBSD:
2909 return new NetBSDTargetInfo<PPC64TargetInfo>(T);
2910 default:
2911 return new PPC64TargetInfo(T);
2912 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002913
Justin Holewinski285dc652011-04-20 19:34:15 +00002914 case llvm::Triple::ptx32:
2915 return new PTX32TargetInfo(T);
2916 case llvm::Triple::ptx64:
2917 return new PTX64TargetInfo(T);
2918
Chris Lattner9cbeb632010-03-06 21:21:27 +00002919 case llvm::Triple::mblaze:
2920 return new MBlazeTargetInfo(T);
2921
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002922 case llvm::Triple::sparc:
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002923 switch (os) {
2924 case llvm::Triple::AuroraUX:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002925 return new AuroraUXSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002926 case llvm::Triple::Solaris:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002927 return new SolarisSparcV8TargetInfo(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002928 case llvm::Triple::NetBSD:
2929 return new NetBSDTargetInfo<SparcV8TargetInfo>(T);
2930 case llvm::Triple::RTEMS:
Douglas Gregordca52262011-07-01 22:41:14 +00002931 return new RTEMSTargetInfo<SparcV8TargetInfo>(T);
Joerg Sonnenberger9a11b742011-07-04 21:59:44 +00002932 default:
2933 return new SparcV8TargetInfo(T);
2934 }
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002935
John Thompson3f6918a2009-11-19 17:18:50 +00002936 // FIXME: Need a real SPU target.
2937 case llvm::Triple::cellspu:
2938 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
2939
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002940 case llvm::Triple::systemz:
2941 return new SystemZTargetInfo(T);
2942
Eli Friedmanb63decf2009-08-19 20:47:07 +00002943 case llvm::Triple::tce:
2944 return new TCETargetInfo(T);
2945
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002946 case llvm::Triple::x86:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00002947 if (Triple.isOSDarwin())
2948 return new DarwinI386TargetInfo(T);
2949
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002950 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002951 case llvm::Triple::AuroraUX:
2952 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002953 case llvm::Triple::Linux:
2954 return new LinuxTargetInfo<X86_32TargetInfo>(T);
2955 case llvm::Triple::DragonFly:
2956 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
2957 case llvm::Triple::NetBSD:
2958 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
2959 case llvm::Triple::OpenBSD:
2960 return new OpenBSDI386TargetInfo(T);
2961 case llvm::Triple::FreeBSD:
2962 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00002963 case llvm::Triple::Minix:
2964 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002965 case llvm::Triple::Solaris:
2966 return new SolarisTargetInfo<X86_32TargetInfo>(T);
2967 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002968 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002969 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002970 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002971 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00002972 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00002973 case llvm::Triple::Haiku:
2974 return new HaikuX86_32TargetInfo(T);
Douglas Gregordca52262011-07-01 22:41:14 +00002975 case llvm::Triple::RTEMS:
2976 return new RTEMSX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002977 default:
2978 return new X86_32TargetInfo(T);
2979 }
2980
2981 case llvm::Triple::x86_64:
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00002982 if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO)
2983 return new DarwinX86_64TargetInfo(T);
2984
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002985 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002986 case llvm::Triple::AuroraUX:
2987 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002988 case llvm::Triple::Linux:
2989 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00002990 case llvm::Triple::DragonFly:
2991 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002992 case llvm::Triple::NetBSD:
2993 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
2994 case llvm::Triple::OpenBSD:
2995 return new OpenBSDX86_64TargetInfo(T);
2996 case llvm::Triple::FreeBSD:
2997 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
2998 case llvm::Triple::Solaris:
2999 return new SolarisTargetInfo<X86_64TargetInfo>(T);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00003000 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00003001 return new MinGWX86_64TargetInfo(T);
3002 case llvm::Triple::Win32: // This is what Triple.h supports now.
Daniel Dunbardb57a4c2011-04-19 21:43:27 +00003003 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00003004 default:
3005 return new X86_64TargetInfo(T);
3006 }
3007 }
Reid Spencer5f016e22007-07-11 17:01:13 +00003008}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003009
3010/// CreateTargetInfo - Return the target info object for the specified target
3011/// triple.
3012TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003013 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003014 llvm::Triple Triple(Opts.Triple);
3015
3016 // Construct the target
3017 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
3018 if (!Target) {
3019 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
3020 return 0;
3021 }
3022
Daniel Dunbareac7c532009-12-18 18:42:37 +00003023 // Set the target CPU if specified.
3024 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
3025 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
3026 return 0;
3027 }
3028
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003029 // Set the target ABI if specified.
3030 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
3031 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
3032 return 0;
3033 }
3034
Charles Davis98b7c5c2010-06-11 01:06:47 +00003035 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00003036 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00003037 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
3038 return 0;
3039 }
3040
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003041 // Compute the default target features, we need the target to handle this
3042 // because features may have dependencies on one another.
3043 llvm::StringMap<bool> Features;
3044 Target->getDefaultFeatures(Opts.CPU, Features);
3045
3046 // Apply the user specified deltas.
3047 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
3048 ie = Opts.Features.end(); it != ie; ++it) {
3049 const char *Name = it->c_str();
3050
3051 // Apply the feature via the target.
3052 if ((Name[0] != '-' && Name[0] != '+') ||
3053 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
3054 Diags.Report(diag::err_target_invalid_feature) << Name;
3055 return 0;
3056 }
3057 }
3058
3059 // Add the features to the compile options.
3060 //
3061 // FIXME: If we are completely confident that we have the right set, we only
3062 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003063 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003064 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
3065 ie = Features.end(); it != ie; ++it)
Chris Lattner1e5f83b2011-07-14 18:24:21 +00003066 Opts.Features.push_back(std::string(it->second ? "+" : "-") +
Chris Lattner48b78bd2011-07-14 18:45:41 +00003067 it->first().str());
Daniel Dunbarb93292a2009-12-19 03:30:57 +00003068 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00003069
3070 return Target.take();
3071}