blob: 7298db45f0b15070f3e560c815e1b526118a7cbe [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
Chris Lattner6b15cdc2009-06-14 01:05:48 +000015#include "clang/Basic/Builtins.h"
16#include "clang/Basic/TargetBuiltins.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000017#include "clang/Basic/TargetInfo.h"
Chris Lattner8fc4dfb2008-12-04 22:54:33 +000018#include "clang/Basic/LangOptions.h"
Anders Carlsson3346ae62007-11-24 23:38:12 +000019#include "llvm/ADT/STLExtras.h"
Eli Friedman25531262008-05-20 14:27:34 +000020#include "llvm/ADT/APFloat.h"
Chris Lattnerca45cff2009-03-20 16:06:38 +000021#include "llvm/ADT/SmallString.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000022using namespace clang;
23
Reid Spencer5f016e22007-07-11 17:01:13 +000024//===----------------------------------------------------------------------===//
25// Common code shared among targets.
26//===----------------------------------------------------------------------===//
27
Chris Lattnerd15fa822007-10-06 06:57:34 +000028static void Define(std::vector<char> &Buf, const char *Macro,
29 const char *Val = "1") {
30 const char *Def = "#define ";
31 Buf.insert(Buf.end(), Def, Def+strlen(Def));
32 Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
33 Buf.push_back(' ');
34 Buf.insert(Buf.end(), Val, Val+strlen(Val));
35 Buf.push_back('\n');
36}
37
Chris Lattnerca45cff2009-03-20 16:06:38 +000038/// DefineStd - Define a macro name and standard variants. For example if
39/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
40/// when in GNU mode.
Anton Korobeynikova7c47172009-05-03 13:42:53 +000041static void DefineStd(std::vector<char> &Buf, const char *MacroName,
Chris Lattnerca45cff2009-03-20 16:06:38 +000042 const LangOptions &Opts) {
43 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000044
Chris Lattnerca45cff2009-03-20 16:06:38 +000045 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
46 // in the user's namespace.
47 if (Opts.GNUMode)
48 Define(Buf, MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000049
Chris Lattnerca45cff2009-03-20 16:06:38 +000050 // Define __unix.
51 llvm::SmallString<20> TmpStr;
52 TmpStr = "__";
53 TmpStr += MacroName;
54 Define(Buf, TmpStr.c_str());
Anton Korobeynikova7c47172009-05-03 13:42:53 +000055
Chris Lattnerca45cff2009-03-20 16:06:38 +000056 // Define __unix__.
57 TmpStr += "__";
58 Define(Buf, TmpStr.c_str());
59}
60
Chris Lattnerd29b6302008-10-05 21:50:58 +000061//===----------------------------------------------------------------------===//
62// Defines specific to certain operating systems.
63//===----------------------------------------------------------------------===//
Torok Edwin5f6c1942009-06-30 17:10:35 +000064namespace {
Douglas Gregora3844922009-07-01 15:12:53 +000065template<typename TgtInfo>
66class OSTargetInfo : public TgtInfo {
Torok Edwin5f6c1942009-06-30 17:10:35 +000067protected:
68 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
69 std::vector<char> &Defines) const=0;
70public:
Douglas Gregora3844922009-07-01 15:12:53 +000071 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {}
Torok Edwin5f6c1942009-06-30 17:10:35 +000072 virtual void getTargetDefines(const LangOptions &Opts,
73 std::vector<char> &Defines) const {
Douglas Gregora3844922009-07-01 15:12:53 +000074 TgtInfo::getTargetDefines(Opts, Defines);
75 getOSDefines(Opts, TgtInfo::getTargetTriple(), Defines);
Torok Edwinb0a5b242009-06-30 17:00:25 +000076 }
Torok Edwin5f6c1942009-06-30 17:10:35 +000077
78};
Torok Edwinb0a5b242009-06-30 17:00:25 +000079}
80
Torok Edwin5f6c1942009-06-30 17:10:35 +000081namespace {
Chris Lattnerae0ee032008-12-04 23:20:07 +000082/// getDarwinNumber - Parse the 'darwin number' out of the specific targe
Daniel Dunbar8d33cd72009-04-10 19:52:24 +000083/// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is
Chris Lattnerae0ee032008-12-04 23:20:07 +000084/// not defined, return 0's. Return true if we have -darwin in the string or
85/// false otherwise.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +000086static bool getDarwinNumber(const char *Triple, unsigned &Maj, unsigned &Min, unsigned &Revision) {
87 Maj = Min = Revision = 0;
Chris Lattnerae0ee032008-12-04 23:20:07 +000088 const char *Darwin = strstr(Triple, "-darwin");
89 if (Darwin == 0) return false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +000090
Chris Lattnerae0ee032008-12-04 23:20:07 +000091 Darwin += strlen("-darwin");
92 if (Darwin[0] < '0' || Darwin[0] > '9')
93 return true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +000094
Chris Lattnerae0ee032008-12-04 23:20:07 +000095 Maj = Darwin[0]-'0';
96 ++Darwin;
Anton Korobeynikova7c47172009-05-03 13:42:53 +000097
Chris Lattnerae0ee032008-12-04 23:20:07 +000098 // Handle "darwin11".
99 if (Maj == 1 && Darwin[0] >= '0' && Darwin[0] <= '9') {
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000100 Maj = Maj*10 + (Darwin[0] - '0');
Chris Lattnerae0ee032008-12-04 23:20:07 +0000101 ++Darwin;
102 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000103
Chris Lattnerae0ee032008-12-04 23:20:07 +0000104 // Handle minor version: 10.4.9 -> darwin8.9 -> "1049"
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000105 if (Darwin[0] != '.')
106 return true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000107
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000108 ++Darwin;
109 if (Darwin[0] < '0' || Darwin[0] > '9')
110 return true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000111
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000112 Min = Darwin[0]-'0';
113 ++Darwin;
114
115 // Handle 10.4.11 -> darwin8.11
116 if (Min == 1 && Darwin[0] >= '0' && Darwin[0] <= '9') {
117 Min = Min*10 + (Darwin[0] - '0');
118 ++Darwin;
119 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000120
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000121 // Handle revision darwin8.9.1
122 if (Darwin[0] != '.')
123 return true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000124
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000125 ++Darwin;
126 if (Darwin[0] < '0' || Darwin[0] > '9')
127 return true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000128
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000129 Revision = Darwin[0]-'0';
130 ++Darwin;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000131
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000132 if (Revision == 1 && Darwin[0] >= '0' && Darwin[0] <= '9') {
133 Revision = Revision*10 + (Darwin[0] - '0');
134 ++Darwin;
135 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000136
Chris Lattnerae0ee032008-12-04 23:20:07 +0000137 return true;
138}
139
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000140static void getDarwinDefines(std::vector<char> &Defs, const LangOptions &Opts) {
Chris Lattner7478bbf2009-06-23 00:43:21 +0000141 Define(Defs, "__APPLE_CC__", "5621");
Eli Friedman618234a2008-08-20 02:34:37 +0000142 Define(Defs, "__APPLE__");
143 Define(Defs, "__MACH__");
Chris Lattnerd427ad42009-02-05 07:19:24 +0000144 Define(Defs, "OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000145
Chris Lattner10d24272009-04-07 16:50:40 +0000146 // __weak is always defined, for use in blocks and with objc pointers.
147 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000148
Chris Lattner10d24272009-04-07 16:50:40 +0000149 // Darwin defines __strong even in C mode (just to nothing).
150 if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC)
Chris Lattner3a5cbd32009-04-07 04:48:21 +0000151 Define(Defs, "__strong", "");
Chris Lattner10d24272009-04-07 16:50:40 +0000152 else
Chris Lattner3a5cbd32009-04-07 04:48:21 +0000153 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
Eli Friedman2de4fee2009-06-04 23:00:29 +0000154
155 if (Opts.Static)
156 Define(Defs, "__STATIC__");
157 else
158 Define(Defs, "__DYNAMIC__");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000159}
160
161static void getDarwinOSXDefines(std::vector<char> &Defs, const char *Triple) {
Chris Lattner8b30c412008-09-30 01:00:25 +0000162 // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000163 unsigned Maj, Min, Rev;
164 if (getDarwinNumber(Triple, Maj, Min, Rev)) {
165 char MacOSXStr[] = "1000";
Chris Lattnerae0ee032008-12-04 23:20:07 +0000166 if (Maj >= 4 && Maj <= 13) { // 10.0-10.9
167 // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000168 MacOSXStr[2] = '0' + Maj-4;
169 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000170
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000171 // Handle minor version: 10.4.9 -> darwin8.9 -> "1049"
172 // Cap 10.4.11 -> darwin8.11 -> "1049"
173 MacOSXStr[3] = std::min(Min, 9U)+'0';
174 Define(Defs, "__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", MacOSXStr);
175 }
176}
177
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000178static void getDarwinIPhoneOSDefines(std::vector<char> &Defs,
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000179 const char *Triple) {
180 // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5.
181 unsigned Maj, Min, Rev;
182 if (getDarwinNumber(Triple, Maj, Min, Rev)) {
183 // When targetting iPhone OS, interpret the minor version and
184 // revision as the iPhone OS version
185 char iPhoneOSStr[] = "10000";
186 if (Min >= 2 && Min <= 9) { // iPhone OS 2.0-9.0
187 // darwin9.2.0 -> 20000, darwin9.3.0 -> 30000, etc.
188 iPhoneOSStr[0] = '0' + Min;
Chris Lattner8b30c412008-09-30 01:00:25 +0000189 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000190
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000191 // Handle minor version: 2.2 -> darwin9.2.2 -> 20200
192 iPhoneOSStr[2] = std::min(Rev, 9U)+'0';
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000193 Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__",
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000194 iPhoneOSStr);
Chris Lattner8b30c412008-09-30 01:00:25 +0000195 }
Eli Friedman618234a2008-08-20 02:34:37 +0000196}
Reid Spencer5f016e22007-07-11 17:01:13 +0000197
Chris Lattnerae0ee032008-12-04 23:20:07 +0000198/// GetDarwinLanguageOptions - Set the default language options for darwin.
199static void GetDarwinLanguageOptions(LangOptions &Opts,
200 const char *Triple) {
201 Opts.NeXTRuntime = true;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000202
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000203 unsigned Maj, Min, Rev;
204 if (!getDarwinNumber(Triple, Maj, Min, Rev))
Chris Lattnerae0ee032008-12-04 23:20:07 +0000205 return;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000206
Bill Wendling45483f72009-06-28 07:36:13 +0000207 // Blocks and stack protectors default to on for 10.6 (darwin10) and beyond.
208 if (Maj > 9) {
Chris Lattnerae0ee032008-12-04 23:20:07 +0000209 Opts.Blocks = 1;
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000210 Opts.setStackProtectorMode(LangOptions::SSPOn);
Bill Wendling45483f72009-06-28 07:36:13 +0000211 }
Fariborz Jahanian66a5c2c2009-02-24 23:34:44 +0000212
Bill Wendling45483f72009-06-28 07:36:13 +0000213 // Non-fragile ABI (in 64-bit mode) default to on for 10.5 (darwin9) and
214 // beyond.
Fariborz Jahanian84d01332009-02-24 23:38:42 +0000215 if (Maj >= 9 && Opts.ObjC1 && !strncmp(Triple, "x86_64", 6))
216 Opts.ObjCNonFragileABI = 1;
Chris Lattnerae0ee032008-12-04 23:20:07 +0000217}
218
Torok Edwin5f6c1942009-06-30 17:10:35 +0000219template<typename Target>
220class DarwinTargetInfo : public OSTargetInfo<Target> {
221protected:
222 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
223 std::vector<char> &Defines) const {
224 getDarwinDefines(Defines, Opts);
225 getDarwinOSXDefines(Defines, Triple);
226 }
227
228 /// getDefaultLangOptions - Allow the target to specify default settings for
229 /// various language options. These may be overridden by command line
230 /// options.
231 virtual void getDefaultLangOptions(LangOptions &Opts) {
232 TargetInfo::getDefaultLangOptions(Opts);
233 GetDarwinLanguageOptions(Opts, TargetInfo::getTargetTriple());
234 }
235public:
236 DarwinTargetInfo(const std::string& triple) :
237 OSTargetInfo<Target>(triple) {
238 this->TLSSupported = false;
239 }
240
Torok Edwin5f6c1942009-06-30 17:10:35 +0000241 virtual const char *getUnicodeStringSymbolPrefix() const {
242 return "__utf16_string_";
243 }
244
245 virtual const char *getUnicodeStringSection() const {
246 return "__TEXT,__ustring";
247 }
248};
249
250// DragonFlyBSD Target
251template<typename Target>
252class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
253protected:
254 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
255 std::vector<char> &Defs) const {
256 // DragonFly defines; list based off of gcc output
257 Define(Defs, "__DragonFly__");
258 Define(Defs, "__DragonFly_cc_version", "100001");
259 Define(Defs, "__ELF__");
260 Define(Defs, "__KPRINTF_ATTRIBUTE__");
261 Define(Defs, "__tune_i386__");
262 DefineStd(Defs, "unix", Opts);
263 }
264public:
265 DragonFlyBSDTargetInfo(const std::string &triple)
266 : OSTargetInfo<Target>(triple) {}
267};
268
269// FreeBSD Target
270template<typename Target>
271class FreeBSDTargetInfo : public OSTargetInfo<Target> {
272protected:
273 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
274 std::vector<char> &Defs) const {
275 // FreeBSD defines; list based off of gcc output
276
277 const char *FreeBSD = strstr(Triple, "-freebsd");
278 FreeBSD += strlen("-freebsd");
279 char release[] = "X";
280 release[0] = FreeBSD[0];
281 char version[] = "X00001";
282 version[0] = FreeBSD[0];
283
284 Define(Defs, "__FreeBSD__", release);
285 Define(Defs, "__FreeBSD_cc_version", version);
286 Define(Defs, "__KPRINTF_ATTRIBUTE__");
287 DefineStd(Defs, "unix", Opts);
288 Define(Defs, "__ELF__", "1");
289 }
290public:
291 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000292 : OSTargetInfo<Target>(triple) {
293 this->UserLabelPrefix = "";
294 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000295};
296
297// Linux target
298template<typename Target>
299class LinuxTargetInfo : public OSTargetInfo<Target> {
300protected:
301 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
302 std::vector<char> &Defs) const {
303 // Linux defines; list based off of gcc output
304 DefineStd(Defs, "unix", Opts);
305 DefineStd(Defs, "linux", Opts);
306 Define(Defs, "__gnu_linux__");
307 Define(Defs, "__ELF__", "1");
308 }
309public:
310 LinuxTargetInfo(const std::string& triple)
311 : OSTargetInfo<Target>(triple) {
312 this->UserLabelPrefix = "";
313 }
314};
315
Chris Lattnerb62bb282009-07-13 20:29:08 +0000316// NetBSD Target
317template<typename Target>
318class NetBSDTargetInfo : public OSTargetInfo<Target> {
319protected:
320 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
321 std::vector<char> &Defs) const {
322 // NetBSD defines; list based off of gcc output
323 Define(Defs, "__NetBSD__", "1");
324 Define(Defs, "__unix__", "1");
325 Define(Defs, "__ELF__", "1");
326 }
327public:
328 NetBSDTargetInfo(const std::string &triple)
329 : OSTargetInfo<Target>(triple) {
330 this->UserLabelPrefix = "";
331 }
332};
333
Torok Edwin5f6c1942009-06-30 17:10:35 +0000334// OpenBSD Target
335template<typename Target>
336class OpenBSDTargetInfo : public OSTargetInfo<Target> {
337protected:
338 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
339 std::vector<char> &Defs) const {
340 // OpenBSD defines; list based off of gcc output
341
342 Define(Defs, "__OpenBSD__", "1");
343 DefineStd(Defs, "unix", Opts);
344 Define(Defs, "__ELF__", "1");
345 }
346public:
347 OpenBSDTargetInfo(const std::string &triple)
348 : OSTargetInfo<Target>(triple) {}
349};
350
351// Solaris target
352template<typename Target>
353class SolarisTargetInfo : public OSTargetInfo<Target> {
354protected:
355 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
356 std::vector<char> &Defs) const {
357 DefineStd(Defs, "sun", Opts);
358 DefineStd(Defs, "unix", Opts);
359 Define(Defs, "__ELF__");
360 Define(Defs, "__svr4__");
361 Define(Defs, "__SVR4");
362 }
363public:
364 SolarisTargetInfo(const std::string& triple)
365 : OSTargetInfo<Target>(triple) {
366 this->UserLabelPrefix = "";
367 this->WCharType = this->SignedLong;
368 // FIXME: WIntType should be SignedLong
369 }
370};
371} // end anonymous namespace.
372
Eli Friedmanabc4e322009-06-08 06:11:14 +0000373/// GetWindowsLanguageOptions - Set the default language options for Windows.
374static void GetWindowsLanguageOptions(LangOptions &Opts,
375 const char *Triple) {
376 Opts.Microsoft = true;
377}
Chris Lattnerae0ee032008-12-04 23:20:07 +0000378
Chris Lattnerd29b6302008-10-05 21:50:58 +0000379//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000380// Specific target implementations.
381//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000382
Eli Friedmane4277982008-08-20 23:11:40 +0000383namespace {
384// PPC abstract base class
385class PPCTargetInfo : public TargetInfo {
386 static const Builtin::Info BuiltinInfo[];
387 static const char * const GCCRegNames[];
388 static const TargetInfo::GCCRegAlias GCCRegAliases[];
389
390public:
Eli Friedman15b91762009-06-05 07:05:05 +0000391 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
392
Eli Friedmane4277982008-08-20 23:11:40 +0000393 virtual void getTargetBuiltins(const Builtin::Info *&Records,
394 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000395 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000396 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000397 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000398
Chris Lattner33328642009-03-20 15:52:06 +0000399 virtual void getTargetDefines(const LangOptions &Opts,
400 std::vector<char> &Defines) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000401
Eli Friedmane4277982008-08-20 23:11:40 +0000402 virtual const char *getVAListDeclaration() const {
Chris Lattnerd5998502008-10-27 01:11:29 +0000403 return "typedef char* __builtin_va_list;";
404 // This is the right definition for ABI/V4: System V.4/eabi.
405 /*return "typedef struct __va_list_tag {"
Eli Friedmane4277982008-08-20 23:11:40 +0000406 " unsigned char gpr;"
407 " unsigned char fpr;"
408 " unsigned short reserved;"
409 " void* overflow_arg_area;"
410 " void* reg_save_area;"
Chris Lattnerd5998502008-10-27 01:11:29 +0000411 "} __builtin_va_list[1];";*/
Anders Carlsson3346ae62007-11-24 23:38:12 +0000412 }
Eli Friedmane4277982008-08-20 23:11:40 +0000413 virtual const char *getTargetPrefix() const {
414 return "ppc";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000415 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000416 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000417 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000418 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000419 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000420 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000421 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000422 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000423 default: return false;
424 case 'O': // Zero
425 return true;
426 case 'b': // Base register
427 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000428 Info.setAllowsRegister();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000429 return true;
430 }
431 }
Eli Friedman15b91762009-06-05 07:05:05 +0000432 virtual void getDefaultLangOptions(LangOptions &Opts) {
433 TargetInfo::getDefaultLangOptions(Opts);
434 Opts.CharIsSigned = false;
435 }
Eli Friedmane4277982008-08-20 23:11:40 +0000436 virtual const char *getClobbers() const {
437 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000438 }
Eli Friedmane4277982008-08-20 23:11:40 +0000439};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000440
Eli Friedmane4277982008-08-20 23:11:40 +0000441const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Douglas Gregorb1152d82009-02-16 21:58:21 +0000442#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
443#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000444#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000445};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000446
447
Chris Lattnerc0f59212009-03-02 22:27:17 +0000448/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
449/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000450void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
451 std::vector<char> &Defs) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000452 // Target identification.
453 Define(Defs, "__ppc__");
454 Define(Defs, "_ARCH_PPC");
455 Define(Defs, "__POWERPC__");
456 if (PointerWidth == 64) {
457 Define(Defs, "_ARCH_PPC64");
458 Define(Defs, "_LP64");
459 Define(Defs, "__LP64__");
460 Define(Defs, "__ppc64__");
461 } else {
462 Define(Defs, "__ppc__");
463 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000464
Chris Lattnerc0f59212009-03-02 22:27:17 +0000465 // Target properties.
466 Define(Defs, "_BIG_ENDIAN");
467 Define(Defs, "__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000468
Chris Lattnerc0f59212009-03-02 22:27:17 +0000469 // Subtarget options.
470 Define(Defs, "__NATURAL_ALIGNMENT__");
471 Define(Defs, "__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000472
Chris Lattnerc0f59212009-03-02 22:27:17 +0000473 // FIXME: Should be controlled by command line option.
474 Define(Defs, "__LONG_DOUBLE_128__");
475}
476
Chris Lattner393ff042008-04-21 18:56:49 +0000477
Eli Friedmane4277982008-08-20 23:11:40 +0000478const char * const PPCTargetInfo::GCCRegNames[] = {
479 "0", "1", "2", "3", "4", "5", "6", "7",
480 "8", "9", "10", "11", "12", "13", "14", "15",
481 "16", "17", "18", "19", "20", "21", "22", "23",
482 "24", "25", "26", "27", "28", "29", "30", "31",
483 "0", "1", "2", "3", "4", "5", "6", "7",
484 "8", "9", "10", "11", "12", "13", "14", "15",
485 "16", "17", "18", "19", "20", "21", "22", "23",
486 "24", "25", "26", "27", "28", "29", "30", "31",
487 "mq", "lr", "ctr", "ap",
488 "0", "1", "2", "3", "4", "5", "6", "7",
489 "xer",
490 "0", "1", "2", "3", "4", "5", "6", "7",
491 "8", "9", "10", "11", "12", "13", "14", "15",
492 "16", "17", "18", "19", "20", "21", "22", "23",
493 "24", "25", "26", "27", "28", "29", "30", "31",
494 "vrsave", "vscr",
495 "spe_acc", "spefscr",
496 "sfp"
497};
Reid Spencer5f016e22007-07-11 17:01:13 +0000498
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000499void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000500 unsigned &NumNames) const {
501 Names = GCCRegNames;
502 NumNames = llvm::array_lengthof(GCCRegNames);
503}
Reid Spencer5f016e22007-07-11 17:01:13 +0000504
Eli Friedmane4277982008-08-20 23:11:40 +0000505const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
506 // While some of these aliases do map to different registers
507 // they still share the same register name.
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000508 { { "cc", "cr0", "fr0", "r0", "v0"}, "0" },
509 { { "cr1", "fr1", "r1", "sp", "v1"}, "1" },
510 { { "cr2", "fr2", "r2", "toc", "v2"}, "2" },
511 { { "cr3", "fr3", "r3", "v3"}, "3" },
512 { { "cr4", "fr4", "r4", "v4"}, "4" },
513 { { "cr5", "fr5", "r5", "v5"}, "5" },
514 { { "cr6", "fr6", "r6", "v6"}, "6" },
515 { { "cr7", "fr7", "r7", "v7"}, "7" },
516 { { "fr8", "r8", "v8"}, "8" },
517 { { "fr9", "r9", "v9"}, "9" },
518 { { "fr10", "r10", "v10"}, "10" },
519 { { "fr11", "r11", "v11"}, "11" },
520 { { "fr12", "r12", "v12"}, "12" },
521 { { "fr13", "r13", "v13"}, "13" },
522 { { "fr14", "r14", "v14"}, "14" },
523 { { "fr15", "r15", "v15"}, "15" },
524 { { "fr16", "r16", "v16"}, "16" },
525 { { "fr17", "r17", "v17"}, "17" },
526 { { "fr18", "r18", "v18"}, "18" },
527 { { "fr19", "r19", "v19"}, "19" },
528 { { "fr20", "r20", "v20"}, "20" },
529 { { "fr21", "r21", "v21"}, "21" },
530 { { "fr22", "r22", "v22"}, "22" },
531 { { "fr23", "r23", "v23"}, "23" },
532 { { "fr24", "r24", "v24"}, "24" },
533 { { "fr25", "r25", "v25"}, "25" },
534 { { "fr26", "r26", "v26"}, "26" },
535 { { "fr27", "r27", "v27"}, "27" },
536 { { "fr28", "r28", "v28"}, "28" },
537 { { "fr29", "r29", "v29"}, "29" },
538 { { "fr30", "r30", "v30"}, "30" },
539 { { "fr31", "r31", "v31"}, "31" },
Eli Friedmane4277982008-08-20 23:11:40 +0000540};
541
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000542void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000543 unsigned &NumAliases) const {
544 Aliases = GCCRegAliases;
545 NumAliases = llvm::array_lengthof(GCCRegAliases);
546}
547} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000548
549namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000550class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000551public:
Eli Friedmaned855cb2008-08-21 00:13:15 +0000552 PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
553 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
554 "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
555 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000556};
557} // end anonymous namespace.
558
559namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000560class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000561public:
Eli Friedmane4277982008-08-20 23:11:40 +0000562 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000563 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000564 IntMaxType = SignedLong;
565 UIntMaxType = UnsignedLong;
566 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000567 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
568 "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
Chris Lattnerf291b102008-05-09 06:17:04 +0000569 }
Eli Friedmane4277982008-08-20 23:11:40 +0000570};
571} // end anonymous namespace.
572
Reid Spencer5f016e22007-07-11 17:01:13 +0000573namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000574// Namespace for x86 abstract base class
575const Builtin::Info BuiltinInfo[] = {
Douglas Gregorb1152d82009-02-16 21:58:21 +0000576#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
577#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000578#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +0000579};
Eli Friedman61538a72008-05-20 14:21:01 +0000580
Eli Friedman618234a2008-08-20 02:34:37 +0000581const char *GCCRegNames[] = {
582 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
583 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
584 "argp", "flags", "fspr", "dirflag", "frame",
585 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
586 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
587 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
588 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
589};
590
591const TargetInfo::GCCRegAlias GCCRegAliases[] = {
592 { { "al", "ah", "eax", "rax" }, "ax" },
593 { { "bl", "bh", "ebx", "rbx" }, "bx" },
594 { { "cl", "ch", "ecx", "rcx" }, "cx" },
595 { { "dl", "dh", "edx", "rdx" }, "dx" },
596 { { "esi", "rsi" }, "si" },
597 { { "edi", "rdi" }, "di" },
598 { { "esp", "rsp" }, "sp" },
599 { { "ebp", "rbp" }, "bp" },
600};
601
602// X86 target abstract base class; x86-32 and x86-64 are very close, so
603// most of the implementation can be shared.
604class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +0000605 enum X86SSEEnum {
606 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
607 } SSELevel;
Eli Friedman618234a2008-08-20 02:34:37 +0000608public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000609 X86TargetInfo(const std::string& triple)
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000610 : TargetInfo(triple), SSELevel(NoMMXSSE) {
Eli Friedman618234a2008-08-20 02:34:37 +0000611 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +0000612 }
613 virtual void getTargetBuiltins(const Builtin::Info *&Records,
614 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000615 Records = BuiltinInfo;
616 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000617 }
Anders Carlsson44fe49c2007-12-08 19:32:57 +0000618 virtual const char *getTargetPrefix() const {
Eli Friedman618234a2008-08-20 02:34:37 +0000619 return "x86";
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000620 }
621 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +0000622 unsigned &NumNames) const {
623 Names = GCCRegNames;
624 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +0000625 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000626 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +0000627 unsigned &NumAliases) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000628 Aliases = GCCRegAliases;
629 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000630 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000631 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +0000632 TargetInfo::ConstraintInfo &info) const;
633 virtual std::string convertConstraint(const char Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000634 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +0000635 return "~{dirflag},~{fpsr},~{flags}";
636 }
Chris Lattner33328642009-03-20 15:52:06 +0000637 virtual void getTargetDefines(const LangOptions &Opts,
638 std::vector<char> &Defines) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000639 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
640 const std::string &Name,
641 bool Enabled) const;
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000642 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000643 llvm::StringMap<bool> &Features) const;
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000644 virtual void HandleTargetFeatures(const llvm::StringMap<bool> &Features);
Reid Spencer5f016e22007-07-11 17:01:13 +0000645};
Chris Lattner3daed522009-03-02 22:20:04 +0000646
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000647void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000648 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000649 // FIXME: This should not be here.
650 Features["3dnow"] = false;
651 Features["3dnowa"] = false;
652 Features["mmx"] = false;
653 Features["sse"] = false;
654 Features["sse2"] = false;
655 Features["sse3"] = false;
656 Features["ssse3"] = false;
657 Features["sse41"] = false;
658 Features["sse42"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000659
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000660 // LLVM does not currently recognize this.
661 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000662
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000663 // FIXME: This *really* should not be here.
664
665 // X86_64 always has SSE2.
666 if (PointerWidth == 64)
667 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
668
Daniel Dunbar3ac79042009-05-06 21:56:32 +0000669 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
670 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
671 ;
672 else if (CPU == "pentium-mmx" || CPU == "pentium2")
673 setFeatureEnabled(Features, "mmx", true);
674 else if (CPU == "pentium3")
675 setFeatureEnabled(Features, "sse", true);
676 else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64")
677 setFeatureEnabled(Features, "sse2", true);
678 else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona")
679 setFeatureEnabled(Features, "sse3", true);
680 else if (CPU == "core2")
681 setFeatureEnabled(Features, "ssse3", true);
682 else if (CPU == "penryn") {
683 setFeatureEnabled(Features, "sse4", true);
684 Features["sse42"] = false;
685 } else if (CPU == "atom")
686 setFeatureEnabled(Features, "sse3", true);
687 else if (CPU == "corei7")
688 setFeatureEnabled(Features, "sse4", true);
689 else if (CPU == "k6" || CPU == "winchip-c6")
690 setFeatureEnabled(Features, "mmx", true);
691 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
692 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
693 setFeatureEnabled(Features, "mmx", true);
694 setFeatureEnabled(Features, "3dnow", true);
695 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
696 setFeatureEnabled(Features, "sse", true);
697 setFeatureEnabled(Features, "3dnowa", true);
698 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
699 CPU == "athlon-fx") {
700 setFeatureEnabled(Features, "sse2", true);
701 setFeatureEnabled(Features, "3dnowa", true);
702 } else if (CPU == "c3-2")
703 setFeatureEnabled(Features, "sse", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000704}
705
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000706bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
707 const std::string &Name,
708 bool Enabled) const {
709 // FIXME: This *really* should not be here.
710 if (!Features.count(Name) && Name != "sse4")
711 return false;
712
713 if (Enabled) {
714 if (Name == "mmx")
715 Features["mmx"] = true;
716 else if (Name == "sse")
717 Features["mmx"] = Features["sse"] = true;
718 else if (Name == "sse2")
719 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
720 else if (Name == "sse3")
721 Features["mmx"] = Features["sse"] = Features["sse2"] =
722 Features["sse3"] = true;
723 else if (Name == "ssse3")
724 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
725 Features["ssse3"] = true;
726 else if (Name == "sse4")
727 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
728 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
729 else if (Name == "3dnow")
730 Features["3dnowa"] = true;
731 else if (Name == "3dnowa")
732 Features["3dnow"] = Features["3dnowa"] = true;
733 } else {
734 if (Name == "mmx")
735 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
736 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
737 else if (Name == "sse")
738 Features["sse"] = Features["sse2"] = Features["sse3"] =
739 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
740 else if (Name == "sse2")
741 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
742 Features["sse41"] = Features["sse42"] = false;
743 else if (Name == "sse3")
744 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
745 Features["sse42"] = false;
746 else if (Name == "ssse3")
747 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
748 else if (Name == "sse4")
749 Features["sse41"] = Features["sse42"] = false;
750 else if (Name == "3dnow")
751 Features["3dnow"] = Features["3dnowa"] = false;
752 else if (Name == "3dnowa")
753 Features["3dnowa"] = false;
754 }
755
756 return true;
757}
758
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000759/// HandleTargetOptions - Perform initialization based on the user
760/// configured set of features.
761void X86TargetInfo::HandleTargetFeatures(const llvm::StringMap<bool>&Features) {
762 if (Features.lookup("sse42"))
763 SSELevel = SSE42;
764 else if (Features.lookup("sse41"))
765 SSELevel = SSE41;
766 else if (Features.lookup("ssse3"))
767 SSELevel = SSSE3;
768 else if (Features.lookup("sse3"))
769 SSELevel = SSE3;
770 else if (Features.lookup("sse2"))
771 SSELevel = SSE2;
772 else if (Features.lookup("sse"))
773 SSELevel = SSE1;
774 else if (Features.lookup("mmx"))
775 SSELevel = MMX;
Chris Lattner3daed522009-03-02 22:20:04 +0000776}
Chris Lattnerc0f59212009-03-02 22:27:17 +0000777
778/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
779/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000780void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
781 std::vector<char> &Defs) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000782 // Target identification.
783 if (PointerWidth == 64) {
784 Define(Defs, "_LP64");
785 Define(Defs, "__LP64__");
786 Define(Defs, "__amd64__");
787 Define(Defs, "__amd64");
788 Define(Defs, "__x86_64");
789 Define(Defs, "__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000790 } else {
Chris Lattnerca45cff2009-03-20 16:06:38 +0000791 DefineStd(Defs, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +0000792 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000793
Chris Lattnerc0f59212009-03-02 22:27:17 +0000794 // Target properties.
795 Define(Defs, "__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000796
Chris Lattnerc0f59212009-03-02 22:27:17 +0000797 // Subtarget options.
798 Define(Defs, "__nocona");
799 Define(Defs, "__nocona__");
800 Define(Defs, "__tune_nocona__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000801 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000802
Chris Lattner54175442009-04-19 17:32:33 +0000803 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
804 // functions in glibc header files that use FP Stack inline asm which the
805 // backend can't deal with (PR879).
806 Define(Defs, "__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000807
Chris Lattner84f0ea82009-03-02 22:40:39 +0000808 // Each case falls through to the previous one here.
809 switch (SSELevel) {
810 case SSE42:
811 Define(Defs, "__SSE4_2__");
812 case SSE41:
813 Define(Defs, "__SSE4_1__");
814 case SSSE3:
815 Define(Defs, "__SSSE3__");
816 case SSE3:
817 Define(Defs, "__SSE3__");
818 case SSE2:
819 Define(Defs, "__SSE2__");
820 Define(Defs, "__SSE2_MATH__"); // -mfp-math=sse always implied.
821 case SSE1:
822 Define(Defs, "__SSE__");
823 Define(Defs, "__SSE_MATH__"); // -mfp-math=sse always implied.
824 case MMX:
825 Define(Defs, "__MMX__");
826 case NoMMXSSE:
827 break;
828 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000829}
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000830
831
Eli Friedman618234a2008-08-20 02:34:37 +0000832bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000833X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000834 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000835 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +0000836 default: return false;
837 case 'a': // eax.
838 case 'b': // ebx.
839 case 'c': // ecx.
840 case 'd': // edx.
841 case 'S': // esi.
842 case 'D': // edi.
843 case 'A': // edx:eax.
844 case 't': // top of floating point stack.
845 case 'u': // second from top of floating point stack.
846 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +0000847 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +0000848 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +0000849 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000850 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +0000851 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000852 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +0000853 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +0000854 case 'N': // unsigned 8-bit integer constant for use with in and out
855 // instructions.
Eli Friedman12b2da02009-06-08 20:45:44 +0000856 case 'R': // "legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
Chris Lattner44def072009-04-26 07:16:29 +0000857 Info.setAllowsRegister();
Eli Friedman618234a2008-08-20 02:34:37 +0000858 return true;
859 }
860}
861
862std::string
863X86TargetInfo::convertConstraint(const char Constraint) const {
864 switch (Constraint) {
865 case 'a': return std::string("{ax}");
866 case 'b': return std::string("{bx}");
867 case 'c': return std::string("{cx}");
868 case 'd': return std::string("{dx}");
869 case 'S': return std::string("{si}");
870 case 'D': return std::string("{di}");
871 case 't': // top of floating point stack.
872 return std::string("{st}");
873 case 'u': // second from top of floating point stack.
874 return std::string("{st(1)}"); // second from top of floating point stack.
875 default:
876 return std::string(1, Constraint);
877 }
878}
Eli Friedman618234a2008-08-20 02:34:37 +0000879} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +0000880
881namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000882// X86-32 generic target
883class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000884public:
Eli Friedman618234a2008-08-20 02:34:37 +0000885 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
886 DoubleAlign = LongLongAlign = 32;
887 LongDoubleWidth = 96;
888 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000889 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
890 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
891 "a0:0:64-f80:32:32";
Eli Friedman1afabd92009-03-29 20:31:09 +0000892 SizeType = UnsignedInt;
893 PtrDiffType = SignedInt;
894 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +0000895 RegParmMax = 3;
Eli Friedman618234a2008-08-20 02:34:37 +0000896 }
897 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +0000898 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +0000899 }
Eli Friedman618234a2008-08-20 02:34:37 +0000900};
901} // end anonymous namespace
902
903namespace {
Eli Friedman624c1462009-07-05 18:47:56 +0000904class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
905public:
906 OpenBSDI386TargetInfo(const std::string& triple) :
907 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
908 SizeType = UnsignedLong;
909 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +0000910 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +0000911 }
912};
913} // end anonymous namespace
914
915namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000916class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +0000917public:
Torok Edwin5f6c1942009-06-30 17:10:35 +0000918 DarwinI386TargetInfo(const std::string& triple) :
919 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +0000920 LongDoubleWidth = 128;
921 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +0000922 SizeType = UnsignedLong;
923 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000924 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
925 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
926 "a0:0:64-f80:128:128";
Torok Edwinb0a5b242009-06-30 17:00:25 +0000927 }
928
Eli Friedman618234a2008-08-20 02:34:37 +0000929};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000930} // end anonymous namespace
931
932namespace {
Eli Friedman29a30502008-08-21 01:40:19 +0000933// x86-32 Windows target
934class WindowsX86_32TargetInfo : public X86_32TargetInfo {
935public:
936 WindowsX86_32TargetInfo(const std::string& triple)
937 : X86_32TargetInfo(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +0000938 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +0000939 WCharType = UnsignedShort;
Eli Friedmanabc4e322009-06-08 06:11:14 +0000940 WCharWidth = WCharAlign = 16;
Eli Friedman9c2f84e2009-06-08 21:16:17 +0000941 DoubleAlign = LongLongAlign = 64;
942 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
943 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
944 "a0:0:64-f80:32:32";
Eli Friedman29a30502008-08-21 01:40:19 +0000945 }
Chris Lattner33328642009-03-20 15:52:06 +0000946 virtual void getTargetDefines(const LangOptions &Opts,
947 std::vector<char> &Defines) const {
948 X86_32TargetInfo::getTargetDefines(Opts, Defines);
Eli Friedman29a30502008-08-21 01:40:19 +0000949 // This list is based off of the the list of things MingW defines
Eli Friedman29a30502008-08-21 01:40:19 +0000950 Define(Defines, "_WIN32");
Chris Lattnerca45cff2009-03-20 16:06:38 +0000951 DefineStd(Defines, "WIN32", Opts);
952 DefineStd(Defines, "WINNT", Opts);
Eli Friedman29a30502008-08-21 01:40:19 +0000953 Define(Defines, "_X86_");
954 Define(Defines, "__MSVCRT__");
955 }
Eli Friedmanabc4e322009-06-08 06:11:14 +0000956
957 virtual void getDefaultLangOptions(LangOptions &Opts) {
958 X86_32TargetInfo::getDefaultLangOptions(Opts);
959 GetWindowsLanguageOptions(Opts, getTargetTriple());
960 }
Eli Friedman29a30502008-08-21 01:40:19 +0000961};
962} // end anonymous namespace
963
964namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000965// x86-64 generic target
966class X86_64TargetInfo : public X86TargetInfo {
967public:
Chris Lattner33328642009-03-20 15:52:06 +0000968 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000969 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +0000970 LongDoubleWidth = 128;
971 LongDoubleAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +0000972 IntMaxType = SignedLong;
973 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000974 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +0000975 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +0000976
Eli Friedmaned855cb2008-08-21 00:13:15 +0000977 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
978 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Daniel Dunbar9e7d5962009-06-08 22:39:13 +0000979 "a0:0:64-s0:64:64-f80:128:128";
Reid Spencer5f016e22007-07-11 17:01:13 +0000980 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000981 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +0000982 return "typedef struct __va_list_tag {"
983 " unsigned gp_offset;"
984 " unsigned fp_offset;"
985 " void* overflow_arg_area;"
986 " void* reg_save_area;"
Eli Friedmandc043162009-07-03 00:45:06 +0000987 "} __va_list_tag;"
988 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +0000989 }
Eli Friedman618234a2008-08-20 02:34:37 +0000990};
991} // end anonymous namespace
992
993namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000994class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
995public:
996 DarwinX86_64TargetInfo(const std::string& triple)
997 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
998 Int64Type = SignedLongLong;
999 }
1000};
1001} // end anonymous namespace
1002
1003namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001004class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1005public:
1006 OpenBSDX86_64TargetInfo(const std::string& triple)
1007 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1008 IntMaxType = SignedLongLong;
1009 UIntMaxType = UnsignedLongLong;
1010 Int64Type = SignedLongLong;
1011 }
1012};
1013} // end anonymous namespace
1014
1015namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001016class ARMTargetInfo : public TargetInfo {
Mike Stump437bb4b2009-04-08 02:07:04 +00001017 enum {
1018 Armv4t,
1019 Armv5,
1020 Armv6,
1021 XScale
1022 } ArmArch;
Chris Lattner393ff042008-04-21 18:56:49 +00001023public:
Eli Friedmana9f54962008-08-20 07:44:10 +00001024 ARMTargetInfo(const std::string& triple) : TargetInfo(triple) {
1025 // FIXME: Are the defaults correct for ARM?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001026 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1027 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:64";
Chris Lattner5b37dc02009-04-23 04:22:04 +00001028 if (triple.find("arm-") == 0 || triple.find("armv6-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001029 ArmArch = Armv6;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001030 else if (triple.find("armv5-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001031 ArmArch = Armv5;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001032 else if (triple.find("armv4t-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001033 ArmArch = Armv4t;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001034 else if (triple.find("xscale-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001035 ArmArch = XScale;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001036 else if (triple.find("armv") == 0) {
1037 // FIXME: fuzzy match for other random weird arm triples. This is useful
1038 // for the static analyzer and other clients, but probably should be
1039 // re-evaluated when codegen is brought up.
1040 ArmArch = Armv6;
1041 }
Eli Friedman61538a72008-05-20 14:21:01 +00001042 }
Chris Lattner33328642009-03-20 15:52:06 +00001043 virtual void getTargetDefines(const LangOptions &Opts,
1044 std::vector<char> &Defs) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001045 // Target identification.
1046 Define(Defs, "__arm");
1047 Define(Defs, "__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001048
Chris Lattnerc0f59212009-03-02 22:27:17 +00001049 // Target properties.
1050 Define(Defs, "__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001051
Mike Stump437bb4b2009-04-08 02:07:04 +00001052 // Subtarget options.
1053 if (ArmArch == Armv6) {
1054 Define(Defs, "__ARM_ARCH_6K__");
1055 Define(Defs, "__THUMB_INTERWORK__");
1056 } else if (ArmArch == Armv5) {
1057 Define(Defs, "__ARM_ARCH_5TEJ__");
1058 Define(Defs, "__THUMB_INTERWORK__");
1059 Define(Defs, "__SOFTFP__");
1060 } else if (ArmArch == Armv4t) {
1061 Define(Defs, "__ARM_ARCH_4T__");
1062 Define(Defs, "__SOFTFP__");
1063 } else if (ArmArch == XScale) {
1064 Define(Defs, "__ARM_ARCH_5TE__");
1065 Define(Defs, "__XSCALE__");
1066 Define(Defs, "__SOFTFP__");
1067 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001068 Define(Defs, "__ARMEL__");
Eli Friedman19262422009-05-29 19:00:15 +00001069 Define(Defs, "__APCS_32__");
1070 Define(Defs, "__VFP_FP__");
Chris Lattner393ff042008-04-21 18:56:49 +00001071 }
1072 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1073 unsigned &NumRecords) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001074 // FIXME: Implement.
1075 Records = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001076 NumRecords = 0;
1077 }
1078 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001079 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001080 }
1081 virtual const char *getTargetPrefix() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001082 return "arm";
Chris Lattner393ff042008-04-21 18:56:49 +00001083 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001084 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattner393ff042008-04-21 18:56:49 +00001085 unsigned &NumNames) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001086 // FIXME: Implement.
1087 Names = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001088 NumNames = 0;
1089 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001090 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattner393ff042008-04-21 18:56:49 +00001091 unsigned &NumAliases) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001092 // FIXME: Implement.
1093 Aliases = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001094 NumAliases = 0;
1095 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001096 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001097 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001098 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001099 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001100 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001101 case 'l': // r0-r7
1102 case 'h': // r8-r15
1103 case 'w': // VFP Floating point register single precision
1104 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001105 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001106 return true;
1107 }
Chris Lattner393ff042008-04-21 18:56:49 +00001108 return false;
1109 }
1110 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001111 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001112 return "";
1113 }
1114};
1115} // end anonymous namespace.
1116
Eli Friedmana9f54962008-08-20 07:44:10 +00001117
1118namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001119class DarwinARMTargetInfo :
1120 public DarwinTargetInfo<ARMTargetInfo> {
1121protected:
1122 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
1123 std::vector<char> &Defines) const {
1124 getDarwinDefines(Defines, Opts);
1125 getDarwinIPhoneOSDefines(Defines, Triple);
Eli Friedmanb030f022009-04-19 21:38:35 +00001126 }
Eli Friedmana9f54962008-08-20 07:44:10 +00001127
Torok Edwin5f6c1942009-06-30 17:10:35 +00001128public:
1129 DarwinARMTargetInfo(const std::string& triple)
1130 : DarwinTargetInfo<ARMTargetInfo>(triple) {}
Eli Friedmana9f54962008-08-20 07:44:10 +00001131};
1132} // end anonymous namespace.
1133
Reid Spencer5f016e22007-07-11 17:01:13 +00001134namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00001135class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00001136 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1137 static const char * const GCCRegNames[];
Gabor Greif26658672008-02-21 16:29:08 +00001138public:
Eli Friedman01b86682008-08-20 07:28:14 +00001139 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
1140 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001141 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1142 "i64:64:64-f32:32:32-f64:64:64-v64:64:64";
Eli Friedman01b86682008-08-20 07:28:14 +00001143 }
Chris Lattner33328642009-03-20 15:52:06 +00001144 virtual void getTargetDefines(const LangOptions &Opts,
1145 std::vector<char> &Defines) const {
Eli Friedman09c3a6d2009-05-22 01:12:57 +00001146 DefineStd(Defines, "sparc", Opts);
Gabor Greif26658672008-02-21 16:29:08 +00001147 Define(Defines, "__sparcv8");
Eli Friedman09c3a6d2009-05-22 01:12:57 +00001148 Define(Defines, "__REGISTER_PREFIX__", "");
Gabor Greif26658672008-02-21 16:29:08 +00001149 }
1150 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1151 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001152 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00001153 }
1154 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001155 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00001156 }
1157 virtual const char *getTargetPrefix() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001158 return "sparc";
Gabor Greif26658672008-02-21 16:29:08 +00001159 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001160 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001161 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001162 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001163 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001164 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00001165 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001166 // FIXME: Implement!
1167 return false;
Gabor Greif26658672008-02-21 16:29:08 +00001168 }
1169 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001170 // FIXME: Implement!
1171 return "";
Gabor Greif26658672008-02-21 16:29:08 +00001172 }
1173};
1174
Chris Lattnere957f532009-01-27 01:58:38 +00001175const char * const SparcV8TargetInfo::GCCRegNames[] = {
1176 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1177 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1178 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1179 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
1180};
1181
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001182void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001183 unsigned &NumNames) const {
1184 Names = GCCRegNames;
1185 NumNames = llvm::array_lengthof(GCCRegNames);
1186}
1187
1188const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001189 { { "g0" }, "r0" },
1190 { { "g1" }, "r1" },
1191 { { "g2" }, "r2" },
1192 { { "g3" }, "r3" },
1193 { { "g4" }, "r4" },
1194 { { "g5" }, "r5" },
1195 { { "g6" }, "r6" },
1196 { { "g7" }, "r7" },
1197 { { "o0" }, "r8" },
1198 { { "o1" }, "r9" },
1199 { { "o2" }, "r10" },
1200 { { "o3" }, "r11" },
1201 { { "o4" }, "r12" },
1202 { { "o5" }, "r13" },
1203 { { "o6", "sp" }, "r14" },
1204 { { "o7" }, "r15" },
1205 { { "l0" }, "r16" },
1206 { { "l1" }, "r17" },
1207 { { "l2" }, "r18" },
1208 { { "l3" }, "r19" },
1209 { { "l4" }, "r20" },
1210 { { "l5" }, "r21" },
1211 { { "l6" }, "r22" },
1212 { { "l7" }, "r23" },
1213 { { "i0" }, "r24" },
1214 { { "i1" }, "r25" },
1215 { { "i2" }, "r26" },
1216 { { "i3" }, "r27" },
1217 { { "i4" }, "r28" },
1218 { { "i5" }, "r29" },
1219 { { "i6", "fp" }, "r30" },
1220 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00001221};
1222
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001223void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001224 unsigned &NumAliases) const {
1225 Aliases = GCCRegAliases;
1226 NumAliases = llvm::array_lengthof(GCCRegAliases);
1227}
Gabor Greif26658672008-02-21 16:29:08 +00001228} // end anonymous namespace.
1229
Eli Friedman01b86682008-08-20 07:28:14 +00001230namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001231class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00001232public:
1233 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00001234 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00001235 SizeType = UnsignedInt;
1236 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00001237 }
1238};
1239} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00001240
Chris Lattner2621fd12008-05-08 05:58:21 +00001241namespace {
1242 class PIC16TargetInfo : public TargetInfo{
1243 public:
1244 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001245 TLSSupported = false;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001246 IntWidth = 16;
1247 LongWidth = LongLongWidth = 32;
Eli Friedman3f7a5312009-05-16 23:30:57 +00001248 IntMaxTWidth = 32;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001249 PointerWidth = 16;
1250 IntAlign = 8;
1251 LongAlign = LongLongAlign = 8;
Eli Friedman61538a72008-05-20 14:21:01 +00001252 PointerAlign = 8;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001253 SizeType = UnsignedInt;
1254 IntMaxType = SignedLong;
1255 UIntMaxType = UnsignedLong;
Chris Lattner6ad474f2009-02-13 22:28:55 +00001256 IntPtrType = SignedShort;
Eli Friedmanf509d732008-11-02 02:43:55 +00001257 PtrDiffType = SignedInt;
Sanjiv Gupta9eb4cef2009-06-02 04:43:46 +00001258 FloatWidth = 32;
1259 FloatAlign = 32;
1260 DoubleWidth = 32;
1261 DoubleAlign = 32;
1262 LongDoubleWidth = 32;
1263 LongDoubleAlign = 32;
1264 FloatFormat = &llvm::APFloat::IEEEsingle;
1265 DoubleFormat = &llvm::APFloat::IEEEsingle;
1266 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
1267 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32";
1268
Chris Lattner2621fd12008-05-08 05:58:21 +00001269 }
Chris Lattner927686f2008-05-09 06:08:39 +00001270 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }
1271 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; }
Chris Lattner33328642009-03-20 15:52:06 +00001272 virtual void getTargetDefines(const LangOptions &Opts,
1273 std::vector<char> &Defines) const {
Chris Lattner2621fd12008-05-08 05:58:21 +00001274 Define(Defines, "__pic16");
Sanjiv Gupta7f579b12009-07-07 04:42:23 +00001275 Define(Defines, "rom", "__attribute__((address_space(1)))");
1276 Define(Defines, "ram", "__attribute__((address_space(0)))");
1277 Define(Defines, "_section(SectName)", "__attribute__((section(SectName)))");
1278 Define(Defines, "_address(Addr)","__attribute__((section(\"Address=\"#Addr)))");
1279 Define(Defines, "_CONFIG(conf)", "asm(\"CONFIG \"#conf)");
Chris Lattner2621fd12008-05-08 05:58:21 +00001280 }
1281 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1282 unsigned &NumRecords) const {}
1283 virtual const char *getVAListDeclaration() const { return "";}
1284 virtual const char *getClobbers() const {return "";}
Sanjiv Gupta70aa5f92009-04-21 06:01:16 +00001285 virtual const char *getTargetPrefix() const {return "pic16";}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001286 virtual void getGCCRegNames(const char * const *&Names,
1287 unsigned &NumNames) const {}
1288 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner2621fd12008-05-08 05:58:21 +00001289 TargetInfo::ConstraintInfo &info) const {
1290 return true;
1291 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001292 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattner2621fd12008-05-08 05:58:21 +00001293 unsigned &NumAliases) const {}
1294 virtual bool useGlobalsForAutomaticVariables() const {return true;}
1295 };
1296}
1297
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001298namespace {
1299 class MSP430TargetInfo : public TargetInfo {
1300 static const char * const GCCRegNames[];
1301 public:
1302 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
1303 TLSSupported = false;
1304 IntWidth = 16;
1305 LongWidth = LongLongWidth = 32;
Eli Friedman3f7a5312009-05-16 23:30:57 +00001306 IntMaxTWidth = 32;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001307 PointerWidth = 16;
1308 IntAlign = 8;
1309 LongAlign = LongLongAlign = 8;
1310 PointerAlign = 8;
1311 SizeType = UnsignedInt;
1312 IntMaxType = SignedLong;
1313 UIntMaxType = UnsignedLong;
1314 IntPtrType = SignedShort;
1315 PtrDiffType = SignedInt;
1316 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8";
1317 }
1318 virtual void getTargetDefines(const LangOptions &Opts,
1319 std::vector<char> &Defines) const {
1320 Define(Defines, "MSP430");
1321 Define(Defines, "__MSP430__");
1322 // FIXME: defines for different 'flavours' of MCU
1323 }
1324 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1325 unsigned &NumRecords) const {
1326 // FIXME: Implement.
1327 Records = 0;
1328 NumRecords = 0;
1329 }
1330 virtual const char *getTargetPrefix() const {
1331 return "msp430";
1332 }
1333 virtual void getGCCRegNames(const char * const *&Names,
1334 unsigned &NumNames) const;
1335 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1336 unsigned &NumAliases) const {
1337 // No aliases.
1338 Aliases = 0;
1339 NumAliases = 0;
1340 }
1341 virtual bool validateAsmConstraint(const char *&Name,
1342 TargetInfo::ConstraintInfo &info) const {
1343 // FIXME: implement
1344 return true;
1345 }
1346 virtual const char *getClobbers() const {
1347 // FIXME: Is this really right?
1348 return "";
1349 }
1350 virtual const char *getVAListDeclaration() const {
1351 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00001352 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001353 }
1354 };
1355
1356 const char * const MSP430TargetInfo::GCCRegNames[] = {
1357 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1358 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1359 };
1360
1361 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
1362 unsigned &NumNames) const {
1363 Names = GCCRegNames;
1364 NumNames = llvm::array_lengthof(GCCRegNames);
1365 }
1366}
1367
1368
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001369namespace {
1370 class SystemZTargetInfo : public TargetInfo {
1371 static const char * const GCCRegNames[];
1372 public:
1373 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
1374 TLSSupported = false;
1375 IntWidth = IntAlign = 32;
1376 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
1377 PointerWidth = PointerAlign = 64;
1378 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16";
1379 }
1380 virtual void getTargetDefines(const LangOptions &Opts,
1381 std::vector<char> &Defines) const {
1382 Define(Defines, "__s390__");
1383 Define(Defines, "__s390x__");
1384 }
1385 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1386 unsigned &NumRecords) const {
1387 // FIXME: Implement.
1388 Records = 0;
1389 NumRecords = 0;
1390 }
1391 virtual const char *getTargetPrefix() const {
1392 return "s390x";
1393 }
1394
1395 virtual void getDefaultLangOptions(LangOptions &Opts) {
1396 TargetInfo::getDefaultLangOptions(Opts);
1397 Opts.CharIsSigned = false;
1398 }
1399
1400 virtual void getGCCRegNames(const char * const *&Names,
1401 unsigned &NumNames) const;
1402 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1403 unsigned &NumAliases) const {
1404 // No aliases.
1405 Aliases = 0;
1406 NumAliases = 0;
1407 }
1408 virtual bool validateAsmConstraint(const char *&Name,
1409 TargetInfo::ConstraintInfo &info) const {
1410 // FIXME: implement
1411 return true;
1412 }
1413 virtual const char *getClobbers() const {
1414 // FIXME: Is this really right?
1415 return "";
1416 }
1417 virtual const char *getVAListDeclaration() const {
1418 // FIXME: implement
1419 return "typedef char* __builtin_va_list;";
1420 }
1421 };
1422
1423 const char * const SystemZTargetInfo::GCCRegNames[] = {
1424 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1425 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1426 };
1427
1428 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
1429 unsigned &NumNames) const {
1430 Names = GCCRegNames;
1431 NumNames = llvm::array_lengthof(GCCRegNames);
1432 }
1433}
1434
Reid Spencer5f016e22007-07-11 17:01:13 +00001435//===----------------------------------------------------------------------===//
1436// Driver code
1437//===----------------------------------------------------------------------===//
1438
Ted Kremenek8448d382007-12-04 17:07:35 +00001439static inline bool IsX86(const std::string& TT) {
Ted Kremenekae360762007-12-03 22:06:55 +00001440 return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
1441 TT[4] == '-' && TT[1] - '3' < 6);
1442}
1443
Chris Lattner42e67372008-03-05 01:18:20 +00001444/// CreateTargetInfo - Return the target info object for the specified target
1445/// triple.
1446TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001447 // OS detection; this isn't really anywhere near complete.
1448 // Additions and corrections are welcome.
1449 bool isDarwin = T.find("-darwin") != std::string::npos;
Chris Lattnereac7aee2008-08-23 18:23:14 +00001450 bool isDragonFly = T.find("-dragonfly") != std::string::npos;
Chris Lattnerb62bb282009-07-13 20:29:08 +00001451 bool isNetBSD = T.find("-netbsd") != std::string::npos;
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001452 bool isOpenBSD = T.find("-openbsd") != std::string::npos;
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001453 bool isFreeBSD = T.find("-freebsd") != std::string::npos;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001454 bool isSolaris = T.find("-solaris") != std::string::npos;
1455 bool isLinux = T.find("-linux") != std::string::npos;
1456 bool isWindows = T.find("-windows") != std::string::npos ||
1457 T.find("-win32") != std::string::npos ||
1458 T.find("-mingw") != std::string::npos;
Eli Friedman61538a72008-05-20 14:21:01 +00001459
Eli Friedmaned855cb2008-08-21 00:13:15 +00001460 if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) {
1461 if (isDarwin)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001462 return new DarwinTargetInfo<PPCTargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001463 return new PPC32TargetInfo(T);
1464 }
Eli Friedman61538a72008-05-20 14:21:01 +00001465
Eli Friedmaned855cb2008-08-21 00:13:15 +00001466 if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) {
1467 if (isDarwin)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001468 return new DarwinTargetInfo<PPC64TargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001469 return new PPC64TargetInfo(T);
1470 }
Chris Lattner393ff042008-04-21 18:56:49 +00001471
Chris Lattner5b37dc02009-04-23 04:22:04 +00001472 if (T.find("armv") == 0 || T.find("arm-") == 0 || T.find("xscale") == 0) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001473 if (isDarwin)
1474 return new DarwinARMTargetInfo(T);
Daniel Dunbar1e0107a2009-03-23 16:09:04 +00001475 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001476 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001477 return new ARMTargetInfo(T);
1478 }
Eli Friedman61538a72008-05-20 14:21:01 +00001479
Eli Friedmaned855cb2008-08-21 00:13:15 +00001480 if (T.find("sparc-") == 0) {
1481 if (isSolaris)
1482 return new SolarisSparcV8TargetInfo(T);
1483 return new SparcV8TargetInfo(T);
1484 }
1485
Chris Lattner54fefbe2009-02-20 17:04:14 +00001486 if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001487 if (isDarwin)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001488 return new DarwinX86_64TargetInfo(T);
Daniel Dunbarb55a42b2008-09-23 17:37:57 +00001489 if (isLinux)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001490 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattnerb62bb282009-07-13 20:29:08 +00001491 if (isNetBSD)
1492 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001493 if (isOpenBSD)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001494 return new OpenBSDX86_64TargetInfo(T);
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001495 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001496 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
Douglas Gregor163a7c72009-05-21 23:51:30 +00001497 if (isSolaris)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001498 return new SolarisTargetInfo<X86_64TargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001499 return new X86_64TargetInfo(T);
1500 }
Eli Friedman61538a72008-05-20 14:21:01 +00001501
Chris Lattner2621fd12008-05-08 05:58:21 +00001502 if (T.find("pic16-") == 0)
1503 return new PIC16TargetInfo(T);
1504
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001505 if (T.find("msp430-") == 0)
1506 return new MSP430TargetInfo(T);
1507
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001508 if (T.find("s390x-") == 0)
1509 return new SystemZTargetInfo(T);
1510
Eli Friedmaned855cb2008-08-21 00:13:15 +00001511 if (IsX86(T)) {
1512 if (isDarwin)
1513 return new DarwinI386TargetInfo(T);
Eli Friedman0d4047b2008-08-21 00:24:02 +00001514 if (isLinux)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001515 return new LinuxTargetInfo<X86_32TargetInfo>(T);
Chris Lattnereac7aee2008-08-23 18:23:14 +00001516 if (isDragonFly)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001517 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattnerb62bb282009-07-13 20:29:08 +00001518 if (isNetBSD)
1519 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001520 if (isOpenBSD)
Eli Friedman624c1462009-07-05 18:47:56 +00001521 return new OpenBSDI386TargetInfo(T);
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001522 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001523 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Douglas Gregor163a7c72009-05-21 23:51:30 +00001524 if (isSolaris)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001525 return new SolarisTargetInfo<X86_32TargetInfo>(T);
Eli Friedman29a30502008-08-21 01:40:19 +00001526 if (isWindows)
1527 return new WindowsX86_32TargetInfo(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001528 return new X86_32TargetInfo(T);
1529 }
Eli Friedman61538a72008-05-20 14:21:01 +00001530
Chris Lattner42e67372008-03-05 01:18:20 +00001531 return NULL;
Reid Spencer5f016e22007-07-11 17:01:13 +00001532}