blob: c1cd96e361edf8f5f871a7052b7bb9cc38ba1458 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Anton Korobeynikova7c47172009-05-03 13:42:53 +000010// This file implements construction of a TargetInfo object from a
Ted Kremenekbbced582007-12-12 18:05:32 +000011// target triple.
Reid Spencer5f016e22007-07-11 17:01:13 +000012//
13//===----------------------------------------------------------------------===//
14
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/Basic/TargetInfo.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000016#include "clang/Basic/Builtins.h"
17#include "clang/Basic/Diagnostic.h"
Chris Lattner8fc4dfb2008-12-04 22:54:33 +000018#include "clang/Basic/LangOptions.h"
Chandler Carruth103b71c2010-01-20 06:13:02 +000019#include "clang/Basic/MacroBuilder.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000020#include "clang/Basic/TargetBuiltins.h"
21#include "clang/Basic/TargetOptions.h"
Eli Friedman25531262008-05-20 14:27:34 +000022#include "llvm/ADT/APFloat.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000023#include "llvm/ADT/OwningPtr.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000024#include "llvm/ADT/STLExtras.h"
Daniel Dunbar77659342009-08-19 20:04:03 +000025#include "llvm/ADT/StringRef.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000026#include "llvm/ADT/StringSwitch.h"
Chris Lattner4c28b1c2009-08-12 06:24:27 +000027#include "llvm/ADT/Triple.h"
Chris Lattner797c3c42009-08-10 19:03:04 +000028#include "llvm/MC/MCSectionMachO.h"
Benjamin Kramer48725082010-01-09 18:20:57 +000029#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000030using namespace clang;
31
Reid Spencer5f016e22007-07-11 17:01:13 +000032//===----------------------------------------------------------------------===//
33// Common code shared among targets.
34//===----------------------------------------------------------------------===//
35
Chris Lattnerca45cff2009-03-20 16:06:38 +000036/// DefineStd - Define a macro name and standard variants. For example if
37/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
38/// when in GNU mode.
Benjamin Kramera9992772010-01-09 17:55:51 +000039static void DefineStd(MacroBuilder &Builder, llvm::StringRef MacroName,
Chris Lattnerca45cff2009-03-20 16:06:38 +000040 const LangOptions &Opts) {
41 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000042
Chris Lattnerca45cff2009-03-20 16:06:38 +000043 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
44 // in the user's namespace.
45 if (Opts.GNUMode)
Benjamin Kramera9992772010-01-09 17:55:51 +000046 Builder.defineMacro(MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000047
Chris Lattnerca45cff2009-03-20 16:06:38 +000048 // Define __unix.
Benjamin Kramera9992772010-01-09 17:55:51 +000049 Builder.defineMacro("__" + MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000050
Chris Lattnerca45cff2009-03-20 16:06:38 +000051 // Define __unix__.
Benjamin Kramera9992772010-01-09 17:55:51 +000052 Builder.defineMacro("__" + MacroName + "__");
Chris Lattnerca45cff2009-03-20 16:06:38 +000053}
54
Chris Lattnerd29b6302008-10-05 21:50:58 +000055//===----------------------------------------------------------------------===//
56// Defines specific to certain operating systems.
57//===----------------------------------------------------------------------===//
Chris Lattner797c3c42009-08-10 19:03:04 +000058
Torok Edwin5f6c1942009-06-30 17:10:35 +000059namespace {
Douglas Gregora3844922009-07-01 15:12:53 +000060template<typename TgtInfo>
61class OSTargetInfo : public TgtInfo {
Torok Edwin5f6c1942009-06-30 17:10:35 +000062protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +000063 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +000064 MacroBuilder &Builder) const=0;
Torok Edwin5f6c1942009-06-30 17:10:35 +000065public:
Douglas Gregora3844922009-07-01 15:12:53 +000066 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {}
Torok Edwin5f6c1942009-06-30 17:10:35 +000067 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +000068 MacroBuilder &Builder) const {
69 TgtInfo::getTargetDefines(Opts, Builder);
70 getOSDefines(Opts, TgtInfo::getTriple(), Builder);
Torok Edwinb0a5b242009-06-30 17:00:25 +000071 }
Torok Edwin5f6c1942009-06-30 17:10:35 +000072
73};
Chris Lattner4c28b1c2009-08-12 06:24:27 +000074} // end anonymous namespace
Torok Edwinb0a5b242009-06-30 17:00:25 +000075
Chris Lattner797c3c42009-08-10 19:03:04 +000076
Daniel Dunbar21ae3192010-01-26 01:44:04 +000077static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
78 const llvm::Triple &Triple) {
Benjamin Kramera9992772010-01-09 17:55:51 +000079 Builder.defineMacro("__APPLE_CC__", "5621");
80 Builder.defineMacro("__APPLE__");
81 Builder.defineMacro("__MACH__");
82 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000083
Chris Lattner10d24272009-04-07 16:50:40 +000084 // __weak is always defined, for use in blocks and with objc pointers.
Benjamin Kramera9992772010-01-09 17:55:51 +000085 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000086
Chris Lattner10d24272009-04-07 16:50:40 +000087 // Darwin defines __strong even in C mode (just to nothing).
88 if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC)
Benjamin Kramera9992772010-01-09 17:55:51 +000089 Builder.defineMacro("__strong", "");
Chris Lattner10d24272009-04-07 16:50:40 +000090 else
Benjamin Kramera9992772010-01-09 17:55:51 +000091 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
Eli Friedman2de4fee2009-06-04 23:00:29 +000092
93 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +000094 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +000095 else
Benjamin Kramera9992772010-01-09 17:55:51 +000096 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +000097
98 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +000099 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000100
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000101 // Get the OS version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000102 unsigned Maj, Min, Rev;
Mike Stump1eb44332009-09-09 15:08:12 +0000103
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000104 // If no version was given, default to to 10.4.0, for simplifying tests.
105 if (Triple.getOSName() == "darwin") {
106 Min = Rev = 0;
107 Maj = 8;
108 } else
109 Triple.getDarwinNumber(Maj, Min, Rev);
110
111 // Set the appropriate OS version define.
112 if (Triple.getEnvironmentName() == "iphoneos") {
113 assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!");
114 char Str[6];
115 Str[0] = '0' + Maj;
116 Str[1] = '0' + (Min / 10);
117 Str[2] = '0' + (Min % 10);
118 Str[3] = '0' + (Rev / 10);
119 Str[4] = '0' + (Rev % 10);
120 Str[5] = '\0';
121 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
122 } else {
123 // For historical reasons that make little sense, the version passed here is
124 // the "darwin" version, which drops the 10 and offsets by 4.
125 Rev = Min;
126 Min = Maj - 4;
127 Maj = 10;
128
129 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
130 assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!");
131 char Str[5];
132 Str[0] = '0' + (Maj / 10);
133 Str[1] = '0' + (Maj % 10);
134 Str[2] = '0' + Min;
135 Str[3] = '0' + Rev;
136 Str[4] = '\0';
137 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000138 }
Eli Friedman618234a2008-08-20 02:34:37 +0000139}
Reid Spencer5f016e22007-07-11 17:01:13 +0000140
Chris Lattner797c3c42009-08-10 19:03:04 +0000141namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000142template<typename Target>
143class DarwinTargetInfo : public OSTargetInfo<Target> {
144protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000145 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000146 MacroBuilder &Builder) const {
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000147 getDarwinDefines(Builder, Opts, Triple);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000148 }
Mike Stump1eb44332009-09-09 15:08:12 +0000149
Torok Edwin5f6c1942009-06-30 17:10:35 +0000150public:
151 DarwinTargetInfo(const std::string& triple) :
152 OSTargetInfo<Target>(triple) {
153 this->TLSSupported = false;
154 }
155
Anders Carlssonf959fb52010-01-30 18:33:31 +0000156 virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000157 // Let MCSectionMachO validate this.
158 llvm::StringRef Segment, Section;
159 unsigned TAA, StubSize;
160 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
161 TAA, StubSize);
162 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000163};
164
Chris Lattner797c3c42009-08-10 19:03:04 +0000165
Torok Edwin5f6c1942009-06-30 17:10:35 +0000166// DragonFlyBSD Target
167template<typename Target>
168class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
169protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000170 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000171 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000172 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000173 Builder.defineMacro("__DragonFly__");
174 Builder.defineMacro("__DragonFly_cc_version", "100001");
175 Builder.defineMacro("__ELF__");
176 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
177 Builder.defineMacro("__tune_i386__");
178 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000179 }
180public:
Mike Stump1eb44332009-09-09 15:08:12 +0000181 DragonFlyBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000182 : OSTargetInfo<Target>(triple) {}
183};
184
185// FreeBSD Target
186template<typename Target>
187class FreeBSDTargetInfo : public OSTargetInfo<Target> {
188protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000189 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000190 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000191 // FreeBSD defines; list based off of gcc output
192
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000193 // FIXME: Move version number handling to llvm::Triple.
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000194 llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000195
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000196 Builder.defineMacro("__FreeBSD__", Release);
197 Builder.defineMacro("__FreeBSD_cc_version", Release + "00001");
Benjamin Kramera9992772010-01-09 17:55:51 +0000198 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
199 DefineStd(Builder, "unix", Opts);
200 Builder.defineMacro("__ELF__");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000201 }
202public:
Mike Stump1eb44332009-09-09 15:08:12 +0000203 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000204 : OSTargetInfo<Target>(triple) {
205 this->UserLabelPrefix = "";
206 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000207};
208
209// Linux target
210template<typename Target>
211class LinuxTargetInfo : public OSTargetInfo<Target> {
212protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000213 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000214 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000215 // Linux defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000216 DefineStd(Builder, "unix", Opts);
217 DefineStd(Builder, "linux", Opts);
218 Builder.defineMacro("__gnu_linux__");
219 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000220 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000221 Builder.defineMacro("_REENTRANT");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000222 }
223public:
Mike Stump1eb44332009-09-09 15:08:12 +0000224 LinuxTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000225 : OSTargetInfo<Target>(triple) {
226 this->UserLabelPrefix = "";
227 }
228};
229
Chris Lattnerb62bb282009-07-13 20:29:08 +0000230// NetBSD Target
231template<typename Target>
232class NetBSDTargetInfo : public OSTargetInfo<Target> {
233protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000234 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000235 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000236 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000237 Builder.defineMacro("__NetBSD__");
238 Builder.defineMacro("__unix__");
239 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000240 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000241 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000242 }
243public:
Mike Stump1eb44332009-09-09 15:08:12 +0000244 NetBSDTargetInfo(const std::string &triple)
Chris Lattnerb62bb282009-07-13 20:29:08 +0000245 : OSTargetInfo<Target>(triple) {
246 this->UserLabelPrefix = "";
247 }
248};
249
Torok Edwin5f6c1942009-06-30 17:10:35 +0000250// OpenBSD Target
251template<typename Target>
252class OpenBSDTargetInfo : public OSTargetInfo<Target> {
253protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000254 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000255 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000256 // OpenBSD defines; list based off of gcc output
257
Benjamin Kramera9992772010-01-09 17:55:51 +0000258 Builder.defineMacro("__OpenBSD__");
259 DefineStd(Builder, "unix", Opts);
260 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000261 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000262 Builder.defineMacro("_POSIX_THREADS");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000263 }
264public:
Mike Stump1eb44332009-09-09 15:08:12 +0000265 OpenBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000266 : OSTargetInfo<Target>(triple) {}
267};
268
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000269// PSP Target
270template<typename Target>
271class PSPTargetInfo : public OSTargetInfo<Target> {
272protected:
273 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000274 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000275 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000276 Builder.defineMacro("PSP");
277 Builder.defineMacro("_PSP");
278 Builder.defineMacro("__psp__");
279 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000280 }
281public:
282 PSPTargetInfo(const std::string& triple)
283 : OSTargetInfo<Target>(triple) {
284 this->UserLabelPrefix = "";
285 }
286};
287
John Thompson3f6918a2009-11-19 17:18:50 +0000288// PS3 PPU Target
289template<typename Target>
290class PS3PPUTargetInfo : public OSTargetInfo<Target> {
291protected:
292 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000293 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000294 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000295 Builder.defineMacro("__PPU__");
296 Builder.defineMacro("__CELLOS_LV2__");
297 Builder.defineMacro("__ELF__");
298 Builder.defineMacro("__LP32__");
John Thompson3f6918a2009-11-19 17:18:50 +0000299 }
300public:
301 PS3PPUTargetInfo(const std::string& triple)
302 : OSTargetInfo<Target>(triple) {
303 this->UserLabelPrefix = "";
John Thompsonec387af2009-12-18 14:21:08 +0000304 this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32;
305 this->SizeType = TargetInfo::UnsignedInt;
John Thompson3f6918a2009-11-19 17:18:50 +0000306 }
307};
308
309// FIXME: Need a real SPU target.
310// PS3 SPU Target
311template<typename Target>
312class PS3SPUTargetInfo : public OSTargetInfo<Target> {
313protected:
314 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000315 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000316 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000317 Builder.defineMacro("__SPU__");
318 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000319 }
320public:
321 PS3SPUTargetInfo(const std::string& triple)
322 : OSTargetInfo<Target>(triple) {
323 this->UserLabelPrefix = "";
324 }
325};
326
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000327// AuroraUX target
328template<typename Target>
329class AuroraUXTargetInfo : public OSTargetInfo<Target> {
330protected:
331 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000332 MacroBuilder &Builder) const {
333 DefineStd(Builder, "sun", Opts);
334 DefineStd(Builder, "unix", Opts);
335 Builder.defineMacro("__ELF__");
336 Builder.defineMacro("__svr4__");
337 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000338 }
339public:
340 AuroraUXTargetInfo(const std::string& triple)
341 : OSTargetInfo<Target>(triple) {
342 this->UserLabelPrefix = "";
343 this->WCharType = this->SignedLong;
344 // FIXME: WIntType should be SignedLong
345 }
346};
347
Torok Edwin5f6c1942009-06-30 17:10:35 +0000348// Solaris target
349template<typename Target>
350class SolarisTargetInfo : public OSTargetInfo<Target> {
351protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000352 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000353 MacroBuilder &Builder) const {
354 DefineStd(Builder, "sun", Opts);
355 DefineStd(Builder, "unix", Opts);
356 Builder.defineMacro("__ELF__");
357 Builder.defineMacro("__svr4__");
358 Builder.defineMacro("__SVR4");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000359 }
360public:
Mike Stump1eb44332009-09-09 15:08:12 +0000361 SolarisTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000362 : OSTargetInfo<Target>(triple) {
363 this->UserLabelPrefix = "";
364 this->WCharType = this->SignedLong;
365 // FIXME: WIntType should be SignedLong
366 }
367};
Mike Stump1eb44332009-09-09 15:08:12 +0000368} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000369
Chris Lattnerd29b6302008-10-05 21:50:58 +0000370//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000371// Specific target implementations.
372//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000373
Eli Friedmane4277982008-08-20 23:11:40 +0000374namespace {
375// PPC abstract base class
376class PPCTargetInfo : public TargetInfo {
377 static const Builtin::Info BuiltinInfo[];
378 static const char * const GCCRegNames[];
379 static const TargetInfo::GCCRegAlias GCCRegAliases[];
380
381public:
Eli Friedman15b91762009-06-05 07:05:05 +0000382 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
383
Eli Friedmane4277982008-08-20 23:11:40 +0000384 virtual void getTargetBuiltins(const Builtin::Info *&Records,
385 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000386 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000387 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000388 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000389
Chris Lattner33328642009-03-20 15:52:06 +0000390 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000391 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000392
Eli Friedmane4277982008-08-20 23:11:40 +0000393 virtual const char *getVAListDeclaration() const {
Chris Lattnerd5998502008-10-27 01:11:29 +0000394 return "typedef char* __builtin_va_list;";
395 // This is the right definition for ABI/V4: System V.4/eabi.
396 /*return "typedef struct __va_list_tag {"
Eli Friedmane4277982008-08-20 23:11:40 +0000397 " unsigned char gpr;"
398 " unsigned char fpr;"
399 " unsigned short reserved;"
400 " void* overflow_arg_area;"
401 " void* reg_save_area;"
Chris Lattnerd5998502008-10-27 01:11:29 +0000402 "} __builtin_va_list[1];";*/
Anders Carlsson3346ae62007-11-24 23:38:12 +0000403 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000404 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000405 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000406 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000407 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000408 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000409 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000410 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000411 default: return false;
412 case 'O': // Zero
413 return true;
414 case 'b': // Base register
415 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000416 Info.setAllowsRegister();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000417 return true;
418 }
419 }
Eli Friedmane4277982008-08-20 23:11:40 +0000420 virtual const char *getClobbers() const {
421 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000422 }
Eli Friedmane4277982008-08-20 23:11:40 +0000423};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000424
Eli Friedmane4277982008-08-20 23:11:40 +0000425const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Douglas Gregorb1152d82009-02-16 21:58:21 +0000426#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
427#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000428#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000429};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000430
431
Chris Lattnerc0f59212009-03-02 22:27:17 +0000432/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
433/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000434void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000435 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000436 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000437 Builder.defineMacro("__ppc__");
438 Builder.defineMacro("_ARCH_PPC");
439 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000440 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000441 Builder.defineMacro("_ARCH_PPC64");
442 Builder.defineMacro("_LP64");
443 Builder.defineMacro("__LP64__");
444 Builder.defineMacro("__ppc64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000445 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000446 Builder.defineMacro("__ppc__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000447 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000448
Chris Lattnerc0f59212009-03-02 22:27:17 +0000449 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +0000450 Builder.defineMacro("_BIG_ENDIAN");
451 Builder.defineMacro("__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000452
Chris Lattnerc0f59212009-03-02 22:27:17 +0000453 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000454 Builder.defineMacro("__NATURAL_ALIGNMENT__");
455 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000456
Chris Lattnerc0f59212009-03-02 22:27:17 +0000457 // FIXME: Should be controlled by command line option.
Benjamin Kramera9992772010-01-09 17:55:51 +0000458 Builder.defineMacro("__LONG_DOUBLE_128__");
John Thompson3f6918a2009-11-19 17:18:50 +0000459
460 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000461 Builder.defineMacro("__VEC__", "10206");
462 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000463 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000464}
465
Chris Lattner393ff042008-04-21 18:56:49 +0000466
Eli Friedmane4277982008-08-20 23:11:40 +0000467const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +0000468 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
469 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
470 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
471 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
472 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
473 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
474 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
475 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +0000476 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000477 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +0000478 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000479 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
480 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
481 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
482 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +0000483 "vrsave", "vscr",
484 "spe_acc", "spefscr",
485 "sfp"
486};
Reid Spencer5f016e22007-07-11 17:01:13 +0000487
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000488void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000489 unsigned &NumNames) const {
490 Names = GCCRegNames;
491 NumNames = llvm::array_lengthof(GCCRegNames);
492}
Reid Spencer5f016e22007-07-11 17:01:13 +0000493
Eli Friedmane4277982008-08-20 23:11:40 +0000494const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
495 // While some of these aliases do map to different registers
496 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000497 { { "0" }, "r0" },
498 { { "1"}, "r1" },
499 { { "2" }, "r2" },
500 { { "3" }, "r3" },
501 { { "4" }, "r4" },
502 { { "5" }, "r5" },
503 { { "6" }, "r6" },
504 { { "7" }, "r7" },
505 { { "8" }, "r8" },
506 { { "9" }, "r9" },
507 { { "10" }, "r10" },
508 { { "11" }, "r11" },
509 { { "12" }, "r12" },
510 { { "13" }, "r13" },
511 { { "14" }, "r14" },
512 { { "15" }, "r15" },
513 { { "16" }, "r16" },
514 { { "17" }, "r17" },
515 { { "18" }, "r18" },
516 { { "19" }, "r19" },
517 { { "20" }, "r20" },
518 { { "21" }, "r21" },
519 { { "22" }, "r22" },
520 { { "23" }, "r23" },
521 { { "24" }, "r24" },
522 { { "25" }, "r25" },
523 { { "26" }, "r26" },
524 { { "27" }, "r27" },
525 { { "28" }, "r28" },
526 { { "29" }, "r29" },
527 { { "30" }, "r30" },
528 { { "31" }, "r31" },
529 { { "fr0" }, "f0" },
530 { { "fr1" }, "f1" },
531 { { "fr2" }, "f2" },
532 { { "fr3" }, "f3" },
533 { { "fr4" }, "f4" },
534 { { "fr5" }, "f5" },
535 { { "fr6" }, "f6" },
536 { { "fr7" }, "f7" },
537 { { "fr8" }, "f8" },
538 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +0000539 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000540 { { "fr11" }, "f11" },
541 { { "fr12" }, "f12" },
542 { { "fr13" }, "f13" },
543 { { "fr14" }, "f14" },
544 { { "fr15" }, "f15" },
545 { { "fr16" }, "f16" },
546 { { "fr17" }, "f17" },
547 { { "fr18" }, "f18" },
548 { { "fr19" }, "f19" },
549 { { "fr20" }, "f20" },
550 { { "fr21" }, "f21" },
551 { { "fr22" }, "f22" },
552 { { "fr23" }, "f23" },
553 { { "fr24" }, "f24" },
554 { { "fr25" }, "f25" },
555 { { "fr26" }, "f26" },
556 { { "fr27" }, "f27" },
557 { { "fr28" }, "f28" },
558 { { "fr29" }, "f29" },
559 { { "fr30" }, "f30" },
560 { { "fr31" }, "f31" },
561 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +0000562};
563
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000564void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000565 unsigned &NumAliases) const {
566 Aliases = GCCRegAliases;
567 NumAliases = llvm::array_lengthof(GCCRegAliases);
568}
569} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000570
571namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000572class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000573public:
Eli Friedmaned855cb2008-08-21 00:13:15 +0000574 PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
575 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +0000576 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Eli Friedmaned855cb2008-08-21 00:13:15 +0000577 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000578};
579} // end anonymous namespace.
580
581namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000582class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000583public:
Eli Friedmane4277982008-08-20 23:11:40 +0000584 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000585 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000586 IntMaxType = SignedLong;
587 UIntMaxType = UnsignedLong;
588 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000589 DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +0000590 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Chris Lattnerf291b102008-05-09 06:17:04 +0000591 }
Eli Friedmane4277982008-08-20 23:11:40 +0000592};
593} // end anonymous namespace.
594
Reid Spencer5f016e22007-07-11 17:01:13 +0000595namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000596// Namespace for x86 abstract base class
597const Builtin::Info BuiltinInfo[] = {
Douglas Gregorb1152d82009-02-16 21:58:21 +0000598#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
599#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000600#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +0000601};
Eli Friedman61538a72008-05-20 14:21:01 +0000602
Nuno Lopes2550d702009-12-23 17:49:57 +0000603static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +0000604 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
605 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
606 "argp", "flags", "fspr", "dirflag", "frame",
607 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
608 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
609 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
610 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
611};
612
613const TargetInfo::GCCRegAlias GCCRegAliases[] = {
614 { { "al", "ah", "eax", "rax" }, "ax" },
615 { { "bl", "bh", "ebx", "rbx" }, "bx" },
616 { { "cl", "ch", "ecx", "rcx" }, "cx" },
617 { { "dl", "dh", "edx", "rdx" }, "dx" },
618 { { "esi", "rsi" }, "si" },
619 { { "edi", "rdi" }, "di" },
620 { { "esp", "rsp" }, "sp" },
621 { { "ebp", "rbp" }, "bp" },
622};
623
624// X86 target abstract base class; x86-32 and x86-64 are very close, so
625// most of the implementation can be shared.
626class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +0000627 enum X86SSEEnum {
628 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
629 } SSELevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000630 enum AMD3DNowEnum {
631 NoAMD3DNow, AMD3DNow, AMD3DNowAthlon
632 } AMD3DNowLevel;
633
Eli Friedman618234a2008-08-20 02:34:37 +0000634public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000635 X86TargetInfo(const std::string& triple)
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000636 : TargetInfo(triple), SSELevel(NoMMXSSE), AMD3DNowLevel(NoAMD3DNow) {
Eli Friedman618234a2008-08-20 02:34:37 +0000637 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +0000638 }
639 virtual void getTargetBuiltins(const Builtin::Info *&Records,
640 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000641 Records = BuiltinInfo;
642 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000643 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000644 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +0000645 unsigned &NumNames) const {
646 Names = GCCRegNames;
647 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +0000648 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000649 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +0000650 unsigned &NumAliases) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000651 Aliases = GCCRegAliases;
652 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000653 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000654 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +0000655 TargetInfo::ConstraintInfo &info) const;
656 virtual std::string convertConstraint(const char Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000657 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +0000658 return "~{dirflag},~{fpsr},~{flags}";
659 }
Chris Lattner33328642009-03-20 15:52:06 +0000660 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000661 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000662 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
663 const std::string &Name,
664 bool Enabled) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000665 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000666 llvm::StringMap<bool> &Features) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +0000667 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Reid Spencer5f016e22007-07-11 17:01:13 +0000668};
Chris Lattner3daed522009-03-02 22:20:04 +0000669
Mike Stump1eb44332009-09-09 15:08:12 +0000670void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000671 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000672 // FIXME: This should not be here.
673 Features["3dnow"] = false;
674 Features["3dnowa"] = false;
675 Features["mmx"] = false;
676 Features["sse"] = false;
677 Features["sse2"] = false;
678 Features["sse3"] = false;
679 Features["ssse3"] = false;
680 Features["sse41"] = false;
681 Features["sse42"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000682
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000683 // LLVM does not currently recognize this.
684 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000685
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000686 // FIXME: This *really* should not be here.
687
688 // X86_64 always has SSE2.
689 if (PointerWidth == 64)
690 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
691
Daniel Dunbar3ac79042009-05-06 21:56:32 +0000692 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
693 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
694 ;
695 else if (CPU == "pentium-mmx" || CPU == "pentium2")
696 setFeatureEnabled(Features, "mmx", true);
697 else if (CPU == "pentium3")
698 setFeatureEnabled(Features, "sse", true);
699 else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64")
700 setFeatureEnabled(Features, "sse2", true);
701 else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona")
702 setFeatureEnabled(Features, "sse3", true);
703 else if (CPU == "core2")
704 setFeatureEnabled(Features, "ssse3", true);
705 else if (CPU == "penryn") {
706 setFeatureEnabled(Features, "sse4", true);
707 Features["sse42"] = false;
708 } else if (CPU == "atom")
709 setFeatureEnabled(Features, "sse3", true);
710 else if (CPU == "corei7")
711 setFeatureEnabled(Features, "sse4", true);
712 else if (CPU == "k6" || CPU == "winchip-c6")
713 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +0000714 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +0000715 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
716 setFeatureEnabled(Features, "mmx", true);
717 setFeatureEnabled(Features, "3dnow", true);
718 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
719 setFeatureEnabled(Features, "sse", true);
720 setFeatureEnabled(Features, "3dnowa", true);
721 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
722 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +0000723 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +0000724 setFeatureEnabled(Features, "3dnowa", true);
725 } else if (CPU == "c3-2")
726 setFeatureEnabled(Features, "sse", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000727}
728
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000729bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +0000730 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000731 bool Enabled) const {
732 // FIXME: This *really* should not be here.
733 if (!Features.count(Name) && Name != "sse4")
734 return false;
735
736 if (Enabled) {
737 if (Name == "mmx")
738 Features["mmx"] = true;
739 else if (Name == "sse")
740 Features["mmx"] = Features["sse"] = true;
741 else if (Name == "sse2")
742 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
743 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +0000744 Features["mmx"] = Features["sse"] = Features["sse2"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000745 Features["sse3"] = true;
746 else if (Name == "ssse3")
Mike Stump1eb44332009-09-09 15:08:12 +0000747 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000748 Features["ssse3"] = true;
749 else if (Name == "sse4")
Mike Stump1eb44332009-09-09 15:08:12 +0000750 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000751 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
752 else if (Name == "3dnow")
753 Features["3dnowa"] = true;
754 else if (Name == "3dnowa")
755 Features["3dnow"] = Features["3dnowa"] = true;
756 } else {
757 if (Name == "mmx")
Mike Stump1eb44332009-09-09 15:08:12 +0000758 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000759 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
760 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +0000761 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000762 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
763 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +0000764 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000765 Features["sse41"] = Features["sse42"] = false;
766 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +0000767 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000768 Features["sse42"] = false;
769 else if (Name == "ssse3")
770 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
771 else if (Name == "sse4")
772 Features["sse41"] = Features["sse42"] = false;
773 else if (Name == "3dnow")
774 Features["3dnow"] = Features["3dnowa"] = false;
775 else if (Name == "3dnowa")
776 Features["3dnowa"] = false;
777 }
778
779 return true;
780}
781
Daniel Dunbar868bd0a2009-05-06 03:16:41 +0000782/// HandleTargetOptions - Perform initialization based on the user
783/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +0000784void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000785 // Remember the maximum enabled sselevel.
786 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
787 // Ignore disabled features.
788 if (Features[i][0] == '-')
789 continue;
790
791 assert(Features[i][0] == '+' && "Invalid target feature!");
792 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
793 .Case("sse42", SSE42)
794 .Case("sse41", SSE41)
795 .Case("ssse3", SSSE3)
796 .Case("sse2", SSE2)
797 .Case("sse", SSE1)
798 .Case("mmx", MMX)
799 .Default(NoMMXSSE);
800 SSELevel = std::max(SSELevel, Level);
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000801
802 AMD3DNowEnum ThreeDNowLevel =
803 llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1))
804 .Case("3dnowa", AMD3DNowAthlon)
805 .Case("3dnow", AMD3DNow)
806 .Default(NoAMD3DNow);
807
808 AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000809 }
Chris Lattner3daed522009-03-02 22:20:04 +0000810}
Chris Lattnerc0f59212009-03-02 22:27:17 +0000811
812/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
813/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000814void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000815 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000816 // Target identification.
817 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000818 Builder.defineMacro("_LP64");
819 Builder.defineMacro("__LP64__");
820 Builder.defineMacro("__amd64__");
821 Builder.defineMacro("__amd64");
822 Builder.defineMacro("__x86_64");
823 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000824 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000825 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +0000826 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000827
Chris Lattnerc0f59212009-03-02 22:27:17 +0000828 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +0000829 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000830
Chris Lattnerc0f59212009-03-02 22:27:17 +0000831 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000832 Builder.defineMacro("__nocona");
833 Builder.defineMacro("__nocona__");
834 Builder.defineMacro("__tune_nocona__");
835 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000836
Chris Lattner54175442009-04-19 17:32:33 +0000837 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
838 // functions in glibc header files that use FP Stack inline asm which the
839 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +0000840 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000841
Chris Lattner84f0ea82009-03-02 22:40:39 +0000842 // Each case falls through to the previous one here.
843 switch (SSELevel) {
844 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +0000845 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000846 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +0000847 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000848 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +0000849 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000850 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +0000851 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000852 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +0000853 Builder.defineMacro("__SSE2__");
854 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +0000855 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +0000856 Builder.defineMacro("__SSE__");
857 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +0000858 case MMX:
Benjamin Kramera9992772010-01-09 17:55:51 +0000859 Builder.defineMacro("__MMX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +0000860 case NoMMXSSE:
861 break;
862 }
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000863
864 // Each case falls through to the previous one here.
865 switch (AMD3DNowLevel) {
866 case AMD3DNowAthlon:
867 Builder.defineMacro("__3dNOW_A__");
868 case AMD3DNow:
869 Builder.defineMacro("__3dNOW__");
870 case NoAMD3DNow:
871 break;
872 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000873}
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000874
875
Eli Friedman618234a2008-08-20 02:34:37 +0000876bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000877X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000878 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000879 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +0000880 default: return false;
881 case 'a': // eax.
882 case 'b': // ebx.
883 case 'c': // ecx.
884 case 'd': // edx.
885 case 'S': // esi.
886 case 'D': // edi.
887 case 'A': // edx:eax.
888 case 't': // top of floating point stack.
889 case 'u': // second from top of floating point stack.
890 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +0000891 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +0000892 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +0000893 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000894 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +0000895 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000896 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +0000897 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +0000898 case 'N': // unsigned 8-bit integer constant for use with in and out
899 // instructions.
Eli Friedman12b2da02009-06-08 20:45:44 +0000900 case 'R': // "legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
Chris Lattner44def072009-04-26 07:16:29 +0000901 Info.setAllowsRegister();
Eli Friedman618234a2008-08-20 02:34:37 +0000902 return true;
903 }
904}
905
906std::string
907X86TargetInfo::convertConstraint(const char Constraint) const {
908 switch (Constraint) {
909 case 'a': return std::string("{ax}");
910 case 'b': return std::string("{bx}");
911 case 'c': return std::string("{cx}");
912 case 'd': return std::string("{dx}");
913 case 'S': return std::string("{si}");
914 case 'D': return std::string("{di}");
915 case 't': // top of floating point stack.
916 return std::string("{st}");
917 case 'u': // second from top of floating point stack.
918 return std::string("{st(1)}"); // second from top of floating point stack.
919 default:
920 return std::string(1, Constraint);
921 }
922}
Eli Friedman618234a2008-08-20 02:34:37 +0000923} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +0000924
925namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000926// X86-32 generic target
927class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000928public:
Eli Friedman618234a2008-08-20 02:34:37 +0000929 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
930 DoubleAlign = LongLongAlign = 32;
931 LongDoubleWidth = 96;
932 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000933 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
934 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +0000935 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +0000936 SizeType = UnsignedInt;
937 PtrDiffType = SignedInt;
938 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +0000939 RegParmMax = 3;
Eli Friedman618234a2008-08-20 02:34:37 +0000940 }
941 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +0000942 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +0000943 }
Chris Lattner21fb98e2009-09-23 06:06:36 +0000944
945 int getEHDataRegisterNumber(unsigned RegNo) const {
946 if (RegNo == 0) return 0;
947 if (RegNo == 1) return 2;
948 return -1;
949 }
Eli Friedman618234a2008-08-20 02:34:37 +0000950};
951} // end anonymous namespace
952
953namespace {
Eli Friedman624c1462009-07-05 18:47:56 +0000954class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
955public:
956 OpenBSDI386TargetInfo(const std::string& triple) :
957 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
958 SizeType = UnsignedLong;
959 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +0000960 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +0000961 }
962};
963} // end anonymous namespace
964
965namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000966class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +0000967public:
Torok Edwin5f6c1942009-06-30 17:10:35 +0000968 DarwinI386TargetInfo(const std::string& triple) :
969 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +0000970 LongDoubleWidth = 128;
971 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +0000972 SizeType = UnsignedLong;
973 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000974 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
975 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +0000976 "a0:0:64-f80:128:128-n8:16:32";
Torok Edwinb0a5b242009-06-30 17:00:25 +0000977 }
978
Eli Friedman618234a2008-08-20 02:34:37 +0000979};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000980} // end anonymous namespace
981
982namespace {
Eli Friedman29a30502008-08-21 01:40:19 +0000983// x86-32 Windows target
984class WindowsX86_32TargetInfo : public X86_32TargetInfo {
985public:
986 WindowsX86_32TargetInfo(const std::string& triple)
987 : X86_32TargetInfo(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +0000988 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +0000989 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +0000990 DoubleAlign = LongLongAlign = 64;
991 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Anton Korobeynikovb3814412009-12-19 02:05:07 +0000992 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
993 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +0000994 }
Chris Lattner33328642009-03-20 15:52:06 +0000995 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000996 MacroBuilder &Builder) const {
997 X86_32TargetInfo::getTargetDefines(Opts, Builder);
Eli Friedman29a30502008-08-21 01:40:19 +0000998 // This list is based off of the the list of things MingW defines
Benjamin Kramera9992772010-01-09 17:55:51 +0000999 Builder.defineMacro("_WIN32");
1000 DefineStd(Builder, "WIN32", Opts);
1001 DefineStd(Builder, "WINNT", Opts);
1002 Builder.defineMacro("_X86_");
Eli Friedman29a30502008-08-21 01:40:19 +00001003 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001004};
1005} // end anonymous namespace
Eli Friedmanabc4e322009-06-08 06:11:14 +00001006
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001007namespace {
1008
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001009// x86-32 Windows Visual Studio target
1010class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1011public:
1012 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1013 : WindowsX86_32TargetInfo(triple) {
1014 }
1015 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001016 MacroBuilder &Builder) const {
1017 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001018 // The value of the following reflects processor type.
1019 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1020 // We lost the original triple, so we use the default.
Benjamin Kramera9992772010-01-09 17:55:51 +00001021 Builder.defineMacro("_M_IX86", "600");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001022 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001023};
1024} // end anonymous namespace
1025
1026namespace {
1027// x86-32 MinGW target
1028class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1029public:
1030 MinGWX86_32TargetInfo(const std::string& triple)
1031 : WindowsX86_32TargetInfo(triple) {
1032 }
1033 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001034 MacroBuilder &Builder) const {
1035 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1036 Builder.defineMacro("__MSVCRT__");
1037 Builder.defineMacro("__MINGW32__");
1038 Builder.defineMacro("__declspec", "__declspec");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001039 }
1040};
1041} // end anonymous namespace
1042
1043namespace {
1044// x86-32 Cygwin target
1045class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1046public:
1047 CygwinX86_32TargetInfo(const std::string& triple)
1048 : X86_32TargetInfo(triple) {
1049 TLSSupported = false;
1050 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001051 DoubleAlign = LongLongAlign = 64;
1052 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1053 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001054 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001055 }
1056 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001057 MacroBuilder &Builder) const {
1058 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1059 Builder.defineMacro("__CYGWIN__");
1060 Builder.defineMacro("__CYGWIN32__");
1061 DefineStd(Builder, "unix", Opts);
Eli Friedmanabc4e322009-06-08 06:11:14 +00001062 }
Eli Friedman29a30502008-08-21 01:40:19 +00001063};
1064} // end anonymous namespace
1065
1066namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001067// x86-64 generic target
1068class X86_64TargetInfo : public X86TargetInfo {
1069public:
Chris Lattner33328642009-03-20 15:52:06 +00001070 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001071 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001072 LongDoubleWidth = 128;
1073 LongDoubleAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001074 IntMaxType = SignedLong;
1075 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001076 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001077 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001078
Eli Friedmaned855cb2008-08-21 00:13:15 +00001079 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1080 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001081 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Reid Spencer5f016e22007-07-11 17:01:13 +00001082 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001083 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001084 return "typedef struct __va_list_tag {"
1085 " unsigned gp_offset;"
1086 " unsigned fp_offset;"
1087 " void* overflow_arg_area;"
1088 " void* reg_save_area;"
Eli Friedmandc043162009-07-03 00:45:06 +00001089 "} __va_list_tag;"
1090 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001091 }
Chris Lattner21fb98e2009-09-23 06:06:36 +00001092
1093 int getEHDataRegisterNumber(unsigned RegNo) const {
1094 if (RegNo == 0) return 0;
1095 if (RegNo == 1) return 1;
1096 return -1;
1097 }
Eli Friedman618234a2008-08-20 02:34:37 +00001098};
1099} // end anonymous namespace
1100
1101namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001102// x86-64 Windows target
1103class WindowsX86_64TargetInfo : public X86_64TargetInfo {
1104public:
1105 WindowsX86_64TargetInfo(const std::string& triple)
1106 : X86_64TargetInfo(triple) {
1107 TLSSupported = false;
1108 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001109 LongWidth = LongAlign = 32;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001110 DoubleAlign = LongLongAlign = 64;
1111 }
1112 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001113 MacroBuilder &Builder) const {
1114 X86_64TargetInfo::getTargetDefines(Opts, Builder);
1115 Builder.defineMacro("_WIN64");
1116 DefineStd(Builder, "WIN64", Opts);
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001117 }
1118};
1119} // end anonymous namespace
1120
1121namespace {
1122// x86-64 Windows Visual Studio target
1123class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1124public:
1125 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1126 : WindowsX86_64TargetInfo(triple) {
1127 }
1128 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001129 MacroBuilder &Builder) const {
1130 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1131 Builder.defineMacro("_M_X64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001132 }
1133 virtual const char *getVAListDeclaration() const {
1134 return "typedef char* va_list;";
1135 }
1136};
1137} // end anonymous namespace
1138
1139namespace {
1140// x86-64 MinGW target
1141class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1142public:
1143 MinGWX86_64TargetInfo(const std::string& triple)
1144 : WindowsX86_64TargetInfo(triple) {
1145 }
1146 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001147 MacroBuilder &Builder) const {
1148 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1149 Builder.defineMacro("__MSVCRT__");
1150 Builder.defineMacro("__MINGW64__");
1151 Builder.defineMacro("__declspec");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001152 }
1153};
1154} // end anonymous namespace
1155
1156namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001157class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1158public:
Mike Stump1eb44332009-09-09 15:08:12 +00001159 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001160 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1161 Int64Type = SignedLongLong;
1162 }
1163};
1164} // end anonymous namespace
1165
1166namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001167class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1168public:
Mike Stump1eb44332009-09-09 15:08:12 +00001169 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001170 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1171 IntMaxType = SignedLongLong;
1172 UIntMaxType = UnsignedLongLong;
1173 Int64Type = SignedLongLong;
1174 }
1175};
1176} // end anonymous namespace
1177
1178namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001179class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001180 // Possible FPU choices.
1181 enum FPUMode {
1182 NoFPU,
1183 VFP2FPU,
1184 VFP3FPU,
1185 NeonFPU
1186 };
1187
1188 static bool FPUModeIsVFP(FPUMode Mode) {
1189 return Mode >= VFP2FPU && Mode <= NeonFPU;
1190 }
1191
1192 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1193 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001194
Daniel Dunbareac7c532009-12-18 18:42:37 +00001195 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001196
1197 unsigned FPU : 3;
1198
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001199 unsigned IsThumb : 1;
1200
1201 // Initialized via features.
1202 unsigned SoftFloat : 1;
1203 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001204
Chris Lattner393ff042008-04-21 18:56:49 +00001205public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001206 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001207 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001208 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001209 SizeType = UnsignedInt;
1210 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001211
Daniel Dunbareac7c532009-12-18 18:42:37 +00001212 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001213 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001214 if (IsThumb) {
1215 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1216 "i64:64:64-f32:32:32-f64:64:64-"
Chris Lattner1932e122009-11-07 18:59:41 +00001217 "v64:64:64-v128:128:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001218 } else {
1219 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1220 "i64:64:64-f32:32:32-f64:64:64-"
Chris Lattner1932e122009-11-07 18:59:41 +00001221 "v64:64:64-v128:128:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001222 }
Eli Friedman61538a72008-05-20 14:21:01 +00001223 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001224 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001225 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001226 ABI = Name;
1227
Daniel Dunbara2a41612009-09-14 00:02:24 +00001228 // The defaults (above) are for AAPCS, check if we need to change them.
1229 //
1230 // FIXME: We need support for -meabi... we could just mangle it into the
1231 // name.
1232 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001233 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001234 SizeType = UnsignedLong;
1235
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001236 if (IsThumb) {
1237 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1238 "i64:32:32-f32:32:32-f64:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001239 "v64:64:64-v128:128:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001240 } else {
1241 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1242 "i64:32:32-f32:32:32-f64:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001243 "v64:64:64-v128:128:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001244 }
1245
Daniel Dunbara2a41612009-09-14 00:02:24 +00001246 // FIXME: Override "preferred align" for double and long long.
1247 } else if (Name == "aapcs") {
1248 // FIXME: Enumerated types are variable width in straight AAPCS.
1249 } else if (Name == "aapcs-linux") {
1250 ;
1251 } else
1252 return false;
1253
1254 return true;
1255 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001256
Daniel Dunbara91320b2009-12-21 23:28:17 +00001257 void getDefaultFeatures(const std::string &CPU,
1258 llvm::StringMap<bool> &Features) const {
1259 // FIXME: This should not be here.
1260 Features["vfp2"] = false;
1261 Features["vfp3"] = false;
1262 Features["neon"] = false;
1263
1264 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
1265 Features["vfp2"] = true;
1266 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
1267 Features["neon"] = true;
1268 }
1269
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001270 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1271 const std::string &Name,
1272 bool Enabled) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001273 if (Name == "soft-float" || Name == "soft-float-abi") {
1274 Features[Name] = Enabled;
1275 } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") {
1276 // These effectively are a single option, reset them when any is enabled.
1277 if (Enabled)
1278 Features["vfp2"] = Features["vfp3"] = Features["neon"] = false;
1279 Features[Name] = Enabled;
1280 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001281 return false;
1282
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001283 return true;
1284 }
1285
1286 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001287 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001288 SoftFloat = SoftFloatABI = false;
1289 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
1290 if (Features[i] == "+soft-float")
1291 SoftFloat = true;
1292 else if (Features[i] == "+soft-float-abi")
1293 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001294 else if (Features[i] == "+vfp2")
1295 FPU = VFP2FPU;
1296 else if (Features[i] == "+vfp3")
1297 FPU = VFP3FPU;
1298 else if (Features[i] == "+neon")
1299 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001300 }
1301
1302 // Remove front-end specific options which the backend handles differently.
1303 std::vector<std::string>::iterator it;
1304 it = std::find(Features.begin(), Features.end(), "+soft-float");
1305 if (it != Features.end())
1306 Features.erase(it);
1307 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
1308 if (it != Features.end())
1309 Features.erase(it);
1310 }
1311
Daniel Dunbareac7c532009-12-18 18:42:37 +00001312 static const char *getCPUDefineSuffix(llvm::StringRef Name) {
1313 return llvm::StringSwitch<const char*>(Name)
1314 .Cases("arm8", "arm810", "4")
1315 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
1316 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
1317 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
1318 .Case("ep9312", "4T")
1319 .Cases("arm10tdmi", "arm1020t", "5T")
1320 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
1321 .Case("arm926ej-s", "5TEJ")
1322 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
1323 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001324 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001325 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001326 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001327 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
1328 .Cases("cortex-a8", "cortex-a9", "7A")
1329 .Default(0);
1330 }
1331 virtual bool setCPU(const std::string &Name) {
1332 if (!getCPUDefineSuffix(Name))
1333 return false;
1334
1335 CPU = Name;
1336 return true;
1337 }
Chris Lattner33328642009-03-20 15:52:06 +00001338 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001339 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001340 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00001341 Builder.defineMacro("__arm");
1342 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001343
Chris Lattnerc0f59212009-03-02 22:27:17 +00001344 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001345 Builder.defineMacro("__ARMEL__");
1346 Builder.defineMacro("__LITTLE_ENDIAN__");
1347 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001348
1349 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00001350 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001351
Mike Stump437bb4b2009-04-08 02:07:04 +00001352 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001353
Daniel Dunbareac7c532009-12-18 18:42:37 +00001354 // FIXME: It's more complicated than this and we don't really support
1355 // interworking.
1356 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00001357 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001358
Daniel Dunbareac7c532009-12-18 18:42:37 +00001359 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00001360 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001361
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001362 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00001363 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001364
1365 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00001366 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001367
Daniel Dunbara91320b2009-12-21 23:28:17 +00001368 bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7"));
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001369 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001370 Builder.defineMacro("__THUMBEL__");
1371 Builder.defineMacro("__thumb__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001372 if (IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001373 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001374 }
1375
1376 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00001377 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001378
1379 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00001380 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001381
1382 // This only gets set when Neon instructions are actually available, unlike
1383 // the VFP define, hence the soft float and arch check. This is subtly
1384 // different from gcc, we follow the intent which was that it should be set
1385 // when Neon instructions are actually available.
1386 if (FPU == NeonFPU && !SoftFloat && IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001387 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00001388 }
1389 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1390 unsigned &NumRecords) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001391 // FIXME: Implement.
1392 Records = 0;
Chris Lattner393ff042008-04-21 18:56:49 +00001393 NumRecords = 0;
1394 }
1395 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001396 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001397 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001398 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001399 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001400 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001401 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001402 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001403 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001404 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001405 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001406 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001407 case 'l': // r0-r7
1408 case 'h': // r8-r15
1409 case 'w': // VFP Floating point register single precision
1410 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001411 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001412 return true;
1413 }
Chris Lattner393ff042008-04-21 18:56:49 +00001414 return false;
1415 }
1416 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001417 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001418 return "";
1419 }
1420};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001421
1422const char * const ARMTargetInfo::GCCRegNames[] = {
1423 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1424 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1425};
1426
1427void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
1428 unsigned &NumNames) const {
1429 Names = GCCRegNames;
1430 NumNames = llvm::array_lengthof(GCCRegNames);
1431}
1432
1433const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
1434
1435 { { "a1" }, "r0" },
1436 { { "a2" }, "r1" },
1437 { { "a3" }, "r2" },
1438 { { "a4" }, "r3" },
1439 { { "v1" }, "r4" },
1440 { { "v2" }, "r5" },
1441 { { "v3" }, "r6" },
1442 { { "v4" }, "r7" },
1443 { { "v5" }, "r8" },
1444 { { "v6", "rfp" }, "r9" },
1445 { { "sl" }, "r10" },
1446 { { "fp" }, "r11" },
1447 { { "ip" }, "r12" },
1448 { { "sp" }, "r13" },
1449 { { "lr" }, "r14" },
1450 { { "pc" }, "r15" },
1451};
1452
1453void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
1454 unsigned &NumAliases) const {
1455 Aliases = GCCRegAliases;
1456 NumAliases = llvm::array_lengthof(GCCRegAliases);
1457}
Chris Lattner393ff042008-04-21 18:56:49 +00001458} // end anonymous namespace.
1459
Eli Friedmana9f54962008-08-20 07:44:10 +00001460
1461namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00001462class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00001463 public DarwinTargetInfo<ARMTargetInfo> {
1464protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00001465 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00001466 MacroBuilder &Builder) const {
Daniel Dunbar21ae3192010-01-26 01:44:04 +00001467 getDarwinDefines(Builder, Opts, Triple);
Eli Friedmanb030f022009-04-19 21:38:35 +00001468 }
Eli Friedmana9f54962008-08-20 07:44:10 +00001469
Torok Edwin5f6c1942009-06-30 17:10:35 +00001470public:
Mike Stump1eb44332009-09-09 15:08:12 +00001471 DarwinARMTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +00001472 : DarwinTargetInfo<ARMTargetInfo>(triple) {}
Eli Friedmana9f54962008-08-20 07:44:10 +00001473};
1474} // end anonymous namespace.
1475
Reid Spencer5f016e22007-07-11 17:01:13 +00001476namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00001477class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00001478 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1479 static const char * const GCCRegNames[];
Gabor Greif26658672008-02-21 16:29:08 +00001480public:
Eli Friedman01b86682008-08-20 07:28:14 +00001481 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
1482 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001483 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001484 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00001485 }
Chris Lattner33328642009-03-20 15:52:06 +00001486 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001487 MacroBuilder &Builder) const {
1488 DefineStd(Builder, "sparc", Opts);
1489 Builder.defineMacro("__sparcv8");
1490 Builder.defineMacro("__REGISTER_PREFIX__", "");
Gabor Greif26658672008-02-21 16:29:08 +00001491 }
1492 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1493 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001494 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00001495 }
1496 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001497 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00001498 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001499 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001500 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001501 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001502 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001503 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00001504 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00001505 // FIXME: Implement!
1506 return false;
Gabor Greif26658672008-02-21 16:29:08 +00001507 }
1508 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001509 // FIXME: Implement!
1510 return "";
Gabor Greif26658672008-02-21 16:29:08 +00001511 }
1512};
1513
Chris Lattnere957f532009-01-27 01:58:38 +00001514const char * const SparcV8TargetInfo::GCCRegNames[] = {
1515 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1516 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
1517 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
1518 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
1519};
1520
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001521void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00001522 unsigned &NumNames) const {
1523 Names = GCCRegNames;
1524 NumNames = llvm::array_lengthof(GCCRegNames);
1525}
1526
1527const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001528 { { "g0" }, "r0" },
1529 { { "g1" }, "r1" },
1530 { { "g2" }, "r2" },
1531 { { "g3" }, "r3" },
1532 { { "g4" }, "r4" },
1533 { { "g5" }, "r5" },
1534 { { "g6" }, "r6" },
1535 { { "g7" }, "r7" },
1536 { { "o0" }, "r8" },
1537 { { "o1" }, "r9" },
1538 { { "o2" }, "r10" },
1539 { { "o3" }, "r11" },
1540 { { "o4" }, "r12" },
1541 { { "o5" }, "r13" },
1542 { { "o6", "sp" }, "r14" },
1543 { { "o7" }, "r15" },
1544 { { "l0" }, "r16" },
1545 { { "l1" }, "r17" },
1546 { { "l2" }, "r18" },
1547 { { "l3" }, "r19" },
1548 { { "l4" }, "r20" },
1549 { { "l5" }, "r21" },
1550 { { "l6" }, "r22" },
1551 { { "l7" }, "r23" },
1552 { { "i0" }, "r24" },
1553 { { "i1" }, "r25" },
1554 { { "i2" }, "r26" },
1555 { { "i3" }, "r27" },
1556 { { "i4" }, "r28" },
1557 { { "i5" }, "r29" },
1558 { { "i6", "fp" }, "r30" },
1559 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00001560};
1561
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001562void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00001563 unsigned &NumAliases) const {
1564 Aliases = GCCRegAliases;
1565 NumAliases = llvm::array_lengthof(GCCRegAliases);
1566}
Gabor Greif26658672008-02-21 16:29:08 +00001567} // end anonymous namespace.
1568
Eli Friedman01b86682008-08-20 07:28:14 +00001569namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00001570class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
1571public:
1572 AuroraUXSparcV8TargetInfo(const std::string& triple) :
1573 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
1574 SizeType = UnsignedInt;
1575 PtrDiffType = SignedInt;
1576 }
1577};
Torok Edwin5f6c1942009-06-30 17:10:35 +00001578class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00001579public:
1580 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00001581 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00001582 SizeType = UnsignedInt;
1583 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00001584 }
1585};
1586} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00001587
Chris Lattner2621fd12008-05-08 05:58:21 +00001588namespace {
1589 class PIC16TargetInfo : public TargetInfo{
1590 public:
1591 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001592 TLSSupported = false;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001593 IntWidth = 16;
1594 LongWidth = LongLongWidth = 32;
1595 PointerWidth = 16;
1596 IntAlign = 8;
1597 LongAlign = LongLongAlign = 8;
Eli Friedman61538a72008-05-20 14:21:01 +00001598 PointerAlign = 8;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +00001599 SizeType = UnsignedInt;
1600 IntMaxType = SignedLong;
1601 UIntMaxType = UnsignedLong;
Chris Lattner6ad474f2009-02-13 22:28:55 +00001602 IntPtrType = SignedShort;
Eli Friedmanf509d732008-11-02 02:43:55 +00001603 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00001604 SigAtomicType = SignedLong;
Sanjiv Gupta9eb4cef2009-06-02 04:43:46 +00001605 FloatWidth = 32;
1606 FloatAlign = 32;
1607 DoubleWidth = 32;
1608 DoubleAlign = 32;
1609 LongDoubleWidth = 32;
1610 LongDoubleAlign = 32;
1611 FloatFormat = &llvm::APFloat::IEEEsingle;
1612 DoubleFormat = &llvm::APFloat::IEEEsingle;
1613 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner1932e122009-11-07 18:59:41 +00001614 DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32-n8";
Sanjiv Gupta9eb4cef2009-06-02 04:43:46 +00001615
Chris Lattner2621fd12008-05-08 05:58:21 +00001616 }
Chris Lattner927686f2008-05-09 06:08:39 +00001617 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }
1618 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; }
Chris Lattner33328642009-03-20 15:52:06 +00001619 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001620 MacroBuilder &Builder) const {
1621 Builder.defineMacro("__pic16");
Sanjiv Guptafcd302b2010-02-16 03:37:11 +00001622 Builder.defineMacro("__PIC16");
Benjamin Kramera9992772010-01-09 17:55:51 +00001623 Builder.defineMacro("rom", "__attribute__((address_space(1)))");
1624 Builder.defineMacro("ram", "__attribute__((address_space(0)))");
Sanjiv Guptafcd302b2010-02-16 03:37:11 +00001625 Builder.defineMacro("__section(SectName)",
Sanjiv Guptada3e03e2009-08-20 17:48:52 +00001626 "__attribute__((section(SectName)))");
Benjamin Kramera9992772010-01-09 17:55:51 +00001627 Builder.defineMacro("near",
Sanjiv Gupta7de70092009-10-24 18:08:20 +00001628 "__attribute__((section(\"Address=NEAR\")))");
Sanjiv Guptafcd302b2010-02-16 03:37:11 +00001629 Builder.defineMacro("__address(Addr)",
Sanjiv Guptada3e03e2009-08-20 17:48:52 +00001630 "__attribute__((section(\"Address=\"#Addr)))");
Sanjiv Guptafcd302b2010-02-16 03:37:11 +00001631 Builder.defineMacro("__config(conf)", "asm(\"CONFIG \"#conf)");
1632 Builder.defineMacro("__idlocs(value)", "asm(\"__IDLOCS \"#value)");
1633 Builder.defineMacro("interrupt",
Sanjiv Guptada3e03e2009-08-20 17:48:52 +00001634 "__attribute__((section(\"interrupt=0x4\"))) \
1635 __attribute__((used))");
Chris Lattner2621fd12008-05-08 05:58:21 +00001636 }
1637 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1638 unsigned &NumRecords) const {}
Mike Stump1eb44332009-09-09 15:08:12 +00001639 virtual const char *getVAListDeclaration() const {
Sanjiv Guptafcd302b2010-02-16 03:37:11 +00001640 return "typedef char* __builtin_va_list;";
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001641 }
1642 virtual const char *getClobbers() const {
1643 return "";
1644 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001645 virtual void getGCCRegNames(const char * const *&Names,
1646 unsigned &NumNames) const {}
1647 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner2621fd12008-05-08 05:58:21 +00001648 TargetInfo::ConstraintInfo &info) const {
1649 return true;
1650 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001651 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattner2621fd12008-05-08 05:58:21 +00001652 unsigned &NumAliases) const {}
1653 virtual bool useGlobalsForAutomaticVariables() const {return true;}
1654 };
1655}
1656
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001657namespace {
1658 class MSP430TargetInfo : public TargetInfo {
1659 static const char * const GCCRegNames[];
1660 public:
1661 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
1662 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00001663 IntWidth = 16; IntAlign = 16;
1664 LongWidth = 32; LongLongWidth = 64;
1665 LongAlign = LongLongAlign = 16;
1666 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001667 SizeType = UnsignedInt;
1668 IntMaxType = SignedLong;
1669 UIntMaxType = UnsignedLong;
1670 IntPtrType = SignedShort;
1671 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00001672 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00001673 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001674 }
1675 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001676 MacroBuilder &Builder) const {
1677 Builder.defineMacro("MSP430");
1678 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001679 // FIXME: defines for different 'flavours' of MCU
1680 }
1681 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1682 unsigned &NumRecords) const {
1683 // FIXME: Implement.
1684 Records = 0;
1685 NumRecords = 0;
1686 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001687 virtual void getGCCRegNames(const char * const *&Names,
1688 unsigned &NumNames) const;
1689 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1690 unsigned &NumAliases) const {
1691 // No aliases.
1692 Aliases = 0;
1693 NumAliases = 0;
1694 }
1695 virtual bool validateAsmConstraint(const char *&Name,
1696 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00001697 // No target constraints for now.
1698 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001699 }
1700 virtual const char *getClobbers() const {
1701 // FIXME: Is this really right?
1702 return "";
1703 }
1704 virtual const char *getVAListDeclaration() const {
1705 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00001706 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00001707 }
1708 };
1709
1710 const char * const MSP430TargetInfo::GCCRegNames[] = {
1711 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1712 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1713 };
1714
1715 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
1716 unsigned &NumNames) const {
1717 Names = GCCRegNames;
1718 NumNames = llvm::array_lengthof(GCCRegNames);
1719 }
1720}
1721
1722
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001723namespace {
1724 class SystemZTargetInfo : public TargetInfo {
1725 static const char * const GCCRegNames[];
1726 public:
1727 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
1728 TLSSupported = false;
1729 IntWidth = IntAlign = 32;
1730 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
1731 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00001732 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
1733 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001734 }
1735 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001736 MacroBuilder &Builder) const {
1737 Builder.defineMacro("__s390__");
1738 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001739 }
1740 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1741 unsigned &NumRecords) const {
1742 // FIXME: Implement.
1743 Records = 0;
1744 NumRecords = 0;
1745 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001746
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001747 virtual void getGCCRegNames(const char * const *&Names,
1748 unsigned &NumNames) const;
1749 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1750 unsigned &NumAliases) const {
1751 // No aliases.
1752 Aliases = 0;
1753 NumAliases = 0;
1754 }
1755 virtual bool validateAsmConstraint(const char *&Name,
1756 TargetInfo::ConstraintInfo &info) const {
1757 // FIXME: implement
1758 return true;
1759 }
1760 virtual const char *getClobbers() const {
1761 // FIXME: Is this really right?
1762 return "";
1763 }
1764 virtual const char *getVAListDeclaration() const {
1765 // FIXME: implement
1766 return "typedef char* __builtin_va_list;";
1767 }
1768 };
1769
1770 const char * const SystemZTargetInfo::GCCRegNames[] = {
1771 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1772 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1773 };
1774
1775 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
1776 unsigned &NumNames) const {
1777 Names = GCCRegNames;
1778 NumNames = llvm::array_lengthof(GCCRegNames);
1779 }
1780}
1781
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00001782namespace {
1783 class BlackfinTargetInfo : public TargetInfo {
1784 static const char * const GCCRegNames[];
1785 public:
1786 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
1787 TLSSupported = false;
1788 DoubleAlign = 32;
1789 LongLongAlign = 32;
1790 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00001791 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00001792 }
1793
1794 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001795 MacroBuilder &Builder) const {
1796 DefineStd(Builder, "bfin", Opts);
1797 DefineStd(Builder, "BFIN", Opts);
1798 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00001799 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00001800 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00001801 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
1802 }
1803
1804 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1805 unsigned &NumRecords) const {
1806 // FIXME: Implement.
1807 Records = 0;
1808 NumRecords = 0;
1809 }
1810
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00001811 virtual void getGCCRegNames(const char * const *&Names,
1812 unsigned &NumNames) const;
1813
1814 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1815 unsigned &NumAliases) const {
1816 // No aliases.
1817 Aliases = 0;
1818 NumAliases = 0;
1819 }
1820
1821 virtual bool validateAsmConstraint(const char *&Name,
1822 TargetInfo::ConstraintInfo &Info) const {
1823 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
1824 Info.setAllowsRegister();
1825 return true;
1826 }
1827 return false;
1828 }
1829
1830 virtual const char *getClobbers() const {
1831 return "";
1832 }
1833
1834 virtual const char *getVAListDeclaration() const {
1835 return "typedef char* __builtin_va_list;";
1836 }
1837 };
1838
1839 const char * const BlackfinTargetInfo::GCCRegNames[] = {
1840 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1841 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
1842 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
1843 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
1844 "a0", "a1", "cc",
1845 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
1846 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
1847 };
1848
1849 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
1850 unsigned &NumNames) const {
1851 Names = GCCRegNames;
1852 NumNames = llvm::array_lengthof(GCCRegNames);
1853 }
1854}
1855
Eli Friedmanb63decf2009-08-19 20:47:07 +00001856namespace {
1857
Mike Stump1eb44332009-09-09 15:08:12 +00001858 // LLVM and Clang cannot be used directly to output native binaries for
1859 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00001860 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00001861 //
1862 // TCE uses the llvm bitcode as input and uses it for generating customized
1863 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00001864 // publicly available in http://tce.cs.tut.fi
1865
1866 class TCETargetInfo : public TargetInfo{
1867 public:
1868 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
1869 TLSSupported = false;
1870 IntWidth = 32;
1871 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00001872 PointerWidth = 32;
1873 IntAlign = 32;
1874 LongAlign = LongLongAlign = 32;
1875 PointerAlign = 32;
1876 SizeType = UnsignedInt;
1877 IntMaxType = SignedLong;
1878 UIntMaxType = UnsignedLong;
1879 IntPtrType = SignedInt;
1880 PtrDiffType = SignedInt;
1881 FloatWidth = 32;
1882 FloatAlign = 32;
1883 DoubleWidth = 32;
1884 DoubleAlign = 32;
1885 LongDoubleWidth = 32;
1886 LongDoubleAlign = 32;
1887 FloatFormat = &llvm::APFloat::IEEEsingle;
1888 DoubleFormat = &llvm::APFloat::IEEEsingle;
1889 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
1890 DescriptionString = "E-p:32:32:32-a0:32:32"
1891 "-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64"
Chris Lattner1932e122009-11-07 18:59:41 +00001892 "-f32:32:32-f64:32:64-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00001893 }
1894
1895 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001896 MacroBuilder &Builder) const {
1897 DefineStd(Builder, "tce", Opts);
1898 Builder.defineMacro("__TCE__");
1899 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00001900 }
1901 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1902 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001903 virtual const char *getClobbers() const {
1904 return "";
1905 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00001906 virtual const char *getVAListDeclaration() const {
1907 return "typedef void* __builtin_va_list;";
1908 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00001909 virtual void getGCCRegNames(const char * const *&Names,
1910 unsigned &NumNames) const {}
1911 virtual bool validateAsmConstraint(const char *&Name,
1912 TargetInfo::ConstraintInfo &info) const {
1913 return true;
1914 }
1915 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1916 unsigned &NumAliases) const {}
1917 };
1918}
1919
Edward O'Callaghan84423a82009-11-15 10:22:07 +00001920namespace {
1921class MipsTargetInfo : public TargetInfo {
1922 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1923 static const char * const GCCRegNames[];
1924public:
1925 MipsTargetInfo(const std::string& triple) : TargetInfo(triple) {
1926 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
1927 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
1928 }
1929 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001930 MacroBuilder &Builder) const {
1931 DefineStd(Builder, "mips", Opts);
1932 Builder.defineMacro("_mips");
1933 DefineStd(Builder, "MIPSEB", Opts);
1934 Builder.defineMacro("_MIPSEB");
1935 Builder.defineMacro("__REGISTER_PREFIX__", "");
Edward O'Callaghan84423a82009-11-15 10:22:07 +00001936 }
1937 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1938 unsigned &NumRecords) const {
1939 // FIXME: Implement!
1940 }
1941 virtual const char *getVAListDeclaration() const {
1942 return "typedef void* __builtin_va_list;";
1943 }
1944 virtual void getGCCRegNames(const char * const *&Names,
1945 unsigned &NumNames) const;
1946 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
1947 unsigned &NumAliases) const;
1948 virtual bool validateAsmConstraint(const char *&Name,
1949 TargetInfo::ConstraintInfo &Info) const {
1950 switch (*Name) {
1951 default:
1952 case 'r': // CPU registers.
1953 case 'd': // Equivalent to "r" unless generating MIPS16 code.
1954 case 'y': // Equivalent to "r", backwards compatibility only.
1955 case 'f': // floating-point registers.
1956 Info.setAllowsRegister();
1957 return true;
1958 }
1959 return false;
1960 }
1961
1962 virtual const char *getClobbers() const {
1963 // FIXME: Implement!
1964 return "";
1965 }
1966};
1967
1968const char * const MipsTargetInfo::GCCRegNames[] = {
1969 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
1970 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
1971 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
1972 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
1973 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
1974 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
1975 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
1976 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
1977 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
1978 "$fcc5","$fcc6","$fcc7"
1979};
1980
1981void MipsTargetInfo::getGCCRegNames(const char * const *&Names,
1982 unsigned &NumNames) const {
1983 Names = GCCRegNames;
1984 NumNames = llvm::array_lengthof(GCCRegNames);
1985}
1986
1987const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = {
1988 { { "at" }, "$1" },
1989 { { "v0" }, "$2" },
1990 { { "v1" }, "$3" },
1991 { { "a0" }, "$4" },
1992 { { "a1" }, "$5" },
1993 { { "a2" }, "$6" },
1994 { { "a3" }, "$7" },
1995 { { "t0" }, "$8" },
1996 { { "t1" }, "$9" },
1997 { { "t2" }, "$10" },
1998 { { "t3" }, "$11" },
1999 { { "t4" }, "$12" },
2000 { { "t5" }, "$13" },
2001 { { "t6" }, "$14" },
2002 { { "t7" }, "$15" },
2003 { { "s0" }, "$16" },
2004 { { "s1" }, "$17" },
2005 { { "s2" }, "$18" },
2006 { { "s3" }, "$19" },
2007 { { "s4" }, "$20" },
2008 { { "s5" }, "$21" },
2009 { { "s6" }, "$22" },
2010 { { "s7" }, "$23" },
2011 { { "t8" }, "$24" },
2012 { { "t9" }, "$25" },
2013 { { "k0" }, "$26" },
2014 { { "k1" }, "$27" },
2015 { { "gp" }, "$28" },
2016 { { "sp" }, "$29" },
2017 { { "fp" }, "$30" },
2018 { { "ra" }, "$31" }
2019};
2020
2021void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2022 unsigned &NumAliases) const {
2023 Aliases = GCCRegAliases;
2024 NumAliases = llvm::array_lengthof(GCCRegAliases);
2025}
2026} // end anonymous namespace.
2027
2028namespace {
2029class MipselTargetInfo : public MipsTargetInfo {
2030public:
2031 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) {
2032 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2033 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2034 }
2035
2036 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002037 MacroBuilder &Builder) const;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002038};
2039
2040void MipselTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002041 MacroBuilder &Builder) const {
2042 DefineStd(Builder, "mips", Opts);
2043 Builder.defineMacro("_mips");
2044 DefineStd(Builder, "MIPSEL", Opts);
2045 Builder.defineMacro("_MIPSEL");
2046 Builder.defineMacro("__REGISTER_PREFIX__", "");
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002047}
2048} // end anonymous namespace.
2049
Reid Spencer5f016e22007-07-11 17:01:13 +00002050//===----------------------------------------------------------------------===//
2051// Driver code
2052//===----------------------------------------------------------------------===//
2053
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002054static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002055 llvm::Triple Triple(T);
2056 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00002057
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002058 switch (Triple.getArch()) {
2059 default:
2060 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00002061
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002062 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00002063 case llvm::Triple::thumb:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002064 switch (os) {
2065 case llvm::Triple::Darwin:
Eli Friedmaned855cb2008-08-21 00:13:15 +00002066 return new DarwinARMTargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002067 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002068 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002069 default:
2070 return new ARMTargetInfo(T);
2071 }
Eli Friedman61538a72008-05-20 14:21:01 +00002072
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002073 case llvm::Triple::bfin:
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002074 return new BlackfinTargetInfo(T);
2075
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002076 case llvm::Triple::msp430:
2077 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00002078
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002079 case llvm::Triple::mips:
2080 if (os == llvm::Triple::Psp)
2081 return new PSPTargetInfo<MipsTargetInfo>(T);
2082 if (os == llvm::Triple::Linux)
2083 return new LinuxTargetInfo<MipsTargetInfo>(T);
2084 return new MipsTargetInfo(T);
2085
2086 case llvm::Triple::mipsel:
2087 if (os == llvm::Triple::Psp)
2088 return new PSPTargetInfo<MipselTargetInfo>(T);
2089 if (os == llvm::Triple::Linux)
2090 return new LinuxTargetInfo<MipselTargetInfo>(T);
2091 return new MipselTargetInfo(T);
2092
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002093 case llvm::Triple::pic16:
2094 return new PIC16TargetInfo(T);
2095
2096 case llvm::Triple::ppc:
2097 if (os == llvm::Triple::Darwin)
2098 return new DarwinTargetInfo<PPCTargetInfo>(T);
2099 return new PPC32TargetInfo(T);
2100
2101 case llvm::Triple::ppc64:
2102 if (os == llvm::Triple::Darwin)
2103 return new DarwinTargetInfo<PPC64TargetInfo>(T);
John Thompson3f6918a2009-11-19 17:18:50 +00002104 else if (os == llvm::Triple::Lv2)
2105 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002106 return new PPC64TargetInfo(T);
2107
2108 case llvm::Triple::sparc:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002109 if (os == llvm::Triple::AuroraUX)
2110 return new AuroraUXSparcV8TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002111 if (os == llvm::Triple::Solaris)
2112 return new SolarisSparcV8TargetInfo(T);
2113 return new SparcV8TargetInfo(T);
2114
John Thompson3f6918a2009-11-19 17:18:50 +00002115 // FIXME: Need a real SPU target.
2116 case llvm::Triple::cellspu:
2117 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
2118
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002119 case llvm::Triple::systemz:
2120 return new SystemZTargetInfo(T);
2121
Eli Friedmanb63decf2009-08-19 20:47:07 +00002122 case llvm::Triple::tce:
2123 return new TCETargetInfo(T);
2124
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002125 case llvm::Triple::x86:
2126 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002127 case llvm::Triple::AuroraUX:
2128 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002129 case llvm::Triple::Darwin:
2130 return new DarwinI386TargetInfo(T);
2131 case llvm::Triple::Linux:
2132 return new LinuxTargetInfo<X86_32TargetInfo>(T);
2133 case llvm::Triple::DragonFly:
2134 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
2135 case llvm::Triple::NetBSD:
2136 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
2137 case llvm::Triple::OpenBSD:
2138 return new OpenBSDI386TargetInfo(T);
2139 case llvm::Triple::FreeBSD:
2140 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
2141 case llvm::Triple::Solaris:
2142 return new SolarisTargetInfo<X86_32TargetInfo>(T);
2143 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002144 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002145 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002146 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002147 case llvm::Triple::Win32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002148 return new VisualStudioWindowsX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002149 default:
2150 return new X86_32TargetInfo(T);
2151 }
2152
2153 case llvm::Triple::x86_64:
2154 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002155 case llvm::Triple::AuroraUX:
2156 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002157 case llvm::Triple::Darwin:
2158 return new DarwinX86_64TargetInfo(T);
2159 case llvm::Triple::Linux:
2160 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00002161 case llvm::Triple::DragonFly:
2162 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002163 case llvm::Triple::NetBSD:
2164 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
2165 case llvm::Triple::OpenBSD:
2166 return new OpenBSDX86_64TargetInfo(T);
2167 case llvm::Triple::FreeBSD:
2168 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
2169 case llvm::Triple::Solaris:
2170 return new SolarisTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002171 case llvm::Triple::MinGW64:
2172 return new MinGWX86_64TargetInfo(T);
2173 case llvm::Triple::Win32: // This is what Triple.h supports now.
2174 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002175 default:
2176 return new X86_64TargetInfo(T);
2177 }
2178 }
Reid Spencer5f016e22007-07-11 17:01:13 +00002179}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002180
2181/// CreateTargetInfo - Return the target info object for the specified target
2182/// triple.
2183TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002184 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002185 llvm::Triple Triple(Opts.Triple);
2186
2187 // Construct the target
2188 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
2189 if (!Target) {
2190 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
2191 return 0;
2192 }
2193
Daniel Dunbareac7c532009-12-18 18:42:37 +00002194 // Set the target CPU if specified.
2195 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
2196 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
2197 return 0;
2198 }
2199
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002200 // Set the target ABI if specified.
2201 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
2202 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
2203 return 0;
2204 }
2205
2206 // Compute the default target features, we need the target to handle this
2207 // because features may have dependencies on one another.
2208 llvm::StringMap<bool> Features;
2209 Target->getDefaultFeatures(Opts.CPU, Features);
2210
2211 // Apply the user specified deltas.
2212 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
2213 ie = Opts.Features.end(); it != ie; ++it) {
2214 const char *Name = it->c_str();
2215
2216 // Apply the feature via the target.
2217 if ((Name[0] != '-' && Name[0] != '+') ||
2218 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
2219 Diags.Report(diag::err_target_invalid_feature) << Name;
2220 return 0;
2221 }
2222 }
2223
2224 // Add the features to the compile options.
2225 //
2226 // FIXME: If we are completely confident that we have the right set, we only
2227 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002228 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002229 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
2230 ie = Features.end(); it != ie; ++it)
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002231 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
2232 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002233
2234 return Target.take();
2235}