blob: 45e5db7500ded65e51cd8b8d4db4cf0f2aa8b121 [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,
79 const llvm::Triple &Triple) {
Benjamin Kramera9992772010-01-09 17:55:51 +000080 Builder.defineMacro("__APPLE_CC__", "5621");
81 Builder.defineMacro("__APPLE__");
82 Builder.defineMacro("__MACH__");
83 Builder.defineMacro("OBJC_NEW_PROPERTIES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000084
Chris Lattner10d24272009-04-07 16:50:40 +000085 // __weak is always defined, for use in blocks and with objc pointers.
Benjamin Kramera9992772010-01-09 17:55:51 +000086 Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
Anton Korobeynikova7c47172009-05-03 13:42:53 +000087
Chris Lattner10d24272009-04-07 16:50:40 +000088 // Darwin defines __strong even in C mode (just to nothing).
89 if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC)
Benjamin Kramera9992772010-01-09 17:55:51 +000090 Builder.defineMacro("__strong", "");
Chris Lattner10d24272009-04-07 16:50:40 +000091 else
Benjamin Kramera9992772010-01-09 17:55:51 +000092 Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
Eli Friedman2de4fee2009-06-04 23:00:29 +000093
94 if (Opts.Static)
Benjamin Kramera9992772010-01-09 17:55:51 +000095 Builder.defineMacro("__STATIC__");
Eli Friedman2de4fee2009-06-04 23:00:29 +000096 else
Benjamin Kramera9992772010-01-09 17:55:51 +000097 Builder.defineMacro("__DYNAMIC__");
Daniel Dunbar5345c392009-09-03 04:54:28 +000098
99 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000100 Builder.defineMacro("_REENTRANT");
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000101
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000102 // Get the OS version number from the triple.
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000103 unsigned Maj, Min, Rev;
Mike Stump1eb44332009-09-09 15:08:12 +0000104
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000105 // If no version was given, default to to 10.4.0, for simplifying tests.
106 if (Triple.getOSName() == "darwin") {
107 Min = Rev = 0;
108 Maj = 8;
109 } else
110 Triple.getDarwinNumber(Maj, Min, Rev);
111
112 // Set the appropriate OS version define.
113 if (Triple.getEnvironmentName() == "iphoneos") {
114 assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!");
115 char Str[6];
116 Str[0] = '0' + Maj;
117 Str[1] = '0' + (Min / 10);
118 Str[2] = '0' + (Min % 10);
119 Str[3] = '0' + (Rev / 10);
120 Str[4] = '0' + (Rev % 10);
121 Str[5] = '\0';
122 Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
123 } else {
124 // For historical reasons that make little sense, the version passed here is
125 // the "darwin" version, which drops the 10 and offsets by 4.
126 Rev = Min;
127 Min = Maj - 4;
128 Maj = 10;
129
130 assert(Triple.getEnvironmentName().empty() && "Invalid environment!");
131 assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!");
132 char Str[5];
133 Str[0] = '0' + (Maj / 10);
134 Str[1] = '0' + (Maj % 10);
135 Str[2] = '0' + Min;
136 Str[3] = '0' + Rev;
137 Str[4] = '\0';
138 Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
Daniel Dunbar8d33cd72009-04-10 19:52:24 +0000139 }
Eli Friedman618234a2008-08-20 02:34:37 +0000140}
Reid Spencer5f016e22007-07-11 17:01:13 +0000141
Chris Lattner797c3c42009-08-10 19:03:04 +0000142namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000143template<typename Target>
144class DarwinTargetInfo : public OSTargetInfo<Target> {
145protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000146 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000147 MacroBuilder &Builder) const {
Daniel Dunbar21ae3192010-01-26 01:44:04 +0000148 getDarwinDefines(Builder, Opts, Triple);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000149 }
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Torok Edwin5f6c1942009-06-30 17:10:35 +0000151public:
152 DarwinTargetInfo(const std::string& triple) :
153 OSTargetInfo<Target>(triple) {
Eric Christopherdd53ec92010-06-25 19:04:52 +0000154 this->TLSSupported = llvm::Triple(triple).getDarwinMajorNumber() > 10;
Torok Edwin5f6c1942009-06-30 17:10:35 +0000155 }
156
Anders Carlssonf959fb52010-01-30 18:33:31 +0000157 virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const {
Chris Lattner797c3c42009-08-10 19:03:04 +0000158 // Let MCSectionMachO validate this.
159 llvm::StringRef Segment, Section;
160 unsigned TAA, StubSize;
161 return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
162 TAA, StubSize);
163 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000164
Anders Carlsson18af3682010-06-08 22:47:50 +0000165 virtual const char *getStaticInitSectionSpecifier() const {
166 // FIXME: We should return 0 when building kexts.
167 return "__TEXT,__StaticInit,regular,pure_instructions";
168 }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000169
Torok Edwin5f6c1942009-06-30 17:10:35 +0000170};
171
Chris Lattner797c3c42009-08-10 19:03:04 +0000172
Torok Edwin5f6c1942009-06-30 17:10:35 +0000173// DragonFlyBSD Target
174template<typename Target>
175class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
176protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000177 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000178 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000179 // DragonFly defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000180 Builder.defineMacro("__DragonFly__");
181 Builder.defineMacro("__DragonFly_cc_version", "100001");
182 Builder.defineMacro("__ELF__");
183 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
184 Builder.defineMacro("__tune_i386__");
185 DefineStd(Builder, "unix", Opts);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000186 }
187public:
Mike Stump1eb44332009-09-09 15:08:12 +0000188 DragonFlyBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000189 : OSTargetInfo<Target>(triple) {}
190};
191
192// FreeBSD Target
193template<typename Target>
194class FreeBSDTargetInfo : public OSTargetInfo<Target> {
195protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000196 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000197 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000198 // FreeBSD defines; list based off of gcc output
199
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000200 // FIXME: Move version number handling to llvm::Triple.
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000201 llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1);
Torok Edwin5f6c1942009-06-30 17:10:35 +0000202
Benjamin Kramer3bb65302010-01-30 19:55:01 +0000203 Builder.defineMacro("__FreeBSD__", Release);
204 Builder.defineMacro("__FreeBSD_cc_version", Release + "00001");
Benjamin Kramera9992772010-01-09 17:55:51 +0000205 Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
206 DefineStd(Builder, "unix", Opts);
207 Builder.defineMacro("__ELF__");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000208 }
209public:
Mike Stump1eb44332009-09-09 15:08:12 +0000210 FreeBSDTargetInfo(const std::string &triple)
Duncan Sands1e90faf2009-07-08 13:55:08 +0000211 : OSTargetInfo<Target>(triple) {
212 this->UserLabelPrefix = "";
213 }
Torok Edwin5f6c1942009-06-30 17:10:35 +0000214};
215
Chris Lattner38e317d2010-07-07 16:01:42 +0000216// Minix Target
217template<typename Target>
218class MinixTargetInfo : public OSTargetInfo<Target> {
219protected:
220 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
221 MacroBuilder &Builder) const {
222 // Minix defines
223
224 Builder.defineMacro("__minix", "3");
225 Builder.defineMacro("_EM_WSIZE", "4");
226 Builder.defineMacro("_EM_PSIZE", "4");
227 Builder.defineMacro("_EM_SSIZE", "2");
228 Builder.defineMacro("_EM_LSIZE", "4");
229 Builder.defineMacro("_EM_FSIZE", "4");
230 Builder.defineMacro("_EM_DSIZE", "8");
231 DefineStd(Builder, "unix", Opts);
232 }
233public:
234 MinixTargetInfo(const std::string &triple)
235 : OSTargetInfo<Target>(triple) {
236 this->UserLabelPrefix = "";
237 }
238};
239
Torok Edwin5f6c1942009-06-30 17:10:35 +0000240// Linux target
241template<typename Target>
242class LinuxTargetInfo : public OSTargetInfo<Target> {
243protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000244 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000245 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000246 // Linux defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000247 DefineStd(Builder, "unix", Opts);
248 DefineStd(Builder, "linux", Opts);
249 Builder.defineMacro("__gnu_linux__");
250 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000251 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000252 Builder.defineMacro("_REENTRANT");
Douglas Gregor2b003fd2010-04-21 05:52:38 +0000253 if (Opts.CPlusPlus)
254 Builder.defineMacro("_GNU_SOURCE");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000255 }
256public:
Mike Stump1eb44332009-09-09 15:08:12 +0000257 LinuxTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000258 : OSTargetInfo<Target>(triple) {
259 this->UserLabelPrefix = "";
260 }
261};
262
Chris Lattnerb62bb282009-07-13 20:29:08 +0000263// NetBSD Target
264template<typename Target>
265class NetBSDTargetInfo : public OSTargetInfo<Target> {
266protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000267 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000268 MacroBuilder &Builder) const {
Chris Lattnerb62bb282009-07-13 20:29:08 +0000269 // NetBSD defines; list based off of gcc output
Benjamin Kramera9992772010-01-09 17:55:51 +0000270 Builder.defineMacro("__NetBSD__");
271 Builder.defineMacro("__unix__");
272 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000273 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000274 Builder.defineMacro("_POSIX_THREADS");
Chris Lattnerb62bb282009-07-13 20:29:08 +0000275 }
276public:
Mike Stump1eb44332009-09-09 15:08:12 +0000277 NetBSDTargetInfo(const std::string &triple)
Chris Lattnerb62bb282009-07-13 20:29:08 +0000278 : OSTargetInfo<Target>(triple) {
279 this->UserLabelPrefix = "";
280 }
281};
282
Torok Edwin5f6c1942009-06-30 17:10:35 +0000283// OpenBSD Target
284template<typename Target>
285class OpenBSDTargetInfo : public OSTargetInfo<Target> {
286protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000287 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000288 MacroBuilder &Builder) const {
Torok Edwin5f6c1942009-06-30 17:10:35 +0000289 // OpenBSD defines; list based off of gcc output
290
Benjamin Kramera9992772010-01-09 17:55:51 +0000291 Builder.defineMacro("__OpenBSD__");
292 DefineStd(Builder, "unix", Opts);
293 Builder.defineMacro("__ELF__");
Daniel Dunbar5345c392009-09-03 04:54:28 +0000294 if (Opts.POSIXThreads)
Benjamin Kramera9992772010-01-09 17:55:51 +0000295 Builder.defineMacro("_POSIX_THREADS");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000296 }
297public:
Mike Stump1eb44332009-09-09 15:08:12 +0000298 OpenBSDTargetInfo(const std::string &triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000299 : OSTargetInfo<Target>(triple) {}
300};
301
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000302// PSP Target
303template<typename Target>
304class PSPTargetInfo : public OSTargetInfo<Target> {
305protected:
306 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000307 MacroBuilder &Builder) const {
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000308 // PSP defines; list based on the output of the pspdev gcc toolchain.
Benjamin Kramera9992772010-01-09 17:55:51 +0000309 Builder.defineMacro("PSP");
310 Builder.defineMacro("_PSP");
311 Builder.defineMacro("__psp__");
312 Builder.defineMacro("__ELF__");
Edward O'Callaghan84423a82009-11-15 10:22:07 +0000313 }
314public:
315 PSPTargetInfo(const std::string& triple)
316 : OSTargetInfo<Target>(triple) {
317 this->UserLabelPrefix = "";
318 }
319};
320
John Thompson3f6918a2009-11-19 17:18:50 +0000321// PS3 PPU Target
322template<typename Target>
323class PS3PPUTargetInfo : public OSTargetInfo<Target> {
324protected:
325 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000326 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000327 // PS3 PPU defines.
John Thompsonfb457972010-03-25 16:18:32 +0000328 Builder.defineMacro("__PPC__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000329 Builder.defineMacro("__PPU__");
330 Builder.defineMacro("__CELLOS_LV2__");
331 Builder.defineMacro("__ELF__");
332 Builder.defineMacro("__LP32__");
John Thompson8e6065a2010-06-24 22:44:13 +0000333 Builder.defineMacro("_ARCH_PPC64");
334 Builder.defineMacro("__powerpc64__");
John Thompson3f6918a2009-11-19 17:18:50 +0000335 }
336public:
337 PS3PPUTargetInfo(const std::string& triple)
338 : OSTargetInfo<Target>(triple) {
339 this->UserLabelPrefix = "";
John Thompsonec387af2009-12-18 14:21:08 +0000340 this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32;
John Thompson8e6065a2010-06-24 22:44:13 +0000341 this->IntMaxType = TargetInfo::SignedLongLong;
342 this->UIntMaxType = TargetInfo::UnsignedLongLong;
343 this->Int64Type = TargetInfo::SignedLongLong;
John Thompsonec387af2009-12-18 14:21:08 +0000344 this->SizeType = TargetInfo::UnsignedInt;
John Thompson8e6065a2010-06-24 22:44:13 +0000345 this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
346 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
John Thompson3f6918a2009-11-19 17:18:50 +0000347 }
348};
349
350// FIXME: Need a real SPU target.
351// PS3 SPU Target
352template<typename Target>
353class PS3SPUTargetInfo : public OSTargetInfo<Target> {
354protected:
355 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000356 MacroBuilder &Builder) const {
John Thompson3f6918a2009-11-19 17:18:50 +0000357 // PS3 PPU defines.
Benjamin Kramera9992772010-01-09 17:55:51 +0000358 Builder.defineMacro("__SPU__");
359 Builder.defineMacro("__ELF__");
John Thompson3f6918a2009-11-19 17:18:50 +0000360 }
361public:
362 PS3SPUTargetInfo(const std::string& triple)
363 : OSTargetInfo<Target>(triple) {
364 this->UserLabelPrefix = "";
365 }
366};
367
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000368// AuroraUX target
369template<typename Target>
370class AuroraUXTargetInfo : public OSTargetInfo<Target> {
371protected:
372 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000373 MacroBuilder &Builder) const {
374 DefineStd(Builder, "sun", Opts);
375 DefineStd(Builder, "unix", Opts);
376 Builder.defineMacro("__ELF__");
377 Builder.defineMacro("__svr4__");
378 Builder.defineMacro("__SVR4");
Edward O'Callaghan991f9a72009-10-18 13:33:59 +0000379 }
380public:
381 AuroraUXTargetInfo(const std::string& triple)
382 : OSTargetInfo<Target>(triple) {
383 this->UserLabelPrefix = "";
384 this->WCharType = this->SignedLong;
385 // FIXME: WIntType should be SignedLong
386 }
387};
388
Torok Edwin5f6c1942009-06-30 17:10:35 +0000389// Solaris target
390template<typename Target>
391class SolarisTargetInfo : public OSTargetInfo<Target> {
392protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +0000393 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +0000394 MacroBuilder &Builder) const {
395 DefineStd(Builder, "sun", Opts);
396 DefineStd(Builder, "unix", Opts);
397 Builder.defineMacro("__ELF__");
398 Builder.defineMacro("__svr4__");
399 Builder.defineMacro("__SVR4");
Torok Edwin5f6c1942009-06-30 17:10:35 +0000400 }
401public:
Mike Stump1eb44332009-09-09 15:08:12 +0000402 SolarisTargetInfo(const std::string& triple)
Torok Edwin5f6c1942009-06-30 17:10:35 +0000403 : OSTargetInfo<Target>(triple) {
404 this->UserLabelPrefix = "";
405 this->WCharType = this->SignedLong;
406 // FIXME: WIntType should be SignedLong
407 }
408};
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000409
410// Windows target
411template<typename Target>
412class WindowsTargetInfo : public OSTargetInfo<Target> {
413protected:
414 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
415 MacroBuilder &Builder) const {
Michael J. Spencera764e832010-10-21 08:22:51 +0000416 Builder.defineMacro("_WIN32");
417 }
418 void getVisualStudioDefines(const LangOptions &Opts,
419 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000420 if (Opts.CPlusPlus) {
421 if (Opts.RTTI)
422 Builder.defineMacro("_CPPRTTI");
423
424 if (Opts.Exceptions)
425 Builder.defineMacro("_CPPUNWIND");
426 }
427
428 if (!Opts.CharIsSigned)
429 Builder.defineMacro("_CHAR_UNSIGNED");
430
431 // FIXME: POSIXThreads isn't exactly the option this should be defined for,
432 // but it works for now.
433 if (Opts.POSIXThreads)
434 Builder.defineMacro("_MT");
Michael J. Spencera764e832010-10-21 08:22:51 +0000435
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000436 if (Opts.MSCVersion != 0)
437 Builder.defineMacro("_MSC_VER", llvm::Twine(Opts.MSCVersion));
438
439 if (Opts.Microsoft) {
440 Builder.defineMacro("_MSC_EXTENSIONS");
441
442 if (Opts.CPlusPlus0x) {
443 Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
444 Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
445 Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
446 }
447 }
448
449 Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000450 }
451
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000452public:
453 WindowsTargetInfo(const std::string &triple)
454 : OSTargetInfo<Target>(triple) {}
455};
456
Mike Stump1eb44332009-09-09 15:08:12 +0000457} // end anonymous namespace.
Torok Edwin5f6c1942009-06-30 17:10:35 +0000458
Chris Lattnerd29b6302008-10-05 21:50:58 +0000459//===----------------------------------------------------------------------===//
Eli Friedmane4277982008-08-20 23:11:40 +0000460// Specific target implementations.
461//===----------------------------------------------------------------------===//
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000462
Eli Friedmane4277982008-08-20 23:11:40 +0000463namespace {
464// PPC abstract base class
465class PPCTargetInfo : public TargetInfo {
466 static const Builtin::Info BuiltinInfo[];
467 static const char * const GCCRegNames[];
468 static const TargetInfo::GCCRegAlias GCCRegAliases[];
469
470public:
Eli Friedman15b91762009-06-05 07:05:05 +0000471 PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {}
472
Eli Friedmane4277982008-08-20 23:11:40 +0000473 virtual void getTargetBuiltins(const Builtin::Info *&Records,
474 unsigned &NumRecords) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000475 Records = BuiltinInfo;
Eli Friedmane4277982008-08-20 23:11:40 +0000476 NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000477 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000478
Chris Lattner33328642009-03-20 15:52:06 +0000479 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000480 MacroBuilder &Builder) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000481
Eli Friedmane4277982008-08-20 23:11:40 +0000482 virtual const char *getVAListDeclaration() const {
Chris Lattnerd5998502008-10-27 01:11:29 +0000483 return "typedef char* __builtin_va_list;";
484 // This is the right definition for ABI/V4: System V.4/eabi.
485 /*return "typedef struct __va_list_tag {"
Eli Friedmane4277982008-08-20 23:11:40 +0000486 " unsigned char gpr;"
487 " unsigned char fpr;"
488 " unsigned short reserved;"
489 " void* overflow_arg_area;"
490 " void* reg_save_area;"
Chris Lattnerd5998502008-10-27 01:11:29 +0000491 "} __builtin_va_list[1];";*/
Anders Carlsson3346ae62007-11-24 23:38:12 +0000492 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000493 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000494 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000495 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000496 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000497 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +0000498 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000499 switch (*Name) {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000500 default: return false;
501 case 'O': // Zero
John Thompson8e6065a2010-06-24 22:44:13 +0000502 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000503 case 'b': // Base register
504 case 'f': // Floating point register
Chris Lattner44def072009-04-26 07:16:29 +0000505 Info.setAllowsRegister();
John Thompson8e6065a2010-06-24 22:44:13 +0000506 break;
507 // FIXME: The following are added to allow parsing.
508 // I just took a guess at what the actions should be.
509 // Also, is more specific checking needed? I.e. specific registers?
Michael J. Spencer20249a12010-10-21 03:16:25 +0000510 case 'd': // Floating point register (containing 64-bit value)
John Thompson8e6065a2010-06-24 22:44:13 +0000511 case 'v': // Altivec vector register
512 Info.setAllowsRegister();
513 break;
514 case 'w':
515 switch (Name[1]) {
Michael J. Spencer20249a12010-10-21 03:16:25 +0000516 case 'd':// VSX vector register to hold vector double data
517 case 'f':// VSX vector register to hold vector float data
518 case 's':// VSX vector register to hold scalar float data
519 case 'a':// Any VSX register
John Thompson8e6065a2010-06-24 22:44:13 +0000520 break;
521 default:
522 return false;
523 }
524 Info.setAllowsRegister();
525 Name++; // Skip over 'w'.
526 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000527 case 'h': // `MQ', `CTR', or `LINK' register
528 case 'q': // `MQ' register
529 case 'c': // `CTR' register
530 case 'l': // `LINK' register
531 case 'x': // `CR' register (condition register) number 0
532 case 'y': // `CR' register (condition register)
533 case 'z': // `XER[CA]' carry bit (part of the XER register)
John Thompson8e6065a2010-06-24 22:44:13 +0000534 Info.setAllowsRegister();
535 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000536 case 'I': // Signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000537 case 'J': // Unsigned 16-bit constant shifted left 16 bits
Michael J. Spencer20249a12010-10-21 03:16:25 +0000538 // (use `L' instead for SImode constants)
539 case 'K': // Unsigned 16-bit constant
540 case 'L': // Signed 16-bit constant shifted left 16 bits
541 case 'M': // Constant larger than 31
542 case 'N': // Exact power of 2
543 case 'P': // Constant whose negation is a signed 16-bit constant
John Thompson8e6065a2010-06-24 22:44:13 +0000544 case 'G': // Floating point constant that can be loaded into a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000545 // register with one instruction per word
John Thompson8e6065a2010-06-24 22:44:13 +0000546 case 'H': // Integer/Floating point constant that can be loaded
Michael J. Spencer20249a12010-10-21 03:16:25 +0000547 // into a register using three instructions
John Thompson8e6065a2010-06-24 22:44:13 +0000548 break;
549 case 'm': // Memory operand. Note that on PowerPC targets, m can
550 // include addresses that update the base register. It
551 // is therefore only safe to use `m' in an asm statement
552 // if that asm statement accesses the operand exactly once.
553 // The asm statement must also use `%U<opno>' as a
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000554 // placeholder for the "update" flag in the corresponding
Michael J. Spencer20249a12010-10-21 03:16:25 +0000555 // load or store instruction. For example:
John Thompson8e6065a2010-06-24 22:44:13 +0000556 // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
Michael J. Spencer20249a12010-10-21 03:16:25 +0000557 // is correct but:
John Thompson8e6065a2010-06-24 22:44:13 +0000558 // asm ("st %1,%0" : "=m" (mem) : "r" (val));
559 // is not. Use es rather than m if you don't want the base
Michael J. Spencer20249a12010-10-21 03:16:25 +0000560 // register to be updated.
561 case 'e':
John Thompson56b6eca2010-06-25 00:02:05 +0000562 if (Name[1] != 's')
563 return false;
Sebastian Redl5005a6c2010-08-17 22:42:34 +0000564 // es: A "stable" memory operand; that is, one which does not
John Thompson8e6065a2010-06-24 22:44:13 +0000565 // include any automodification of the base register. Unlike
566 // `m', this constraint can be used in asm statements that
567 // might access the operand several times, or that might not
John Thompson56b6eca2010-06-25 00:02:05 +0000568 // access it at all.
John Thompson8e6065a2010-06-24 22:44:13 +0000569 Info.setAllowsMemory();
John Thompson56b6eca2010-06-25 00:02:05 +0000570 Name++; // Skip over 'e'.
John Thompson8e6065a2010-06-24 22:44:13 +0000571 break;
572 case 'Q': // Memory operand that is an offset from a register (it is
Michael J. Spencer20249a12010-10-21 03:16:25 +0000573 // usually better to use `m' or `es' in asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000574 case 'Z': // Memory operand that is an indexed or indirect from a
575 // register (it is usually better to use `m' or `es' in
Michael J. Spencer20249a12010-10-21 03:16:25 +0000576 // asm statements)
John Thompson8e6065a2010-06-24 22:44:13 +0000577 Info.setAllowsMemory();
578 Info.setAllowsRegister();
579 break;
Michael J. Spencer20249a12010-10-21 03:16:25 +0000580 case 'R': // AIX TOC entry
John Thompson8e6065a2010-06-24 22:44:13 +0000581 case 'a': // Address operand that is an indexed or indirect from a
Michael J. Spencer20249a12010-10-21 03:16:25 +0000582 // register (`p' is preferable for asm statements)
583 case 'S': // Constant suitable as a 64-bit mask operand
584 case 'T': // Constant suitable as a 32-bit mask operand
585 case 'U': // System V Release 4 small data area reference
John Thompson8e6065a2010-06-24 22:44:13 +0000586 case 't': // AND masks that can be performed by two rldic{l, r}
Michael J. Spencer20249a12010-10-21 03:16:25 +0000587 // instructions
588 case 'W': // Vector constant that does not require memory
589 case 'j': // Vector constant that is all zeros.
John Thompson8e6065a2010-06-24 22:44:13 +0000590 break;
591 // End FIXME.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000592 }
John Thompson8e6065a2010-06-24 22:44:13 +0000593 return true;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000594 }
Eli Friedmane4277982008-08-20 23:11:40 +0000595 virtual const char *getClobbers() const {
596 return "";
Anders Carlssond04c6e22007-11-27 04:11:28 +0000597 }
Eli Friedmane4277982008-08-20 23:11:40 +0000598};
Anders Carlssond04c6e22007-11-27 04:11:28 +0000599
Eli Friedmane4277982008-08-20 23:11:40 +0000600const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000601#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
602#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
603 ALL_LANGUAGES, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000604#include "clang/Basic/BuiltinsPPC.def"
Eli Friedmane4277982008-08-20 23:11:40 +0000605};
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000606
607
Chris Lattnerc0f59212009-03-02 22:27:17 +0000608/// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
609/// #defines that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +0000610void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000611 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +0000612 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +0000613 Builder.defineMacro("__ppc__");
614 Builder.defineMacro("_ARCH_PPC");
Chris Lattnere03ae302010-02-16 18:14:57 +0000615 Builder.defineMacro("__powerpc__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000616 Builder.defineMacro("__POWERPC__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000617 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000618 Builder.defineMacro("_ARCH_PPC64");
619 Builder.defineMacro("_LP64");
620 Builder.defineMacro("__LP64__");
Chris Lattnere03ae302010-02-16 18:14:57 +0000621 Builder.defineMacro("__powerpc64__");
Benjamin Kramera9992772010-01-09 17:55:51 +0000622 Builder.defineMacro("__ppc64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000623 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +0000624 Builder.defineMacro("__ppc__");
Chris Lattnerc0f59212009-03-02 22:27:17 +0000625 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000626
Chris Lattnerc0f59212009-03-02 22:27:17 +0000627 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +0000628 Builder.defineMacro("_BIG_ENDIAN");
629 Builder.defineMacro("__BIG_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000630
Chris Lattnerc0f59212009-03-02 22:27:17 +0000631 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +0000632 Builder.defineMacro("__NATURAL_ALIGNMENT__");
633 Builder.defineMacro("__REGISTER_PREFIX__", "");
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000634
Chris Lattnerc0f59212009-03-02 22:27:17 +0000635 // FIXME: Should be controlled by command line option.
Benjamin Kramera9992772010-01-09 17:55:51 +0000636 Builder.defineMacro("__LONG_DOUBLE_128__");
Michael J. Spencer20249a12010-10-21 03:16:25 +0000637
John Thompson3f6918a2009-11-19 17:18:50 +0000638 if (Opts.AltiVec) {
Benjamin Kramera9992772010-01-09 17:55:51 +0000639 Builder.defineMacro("__VEC__", "10206");
640 Builder.defineMacro("__ALTIVEC__");
John Thompson3f6918a2009-11-19 17:18:50 +0000641 }
Chris Lattnerc0f59212009-03-02 22:27:17 +0000642}
643
Chris Lattner393ff042008-04-21 18:56:49 +0000644
Eli Friedmane4277982008-08-20 23:11:40 +0000645const char * const PPCTargetInfo::GCCRegNames[] = {
Chris Lattnere94e0d42009-09-16 05:05:27 +0000646 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
647 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
648 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
649 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
650 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
651 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
652 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
653 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
Eli Friedmane4277982008-08-20 23:11:40 +0000654 "mq", "lr", "ctr", "ap",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000655 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
Eli Friedmane4277982008-08-20 23:11:40 +0000656 "xer",
Chris Lattnere94e0d42009-09-16 05:05:27 +0000657 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
658 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
659 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
660 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
Eli Friedmane4277982008-08-20 23:11:40 +0000661 "vrsave", "vscr",
662 "spe_acc", "spefscr",
663 "sfp"
664};
Reid Spencer5f016e22007-07-11 17:01:13 +0000665
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000666void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
Eli Friedmane4277982008-08-20 23:11:40 +0000667 unsigned &NumNames) const {
668 Names = GCCRegNames;
669 NumNames = llvm::array_lengthof(GCCRegNames);
670}
Reid Spencer5f016e22007-07-11 17:01:13 +0000671
Eli Friedmane4277982008-08-20 23:11:40 +0000672const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
673 // While some of these aliases do map to different registers
674 // they still share the same register name.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000675 { { "0" }, "r0" },
676 { { "1"}, "r1" },
677 { { "2" }, "r2" },
678 { { "3" }, "r3" },
679 { { "4" }, "r4" },
680 { { "5" }, "r5" },
681 { { "6" }, "r6" },
682 { { "7" }, "r7" },
683 { { "8" }, "r8" },
684 { { "9" }, "r9" },
685 { { "10" }, "r10" },
686 { { "11" }, "r11" },
687 { { "12" }, "r12" },
688 { { "13" }, "r13" },
689 { { "14" }, "r14" },
690 { { "15" }, "r15" },
691 { { "16" }, "r16" },
692 { { "17" }, "r17" },
693 { { "18" }, "r18" },
694 { { "19" }, "r19" },
695 { { "20" }, "r20" },
696 { { "21" }, "r21" },
697 { { "22" }, "r22" },
698 { { "23" }, "r23" },
699 { { "24" }, "r24" },
700 { { "25" }, "r25" },
701 { { "26" }, "r26" },
702 { { "27" }, "r27" },
703 { { "28" }, "r28" },
704 { { "29" }, "r29" },
705 { { "30" }, "r30" },
706 { { "31" }, "r31" },
707 { { "fr0" }, "f0" },
708 { { "fr1" }, "f1" },
709 { { "fr2" }, "f2" },
710 { { "fr3" }, "f3" },
711 { { "fr4" }, "f4" },
712 { { "fr5" }, "f5" },
713 { { "fr6" }, "f6" },
714 { { "fr7" }, "f7" },
715 { { "fr8" }, "f8" },
716 { { "fr9" }, "f9" },
Mike Stump10880392009-09-17 21:15:00 +0000717 { { "fr10" }, "f10" },
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +0000718 { { "fr11" }, "f11" },
719 { { "fr12" }, "f12" },
720 { { "fr13" }, "f13" },
721 { { "fr14" }, "f14" },
722 { { "fr15" }, "f15" },
723 { { "fr16" }, "f16" },
724 { { "fr17" }, "f17" },
725 { { "fr18" }, "f18" },
726 { { "fr19" }, "f19" },
727 { { "fr20" }, "f20" },
728 { { "fr21" }, "f21" },
729 { { "fr22" }, "f22" },
730 { { "fr23" }, "f23" },
731 { { "fr24" }, "f24" },
732 { { "fr25" }, "f25" },
733 { { "fr26" }, "f26" },
734 { { "fr27" }, "f27" },
735 { { "fr28" }, "f28" },
736 { { "fr29" }, "f29" },
737 { { "fr30" }, "f30" },
738 { { "fr31" }, "f31" },
739 { { "cc" }, "cr0" },
Eli Friedmane4277982008-08-20 23:11:40 +0000740};
741
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000742void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Eli Friedmane4277982008-08-20 23:11:40 +0000743 unsigned &NumAliases) const {
744 Aliases = GCCRegAliases;
745 NumAliases = llvm::array_lengthof(GCCRegAliases);
746}
747} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +0000748
749namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000750class PPC32TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000751public:
Chris Lattnere03ae302010-02-16 18:14:57 +0000752 PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) {
Eli Friedmaned855cb2008-08-21 00:13:15 +0000753 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 +0000754 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32";
Chris Lattnere03ae302010-02-16 18:14:57 +0000755
756 if (getTriple().getOS() == llvm::Triple::FreeBSD)
757 this->SizeType = TargetInfo::UnsignedInt;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000758 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000759};
760} // end anonymous namespace.
761
762namespace {
Eli Friedmane4277982008-08-20 23:11:40 +0000763class PPC64TargetInfo : public PPCTargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +0000764public:
Eli Friedmane4277982008-08-20 23:11:40 +0000765 PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +0000766 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman3c7b6e42009-07-01 03:36:11 +0000767 IntMaxType = SignedLong;
768 UIntMaxType = UnsignedLong;
769 Int64Type = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +0000770 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 +0000771 "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64";
Chris Lattnerf291b102008-05-09 06:17:04 +0000772 }
Eli Friedmane4277982008-08-20 23:11:40 +0000773};
774} // end anonymous namespace.
775
Daniel Dunbar4c6a2262010-05-30 00:07:30 +0000776
777namespace {
778class DarwinPPCTargetInfo :
779 public DarwinTargetInfo<PPCTargetInfo> {
780public:
781 DarwinPPCTargetInfo(const std::string& triple)
782 : DarwinTargetInfo<PPCTargetInfo>(triple) {
783 HasAlignMac68kSupport = true;
784 }
785};
786
787class DarwinPPC64TargetInfo :
788 public DarwinTargetInfo<PPC64TargetInfo> {
789public:
790 DarwinPPC64TargetInfo(const std::string& triple)
791 : DarwinTargetInfo<PPC64TargetInfo>(triple) {
792 HasAlignMac68kSupport = true;
793 }
794};
795} // end anonymous namespace.
796
Reid Spencer5f016e22007-07-11 17:01:13 +0000797namespace {
Chris Lattner9cbeb632010-03-06 21:21:27 +0000798// MBlaze abstract base class
799class MBlazeTargetInfo : public TargetInfo {
800 static const char * const GCCRegNames[];
801 static const TargetInfo::GCCRegAlias GCCRegAliases[];
802
803public:
804 MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) {
Wesley Pecka48fa4b2010-12-12 20:56:47 +0000805 DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16";
Chris Lattner9cbeb632010-03-06 21:21:27 +0000806 }
807
808 virtual void getTargetBuiltins(const Builtin::Info *&Records,
809 unsigned &NumRecords) const {
810 // FIXME: Implement.
811 Records = 0;
812 NumRecords = 0;
813 }
814
815 virtual void getTargetDefines(const LangOptions &Opts,
816 MacroBuilder &Builder) const;
817
818 virtual const char *getVAListDeclaration() const {
819 return "typedef char* __builtin_va_list;";
820 }
821 virtual const char *getTargetPrefix() const {
822 return "mblaze";
823 }
824 virtual void getGCCRegNames(const char * const *&Names,
825 unsigned &NumNames) const;
826 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
827 unsigned &NumAliases) const;
828 virtual bool validateAsmConstraint(const char *&Name,
829 TargetInfo::ConstraintInfo &Info) const {
830 switch (*Name) {
831 default: return false;
832 case 'O': // Zero
833 return true;
834 case 'b': // Base register
835 case 'f': // Floating point register
836 Info.setAllowsRegister();
837 return true;
838 }
839 }
840 virtual const char *getClobbers() const {
841 return "";
842 }
843};
844
845/// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific
846/// #defines that are not tied to a specific subtarget.
847void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts,
848 MacroBuilder &Builder) const {
849 // Target identification.
850 Builder.defineMacro("__microblaze__");
851 Builder.defineMacro("_ARCH_MICROBLAZE");
852 Builder.defineMacro("__MICROBLAZE__");
853
854 // Target properties.
855 Builder.defineMacro("_BIG_ENDIAN");
856 Builder.defineMacro("__BIG_ENDIAN__");
857
858 // Subtarget options.
859 Builder.defineMacro("__REGISTER_PREFIX__", "");
860}
861
862
863const char * const MBlazeTargetInfo::GCCRegNames[] = {
864 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
865 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
866 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
867 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
868 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
869 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
870 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
871 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
872 "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4",
873 "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp"
874};
875
876void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names,
877 unsigned &NumNames) const {
878 Names = GCCRegNames;
879 NumNames = llvm::array_lengthof(GCCRegNames);
880}
881
882const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = {
883 { {"f0"}, "r0" },
884 { {"f1"}, "r1" },
885 { {"f2"}, "r2" },
886 { {"f3"}, "r3" },
887 { {"f4"}, "r4" },
888 { {"f5"}, "r5" },
889 { {"f6"}, "r6" },
890 { {"f7"}, "r7" },
891 { {"f8"}, "r8" },
892 { {"f9"}, "r9" },
893 { {"f10"}, "r10" },
894 { {"f11"}, "r11" },
895 { {"f12"}, "r12" },
896 { {"f13"}, "r13" },
897 { {"f14"}, "r14" },
898 { {"f15"}, "r15" },
899 { {"f16"}, "r16" },
900 { {"f17"}, "r17" },
901 { {"f18"}, "r18" },
902 { {"f19"}, "r19" },
903 { {"f20"}, "r20" },
904 { {"f21"}, "r21" },
905 { {"f22"}, "r22" },
906 { {"f23"}, "r23" },
907 { {"f24"}, "r24" },
908 { {"f25"}, "r25" },
909 { {"f26"}, "r26" },
910 { {"f27"}, "r27" },
911 { {"f28"}, "r28" },
912 { {"f29"}, "r29" },
913 { {"f30"}, "r30" },
914 { {"f31"}, "r31" },
915};
916
917void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
918 unsigned &NumAliases) const {
919 Aliases = GCCRegAliases;
920 NumAliases = llvm::array_lengthof(GCCRegAliases);
921}
922} // end anonymous namespace.
923
924namespace {
Eli Friedman618234a2008-08-20 02:34:37 +0000925// Namespace for x86 abstract base class
926const Builtin::Info BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +0000927#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
928#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
929 ALL_LANGUAGES, false },
Chris Lattner6b15cdc2009-06-14 01:05:48 +0000930#include "clang/Basic/BuiltinsX86.def"
Eli Friedman618234a2008-08-20 02:34:37 +0000931};
Eli Friedman61538a72008-05-20 14:21:01 +0000932
Nuno Lopes2550d702009-12-23 17:49:57 +0000933static const char* const GCCRegNames[] = {
Eli Friedman618234a2008-08-20 02:34:37 +0000934 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
935 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
936 "argp", "flags", "fspr", "dirflag", "frame",
937 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
938 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
939 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
940 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
941};
942
943const TargetInfo::GCCRegAlias GCCRegAliases[] = {
944 { { "al", "ah", "eax", "rax" }, "ax" },
945 { { "bl", "bh", "ebx", "rbx" }, "bx" },
946 { { "cl", "ch", "ecx", "rcx" }, "cx" },
947 { { "dl", "dh", "edx", "rdx" }, "dx" },
948 { { "esi", "rsi" }, "si" },
949 { { "edi", "rdi" }, "di" },
950 { { "esp", "rsp" }, "sp" },
951 { { "ebp", "rbp" }, "bp" },
952};
953
954// X86 target abstract base class; x86-32 and x86-64 are very close, so
955// most of the implementation can be shared.
956class X86TargetInfo : public TargetInfo {
Chris Lattner84f0ea82009-03-02 22:40:39 +0000957 enum X86SSEEnum {
958 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42
959 } SSELevel;
Anders Carlsson9b0fb622010-01-27 03:47:49 +0000960 enum AMD3DNowEnum {
961 NoAMD3DNow, AMD3DNow, AMD3DNowAthlon
962 } AMD3DNowLevel;
963
Eric Christophereea12d12010-04-02 23:50:19 +0000964 bool HasAES;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +0000965 bool HasAVX;
966
Eli Friedman618234a2008-08-20 02:34:37 +0000967public:
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000968 X86TargetInfo(const std::string& triple)
Eric Christophereea12d12010-04-02 23:50:19 +0000969 : TargetInfo(triple), SSELevel(NoMMXSSE), AMD3DNowLevel(NoAMD3DNow),
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +0000970 HasAES(false), HasAVX(false) {
Eli Friedman618234a2008-08-20 02:34:37 +0000971 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Reid Spencer5f016e22007-07-11 17:01:13 +0000972 }
973 virtual void getTargetBuiltins(const Builtin::Info *&Records,
974 unsigned &NumRecords) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000975 Records = BuiltinInfo;
976 NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
Reid Spencer5f016e22007-07-11 17:01:13 +0000977 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000978 virtual void getGCCRegNames(const char * const *&Names,
Eli Friedman618234a2008-08-20 02:34:37 +0000979 unsigned &NumNames) const {
980 Names = GCCRegNames;
981 NumNames = llvm::array_lengthof(GCCRegNames);
Anders Carlsson3346ae62007-11-24 23:38:12 +0000982 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +0000983 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Anders Carlsson3346ae62007-11-24 23:38:12 +0000984 unsigned &NumAliases) const {
Eli Friedman618234a2008-08-20 02:34:37 +0000985 Aliases = GCCRegAliases;
986 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +0000987 }
Anders Carlsson066d2ea2009-02-28 17:11:49 +0000988 virtual bool validateAsmConstraint(const char *&Name,
Eli Friedman618234a2008-08-20 02:34:37 +0000989 TargetInfo::ConstraintInfo &info) const;
Dale Johannesenf6e2c202010-10-29 23:12:32 +0000990 virtual const llvm::Type* adjustInlineAsmType(std::string& Constraint,
991 const llvm::Type* Ty,
992 llvm::LLVMContext& Context) const;
Eli Friedman618234a2008-08-20 02:34:37 +0000993 virtual std::string convertConstraint(const char Constraint) const;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000994 virtual const char *getClobbers() const {
Eli Friedman618234a2008-08-20 02:34:37 +0000995 return "~{dirflag},~{fpsr},~{flags}";
996 }
Chris Lattner33328642009-03-20 15:52:06 +0000997 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +0000998 MacroBuilder &Builder) const;
Daniel Dunbar17ca3632009-05-06 21:07:50 +0000999 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1000 const std::string &Name,
1001 bool Enabled) const;
Mike Stump1eb44332009-09-09 15:08:12 +00001002 virtual void getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001003 llvm::StringMap<bool> &Features) const;
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001004 virtual void HandleTargetFeatures(std::vector<std::string> &Features);
Reid Spencer5f016e22007-07-11 17:01:13 +00001005};
Chris Lattner3daed522009-03-02 22:20:04 +00001006
Mike Stump1eb44332009-09-09 15:08:12 +00001007void X86TargetInfo::getDefaultFeatures(const std::string &CPU,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001008 llvm::StringMap<bool> &Features) const {
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001009 // FIXME: This should not be here.
1010 Features["3dnow"] = false;
1011 Features["3dnowa"] = false;
1012 Features["mmx"] = false;
1013 Features["sse"] = false;
1014 Features["sse2"] = false;
1015 Features["sse3"] = false;
1016 Features["ssse3"] = false;
1017 Features["sse41"] = false;
1018 Features["sse42"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001019 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001020 Features["avx"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001021
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001022 // LLVM does not currently recognize this.
1023 // Features["sse4a"] = false;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001024
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001025 // FIXME: This *really* should not be here.
1026
1027 // X86_64 always has SSE2.
1028 if (PointerWidth == 64)
1029 Features["sse2"] = Features["sse"] = Features["mmx"] = true;
1030
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001031 if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" ||
1032 CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro")
1033 ;
1034 else if (CPU == "pentium-mmx" || CPU == "pentium2")
1035 setFeatureEnabled(Features, "mmx", true);
1036 else if (CPU == "pentium3")
1037 setFeatureEnabled(Features, "sse", true);
1038 else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64")
1039 setFeatureEnabled(Features, "sse2", true);
1040 else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona")
1041 setFeatureEnabled(Features, "sse3", true);
1042 else if (CPU == "core2")
1043 setFeatureEnabled(Features, "ssse3", true);
1044 else if (CPU == "penryn") {
1045 setFeatureEnabled(Features, "sse4", true);
1046 Features["sse42"] = false;
1047 } else if (CPU == "atom")
1048 setFeatureEnabled(Features, "sse3", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001049 else if (CPU == "corei7") {
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001050 setFeatureEnabled(Features, "sse4", true);
Eric Christophereea12d12010-04-02 23:50:19 +00001051 setFeatureEnabled(Features, "aes", true);
1052 }
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001053 else if (CPU == "k6" || CPU == "winchip-c6")
1054 setFeatureEnabled(Features, "mmx", true);
Mike Stump1eb44332009-09-09 15:08:12 +00001055 else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" ||
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001056 CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") {
1057 setFeatureEnabled(Features, "mmx", true);
1058 setFeatureEnabled(Features, "3dnow", true);
1059 } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") {
1060 setFeatureEnabled(Features, "sse", true);
1061 setFeatureEnabled(Features, "3dnowa", true);
1062 } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" ||
1063 CPU == "athlon-fx") {
Mike Stump1eb44332009-09-09 15:08:12 +00001064 setFeatureEnabled(Features, "sse2", true);
Daniel Dunbar3ac79042009-05-06 21:56:32 +00001065 setFeatureEnabled(Features, "3dnowa", true);
1066 } else if (CPU == "c3-2")
1067 setFeatureEnabled(Features, "sse", true);
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001068}
1069
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001070bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
Mike Stump1eb44332009-09-09 15:08:12 +00001071 const std::string &Name,
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001072 bool Enabled) const {
Eric Christopherd39ebe22010-03-04 02:26:37 +00001073 // FIXME: This *really* should not be here. We need some way of translating
1074 // options into llvm subtarget features.
1075 if (!Features.count(Name) &&
1076 (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001077 return false;
1078
1079 if (Enabled) {
1080 if (Name == "mmx")
1081 Features["mmx"] = true;
1082 else if (Name == "sse")
1083 Features["mmx"] = Features["sse"] = true;
1084 else if (Name == "sse2")
1085 Features["mmx"] = Features["sse"] = Features["sse2"] = true;
1086 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001087 Features["mmx"] = Features["sse"] = Features["sse2"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001088 Features["sse3"] = true;
1089 else if (Name == "ssse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001090 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001091 Features["ssse3"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001092 else if (Name == "sse4" || Name == "sse4.2")
Mike Stump1eb44332009-09-09 15:08:12 +00001093 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001094 Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
Eric Christopherd39ebe22010-03-04 02:26:37 +00001095 else if (Name == "sse4.1")
1096 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
1097 Features["ssse3"] = Features["sse41"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001098 else if (Name == "3dnow")
1099 Features["3dnowa"] = true;
1100 else if (Name == "3dnowa")
1101 Features["3dnow"] = Features["3dnowa"] = true;
Eric Christophereea12d12010-04-02 23:50:19 +00001102 else if (Name == "aes")
1103 Features["aes"] = true;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001104 else if (Name == "avx")
1105 Features["avx"] = true;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001106 } else {
1107 if (Name == "mmx")
Mike Stump1eb44332009-09-09 15:08:12 +00001108 Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001109 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1110 else if (Name == "sse")
Mike Stump1eb44332009-09-09 15:08:12 +00001111 Features["sse"] = Features["sse2"] = Features["sse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001112 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1113 else if (Name == "sse2")
Mike Stump1eb44332009-09-09 15:08:12 +00001114 Features["sse2"] = Features["sse3"] = Features["ssse3"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001115 Features["sse41"] = Features["sse42"] = false;
1116 else if (Name == "sse3")
Mike Stump1eb44332009-09-09 15:08:12 +00001117 Features["sse3"] = Features["ssse3"] = Features["sse41"] =
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001118 Features["sse42"] = false;
1119 else if (Name == "ssse3")
1120 Features["ssse3"] = Features["sse41"] = Features["sse42"] = false;
1121 else if (Name == "sse4")
1122 Features["sse41"] = Features["sse42"] = false;
Eric Christopherd41b4ec2010-03-04 02:31:44 +00001123 else if (Name == "sse4.2")
1124 Features["sse42"] = false;
1125 else if (Name == "sse4.1")
1126 Features["sse41"] = Features["sse42"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001127 else if (Name == "3dnow")
1128 Features["3dnow"] = Features["3dnowa"] = false;
1129 else if (Name == "3dnowa")
1130 Features["3dnowa"] = false;
Eric Christophereea12d12010-04-02 23:50:19 +00001131 else if (Name == "aes")
1132 Features["aes"] = false;
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001133 else if (Name == "avx")
1134 Features["avx"] = false;
Daniel Dunbar17ca3632009-05-06 21:07:50 +00001135 }
1136
1137 return true;
1138}
1139
Daniel Dunbar868bd0a2009-05-06 03:16:41 +00001140/// HandleTargetOptions - Perform initialization based on the user
1141/// configured set of features.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00001142void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001143 // Remember the maximum enabled sselevel.
1144 for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
1145 // Ignore disabled features.
1146 if (Features[i][0] == '-')
1147 continue;
1148
Eric Christophereea12d12010-04-02 23:50:19 +00001149 if (Features[i].substr(1) == "aes") {
1150 HasAES = true;
1151 continue;
1152 }
1153
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001154 // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
1155 // For now let it be enabled together with other SSE levels.
1156 if (Features[i].substr(1) == "avx") {
1157 HasAVX = true;
1158 continue;
1159 }
1160
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001161 assert(Features[i][0] == '+' && "Invalid target feature!");
1162 X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
1163 .Case("sse42", SSE42)
1164 .Case("sse41", SSE41)
1165 .Case("ssse3", SSSE3)
Nuno Lopes33d3bca2010-03-12 10:20:09 +00001166 .Case("sse3", SSE3)
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001167 .Case("sse2", SSE2)
1168 .Case("sse", SSE1)
1169 .Case("mmx", MMX)
1170 .Default(NoMMXSSE);
1171 SSELevel = std::max(SSELevel, Level);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001172
1173 AMD3DNowEnum ThreeDNowLevel =
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001174 llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1))
1175 .Case("3dnowa", AMD3DNowAthlon)
1176 .Case("3dnow", AMD3DNow)
1177 .Default(NoAMD3DNow);
Michael J. Spencer20249a12010-10-21 03:16:25 +00001178
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001179 AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel);
Daniel Dunbar29a790b2009-11-11 09:38:56 +00001180 }
Chris Lattner3daed522009-03-02 22:20:04 +00001181}
Chris Lattnerc0f59212009-03-02 22:27:17 +00001182
1183/// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines
1184/// that are not tied to a specific subtarget.
Chris Lattner33328642009-03-20 15:52:06 +00001185void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001186 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001187 // Target identification.
1188 if (PointerWidth == 64) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001189 Builder.defineMacro("_LP64");
1190 Builder.defineMacro("__LP64__");
1191 Builder.defineMacro("__amd64__");
1192 Builder.defineMacro("__amd64");
1193 Builder.defineMacro("__x86_64");
1194 Builder.defineMacro("__x86_64__");
Chris Lattnerc0f59212009-03-02 22:27:17 +00001195 } else {
Benjamin Kramera9992772010-01-09 17:55:51 +00001196 DefineStd(Builder, "i386", Opts);
Chris Lattnerc0f59212009-03-02 22:27:17 +00001197 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001198
Eric Christophereea12d12010-04-02 23:50:19 +00001199 if (HasAES)
1200 Builder.defineMacro("__AES__");
1201
Bruno Cardoso Lopes7377ed92010-08-04 22:29:13 +00001202 if (HasAVX)
1203 Builder.defineMacro("__AVX__");
1204
Chris Lattnerc0f59212009-03-02 22:27:17 +00001205 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001206 Builder.defineMacro("__LITTLE_ENDIAN__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001207
Chris Lattnerc0f59212009-03-02 22:27:17 +00001208 // Subtarget options.
Benjamin Kramera9992772010-01-09 17:55:51 +00001209 Builder.defineMacro("__nocona");
1210 Builder.defineMacro("__nocona__");
1211 Builder.defineMacro("__tune_nocona__");
1212 Builder.defineMacro("__REGISTER_PREFIX__", "");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001213
Chris Lattner54175442009-04-19 17:32:33 +00001214 // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
1215 // functions in glibc header files that use FP Stack inline asm which the
1216 // backend can't deal with (PR879).
Benjamin Kramera9992772010-01-09 17:55:51 +00001217 Builder.defineMacro("__NO_MATH_INLINES");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001218
Chris Lattner84f0ea82009-03-02 22:40:39 +00001219 // Each case falls through to the previous one here.
1220 switch (SSELevel) {
1221 case SSE42:
Benjamin Kramera9992772010-01-09 17:55:51 +00001222 Builder.defineMacro("__SSE4_2__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001223 case SSE41:
Benjamin Kramera9992772010-01-09 17:55:51 +00001224 Builder.defineMacro("__SSE4_1__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001225 case SSSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001226 Builder.defineMacro("__SSSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001227 case SSE3:
Benjamin Kramera9992772010-01-09 17:55:51 +00001228 Builder.defineMacro("__SSE3__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001229 case SSE2:
Benjamin Kramera9992772010-01-09 17:55:51 +00001230 Builder.defineMacro("__SSE2__");
1231 Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001232 case SSE1:
Benjamin Kramera9992772010-01-09 17:55:51 +00001233 Builder.defineMacro("__SSE__");
1234 Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
Chris Lattner84f0ea82009-03-02 22:40:39 +00001235 case MMX:
Benjamin Kramera9992772010-01-09 17:55:51 +00001236 Builder.defineMacro("__MMX__");
Chris Lattner84f0ea82009-03-02 22:40:39 +00001237 case NoMMXSSE:
1238 break;
1239 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001240
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001241 if (Opts.Microsoft && PointerWidth == 32) {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001242 switch (SSELevel) {
Michael J. Spencera764e832010-10-21 08:22:51 +00001243 case SSE42:
1244 case SSE41:
1245 case SSSE3:
1246 case SSE3:
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001247 case SSE2:
1248 Builder.defineMacro("_M_IX86_FP", llvm::Twine(2));
1249 break;
1250 case SSE1:
1251 Builder.defineMacro("_M_IX86_FP", llvm::Twine(1));
1252 break;
1253 default:
1254 Builder.defineMacro("_M_IX86_FP", llvm::Twine(0));
1255 }
1256 }
1257
Anders Carlsson9b0fb622010-01-27 03:47:49 +00001258 // Each case falls through to the previous one here.
1259 switch (AMD3DNowLevel) {
1260 case AMD3DNowAthlon:
1261 Builder.defineMacro("__3dNOW_A__");
1262 case AMD3DNow:
1263 Builder.defineMacro("__3dNOW__");
1264 case NoAMD3DNow:
1265 break;
1266 }
Chris Lattnerc0f59212009-03-02 22:27:17 +00001267}
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001268
1269
Eli Friedman618234a2008-08-20 02:34:37 +00001270bool
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001271X86TargetInfo::validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001272 TargetInfo::ConstraintInfo &Info) const {
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001273 switch (*Name) {
Eli Friedman618234a2008-08-20 02:34:37 +00001274 default: return false;
Dale Johannesen545be512010-08-24 22:33:12 +00001275 case 'Y': // first letter of a pair:
1276 switch (*(Name+1)) {
1277 default: return false;
1278 case '0': // First SSE register.
1279 case 't': // Any SSE register, when SSE2 is enabled.
1280 case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
1281 case 'm': // any MMX register, when inter-unit moves enabled.
1282 break; // falls through to setAllowsRegister.
1283 }
Eli Friedman618234a2008-08-20 02:34:37 +00001284 case 'a': // eax.
1285 case 'b': // ebx.
1286 case 'c': // ecx.
1287 case 'd': // edx.
1288 case 'S': // esi.
1289 case 'D': // edi.
1290 case 'A': // edx:eax.
Dale Johannesen545be512010-08-24 22:33:12 +00001291 case 'f': // any x87 floating point stack register.
Eli Friedman618234a2008-08-20 02:34:37 +00001292 case 't': // top of floating point stack.
1293 case 'u': // second from top of floating point stack.
1294 case 'q': // Any register accessible as [r]l: a, b, c, and d.
Anders Carlssonfce09342008-10-06 00:41:45 +00001295 case 'y': // Any MMX register.
Anders Carlssona7406d42008-10-06 19:17:39 +00001296 case 'x': // Any SSE register.
Eli Friedman618234a2008-08-20 02:34:37 +00001297 case 'Q': // Any register accessible as [r]h: a, b, c, and d.
Dale Johannesen545be512010-08-24 22:33:12 +00001298 case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
1299 case 'l': // "Index" registers: any general register that can be used as an
1300 // index in a base+index memory access.
1301 Info.setAllowsRegister();
1302 return true;
1303 case 'C': // SSE floating point constant.
1304 case 'G': // x87 floating point constant.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001305 case 'e': // 32-bit signed integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001306 // x86_64 instructions.
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001307 case 'Z': // 32-bit unsigned integer constant for use with zero-extending
Anders Carlsson79bc64c2009-01-24 18:03:09 +00001308 // x86_64 instructions.
Eli Friedman618234a2008-08-20 02:34:37 +00001309 return true;
1310 }
Dale Johannesen545be512010-08-24 22:33:12 +00001311 return false;
Eli Friedman618234a2008-08-20 02:34:37 +00001312}
1313
Dale Johannesenf6e2c202010-10-29 23:12:32 +00001314const llvm::Type*
1315X86TargetInfo::adjustInlineAsmType(std::string& Constraint,
1316 const llvm::Type* Ty,
1317 llvm::LLVMContext &Context) const {
1318 if (Constraint=="y" && Ty->isVectorTy())
1319 return llvm::Type::getX86_MMXTy(Context);
1320 return Ty;
1321}
1322
1323
Eli Friedman618234a2008-08-20 02:34:37 +00001324std::string
1325X86TargetInfo::convertConstraint(const char Constraint) const {
1326 switch (Constraint) {
1327 case 'a': return std::string("{ax}");
1328 case 'b': return std::string("{bx}");
1329 case 'c': return std::string("{cx}");
1330 case 'd': return std::string("{dx}");
1331 case 'S': return std::string("{si}");
1332 case 'D': return std::string("{di}");
Dale Johannesencee55012010-10-22 21:07:10 +00001333 case 'p': // address
1334 return std::string("im");
Eli Friedman618234a2008-08-20 02:34:37 +00001335 case 't': // top of floating point stack.
1336 return std::string("{st}");
1337 case 'u': // second from top of floating point stack.
1338 return std::string("{st(1)}"); // second from top of floating point stack.
1339 default:
1340 return std::string(1, Constraint);
1341 }
1342}
Eli Friedman618234a2008-08-20 02:34:37 +00001343} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +00001344
1345namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001346// X86-32 generic target
1347class X86_32TargetInfo : public X86TargetInfo {
Reid Spencer5f016e22007-07-11 17:01:13 +00001348public:
Eli Friedman618234a2008-08-20 02:34:37 +00001349 X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) {
1350 DoubleAlign = LongLongAlign = 32;
1351 LongDoubleWidth = 96;
1352 LongDoubleAlign = 32;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001353 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1354 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001355 "a0:0:64-f80:32:32-n8:16:32";
Eli Friedman1afabd92009-03-29 20:31:09 +00001356 SizeType = UnsignedInt;
1357 PtrDiffType = SignedInt;
1358 IntPtrType = SignedInt;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001359 RegParmMax = 3;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001360
1361 // Use fpret for all types.
1362 RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
1363 (1 << TargetInfo::Double) |
1364 (1 << TargetInfo::LongDouble));
Eli Friedman618234a2008-08-20 02:34:37 +00001365 }
1366 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001367 return "typedef char* __builtin_va_list;";
Eli Friedman618234a2008-08-20 02:34:37 +00001368 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001369
Chris Lattner21fb98e2009-09-23 06:06:36 +00001370 int getEHDataRegisterNumber(unsigned RegNo) const {
1371 if (RegNo == 0) return 0;
1372 if (RegNo == 1) return 2;
1373 return -1;
1374 }
Eli Friedman618234a2008-08-20 02:34:37 +00001375};
1376} // end anonymous namespace
1377
1378namespace {
Eli Friedman624c1462009-07-05 18:47:56 +00001379class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
1380public:
1381 OpenBSDI386TargetInfo(const std::string& triple) :
1382 OpenBSDTargetInfo<X86_32TargetInfo>(triple) {
1383 SizeType = UnsignedLong;
1384 IntPtrType = SignedLong;
Eli Friedman6036ebe2009-07-05 22:31:18 +00001385 PtrDiffType = SignedLong;
Eli Friedman624c1462009-07-05 18:47:56 +00001386 }
1387};
1388} // end anonymous namespace
1389
1390namespace {
Torok Edwin5f6c1942009-06-30 17:10:35 +00001391class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
Eli Friedman618234a2008-08-20 02:34:37 +00001392public:
Torok Edwin5f6c1942009-06-30 17:10:35 +00001393 DarwinI386TargetInfo(const std::string& triple) :
1394 DarwinTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedman618234a2008-08-20 02:34:37 +00001395 LongDoubleWidth = 128;
1396 LongDoubleAlign = 128;
Eli Friedman1afabd92009-03-29 20:31:09 +00001397 SizeType = UnsignedLong;
1398 IntPtrType = SignedLong;
Eli Friedmaned855cb2008-08-21 00:13:15 +00001399 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1400 "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001401 "a0:0:64-f80:128:128-n8:16:32";
Daniel Dunbar613fd672010-05-27 00:35:16 +00001402 HasAlignMac68kSupport = true;
Torok Edwinb0a5b242009-06-30 17:00:25 +00001403 }
1404
Eli Friedman618234a2008-08-20 02:34:37 +00001405};
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +00001406} // end anonymous namespace
1407
1408namespace {
Eli Friedman29a30502008-08-21 01:40:19 +00001409// x86-32 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001410class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
Eli Friedman29a30502008-08-21 01:40:19 +00001411public:
1412 WindowsX86_32TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001413 : WindowsTargetInfo<X86_32TargetInfo>(triple) {
Eli Friedmanb030f022009-04-19 21:38:35 +00001414 TLSSupported = false;
Chris Lattner85de9e72009-06-24 17:12:15 +00001415 WCharType = UnsignedShort;
Eli Friedman9c2f84e2009-06-08 21:16:17 +00001416 DoubleAlign = LongLongAlign = 64;
1417 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 +00001418 "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-"
1419 "v128:128:128-a0:0:64-f80:32:32-n8:16:32";
Eli Friedman29a30502008-08-21 01:40:19 +00001420 }
Michael J. Spencera764e832010-10-21 08:22:51 +00001421 virtual void getTargetDefines(const LangOptions &Opts,
1422 MacroBuilder &Builder) const {
1423 WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
1424 }
1425};
1426} // end anonymous namespace
1427
1428namespace {
1429
1430// x86-32 Windows Visual Studio target
1431class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo {
1432public:
1433 VisualStudioWindowsX86_32TargetInfo(const std::string& triple)
1434 : WindowsX86_32TargetInfo(triple) {
1435 LongDoubleWidth = 64;
1436 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
1437 }
1438 virtual void getTargetDefines(const LangOptions &Opts,
1439 MacroBuilder &Builder) const {
1440 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
1441 WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
1442 // The value of the following reflects processor type.
1443 // 300=386, 400=486, 500=Pentium, 600=Blend (default)
1444 // We lost the original triple, so we use the default.
1445 Builder.defineMacro("_M_IX86", "600");
1446 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001447};
1448} // end anonymous namespace
1449
1450namespace {
1451// x86-32 MinGW target
1452class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
1453public:
1454 MinGWX86_32TargetInfo(const std::string& triple)
1455 : WindowsX86_32TargetInfo(triple) {
1456 }
1457 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001458 MacroBuilder &Builder) const {
1459 WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001460 DefineStd(Builder, "WIN32", Opts);
1461 DefineStd(Builder, "WINNT", Opts);
1462 Builder.defineMacro("_X86_");
Benjamin Kramera9992772010-01-09 17:55:51 +00001463 Builder.defineMacro("__MSVCRT__");
1464 Builder.defineMacro("__MINGW32__");
1465 Builder.defineMacro("__declspec", "__declspec");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001466 }
1467};
1468} // end anonymous namespace
1469
1470namespace {
1471// x86-32 Cygwin target
1472class CygwinX86_32TargetInfo : public X86_32TargetInfo {
1473public:
1474 CygwinX86_32TargetInfo(const std::string& triple)
1475 : X86_32TargetInfo(triple) {
1476 TLSSupported = false;
1477 WCharType = UnsignedShort;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001478 DoubleAlign = LongLongAlign = 64;
1479 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1480 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001481 "a0:0:64-f80:32:32-n8:16:32";
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001482 }
1483 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001484 MacroBuilder &Builder) const {
1485 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1486 Builder.defineMacro("__CYGWIN__");
1487 Builder.defineMacro("__CYGWIN32__");
1488 DefineStd(Builder, "unix", Opts);
Douglas Gregor2b003fd2010-04-21 05:52:38 +00001489 if (Opts.CPlusPlus)
1490 Builder.defineMacro("_GNU_SOURCE");
Eli Friedmanabc4e322009-06-08 06:11:14 +00001491 }
Eli Friedman29a30502008-08-21 01:40:19 +00001492};
1493} // end anonymous namespace
1494
1495namespace {
Chris Lattner86ed3a32010-04-11 19:29:39 +00001496// x86-32 Haiku target
1497class HaikuX86_32TargetInfo : public X86_32TargetInfo {
1498public:
1499 HaikuX86_32TargetInfo(const std::string& triple)
1500 : X86_32TargetInfo(triple) {
1501 SizeType = UnsignedLong;
Chris Lattnerfe1ea7b2010-04-22 17:48:00 +00001502 IntPtrType = SignedLong;
1503 PtrDiffType = SignedLong;
Rafael Espindola19ddda82010-11-09 16:41:02 +00001504 this->UserLabelPrefix = "";
Eli Friedmana7e68452010-08-22 01:00:03 +00001505 }
Chris Lattner86ed3a32010-04-11 19:29:39 +00001506 virtual void getTargetDefines(const LangOptions &Opts,
1507 MacroBuilder &Builder) const {
1508 X86_32TargetInfo::getTargetDefines(Opts, Builder);
1509 Builder.defineMacro("__INTEL__");
1510 Builder.defineMacro("__HAIKU__");
1511 }
1512};
1513} // end anonymous namespace
1514
1515namespace {
Eli Friedman618234a2008-08-20 02:34:37 +00001516// x86-64 generic target
1517class X86_64TargetInfo : public X86TargetInfo {
1518public:
Chris Lattner33328642009-03-20 15:52:06 +00001519 X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) {
Chris Lattnerf291b102008-05-09 06:17:04 +00001520 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +00001521 LongDoubleWidth = 128;
1522 LongDoubleAlign = 128;
Rafael Espindola6deecb02010-06-04 23:15:27 +00001523 LargeArrayMinWidth = 128;
1524 LargeArrayAlign = 128;
Chris Lattner06ebe862009-02-05 07:32:46 +00001525 IntMaxType = SignedLong;
1526 UIntMaxType = UnsignedLong;
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001527 Int64Type = SignedLong;
Anton Korobeynikov264a76c2009-04-03 23:38:25 +00001528 RegParmMax = 6;
Chris Lattner06ebe862009-02-05 07:32:46 +00001529
Eli Friedmaned855cb2008-08-21 00:13:15 +00001530 DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1531 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Chris Lattner1932e122009-11-07 18:59:41 +00001532 "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64";
Daniel Dunbardacf9dd2010-07-14 23:39:36 +00001533
1534 // Use fpret only for long double.
1535 RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
Reid Spencer5f016e22007-07-11 17:01:13 +00001536 }
Anders Carlssonfb5e5ba2007-10-13 00:45:48 +00001537 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00001538 return "typedef struct __va_list_tag {"
1539 " unsigned gp_offset;"
1540 " unsigned fp_offset;"
1541 " void* overflow_arg_area;"
1542 " void* reg_save_area;"
John McCall2b7baf02010-05-28 18:25:28 +00001543 "} __va_list_tag;"
Eli Friedmandc043162009-07-03 00:45:06 +00001544 "typedef __va_list_tag __builtin_va_list[1];";
Anders Carlsson3346ae62007-11-24 23:38:12 +00001545 }
Michael J. Spencer237cf582010-10-18 07:10:59 +00001546
Chris Lattner21fb98e2009-09-23 06:06:36 +00001547 int getEHDataRegisterNumber(unsigned RegNo) const {
1548 if (RegNo == 0) return 0;
1549 if (RegNo == 1) return 1;
1550 return -1;
1551 }
Eli Friedman618234a2008-08-20 02:34:37 +00001552};
1553} // end anonymous namespace
1554
1555namespace {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001556// x86-64 Windows target
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001557class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001558public:
1559 WindowsX86_64TargetInfo(const std::string& triple)
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001560 : WindowsTargetInfo<X86_64TargetInfo>(triple) {
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001561 TLSSupported = false;
1562 WCharType = UnsignedShort;
Mike Stumpa55cce82009-10-08 23:00:00 +00001563 LongWidth = LongAlign = 32;
Michael J. Spencer237cf582010-10-18 07:10:59 +00001564 DoubleAlign = LongLongAlign = 64;
Nate Begemandbf8ea42010-07-21 02:02:56 +00001565 IntMaxType = SignedLongLong;
1566 UIntMaxType = UnsignedLongLong;
1567 Int64Type = SignedLongLong;
Cameron Esfahani1484e0d2010-09-15 00:28:12 +00001568 SizeType = UnsignedLongLong;
1569 PtrDiffType = SignedLongLong;
1570 IntPtrType = SignedLongLong;
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001571 }
1572 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001573 MacroBuilder &Builder) const {
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001574 WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001575 Builder.defineMacro("_WIN64");
Michael J. Spencera764e832010-10-21 08:22:51 +00001576 }
1577};
1578} // end anonymous namespace
1579
1580namespace {
1581// x86-64 Windows Visual Studio target
1582class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo {
1583public:
1584 VisualStudioWindowsX86_64TargetInfo(const std::string& triple)
1585 : WindowsX86_64TargetInfo(triple) {
1586 }
1587 virtual void getTargetDefines(const LangOptions &Opts,
1588 MacroBuilder &Builder) const {
1589 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
1590 WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
Benjamin Kramera9992772010-01-09 17:55:51 +00001591 Builder.defineMacro("_M_X64");
Michael J. Spencerdae4ac42010-10-21 05:21:48 +00001592 Builder.defineMacro("_M_AMD64");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001593 }
Chris Lattnerf13721d2010-08-31 16:44:54 +00001594 virtual const char *getVAListDeclaration() const {
1595 return "typedef char* __builtin_va_list;";
1596 }
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001597};
1598} // end anonymous namespace
1599
1600namespace {
1601// x86-64 MinGW target
1602class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
1603public:
1604 MinGWX86_64TargetInfo(const std::string& triple)
1605 : WindowsX86_64TargetInfo(triple) {
1606 }
1607 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001608 MacroBuilder &Builder) const {
1609 WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
Michael J. Spencera764e832010-10-21 08:22:51 +00001610 DefineStd(Builder, "WIN64", Opts);
Benjamin Kramera9992772010-01-09 17:55:51 +00001611 Builder.defineMacro("__MSVCRT__");
1612 Builder.defineMacro("__MINGW64__");
1613 Builder.defineMacro("__declspec");
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00001614 }
1615};
1616} // end anonymous namespace
1617
1618namespace {
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001619class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
1620public:
Mike Stump1eb44332009-09-09 15:08:12 +00001621 DarwinX86_64TargetInfo(const std::string& triple)
Eli Friedman3c7b6e42009-07-01 03:36:11 +00001622 : DarwinTargetInfo<X86_64TargetInfo>(triple) {
1623 Int64Type = SignedLongLong;
1624 }
1625};
1626} // end anonymous namespace
1627
1628namespace {
Eli Friedman6036ebe2009-07-05 22:31:18 +00001629class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
1630public:
Mike Stump1eb44332009-09-09 15:08:12 +00001631 OpenBSDX86_64TargetInfo(const std::string& triple)
Eli Friedman6036ebe2009-07-05 22:31:18 +00001632 : OpenBSDTargetInfo<X86_64TargetInfo>(triple) {
1633 IntMaxType = SignedLongLong;
1634 UIntMaxType = UnsignedLongLong;
1635 Int64Type = SignedLongLong;
1636 }
1637};
1638} // end anonymous namespace
1639
1640namespace {
Eli Friedmana9f54962008-08-20 07:44:10 +00001641class ARMTargetInfo : public TargetInfo {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001642 // Possible FPU choices.
1643 enum FPUMode {
1644 NoFPU,
1645 VFP2FPU,
1646 VFP3FPU,
1647 NeonFPU
1648 };
1649
1650 static bool FPUModeIsVFP(FPUMode Mode) {
1651 return Mode >= VFP2FPU && Mode <= NeonFPU;
1652 }
1653
1654 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1655 static const char * const GCCRegNames[];
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001656
Daniel Dunbareac7c532009-12-18 18:42:37 +00001657 std::string ABI, CPU;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001658
1659 unsigned FPU : 3;
1660
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001661 unsigned IsThumb : 1;
1662
1663 // Initialized via features.
1664 unsigned SoftFloat : 1;
1665 unsigned SoftFloatABI : 1;
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001666
Chris Lattner2752c012010-03-03 19:03:45 +00001667 static const Builtin::Info BuiltinInfo[];
1668
Chris Lattner393ff042008-04-21 18:56:49 +00001669public:
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001670 ARMTargetInfo(const std::string &TripleStr)
Daniel Dunbareac7c532009-12-18 18:42:37 +00001671 : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s")
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001672 {
Daniel Dunbara2a41612009-09-14 00:02:24 +00001673 SizeType = UnsignedInt;
1674 PtrDiffType = SignedInt;
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001675
Chris Lattner9bffb072010-04-23 16:29:58 +00001676 // {} in inline assembly are neon specifiers, not assembly variant
1677 // specifiers.
1678 NoAsmVariants = true;
Michael J. Spencer20249a12010-10-21 03:16:25 +00001679
Daniel Dunbareac7c532009-12-18 18:42:37 +00001680 // FIXME: Should we just treat this as a feature?
Daniel Dunbar0791aa52009-12-18 19:57:13 +00001681 IsThumb = getTriple().getArchName().startswith("thumb");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001682 if (IsThumb) {
1683 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1684 "i64:64:64-f32:32:32-f64:64:64-"
Chris Lattner1932e122009-11-07 18:59:41 +00001685 "v64:64:64-v128:128:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001686 } else {
1687 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1688 "i64:64:64-f32:32:32-f64:64:64-"
Chris Lattner1932e122009-11-07 18:59:41 +00001689 "v64:64:64-v128:128:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001690 }
John McCallee79a4c2010-08-21 22:46:04 +00001691
1692 // ARM targets default to using the ARM C++ ABI.
1693 CXXABI = CXXABI_ARM;
Eli Friedman61538a72008-05-20 14:21:01 +00001694 }
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001695 virtual const char *getABI() const { return ABI.c_str(); }
Daniel Dunbara2a41612009-09-14 00:02:24 +00001696 virtual bool setABI(const std::string &Name) {
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001697 ABI = Name;
1698
Daniel Dunbara2a41612009-09-14 00:02:24 +00001699 // The defaults (above) are for AAPCS, check if we need to change them.
1700 //
1701 // FIXME: We need support for -meabi... we could just mangle it into the
1702 // name.
1703 if (Name == "apcs-gnu") {
Daniel Dunbard410fa22010-01-27 20:23:08 +00001704 DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
Daniel Dunbara2a41612009-09-14 00:02:24 +00001705 SizeType = UnsignedLong;
1706
Daniel Dunbar684de632010-04-22 16:14:54 +00001707 // Do not respect the alignment of bit-field types when laying out
1708 // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
1709 UseBitFieldTypeAlignment = false;
1710
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001711 if (IsThumb) {
1712 DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
1713 "i64:32:32-f32:32:32-f64:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001714 "v64:64:64-v128:128:128-a0:0:32-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001715 } else {
1716 DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
1717 "i64:32:32-f32:32:32-f64:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +00001718 "v64:64:64-v128:128:128-a0:0:64-n32");
Daniel Dunbardff10dc2009-09-22 21:44:58 +00001719 }
1720
Daniel Dunbara2a41612009-09-14 00:02:24 +00001721 // FIXME: Override "preferred align" for double and long long.
1722 } else if (Name == "aapcs") {
1723 // FIXME: Enumerated types are variable width in straight AAPCS.
1724 } else if (Name == "aapcs-linux") {
1725 ;
1726 } else
1727 return false;
1728
1729 return true;
1730 }
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001731
Daniel Dunbara91320b2009-12-21 23:28:17 +00001732 void getDefaultFeatures(const std::string &CPU,
1733 llvm::StringMap<bool> &Features) const {
1734 // FIXME: This should not be here.
1735 Features["vfp2"] = false;
1736 Features["vfp3"] = false;
1737 Features["neon"] = false;
1738
1739 if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
1740 Features["vfp2"] = true;
1741 else if (CPU == "cortex-a8" || CPU == "cortex-a9")
1742 Features["neon"] = true;
1743 }
Michael J. Spencer20249a12010-10-21 03:16:25 +00001744
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001745 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1746 const std::string &Name,
1747 bool Enabled) const {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001748 if (Name == "soft-float" || Name == "soft-float-abi") {
1749 Features[Name] = Enabled;
1750 } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") {
1751 // These effectively are a single option, reset them when any is enabled.
1752 if (Enabled)
1753 Features["vfp2"] = Features["vfp3"] = Features["neon"] = false;
1754 Features[Name] = Enabled;
1755 } else
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001756 return false;
1757
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001758 return true;
1759 }
1760
1761 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
Daniel Dunbara91320b2009-12-21 23:28:17 +00001762 FPU = NoFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001763 SoftFloat = SoftFloatABI = false;
1764 for (unsigned i = 0, e = Features.size(); i != e; ++i) {
1765 if (Features[i] == "+soft-float")
1766 SoftFloat = true;
1767 else if (Features[i] == "+soft-float-abi")
1768 SoftFloatABI = true;
Daniel Dunbara91320b2009-12-21 23:28:17 +00001769 else if (Features[i] == "+vfp2")
1770 FPU = VFP2FPU;
1771 else if (Features[i] == "+vfp3")
1772 FPU = VFP3FPU;
1773 else if (Features[i] == "+neon")
1774 FPU = NeonFPU;
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001775 }
1776
1777 // Remove front-end specific options which the backend handles differently.
1778 std::vector<std::string>::iterator it;
1779 it = std::find(Features.begin(), Features.end(), "+soft-float");
1780 if (it != Features.end())
1781 Features.erase(it);
1782 it = std::find(Features.begin(), Features.end(), "+soft-float-abi");
1783 if (it != Features.end())
1784 Features.erase(it);
1785 }
1786
Daniel Dunbareac7c532009-12-18 18:42:37 +00001787 static const char *getCPUDefineSuffix(llvm::StringRef Name) {
1788 return llvm::StringSwitch<const char*>(Name)
1789 .Cases("arm8", "arm810", "4")
1790 .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4")
1791 .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T")
1792 .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T")
1793 .Case("ep9312", "4T")
1794 .Cases("arm10tdmi", "arm1020t", "5T")
1795 .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE")
1796 .Case("arm926ej-s", "5TEJ")
1797 .Cases("arm10e", "arm1020e", "arm1022e", "5TE")
1798 .Cases("xscale", "iwmmxt", "5TE")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001799 .Case("arm1136j-s", "6J")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001800 .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK")
Daniel Dunbara91320b2009-12-21 23:28:17 +00001801 .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K")
Daniel Dunbareac7c532009-12-18 18:42:37 +00001802 .Cases("arm1156t2-s", "arm1156t2f-s", "6T2")
1803 .Cases("cortex-a8", "cortex-a9", "7A")
1804 .Default(0);
1805 }
1806 virtual bool setCPU(const std::string &Name) {
1807 if (!getCPUDefineSuffix(Name))
1808 return false;
1809
1810 CPU = Name;
1811 return true;
1812 }
Chris Lattner33328642009-03-20 15:52:06 +00001813 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00001814 MacroBuilder &Builder) const {
Chris Lattnerc0f59212009-03-02 22:27:17 +00001815 // Target identification.
Benjamin Kramera9992772010-01-09 17:55:51 +00001816 Builder.defineMacro("__arm");
1817 Builder.defineMacro("__arm__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001818
Chris Lattnerc0f59212009-03-02 22:27:17 +00001819 // Target properties.
Benjamin Kramera9992772010-01-09 17:55:51 +00001820 Builder.defineMacro("__ARMEL__");
1821 Builder.defineMacro("__LITTLE_ENDIAN__");
1822 Builder.defineMacro("__REGISTER_PREFIX__", "");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001823
1824 llvm::StringRef CPUArch = getCPUDefineSuffix(CPU);
Benjamin Kramera9992772010-01-09 17:55:51 +00001825 Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001826
Mike Stump437bb4b2009-04-08 02:07:04 +00001827 // Subtarget options.
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001828
Daniel Dunbareac7c532009-12-18 18:42:37 +00001829 // FIXME: It's more complicated than this and we don't really support
1830 // interworking.
1831 if ('5' <= CPUArch[0] && CPUArch[0] <= '7')
Benjamin Kramera9992772010-01-09 17:55:51 +00001832 Builder.defineMacro("__THUMB_INTERWORK__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001833
Daniel Dunbareac7c532009-12-18 18:42:37 +00001834 if (ABI == "aapcs" || ABI == "aapcs-linux")
Benjamin Kramera9992772010-01-09 17:55:51 +00001835 Builder.defineMacro("__ARM_EABI__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001836
Daniel Dunbar97f52ac2009-12-19 04:15:38 +00001837 if (SoftFloat)
Benjamin Kramera9992772010-01-09 17:55:51 +00001838 Builder.defineMacro("__SOFTFP__");
Daniel Dunbareac7c532009-12-18 18:42:37 +00001839
1840 if (CPU == "xscale")
Benjamin Kramera9992772010-01-09 17:55:51 +00001841 Builder.defineMacro("__XSCALE__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001842
Daniel Dunbara91320b2009-12-21 23:28:17 +00001843 bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7"));
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001844 if (IsThumb) {
Benjamin Kramera9992772010-01-09 17:55:51 +00001845 Builder.defineMacro("__THUMBEL__");
1846 Builder.defineMacro("__thumb__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001847 if (IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001848 Builder.defineMacro("__thumb2__");
Daniel Dunbare1f63b32009-09-17 16:21:10 +00001849 }
1850
1851 // Note, this is always on in gcc, even though it doesn't make sense.
Benjamin Kramera9992772010-01-09 17:55:51 +00001852 Builder.defineMacro("__APCS_32__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001853
1854 if (FPUModeIsVFP((FPUMode) FPU))
Benjamin Kramera9992772010-01-09 17:55:51 +00001855 Builder.defineMacro("__VFP_FP__");
Daniel Dunbara91320b2009-12-21 23:28:17 +00001856
1857 // This only gets set when Neon instructions are actually available, unlike
1858 // the VFP define, hence the soft float and arch check. This is subtly
1859 // different from gcc, we follow the intent which was that it should be set
1860 // when Neon instructions are actually available.
1861 if (FPU == NeonFPU && !SoftFloat && IsThumb2)
Benjamin Kramera9992772010-01-09 17:55:51 +00001862 Builder.defineMacro("__ARM_NEON__");
Chris Lattner393ff042008-04-21 18:56:49 +00001863 }
1864 virtual void getTargetBuiltins(const Builtin::Info *&Records,
1865 unsigned &NumRecords) const {
Chris Lattner2752c012010-03-03 19:03:45 +00001866 Records = BuiltinInfo;
1867 NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
Chris Lattner393ff042008-04-21 18:56:49 +00001868 }
1869 virtual const char *getVAListDeclaration() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001870 return "typedef char* __builtin_va_list;";
Chris Lattner393ff042008-04-21 18:56:49 +00001871 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001872 virtual void getGCCRegNames(const char * const *&Names,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001873 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00001874 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001875 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001876 virtual bool validateAsmConstraint(const char *&Name,
Chris Lattner44def072009-04-26 07:16:29 +00001877 TargetInfo::ConstraintInfo &Info) const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001878 // FIXME: Check if this is complete
Anders Carlsson066d2ea2009-02-28 17:11:49 +00001879 switch (*Name) {
Eli Friedmana9f54962008-08-20 07:44:10 +00001880 default:
Nate Begemanad487f42008-04-22 05:03:19 +00001881 case 'l': // r0-r7
1882 case 'h': // r8-r15
1883 case 'w': // VFP Floating point register single precision
1884 case 'P': // VFP Floating point register double precision
Chris Lattner44def072009-04-26 07:16:29 +00001885 Info.setAllowsRegister();
Nate Begemanad487f42008-04-22 05:03:19 +00001886 return true;
1887 }
Chris Lattner393ff042008-04-21 18:56:49 +00001888 return false;
1889 }
1890 virtual const char *getClobbers() const {
Eli Friedmana9f54962008-08-20 07:44:10 +00001891 // FIXME: Is this really right?
Chris Lattner393ff042008-04-21 18:56:49 +00001892 return "";
1893 }
1894};
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001895
1896const char * const ARMTargetInfo::GCCRegNames[] = {
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001897 // Integer registers
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001898 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001899 "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
1900
1901 // Float registers
1902 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
1903 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
1904 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001905 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
Daniel Dunbarbf3d5522010-08-11 02:17:20 +00001906
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001907 // Double registers
1908 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
1909 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
Dale Johannesend1455352010-10-28 01:05:37 +00001910 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
1911 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001912
1913 // Quad registers
Dale Johannesend1455352010-10-28 01:05:37 +00001914 "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
1915 "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001916};
1917
1918void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001919 unsigned &NumNames) const {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001920 Names = GCCRegNames;
1921 NumNames = llvm::array_lengthof(GCCRegNames);
1922}
1923
1924const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001925 { { "a1" }, "r0" },
1926 { { "a2" }, "r1" },
1927 { { "a3" }, "r2" },
1928 { { "a4" }, "r3" },
1929 { { "v1" }, "r4" },
1930 { { "v2" }, "r5" },
1931 { { "v3" }, "r6" },
1932 { { "v4" }, "r7" },
1933 { { "v5" }, "r8" },
1934 { { "v6", "rfp" }, "r9" },
1935 { { "sl" }, "r10" },
1936 { { "fp" }, "r11" },
1937 { { "ip" }, "r12" },
Daniel Dunbar1fd71712010-08-11 02:17:11 +00001938 { { "r13" }, "sp" },
1939 { { "r14" }, "lr" },
1940 { { "r15" }, "pc" },
Dale Johannesen20eb49b2010-10-27 23:34:42 +00001941 // The S, D and Q registers overlap, but aren't really aliases; we
1942 // don't want to substitute one of these for a different-sized one.
Daniel Dunbarc1f2cdd2009-09-17 07:03:19 +00001943};
1944
1945void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
1946 unsigned &NumAliases) const {
1947 Aliases = GCCRegAliases;
1948 NumAliases = llvm::array_lengthof(GCCRegAliases);
1949}
Chris Lattner2752c012010-03-03 19:03:45 +00001950
1951const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
Fariborz Jahanian67aba812010-11-30 17:35:24 +00001952#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
1953#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
1954 ALL_LANGUAGES, false },
Chris Lattner2752c012010-03-03 19:03:45 +00001955#include "clang/Basic/BuiltinsARM.def"
1956};
Chris Lattner393ff042008-04-21 18:56:49 +00001957} // end anonymous namespace.
1958
Eli Friedmana9f54962008-08-20 07:44:10 +00001959
1960namespace {
Mike Stump1eb44332009-09-09 15:08:12 +00001961class DarwinARMTargetInfo :
Torok Edwin5f6c1942009-06-30 17:10:35 +00001962 public DarwinTargetInfo<ARMTargetInfo> {
1963protected:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00001964 virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
Benjamin Kramera9992772010-01-09 17:55:51 +00001965 MacroBuilder &Builder) const {
Daniel Dunbar21ae3192010-01-26 01:44:04 +00001966 getDarwinDefines(Builder, Opts, Triple);
Eli Friedmanb030f022009-04-19 21:38:35 +00001967 }
Eli Friedmana9f54962008-08-20 07:44:10 +00001968
Torok Edwin5f6c1942009-06-30 17:10:35 +00001969public:
Mike Stump1eb44332009-09-09 15:08:12 +00001970 DarwinARMTargetInfo(const std::string& triple)
Daniel Dunbar350b9f32010-05-27 07:00:26 +00001971 : DarwinTargetInfo<ARMTargetInfo>(triple) {
1972 HasAlignMac68kSupport = true;
1973 }
Eli Friedmana9f54962008-08-20 07:44:10 +00001974};
1975} // end anonymous namespace.
1976
Reid Spencer5f016e22007-07-11 17:01:13 +00001977namespace {
Eli Friedman01b86682008-08-20 07:28:14 +00001978class SparcV8TargetInfo : public TargetInfo {
Chris Lattnere957f532009-01-27 01:58:38 +00001979 static const TargetInfo::GCCRegAlias GCCRegAliases[];
1980 static const char * const GCCRegNames[];
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00001981 bool SoftFloat;
Gabor Greif26658672008-02-21 16:29:08 +00001982public:
Eli Friedman01b86682008-08-20 07:28:14 +00001983 SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) {
1984 // FIXME: Support Sparc quad-precision long double?
Eli Friedmaned855cb2008-08-21 00:13:15 +00001985 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 +00001986 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
Eli Friedman01b86682008-08-20 07:28:14 +00001987 }
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00001988 virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
1989 const std::string &Name,
1990 bool Enabled) const {
1991 if (Name == "soft-float")
1992 Features[Name] = Enabled;
1993 else
1994 return false;
1995
1996 return true;
1997 }
1998 virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
1999 SoftFloat = false;
2000 for (unsigned i = 0, e = Features.size(); i != e; ++i)
2001 if (Features[i] == "+soft-float")
2002 SoftFloat = true;
2003 }
Chris Lattner33328642009-03-20 15:52:06 +00002004 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002005 MacroBuilder &Builder) const {
2006 DefineStd(Builder, "sparc", Opts);
2007 Builder.defineMacro("__sparcv8");
2008 Builder.defineMacro("__REGISTER_PREFIX__", "");
Bruno Cardoso Lopes9284d212010-11-09 17:21:19 +00002009
2010 if (SoftFloat)
2011 Builder.defineMacro("SOFT_FLOAT", "1");
Gabor Greif26658672008-02-21 16:29:08 +00002012 }
2013 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2014 unsigned &NumRecords) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002015 // FIXME: Implement!
Gabor Greif26658672008-02-21 16:29:08 +00002016 }
2017 virtual const char *getVAListDeclaration() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002018 return "typedef void* __builtin_va_list;";
Gabor Greif26658672008-02-21 16:29:08 +00002019 }
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002020 virtual void getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002021 unsigned &NumNames) const;
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002022 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002023 unsigned &NumAliases) const;
Anders Carlsson066d2ea2009-02-28 17:11:49 +00002024 virtual bool validateAsmConstraint(const char *&Name,
Gabor Greif26658672008-02-21 16:29:08 +00002025 TargetInfo::ConstraintInfo &info) const {
Eli Friedman01b86682008-08-20 07:28:14 +00002026 // FIXME: Implement!
2027 return false;
Gabor Greif26658672008-02-21 16:29:08 +00002028 }
2029 virtual const char *getClobbers() const {
Eli Friedman01b86682008-08-20 07:28:14 +00002030 // FIXME: Implement!
2031 return "";
Gabor Greif26658672008-02-21 16:29:08 +00002032 }
2033};
2034
Chris Lattnere957f532009-01-27 01:58:38 +00002035const char * const SparcV8TargetInfo::GCCRegNames[] = {
2036 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2037 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
2038 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
2039 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
2040};
2041
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002042void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names,
Chris Lattnere957f532009-01-27 01:58:38 +00002043 unsigned &NumNames) const {
2044 Names = GCCRegNames;
2045 NumNames = llvm::array_lengthof(GCCRegNames);
2046}
2047
2048const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = {
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002049 { { "g0" }, "r0" },
2050 { { "g1" }, "r1" },
2051 { { "g2" }, "r2" },
2052 { { "g3" }, "r3" },
2053 { { "g4" }, "r4" },
2054 { { "g5" }, "r5" },
2055 { { "g6" }, "r6" },
2056 { { "g7" }, "r7" },
2057 { { "o0" }, "r8" },
2058 { { "o1" }, "r9" },
2059 { { "o2" }, "r10" },
2060 { { "o3" }, "r11" },
2061 { { "o4" }, "r12" },
2062 { { "o5" }, "r13" },
2063 { { "o6", "sp" }, "r14" },
2064 { { "o7" }, "r15" },
2065 { { "l0" }, "r16" },
2066 { { "l1" }, "r17" },
2067 { { "l2" }, "r18" },
2068 { { "l3" }, "r19" },
2069 { { "l4" }, "r20" },
2070 { { "l5" }, "r21" },
2071 { { "l6" }, "r22" },
2072 { { "l7" }, "r23" },
2073 { { "i0" }, "r24" },
2074 { { "i1" }, "r25" },
2075 { { "i2" }, "r26" },
2076 { { "i3" }, "r27" },
2077 { { "i4" }, "r28" },
2078 { { "i5" }, "r29" },
2079 { { "i6", "fp" }, "r30" },
2080 { { "i7" }, "r31" },
Chris Lattnere957f532009-01-27 01:58:38 +00002081};
2082
Anton Korobeynikova7c47172009-05-03 13:42:53 +00002083void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
Chris Lattnere957f532009-01-27 01:58:38 +00002084 unsigned &NumAliases) const {
2085 Aliases = GCCRegAliases;
2086 NumAliases = llvm::array_lengthof(GCCRegAliases);
2087}
Gabor Greif26658672008-02-21 16:29:08 +00002088} // end anonymous namespace.
2089
Eli Friedman01b86682008-08-20 07:28:14 +00002090namespace {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002091class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> {
2092public:
2093 AuroraUXSparcV8TargetInfo(const std::string& triple) :
2094 AuroraUXTargetInfo<SparcV8TargetInfo>(triple) {
2095 SizeType = UnsignedInt;
2096 PtrDiffType = SignedInt;
2097 }
2098};
Torok Edwin5f6c1942009-06-30 17:10:35 +00002099class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> {
Eli Friedman01b86682008-08-20 07:28:14 +00002100public:
2101 SolarisSparcV8TargetInfo(const std::string& triple) :
Torok Edwin5f6c1942009-06-30 17:10:35 +00002102 SolarisTargetInfo<SparcV8TargetInfo>(triple) {
Eli Friedmanf509d732008-11-02 02:43:55 +00002103 SizeType = UnsignedInt;
2104 PtrDiffType = SignedInt;
Eli Friedman01b86682008-08-20 07:28:14 +00002105 }
2106};
2107} // end anonymous namespace.
Reid Spencer5f016e22007-07-11 17:01:13 +00002108
Chris Lattner2621fd12008-05-08 05:58:21 +00002109namespace {
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002110 class MSP430TargetInfo : public TargetInfo {
2111 static const char * const GCCRegNames[];
2112 public:
2113 MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) {
2114 TLSSupported = false;
Anton Korobeynikov09f52a62010-01-30 12:55:11 +00002115 IntWidth = 16; IntAlign = 16;
2116 LongWidth = 32; LongLongWidth = 64;
2117 LongAlign = LongLongAlign = 16;
2118 PointerWidth = 16; PointerAlign = 16;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002119 SizeType = UnsignedInt;
2120 IntMaxType = SignedLong;
2121 UIntMaxType = UnsignedLong;
2122 IntPtrType = SignedShort;
2123 PtrDiffType = SignedInt;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +00002124 SigAtomicType = SignedLong;
Anton Korobeynikov5d7c2512009-12-19 01:32:37 +00002125 DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002126 }
2127 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002128 MacroBuilder &Builder) const {
2129 Builder.defineMacro("MSP430");
2130 Builder.defineMacro("__MSP430__");
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002131 // FIXME: defines for different 'flavours' of MCU
2132 }
2133 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2134 unsigned &NumRecords) const {
2135 // FIXME: Implement.
2136 Records = 0;
2137 NumRecords = 0;
2138 }
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002139 virtual void getGCCRegNames(const char * const *&Names,
2140 unsigned &NumNames) const;
2141 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2142 unsigned &NumAliases) const {
2143 // No aliases.
2144 Aliases = 0;
2145 NumAliases = 0;
2146 }
2147 virtual bool validateAsmConstraint(const char *&Name,
2148 TargetInfo::ConstraintInfo &info) const {
Anton Korobeynikov03265b62009-10-15 23:17:13 +00002149 // No target constraints for now.
2150 return false;
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002151 }
2152 virtual const char *getClobbers() const {
2153 // FIXME: Is this really right?
2154 return "";
2155 }
2156 virtual const char *getVAListDeclaration() const {
2157 // FIXME: implement
Anton Korobeynikoveb716852009-05-08 18:24:57 +00002158 return "typedef char* __builtin_va_list;";
Anton Korobeynikov73c64e52009-05-03 13:43:08 +00002159 }
2160 };
2161
2162 const char * const MSP430TargetInfo::GCCRegNames[] = {
2163 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2164 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2165 };
2166
2167 void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
2168 unsigned &NumNames) const {
2169 Names = GCCRegNames;
2170 NumNames = llvm::array_lengthof(GCCRegNames);
2171 }
2172}
2173
2174
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002175namespace {
2176 class SystemZTargetInfo : public TargetInfo {
2177 static const char * const GCCRegNames[];
2178 public:
2179 SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) {
2180 TLSSupported = false;
2181 IntWidth = IntAlign = 32;
2182 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
2183 PointerWidth = PointerAlign = 64;
Chris Lattner1932e122009-11-07 18:59:41 +00002184 DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-"
2185 "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64";
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002186 }
2187 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002188 MacroBuilder &Builder) const {
2189 Builder.defineMacro("__s390__");
2190 Builder.defineMacro("__s390x__");
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002191 }
2192 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2193 unsigned &NumRecords) const {
2194 // FIXME: Implement.
2195 Records = 0;
2196 NumRecords = 0;
2197 }
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002198
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002199 virtual void getGCCRegNames(const char * const *&Names,
2200 unsigned &NumNames) const;
2201 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2202 unsigned &NumAliases) const {
2203 // No aliases.
2204 Aliases = 0;
2205 NumAliases = 0;
2206 }
2207 virtual bool validateAsmConstraint(const char *&Name,
2208 TargetInfo::ConstraintInfo &info) const {
2209 // FIXME: implement
2210 return true;
2211 }
2212 virtual const char *getClobbers() const {
2213 // FIXME: Is this really right?
2214 return "";
2215 }
2216 virtual const char *getVAListDeclaration() const {
2217 // FIXME: implement
2218 return "typedef char* __builtin_va_list;";
2219 }
2220 };
2221
2222 const char * const SystemZTargetInfo::GCCRegNames[] = {
2223 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2224 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2225 };
2226
2227 void SystemZTargetInfo::getGCCRegNames(const char * const *&Names,
2228 unsigned &NumNames) const {
2229 Names = GCCRegNames;
2230 NumNames = llvm::array_lengthof(GCCRegNames);
2231 }
2232}
2233
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002234namespace {
2235 class BlackfinTargetInfo : public TargetInfo {
2236 static const char * const GCCRegNames[];
2237 public:
2238 BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) {
2239 TLSSupported = false;
2240 DoubleAlign = 32;
2241 LongLongAlign = 32;
2242 LongDoubleAlign = 32;
Chris Lattner1932e122009-11-07 18:59:41 +00002243 DescriptionString = "e-p:32:32-i64:32-f64:32-n32";
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002244 }
2245
2246 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002247 MacroBuilder &Builder) const {
2248 DefineStd(Builder, "bfin", Opts);
2249 DefineStd(Builder, "BFIN", Opts);
2250 Builder.defineMacro("__ADSPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002251 // FIXME: This one is really dependent on -mcpu
Benjamin Kramera9992772010-01-09 17:55:51 +00002252 Builder.defineMacro("__ADSPLPBLACKFIN__");
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002253 // FIXME: Add cpu-dependent defines and __SILICON_REVISION__
2254 }
2255
2256 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2257 unsigned &NumRecords) const {
2258 // FIXME: Implement.
2259 Records = 0;
2260 NumRecords = 0;
2261 }
2262
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002263 virtual void getGCCRegNames(const char * const *&Names,
2264 unsigned &NumNames) const;
2265
2266 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2267 unsigned &NumAliases) const {
2268 // No aliases.
2269 Aliases = 0;
2270 NumAliases = 0;
2271 }
2272
2273 virtual bool validateAsmConstraint(const char *&Name,
2274 TargetInfo::ConstraintInfo &Info) const {
2275 if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) {
2276 Info.setAllowsRegister();
2277 return true;
2278 }
2279 return false;
2280 }
2281
2282 virtual const char *getClobbers() const {
2283 return "";
2284 }
2285
2286 virtual const char *getVAListDeclaration() const {
2287 return "typedef char* __builtin_va_list;";
2288 }
2289 };
2290
2291 const char * const BlackfinTargetInfo::GCCRegNames[] = {
2292 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2293 "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp",
2294 "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3",
2295 "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3",
2296 "a0", "a1", "cc",
2297 "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp",
2298 "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1"
2299 };
2300
2301 void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names,
2302 unsigned &NumNames) const {
2303 Names = GCCRegNames;
2304 NumNames = llvm::array_lengthof(GCCRegNames);
2305 }
2306}
2307
Eli Friedmanb63decf2009-08-19 20:47:07 +00002308namespace {
2309
Mike Stump1eb44332009-09-09 15:08:12 +00002310 // LLVM and Clang cannot be used directly to output native binaries for
2311 // target, but is used to compile C code to llvm bitcode with correct
Eli Friedmanb63decf2009-08-19 20:47:07 +00002312 // type and alignment information.
Mike Stump1eb44332009-09-09 15:08:12 +00002313 //
2314 // TCE uses the llvm bitcode as input and uses it for generating customized
2315 // target processor and program binary. TCE co-design environment is
Eli Friedmanb63decf2009-08-19 20:47:07 +00002316 // publicly available in http://tce.cs.tut.fi
2317
2318 class TCETargetInfo : public TargetInfo{
2319 public:
2320 TCETargetInfo(const std::string& triple) : TargetInfo(triple) {
2321 TLSSupported = false;
2322 IntWidth = 32;
2323 LongWidth = LongLongWidth = 32;
Eli Friedmanb63decf2009-08-19 20:47:07 +00002324 PointerWidth = 32;
2325 IntAlign = 32;
2326 LongAlign = LongLongAlign = 32;
2327 PointerAlign = 32;
2328 SizeType = UnsignedInt;
2329 IntMaxType = SignedLong;
2330 UIntMaxType = UnsignedLong;
2331 IntPtrType = SignedInt;
2332 PtrDiffType = SignedInt;
2333 FloatWidth = 32;
2334 FloatAlign = 32;
2335 DoubleWidth = 32;
2336 DoubleAlign = 32;
2337 LongDoubleWidth = 32;
2338 LongDoubleAlign = 32;
2339 FloatFormat = &llvm::APFloat::IEEEsingle;
2340 DoubleFormat = &llvm::APFloat::IEEEsingle;
2341 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
Chris Lattner3a47c4e2010-03-04 21:07:38 +00002342 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-"
2343 "i16:16:32-i32:32:32-i64:32:32-"
2344 "f32:32:32-f64:64:64-v64:64:64-"
2345 "v128:128:128-a0:0:64-n32";
Eli Friedmanb63decf2009-08-19 20:47:07 +00002346 }
2347
2348 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002349 MacroBuilder &Builder) const {
2350 DefineStd(Builder, "tce", Opts);
2351 Builder.defineMacro("__TCE__");
2352 Builder.defineMacro("__TCE_V1__");
Eli Friedmanb63decf2009-08-19 20:47:07 +00002353 }
2354 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2355 unsigned &NumRecords) const {}
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00002356 virtual const char *getClobbers() const {
2357 return "";
2358 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002359 virtual const char *getVAListDeclaration() const {
2360 return "typedef void* __builtin_va_list;";
2361 }
Eli Friedmanb63decf2009-08-19 20:47:07 +00002362 virtual void getGCCRegNames(const char * const *&Names,
2363 unsigned &NumNames) const {}
2364 virtual bool validateAsmConstraint(const char *&Name,
2365 TargetInfo::ConstraintInfo &info) const {
2366 return true;
2367 }
2368 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2369 unsigned &NumAliases) const {}
2370 };
2371}
2372
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002373namespace {
2374class MipsTargetInfo : public TargetInfo {
Eric Christophered734732010-03-02 02:41:08 +00002375 std::string ABI, CPU;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002376 static const TargetInfo::GCCRegAlias GCCRegAliases[];
2377 static const char * const GCCRegNames[];
2378public:
Eric Christophered734732010-03-02 02:41:08 +00002379 MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") {
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002380 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2381 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2382 }
Eric Christophered734732010-03-02 02:41:08 +00002383 virtual const char *getABI() const { return ABI.c_str(); }
2384 virtual bool setABI(const std::string &Name) {
2385
2386 if ((Name == "o32") || (Name == "eabi")) {
2387 ABI = Name;
2388 return true;
2389 } else
2390 return false;
2391 }
2392 virtual bool setCPU(const std::string &Name) {
2393 CPU = Name;
2394 return true;
2395 }
2396 void getDefaultFeatures(const std::string &CPU,
2397 llvm::StringMap<bool> &Features) const {
2398 Features[ABI] = true;
2399 Features[CPU] = true;
2400 }
2401 virtual void getArchDefines(const LangOptions &Opts,
2402 MacroBuilder &Builder) const {
2403 if (ABI == "o32")
2404 Builder.defineMacro("__mips_o32");
2405 else if (ABI == "eabi")
2406 Builder.defineMacro("__mips_eabi");
2407 }
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002408 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002409 MacroBuilder &Builder) const {
2410 DefineStd(Builder, "mips", Opts);
2411 Builder.defineMacro("_mips");
2412 DefineStd(Builder, "MIPSEB", Opts);
2413 Builder.defineMacro("_MIPSEB");
2414 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002415 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002416 }
2417 virtual void getTargetBuiltins(const Builtin::Info *&Records,
2418 unsigned &NumRecords) const {
2419 // FIXME: Implement!
2420 }
2421 virtual const char *getVAListDeclaration() const {
2422 return "typedef void* __builtin_va_list;";
2423 }
2424 virtual void getGCCRegNames(const char * const *&Names,
2425 unsigned &NumNames) const;
2426 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
2427 unsigned &NumAliases) const;
2428 virtual bool validateAsmConstraint(const char *&Name,
2429 TargetInfo::ConstraintInfo &Info) const {
2430 switch (*Name) {
2431 default:
2432 case 'r': // CPU registers.
2433 case 'd': // Equivalent to "r" unless generating MIPS16 code.
2434 case 'y': // Equivalent to "r", backwards compatibility only.
2435 case 'f': // floating-point registers.
2436 Info.setAllowsRegister();
2437 return true;
2438 }
2439 return false;
2440 }
2441
2442 virtual const char *getClobbers() const {
2443 // FIXME: Implement!
2444 return "";
2445 }
2446};
2447
2448const char * const MipsTargetInfo::GCCRegNames[] = {
Michael J. Spencer20249a12010-10-21 03:16:25 +00002449 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002450 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
2451 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
2452 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
2453 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
2454 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
2455 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
2456 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
2457 "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
2458 "$fcc5","$fcc6","$fcc7"
2459};
2460
2461void MipsTargetInfo::getGCCRegNames(const char * const *&Names,
2462 unsigned &NumNames) const {
2463 Names = GCCRegNames;
2464 NumNames = llvm::array_lengthof(GCCRegNames);
2465}
2466
2467const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = {
2468 { { "at" }, "$1" },
2469 { { "v0" }, "$2" },
2470 { { "v1" }, "$3" },
2471 { { "a0" }, "$4" },
2472 { { "a1" }, "$5" },
2473 { { "a2" }, "$6" },
2474 { { "a3" }, "$7" },
2475 { { "t0" }, "$8" },
2476 { { "t1" }, "$9" },
2477 { { "t2" }, "$10" },
2478 { { "t3" }, "$11" },
2479 { { "t4" }, "$12" },
2480 { { "t5" }, "$13" },
2481 { { "t6" }, "$14" },
2482 { { "t7" }, "$15" },
2483 { { "s0" }, "$16" },
2484 { { "s1" }, "$17" },
2485 { { "s2" }, "$18" },
2486 { { "s3" }, "$19" },
2487 { { "s4" }, "$20" },
2488 { { "s5" }, "$21" },
2489 { { "s6" }, "$22" },
2490 { { "s7" }, "$23" },
2491 { { "t8" }, "$24" },
2492 { { "t9" }, "$25" },
2493 { { "k0" }, "$26" },
2494 { { "k1" }, "$27" },
2495 { { "gp" }, "$28" },
2496 { { "sp" }, "$29" },
2497 { { "fp" }, "$30" },
2498 { { "ra" }, "$31" }
2499};
2500
2501void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
2502 unsigned &NumAliases) const {
2503 Aliases = GCCRegAliases;
2504 NumAliases = llvm::array_lengthof(GCCRegAliases);
2505}
2506} // end anonymous namespace.
2507
2508namespace {
2509class MipselTargetInfo : public MipsTargetInfo {
2510public:
2511 MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) {
2512 DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-"
2513 "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32";
2514 }
2515
2516 virtual void getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002517 MacroBuilder &Builder) const;
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002518};
2519
2520void MipselTargetInfo::getTargetDefines(const LangOptions &Opts,
Benjamin Kramera9992772010-01-09 17:55:51 +00002521 MacroBuilder &Builder) const {
2522 DefineStd(Builder, "mips", Opts);
2523 Builder.defineMacro("_mips");
2524 DefineStd(Builder, "MIPSEL", Opts);
2525 Builder.defineMacro("_MIPSEL");
2526 Builder.defineMacro("__REGISTER_PREFIX__", "");
Eric Christophered734732010-03-02 02:41:08 +00002527 getArchDefines(Opts, Builder);
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002528}
2529} // end anonymous namespace.
2530
Reid Spencer5f016e22007-07-11 17:01:13 +00002531//===----------------------------------------------------------------------===//
2532// Driver code
2533//===----------------------------------------------------------------------===//
2534
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002535static TargetInfo *AllocateTarget(const std::string &T) {
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002536 llvm::Triple Triple(T);
2537 llvm::Triple::OSType os = Triple.getOS();
Eli Friedman61538a72008-05-20 14:21:01 +00002538
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002539 switch (Triple.getArch()) {
2540 default:
2541 return NULL;
Eli Friedman61538a72008-05-20 14:21:01 +00002542
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002543 case llvm::Triple::arm:
Daniel Dunbarf4aa4f612009-09-11 01:14:50 +00002544 case llvm::Triple::thumb:
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002545 switch (os) {
Rafael Espindola022a8a52010-06-10 00:46:51 +00002546 case llvm::Triple::Linux:
2547 return new LinuxTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002548 case llvm::Triple::Darwin:
Eli Friedmaned855cb2008-08-21 00:13:15 +00002549 return new DarwinARMTargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002550 case llvm::Triple::FreeBSD:
Torok Edwin5f6c1942009-06-30 17:10:35 +00002551 return new FreeBSDTargetInfo<ARMTargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002552 default:
2553 return new ARMTargetInfo(T);
2554 }
Eli Friedman61538a72008-05-20 14:21:01 +00002555
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002556 case llvm::Triple::bfin:
Jakob Stoklund Olesen1eb43432009-08-17 20:08:44 +00002557 return new BlackfinTargetInfo(T);
2558
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002559 case llvm::Triple::msp430:
2560 return new MSP430TargetInfo(T);
Eli Friedman61538a72008-05-20 14:21:01 +00002561
Edward O'Callaghan84423a82009-11-15 10:22:07 +00002562 case llvm::Triple::mips:
2563 if (os == llvm::Triple::Psp)
2564 return new PSPTargetInfo<MipsTargetInfo>(T);
2565 if (os == llvm::Triple::Linux)
2566 return new LinuxTargetInfo<MipsTargetInfo>(T);
2567 return new MipsTargetInfo(T);
2568
2569 case llvm::Triple::mipsel:
2570 if (os == llvm::Triple::Psp)
2571 return new PSPTargetInfo<MipselTargetInfo>(T);
2572 if (os == llvm::Triple::Linux)
2573 return new LinuxTargetInfo<MipselTargetInfo>(T);
2574 return new MipselTargetInfo(T);
2575
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002576 case llvm::Triple::ppc:
2577 if (os == llvm::Triple::Darwin)
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00002578 return new DarwinPPCTargetInfo(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002579 else if (os == llvm::Triple::FreeBSD)
2580 return new FreeBSDTargetInfo<PPC32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002581 return new PPC32TargetInfo(T);
2582
2583 case llvm::Triple::ppc64:
2584 if (os == llvm::Triple::Darwin)
Daniel Dunbar4c6a2262010-05-30 00:07:30 +00002585 return new DarwinPPC64TargetInfo(T);
John Thompson3f6918a2009-11-19 17:18:50 +00002586 else if (os == llvm::Triple::Lv2)
2587 return new PS3PPUTargetInfo<PPC64TargetInfo>(T);
Chris Lattnere03ae302010-02-16 18:14:57 +00002588 else if (os == llvm::Triple::FreeBSD)
2589 return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002590 return new PPC64TargetInfo(T);
2591
Chris Lattner9cbeb632010-03-06 21:21:27 +00002592 case llvm::Triple::mblaze:
2593 return new MBlazeTargetInfo(T);
2594
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002595 case llvm::Triple::sparc:
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002596 if (os == llvm::Triple::AuroraUX)
2597 return new AuroraUXSparcV8TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002598 if (os == llvm::Triple::Solaris)
2599 return new SolarisSparcV8TargetInfo(T);
2600 return new SparcV8TargetInfo(T);
2601
John Thompson3f6918a2009-11-19 17:18:50 +00002602 // FIXME: Need a real SPU target.
2603 case llvm::Triple::cellspu:
2604 return new PS3SPUTargetInfo<PPC64TargetInfo>(T);
2605
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002606 case llvm::Triple::systemz:
2607 return new SystemZTargetInfo(T);
2608
Eli Friedmanb63decf2009-08-19 20:47:07 +00002609 case llvm::Triple::tce:
2610 return new TCETargetInfo(T);
2611
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002612 case llvm::Triple::x86:
2613 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002614 case llvm::Triple::AuroraUX:
2615 return new AuroraUXTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002616 case llvm::Triple::Darwin:
2617 return new DarwinI386TargetInfo(T);
2618 case llvm::Triple::Linux:
2619 return new LinuxTargetInfo<X86_32TargetInfo>(T);
2620 case llvm::Triple::DragonFly:
2621 return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T);
2622 case llvm::Triple::NetBSD:
2623 return new NetBSDTargetInfo<X86_32TargetInfo>(T);
2624 case llvm::Triple::OpenBSD:
2625 return new OpenBSDI386TargetInfo(T);
2626 case llvm::Triple::FreeBSD:
2627 return new FreeBSDTargetInfo<X86_32TargetInfo>(T);
Chris Lattner38e317d2010-07-07 16:01:42 +00002628 case llvm::Triple::Minix:
2629 return new MinixTargetInfo<X86_32TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002630 case llvm::Triple::Solaris:
2631 return new SolarisTargetInfo<X86_32TargetInfo>(T);
2632 case llvm::Triple::Cygwin:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002633 return new CygwinX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002634 case llvm::Triple::MinGW32:
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002635 return new MinGWX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002636 case llvm::Triple::Win32:
Michael J. Spencera764e832010-10-21 08:22:51 +00002637 return new VisualStudioWindowsX86_32TargetInfo(T);
Chris Lattner86ed3a32010-04-11 19:29:39 +00002638 case llvm::Triple::Haiku:
2639 return new HaikuX86_32TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002640 default:
2641 return new X86_32TargetInfo(T);
2642 }
2643
2644 case llvm::Triple::x86_64:
2645 switch (os) {
Edward O'Callaghan991f9a72009-10-18 13:33:59 +00002646 case llvm::Triple::AuroraUX:
2647 return new AuroraUXTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002648 case llvm::Triple::Darwin:
2649 return new DarwinX86_64TargetInfo(T);
2650 case llvm::Triple::Linux:
2651 return new LinuxTargetInfo<X86_64TargetInfo>(T);
Chris Lattner7a7ca282010-01-09 05:41:14 +00002652 case llvm::Triple::DragonFly:
2653 return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002654 case llvm::Triple::NetBSD:
2655 return new NetBSDTargetInfo<X86_64TargetInfo>(T);
2656 case llvm::Triple::OpenBSD:
2657 return new OpenBSDX86_64TargetInfo(T);
2658 case llvm::Triple::FreeBSD:
2659 return new FreeBSDTargetInfo<X86_64TargetInfo>(T);
2660 case llvm::Triple::Solaris:
2661 return new SolarisTargetInfo<X86_64TargetInfo>(T);
Daniel Dunbar9fe4a5d2009-09-23 07:31:35 +00002662 case llvm::Triple::MinGW64:
2663 return new MinGWX86_64TargetInfo(T);
2664 case llvm::Triple::Win32: // This is what Triple.h supports now.
Michael J. Spencera764e832010-10-21 08:22:51 +00002665 return new VisualStudioWindowsX86_64TargetInfo(T);
Daniel Dunbar9d6fa612009-08-18 05:47:58 +00002666 default:
2667 return new X86_64TargetInfo(T);
2668 }
2669 }
Reid Spencer5f016e22007-07-11 17:01:13 +00002670}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002671
2672/// CreateTargetInfo - Return the target info object for the specified target
2673/// triple.
2674TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags,
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002675 TargetOptions &Opts) {
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002676 llvm::Triple Triple(Opts.Triple);
2677
2678 // Construct the target
2679 llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str()));
2680 if (!Target) {
2681 Diags.Report(diag::err_target_unknown_triple) << Triple.str();
2682 return 0;
2683 }
2684
Daniel Dunbareac7c532009-12-18 18:42:37 +00002685 // Set the target CPU if specified.
2686 if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) {
2687 Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU;
2688 return 0;
2689 }
2690
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002691 // Set the target ABI if specified.
2692 if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) {
2693 Diags.Report(diag::err_target_unknown_abi) << Opts.ABI;
2694 return 0;
2695 }
2696
Charles Davis98b7c5c2010-06-11 01:06:47 +00002697 // Set the target C++ ABI.
John McCallee79a4c2010-08-21 22:46:04 +00002698 if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) {
Charles Davis98b7c5c2010-06-11 01:06:47 +00002699 Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI;
2700 return 0;
2701 }
2702
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002703 // Compute the default target features, we need the target to handle this
2704 // because features may have dependencies on one another.
2705 llvm::StringMap<bool> Features;
2706 Target->getDefaultFeatures(Opts.CPU, Features);
2707
2708 // Apply the user specified deltas.
2709 for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
2710 ie = Opts.Features.end(); it != ie; ++it) {
2711 const char *Name = it->c_str();
2712
2713 // Apply the feature via the target.
2714 if ((Name[0] != '-' && Name[0] != '+') ||
2715 !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
2716 Diags.Report(diag::err_target_invalid_feature) << Name;
2717 return 0;
2718 }
2719 }
2720
2721 // Add the features to the compile options.
2722 //
2723 // FIXME: If we are completely confident that we have the right set, we only
2724 // need to pass the minuses.
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002725 Opts.Features.clear();
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002726 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
2727 ie = Features.end(); it != ie; ++it)
Daniel Dunbarb93292a2009-12-19 03:30:57 +00002728 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
2729 Target->HandleTargetFeatures(Opts.Features);
Daniel Dunbard58c03f2009-11-15 06:48:46 +00002730
2731 return Target.take();
2732}