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