blob: 973518312dbead4399966ad0274908a7965ff2cd [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);
1087 }
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001088 else if (CPU == "k6" || CPU == "winchip-c6")
1089 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +00001090 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001091 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
1092 setFeatureEnabled(Features, "mmx", true);
1093 setFeatureEnabled(Features, "3dnow", true);
1094 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
1095 setFeatureEnabled(Features, "sse", true);
1096 setFeatureEnabled(Features, "3dnowa", true);
1097 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
1098 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +00001099 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001100 setFeatureEnabled(Features, "3dnowa", true);
Roman Divackyc8b09a12010-12-29 13:28:29 +00001101 } else if (CPU == "k8-sse3") {
1102 setFeatureEnabled(Features, "sse3", true);
1103 setFeatureEnabled(Features, "3dnowa", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001104 } else if (CPU == "c3-2")
1105 setFeatureEnabled(Features, "sse", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001106}
1107
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001108bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +00001109 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001110 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001111 // FIXME: This *really* should not be here. We need some way of translating
1112 // options into llvm subtarget features.
1113 if (!Features.count(Name) &&
1114 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001115 return false;
1116
1117 if (Enabled) {
1118 if (Name == "mmx")
1119 Features["mmx"] = true;
1120 else if (Name == "sse")
1121 Features["mmx"] = Features["sse"] = true;
1122 else if (Name == "sse2")
1123 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
1124 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001125 Features["mmx"] = Features["sse"] = Features["sse2"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001126 Features["sse3"] = true;
1127 else if (Name == "ssse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001128 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001129 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001130 else if (Name == "sse4" || Name == "sse4.2")
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"] = Features["sse41"] = Features["sse42"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001133 else if (Name == "sse4.1")
1134 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1135 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001136 else if (Name == "3dnow")
1137 Features["3dnowa"] = true;
1138 else if (Name == "3dnowa")
1139 Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001140 else if (Name == "aes")
1141 Features["aes"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001142 else if (Name == "avx")
1143 Features["avx"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001144 } else {
1145 if (Name == "mmx")
Mike Stump1eb44332009-09-09 15:08:12 +00001146 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001147 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1148 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001149 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 == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001152 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001153 Features["sse41"] = Features["sse42"] = false;
1154 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001155 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001156 Features["sse42"] = false;
1157 else if (Name == "ssse3")
1158 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1159 else if (Name == "sse4")
1160 Features["sse41"] = Features["sse42"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001161 else if (Name == "sse4.2")
1162 Features["sse42"] = false;
1163 else if (Name == "sse4.1")
1164 Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001165 else if (Name == "3dnow")
1166 Features["3dnow"] = Features["3dnowa"] = false;
1167 else if (Name == "3dnowa")
1168 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001169 else if (Name == "aes")
1170 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001171 else if (Name == "avx")
1172 Features["avx"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001173 }
1174
1175 return true;
1176}
1177
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001178/// HandleTargetOptions - Perform initialization based on the user
1179/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001180void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001181 // Remember the maximum enabled sselevel.
1182 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1183 // Ignore disabled features.
1184 if (Features[i][0] == '-')
1185 continue;
1186
Eric Christophereea12d12010-04-02 23:50:19 +00001187 if (Features[i].substr(1) == "aes") {
1188 HasAES = true;
1189 continue;
1190 }
1191
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001192 // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
1193 // For now let it be enabled together with other SSE levels.
1194 if (Features[i].substr(1) == "avx") {
1195 HasAVX = true;
1196 continue;
1197 }
1198
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001199 assert(Features[i][0] == '+' && "Invalid target feature!");
1200 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
1201 .Case("sse42", SSE42)
1202 .Case("sse41", SSE41)
1203 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001204 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001205 .Case("sse2", SSE2)
1206 .Case("sse", SSE1)
1207 .Case("mmx", MMX)
1208 .Default(NoMMXSSE);
1209 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001210
1211 AMD3DNowEnum ThreeDNowLevel =
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001212 llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1))
1213 .Case("3dnowa", AMD3DNowAthlon)
1214 .Case("3dnow", AMD3DNow)
1215 .Default(NoAMD3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001216
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001217 AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001218 }
Chris Lattner3daed522009-03-02 22:20:04 +00001219}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001220
1221/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
1222/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001223void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001224 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001225 // Target identification.
1226 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001227 Builder.defineMacro("_LP64");
1228 Builder.defineMacro("__LP64__");
1229 Builder.defineMacro("__amd64__");
1230 Builder.defineMacro("__amd64");
1231 Builder.defineMacro("__x86_64");
1232 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001233 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001234 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001235 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001236
Eric Christophereea12d12010-04-02 23:50:19 +00001237 if (HasAES)
1238 Builder.defineMacro("__AES__");
1239
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001240 if (HasAVX)
1241 Builder.defineMacro("__AVX__");
1242
Chris Lattnerc0f59212009-03-02 22:27:17 +00001243 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001244 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001245
Chris Lattnerc0f59212009-03-02 22:27:17 +00001246 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +00001247 Builder.defineMacro("__nocona");
1248 Builder.defineMacro("__nocona__");
1249 Builder.defineMacro("__tune_nocona__");
1250 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001251
Chris Lattner54175442009-04-19 17:32:33 +00001252 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
1253 // functions in glibc header files that use FP Stack inline asm which the
1254 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00001255 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001256
Chris Lattner84f0ea82009-03-02 22:40:39 +00001257 // Each case falls through to the previous one here.
1258 switch (SSELevel) {
1259 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00001260 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001261 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00001262 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001263 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001264 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001265 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001266 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001267 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00001268 Builder.defineMacro("__SSE2__");
1269 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001270 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00001271 Builder.defineMacro("__SSE__");
1272 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001273 case MMX:
Benjamin Kramera9992772010-01-09 17:55:51 +00001274 Builder.defineMacro("__MMX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001275 case NoMMXSSE:
1276 break;
1277 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001278
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001279 if (Opts.Microsoft && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001280 switch (SSELevel) {
Michael J. Spencera764e832010-10-21 08:22:51 +00001281 case SSE42:
1282 case SSE41:
1283 case SSSE3:
1284 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001285 case SSE2:
1286 Builder.defineMacro("_M_IX86_FP", llvm::Twine(2));
1287 break;
1288 case SSE1:
1289 Builder.defineMacro("_M_IX86_FP", llvm::Twine(1));
1290 break;
1291 default:
1292 Builder.defineMacro("_M_IX86_FP", llvm::Twine(0));
1293 }
1294 }
1295
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001296 // Each case falls through to the previous one here.
1297 switch (AMD3DNowLevel) {
1298 case AMD3DNowAthlon:
1299 Builder.defineMacro("__3dNOW_A__");
1300 case AMD3DNow:
1301 Builder.defineMacro("__3dNOW__");
1302 case NoAMD3DNow:
1303 break;
1304 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001305}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001306
1307
Eli Friedman618234a2008-08-20 02:34:37 +00001308bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001309X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001310 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001311 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00001312 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00001313 case 'Y': // first letter of a pair:
1314 switch (*(Name+1)) {
1315 default: return false;
1316 case '0': // First SSE register.
1317 case 't': // Any SSE register, when SSE2 is enabled.
1318 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1319 case 'm': // any MMX register, when inter-unit moves enabled.
1320 break; // falls through to setAllowsRegister.
1321 }
Eli Friedman618234a2008-08-20 02:34:37 +00001322 case 'a': // eax.
1323 case 'b': // ebx.
1324 case 'c': // ecx.
1325 case 'd': // edx.
1326 case 'S': // esi.
1327 case 'D': // edi.
1328 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00001329 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00001330 case 't': // top of floating point stack.
1331 case 'u': // second from top of floating point stack.
1332 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00001333 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00001334 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00001335 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00001336 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1337 case 'l': // "Index" registers: any general register that can be used as an
1338 // index in a base+index memory access.
1339 Info.setAllowsRegister();
1340 return true;
1341 case 'C': // SSE floating point constant.
1342 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001343 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001344 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001345 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001346 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00001347 return true;
1348 }
Dale Johannesen545be512010-08-24 22:33:12 +00001349 return false;
Eli Friedman618234a2008-08-20 02:34:37 +00001350}
1351
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001352
Eli Friedman618234a2008-08-20 02:34:37 +00001353std::string
1354X86TargetInfo::convertConstraint(const char Constraint) const {
1355 switch (Constraint) {
1356 case 'a': return std::string("{ax}");
1357 case 'b': return std::string("{bx}");
1358 case 'c': return std::string("{cx}");
1359 case 'd': return std::string("{dx}");
1360 case 'S': return std::string("{si}");
1361 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00001362 case 'p': // address
1363 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00001364 case 't': // top of floating point stack.
1365 return std::string("{st}");
1366 case 'u': // second from top of floating point stack.
1367 return std::string("{st(1)}"); // second from top of floating point stack.
1368 default:
1369 return std::string(1, Constraint);
1370 }
1371}
Eli Friedman618234a2008-08-20 02:34:37 +00001372} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00001373
1374namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001375// X86-32 generic target
1376class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001377public:
Eli Friedman618234a2008-08-20 02:34:37 +00001378 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
1379 DoubleAlign = LongLongAlign = 32;
1380 LongDoubleWidth = 96;
1381 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001382 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1383 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001384 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +00001385 SizeType = UnsignedInt;
1386 PtrDiffType = SignedInt;
1387 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001388 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001389
1390 // Use fpret for all types.
1391 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
1392 (1 << TargetInfo::Double) |
1393 (1 << TargetInfo::LongDouble));
Eli Friedman618234a2008-08-20 02:34:37 +00001394 }
1395 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001396 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00001397 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001398
Chris Lattner21fb98e2009-09-23 06:06:36 +00001399 int getEHDataRegisterNumber(unsigned RegNo) const {
1400 if (RegNo == 0) return 0;
1401 if (RegNo == 1) return 2;
1402 return -1;
1403 }
Eli Friedman618234a2008-08-20 02:34:37 +00001404};
1405} // end anonymous namespace
1406
1407namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00001408class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
1409public:
1410 OpenBSDI386TargetInfo(const std::string& triple) :
1411 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
1412 SizeType = UnsignedLong;
1413 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00001414 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00001415 }
1416};
1417} // end anonymous namespace
1418
1419namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001420class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00001421public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00001422 DarwinI386TargetInfo(const std::string& triple) :
1423 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00001424 LongDoubleWidth = 128;
1425 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00001426 SizeType = UnsignedLong;
1427 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001428 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1429 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001430 "a0:0:64-f80:128:128-n8:16:32";
Daniel Dunbar613fd672010-05-27 00:35:16 +00001431 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00001432 }
1433
Eli Friedman618234a2008-08-20 02:34:37 +00001434};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001435} // end anonymous namespace
1436
1437namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00001438// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001439class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00001440public:
1441 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001442 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001443 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00001444 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00001445 DoubleAlign = LongLongAlign = 64;
1446 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 +00001447 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
1448 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +00001449 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001450 virtual void getTargetDefines(const LangOptions &Opts,
1451 MacroBuilder &Builder) const {
1452 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
1453 }
1454};
1455} // end anonymous namespace
1456
1457namespace {
1458
1459// x86-32 Windows Visual Studio target
1460class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1461public:
1462 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1463 : WindowsX86_32TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001464 LongDoubleWidth = LongDoubleAlign = 64;
Michael J. Spencera764e832010-10-21 08:22:51 +00001465 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
1466 }
1467 virtual void getTargetDefines(const LangOptions &Opts,
1468 MacroBuilder &Builder) const {
1469 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1470 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
1471 // The value of the following reflects processor type.
1472 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1473 // We lost the original triple, so we use the default.
1474 Builder.defineMacro("_M_IX86", "600");
1475 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001476};
1477} // end anonymous namespace
1478
1479namespace {
1480// x86-32 MinGW target
1481class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1482public:
1483 MinGWX86_32TargetInfo(const std::string& triple)
1484 : WindowsX86_32TargetInfo(triple) {
1485 }
1486 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001487 MacroBuilder &Builder) const {
1488 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001489 DefineStd(Builder, "WIN32", Opts);
1490 DefineStd(Builder, "WINNT", Opts);
1491 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00001492 Builder.defineMacro("__MSVCRT__");
1493 Builder.defineMacro("__MINGW32__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001494
1495 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1496 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1497 if (Opts.Microsoft)
1498 // Provide "as-is" __declspec.
1499 Builder.defineMacro("__declspec", "__declspec");
1500 else
1501 // Provide alias of __attribute__ like mingw32-gcc.
1502 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001503 }
1504};
1505} // end anonymous namespace
1506
1507namespace {
1508// x86-32 Cygwin target
1509class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1510public:
1511 CygwinX86_32TargetInfo(const std::string& triple)
1512 : X86_32TargetInfo(triple) {
1513 TLSSupported = false;
1514 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001515 DoubleAlign = LongLongAlign = 64;
1516 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1517 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001518 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001519 }
1520 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001521 MacroBuilder &Builder) const {
1522 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1523 Builder.defineMacro("__CYGWIN__");
1524 Builder.defineMacro("__CYGWIN32__");
1525 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00001526 if (Opts.CPlusPlus)
1527 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00001528 }
Eli Friedman29a30502008-08-21 01:40:19 +00001529};
1530} // end anonymous namespace
1531
1532namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00001533// x86-32 Haiku target
1534class HaikuX86_32TargetInfo : public X86_32TargetInfo {
1535public:
1536 HaikuX86_32TargetInfo(const std::string& triple)
1537 : X86_32TargetInfo(triple) {
1538 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00001539 IntPtrType = SignedLong;
1540 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00001541 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00001542 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00001543 virtual void getTargetDefines(const LangOptions &Opts,
1544 MacroBuilder &Builder) const {
1545 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1546 Builder.defineMacro("__INTEL__");
1547 Builder.defineMacro("__HAIKU__");
1548 }
1549};
1550} // end anonymous namespace
1551
1552namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001553// x86-64 generic target
1554class X86_64TargetInfo : public X86TargetInfo {
1555public:
Chris Lattner33328642009-03-20 15:52:06 +00001556 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001557 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001558 LongDoubleWidth = 128;
1559 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00001560 LargeArrayMinWidth = 128;
1561 LargeArrayAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001562 IntMaxType = SignedLong;
1563 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001564 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001565 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001566
Eli Friedmaned855cb2008-08-21 00:13:15 +00001567 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1568 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001569 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001570
1571 // Use fpret only for long double.
1572 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Reid Spencer5f016e22007-07-11 17:01:13 +00001573 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001574 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001575 return "typedef struct __va_list_tag {"
1576 " unsigned gp_offset;"
1577 " unsigned fp_offset;"
1578 " void* overflow_arg_area;"
1579 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00001580 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00001581 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001582 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001583
Chris Lattner21fb98e2009-09-23 06:06:36 +00001584 int getEHDataRegisterNumber(unsigned RegNo) const {
1585 if (RegNo == 0) return 0;
1586 if (RegNo == 1) return 1;
1587 return -1;
1588 }
Eli Friedman618234a2008-08-20 02:34:37 +00001589};
1590} // end anonymous namespace
1591
1592namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001593// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001594class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001595public:
1596 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001597 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001598 TLSSupported = false;
1599 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001600 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00001601 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00001602 IntMaxType = SignedLongLong;
1603 UIntMaxType = UnsignedLongLong;
1604 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00001605 SizeType = UnsignedLongLong;
1606 PtrDiffType = SignedLongLong;
1607 IntPtrType = SignedLongLong;
NAKAMURA Takumi8c959d92011-01-17 22:56:08 +00001608 this->UserLabelPrefix = "";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001609 }
1610 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001611 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001612 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001613 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00001614 }
NAKAMURA Takumi79521992011-01-17 22:56:23 +00001615 virtual const char *getVAListDeclaration() const {
1616 return "typedef char* __builtin_va_list;";
1617 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001618};
1619} // end anonymous namespace
1620
1621namespace {
1622// x86-64 Windows Visual Studio target
1623class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1624public:
1625 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1626 : WindowsX86_64TargetInfo(triple) {
Eli Friedmand9c3fa32011-03-22 21:25:11 +00001627 LongDoubleWidth = LongDoubleAlign = 64;
1628 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Michael J. Spencera764e832010-10-21 08:22:51 +00001629 }
1630 virtual void getTargetDefines(const LangOptions &Opts,
1631 MacroBuilder &Builder) const {
1632 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1633 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00001634 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001635 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001636 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001637};
1638} // end anonymous namespace
1639
1640namespace {
1641// x86-64 MinGW target
1642class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1643public:
1644 MinGWX86_64TargetInfo(const std::string& triple)
1645 : WindowsX86_64TargetInfo(triple) {
1646 }
1647 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001648 MacroBuilder &Builder) const {
1649 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001650 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00001651 Builder.defineMacro("__MSVCRT__");
NAKAMURA Takumi17c964a2011-03-08 12:06:46 +00001652 Builder.defineMacro("__MINGW32__");
Benjamin Kramera9992772010-01-09 17:55:51 +00001653 Builder.defineMacro("__MINGW64__");
NAKAMURA Takumi853134a2011-03-15 02:32:50 +00001654
1655 // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)).
1656 // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions.
1657 if (Opts.Microsoft)
1658 // Provide "as-is" __declspec.
1659 Builder.defineMacro("__declspec", "__declspec");
1660 else
1661 // Provide alias of __attribute__ like mingw32-gcc.
1662 Builder.defineMacro("__declspec(a)", "__attribute__((a))");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001663 }
1664};
1665} // end anonymous namespace
1666
1667namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001668class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1669public:
Mike Stump1eb44332009-09-09 15:08:12 +00001670 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001671 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1672 Int64Type = SignedLongLong;
1673 }
1674};
1675} // end anonymous namespace
1676
1677namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001678class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1679public:
Mike Stump1eb44332009-09-09 15:08:12 +00001680 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001681 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1682 IntMaxType = SignedLongLong;
1683 UIntMaxType = UnsignedLongLong;
1684 Int64Type = SignedLongLong;
1685 }
1686};
1687} // end anonymous namespace
1688
1689namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001690class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001691 // Possible FPU choices.
1692 enum FPUMode {
1693 NoFPU,
1694 VFP2FPU,
1695 VFP3FPU,
1696 NeonFPU
1697 };
1698
1699 static bool FPUModeIsVFP(FPUMode Mode) {
1700 return Mode >= VFP2FPU && Mode <= NeonFPU;
1701 }
1702
1703 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1704 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001705
Daniel Dunbareac7c532009-12-18 18:42:37 +00001706 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001707
1708 unsigned FPU : 3;
1709
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001710 unsigned IsThumb : 1;
1711
1712 // Initialized via features.
1713 unsigned SoftFloat : 1;
1714 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001715
Chris Lattner2752c012010-03-03 19:03:45 +00001716 static const Builtin::Info BuiltinInfo[];
1717
Chris Lattner393ff042008-04-21 18:56:49 +00001718public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001719 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001720 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001721 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001722 SizeType = UnsignedInt;
1723 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001724
Chris Lattner9bffb072010-04-23 16:29:58 +00001725 // {} in inline assembly are neon specifiers, not assembly variant
1726 // specifiers.
1727 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00001728
Daniel Dunbareac7c532009-12-18 18:42:37 +00001729 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001730 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001731 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001732 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1733 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001734 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1735 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001736 "v64:64:64-v128:64:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001737 } else {
1738 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1739 "i64:64:64-f32:32:32-f64:64:64-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001740 "v64:64:64-v128:64:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001741 }
John McCallee79a4c2010-08-21 22:46:04 +00001742
1743 // ARM targets default to using the ARM C++ ABI.
1744 CXXABI = CXXABI_ARM;
Eli Friedman61538a72008-05-20 14:21:01 +00001745 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001746 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001747 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001748 ABI = Name;
1749
Daniel Dunbara2a41612009-09-14 00:02:24 +00001750 // The defaults (above) are for AAPCS, check if we need to change them.
1751 //
1752 // FIXME: We need support for -meabi... we could just mangle it into the
1753 // name.
1754 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001755 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001756 SizeType = UnsignedLong;
1757
Daniel Dunbar684de632010-04-22 16:14:54 +00001758 // Do not respect the alignment of bit-field types when laying out
1759 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
1760 UseBitFieldTypeAlignment = false;
1761
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001762 if (IsThumb) {
Sandeep Patel3a41d142011-04-04 22:58:12 +00001763 // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
1764 // so set preferred for small types to 32.
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001765 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1766 "i64:32:32-f32:32:32-f64:32:32-"
Bob Wilsoncd5ce092011-04-04 16:53:11 +00001767 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001768 } else {
1769 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 +00001770 "i64:32:64-f32:32:32-f64:32:64-"
1771 "v64:32:64-v128:32:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001772 }
1773
Daniel Dunbara2a41612009-09-14 00:02:24 +00001774 // FIXME: Override "preferred align" for double and long long.
1775 } else if (Name == "aapcs") {
1776 // FIXME: Enumerated types are variable width in straight AAPCS.
1777 } else if (Name == "aapcs-linux") {
1778 ;
1779 } else
1780 return false;
1781
1782 return true;
1783 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001784
Daniel Dunbara91320b2009-12-21 23:28:17 +00001785 void getDefaultFeatures(const std::string &CPU,
1786 llvm::StringMap<bool> &Features) const {
1787 // FIXME: This should not be here.
1788 Features["vfp2"] = false;
1789 Features["vfp3"] = false;
1790 Features["neon"] = false;
1791
1792 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
1793 Features["vfp2"] = true;
1794 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
1795 Features["neon"] = true;
1796 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001797
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001798 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1799 const std::string &Name,
1800 bool Enabled) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001801 if (Name == "soft-float" || Name == "soft-float-abi") {
1802 Features[Name] = Enabled;
1803 } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") {
1804 // These effectively are a single option, reset them when any is enabled.
1805 if (Enabled)
1806 Features["vfp2"] = Features["vfp3"] = Features["neon"] = false;
1807 Features[Name] = Enabled;
1808 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001809 return false;
1810
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001811 return true;
1812 }
1813
1814 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001815 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001816 SoftFloat = SoftFloatABI = false;
1817 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
1818 if (Features[i] == "+soft-float")
1819 SoftFloat = true;
1820 else if (Features[i] == "+soft-float-abi")
1821 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001822 else if (Features[i] == "+vfp2")
1823 FPU = VFP2FPU;
1824 else if (Features[i] == "+vfp3")
1825 FPU = VFP3FPU;
1826 else if (Features[i] == "+neon")
1827 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001828 }
1829
1830 // Remove front-end specific options which the backend handles differently.
1831 std::vector<std::string>::iterator it;
1832 it = std::find(Features.begin(), Features.end(), "+soft-float");
1833 if (it != Features.end())
1834 Features.erase(it);
1835 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
1836 if (it != Features.end())
1837 Features.erase(it);
1838 }
1839
Daniel Dunbareac7c532009-12-18 18:42:37 +00001840 static const char *getCPUDefineSuffix(llvm::StringRef Name) {
1841 return llvm::StringSwitch<const char*>(Name)
1842 .Cases("arm8", "arm810", "4")
1843 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
1844 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
1845 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
1846 .Case("ep9312", "4T")
1847 .Cases("arm10tdmi", "arm1020t", "5T")
1848 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
1849 .Case("arm926ej-s", "5TEJ")
1850 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
1851 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001852 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001853 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001854 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001855 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
1856 .Cases("cortex-a8", "cortex-a9", "7A")
Bob Wilson06f45632011-01-06 16:57:20 +00001857 .Case("cortex-m3", "7M")
Bob Wilsona291d5f2011-03-21 21:55:25 +00001858 .Case("cortex-m0", "6M")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001859 .Default(0);
1860 }
1861 virtual bool setCPU(const std::string &Name) {
1862 if (!getCPUDefineSuffix(Name))
1863 return false;
1864
1865 CPU = Name;
1866 return true;
1867 }
Chris Lattner33328642009-03-20 15:52:06 +00001868 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001869 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001870 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00001871 Builder.defineMacro("__arm");
1872 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001873
Chris Lattnerc0f59212009-03-02 22:27:17 +00001874 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001875 Builder.defineMacro("__ARMEL__");
1876 Builder.defineMacro("__LITTLE_ENDIAN__");
1877 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001878
1879 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00001880 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001881
Mike Stump437bb4b2009-04-08 02:07:04 +00001882 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001883
Daniel Dunbareac7c532009-12-18 18:42:37 +00001884 // FIXME: It's more complicated than this and we don't really support
1885 // interworking.
1886 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00001887 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001888
Daniel Dunbareac7c532009-12-18 18:42:37 +00001889 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00001890 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001891
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001892 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00001893 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001894
1895 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00001896 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001897
Daniel Dunbara91320b2009-12-21 23:28:17 +00001898 bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7"));
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001899 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001900 Builder.defineMacro("__THUMBEL__");
1901 Builder.defineMacro("__thumb__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001902 if (IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001903 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001904 }
1905
1906 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00001907 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001908
1909 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00001910 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001911
1912 // This only gets set when Neon instructions are actually available, unlike
1913 // the VFP define, hence the soft float and arch check. This is subtly
1914 // different from gcc, we follow the intent which was that it should be set
1915 // when Neon instructions are actually available.
1916 if (FPU == NeonFPU && !SoftFloat && IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001917 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00001918 }
1919 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1920 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00001921 Records = BuiltinInfo;
1922 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00001923 }
1924 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001925 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001926 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001927 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001928 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001929 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001930 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001931 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001932 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001933 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001934 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001935 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001936 case 'l': // r0-r7
1937 case 'h': // r8-r15
1938 case 'w': // VFP Floating point register single precision
1939 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001940 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001941 return true;
1942 }
Chris Lattner393ff042008-04-21 18:56:49 +00001943 return false;
1944 }
1945 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001946 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001947 return "";
1948 }
1949};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001950
1951const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001952 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001953 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001954 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
1955
1956 // Float registers
1957 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
1958 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
1959 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001960 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001961
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001962 // Double registers
1963 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
1964 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00001965 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
1966 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001967
1968 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00001969 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
1970 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001971};
1972
1973void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001974 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001975 Names = GCCRegNames;
1976 NumNames = llvm::array_lengthof(GCCRegNames);
1977}
1978
1979const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001980 { { "a1" }, "r0" },
1981 { { "a2" }, "r1" },
1982 { { "a3" }, "r2" },
1983 { { "a4" }, "r3" },
1984 { { "v1" }, "r4" },
1985 { { "v2" }, "r5" },
1986 { { "v3" }, "r6" },
1987 { { "v4" }, "r7" },
1988 { { "v5" }, "r8" },
1989 { { "v6", "rfp" }, "r9" },
1990 { { "sl" }, "r10" },
1991 { { "fp" }, "r11" },
1992 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001993 { { "r13" }, "sp" },
1994 { { "r14" }, "lr" },
1995 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001996 // The S, D and Q registers overlap, but aren't really aliases; we
1997 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001998};
1999
2000void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2001 unsigned &NumAliases) const {
2002 Aliases = GCCRegAliases;
2003 NumAliases = llvm::array_lengthof(GCCRegAliases);
2004}
Chris Lattner2752c012010-03-03 19:03:45 +00002005
2006const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +00002007#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
2008#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
2009 ALL_LANGUAGES, false },
Chris Lattner2752c012010-03-03 19:03:45 +00002010#include "clang/Basic/BuiltinsARM.def"
2011};
Chris Lattner393ff042008-04-21 18:56:49 +00002012} // end anonymous namespace.
2013
Eli Friedmana9f54962008-08-20 07:44:10 +00002014
2015namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00002016class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002017 public DarwinTargetInfo<ARMTargetInfo> {
2018protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002019 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00002020 MacroBuilder &Builder) const {
Douglas Gregor0a0d2b12011-03-23 00:50:03 +00002021 getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
Eli Friedmanb030f022009-04-19 21:38:35 +00002022 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002023
Torok Edwin5f6c1942009-06-30 17:10:35 +00002024public:
Mike Stump1eb44332009-09-09 15:08:12 +00002025 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00002026 : DarwinTargetInfo<ARMTargetInfo>(triple) {
2027 HasAlignMac68kSupport = true;
2028 }
Eli Friedmana9f54962008-08-20 07:44:10 +00002029};
2030} // end anonymous namespace.
2031
Reid Spencer5f016e22007-07-11 17:01:13 +00002032namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00002033class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00002034 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2035 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002036 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00002037public:
Eli Friedman01b86682008-08-20 07:28:14 +00002038 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
2039 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00002040 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 +00002041 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00002042 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002043 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
2044 const std::string &Name,
2045 bool Enabled) const {
2046 if (Name == "soft-float")
2047 Features[Name] = Enabled;
2048 else
2049 return false;
2050
2051 return true;
2052 }
2053 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
2054 SoftFloat = false;
2055 for (unsigned i = 0, e = Features.size(); i != e; ++i)
2056 if (Features[i] == "+soft-float")
2057 SoftFloat = true;
2058 }
Chris Lattner33328642009-03-20 15:52:06 +00002059 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002060 MacroBuilder &Builder) const {
2061 DefineStd(Builder, "sparc", Opts);
2062 Builder.defineMacro("__sparcv8");
2063 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002064
2065 if (SoftFloat)
2066 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00002067 }
2068 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2069 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002070 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00002071 }
2072 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002073 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00002074 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002075 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002076 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002077 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002078 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002079 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00002080 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002081 // FIXME: Implement!
2082 return false;
Gabor Greif26658672008-02-21 16:29:08 +00002083 }
2084 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002085 // FIXME: Implement!
2086 return "";
Gabor Greif26658672008-02-21 16:29:08 +00002087 }
2088};
2089
Chris Lattnere957f532009-01-27 01:58:38 +00002090const char * const SparcV8TargetInfo::GCCRegNames[] = {
2091 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2092 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2093 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2094 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
2095};
2096
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002097void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002098 unsigned &NumNames) const {
2099 Names = GCCRegNames;
2100 NumNames = llvm::array_lengthof(GCCRegNames);
2101}
2102
2103const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002104 { { "g0" }, "r0" },
2105 { { "g1" }, "r1" },
2106 { { "g2" }, "r2" },
2107 { { "g3" }, "r3" },
2108 { { "g4" }, "r4" },
2109 { { "g5" }, "r5" },
2110 { { "g6" }, "r6" },
2111 { { "g7" }, "r7" },
2112 { { "o0" }, "r8" },
2113 { { "o1" }, "r9" },
2114 { { "o2" }, "r10" },
2115 { { "o3" }, "r11" },
2116 { { "o4" }, "r12" },
2117 { { "o5" }, "r13" },
2118 { { "o6", "sp" }, "r14" },
2119 { { "o7" }, "r15" },
2120 { { "l0" }, "r16" },
2121 { { "l1" }, "r17" },
2122 { { "l2" }, "r18" },
2123 { { "l3" }, "r19" },
2124 { { "l4" }, "r20" },
2125 { { "l5" }, "r21" },
2126 { { "l6" }, "r22" },
2127 { { "l7" }, "r23" },
2128 { { "i0" }, "r24" },
2129 { { "i1" }, "r25" },
2130 { { "i2" }, "r26" },
2131 { { "i3" }, "r27" },
2132 { { "i4" }, "r28" },
2133 { { "i5" }, "r29" },
2134 { { "i6", "fp" }, "r30" },
2135 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00002136};
2137
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002138void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002139 unsigned &NumAliases) const {
2140 Aliases = GCCRegAliases;
2141 NumAliases = llvm::array_lengthof(GCCRegAliases);
2142}
Gabor Greif26658672008-02-21 16:29:08 +00002143} // end anonymous namespace.
2144
Eli Friedman01b86682008-08-20 07:28:14 +00002145namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002146class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
2147public:
2148 AuroraUXSparcV8TargetInfo(const std::string& triple) :
2149 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
2150 SizeType = UnsignedInt;
2151 PtrDiffType = SignedInt;
2152 }
2153};
Torok Edwin5f6c1942009-06-30 17:10:35 +00002154class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00002155public:
2156 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002157 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00002158 SizeType = UnsignedInt;
2159 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00002160 }
2161};
2162} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00002163
Chris Lattner2621fd12008-05-08 05:58:21 +00002164namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002165 class MSP430TargetInfo : public TargetInfo {
2166 static const char * const GCCRegNames[];
2167 public:
2168 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
2169 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00002170 IntWidth = 16; IntAlign = 16;
2171 LongWidth = 32; LongLongWidth = 64;
2172 LongAlign = LongLongAlign = 16;
2173 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002174 SizeType = UnsignedInt;
2175 IntMaxType = SignedLong;
2176 UIntMaxType = UnsignedLong;
2177 IntPtrType = SignedShort;
2178 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00002179 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00002180 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002181 }
2182 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002183 MacroBuilder &Builder) const {
2184 Builder.defineMacro("MSP430");
2185 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002186 // FIXME: defines for different 'flavours' of MCU
2187 }
2188 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2189 unsigned &NumRecords) const {
2190 // FIXME: Implement.
2191 Records = 0;
2192 NumRecords = 0;
2193 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002194 virtual void getGCCRegNames(const char * const *&Names,
2195 unsigned &NumNames) const;
2196 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2197 unsigned &NumAliases) const {
2198 // No aliases.
2199 Aliases = 0;
2200 NumAliases = 0;
2201 }
2202 virtual bool validateAsmConstraint(const char *&Name,
2203 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00002204 // No target constraints for now.
2205 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002206 }
2207 virtual const char *getClobbers() const {
2208 // FIXME: Is this really right?
2209 return "";
2210 }
2211 virtual const char *getVAListDeclaration() const {
2212 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00002213 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002214 }
2215 };
2216
2217 const char * const MSP430TargetInfo::GCCRegNames[] = {
2218 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2219 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2220 };
2221
2222 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
2223 unsigned &NumNames) const {
2224 Names = GCCRegNames;
2225 NumNames = llvm::array_lengthof(GCCRegNames);
2226 }
2227}
2228
2229
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002230namespace {
2231 class SystemZTargetInfo : public TargetInfo {
2232 static const char * const GCCRegNames[];
2233 public:
2234 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
2235 TLSSupported = false;
2236 IntWidth = IntAlign = 32;
2237 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
2238 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00002239 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
2240 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002241 }
2242 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002243 MacroBuilder &Builder) const {
2244 Builder.defineMacro("__s390__");
2245 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002246 }
2247 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2248 unsigned &NumRecords) const {
2249 // FIXME: Implement.
2250 Records = 0;
2251 NumRecords = 0;
2252 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002253
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002254 virtual void getGCCRegNames(const char * const *&Names,
2255 unsigned &NumNames) const;
2256 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2257 unsigned &NumAliases) const {
2258 // No aliases.
2259 Aliases = 0;
2260 NumAliases = 0;
2261 }
2262 virtual bool validateAsmConstraint(const char *&Name,
2263 TargetInfo::ConstraintInfo &info) const {
2264 // FIXME: implement
2265 return true;
2266 }
2267 virtual const char *getClobbers() const {
2268 // FIXME: Is this really right?
2269 return "";
2270 }
2271 virtual const char *getVAListDeclaration() const {
2272 // FIXME: implement
2273 return "typedef char* __builtin_va_list;";
2274 }
2275 };
2276
2277 const char * const SystemZTargetInfo::GCCRegNames[] = {
2278 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2279 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2280 };
2281
2282 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
2283 unsigned &NumNames) const {
2284 Names = GCCRegNames;
2285 NumNames = llvm::array_lengthof(GCCRegNames);
2286 }
2287}
2288
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002289namespace {
2290 class BlackfinTargetInfo : public TargetInfo {
2291 static const char * const GCCRegNames[];
2292 public:
2293 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
2294 TLSSupported = false;
2295 DoubleAlign = 32;
2296 LongLongAlign = 32;
2297 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00002298 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002299 }
2300
2301 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002302 MacroBuilder &Builder) const {
2303 DefineStd(Builder, "bfin", Opts);
2304 DefineStd(Builder, "BFIN", Opts);
2305 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002306 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00002307 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002308 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
2309 }
2310
2311 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2312 unsigned &NumRecords) const {
2313 // FIXME: Implement.
2314 Records = 0;
2315 NumRecords = 0;
2316 }
2317
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002318 virtual void getGCCRegNames(const char * const *&Names,
2319 unsigned &NumNames) const;
2320
2321 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2322 unsigned &NumAliases) const {
2323 // No aliases.
2324 Aliases = 0;
2325 NumAliases = 0;
2326 }
2327
2328 virtual bool validateAsmConstraint(const char *&Name,
2329 TargetInfo::ConstraintInfo &Info) const {
2330 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
2331 Info.setAllowsRegister();
2332 return true;
2333 }
2334 return false;
2335 }
2336
2337 virtual const char *getClobbers() const {
2338 return "";
2339 }
2340
2341 virtual const char *getVAListDeclaration() const {
2342 return "typedef char* __builtin_va_list;";
2343 }
2344 };
2345
2346 const char * const BlackfinTargetInfo::GCCRegNames[] = {
2347 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2348 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
2349 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
2350 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
2351 "a0", "a1", "cc",
2352 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
2353 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
2354 };
2355
2356 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
2357 unsigned &NumNames) const {
2358 Names = GCCRegNames;
2359 NumNames = llvm::array_lengthof(GCCRegNames);
2360 }
2361}
2362
Eli Friedmanb63decf2009-08-19 20:47:07 +00002363namespace {
2364
Mike Stump1eb44332009-09-09 15:08:12 +00002365 // LLVM and Clang cannot be used directly to output native binaries for
2366 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00002367 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00002368 //
2369 // TCE uses the llvm bitcode as input and uses it for generating customized
2370 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00002371 // publicly available in http://tce.cs.tut.fi
2372
2373 class TCETargetInfo : public TargetInfo{
2374 public:
2375 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
2376 TLSSupported = false;
2377 IntWidth = 32;
2378 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00002379 PointerWidth = 32;
2380 IntAlign = 32;
2381 LongAlign = LongLongAlign = 32;
2382 PointerAlign = 32;
2383 SizeType = UnsignedInt;
2384 IntMaxType = SignedLong;
2385 UIntMaxType = UnsignedLong;
2386 IntPtrType = SignedInt;
2387 PtrDiffType = SignedInt;
2388 FloatWidth = 32;
2389 FloatAlign = 32;
2390 DoubleWidth = 32;
2391 DoubleAlign = 32;
2392 LongDoubleWidth = 32;
2393 LongDoubleAlign = 32;
2394 FloatFormat = &llvm::APFloat::IEEEsingle;
2395 DoubleFormat = &llvm::APFloat::IEEEsingle;
2396 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00002397 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
2398 "i16:16:32-i32:32:32-i64:32:32-"
NAKAMURA Takumic9109292011-02-18 08:44:38 +00002399 "f32:32:32-f64:32:32-v64:32:32-"
2400 "v128:32:32-a0:0:32-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00002401 }
2402
2403 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002404 MacroBuilder &Builder) const {
2405 DefineStd(Builder, "tce", Opts);
2406 Builder.defineMacro("__TCE__");
2407 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00002408 }
2409 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2410 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00002411 virtual const char *getClobbers() const {
2412 return "";
2413 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002414 virtual const char *getVAListDeclaration() const {
2415 return "typedef void* __builtin_va_list;";
2416 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002417 virtual void getGCCRegNames(const char * const *&Names,
2418 unsigned &NumNames) const {}
2419 virtual bool validateAsmConstraint(const char *&Name,
2420 TargetInfo::ConstraintInfo &info) const {
2421 return true;
2422 }
2423 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2424 unsigned &NumAliases) const {}
2425 };
2426}
2427
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002428namespace {
2429class MipsTargetInfo : public TargetInfo {
Eric Christophered734732010-03-02 02:41:08 +00002430 std::string ABI, CPU;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002431 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2432 static const char * const GCCRegNames[];
2433public:
Eric Christophered734732010-03-02 02:41:08 +00002434 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002435 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2436 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2437 }
Eric Christophered734732010-03-02 02:41:08 +00002438 virtual const char *getABI() const { return ABI.c_str(); }
2439 virtual bool setABI(const std::string &Name) {
2440
2441 if ((Name == "o32") || (Name == "eabi")) {
2442 ABI = Name;
2443 return true;
2444 } else
2445 return false;
2446 }
2447 virtual bool setCPU(const std::string &Name) {
2448 CPU = Name;
2449 return true;
2450 }
2451 void getDefaultFeatures(const std::string &CPU,
2452 llvm::StringMap<bool> &Features) const {
2453 Features[ABI] = true;
2454 Features[CPU] = true;
2455 }
2456 virtual void getArchDefines(const LangOptions &Opts,
2457 MacroBuilder &Builder) const {
2458 if (ABI == "o32")
2459 Builder.defineMacro("__mips_o32");
2460 else if (ABI == "eabi")
2461 Builder.defineMacro("__mips_eabi");
2462 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002463 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002464 MacroBuilder &Builder) const {
2465 DefineStd(Builder, "mips", Opts);
2466 Builder.defineMacro("_mips");
2467 DefineStd(Builder, "MIPSEB", Opts);
2468 Builder.defineMacro("_MIPSEB");
2469 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002470 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002471 }
2472 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2473 unsigned &NumRecords) const {
2474 // FIXME: Implement!
2475 }
2476 virtual const char *getVAListDeclaration() const {
2477 return "typedef void* __builtin_va_list;";
2478 }
2479 virtual void getGCCRegNames(const char * const *&Names,
2480 unsigned &NumNames) const;
2481 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2482 unsigned &NumAliases) const;
2483 virtual bool validateAsmConstraint(const char *&Name,
2484 TargetInfo::ConstraintInfo &Info) const {
2485 switch (*Name) {
2486 default:
2487 case 'r': // CPU registers.
2488 case 'd': // Equivalent to "r" unless generating MIPS16 code.
2489 case 'y': // Equivalent to "r", backwards compatibility only.
2490 case 'f': // floating-point registers.
2491 Info.setAllowsRegister();
2492 return true;
2493 }
2494 return false;
2495 }
2496
2497 virtual const char *getClobbers() const {
2498 // FIXME: Implement!
2499 return "";
2500 }
2501};
2502
2503const char * const MipsTargetInfo::GCCRegNames[] = {
Michael J. Spencer20249a12010-10-21 03:16:25 +00002504 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002505 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2506 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
2507 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
2508 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
2509 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
2510 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
2511 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
2512 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
2513 "$fcc5","$fcc6","$fcc7"
2514};
2515
2516void MipsTargetInfo::getGCCRegNames(const char * const *&Names,
2517 unsigned &NumNames) const {
2518 Names = GCCRegNames;
2519 NumNames = llvm::array_lengthof(GCCRegNames);
2520}
2521
2522const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = {
2523 { { "at" }, "$1" },
2524 { { "v0" }, "$2" },
2525 { { "v1" }, "$3" },
2526 { { "a0" }, "$4" },
2527 { { "a1" }, "$5" },
2528 { { "a2" }, "$6" },
2529 { { "a3" }, "$7" },
2530 { { "t0" }, "$8" },
2531 { { "t1" }, "$9" },
2532 { { "t2" }, "$10" },
2533 { { "t3" }, "$11" },
2534 { { "t4" }, "$12" },
2535 { { "t5" }, "$13" },
2536 { { "t6" }, "$14" },
2537 { { "t7" }, "$15" },
2538 { { "s0" }, "$16" },
2539 { { "s1" }, "$17" },
2540 { { "s2" }, "$18" },
2541 { { "s3" }, "$19" },
2542 { { "s4" }, "$20" },
2543 { { "s5" }, "$21" },
2544 { { "s6" }, "$22" },
2545 { { "s7" }, "$23" },
2546 { { "t8" }, "$24" },
2547 { { "t9" }, "$25" },
2548 { { "k0" }, "$26" },
2549 { { "k1" }, "$27" },
2550 { { "gp" }, "$28" },
2551 { { "sp" }, "$29" },
2552 { { "fp" }, "$30" },
2553 { { "ra" }, "$31" }
2554};
2555
2556void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2557 unsigned &NumAliases) const {
2558 Aliases = GCCRegAliases;
2559 NumAliases = llvm::array_lengthof(GCCRegAliases);
2560}
2561} // end anonymous namespace.
2562
2563namespace {
2564class MipselTargetInfo : public MipsTargetInfo {
2565public:
2566 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) {
2567 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2568 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2569 }
2570
2571 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002572 MacroBuilder &Builder) const;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002573};
2574
2575void MipselTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002576 MacroBuilder &Builder) const {
2577 DefineStd(Builder, "mips", Opts);
2578 Builder.defineMacro("_mips");
2579 DefineStd(Builder, "MIPSEL", Opts);
2580 Builder.defineMacro("_MIPSEL");
2581 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002582 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002583}
2584} // end anonymous namespace.
2585
Reid Spencer5f016e22007-07-11 17:01:13 +00002586//===----------------------------------------------------------------------===//
2587// Driver code
2588//===----------------------------------------------------------------------===//
2589
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002590static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002591 llvm::Triple Triple(T);
2592 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00002593
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002594 switch (Triple.getArch()) {
2595 default:
2596 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00002597
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002598 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00002599 case llvm::Triple::thumb:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002600 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00002601 case llvm::Triple::Linux:
2602 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002603 case llvm::Triple::Darwin:
Eli Friedmaned855cb2008-08-21 00:13:15 +00002604 return new DarwinARMTargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002605 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002606 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002607 default:
2608 return new ARMTargetInfo(T);
2609 }
Eli Friedman61538a72008-05-20 14:21:01 +00002610
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002611 case llvm::Triple::bfin:
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002612 return new BlackfinTargetInfo(T);
2613
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002614 case llvm::Triple::msp430:
2615 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00002616
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002617 case llvm::Triple::mips:
2618 if (os == llvm::Triple::Psp)
2619 return new PSPTargetInfo<MipsTargetInfo>(T);
2620 if (os == llvm::Triple::Linux)
2621 return new LinuxTargetInfo<MipsTargetInfo>(T);
2622 return new MipsTargetInfo(T);
2623
2624 case llvm::Triple::mipsel:
2625 if (os == llvm::Triple::Psp)
2626 return new PSPTargetInfo<MipselTargetInfo>(T);
2627 if (os == llvm::Triple::Linux)
2628 return new LinuxTargetInfo<MipselTargetInfo>(T);
2629 return new MipselTargetInfo(T);
2630
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002631 case llvm::Triple::ppc:
2632 if (os == llvm::Triple::Darwin)
Roman Divackyc81f2a22011-01-06 08:27:10 +00002633 return new DarwinPPC32TargetInfo(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002634 else if (os == llvm::Triple::FreeBSD)
2635 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002636 return new PPC32TargetInfo(T);
2637
2638 case llvm::Triple::ppc64:
2639 if (os == llvm::Triple::Darwin)
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00002640 return new DarwinPPC64TargetInfo(T);
John Thompson3f6918a2009-11-19 17:18:50 +00002641 else if (os == llvm::Triple::Lv2)
2642 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002643 else if (os == llvm::Triple::FreeBSD)
2644 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002645 return new PPC64TargetInfo(T);
2646
Chris Lattner9cbeb632010-03-06 21:21:27 +00002647 case llvm::Triple::mblaze:
2648 return new MBlazeTargetInfo(T);
2649
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002650 case llvm::Triple::sparc:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002651 if (os == llvm::Triple::AuroraUX)
2652 return new AuroraUXSparcV8TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002653 if (os == llvm::Triple::Solaris)
2654 return new SolarisSparcV8TargetInfo(T);
2655 return new SparcV8TargetInfo(T);
2656
John Thompson3f6918a2009-11-19 17:18:50 +00002657 // FIXME: Need a real SPU target.
2658 case llvm::Triple::cellspu:
2659 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
2660
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002661 case llvm::Triple::systemz:
2662 return new SystemZTargetInfo(T);
2663
Eli Friedmanb63decf2009-08-19 20:47:07 +00002664 case llvm::Triple::tce:
2665 return new TCETargetInfo(T);
2666
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002667 case llvm::Triple::x86:
2668 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002669 case llvm::Triple::AuroraUX:
2670 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002671 case llvm::Triple::Darwin:
2672 return new DarwinI386TargetInfo(T);
2673 case llvm::Triple::Linux:
2674 return new LinuxTargetInfo<X86_32TargetInfo>(T);
2675 case llvm::Triple::DragonFly:
2676 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
2677 case llvm::Triple::NetBSD:
2678 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
2679 case llvm::Triple::OpenBSD:
2680 return new OpenBSDI386TargetInfo(T);
2681 case llvm::Triple::FreeBSD:
2682 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00002683 case llvm::Triple::Minix:
2684 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002685 case llvm::Triple::Solaris:
2686 return new SolarisTargetInfo<X86_32TargetInfo>(T);
2687 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002688 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002689 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002690 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002691 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00002692 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00002693 case llvm::Triple::Haiku:
2694 return new HaikuX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002695 default:
2696 return new X86_32TargetInfo(T);
2697 }
2698
2699 case llvm::Triple::x86_64:
2700 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002701 case llvm::Triple::AuroraUX:
2702 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002703 case llvm::Triple::Darwin:
2704 return new DarwinX86_64TargetInfo(T);
2705 case llvm::Triple::Linux:
2706 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00002707 case llvm::Triple::DragonFly:
2708 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002709 case llvm::Triple::NetBSD:
2710 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
2711 case llvm::Triple::OpenBSD:
2712 return new OpenBSDX86_64TargetInfo(T);
2713 case llvm::Triple::FreeBSD:
2714 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
2715 case llvm::Triple::Solaris:
2716 return new SolarisTargetInfo<X86_64TargetInfo>(T);
NAKAMURA Takumi0aa20572011-02-17 08:51:38 +00002717 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002718 return new MinGWX86_64TargetInfo(T);
2719 case llvm::Triple::Win32: // This is what Triple.h supports now.
Douglas Gregorfb7049a2011-02-01 15:06:18 +00002720 if (Triple.getEnvironment() == llvm::Triple::MachO)
2721 return new DarwinX86_64TargetInfo(T);
2722 else
2723 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002724 default:
2725 return new X86_64TargetInfo(T);
2726 }
2727 }
Reid Spencer5f016e22007-07-11 17:01:13 +00002728}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002729
2730/// CreateTargetInfo - Return the target info object for the specified target
2731/// triple.
2732TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002733 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002734 llvm::Triple Triple(Opts.Triple);
2735
2736 // Construct the target
2737 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
2738 if (!Target) {
2739 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
2740 return 0;
2741 }
2742
Daniel Dunbareac7c532009-12-18 18:42:37 +00002743 // Set the target CPU if specified.
2744 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
2745 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
2746 return 0;
2747 }
2748
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002749 // Set the target ABI if specified.
2750 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
2751 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
2752 return 0;
2753 }
2754
Charles Davis98b7c5c2010-06-11 01:06:47 +00002755 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00002756 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00002757 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
2758 return 0;
2759 }
2760
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002761 // Compute the default target features, we need the target to handle this
2762 // because features may have dependencies on one another.
2763 llvm::StringMap<bool> Features;
2764 Target->getDefaultFeatures(Opts.CPU, Features);
2765
2766 // Apply the user specified deltas.
2767 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
2768 ie = Opts.Features.end(); it != ie; ++it) {
2769 const char *Name = it->c_str();
2770
2771 // Apply the feature via the target.
2772 if ((Name[0] != '-' && Name[0] != '+') ||
2773 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
2774 Diags.Report(diag::err_target_invalid_feature) << Name;
2775 return 0;
2776 }
2777 }
2778
2779 // Add the features to the compile options.
2780 //
2781 // FIXME: If we are completely confident that we have the right set, we only
2782 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002783 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002784 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
2785 ie = Features.end(); it != ie; ++it)
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002786 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
2787 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002788
2789 return Target.take();
2790}