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. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 40 | static void DefineStd(MacroBuilder &Builder, 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, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 80 | StringRef &PlatformName, |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 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). |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 92 | if (Opts.getGC() != LangOptions::NonGC) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 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 |
Eric Christopher | 895d422 | 2011-07-29 21:20:35 +0000 | [diff] [blame] | 150 | // generating code for Win32 ABI. No need to emit |
Chad Rosier | d9259f3 | 2011-07-19 20:00:06 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 205 | virtual std::string isValidSectionSpecifier(StringRef SR) const { |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 206 | // Let MCSectionMachO validate this. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 207 | StringRef Segment, Section; |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 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. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 250 | 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) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 506 | Builder.defineMacro("_MSC_VER", Twine(Opts.MSCVersion)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 507 | |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 508 | if (Opts.MicrosoftExt) { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 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[]; |
Justin Holewinski | d8e0fe6 | 2011-09-22 17:57:40 +0000 | [diff] [blame] | 883 | std::vector<llvm::StringRef> AvailableFeatures; |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 884 | public: |
| 885 | PTXTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 886 | TLSSupported = false; |
| 887 | LongWidth = LongAlign = 64; |
Justin Holewinski | d8e0fe6 | 2011-09-22 17:57:40 +0000 | [diff] [blame] | 888 | // Define available target features |
| 889 | // These must be defined in sorted order! |
| 890 | AvailableFeatures.push_back("compute10"); |
| 891 | AvailableFeatures.push_back("compute11"); |
| 892 | AvailableFeatures.push_back("compute12"); |
| 893 | AvailableFeatures.push_back("compute13"); |
| 894 | AvailableFeatures.push_back("compute20"); |
| 895 | AvailableFeatures.push_back("double"); |
| 896 | AvailableFeatures.push_back("no-fma"); |
| 897 | AvailableFeatures.push_back("ptx20"); |
| 898 | AvailableFeatures.push_back("ptx21"); |
| 899 | AvailableFeatures.push_back("ptx22"); |
| 900 | AvailableFeatures.push_back("ptx23"); |
| 901 | AvailableFeatures.push_back("sm10"); |
| 902 | AvailableFeatures.push_back("sm11"); |
| 903 | AvailableFeatures.push_back("sm12"); |
| 904 | AvailableFeatures.push_back("sm13"); |
| 905 | AvailableFeatures.push_back("sm20"); |
| 906 | AvailableFeatures.push_back("sm21"); |
| 907 | AvailableFeatures.push_back("sm22"); |
| 908 | AvailableFeatures.push_back("sm23"); |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 909 | } |
| 910 | virtual void getTargetDefines(const LangOptions &Opts, |
| 911 | MacroBuilder &Builder) const { |
| 912 | Builder.defineMacro("__PTX__"); |
| 913 | } |
| 914 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 915 | unsigned &NumRecords) const { |
| 916 | Records = BuiltinInfo; |
| 917 | NumRecords = clang::PTX::LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 918 | } |
| 919 | |
| 920 | virtual void getGCCRegNames(const char * const *&Names, |
| 921 | unsigned &NumNames) const; |
| 922 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 923 | unsigned &NumAliases) const { |
| 924 | // No aliases. |
| 925 | Aliases = 0; |
| 926 | NumAliases = 0; |
| 927 | } |
| 928 | virtual bool validateAsmConstraint(const char *&Name, |
| 929 | TargetInfo::ConstraintInfo &info) const { |
| 930 | // FIXME: implement |
| 931 | return true; |
| 932 | } |
| 933 | virtual const char *getClobbers() const { |
| 934 | // FIXME: Is this really right? |
| 935 | return ""; |
| 936 | } |
| 937 | virtual const char *getVAListDeclaration() const { |
| 938 | // FIXME: implement |
| 939 | return "typedef char* __builtin_va_list;"; |
| 940 | } |
Justin Holewinski | 808ef66 | 2011-09-15 12:13:38 +0000 | [diff] [blame] | 941 | |
| 942 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 943 | const std::string &Name, |
| 944 | bool Enabled) const; |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 945 | }; |
| 946 | |
| 947 | const Builtin::Info PTXTargetInfo::BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 948 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 949 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 950 | ALL_LANGUAGES }, |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 951 | #include "clang/Basic/BuiltinsPTX.def" |
| 952 | }; |
| 953 | |
| 954 | const char * const PTXTargetInfo::GCCRegNames[] = { |
| 955 | "r0" |
| 956 | }; |
| 957 | |
| 958 | void PTXTargetInfo::getGCCRegNames(const char * const *&Names, |
| 959 | unsigned &NumNames) const { |
| 960 | Names = GCCRegNames; |
| 961 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 962 | } |
| 963 | |
Justin Holewinski | 808ef66 | 2011-09-15 12:13:38 +0000 | [diff] [blame] | 964 | bool PTXTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 965 | const std::string &Name, |
| 966 | bool Enabled) const { |
Justin Holewinski | d8e0fe6 | 2011-09-22 17:57:40 +0000 | [diff] [blame] | 967 | if(std::binary_search(AvailableFeatures.begin(), AvailableFeatures.end(), |
| 968 | Name)) { |
| 969 | Features[Name] = Enabled; |
| 970 | return true; |
Justin Holewinski | 808ef66 | 2011-09-15 12:13:38 +0000 | [diff] [blame] | 971 | } else { |
Justin Holewinski | d8e0fe6 | 2011-09-22 17:57:40 +0000 | [diff] [blame] | 972 | return false; |
Justin Holewinski | 808ef66 | 2011-09-15 12:13:38 +0000 | [diff] [blame] | 973 | } |
Justin Holewinski | 808ef66 | 2011-09-15 12:13:38 +0000 | [diff] [blame] | 974 | } |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 975 | |
| 976 | class PTX32TargetInfo : public PTXTargetInfo { |
| 977 | public: |
| 978 | PTX32TargetInfo(const std::string& triple) : PTXTargetInfo(triple) { |
| 979 | PointerWidth = PointerAlign = 32; |
| 980 | SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt; |
| 981 | DescriptionString |
| 982 | = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64"; |
| 983 | } |
| 984 | }; |
| 985 | |
| 986 | class PTX64TargetInfo : public PTXTargetInfo { |
| 987 | public: |
| 988 | PTX64TargetInfo(const std::string& triple) : PTXTargetInfo(triple) { |
| 989 | PointerWidth = PointerAlign = 64; |
| 990 | SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong; |
| 991 | DescriptionString |
| 992 | = "e-p:64:64-i64:64:64-f64:64:64-n1:8:16:32:64"; |
| 993 | } |
| 994 | }; |
| 995 | } |
| 996 | |
| 997 | namespace { |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 998 | // MBlaze abstract base class |
| 999 | class MBlazeTargetInfo : public TargetInfo { |
| 1000 | static const char * const GCCRegNames[]; |
| 1001 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 1002 | |
| 1003 | public: |
| 1004 | MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) { |
Wesley Peck | a48fa4b | 2010-12-12 20:56:47 +0000 | [diff] [blame] | 1005 | DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16"; |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1009 | unsigned &NumRecords) const { |
| 1010 | // FIXME: Implement. |
| 1011 | Records = 0; |
| 1012 | NumRecords = 0; |
| 1013 | } |
| 1014 | |
| 1015 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1016 | MacroBuilder &Builder) const; |
| 1017 | |
| 1018 | virtual const char *getVAListDeclaration() const { |
| 1019 | return "typedef char* __builtin_va_list;"; |
| 1020 | } |
| 1021 | virtual const char *getTargetPrefix() const { |
| 1022 | return "mblaze"; |
| 1023 | } |
| 1024 | virtual void getGCCRegNames(const char * const *&Names, |
| 1025 | unsigned &NumNames) const; |
| 1026 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1027 | unsigned &NumAliases) const; |
| 1028 | virtual bool validateAsmConstraint(const char *&Name, |
| 1029 | TargetInfo::ConstraintInfo &Info) const { |
| 1030 | switch (*Name) { |
| 1031 | default: return false; |
| 1032 | case 'O': // Zero |
| 1033 | return true; |
| 1034 | case 'b': // Base register |
| 1035 | case 'f': // Floating point register |
| 1036 | Info.setAllowsRegister(); |
| 1037 | return true; |
| 1038 | } |
| 1039 | } |
| 1040 | virtual const char *getClobbers() const { |
| 1041 | return ""; |
| 1042 | } |
| 1043 | }; |
| 1044 | |
| 1045 | /// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific |
| 1046 | /// #defines that are not tied to a specific subtarget. |
| 1047 | void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts, |
| 1048 | MacroBuilder &Builder) const { |
| 1049 | // Target identification. |
| 1050 | Builder.defineMacro("__microblaze__"); |
| 1051 | Builder.defineMacro("_ARCH_MICROBLAZE"); |
| 1052 | Builder.defineMacro("__MICROBLAZE__"); |
| 1053 | |
| 1054 | // Target properties. |
| 1055 | Builder.defineMacro("_BIG_ENDIAN"); |
| 1056 | Builder.defineMacro("__BIG_ENDIAN__"); |
| 1057 | |
| 1058 | // Subtarget options. |
| 1059 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | const char * const MBlazeTargetInfo::GCCRegNames[] = { |
| 1064 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1065 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 1066 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 1067 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 1068 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 1069 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 1070 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 1071 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
| 1072 | "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4", |
| 1073 | "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp" |
| 1074 | }; |
| 1075 | |
| 1076 | void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names, |
| 1077 | unsigned &NumNames) const { |
| 1078 | Names = GCCRegNames; |
| 1079 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1080 | } |
| 1081 | |
| 1082 | const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = { |
| 1083 | { {"f0"}, "r0" }, |
| 1084 | { {"f1"}, "r1" }, |
| 1085 | { {"f2"}, "r2" }, |
| 1086 | { {"f3"}, "r3" }, |
| 1087 | { {"f4"}, "r4" }, |
| 1088 | { {"f5"}, "r5" }, |
| 1089 | { {"f6"}, "r6" }, |
| 1090 | { {"f7"}, "r7" }, |
| 1091 | { {"f8"}, "r8" }, |
| 1092 | { {"f9"}, "r9" }, |
| 1093 | { {"f10"}, "r10" }, |
| 1094 | { {"f11"}, "r11" }, |
| 1095 | { {"f12"}, "r12" }, |
| 1096 | { {"f13"}, "r13" }, |
| 1097 | { {"f14"}, "r14" }, |
| 1098 | { {"f15"}, "r15" }, |
| 1099 | { {"f16"}, "r16" }, |
| 1100 | { {"f17"}, "r17" }, |
| 1101 | { {"f18"}, "r18" }, |
| 1102 | { {"f19"}, "r19" }, |
| 1103 | { {"f20"}, "r20" }, |
| 1104 | { {"f21"}, "r21" }, |
| 1105 | { {"f22"}, "r22" }, |
| 1106 | { {"f23"}, "r23" }, |
| 1107 | { {"f24"}, "r24" }, |
| 1108 | { {"f25"}, "r25" }, |
| 1109 | { {"f26"}, "r26" }, |
| 1110 | { {"f27"}, "r27" }, |
| 1111 | { {"f28"}, "r28" }, |
| 1112 | { {"f29"}, "r29" }, |
| 1113 | { {"f30"}, "r30" }, |
| 1114 | { {"f31"}, "r31" }, |
| 1115 | }; |
| 1116 | |
| 1117 | void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1118 | unsigned &NumAliases) const { |
| 1119 | Aliases = GCCRegAliases; |
| 1120 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 1121 | } |
| 1122 | } // end anonymous namespace. |
| 1123 | |
| 1124 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1125 | // Namespace for x86 abstract base class |
| 1126 | const Builtin::Info BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 1127 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 1128 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 1129 | ALL_LANGUAGES }, |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 1130 | #include "clang/Basic/BuiltinsX86.def" |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1131 | }; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1132 | |
Nuno Lopes | 2550d70 | 2009-12-23 17:49:57 +0000 | [diff] [blame] | 1133 | static const char* const GCCRegNames[] = { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1134 | "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", |
| 1135 | "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] | 1136 | "argp", "flags", "fpcr", "fpsr", "dirflag", "frame", |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1137 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 1138 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", |
| 1139 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1140 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1141 | }; |
| 1142 | |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1143 | const TargetInfo::AddlRegName AddlRegNames[] = { |
| 1144 | { { "al", "ah", "eax", "rax" }, 0 }, |
| 1145 | { { "bl", "bh", "ebx", "rbx" }, 3 }, |
| 1146 | { { "cl", "ch", "ecx", "rcx" }, 2 }, |
| 1147 | { { "dl", "dh", "edx", "rdx" }, 1 }, |
| 1148 | { { "esi", "rsi" }, 4 }, |
| 1149 | { { "edi", "rdi" }, 5 }, |
| 1150 | { { "esp", "rsp" }, 7 }, |
| 1151 | { { "ebp", "rbp" }, 6 }, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | // X86 target abstract base class; x86-32 and x86-64 are very close, so |
| 1155 | // most of the implementation can be shared. |
| 1156 | class X86TargetInfo : public TargetInfo { |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1157 | enum X86SSEEnum { |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1158 | NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1159 | } SSELevel; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1160 | enum MMX3DNowEnum { |
| 1161 | NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon |
| 1162 | } MMX3DNowLevel; |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1163 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1164 | bool HasAES; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1165 | bool HasAVX; |
| 1166 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1167 | public: |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1168 | X86TargetInfo(const std::string& triple) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1169 | : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow), |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1170 | HasAES(false), HasAVX(false) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1171 | LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1172 | } |
| 1173 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1174 | unsigned &NumRecords) const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1175 | Records = BuiltinInfo; |
| 1176 | NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1177 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1178 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1179 | unsigned &NumNames) const { |
| 1180 | Names = GCCRegNames; |
| 1181 | NumNames = llvm::array_lengthof(GCCRegNames); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1182 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1183 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1184 | unsigned &NumAliases) const { |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1185 | Aliases = 0; |
| 1186 | NumAliases = 0; |
| 1187 | } |
| 1188 | virtual void getGCCAddlRegNames(const AddlRegName *&Names, |
| 1189 | unsigned &NumNames) const { |
| 1190 | Names = AddlRegNames; |
| 1191 | NumNames = llvm::array_lengthof(AddlRegNames); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 1192 | } |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1193 | virtual bool validateAsmConstraint(const char *&Name, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1194 | TargetInfo::ConstraintInfo &info) const; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 1195 | virtual std::string convertConstraint(const char *&Constraint) const; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 1196 | virtual const char *getClobbers() const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1197 | return "~{dirflag},~{fpsr},~{flags}"; |
| 1198 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1199 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1200 | MacroBuilder &Builder) const; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1201 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 1202 | const std::string &Name, |
| 1203 | bool Enabled) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 | virtual void getDefaultFeatures(const std::string &CPU, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1205 | llvm::StringMap<bool> &Features) const; |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 1206 | virtual void HandleTargetFeatures(std::vector<std::string> &Features); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1207 | virtual const char* getABI() const { |
| 1208 | return MMX3DNowLevel == NoMMX3DNow ? "no-mmx" : ""; |
| 1209 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1210 | }; |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 1211 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | void X86TargetInfo::getDefaultFeatures(const std::string &CPU, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1213 | llvm::StringMap<bool> &Features) const { |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1214 | // FIXME: This should not be here. |
| 1215 | Features["3dnow"] = false; |
| 1216 | Features["3dnowa"] = false; |
| 1217 | Features["mmx"] = false; |
| 1218 | Features["sse"] = false; |
| 1219 | Features["sse2"] = false; |
| 1220 | Features["sse3"] = false; |
| 1221 | Features["ssse3"] = false; |
| 1222 | Features["sse41"] = false; |
| 1223 | Features["sse42"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1224 | Features["aes"] = false; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1225 | Features["avx"] = false; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1226 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1227 | // LLVM does not currently recognize this. |
| 1228 | // Features["sse4a"] = false; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1229 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1230 | // FIXME: This *really* should not be here. |
| 1231 | |
| 1232 | // X86_64 always has SSE2. |
| 1233 | if (PointerWidth == 64) |
| 1234 | Features["sse2"] = Features["sse"] = Features["mmx"] = true; |
| 1235 | |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1236 | if (CPU == "generic" || CPU == "i386" || CPU == "i486" || CPU == "i586" || |
| 1237 | CPU == "pentium" || CPU == "i686" || CPU == "pentiumpro") |
| 1238 | ; |
| 1239 | else if (CPU == "pentium-mmx" || CPU == "pentium2") |
| 1240 | setFeatureEnabled(Features, "mmx", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1241 | else if (CPU == "pentium3") { |
| 1242 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1243 | setFeatureEnabled(Features, "sse", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1244 | } else if (CPU == "pentium-m" || CPU == "pentium4" || CPU == "x86-64") { |
| 1245 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1246 | setFeatureEnabled(Features, "sse2", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1247 | } else if (CPU == "yonah" || CPU == "prescott" || CPU == "nocona") { |
| 1248 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1249 | setFeatureEnabled(Features, "sse3", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1250 | } else if (CPU == "core2") { |
| 1251 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1252 | setFeatureEnabled(Features, "ssse3", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1253 | } else if (CPU == "penryn") { |
| 1254 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1255 | setFeatureEnabled(Features, "sse4", true); |
| 1256 | Features["sse42"] = false; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1257 | } else if (CPU == "atom") { |
| 1258 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1259 | setFeatureEnabled(Features, "sse3", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1260 | } else if (CPU == "corei7") { |
| 1261 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1262 | setFeatureEnabled(Features, "sse4", true); |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1263 | setFeatureEnabled(Features, "aes", true); |
Benjamin Kramer | b65b672 | 2011-05-20 15:11:23 +0000 | [diff] [blame] | 1264 | } else if (CPU == "corei7-avx") { |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1265 | setFeatureEnabled(Features, "mmx", true); |
Roman Divacky | bcaa3b8 | 2011-04-05 20:32:44 +0000 | [diff] [blame] | 1266 | setFeatureEnabled(Features, "sse4", true); |
| 1267 | setFeatureEnabled(Features, "aes", true); |
Bruno Cardoso Lopes | e02d391 | 2011-07-11 23:33:46 +0000 | [diff] [blame] | 1268 | //setFeatureEnabled(Features, "avx", true); |
Roman Divacky | bcaa3b8 | 2011-04-05 20:32:44 +0000 | [diff] [blame] | 1269 | } else if (CPU == "k6" || CPU == "winchip-c6") |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1270 | setFeatureEnabled(Features, "mmx", true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1271 | else if (CPU == "k6-2" || CPU == "k6-3" || CPU == "athlon" || |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1272 | CPU == "athlon-tbird" || CPU == "winchip2" || CPU == "c3") { |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1273 | setFeatureEnabled(Features, "3dnow", true); |
| 1274 | } else if (CPU == "athlon-4" || CPU == "athlon-xp" || CPU == "athlon-mp") { |
| 1275 | setFeatureEnabled(Features, "sse", true); |
| 1276 | setFeatureEnabled(Features, "3dnowa", true); |
| 1277 | } else if (CPU == "k8" || CPU == "opteron" || CPU == "athlon64" || |
| 1278 | CPU == "athlon-fx") { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | setFeatureEnabled(Features, "sse2", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1280 | setFeatureEnabled(Features, "3dnowa", true); |
Roman Divacky | c8b09a1 | 2010-12-29 13:28:29 +0000 | [diff] [blame] | 1281 | } else if (CPU == "k8-sse3") { |
| 1282 | setFeatureEnabled(Features, "sse3", true); |
| 1283 | setFeatureEnabled(Features, "3dnowa", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1284 | } else if (CPU == "c3-2") { |
| 1285 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1286 | setFeatureEnabled(Features, "sse", true); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1287 | } |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1290 | bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | const std::string &Name, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1292 | bool Enabled) const { |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1293 | // FIXME: This *really* should not be here. We need some way of translating |
| 1294 | // options into llvm subtarget features. |
| 1295 | if (!Features.count(Name) && |
| 1296 | (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1")) |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1297 | return false; |
| 1298 | |
| 1299 | if (Enabled) { |
| 1300 | if (Name == "mmx") |
| 1301 | Features["mmx"] = true; |
| 1302 | else if (Name == "sse") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1303 | Features["sse"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1304 | else if (Name == "sse2") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1305 | Features["sse"] = Features["sse2"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1306 | else if (Name == "sse3") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1307 | Features["sse"] = Features["sse2"] = Features["sse3"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1308 | else if (Name == "ssse3") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1309 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1310 | Features["ssse3"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1311 | else if (Name == "sse4" || Name == "sse4.2") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1312 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1313 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1314 | else if (Name == "sse4.1") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1315 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1316 | Features["ssse3"] = Features["sse41"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1317 | else if (Name == "3dnow") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1318 | Features["mmx"] = Features["3dnow"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1319 | else if (Name == "3dnowa") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1320 | Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1321 | else if (Name == "aes") |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1322 | Features["aes"] = true; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1323 | else if (Name == "avx") |
Bruno Cardoso Lopes | 292772c | 2011-08-18 00:07:03 +0000 | [diff] [blame] | 1324 | Features["avx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1325 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1326 | } else { |
| 1327 | if (Name == "mmx") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1328 | Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1329 | else if (Name == "sse") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1331 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1332 | else if (Name == "sse2") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | Features["sse2"] = Features["sse3"] = Features["ssse3"] = |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1334 | Features["sse41"] = Features["sse42"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1335 | else if (Name == "sse3") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | Features["sse3"] = Features["ssse3"] = Features["sse41"] = |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1337 | Features["sse42"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1338 | else if (Name == "ssse3") |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1339 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = false; |
Michael J. Spencer | b24bac9 | 2011-04-17 19:22:03 +0000 | [diff] [blame] | 1340 | else if (Name == "sse4" || Name == "sse4.1") |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1341 | Features["sse41"] = Features["sse42"] = false; |
Eric Christopher | d41b4ec | 2010-03-04 02:31:44 +0000 | [diff] [blame] | 1342 | else if (Name == "sse4.2") |
Daniel Dunbar | cb65de1 | 2011-05-03 15:34:01 +0000 | [diff] [blame] | 1343 | Features["sse42"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1344 | else if (Name == "3dnow") |
| 1345 | Features["3dnow"] = Features["3dnowa"] = false; |
| 1346 | else if (Name == "3dnowa") |
| 1347 | Features["3dnowa"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1348 | else if (Name == "aes") |
| 1349 | Features["aes"] = false; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1350 | else if (Name == "avx") |
| 1351 | Features["avx"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | return true; |
| 1355 | } |
| 1356 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1357 | /// HandleTargetOptions - Perform initialization based on the user |
| 1358 | /// configured set of features. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 1359 | void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1360 | // Remember the maximum enabled sselevel. |
| 1361 | for (unsigned i = 0, e = Features.size(); i !=e; ++i) { |
| 1362 | // Ignore disabled features. |
| 1363 | if (Features[i][0] == '-') |
| 1364 | continue; |
| 1365 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1366 | if (Features[i].substr(1) == "aes") { |
| 1367 | HasAES = true; |
| 1368 | continue; |
| 1369 | } |
| 1370 | |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1371 | // FIXME: Not sure yet how to treat AVX in regard to SSE levels. |
| 1372 | // For now let it be enabled together with other SSE levels. |
| 1373 | if (Features[i].substr(1) == "avx") { |
| 1374 | HasAVX = true; |
| 1375 | continue; |
| 1376 | } |
| 1377 | |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1378 | assert(Features[i][0] == '+' && "Invalid target feature!"); |
| 1379 | X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1)) |
| 1380 | .Case("sse42", SSE42) |
| 1381 | .Case("sse41", SSE41) |
| 1382 | .Case("ssse3", SSSE3) |
Nuno Lopes | 33d3bca | 2010-03-12 10:20:09 +0000 | [diff] [blame] | 1383 | .Case("sse3", SSE3) |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1384 | .Case("sse2", SSE2) |
| 1385 | .Case("sse", SSE1) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1386 | .Default(NoSSE); |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1387 | SSELevel = std::max(SSELevel, Level); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1388 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1389 | MMX3DNowEnum ThreeDNowLevel = |
| 1390 | llvm::StringSwitch<MMX3DNowEnum>(Features[i].substr(1)) |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1391 | .Case("3dnowa", AMD3DNowAthlon) |
| 1392 | .Case("3dnow", AMD3DNow) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1393 | .Case("mmx", MMX) |
| 1394 | .Default(NoMMX3DNow); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1395 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1396 | MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel); |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1397 | } |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1398 | |
| 1399 | // Don't tell the backend if we're turning off mmx; it will end up disabling |
| 1400 | // SSE, which we don't want. |
| 1401 | std::vector<std::string>::iterator it; |
| 1402 | it = std::find(Features.begin(), Features.end(), "-mmx"); |
| 1403 | if (it != Features.end()) |
| 1404 | Features.erase(it); |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 1405 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1406 | |
| 1407 | /// X86TargetInfo::getTargetDefines - Return a set of the X86-specific #defines |
| 1408 | /// that are not tied to a specific subtarget. |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1409 | void X86TargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1410 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1411 | // Target identification. |
| 1412 | if (PointerWidth == 64) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1413 | Builder.defineMacro("_LP64"); |
| 1414 | Builder.defineMacro("__LP64__"); |
| 1415 | Builder.defineMacro("__amd64__"); |
| 1416 | Builder.defineMacro("__amd64"); |
| 1417 | Builder.defineMacro("__x86_64"); |
| 1418 | Builder.defineMacro("__x86_64__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1419 | } else { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1420 | DefineStd(Builder, "i386", Opts); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1421 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1422 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1423 | if (HasAES) |
| 1424 | Builder.defineMacro("__AES__"); |
| 1425 | |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1426 | if (HasAVX) |
| 1427 | Builder.defineMacro("__AVX__"); |
| 1428 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1429 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1430 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1431 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1432 | // Subtarget options. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1433 | Builder.defineMacro("__nocona"); |
| 1434 | Builder.defineMacro("__nocona__"); |
| 1435 | Builder.defineMacro("__tune_nocona__"); |
| 1436 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1437 | |
Chris Lattner | 5417544 | 2009-04-19 17:32:33 +0000 | [diff] [blame] | 1438 | // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline |
| 1439 | // functions in glibc header files that use FP Stack inline asm which the |
| 1440 | // backend can't deal with (PR879). |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1441 | Builder.defineMacro("__NO_MATH_INLINES"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1442 | |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1443 | // Each case falls through to the previous one here. |
| 1444 | switch (SSELevel) { |
| 1445 | case SSE42: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1446 | Builder.defineMacro("__SSE4_2__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1447 | case SSE41: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1448 | Builder.defineMacro("__SSE4_1__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1449 | case SSSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1450 | Builder.defineMacro("__SSSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1451 | case SSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1452 | Builder.defineMacro("__SSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1453 | case SSE2: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1454 | Builder.defineMacro("__SSE2__"); |
| 1455 | Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied. |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1456 | case SSE1: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1457 | Builder.defineMacro("__SSE__"); |
| 1458 | Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied. |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1459 | case NoSSE: |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1460 | break; |
| 1461 | } |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 1462 | |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 1463 | if (Opts.MicrosoftExt && PointerWidth == 32) { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1464 | switch (SSELevel) { |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1465 | case SSE42: |
| 1466 | case SSE41: |
| 1467 | case SSSE3: |
| 1468 | case SSE3: |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1469 | case SSE2: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1470 | Builder.defineMacro("_M_IX86_FP", Twine(2)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1471 | break; |
| 1472 | case SSE1: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1473 | Builder.defineMacro("_M_IX86_FP", Twine(1)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1474 | break; |
| 1475 | default: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1476 | Builder.defineMacro("_M_IX86_FP", Twine(0)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1480 | // Each case falls through to the previous one here. |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1481 | switch (MMX3DNowLevel) { |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1482 | case AMD3DNowAthlon: |
| 1483 | Builder.defineMacro("__3dNOW_A__"); |
| 1484 | case AMD3DNow: |
| 1485 | Builder.defineMacro("__3dNOW__"); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1486 | case MMX: |
| 1487 | Builder.defineMacro("__MMX__"); |
| 1488 | case NoMMX3DNow: |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1489 | break; |
| 1490 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1491 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1492 | |
| 1493 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1494 | bool |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1495 | X86TargetInfo::validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 1496 | TargetInfo::ConstraintInfo &Info) const { |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1497 | switch (*Name) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1498 | default: return false; |
Dale Johannesen | 545be51 | 2010-08-24 22:33:12 +0000 | [diff] [blame] | 1499 | case 'Y': // first letter of a pair: |
| 1500 | switch (*(Name+1)) { |
| 1501 | default: return false; |
| 1502 | case '0': // First SSE register. |
| 1503 | case 't': // Any SSE register, when SSE2 is enabled. |
| 1504 | case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled. |
| 1505 | case 'm': // any MMX register, when inter-unit moves enabled. |
| 1506 | break; // falls through to setAllowsRegister. |
| 1507 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1508 | case 'a': // eax. |
| 1509 | case 'b': // ebx. |
| 1510 | case 'c': // ecx. |
| 1511 | case 'd': // edx. |
| 1512 | case 'S': // esi. |
| 1513 | case 'D': // edi. |
| 1514 | case 'A': // edx:eax. |
Dale Johannesen | 545be51 | 2010-08-24 22:33:12 +0000 | [diff] [blame] | 1515 | case 'f': // any x87 floating point stack register. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1516 | case 't': // top of floating point stack. |
| 1517 | case 'u': // second from top of floating point stack. |
| 1518 | 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] | 1519 | case 'y': // Any MMX register. |
Anders Carlsson | a7406d4 | 2008-10-06 19:17:39 +0000 | [diff] [blame] | 1520 | case 'x': // Any SSE register. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1521 | 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] | 1522 | case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp. |
| 1523 | case 'l': // "Index" registers: any general register that can be used as an |
| 1524 | // index in a base+index memory access. |
| 1525 | Info.setAllowsRegister(); |
| 1526 | return true; |
| 1527 | case 'C': // SSE floating point constant. |
| 1528 | case 'G': // x87 floating point constant. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1529 | case 'e': // 32-bit signed integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 1530 | // x86_64 instructions. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1531 | case 'Z': // 32-bit unsigned integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 1532 | // x86_64 instructions. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1533 | return true; |
| 1534 | } |
Dale Johannesen | 545be51 | 2010-08-24 22:33:12 +0000 | [diff] [blame] | 1535 | return false; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Dale Johannesen | f6e2c20 | 2010-10-29 23:12:32 +0000 | [diff] [blame] | 1538 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1539 | std::string |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 1540 | X86TargetInfo::convertConstraint(const char *&Constraint) const { |
| 1541 | switch (*Constraint) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1542 | case 'a': return std::string("{ax}"); |
| 1543 | case 'b': return std::string("{bx}"); |
| 1544 | case 'c': return std::string("{cx}"); |
| 1545 | case 'd': return std::string("{dx}"); |
| 1546 | case 'S': return std::string("{si}"); |
| 1547 | case 'D': return std::string("{di}"); |
Dale Johannesen | cee5501 | 2010-10-22 21:07:10 +0000 | [diff] [blame] | 1548 | case 'p': // address |
| 1549 | return std::string("im"); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1550 | case 't': // top of floating point stack. |
| 1551 | return std::string("{st}"); |
| 1552 | case 'u': // second from top of floating point stack. |
| 1553 | return std::string("{st(1)}"); // second from top of floating point stack. |
| 1554 | default: |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 1555 | return std::string(1, *Constraint); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1558 | } // end anonymous namespace |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1559 | |
| 1560 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1561 | // X86-32 generic target |
| 1562 | class X86_32TargetInfo : public X86TargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1563 | public: |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1564 | X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { |
| 1565 | DoubleAlign = LongLongAlign = 32; |
| 1566 | LongDoubleWidth = 96; |
| 1567 | LongDoubleAlign = 32; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1568 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1569 | "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] | 1570 | "a0:0:64-f80:32:32-n8:16:32"; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 1571 | SizeType = UnsignedInt; |
| 1572 | PtrDiffType = SignedInt; |
| 1573 | IntPtrType = SignedInt; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 1574 | RegParmMax = 3; |
Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 1575 | |
| 1576 | // Use fpret for all types. |
| 1577 | RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) | |
| 1578 | (1 << TargetInfo::Double) | |
| 1579 | (1 << TargetInfo::LongDouble)); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1580 | } |
| 1581 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1582 | return "typedef char* __builtin_va_list;"; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1583 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1584 | |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 1585 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 1586 | if (RegNo == 0) return 0; |
| 1587 | if (RegNo == 1) return 2; |
| 1588 | return -1; |
| 1589 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1590 | }; |
| 1591 | } // end anonymous namespace |
| 1592 | |
| 1593 | namespace { |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 1594 | class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> { |
| 1595 | public: |
| 1596 | OpenBSDI386TargetInfo(const std::string& triple) : |
| 1597 | OpenBSDTargetInfo<X86_32TargetInfo>(triple) { |
| 1598 | SizeType = UnsignedLong; |
| 1599 | IntPtrType = SignedLong; |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1600 | PtrDiffType = SignedLong; |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 1601 | } |
| 1602 | }; |
| 1603 | } // end anonymous namespace |
| 1604 | |
| 1605 | namespace { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1606 | class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1607 | public: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 1608 | DarwinI386TargetInfo(const std::string& triple) : |
| 1609 | DarwinTargetInfo<X86_32TargetInfo>(triple) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1610 | LongDoubleWidth = 128; |
| 1611 | LongDoubleAlign = 128; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 1612 | SizeType = UnsignedLong; |
| 1613 | IntPtrType = SignedLong; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1614 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1615 | "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] | 1616 | "a0:0:64-f80:128:128-n8:16:32"; |
Daniel Dunbar | 613fd67 | 2010-05-27 00:35:16 +0000 | [diff] [blame] | 1617 | HasAlignMac68kSupport = true; |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1620 | }; |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1621 | } // end anonymous namespace |
| 1622 | |
| 1623 | namespace { |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1624 | // x86-32 Windows target |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1625 | class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> { |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1626 | public: |
| 1627 | WindowsX86_32TargetInfo(const std::string& triple) |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1628 | : WindowsTargetInfo<X86_32TargetInfo>(triple) { |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 1629 | TLSSupported = false; |
Chris Lattner | 85de9e7 | 2009-06-24 17:12:15 +0000 | [diff] [blame] | 1630 | WCharType = UnsignedShort; |
Eli Friedman | 9c2f84e | 2009-06-08 21:16:17 +0000 | [diff] [blame] | 1631 | DoubleAlign = LongLongAlign = 64; |
| 1632 | 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] | 1633 | "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-" |
| 1634 | "v128:128:128-a0:0:64-f80:32:32-n8:16:32"; |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1635 | } |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1636 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1637 | MacroBuilder &Builder) const { |
| 1638 | WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder); |
| 1639 | } |
| 1640 | }; |
| 1641 | } // end anonymous namespace |
| 1642 | |
| 1643 | namespace { |
| 1644 | |
| 1645 | // x86-32 Windows Visual Studio target |
| 1646 | class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 1647 | public: |
| 1648 | VisualStudioWindowsX86_32TargetInfo(const std::string& triple) |
| 1649 | : WindowsX86_32TargetInfo(triple) { |
Eli Friedman | d9c3fa3 | 2011-03-22 21:25:11 +0000 | [diff] [blame] | 1650 | LongDoubleWidth = LongDoubleAlign = 64; |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1651 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
| 1652 | } |
| 1653 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1654 | MacroBuilder &Builder) const { |
| 1655 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1656 | WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder); |
| 1657 | // The value of the following reflects processor type. |
| 1658 | // 300=386, 400=486, 500=Pentium, 600=Blend (default) |
| 1659 | // We lost the original triple, so we use the default. |
| 1660 | Builder.defineMacro("_M_IX86", "600"); |
| 1661 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1662 | }; |
| 1663 | } // end anonymous namespace |
| 1664 | |
| 1665 | namespace { |
| 1666 | // x86-32 MinGW target |
| 1667 | class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 1668 | public: |
| 1669 | MinGWX86_32TargetInfo(const std::string& triple) |
| 1670 | : WindowsX86_32TargetInfo(triple) { |
| 1671 | } |
| 1672 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1673 | MacroBuilder &Builder) const { |
| 1674 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1675 | DefineStd(Builder, "WIN32", Opts); |
| 1676 | DefineStd(Builder, "WINNT", Opts); |
| 1677 | Builder.defineMacro("_X86_"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1678 | Builder.defineMacro("__MSVCRT__"); |
| 1679 | Builder.defineMacro("__MINGW32__"); |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 1680 | |
| 1681 | // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). |
| 1682 | // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 1683 | if (Opts.MicrosoftExt) |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 1684 | // Provide "as-is" __declspec. |
| 1685 | Builder.defineMacro("__declspec", "__declspec"); |
| 1686 | else |
| 1687 | // Provide alias of __attribute__ like mingw32-gcc. |
| 1688 | Builder.defineMacro("__declspec(a)", "__attribute__((a))"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1689 | } |
| 1690 | }; |
| 1691 | } // end anonymous namespace |
| 1692 | |
| 1693 | namespace { |
| 1694 | // x86-32 Cygwin target |
| 1695 | class CygwinX86_32TargetInfo : public X86_32TargetInfo { |
| 1696 | public: |
| 1697 | CygwinX86_32TargetInfo(const std::string& triple) |
| 1698 | : X86_32TargetInfo(triple) { |
| 1699 | TLSSupported = false; |
| 1700 | WCharType = UnsignedShort; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1701 | DoubleAlign = LongLongAlign = 64; |
| 1702 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1703 | "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] | 1704 | "a0:0:64-f80:32:32-n8:16:32"; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1705 | } |
| 1706 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1707 | MacroBuilder &Builder) const { |
| 1708 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1709 | Builder.defineMacro("__CYGWIN__"); |
| 1710 | Builder.defineMacro("__CYGWIN32__"); |
| 1711 | DefineStd(Builder, "unix", Opts); |
Douglas Gregor | 2b003fd | 2010-04-21 05:52:38 +0000 | [diff] [blame] | 1712 | if (Opts.CPlusPlus) |
| 1713 | Builder.defineMacro("_GNU_SOURCE"); |
Eli Friedman | abc4e32 | 2009-06-08 06:11:14 +0000 | [diff] [blame] | 1714 | } |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1715 | }; |
| 1716 | } // end anonymous namespace |
| 1717 | |
| 1718 | namespace { |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1719 | // x86-32 Haiku target |
| 1720 | class HaikuX86_32TargetInfo : public X86_32TargetInfo { |
| 1721 | public: |
| 1722 | HaikuX86_32TargetInfo(const std::string& triple) |
| 1723 | : X86_32TargetInfo(triple) { |
| 1724 | SizeType = UnsignedLong; |
Chris Lattner | fe1ea7b | 2010-04-22 17:48:00 +0000 | [diff] [blame] | 1725 | IntPtrType = SignedLong; |
| 1726 | PtrDiffType = SignedLong; |
Rafael Espindola | 19ddda8 | 2010-11-09 16:41:02 +0000 | [diff] [blame] | 1727 | this->UserLabelPrefix = ""; |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 1728 | } |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1729 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1730 | MacroBuilder &Builder) const { |
| 1731 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1732 | Builder.defineMacro("__INTEL__"); |
| 1733 | Builder.defineMacro("__HAIKU__"); |
| 1734 | } |
| 1735 | }; |
| 1736 | } // end anonymous namespace |
| 1737 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 1738 | // RTEMS Target |
| 1739 | template<typename Target> |
| 1740 | class RTEMSTargetInfo : public OSTargetInfo<Target> { |
| 1741 | protected: |
| 1742 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 1743 | MacroBuilder &Builder) const { |
| 1744 | // RTEMS defines; list based off of gcc output |
| 1745 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 1746 | Builder.defineMacro("__rtems__"); |
| 1747 | Builder.defineMacro("__ELF__"); |
| 1748 | } |
| 1749 | public: |
| 1750 | RTEMSTargetInfo(const std::string &triple) |
| 1751 | : OSTargetInfo<Target>(triple) { |
| 1752 | this->UserLabelPrefix = ""; |
| 1753 | |
| 1754 | llvm::Triple Triple(triple); |
| 1755 | switch (Triple.getArch()) { |
| 1756 | default: |
| 1757 | case llvm::Triple::x86: |
| 1758 | // this->MCountName = ".mcount"; |
| 1759 | break; |
| 1760 | case llvm::Triple::mips: |
| 1761 | case llvm::Triple::mipsel: |
| 1762 | case llvm::Triple::ppc: |
| 1763 | case llvm::Triple::ppc64: |
| 1764 | // this->MCountName = "_mcount"; |
| 1765 | break; |
| 1766 | case llvm::Triple::arm: |
| 1767 | // this->MCountName = "__mcount"; |
| 1768 | break; |
| 1769 | } |
| 1770 | |
| 1771 | } |
| 1772 | }; |
| 1773 | |
| 1774 | namespace { |
| 1775 | // x86-32 RTEMS target |
| 1776 | class RTEMSX86_32TargetInfo : public X86_32TargetInfo { |
| 1777 | public: |
| 1778 | RTEMSX86_32TargetInfo(const std::string& triple) |
| 1779 | : X86_32TargetInfo(triple) { |
| 1780 | SizeType = UnsignedLong; |
| 1781 | IntPtrType = SignedLong; |
| 1782 | PtrDiffType = SignedLong; |
| 1783 | this->UserLabelPrefix = ""; |
| 1784 | } |
| 1785 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1786 | MacroBuilder &Builder) const { |
| 1787 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 1788 | Builder.defineMacro("__INTEL__"); |
| 1789 | Builder.defineMacro("__rtems__"); |
| 1790 | } |
| 1791 | }; |
| 1792 | } // end anonymous namespace |
| 1793 | |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 1794 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1795 | // x86-64 generic target |
| 1796 | class X86_64TargetInfo : public X86TargetInfo { |
| 1797 | public: |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1798 | X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 1799 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1800 | LongDoubleWidth = 128; |
| 1801 | LongDoubleAlign = 128; |
Rafael Espindola | 6deecb0 | 2010-06-04 23:15:27 +0000 | [diff] [blame] | 1802 | LargeArrayMinWidth = 128; |
| 1803 | LargeArrayAlign = 128; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 1804 | IntMaxType = SignedLong; |
| 1805 | UIntMaxType = UnsignedLong; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1806 | Int64Type = SignedLong; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 1807 | RegParmMax = 6; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 1808 | |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1809 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1810 | "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] | 1811 | "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] | 1812 | |
| 1813 | // Use fpret only for long double. |
| 1814 | RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1815 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 1816 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 1817 | return "typedef struct __va_list_tag {" |
| 1818 | " unsigned gp_offset;" |
| 1819 | " unsigned fp_offset;" |
| 1820 | " void* overflow_arg_area;" |
| 1821 | " void* reg_save_area;" |
John McCall | 2b7baf0 | 2010-05-28 18:25:28 +0000 | [diff] [blame] | 1822 | "} __va_list_tag;" |
Eli Friedman | dc04316 | 2009-07-03 00:45:06 +0000 | [diff] [blame] | 1823 | "typedef __va_list_tag __builtin_va_list[1];"; |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1824 | } |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 1825 | |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 1826 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 1827 | if (RegNo == 0) return 0; |
| 1828 | if (RegNo == 1) return 1; |
| 1829 | return -1; |
| 1830 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1831 | }; |
| 1832 | } // end anonymous namespace |
| 1833 | |
| 1834 | namespace { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1835 | // x86-64 Windows target |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1836 | class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1837 | public: |
| 1838 | WindowsX86_64TargetInfo(const std::string& triple) |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1839 | : WindowsTargetInfo<X86_64TargetInfo>(triple) { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1840 | TLSSupported = false; |
| 1841 | WCharType = UnsignedShort; |
Mike Stump | a55cce8 | 2009-10-08 23:00:00 +0000 | [diff] [blame] | 1842 | LongWidth = LongAlign = 32; |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 1843 | DoubleAlign = LongLongAlign = 64; |
Nate Begeman | dbf8ea4 | 2010-07-21 02:02:56 +0000 | [diff] [blame] | 1844 | IntMaxType = SignedLongLong; |
| 1845 | UIntMaxType = UnsignedLongLong; |
| 1846 | Int64Type = SignedLongLong; |
Cameron Esfahani | 1484e0d | 2010-09-15 00:28:12 +0000 | [diff] [blame] | 1847 | SizeType = UnsignedLongLong; |
| 1848 | PtrDiffType = SignedLongLong; |
| 1849 | IntPtrType = SignedLongLong; |
NAKAMURA Takumi | 8c959d9 | 2011-01-17 22:56:08 +0000 | [diff] [blame] | 1850 | this->UserLabelPrefix = ""; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1851 | } |
| 1852 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1853 | MacroBuilder &Builder) const { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1854 | WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1855 | Builder.defineMacro("_WIN64"); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1856 | } |
NAKAMURA Takumi | 7952199 | 2011-01-17 22:56:23 +0000 | [diff] [blame] | 1857 | virtual const char *getVAListDeclaration() const { |
| 1858 | return "typedef char* __builtin_va_list;"; |
| 1859 | } |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1860 | }; |
| 1861 | } // end anonymous namespace |
| 1862 | |
| 1863 | namespace { |
| 1864 | // x86-64 Windows Visual Studio target |
| 1865 | class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 1866 | public: |
| 1867 | VisualStudioWindowsX86_64TargetInfo(const std::string& triple) |
| 1868 | : WindowsX86_64TargetInfo(triple) { |
Eli Friedman | d9c3fa3 | 2011-03-22 21:25:11 +0000 | [diff] [blame] | 1869 | LongDoubleWidth = LongDoubleAlign = 64; |
| 1870 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1871 | } |
| 1872 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1873 | MacroBuilder &Builder) const { |
| 1874 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
| 1875 | WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1876 | Builder.defineMacro("_M_X64"); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1877 | Builder.defineMacro("_M_AMD64"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1878 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1879 | }; |
| 1880 | } // end anonymous namespace |
| 1881 | |
| 1882 | namespace { |
| 1883 | // x86-64 MinGW target |
| 1884 | class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 1885 | public: |
| 1886 | MinGWX86_64TargetInfo(const std::string& triple) |
| 1887 | : WindowsX86_64TargetInfo(triple) { |
| 1888 | } |
| 1889 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1890 | MacroBuilder &Builder) const { |
| 1891 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 1892 | DefineStd(Builder, "WIN64", Opts); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1893 | Builder.defineMacro("__MSVCRT__"); |
NAKAMURA Takumi | 17c964a | 2011-03-08 12:06:46 +0000 | [diff] [blame] | 1894 | Builder.defineMacro("__MINGW32__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1895 | Builder.defineMacro("__MINGW64__"); |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 1896 | |
| 1897 | // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). |
| 1898 | // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 1899 | if (Opts.MicrosoftExt) |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 1900 | // Provide "as-is" __declspec. |
| 1901 | Builder.defineMacro("__declspec", "__declspec"); |
| 1902 | else |
| 1903 | // Provide alias of __attribute__ like mingw32-gcc. |
| 1904 | Builder.defineMacro("__declspec(a)", "__attribute__((a))"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 1905 | } |
| 1906 | }; |
| 1907 | } // end anonymous namespace |
| 1908 | |
| 1909 | namespace { |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1910 | class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { |
| 1911 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1912 | DarwinX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 1913 | : DarwinTargetInfo<X86_64TargetInfo>(triple) { |
| 1914 | Int64Type = SignedLongLong; |
| 1915 | } |
| 1916 | }; |
| 1917 | } // end anonymous namespace |
| 1918 | |
| 1919 | namespace { |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1920 | class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { |
| 1921 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1922 | OpenBSDX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 1923 | : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { |
| 1924 | IntMaxType = SignedLongLong; |
| 1925 | UIntMaxType = UnsignedLongLong; |
| 1926 | Int64Type = SignedLongLong; |
| 1927 | } |
| 1928 | }; |
| 1929 | } // end anonymous namespace |
| 1930 | |
| 1931 | namespace { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 1932 | class ARMTargetInfo : public TargetInfo { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1933 | // Possible FPU choices. |
| 1934 | enum FPUMode { |
| 1935 | NoFPU, |
| 1936 | VFP2FPU, |
| 1937 | VFP3FPU, |
| 1938 | NeonFPU |
| 1939 | }; |
| 1940 | |
| 1941 | static bool FPUModeIsVFP(FPUMode Mode) { |
| 1942 | return Mode >= VFP2FPU && Mode <= NeonFPU; |
| 1943 | } |
| 1944 | |
| 1945 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 1946 | static const char * const GCCRegNames[]; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 1947 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1948 | std::string ABI, CPU; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 1949 | |
| 1950 | unsigned FPU : 3; |
| 1951 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 1952 | unsigned IsThumb : 1; |
| 1953 | |
| 1954 | // Initialized via features. |
| 1955 | unsigned SoftFloat : 1; |
| 1956 | unsigned SoftFloatABI : 1; |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1957 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1958 | static const Builtin::Info BuiltinInfo[]; |
| 1959 | |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1960 | public: |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1961 | ARMTargetInfo(const std::string &TripleStr) |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1962 | : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s") |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1963 | { |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1964 | SizeType = UnsignedInt; |
| 1965 | PtrDiffType = SignedInt; |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 1966 | |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 1967 | // {} in inline assembly are neon specifiers, not assembly variant |
| 1968 | // specifiers. |
| 1969 | NoAsmVariants = true; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1970 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 1971 | // FIXME: Should we just treat this as a feature? |
Daniel Dunbar | 0791aa5 | 2009-12-18 19:57:13 +0000 | [diff] [blame] | 1972 | IsThumb = getTriple().getArchName().startswith("thumb"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1973 | if (IsThumb) { |
Sandeep Patel | 3a41d14 | 2011-04-04 22:58:12 +0000 | [diff] [blame] | 1974 | // Thumb1 add sp, #imm requires the immediate value be multiple of 4, |
| 1975 | // so set preferred for small types to 32. |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1976 | DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" |
| 1977 | "i64:64:64-f32:32:32-f64:64:64-" |
Bob Wilson | cd5ce09 | 2011-04-04 16:53:11 +0000 | [diff] [blame] | 1978 | "v64:64:64-v128:64:128-a0:0:32-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1979 | } else { |
| 1980 | DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 1981 | "i64:64:64-f32:32:32-f64:64:64-" |
Bob Wilson | cd5ce09 | 2011-04-04 16:53:11 +0000 | [diff] [blame] | 1982 | "v64:64:64-v128:64:128-a0:0:64-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 1983 | } |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 1984 | |
| 1985 | // ARM targets default to using the ARM C++ ABI. |
| 1986 | CXXABI = CXXABI_ARM; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1987 | } |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1988 | virtual const char *getABI() const { return ABI.c_str(); } |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1989 | virtual bool setABI(const std::string &Name) { |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 1990 | ABI = Name; |
| 1991 | |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1992 | // The defaults (above) are for AAPCS, check if we need to change them. |
| 1993 | // |
| 1994 | // FIXME: We need support for -meabi... we could just mangle it into the |
| 1995 | // name. |
| 1996 | if (Name == "apcs-gnu") { |
Daniel Dunbar | d410fa2 | 2010-01-27 20:23:08 +0000 | [diff] [blame] | 1997 | DoubleAlign = LongLongAlign = LongDoubleAlign = 32; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 1998 | SizeType = UnsignedLong; |
| 1999 | |
Daniel Dunbar | 684de63 | 2010-04-22 16:14:54 +0000 | [diff] [blame] | 2000 | // Do not respect the alignment of bit-field types when laying out |
| 2001 | // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc. |
| 2002 | UseBitFieldTypeAlignment = false; |
| 2003 | |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 2004 | /// Do force alignment of members that follow zero length bitfields. If |
| 2005 | /// the alignment of the zero-length bitfield is greater than the member |
| 2006 | /// that follows it, `bar', `bar' will be aligned as the type of the |
| 2007 | /// zero length bitfield. |
| 2008 | UseZeroLengthBitfieldAlignment = true; |
| 2009 | |
| 2010 | /// gcc forces the alignment to 4 bytes, regardless of the type of the |
Chad Rosier | 6e43f3f | 2011-08-04 17:52:43 +0000 | [diff] [blame] | 2011 | /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in |
| 2012 | /// gcc. |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 2013 | ZeroLengthBitfieldBoundary = 32; |
| 2014 | |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2015 | if (IsThumb) { |
Sandeep Patel | 3a41d14 | 2011-04-04 22:58:12 +0000 | [diff] [blame] | 2016 | // Thumb1 add sp, #imm requires the immediate value be multiple of 4, |
| 2017 | // so set preferred for small types to 32. |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2018 | 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] | 2019 | "i64:32:64-f32:32:32-f64:32:64-" |
Bob Wilson | cd5ce09 | 2011-04-04 16:53:11 +0000 | [diff] [blame] | 2020 | "v64:32:64-v128:32:128-a0:0:32-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2021 | } else { |
| 2022 | 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] | 2023 | "i64:32:64-f32:32:32-f64:32:64-" |
| 2024 | "v64:32:64-v128:32:128-a0:0:32-n32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Chad Rosier | 9f1210c | 2011-07-26 07:03:04 +0000 | [diff] [blame] | 2027 | // FIXME: Override "preferred align" for double and long long. |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2028 | } else if (Name == "aapcs") { |
| 2029 | // FIXME: Enumerated types are variable width in straight AAPCS. |
| 2030 | } else if (Name == "aapcs-linux") { |
Chad Rosier | 9f1210c | 2011-07-26 07:03:04 +0000 | [diff] [blame] | 2031 | ; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2032 | } else |
| 2033 | return false; |
| 2034 | |
| 2035 | return true; |
| 2036 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2037 | |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2038 | void getDefaultFeatures(const std::string &CPU, |
| 2039 | llvm::StringMap<bool> &Features) const { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2040 | if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") |
| 2041 | Features["vfp2"] = true; |
| 2042 | else if (CPU == "cortex-a8" || CPU == "cortex-a9") |
| 2043 | Features["neon"] = true; |
| 2044 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2045 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2046 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 2047 | const std::string &Name, |
| 2048 | bool Enabled) const { |
Evan Cheng | f972b26 | 2011-07-08 06:40:11 +0000 | [diff] [blame] | 2049 | if (Name == "soft-float" || Name == "soft-float-abi" || |
| 2050 | Name == "vfp2" || Name == "vfp3" || Name == "neon") { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2051 | Features[Name] = Enabled; |
| 2052 | } else |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2053 | return false; |
| 2054 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2055 | return true; |
| 2056 | } |
| 2057 | |
| 2058 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2059 | FPU = NoFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2060 | SoftFloat = SoftFloatABI = false; |
| 2061 | for (unsigned i = 0, e = Features.size(); i != e; ++i) { |
| 2062 | if (Features[i] == "+soft-float") |
| 2063 | SoftFloat = true; |
| 2064 | else if (Features[i] == "+soft-float-abi") |
| 2065 | SoftFloatABI = true; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2066 | else if (Features[i] == "+vfp2") |
| 2067 | FPU = VFP2FPU; |
| 2068 | else if (Features[i] == "+vfp3") |
| 2069 | FPU = VFP3FPU; |
| 2070 | else if (Features[i] == "+neon") |
| 2071 | FPU = NeonFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | // Remove front-end specific options which the backend handles differently. |
| 2075 | std::vector<std::string>::iterator it; |
| 2076 | it = std::find(Features.begin(), Features.end(), "+soft-float"); |
| 2077 | if (it != Features.end()) |
| 2078 | Features.erase(it); |
| 2079 | it = std::find(Features.begin(), Features.end(), "+soft-float-abi"); |
| 2080 | if (it != Features.end()) |
| 2081 | Features.erase(it); |
| 2082 | } |
| 2083 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2084 | static const char *getCPUDefineSuffix(StringRef Name) { |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2085 | return llvm::StringSwitch<const char*>(Name) |
| 2086 | .Cases("arm8", "arm810", "4") |
| 2087 | .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4") |
| 2088 | .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T") |
| 2089 | .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T") |
| 2090 | .Case("ep9312", "4T") |
| 2091 | .Cases("arm10tdmi", "arm1020t", "5T") |
| 2092 | .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE") |
| 2093 | .Case("arm926ej-s", "5TEJ") |
| 2094 | .Cases("arm10e", "arm1020e", "arm1022e", "5TE") |
| 2095 | .Cases("xscale", "iwmmxt", "5TE") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2096 | .Case("arm1136j-s", "6J") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2097 | .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2098 | .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2099 | .Cases("arm1156t2-s", "arm1156t2f-s", "6T2") |
| 2100 | .Cases("cortex-a8", "cortex-a9", "7A") |
Bob Wilson | 06f4563 | 2011-01-06 16:57:20 +0000 | [diff] [blame] | 2101 | .Case("cortex-m3", "7M") |
Bob Wilson | a291d5f | 2011-03-21 21:55:25 +0000 | [diff] [blame] | 2102 | .Case("cortex-m0", "6M") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2103 | .Default(0); |
| 2104 | } |
| 2105 | virtual bool setCPU(const std::string &Name) { |
| 2106 | if (!getCPUDefineSuffix(Name)) |
| 2107 | return false; |
| 2108 | |
| 2109 | CPU = Name; |
| 2110 | return true; |
| 2111 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 2112 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2113 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 2114 | // Target identification. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2115 | Builder.defineMacro("__arm"); |
| 2116 | Builder.defineMacro("__arm__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2117 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 2118 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2119 | Builder.defineMacro("__ARMEL__"); |
| 2120 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
| 2121 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2122 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2123 | StringRef CPUArch = getCPUDefineSuffix(CPU); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2124 | Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2125 | |
Mike Stump | 437bb4b | 2009-04-08 02:07:04 +0000 | [diff] [blame] | 2126 | // Subtarget options. |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2127 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2128 | // FIXME: It's more complicated than this and we don't really support |
| 2129 | // interworking. |
| 2130 | if ('5' <= CPUArch[0] && CPUArch[0] <= '7') |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2131 | Builder.defineMacro("__THUMB_INTERWORK__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2132 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2133 | if (ABI == "aapcs" || ABI == "aapcs-linux") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2134 | Builder.defineMacro("__ARM_EABI__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2135 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2136 | if (SoftFloat) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2137 | Builder.defineMacro("__SOFTFP__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2138 | |
| 2139 | if (CPU == "xscale") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2140 | Builder.defineMacro("__XSCALE__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2141 | |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2142 | bool IsARMv7 = CPUArch.startswith("7"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2143 | if (IsThumb) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2144 | Builder.defineMacro("__THUMBEL__"); |
| 2145 | Builder.defineMacro("__thumb__"); |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2146 | if (CPUArch == "6T2" || IsARMv7) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2147 | Builder.defineMacro("__thumb2__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | // 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] | 2151 | Builder.defineMacro("__APCS_32__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2152 | |
| 2153 | if (FPUModeIsVFP((FPUMode) FPU)) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2154 | Builder.defineMacro("__VFP_FP__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2155 | |
| 2156 | // This only gets set when Neon instructions are actually available, unlike |
| 2157 | // the VFP define, hence the soft float and arch check. This is subtly |
| 2158 | // different from gcc, we follow the intent which was that it should be set |
| 2159 | // when Neon instructions are actually available. |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2160 | if (FPU == NeonFPU && !SoftFloat && IsARMv7) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2161 | Builder.defineMacro("__ARM_NEON__"); |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2162 | } |
| 2163 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2164 | unsigned &NumRecords) const { |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2165 | Records = BuiltinInfo; |
| 2166 | NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2167 | } |
| 2168 | virtual const char *getVAListDeclaration() const { |
John McCall | 0e9972c | 2011-05-09 02:19:37 +0000 | [diff] [blame] | 2169 | return "typedef void* __builtin_va_list;"; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2170 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2171 | virtual void getGCCRegNames(const char * const *&Names, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2172 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2173 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2174 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2175 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 2176 | TargetInfo::ConstraintInfo &Info) const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2177 | // FIXME: Check if this is complete |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2178 | switch (*Name) { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2179 | default: |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2180 | case 'l': // r0-r7 |
| 2181 | case 'h': // r8-r15 |
| 2182 | case 'w': // VFP Floating point register single precision |
| 2183 | case 'P': // VFP Floating point register double precision |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 2184 | Info.setAllowsRegister(); |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2185 | return true; |
Eric Christopher | 895d422 | 2011-07-29 21:20:35 +0000 | [diff] [blame] | 2186 | case 'Q': // A memory address that is a single base register. |
| 2187 | Info.setAllowsMemory(); |
| 2188 | return true; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2189 | case 'U': // a memory reference... |
| 2190 | switch (Name[1]) { |
| 2191 | case 'q': // ...ARMV4 ldrsb |
| 2192 | case 'v': // ...VFP load/store (reg+constant offset) |
| 2193 | case 'y': // ...iWMMXt load/store |
Eric Christopher | dda231a | 2011-06-17 01:40:49 +0000 | [diff] [blame] | 2194 | case 't': // address valid for load/store opaque types wider |
| 2195 | // than 128-bits |
| 2196 | case 'n': // valid address for Neon doubleword vector load/store |
| 2197 | case 'm': // valid address for Neon element and structure load/store |
| 2198 | case 's': // valid address for non-offset loads/stores of quad-word |
| 2199 | // values in four ARM registers |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2200 | Info.setAllowsMemory(); |
| 2201 | Name++; |
| 2202 | return true; |
| 2203 | } |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2204 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2205 | return false; |
| 2206 | } |
Evan Cheng | 8bfa257 | 2011-06-16 19:13:15 +0000 | [diff] [blame] | 2207 | virtual std::string convertConstraint(const char *&Constraint) const { |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2208 | std::string R; |
| 2209 | switch (*Constraint) { |
| 2210 | case 'U': // Two-character constraint; add "^" hint for later parsing. |
Stuart Hastings | 6ce33d6 | 2011-06-08 16:06:31 +0000 | [diff] [blame] | 2211 | R = std::string("^") + std::string(Constraint, 2); |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2212 | Constraint++; |
| 2213 | break; |
Eric Christopher | 283f447 | 2011-06-17 00:40:18 +0000 | [diff] [blame] | 2214 | case 'p': // 'p' should be translated to 'r' by default. |
| 2215 | R = std::string("r"); |
| 2216 | break; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2217 | default: |
| 2218 | return std::string(1, *Constraint); |
| 2219 | } |
| 2220 | return R; |
| 2221 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2222 | virtual const char *getClobbers() const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2223 | // FIXME: Is this really right? |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2224 | return ""; |
| 2225 | } |
| 2226 | }; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2227 | |
| 2228 | const char * const ARMTargetInfo::GCCRegNames[] = { |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 2229 | // Integer registers |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2230 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 2231 | "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc", |
| 2232 | |
| 2233 | // Float registers |
| 2234 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 2235 | "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", |
| 2236 | "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 2237 | "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 2238 | |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 2239 | // Double registers |
| 2240 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", |
| 2241 | "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", |
Dale Johannesen | d145535 | 2010-10-28 01:05:37 +0000 | [diff] [blame] | 2242 | "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", |
| 2243 | "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 2244 | |
| 2245 | // Quad registers |
Dale Johannesen | d145535 | 2010-10-28 01:05:37 +0000 | [diff] [blame] | 2246 | "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", |
| 2247 | "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2248 | }; |
| 2249 | |
| 2250 | void ARMTargetInfo::getGCCRegNames(const char * const *&Names, |
Daniel Dunbar | 1fd7171 | 2010-08-11 02:17:11 +0000 | [diff] [blame] | 2251 | unsigned &NumNames) const { |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2252 | Names = GCCRegNames; |
| 2253 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2254 | } |
| 2255 | |
| 2256 | const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2257 | { { "a1" }, "r0" }, |
| 2258 | { { "a2" }, "r1" }, |
| 2259 | { { "a3" }, "r2" }, |
| 2260 | { { "a4" }, "r3" }, |
| 2261 | { { "v1" }, "r4" }, |
| 2262 | { { "v2" }, "r5" }, |
| 2263 | { { "v3" }, "r6" }, |
| 2264 | { { "v4" }, "r7" }, |
| 2265 | { { "v5" }, "r8" }, |
| 2266 | { { "v6", "rfp" }, "r9" }, |
| 2267 | { { "sl" }, "r10" }, |
| 2268 | { { "fp" }, "r11" }, |
| 2269 | { { "ip" }, "r12" }, |
Daniel Dunbar | 1fd7171 | 2010-08-11 02:17:11 +0000 | [diff] [blame] | 2270 | { { "r13" }, "sp" }, |
| 2271 | { { "r14" }, "lr" }, |
| 2272 | { { "r15" }, "pc" }, |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 2273 | // The S, D and Q registers overlap, but aren't really aliases; we |
| 2274 | // 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] | 2275 | }; |
| 2276 | |
| 2277 | void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2278 | unsigned &NumAliases) const { |
| 2279 | Aliases = GCCRegAliases; |
| 2280 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 2281 | } |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2282 | |
| 2283 | const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 2284 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 2285 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 2286 | ALL_LANGUAGES }, |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2287 | #include "clang/Basic/BuiltinsARM.def" |
| 2288 | }; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2289 | } // end anonymous namespace. |
| 2290 | |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2291 | |
| 2292 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2293 | class DarwinARMTargetInfo : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2294 | public DarwinTargetInfo<ARMTargetInfo> { |
| 2295 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 2296 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2297 | MacroBuilder &Builder) const { |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 2298 | getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion); |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 2299 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2300 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2301 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2302 | DarwinARMTargetInfo(const std::string& triple) |
Daniel Dunbar | 350b9f3 | 2010-05-27 07:00:26 +0000 | [diff] [blame] | 2303 | : DarwinTargetInfo<ARMTargetInfo>(triple) { |
| 2304 | HasAlignMac68kSupport = true; |
| 2305 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2306 | }; |
| 2307 | } // end anonymous namespace. |
| 2308 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2309 | namespace { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2310 | class SparcV8TargetInfo : public TargetInfo { |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2311 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 2312 | static const char * const GCCRegNames[]; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 2313 | bool SoftFloat; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2314 | public: |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2315 | SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2316 | // FIXME: Support Sparc quad-precision long double? |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 2317 | 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] | 2318 | "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] | 2319 | } |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 2320 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 2321 | const std::string &Name, |
| 2322 | bool Enabled) const { |
| 2323 | if (Name == "soft-float") |
| 2324 | Features[Name] = Enabled; |
| 2325 | else |
| 2326 | return false; |
| 2327 | |
| 2328 | return true; |
| 2329 | } |
| 2330 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
| 2331 | SoftFloat = false; |
| 2332 | for (unsigned i = 0, e = Features.size(); i != e; ++i) |
| 2333 | if (Features[i] == "+soft-float") |
| 2334 | SoftFloat = true; |
| 2335 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 2336 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2337 | MacroBuilder &Builder) const { |
| 2338 | DefineStd(Builder, "sparc", Opts); |
| 2339 | Builder.defineMacro("__sparcv8"); |
| 2340 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 2341 | |
| 2342 | if (SoftFloat) |
| 2343 | Builder.defineMacro("SOFT_FLOAT", "1"); |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2344 | } |
| 2345 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2346 | unsigned &NumRecords) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2347 | // FIXME: Implement! |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2348 | } |
| 2349 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2350 | return "typedef void* __builtin_va_list;"; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2351 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2352 | virtual void getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2353 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2354 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2355 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2356 | virtual bool validateAsmConstraint(const char *&Name, |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2357 | TargetInfo::ConstraintInfo &info) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2358 | // FIXME: Implement! |
| 2359 | return false; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2360 | } |
| 2361 | virtual const char *getClobbers() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2362 | // FIXME: Implement! |
| 2363 | return ""; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2364 | } |
| 2365 | }; |
| 2366 | |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2367 | const char * const SparcV8TargetInfo::GCCRegNames[] = { |
| 2368 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2369 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 2370 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 2371 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" |
| 2372 | }; |
| 2373 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2374 | void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2375 | unsigned &NumNames) const { |
| 2376 | Names = GCCRegNames; |
| 2377 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2378 | } |
| 2379 | |
| 2380 | const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2381 | { { "g0" }, "r0" }, |
| 2382 | { { "g1" }, "r1" }, |
| 2383 | { { "g2" }, "r2" }, |
| 2384 | { { "g3" }, "r3" }, |
| 2385 | { { "g4" }, "r4" }, |
| 2386 | { { "g5" }, "r5" }, |
| 2387 | { { "g6" }, "r6" }, |
| 2388 | { { "g7" }, "r7" }, |
| 2389 | { { "o0" }, "r8" }, |
| 2390 | { { "o1" }, "r9" }, |
| 2391 | { { "o2" }, "r10" }, |
| 2392 | { { "o3" }, "r11" }, |
| 2393 | { { "o4" }, "r12" }, |
| 2394 | { { "o5" }, "r13" }, |
| 2395 | { { "o6", "sp" }, "r14" }, |
| 2396 | { { "o7" }, "r15" }, |
| 2397 | { { "l0" }, "r16" }, |
| 2398 | { { "l1" }, "r17" }, |
| 2399 | { { "l2" }, "r18" }, |
| 2400 | { { "l3" }, "r19" }, |
| 2401 | { { "l4" }, "r20" }, |
| 2402 | { { "l5" }, "r21" }, |
| 2403 | { { "l6" }, "r22" }, |
| 2404 | { { "l7" }, "r23" }, |
| 2405 | { { "i0" }, "r24" }, |
| 2406 | { { "i1" }, "r25" }, |
| 2407 | { { "i2" }, "r26" }, |
| 2408 | { { "i3" }, "r27" }, |
| 2409 | { { "i4" }, "r28" }, |
| 2410 | { { "i5" }, "r29" }, |
| 2411 | { { "i6", "fp" }, "r30" }, |
| 2412 | { { "i7" }, "r31" }, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2413 | }; |
| 2414 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2415 | void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 2416 | unsigned &NumAliases) const { |
| 2417 | Aliases = GCCRegAliases; |
| 2418 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 2419 | } |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 2420 | } // end anonymous namespace. |
| 2421 | |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2422 | namespace { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 2423 | class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> { |
| 2424 | public: |
| 2425 | AuroraUXSparcV8TargetInfo(const std::string& triple) : |
| 2426 | AuroraUXTargetInfo<SparcV8TargetInfo>(triple) { |
| 2427 | SizeType = UnsignedInt; |
| 2428 | PtrDiffType = SignedInt; |
| 2429 | } |
| 2430 | }; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2431 | class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2432 | public: |
| 2433 | SolarisSparcV8TargetInfo(const std::string& triple) : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2434 | SolarisTargetInfo<SparcV8TargetInfo>(triple) { |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 2435 | SizeType = UnsignedInt; |
| 2436 | PtrDiffType = SignedInt; |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2437 | } |
| 2438 | }; |
| 2439 | } // end anonymous namespace. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2440 | |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 2441 | namespace { |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2442 | class MSP430TargetInfo : public TargetInfo { |
| 2443 | static const char * const GCCRegNames[]; |
| 2444 | public: |
| 2445 | MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2446 | TLSSupported = false; |
Anton Korobeynikov | 09f52a6 | 2010-01-30 12:55:11 +0000 | [diff] [blame] | 2447 | IntWidth = 16; IntAlign = 16; |
| 2448 | LongWidth = 32; LongLongWidth = 64; |
| 2449 | LongAlign = LongLongAlign = 16; |
| 2450 | PointerWidth = 16; PointerAlign = 16; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2451 | SizeType = UnsignedInt; |
| 2452 | IntMaxType = SignedLong; |
| 2453 | UIntMaxType = UnsignedLong; |
| 2454 | IntPtrType = SignedShort; |
| 2455 | PtrDiffType = SignedInt; |
Edward O'Callaghan | 9cf910e | 2009-11-21 00:49:54 +0000 | [diff] [blame] | 2456 | SigAtomicType = SignedLong; |
Anton Korobeynikov | 5d7c251 | 2009-12-19 01:32:37 +0000 | [diff] [blame] | 2457 | 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] | 2458 | } |
| 2459 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2460 | MacroBuilder &Builder) const { |
| 2461 | Builder.defineMacro("MSP430"); |
| 2462 | Builder.defineMacro("__MSP430__"); |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2463 | // FIXME: defines for different 'flavours' of MCU |
| 2464 | } |
| 2465 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2466 | unsigned &NumRecords) const { |
| 2467 | // FIXME: Implement. |
| 2468 | Records = 0; |
| 2469 | NumRecords = 0; |
| 2470 | } |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2471 | virtual void getGCCRegNames(const char * const *&Names, |
| 2472 | unsigned &NumNames) const; |
| 2473 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2474 | unsigned &NumAliases) const { |
| 2475 | // No aliases. |
| 2476 | Aliases = 0; |
| 2477 | NumAliases = 0; |
| 2478 | } |
| 2479 | virtual bool validateAsmConstraint(const char *&Name, |
| 2480 | TargetInfo::ConstraintInfo &info) const { |
Anton Korobeynikov | 03265b6 | 2009-10-15 23:17:13 +0000 | [diff] [blame] | 2481 | // No target constraints for now. |
| 2482 | return false; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2483 | } |
| 2484 | virtual const char *getClobbers() const { |
| 2485 | // FIXME: Is this really right? |
| 2486 | return ""; |
| 2487 | } |
| 2488 | virtual const char *getVAListDeclaration() const { |
| 2489 | // FIXME: implement |
Anton Korobeynikov | eb71685 | 2009-05-08 18:24:57 +0000 | [diff] [blame] | 2490 | return "typedef char* __builtin_va_list;"; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 2491 | } |
| 2492 | }; |
| 2493 | |
| 2494 | const char * const MSP430TargetInfo::GCCRegNames[] = { |
| 2495 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2496 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 2497 | }; |
| 2498 | |
| 2499 | void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, |
| 2500 | unsigned &NumNames) const { |
| 2501 | Names = GCCRegNames; |
| 2502 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 2507 | namespace { |
| 2508 | class SystemZTargetInfo : public TargetInfo { |
| 2509 | static const char * const GCCRegNames[]; |
| 2510 | public: |
| 2511 | SystemZTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2512 | TLSSupported = false; |
| 2513 | IntWidth = IntAlign = 32; |
| 2514 | LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; |
| 2515 | PointerWidth = PointerAlign = 64; |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 2516 | DescriptionString = "E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-" |
| 2517 | "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] | 2518 | } |
| 2519 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2520 | MacroBuilder &Builder) const { |
| 2521 | Builder.defineMacro("__s390__"); |
| 2522 | Builder.defineMacro("__s390x__"); |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 2523 | } |
| 2524 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2525 | unsigned &NumRecords) const { |
| 2526 | // FIXME: Implement. |
| 2527 | Records = 0; |
| 2528 | NumRecords = 0; |
| 2529 | } |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 2530 | |
Anton Korobeynikov | 89e887f | 2009-07-16 20:09:57 +0000 | [diff] [blame] | 2531 | virtual void getGCCRegNames(const char * const *&Names, |
| 2532 | unsigned &NumNames) const; |
| 2533 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2534 | unsigned &NumAliases) const { |
| 2535 | // No aliases. |
| 2536 | Aliases = 0; |
| 2537 | NumAliases = 0; |
| 2538 | } |
| 2539 | virtual bool validateAsmConstraint(const char *&Name, |
| 2540 | TargetInfo::ConstraintInfo &info) const { |
| 2541 | // FIXME: implement |
| 2542 | return true; |
| 2543 | } |
| 2544 | virtual const char *getClobbers() const { |
| 2545 | // FIXME: Is this really right? |
| 2546 | return ""; |
| 2547 | } |
| 2548 | virtual const char *getVAListDeclaration() const { |
| 2549 | // FIXME: implement |
| 2550 | return "typedef char* __builtin_va_list;"; |
| 2551 | } |
| 2552 | }; |
| 2553 | |
| 2554 | const char * const SystemZTargetInfo::GCCRegNames[] = { |
| 2555 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2556 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 2557 | }; |
| 2558 | |
| 2559 | void SystemZTargetInfo::getGCCRegNames(const char * const *&Names, |
| 2560 | unsigned &NumNames) const { |
| 2561 | Names = GCCRegNames; |
| 2562 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2563 | } |
| 2564 | } |
| 2565 | |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2566 | namespace { |
| 2567 | class BlackfinTargetInfo : public TargetInfo { |
| 2568 | static const char * const GCCRegNames[]; |
| 2569 | public: |
| 2570 | BlackfinTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2571 | TLSSupported = false; |
| 2572 | DoubleAlign = 32; |
| 2573 | LongLongAlign = 32; |
| 2574 | LongDoubleAlign = 32; |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 2575 | DescriptionString = "e-p:32:32-i64:32-f64:32-n32"; |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2579 | MacroBuilder &Builder) const { |
| 2580 | DefineStd(Builder, "bfin", Opts); |
| 2581 | DefineStd(Builder, "BFIN", Opts); |
| 2582 | Builder.defineMacro("__ADSPBLACKFIN__"); |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2583 | // FIXME: This one is really dependent on -mcpu |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2584 | Builder.defineMacro("__ADSPLPBLACKFIN__"); |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2585 | // FIXME: Add cpu-dependent defines and __SILICON_REVISION__ |
| 2586 | } |
| 2587 | |
| 2588 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2589 | unsigned &NumRecords) const { |
| 2590 | // FIXME: Implement. |
| 2591 | Records = 0; |
| 2592 | NumRecords = 0; |
| 2593 | } |
| 2594 | |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 2595 | virtual void getGCCRegNames(const char * const *&Names, |
| 2596 | unsigned &NumNames) const; |
| 2597 | |
| 2598 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2599 | unsigned &NumAliases) const { |
| 2600 | // No aliases. |
| 2601 | Aliases = 0; |
| 2602 | NumAliases = 0; |
| 2603 | } |
| 2604 | |
| 2605 | virtual bool validateAsmConstraint(const char *&Name, |
| 2606 | TargetInfo::ConstraintInfo &Info) const { |
| 2607 | if (strchr("adzDWeABbvfcCtukxywZY", Name[0])) { |
| 2608 | Info.setAllowsRegister(); |
| 2609 | return true; |
| 2610 | } |
| 2611 | return false; |
| 2612 | } |
| 2613 | |
| 2614 | virtual const char *getClobbers() const { |
| 2615 | return ""; |
| 2616 | } |
| 2617 | |
| 2618 | virtual const char *getVAListDeclaration() const { |
| 2619 | return "typedef char* __builtin_va_list;"; |
| 2620 | } |
| 2621 | }; |
| 2622 | |
| 2623 | const char * const BlackfinTargetInfo::GCCRegNames[] = { |
| 2624 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2625 | "p0", "p1", "p2", "p3", "p4", "p5", "sp", "fp", |
| 2626 | "i0", "i1", "i2", "i3", "b0", "b1", "b2", "b3", |
| 2627 | "l0", "l1", "l2", "l3", "m0", "m1", "m2", "m3", |
| 2628 | "a0", "a1", "cc", |
| 2629 | "rets", "reti", "retx", "retn", "rete", "astat", "seqstat", "usp", |
| 2630 | "argp", "lt0", "lt1", "lc0", "lc1", "lb0", "lb1" |
| 2631 | }; |
| 2632 | |
| 2633 | void BlackfinTargetInfo::getGCCRegNames(const char * const *&Names, |
| 2634 | unsigned &NumNames) const { |
| 2635 | Names = GCCRegNames; |
| 2636 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2637 | } |
| 2638 | } |
| 2639 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2640 | namespace { |
| 2641 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | // LLVM and Clang cannot be used directly to output native binaries for |
| 2643 | // 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] | 2644 | // type and alignment information. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2645 | // |
| 2646 | // TCE uses the llvm bitcode as input and uses it for generating customized |
| 2647 | // target processor and program binary. TCE co-design environment is |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2648 | // publicly available in http://tce.cs.tut.fi |
| 2649 | |
| 2650 | class TCETargetInfo : public TargetInfo{ |
| 2651 | public: |
| 2652 | TCETargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2653 | TLSSupported = false; |
| 2654 | IntWidth = 32; |
| 2655 | LongWidth = LongLongWidth = 32; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2656 | PointerWidth = 32; |
| 2657 | IntAlign = 32; |
| 2658 | LongAlign = LongLongAlign = 32; |
| 2659 | PointerAlign = 32; |
| 2660 | SizeType = UnsignedInt; |
| 2661 | IntMaxType = SignedLong; |
| 2662 | UIntMaxType = UnsignedLong; |
| 2663 | IntPtrType = SignedInt; |
| 2664 | PtrDiffType = SignedInt; |
| 2665 | FloatWidth = 32; |
| 2666 | FloatAlign = 32; |
| 2667 | DoubleWidth = 32; |
| 2668 | DoubleAlign = 32; |
| 2669 | LongDoubleWidth = 32; |
| 2670 | LongDoubleAlign = 32; |
| 2671 | FloatFormat = &llvm::APFloat::IEEEsingle; |
| 2672 | DoubleFormat = &llvm::APFloat::IEEEsingle; |
| 2673 | LongDoubleFormat = &llvm::APFloat::IEEEsingle; |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 2674 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-" |
| 2675 | "i16:16:32-i32:32:32-i64:32:32-" |
NAKAMURA Takumi | c910929 | 2011-02-18 08:44:38 +0000 | [diff] [blame] | 2676 | "f32:32:32-f64:32:32-v64:32:32-" |
| 2677 | "v128:32:32-a0:0:32-n32"; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2681 | MacroBuilder &Builder) const { |
| 2682 | DefineStd(Builder, "tce", Opts); |
| 2683 | Builder.defineMacro("__TCE__"); |
| 2684 | Builder.defineMacro("__TCE_V1__"); |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2685 | } |
| 2686 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2687 | unsigned &NumRecords) const {} |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2688 | virtual const char *getClobbers() const { |
| 2689 | return ""; |
| 2690 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2691 | virtual const char *getVAListDeclaration() const { |
| 2692 | return "typedef void* __builtin_va_list;"; |
| 2693 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 2694 | virtual void getGCCRegNames(const char * const *&Names, |
| 2695 | unsigned &NumNames) const {} |
| 2696 | virtual bool validateAsmConstraint(const char *&Name, |
| 2697 | TargetInfo::ConstraintInfo &info) const { |
| 2698 | return true; |
| 2699 | } |
| 2700 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2701 | unsigned &NumAliases) const {} |
| 2702 | }; |
| 2703 | } |
| 2704 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2705 | namespace { |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2706 | class MipsTargetInfoBase : public TargetInfo { |
| 2707 | std::string CPU; |
| 2708 | protected: |
| 2709 | std::string ABI; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2710 | public: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2711 | MipsTargetInfoBase(const std::string& triple, const std::string& ABIStr) |
| 2712 | : TargetInfo(triple), ABI(ABIStr) { |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 2713 | SizeType = UnsignedInt; |
| 2714 | PtrDiffType = SignedInt; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2715 | } |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2716 | virtual const char *getABI() const { return ABI.c_str(); } |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2717 | virtual bool setABI(const std::string &Name) = 0; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 2718 | virtual bool setCPU(const std::string &Name) { |
| 2719 | CPU = Name; |
| 2720 | return true; |
| 2721 | } |
| 2722 | void getDefaultFeatures(const std::string &CPU, |
| 2723 | llvm::StringMap<bool> &Features) const { |
| 2724 | Features[ABI] = true; |
| 2725 | Features[CPU] = true; |
| 2726 | } |
| 2727 | virtual void getArchDefines(const LangOptions &Opts, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2728 | MacroBuilder &Builder) const = 0; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2729 | virtual void getTargetDefines(const LangOptions &Opts, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2730 | MacroBuilder &Builder) const = 0; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2731 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2732 | unsigned &NumRecords) const { |
| 2733 | // FIXME: Implement! |
| 2734 | } |
| 2735 | virtual const char *getVAListDeclaration() const { |
| 2736 | return "typedef void* __builtin_va_list;"; |
| 2737 | } |
| 2738 | virtual void getGCCRegNames(const char * const *&Names, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2739 | unsigned &NumNames) const { |
| 2740 | static const char * const GCCRegNames[] = { |
| 2741 | "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", |
| 2742 | "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", |
| 2743 | "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23", |
| 2744 | "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31", |
| 2745 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 2746 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 2747 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 2748 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
| 2749 | "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4", |
| 2750 | "$fcc5","$fcc6","$fcc7" |
| 2751 | }; |
| 2752 | Names = GCCRegNames; |
| 2753 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 2754 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2755 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2756 | unsigned &NumAliases) const = 0; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2757 | virtual bool validateAsmConstraint(const char *&Name, |
| 2758 | TargetInfo::ConstraintInfo &Info) const { |
| 2759 | switch (*Name) { |
| 2760 | default: |
| 2761 | case 'r': // CPU registers. |
| 2762 | case 'd': // Equivalent to "r" unless generating MIPS16 code. |
| 2763 | case 'y': // Equivalent to "r", backwards compatibility only. |
| 2764 | case 'f': // floating-point registers. |
| 2765 | Info.setAllowsRegister(); |
| 2766 | return true; |
| 2767 | } |
| 2768 | return false; |
| 2769 | } |
| 2770 | |
| 2771 | virtual const char *getClobbers() const { |
| 2772 | // FIXME: Implement! |
| 2773 | return ""; |
| 2774 | } |
| 2775 | }; |
| 2776 | |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2777 | class Mips32TargetInfoBase : public MipsTargetInfoBase { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2778 | public: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2779 | Mips32TargetInfoBase(const std::string& triple) : |
| 2780 | MipsTargetInfoBase(triple, "o32") {} |
| 2781 | virtual bool setABI(const std::string &Name) { |
| 2782 | if ((Name == "o32") || (Name == "eabi")) { |
| 2783 | ABI = Name; |
| 2784 | return true; |
| 2785 | } else |
| 2786 | return false; |
| 2787 | } |
| 2788 | virtual void getArchDefines(const LangOptions &Opts, |
| 2789 | MacroBuilder &Builder) const { |
| 2790 | if (ABI == "o32") { |
| 2791 | Builder.defineMacro("__mips_o32"); |
| 2792 | Builder.defineMacro("_ABIO32", "1"); |
| 2793 | Builder.defineMacro("_MIPS_SIM", "_ABIO32"); |
| 2794 | } |
| 2795 | else if (ABI == "eabi") |
| 2796 | Builder.defineMacro("__mips_eabi"); |
| 2797 | else |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame^] | 2798 | llvm_unreachable("Invalid ABI for Mips32."); |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2799 | } |
| 2800 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2801 | unsigned &NumAliases) const { |
| 2802 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 2803 | { { "at" }, "$1" }, |
| 2804 | { { "v0" }, "$2" }, |
| 2805 | { { "v1" }, "$3" }, |
| 2806 | { { "a0" }, "$4" }, |
| 2807 | { { "a1" }, "$5" }, |
| 2808 | { { "a2" }, "$6" }, |
| 2809 | { { "a3" }, "$7" }, |
| 2810 | { { "t0" }, "$8" }, |
| 2811 | { { "t1" }, "$9" }, |
| 2812 | { { "t2" }, "$10" }, |
| 2813 | { { "t3" }, "$11" }, |
| 2814 | { { "t4" }, "$12" }, |
| 2815 | { { "t5" }, "$13" }, |
| 2816 | { { "t6" }, "$14" }, |
| 2817 | { { "t7" }, "$15" }, |
| 2818 | { { "s0" }, "$16" }, |
| 2819 | { { "s1" }, "$17" }, |
| 2820 | { { "s2" }, "$18" }, |
| 2821 | { { "s3" }, "$19" }, |
| 2822 | { { "s4" }, "$20" }, |
| 2823 | { { "s5" }, "$21" }, |
| 2824 | { { "s6" }, "$22" }, |
| 2825 | { { "s7" }, "$23" }, |
| 2826 | { { "t8" }, "$24" }, |
| 2827 | { { "t9" }, "$25" }, |
| 2828 | { { "k0" }, "$26" }, |
| 2829 | { { "k1" }, "$27" }, |
| 2830 | { { "gp" }, "$28" }, |
| 2831 | { { "sp" }, "$29" }, |
| 2832 | { { "fp" }, "$30" }, |
| 2833 | { { "ra" }, "$31" } |
| 2834 | }; |
| 2835 | Aliases = GCCRegAliases; |
| 2836 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 2837 | } |
| 2838 | }; |
| 2839 | |
| 2840 | class Mips32EBTargetInfo : public Mips32TargetInfoBase { |
| 2841 | public: |
| 2842 | Mips32EBTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) { |
| 2843 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2844 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2845 | } |
| 2846 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2847 | MacroBuilder &Builder) const { |
| 2848 | DefineStd(Builder, "mips", Opts); |
| 2849 | Builder.defineMacro("_mips"); |
| 2850 | DefineStd(Builder, "MIPSEB", Opts); |
| 2851 | Builder.defineMacro("_MIPSEB"); |
| 2852 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 2853 | getArchDefines(Opts, Builder); |
| 2854 | } |
| 2855 | }; |
| 2856 | |
| 2857 | class Mips32ELTargetInfo : public Mips32TargetInfoBase { |
| 2858 | public: |
| 2859 | Mips32ELTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2860 | 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] | 2861 | "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] | 2862 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2863 | virtual void getTargetDefines(const LangOptions &Opts, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 2864 | MacroBuilder &Builder) const { |
| 2865 | DefineStd(Builder, "mips", Opts); |
| 2866 | Builder.defineMacro("_mips"); |
| 2867 | DefineStd(Builder, "MIPSEL", Opts); |
| 2868 | Builder.defineMacro("_MIPSEL"); |
| 2869 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 2870 | getArchDefines(Opts, Builder); |
| 2871 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2872 | }; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 2873 | |
| 2874 | class Mips64TargetInfoBase : public MipsTargetInfoBase { |
| 2875 | virtual void SetDescriptionString(const std::string &Name) = 0; |
| 2876 | public: |
| 2877 | Mips64TargetInfoBase(const std::string& triple) : |
| 2878 | MipsTargetInfoBase(triple, "n64") {} |
| 2879 | virtual bool setABI(const std::string &Name) { |
| 2880 | SetDescriptionString(Name); |
| 2881 | if ((Name == "n32") || (Name == "n64")) { |
| 2882 | ABI = Name; |
| 2883 | return true; |
| 2884 | } else |
| 2885 | return false; |
| 2886 | } |
| 2887 | virtual void getArchDefines(const LangOptions &Opts, |
| 2888 | MacroBuilder &Builder) const { |
| 2889 | if (ABI == "n32") { |
| 2890 | Builder.defineMacro("__mips_n32"); |
| 2891 | Builder.defineMacro("_ABIN32", "2"); |
| 2892 | Builder.defineMacro("_MIPS_SIM", "_ABIN32"); |
| 2893 | } |
| 2894 | else if (ABI == "n64") { |
| 2895 | Builder.defineMacro("__mips_n64"); |
| 2896 | Builder.defineMacro("_ABI64", "3"); |
| 2897 | Builder.defineMacro("_MIPS_SIM", "_ABI64"); |
| 2898 | } |
| 2899 | else |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame^] | 2900 | llvm_unreachable("Invalid ABI for Mips64."); |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 2901 | } |
| 2902 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 2903 | unsigned &NumAliases) const { |
| 2904 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 2905 | { { "at" }, "$1" }, |
| 2906 | { { "v0" }, "$2" }, |
| 2907 | { { "v1" }, "$3" }, |
| 2908 | { { "a0" }, "$4" }, |
| 2909 | { { "a1" }, "$5" }, |
| 2910 | { { "a2" }, "$6" }, |
| 2911 | { { "a3" }, "$7" }, |
| 2912 | { { "a4" }, "$8" }, |
| 2913 | { { "a5" }, "$9" }, |
| 2914 | { { "a6" }, "$10" }, |
| 2915 | { { "a7" }, "$11" }, |
| 2916 | { { "t0" }, "$12" }, |
| 2917 | { { "t1" }, "$13" }, |
| 2918 | { { "t2" }, "$14" }, |
| 2919 | { { "t3" }, "$15" }, |
| 2920 | { { "s0" }, "$16" }, |
| 2921 | { { "s1" }, "$17" }, |
| 2922 | { { "s2" }, "$18" }, |
| 2923 | { { "s3" }, "$19" }, |
| 2924 | { { "s4" }, "$20" }, |
| 2925 | { { "s5" }, "$21" }, |
| 2926 | { { "s6" }, "$22" }, |
| 2927 | { { "s7" }, "$23" }, |
| 2928 | { { "t8" }, "$24" }, |
| 2929 | { { "t9" }, "$25" }, |
| 2930 | { { "k0" }, "$26" }, |
| 2931 | { { "k1" }, "$27" }, |
| 2932 | { { "gp" }, "$28" }, |
| 2933 | { { "sp" }, "$29" }, |
| 2934 | { { "fp" }, "$30" }, |
| 2935 | { { "ra" }, "$31" } |
| 2936 | }; |
| 2937 | Aliases = GCCRegAliases; |
| 2938 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 2939 | } |
| 2940 | }; |
| 2941 | |
| 2942 | class Mips64EBTargetInfo : public Mips64TargetInfoBase { |
| 2943 | virtual void SetDescriptionString(const std::string &Name) { |
| 2944 | // Change DescriptionString only if ABI is n32. |
| 2945 | if (Name == "n32") |
| 2946 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2947 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2948 | } |
| 2949 | public: |
| 2950 | Mips64EBTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) { |
| 2951 | // Default ABI is n64. |
| 2952 | DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2953 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2954 | } |
| 2955 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2956 | MacroBuilder &Builder) const { |
| 2957 | DefineStd(Builder, "mips", Opts); |
| 2958 | Builder.defineMacro("_mips"); |
| 2959 | DefineStd(Builder, "MIPSEB", Opts); |
| 2960 | Builder.defineMacro("_MIPSEB"); |
| 2961 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 2962 | getArchDefines(Opts, Builder); |
| 2963 | } |
| 2964 | }; |
| 2965 | |
| 2966 | class Mips64ELTargetInfo : public Mips64TargetInfoBase { |
| 2967 | virtual void SetDescriptionString(const std::string &Name) { |
| 2968 | // Change DescriptionString only if ABI is n32. |
| 2969 | if (Name == "n32") |
| 2970 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2971 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2972 | } |
| 2973 | public: |
| 2974 | Mips64ELTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) { |
| 2975 | // Default ABI is n64. |
| 2976 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 2977 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 2978 | } |
| 2979 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2980 | MacroBuilder &Builder) const { |
| 2981 | DefineStd(Builder, "mips", Opts); |
| 2982 | Builder.defineMacro("_mips"); |
| 2983 | DefineStd(Builder, "MIPSEL", Opts); |
| 2984 | Builder.defineMacro("_MIPSEL"); |
| 2985 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 2986 | getArchDefines(Opts, Builder); |
| 2987 | } |
| 2988 | }; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 2989 | } // end anonymous namespace. |
| 2990 | |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 2991 | namespace { |
| 2992 | class PNaClTargetInfo : public TargetInfo { |
| 2993 | public: |
| 2994 | PNaClTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 2995 | this->UserLabelPrefix = ""; |
| 2996 | this->LongAlign = 32; |
| 2997 | this->LongWidth = 32; |
| 2998 | this->PointerAlign = 32; |
| 2999 | this->PointerWidth = 32; |
| 3000 | this->IntMaxType = TargetInfo::SignedLongLong; |
| 3001 | this->UIntMaxType = TargetInfo::UnsignedLongLong; |
| 3002 | this->Int64Type = TargetInfo::SignedLongLong; |
Ivan Krasin | f619cdc | 2011-08-29 22:39:12 +0000 | [diff] [blame] | 3003 | this->DoubleAlign = 64; |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3004 | this->LongDoubleWidth = 64; |
Ivan Krasin | f619cdc | 2011-08-29 22:39:12 +0000 | [diff] [blame] | 3005 | this->LongDoubleAlign = 64; |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3006 | this->SizeType = TargetInfo::UnsignedInt; |
| 3007 | this->PtrDiffType = TargetInfo::SignedInt; |
| 3008 | this->IntPtrType = TargetInfo::SignedInt; |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3009 | DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
| 3010 | "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"; |
| 3011 | } |
| 3012 | |
| 3013 | void getDefaultFeatures(const std::string &CPU, |
| 3014 | llvm::StringMap<bool> &Features) const { |
| 3015 | } |
| 3016 | virtual void getArchDefines(const LangOptions &Opts, |
| 3017 | MacroBuilder &Builder) const { |
| 3018 | Builder.defineMacro("__le32__"); |
| 3019 | Builder.defineMacro("__pnacl__"); |
| 3020 | } |
| 3021 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3022 | MacroBuilder &Builder) const { |
Ivan Krasin | 089ee11 | 2011-08-25 23:49:20 +0000 | [diff] [blame] | 3023 | DefineStd(Builder, "unix", Opts); |
| 3024 | Builder.defineMacro("__ELF__"); |
| 3025 | if (Opts.POSIXThreads) |
| 3026 | Builder.defineMacro("_REENTRANT"); |
| 3027 | if (Opts.CPlusPlus) |
| 3028 | Builder.defineMacro("_GNU_SOURCE"); |
| 3029 | |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3030 | Builder.defineMacro("__native_client__"); |
| 3031 | getArchDefines(Opts, Builder); |
| 3032 | } |
| 3033 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3034 | unsigned &NumRecords) const { |
| 3035 | } |
| 3036 | virtual const char *getVAListDeclaration() const { |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3037 | return "typedef int __builtin_va_list[4];"; |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3038 | } |
| 3039 | virtual void getGCCRegNames(const char * const *&Names, |
| 3040 | unsigned &NumNames) const; |
| 3041 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3042 | unsigned &NumAliases) const; |
| 3043 | virtual bool validateAsmConstraint(const char *&Name, |
| 3044 | TargetInfo::ConstraintInfo &Info) const { |
| 3045 | return false; |
| 3046 | } |
| 3047 | |
| 3048 | virtual const char *getClobbers() const { |
| 3049 | return ""; |
| 3050 | } |
| 3051 | }; |
| 3052 | |
| 3053 | void PNaClTargetInfo::getGCCRegNames(const char * const *&Names, |
| 3054 | unsigned &NumNames) const { |
| 3055 | Names = NULL; |
| 3056 | NumNames = 0; |
| 3057 | } |
| 3058 | |
| 3059 | void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3060 | unsigned &NumAliases) const { |
| 3061 | Aliases = NULL; |
| 3062 | NumAliases = 0; |
| 3063 | } |
| 3064 | } // end anonymous namespace. |
| 3065 | |
| 3066 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3067 | //===----------------------------------------------------------------------===// |
| 3068 | // Driver code |
| 3069 | //===----------------------------------------------------------------------===// |
| 3070 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3071 | static TargetInfo *AllocateTarget(const std::string &T) { |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3072 | llvm::Triple Triple(T); |
| 3073 | llvm::Triple::OSType os = Triple.getOS(); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3074 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3075 | switch (Triple.getArch()) { |
| 3076 | default: |
| 3077 | return NULL; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3078 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3079 | case llvm::Triple::arm: |
Daniel Dunbar | f4aa4f61 | 2009-09-11 01:14:50 +0000 | [diff] [blame] | 3080 | case llvm::Triple::thumb: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3081 | if (Triple.isOSDarwin()) |
| 3082 | return new DarwinARMTargetInfo(T); |
| 3083 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3084 | switch (os) { |
Rafael Espindola | 022a8a5 | 2010-06-10 00:46:51 +0000 | [diff] [blame] | 3085 | case llvm::Triple::Linux: |
| 3086 | return new LinuxTargetInfo<ARMTargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3087 | case llvm::Triple::FreeBSD: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 3088 | return new FreeBSDTargetInfo<ARMTargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3089 | case llvm::Triple::NetBSD: |
| 3090 | return new NetBSDTargetInfo<ARMTargetInfo>(T); |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 3091 | case llvm::Triple::RTEMS: |
| 3092 | return new RTEMSTargetInfo<ARMTargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3093 | default: |
| 3094 | return new ARMTargetInfo(T); |
| 3095 | } |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3096 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3097 | case llvm::Triple::bfin: |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 3098 | if ( os == llvm::Triple::RTEMS ) |
| 3099 | return new RTEMSTargetInfo<BlackfinTargetInfo>(T); |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 3100 | return new BlackfinTargetInfo(T); |
| 3101 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3102 | case llvm::Triple::msp430: |
| 3103 | return new MSP430TargetInfo(T); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3104 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3105 | case llvm::Triple::mips: |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3106 | switch (os) { |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3107 | case llvm::Triple::Linux: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3108 | return new LinuxTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3109 | case llvm::Triple::RTEMS: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3110 | return new RTEMSTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3111 | case llvm::Triple::FreeBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3112 | return new FreeBSDTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3113 | case llvm::Triple::NetBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3114 | return new NetBSDTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3115 | default: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3116 | return new Mips32EBTargetInfo(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 3117 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3118 | |
| 3119 | case llvm::Triple::mipsel: |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3120 | switch (os) { |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3121 | case llvm::Triple::Linux: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3122 | return new LinuxTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3123 | case llvm::Triple::RTEMS: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3124 | return new RTEMSTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3125 | case llvm::Triple::FreeBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3126 | return new FreeBSDTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3127 | case llvm::Triple::NetBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3128 | return new NetBSDTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3129 | default: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3130 | return new Mips32ELTargetInfo(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 3131 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3132 | |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3133 | case llvm::Triple::mips64: |
| 3134 | switch (os) { |
| 3135 | case llvm::Triple::Linux: |
| 3136 | return new LinuxTargetInfo<Mips64EBTargetInfo>(T); |
| 3137 | case llvm::Triple::RTEMS: |
| 3138 | return new RTEMSTargetInfo<Mips64EBTargetInfo>(T); |
| 3139 | case llvm::Triple::FreeBSD: |
| 3140 | return new FreeBSDTargetInfo<Mips64EBTargetInfo>(T); |
| 3141 | case llvm::Triple::NetBSD: |
| 3142 | return new NetBSDTargetInfo<Mips64EBTargetInfo>(T); |
| 3143 | default: |
| 3144 | return new Mips64EBTargetInfo(T); |
| 3145 | } |
| 3146 | |
| 3147 | case llvm::Triple::mips64el: |
| 3148 | switch (os) { |
| 3149 | case llvm::Triple::Linux: |
| 3150 | return new LinuxTargetInfo<Mips64ELTargetInfo>(T); |
| 3151 | case llvm::Triple::RTEMS: |
| 3152 | return new RTEMSTargetInfo<Mips64ELTargetInfo>(T); |
| 3153 | case llvm::Triple::FreeBSD: |
| 3154 | return new FreeBSDTargetInfo<Mips64ELTargetInfo>(T); |
| 3155 | case llvm::Triple::NetBSD: |
| 3156 | return new NetBSDTargetInfo<Mips64ELTargetInfo>(T); |
| 3157 | default: |
| 3158 | return new Mips64ELTargetInfo(T); |
| 3159 | } |
| 3160 | |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3161 | case llvm::Triple::le32: |
| 3162 | switch (os) { |
| 3163 | case llvm::Triple::NativeClient: |
| 3164 | return new PNaClTargetInfo(T); |
| 3165 | default: |
| 3166 | return NULL; |
| 3167 | } |
| 3168 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3169 | case llvm::Triple::ppc: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3170 | if (Triple.isOSDarwin()) |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 3171 | return new DarwinPPC32TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3172 | switch (os) { |
| 3173 | case llvm::Triple::FreeBSD: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 3174 | return new FreeBSDTargetInfo<PPC32TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3175 | case llvm::Triple::NetBSD: |
| 3176 | return new NetBSDTargetInfo<PPC32TargetInfo>(T); |
| 3177 | case llvm::Triple::RTEMS: |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 3178 | return new RTEMSTargetInfo<PPC32TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3179 | default: |
| 3180 | return new PPC32TargetInfo(T); |
| 3181 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3182 | |
| 3183 | case llvm::Triple::ppc64: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3184 | if (Triple.isOSDarwin()) |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 3185 | return new DarwinPPC64TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3186 | switch (os) { |
| 3187 | case llvm::Triple::Lv2: |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 3188 | return new PS3PPUTargetInfo<PPC64TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3189 | case llvm::Triple::FreeBSD: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 3190 | return new FreeBSDTargetInfo<PPC64TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3191 | case llvm::Triple::NetBSD: |
| 3192 | return new NetBSDTargetInfo<PPC64TargetInfo>(T); |
| 3193 | default: |
| 3194 | return new PPC64TargetInfo(T); |
| 3195 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3196 | |
Justin Holewinski | 285dc65 | 2011-04-20 19:34:15 +0000 | [diff] [blame] | 3197 | case llvm::Triple::ptx32: |
| 3198 | return new PTX32TargetInfo(T); |
| 3199 | case llvm::Triple::ptx64: |
| 3200 | return new PTX64TargetInfo(T); |
| 3201 | |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 3202 | case llvm::Triple::mblaze: |
| 3203 | return new MBlazeTargetInfo(T); |
| 3204 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3205 | case llvm::Triple::sparc: |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3206 | switch (os) { |
| 3207 | case llvm::Triple::AuroraUX: |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 3208 | return new AuroraUXSparcV8TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3209 | case llvm::Triple::Solaris: |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3210 | return new SolarisSparcV8TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3211 | case llvm::Triple::NetBSD: |
| 3212 | return new NetBSDTargetInfo<SparcV8TargetInfo>(T); |
| 3213 | case llvm::Triple::RTEMS: |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 3214 | return new RTEMSTargetInfo<SparcV8TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 3215 | default: |
| 3216 | return new SparcV8TargetInfo(T); |
| 3217 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3218 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 3219 | // FIXME: Need a real SPU target. |
| 3220 | case llvm::Triple::cellspu: |
| 3221 | return new PS3SPUTargetInfo<PPC64TargetInfo>(T); |
| 3222 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3223 | case llvm::Triple::systemz: |
| 3224 | return new SystemZTargetInfo(T); |
| 3225 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3226 | case llvm::Triple::tce: |
| 3227 | return new TCETargetInfo(T); |
| 3228 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3229 | case llvm::Triple::x86: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3230 | if (Triple.isOSDarwin()) |
| 3231 | return new DarwinI386TargetInfo(T); |
| 3232 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3233 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 3234 | case llvm::Triple::AuroraUX: |
| 3235 | return new AuroraUXTargetInfo<X86_32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3236 | case llvm::Triple::Linux: |
| 3237 | return new LinuxTargetInfo<X86_32TargetInfo>(T); |
| 3238 | case llvm::Triple::DragonFly: |
| 3239 | return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); |
| 3240 | case llvm::Triple::NetBSD: |
| 3241 | return new NetBSDTargetInfo<X86_32TargetInfo>(T); |
| 3242 | case llvm::Triple::OpenBSD: |
| 3243 | return new OpenBSDI386TargetInfo(T); |
| 3244 | case llvm::Triple::FreeBSD: |
| 3245 | return new FreeBSDTargetInfo<X86_32TargetInfo>(T); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3246 | case llvm::Triple::Minix: |
| 3247 | return new MinixTargetInfo<X86_32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3248 | case llvm::Triple::Solaris: |
| 3249 | return new SolarisTargetInfo<X86_32TargetInfo>(T); |
| 3250 | case llvm::Triple::Cygwin: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 3251 | return new CygwinX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3252 | case llvm::Triple::MinGW32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 3253 | return new MinGWX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3254 | case llvm::Triple::Win32: |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 3255 | return new VisualStudioWindowsX86_32TargetInfo(T); |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 3256 | case llvm::Triple::Haiku: |
| 3257 | return new HaikuX86_32TargetInfo(T); |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 3258 | case llvm::Triple::RTEMS: |
| 3259 | return new RTEMSX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3260 | default: |
| 3261 | return new X86_32TargetInfo(T); |
| 3262 | } |
| 3263 | |
| 3264 | case llvm::Triple::x86_64: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3265 | if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO) |
| 3266 | return new DarwinX86_64TargetInfo(T); |
| 3267 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3268 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 3269 | case llvm::Triple::AuroraUX: |
| 3270 | return new AuroraUXTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3271 | case llvm::Triple::Linux: |
| 3272 | return new LinuxTargetInfo<X86_64TargetInfo>(T); |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 3273 | case llvm::Triple::DragonFly: |
| 3274 | return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3275 | case llvm::Triple::NetBSD: |
| 3276 | return new NetBSDTargetInfo<X86_64TargetInfo>(T); |
| 3277 | case llvm::Triple::OpenBSD: |
| 3278 | return new OpenBSDX86_64TargetInfo(T); |
| 3279 | case llvm::Triple::FreeBSD: |
| 3280 | return new FreeBSDTargetInfo<X86_64TargetInfo>(T); |
| 3281 | case llvm::Triple::Solaris: |
| 3282 | return new SolarisTargetInfo<X86_64TargetInfo>(T); |
NAKAMURA Takumi | 0aa2057 | 2011-02-17 08:51:38 +0000 | [diff] [blame] | 3283 | case llvm::Triple::MinGW32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 3284 | return new MinGWX86_64TargetInfo(T); |
| 3285 | case llvm::Triple::Win32: // This is what Triple.h supports now. |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3286 | return new VisualStudioWindowsX86_64TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3287 | default: |
| 3288 | return new X86_64TargetInfo(T); |
| 3289 | } |
| 3290 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3291 | } |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3292 | |
| 3293 | /// CreateTargetInfo - Return the target info object for the specified target |
| 3294 | /// triple. |
| 3295 | TargetInfo *TargetInfo::CreateTargetInfo(Diagnostic &Diags, |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 3296 | TargetOptions &Opts) { |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3297 | llvm::Triple Triple(Opts.Triple); |
| 3298 | |
| 3299 | // Construct the target |
| 3300 | llvm::OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str())); |
| 3301 | if (!Target) { |
| 3302 | Diags.Report(diag::err_target_unknown_triple) << Triple.str(); |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 3306 | // Set the target CPU if specified. |
| 3307 | if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) { |
| 3308 | Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU; |
| 3309 | return 0; |
| 3310 | } |
| 3311 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3312 | // Set the target ABI if specified. |
| 3313 | if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) { |
| 3314 | Diags.Report(diag::err_target_unknown_abi) << Opts.ABI; |
| 3315 | return 0; |
| 3316 | } |
| 3317 | |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 3318 | // Set the target C++ ABI. |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 3319 | if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) { |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 3320 | Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI; |
| 3321 | return 0; |
| 3322 | } |
| 3323 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3324 | // Compute the default target features, we need the target to handle this |
| 3325 | // because features may have dependencies on one another. |
| 3326 | llvm::StringMap<bool> Features; |
| 3327 | Target->getDefaultFeatures(Opts.CPU, Features); |
| 3328 | |
| 3329 | // Apply the user specified deltas. |
| 3330 | for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), |
| 3331 | ie = Opts.Features.end(); it != ie; ++it) { |
| 3332 | const char *Name = it->c_str(); |
| 3333 | |
| 3334 | // Apply the feature via the target. |
| 3335 | if ((Name[0] != '-' && Name[0] != '+') || |
| 3336 | !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) { |
| 3337 | Diags.Report(diag::err_target_invalid_feature) << Name; |
| 3338 | return 0; |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | // Add the features to the compile options. |
| 3343 | // |
| 3344 | // FIXME: If we are completely confident that we have the right set, we only |
| 3345 | // need to pass the minuses. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 3346 | Opts.Features.clear(); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3347 | for (llvm::StringMap<bool>::const_iterator it = Features.begin(), |
| 3348 | ie = Features.end(); it != ie; ++it) |
Chris Lattner | 1e5f83b | 2011-07-14 18:24:21 +0000 | [diff] [blame] | 3349 | Opts.Features.push_back(std::string(it->second ? "+" : "-") + |
Chris Lattner | 48b78bd | 2011-07-14 18:45:41 +0000 | [diff] [blame] | 3350 | it->first().str()); |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 3351 | Target->HandleTargetFeatures(Opts.Features); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3352 | |
| 3353 | return Target.take(); |
| 3354 | } |