blob: 0dcb95903930fdf3c0747fd4c87ed9ead295e194 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Anton Korobeynikova7c47172009-05-03 13:42:53 +000010// This file implements construction of a TargetInfo object from a
Ted Kremenekbbced582007-12-12 18:05:32 +000011// target triple.
Reid Spencer5f016e22007-07-11 17:01:13 +000012//
13//===----------------------------------------------------------------------===//
14
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/Basic/TargetInfo.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000016#include "clang/Basic/Builtins.h"
17#include "clang/Basic/Diagnostic.h"
Chris Lattner8fc4dfb2008-12-04 22:54:33 +000018#include "clang/Basic/LangOptions.h"
Chandler Carruth103b71c2010-01-20 06:13:02 +000019#include "clang/Basic/MacroBuilder.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000020#include "clang/Basic/TargetBuiltins.h"
21#include "clang/Basic/TargetOptions.h"
Eli Friedman25531262008-05-20 14:27:34 +000022#include "llvm/ADT/APFloat.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000023#include "llvm/ADT/OwningPtr.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000024#include "llvm/ADT/STLExtras.h"
Daniel Dunbar77659342009-08-19 20:04:03 +000025#include "llvm/ADT/StringRef.h"
Daniel Dunbar29a790b2009-11-11 09:38:56 +000026#include "llvm/ADT/StringSwitch.h"
Chris Lattner4c28b1c2009-08-12 06:24:27 +000027#include "llvm/ADT/Triple.h"
Chris Lattner797c3c42009-08-10 19:03:04 +000028#include "llvm/MC/MCSectionMachO.h"
Dale Johannesen1e592cb2010-10-29 23:24:33 +000029#include "llvm/Type.h"
Benjamin Kramer48725082010-01-09 18:20:57 +000030#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000031using namespace clang;
32
Reid Spencer5f016e22007-07-11 17:01:13 +000033//===----------------------------------------------------------------------===//
34// Common code shared among targets.
35//===----------------------------------------------------------------------===//
36
Chris Lattnerca45cff2009-03-20 16:06:38 +000037/// DefineStd - Define a macro name and standard variants. For example if
38/// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
39/// when in GNU mode.
Benjamin Kramera9992772010-01-09 17:55:51 +000040static void DefineStd(MacroBuilder &Builder, llvm::StringRef MacroName,
Chris Lattnerca45cff2009-03-20 16:06:38 +000041 const LangOptions &Opts) {
42 assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000043
Chris Lattnerca45cff2009-03-20 16:06:38 +000044 // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
45 // in the user's namespace.
46 if (Opts.GNUMode)
Benjamin Kramera9992772010-01-09 17:55:51 +000047 Builder.defineMacro(MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000048
Chris Lattnerca45cff2009-03-20 16:06:38 +000049 // Define __unix.
Benjamin Kramera9992772010-01-09 17:55:51 +000050 Builder.defineMacro("__" + MacroName);
Anton Korobeynikova7c47172009-05-03 13:42:53 +000051
Chris Lattnerca45cff2009-03-20 16:06:38 +000052 // Define __unix__.
Benjamin Kramera9992772010-01-09 17:55:51 +000053 Builder.defineMacro("__" + MacroName + "__");
Chris Lattnerca45cff2009-03-20 16:06:38 +000054}
55
Chris Lattnerd29b6302008-10-05 21:50:58 +000056//===----------------------------------------------------------------------===//
57// Defines specific to certain operating systems.
58//===----------------------------------------------------------------------===//
Chris Lattner797c3c42009-08-10 19:03:04 +000059
Torok Edwin5f6c1942009-06-30 17:10:35 +000060namespace {
Douglas Gregora3844922009-07-01 15:12:53 +000061template<typename TgtInfo>
62class OSTargetInfo : public TgtInfo {
Torok Edwin5f6c1942009-06-30 17:10:35 +000063protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +000064 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +000065 MacroBuilder &Builder) const=0;
Torok Edwin5f6c1942009-06-30 17:10:35 +000066public:
Douglas Gregora3844922009-07-01 15:12:53 +000067 OSTargetInfo(const std::string& triple) : TgtInfo(triple) {}
Torok Edwin5f6c1942009-06-30 17:10:35 +000068 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +000069 MacroBuilder &Builder) const {
70 TgtInfo::getTargetDefines(Opts, Builder);
71 getOSDefines(Opts, TgtInfo::getTriple(), Builder);
Torok Edwinb0a5b242009-06-30 17:00:25 +000072 }
Torok Edwin5f6c1942009-06-30 17:10:35 +000073
74};
Chris Lattner4c28b1c2009-08-12 06:24:27 +000075} // end anonymous namespace
Torok Edwinb0a5b242009-06-30 17:00:25 +000076
Chris Lattner797c3c42009-08-10 19:03:04 +000077
Daniel Dunbar21ae3192010-01-26 01:44:04 +000078static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000079 const llvm::Triple &Triple,
80 llvm::StringRef &PlatformName,
81 VersionTuple &PlatformMinVersion) {
Benjamin Kramera9992772010-01-09 17:55:51 +000082 Builder.defineMacro("__APPLE_CC__", "5621");
83 Builder.defineMacro("__APPLE__");
84 Builder.defineMacro("__MACH__");
85 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000086
Chris Lattner10d24272009-04-07 16:50:40 +000087 // __weak is always defined, for use in blocks and with objc pointers.
Benjamin Kramera9992772010-01-09 17:55:51 +000088 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000089
Chris Lattner10d24272009-04-07 16:50:40 +000090 // Darwin defines __strong even in C mode (just to nothing).
91 if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC)
Benjamin Kramera9992772010-01-09 17:55:51 +000092 Builder.defineMacro("__strong", "");
Chris Lattner10d24272009-04-07 16:50:40 +000093 else
Benjamin Kramera9992772010-01-09 17:55:51 +000094 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
Eli Friedman2de4fee2009-06-04 23:00:29 +000095
96 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +000097 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +000098 else
Benjamin Kramera9992772010-01-09 17:55:51 +000099 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000100
101 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000102 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000103
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000104 // Get the OS version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000105 unsigned Maj, Min, Rev;
Mike Stump1eb44332009-09-09 15:08:12 +0000106
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000107 // If no version was given, default to to 10.4.0, for simplifying tests.
108 if (Triple.getOSName() == "darwin") {
109 Min = Rev = 0;
110 Maj = 8;
111 } else
112 Triple.getDarwinNumber(Maj, Min, Rev);
113
114 // Set the appropriate OS version define.
115 if (Triple.getEnvironmentName() == "iphoneos") {
116 assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!");
117 char Str[6];
118 Str[0] = '0' + Maj;
119 Str[1] = '0' + (Min / 10);
120 Str[2] = '0' + (Min % 10);
121 Str[3] = '0' + (Rev / 10);
122 Str[4] = '0' + (Rev % 10);
123 Str[5] = '\0';
124 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000125
126 PlatformName = "ios";
127 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000128 } else {
129 // For historical reasons that make little sense, the version passed here is
130 // the "darwin" version, which drops the 10 and offsets by 4.
131 Rev = Min;
132 Min = Maj - 4;
133 Maj = 10;
134
135 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
136 assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!");
137 char Str[5];
138 Str[0] = '0' + (Maj / 10);
139 Str[1] = '0' + (Maj % 10);
140 Str[2] = '0' + Min;
141 Str[3] = '0' + Rev;
142 Str[4] = '\0';
143 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000144
145 PlatformName = "macosx";
146 PlatformMinVersion = VersionTuple(Maj, Min, Rev);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000147 }
Eli Friedman618234a2008-08-20 02:34:37 +0000148}
Reid Spencer5f016e22007-07-11 17:01:13 +0000149
Chris Lattner797c3c42009-08-10 19:03:04 +0000150namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000151template<typename Target>
152class DarwinTargetInfo : public OSTargetInfo<Target> {
153protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000154 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000155 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +0000156 getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
157 this->PlatformMinVersion);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000158 }
Mike Stump1eb44332009-09-09 15:08:12 +0000159
Torok Edwin5f6c1942009-06-30 17:10:35 +0000160public:
161 DarwinTargetInfo(const std::string& triple) :
162 OSTargetInfo<Target>(triple) {
Eric Christopherdd53ec92010-06-25 19:04:52 +0000163 this->TLSSupported = llvm::Triple(triple).getDarwinMajorNumber() > 10;
Daniel Dunbare177d3b2011-02-21 23:12:51 +0000164 this->MCountName = "\01mcount";
Torok Edwin5f6c1942009-06-30 17:10:35 +0000165 }
166
Anders Carlssonf959fb52010-01-30 18:33:31 +0000167 virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000168 // Let MCSectionMachO validate this.
169 llvm::StringRef Segment, Section;
170 unsigned TAA, StubSize;
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000171 bool HasTAA;
Chris Lattner797c3c42009-08-10 19:03:04 +0000172 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
Daniel Dunbar9ae186f2011-03-19 02:06:21 +0000173 TAA, HasTAA, StubSize);
Chris Lattner797c3c42009-08-10 19:03:04 +0000174 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000175
Anders Carlsson18af3682010-06-08 22:47:50 +0000176 virtual const char *getStaticInitSectionSpecifier() const {
177 // FIXME: We should return 0 when building kexts.
178 return "__TEXT,__StaticInit,regular,pure_instructions";
179 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000180
Torok Edwin5f6c1942009-06-30 17:10:35 +0000181};
182
Chris Lattner797c3c42009-08-10 19:03:04 +0000183
Torok Edwin5f6c1942009-06-30 17:10:35 +0000184// DragonFlyBSD Target
185template<typename Target>
186class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
187protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000188 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000189 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000190 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000191 Builder.defineMacro("__DragonFly__");
192 Builder.defineMacro("__DragonFly_cc_version", "100001");
193 Builder.defineMacro("__ELF__");
194 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
195 Builder.defineMacro("__tune_i386__");
196 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000197 }
198public:
Mike Stump1eb44332009-09-09 15:08:12 +0000199 DragonFlyBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000200 : OSTargetInfo<Target>(triple) {}
201};
202
203// FreeBSD Target
204template<typename Target>
205class FreeBSDTargetInfo : public OSTargetInfo<Target> {
206protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000207 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000208 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000209 // FreeBSD defines; list based off of gcc output
210
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000211 // FIXME: Move version number handling to llvm::Triple.
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000212 llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000213
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000214 Builder.defineMacro("__FreeBSD__", Release);
215 Builder.defineMacro("__FreeBSD_cc_version", Release + "00001");
Benjamin Kramera9992772010-01-09 17:55:51 +0000216 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
217 DefineStd(Builder, "unix", Opts);
218 Builder.defineMacro("__ELF__");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000219 }
220public:
Mike Stump1eb44332009-09-09 15:08:12 +0000221 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000222 : OSTargetInfo<Target>(triple) {
223 this->UserLabelPrefix = "";
Roman Divackybe4c8702011-02-10 16:52:03 +0000224
225 llvm::Triple Triple(triple);
226 switch (Triple.getArch()) {
227 default:
228 case llvm::Triple::x86:
229 case llvm::Triple::x86_64:
230 this->MCountName = ".mcount";
231 break;
232 case llvm::Triple::mips:
233 case llvm::Triple::mipsel:
234 case llvm::Triple::ppc:
235 case llvm::Triple::ppc64:
236 this->MCountName = "_mcount";
237 break;
238 case llvm::Triple::arm:
239 this->MCountName = "__mcount";
240 break;
241 }
242
Duncan Sands1e90faf2009-07-08 13:55:08 +0000243 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000244};
245
Chris Lattner38e317d2010-07-07 16:01:42 +0000246// Minix Target
247template<typename Target>
248class MinixTargetInfo : public OSTargetInfo<Target> {
249protected:
250 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
251 MacroBuilder &Builder) const {
252 // Minix defines
253
254 Builder.defineMacro("__minix", "3");
255 Builder.defineMacro("_EM_WSIZE", "4");
256 Builder.defineMacro("_EM_PSIZE", "4");
257 Builder.defineMacro("_EM_SSIZE", "2");
258 Builder.defineMacro("_EM_LSIZE", "4");
259 Builder.defineMacro("_EM_FSIZE", "4");
260 Builder.defineMacro("_EM_DSIZE", "8");
261 DefineStd(Builder, "unix", Opts);
262 }
263public:
264 MinixTargetInfo(const std::string &triple)
265 : OSTargetInfo<Target>(triple) {
266 this->UserLabelPrefix = "";
267 }
268};
269
Torok Edwin5f6c1942009-06-30 17:10:35 +0000270// Linux target
271template<typename Target>
272class LinuxTargetInfo : public OSTargetInfo<Target> {
273protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000274 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000275 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000276 // Linux defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000277 DefineStd(Builder, "unix", Opts);
278 DefineStd(Builder, "linux", Opts);
279 Builder.defineMacro("__gnu_linux__");
280 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000281 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000282 Builder.defineMacro("_REENTRANT");
Douglas Gregor2b003fd2010-04-21 05:52:38 +0000283 if (Opts.CPlusPlus)
284 Builder.defineMacro("_GNU_SOURCE");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000285 }
286public:
Mike Stump1eb44332009-09-09 15:08:12 +0000287 LinuxTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000288 : OSTargetInfo<Target>(triple) {
289 this->UserLabelPrefix = "";
Douglas Gregor12e84642011-01-12 21:19:25 +0000290 this->WIntType = TargetInfo::UnsignedInt;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000291 }
292};
293
Chris Lattnerb62bb282009-07-13 20:29:08 +0000294// NetBSD Target
295template<typename Target>
296class NetBSDTargetInfo : public OSTargetInfo<Target> {
297protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000298 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000299 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000300 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000301 Builder.defineMacro("__NetBSD__");
302 Builder.defineMacro("__unix__");
303 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000304 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000305 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000306 }
307public:
Mike Stump1eb44332009-09-09 15:08:12 +0000308 NetBSDTargetInfo(const std::string &triple)
Chris Lattnerb62bb282009-07-13 20:29:08 +0000309 : OSTargetInfo<Target>(triple) {
310 this->UserLabelPrefix = "";
311 }
312};
313
Torok Edwin5f6c1942009-06-30 17:10:35 +0000314// OpenBSD Target
315template<typename Target>
316class OpenBSDTargetInfo : public OSTargetInfo<Target> {
317protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000318 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000319 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000320 // OpenBSD defines; list based off of gcc output
321
Benjamin Kramera9992772010-01-09 17:55:51 +0000322 Builder.defineMacro("__OpenBSD__");
323 DefineStd(Builder, "unix", Opts);
324 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000325 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000326 Builder.defineMacro("_POSIX_THREADS");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000327 }
328public:
Mike Stump1eb44332009-09-09 15:08:12 +0000329 OpenBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000330 : OSTargetInfo<Target>(triple) {}
331};
332
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000333// PSP Target
334template<typename Target>
335class PSPTargetInfo : public OSTargetInfo<Target> {
336protected:
337 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000338 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000339 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000340 Builder.defineMacro("PSP");
341 Builder.defineMacro("_PSP");
342 Builder.defineMacro("__psp__");
343 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000344 }
345public:
346 PSPTargetInfo(const std::string& triple)
347 : OSTargetInfo<Target>(triple) {
348 this->UserLabelPrefix = "";
349 }
350};
351
John Thompson3f6918a2009-11-19 17:18:50 +0000352// PS3 PPU Target
353template<typename Target>
354class PS3PPUTargetInfo : public OSTargetInfo<Target> {
355protected:
356 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000357 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000358 // PS3 PPU defines.
John Thompsonfb457972010-03-25 16:18:32 +0000359 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000360 Builder.defineMacro("__PPU__");
361 Builder.defineMacro("__CELLOS_LV2__");
362 Builder.defineMacro("__ELF__");
363 Builder.defineMacro("__LP32__");
John Thompson8e6065a2010-06-24 22:44:13 +0000364 Builder.defineMacro("_ARCH_PPC64");
365 Builder.defineMacro("__powerpc64__");
John Thompson3f6918a2009-11-19 17:18:50 +0000366 }
367public:
368 PS3PPUTargetInfo(const std::string& triple)
369 : OSTargetInfo<Target>(triple) {
370 this->UserLabelPrefix = "";
John Thompsonec387af2009-12-18 14:21:08 +0000371 this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32;
John Thompson8e6065a2010-06-24 22:44:13 +0000372 this->IntMaxType = TargetInfo::SignedLongLong;
373 this->UIntMaxType = TargetInfo::UnsignedLongLong;
374 this->Int64Type = TargetInfo::SignedLongLong;
John Thompsonec387af2009-12-18 14:21:08 +0000375 this->SizeType = TargetInfo::UnsignedInt;
John Thompson8e6065a2010-06-24 22:44:13 +0000376 this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
377 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
John Thompson3f6918a2009-11-19 17:18:50 +0000378 }
379};
380
381// FIXME: Need a real SPU target.
382// PS3 SPU Target
383template<typename Target>
384class PS3SPUTargetInfo : public OSTargetInfo<Target> {
385protected:
386 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000387 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000388 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000389 Builder.defineMacro("__SPU__");
390 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000391 }
392public:
393 PS3SPUTargetInfo(const std::string& triple)
394 : OSTargetInfo<Target>(triple) {
395 this->UserLabelPrefix = "";
396 }
397};
398
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000399// AuroraUX target
400template<typename Target>
401class AuroraUXTargetInfo : public OSTargetInfo<Target> {
402protected:
403 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000404 MacroBuilder &Builder) const {
405 DefineStd(Builder, "sun", Opts);
406 DefineStd(Builder, "unix", Opts);
407 Builder.defineMacro("__ELF__");
408 Builder.defineMacro("__svr4__");
409 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000410 }
411public:
412 AuroraUXTargetInfo(const std::string& triple)
413 : OSTargetInfo<Target>(triple) {
414 this->UserLabelPrefix = "";
415 this->WCharType = this->SignedLong;
416 // FIXME: WIntType should be SignedLong
417 }
418};
419
Torok Edwin5f6c1942009-06-30 17:10:35 +0000420// Solaris target
421template<typename Target>
422class SolarisTargetInfo : public OSTargetInfo<Target> {
423protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000424 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000425 MacroBuilder &Builder) const {
426 DefineStd(Builder, "sun", Opts);
427 DefineStd(Builder, "unix", Opts);
428 Builder.defineMacro("__ELF__");
429 Builder.defineMacro("__svr4__");
430 Builder.defineMacro("__SVR4");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000431 }
432public:
Mike Stump1eb44332009-09-09 15:08:12 +0000433 SolarisTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000434 : OSTargetInfo<Target>(triple) {
435 this->UserLabelPrefix = "";
436 this->WCharType = this->SignedLong;
437 // FIXME: WIntType should be SignedLong
438 }
439};
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000440
441// Windows target
442template<typename Target>
443class WindowsTargetInfo : public OSTargetInfo<Target> {
444protected:
445 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
446 MacroBuilder &Builder) const {
Michael J. Spencera764e832010-10-21 08:22:51 +0000447 Builder.defineMacro("_WIN32");
448 }
449 void getVisualStudioDefines(const LangOptions &Opts,
450 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000451 if (Opts.CPlusPlus) {
452 if (Opts.RTTI)
453 Builder.defineMacro("_CPPRTTI");
454
455 if (Opts.Exceptions)
456 Builder.defineMacro("_CPPUNWIND");
457 }
458
459 if (!Opts.CharIsSigned)
460 Builder.defineMacro("_CHAR_UNSIGNED");
461
462 // FIXME: POSIXThreads isn't exactly the option this should be defined for,
463 // but it works for now.
464 if (Opts.POSIXThreads)
465 Builder.defineMacro("_MT");
Michael J. Spencera764e832010-10-21 08:22:51 +0000466
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000467 if (Opts.MSCVersion != 0)
468 Builder.defineMacro("_MSC_VER", llvm::Twine(Opts.MSCVersion));
469
470 if (Opts.Microsoft) {
471 Builder.defineMacro("_MSC_EXTENSIONS");
472
473 if (Opts.CPlusPlus0x) {
474 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
475 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
476 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
477 }
478 }
479
480 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000481 }
482
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000483public:
484 WindowsTargetInfo(const std::string &triple)
485 : OSTargetInfo<Target>(triple) {}
486};
487
Mike Stump1eb44332009-09-09 15:08:12 +0000488} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000489
Chris Lattnerd29b6302008-10-05 21:50:58 +0000490//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000491// Specific target implementations.
492//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000493
Eli Friedmane4277982008-08-20 23:11:40 +0000494namespace {
495// PPC abstract base class
496class PPCTargetInfo : public TargetInfo {
497 static const Builtin::Info BuiltinInfo[];
498 static const char * const GCCRegNames[];
499 static const TargetInfo::GCCRegAlias GCCRegAliases[];
500
501public:
Eli Friedman15b91762009-06-05 07:05:05 +0000502 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
503
Eli Friedmane4277982008-08-20 23:11:40 +0000504 virtual void getTargetBuiltins(const Builtin::Info *&Records,
505 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000506 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000507 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000508 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000509
Chris Lattner33328642009-03-20 15:52:06 +0000510 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000511 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000512
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000513 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000514 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000515 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000516 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000517 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000518 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000519 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000520 default: return false;
521 case 'O': // Zero
John Thompson8e6065a2010-06-24 22:44:13 +0000522 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000523 case 'b': // Base register
524 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000525 Info.setAllowsRegister();
John Thompson8e6065a2010-06-24 22:44:13 +0000526 break;
527 // FIXME: The following are added to allow parsing.
528 // I just took a guess at what the actions should be.
529 // Also, is more specific checking needed? I.e. specific registers?
Michael J. Spencer20249a12010-10-21 03:16:25 +0000530 case 'd': // Floating point register (containing 64-bit value)
John Thompson8e6065a2010-06-24 22:44:13 +0000531 case 'v': // Altivec vector register
532 Info.setAllowsRegister();
533 break;
534 case 'w':
535 switch (Name[1]) {
Michael J. Spencer20249a12010-10-21 03:16:25 +0000536 case 'd':// VSX vector register to hold vector double data
537 case 'f':// VSX vector register to hold vector float data
538 case 's':// VSX vector register to hold scalar float data
539 case 'a':// Any VSX register
John Thompson8e6065a2010-06-24 22:44:13 +0000540 break;
541 default:
542 return false;
543 }
544 Info.setAllowsRegister();
545 Name++; // Skip over 'w'.
546 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000547 case 'h': // `MQ', `CTR', or `LINK' register
548 case 'q': // `MQ' register
549 case 'c': // `CTR' register
550 case 'l': // `LINK' register
551 case 'x': // `CR' register (condition register) number 0
552 case 'y': // `CR' register (condition register)
553 case 'z': // `XER[CA]' carry bit (part of the XER register)
John Thompson8e6065a2010-06-24 22:44:13 +0000554 Info.setAllowsRegister();
555 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000556 case 'I': // Signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000557 case 'J': // Unsigned 16-bit constant shifted left 16 bits
Michael J. Spencer20249a12010-10-21 03:16:25 +0000558 // (use `L' instead for SImode constants)
559 case 'K': // Unsigned 16-bit constant
560 case 'L': // Signed 16-bit constant shifted left 16 bits
561 case 'M': // Constant larger than 31
562 case 'N': // Exact power of 2
563 case 'P': // Constant whose negation is a signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000564 case 'G': // Floating point constant that can be loaded into a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000565 // register with one instruction per word
John Thompson8e6065a2010-06-24 22:44:13 +0000566 case 'H': // Integer/Floating point constant that can be loaded
Michael J. Spencer20249a12010-10-21 03:16:25 +0000567 // into a register using three instructions
John Thompson8e6065a2010-06-24 22:44:13 +0000568 break;
569 case 'm': // Memory operand. Note that on PowerPC targets, m can
570 // include addresses that update the base register. It
571 // is therefore only safe to use `m' in an asm statement
572 // if that asm statement accesses the operand exactly once.
573 // The asm statement must also use `%U<opno>' as a
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000574 // placeholder for the "update" flag in the corresponding
Michael J. Spencer20249a12010-10-21 03:16:25 +0000575 // load or store instruction. For example:
John Thompson8e6065a2010-06-24 22:44:13 +0000576 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
Michael J. Spencer20249a12010-10-21 03:16:25 +0000577 // is correct but:
John Thompson8e6065a2010-06-24 22:44:13 +0000578 // asm ("st %1,%0" : "=m" (mem) : "r" (val));
579 // is not. Use es rather than m if you don't want the base
Michael J. Spencer20249a12010-10-21 03:16:25 +0000580 // register to be updated.
581 case 'e':
John Thompson56b6eca2010-06-25 00:02:05 +0000582 if (Name[1] != 's')
583 return false;
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000584 // es: A "stable" memory operand; that is, one which does not
John Thompson8e6065a2010-06-24 22:44:13 +0000585 // include any automodification of the base register. Unlike
586 // `m', this constraint can be used in asm statements that
587 // might access the operand several times, or that might not
John Thompson56b6eca2010-06-25 00:02:05 +0000588 // access it at all.
John Thompson8e6065a2010-06-24 22:44:13 +0000589 Info.setAllowsMemory();
John Thompson56b6eca2010-06-25 00:02:05 +0000590 Name++; // Skip over 'e'.
John Thompson8e6065a2010-06-24 22:44:13 +0000591 break;
592 case 'Q': // Memory operand that is an offset from a register (it is
Michael J. Spencer20249a12010-10-21 03:16:25 +0000593 // usually better to use `m' or `es' in asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000594 case 'Z': // Memory operand that is an indexed or indirect from a
595 // register (it is usually better to use `m' or `es' in
Michael J. Spencer20249a12010-10-21 03:16:25 +0000596 // asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000597 Info.setAllowsMemory();
598 Info.setAllowsRegister();
599 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000600 case 'R': // AIX TOC entry
John Thompson8e6065a2010-06-24 22:44:13 +0000601 case 'a': // Address operand that is an indexed or indirect from a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000602 // register (`p' is preferable for asm statements)
603 case 'S': // Constant suitable as a 64-bit mask operand
604 case 'T': // Constant suitable as a 32-bit mask operand
605 case 'U': // System V Release 4 small data area reference
John Thompson8e6065a2010-06-24 22:44:13 +0000606 case 't': // AND masks that can be performed by two rldic{l, r}
Michael J. Spencer20249a12010-10-21 03:16:25 +0000607 // instructions
608 case 'W': // Vector constant that does not require memory
609 case 'j': // Vector constant that is all zeros.
John Thompson8e6065a2010-06-24 22:44:13 +0000610 break;
611 // End FIXME.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000612 }
John Thompson8e6065a2010-06-24 22:44:13 +0000613 return true;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000614 }
Eli Friedmane4277982008-08-20 23:11:40 +0000615 virtual const char *getClobbers() const {
616 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000617 }
Eli Friedmane4277982008-08-20 23:11:40 +0000618};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000619
Eli Friedmane4277982008-08-20 23:11:40 +0000620const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000621#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
622#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
623 ALL_LANGUAGES, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000624#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000625};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000626
627
Chris Lattnerc0f59212009-03-02 22:27:17 +0000628/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
629/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000630void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000631 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000632 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000633 Builder.defineMacro("__ppc__");
634 Builder.defineMacro("_ARCH_PPC");
Chris Lattnere03ae302010-02-16 18:14:57 +0000635 Builder.defineMacro("__powerpc__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000636 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000637 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000638 Builder.defineMacro("_ARCH_PPC64");
639 Builder.defineMacro("_LP64");
640 Builder.defineMacro("__LP64__");
Chris Lattnere03ae302010-02-16 18:14:57 +0000641 Builder.defineMacro("__powerpc64__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000642 Builder.defineMacro("__ppc64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000643 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000644 Builder.defineMacro("__ppc__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000645 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000646
Chris Lattnerc0f59212009-03-02 22:27:17 +0000647 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +0000648 Builder.defineMacro("_BIG_ENDIAN");
649 Builder.defineMacro("__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000650
Chris Lattnerc0f59212009-03-02 22:27:17 +0000651 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000652 Builder.defineMacro("__NATURAL_ALIGNMENT__");
653 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000654
Chris Lattnerc0f59212009-03-02 22:27:17 +0000655 // FIXME: Should be controlled by command line option.
Benjamin Kramera9992772010-01-09 17:55:51 +0000656 Builder.defineMacro("__LONG_DOUBLE_128__");
Michael J. Spencer20249a12010-10-21 03:16:25 +0000657
John Thompson3f6918a2009-11-19 17:18:50 +0000658 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000659 Builder.defineMacro("__VEC__", "10206");
660 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000661 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000662}
663
Chris Lattner393ff042008-04-21 18:56:49 +0000664
Eli Friedmane4277982008-08-20 23:11:40 +0000665const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +0000666 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
667 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
668 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
669 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
670 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
671 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
672 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
673 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +0000674 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000675 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +0000676 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000677 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
678 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
679 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
680 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +0000681 "vrsave", "vscr",
682 "spe_acc", "spefscr",
683 "sfp"
684};
Reid Spencer5f016e22007-07-11 17:01:13 +0000685
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000686void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000687 unsigned &NumNames) const {
688 Names = GCCRegNames;
689 NumNames = llvm::array_lengthof(GCCRegNames);
690}
Reid Spencer5f016e22007-07-11 17:01:13 +0000691
Eli Friedmane4277982008-08-20 23:11:40 +0000692const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
693 // While some of these aliases do map to different registers
694 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000695 { { "0" }, "r0" },
696 { { "1"}, "r1" },
697 { { "2" }, "r2" },
698 { { "3" }, "r3" },
699 { { "4" }, "r4" },
700 { { "5" }, "r5" },
701 { { "6" }, "r6" },
702 { { "7" }, "r7" },
703 { { "8" }, "r8" },
704 { { "9" }, "r9" },
705 { { "10" }, "r10" },
706 { { "11" }, "r11" },
707 { { "12" }, "r12" },
708 { { "13" }, "r13" },
709 { { "14" }, "r14" },
710 { { "15" }, "r15" },
711 { { "16" }, "r16" },
712 { { "17" }, "r17" },
713 { { "18" }, "r18" },
714 { { "19" }, "r19" },
715 { { "20" }, "r20" },
716 { { "21" }, "r21" },
717 { { "22" }, "r22" },
718 { { "23" }, "r23" },
719 { { "24" }, "r24" },
720 { { "25" }, "r25" },
721 { { "26" }, "r26" },
722 { { "27" }, "r27" },
723 { { "28" }, "r28" },
724 { { "29" }, "r29" },
725 { { "30" }, "r30" },
726 { { "31" }, "r31" },
727 { { "fr0" }, "f0" },
728 { { "fr1" }, "f1" },
729 { { "fr2" }, "f2" },
730 { { "fr3" }, "f3" },
731 { { "fr4" }, "f4" },
732 { { "fr5" }, "f5" },
733 { { "fr6" }, "f6" },
734 { { "fr7" }, "f7" },
735 { { "fr8" }, "f8" },
736 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +0000737 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000738 { { "fr11" }, "f11" },
739 { { "fr12" }, "f12" },
740 { { "fr13" }, "f13" },
741 { { "fr14" }, "f14" },
742 { { "fr15" }, "f15" },
743 { { "fr16" }, "f16" },
744 { { "fr17" }, "f17" },
745 { { "fr18" }, "f18" },
746 { { "fr19" }, "f19" },
747 { { "fr20" }, "f20" },
748 { { "fr21" }, "f21" },
749 { { "fr22" }, "f22" },
750 { { "fr23" }, "f23" },
751 { { "fr24" }, "f24" },
752 { { "fr25" }, "f25" },
753 { { "fr26" }, "f26" },
754 { { "fr27" }, "f27" },
755 { { "fr28" }, "f28" },
756 { { "fr29" }, "f29" },
757 { { "fr30" }, "f30" },
758 { { "fr31" }, "f31" },
759 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +0000760};
761
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000762void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000763 unsigned &NumAliases) const {
764 Aliases = GCCRegAliases;
765 NumAliases = llvm::array_lengthof(GCCRegAliases);
766}
767} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000768
769namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000770class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000771public:
Chris Lattnere03ae302010-02-16 18:14:57 +0000772 PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) {
Eli Friedmaned855cb2008-08-21 00:13:15 +0000773 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 +0000774 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Chris Lattnere03ae302010-02-16 18:14:57 +0000775
776 if (getTriple().getOS() == llvm::Triple::FreeBSD)
Roman Divackyc81f2a22011-01-06 08:27:10 +0000777 SizeType = UnsignedInt;
778 }
779
780 virtual const char *getVAListDeclaration() const {
781 // This is the ELF definition, and is overridden by the Darwin sub-target
782 return "typedef struct __va_list_tag {"
783 " unsigned char gpr;"
784 " unsigned char fpr;"
785 " unsigned short reserved;"
786 " void* overflow_arg_area;"
787 " void* reg_save_area;"
788 "} __builtin_va_list[1];";
Eli Friedmaned855cb2008-08-21 00:13:15 +0000789 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000790};
791} // end anonymous namespace.
792
793namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000794class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000795public:
Eli Friedmane4277982008-08-20 23:11:40 +0000796 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000797 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000798 IntMaxType = SignedLong;
799 UIntMaxType = UnsignedLong;
800 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000801 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 +0000802 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Chris Lattnerf291b102008-05-09 06:17:04 +0000803 }
Roman Divackyc81f2a22011-01-06 08:27:10 +0000804 virtual const char *getVAListDeclaration() const {
805 return "typedef char* __builtin_va_list;";
806 }
Eli Friedmane4277982008-08-20 23:11:40 +0000807};
808} // end anonymous namespace.
809
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000810
811namespace {
Roman Divackyc81f2a22011-01-06 08:27:10 +0000812class DarwinPPC32TargetInfo :
813 public DarwinTargetInfo<PPC32TargetInfo> {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000814public:
Roman Divackyc81f2a22011-01-06 08:27:10 +0000815 DarwinPPC32TargetInfo(const std::string& triple)
816 : DarwinTargetInfo<PPC32TargetInfo>(triple) {
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000817 HasAlignMac68kSupport = true;
Roman Divackyc81f2a22011-01-06 08:27:10 +0000818 BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool?
819 }
820 virtual const char *getVAListDeclaration() const {
821 return "typedef char* __builtin_va_list;";
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000822 }
823};
824
825class DarwinPPC64TargetInfo :
826 public DarwinTargetInfo<PPC64TargetInfo> {
827public:
828 DarwinPPC64TargetInfo(const std::string& triple)
829 : DarwinTargetInfo<PPC64TargetInfo>(triple) {
830 HasAlignMac68kSupport = true;
831 }
832};
833} // end anonymous namespace.
834
Reid Spencer5f016e22007-07-11 17:01:13 +0000835namespace {
Chris Lattner9cbeb632010-03-06 21:21:27 +0000836// MBlaze abstract base class
837class MBlazeTargetInfo : public TargetInfo {
838 static const char * const GCCRegNames[];
839 static const TargetInfo::GCCRegAlias GCCRegAliases[];
840
841public:
842 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) {
Wesley Pecka48fa4b2010-12-12 20:56:47 +0000843 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16";
Chris Lattner9cbeb632010-03-06 21:21:27 +0000844 }
845
846 virtual void getTargetBuiltins(const Builtin::Info *&Records,
847 unsigned &NumRecords) const {
848 // FIXME: Implement.
849 Records = 0;
850 NumRecords = 0;
851 }
852
853 virtual void getTargetDefines(const LangOptions &Opts,
854 MacroBuilder &Builder) const;
855
856 virtual const char *getVAListDeclaration() const {
857 return "typedef char* __builtin_va_list;";
858 }
859 virtual const char *getTargetPrefix() const {
860 return "mblaze";
861 }
862 virtual void getGCCRegNames(const char * const *&Names,
863 unsigned &NumNames) const;
864 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
865 unsigned &NumAliases) const;
866 virtual bool validateAsmConstraint(const char *&Name,
867 TargetInfo::ConstraintInfo &Info) const {
868 switch (*Name) {
869 default: return false;
870 case 'O': // Zero
871 return true;
872 case 'b': // Base register
873 case 'f': // Floating point register
874 Info.setAllowsRegister();
875 return true;
876 }
877 }
878 virtual const char *getClobbers() const {
879 return "";
880 }
881};
882
883/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific
884/// #defines that are not tied to a specific subtarget.
885void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts,
886 MacroBuilder &Builder) const {
887 // Target identification.
888 Builder.defineMacro("__microblaze__");
889 Builder.defineMacro("_ARCH_MICROBLAZE");
890 Builder.defineMacro("__MICROBLAZE__");
891
892 // Target properties.
893 Builder.defineMacro("_BIG_ENDIAN");
894 Builder.defineMacro("__BIG_ENDIAN__");
895
896 // Subtarget options.
897 Builder.defineMacro("__REGISTER_PREFIX__", "");
898}
899
900
901const char * const MBlazeTargetInfo::GCCRegNames[] = {
902 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
903 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
904 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
905 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
906 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
907 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
908 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
909 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
910 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4",
911 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp"
912};
913
914void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names,
915 unsigned &NumNames) const {
916 Names = GCCRegNames;
917 NumNames = llvm::array_lengthof(GCCRegNames);
918}
919
920const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = {
921 { {"f0"}, "r0" },
922 { {"f1"}, "r1" },
923 { {"f2"}, "r2" },
924 { {"f3"}, "r3" },
925 { {"f4"}, "r4" },
926 { {"f5"}, "r5" },
927 { {"f6"}, "r6" },
928 { {"f7"}, "r7" },
929 { {"f8"}, "r8" },
930 { {"f9"}, "r9" },
931 { {"f10"}, "r10" },
932 { {"f11"}, "r11" },
933 { {"f12"}, "r12" },
934 { {"f13"}, "r13" },
935 { {"f14"}, "r14" },
936 { {"f15"}, "r15" },
937 { {"f16"}, "r16" },
938 { {"f17"}, "r17" },
939 { {"f18"}, "r18" },
940 { {"f19"}, "r19" },
941 { {"f20"}, "r20" },
942 { {"f21"}, "r21" },
943 { {"f22"}, "r22" },
944 { {"f23"}, "r23" },
945 { {"f24"}, "r24" },
946 { {"f25"}, "r25" },
947 { {"f26"}, "r26" },
948 { {"f27"}, "r27" },
949 { {"f28"}, "r28" },
950 { {"f29"}, "r29" },
951 { {"f30"}, "r30" },
952 { {"f31"}, "r31" },
953};
954
955void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
956 unsigned &NumAliases) const {
957 Aliases = GCCRegAliases;
958 NumAliases = llvm::array_lengthof(GCCRegAliases);
959}
960} // end anonymous namespace.
961
962namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000963// Namespace for x86 abstract base class
964const Builtin::Info BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000965#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
966#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
967 ALL_LANGUAGES, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000968#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +0000969};
Eli Friedman61538a72008-05-20 14:21:01 +0000970
Nuno Lopes2550d702009-12-23 17:49:57 +0000971static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +0000972 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
973 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
974 "argp", "flags", "fspr", "dirflag", "frame",
975 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
976 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
977 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
978 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
979};
980
981const TargetInfo::GCCRegAlias GCCRegAliases[] = {
982 { { "al", "ah", "eax", "rax" }, "ax" },
983 { { "bl", "bh", "ebx", "rbx" }, "bx" },
984 { { "cl", "ch", "ecx", "rcx" }, "cx" },
985 { { "dl", "dh", "edx", "rdx" }, "dx" },
986 { { "esi", "rsi" }, "si" },
987 { { "edi", "rdi" }, "di" },
988 { { "esp", "rsp" }, "sp" },
989 { { "ebp", "rbp" }, "bp" },
990};
991
992// X86 target abstract base class; x86-32 and x86-64 are very close, so
993// most of the implementation can be shared.
994class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +0000995 enum X86SSEEnum {
996 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
997 } SSELevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000998 enum AMD3DNowEnum {
999 NoAMD3DNow, AMD3DNow, AMD3DNowAthlon
1000 } AMD3DNowLevel;
1001
Eric Christophereea12d12010-04-02 23:50:19 +00001002 bool HasAES;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001003 bool HasAVX;
1004
Eli Friedman618234a2008-08-20 02:34:37 +00001005public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001006 X86TargetInfo(const std::string& triple)
Eric Christophereea12d12010-04-02 23:50:19 +00001007 : TargetInfo(triple), SSELevel(NoMMXSSE), AMD3DNowLevel(NoAMD3DNow),
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001008 HasAES(false), HasAVX(false) {
Eli Friedman618234a2008-08-20 02:34:37 +00001009 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +00001010 }
1011 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1012 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001013 Records = BuiltinInfo;
1014 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +00001015 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001016 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +00001017 unsigned &NumNames) const {
1018 Names = GCCRegNames;
1019 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +00001020 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001021 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +00001022 unsigned &NumAliases) const {
Eli Friedman618234a2008-08-20 02:34:37 +00001023 Aliases = GCCRegAliases;
1024 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001025 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001026 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +00001027 TargetInfo::ConstraintInfo &info) const;
1028 virtual std::string convertConstraint(const char Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +00001029 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +00001030 return "~{dirflag},~{fpsr},~{flags}";
1031 }
Chris Lattner33328642009-03-20 15:52:06 +00001032 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001033 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001034 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1035 const std::string &Name,
1036 bool Enabled) const;
Mike Stump1eb44332009-09-09 15:08:12 +00001037 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001038 llvm::StringMap<bool> &Features) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001039 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Reid Spencer5f016e22007-07-11 17:01:13 +00001040};
Chris Lattner3daed522009-03-02 22:20:04 +00001041
Mike Stump1eb44332009-09-09 15:08:12 +00001042void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001043 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001044 // FIXME: This should not be here.
1045 Features["3dnow"] = false;
1046 Features["3dnowa"] = false;
1047 Features["mmx"] = false;
1048 Features["sse"] = false;
1049 Features["sse2"] = false;
1050 Features["sse3"] = false;
1051 Features["ssse3"] = false;
1052 Features["sse41"] = false;
1053 Features["sse42"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001054 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001055 Features["avx"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001056
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001057 // LLVM does not currently recognize this.
1058 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001059
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001060 // FIXME: This *really* should not be here.
1061
1062 // X86_64 always has SSE2.
1063 if (PointerWidth == 64)
1064 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
1065
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001066 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
1067 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
1068 ;
1069 else if (CPU == "pentium-mmx" || CPU == "pentium2")
1070 setFeatureEnabled(Features, "mmx", true);
1071 else if (CPU == "pentium3")
1072 setFeatureEnabled(Features, "sse", true);
1073 else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64")
1074 setFeatureEnabled(Features, "sse2", true);
1075 else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona")
1076 setFeatureEnabled(Features, "sse3", true);
1077 else if (CPU == "core2")
1078 setFeatureEnabled(Features, "ssse3", true);
1079 else if (CPU == "penryn") {
1080 setFeatureEnabled(Features, "sse4", true);
1081 Features["sse42"] = false;
1082 } else if (CPU == "atom")
1083 setFeatureEnabled(Features, "sse3", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001084 else if (CPU == "corei7") {
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001085 setFeatureEnabled(Features, "sse4", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001086 setFeatureEnabled(Features, "aes", true);
Roman Divackybcaa3b82011-04-05 20:32:44 +00001087 } else if (CPU == "sandybridge") {
1088 setFeatureEnabled(Features, "sse4", true);
1089 setFeatureEnabled(Features, "aes", true);
1090// setFeatureEnabled(Features, "avx", true);
1091 } else if (CPU == "k6" || CPU == "winchip-c6")
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001092 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +00001093 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001094 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
1095 setFeatureEnabled(Features, "mmx", true);
1096 setFeatureEnabled(Features, "3dnow", true);
1097 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
1098 setFeatureEnabled(Features, "sse", true);
1099 setFeatureEnabled(Features, "3dnowa", true);
1100 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
1101 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +00001102 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001103 setFeatureEnabled(Features, "3dnowa", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00001104 } else if (CPU == "k8-sse3") {
1105 setFeatureEnabled(Features, "sse3", true);
1106 setFeatureEnabled(Features, "3dnowa", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001107 } else if (CPU == "c3-2")
1108 setFeatureEnabled(Features, "sse", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001109}
1110
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001111bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +00001112 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001113 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001114 // FIXME: This *really* should not be here. We need some way of translating
1115 // options into llvm subtarget features.
1116 if (!Features.count(Name) &&
1117 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001118 return false;
1119
1120 if (Enabled) {
1121 if (Name == "mmx")
1122 Features["mmx"] = true;
1123 else if (Name == "sse")
1124 Features["mmx"] = Features["sse"] = true;
1125 else if (Name == "sse2")
1126 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
1127 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001128 Features["mmx"] = Features["sse"] = Features["sse2"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001129 Features["sse3"] = true;
1130 else if (Name == "ssse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001131 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001132 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001133 else if (Name == "sse4" || Name == "sse4.2")
Mike Stump1eb44332009-09-09 15:08:12 +00001134 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001135 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001136 else if (Name == "sse4.1")
1137 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1138 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001139 else if (Name == "3dnow")
1140 Features["3dnowa"] = true;
1141 else if (Name == "3dnowa")
1142 Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001143 else if (Name == "aes")
1144 Features["aes"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001145 else if (Name == "avx")
1146 Features["avx"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001147 } else {
1148 if (Name == "mmx")
Mike Stump1eb44332009-09-09 15:08:12 +00001149 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001150 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1151 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001152 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001153 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1154 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001155 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001156 Features["sse41"] = Features["sse42"] = false;
1157 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001158 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001159 Features["sse42"] = false;
1160 else if (Name == "ssse3")
1161 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1162 else if (Name == "sse4")
1163 Features["sse41"] = Features["sse42"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001164 else if (Name == "sse4.2")
1165 Features["sse42"] = false;
1166 else if (Name == "sse4.1")
1167 Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001168 else if (Name == "3dnow")
1169 Features["3dnow"] = Features["3dnowa"] = false;
1170 else if (Name == "3dnowa")
1171 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001172 else if (Name == "aes")
1173 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001174 else if (Name == "avx")
1175 Features["avx"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001176 }
1177
1178 return true;
1179}
1180
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001181/// HandleTargetOptions - Perform initialization based on the user
1182/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001183void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001184 // Remember the maximum enabled sselevel.
1185 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1186 // Ignore disabled features.
1187 if (Features[i][0] == '-')
1188 continue;
1189
Eric Christophereea12d12010-04-02 23:50:19 +00001190 if (Features[i].substr(1) == "aes") {
1191 HasAES = true;
1192 continue;
1193 }
1194
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001195 // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
1196 // For now let it be enabled together with other SSE levels.
1197 if (Features[i].substr(1) == "avx") {
1198 HasAVX = true;
1199 continue;
1200 }
1201
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001202 assert(Features[i][0] == '+' && "Invalid target feature!");
1203 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
1204 .Case("sse42", SSE42)
1205 .Case("sse41", SSE41)
1206 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001207 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001208 .Case("sse2", SSE2)
1209 .Case("sse", SSE1)
1210 .Case("mmx", MMX)
1211 .Default(NoMMXSSE);
1212 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001213
1214 AMD3DNowEnum ThreeDNowLevel =
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001215 llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1))
1216 .Case("3dnowa", AMD3DNowAthlon)
1217 .Case("3dnow", AMD3DNow)
1218 .Default(NoAMD3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001219
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001220 AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001221 }
Chris Lattner3daed522009-03-02 22:20:04 +00001222}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001223
1224/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
1225/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001226void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001227 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001228 // Target identification.
1229 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001230 Builder.defineMacro("_LP64");
1231 Builder.defineMacro("__LP64__");
1232 Builder.defineMacro("__amd64__");
1233 Builder.defineMacro("__amd64");
1234 Builder.defineMacro("__x86_64");
1235 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001236 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001237 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001238 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001239
Eric Christophereea12d12010-04-02 23:50:19 +00001240 if (HasAES)
1241 Builder.defineMacro("__AES__");
1242
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001243 if (HasAVX)
1244 Builder.defineMacro("__AVX__");
1245
Chris Lattnerc0f59212009-03-02 22:27:17 +00001246 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001247 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001248
Chris Lattnerc0f59212009-03-02 22:27:17 +00001249 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +00001250 Builder.defineMacro("__nocona");
1251 Builder.defineMacro("__nocona__");
1252 Builder.defineMacro("__tune_nocona__");
1253 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001254
Chris Lattner54175442009-04-19 17:32:33 +00001255 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
1256 // functions in glibc header files that use FP Stack inline asm which the
1257 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00001258 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001259
Chris Lattner84f0ea82009-03-02 22:40:39 +00001260 // Each case falls through to the previous one here.
1261 switch (SSELevel) {
1262 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00001263 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001264 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00001265 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001266 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001267 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001268 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001269 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001270 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00001271 Builder.defineMacro("__SSE2__");
1272 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001273 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00001274 Builder.defineMacro("__SSE__");
1275 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001276 case MMX:
Benjamin Kramera9992772010-01-09 17:55:51 +00001277 Builder.defineMacro("__MMX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001278 case NoMMXSSE:
1279 break;
1280 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001281
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001282 if (Opts.Microsoft && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001283 switch (SSELevel) {
Michael J. Spencera764e832010-10-21 08:22:51 +00001284 case SSE42:
1285 case SSE41:
1286 case SSSE3:
1287 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001288 case SSE2:
1289 Builder.defineMacro("_M_IX86_FP", llvm::Twine(2));
1290 break;
1291 case SSE1:
1292 Builder.defineMacro("_M_IX86_FP", llvm::Twine(1));
1293 break;
1294 default:
1295 Builder.defineMacro("_M_IX86_FP", llvm::Twine(0));
1296 }
1297 }
1298
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001299 // Each case falls through to the previous one here.
1300 switch (AMD3DNowLevel) {
1301 case AMD3DNowAthlon:
1302 Builder.defineMacro("__3dNOW_A__");
1303 case AMD3DNow:
1304 Builder.defineMacro("__3dNOW__");
1305 case NoAMD3DNow:
1306 break;
1307 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001308}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001309
1310
Eli Friedman618234a2008-08-20 02:34:37 +00001311bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001312X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001313 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001314 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00001315 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00001316 case 'Y': // first letter of a pair:
1317 switch (*(Name+1)) {
1318 default: return false;
1319 case '0': // First SSE register.
1320 case 't': // Any SSE register, when SSE2 is enabled.
1321 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1322 case 'm': // any MMX register, when inter-unit moves enabled.
1323 break; // falls through to setAllowsRegister.
1324 }
Eli Friedman618234a2008-08-20 02:34:37 +00001325 case 'a': // eax.
1326 case 'b': // ebx.
1327 case 'c': // ecx.
1328 case 'd': // edx.
1329 case 'S': // esi.
1330 case 'D': // edi.
1331 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00001332 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00001333 case 't': // top of floating point stack.
1334 case 'u': // second from top of floating point stack.
1335 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00001336 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00001337 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00001338 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00001339 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1340 case 'l': // "Index" registers: any general register that can be used as an
1341 // index in a base+index memory access.
1342 Info.setAllowsRegister();
1343 return true;
1344 case 'C': // SSE floating point constant.
1345 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001346 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001347 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001348 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001349 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00001350 return true;
1351 }
Dale Johannesen545be512010-08-24 22:33:12 +00001352 return false;
Eli Friedman618234a2008-08-20 02:34:37 +00001353}
1354
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001355
Eli Friedman618234a2008-08-20 02:34:37 +00001356std::string
1357X86TargetInfo::convertConstraint(const char Constraint) const {
1358 switch (Constraint) {
1359 case 'a': return std::string("{ax}");
1360 case 'b': return std::string("{bx}");
1361 case 'c': return std::string("{cx}");
1362 case 'd': return std::string("{dx}");
1363 case 'S': return std::string("{si}");
1364 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00001365 case 'p': // address
1366 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00001367 case 't': // top of floating point stack.
1368 return std::string("{st}");
1369 case 'u': // second from top of floating point stack.
1370 return std::string("{st(1)}"); // second from top of floating point stack.
1371 default:
1372 return std::string(1, Constraint);
1373 }
1374}
Eli Friedman618234a2008-08-20 02:34:37 +00001375} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00001376
1377namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001378// X86-32 generic target
1379class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001380public:
Eli Friedman618234a2008-08-20 02:34:37 +00001381 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
1382 DoubleAlign = LongLongAlign = 32;
1383 LongDoubleWidth = 96;
1384 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001385 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1386 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001387 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +00001388 SizeType = UnsignedInt;
1389 PtrDiffType = SignedInt;
1390 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001391 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001392
1393 // Use fpret for all types.
1394 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
1395 (1 << TargetInfo::Double) |
1396 (1 << TargetInfo::LongDouble));
Eli Friedman618234a2008-08-20 02:34:37 +00001397 }
1398 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001399 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00001400 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001401
Chris Lattner21fb98e2009-09-23 06:06:36 +00001402 int getEHDataRegisterNumber(unsigned RegNo) const {
1403 if (RegNo == 0) return 0;
1404 if (RegNo == 1) return 2;
1405 return -1;
1406 }
Eli Friedman618234a2008-08-20 02:34:37 +00001407};
1408} // end anonymous namespace
1409
1410namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00001411class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
1412public:
1413 OpenBSDI386TargetInfo(const std::string& triple) :
1414 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
1415 SizeType = UnsignedLong;
1416 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00001417 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00001418 }
1419};
1420} // end anonymous namespace
1421
1422namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001423class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00001424public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00001425 DarwinI386TargetInfo(const std::string& triple) :
1426 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00001427 LongDoubleWidth = 128;
1428 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00001429 SizeType = UnsignedLong;
1430 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001431 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1432 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001433 "a0:0:64-f80:128:128-n8:16:32";
Daniel Dunbar613fd672010-05-27 00:35:16 +00001434 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00001435 }
1436
Eli Friedman618234a2008-08-20 02:34:37 +00001437};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001438} // end anonymous namespace
1439
1440namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00001441// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001442class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00001443public:
1444 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001445 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001446 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00001447 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00001448 DoubleAlign = LongLongAlign = 64;
1449 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 +00001450 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
1451 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +00001452 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001453 virtual void getTargetDefines(const LangOptions &Opts,
1454 MacroBuilder &Builder) const {
1455 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
1456 }
1457};
1458} // end anonymous namespace
1459
1460namespace {
1461
1462// x86-32 Windows Visual Studio target
1463class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1464public:
1465 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1466 : WindowsX86_32TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001467 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00001468 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
1469 }
1470 virtual void getTargetDefines(const LangOptions &Opts,
1471 MacroBuilder &Builder) const {
1472 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1473 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
1474 // The value of the following reflects processor type.
1475 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1476 // We lost the original triple, so we use the default.
1477 Builder.defineMacro("_M_IX86", "600");
1478 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001479};
1480} // end anonymous namespace
1481
1482namespace {
1483// x86-32 MinGW target
1484class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1485public:
1486 MinGWX86_32TargetInfo(const std::string& triple)
1487 : WindowsX86_32TargetInfo(triple) {
1488 }
1489 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001490 MacroBuilder &Builder) const {
1491 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001492 DefineStd(Builder, "WIN32", Opts);
1493 DefineStd(Builder, "WINNT", Opts);
1494 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00001495 Builder.defineMacro("__MSVCRT__");
1496 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001497
1498 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1499 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1500 if (Opts.Microsoft)
1501 // Provide "as-is" __declspec.
1502 Builder.defineMacro("__declspec", "__declspec");
1503 else
1504 // Provide alias of __attribute__ like mingw32-gcc.
1505 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001506 }
1507};
1508} // end anonymous namespace
1509
1510namespace {
1511// x86-32 Cygwin target
1512class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1513public:
1514 CygwinX86_32TargetInfo(const std::string& triple)
1515 : X86_32TargetInfo(triple) {
1516 TLSSupported = false;
1517 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001518 DoubleAlign = LongLongAlign = 64;
1519 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1520 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001521 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001522 }
1523 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001524 MacroBuilder &Builder) const {
1525 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1526 Builder.defineMacro("__CYGWIN__");
1527 Builder.defineMacro("__CYGWIN32__");
1528 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00001529 if (Opts.CPlusPlus)
1530 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00001531 }
Eli Friedman29a30502008-08-21 01:40:19 +00001532};
1533} // end anonymous namespace
1534
1535namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00001536// x86-32 Haiku target
1537class HaikuX86_32TargetInfo : public X86_32TargetInfo {
1538public:
1539 HaikuX86_32TargetInfo(const std::string& triple)
1540 : X86_32TargetInfo(triple) {
1541 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00001542 IntPtrType = SignedLong;
1543 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00001544 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00001545 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00001546 virtual void getTargetDefines(const LangOptions &Opts,
1547 MacroBuilder &Builder) const {
1548 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1549 Builder.defineMacro("__INTEL__");
1550 Builder.defineMacro("__HAIKU__");
1551 }
1552};
1553} // end anonymous namespace
1554
1555namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001556// x86-64 generic target
1557class X86_64TargetInfo : public X86TargetInfo {
1558public:
Chris Lattner33328642009-03-20 15:52:06 +00001559 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001560 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001561 LongDoubleWidth = 128;
1562 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00001563 LargeArrayMinWidth = 128;
1564 LargeArrayAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001565 IntMaxType = SignedLong;
1566 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001567 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001568 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001569
Eli Friedmaned855cb2008-08-21 00:13:15 +00001570 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1571 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001572 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001573
1574 // Use fpret only for long double.
1575 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Reid Spencer5f016e22007-07-11 17:01:13 +00001576 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001577 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001578 return "typedef struct __va_list_tag {"
1579 " unsigned gp_offset;"
1580 " unsigned fp_offset;"
1581 " void* overflow_arg_area;"
1582 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00001583 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00001584 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001585 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001586
Chris Lattner21fb98e2009-09-23 06:06:36 +00001587 int getEHDataRegisterNumber(unsigned RegNo) const {
1588 if (RegNo == 0) return 0;
1589 if (RegNo == 1) return 1;
1590 return -1;
1591 }
Eli Friedman618234a2008-08-20 02:34:37 +00001592};
1593} // end anonymous namespace
1594
1595namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001596// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001597class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001598public:
1599 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001600 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001601 TLSSupported = false;
1602 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001603 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00001604 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00001605 IntMaxType = SignedLongLong;
1606 UIntMaxType = UnsignedLongLong;
1607 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00001608 SizeType = UnsignedLongLong;
1609 PtrDiffType = SignedLongLong;
1610 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00001611 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001612 }
1613 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001614 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001615 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001616 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00001617 }
NAKAMURA Takumi79521992011-01-17 22:56:23 +00001618 virtual const char *getVAListDeclaration() const {
1619 return "typedef char* __builtin_va_list;";
1620 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001621};
1622} // end anonymous namespace
1623
1624namespace {
1625// x86-64 Windows Visual Studio target
1626class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1627public:
1628 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1629 : WindowsX86_64TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001630 LongDoubleWidth = LongDoubleAlign = 64;
1631 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00001632 }
1633 virtual void getTargetDefines(const LangOptions &Opts,
1634 MacroBuilder &Builder) const {
1635 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1636 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00001637 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001638 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001639 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001640};
1641} // end anonymous namespace
1642
1643namespace {
1644// x86-64 MinGW target
1645class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1646public:
1647 MinGWX86_64TargetInfo(const std::string& triple)
1648 : WindowsX86_64TargetInfo(triple) {
1649 }
1650 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001651 MacroBuilder &Builder) const {
1652 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001653 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00001654 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00001655 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00001656 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001657
1658 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1659 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1660 if (Opts.Microsoft)
1661 // Provide "as-is" __declspec.
1662 Builder.defineMacro("__declspec", "__declspec");
1663 else
1664 // Provide alias of __attribute__ like mingw32-gcc.
1665 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001666 }
1667};
1668} // end anonymous namespace
1669
1670namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001671class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1672public:
Mike Stump1eb44332009-09-09 15:08:12 +00001673 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001674 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1675 Int64Type = SignedLongLong;
1676 }
1677};
1678} // end anonymous namespace
1679
1680namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001681class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1682public:
Mike Stump1eb44332009-09-09 15:08:12 +00001683 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001684 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1685 IntMaxType = SignedLongLong;
1686 UIntMaxType = UnsignedLongLong;
1687 Int64Type = SignedLongLong;
1688 }
1689};
1690} // end anonymous namespace
1691
1692namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001693class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001694 // Possible FPU choices.
1695 enum FPUMode {
1696 NoFPU,
1697 VFP2FPU,
1698 VFP3FPU,
1699 NeonFPU
1700 };
1701
1702 static bool FPUModeIsVFP(FPUMode Mode) {
1703 return Mode >= VFP2FPU && Mode <= NeonFPU;
1704 }
1705
1706 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1707 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001708
Daniel Dunbareac7c532009-12-18 18:42:37 +00001709 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001710
1711 unsigned FPU : 3;
1712
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001713 unsigned IsThumb : 1;
1714
1715 // Initialized via features.
1716 unsigned SoftFloat : 1;
1717 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001718
Chris Lattner2752c012010-03-03 19:03:45 +00001719 static const Builtin::Info BuiltinInfo[];
1720
Chris Lattner393ff042008-04-21 18:56:49 +00001721public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001722 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001723 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001724 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001725 SizeType = UnsignedInt;
1726 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001727
Chris Lattner9bffb072010-04-23 16:29:58 +00001728 // {} in inline assembly are neon specifiers, not assembly variant
1729 // specifiers.
1730 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00001731
Daniel Dunbareac7c532009-12-18 18:42:37 +00001732 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001733 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001734 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001735 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1736 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001737 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1738 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001739 "v64:64:64-v128:64:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001740 } else {
1741 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1742 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001743 "v64:64:64-v128:64:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001744 }
John McCallee79a4c2010-08-21 22:46:04 +00001745
1746 // ARM targets default to using the ARM C++ ABI.
1747 CXXABI = CXXABI_ARM;
Eli Friedman61538a72008-05-20 14:21:01 +00001748 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001749 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001750 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001751 ABI = Name;
1752
Daniel Dunbara2a41612009-09-14 00:02:24 +00001753 // The defaults (above) are for AAPCS, check if we need to change them.
1754 //
1755 // FIXME: We need support for -meabi... we could just mangle it into the
1756 // name.
1757 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001758 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001759 SizeType = UnsignedLong;
1760
Daniel Dunbar684de632010-04-22 16:14:54 +00001761 // Do not respect the alignment of bit-field types when laying out
1762 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
1763 UseBitFieldTypeAlignment = false;
1764
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001765 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001766 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1767 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001768 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1769 "i64:32:32-f32:32:32-f64:32:32-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001770 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001771 } else {
1772 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001773 "i64:32:64-f32:32:32-f64:32:64-"
1774 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001775 }
1776
Daniel Dunbara2a41612009-09-14 00:02:24 +00001777 // FIXME: Override "preferred align" for double and long long.
1778 } else if (Name == "aapcs") {
1779 // FIXME: Enumerated types are variable width in straight AAPCS.
1780 } else if (Name == "aapcs-linux") {
1781 ;
1782 } else
1783 return false;
1784
1785 return true;
1786 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001787
Daniel Dunbara91320b2009-12-21 23:28:17 +00001788 void getDefaultFeatures(const std::string &CPU,
1789 llvm::StringMap<bool> &Features) const {
1790 // FIXME: This should not be here.
1791 Features["vfp2"] = false;
1792 Features["vfp3"] = false;
1793 Features["neon"] = false;
1794
1795 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
1796 Features["vfp2"] = true;
1797 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
1798 Features["neon"] = true;
1799 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001800
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001801 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1802 const std::string &Name,
1803 bool Enabled) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001804 if (Name == "soft-float" || Name == "soft-float-abi") {
1805 Features[Name] = Enabled;
1806 } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") {
1807 // These effectively are a single option, reset them when any is enabled.
1808 if (Enabled)
1809 Features["vfp2"] = Features["vfp3"] = Features["neon"] = false;
1810 Features[Name] = Enabled;
1811 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001812 return false;
1813
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001814 return true;
1815 }
1816
1817 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001818 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001819 SoftFloat = SoftFloatABI = false;
1820 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
1821 if (Features[i] == "+soft-float")
1822 SoftFloat = true;
1823 else if (Features[i] == "+soft-float-abi")
1824 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001825 else if (Features[i] == "+vfp2")
1826 FPU = VFP2FPU;
1827 else if (Features[i] == "+vfp3")
1828 FPU = VFP3FPU;
1829 else if (Features[i] == "+neon")
1830 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001831 }
1832
1833 // Remove front-end specific options which the backend handles differently.
1834 std::vector<std::string>::iterator it;
1835 it = std::find(Features.begin(), Features.end(), "+soft-float");
1836 if (it != Features.end())
1837 Features.erase(it);
1838 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
1839 if (it != Features.end())
1840 Features.erase(it);
1841 }
1842
Daniel Dunbareac7c532009-12-18 18:42:37 +00001843 static const char *getCPUDefineSuffix(llvm::StringRef Name) {
1844 return llvm::StringSwitch<const char*>(Name)
1845 .Cases("arm8", "arm810", "4")
1846 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
1847 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
1848 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
1849 .Case("ep9312", "4T")
1850 .Cases("arm10tdmi", "arm1020t", "5T")
1851 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
1852 .Case("arm926ej-s", "5TEJ")
1853 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
1854 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001855 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001856 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001857 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001858 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
1859 .Cases("cortex-a8", "cortex-a9", "7A")
Bob Wilson06f45632011-01-06 16:57:20 +00001860 .Case("cortex-m3", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00001861 .Case("cortex-m0", "6M")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001862 .Default(0);
1863 }
1864 virtual bool setCPU(const std::string &Name) {
1865 if (!getCPUDefineSuffix(Name))
1866 return false;
1867
1868 CPU = Name;
1869 return true;
1870 }
Chris Lattner33328642009-03-20 15:52:06 +00001871 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001872 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001873 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00001874 Builder.defineMacro("__arm");
1875 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001876
Chris Lattnerc0f59212009-03-02 22:27:17 +00001877 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001878 Builder.defineMacro("__ARMEL__");
1879 Builder.defineMacro("__LITTLE_ENDIAN__");
1880 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001881
1882 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00001883 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001884
Mike Stump437bb4b2009-04-08 02:07:04 +00001885 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001886
Daniel Dunbareac7c532009-12-18 18:42:37 +00001887 // FIXME: It's more complicated than this and we don't really support
1888 // interworking.
1889 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00001890 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001891
Daniel Dunbareac7c532009-12-18 18:42:37 +00001892 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00001893 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001894
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001895 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00001896 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001897
1898 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00001899 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001900
Daniel Dunbara91320b2009-12-21 23:28:17 +00001901 bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7"));
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001902 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001903 Builder.defineMacro("__THUMBEL__");
1904 Builder.defineMacro("__thumb__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001905 if (IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001906 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001907 }
1908
1909 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00001910 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001911
1912 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00001913 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001914
1915 // This only gets set when Neon instructions are actually available, unlike
1916 // the VFP define, hence the soft float and arch check. This is subtly
1917 // different from gcc, we follow the intent which was that it should be set
1918 // when Neon instructions are actually available.
1919 if (FPU == NeonFPU && !SoftFloat && IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001920 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00001921 }
1922 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1923 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00001924 Records = BuiltinInfo;
1925 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00001926 }
1927 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001928 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001929 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001930 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001931 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001932 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001933 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001934 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001935 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001936 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001937 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001938 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001939 case 'l': // r0-r7
1940 case 'h': // r8-r15
1941 case 'w': // VFP Floating point register single precision
1942 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001943 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001944 return true;
1945 }
Chris Lattner393ff042008-04-21 18:56:49 +00001946 return false;
1947 }
1948 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001949 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001950 return "";
1951 }
1952};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001953
1954const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001955 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001956 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001957 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
1958
1959 // Float registers
1960 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
1961 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
1962 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001963 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001964
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001965 // Double registers
1966 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
1967 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00001968 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
1969 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001970
1971 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00001972 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
1973 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001974};
1975
1976void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001977 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001978 Names = GCCRegNames;
1979 NumNames = llvm::array_lengthof(GCCRegNames);
1980}
1981
1982const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001983 { { "a1" }, "r0" },
1984 { { "a2" }, "r1" },
1985 { { "a3" }, "r2" },
1986 { { "a4" }, "r3" },
1987 { { "v1" }, "r4" },
1988 { { "v2" }, "r5" },
1989 { { "v3" }, "r6" },
1990 { { "v4" }, "r7" },
1991 { { "v5" }, "r8" },
1992 { { "v6", "rfp" }, "r9" },
1993 { { "sl" }, "r10" },
1994 { { "fp" }, "r11" },
1995 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001996 { { "r13" }, "sp" },
1997 { { "r14" }, "lr" },
1998 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001999 // The S, D and Q registers overlap, but aren't really aliases; we
2000 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00002001};
2002
2003void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2004 unsigned &NumAliases) const {
2005 Aliases = GCCRegAliases;
2006 NumAliases = llvm::array_lengthof(GCCRegAliases);
2007}
Chris Lattner2752c012010-03-03 19:03:45 +00002008
2009const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +00002010#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
2011#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
2012 ALL_LANGUAGES, false },
Chris Lattner2752c012010-03-03 19:03:45 +00002013#include "clang/Basic/BuiltinsARM.def"
2014};
Chris Lattner393ff042008-04-21 18:56:49 +00002015} // end anonymous namespace.
2016
Eli Friedmana9f54962008-08-20 07:44:10 +00002017
2018namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00002019class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002020 public DarwinTargetInfo<ARMTargetInfo> {
2021protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002022 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00002023 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00002024 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00002025 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002026
Torok Edwin5f6c1942009-06-30 17:10:35 +00002027public:
Mike Stump1eb44332009-09-09 15:08:12 +00002028 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00002029 : DarwinTargetInfo<ARMTargetInfo>(triple) {
2030 HasAlignMac68kSupport = true;
2031 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002032};
2033} // end anonymous namespace.
2034
Reid Spencer5f016e22007-07-11 17:01:13 +00002035namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00002036class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00002037 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2038 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002039 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00002040public:
Eli Friedman01b86682008-08-20 07:28:14 +00002041 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
2042 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00002043 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 +00002044 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00002045 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002046 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2047 const std::string &Name,
2048 bool Enabled) const {
2049 if (Name == "soft-float")
2050 Features[Name] = Enabled;
2051 else
2052 return false;
2053
2054 return true;
2055 }
2056 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
2057 SoftFloat = false;
2058 for (unsigned i = 0, e = Features.size(); i != e; ++i)
2059 if (Features[i] == "+soft-float")
2060 SoftFloat = true;
2061 }
Chris Lattner33328642009-03-20 15:52:06 +00002062 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002063 MacroBuilder &Builder) const {
2064 DefineStd(Builder, "sparc", Opts);
2065 Builder.defineMacro("__sparcv8");
2066 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002067
2068 if (SoftFloat)
2069 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00002070 }
2071 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2072 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002073 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00002074 }
2075 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002076 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00002077 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002078 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002079 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002080 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002081 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002082 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00002083 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002084 // FIXME: Implement!
2085 return false;
Gabor Greif26658672008-02-21 16:29:08 +00002086 }
2087 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002088 // FIXME: Implement!
2089 return "";
Gabor Greif26658672008-02-21 16:29:08 +00002090 }
2091};
2092
Chris Lattnere957f532009-01-27 01:58:38 +00002093const char * const SparcV8TargetInfo::GCCRegNames[] = {
2094 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2095 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2096 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2097 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
2098};
2099
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002100void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002101 unsigned &NumNames) const {
2102 Names = GCCRegNames;
2103 NumNames = llvm::array_lengthof(GCCRegNames);
2104}
2105
2106const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002107 { { "g0" }, "r0" },
2108 { { "g1" }, "r1" },
2109 { { "g2" }, "r2" },
2110 { { "g3" }, "r3" },
2111 { { "g4" }, "r4" },
2112 { { "g5" }, "r5" },
2113 { { "g6" }, "r6" },
2114 { { "g7" }, "r7" },
2115 { { "o0" }, "r8" },
2116 { { "o1" }, "r9" },
2117 { { "o2" }, "r10" },
2118 { { "o3" }, "r11" },
2119 { { "o4" }, "r12" },
2120 { { "o5" }, "r13" },
2121 { { "o6", "sp" }, "r14" },
2122 { { "o7" }, "r15" },
2123 { { "l0" }, "r16" },
2124 { { "l1" }, "r17" },
2125 { { "l2" }, "r18" },
2126 { { "l3" }, "r19" },
2127 { { "l4" }, "r20" },
2128 { { "l5" }, "r21" },
2129 { { "l6" }, "r22" },
2130 { { "l7" }, "r23" },
2131 { { "i0" }, "r24" },
2132 { { "i1" }, "r25" },
2133 { { "i2" }, "r26" },
2134 { { "i3" }, "r27" },
2135 { { "i4" }, "r28" },
2136 { { "i5" }, "r29" },
2137 { { "i6", "fp" }, "r30" },
2138 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00002139};
2140
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002141void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002142 unsigned &NumAliases) const {
2143 Aliases = GCCRegAliases;
2144 NumAliases = llvm::array_lengthof(GCCRegAliases);
2145}
Gabor Greif26658672008-02-21 16:29:08 +00002146} // end anonymous namespace.
2147
Eli Friedman01b86682008-08-20 07:28:14 +00002148namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002149class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
2150public:
2151 AuroraUXSparcV8TargetInfo(const std::string& triple) :
2152 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
2153 SizeType = UnsignedInt;
2154 PtrDiffType = SignedInt;
2155 }
2156};
Torok Edwin5f6c1942009-06-30 17:10:35 +00002157class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00002158public:
2159 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002160 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00002161 SizeType = UnsignedInt;
2162 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00002163 }
2164};
2165} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00002166
Chris Lattner2621fd12008-05-08 05:58:21 +00002167namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002168 class MSP430TargetInfo : public TargetInfo {
2169 static const char * const GCCRegNames[];
2170 public:
2171 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
2172 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00002173 IntWidth = 16; IntAlign = 16;
2174 LongWidth = 32; LongLongWidth = 64;
2175 LongAlign = LongLongAlign = 16;
2176 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002177 SizeType = UnsignedInt;
2178 IntMaxType = SignedLong;
2179 UIntMaxType = UnsignedLong;
2180 IntPtrType = SignedShort;
2181 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00002182 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00002183 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002184 }
2185 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002186 MacroBuilder &Builder) const {
2187 Builder.defineMacro("MSP430");
2188 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002189 // FIXME: defines for different 'flavours' of MCU
2190 }
2191 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2192 unsigned &NumRecords) const {
2193 // FIXME: Implement.
2194 Records = 0;
2195 NumRecords = 0;
2196 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002197 virtual void getGCCRegNames(const char * const *&Names,
2198 unsigned &NumNames) const;
2199 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2200 unsigned &NumAliases) const {
2201 // No aliases.
2202 Aliases = 0;
2203 NumAliases = 0;
2204 }
2205 virtual bool validateAsmConstraint(const char *&Name,
2206 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00002207 // No target constraints for now.
2208 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002209 }
2210 virtual const char *getClobbers() const {
2211 // FIXME: Is this really right?
2212 return "";
2213 }
2214 virtual const char *getVAListDeclaration() const {
2215 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00002216 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002217 }
2218 };
2219
2220 const char * const MSP430TargetInfo::GCCRegNames[] = {
2221 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2222 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2223 };
2224
2225 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
2226 unsigned &NumNames) const {
2227 Names = GCCRegNames;
2228 NumNames = llvm::array_lengthof(GCCRegNames);
2229 }
2230}
2231
2232
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002233namespace {
2234 class SystemZTargetInfo : public TargetInfo {
2235 static const char * const GCCRegNames[];
2236 public:
2237 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
2238 TLSSupported = false;
2239 IntWidth = IntAlign = 32;
2240 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
2241 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00002242 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
2243 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002244 }
2245 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002246 MacroBuilder &Builder) const {
2247 Builder.defineMacro("__s390__");
2248 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002249 }
2250 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2251 unsigned &NumRecords) const {
2252 // FIXME: Implement.
2253 Records = 0;
2254 NumRecords = 0;
2255 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002256
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002257 virtual void getGCCRegNames(const char * const *&Names,
2258 unsigned &NumNames) const;
2259 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2260 unsigned &NumAliases) const {
2261 // No aliases.
2262 Aliases = 0;
2263 NumAliases = 0;
2264 }
2265 virtual bool validateAsmConstraint(const char *&Name,
2266 TargetInfo::ConstraintInfo &info) const {
2267 // FIXME: implement
2268 return true;
2269 }
2270 virtual const char *getClobbers() const {
2271 // FIXME: Is this really right?
2272 return "";
2273 }
2274 virtual const char *getVAListDeclaration() const {
2275 // FIXME: implement
2276 return "typedef char* __builtin_va_list;";
2277 }
2278 };
2279
2280 const char * const SystemZTargetInfo::GCCRegNames[] = {
2281 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2282 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2283 };
2284
2285 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
2286 unsigned &NumNames) const {
2287 Names = GCCRegNames;
2288 NumNames = llvm::array_lengthof(GCCRegNames);
2289 }
2290}
2291
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002292namespace {
2293 class BlackfinTargetInfo : public TargetInfo {
2294 static const char * const GCCRegNames[];
2295 public:
2296 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
2297 TLSSupported = false;
2298 DoubleAlign = 32;
2299 LongLongAlign = 32;
2300 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00002301 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002302 }
2303
2304 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002305 MacroBuilder &Builder) const {
2306 DefineStd(Builder, "bfin", Opts);
2307 DefineStd(Builder, "BFIN", Opts);
2308 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002309 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00002310 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002311 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
2312 }
2313
2314 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2315 unsigned &NumRecords) const {
2316 // FIXME: Implement.
2317 Records = 0;
2318 NumRecords = 0;
2319 }
2320
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002321 virtual void getGCCRegNames(const char * const *&Names,
2322 unsigned &NumNames) const;
2323
2324 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2325 unsigned &NumAliases) const {
2326 // No aliases.
2327 Aliases = 0;
2328 NumAliases = 0;
2329 }
2330
2331 virtual bool validateAsmConstraint(const char *&Name,
2332 TargetInfo::ConstraintInfo &Info) const {
2333 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
2334 Info.setAllowsRegister();
2335 return true;
2336 }
2337 return false;
2338 }
2339
2340 virtual const char *getClobbers() const {
2341 return "";
2342 }
2343
2344 virtual const char *getVAListDeclaration() const {
2345 return "typedef char* __builtin_va_list;";
2346 }
2347 };
2348
2349 const char * const BlackfinTargetInfo::GCCRegNames[] = {
2350 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2351 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
2352 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
2353 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
2354 "a0", "a1", "cc",
2355 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
2356 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
2357 };
2358
2359 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
2360 unsigned &NumNames) const {
2361 Names = GCCRegNames;
2362 NumNames = llvm::array_lengthof(GCCRegNames);
2363 }
2364}
2365
Eli Friedmanb63decf2009-08-19 20:47:07 +00002366namespace {
2367
Mike Stump1eb44332009-09-09 15:08:12 +00002368 // LLVM and Clang cannot be used directly to output native binaries for
2369 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00002370 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00002371 //
2372 // TCE uses the llvm bitcode as input and uses it for generating customized
2373 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00002374 // publicly available in http://tce.cs.tut.fi
2375
2376 class TCETargetInfo : public TargetInfo{
2377 public:
2378 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
2379 TLSSupported = false;
2380 IntWidth = 32;
2381 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00002382 PointerWidth = 32;
2383 IntAlign = 32;
2384 LongAlign = LongLongAlign = 32;
2385 PointerAlign = 32;
2386 SizeType = UnsignedInt;
2387 IntMaxType = SignedLong;
2388 UIntMaxType = UnsignedLong;
2389 IntPtrType = SignedInt;
2390 PtrDiffType = SignedInt;
2391 FloatWidth = 32;
2392 FloatAlign = 32;
2393 DoubleWidth = 32;
2394 DoubleAlign = 32;
2395 LongDoubleWidth = 32;
2396 LongDoubleAlign = 32;
2397 FloatFormat = &llvm::APFloat::IEEEsingle;
2398 DoubleFormat = &llvm::APFloat::IEEEsingle;
2399 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00002400 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
2401 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00002402 "f32:32:32-f64:32:32-v64:32:32-"
2403 "v128:32:32-a0:0:32-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00002404 }
2405
2406 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002407 MacroBuilder &Builder) const {
2408 DefineStd(Builder, "tce", Opts);
2409 Builder.defineMacro("__TCE__");
2410 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00002411 }
2412 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2413 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00002414 virtual const char *getClobbers() const {
2415 return "";
2416 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002417 virtual const char *getVAListDeclaration() const {
2418 return "typedef void* __builtin_va_list;";
2419 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002420 virtual void getGCCRegNames(const char * const *&Names,
2421 unsigned &NumNames) const {}
2422 virtual bool validateAsmConstraint(const char *&Name,
2423 TargetInfo::ConstraintInfo &info) const {
2424 return true;
2425 }
2426 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2427 unsigned &NumAliases) const {}
2428 };
2429}
2430
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002431namespace {
2432class MipsTargetInfo : public TargetInfo {
Eric Christophered734732010-03-02 02:41:08 +00002433 std::string ABI, CPU;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002434 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2435 static const char * const GCCRegNames[];
2436public:
Eric Christophered734732010-03-02 02:41:08 +00002437 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002438 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2439 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2440 }
Eric Christophered734732010-03-02 02:41:08 +00002441 virtual const char *getABI() const { return ABI.c_str(); }
2442 virtual bool setABI(const std::string &Name) {
2443
2444 if ((Name == "o32") || (Name == "eabi")) {
2445 ABI = Name;
2446 return true;
2447 } else
2448 return false;
2449 }
2450 virtual bool setCPU(const std::string &Name) {
2451 CPU = Name;
2452 return true;
2453 }
2454 void getDefaultFeatures(const std::string &CPU,
2455 llvm::StringMap<bool> &Features) const {
2456 Features[ABI] = true;
2457 Features[CPU] = true;
2458 }
2459 virtual void getArchDefines(const LangOptions &Opts,
2460 MacroBuilder &Builder) const {
2461 if (ABI == "o32")
2462 Builder.defineMacro("__mips_o32");
2463 else if (ABI == "eabi")
2464 Builder.defineMacro("__mips_eabi");
2465 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002466 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002467 MacroBuilder &Builder) const {
2468 DefineStd(Builder, "mips", Opts);
2469 Builder.defineMacro("_mips");
2470 DefineStd(Builder, "MIPSEB", Opts);
2471 Builder.defineMacro("_MIPSEB");
2472 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002473 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002474 }
2475 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2476 unsigned &NumRecords) const {
2477 // FIXME: Implement!
2478 }
2479 virtual const char *getVAListDeclaration() const {
2480 return "typedef void* __builtin_va_list;";
2481 }
2482 virtual void getGCCRegNames(const char * const *&Names,
2483 unsigned &NumNames) const;
2484 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2485 unsigned &NumAliases) const;
2486 virtual bool validateAsmConstraint(const char *&Name,
2487 TargetInfo::ConstraintInfo &Info) const {
2488 switch (*Name) {
2489 default:
2490 case 'r': // CPU registers.
2491 case 'd': // Equivalent to "r" unless generating MIPS16 code.
2492 case 'y': // Equivalent to "r", backwards compatibility only.
2493 case 'f': // floating-point registers.
2494 Info.setAllowsRegister();
2495 return true;
2496 }
2497 return false;
2498 }
2499
2500 virtual const char *getClobbers() const {
2501 // FIXME: Implement!
2502 return "";
2503 }
2504};
2505
2506const char * const MipsTargetInfo::GCCRegNames[] = {
Michael J. Spencer20249a12010-10-21 03:16:25 +00002507 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002508 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2509 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
2510 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
2511 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
2512 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
2513 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
2514 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
2515 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
2516 "$fcc5","$fcc6","$fcc7"
2517};
2518
2519void MipsTargetInfo::getGCCRegNames(const char * const *&Names,
2520 unsigned &NumNames) const {
2521 Names = GCCRegNames;
2522 NumNames = llvm::array_lengthof(GCCRegNames);
2523}
2524
2525const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = {
2526 { { "at" }, "$1" },
2527 { { "v0" }, "$2" },
2528 { { "v1" }, "$3" },
2529 { { "a0" }, "$4" },
2530 { { "a1" }, "$5" },
2531 { { "a2" }, "$6" },
2532 { { "a3" }, "$7" },
2533 { { "t0" }, "$8" },
2534 { { "t1" }, "$9" },
2535 { { "t2" }, "$10" },
2536 { { "t3" }, "$11" },
2537 { { "t4" }, "$12" },
2538 { { "t5" }, "$13" },
2539 { { "t6" }, "$14" },
2540 { { "t7" }, "$15" },
2541 { { "s0" }, "$16" },
2542 { { "s1" }, "$17" },
2543 { { "s2" }, "$18" },
2544 { { "s3" }, "$19" },
2545 { { "s4" }, "$20" },
2546 { { "s5" }, "$21" },
2547 { { "s6" }, "$22" },
2548 { { "s7" }, "$23" },
2549 { { "t8" }, "$24" },
2550 { { "t9" }, "$25" },
2551 { { "k0" }, "$26" },
2552 { { "k1" }, "$27" },
2553 { { "gp" }, "$28" },
2554 { { "sp" }, "$29" },
2555 { { "fp" }, "$30" },
2556 { { "ra" }, "$31" }
2557};
2558
2559void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2560 unsigned &NumAliases) const {
2561 Aliases = GCCRegAliases;
2562 NumAliases = llvm::array_lengthof(GCCRegAliases);
2563}
2564} // end anonymous namespace.
2565
2566namespace {
2567class MipselTargetInfo : public MipsTargetInfo {
2568public:
2569 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) {
2570 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2571 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2572 }
2573
2574 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002575 MacroBuilder &Builder) const;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002576};
2577
2578void MipselTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002579 MacroBuilder &Builder) const {
2580 DefineStd(Builder, "mips", Opts);
2581 Builder.defineMacro("_mips");
2582 DefineStd(Builder, "MIPSEL", Opts);
2583 Builder.defineMacro("_MIPSEL");
2584 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002585 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002586}
2587} // end anonymous namespace.
2588
Reid Spencer5f016e22007-07-11 17:01:13 +00002589//===----------------------------------------------------------------------===//
2590// Driver code
2591//===----------------------------------------------------------------------===//
2592
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002593static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002594 llvm::Triple Triple(T);
2595 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00002596
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002597 switch (Triple.getArch()) {
2598 default:
2599 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00002600
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002601 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00002602 case llvm::Triple::thumb:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002603 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00002604 case llvm::Triple::Linux:
2605 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002606 case llvm::Triple::Darwin:
Eli Friedmaned855cb2008-08-21 00:13:15 +00002607 return new DarwinARMTargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002608 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002609 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002610 default:
2611 return new ARMTargetInfo(T);
2612 }
Eli Friedman61538a72008-05-20 14:21:01 +00002613
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002614 case llvm::Triple::bfin:
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002615 return new BlackfinTargetInfo(T);
2616
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002617 case llvm::Triple::msp430:
2618 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00002619
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002620 case llvm::Triple::mips:
2621 if (os == llvm::Triple::Psp)
2622 return new PSPTargetInfo<MipsTargetInfo>(T);
2623 if (os == llvm::Triple::Linux)
2624 return new LinuxTargetInfo<MipsTargetInfo>(T);
2625 return new MipsTargetInfo(T);
2626
2627 case llvm::Triple::mipsel:
2628 if (os == llvm::Triple::Psp)
2629 return new PSPTargetInfo<MipselTargetInfo>(T);
2630 if (os == llvm::Triple::Linux)
2631 return new LinuxTargetInfo<MipselTargetInfo>(T);
2632 return new MipselTargetInfo(T);
2633
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002634 case llvm::Triple::ppc:
2635 if (os == llvm::Triple::Darwin)
Roman Divackyc81f2a22011-01-06 08:27:10 +00002636 return new DarwinPPC32TargetInfo(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002637 else if (os == llvm::Triple::FreeBSD)
2638 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002639 return new PPC32TargetInfo(T);
2640
2641 case llvm::Triple::ppc64:
2642 if (os == llvm::Triple::Darwin)
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00002643 return new DarwinPPC64TargetInfo(T);
John Thompson3f6918a2009-11-19 17:18:50 +00002644 else if (os == llvm::Triple::Lv2)
2645 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002646 else if (os == llvm::Triple::FreeBSD)
2647 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002648 return new PPC64TargetInfo(T);
2649
Chris Lattner9cbeb632010-03-06 21:21:27 +00002650 case llvm::Triple::mblaze:
2651 return new MBlazeTargetInfo(T);
2652
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002653 case llvm::Triple::sparc:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002654 if (os == llvm::Triple::AuroraUX)
2655 return new AuroraUXSparcV8TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002656 if (os == llvm::Triple::Solaris)
2657 return new SolarisSparcV8TargetInfo(T);
2658 return new SparcV8TargetInfo(T);
2659
John Thompson3f6918a2009-11-19 17:18:50 +00002660 // FIXME: Need a real SPU target.
2661 case llvm::Triple::cellspu:
2662 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
2663
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002664 case llvm::Triple::systemz:
2665 return new SystemZTargetInfo(T);
2666
Eli Friedmanb63decf2009-08-19 20:47:07 +00002667 case llvm::Triple::tce:
2668 return new TCETargetInfo(T);
2669
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002670 case llvm::Triple::x86:
2671 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002672 case llvm::Triple::AuroraUX:
2673 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002674 case llvm::Triple::Darwin:
2675 return new DarwinI386TargetInfo(T);
2676 case llvm::Triple::Linux:
2677 return new LinuxTargetInfo<X86_32TargetInfo>(T);
2678 case llvm::Triple::DragonFly:
2679 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
2680 case llvm::Triple::NetBSD:
2681 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
2682 case llvm::Triple::OpenBSD:
2683 return new OpenBSDI386TargetInfo(T);
2684 case llvm::Triple::FreeBSD:
2685 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00002686 case llvm::Triple::Minix:
2687 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002688 case llvm::Triple::Solaris:
2689 return new SolarisTargetInfo<X86_32TargetInfo>(T);
2690 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002691 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002692 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002693 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002694 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00002695 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00002696 case llvm::Triple::Haiku:
2697 return new HaikuX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002698 default:
2699 return new X86_32TargetInfo(T);
2700 }
2701
2702 case llvm::Triple::x86_64:
2703 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002704 case llvm::Triple::AuroraUX:
2705 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002706 case llvm::Triple::Darwin:
2707 return new DarwinX86_64TargetInfo(T);
2708 case llvm::Triple::Linux:
2709 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00002710 case llvm::Triple::DragonFly:
2711 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002712 case llvm::Triple::NetBSD:
2713 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
2714 case llvm::Triple::OpenBSD:
2715 return new OpenBSDX86_64TargetInfo(T);
2716 case llvm::Triple::FreeBSD:
2717 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
2718 case llvm::Triple::Solaris:
2719 return new SolarisTargetInfo<X86_64TargetInfo>(T);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00002720 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002721 return new MinGWX86_64TargetInfo(T);
2722 case llvm::Triple::Win32: // This is what Triple.h supports now.
Douglas Gregorfb7049a2011-02-01 15:06:18 +00002723 if (Triple.getEnvironment() == llvm::Triple::MachO)
2724 return new DarwinX86_64TargetInfo(T);
2725 else
2726 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002727 default:
2728 return new X86_64TargetInfo(T);
2729 }
2730 }
Reid Spencer5f016e22007-07-11 17:01:13 +00002731}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002732
2733/// CreateTargetInfo - Return the target info object for the specified target
2734/// triple.
2735TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002736 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002737 llvm::Triple Triple(Opts.Triple);
2738
2739 // Construct the target
2740 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
2741 if (!Target) {
2742 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
2743 return 0;
2744 }
2745
Daniel Dunbareac7c532009-12-18 18:42:37 +00002746 // Set the target CPU if specified.
2747 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
2748 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
2749 return 0;
2750 }
2751
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002752 // Set the target ABI if specified.
2753 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
2754 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
2755 return 0;
2756 }
2757
Charles Davis98b7c5c2010-06-11 01:06:47 +00002758 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00002759 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00002760 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
2761 return 0;
2762 }
2763
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002764 // Compute the default target features, we need the target to handle this
2765 // because features may have dependencies on one another.
2766 llvm::StringMap<bool> Features;
2767 Target->getDefaultFeatures(Opts.CPU, Features);
2768
2769 // Apply the user specified deltas.
2770 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
2771 ie = Opts.Features.end(); it != ie; ++it) {
2772 const char *Name = it->c_str();
2773
2774 // Apply the feature via the target.
2775 if ((Name[0] != '-' && Name[0] != '+') ||
2776 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
2777 Diags.Report(diag::err_target_invalid_feature) << Name;
2778 return 0;
2779 }
2780 }
2781
2782 // Add the features to the compile options.
2783 //
2784 // FIXME: If we are completely confident that we have the right set, we only
2785 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002786 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002787 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
2788 ie = Features.end(); it != ie; ++it)
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002789 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
2790 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002791
2792 return Target.take();
2793}