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