blob: 51f5c87803e03d00be264654c5651a7135f6108c [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,
Mike Stump59e65722009-08-04 19:48:52 +00001021 Armv7a,
Mike Stump437bb4b2009-04-08 02:07:04 +00001022 XScale
1023 } ArmArch;
Chris Lattner393ff042008-04-21 18:56:49 +00001024public:
Eli Friedmana9f54962008-08-20 07:44:10 +00001025 ARMTargetInfo(const std::string& triple) : TargetInfo(triple) {
1026 // FIXME: Are the defaults correct for ARM?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001027 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1028 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:64";
Mike Stump59e65722009-08-04 19:48:52 +00001029 if (triple.find("armv7-") == 0)
1030 ArmArch = Armv7a;
1031 else if (triple.find("arm-") == 0 || triple.find("armv6-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001032 ArmArch = Armv6;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001033 else if (triple.find("armv5-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001034 ArmArch = Armv5;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001035 else if (triple.find("armv4t-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001036 ArmArch = Armv4t;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001037 else if (triple.find("xscale-") == 0)
Mike Stump437bb4b2009-04-08 02:07:04 +00001038 ArmArch = XScale;
Chris Lattner5b37dc02009-04-23 04:22:04 +00001039 else if (triple.find("armv") == 0) {
1040 // FIXME: fuzzy match for other random weird arm triples. This is useful
1041 // for the static analyzer and other clients, but probably should be
1042 // re-evaluated when codegen is brought up.
1043 ArmArch = Armv6;
1044 }
Eli Friedman61538a72008-05-20 14:21:01 +00001045 }
Chris Lattner33328642009-03-20 15:52:06 +00001046 virtual void getTargetDefines(const LangOptions &Opts,
1047 std::vector<char> &Defs) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001048 // Target identification.
1049 Define(Defs, "__arm");
1050 Define(Defs, "__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001051
Chris Lattnerc0f59212009-03-02 22:27:17 +00001052 // Target properties.
1053 Define(Defs, "__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001054
Mike Stump437bb4b2009-04-08 02:07:04 +00001055 // Subtarget options.
Mike Stump59e65722009-08-04 19:48:52 +00001056 if (ArmArch == Armv7a) {
1057 Define(Defs, "__ARM_ARCH_7A__");
1058 Define(Defs, "__THUMB_INTERWORK__");
1059 } else if (ArmArch == Armv6) {
Mike Stump437bb4b2009-04-08 02:07:04 +00001060 Define(Defs, "__ARM_ARCH_6K__");
1061 Define(Defs, "__THUMB_INTERWORK__");
1062 } else if (ArmArch == Armv5) {
1063 Define(Defs, "__ARM_ARCH_5TEJ__");
1064 Define(Defs, "__THUMB_INTERWORK__");
1065 Define(Defs, "__SOFTFP__");
1066 } else if (ArmArch == Armv4t) {
1067 Define(Defs, "__ARM_ARCH_4T__");
1068 Define(Defs, "__SOFTFP__");
1069 } else if (ArmArch == XScale) {
1070 Define(Defs, "__ARM_ARCH_5TE__");
1071 Define(Defs, "__XSCALE__");
1072 Define(Defs, "__SOFTFP__");
1073 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001074 Define(Defs, "__ARMEL__");
Eli Friedman19262422009-05-29 19:00:15 +00001075 Define(Defs, "__APCS_32__");
1076 Define(Defs, "__VFP_FP__");
Chris Lattner393ff042008-04-21 18:56:49 +00001077 }
1078 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1079 unsigned &NumRecords) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001080 // FIXME: Implement.
1081 Records = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001082 NumRecords = 0;
1083 }
1084 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001085 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001086 }
1087 virtual const char *getTargetPrefix() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001088 return "arm";
Chris Lattner393ff042008-04-21 18:56:49 +00001089 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001090 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattner393ff042008-04-21 18:56:49 +00001091 unsigned &NumNames) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001092 // FIXME: Implement.
1093 Names = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001094 NumNames = 0;
1095 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001096 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattner393ff042008-04-21 18:56:49 +00001097 unsigned &NumAliases) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001098 // FIXME: Implement.
1099 Aliases = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001100 NumAliases = 0;
1101 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001102 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001103 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001104 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001105 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001106 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001107 case 'l': // r0-r7
1108 case 'h': // r8-r15
1109 case 'w': // VFP Floating point register single precision
1110 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001111 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001112 return true;
1113 }
Chris Lattner393ff042008-04-21 18:56:49 +00001114 return false;
1115 }
1116 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001117 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001118 return "";
1119 }
1120};
1121} // end anonymous namespace.
1122
Eli Friedmana9f54962008-08-20 07:44:10 +00001123
1124namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001125class DarwinARMTargetInfo :
1126 public DarwinTargetInfo<ARMTargetInfo> {
1127protected:
1128 virtual void getOSDefines(const LangOptions &Opts, const char *Triple,
1129 std::vector<char> &Defines) const {
1130 getDarwinDefines(Defines, Opts);
1131 getDarwinIPhoneOSDefines(Defines, Triple);
Eli Friedmanb030f022009-04-19 21:38:35 +00001132 }
Eli Friedmana9f54962008-08-20 07:44:10 +00001133
Torok Edwin5f6c1942009-06-30 17:10:35 +00001134public:
1135 DarwinARMTargetInfo(const std::string& triple)
1136 : DarwinTargetInfo<ARMTargetInfo>(triple) {}
Eli Friedmana9f54962008-08-20 07:44:10 +00001137};
1138} // end anonymous namespace.
1139
Reid Spencer5f016e22007-07-11 17:01:13 +00001140namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00001141class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00001142 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1143 static const char * const GCCRegNames[];
Gabor Greif26658672008-02-21 16:29:08 +00001144public:
Eli Friedman01b86682008-08-20 07:28:14 +00001145 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
1146 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001147 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1148 "i64:64:64-f32:32:32-f64:64:64-v64:64:64";
Eli Friedman01b86682008-08-20 07:28:14 +00001149 }
Chris Lattner33328642009-03-20 15:52:06 +00001150 virtual void getTargetDefines(const LangOptions &Opts,
1151 std::vector<char> &Defines) const {
Eli Friedman09c3a6d2009-05-22 01:12:57 +00001152 DefineStd(Defines, "sparc", Opts);
Gabor Greif26658672008-02-21 16:29:08 +00001153 Define(Defines, "__sparcv8");
Eli Friedman09c3a6d2009-05-22 01:12:57 +00001154 Define(Defines, "__REGISTER_PREFIX__", "");
Gabor Greif26658672008-02-21 16:29:08 +00001155 }
1156 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1157 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001158 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00001159 }
1160 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001161 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00001162 }
1163 virtual const char *getTargetPrefix() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001164 return "sparc";
Gabor Greif26658672008-02-21 16:29:08 +00001165 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001166 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001167 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001168 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001169 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001170 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00001171 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001172 // FIXME: Implement!
1173 return false;
Gabor Greif26658672008-02-21 16:29:08 +00001174 }
1175 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001176 // FIXME: Implement!
1177 return "";
Gabor Greif26658672008-02-21 16:29:08 +00001178 }
1179};
1180
Chris Lattnere957f532009-01-27 01:58:38 +00001181const char * const SparcV8TargetInfo::GCCRegNames[] = {
1182 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1183 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1184 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1185 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
1186};
1187
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001188void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001189 unsigned &NumNames) const {
1190 Names = GCCRegNames;
1191 NumNames = llvm::array_lengthof(GCCRegNames);
1192}
1193
1194const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001195 { { "g0" }, "r0" },
1196 { { "g1" }, "r1" },
1197 { { "g2" }, "r2" },
1198 { { "g3" }, "r3" },
1199 { { "g4" }, "r4" },
1200 { { "g5" }, "r5" },
1201 { { "g6" }, "r6" },
1202 { { "g7" }, "r7" },
1203 { { "o0" }, "r8" },
1204 { { "o1" }, "r9" },
1205 { { "o2" }, "r10" },
1206 { { "o3" }, "r11" },
1207 { { "o4" }, "r12" },
1208 { { "o5" }, "r13" },
1209 { { "o6", "sp" }, "r14" },
1210 { { "o7" }, "r15" },
1211 { { "l0" }, "r16" },
1212 { { "l1" }, "r17" },
1213 { { "l2" }, "r18" },
1214 { { "l3" }, "r19" },
1215 { { "l4" }, "r20" },
1216 { { "l5" }, "r21" },
1217 { { "l6" }, "r22" },
1218 { { "l7" }, "r23" },
1219 { { "i0" }, "r24" },
1220 { { "i1" }, "r25" },
1221 { { "i2" }, "r26" },
1222 { { "i3" }, "r27" },
1223 { { "i4" }, "r28" },
1224 { { "i5" }, "r29" },
1225 { { "i6", "fp" }, "r30" },
1226 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00001227};
1228
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001229void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001230 unsigned &NumAliases) const {
1231 Aliases = GCCRegAliases;
1232 NumAliases = llvm::array_lengthof(GCCRegAliases);
1233}
Gabor Greif26658672008-02-21 16:29:08 +00001234} // end anonymous namespace.
1235
Eli Friedman01b86682008-08-20 07:28:14 +00001236namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001237class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00001238public:
1239 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00001240 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00001241 SizeType = UnsignedInt;
1242 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00001243 }
1244};
1245} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00001246
Chris Lattner2621fd12008-05-08 05:58:21 +00001247namespace {
1248 class PIC16TargetInfo : public TargetInfo{
1249 public:
1250 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001251 TLSSupported = false;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001252 IntWidth = 16;
1253 LongWidth = LongLongWidth = 32;
Eli Friedman3f7a5312009-05-16 23:30:57 +00001254 IntMaxTWidth = 32;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001255 PointerWidth = 16;
1256 IntAlign = 8;
1257 LongAlign = LongLongAlign = 8;
Eli Friedman61538a72008-05-20 14:21:01 +00001258 PointerAlign = 8;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001259 SizeType = UnsignedInt;
1260 IntMaxType = SignedLong;
1261 UIntMaxType = UnsignedLong;
Chris Lattner6ad474f2009-02-13 22:28:55 +00001262 IntPtrType = SignedShort;
Eli Friedmanf509d732008-11-02 02:43:55 +00001263 PtrDiffType = SignedInt;
Sanjiv Gupta9eb4cef2009-06-02 04:43:46 +00001264 FloatWidth = 32;
1265 FloatAlign = 32;
1266 DoubleWidth = 32;
1267 DoubleAlign = 32;
1268 LongDoubleWidth = 32;
1269 LongDoubleAlign = 32;
1270 FloatFormat = &llvm::APFloat::IEEEsingle;
1271 DoubleFormat = &llvm::APFloat::IEEEsingle;
1272 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
1273 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32";
1274
Chris Lattner2621fd12008-05-08 05:58:21 +00001275 }
Chris Lattner927686f2008-05-09 06:08:39 +00001276 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }
1277 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; }
Chris Lattner33328642009-03-20 15:52:06 +00001278 virtual void getTargetDefines(const LangOptions &Opts,
1279 std::vector<char> &Defines) const {
Chris Lattner2621fd12008-05-08 05:58:21 +00001280 Define(Defines, "__pic16");
Sanjiv Gupta7f579b12009-07-07 04:42:23 +00001281 Define(Defines, "rom", "__attribute__((address_space(1)))");
1282 Define(Defines, "ram", "__attribute__((address_space(0)))");
1283 Define(Defines, "_section(SectName)", "__attribute__((section(SectName)))");
1284 Define(Defines, "_address(Addr)","__attribute__((section(\"Address=\"#Addr)))");
1285 Define(Defines, "_CONFIG(conf)", "asm(\"CONFIG \"#conf)");
Chris Lattner2621fd12008-05-08 05:58:21 +00001286 }
1287 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1288 unsigned &NumRecords) const {}
1289 virtual const char *getVAListDeclaration() const { return "";}
1290 virtual const char *getClobbers() const {return "";}
Sanjiv Gupta70aa5f92009-04-21 06:01:16 +00001291 virtual const char *getTargetPrefix() const {return "pic16";}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001292 virtual void getGCCRegNames(const char * const *&Names,
1293 unsigned &NumNames) const {}
1294 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner2621fd12008-05-08 05:58:21 +00001295 TargetInfo::ConstraintInfo &info) const {
1296 return true;
1297 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001298 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattner2621fd12008-05-08 05:58:21 +00001299 unsigned &NumAliases) const {}
1300 virtual bool useGlobalsForAutomaticVariables() const {return true;}
1301 };
1302}
1303
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001304namespace {
1305 class MSP430TargetInfo : public TargetInfo {
1306 static const char * const GCCRegNames[];
1307 public:
1308 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
1309 TLSSupported = false;
1310 IntWidth = 16;
1311 LongWidth = LongLongWidth = 32;
Eli Friedman3f7a5312009-05-16 23:30:57 +00001312 IntMaxTWidth = 32;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001313 PointerWidth = 16;
1314 IntAlign = 8;
1315 LongAlign = LongLongAlign = 8;
1316 PointerAlign = 8;
1317 SizeType = UnsignedInt;
1318 IntMaxType = SignedLong;
1319 UIntMaxType = UnsignedLong;
1320 IntPtrType = SignedShort;
1321 PtrDiffType = SignedInt;
1322 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8";
1323 }
1324 virtual void getTargetDefines(const LangOptions &Opts,
1325 std::vector<char> &Defines) const {
1326 Define(Defines, "MSP430");
1327 Define(Defines, "__MSP430__");
1328 // FIXME: defines for different 'flavours' of MCU
1329 }
1330 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1331 unsigned &NumRecords) const {
1332 // FIXME: Implement.
1333 Records = 0;
1334 NumRecords = 0;
1335 }
1336 virtual const char *getTargetPrefix() const {
1337 return "msp430";
1338 }
1339 virtual void getGCCRegNames(const char * const *&Names,
1340 unsigned &NumNames) const;
1341 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1342 unsigned &NumAliases) const {
1343 // No aliases.
1344 Aliases = 0;
1345 NumAliases = 0;
1346 }
1347 virtual bool validateAsmConstraint(const char *&Name,
1348 TargetInfo::ConstraintInfo &info) const {
1349 // FIXME: implement
1350 return true;
1351 }
1352 virtual const char *getClobbers() const {
1353 // FIXME: Is this really right?
1354 return "";
1355 }
1356 virtual const char *getVAListDeclaration() const {
1357 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00001358 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001359 }
1360 };
1361
1362 const char * const MSP430TargetInfo::GCCRegNames[] = {
1363 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1364 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1365 };
1366
1367 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
1368 unsigned &NumNames) const {
1369 Names = GCCRegNames;
1370 NumNames = llvm::array_lengthof(GCCRegNames);
1371 }
1372}
1373
1374
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001375namespace {
1376 class SystemZTargetInfo : public TargetInfo {
1377 static const char * const GCCRegNames[];
1378 public:
1379 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
1380 TLSSupported = false;
1381 IntWidth = IntAlign = 32;
1382 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
1383 PointerWidth = PointerAlign = 64;
1384 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";
1385 }
1386 virtual void getTargetDefines(const LangOptions &Opts,
1387 std::vector<char> &Defines) const {
1388 Define(Defines, "__s390__");
1389 Define(Defines, "__s390x__");
1390 }
1391 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1392 unsigned &NumRecords) const {
1393 // FIXME: Implement.
1394 Records = 0;
1395 NumRecords = 0;
1396 }
1397 virtual const char *getTargetPrefix() const {
1398 return "s390x";
1399 }
1400
1401 virtual void getDefaultLangOptions(LangOptions &Opts) {
1402 TargetInfo::getDefaultLangOptions(Opts);
1403 Opts.CharIsSigned = false;
1404 }
1405
1406 virtual void getGCCRegNames(const char * const *&Names,
1407 unsigned &NumNames) const;
1408 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1409 unsigned &NumAliases) const {
1410 // No aliases.
1411 Aliases = 0;
1412 NumAliases = 0;
1413 }
1414 virtual bool validateAsmConstraint(const char *&Name,
1415 TargetInfo::ConstraintInfo &info) const {
1416 // FIXME: implement
1417 return true;
1418 }
1419 virtual const char *getClobbers() const {
1420 // FIXME: Is this really right?
1421 return "";
1422 }
1423 virtual const char *getVAListDeclaration() const {
1424 // FIXME: implement
1425 return "typedef char* __builtin_va_list;";
1426 }
1427 };
1428
1429 const char * const SystemZTargetInfo::GCCRegNames[] = {
1430 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1431 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1432 };
1433
1434 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
1435 unsigned &NumNames) const {
1436 Names = GCCRegNames;
1437 NumNames = llvm::array_lengthof(GCCRegNames);
1438 }
1439}
1440
Reid Spencer5f016e22007-07-11 17:01:13 +00001441//===----------------------------------------------------------------------===//
1442// Driver code
1443//===----------------------------------------------------------------------===//
1444
Ted Kremenek8448d382007-12-04 17:07:35 +00001445static inline bool IsX86(const std::string& TT) {
Ted Kremenekae360762007-12-03 22:06:55 +00001446 return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
1447 TT[4] == '-' && TT[1] - '3' < 6);
1448}
1449
Chris Lattner42e67372008-03-05 01:18:20 +00001450/// CreateTargetInfo - Return the target info object for the specified target
1451/// triple.
1452TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001453 // OS detection; this isn't really anywhere near complete.
1454 // Additions and corrections are welcome.
1455 bool isDarwin = T.find("-darwin") != std::string::npos;
Chris Lattnereac7aee2008-08-23 18:23:14 +00001456 bool isDragonFly = T.find("-dragonfly") != std::string::npos;
Chris Lattnerb62bb282009-07-13 20:29:08 +00001457 bool isNetBSD = T.find("-netbsd") != std::string::npos;
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001458 bool isOpenBSD = T.find("-openbsd") != std::string::npos;
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001459 bool isFreeBSD = T.find("-freebsd") != std::string::npos;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001460 bool isSolaris = T.find("-solaris") != std::string::npos;
1461 bool isLinux = T.find("-linux") != std::string::npos;
1462 bool isWindows = T.find("-windows") != std::string::npos ||
1463 T.find("-win32") != std::string::npos ||
1464 T.find("-mingw") != std::string::npos;
Eli Friedman61538a72008-05-20 14:21:01 +00001465
Eli Friedmaned855cb2008-08-21 00:13:15 +00001466 if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) {
1467 if (isDarwin)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001468 return new DarwinTargetInfo<PPCTargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001469 return new PPC32TargetInfo(T);
1470 }
Eli Friedman61538a72008-05-20 14:21:01 +00001471
Eli Friedmaned855cb2008-08-21 00:13:15 +00001472 if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) {
1473 if (isDarwin)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001474 return new DarwinTargetInfo<PPC64TargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001475 return new PPC64TargetInfo(T);
1476 }
Chris Lattner393ff042008-04-21 18:56:49 +00001477
Chris Lattner5b37dc02009-04-23 04:22:04 +00001478 if (T.find("armv") == 0 || T.find("arm-") == 0 || T.find("xscale") == 0) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001479 if (isDarwin)
1480 return new DarwinARMTargetInfo(T);
Daniel Dunbar1e0107a2009-03-23 16:09:04 +00001481 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001482 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001483 return new ARMTargetInfo(T);
1484 }
Eli Friedman61538a72008-05-20 14:21:01 +00001485
Eli Friedmaned855cb2008-08-21 00:13:15 +00001486 if (T.find("sparc-") == 0) {
1487 if (isSolaris)
1488 return new SolarisSparcV8TargetInfo(T);
1489 return new SparcV8TargetInfo(T);
1490 }
1491
Chris Lattner54fefbe2009-02-20 17:04:14 +00001492 if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) {
Eli Friedmaned855cb2008-08-21 00:13:15 +00001493 if (isDarwin)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001494 return new DarwinX86_64TargetInfo(T);
Daniel Dunbarb55a42b2008-09-23 17:37:57 +00001495 if (isLinux)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001496 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattnerb62bb282009-07-13 20:29:08 +00001497 if (isNetBSD)
1498 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001499 if (isOpenBSD)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001500 return new OpenBSDX86_64TargetInfo(T);
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001501 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001502 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
Douglas Gregor163a7c72009-05-21 23:51:30 +00001503 if (isSolaris)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001504 return new SolarisTargetInfo<X86_64TargetInfo>(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001505 return new X86_64TargetInfo(T);
1506 }
Eli Friedman61538a72008-05-20 14:21:01 +00001507
Chris Lattner2621fd12008-05-08 05:58:21 +00001508 if (T.find("pic16-") == 0)
1509 return new PIC16TargetInfo(T);
1510
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001511 if (T.find("msp430-") == 0)
1512 return new MSP430TargetInfo(T);
1513
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001514 if (T.find("s390x-") == 0)
1515 return new SystemZTargetInfo(T);
1516
Eli Friedmaned855cb2008-08-21 00:13:15 +00001517 if (IsX86(T)) {
1518 if (isDarwin)
1519 return new DarwinI386TargetInfo(T);
Eli Friedman0d4047b2008-08-21 00:24:02 +00001520 if (isLinux)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001521 return new LinuxTargetInfo<X86_32TargetInfo>(T);
Chris Lattnereac7aee2008-08-23 18:23:14 +00001522 if (isDragonFly)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001523 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattnerb62bb282009-07-13 20:29:08 +00001524 if (isNetBSD)
1525 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001526 if (isOpenBSD)
Eli Friedman624c1462009-07-05 18:47:56 +00001527 return new OpenBSDI386TargetInfo(T);
Chris Lattnerfd0269d2008-10-16 17:04:31 +00001528 if (isFreeBSD)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001529 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Douglas Gregor163a7c72009-05-21 23:51:30 +00001530 if (isSolaris)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001531 return new SolarisTargetInfo<X86_32TargetInfo>(T);
Eli Friedman29a30502008-08-21 01:40:19 +00001532 if (isWindows)
1533 return new WindowsX86_32TargetInfo(T);
Eli Friedmaned855cb2008-08-21 00:13:15 +00001534 return new X86_32TargetInfo(T);
1535 }
Eli Friedman61538a72008-05-20 14:21:01 +00001536
Chris Lattner42e67372008-03-05 01:18:20 +00001537 return NULL;
Reid Spencer5f016e22007-07-11 17:01:13 +00001538}