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