Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Targets.cpp - Implement -arch option and targets -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 10 | // This file implements construction of a TargetInfo object from a |
Ted Kremenek | bbced58 | 2007-12-12 18:05:32 +0000 | [diff] [blame] | 11 | // target triple. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 16 | #include "clang/Basic/Builtins.h" |
| 17 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 8fc4dfb | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 18 | #include "clang/Basic/LangOptions.h" |
Chandler Carruth | 103b71c | 2010-01-20 06:13:02 +0000 | [diff] [blame] | 19 | #include "clang/Basic/MacroBuilder.h" |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 20 | #include "clang/Basic/TargetBuiltins.h" |
| 21 | #include "clang/Basic/TargetOptions.h" |
Eli Friedman | 2553126 | 2008-05-20 14:27:34 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/APFloat.h" |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/OwningPtr.h" |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
Daniel Dunbar | 7765934 | 2009-08-19 20:04:03 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringRef.h" |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
Chris Lattner | 4c28b1c | 2009-08-12 06:24:27 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Triple.h" |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSectionMachO.h" |
Benjamin Kramer | 4872508 | 2010-01-09 18:20:57 +0000 | [diff] [blame] | 29 | #include <algorithm> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 30 | using namespace clang; |
| 31 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
| 33 | // Common code shared among targets. |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 36 | /// DefineStd - Define a macro name and standard variants. For example if |
| 37 | /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix" |
| 38 | /// when in GNU mode. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 39 | static void DefineStd(MacroBuilder &Builder, llvm::StringRef MacroName, |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 40 | const LangOptions &Opts) { |
| 41 | assert(MacroName[0] != '_' && "Identifier should be in the user's namespace"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 42 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 43 | // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier |
| 44 | // in the user's namespace. |
| 45 | if (Opts.GNUMode) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 46 | Builder.defineMacro(MacroName); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 47 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 48 | // Define __unix. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 49 | Builder.defineMacro("__" + MacroName); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 50 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 51 | // Define __unix__. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 52 | Builder.defineMacro("__" + MacroName + "__"); |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Chris Lattner | d29b630 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 55 | //===----------------------------------------------------------------------===// |
| 56 | // Defines specific to certain operating systems. |
| 57 | //===----------------------------------------------------------------------===// |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 58 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 59 | namespace { |
Douglas Gregor | a384492 | 2009-07-01 15:12:53 +0000 | [diff] [blame] | 60 | template<typename TgtInfo> |
| 61 | class OSTargetInfo : public TgtInfo { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 62 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 63 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 64 | MacroBuilder &Builder) const=0; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 65 | public: |
Douglas Gregor | a384492 | 2009-07-01 15:12:53 +0000 | [diff] [blame] | 66 | OSTargetInfo(const std::string& triple) : TgtInfo(triple) {} |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 67 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 68 | MacroBuilder &Builder) const { |
| 69 | TgtInfo::getTargetDefines(Opts, Builder); |
| 70 | getOSDefines(Opts, TgtInfo::getTriple(), Builder); |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 71 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 72 | |
| 73 | }; |
Chris Lattner | 4c28b1c | 2009-08-12 06:24:27 +0000 | [diff] [blame] | 74 | } // end anonymous namespace |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 76 | |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 77 | static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, |
| 78 | const llvm::Triple &Triple) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 79 | Builder.defineMacro("__APPLE_CC__", "5621"); |
| 80 | Builder.defineMacro("__APPLE__"); |
| 81 | Builder.defineMacro("__MACH__"); |
| 82 | Builder.defineMacro("OBJC_NEW_PROPERTIES"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 10d2427 | 2009-04-07 16:50:40 +0000 | [diff] [blame] | 84 | // __weak is always defined, for use in blocks and with objc pointers. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 85 | Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 10d2427 | 2009-04-07 16:50:40 +0000 | [diff] [blame] | 87 | // Darwin defines __strong even in C mode (just to nothing). |
| 88 | if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 89 | Builder.defineMacro("__strong", ""); |
Chris Lattner | 10d2427 | 2009-04-07 16:50:40 +0000 | [diff] [blame] | 90 | else |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 91 | Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))"); |
Eli Friedman | 2de4fee | 2009-06-04 23:00:29 +0000 | [diff] [blame] | 92 | |
| 93 | if (Opts.Static) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 94 | Builder.defineMacro("__STATIC__"); |
Eli Friedman | 2de4fee | 2009-06-04 23:00:29 +0000 | [diff] [blame] | 95 | else |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 96 | Builder.defineMacro("__DYNAMIC__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 97 | |
| 98 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 99 | Builder.defineMacro("_REENTRANT"); |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 100 | |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 101 | // Get the OS version number from the triple. |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 102 | unsigned Maj, Min, Rev; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 104 | // If no version was given, default to to 10.4.0, for simplifying tests. |
| 105 | if (Triple.getOSName() == "darwin") { |
| 106 | Min = Rev = 0; |
| 107 | Maj = 8; |
| 108 | } else |
| 109 | Triple.getDarwinNumber(Maj, Min, Rev); |
| 110 | |
| 111 | // Set the appropriate OS version define. |
| 112 | if (Triple.getEnvironmentName() == "iphoneos") { |
| 113 | assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!"); |
| 114 | char Str[6]; |
| 115 | Str[0] = '0' + Maj; |
| 116 | Str[1] = '0' + (Min / 10); |
| 117 | Str[2] = '0' + (Min % 10); |
| 118 | Str[3] = '0' + (Rev / 10); |
| 119 | Str[4] = '0' + (Rev % 10); |
| 120 | Str[5] = '\0'; |
| 121 | Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str); |
| 122 | } else { |
| 123 | // For historical reasons that make little sense, the version passed here is |
| 124 | // the "darwin" version, which drops the 10 and offsets by 4. |
| 125 | Rev = Min; |
| 126 | Min = Maj - 4; |
| 127 | Maj = 10; |
| 128 | |
| 129 | assert(Triple.getEnvironmentName().empty() && "Invalid environment!"); |
| 130 | assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!"); |
| 131 | char Str[5]; |
| 132 | Str[0] = '0' + (Maj / 10); |
| 133 | Str[1] = '0' + (Maj % 10); |
| 134 | Str[2] = '0' + Min; |
| 135 | Str[3] = '0' + Rev; |
| 136 | Str[4] = '\0'; |
| 137 | Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str); |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 138 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 139 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 141 | namespace { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 142 | template<typename Target> |
| 143 | class DarwinTargetInfo : public OSTargetInfo<Target> { |
| 144 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 145 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 146 | MacroBuilder &Builder) const { |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 147 | getDarwinDefines(Builder, Opts, Triple); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 150 | public: |
| 151 | DarwinTargetInfo(const std::string& triple) : |
| 152 | OSTargetInfo<Target>(triple) { |
| 153 | this->TLSSupported = false; |
| 154 | } |
| 155 | |
Anders Carlsson | f959fb5 | 2010-01-30 18:33:31 +0000 | [diff] [blame] | 156 | virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const { |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 157 | // Let MCSectionMachO validate this. |
| 158 | llvm::StringRef Segment, Section; |
| 159 | unsigned TAA, StubSize; |
| 160 | return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section, |
| 161 | TAA, StubSize); |
| 162 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 165 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 166 | // DragonFlyBSD Target |
| 167 | template<typename Target> |
| 168 | class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> { |
| 169 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 170 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 171 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 172 | // DragonFly defines; list based off of gcc output |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 173 | Builder.defineMacro("__DragonFly__"); |
| 174 | Builder.defineMacro("__DragonFly_cc_version", "100001"); |
| 175 | Builder.defineMacro("__ELF__"); |
| 176 | Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); |
| 177 | Builder.defineMacro("__tune_i386__"); |
| 178 | DefineStd(Builder, "unix", Opts); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 179 | } |
| 180 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | DragonFlyBSDTargetInfo(const std::string &triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 182 | : OSTargetInfo<Target>(triple) {} |
| 183 | }; |
| 184 | |
| 185 | // FreeBSD Target |
| 186 | template<typename Target> |
| 187 | class FreeBSDTargetInfo : public OSTargetInfo<Target> { |
| 188 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 189 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 190 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 191 | // FreeBSD defines; list based off of gcc output |
| 192 | |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 193 | // FIXME: Move version number handling to llvm::Triple. |
Benjamin Kramer | 3bb6530 | 2010-01-30 19:55:01 +0000 | [diff] [blame] | 194 | llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 195 | |
Benjamin Kramer | 3bb6530 | 2010-01-30 19:55:01 +0000 | [diff] [blame] | 196 | Builder.defineMacro("__FreeBSD__", Release); |
| 197 | Builder.defineMacro("__FreeBSD_cc_version", Release + "00001"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 198 | Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); |
| 199 | DefineStd(Builder, "unix", Opts); |
| 200 | Builder.defineMacro("__ELF__"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 201 | } |
| 202 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 203 | FreeBSDTargetInfo(const std::string &triple) |
Duncan Sands | 1e90faf | 2009-07-08 13:55:08 +0000 | [diff] [blame] | 204 | : OSTargetInfo<Target>(triple) { |
| 205 | this->UserLabelPrefix = ""; |
| 206 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | // Linux target |
| 210 | template<typename Target> |
| 211 | class LinuxTargetInfo : public OSTargetInfo<Target> { |
| 212 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 213 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 214 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 215 | // Linux defines; list based off of gcc output |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 216 | DefineStd(Builder, "unix", Opts); |
| 217 | DefineStd(Builder, "linux", Opts); |
| 218 | Builder.defineMacro("__gnu_linux__"); |
| 219 | Builder.defineMacro("__ELF__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 220 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 221 | Builder.defineMacro("_REENTRANT"); |
Douglas Gregor | 2b003fd | 2010-04-21 05:52:38 +0000 | [diff] [blame] | 222 | if (Opts.CPlusPlus) |
| 223 | Builder.defineMacro("_GNU_SOURCE"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 224 | } |
| 225 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 226 | LinuxTargetInfo(const std::string& triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 227 | : OSTargetInfo<Target>(triple) { |
| 228 | this->UserLabelPrefix = ""; |
| 229 | } |
| 230 | }; |
| 231 | |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 232 | // NetBSD Target |
| 233 | template<typename Target> |
| 234 | class NetBSDTargetInfo : public OSTargetInfo<Target> { |
| 235 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 236 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 237 | MacroBuilder &Builder) const { |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 238 | // NetBSD defines; list based off of gcc output |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 239 | Builder.defineMacro("__NetBSD__"); |
| 240 | Builder.defineMacro("__unix__"); |
| 241 | Builder.defineMacro("__ELF__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 242 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 243 | Builder.defineMacro("_POSIX_THREADS"); |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 244 | } |
| 245 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 246 | NetBSDTargetInfo(const std::string &triple) |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 247 | : OSTargetInfo<Target>(triple) { |
| 248 | this->UserLabelPrefix = ""; |
| 249 | } |
| 250 | }; |
| 251 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 252 | // OpenBSD Target |
| 253 | template<typename Target> |
| 254 | class OpenBSDTargetInfo : public OSTargetInfo<Target> { |
| 255 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 256 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 257 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 258 | // OpenBSD defines; list based off of gcc output |
| 259 | |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 260 | Builder.defineMacro("__OpenBSD__"); |
| 261 | DefineStd(Builder, "unix", Opts); |
| 262 | Builder.defineMacro("__ELF__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 263 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 264 | Builder.defineMacro("_POSIX_THREADS"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 265 | } |
| 266 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 267 | OpenBSDTargetInfo(const std::string &triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 268 | : OSTargetInfo<Target>(triple) {} |
| 269 | }; |
| 270 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 271 | // PSP Target |
| 272 | template<typename Target> |
| 273 | class PSPTargetInfo : public OSTargetInfo<Target> { |
| 274 | protected: |
| 275 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 276 | MacroBuilder &Builder) const { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 277 | // PSP defines; list based on the output of the pspdev gcc toolchain. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 278 | Builder.defineMacro("PSP"); |
| 279 | Builder.defineMacro("_PSP"); |
| 280 | Builder.defineMacro("__psp__"); |
| 281 | Builder.defineMacro("__ELF__"); |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 282 | } |
| 283 | public: |
| 284 | PSPTargetInfo(const std::string& triple) |
| 285 | : OSTargetInfo<Target>(triple) { |
| 286 | this->UserLabelPrefix = ""; |
| 287 | } |
| 288 | }; |
| 289 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 290 | // PS3 PPU Target |
| 291 | template<typename Target> |
| 292 | class PS3PPUTargetInfo : public OSTargetInfo<Target> { |
| 293 | protected: |
| 294 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 295 | MacroBuilder &Builder) const { |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 296 | // PS3 PPU defines. |
John Thompson | fb45797 | 2010-03-25 16:18:32 +0000 | [diff] [blame] | 297 | Builder.defineMacro("__PPC__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 298 | Builder.defineMacro("__PPU__"); |
| 299 | Builder.defineMacro("__CELLOS_LV2__"); |
| 300 | Builder.defineMacro("__ELF__"); |
| 301 | Builder.defineMacro("__LP32__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 302 | } |
| 303 | public: |
| 304 | PS3PPUTargetInfo(const std::string& triple) |
| 305 | : OSTargetInfo<Target>(triple) { |
| 306 | this->UserLabelPrefix = ""; |
John Thompson | ec387af | 2009-12-18 14:21:08 +0000 | [diff] [blame] | 307 | this->LongWidth = this->LongAlign = this->PointerWidth = this->PointerAlign = 32; |
| 308 | this->SizeType = TargetInfo::UnsignedInt; |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 309 | } |
| 310 | }; |
| 311 | |
| 312 | // FIXME: Need a real SPU target. |
| 313 | // PS3 SPU Target |
| 314 | template<typename Target> |
| 315 | class PS3SPUTargetInfo : public OSTargetInfo<Target> { |
| 316 | protected: |
| 317 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 318 | MacroBuilder &Builder) const { |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 319 | // PS3 PPU defines. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 320 | Builder.defineMacro("__SPU__"); |
| 321 | Builder.defineMacro("__ELF__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 322 | } |
| 323 | public: |
| 324 | PS3SPUTargetInfo(const std::string& triple) |
| 325 | : OSTargetInfo<Target>(triple) { |
| 326 | this->UserLabelPrefix = ""; |
| 327 | } |
| 328 | }; |
| 329 | |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 330 | // AuroraUX target |
| 331 | template<typename Target> |
| 332 | class AuroraUXTargetInfo : public OSTargetInfo<Target> { |
| 333 | protected: |
| 334 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 335 | MacroBuilder &Builder) const { |
| 336 | DefineStd(Builder, "sun", Opts); |
| 337 | DefineStd(Builder, "unix", Opts); |
| 338 | Builder.defineMacro("__ELF__"); |
| 339 | Builder.defineMacro("__svr4__"); |
| 340 | Builder.defineMacro("__SVR4"); |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 341 | } |
| 342 | public: |
| 343 | AuroraUXTargetInfo(const std::string& triple) |
| 344 | : OSTargetInfo<Target>(triple) { |
| 345 | this->UserLabelPrefix = ""; |
| 346 | this->WCharType = this->SignedLong; |
| 347 | // FIXME: WIntType should be SignedLong |
| 348 | } |
| 349 | }; |
| 350 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 351 | // Solaris target |
| 352 | template<typename Target> |
| 353 | class SolarisTargetInfo : public OSTargetInfo<Target> { |
| 354 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 355 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 356 | MacroBuilder &Builder) const { |
| 357 | DefineStd(Builder, "sun", Opts); |
| 358 | DefineStd(Builder, "unix", Opts); |
| 359 | Builder.defineMacro("__ELF__"); |
| 360 | Builder.defineMacro("__svr4__"); |
| 361 | Builder.defineMacro("__SVR4"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 362 | } |
| 363 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | SolarisTargetInfo(const std::string& triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 365 | : OSTargetInfo<Target>(triple) { |
| 366 | this->UserLabelPrefix = ""; |
| 367 | this->WCharType = this->SignedLong; |
| 368 | // FIXME: WIntType should be SignedLong |
| 369 | } |
| 370 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | } // end anonymous namespace. |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 372 | |
Chris Lattner | d29b630 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 373 | //===----------------------------------------------------------------------===// |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 374 | // Specific target implementations. |
| 375 | //===----------------------------------------------------------------------===// |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 376 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 377 | namespace { |
| 378 | // PPC abstract base class |
| 379 | class PPCTargetInfo : public TargetInfo { |
| 380 | static const Builtin::Info BuiltinInfo[]; |
| 381 | static const char * const GCCRegNames[]; |
| 382 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 383 | |
| 384 | public: |
Eli Friedman | 15b9176 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 385 | PPCTargetInfo(const std::string& triple) : TargetInfo(triple) {} |
| 386 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 387 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 388 | unsigned &NumRecords) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 389 | Records = BuiltinInfo; |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 390 | NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 391 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 392 | |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 393 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 394 | MacroBuilder &Builder) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 395 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 396 | virtual const char *getVAListDeclaration() const { |
Chris Lattner | d599850 | 2008-10-27 01:11:29 +0000 | [diff] [blame] | 397 | return "typedef char* __builtin_va_list;"; |
| 398 | // This is the right definition for ABI/V4: System V.4/eabi. |
| 399 | /*return "typedef struct __va_list_tag {" |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 400 | " unsigned char gpr;" |
| 401 | " unsigned char fpr;" |
| 402 | " unsigned short reserved;" |
| 403 | " void* overflow_arg_area;" |
| 404 | " void* reg_save_area;" |
Chris Lattner | d599850 | 2008-10-27 01:11:29 +0000 | [diff] [blame] | 405 | "} __builtin_va_list[1];";*/ |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 406 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 407 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 408 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 409 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 410 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 411 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 412 | TargetInfo::ConstraintInfo &Info) const { |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 413 | switch (*Name) { |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 414 | default: return false; |
| 415 | case 'O': // Zero |
| 416 | return true; |
| 417 | case 'b': // Base register |
| 418 | case 'f': // Floating point register |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 419 | Info.setAllowsRegister(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 420 | return true; |
| 421 | } |
| 422 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 423 | virtual const char *getClobbers() const { |
| 424 | return ""; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 425 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 426 | }; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 427 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 428 | const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { |
Douglas Gregor | b1152d8 | 2009-02-16 21:58:21 +0000 | [diff] [blame] | 429 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, |
| 430 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 431 | #include "clang/Basic/BuiltinsPPC.def" |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 432 | }; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 433 | |
| 434 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 435 | /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific |
| 436 | /// #defines that are not tied to a specific subtarget. |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 437 | void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 438 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 439 | // Target identification. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 440 | Builder.defineMacro("__ppc__"); |
| 441 | Builder.defineMacro("_ARCH_PPC"); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 442 | Builder.defineMacro("__powerpc__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 443 | Builder.defineMacro("__POWERPC__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 444 | if (PointerWidth == 64) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 445 | Builder.defineMacro("_ARCH_PPC64"); |
| 446 | Builder.defineMacro("_LP64"); |
| 447 | Builder.defineMacro("__LP64__"); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 448 | Builder.defineMacro("__powerpc64__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 449 | Builder.defineMacro("__ppc64__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 450 | } else { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 451 | Builder.defineMacro("__ppc__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 452 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 453 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 454 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 455 | Builder.defineMacro("_BIG_ENDIAN"); |
| 456 | Builder.defineMacro("__BIG_ENDIAN__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 457 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 458 | // Subtarget options. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 459 | Builder.defineMacro("__NATURAL_ALIGNMENT__"); |
| 460 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 461 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 462 | // FIXME: Should be controlled by command line option. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 463 | Builder.defineMacro("__LONG_DOUBLE_128__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 464 | |
| 465 | if (Opts.AltiVec) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 466 | Builder.defineMacro("__VEC__", "10206"); |
| 467 | Builder.defineMacro("__ALTIVEC__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 468 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 471 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 472 | const char * const PPCTargetInfo::GCCRegNames[] = { |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 473 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 474 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 475 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 476 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 477 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 478 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 479 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 480 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 481 | "mq", "lr", "ctr", "ap", |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 482 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 483 | "xer", |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 484 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
| 485 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", |
| 486 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
| 487 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 488 | "vrsave", "vscr", |
| 489 | "spe_acc", "spefscr", |
| 490 | "sfp" |
| 491 | }; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 492 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 493 | void PPCTargetInfo::getGCCRegNames(const char * const *&Names, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 494 | unsigned &NumNames) const { |
| 495 | Names = GCCRegNames; |
| 496 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 497 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 498 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 499 | const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = { |
| 500 | // While some of these aliases do map to different registers |
| 501 | // they still share the same register name. |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 502 | { { "0" }, "r0" }, |
| 503 | { { "1"}, "r1" }, |
| 504 | { { "2" }, "r2" }, |
| 505 | { { "3" }, "r3" }, |
| 506 | { { "4" }, "r4" }, |
| 507 | { { "5" }, "r5" }, |
| 508 | { { "6" }, "r6" }, |
| 509 | { { "7" }, "r7" }, |
| 510 | { { "8" }, "r8" }, |
| 511 | { { "9" }, "r9" }, |
| 512 | { { "10" }, "r10" }, |
| 513 | { { "11" }, "r11" }, |
| 514 | { { "12" }, "r12" }, |
| 515 | { { "13" }, "r13" }, |
| 516 | { { "14" }, "r14" }, |
| 517 | { { "15" }, "r15" }, |
| 518 | { { "16" }, "r16" }, |
| 519 | { { "17" }, "r17" }, |
| 520 | { { "18" }, "r18" }, |
| 521 | { { "19" }, "r19" }, |
| 522 | { { "20" }, "r20" }, |
| 523 | { { "21" }, "r21" }, |
| 524 | { { "22" }, "r22" }, |
| 525 | { { "23" }, "r23" }, |
| 526 | { { "24" }, "r24" }, |
| 527 | { { "25" }, "r25" }, |
| 528 | { { "26" }, "r26" }, |
| 529 | { { "27" }, "r27" }, |
| 530 | { { "28" }, "r28" }, |
| 531 | { { "29" }, "r29" }, |
| 532 | { { "30" }, "r30" }, |
| 533 | { { "31" }, "r31" }, |
| 534 | { { "fr0" }, "f0" }, |
| 535 | { { "fr1" }, "f1" }, |
| 536 | { { "fr2" }, "f2" }, |
| 537 | { { "fr3" }, "f3" }, |
| 538 | { { "fr4" }, "f4" }, |
| 539 | { { "fr5" }, "f5" }, |
| 540 | { { "fr6" }, "f6" }, |
| 541 | { { "fr7" }, "f7" }, |
| 542 | { { "fr8" }, "f8" }, |
| 543 | { { "fr9" }, "f9" }, |
Mike Stump | 1088039 | 2009-09-17 21:15:00 +0000 | [diff] [blame] | 544 | { { "fr10" }, "f10" }, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 545 | { { "fr11" }, "f11" }, |
| 546 | { { "fr12" }, "f12" }, |
| 547 | { { "fr13" }, "f13" }, |
| 548 | { { "fr14" }, "f14" }, |
| 549 | { { "fr15" }, "f15" }, |
| 550 | { { "fr16" }, "f16" }, |
| 551 | { { "fr17" }, "f17" }, |
| 552 | { { "fr18" }, "f18" }, |
| 553 | { { "fr19" }, "f19" }, |
| 554 | { { "fr20" }, "f20" }, |
| 555 | { { "fr21" }, "f21" }, |
| 556 | { { "fr22" }, "f22" }, |
| 557 | { { "fr23" }, "f23" }, |
| 558 | { { "fr24" }, "f24" }, |
| 559 | { { "fr25" }, "f25" }, |
| 560 | { { "fr26" }, "f26" }, |
| 561 | { { "fr27" }, "f27" }, |
| 562 | { { "fr28" }, "f28" }, |
| 563 | { { "fr29" }, "f29" }, |
| 564 | { { "fr30" }, "f30" }, |
| 565 | { { "fr31" }, "f31" }, |
| 566 | { { "cc" }, "cr0" }, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 567 | }; |
| 568 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 569 | void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 570 | unsigned &NumAliases) const { |
| 571 | Aliases = GCCRegAliases; |
| 572 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 573 | } |
| 574 | } // end anonymous namespace. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 575 | |
| 576 | namespace { |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 577 | class PPC32TargetInfo : public PPCTargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 578 | public: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 579 | PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) { |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 580 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 581 | "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32"; |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 582 | |
| 583 | if (getTriple().getOS() == llvm::Triple::FreeBSD) |
| 584 | this->SizeType = TargetInfo::UnsignedInt; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 585 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 586 | }; |
| 587 | } // end anonymous namespace. |
| 588 | |
| 589 | namespace { |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 590 | class PPC64TargetInfo : public PPCTargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 591 | public: |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 592 | PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 593 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 594 | IntMaxType = SignedLong; |
| 595 | UIntMaxType = UnsignedLong; |
| 596 | Int64Type = SignedLong; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 597 | DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 598 | "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64"; |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 599 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 600 | }; |
| 601 | } // end anonymous namespace. |
| 602 | |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 603 | |
| 604 | namespace { |
| 605 | class DarwinPPCTargetInfo : |
| 606 | public DarwinTargetInfo<PPCTargetInfo> { |
| 607 | public: |
| 608 | DarwinPPCTargetInfo(const std::string& triple) |
| 609 | : DarwinTargetInfo<PPCTargetInfo>(triple) { |
| 610 | HasAlignMac68kSupport = true; |
| 611 | } |
| 612 | }; |
| 613 | |
| 614 | class DarwinPPC64TargetInfo : |
| 615 | public DarwinTargetInfo<PPC64TargetInfo> { |
| 616 | public: |
| 617 | DarwinPPC64TargetInfo(const std::string& triple) |
| 618 | : DarwinTargetInfo<PPC64TargetInfo>(triple) { |
| 619 | HasAlignMac68kSupport = true; |
| 620 | } |
| 621 | }; |
| 622 | } // end anonymous namespace. |
| 623 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 624 | namespace { |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 625 | // MBlaze abstract base class |
| 626 | class MBlazeTargetInfo : public TargetInfo { |
| 627 | static const char * const GCCRegNames[]; |
| 628 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 629 | |
| 630 | public: |
| 631 | MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 632 | DescriptionString = "E-p:32:32-i8:8:8-i16:16:16-i64:32:32-f64:32:32-" |
| 633 | "v64:32:32-v128:32:32-n32"; |
| 634 | } |
| 635 | |
| 636 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 637 | unsigned &NumRecords) const { |
| 638 | // FIXME: Implement. |
| 639 | Records = 0; |
| 640 | NumRecords = 0; |
| 641 | } |
| 642 | |
| 643 | virtual void getTargetDefines(const LangOptions &Opts, |
| 644 | MacroBuilder &Builder) const; |
| 645 | |
| 646 | virtual const char *getVAListDeclaration() const { |
| 647 | return "typedef char* __builtin_va_list;"; |
| 648 | } |
| 649 | virtual const char *getTargetPrefix() const { |
| 650 | return "mblaze"; |
| 651 | } |
| 652 | virtual void getGCCRegNames(const char * const *&Names, |
| 653 | unsigned &NumNames) const; |
| 654 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 655 | unsigned &NumAliases) const; |
| 656 | virtual bool validateAsmConstraint(const char *&Name, |
| 657 | TargetInfo::ConstraintInfo &Info) const { |
| 658 | switch (*Name) { |
| 659 | default: return false; |
| 660 | case 'O': // Zero |
| 661 | return true; |
| 662 | case 'b': // Base register |
| 663 | case 'f': // Floating point register |
| 664 | Info.setAllowsRegister(); |
| 665 | return true; |
| 666 | } |
| 667 | } |
| 668 | virtual const char *getClobbers() const { |
| 669 | return ""; |
| 670 | } |
| 671 | }; |
| 672 | |
| 673 | /// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific |
| 674 | /// #defines that are not tied to a specific subtarget. |
| 675 | void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts, |
| 676 | MacroBuilder &Builder) const { |
| 677 | // Target identification. |
| 678 | Builder.defineMacro("__microblaze__"); |
| 679 | Builder.defineMacro("_ARCH_MICROBLAZE"); |
| 680 | Builder.defineMacro("__MICROBLAZE__"); |
| 681 | |
| 682 | // Target properties. |
| 683 | Builder.defineMacro("_BIG_ENDIAN"); |
| 684 | Builder.defineMacro("__BIG_ENDIAN__"); |
| 685 | |
| 686 | // Subtarget options. |
| 687 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 688 | } |
| 689 | |
| 690 | |
| 691 | const char * const MBlazeTargetInfo::GCCRegNames[] = { |
| 692 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 693 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 694 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 695 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 696 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 697 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 698 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 699 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
| 700 | "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4", |
| 701 | "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp" |
| 702 | }; |
| 703 | |
| 704 | void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names, |
| 705 | unsigned &NumNames) const { |
| 706 | Names = GCCRegNames; |
| 707 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 708 | } |
| 709 | |
| 710 | const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = { |
| 711 | { {"f0"}, "r0" }, |
| 712 | { {"f1"}, "r1" }, |
| 713 | { {"f2"}, "r2" }, |
| 714 | { {"f3"}, "r3" }, |
| 715 | { {"f4"}, "r4" }, |
| 716 | { {"f5"}, "r5" }, |
| 717 | { {"f6"}, "r6" }, |
| 718 | { {"f7"}, "r7" }, |
| 719 | { {"f8"}, "r8" }, |
| 720 | { {"f9"}, "r9" }, |
| 721 | { {"f10"}, "r10" }, |
| 722 | { {"f11"}, "r11" }, |
| 723 | { {"f12"}, "r12" }, |
| 724 | { {"f13"}, "r13" }, |
| 725 | { {"f14"}, "r14" }, |
| 726 | { {"f15"}, "r15" }, |
| 727 | { {"f16"}, "r16" }, |
| 728 | { {"f17"}, "r17" }, |
| 729 | { {"f18"}, "r18" }, |
| 730 | { {"f19"}, "r19" }, |
| 731 | { {"f20"}, "r20" }, |
| 732 | { {"f21"}, "r21" }, |
| 733 | { {"f22"}, "r22" }, |
| 734 | { {"f23"}, "r23" }, |
| 735 | { {"f24"}, "r24" }, |
| 736 | { {"f25"}, "r25" }, |
| 737 | { {"f26"}, "r26" }, |
| 738 | { {"f27"}, "r27" }, |
| 739 | { {"f28"}, "r28" }, |
| 740 | { {"f29"}, "r29" }, |
| 741 | { {"f30"}, "r30" }, |
| 742 | { {"f31"}, "r31" }, |
| 743 | }; |
| 744 | |
| 745 | void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 746 | unsigned &NumAliases) const { |
| 747 | Aliases = GCCRegAliases; |
| 748 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 749 | } |
| 750 | } // end anonymous namespace. |
| 751 | |
| 752 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 753 | // Namespace for x86 abstract base class |
| 754 | const Builtin::Info BuiltinInfo[] = { |
Douglas Gregor | b1152d8 | 2009-02-16 21:58:21 +0000 | [diff] [blame] | 755 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, |
| 756 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 757 | #include "clang/Basic/BuiltinsX86.def" |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 758 | }; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 759 | |
Nuno Lopes | 2550d70 | 2009-12-23 17:49:57 +0000 | [diff] [blame] | 760 | static const char* const GCCRegNames[] = { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 761 | "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", |
| 762 | "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", |
| 763 | "argp", "flags", "fspr", "dirflag", "frame", |
| 764 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 765 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", |
| 766 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 767 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" |
| 768 | }; |
| 769 | |
| 770 | const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 771 | { { "al", "ah", "eax", "rax" }, "ax" }, |
| 772 | { { "bl", "bh", "ebx", "rbx" }, "bx" }, |
| 773 | { { "cl", "ch", "ecx", "rcx" }, "cx" }, |
| 774 | { { "dl", "dh", "edx", "rdx" }, "dx" }, |
| 775 | { { "esi", "rsi" }, "si" }, |
| 776 | { { "edi", "rdi" }, "di" }, |
| 777 | { { "esp", "rsp" }, "sp" }, |
| 778 | { { "ebp", "rbp" }, "bp" }, |
| 779 | }; |
| 780 | |
| 781 | // X86 target abstract base class; x86-32 and x86-64 are very close, so |
| 782 | // most of the implementation can be shared. |
| 783 | class X86TargetInfo : public TargetInfo { |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 784 | enum X86SSEEnum { |
| 785 | NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 |
| 786 | } SSELevel; |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 787 | enum AMD3DNowEnum { |
| 788 | NoAMD3DNow, AMD3DNow, AMD3DNowAthlon |
| 789 | } AMD3DNowLevel; |
| 790 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 791 | bool HasAES; |
| 792 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 793 | public: |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 794 | X86TargetInfo(const std::string& triple) |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 795 | : TargetInfo(triple), SSELevel(NoMMXSSE), AMD3DNowLevel(NoAMD3DNow), |
| 796 | HasAES(false) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 797 | LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 798 | } |
| 799 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 800 | unsigned &NumRecords) const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 801 | Records = BuiltinInfo; |
| 802 | NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 803 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 804 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 805 | unsigned &NumNames) const { |
| 806 | Names = GCCRegNames; |
| 807 | NumNames = llvm::array_lengthof(GCCRegNames); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 808 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 809 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 810 | unsigned &NumAliases) const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 811 | Aliases = GCCRegAliases; |
| 812 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 813 | } |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 814 | virtual bool validateAsmConstraint(const char *&Name, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 815 | TargetInfo::ConstraintInfo &info) const; |
| 816 | virtual std::string convertConstraint(const char Constraint) const; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 817 | virtual const char *getClobbers() const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 818 | return "~{dirflag},~{fpsr},~{flags}"; |
| 819 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 820 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 821 | MacroBuilder &Builder) const; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 822 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 823 | const std::string &Name, |
| 824 | bool Enabled) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | virtual void getDefaultFeatures(const std::string &CPU, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 826 | llvm::StringMap<bool> &Features) const; |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 827 | virtual void HandleTargetFeatures(std::vector<std::string> &Features); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 828 | }; |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 829 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | void X86TargetInfo::getDefaultFeatures(const std::string &CPU, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 831 | llvm::StringMap<bool> &Features) const { |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 832 | // FIXME: This should not be here. |
| 833 | Features["3dnow"] = false; |
| 834 | Features["3dnowa"] = false; |
| 835 | Features["mmx"] = false; |
| 836 | Features["sse"] = false; |
| 837 | Features["sse2"] = false; |
| 838 | Features["sse3"] = false; |
| 839 | Features["ssse3"] = false; |
| 840 | Features["sse41"] = false; |
| 841 | Features["sse42"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 842 | Features["aes"] = false; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 843 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 844 | // LLVM does not currently recognize this. |
| 845 | // Features["sse4a"] = false; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 846 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 847 | // FIXME: This *really* should not be here. |
| 848 | |
| 849 | // X86_64 always has SSE2. |
| 850 | if (PointerWidth == 64) |
| 851 | Features["sse2"] = Features["sse"] = Features["mmx"] = true; |
| 852 | |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 853 | if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" || |
| 854 | CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro") |
| 855 | ; |
| 856 | else if (CPU == "pentium-mmx" || CPU == "pentium2") |
| 857 | setFeatureEnabled(Features, "mmx", true); |
| 858 | else if (CPU == "pentium3") |
| 859 | setFeatureEnabled(Features, "sse", true); |
| 860 | else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") |
| 861 | setFeatureEnabled(Features, "sse2", true); |
| 862 | else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") |
| 863 | setFeatureEnabled(Features, "sse3", true); |
| 864 | else if (CPU == "core2") |
| 865 | setFeatureEnabled(Features, "ssse3", true); |
| 866 | else if (CPU == "penryn") { |
| 867 | setFeatureEnabled(Features, "sse4", true); |
| 868 | Features["sse42"] = false; |
| 869 | } else if (CPU == "atom") |
| 870 | setFeatureEnabled(Features, "sse3", true); |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 871 | else if (CPU == "corei7") { |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 872 | setFeatureEnabled(Features, "sse4", true); |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 873 | setFeatureEnabled(Features, "aes", true); |
| 874 | } |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 875 | else if (CPU == "k6" || CPU == "winchip-c6") |
| 876 | setFeatureEnabled(Features, "mmx", true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" || |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 878 | CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") { |
| 879 | setFeatureEnabled(Features, "mmx", true); |
| 880 | setFeatureEnabled(Features, "3dnow", true); |
| 881 | } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") { |
| 882 | setFeatureEnabled(Features, "sse", true); |
| 883 | setFeatureEnabled(Features, "3dnowa", true); |
| 884 | } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" || |
| 885 | CPU == "athlon-fx") { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | setFeatureEnabled(Features, "sse2", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 887 | setFeatureEnabled(Features, "3dnowa", true); |
| 888 | } else if (CPU == "c3-2") |
| 889 | setFeatureEnabled(Features, "sse", true); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 892 | bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | const std::string &Name, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 894 | bool Enabled) const { |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 895 | // FIXME: This *really* should not be here. We need some way of translating |
| 896 | // options into llvm subtarget features. |
| 897 | if (!Features.count(Name) && |
| 898 | (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1")) |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 899 | return false; |
| 900 | |
| 901 | if (Enabled) { |
| 902 | if (Name == "mmx") |
| 903 | Features["mmx"] = true; |
| 904 | else if (Name == "sse") |
| 905 | Features["mmx"] = Features["sse"] = true; |
| 906 | else if (Name == "sse2") |
| 907 | Features["mmx"] = Features["sse"] = Features["sse2"] = true; |
| 908 | else if (Name == "sse3") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | Features["mmx"] = Features["sse"] = Features["sse2"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 910 | Features["sse3"] = true; |
| 911 | else if (Name == "ssse3") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 913 | Features["ssse3"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 914 | else if (Name == "sse4" || Name == "sse4.2") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 916 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 917 | else if (Name == "sse4.1") |
| 918 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 919 | Features["ssse3"] = Features["sse41"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 920 | else if (Name == "3dnow") |
| 921 | Features["3dnowa"] = true; |
| 922 | else if (Name == "3dnowa") |
| 923 | Features["3dnow"] = Features["3dnowa"] = true; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 924 | else if (Name == "aes") |
| 925 | Features["aes"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 926 | } else { |
| 927 | if (Name == "mmx") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 929 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; |
| 930 | else if (Name == "sse") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 932 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; |
| 933 | else if (Name == "sse2") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | Features["sse2"] = Features["sse3"] = Features["ssse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 935 | Features["sse41"] = Features["sse42"] = false; |
| 936 | else if (Name == "sse3") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | Features["sse3"] = Features["ssse3"] = Features["sse41"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 938 | Features["sse42"] = false; |
| 939 | else if (Name == "ssse3") |
| 940 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; |
| 941 | else if (Name == "sse4") |
| 942 | Features["sse41"] = Features["sse42"] = false; |
Eric Christopher | d41b4ec | 2010-03-04 02:31:44 +0000 | [diff] [blame] | 943 | else if (Name == "sse4.2") |
| 944 | Features["sse42"] = false; |
| 945 | else if (Name == "sse4.1") |
| 946 | Features["sse41"] = Features["sse42"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 947 | else if (Name == "3dnow") |
| 948 | Features["3dnow"] = Features["3dnowa"] = false; |
| 949 | else if (Name == "3dnowa") |
| 950 | Features["3dnowa"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 951 | else if (Name == "aes") |
| 952 | Features["aes"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | return true; |
| 956 | } |
| 957 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 958 | /// HandleTargetOptions - Perform initialization based on the user |
| 959 | /// configured set of features. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 960 | void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 961 | // Remember the maximum enabled sselevel. |
| 962 | for (unsigned i = 0, e = Features.size(); i !=e; ++i) { |
| 963 | // Ignore disabled features. |
| 964 | if (Features[i][0] == '-') |
| 965 | continue; |
| 966 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 967 | if (Features[i].substr(1) == "aes") { |
| 968 | HasAES = true; |
| 969 | continue; |
| 970 | } |
| 971 | |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 972 | assert(Features[i][0] == '+' && "Invalid target feature!"); |
| 973 | X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1)) |
| 974 | .Case("sse42", SSE42) |
| 975 | .Case("sse41", SSE41) |
| 976 | .Case("ssse3", SSSE3) |
Nuno Lopes | 33d3bca | 2010-03-12 10:20:09 +0000 | [diff] [blame] | 977 | .Case("sse3", SSE3) |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 978 | .Case("sse2", SSE2) |
| 979 | .Case("sse", SSE1) |
| 980 | .Case("mmx", MMX) |
| 981 | .Default(NoMMXSSE); |
| 982 | SSELevel = std::max(SSELevel, Level); |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 983 | |
| 984 | AMD3DNowEnum ThreeDNowLevel = |
| 985 | llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1)) |
| 986 | .Case("3dnowa", AMD3DNowAthlon) |
| 987 | .Case("3dnow", AMD3DNow) |
| 988 | .Default(NoAMD3DNow); |
| 989 | |
| 990 | AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel); |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 991 | } |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 992 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 993 | |
| 994 | /// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines |
| 995 | /// that are not tied to a specific subtarget. |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 996 | void X86TargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 997 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 998 | // Target identification. |
| 999 | if (PointerWidth == 64) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1000 | Builder.defineMacro("_LP64"); |
| 1001 | Builder.defineMacro("__LP64__"); |
| 1002 | Builder.defineMacro("__amd64__"); |
| 1003 | Builder.defineMacro("__amd64"); |
| 1004 | Builder.defineMacro("__x86_64"); |
| 1005 | Builder.defineMacro("__x86_64__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1006 | } else { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1007 | DefineStd(Builder, "i386", Opts); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1008 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1009 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1010 | if (HasAES) |
| 1011 | Builder.defineMacro("__AES__"); |
| 1012 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1013 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1014 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1015 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1016 | // Subtarget options. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1017 | Builder.defineMacro("__nocona"); |
| 1018 | Builder.defineMacro("__nocona__"); |
| 1019 | Builder.defineMacro("__tune_nocona__"); |
| 1020 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1021 | |
Chris Lattner | 5417544 | 2009-04-19 17:32:33 +0000 | [diff] [blame] | 1022 | // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline |
| 1023 | // functions in glibc header files that use FP Stack inline asm which the |
| 1024 | // backend can't deal with (PR879). |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1025 | Builder.defineMacro("__NO_MATH_INLINES"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1026 | |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1027 | // Each case falls through to the previous one here. |
| 1028 | switch (SSELevel) { |
| 1029 | case SSE42: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1030 | Builder.defineMacro("__SSE4_2__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1031 | case SSE41: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1032 | Builder.defineMacro("__SSE4_1__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1033 | case SSSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1034 | Builder.defineMacro("__SSSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1035 | case SSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1036 | Builder.defineMacro("__SSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1037 | case SSE2: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1038 | Builder.defineMacro("__SSE2__"); |
| 1039 | Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied. |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1040 | case SSE1: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1041 | Builder.defineMacro("__SSE__"); |
| 1042 | Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied. |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1043 | case MMX: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1044 | Builder.defineMacro("__MMX__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1045 | case NoMMXSSE: |
| 1046 | break; |
| 1047 | } |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1048 | |
| 1049 | // Each case falls through to the previous one here. |
| 1050 | switch (AMD3DNowLevel) { |
| 1051 | case AMD3DNowAthlon: |
| 1052 | Builder.defineMacro("__3dNOW_A__"); |
| 1053 | case AMD3DNow: |
| 1054 | Builder.defineMacro("__3dNOW__"); |
| 1055 | case NoAMD3DNow: |
| 1056 | break; |
| 1057 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1058 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1059 | |
| 1060 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1061 | bool |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1062 | X86TargetInfo::validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 1063 | TargetInfo::ConstraintInfo &Info) const { |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1064 | switch (*Name) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1065 | default: return false; |
| 1066 | case 'a': // eax. |
| 1067 | case 'b': // ebx. |
| 1068 | case 'c': // ecx. |
| 1069 | case 'd': // edx. |
| 1070 | case 'S': // esi. |
| 1071 | case 'D': // edi. |
| 1072 | case 'A': // edx:eax. |
| 1073 | case 't': // top of floating point stack. |
| 1074 | case 'u': // second from top of floating point stack. |
| 1075 | case 'q': // Any register accessible as [r]l: a, b, c, and d. |
Anders Carlsson | fce0934 | 2008-10-06 00:41:45 +0000 | [diff] [blame] | 1076 | case 'y': // Any MMX register. |
Anders Carlsson | a7406d4 | 2008-10-06 19:17:39 +0000 | [diff] [blame] | 1077 | case 'x': // Any SSE register. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1078 | case 'Q': // Any register accessible as [r]h: a, b, c, and d. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1079 | case 'e': // 32-bit signed integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 1080 | // x86_64 instructions. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1081 | case 'Z': // 32-bit unsigned integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 1082 | // x86_64 instructions. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1083 | case 'N': // unsigned 8-bit integer constant for use with in and out |
| 1084 | // instructions. |
Eli Friedman | 12b2da0 | 2009-06-08 20:45:44 +0000 | [diff] [blame] | 1085 | case 'R': // "legacy" registers: ax, bx, cx, dx, di, si, sp, bp. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 1086 | Info.setAllowsRegister(); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1087 | return true; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | std::string |
| 1092 | X86TargetInfo::convertConstraint(const char Constraint) const { |
| 1093 | switch (Constraint) { |
| 1094 | case 'a': return std::string("{ax}"); |
| 1095 | case 'b': return std::string("{bx}"); |
| 1096 | case 'c': return std::string("{cx}"); |
| 1097 | case 'd': return std::string("{dx}"); |
| 1098 | case 'S': return std::string("{si}"); |
| 1099 | case 'D': return std::string("{di}"); |
| 1100 | case 't': // top of floating point stack. |
| 1101 | return std::string("{st}"); |
| 1102 | case 'u': // second from top of floating point stack. |
| 1103 | return std::string("{st(1)}"); // second from top of floating point stack. |
| 1104 | default: |
| 1105 | return std::string(1, Constraint); |
| 1106 | } |
| 1107 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1108 | } // end anonymous namespace |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1109 | |
| 1110 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1111 | // X86-32 generic target |
| 1112 | class X86_32TargetInfo : public X86TargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1113 | public: |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1114 | X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { |
| 1115 | DoubleAlign = LongLongAlign = 32; |
| 1116 | LongDoubleWidth = 96; |
| 1117 | LongDoubleAlign = 32; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1118 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1119 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1120 | "a0:0:64-f80:32:32-n8:16:32"; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 1121 | SizeType = UnsignedInt; |
| 1122 | PtrDiffType = SignedInt; |
| 1123 | IntPtrType = SignedInt; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 1124 | RegParmMax = 3; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1125 | } |
| 1126 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1127 | return "typedef char* __builtin_va_list;"; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1128 | } |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 1129 | |
| 1130 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 1131 | if (RegNo == 0) return 0; |
| 1132 | if (RegNo == 1) return 2; |
| 1133 | return -1; |
| 1134 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1135 | }; |
| 1136 | } // end anonymous namespace |
| 1137 | |
| 1138 | namespace { |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 1139 | class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> { |
| 1140 | public: |
| 1141 | OpenBSDI386TargetInfo(const std::string& triple) : |
| 1142 | OpenBSDTargetInfo<X86_32TargetInfo>(triple) { |
| 1143 | SizeType = UnsignedLong; |
| 1144 | IntPtrType = SignedLong; |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1145 | PtrDiffType = SignedLong; |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 1146 | } |
| 1147 | }; |
| 1148 | } // end anonymous namespace |
| 1149 | |
| 1150 | namespace { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1151 | class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1152 | public: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1153 | DarwinI386TargetInfo(const std::string& triple) : |
| 1154 | DarwinTargetInfo<X86_32TargetInfo>(triple) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1155 | LongDoubleWidth = 128; |
| 1156 | LongDoubleAlign = 128; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 1157 | SizeType = UnsignedLong; |
| 1158 | IntPtrType = SignedLong; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1159 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1160 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1161 | "a0:0:64-f80:128:128-n8:16:32"; |
Daniel Dunbar | 613fd67 | 2010-05-27 00:35:16 +0000 | [diff] [blame] | 1162 | HasAlignMac68kSupport = true; |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1165 | }; |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1166 | } // end anonymous namespace |
| 1167 | |
| 1168 | namespace { |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1169 | // x86-32 Windows target |
| 1170 | class WindowsX86_32TargetInfo : public X86_32TargetInfo { |
| 1171 | public: |
| 1172 | WindowsX86_32TargetInfo(const std::string& triple) |
| 1173 | : X86_32TargetInfo(triple) { |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 1174 | TLSSupported = false; |
Chris Lattner | 85de9e7 | 2009-06-24 17:12:15 +0000 | [diff] [blame] | 1175 | WCharType = UnsignedShort; |
Eli Friedman | 9c2f84e | 2009-06-08 21:16:17 +0000 | [diff] [blame] | 1176 | DoubleAlign = LongLongAlign = 64; |
| 1177 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Anton Korobeynikov | b381441 | 2009-12-19 02:05:07 +0000 | [diff] [blame] | 1178 | "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-" |
| 1179 | "v128:128:128-a0:0:64-f80:32:32-n8:16:32"; |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1180 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1181 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1182 | MacroBuilder &Builder) const { |
| 1183 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1184 | // This list is based off of the the list of things MingW defines |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1185 | Builder.defineMacro("_WIN32"); |
| 1186 | DefineStd(Builder, "WIN32", Opts); |
| 1187 | DefineStd(Builder, "WINNT", Opts); |
| 1188 | Builder.defineMacro("_X86_"); |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1189 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1190 | }; |
| 1191 | } // end anonymous namespace |
Eli Friedman | abc4e32 | 2009-06-08 06:11:14 +0000 | [diff] [blame] | 1192 | |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1193 | namespace { |
| 1194 | |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1195 | // x86-32 Windows Visual Studio target |
| 1196 | class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 1197 | public: |
| 1198 | VisualStudioWindowsX86_32TargetInfo(const std::string& triple) |
| 1199 | : WindowsX86_32TargetInfo(triple) { |
| 1200 | } |
| 1201 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1202 | MacroBuilder &Builder) const { |
| 1203 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1204 | // The value of the following reflects processor type. |
| 1205 | // 300=386, 400=486, 500=Pentium, 600=Blend (default) |
| 1206 | // We lost the original triple, so we use the default. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1207 | Builder.defineMacro("_M_IX86", "600"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1208 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1209 | }; |
| 1210 | } // end anonymous namespace |
| 1211 | |
| 1212 | namespace { |
| 1213 | // x86-32 MinGW target |
| 1214 | class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 1215 | public: |
| 1216 | MinGWX86_32TargetInfo(const std::string& triple) |
| 1217 | : WindowsX86_32TargetInfo(triple) { |
| 1218 | } |
| 1219 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1220 | MacroBuilder &Builder) const { |
| 1221 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1222 | Builder.defineMacro("__MSVCRT__"); |
| 1223 | Builder.defineMacro("__MINGW32__"); |
| 1224 | Builder.defineMacro("__declspec", "__declspec"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1225 | } |
| 1226 | }; |
| 1227 | } // end anonymous namespace |
| 1228 | |
| 1229 | namespace { |
| 1230 | // x86-32 Cygwin target |
| 1231 | class CygwinX86_32TargetInfo : public X86_32TargetInfo { |
| 1232 | public: |
| 1233 | CygwinX86_32TargetInfo(const std::string& triple) |
| 1234 | : X86_32TargetInfo(triple) { |
| 1235 | TLSSupported = false; |
| 1236 | WCharType = UnsignedShort; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1237 | DoubleAlign = LongLongAlign = 64; |
| 1238 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1239 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1240 | "a0:0:64-f80:32:32-n8:16:32"; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1241 | } |
| 1242 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1243 | MacroBuilder &Builder) const { |
| 1244 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1245 | Builder.defineMacro("__CYGWIN__"); |
| 1246 | Builder.defineMacro("__CYGWIN32__"); |
| 1247 | DefineStd(Builder, "unix", Opts); |
Douglas Gregor | 2b003fd | 2010-04-21 05:52:38 +0000 | [diff] [blame] | 1248 | if (Opts.CPlusPlus) |
| 1249 | Builder.defineMacro("_GNU_SOURCE"); |
Eli Friedman | abc4e32 | 2009-06-08 06:11:14 +0000 | [diff] [blame] | 1250 | } |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1251 | }; |
| 1252 | } // end anonymous namespace |
| 1253 | |
| 1254 | namespace { |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1255 | // x86-32 Haiku target |
| 1256 | class HaikuX86_32TargetInfo : public X86_32TargetInfo { |
| 1257 | public: |
| 1258 | HaikuX86_32TargetInfo(const std::string& triple) |
| 1259 | : X86_32TargetInfo(triple) { |
| 1260 | SizeType = UnsignedLong; |
Chris Lattner | fe1ea7b | 2010-04-22 17:48:00 +0000 | [diff] [blame] | 1261 | IntPtrType = SignedLong; |
| 1262 | PtrDiffType = SignedLong; |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1263 | } |
| 1264 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1265 | MacroBuilder &Builder) const { |
| 1266 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1267 | Builder.defineMacro("__INTEL__"); |
| 1268 | Builder.defineMacro("__HAIKU__"); |
| 1269 | } |
| 1270 | }; |
| 1271 | } // end anonymous namespace |
| 1272 | |
| 1273 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1274 | // x86-64 generic target |
| 1275 | class X86_64TargetInfo : public X86TargetInfo { |
| 1276 | public: |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1277 | X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 1278 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1279 | LongDoubleWidth = 128; |
| 1280 | LongDoubleAlign = 128; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 1281 | IntMaxType = SignedLong; |
| 1282 | UIntMaxType = UnsignedLong; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1283 | Int64Type = SignedLong; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 1284 | RegParmMax = 6; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 1285 | |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1286 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1287 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1288 | "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1289 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 1290 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1291 | return "typedef struct __va_list_tag {" |
| 1292 | " unsigned gp_offset;" |
| 1293 | " unsigned fp_offset;" |
| 1294 | " void* overflow_arg_area;" |
| 1295 | " void* reg_save_area;" |
John McCall | 2b7baf0 | 2010-05-28 18:25:28 +0000 | [diff] [blame] | 1296 | "} __va_list_tag;" |
Eli Friedman | dc04316 | 2009-07-03 00:45:06 +0000 | [diff] [blame] | 1297 | "typedef __va_list_tag __builtin_va_list[1];"; |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1298 | } |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 1299 | |
| 1300 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 1301 | if (RegNo == 0) return 0; |
| 1302 | if (RegNo == 1) return 1; |
| 1303 | return -1; |
| 1304 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1305 | }; |
| 1306 | } // end anonymous namespace |
| 1307 | |
| 1308 | namespace { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1309 | // x86-64 Windows target |
| 1310 | class WindowsX86_64TargetInfo : public X86_64TargetInfo { |
| 1311 | public: |
| 1312 | WindowsX86_64TargetInfo(const std::string& triple) |
| 1313 | : X86_64TargetInfo(triple) { |
| 1314 | TLSSupported = false; |
| 1315 | WCharType = UnsignedShort; |
Mike Stump | a55cce8 | 2009-10-08 23:00:00 +0000 | [diff] [blame] | 1316 | LongWidth = LongAlign = 32; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1317 | DoubleAlign = LongLongAlign = 64; |
| 1318 | } |
| 1319 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1320 | MacroBuilder &Builder) const { |
| 1321 | X86_64TargetInfo::getTargetDefines(Opts, Builder); |
| 1322 | Builder.defineMacro("_WIN64"); |
| 1323 | DefineStd(Builder, "WIN64", Opts); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1324 | } |
| 1325 | }; |
| 1326 | } // end anonymous namespace |
| 1327 | |
| 1328 | namespace { |
| 1329 | // x86-64 Windows Visual Studio target |
| 1330 | class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 1331 | public: |
| 1332 | VisualStudioWindowsX86_64TargetInfo(const std::string& triple) |
| 1333 | : WindowsX86_64TargetInfo(triple) { |
| 1334 | } |
| 1335 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1336 | MacroBuilder &Builder) const { |
| 1337 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
| 1338 | Builder.defineMacro("_M_X64"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1339 | } |
| 1340 | virtual const char *getVAListDeclaration() const { |
| 1341 | return "typedef char* va_list;"; |
| 1342 | } |
| 1343 | }; |
| 1344 | } // end anonymous namespace |
| 1345 | |
| 1346 | namespace { |
| 1347 | // x86-64 MinGW target |
| 1348 | class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 1349 | public: |
| 1350 | MinGWX86_64TargetInfo(const std::string& triple) |
| 1351 | : WindowsX86_64TargetInfo(triple) { |
| 1352 | } |
| 1353 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1354 | MacroBuilder &Builder) const { |
| 1355 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
| 1356 | Builder.defineMacro("__MSVCRT__"); |
| 1357 | Builder.defineMacro("__MINGW64__"); |
| 1358 | Builder.defineMacro("__declspec"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1359 | } |
| 1360 | }; |
| 1361 | } // end anonymous namespace |
| 1362 | |
| 1363 | namespace { |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1364 | class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { |
| 1365 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | DarwinX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1367 | : DarwinTargetInfo<X86_64TargetInfo>(triple) { |
| 1368 | Int64Type = SignedLongLong; |
| 1369 | } |
| 1370 | }; |
| 1371 | } // end anonymous namespace |
| 1372 | |
| 1373 | namespace { |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1374 | class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { |
| 1375 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | OpenBSDX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1377 | : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { |
| 1378 | IntMaxType = SignedLongLong; |
| 1379 | UIntMaxType = UnsignedLongLong; |
| 1380 | Int64Type = SignedLongLong; |
| 1381 | } |
| 1382 | }; |
| 1383 | } // end anonymous namespace |
| 1384 | |
| 1385 | namespace { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1386 | class ARMTargetInfo : public TargetInfo { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1387 | // Possible FPU choices. |
| 1388 | enum FPUMode { |
| 1389 | NoFPU, |
| 1390 | VFP2FPU, |
| 1391 | VFP3FPU, |
| 1392 | NeonFPU |
| 1393 | }; |
| 1394 | |
| 1395 | static bool FPUModeIsVFP(FPUMode Mode) { |
| 1396 | return Mode >= VFP2FPU && Mode <= NeonFPU; |
| 1397 | } |
| 1398 | |
| 1399 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 1400 | static const char * const GCCRegNames[]; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 1401 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1402 | std::string ABI, CPU; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1403 | |
| 1404 | unsigned FPU : 3; |
| 1405 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1406 | unsigned IsThumb : 1; |
| 1407 | |
| 1408 | // Initialized via features. |
| 1409 | unsigned SoftFloat : 1; |
| 1410 | unsigned SoftFloatABI : 1; |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1411 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1412 | static const Builtin::Info BuiltinInfo[]; |
| 1413 | |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1414 | public: |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1415 | ARMTargetInfo(const std::string &TripleStr) |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1416 | : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s") |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1417 | { |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1418 | SizeType = UnsignedInt; |
| 1419 | PtrDiffType = SignedInt; |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1420 | |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 1421 | // {} in inline assembly are neon specifiers, not assembly variant |
| 1422 | // specifiers. |
| 1423 | NoAsmVariants = true; |
| 1424 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1425 | // FIXME: Should we just treat this as a feature? |
Daniel Dunbar | 0791aa5 | 2009-12-18 19:57:13 +0000 | [diff] [blame] | 1426 | IsThumb = getTriple().getArchName().startswith("thumb"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1427 | if (IsThumb) { |
| 1428 | DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" |
| 1429 | "i64:64:64-f32:32:32-f64:64:64-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1430 | "v64:64:64-v128:128:128-a0:0:32-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1431 | } else { |
| 1432 | DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1433 | "i64:64:64-f32:32:32-f64:64:64-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1434 | "v64:64:64-v128:128:128-a0:0:64-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1435 | } |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1436 | } |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1437 | virtual const char *getABI() const { return ABI.c_str(); } |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1438 | virtual bool setABI(const std::string &Name) { |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1439 | ABI = Name; |
| 1440 | |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1441 | // The defaults (above) are for AAPCS, check if we need to change them. |
| 1442 | // |
| 1443 | // FIXME: We need support for -meabi... we could just mangle it into the |
| 1444 | // name. |
| 1445 | if (Name == "apcs-gnu") { |
Daniel Dunbar | d410fa2 | 2010-01-27 20:23:08 +0000 | [diff] [blame] | 1446 | DoubleAlign = LongLongAlign = LongDoubleAlign = 32; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1447 | SizeType = UnsignedLong; |
| 1448 | |
Daniel Dunbar | 684de63 | 2010-04-22 16:14:54 +0000 | [diff] [blame] | 1449 | // Do not respect the alignment of bit-field types when laying out |
| 1450 | // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc. |
| 1451 | UseBitFieldTypeAlignment = false; |
| 1452 | |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1453 | if (IsThumb) { |
| 1454 | DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" |
| 1455 | "i64:32:32-f32:32:32-f64:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1456 | "v64:64:64-v128:128:128-a0:0:32-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1457 | } else { |
| 1458 | DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1459 | "i64:32:32-f32:32:32-f64:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1460 | "v64:64:64-v128:128:128-a0:0:64-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1463 | // FIXME: Override "preferred align" for double and long long. |
| 1464 | } else if (Name == "aapcs") { |
| 1465 | // FIXME: Enumerated types are variable width in straight AAPCS. |
| 1466 | } else if (Name == "aapcs-linux") { |
| 1467 | ; |
| 1468 | } else |
| 1469 | return false; |
| 1470 | |
| 1471 | return true; |
| 1472 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1473 | |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1474 | void getDefaultFeatures(const std::string &CPU, |
| 1475 | llvm::StringMap<bool> &Features) const { |
| 1476 | // FIXME: This should not be here. |
| 1477 | Features["vfp2"] = false; |
| 1478 | Features["vfp3"] = false; |
| 1479 | Features["neon"] = false; |
| 1480 | |
| 1481 | if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") |
| 1482 | Features["vfp2"] = true; |
| 1483 | else if (CPU == "cortex-a8" || CPU == "cortex-a9") |
| 1484 | Features["neon"] = true; |
| 1485 | } |
| 1486 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1487 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 1488 | const std::string &Name, |
| 1489 | bool Enabled) const { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1490 | if (Name == "soft-float" || Name == "soft-float-abi") { |
| 1491 | Features[Name] = Enabled; |
| 1492 | } else if (Name == "vfp2" || Name == "vfp3" || Name == "neon") { |
| 1493 | // These effectively are a single option, reset them when any is enabled. |
| 1494 | if (Enabled) |
| 1495 | Features["vfp2"] = Features["vfp3"] = Features["neon"] = false; |
| 1496 | Features[Name] = Enabled; |
| 1497 | } else |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1498 | return false; |
| 1499 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1500 | return true; |
| 1501 | } |
| 1502 | |
| 1503 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1504 | FPU = NoFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1505 | SoftFloat = SoftFloatABI = false; |
| 1506 | for (unsigned i = 0, e = Features.size(); i != e; ++i) { |
| 1507 | if (Features[i] == "+soft-float") |
| 1508 | SoftFloat = true; |
| 1509 | else if (Features[i] == "+soft-float-abi") |
| 1510 | SoftFloatABI = true; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1511 | else if (Features[i] == "+vfp2") |
| 1512 | FPU = VFP2FPU; |
| 1513 | else if (Features[i] == "+vfp3") |
| 1514 | FPU = VFP3FPU; |
| 1515 | else if (Features[i] == "+neon") |
| 1516 | FPU = NeonFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | // Remove front-end specific options which the backend handles differently. |
| 1520 | std::vector<std::string>::iterator it; |
| 1521 | it = std::find(Features.begin(), Features.end(), "+soft-float"); |
| 1522 | if (it != Features.end()) |
| 1523 | Features.erase(it); |
| 1524 | it = std::find(Features.begin(), Features.end(), "+soft-float-abi"); |
| 1525 | if (it != Features.end()) |
| 1526 | Features.erase(it); |
| 1527 | } |
| 1528 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1529 | static const char *getCPUDefineSuffix(llvm::StringRef Name) { |
| 1530 | return llvm::StringSwitch<const char*>(Name) |
| 1531 | .Cases("arm8", "arm810", "4") |
| 1532 | .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4") |
| 1533 | .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T") |
| 1534 | .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T") |
| 1535 | .Case("ep9312", "4T") |
| 1536 | .Cases("arm10tdmi", "arm1020t", "5T") |
| 1537 | .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE") |
| 1538 | .Case("arm926ej-s", "5TEJ") |
| 1539 | .Cases("arm10e", "arm1020e", "arm1022e", "5TE") |
| 1540 | .Cases("xscale", "iwmmxt", "5TE") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1541 | .Case("arm1136j-s", "6J") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1542 | .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1543 | .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1544 | .Cases("arm1156t2-s", "arm1156t2f-s", "6T2") |
| 1545 | .Cases("cortex-a8", "cortex-a9", "7A") |
| 1546 | .Default(0); |
| 1547 | } |
| 1548 | virtual bool setCPU(const std::string &Name) { |
| 1549 | if (!getCPUDefineSuffix(Name)) |
| 1550 | return false; |
| 1551 | |
| 1552 | CPU = Name; |
| 1553 | return true; |
| 1554 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1555 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1556 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1557 | // Target identification. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1558 | Builder.defineMacro("__arm"); |
| 1559 | Builder.defineMacro("__arm__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1560 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1561 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1562 | Builder.defineMacro("__ARMEL__"); |
| 1563 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
| 1564 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1565 | |
| 1566 | llvm::StringRef CPUArch = getCPUDefineSuffix(CPU); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1567 | Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1568 | |
Mike Stump | 437bb4b | 2009-04-08 02:07:04 +0000 | [diff] [blame] | 1569 | // Subtarget options. |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1570 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1571 | // FIXME: It's more complicated than this and we don't really support |
| 1572 | // interworking. |
| 1573 | if ('5' <= CPUArch[0] && CPUArch[0] <= '7') |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1574 | Builder.defineMacro("__THUMB_INTERWORK__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1575 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1576 | if (ABI == "aapcs" || ABI == "aapcs-linux") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1577 | Builder.defineMacro("__ARM_EABI__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1578 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1579 | if (SoftFloat) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1580 | Builder.defineMacro("__SOFTFP__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1581 | |
| 1582 | if (CPU == "xscale") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1583 | Builder.defineMacro("__XSCALE__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1584 | |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1585 | bool IsThumb2 = IsThumb && (CPUArch == "6T2" || CPUArch.startswith("7")); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1586 | if (IsThumb) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1587 | Builder.defineMacro("__THUMBEL__"); |
| 1588 | Builder.defineMacro("__thumb__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1589 | if (IsThumb2) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1590 | Builder.defineMacro("__thumb2__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | // Note, this is always on in gcc, even though it doesn't make sense. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1594 | Builder.defineMacro("__APCS_32__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1595 | |
| 1596 | if (FPUModeIsVFP((FPUMode) FPU)) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1597 | Builder.defineMacro("__VFP_FP__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1598 | |
| 1599 | // This only gets set when Neon instructions are actually available, unlike |
| 1600 | // the VFP define, hence the soft float and arch check. This is subtly |
| 1601 | // different from gcc, we follow the intent which was that it should be set |
| 1602 | // when Neon instructions are actually available. |
| 1603 | if (FPU == NeonFPU && !SoftFloat && IsThumb2) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1604 | Builder.defineMacro("__ARM_NEON__"); |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1605 | } |
| 1606 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1607 | unsigned &NumRecords) const { |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1608 | Records = BuiltinInfo; |
| 1609 | NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1610 | } |
| 1611 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1612 | return "typedef char* __builtin_va_list;"; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1613 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1614 | virtual void getGCCRegNames(const char * const *&Names, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 1615 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1616 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 1617 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1618 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 1619 | TargetInfo::ConstraintInfo &Info) const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1620 | // FIXME: Check if this is complete |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1621 | switch (*Name) { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1622 | default: |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 1623 | case 'l': // r0-r7 |
| 1624 | case 'h': // r8-r15 |
| 1625 | case 'w': // VFP Floating point register single precision |
| 1626 | case 'P': // VFP Floating point register double precision |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 1627 | Info.setAllowsRegister(); |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 1628 | return true; |
| 1629 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1630 | return false; |
| 1631 | } |
| 1632 | virtual const char *getClobbers() const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1633 | // FIXME: Is this really right? |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1634 | return ""; |
| 1635 | } |
| 1636 | }; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 1637 | |
| 1638 | const char * const ARMTargetInfo::GCCRegNames[] = { |
| 1639 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1640 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 1641 | }; |
| 1642 | |
| 1643 | void ARMTargetInfo::getGCCRegNames(const char * const *&Names, |
| 1644 | unsigned &NumNames) const { |
| 1645 | Names = GCCRegNames; |
| 1646 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1647 | } |
| 1648 | |
| 1649 | const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { |
| 1650 | |
| 1651 | { { "a1" }, "r0" }, |
| 1652 | { { "a2" }, "r1" }, |
| 1653 | { { "a3" }, "r2" }, |
| 1654 | { { "a4" }, "r3" }, |
| 1655 | { { "v1" }, "r4" }, |
| 1656 | { { "v2" }, "r5" }, |
| 1657 | { { "v3" }, "r6" }, |
| 1658 | { { "v4" }, "r7" }, |
| 1659 | { { "v5" }, "r8" }, |
| 1660 | { { "v6", "rfp" }, "r9" }, |
| 1661 | { { "sl" }, "r10" }, |
| 1662 | { { "fp" }, "r11" }, |
| 1663 | { { "ip" }, "r12" }, |
| 1664 | { { "sp" }, "r13" }, |
| 1665 | { { "lr" }, "r14" }, |
| 1666 | { { "pc" }, "r15" }, |
| 1667 | }; |
| 1668 | |
| 1669 | void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1670 | unsigned &NumAliases) const { |
| 1671 | Aliases = GCCRegAliases; |
| 1672 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 1673 | } |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1674 | |
| 1675 | const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { |
| 1676 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, |
| 1677 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, |
| 1678 | #include "clang/Basic/BuiltinsARM.def" |
| 1679 | }; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1680 | } // end anonymous namespace. |
| 1681 | |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1682 | |
| 1683 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | class DarwinARMTargetInfo : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1685 | public DarwinTargetInfo<ARMTargetInfo> { |
| 1686 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 1687 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1688 | MacroBuilder &Builder) const { |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 1689 | getDarwinDefines(Builder, Opts, Triple); |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 1690 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1691 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1692 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | DarwinARMTargetInfo(const std::string& triple) |
Daniel Dunbar | 350b9f3 | 2010-05-27 07:00:26 +0000 | [diff] [blame] | 1694 | : DarwinTargetInfo<ARMTargetInfo>(triple) { |
| 1695 | HasAlignMac68kSupport = true; |
| 1696 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1697 | }; |
| 1698 | } // end anonymous namespace. |
| 1699 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1700 | namespace { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1701 | class SparcV8TargetInfo : public TargetInfo { |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1702 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 1703 | static const char * const GCCRegNames[]; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1704 | public: |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1705 | SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 1706 | // FIXME: Support Sparc quad-precision long double? |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1707 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1708 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1709 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1710 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1711 | MacroBuilder &Builder) const { |
| 1712 | DefineStd(Builder, "sparc", Opts); |
| 1713 | Builder.defineMacro("__sparcv8"); |
| 1714 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1715 | } |
| 1716 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1717 | unsigned &NumRecords) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1718 | // FIXME: Implement! |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1719 | } |
| 1720 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1721 | return "typedef void* __builtin_va_list;"; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1722 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1723 | virtual void getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1724 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1725 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1726 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1727 | virtual bool validateAsmConstraint(const char *&Name, |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1728 | TargetInfo::ConstraintInfo &info) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1729 | // FIXME: Implement! |
| 1730 | return false; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1731 | } |
| 1732 | virtual const char *getClobbers() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1733 | // FIXME: Implement! |
| 1734 | return ""; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1735 | } |
| 1736 | }; |
| 1737 | |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1738 | const char * const SparcV8TargetInfo::GCCRegNames[] = { |
| 1739 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1740 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 1741 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 1742 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" |
| 1743 | }; |
| 1744 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1745 | void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1746 | unsigned &NumNames) const { |
| 1747 | Names = GCCRegNames; |
| 1748 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1749 | } |
| 1750 | |
| 1751 | const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1752 | { { "g0" }, "r0" }, |
| 1753 | { { "g1" }, "r1" }, |
| 1754 | { { "g2" }, "r2" }, |
| 1755 | { { "g3" }, "r3" }, |
| 1756 | { { "g4" }, "r4" }, |
| 1757 | { { "g5" }, "r5" }, |
| 1758 | { { "g6" }, "r6" }, |
| 1759 | { { "g7" }, "r7" }, |
| 1760 | { { "o0" }, "r8" }, |
| 1761 | { { "o1" }, "r9" }, |
| 1762 | { { "o2" }, "r10" }, |
| 1763 | { { "o3" }, "r11" }, |
| 1764 | { { "o4" }, "r12" }, |
| 1765 | { { "o5" }, "r13" }, |
| 1766 | { { "o6", "sp" }, "r14" }, |
| 1767 | { { "o7" }, "r15" }, |
| 1768 | { { "l0" }, "r16" }, |
| 1769 | { { "l1" }, "r17" }, |
| 1770 | { { "l2" }, "r18" }, |
| 1771 | { { "l3" }, "r19" }, |
| 1772 | { { "l4" }, "r20" }, |
| 1773 | { { "l5" }, "r21" }, |
| 1774 | { { "l6" }, "r22" }, |
| 1775 | { { "l7" }, "r23" }, |
| 1776 | { { "i0" }, "r24" }, |
| 1777 | { { "i1" }, "r25" }, |
| 1778 | { { "i2" }, "r26" }, |
| 1779 | { { "i3" }, "r27" }, |
| 1780 | { { "i4" }, "r28" }, |
| 1781 | { { "i5" }, "r29" }, |
| 1782 | { { "i6", "fp" }, "r30" }, |
| 1783 | { { "i7" }, "r31" }, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1784 | }; |
| 1785 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1786 | void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 1787 | unsigned &NumAliases) const { |
| 1788 | Aliases = GCCRegAliases; |
| 1789 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 1790 | } |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 1791 | } // end anonymous namespace. |
| 1792 | |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1793 | namespace { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 1794 | class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> { |
| 1795 | public: |
| 1796 | AuroraUXSparcV8TargetInfo(const std::string& triple) : |
| 1797 | AuroraUXTargetInfo<SparcV8TargetInfo>(triple) { |
| 1798 | SizeType = UnsignedInt; |
| 1799 | PtrDiffType = SignedInt; |
| 1800 | } |
| 1801 | }; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1802 | class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1803 | public: |
| 1804 | SolarisSparcV8TargetInfo(const std::string& triple) : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1805 | SolarisTargetInfo<SparcV8TargetInfo>(triple) { |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 1806 | SizeType = UnsignedInt; |
| 1807 | PtrDiffType = SignedInt; |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1808 | } |
| 1809 | }; |
| 1810 | } // end anonymous namespace. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1811 | |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1812 | namespace { |
| 1813 | class PIC16TargetInfo : public TargetInfo{ |
| 1814 | public: |
| 1815 | PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) { |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 1816 | TLSSupported = false; |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1817 | IntWidth = 16; |
| 1818 | LongWidth = LongLongWidth = 32; |
| 1819 | PointerWidth = 16; |
| 1820 | IntAlign = 8; |
| 1821 | LongAlign = LongLongAlign = 8; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1822 | PointerAlign = 8; |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1823 | SizeType = UnsignedInt; |
| 1824 | IntMaxType = SignedLong; |
| 1825 | UIntMaxType = UnsignedLong; |
Chris Lattner | 6ad474f | 2009-02-13 22:28:55 +0000 | [diff] [blame] | 1826 | IntPtrType = SignedShort; |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 1827 | PtrDiffType = SignedInt; |
Edward O'Callaghan | 9cf910e | 2009-11-21 00:49:54 +0000 | [diff] [blame] | 1828 | SigAtomicType = SignedLong; |
Sanjiv Gupta | 9eb4cef | 2009-06-02 04:43:46 +0000 | [diff] [blame] | 1829 | FloatWidth = 32; |
| 1830 | FloatAlign = 32; |
| 1831 | DoubleWidth = 32; |
| 1832 | DoubleAlign = 32; |
| 1833 | LongDoubleWidth = 32; |
| 1834 | LongDoubleAlign = 32; |
| 1835 | FloatFormat = &llvm::APFloat::IEEEsingle; |
| 1836 | DoubleFormat = &llvm::APFloat::IEEEsingle; |
| 1837 | LongDoubleFormat = &llvm::APFloat::IEEEsingle; |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1838 | DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-f32:32:32-n8"; |
Sanjiv Gupta | 9eb4cef | 2009-06-02 04:43:46 +0000 | [diff] [blame] | 1839 | |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1840 | } |
Chris Lattner | 927686f | 2008-05-09 06:08:39 +0000 | [diff] [blame] | 1841 | virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; } |
| 1842 | virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1843 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1844 | MacroBuilder &Builder) const { |
| 1845 | Builder.defineMacro("__pic16"); |
Sanjiv Gupta | fcd302b | 2010-02-16 03:37:11 +0000 | [diff] [blame] | 1846 | Builder.defineMacro("__PIC16"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1847 | Builder.defineMacro("rom", "__attribute__((address_space(1)))"); |
| 1848 | Builder.defineMacro("ram", "__attribute__((address_space(0)))"); |
Sanjiv Gupta | fcd302b | 2010-02-16 03:37:11 +0000 | [diff] [blame] | 1849 | Builder.defineMacro("__section(SectName)", |
Sanjiv Gupta | da3e03e | 2009-08-20 17:48:52 +0000 | [diff] [blame] | 1850 | "__attribute__((section(SectName)))"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1851 | Builder.defineMacro("near", |
Sanjiv Gupta | 7de7009 | 2009-10-24 18:08:20 +0000 | [diff] [blame] | 1852 | "__attribute__((section(\"Address=NEAR\")))"); |
Sanjiv Gupta | fcd302b | 2010-02-16 03:37:11 +0000 | [diff] [blame] | 1853 | Builder.defineMacro("__address(Addr)", |
Sanjiv Gupta | da3e03e | 2009-08-20 17:48:52 +0000 | [diff] [blame] | 1854 | "__attribute__((section(\"Address=\"#Addr)))"); |
Sanjiv Gupta | fcd302b | 2010-02-16 03:37:11 +0000 | [diff] [blame] | 1855 | Builder.defineMacro("__config(conf)", "asm(\"CONFIG \"#conf)"); |
| 1856 | Builder.defineMacro("__idlocs(value)", "asm(\"__IDLOCS \"#value)"); |
| 1857 | Builder.defineMacro("interrupt", |
Sanjiv Gupta | da3e03e | 2009-08-20 17:48:52 +0000 | [diff] [blame] | 1858 | "__attribute__((section(\"interrupt=0x4\"))) \ |
| 1859 | __attribute__((used))"); |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1860 | } |
| 1861 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1862 | unsigned &NumRecords) const {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | virtual const char *getVAListDeclaration() const { |
Sanjiv Gupta | fcd302b | 2010-02-16 03:37:11 +0000 | [diff] [blame] | 1864 | return "typedef char* __builtin_va_list;"; |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1865 | } |
| 1866 | virtual const char *getClobbers() const { |
| 1867 | return ""; |
| 1868 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1869 | virtual void getGCCRegNames(const char * const *&Names, |
| 1870 | unsigned &NumNames) const {} |
| 1871 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1872 | TargetInfo::ConstraintInfo &info) const { |
| 1873 | return true; |
| 1874 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1875 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1876 | unsigned &NumAliases) const {} |
| 1877 | virtual bool useGlobalsForAutomaticVariables() const {return true;} |
| 1878 | }; |
| 1879 | } |
| 1880 | |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1881 | namespace { |
| 1882 | class MSP430TargetInfo : public TargetInfo { |
| 1883 | static const char * const GCCRegNames[]; |
| 1884 | public: |
| 1885 | MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 1886 | TLSSupported = false; |
Anton Korobeynikov | 09f52a6 | 2010-01-30 12:55:11 +0000 | [diff] [blame] | 1887 | IntWidth = 16; IntAlign = 16; |
| 1888 | LongWidth = 32; LongLongWidth = 64; |
| 1889 | LongAlign = LongLongAlign = 16; |
| 1890 | PointerWidth = 16; PointerAlign = 16; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1891 | SizeType = UnsignedInt; |
| 1892 | IntMaxType = SignedLong; |
| 1893 | UIntMaxType = UnsignedLong; |
| 1894 | IntPtrType = SignedShort; |
| 1895 | PtrDiffType = SignedInt; |
Edward O'Callaghan | 9cf910e | 2009-11-21 00:49:54 +0000 | [diff] [blame] | 1896 | SigAtomicType = SignedLong; |
Anton Korobeynikov | 5d7c251 | 2009-12-19 01:32:37 +0000 | [diff] [blame] | 1897 | DescriptionString = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1898 | } |
| 1899 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1900 | MacroBuilder &Builder) const { |
| 1901 | Builder.defineMacro("MSP430"); |
| 1902 | Builder.defineMacro("__MSP430__"); |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1903 | // FIXME: defines for different 'flavours' of MCU |
| 1904 | } |
| 1905 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1906 | unsigned &NumRecords) const { |
| 1907 | // FIXME: Implement. |
| 1908 | Records = 0; |
| 1909 | NumRecords = 0; |
| 1910 | } |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1911 | virtual void getGCCRegNames(const char * const *&Names, |
| 1912 | unsigned &NumNames) const; |
| 1913 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1914 | unsigned &NumAliases) const { |
| 1915 | // No aliases. |
| 1916 | Aliases = 0; |
| 1917 | NumAliases = 0; |
| 1918 | } |
| 1919 | virtual bool validateAsmConstraint(const char *&Name, |
| 1920 | TargetInfo::ConstraintInfo &info) const { |
Anton Korobeynikov | 03265b6 | 2009-10-15 23:17:13 +0000 | [diff] [blame] | 1921 | // No target constraints for now. |
| 1922 | return false; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1923 | } |
| 1924 | virtual const char *getClobbers() const { |
| 1925 | // FIXME: Is this really right? |
| 1926 | return ""; |
| 1927 | } |
| 1928 | virtual const char *getVAListDeclaration() const { |
| 1929 | // FIXME: implement |
Anton Korobeynikov | eb71685 | 2009-05-08 18:24:57 +0000 | [diff] [blame] | 1930 | return "typedef char* __builtin_va_list;"; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 1931 | } |
| 1932 | }; |
| 1933 | |
| 1934 | const char * const MSP430TargetInfo::GCCRegNames[] = { |
| 1935 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1936 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 1937 | }; |
| 1938 | |
| 1939 | void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, |
| 1940 | unsigned &NumNames) const { |
| 1941 | Names = GCCRegNames; |
| 1942 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 1947 | namespace { |
| 1948 | class SystemZTargetInfo : public TargetInfo { |
| 1949 | static const char * const GCCRegNames[]; |
| 1950 | public: |
| 1951 | SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 1952 | TLSSupported = false; |
| 1953 | IntWidth = IntAlign = 32; |
| 1954 | LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; |
| 1955 | PointerWidth = PointerAlign = 64; |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 1956 | DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-" |
| 1957 | "i64:64:64-f32:32:32-f64:64:64-f128:128:128-a0:16:16-n32:64"; |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 1958 | } |
| 1959 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1960 | MacroBuilder &Builder) const { |
| 1961 | Builder.defineMacro("__s390__"); |
| 1962 | Builder.defineMacro("__s390x__"); |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 1963 | } |
| 1964 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1965 | unsigned &NumRecords) const { |
| 1966 | // FIXME: Implement. |
| 1967 | Records = 0; |
| 1968 | NumRecords = 0; |
| 1969 | } |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 1970 | |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 1971 | virtual void getGCCRegNames(const char * const *&Names, |
| 1972 | unsigned &NumNames) const; |
| 1973 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1974 | unsigned &NumAliases) const { |
| 1975 | // No aliases. |
| 1976 | Aliases = 0; |
| 1977 | NumAliases = 0; |
| 1978 | } |
| 1979 | virtual bool validateAsmConstraint(const char *&Name, |
| 1980 | TargetInfo::ConstraintInfo &info) const { |
| 1981 | // FIXME: implement |
| 1982 | return true; |
| 1983 | } |
| 1984 | virtual const char *getClobbers() const { |
| 1985 | // FIXME: Is this really right? |
| 1986 | return ""; |
| 1987 | } |
| 1988 | virtual const char *getVAListDeclaration() const { |
| 1989 | // FIXME: implement |
| 1990 | return "typedef char* __builtin_va_list;"; |
| 1991 | } |
| 1992 | }; |
| 1993 | |
| 1994 | const char * const SystemZTargetInfo::GCCRegNames[] = { |
| 1995 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1996 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 1997 | }; |
| 1998 | |
| 1999 | void SystemZTargetInfo::getGCCRegNames(const char * const *&Names, |
| 2000 | unsigned &NumNames) const { |
| 2001 | Names = GCCRegNames; |
| 2002 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2003 | } |
| 2004 | } |
| 2005 | |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2006 | namespace { |
| 2007 | class BlackfinTargetInfo : public TargetInfo { |
| 2008 | static const char * const GCCRegNames[]; |
| 2009 | public: |
| 2010 | BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2011 | TLSSupported = false; |
| 2012 | DoubleAlign = 32; |
| 2013 | LongLongAlign = 32; |
| 2014 | LongDoubleAlign = 32; |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 2015 | DescriptionString = "e-p:32:32-i64:32-f64:32-n32"; |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2019 | MacroBuilder &Builder) const { |
| 2020 | DefineStd(Builder, "bfin", Opts); |
| 2021 | DefineStd(Builder, "BFIN", Opts); |
| 2022 | Builder.defineMacro("__ADSPBLACKFIN__"); |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2023 | // FIXME: This one is really dependent on -mcpu |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2024 | Builder.defineMacro("__ADSPLPBLACKFIN__"); |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2025 | // FIXME: Add cpu-dependent defines and __SILICON_REVISION__ |
| 2026 | } |
| 2027 | |
| 2028 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2029 | unsigned &NumRecords) const { |
| 2030 | // FIXME: Implement. |
| 2031 | Records = 0; |
| 2032 | NumRecords = 0; |
| 2033 | } |
| 2034 | |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2035 | virtual void getGCCRegNames(const char * const *&Names, |
| 2036 | unsigned &NumNames) const; |
| 2037 | |
| 2038 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2039 | unsigned &NumAliases) const { |
| 2040 | // No aliases. |
| 2041 | Aliases = 0; |
| 2042 | NumAliases = 0; |
| 2043 | } |
| 2044 | |
| 2045 | virtual bool validateAsmConstraint(const char *&Name, |
| 2046 | TargetInfo::ConstraintInfo &Info) const { |
| 2047 | if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) { |
| 2048 | Info.setAllowsRegister(); |
| 2049 | return true; |
| 2050 | } |
| 2051 | return false; |
| 2052 | } |
| 2053 | |
| 2054 | virtual const char *getClobbers() const { |
| 2055 | return ""; |
| 2056 | } |
| 2057 | |
| 2058 | virtual const char *getVAListDeclaration() const { |
| 2059 | return "typedef char* __builtin_va_list;"; |
| 2060 | } |
| 2061 | }; |
| 2062 | |
| 2063 | const char * const BlackfinTargetInfo::GCCRegNames[] = { |
| 2064 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2065 | "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp", |
| 2066 | "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3", |
| 2067 | "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3", |
| 2068 | "a0", "a1", "cc", |
| 2069 | "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp", |
| 2070 | "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1" |
| 2071 | }; |
| 2072 | |
| 2073 | void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names, |
| 2074 | unsigned &NumNames) const { |
| 2075 | Names = GCCRegNames; |
| 2076 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2077 | } |
| 2078 | } |
| 2079 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2080 | namespace { |
| 2081 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2082 | // LLVM and Clang cannot be used directly to output native binaries for |
| 2083 | // target, but is used to compile C code to llvm bitcode with correct |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2084 | // type and alignment information. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2085 | // |
| 2086 | // TCE uses the llvm bitcode as input and uses it for generating customized |
| 2087 | // target processor and program binary. TCE co-design environment is |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2088 | // publicly available in http://tce.cs.tut.fi |
| 2089 | |
| 2090 | class TCETargetInfo : public TargetInfo{ |
| 2091 | public: |
| 2092 | TCETargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2093 | TLSSupported = false; |
| 2094 | IntWidth = 32; |
| 2095 | LongWidth = LongLongWidth = 32; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2096 | PointerWidth = 32; |
| 2097 | IntAlign = 32; |
| 2098 | LongAlign = LongLongAlign = 32; |
| 2099 | PointerAlign = 32; |
| 2100 | SizeType = UnsignedInt; |
| 2101 | IntMaxType = SignedLong; |
| 2102 | UIntMaxType = UnsignedLong; |
| 2103 | IntPtrType = SignedInt; |
| 2104 | PtrDiffType = SignedInt; |
| 2105 | FloatWidth = 32; |
| 2106 | FloatAlign = 32; |
| 2107 | DoubleWidth = 32; |
| 2108 | DoubleAlign = 32; |
| 2109 | LongDoubleWidth = 32; |
| 2110 | LongDoubleAlign = 32; |
| 2111 | FloatFormat = &llvm::APFloat::IEEEsingle; |
| 2112 | DoubleFormat = &llvm::APFloat::IEEEsingle; |
| 2113 | LongDoubleFormat = &llvm::APFloat::IEEEsingle; |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2114 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-" |
| 2115 | "i16:16:32-i32:32:32-i64:32:32-" |
| 2116 | "f32:32:32-f64:64:64-v64:64:64-" |
| 2117 | "v128:128:128-a0:0:64-n32"; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2121 | MacroBuilder &Builder) const { |
| 2122 | DefineStd(Builder, "tce", Opts); |
| 2123 | Builder.defineMacro("__TCE__"); |
| 2124 | Builder.defineMacro("__TCE_V1__"); |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2125 | } |
| 2126 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2127 | unsigned &NumRecords) const {} |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2128 | virtual const char *getClobbers() const { |
| 2129 | return ""; |
| 2130 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2131 | virtual const char *getVAListDeclaration() const { |
| 2132 | return "typedef void* __builtin_va_list;"; |
| 2133 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2134 | virtual void getGCCRegNames(const char * const *&Names, |
| 2135 | unsigned &NumNames) const {} |
| 2136 | virtual bool validateAsmConstraint(const char *&Name, |
| 2137 | TargetInfo::ConstraintInfo &info) const { |
| 2138 | return true; |
| 2139 | } |
| 2140 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2141 | unsigned &NumAliases) const {} |
| 2142 | }; |
| 2143 | } |
| 2144 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2145 | namespace { |
| 2146 | class MipsTargetInfo : public TargetInfo { |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2147 | std::string ABI, CPU; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2148 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 2149 | static const char * const GCCRegNames[]; |
| 2150 | public: |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2151 | MipsTargetInfo(const std::string& triple) : TargetInfo(triple), ABI("o32") { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2152 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2153 | "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2154 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2155 | virtual const char *getABI() const { return ABI.c_str(); } |
| 2156 | virtual bool setABI(const std::string &Name) { |
| 2157 | |
| 2158 | if ((Name == "o32") || (Name == "eabi")) { |
| 2159 | ABI = Name; |
| 2160 | return true; |
| 2161 | } else |
| 2162 | return false; |
| 2163 | } |
| 2164 | virtual bool setCPU(const std::string &Name) { |
| 2165 | CPU = Name; |
| 2166 | return true; |
| 2167 | } |
| 2168 | void getDefaultFeatures(const std::string &CPU, |
| 2169 | llvm::StringMap<bool> &Features) const { |
| 2170 | Features[ABI] = true; |
| 2171 | Features[CPU] = true; |
| 2172 | } |
| 2173 | virtual void getArchDefines(const LangOptions &Opts, |
| 2174 | MacroBuilder &Builder) const { |
| 2175 | if (ABI == "o32") |
| 2176 | Builder.defineMacro("__mips_o32"); |
| 2177 | else if (ABI == "eabi") |
| 2178 | Builder.defineMacro("__mips_eabi"); |
| 2179 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2180 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2181 | MacroBuilder &Builder) const { |
| 2182 | DefineStd(Builder, "mips", Opts); |
| 2183 | Builder.defineMacro("_mips"); |
| 2184 | DefineStd(Builder, "MIPSEB", Opts); |
| 2185 | Builder.defineMacro("_MIPSEB"); |
| 2186 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2187 | getArchDefines(Opts, Builder); |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2188 | } |
| 2189 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2190 | unsigned &NumRecords) const { |
| 2191 | // FIXME: Implement! |
| 2192 | } |
| 2193 | virtual const char *getVAListDeclaration() const { |
| 2194 | return "typedef void* __builtin_va_list;"; |
| 2195 | } |
| 2196 | virtual void getGCCRegNames(const char * const *&Names, |
| 2197 | unsigned &NumNames) const; |
| 2198 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2199 | unsigned &NumAliases) const; |
| 2200 | virtual bool validateAsmConstraint(const char *&Name, |
| 2201 | TargetInfo::ConstraintInfo &Info) const { |
| 2202 | switch (*Name) { |
| 2203 | default: |
| 2204 | case 'r': // CPU registers. |
| 2205 | case 'd': // Equivalent to "r" unless generating MIPS16 code. |
| 2206 | case 'y': // Equivalent to "r", backwards compatibility only. |
| 2207 | case 'f': // floating-point registers. |
| 2208 | Info.setAllowsRegister(); |
| 2209 | return true; |
| 2210 | } |
| 2211 | return false; |
| 2212 | } |
| 2213 | |
| 2214 | virtual const char *getClobbers() const { |
| 2215 | // FIXME: Implement! |
| 2216 | return ""; |
| 2217 | } |
| 2218 | }; |
| 2219 | |
| 2220 | const char * const MipsTargetInfo::GCCRegNames[] = { |
| 2221 | "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", |
| 2222 | "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", |
| 2223 | "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23", |
| 2224 | "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31", |
| 2225 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 2226 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 2227 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 2228 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
| 2229 | "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4", |
| 2230 | "$fcc5","$fcc6","$fcc7" |
| 2231 | }; |
| 2232 | |
| 2233 | void MipsTargetInfo::getGCCRegNames(const char * const *&Names, |
| 2234 | unsigned &NumNames) const { |
| 2235 | Names = GCCRegNames; |
| 2236 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2237 | } |
| 2238 | |
| 2239 | const TargetInfo::GCCRegAlias MipsTargetInfo::GCCRegAliases[] = { |
| 2240 | { { "at" }, "$1" }, |
| 2241 | { { "v0" }, "$2" }, |
| 2242 | { { "v1" }, "$3" }, |
| 2243 | { { "a0" }, "$4" }, |
| 2244 | { { "a1" }, "$5" }, |
| 2245 | { { "a2" }, "$6" }, |
| 2246 | { { "a3" }, "$7" }, |
| 2247 | { { "t0" }, "$8" }, |
| 2248 | { { "t1" }, "$9" }, |
| 2249 | { { "t2" }, "$10" }, |
| 2250 | { { "t3" }, "$11" }, |
| 2251 | { { "t4" }, "$12" }, |
| 2252 | { { "t5" }, "$13" }, |
| 2253 | { { "t6" }, "$14" }, |
| 2254 | { { "t7" }, "$15" }, |
| 2255 | { { "s0" }, "$16" }, |
| 2256 | { { "s1" }, "$17" }, |
| 2257 | { { "s2" }, "$18" }, |
| 2258 | { { "s3" }, "$19" }, |
| 2259 | { { "s4" }, "$20" }, |
| 2260 | { { "s5" }, "$21" }, |
| 2261 | { { "s6" }, "$22" }, |
| 2262 | { { "s7" }, "$23" }, |
| 2263 | { { "t8" }, "$24" }, |
| 2264 | { { "t9" }, "$25" }, |
| 2265 | { { "k0" }, "$26" }, |
| 2266 | { { "k1" }, "$27" }, |
| 2267 | { { "gp" }, "$28" }, |
| 2268 | { { "sp" }, "$29" }, |
| 2269 | { { "fp" }, "$30" }, |
| 2270 | { { "ra" }, "$31" } |
| 2271 | }; |
| 2272 | |
| 2273 | void MipsTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2274 | unsigned &NumAliases) const { |
| 2275 | Aliases = GCCRegAliases; |
| 2276 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 2277 | } |
| 2278 | } // end anonymous namespace. |
| 2279 | |
| 2280 | namespace { |
| 2281 | class MipselTargetInfo : public MipsTargetInfo { |
| 2282 | public: |
| 2283 | MipselTargetInfo(const std::string& triple) : MipsTargetInfo(triple) { |
| 2284 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2285 | "i64:32:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2286 | } |
| 2287 | |
| 2288 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2289 | MacroBuilder &Builder) const; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2290 | }; |
| 2291 | |
| 2292 | void MipselTargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2293 | MacroBuilder &Builder) const { |
| 2294 | DefineStd(Builder, "mips", Opts); |
| 2295 | Builder.defineMacro("_mips"); |
| 2296 | DefineStd(Builder, "MIPSEL", Opts); |
| 2297 | Builder.defineMacro("_MIPSEL"); |
| 2298 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2299 | getArchDefines(Opts, Builder); |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } // end anonymous namespace. |
| 2302 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2303 | //===----------------------------------------------------------------------===// |
| 2304 | // Driver code |
| 2305 | //===----------------------------------------------------------------------===// |
| 2306 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2307 | static TargetInfo *AllocateTarget(const std::string &T) { |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2308 | llvm::Triple Triple(T); |
| 2309 | llvm::Triple::OSType os = Triple.getOS(); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2310 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2311 | switch (Triple.getArch()) { |
| 2312 | default: |
| 2313 | return NULL; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2314 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2315 | case llvm::Triple::arm: |
Daniel Dunbar | f4aa4f61 | 2009-09-11 01:14:50 +0000 | [diff] [blame] | 2316 | case llvm::Triple::thumb: |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2317 | switch (os) { |
| 2318 | case llvm::Triple::Darwin: |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 2319 | return new DarwinARMTargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2320 | case llvm::Triple::FreeBSD: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2321 | return new FreeBSDTargetInfo<ARMTargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2322 | default: |
| 2323 | return new ARMTargetInfo(T); |
| 2324 | } |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2325 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2326 | case llvm::Triple::bfin: |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2327 | return new BlackfinTargetInfo(T); |
| 2328 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2329 | case llvm::Triple::msp430: |
| 2330 | return new MSP430TargetInfo(T); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2331 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2332 | case llvm::Triple::mips: |
| 2333 | if (os == llvm::Triple::Psp) |
| 2334 | return new PSPTargetInfo<MipsTargetInfo>(T); |
| 2335 | if (os == llvm::Triple::Linux) |
| 2336 | return new LinuxTargetInfo<MipsTargetInfo>(T); |
| 2337 | return new MipsTargetInfo(T); |
| 2338 | |
| 2339 | case llvm::Triple::mipsel: |
| 2340 | if (os == llvm::Triple::Psp) |
| 2341 | return new PSPTargetInfo<MipselTargetInfo>(T); |
| 2342 | if (os == llvm::Triple::Linux) |
| 2343 | return new LinuxTargetInfo<MipselTargetInfo>(T); |
| 2344 | return new MipselTargetInfo(T); |
| 2345 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2346 | case llvm::Triple::pic16: |
| 2347 | return new PIC16TargetInfo(T); |
| 2348 | |
| 2349 | case llvm::Triple::ppc: |
| 2350 | if (os == llvm::Triple::Darwin) |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 2351 | return new DarwinPPCTargetInfo(T); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 2352 | else if (os == llvm::Triple::FreeBSD) |
| 2353 | return new FreeBSDTargetInfo<PPC32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2354 | return new PPC32TargetInfo(T); |
| 2355 | |
| 2356 | case llvm::Triple::ppc64: |
| 2357 | if (os == llvm::Triple::Darwin) |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 2358 | return new DarwinPPC64TargetInfo(T); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 2359 | else if (os == llvm::Triple::Lv2) |
| 2360 | return new PS3PPUTargetInfo<PPC64TargetInfo>(T); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 2361 | else if (os == llvm::Triple::FreeBSD) |
| 2362 | return new FreeBSDTargetInfo<PPC64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2363 | return new PPC64TargetInfo(T); |
| 2364 | |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 2365 | case llvm::Triple::mblaze: |
| 2366 | return new MBlazeTargetInfo(T); |
| 2367 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2368 | case llvm::Triple::sparc: |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 2369 | if (os == llvm::Triple::AuroraUX) |
| 2370 | return new AuroraUXSparcV8TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2371 | if (os == llvm::Triple::Solaris) |
| 2372 | return new SolarisSparcV8TargetInfo(T); |
| 2373 | return new SparcV8TargetInfo(T); |
| 2374 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 2375 | // FIXME: Need a real SPU target. |
| 2376 | case llvm::Triple::cellspu: |
| 2377 | return new PS3SPUTargetInfo<PPC64TargetInfo>(T); |
| 2378 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2379 | case llvm::Triple::systemz: |
| 2380 | return new SystemZTargetInfo(T); |
| 2381 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2382 | case llvm::Triple::tce: |
| 2383 | return new TCETargetInfo(T); |
| 2384 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2385 | case llvm::Triple::x86: |
| 2386 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 2387 | case llvm::Triple::AuroraUX: |
| 2388 | return new AuroraUXTargetInfo<X86_32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2389 | case llvm::Triple::Darwin: |
| 2390 | return new DarwinI386TargetInfo(T); |
| 2391 | case llvm::Triple::Linux: |
| 2392 | return new LinuxTargetInfo<X86_32TargetInfo>(T); |
| 2393 | case llvm::Triple::DragonFly: |
| 2394 | return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); |
| 2395 | case llvm::Triple::NetBSD: |
| 2396 | return new NetBSDTargetInfo<X86_32TargetInfo>(T); |
| 2397 | case llvm::Triple::OpenBSD: |
| 2398 | return new OpenBSDI386TargetInfo(T); |
| 2399 | case llvm::Triple::FreeBSD: |
| 2400 | return new FreeBSDTargetInfo<X86_32TargetInfo>(T); |
| 2401 | case llvm::Triple::Solaris: |
| 2402 | return new SolarisTargetInfo<X86_32TargetInfo>(T); |
| 2403 | case llvm::Triple::Cygwin: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2404 | return new CygwinX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2405 | case llvm::Triple::MinGW32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2406 | return new MinGWX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2407 | case llvm::Triple::Win32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2408 | return new VisualStudioWindowsX86_32TargetInfo(T); |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 2409 | case llvm::Triple::Haiku: |
| 2410 | return new HaikuX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2411 | default: |
| 2412 | return new X86_32TargetInfo(T); |
| 2413 | } |
| 2414 | |
| 2415 | case llvm::Triple::x86_64: |
| 2416 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 2417 | case llvm::Triple::AuroraUX: |
| 2418 | return new AuroraUXTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2419 | case llvm::Triple::Darwin: |
| 2420 | return new DarwinX86_64TargetInfo(T); |
| 2421 | case llvm::Triple::Linux: |
| 2422 | return new LinuxTargetInfo<X86_64TargetInfo>(T); |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 2423 | case llvm::Triple::DragonFly: |
| 2424 | return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2425 | case llvm::Triple::NetBSD: |
| 2426 | return new NetBSDTargetInfo<X86_64TargetInfo>(T); |
| 2427 | case llvm::Triple::OpenBSD: |
| 2428 | return new OpenBSDX86_64TargetInfo(T); |
| 2429 | case llvm::Triple::FreeBSD: |
| 2430 | return new FreeBSDTargetInfo<X86_64TargetInfo>(T); |
| 2431 | case llvm::Triple::Solaris: |
| 2432 | return new SolarisTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2433 | case llvm::Triple::MinGW64: |
| 2434 | return new MinGWX86_64TargetInfo(T); |
| 2435 | case llvm::Triple::Win32: // This is what Triple.h supports now. |
| 2436 | return new VisualStudioWindowsX86_64TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 2437 | default: |
| 2438 | return new X86_64TargetInfo(T); |
| 2439 | } |
| 2440 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2441 | } |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2442 | |
| 2443 | /// CreateTargetInfo - Return the target info object for the specified target |
| 2444 | /// triple. |
| 2445 | TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 2446 | TargetOptions &Opts) { |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2447 | llvm::Triple Triple(Opts.Triple); |
| 2448 | |
| 2449 | // Construct the target |
| 2450 | llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str())); |
| 2451 | if (!Target) { |
| 2452 | Diags.Report(diag::err_target_unknown_triple) << Triple.str(); |
| 2453 | return 0; |
| 2454 | } |
| 2455 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2456 | // Set the target CPU if specified. |
| 2457 | if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) { |
| 2458 | Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU; |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2462 | // Set the target ABI if specified. |
| 2463 | if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) { |
| 2464 | Diags.Report(diag::err_target_unknown_abi) << Opts.ABI; |
| 2465 | return 0; |
| 2466 | } |
| 2467 | |
| 2468 | // Compute the default target features, we need the target to handle this |
| 2469 | // because features may have dependencies on one another. |
| 2470 | llvm::StringMap<bool> Features; |
| 2471 | Target->getDefaultFeatures(Opts.CPU, Features); |
| 2472 | |
| 2473 | // Apply the user specified deltas. |
| 2474 | for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), |
| 2475 | ie = Opts.Features.end(); it != ie; ++it) { |
| 2476 | const char *Name = it->c_str(); |
| 2477 | |
| 2478 | // Apply the feature via the target. |
| 2479 | if ((Name[0] != '-' && Name[0] != '+') || |
| 2480 | !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { |
| 2481 | Diags.Report(diag::err_target_invalid_feature) << Name; |
| 2482 | return 0; |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | // Add the features to the compile options. |
| 2487 | // |
| 2488 | // FIXME: If we are completely confident that we have the right set, we only |
| 2489 | // need to pass the minuses. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 2490 | Opts.Features.clear(); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2491 | for (llvm::StringMap<bool>::const_iterator it = Features.begin(), |
| 2492 | ie = Features.end(); it != ie; ++it) |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 2493 | Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first()); |
| 2494 | Target->HandleTargetFeatures(Opts.Features); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 2495 | |
| 2496 | return Target.take(); |
| 2497 | } |