blob: 1aa82829bbe76f3d64f72fb716afbab36c70a1e2 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
Ted Kremenek38591a22007-12-12 18:05:32 +000010// This file implements construction of a TargetInfo object from a
11// target triple.
Chris Lattner4b009652007-07-25 00:24:17 +000012//
13//===----------------------------------------------------------------------===//
14
Douglas Gregor2e8a7aa2009-02-16 21:58:21 +000015// FIXME: Layering violation
Chris Lattner4b009652007-07-25 00:24:17 +000016#include "clang/AST/Builtins.h"
Anders Carlssone1449c12007-12-09 23:17:02 +000017#include "clang/AST/TargetBuiltins.h"
Chris Lattner4b009652007-07-25 00:24:17 +000018#include "clang/Basic/TargetInfo.h"
Chris Lattnerddae7102008-12-04 22:54:33 +000019#include "clang/Basic/LangOptions.h"
Anders Carlsson7dd1c952007-11-24 23:38:12 +000020#include "llvm/ADT/STLExtras.h"
Eli Friedmand4011892008-05-20 14:27:34 +000021#include "llvm/ADT/APFloat.h"
Chris Lattner4b009652007-07-25 00:24:17 +000022using namespace clang;
23
Chris Lattner4b009652007-07-25 00:24:17 +000024//===----------------------------------------------------------------------===//
25// Common code shared among targets.
26//===----------------------------------------------------------------------===//
27
Chris Lattner0db667a2007-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 Lattnerbd00eb82008-10-05 21:50:58 +000038//===----------------------------------------------------------------------===//
39// Defines specific to certain operating systems.
40//===----------------------------------------------------------------------===//
41
Eli Friedmanff158dd2008-08-20 07:28:14 +000042static void getSolarisDefines(std::vector<char> &Defs) {
43 Define(Defs, "__SUN__");
44 Define(Defs, "__SOLARIS__");
45}
Chris Lattner4b009652007-07-25 00:24:17 +000046
Nate Begemanff1ba1f2009-01-18 01:08:03 +000047static void getFreeBSDDefines(std::vector<char> &Defs, bool is64Bit,
48 const char *Triple) {
Chris Lattner98cb2a22008-10-16 17:04:31 +000049 // FreeBSD defines; list based off of gcc output
50
51 const char *FreeBSD = strstr(Triple, "-freebsd");
52 FreeBSD += strlen("-freebsd");
53 char release[] = "X";
54 release[0] = FreeBSD[0];
55 char version[] = "X00001";
56 version[0] = FreeBSD[0];
57
58 Define(Defs, "__FreeBSD__", release);
59 Define(Defs, "__FreeBSD_cc_version", version);
60 Define(Defs, "__KPRINTF_ATTRIBUTE__");
61 Define(Defs, "unix");
Anton Korobeynikovfb820852009-02-14 16:42:50 +000062 Define(Defs, "__ELF__", "1");
Chris Lattner98cb2a22008-10-16 17:04:31 +000063 if (is64Bit) {
64 Define(Defs, "__LP64__");
65 }
66}
67
Chris Lattnerbd00eb82008-10-05 21:50:58 +000068static void getDragonFlyDefines(std::vector<char> &Defs) {
69 // DragonFly defines; list based off of gcc output
70 Define(Defs, "__DragonFly__");
71 Define(Defs, "__DragonFly_cc_version", "100001");
72 Define(Defs, "__ELF__");
73 Define(Defs, "__KPRINTF_ATTRIBUTE__");
74 Define(Defs, "__tune_i386__");
75 Define(Defs, "unix");
76 Define(Defs, "__unix");
77 Define(Defs, "__unix__");
78}
79
80static void getLinuxDefines(std::vector<char> &Defs) {
81 // Linux defines; list based off of gcc output
82 Define(Defs, "__unix__");
83 Define(Defs, "__unix");
84 Define(Defs, "unix");
85 Define(Defs, "__linux__");
86 Define(Defs, "__linux");
87 Define(Defs, "linux");
88 Define(Defs, "__gnu_linux__");
Argiris Kirtzidis99de9532009-02-14 15:02:45 +000089 Define(Defs, "__ELF__", "1");
Chris Lattnerbd00eb82008-10-05 21:50:58 +000090}
91
Chris Lattnerd7bc88b2008-12-04 23:20:07 +000092/// getDarwinNumber - Parse the 'darwin number' out of the specific targe
93/// triple. For example, if we have darwin8.5 return 8,5,4. If any entry is
94/// not defined, return 0's. Return true if we have -darwin in the string or
95/// false otherwise.
96static bool getDarwinNumber(const char *Triple, unsigned &Maj, unsigned &Min) {
97 Maj = Min = 0;
98 const char *Darwin = strstr(Triple, "-darwin");
99 if (Darwin == 0) return false;
100
101 Darwin += strlen("-darwin");
102 if (Darwin[0] < '0' || Darwin[0] > '9')
103 return true;
104
105 Maj = Darwin[0]-'0';
106 ++Darwin;
107
108 // Handle "darwin11".
109 if (Maj == 1 && Darwin[0] >= '0' && Darwin[0] <= '9') {
110 Maj = 10+Darwin[0]-'0';
111 ++Darwin;
112 }
113
114 // Handle minor version: 10.4.9 -> darwin8.9 -> "1049"
115 if (Darwin[0] == '.' && Darwin[1] >= '0' && Darwin[1] <= '9' &&
116 Darwin[2] == '\0')
117 Min = Darwin[1]-'0';
118
119 return true;
120}
121
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000122static void getDarwinDefines(std::vector<char> &Defs, const char *Triple) {
Eli Friedman872996c2008-08-20 02:34:37 +0000123 Define(Defs, "__APPLE__");
124 Define(Defs, "__MACH__");
Chris Lattner8405e092009-02-05 07:19:24 +0000125 Define(Defs, "OBJC_NEW_PROPERTIES");
126
127 // FIXME: OBJC_ZEROCOST_EXCEPTIONS when using zero cost eh.
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000128
129 // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5.
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000130 unsigned Maj, Min;
131 if (getDarwinNumber(Triple, Maj, Min)) {
Chris Lattnerd376f6d2008-09-30 20:30:12 +0000132 char DarwinStr[] = "1000";
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000133 if (Maj >= 4 && Maj <= 13) { // 10.0-10.9
134 // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc.
135 DarwinStr[2] = '0' + Maj-4;
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000136 }
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000137
138 // Handle minor version: 10.4.9 -> darwin8.9 -> "1049"
139 DarwinStr[3] = Min+'0';
Chris Lattnerd376f6d2008-09-30 20:30:12 +0000140 Define(Defs, "__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", DarwinStr);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000141 }
Eli Friedman872996c2008-08-20 02:34:37 +0000142}
Chris Lattner4b009652007-07-25 00:24:17 +0000143
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000144/// GetDarwinLanguageOptions - Set the default language options for darwin.
145static void GetDarwinLanguageOptions(LangOptions &Opts,
146 const char *Triple) {
147 Opts.NeXTRuntime = true;
148
149 unsigned Maj, Min;
150 if (!getDarwinNumber(Triple, Maj, Min))
151 return;
152
153 // Blocks default to on for 10.6 (darwin10) and beyond.
Fariborz Jahaniand09b9f72009-02-12 17:54:33 +0000154 // As does nonfragile-abi for 64bit mode
Fariborz Jahanian27f58962009-02-24 23:34:44 +0000155 if (Maj > 9)
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000156 Opts.Blocks = 1;
Fariborz Jahanian27f58962009-02-24 23:34:44 +0000157
Fariborz Jahanian72efecb2009-02-24 23:38:42 +0000158 if (Maj >= 9 && Opts.ObjC1 && !strncmp(Triple, "x86_64", 6))
159 Opts.ObjCNonFragileABI = 1;
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000160}
161
162
Chris Lattnerbd00eb82008-10-05 21:50:58 +0000163//===----------------------------------------------------------------------===//
164// Defines specific to certain architectures.
165//===----------------------------------------------------------------------===//
Eli Friedman5fb0a022008-08-21 00:24:02 +0000166
Chris Lattner4b009652007-07-25 00:24:17 +0000167/// getPowerPCDefines - Return a set of the PowerPC-specific #defines that are
168/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +0000169static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +0000170 // Target identification.
Chris Lattner0db667a2007-10-06 06:57:34 +0000171 Define(Defs, "__ppc__");
172 Define(Defs, "_ARCH_PPC");
173 Define(Defs, "__POWERPC__");
Chris Lattner4b009652007-07-25 00:24:17 +0000174 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000175 Define(Defs, "_ARCH_PPC64");
176 Define(Defs, "_LP64");
177 Define(Defs, "__LP64__");
178 Define(Defs, "__ppc64__");
Chris Lattner4b009652007-07-25 00:24:17 +0000179 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000180 Define(Defs, "__ppc__");
Chris Lattner4b009652007-07-25 00:24:17 +0000181 }
182
183 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000184 Define(Defs, "_BIG_ENDIAN");
185 Define(Defs, "__BIG_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000186
Chris Lattner4b009652007-07-25 00:24:17 +0000187 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000188 Define(Defs, "__NATURAL_ALIGNMENT__");
189 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000190
Chris Lattner3da35682008-10-05 21:49:27 +0000191 // FIXME: Should be controlled by command line option.
Chris Lattner0db667a2007-10-06 06:57:34 +0000192 Define(Defs, "__LONG_DOUBLE_128__");
Chris Lattner4b009652007-07-25 00:24:17 +0000193}
194
195/// getX86Defines - Return a set of the X86-specific #defines that are
196/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +0000197static void getX86Defines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +0000198 // Target identification.
199 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000200 Define(Defs, "_LP64");
201 Define(Defs, "__LP64__");
202 Define(Defs, "__amd64__");
203 Define(Defs, "__amd64");
204 Define(Defs, "__x86_64");
205 Define(Defs, "__x86_64__");
Chris Lattnerbfbfbaf2009-02-05 07:32:46 +0000206 Define(Defs, "__SSE3__");
Chris Lattner4b009652007-07-25 00:24:17 +0000207 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000208 Define(Defs, "__i386__");
209 Define(Defs, "__i386");
210 Define(Defs, "i386");
Chris Lattner4b009652007-07-25 00:24:17 +0000211 }
212
213 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000214 Define(Defs, "__LITTLE_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000215
Chris Lattner4b009652007-07-25 00:24:17 +0000216 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000217 Define(Defs, "__nocona");
218 Define(Defs, "__nocona__");
219 Define(Defs, "__tune_nocona__");
220 Define(Defs, "__SSE2_MATH__");
221 Define(Defs, "__SSE2__");
222 Define(Defs, "__SSE_MATH__");
223 Define(Defs, "__SSE__");
224 Define(Defs, "__MMX__");
225 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000226}
227
Chris Lattnerb6444052008-04-21 20:19:54 +0000228/// getARMDefines - Return a set of the ARM-specific #defines that are
Chris Lattner9fd73612008-04-21 18:56:49 +0000229/// not tied to a specific subtarget.
230static void getARMDefines(std::vector<char> &Defs) {
231 // Target identification.
232 Define(Defs, "__arm");
233 Define(Defs, "__arm__");
234
235 // Target properties.
236 Define(Defs, "__LITTLE_ENDIAN__");
237
Chris Lattner9fd73612008-04-21 18:56:49 +0000238 // Subtarget options. [hard coded to v6 for now]
239 Define(Defs, "__ARM_ARCH_6K__");
240 Define(Defs, "__ARMEL__");
241 Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", "20000");
Chris Lattner9fd73612008-04-21 18:56:49 +0000242}
243
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000244//===----------------------------------------------------------------------===//
245// Specific target implementations.
246//===----------------------------------------------------------------------===//
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000247
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000248namespace {
249// PPC abstract base class
250class PPCTargetInfo : public TargetInfo {
251 static const Builtin::Info BuiltinInfo[];
252 static const char * const GCCRegNames[];
253 static const TargetInfo::GCCRegAlias GCCRegAliases[];
254
255public:
256 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {
257 CharIsSigned = false;
258 }
259 virtual void getTargetBuiltins(const Builtin::Info *&Records,
260 unsigned &NumRecords) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000261 Records = BuiltinInfo;
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000262 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner4b009652007-07-25 00:24:17 +0000263 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000264 virtual const char *getVAListDeclaration() const {
Chris Lattnera07708f2008-10-27 01:11:29 +0000265 return "typedef char* __builtin_va_list;";
266 // This is the right definition for ABI/V4: System V.4/eabi.
267 /*return "typedef struct __va_list_tag {"
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000268 " unsigned char gpr;"
269 " unsigned char fpr;"
270 " unsigned short reserved;"
271 " void* overflow_arg_area;"
272 " void* reg_save_area;"
Chris Lattnera07708f2008-10-27 01:11:29 +0000273 "} __builtin_va_list[1];";*/
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000274 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000275 virtual const char *getTargetPrefix() const {
276 return "ppc";
Anders Carlsson4ce42302007-11-27 04:11:28 +0000277 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000278 virtual void getGCCRegNames(const char * const *&Names,
279 unsigned &NumNames) const;
280 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
281 unsigned &NumAliases) const;
282 virtual bool validateAsmConstraint(char c,
283 TargetInfo::ConstraintInfo &info) const {
Anders Carlsson4ce42302007-11-27 04:11:28 +0000284 switch (c) {
285 default: return false;
286 case 'O': // Zero
287 return true;
288 case 'b': // Base register
289 case 'f': // Floating point register
290 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
291 return true;
292 }
293 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000294 virtual const char *getClobbers() const {
295 return "";
Anders Carlsson4ce42302007-11-27 04:11:28 +0000296 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000297};
Anders Carlsson4ce42302007-11-27 04:11:28 +0000298
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000299const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Douglas Gregor2e8a7aa2009-02-16 21:58:21 +0000300#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
301#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000302#include "clang/AST/PPCBuiltins.def"
303};
Chris Lattner9fd73612008-04-21 18:56:49 +0000304
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000305const char * const PPCTargetInfo::GCCRegNames[] = {
306 "0", "1", "2", "3", "4", "5", "6", "7",
307 "8", "9", "10", "11", "12", "13", "14", "15",
308 "16", "17", "18", "19", "20", "21", "22", "23",
309 "24", "25", "26", "27", "28", "29", "30", "31",
310 "0", "1", "2", "3", "4", "5", "6", "7",
311 "8", "9", "10", "11", "12", "13", "14", "15",
312 "16", "17", "18", "19", "20", "21", "22", "23",
313 "24", "25", "26", "27", "28", "29", "30", "31",
314 "mq", "lr", "ctr", "ap",
315 "0", "1", "2", "3", "4", "5", "6", "7",
316 "xer",
317 "0", "1", "2", "3", "4", "5", "6", "7",
318 "8", "9", "10", "11", "12", "13", "14", "15",
319 "16", "17", "18", "19", "20", "21", "22", "23",
320 "24", "25", "26", "27", "28", "29", "30", "31",
321 "vrsave", "vscr",
322 "spe_acc", "spefscr",
323 "sfp"
324};
Chris Lattner4b009652007-07-25 00:24:17 +0000325
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000326void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
327 unsigned &NumNames) const {
328 Names = GCCRegNames;
329 NumNames = llvm::array_lengthof(GCCRegNames);
330}
Chris Lattner4b009652007-07-25 00:24:17 +0000331
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000332const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
333 // While some of these aliases do map to different registers
334 // they still share the same register name.
335 { { "cc", "cr0", "fr0", "r0", "v0"}, "0" },
336 { { "cr1", "fr1", "r1", "sp", "v1"}, "1" },
337 { { "cr2", "fr2", "r2", "toc", "v2"}, "2" },
338 { { "cr3", "fr3", "r3", "v3"}, "3" },
339 { { "cr4", "fr4", "r4", "v4"}, "4" },
340 { { "cr5", "fr5", "r5", "v5"}, "5" },
341 { { "cr6", "fr6", "r6", "v6"}, "6" },
342 { { "cr7", "fr7", "r7", "v7"}, "7" },
343 { { "fr8", "r8", "v8"}, "8" },
344 { { "fr9", "r9", "v9"}, "9" },
345 { { "fr10", "r10", "v10"}, "10" },
346 { { "fr11", "r11", "v11"}, "11" },
347 { { "fr12", "r12", "v12"}, "12" },
348 { { "fr13", "r13", "v13"}, "13" },
349 { { "fr14", "r14", "v14"}, "14" },
350 { { "fr15", "r15", "v15"}, "15" },
351 { { "fr16", "r16", "v16"}, "16" },
352 { { "fr17", "r17", "v17"}, "17" },
353 { { "fr18", "r18", "v18"}, "18" },
354 { { "fr19", "r19", "v19"}, "19" },
355 { { "fr20", "r20", "v20"}, "20" },
356 { { "fr21", "r21", "v21"}, "21" },
357 { { "fr22", "r22", "v22"}, "22" },
358 { { "fr23", "r23", "v23"}, "23" },
359 { { "fr24", "r24", "v24"}, "24" },
360 { { "fr25", "r25", "v25"}, "25" },
361 { { "fr26", "r26", "v26"}, "26" },
362 { { "fr27", "r27", "v27"}, "27" },
363 { { "fr28", "r28", "v28"}, "28" },
364 { { "fr29", "r29", "v29"}, "29" },
365 { { "fr30", "r30", "v30"}, "30" },
366 { { "fr31", "r31", "v31"}, "31" },
367};
368
369void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
370 unsigned &NumAliases) const {
371 Aliases = GCCRegAliases;
372 NumAliases = llvm::array_lengthof(GCCRegAliases);
373}
374} // end anonymous namespace.
Chris Lattner4b009652007-07-25 00:24:17 +0000375
376namespace {
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000377class PPC32TargetInfo : public PPCTargetInfo {
Chris Lattner4b009652007-07-25 00:24:17 +0000378public:
Eli Friedman2b161652008-08-21 00:13:15 +0000379 PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
380 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
381 "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
382 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000383 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000384 getPowerPCDefines(Defines, false);
385 }
Chris Lattner4b009652007-07-25 00:24:17 +0000386};
387} // end anonymous namespace.
388
389namespace {
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000390class PPC64TargetInfo : public PPCTargetInfo {
Chris Lattner4b009652007-07-25 00:24:17 +0000391public:
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000392 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnere5fde952008-05-09 06:17:04 +0000393 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman2b161652008-08-21 00:13:15 +0000394 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
395 "i64:64:64-f32:32:32-f64:64:64-v128:128:128";
Chris Lattnere5fde952008-05-09 06:17:04 +0000396 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000397 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000398 getPowerPCDefines(Defines, true);
399 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000400};
401} // end anonymous namespace.
402
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000403
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000404namespace {
405class DarwinPPCTargetInfo : public PPC32TargetInfo {
406public:
407 DarwinPPCTargetInfo(const std::string& triple) : PPC32TargetInfo(triple) {}
408 virtual void getTargetDefines(std::vector<char> &Defines) const {
409 PPC32TargetInfo::getTargetDefines(Defines);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000410 getDarwinDefines(Defines, getTargetTriple());
Chris Lattner4b009652007-07-25 00:24:17 +0000411 }
Daniel Dunbar34542952008-08-23 08:43:39 +0000412
Chris Lattnerddae7102008-12-04 22:54:33 +0000413 /// getDefaultLangOptions - Allow the target to specify default settings for
414 /// various language options. These may be overridden by command line
415 /// options.
416 virtual void getDefaultLangOptions(LangOptions &Opts) {
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000417 GetDarwinLanguageOptions(Opts, getTargetTriple());
Chris Lattnerddae7102008-12-04 22:54:33 +0000418 }
Eli Friedmanfd5a4122008-08-20 23:11:40 +0000419};
420} // end anonymous namespace.
421
422namespace {
423class DarwinPPC64TargetInfo : public PPC64TargetInfo {
424public:
425 DarwinPPC64TargetInfo(const std::string& triple) : PPC64TargetInfo(triple) {}
426 virtual void getTargetDefines(std::vector<char> &Defines) const {
427 PPC64TargetInfo::getTargetDefines(Defines);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000428 getDarwinDefines(Defines, getTargetTriple());
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000429 }
Daniel Dunbar34542952008-08-23 08:43:39 +0000430
Chris Lattnerddae7102008-12-04 22:54:33 +0000431 /// getDefaultLangOptions - Allow the target to specify default settings for
432 /// various language options. These may be overridden by command line
433 /// options.
434 virtual void getDefaultLangOptions(LangOptions &Opts) {
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000435 GetDarwinLanguageOptions(Opts, getTargetTriple());
Chris Lattnerddae7102008-12-04 22:54:33 +0000436 }
Chris Lattner4b009652007-07-25 00:24:17 +0000437};
438} // end anonymous namespace.
439
440namespace {
Eli Friedman872996c2008-08-20 02:34:37 +0000441// Namespace for x86 abstract base class
442const Builtin::Info BuiltinInfo[] = {
Douglas Gregor2e8a7aa2009-02-16 21:58:21 +0000443#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
444#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Eli Friedman872996c2008-08-20 02:34:37 +0000445#include "clang/AST/X86Builtins.def"
446};
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000447
Eli Friedman872996c2008-08-20 02:34:37 +0000448const char *GCCRegNames[] = {
449 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
450 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
451 "argp", "flags", "fspr", "dirflag", "frame",
452 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
453 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
454 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
455 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
456};
457
458const TargetInfo::GCCRegAlias GCCRegAliases[] = {
459 { { "al", "ah", "eax", "rax" }, "ax" },
460 { { "bl", "bh", "ebx", "rbx" }, "bx" },
461 { { "cl", "ch", "ecx", "rcx" }, "cx" },
462 { { "dl", "dh", "edx", "rdx" }, "dx" },
463 { { "esi", "rsi" }, "si" },
464 { { "edi", "rdi" }, "di" },
465 { { "esp", "rsp" }, "sp" },
466 { { "ebp", "rbp" }, "bp" },
467};
468
469// X86 target abstract base class; x86-32 and x86-64 are very close, so
470// most of the implementation can be shared.
471class X86TargetInfo : public TargetInfo {
472public:
473 X86TargetInfo(const std::string& triple) : TargetInfo(triple) {
474 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Chris Lattner4b009652007-07-25 00:24:17 +0000475 }
476 virtual void getTargetBuiltins(const Builtin::Info *&Records,
477 unsigned &NumRecords) const {
Eli Friedman872996c2008-08-20 02:34:37 +0000478 Records = BuiltinInfo;
479 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner4b009652007-07-25 00:24:17 +0000480 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000481 virtual const char *getTargetPrefix() const {
Eli Friedman872996c2008-08-20 02:34:37 +0000482 return "x86";
Anders Carlsson333052c2007-12-08 19:32:57 +0000483 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000484 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman872996c2008-08-20 02:34:37 +0000485 unsigned &NumNames) const {
486 Names = GCCRegNames;
487 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000488 }
489 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
490 unsigned &NumAliases) const {
Eli Friedman872996c2008-08-20 02:34:37 +0000491 Aliases = GCCRegAliases;
492 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000493 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000494 virtual bool validateAsmConstraint(char c,
Eli Friedman872996c2008-08-20 02:34:37 +0000495 TargetInfo::ConstraintInfo &info) const;
496 virtual std::string convertConstraint(const char Constraint) const;
Anders Carlsson4ce42302007-11-27 04:11:28 +0000497 virtual const char *getClobbers() const {
Eli Friedman872996c2008-08-20 02:34:37 +0000498 return "~{dirflag},~{fpsr},~{flags}";
499 }
Chris Lattner4b009652007-07-25 00:24:17 +0000500};
Eli Friedman872996c2008-08-20 02:34:37 +0000501
502bool
503X86TargetInfo::validateAsmConstraint(char c,
504 TargetInfo::ConstraintInfo &info) const {
505 switch (c) {
506 default: return false;
507 case 'a': // eax.
508 case 'b': // ebx.
509 case 'c': // ecx.
510 case 'd': // edx.
511 case 'S': // esi.
512 case 'D': // edi.
513 case 'A': // edx:eax.
514 case 't': // top of floating point stack.
515 case 'u': // second from top of floating point stack.
516 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlsson2285e622008-10-06 00:41:45 +0000517 case 'y': // Any MMX register.
Anders Carlssond2459f92008-10-06 19:17:39 +0000518 case 'x': // Any SSE register.
Eli Friedman872996c2008-08-20 02:34:37 +0000519 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Anders Carlssonff235da2009-01-24 18:03:09 +0000520 case 'e': // 32-bit signed integer constant for use with zero-extending
521 // x86_64 instructions.
522 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
523 // x86_64 instructions.
Eli Friedman872996c2008-08-20 02:34:37 +0000524 case 'N': // unsigned 8-bit integer constant for use with in and out
525 // instructions.
526 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
527 return true;
528 }
529}
530
531std::string
532X86TargetInfo::convertConstraint(const char Constraint) const {
533 switch (Constraint) {
534 case 'a': return std::string("{ax}");
535 case 'b': return std::string("{bx}");
536 case 'c': return std::string("{cx}");
537 case 'd': return std::string("{dx}");
538 case 'S': return std::string("{si}");
539 case 'D': return std::string("{di}");
540 case 't': // top of floating point stack.
541 return std::string("{st}");
542 case 'u': // second from top of floating point stack.
543 return std::string("{st(1)}"); // second from top of floating point stack.
544 default:
545 return std::string(1, Constraint);
546 }
547}
Eli Friedman872996c2008-08-20 02:34:37 +0000548} // end anonymous namespace
Chris Lattner4b009652007-07-25 00:24:17 +0000549
550namespace {
Eli Friedman872996c2008-08-20 02:34:37 +0000551// X86-32 generic target
552class X86_32TargetInfo : public X86TargetInfo {
Chris Lattner4b009652007-07-25 00:24:17 +0000553public:
Eli Friedman872996c2008-08-20 02:34:37 +0000554 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
555 DoubleAlign = LongLongAlign = 32;
556 LongDoubleWidth = 96;
557 LongDoubleAlign = 32;
Eli Friedman2b161652008-08-21 00:13:15 +0000558 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
559 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
560 "a0:0:64-f80:32:32";
Eli Friedman872996c2008-08-20 02:34:37 +0000561 }
562 virtual const char *getVAListDeclaration() const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000563 return "typedef char* __builtin_va_list;";
Eli Friedman872996c2008-08-20 02:34:37 +0000564 }
565 virtual void getTargetDefines(std::vector<char> &Defines) const {
566 getX86Defines(Defines, false);
567 }
568};
569} // end anonymous namespace
570
571namespace {
572// x86-32 Darwin (OS X) target
573class DarwinI386TargetInfo : public X86_32TargetInfo {
574public:
575 DarwinI386TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) {
576 LongDoubleWidth = 128;
577 LongDoubleAlign = 128;
Chris Lattner8405e092009-02-05 07:19:24 +0000578 PtrDiffType = SignedInt;
Eli Friedman2b161652008-08-21 00:13:15 +0000579 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
580 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
581 "a0:0:64-f80:128:128";
Eli Friedman872996c2008-08-20 02:34:37 +0000582 }
583 virtual void getTargetDefines(std::vector<char> &Defines) const {
584 X86_32TargetInfo::getTargetDefines(Defines);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000585 getDarwinDefines(Defines, getTargetTriple());
Eli Friedman872996c2008-08-20 02:34:37 +0000586 }
Chris Lattnerddae7102008-12-04 22:54:33 +0000587 /// getDefaultLangOptions - Allow the target to specify default settings for
588 /// various language options. These may be overridden by command line
589 /// options.
590 virtual void getDefaultLangOptions(LangOptions &Opts) {
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000591 GetDarwinLanguageOptions(Opts, getTargetTriple());
Chris Lattnerddae7102008-12-04 22:54:33 +0000592 }
Eli Friedman872996c2008-08-20 02:34:37 +0000593};
594} // end anonymous namespace
595
596namespace {
Chris Lattner98cb2a22008-10-16 17:04:31 +0000597// x86-32 FreeBSD target
598class FreeBSDX86_32TargetInfo : public X86_32TargetInfo {
599public:
Eli Friedman7cca0982008-11-02 02:43:55 +0000600 FreeBSDX86_32TargetInfo(const std::string& triple) :
601 X86_32TargetInfo(triple) {
602 SizeType = UnsignedInt;
603 PtrDiffType = SignedInt;
Chris Lattner98cb2a22008-10-16 17:04:31 +0000604 }
605 virtual void getTargetDefines(std::vector<char> &Defines) const {
606 X86_32TargetInfo::getTargetDefines(Defines);
607 getFreeBSDDefines(Defines, 0, getTargetTriple());
608 }
609};
610} // end anonymous namespace
611
612namespace {
Chris Lattnerd4faca42008-08-23 18:23:14 +0000613// x86-32 DragonFly target
614class DragonFlyX86_32TargetInfo : public X86_32TargetInfo {
615public:
Eli Friedman7cca0982008-11-02 02:43:55 +0000616 DragonFlyX86_32TargetInfo(const std::string& triple) :
617 X86_32TargetInfo(triple) {
618 SizeType = UnsignedInt;
619 PtrDiffType = SignedInt;
Chris Lattnerd4faca42008-08-23 18:23:14 +0000620 }
621 virtual void getTargetDefines(std::vector<char> &Defines) const {
622 X86_32TargetInfo::getTargetDefines(Defines);
623 getDragonFlyDefines(Defines);
624 }
625};
626} // end anonymous namespace
627
628namespace {
Eli Friedman5fb0a022008-08-21 00:24:02 +0000629// x86-32 Linux target
630class LinuxX86_32TargetInfo : public X86_32TargetInfo {
631public:
632 LinuxX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) {
Chris Lattner5edfe012008-10-05 19:44:25 +0000633 UserLabelPrefix = "";
Eli Friedman7cca0982008-11-02 02:43:55 +0000634 SizeType = UnsignedInt;
635 PtrDiffType = SignedInt;
Chris Lattnerd9ef7242009-02-13 22:28:55 +0000636 IntPtrType = SignedInt;
Eli Friedman5fb0a022008-08-21 00:24:02 +0000637 }
638 virtual void getTargetDefines(std::vector<char> &Defines) const {
639 X86_32TargetInfo::getTargetDefines(Defines);
640 getLinuxDefines(Defines);
641 }
642};
643} // end anonymous namespace
644
645namespace {
Eli Friedman23cb7912008-08-21 01:40:19 +0000646// x86-32 Windows target
647class WindowsX86_32TargetInfo : public X86_32TargetInfo {
648public:
649 WindowsX86_32TargetInfo(const std::string& triple)
650 : X86_32TargetInfo(triple) {
651 // FIXME: Fix wchar_t.
652 // FIXME: We should probably enable -fms-extensions by default for
653 // this target.
Eli Friedman7cca0982008-11-02 02:43:55 +0000654 SizeType = UnsignedInt;
655 PtrDiffType = SignedInt;
Eli Friedman23cb7912008-08-21 01:40:19 +0000656 }
657 virtual void getTargetDefines(std::vector<char> &Defines) const {
658 X86_32TargetInfo::getTargetDefines(Defines);
659 // This list is based off of the the list of things MingW defines
660 Define(Defines, "__WIN32__");
661 Define(Defines, "__WIN32");
662 Define(Defines, "_WIN32");
663 Define(Defines, "WIN32");
664 Define(Defines, "__WINNT__");
665 Define(Defines, "__WINNT");
666 Define(Defines, "WINNT");
Eli Friedman23cb7912008-08-21 01:40:19 +0000667 Define(Defines, "_X86_");
668 Define(Defines, "__MSVCRT__");
669 }
670};
671} // end anonymous namespace
672
673namespace {
Eli Friedman872996c2008-08-20 02:34:37 +0000674// x86-64 generic target
675class X86_64TargetInfo : public X86TargetInfo {
676public:
677 X86_64TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
Chris Lattnere5fde952008-05-09 06:17:04 +0000678 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Chris Lattner4dfc45a2009-01-28 06:58:19 +0000679 DoubleAlign = LongLongAlign = 64;
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000680 LongDoubleWidth = 128;
681 LongDoubleAlign = 128;
Chris Lattnerbfbfbaf2009-02-05 07:32:46 +0000682 IntMaxType = SignedLong;
683 UIntMaxType = UnsignedLong;
684
Eli Friedman2b161652008-08-21 00:13:15 +0000685 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
686 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
687 "a0:0:64-f80:128:128";
Chris Lattner4b009652007-07-25 00:24:17 +0000688 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000689 virtual const char *getVAListDeclaration() const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000690 return "typedef struct __va_list_tag {"
691 " unsigned gp_offset;"
692 " unsigned fp_offset;"
693 " void* overflow_arg_area;"
694 " void* reg_save_area;"
695 "} __builtin_va_list[1];";
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000696 }
Eli Friedman872996c2008-08-20 02:34:37 +0000697 virtual void getTargetDefines(std::vector<char> &Defines) const {
698 getX86Defines(Defines, true);
Anders Carlsson333052c2007-12-08 19:32:57 +0000699 }
Eli Friedman872996c2008-08-20 02:34:37 +0000700};
701} // end anonymous namespace
702
703namespace {
Chris Lattner98cb2a22008-10-16 17:04:31 +0000704// x86-64 FreeBSD target
705class FreeBSDX86_64TargetInfo : public X86_64TargetInfo {
706public:
Eli Friedman7cca0982008-11-02 02:43:55 +0000707 FreeBSDX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) {}
Chris Lattner98cb2a22008-10-16 17:04:31 +0000708 virtual void getTargetDefines(std::vector<char> &Defines) const {
709 X86_64TargetInfo::getTargetDefines(Defines);
710 getFreeBSDDefines(Defines, 1, getTargetTriple());
711 }
712};
713} // end anonymous namespace
714
715namespace {
Daniel Dunbare5a80f22008-09-23 17:37:57 +0000716// x86-64 Linux target
717class LinuxX86_64TargetInfo : public X86_64TargetInfo {
718public:
719 LinuxX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) {
Chris Lattner5edfe012008-10-05 19:44:25 +0000720 UserLabelPrefix = "";
Daniel Dunbare5a80f22008-09-23 17:37:57 +0000721 }
722 virtual void getTargetDefines(std::vector<char> &Defines) const {
723 X86_64TargetInfo::getTargetDefines(Defines);
724 getLinuxDefines(Defines);
Daniel Dunbare5a80f22008-09-23 17:37:57 +0000725 }
726};
727} // end anonymous namespace
728
729namespace {
Eli Friedman872996c2008-08-20 02:34:37 +0000730// x86-64 Darwin (OS X) target
731class DarwinX86_64TargetInfo : public X86_64TargetInfo {
732public:
733 DarwinX86_64TargetInfo(const std::string& triple) :
734 X86_64TargetInfo(triple) {}
735
736 virtual void getTargetDefines(std::vector<char> &Defines) const {
737 X86_64TargetInfo::getTargetDefines(Defines);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000738 getDarwinDefines(Defines, getTargetTriple());
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000739 }
Daniel Dunbar34542952008-08-23 08:43:39 +0000740
Chris Lattnerddae7102008-12-04 22:54:33 +0000741 /// getDefaultLangOptions - Allow the target to specify default settings for
742 /// various language options. These may be overridden by command line
743 /// options.
744 virtual void getDefaultLangOptions(LangOptions &Opts) {
Chris Lattnerd7bc88b2008-12-04 23:20:07 +0000745 GetDarwinLanguageOptions(Opts, getTargetTriple());
Chris Lattnerddae7102008-12-04 22:54:33 +0000746 }
Chris Lattner4b009652007-07-25 00:24:17 +0000747};
748} // end anonymous namespace.
749
Chris Lattner9fd73612008-04-21 18:56:49 +0000750namespace {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000751class ARMTargetInfo : public TargetInfo {
Chris Lattner9fd73612008-04-21 18:56:49 +0000752public:
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000753 ARMTargetInfo(const std::string& triple) : TargetInfo(triple) {
754 // FIXME: Are the defaults correct for ARM?
Eli Friedman2b161652008-08-21 00:13:15 +0000755 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
756 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:64";
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000757 }
Chris Lattner9fd73612008-04-21 18:56:49 +0000758 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner9fd73612008-04-21 18:56:49 +0000759 getARMDefines(Defines);
760 }
761 virtual void getTargetBuiltins(const Builtin::Info *&Records,
762 unsigned &NumRecords) const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000763 // FIXME: Implement.
764 Records = 0;
Chris Lattner9fd73612008-04-21 18:56:49 +0000765 NumRecords = 0;
766 }
767 virtual const char *getVAListDeclaration() const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000768 return "typedef char* __builtin_va_list;";
Chris Lattner9fd73612008-04-21 18:56:49 +0000769 }
770 virtual const char *getTargetPrefix() const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000771 return "arm";
Chris Lattner9fd73612008-04-21 18:56:49 +0000772 }
Chris Lattner9fd73612008-04-21 18:56:49 +0000773 virtual void getGCCRegNames(const char * const *&Names,
774 unsigned &NumNames) const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000775 // FIXME: Implement.
776 Names = 0;
Chris Lattner9fd73612008-04-21 18:56:49 +0000777 NumNames = 0;
778 }
779 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
780 unsigned &NumAliases) const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000781 // FIXME: Implement.
782 Aliases = 0;
Chris Lattner9fd73612008-04-21 18:56:49 +0000783 NumAliases = 0;
784 }
785 virtual bool validateAsmConstraint(char c,
Nate Begeman222823a2008-04-22 05:03:19 +0000786 TargetInfo::ConstraintInfo &info) const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000787 // FIXME: Check if this is complete
Nate Begeman222823a2008-04-22 05:03:19 +0000788 switch (c) {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000789 default:
Nate Begeman222823a2008-04-22 05:03:19 +0000790 case 'l': // r0-r7
791 case 'h': // r8-r15
792 case 'w': // VFP Floating point register single precision
793 case 'P': // VFP Floating point register double precision
794 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
795 return true;
796 }
Chris Lattner9fd73612008-04-21 18:56:49 +0000797 return false;
798 }
799 virtual const char *getClobbers() const {
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000800 // FIXME: Is this really right?
Chris Lattner9fd73612008-04-21 18:56:49 +0000801 return "";
802 }
803};
804} // end anonymous namespace.
805
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000806
807namespace {
808class DarwinARMTargetInfo : public ARMTargetInfo {
809public:
810 DarwinARMTargetInfo(const std::string& triple) : ARMTargetInfo(triple) {}
811
812 virtual void getTargetDefines(std::vector<char> &Defines) const {
813 ARMTargetInfo::getTargetDefines(Defines);
Chris Lattnerc5dc8eb2008-09-30 01:00:25 +0000814 getDarwinDefines(Defines, getTargetTriple());
Eli Friedmanbe727fe2008-08-20 07:44:10 +0000815 }
816};
817} // end anonymous namespace.
818
Chris Lattner4b009652007-07-25 00:24:17 +0000819namespace {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000820class SparcV8TargetInfo : public TargetInfo {
Chris Lattnerff7c53d2009-01-27 01:58:38 +0000821 static const TargetInfo::GCCRegAlias GCCRegAliases[];
822 static const char * const GCCRegNames[];
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000823public:
Eli Friedmanff158dd2008-08-20 07:28:14 +0000824 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
825 // FIXME: Support Sparc quad-precision long double?
Eli Friedman2b161652008-08-21 00:13:15 +0000826 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
827 "i64:64:64-f32:32:32-f64:64:64-v64:64:64";
Eli Friedmanff158dd2008-08-20 07:28:14 +0000828 }
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000829 virtual void getTargetDefines(std::vector<char> &Defines) const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000830 // FIXME: This is missing a lot of important defines; some of the
831 // missing stuff is likely to break system headers.
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000832 Define(Defines, "__sparc");
Eli Friedman1dee5c52008-05-25 05:26:09 +0000833 Define(Defines, "__sparc__");
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000834 Define(Defines, "__sparcv8");
835 }
836 virtual void getTargetBuiltins(const Builtin::Info *&Records,
837 unsigned &NumRecords) const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000838 // FIXME: Implement!
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000839 }
840 virtual const char *getVAListDeclaration() const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000841 return "typedef void* __builtin_va_list;";
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000842 }
843 virtual const char *getTargetPrefix() const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000844 return "sparc";
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000845 }
846 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnerff7c53d2009-01-27 01:58:38 +0000847 unsigned &NumNames) const;
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000848 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnerff7c53d2009-01-27 01:58:38 +0000849 unsigned &NumAliases) const;
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000850 virtual bool validateAsmConstraint(char c,
851 TargetInfo::ConstraintInfo &info) const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000852 // FIXME: Implement!
853 return false;
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000854 }
855 virtual const char *getClobbers() const {
Eli Friedmanff158dd2008-08-20 07:28:14 +0000856 // FIXME: Implement!
857 return "";
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000858 }
859};
860
Chris Lattnerff7c53d2009-01-27 01:58:38 +0000861const char * const SparcV8TargetInfo::GCCRegNames[] = {
862 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
863 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
864 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
865 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
866};
867
868void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
869 unsigned &NumNames) const {
870 Names = GCCRegNames;
871 NumNames = llvm::array_lengthof(GCCRegNames);
872}
873
874const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
875 { { "g0" }, "r0" },
876 { { "g1" }, "r1" },
877 { { "g2" }, "r2" },
878 { { "g3" }, "r3" },
879 { { "g4" }, "r4" },
880 { { "g5" }, "r5" },
881 { { "g6" }, "r6" },
882 { { "g7" }, "r7" },
883 { { "o0" }, "r8" },
884 { { "o1" }, "r9" },
885 { { "o2" }, "r10" },
886 { { "o3" }, "r11" },
887 { { "o4" }, "r12" },
888 { { "o5" }, "r13" },
889 { { "o6", "sp" }, "r14" },
890 { { "o7" }, "r15" },
891 { { "l0" }, "r16" },
892 { { "l1" }, "r17" },
893 { { "l2" }, "r18" },
894 { { "l3" }, "r19" },
895 { { "l4" }, "r20" },
896 { { "l5" }, "r21" },
897 { { "l6" }, "r22" },
898 { { "l7" }, "r23" },
899 { { "i0" }, "r24" },
900 { { "i1" }, "r25" },
901 { { "i2" }, "r26" },
902 { { "i3" }, "r27" },
903 { { "i4" }, "r28" },
904 { { "i5" }, "r29" },
905 { { "i6", "fp" }, "r30" },
906 { { "i7" }, "r31" },
907};
908
909void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
910 unsigned &NumAliases) const {
911 Aliases = GCCRegAliases;
912 NumAliases = llvm::array_lengthof(GCCRegAliases);
913}
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000914} // end anonymous namespace.
915
Eli Friedmanff158dd2008-08-20 07:28:14 +0000916namespace {
917class SolarisSparcV8TargetInfo : public SparcV8TargetInfo {
918public:
919 SolarisSparcV8TargetInfo(const std::string& triple) :
Eli Friedman7cca0982008-11-02 02:43:55 +0000920 SparcV8TargetInfo(triple) {
921 SizeType = UnsignedInt;
922 PtrDiffType = SignedInt;
923 }
Eli Friedmanff158dd2008-08-20 07:28:14 +0000924
925 virtual void getTargetDefines(std::vector<char> &Defines) const {
926 SparcV8TargetInfo::getTargetDefines(Defines);
927 getSolarisDefines(Defines);
928 }
929};
930} // end anonymous namespace.
Chris Lattner4b009652007-07-25 00:24:17 +0000931
Chris Lattner85970f32008-05-08 05:58:21 +0000932namespace {
933 class PIC16TargetInfo : public TargetInfo{
934 public:
935 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
Sanjiv Guptafa451432008-10-31 09:52:39 +0000936 IntWidth = 16;
937 LongWidth = LongLongWidth = 32;
938 PointerWidth = 16;
939 IntAlign = 8;
940 LongAlign = LongLongAlign = 8;
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000941 PointerAlign = 8;
Sanjiv Guptafa451432008-10-31 09:52:39 +0000942 SizeType = UnsignedInt;
943 IntMaxType = SignedLong;
944 UIntMaxType = UnsignedLong;
Chris Lattnerd9ef7242009-02-13 22:28:55 +0000945 IntPtrType = SignedShort;
Eli Friedman7cca0982008-11-02 02:43:55 +0000946 PtrDiffType = SignedInt;
Sanjiv Guptaebd8f0f2008-08-18 10:05:22 +0000947 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8";
Chris Lattner85970f32008-05-08 05:58:21 +0000948 }
Chris Lattner727b3c42008-05-09 06:08:39 +0000949 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }
950 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; }
Chris Lattner85970f32008-05-08 05:58:21 +0000951 virtual void getTargetDefines(std::vector<char> &Defines) const {
952 Define(Defines, "__pic16");
953 }
954 virtual void getTargetBuiltins(const Builtin::Info *&Records,
955 unsigned &NumRecords) const {}
956 virtual const char *getVAListDeclaration() const { return "";}
957 virtual const char *getClobbers() const {return "";}
958 virtual const char *getTargetPrefix() const {return "";}
959 virtual void getGCCRegNames(const char * const *&Names,
960 unsigned &NumNames) const {}
961 virtual bool validateAsmConstraint(char c,
962 TargetInfo::ConstraintInfo &info) const {
963 return true;
964 }
965 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
966 unsigned &NumAliases) const {}
967 virtual bool useGlobalsForAutomaticVariables() const {return true;}
968 };
969}
970
Chris Lattner4b009652007-07-25 00:24:17 +0000971//===----------------------------------------------------------------------===//
972// Driver code
973//===----------------------------------------------------------------------===//
974
Ted Kremenekb97d7672007-12-04 17:07:35 +0000975static inline bool IsX86(const std::string& TT) {
Ted Kremenek40499482007-12-03 22:06:55 +0000976 return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
977 TT[4] == '-' && TT[1] - '3' < 6);
978}
979
Chris Lattnerfc457002008-03-05 01:18:20 +0000980/// CreateTargetInfo - Return the target info object for the specified target
981/// triple.
982TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
Eli Friedman2b161652008-08-21 00:13:15 +0000983 // OS detection; this isn't really anywhere near complete.
984 // Additions and corrections are welcome.
985 bool isDarwin = T.find("-darwin") != std::string::npos;
Chris Lattnerd4faca42008-08-23 18:23:14 +0000986 bool isDragonFly = T.find("-dragonfly") != std::string::npos;
Chris Lattner98cb2a22008-10-16 17:04:31 +0000987 bool isFreeBSD = T.find("-freebsd") != std::string::npos;
Eli Friedman2b161652008-08-21 00:13:15 +0000988 bool isSolaris = T.find("-solaris") != std::string::npos;
989 bool isLinux = T.find("-linux") != std::string::npos;
990 bool isWindows = T.find("-windows") != std::string::npos ||
991 T.find("-win32") != std::string::npos ||
992 T.find("-mingw") != std::string::npos;
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000993
Eli Friedman2b161652008-08-21 00:13:15 +0000994 if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) {
995 if (isDarwin)
996 return new DarwinPPCTargetInfo(T);
997 return new PPC32TargetInfo(T);
998 }
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000999
Eli Friedman2b161652008-08-21 00:13:15 +00001000 if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) {
1001 if (isDarwin)
1002 return new DarwinPPC64TargetInfo(T);
1003 return new PPC64TargetInfo(T);
1004 }
Chris Lattner9fd73612008-04-21 18:56:49 +00001005
Eli Friedman2b161652008-08-21 00:13:15 +00001006 if (T.find("armv6-") == 0 || T.find("arm-") == 0) {
1007 if (isDarwin)
1008 return new DarwinARMTargetInfo(T);
1009 return new ARMTargetInfo(T);
1010 }
Eli Friedman0b7b1cb2008-05-20 14:21:01 +00001011
Eli Friedman2b161652008-08-21 00:13:15 +00001012 if (T.find("sparc-") == 0) {
1013 if (isSolaris)
1014 return new SolarisSparcV8TargetInfo(T);
1015 return new SparcV8TargetInfo(T);
1016 }
1017
Chris Lattner273dce42009-02-20 17:04:14 +00001018 if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) {
Eli Friedman2b161652008-08-21 00:13:15 +00001019 if (isDarwin)
1020 return new DarwinX86_64TargetInfo(T);
Daniel Dunbare5a80f22008-09-23 17:37:57 +00001021 if (isLinux)
1022 return new LinuxX86_64TargetInfo(T);
Chris Lattner98cb2a22008-10-16 17:04:31 +00001023 if (isFreeBSD)
1024 return new FreeBSDX86_64TargetInfo(T);
Eli Friedman2b161652008-08-21 00:13:15 +00001025 return new X86_64TargetInfo(T);
1026 }
Eli Friedman0b7b1cb2008-05-20 14:21:01 +00001027
Chris Lattner85970f32008-05-08 05:58:21 +00001028 if (T.find("pic16-") == 0)
1029 return new PIC16TargetInfo(T);
1030
Eli Friedman2b161652008-08-21 00:13:15 +00001031 if (IsX86(T)) {
1032 if (isDarwin)
1033 return new DarwinI386TargetInfo(T);
Eli Friedman5fb0a022008-08-21 00:24:02 +00001034 if (isLinux)
1035 return new LinuxX86_32TargetInfo(T);
Chris Lattnerd4faca42008-08-23 18:23:14 +00001036 if (isDragonFly)
1037 return new DragonFlyX86_32TargetInfo(T);
Chris Lattner98cb2a22008-10-16 17:04:31 +00001038 if (isFreeBSD)
1039 return new FreeBSDX86_32TargetInfo(T);
Eli Friedman23cb7912008-08-21 01:40:19 +00001040 if (isWindows)
1041 return new WindowsX86_32TargetInfo(T);
Eli Friedman2b161652008-08-21 00:13:15 +00001042 return new X86_32TargetInfo(T);
1043 }
Eli Friedman0b7b1cb2008-05-20 14:21:01 +00001044
Chris Lattnerfc457002008-03-05 01:18:20 +00001045 return NULL;
Chris Lattner4b009652007-07-25 00:24:17 +00001046}
Ted Kremenekd507bab2008-03-04 17:47:18 +00001047