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