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" |
David Blaikie | 9fe8c74 | 2011-09-23 05:35:21 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Dale Johannesen | 1e592cb | 2010-10-29 23:24:33 +0000 | [diff] [blame] | 30 | #include "llvm/Type.h" |
Benjamin Kramer | 4872508 | 2010-01-09 18:20:57 +0000 | [diff] [blame] | 31 | #include <algorithm> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Common code shared among targets. |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 38 | /// DefineStd - Define a macro name and standard variants. For example if |
| 39 | /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix" |
| 40 | /// when in GNU mode. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 41 | static void DefineStd(MacroBuilder &Builder, StringRef MacroName, |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 42 | const LangOptions &Opts) { |
| 43 | assert(MacroName[0] != '_' && "Identifier should be in the user's namespace"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 44 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 45 | // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier |
| 46 | // in the user's namespace. |
| 47 | if (Opts.GNUMode) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 48 | Builder.defineMacro(MacroName); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 49 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 50 | // Define __unix. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 51 | Builder.defineMacro("__" + MacroName); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 52 | |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 53 | // Define __unix__. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 54 | Builder.defineMacro("__" + MacroName + "__"); |
Chris Lattner | ca45cff | 2009-03-20 16:06:38 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 57 | static void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName, |
| 58 | bool Tuning = true) { |
| 59 | Builder.defineMacro("__" + CPUName); |
| 60 | Builder.defineMacro("__" + CPUName + "__"); |
| 61 | if (Tuning) |
| 62 | Builder.defineMacro("__tune_" + CPUName + "__"); |
| 63 | } |
| 64 | |
Chris Lattner | d29b630 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 65 | //===----------------------------------------------------------------------===// |
| 66 | // Defines specific to certain operating systems. |
| 67 | //===----------------------------------------------------------------------===// |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 68 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 69 | namespace { |
Douglas Gregor | a384492 | 2009-07-01 15:12:53 +0000 | [diff] [blame] | 70 | template<typename TgtInfo> |
| 71 | class OSTargetInfo : public TgtInfo { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 72 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 73 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 74 | MacroBuilder &Builder) const=0; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 75 | public: |
Douglas Gregor | a384492 | 2009-07-01 15:12:53 +0000 | [diff] [blame] | 76 | OSTargetInfo(const std::string& triple) : TgtInfo(triple) {} |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 77 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 78 | MacroBuilder &Builder) const { |
| 79 | TgtInfo::getTargetDefines(Opts, Builder); |
| 80 | getOSDefines(Opts, TgtInfo::getTriple(), Builder); |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 81 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 82 | |
| 83 | }; |
Chris Lattner | 4c28b1c | 2009-08-12 06:24:27 +0000 | [diff] [blame] | 84 | } // end anonymous namespace |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 85 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 86 | |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 87 | static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 88 | const llvm::Triple &Triple, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 89 | StringRef &PlatformName, |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 90 | VersionTuple &PlatformMinVersion) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 91 | Builder.defineMacro("__APPLE_CC__", "5621"); |
| 92 | Builder.defineMacro("__APPLE__"); |
| 93 | Builder.defineMacro("__MACH__"); |
| 94 | Builder.defineMacro("OBJC_NEW_PROPERTIES"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 95 | |
John McCall | 098df7f | 2011-06-16 00:03:19 +0000 | [diff] [blame] | 96 | if (!Opts.ObjCAutoRefCount) { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 97 | // __weak is always defined, for use in blocks and with objc pointers. |
| 98 | Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 99 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 100 | // Darwin defines __strong even in C mode (just to nothing). |
Douglas Gregor | e289d81 | 2011-09-13 17:21:33 +0000 | [diff] [blame] | 101 | if (Opts.getGC() != LangOptions::NonGC) |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 102 | Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))"); |
| 103 | else |
| 104 | Builder.defineMacro("__strong", ""); |
Eric Christopher | 7c9adf9 | 2011-07-07 22:55:26 +0000 | [diff] [blame] | 105 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 106 | // __unsafe_unretained is defined to nothing in non-ARC mode. We even |
| 107 | // allow this in C, since one might have block pointers in structs that |
| 108 | // are used in pure C code and in Objective-C ARC. |
| 109 | Builder.defineMacro("__unsafe_unretained", ""); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 110 | } |
Eric Christopher | 7c9adf9 | 2011-07-07 22:55:26 +0000 | [diff] [blame] | 111 | |
Eli Friedman | 2de4fee | 2009-06-04 23:00:29 +0000 | [diff] [blame] | 112 | if (Opts.Static) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 113 | Builder.defineMacro("__STATIC__"); |
Eli Friedman | 2de4fee | 2009-06-04 23:00:29 +0000 | [diff] [blame] | 114 | else |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 115 | Builder.defineMacro("__DYNAMIC__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 116 | |
| 117 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 118 | Builder.defineMacro("_REENTRANT"); |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 119 | |
Daniel Dunbar | 0d027ba | 2011-04-19 21:40:34 +0000 | [diff] [blame] | 120 | // Get the platform type and version number from the triple. |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 121 | unsigned Maj, Min, Rev; |
Bob Wilson | 48b68a0 | 2012-01-31 23:52:58 +0000 | [diff] [blame] | 122 | if (Triple.isMacOSX()) { |
| 123 | Triple.getMacOSXVersion(Maj, Min, Rev); |
Daniel Dunbar | 0d027ba | 2011-04-19 21:40:34 +0000 | [diff] [blame] | 124 | PlatformName = "macosx"; |
Daniel Dunbar | 0d027ba | 2011-04-19 21:40:34 +0000 | [diff] [blame] | 125 | } else { |
Bob Wilson | 48b68a0 | 2012-01-31 23:52:58 +0000 | [diff] [blame] | 126 | Triple.getOSVersion(Maj, Min, Rev); |
| 127 | PlatformName = llvm::Triple::getOSTypeName(Triple.getOS()); |
Daniel Dunbar | 0d027ba | 2011-04-19 21:40:34 +0000 | [diff] [blame] | 128 | } |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 129 | |
Sebastian Pop | 9ec60df | 2012-01-20 22:01:23 +0000 | [diff] [blame] | 130 | // If -target arch-pc-win32-macho option specified, we're |
Eric Christopher | 895d422 | 2011-07-29 21:20:35 +0000 | [diff] [blame] | 131 | // generating code for Win32 ABI. No need to emit |
Chad Rosier | d9259f3 | 2011-07-19 20:00:06 +0000 | [diff] [blame] | 132 | // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__. |
| 133 | if (PlatformName == "win32") { |
| 134 | PlatformMinVersion = VersionTuple(Maj, Min, Rev); |
| 135 | return; |
| 136 | } |
| 137 | |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 138 | // Set the appropriate OS version define. |
Bob Wilson | 48b68a0 | 2012-01-31 23:52:58 +0000 | [diff] [blame] | 139 | if (Triple.getOS() == llvm::Triple::IOS) { |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 140 | assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!"); |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 141 | char Str[6]; |
| 142 | Str[0] = '0' + Maj; |
| 143 | Str[1] = '0' + (Min / 10); |
| 144 | Str[2] = '0' + (Min % 10); |
| 145 | Str[3] = '0' + (Rev / 10); |
| 146 | Str[4] = '0' + (Rev % 10); |
| 147 | Str[5] = '\0'; |
| 148 | Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str); |
| 149 | } else { |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 150 | // Note that the Driver allows versions which aren't representable in the |
| 151 | // define (because we only get a single digit for the minor and micro |
| 152 | // revision numbers). So, we limit them to the maximum representable |
| 153 | // version. |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 154 | assert(Triple.getEnvironmentName().empty() && "Invalid environment!"); |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 155 | assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!"); |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 156 | char Str[5]; |
| 157 | Str[0] = '0' + (Maj / 10); |
| 158 | Str[1] = '0' + (Maj % 10); |
Daniel Dunbar | 8a3a7f3 | 2011-04-21 21:27:33 +0000 | [diff] [blame] | 159 | Str[2] = '0' + std::min(Min, 9U); |
| 160 | Str[3] = '0' + std::min(Rev, 9U); |
Daniel Dunbar | 21ae319 | 2010-01-26 01:44:04 +0000 | [diff] [blame] | 161 | Str[4] = '\0'; |
| 162 | Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str); |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 163 | } |
Daniel Dunbar | 0d027ba | 2011-04-19 21:40:34 +0000 | [diff] [blame] | 164 | |
| 165 | PlatformMinVersion = VersionTuple(Maj, Min, Rev); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 166 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 167 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 168 | namespace { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 169 | template<typename Target> |
| 170 | class DarwinTargetInfo : public OSTargetInfo<Target> { |
| 171 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 172 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 173 | MacroBuilder &Builder) const { |
Eric Christopher | 7c9adf9 | 2011-07-07 22:55:26 +0000 | [diff] [blame] | 174 | getDarwinDefines(Builder, Opts, Triple, this->PlatformName, |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 175 | this->PlatformMinVersion); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 178 | public: |
| 179 | DarwinTargetInfo(const std::string& triple) : |
| 180 | OSTargetInfo<Target>(triple) { |
Eric Christopher | aa7333c | 2011-07-02 00:20:22 +0000 | [diff] [blame] | 181 | llvm::Triple T = llvm::Triple(triple); |
| 182 | this->TLSSupported = T.isMacOSX() && !T.isMacOSXVersionLT(10,7); |
Daniel Dunbar | e177d3b | 2011-02-21 23:12:51 +0000 | [diff] [blame] | 183 | this->MCountName = "\01mcount"; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 186 | virtual std::string isValidSectionSpecifier(StringRef SR) const { |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 187 | // Let MCSectionMachO validate this. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 188 | StringRef Segment, Section; |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 189 | unsigned TAA, StubSize; |
Daniel Dunbar | 9ae186f | 2011-03-19 02:06:21 +0000 | [diff] [blame] | 190 | bool HasTAA; |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 191 | return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section, |
Daniel Dunbar | 9ae186f | 2011-03-19 02:06:21 +0000 | [diff] [blame] | 192 | TAA, HasTAA, StubSize); |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 193 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 194 | |
Anders Carlsson | 18af368 | 2010-06-08 22:47:50 +0000 | [diff] [blame] | 195 | virtual const char *getStaticInitSectionSpecifier() const { |
| 196 | // FIXME: We should return 0 when building kexts. |
| 197 | return "__TEXT,__StaticInit,regular,pure_instructions"; |
| 198 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 199 | |
John McCall | 4188760 | 2012-01-29 01:20:30 +0000 | [diff] [blame] | 200 | /// Darwin does not support protected visibility. Darwin's "default" |
| 201 | /// is very similar to ELF's "protected"; Darwin requires a "weak" |
| 202 | /// attribute on declarations that can be dynamically replaced. |
| 203 | virtual bool hasProtectedVisibility() const { |
| 204 | return false; |
| 205 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
Chris Lattner | 797c3c4 | 2009-08-10 19:03:04 +0000 | [diff] [blame] | 208 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 209 | // DragonFlyBSD Target |
| 210 | template<typename Target> |
| 211 | class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> { |
| 212 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 213 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 214 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 215 | // DragonFly defines; list based off of gcc output |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 216 | Builder.defineMacro("__DragonFly__"); |
| 217 | Builder.defineMacro("__DragonFly_cc_version", "100001"); |
| 218 | Builder.defineMacro("__ELF__"); |
| 219 | Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); |
| 220 | Builder.defineMacro("__tune_i386__"); |
| 221 | DefineStd(Builder, "unix", Opts); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 222 | } |
| 223 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | DragonFlyBSDTargetInfo(const std::string &triple) |
Eli Friedman | b089c4d | 2012-02-10 23:02:29 +0000 | [diff] [blame] | 225 | : OSTargetInfo<Target>(triple) { |
| 226 | this->UserLabelPrefix = ""; |
| 227 | |
| 228 | llvm::Triple Triple(triple); |
| 229 | switch (Triple.getArch()) { |
| 230 | default: |
| 231 | case llvm::Triple::x86: |
| 232 | case llvm::Triple::x86_64: |
| 233 | this->MCountName = ".mcount"; |
| 234 | break; |
| 235 | } |
| 236 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | // FreeBSD Target |
| 240 | template<typename Target> |
| 241 | class FreeBSDTargetInfo : public OSTargetInfo<Target> { |
| 242 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 243 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 244 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 245 | // FreeBSD defines; list based off of gcc output |
| 246 | |
Benjamin Kramer | 474202f | 2011-10-18 10:10:08 +0000 | [diff] [blame] | 247 | unsigned Release = Triple.getOSMajorVersion(); |
| 248 | if (Release == 0U) |
| 249 | Release = 8; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 250 | |
Benjamin Kramer | 474202f | 2011-10-18 10:10:08 +0000 | [diff] [blame] | 251 | Builder.defineMacro("__FreeBSD__", Twine(Release)); |
| 252 | Builder.defineMacro("__FreeBSD_cc_version", Twine(Release * 100000U + 1U)); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 253 | Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); |
| 254 | DefineStd(Builder, "unix", Opts); |
| 255 | Builder.defineMacro("__ELF__"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 256 | } |
| 257 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | FreeBSDTargetInfo(const std::string &triple) |
Duncan Sands | 1e90faf | 2009-07-08 13:55:08 +0000 | [diff] [blame] | 259 | : OSTargetInfo<Target>(triple) { |
| 260 | this->UserLabelPrefix = ""; |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 261 | |
| 262 | llvm::Triple Triple(triple); |
| 263 | switch (Triple.getArch()) { |
| 264 | default: |
| 265 | case llvm::Triple::x86: |
| 266 | case llvm::Triple::x86_64: |
| 267 | this->MCountName = ".mcount"; |
| 268 | break; |
| 269 | case llvm::Triple::mips: |
| 270 | case llvm::Triple::mipsel: |
| 271 | case llvm::Triple::ppc: |
| 272 | case llvm::Triple::ppc64: |
| 273 | this->MCountName = "_mcount"; |
| 274 | break; |
| 275 | case llvm::Triple::arm: |
| 276 | this->MCountName = "__mcount"; |
| 277 | break; |
| 278 | } |
| 279 | |
Duncan Sands | 1e90faf | 2009-07-08 13:55:08 +0000 | [diff] [blame] | 280 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 283 | // Minix Target |
| 284 | template<typename Target> |
| 285 | class MinixTargetInfo : public OSTargetInfo<Target> { |
| 286 | protected: |
| 287 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 288 | MacroBuilder &Builder) const { |
| 289 | // Minix defines |
| 290 | |
| 291 | Builder.defineMacro("__minix", "3"); |
| 292 | Builder.defineMacro("_EM_WSIZE", "4"); |
| 293 | Builder.defineMacro("_EM_PSIZE", "4"); |
| 294 | Builder.defineMacro("_EM_SSIZE", "2"); |
| 295 | Builder.defineMacro("_EM_LSIZE", "4"); |
| 296 | Builder.defineMacro("_EM_FSIZE", "4"); |
| 297 | Builder.defineMacro("_EM_DSIZE", "8"); |
Eli Friedman | 6d402dc | 2011-12-08 23:54:21 +0000 | [diff] [blame] | 298 | Builder.defineMacro("__ELF__"); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 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__"); |
Evgeniy Stepanov | 3206403 | 2012-04-26 12:08:09 +0000 | [diff] [blame] | 319 | if (Triple.getEnvironment() == llvm::Triple::ANDROIDEABI) |
| 320 | Builder.defineMacro("__ANDROID__", "1"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 321 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 322 | Builder.defineMacro("_REENTRANT"); |
Douglas Gregor | 2b003fd | 2010-04-21 05:52:38 +0000 | [diff] [blame] | 323 | if (Opts.CPlusPlus) |
| 324 | Builder.defineMacro("_GNU_SOURCE"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 325 | } |
| 326 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | LinuxTargetInfo(const std::string& triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 328 | : OSTargetInfo<Target>(triple) { |
| 329 | this->UserLabelPrefix = ""; |
Douglas Gregor | 12e8464 | 2011-01-12 21:19:25 +0000 | [diff] [blame] | 330 | this->WIntType = TargetInfo::UnsignedInt; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 331 | } |
Benjamin Kramer | 86d18c5 | 2011-10-15 17:53:33 +0000 | [diff] [blame] | 332 | |
| 333 | virtual const char *getStaticInitSectionSpecifier() const { |
| 334 | return ".text.startup"; |
| 335 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 338 | // NetBSD Target |
| 339 | template<typename Target> |
| 340 | class NetBSDTargetInfo : public OSTargetInfo<Target> { |
| 341 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 342 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 343 | MacroBuilder &Builder) const { |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 344 | // NetBSD defines; list based off of gcc output |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 345 | Builder.defineMacro("__NetBSD__"); |
| 346 | Builder.defineMacro("__unix__"); |
| 347 | Builder.defineMacro("__ELF__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 348 | if (Opts.POSIXThreads) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 349 | Builder.defineMacro("_POSIX_THREADS"); |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 350 | } |
| 351 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | NetBSDTargetInfo(const std::string &triple) |
Chris Lattner | b62bb28 | 2009-07-13 20:29:08 +0000 | [diff] [blame] | 353 | : OSTargetInfo<Target>(triple) { |
| 354 | this->UserLabelPrefix = ""; |
| 355 | } |
| 356 | }; |
| 357 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 358 | // OpenBSD Target |
| 359 | template<typename Target> |
| 360 | class OpenBSDTargetInfo : public OSTargetInfo<Target> { |
| 361 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 362 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 363 | MacroBuilder &Builder) const { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 364 | // OpenBSD defines; list based off of gcc output |
| 365 | |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 366 | Builder.defineMacro("__OpenBSD__"); |
| 367 | DefineStd(Builder, "unix", Opts); |
| 368 | Builder.defineMacro("__ELF__"); |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 369 | if (Opts.POSIXThreads) |
Chris Lattner | 4ddcf3b | 2012-04-25 06:12:24 +0000 | [diff] [blame] | 370 | Builder.defineMacro("_REENTRANT"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 371 | } |
| 372 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | OpenBSDTargetInfo(const std::string &triple) |
Eli Friedman | 62d829a | 2011-12-15 02:15:56 +0000 | [diff] [blame] | 374 | : OSTargetInfo<Target>(triple) { |
| 375 | this->UserLabelPrefix = ""; |
| 376 | |
| 377 | llvm::Triple Triple(triple); |
| 378 | switch (Triple.getArch()) { |
| 379 | default: |
| 380 | case llvm::Triple::x86: |
| 381 | case llvm::Triple::x86_64: |
| 382 | case llvm::Triple::arm: |
| 383 | case llvm::Triple::sparc: |
| 384 | this->MCountName = "__mcount"; |
| 385 | break; |
| 386 | case llvm::Triple::mips64: |
| 387 | case llvm::Triple::mips64el: |
| 388 | case llvm::Triple::ppc: |
| 389 | case llvm::Triple::sparcv9: |
| 390 | this->MCountName = "_mcount"; |
| 391 | break; |
| 392 | } |
| 393 | } |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 394 | }; |
| 395 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 396 | // PSP Target |
| 397 | template<typename Target> |
| 398 | class PSPTargetInfo : public OSTargetInfo<Target> { |
| 399 | protected: |
| 400 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 401 | MacroBuilder &Builder) const { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 402 | // PSP defines; list based on the output of the pspdev gcc toolchain. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 403 | Builder.defineMacro("PSP"); |
| 404 | Builder.defineMacro("_PSP"); |
| 405 | Builder.defineMacro("__psp__"); |
| 406 | Builder.defineMacro("__ELF__"); |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 407 | } |
| 408 | public: |
| 409 | PSPTargetInfo(const std::string& triple) |
| 410 | : OSTargetInfo<Target>(triple) { |
| 411 | this->UserLabelPrefix = ""; |
| 412 | } |
| 413 | }; |
| 414 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 415 | // PS3 PPU Target |
| 416 | template<typename Target> |
| 417 | class PS3PPUTargetInfo : public OSTargetInfo<Target> { |
| 418 | protected: |
| 419 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 420 | MacroBuilder &Builder) const { |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 421 | // PS3 PPU defines. |
John Thompson | fb45797 | 2010-03-25 16:18:32 +0000 | [diff] [blame] | 422 | Builder.defineMacro("__PPC__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 423 | Builder.defineMacro("__PPU__"); |
| 424 | Builder.defineMacro("__CELLOS_LV2__"); |
| 425 | Builder.defineMacro("__ELF__"); |
| 426 | Builder.defineMacro("__LP32__"); |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 427 | Builder.defineMacro("_ARCH_PPC64"); |
| 428 | Builder.defineMacro("__powerpc64__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 429 | } |
| 430 | public: |
| 431 | PS3PPUTargetInfo(const std::string& triple) |
| 432 | : OSTargetInfo<Target>(triple) { |
| 433 | this->UserLabelPrefix = ""; |
Nick Lewycky | 9952070 | 2011-12-16 22:32:39 +0000 | [diff] [blame] | 434 | this->LongWidth = this->LongAlign = 32; |
| 435 | this->PointerWidth = this->PointerAlign = 32; |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 436 | this->IntMaxType = TargetInfo::SignedLongLong; |
| 437 | this->UIntMaxType = TargetInfo::UnsignedLongLong; |
| 438 | this->Int64Type = TargetInfo::SignedLongLong; |
John Thompson | ec387af | 2009-12-18 14:21:08 +0000 | [diff] [blame] | 439 | this->SizeType = TargetInfo::UnsignedInt; |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 440 | this->DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Nick Lewycky | 9952070 | 2011-12-16 22:32:39 +0000 | [diff] [blame] | 441 | "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] | 442 | } |
| 443 | }; |
| 444 | |
| 445 | // FIXME: Need a real SPU target. |
| 446 | // PS3 SPU Target |
| 447 | template<typename Target> |
| 448 | class PS3SPUTargetInfo : public OSTargetInfo<Target> { |
| 449 | protected: |
| 450 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 451 | MacroBuilder &Builder) const { |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 452 | // PS3 PPU defines. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 453 | Builder.defineMacro("__SPU__"); |
| 454 | Builder.defineMacro("__ELF__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 455 | } |
| 456 | public: |
| 457 | PS3SPUTargetInfo(const std::string& triple) |
| 458 | : OSTargetInfo<Target>(triple) { |
| 459 | this->UserLabelPrefix = ""; |
| 460 | } |
| 461 | }; |
| 462 | |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 463 | // AuroraUX target |
| 464 | template<typename Target> |
| 465 | class AuroraUXTargetInfo : public OSTargetInfo<Target> { |
| 466 | protected: |
| 467 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 468 | MacroBuilder &Builder) const { |
| 469 | DefineStd(Builder, "sun", Opts); |
| 470 | DefineStd(Builder, "unix", Opts); |
| 471 | Builder.defineMacro("__ELF__"); |
| 472 | Builder.defineMacro("__svr4__"); |
| 473 | Builder.defineMacro("__SVR4"); |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 474 | } |
| 475 | public: |
| 476 | AuroraUXTargetInfo(const std::string& triple) |
| 477 | : OSTargetInfo<Target>(triple) { |
| 478 | this->UserLabelPrefix = ""; |
| 479 | this->WCharType = this->SignedLong; |
| 480 | // FIXME: WIntType should be SignedLong |
| 481 | } |
| 482 | }; |
| 483 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 484 | // Solaris target |
| 485 | template<typename Target> |
| 486 | class SolarisTargetInfo : public OSTargetInfo<Target> { |
| 487 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 488 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 489 | MacroBuilder &Builder) const { |
| 490 | DefineStd(Builder, "sun", Opts); |
| 491 | DefineStd(Builder, "unix", Opts); |
| 492 | Builder.defineMacro("__ELF__"); |
| 493 | Builder.defineMacro("__svr4__"); |
| 494 | Builder.defineMacro("__SVR4"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 495 | // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and |
| 496 | // newer, but to 500 for everything else. feature_test.h has a check to |
| 497 | // ensure that you are not using C99 with an old version of X/Open or C89 |
| 498 | // with a new version. |
| 499 | if (Opts.C99 || Opts.C11) |
| 500 | Builder.defineMacro("_XOPEN_SOURCE", "600"); |
| 501 | else |
| 502 | Builder.defineMacro("_XOPEN_SOURCE", "500"); |
David Chisnall | b4f0bd6 | 2012-03-02 10:49:52 +0000 | [diff] [blame] | 503 | if (Opts.CPlusPlus) |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 504 | Builder.defineMacro("__C99FEATURES__"); |
David Chisnall | 48fad49 | 2012-02-17 18:35:11 +0000 | [diff] [blame] | 505 | Builder.defineMacro("_LARGEFILE_SOURCE"); |
| 506 | Builder.defineMacro("_LARGEFILE64_SOURCE"); |
| 507 | Builder.defineMacro("__EXTENSIONS__"); |
David Chisnall | 165329c | 2012-02-28 17:10:04 +0000 | [diff] [blame] | 508 | Builder.defineMacro("_REENTRANT"); |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 509 | } |
| 510 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | SolarisTargetInfo(const std::string& triple) |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 512 | : OSTargetInfo<Target>(triple) { |
| 513 | this->UserLabelPrefix = ""; |
David Chisnall | fb02784 | 2012-03-28 18:04:14 +0000 | [diff] [blame] | 514 | this->WCharType = this->SignedInt; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 515 | // FIXME: WIntType should be SignedLong |
| 516 | } |
| 517 | }; |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 518 | |
| 519 | // Windows target |
| 520 | template<typename Target> |
| 521 | class WindowsTargetInfo : public OSTargetInfo<Target> { |
| 522 | protected: |
| 523 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 524 | MacroBuilder &Builder) const { |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 525 | Builder.defineMacro("_WIN32"); |
| 526 | } |
| 527 | void getVisualStudioDefines(const LangOptions &Opts, |
| 528 | MacroBuilder &Builder) const { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 529 | if (Opts.CPlusPlus) { |
| 530 | if (Opts.RTTI) |
| 531 | Builder.defineMacro("_CPPRTTI"); |
| 532 | |
| 533 | if (Opts.Exceptions) |
| 534 | Builder.defineMacro("_CPPUNWIND"); |
| 535 | } |
| 536 | |
| 537 | if (!Opts.CharIsSigned) |
| 538 | Builder.defineMacro("_CHAR_UNSIGNED"); |
| 539 | |
| 540 | // FIXME: POSIXThreads isn't exactly the option this should be defined for, |
| 541 | // but it works for now. |
| 542 | if (Opts.POSIXThreads) |
| 543 | Builder.defineMacro("_MT"); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 544 | |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 545 | if (Opts.MSCVersion != 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 546 | Builder.defineMacro("_MSC_VER", Twine(Opts.MSCVersion)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 547 | |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 548 | if (Opts.MicrosoftExt) { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 549 | Builder.defineMacro("_MSC_EXTENSIONS"); |
| 550 | |
| 551 | if (Opts.CPlusPlus0x) { |
| 552 | Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED"); |
| 553 | Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED"); |
| 554 | Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED"); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | Builder.defineMacro("_INTEGRAL_MAX_BITS", "64"); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 561 | public: |
| 562 | WindowsTargetInfo(const std::string &triple) |
| 563 | : OSTargetInfo<Target>(triple) {} |
| 564 | }; |
| 565 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 566 | } // end anonymous namespace. |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 567 | |
Chris Lattner | d29b630 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 568 | //===----------------------------------------------------------------------===// |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 569 | // Specific target implementations. |
| 570 | //===----------------------------------------------------------------------===// |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 571 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 572 | namespace { |
| 573 | // PPC abstract base class |
| 574 | class PPCTargetInfo : public TargetInfo { |
| 575 | static const Builtin::Info BuiltinInfo[]; |
| 576 | static const char * const GCCRegNames[]; |
| 577 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 578 | public: |
Nico Weber | 6e1d2ea | 2012-01-31 02:07:33 +0000 | [diff] [blame] | 579 | PPCTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 580 | LongDoubleWidth = LongDoubleAlign = 128; |
| 581 | LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble; |
| 582 | } |
Eli Friedman | 15b9176 | 2009-06-05 07:05:05 +0000 | [diff] [blame] | 583 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 584 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 585 | unsigned &NumRecords) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 586 | Records = BuiltinInfo; |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 587 | NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 588 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 589 | |
Bob Wilson | 9f1c49c | 2012-01-28 18:02:29 +0000 | [diff] [blame] | 590 | virtual bool isCLZForZeroUndef() const { return false; } |
| 591 | |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 592 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 593 | MacroBuilder &Builder) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 594 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 595 | virtual bool hasFeature(StringRef Feature) const; |
| 596 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 597 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 598 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 599 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 600 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 601 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 602 | TargetInfo::ConstraintInfo &Info) const { |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 603 | switch (*Name) { |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 604 | default: return false; |
| 605 | case 'O': // Zero |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 606 | break; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 607 | case 'b': // Base register |
| 608 | case 'f': // Floating point register |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 609 | Info.setAllowsRegister(); |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 610 | break; |
| 611 | // FIXME: The following are added to allow parsing. |
| 612 | // I just took a guess at what the actions should be. |
| 613 | // Also, is more specific checking needed? I.e. specific registers? |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 614 | case 'd': // Floating point register (containing 64-bit value) |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 615 | case 'v': // Altivec vector register |
| 616 | Info.setAllowsRegister(); |
| 617 | break; |
| 618 | case 'w': |
| 619 | switch (Name[1]) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 620 | case 'd':// VSX vector register to hold vector double data |
| 621 | case 'f':// VSX vector register to hold vector float data |
| 622 | case 's':// VSX vector register to hold scalar float data |
| 623 | case 'a':// Any VSX register |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 624 | break; |
| 625 | default: |
| 626 | return false; |
| 627 | } |
| 628 | Info.setAllowsRegister(); |
| 629 | Name++; // Skip over 'w'. |
| 630 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 631 | case 'h': // `MQ', `CTR', or `LINK' register |
| 632 | case 'q': // `MQ' register |
| 633 | case 'c': // `CTR' register |
| 634 | case 'l': // `LINK' register |
| 635 | case 'x': // `CR' register (condition register) number 0 |
| 636 | case 'y': // `CR' register (condition register) |
| 637 | case 'z': // `XER[CA]' carry bit (part of the XER register) |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 638 | Info.setAllowsRegister(); |
| 639 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 640 | case 'I': // Signed 16-bit constant |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 641 | case 'J': // Unsigned 16-bit constant shifted left 16 bits |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 642 | // (use `L' instead for SImode constants) |
| 643 | case 'K': // Unsigned 16-bit constant |
| 644 | case 'L': // Signed 16-bit constant shifted left 16 bits |
| 645 | case 'M': // Constant larger than 31 |
| 646 | case 'N': // Exact power of 2 |
| 647 | case 'P': // Constant whose negation is a signed 16-bit constant |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 648 | case 'G': // Floating point constant that can be loaded into a |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 649 | // register with one instruction per word |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 650 | case 'H': // Integer/Floating point constant that can be loaded |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 651 | // into a register using three instructions |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 652 | break; |
| 653 | case 'm': // Memory operand. Note that on PowerPC targets, m can |
| 654 | // include addresses that update the base register. It |
| 655 | // is therefore only safe to use `m' in an asm statement |
| 656 | // if that asm statement accesses the operand exactly once. |
| 657 | // The asm statement must also use `%U<opno>' as a |
Sebastian Redl | 5005a6c | 2010-08-17 22:42:34 +0000 | [diff] [blame] | 658 | // placeholder for the "update" flag in the corresponding |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 659 | // load or store instruction. For example: |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 660 | // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 661 | // is correct but: |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 662 | // asm ("st %1,%0" : "=m" (mem) : "r" (val)); |
| 663 | // 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] | 664 | // register to be updated. |
| 665 | case 'e': |
John Thompson | 56b6eca | 2010-06-25 00:02:05 +0000 | [diff] [blame] | 666 | if (Name[1] != 's') |
| 667 | return false; |
Sebastian Redl | 5005a6c | 2010-08-17 22:42:34 +0000 | [diff] [blame] | 668 | // es: A "stable" memory operand; that is, one which does not |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 669 | // include any automodification of the base register. Unlike |
| 670 | // `m', this constraint can be used in asm statements that |
| 671 | // might access the operand several times, or that might not |
John Thompson | 56b6eca | 2010-06-25 00:02:05 +0000 | [diff] [blame] | 672 | // access it at all. |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 673 | Info.setAllowsMemory(); |
John Thompson | 56b6eca | 2010-06-25 00:02:05 +0000 | [diff] [blame] | 674 | Name++; // Skip over 'e'. |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 675 | break; |
| 676 | 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] | 677 | // usually better to use `m' or `es' in asm statements) |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 678 | case 'Z': // Memory operand that is an indexed or indirect from a |
| 679 | // register (it is usually better to use `m' or `es' in |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 680 | // asm statements) |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 681 | Info.setAllowsMemory(); |
| 682 | Info.setAllowsRegister(); |
| 683 | break; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 684 | case 'R': // AIX TOC entry |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 685 | 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] | 686 | // register (`p' is preferable for asm statements) |
| 687 | case 'S': // Constant suitable as a 64-bit mask operand |
| 688 | case 'T': // Constant suitable as a 32-bit mask operand |
| 689 | case 'U': // System V Release 4 small data area reference |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 690 | 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] | 691 | // instructions |
| 692 | case 'W': // Vector constant that does not require memory |
| 693 | case 'j': // Vector constant that is all zeros. |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 694 | break; |
| 695 | // End FIXME. |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 696 | } |
John Thompson | 8e6065a | 2010-06-24 22:44:13 +0000 | [diff] [blame] | 697 | return true; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 698 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 699 | virtual const char *getClobbers() const { |
| 700 | return ""; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 701 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 702 | }; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 703 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 704 | const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 705 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 706 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 707 | ALL_LANGUAGES }, |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 708 | #include "clang/Basic/BuiltinsPPC.def" |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 709 | }; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 710 | |
| 711 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 712 | /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific |
| 713 | /// #defines that are not tied to a specific subtarget. |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 714 | void PPCTargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 715 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 716 | // Target identification. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 717 | Builder.defineMacro("__ppc__"); |
| 718 | Builder.defineMacro("_ARCH_PPC"); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 719 | Builder.defineMacro("__powerpc__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 720 | Builder.defineMacro("__POWERPC__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 721 | if (PointerWidth == 64) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 722 | Builder.defineMacro("_ARCH_PPC64"); |
| 723 | Builder.defineMacro("_LP64"); |
| 724 | Builder.defineMacro("__LP64__"); |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 725 | Builder.defineMacro("__powerpc64__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 726 | Builder.defineMacro("__ppc64__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 727 | } else { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 728 | Builder.defineMacro("__ppc__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 729 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 730 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 731 | // Target properties. |
Joerg Sonnenberger | 7cd1de5 | 2011-07-05 14:56:12 +0000 | [diff] [blame] | 732 | if (getTriple().getOS() != llvm::Triple::NetBSD) |
| 733 | Builder.defineMacro("_BIG_ENDIAN"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 734 | Builder.defineMacro("__BIG_ENDIAN__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 735 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 736 | // Subtarget options. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 737 | Builder.defineMacro("__NATURAL_ALIGNMENT__"); |
| 738 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 739 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 740 | // FIXME: Should be controlled by command line option. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 741 | Builder.defineMacro("__LONG_DOUBLE_128__"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 742 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 743 | if (Opts.AltiVec) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 744 | Builder.defineMacro("__VEC__", "10206"); |
| 745 | Builder.defineMacro("__ALTIVEC__"); |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 746 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 749 | bool PPCTargetInfo::hasFeature(StringRef Feature) const { |
| 750 | return Feature == "powerpc"; |
| 751 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 753 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 754 | const char * const PPCTargetInfo::GCCRegNames[] = { |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 755 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 756 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 757 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 758 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 759 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 760 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 761 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 762 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 763 | "mq", "lr", "ctr", "ap", |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 764 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 765 | "xer", |
Chris Lattner | e94e0d4 | 2009-09-16 05:05:27 +0000 | [diff] [blame] | 766 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
| 767 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", |
| 768 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
| 769 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 770 | "vrsave", "vscr", |
| 771 | "spe_acc", "spefscr", |
| 772 | "sfp" |
| 773 | }; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 774 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 775 | void PPCTargetInfo::getGCCRegNames(const char * const *&Names, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 776 | unsigned &NumNames) const { |
| 777 | Names = GCCRegNames; |
| 778 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 779 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 780 | |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 781 | const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = { |
| 782 | // While some of these aliases do map to different registers |
| 783 | // they still share the same register name. |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 784 | { { "0" }, "r0" }, |
| 785 | { { "1"}, "r1" }, |
| 786 | { { "2" }, "r2" }, |
| 787 | { { "3" }, "r3" }, |
| 788 | { { "4" }, "r4" }, |
| 789 | { { "5" }, "r5" }, |
| 790 | { { "6" }, "r6" }, |
| 791 | { { "7" }, "r7" }, |
| 792 | { { "8" }, "r8" }, |
| 793 | { { "9" }, "r9" }, |
| 794 | { { "10" }, "r10" }, |
| 795 | { { "11" }, "r11" }, |
| 796 | { { "12" }, "r12" }, |
| 797 | { { "13" }, "r13" }, |
| 798 | { { "14" }, "r14" }, |
| 799 | { { "15" }, "r15" }, |
| 800 | { { "16" }, "r16" }, |
| 801 | { { "17" }, "r17" }, |
| 802 | { { "18" }, "r18" }, |
| 803 | { { "19" }, "r19" }, |
| 804 | { { "20" }, "r20" }, |
| 805 | { { "21" }, "r21" }, |
| 806 | { { "22" }, "r22" }, |
| 807 | { { "23" }, "r23" }, |
| 808 | { { "24" }, "r24" }, |
| 809 | { { "25" }, "r25" }, |
| 810 | { { "26" }, "r26" }, |
| 811 | { { "27" }, "r27" }, |
| 812 | { { "28" }, "r28" }, |
| 813 | { { "29" }, "r29" }, |
| 814 | { { "30" }, "r30" }, |
| 815 | { { "31" }, "r31" }, |
| 816 | { { "fr0" }, "f0" }, |
| 817 | { { "fr1" }, "f1" }, |
| 818 | { { "fr2" }, "f2" }, |
| 819 | { { "fr3" }, "f3" }, |
| 820 | { { "fr4" }, "f4" }, |
| 821 | { { "fr5" }, "f5" }, |
| 822 | { { "fr6" }, "f6" }, |
| 823 | { { "fr7" }, "f7" }, |
| 824 | { { "fr8" }, "f8" }, |
| 825 | { { "fr9" }, "f9" }, |
Mike Stump | 1088039 | 2009-09-17 21:15:00 +0000 | [diff] [blame] | 826 | { { "fr10" }, "f10" }, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 827 | { { "fr11" }, "f11" }, |
| 828 | { { "fr12" }, "f12" }, |
| 829 | { { "fr13" }, "f13" }, |
| 830 | { { "fr14" }, "f14" }, |
| 831 | { { "fr15" }, "f15" }, |
| 832 | { { "fr16" }, "f16" }, |
| 833 | { { "fr17" }, "f17" }, |
| 834 | { { "fr18" }, "f18" }, |
| 835 | { { "fr19" }, "f19" }, |
| 836 | { { "fr20" }, "f20" }, |
| 837 | { { "fr21" }, "f21" }, |
| 838 | { { "fr22" }, "f22" }, |
| 839 | { { "fr23" }, "f23" }, |
| 840 | { { "fr24" }, "f24" }, |
| 841 | { { "fr25" }, "f25" }, |
| 842 | { { "fr26" }, "f26" }, |
| 843 | { { "fr27" }, "f27" }, |
| 844 | { { "fr28" }, "f28" }, |
| 845 | { { "fr29" }, "f29" }, |
| 846 | { { "fr30" }, "f30" }, |
| 847 | { { "fr31" }, "f31" }, |
| 848 | { { "cc" }, "cr0" }, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 849 | }; |
| 850 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 851 | void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 852 | unsigned &NumAliases) const { |
| 853 | Aliases = GCCRegAliases; |
| 854 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 855 | } |
| 856 | } // end anonymous namespace. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 857 | |
| 858 | namespace { |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 859 | class PPC32TargetInfo : public PPCTargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 860 | public: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 861 | PPC32TargetInfo(const std::string &triple) : PPCTargetInfo(triple) { |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 862 | 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] | 863 | "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] | 864 | |
Joerg Sonnenberger | 6ac26fa | 2011-07-04 21:57:55 +0000 | [diff] [blame] | 865 | switch (getTriple().getOS()) { |
Nico Weber | 6e1d2ea | 2012-01-31 02:07:33 +0000 | [diff] [blame] | 866 | case llvm::Triple::Linux: |
Joerg Sonnenberger | 6ac26fa | 2011-07-04 21:57:55 +0000 | [diff] [blame] | 867 | case llvm::Triple::FreeBSD: |
| 868 | case llvm::Triple::NetBSD: |
Joerg Sonnenberger | 78542df | 2011-07-05 14:54:41 +0000 | [diff] [blame] | 869 | SizeType = UnsignedInt; |
Hal Finkel | 178a9b8 | 2012-03-02 20:54:36 +0000 | [diff] [blame] | 870 | PtrDiffType = SignedInt; |
| 871 | IntPtrType = SignedInt; |
Joerg Sonnenberger | 78542df | 2011-07-05 14:54:41 +0000 | [diff] [blame] | 872 | break; |
Joerg Sonnenberger | 1a83b43 | 2011-07-04 23:11:58 +0000 | [diff] [blame] | 873 | default: |
Joerg Sonnenberger | 78542df | 2011-07-05 14:54:41 +0000 | [diff] [blame] | 874 | break; |
Joerg Sonnenberger | 6ac26fa | 2011-07-04 21:57:55 +0000 | [diff] [blame] | 875 | } |
Roman Divacky | e3d175d | 2012-03-13 16:53:54 +0000 | [diff] [blame] | 876 | |
Roman Divacky | efe9c0d | 2012-03-13 19:20:17 +0000 | [diff] [blame] | 877 | if (getTriple().getOS() == llvm::Triple::FreeBSD) { |
| 878 | LongDoubleWidth = LongDoubleAlign = 64; |
Roman Divacky | e3d175d | 2012-03-13 16:53:54 +0000 | [diff] [blame] | 879 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
Roman Divacky | efe9c0d | 2012-03-13 19:20:17 +0000 | [diff] [blame] | 880 | } |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | virtual const char *getVAListDeclaration() const { |
| 884 | // This is the ELF definition, and is overridden by the Darwin sub-target |
| 885 | return "typedef struct __va_list_tag {" |
| 886 | " unsigned char gpr;" |
| 887 | " unsigned char fpr;" |
| 888 | " unsigned short reserved;" |
| 889 | " void* overflow_arg_area;" |
| 890 | " void* reg_save_area;" |
| 891 | "} __builtin_va_list[1];"; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 892 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 893 | }; |
| 894 | } // end anonymous namespace. |
| 895 | |
| 896 | namespace { |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 897 | class PPC64TargetInfo : public PPCTargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 898 | public: |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 899 | PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 900 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 901 | IntMaxType = SignedLong; |
| 902 | UIntMaxType = UnsignedLong; |
| 903 | Int64Type = SignedLong; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 904 | 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] | 905 | "i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64"; |
Roman Divacky | e3d175d | 2012-03-13 16:53:54 +0000 | [diff] [blame] | 906 | |
Roman Divacky | efe9c0d | 2012-03-13 19:20:17 +0000 | [diff] [blame] | 907 | if (getTriple().getOS() == llvm::Triple::FreeBSD) { |
| 908 | LongDoubleWidth = LongDoubleAlign = 64; |
Roman Divacky | e3d175d | 2012-03-13 16:53:54 +0000 | [diff] [blame] | 909 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
Roman Divacky | efe9c0d | 2012-03-13 19:20:17 +0000 | [diff] [blame] | 910 | } |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 911 | } |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 912 | virtual const char *getVAListDeclaration() const { |
| 913 | return "typedef char* __builtin_va_list;"; |
| 914 | } |
Eli Friedman | e427798 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 915 | }; |
| 916 | } // end anonymous namespace. |
| 917 | |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 918 | |
| 919 | namespace { |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 920 | class DarwinPPC32TargetInfo : |
| 921 | public DarwinTargetInfo<PPC32TargetInfo> { |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 922 | public: |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 923 | DarwinPPC32TargetInfo(const std::string& triple) |
| 924 | : DarwinTargetInfo<PPC32TargetInfo>(triple) { |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 925 | HasAlignMac68kSupport = true; |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 926 | BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool? |
Anton Yartsev | 9bc23ba | 2012-01-17 22:40:00 +0000 | [diff] [blame] | 927 | LongLongAlign = 32; |
Nick Lewycky | 9bddf43 | 2011-12-21 04:25:47 +0000 | [diff] [blame] | 928 | SuitableAlign = 128; |
Anton Yartsev | 9bc23ba | 2012-01-17 22:40:00 +0000 | [diff] [blame] | 929 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 930 | "i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32"; |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 931 | } |
| 932 | virtual const char *getVAListDeclaration() const { |
| 933 | return "typedef char* __builtin_va_list;"; |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 934 | } |
| 935 | }; |
| 936 | |
| 937 | class DarwinPPC64TargetInfo : |
| 938 | public DarwinTargetInfo<PPC64TargetInfo> { |
| 939 | public: |
| 940 | DarwinPPC64TargetInfo(const std::string& triple) |
| 941 | : DarwinTargetInfo<PPC64TargetInfo>(triple) { |
| 942 | HasAlignMac68kSupport = true; |
Nick Lewycky | 9bddf43 | 2011-12-21 04:25:47 +0000 | [diff] [blame] | 943 | SuitableAlign = 128; |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 944 | } |
| 945 | }; |
| 946 | } // end anonymous namespace. |
| 947 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 948 | namespace { |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 949 | static const unsigned NVPTXAddrSpaceMap[] = { |
| 950 | 1, // opencl_global |
| 951 | 3, // opencl_local |
| 952 | 4, // opencl_constant |
| 953 | 1, // cuda_device |
| 954 | 4, // cuda_constant |
| 955 | 3, // cuda_shared |
| 956 | }; |
| 957 | class NVPTXTargetInfo : public TargetInfo { |
| 958 | static const char * const GCCRegNames[]; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 959 | static const Builtin::Info BuiltinInfo[]; |
| 960 | std::vector<llvm::StringRef> AvailableFeatures; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 961 | public: |
| 962 | NVPTXTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 963 | BigEndian = false; |
| 964 | TLSSupported = false; |
| 965 | LongWidth = LongAlign = 64; |
| 966 | AddrSpaceMap = &NVPTXAddrSpaceMap; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 967 | // Define available target features |
| 968 | // These must be defined in sorted order! |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 969 | } |
| 970 | virtual void getTargetDefines(const LangOptions &Opts, |
| 971 | MacroBuilder &Builder) const { |
| 972 | Builder.defineMacro("__PTX__"); |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 973 | Builder.defineMacro("__NVPTX__"); |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 974 | } |
| 975 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 976 | unsigned &NumRecords) const { |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 977 | Records = BuiltinInfo; |
| 978 | NumRecords = clang::NVPTX::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 979 | } |
| 980 | virtual bool hasFeature(StringRef Feature) const { |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 981 | return Feature == "ptx" || Feature == "nvptx"; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | virtual void getGCCRegNames(const char * const *&Names, |
| 985 | unsigned &NumNames) const; |
| 986 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 987 | unsigned &NumAliases) const { |
| 988 | // No aliases. |
| 989 | Aliases = 0; |
| 990 | NumAliases = 0; |
| 991 | } |
| 992 | virtual bool validateAsmConstraint(const char *&Name, |
| 993 | TargetInfo::ConstraintInfo &info) const { |
| 994 | // FIXME: implement |
| 995 | return true; |
| 996 | } |
| 997 | virtual const char *getClobbers() const { |
| 998 | // FIXME: Is this really right? |
| 999 | return ""; |
| 1000 | } |
| 1001 | virtual const char *getVAListDeclaration() const { |
| 1002 | // FIXME: implement |
| 1003 | return "typedef char* __builtin_va_list;"; |
| 1004 | } |
| 1005 | virtual bool setCPU(const std::string &Name) { |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1006 | return Name == "sm_10" || Name == "sm_13" || Name == "sm_20"; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1007 | } |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1008 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 1009 | StringRef Name, |
| 1010 | bool Enabled) const; |
| 1011 | }; |
| 1012 | |
| 1013 | const Builtin::Info NVPTXTargetInfo::BuiltinInfo[] = { |
| 1014 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
| 1015 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
| 1016 | ALL_LANGUAGES }, |
| 1017 | #include "clang/Basic/BuiltinsNVPTX.def" |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1018 | }; |
| 1019 | |
| 1020 | const char * const NVPTXTargetInfo::GCCRegNames[] = { |
| 1021 | "r0" |
| 1022 | }; |
| 1023 | |
| 1024 | void NVPTXTargetInfo::getGCCRegNames(const char * const *&Names, |
| 1025 | unsigned &NumNames) const { |
| 1026 | Names = GCCRegNames; |
| 1027 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1028 | } |
| 1029 | |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1030 | bool NVPTXTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 1031 | StringRef Name, |
| 1032 | bool Enabled) const { |
| 1033 | if(std::binary_search(AvailableFeatures.begin(), AvailableFeatures.end(), |
| 1034 | Name)) { |
| 1035 | Features[Name] = Enabled; |
| 1036 | return true; |
| 1037 | } else { |
| 1038 | return false; |
| 1039 | } |
| 1040 | } |
| 1041 | |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1042 | class NVPTX32TargetInfo : public NVPTXTargetInfo { |
| 1043 | public: |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1044 | NVPTX32TargetInfo(const std::string& triple) : NVPTXTargetInfo(triple) { |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1045 | PointerWidth = PointerAlign = 32; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1046 | SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1047 | DescriptionString |
| 1048 | = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
| 1049 | "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-" |
| 1050 | "n16:32:64"; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1051 | } |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1052 | }; |
| 1053 | |
| 1054 | class NVPTX64TargetInfo : public NVPTXTargetInfo { |
| 1055 | public: |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1056 | NVPTX64TargetInfo(const std::string& triple) : NVPTXTargetInfo(triple) { |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1057 | PointerWidth = PointerAlign = 64; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1058 | SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong; |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1059 | DescriptionString |
| 1060 | = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
| 1061 | "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-" |
| 1062 | "n16:32:64"; |
Justin Holewinski | 2c585b9 | 2012-05-24 17:43:12 +0000 | [diff] [blame] | 1063 | } |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 1064 | }; |
| 1065 | } |
| 1066 | |
| 1067 | namespace { |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 1068 | // MBlaze abstract base class |
| 1069 | class MBlazeTargetInfo : public TargetInfo { |
| 1070 | static const char * const GCCRegNames[]; |
| 1071 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 1072 | |
| 1073 | public: |
| 1074 | MBlazeTargetInfo(const std::string& triple) : TargetInfo(triple) { |
Wesley Peck | a48fa4b | 2010-12-12 20:56:47 +0000 | [diff] [blame] | 1075 | DescriptionString = "E-p:32:32:32-i8:8:8-i16:16:16"; |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1079 | unsigned &NumRecords) const { |
| 1080 | // FIXME: Implement. |
| 1081 | Records = 0; |
| 1082 | NumRecords = 0; |
| 1083 | } |
| 1084 | |
| 1085 | virtual void getTargetDefines(const LangOptions &Opts, |
| 1086 | MacroBuilder &Builder) const; |
| 1087 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 1088 | virtual bool hasFeature(StringRef Feature) const { |
| 1089 | return Feature == "mblaze"; |
| 1090 | } |
| 1091 | |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 1092 | virtual const char *getVAListDeclaration() const { |
| 1093 | return "typedef char* __builtin_va_list;"; |
| 1094 | } |
| 1095 | virtual const char *getTargetPrefix() const { |
| 1096 | return "mblaze"; |
| 1097 | } |
| 1098 | virtual void getGCCRegNames(const char * const *&Names, |
| 1099 | unsigned &NumNames) const; |
| 1100 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1101 | unsigned &NumAliases) const; |
| 1102 | virtual bool validateAsmConstraint(const char *&Name, |
| 1103 | TargetInfo::ConstraintInfo &Info) const { |
| 1104 | switch (*Name) { |
| 1105 | default: return false; |
| 1106 | case 'O': // Zero |
| 1107 | return true; |
| 1108 | case 'b': // Base register |
| 1109 | case 'f': // Floating point register |
| 1110 | Info.setAllowsRegister(); |
| 1111 | return true; |
| 1112 | } |
| 1113 | } |
| 1114 | virtual const char *getClobbers() const { |
| 1115 | return ""; |
| 1116 | } |
| 1117 | }; |
| 1118 | |
| 1119 | /// MBlazeTargetInfo::getTargetDefines - Return a set of the MBlaze-specific |
| 1120 | /// #defines that are not tied to a specific subtarget. |
| 1121 | void MBlazeTargetInfo::getTargetDefines(const LangOptions &Opts, |
| 1122 | MacroBuilder &Builder) const { |
| 1123 | // Target identification. |
| 1124 | Builder.defineMacro("__microblaze__"); |
| 1125 | Builder.defineMacro("_ARCH_MICROBLAZE"); |
| 1126 | Builder.defineMacro("__MICROBLAZE__"); |
| 1127 | |
| 1128 | // Target properties. |
| 1129 | Builder.defineMacro("_BIG_ENDIAN"); |
| 1130 | Builder.defineMacro("__BIG_ENDIAN__"); |
| 1131 | |
| 1132 | // Subtarget options. |
| 1133 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 1134 | } |
| 1135 | |
| 1136 | |
| 1137 | const char * const MBlazeTargetInfo::GCCRegNames[] = { |
| 1138 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 1139 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 1140 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 1141 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 1142 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 1143 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 1144 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 1145 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
| 1146 | "hi", "lo", "accum","rmsr", "$fcc1","$fcc2","$fcc3","$fcc4", |
| 1147 | "$fcc5","$fcc6","$fcc7","$ap", "$rap", "$frp" |
| 1148 | }; |
| 1149 | |
| 1150 | void MBlazeTargetInfo::getGCCRegNames(const char * const *&Names, |
| 1151 | unsigned &NumNames) const { |
| 1152 | Names = GCCRegNames; |
| 1153 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 1154 | } |
| 1155 | |
| 1156 | const TargetInfo::GCCRegAlias MBlazeTargetInfo::GCCRegAliases[] = { |
| 1157 | { {"f0"}, "r0" }, |
| 1158 | { {"f1"}, "r1" }, |
| 1159 | { {"f2"}, "r2" }, |
| 1160 | { {"f3"}, "r3" }, |
| 1161 | { {"f4"}, "r4" }, |
| 1162 | { {"f5"}, "r5" }, |
| 1163 | { {"f6"}, "r6" }, |
| 1164 | { {"f7"}, "r7" }, |
| 1165 | { {"f8"}, "r8" }, |
| 1166 | { {"f9"}, "r9" }, |
| 1167 | { {"f10"}, "r10" }, |
| 1168 | { {"f11"}, "r11" }, |
| 1169 | { {"f12"}, "r12" }, |
| 1170 | { {"f13"}, "r13" }, |
| 1171 | { {"f14"}, "r14" }, |
| 1172 | { {"f15"}, "r15" }, |
| 1173 | { {"f16"}, "r16" }, |
| 1174 | { {"f17"}, "r17" }, |
| 1175 | { {"f18"}, "r18" }, |
| 1176 | { {"f19"}, "r19" }, |
| 1177 | { {"f20"}, "r20" }, |
| 1178 | { {"f21"}, "r21" }, |
| 1179 | { {"f22"}, "r22" }, |
| 1180 | { {"f23"}, "r23" }, |
| 1181 | { {"f24"}, "r24" }, |
| 1182 | { {"f25"}, "r25" }, |
| 1183 | { {"f26"}, "r26" }, |
| 1184 | { {"f27"}, "r27" }, |
| 1185 | { {"f28"}, "r28" }, |
| 1186 | { {"f29"}, "r29" }, |
| 1187 | { {"f30"}, "r30" }, |
| 1188 | { {"f31"}, "r31" }, |
| 1189 | }; |
| 1190 | |
| 1191 | void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 1192 | unsigned &NumAliases) const { |
| 1193 | Aliases = GCCRegAliases; |
| 1194 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 1195 | } |
| 1196 | } // end anonymous namespace. |
| 1197 | |
| 1198 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1199 | // Namespace for x86 abstract base class |
| 1200 | const Builtin::Info BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 1201 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 1202 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 1203 | ALL_LANGUAGES }, |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 1204 | #include "clang/Basic/BuiltinsX86.def" |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1205 | }; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1206 | |
Nuno Lopes | 2550d70 | 2009-12-23 17:49:57 +0000 | [diff] [blame] | 1207 | static const char* const GCCRegNames[] = { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1208 | "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", |
| 1209 | "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] | 1210 | "argp", "flags", "fpcr", "fpsr", "dirflag", "frame", |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1211 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 1212 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", |
| 1213 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1214 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15", |
Eric Christopher | c5f9a01 | 2011-12-02 02:12:16 +0000 | [diff] [blame] | 1215 | "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7", |
| 1216 | "ymm8", "ymm9", "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15", |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1217 | }; |
| 1218 | |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1219 | const TargetInfo::AddlRegName AddlRegNames[] = { |
| 1220 | { { "al", "ah", "eax", "rax" }, 0 }, |
| 1221 | { { "bl", "bh", "ebx", "rbx" }, 3 }, |
| 1222 | { { "cl", "ch", "ecx", "rcx" }, 2 }, |
| 1223 | { { "dl", "dh", "edx", "rdx" }, 1 }, |
| 1224 | { { "esi", "rsi" }, 4 }, |
| 1225 | { { "edi", "rdi" }, 5 }, |
| 1226 | { { "esp", "rsp" }, 7 }, |
| 1227 | { { "ebp", "rbp" }, 6 }, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1228 | }; |
| 1229 | |
| 1230 | // X86 target abstract base class; x86-32 and x86-64 are very close, so |
| 1231 | // most of the implementation can be shared. |
| 1232 | class X86TargetInfo : public TargetInfo { |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1233 | enum X86SSEEnum { |
Craig Topper | 05fe4b5 | 2012-01-09 09:19:09 +0000 | [diff] [blame] | 1234 | NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2 |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 1235 | } SSELevel; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1236 | enum MMX3DNowEnum { |
| 1237 | NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon |
| 1238 | } MMX3DNowLevel; |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1239 | |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1240 | bool HasAES; |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1241 | bool HasPCLMUL; |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1242 | bool HasLZCNT; |
| 1243 | bool HasBMI; |
| 1244 | bool HasBMI2; |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1245 | bool HasPOPCNT; |
Benjamin Kramer | 4dfa5ad | 2012-05-29 17:48:39 +0000 | [diff] [blame] | 1246 | bool HasSSE4a; |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1247 | bool HasFMA4; |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1248 | bool HasFMA; |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1249 | bool HasXOP; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1250 | |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1251 | /// \brief Enumeration of all of the X86 CPUs supported by Clang. |
| 1252 | /// |
| 1253 | /// Each enumeration represents a particular CPU supported by Clang. These |
| 1254 | /// loosely correspond to the options passed to '-march' or '-mtune' flags. |
| 1255 | enum CPUKind { |
| 1256 | CK_Generic, |
| 1257 | |
| 1258 | /// \name i386 |
| 1259 | /// i386-generation processors. |
| 1260 | //@{ |
| 1261 | CK_i386, |
| 1262 | //@} |
| 1263 | |
| 1264 | /// \name i486 |
| 1265 | /// i486-generation processors. |
| 1266 | //@{ |
| 1267 | CK_i486, |
| 1268 | CK_WinChipC6, |
| 1269 | CK_WinChip2, |
| 1270 | CK_C3, |
| 1271 | //@} |
| 1272 | |
| 1273 | /// \name i586 |
| 1274 | /// i586-generation processors, P5 microarchitecture based. |
| 1275 | //@{ |
| 1276 | CK_i586, |
| 1277 | CK_Pentium, |
| 1278 | CK_PentiumMMX, |
| 1279 | //@} |
| 1280 | |
| 1281 | /// \name i686 |
| 1282 | /// i686-generation processors, P6 / Pentium M microarchitecture based. |
| 1283 | //@{ |
| 1284 | CK_i686, |
| 1285 | CK_PentiumPro, |
| 1286 | CK_Pentium2, |
| 1287 | CK_Pentium3, |
| 1288 | CK_Pentium3M, |
| 1289 | CK_PentiumM, |
| 1290 | CK_C3_2, |
| 1291 | |
| 1292 | /// This enumerator is a bit odd, as GCC no longer accepts -march=yonah. |
| 1293 | /// Clang however has some logic to suport this. |
| 1294 | // FIXME: Warn, deprecate, and potentially remove this. |
| 1295 | CK_Yonah, |
| 1296 | //@} |
| 1297 | |
| 1298 | /// \name Netburst |
Chandler Carruth | 83450aa | 2011-09-28 18:17:30 +0000 | [diff] [blame] | 1299 | /// Netburst microarchitecture based processors. |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1300 | //@{ |
| 1301 | CK_Pentium4, |
| 1302 | CK_Pentium4M, |
| 1303 | CK_Prescott, |
| 1304 | CK_Nocona, |
| 1305 | //@} |
| 1306 | |
| 1307 | /// \name Core |
| 1308 | /// Core microarchitecture based processors. |
| 1309 | //@{ |
| 1310 | CK_Core2, |
| 1311 | |
| 1312 | /// This enumerator, like \see CK_Yonah, is a bit odd. It is another |
| 1313 | /// codename which GCC no longer accepts as an option to -march, but Clang |
| 1314 | /// has some logic for recognizing it. |
| 1315 | // FIXME: Warn, deprecate, and potentially remove this. |
| 1316 | CK_Penryn, |
| 1317 | //@} |
| 1318 | |
| 1319 | /// \name Atom |
| 1320 | /// Atom processors |
| 1321 | //@{ |
| 1322 | CK_Atom, |
| 1323 | //@} |
| 1324 | |
| 1325 | /// \name Nehalem |
| 1326 | /// Nehalem microarchitecture based processors. |
| 1327 | //@{ |
| 1328 | CK_Corei7, |
| 1329 | CK_Corei7AVX, |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1330 | CK_CoreAVXi, |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1331 | CK_CoreAVX2, |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1332 | //@} |
| 1333 | |
| 1334 | /// \name K6 |
| 1335 | /// K6 architecture processors. |
| 1336 | //@{ |
| 1337 | CK_K6, |
| 1338 | CK_K6_2, |
| 1339 | CK_K6_3, |
| 1340 | //@} |
| 1341 | |
| 1342 | /// \name K7 |
| 1343 | /// K7 architecture processors. |
| 1344 | //@{ |
| 1345 | CK_Athlon, |
| 1346 | CK_AthlonThunderbird, |
| 1347 | CK_Athlon4, |
| 1348 | CK_AthlonXP, |
| 1349 | CK_AthlonMP, |
| 1350 | //@} |
| 1351 | |
| 1352 | /// \name K8 |
| 1353 | /// K8 architecture processors. |
| 1354 | //@{ |
| 1355 | CK_Athlon64, |
| 1356 | CK_Athlon64SSE3, |
| 1357 | CK_AthlonFX, |
| 1358 | CK_K8, |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1359 | CK_K8SSE3, |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1360 | CK_Opteron, |
| 1361 | CK_OpteronSSE3, |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 1362 | CK_AMDFAM10, |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1363 | //@} |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1364 | |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1365 | /// \name Bobcat |
| 1366 | /// Bobcat architecture processors. |
| 1367 | //@{ |
| 1368 | CK_BTVER1, |
| 1369 | //@} |
| 1370 | |
| 1371 | /// \name Bulldozer |
| 1372 | /// Bulldozer architecture processors. |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1373 | //@{ |
| 1374 | CK_BDVER1, |
| 1375 | CK_BDVER2, |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1376 | //@} |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1377 | |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1378 | /// This specification is deprecated and will be removed in the future. |
| 1379 | /// Users should prefer \see CK_K8. |
| 1380 | // FIXME: Warn on this when the CPU is set to it. |
| 1381 | CK_x86_64, |
| 1382 | //@} |
| 1383 | |
| 1384 | /// \name Geode |
| 1385 | /// Geode processors. |
| 1386 | //@{ |
| 1387 | CK_Geode |
| 1388 | //@} |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1389 | } CPU; |
Chandler Carruth | 499d972 | 2011-09-28 08:55:34 +0000 | [diff] [blame] | 1390 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1391 | public: |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1392 | X86TargetInfo(const std::string& triple) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1393 | : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow), |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1394 | HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasBMI(false), |
| 1395 | HasBMI2(false), HasPOPCNT(false), HasSSE4a(false), HasFMA4(false), |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1396 | HasFMA(false), HasXOP(false), CPU(CK_Generic) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 1397 | BigEndian = false; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1398 | LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1399 | } |
Benjamin Kramer | b406669 | 2011-12-28 15:47:06 +0000 | [diff] [blame] | 1400 | virtual unsigned getFloatEvalMethod() const { |
| 1401 | // X87 evaluates with 80 bits "long double" precision. |
| 1402 | return SSELevel == NoSSE ? 2 : 0; |
| 1403 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1404 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 1405 | unsigned &NumRecords) const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1406 | Records = BuiltinInfo; |
| 1407 | NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1408 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1409 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1410 | unsigned &NumNames) const { |
| 1411 | Names = GCCRegNames; |
| 1412 | NumNames = llvm::array_lengthof(GCCRegNames); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1413 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1414 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 1415 | unsigned &NumAliases) const { |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 1416 | Aliases = 0; |
| 1417 | NumAliases = 0; |
| 1418 | } |
| 1419 | virtual void getGCCAddlRegNames(const AddlRegName *&Names, |
| 1420 | unsigned &NumNames) const { |
| 1421 | Names = AddlRegNames; |
| 1422 | NumNames = llvm::array_lengthof(AddlRegNames); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 1423 | } |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 1424 | virtual bool validateAsmConstraint(const char *&Name, |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1425 | TargetInfo::ConstraintInfo &info) const; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 1426 | virtual std::string convertConstraint(const char *&Constraint) const; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 1427 | virtual const char *getClobbers() const { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 1428 | return "~{dirflag},~{fpsr},~{flags}"; |
| 1429 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1430 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1431 | MacroBuilder &Builder) const; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1432 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1433 | StringRef Name, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1434 | bool Enabled) const; |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 1435 | virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const; |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 1436 | virtual bool hasFeature(StringRef Feature) const; |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 1437 | virtual void HandleTargetFeatures(std::vector<std::string> &Features); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1438 | virtual const char* getABI() const { |
Craig Topper | 05fe4b5 | 2012-01-09 09:19:09 +0000 | [diff] [blame] | 1439 | if (PointerWidth == 64 && SSELevel >= AVX) |
Eli Friedman | ee1ad99 | 2011-12-02 00:11:43 +0000 | [diff] [blame] | 1440 | return "avx"; |
| 1441 | else if (PointerWidth == 32 && MMX3DNowLevel == NoMMX3DNow) |
| 1442 | return "no-mmx"; |
| 1443 | return ""; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1444 | } |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 1445 | virtual bool setCPU(const std::string &Name) { |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1446 | CPU = llvm::StringSwitch<CPUKind>(Name) |
| 1447 | .Case("i386", CK_i386) |
| 1448 | .Case("i486", CK_i486) |
| 1449 | .Case("winchip-c6", CK_WinChipC6) |
| 1450 | .Case("winchip2", CK_WinChip2) |
| 1451 | .Case("c3", CK_C3) |
| 1452 | .Case("i586", CK_i586) |
| 1453 | .Case("pentium", CK_Pentium) |
| 1454 | .Case("pentium-mmx", CK_PentiumMMX) |
| 1455 | .Case("i686", CK_i686) |
| 1456 | .Case("pentiumpro", CK_PentiumPro) |
| 1457 | .Case("pentium2", CK_Pentium2) |
| 1458 | .Case("pentium3", CK_Pentium3) |
| 1459 | .Case("pentium3m", CK_Pentium3M) |
| 1460 | .Case("pentium-m", CK_PentiumM) |
| 1461 | .Case("c3-2", CK_C3_2) |
| 1462 | .Case("yonah", CK_Yonah) |
| 1463 | .Case("pentium4", CK_Pentium4) |
| 1464 | .Case("pentium4m", CK_Pentium4M) |
| 1465 | .Case("prescott", CK_Prescott) |
| 1466 | .Case("nocona", CK_Nocona) |
| 1467 | .Case("core2", CK_Core2) |
| 1468 | .Case("penryn", CK_Penryn) |
| 1469 | .Case("atom", CK_Atom) |
| 1470 | .Case("corei7", CK_Corei7) |
| 1471 | .Case("corei7-avx", CK_Corei7AVX) |
| 1472 | .Case("core-avx-i", CK_CoreAVXi) |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1473 | .Case("core-avx2", CK_CoreAVX2) |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1474 | .Case("k6", CK_K6) |
| 1475 | .Case("k6-2", CK_K6_2) |
| 1476 | .Case("k6-3", CK_K6_3) |
| 1477 | .Case("athlon", CK_Athlon) |
| 1478 | .Case("athlon-tbird", CK_AthlonThunderbird) |
| 1479 | .Case("athlon-4", CK_Athlon4) |
| 1480 | .Case("athlon-xp", CK_AthlonXP) |
| 1481 | .Case("athlon-mp", CK_AthlonMP) |
| 1482 | .Case("athlon64", CK_Athlon64) |
| 1483 | .Case("athlon64-sse3", CK_Athlon64SSE3) |
| 1484 | .Case("athlon-fx", CK_AthlonFX) |
| 1485 | .Case("k8", CK_K8) |
| 1486 | .Case("k8-sse3", CK_K8SSE3) |
| 1487 | .Case("opteron", CK_Opteron) |
| 1488 | .Case("opteron-sse3", CK_OpteronSSE3) |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 1489 | .Case("amdfam10", CK_AMDFAM10) |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1490 | .Case("btver1", CK_BTVER1) |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1491 | .Case("bdver1", CK_BDVER1) |
| 1492 | .Case("bdver2", CK_BDVER2) |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1493 | .Case("x86-64", CK_x86_64) |
| 1494 | .Case("geode", CK_Geode) |
| 1495 | .Default(CK_Generic); |
| 1496 | |
Chandler Carruth | 26a3914 | 2011-09-28 09:45:08 +0000 | [diff] [blame] | 1497 | // Perform any per-CPU checks necessary to determine if this CPU is |
| 1498 | // acceptable. |
| 1499 | // FIXME: This results in terrible diagnostics. Clang just says the CPU is |
| 1500 | // invalid without explaining *why*. |
| 1501 | switch (CPU) { |
| 1502 | case CK_Generic: |
| 1503 | // No processor selected! |
| 1504 | return false; |
| 1505 | |
| 1506 | case CK_i386: |
| 1507 | case CK_i486: |
| 1508 | case CK_WinChipC6: |
| 1509 | case CK_WinChip2: |
| 1510 | case CK_C3: |
| 1511 | case CK_i586: |
| 1512 | case CK_Pentium: |
| 1513 | case CK_PentiumMMX: |
| 1514 | case CK_i686: |
| 1515 | case CK_PentiumPro: |
| 1516 | case CK_Pentium2: |
| 1517 | case CK_Pentium3: |
| 1518 | case CK_Pentium3M: |
| 1519 | case CK_PentiumM: |
| 1520 | case CK_Yonah: |
| 1521 | case CK_C3_2: |
| 1522 | case CK_Pentium4: |
| 1523 | case CK_Pentium4M: |
| 1524 | case CK_Prescott: |
| 1525 | case CK_K6: |
| 1526 | case CK_K6_2: |
| 1527 | case CK_K6_3: |
| 1528 | case CK_Athlon: |
| 1529 | case CK_AthlonThunderbird: |
| 1530 | case CK_Athlon4: |
| 1531 | case CK_AthlonXP: |
| 1532 | case CK_AthlonMP: |
| 1533 | case CK_Geode: |
| 1534 | // Only accept certain architectures when compiling in 32-bit mode. |
| 1535 | if (PointerWidth != 32) |
| 1536 | return false; |
| 1537 | |
| 1538 | // Fallthrough |
| 1539 | case CK_Nocona: |
| 1540 | case CK_Core2: |
| 1541 | case CK_Penryn: |
| 1542 | case CK_Atom: |
| 1543 | case CK_Corei7: |
| 1544 | case CK_Corei7AVX: |
| 1545 | case CK_CoreAVXi: |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1546 | case CK_CoreAVX2: |
Chandler Carruth | 26a3914 | 2011-09-28 09:45:08 +0000 | [diff] [blame] | 1547 | case CK_Athlon64: |
| 1548 | case CK_Athlon64SSE3: |
| 1549 | case CK_AthlonFX: |
| 1550 | case CK_K8: |
| 1551 | case CK_K8SSE3: |
| 1552 | case CK_Opteron: |
| 1553 | case CK_OpteronSSE3: |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 1554 | case CK_AMDFAM10: |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1555 | case CK_BTVER1: |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1556 | case CK_BDVER1: |
| 1557 | case CK_BDVER2: |
Chandler Carruth | 26a3914 | 2011-09-28 09:45:08 +0000 | [diff] [blame] | 1558 | case CK_x86_64: |
| 1559 | return true; |
| 1560 | } |
Chandler Carruth | 5b7803d | 2011-09-28 10:49:06 +0000 | [diff] [blame] | 1561 | llvm_unreachable("Unhandled CPU kind"); |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 1562 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1563 | }; |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 1564 | |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 1565 | void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const { |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1566 | // FIXME: This should not be here. |
| 1567 | Features["3dnow"] = false; |
| 1568 | Features["3dnowa"] = false; |
| 1569 | Features["mmx"] = false; |
| 1570 | Features["sse"] = false; |
| 1571 | Features["sse2"] = false; |
| 1572 | Features["sse3"] = false; |
| 1573 | Features["ssse3"] = false; |
| 1574 | Features["sse41"] = false; |
| 1575 | Features["sse42"] = false; |
Roman Divacky | 80b32b8 | 2011-10-30 13:47:56 +0000 | [diff] [blame] | 1576 | Features["sse4a"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1577 | Features["aes"] = false; |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1578 | Features["pclmul"] = false; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1579 | Features["avx"] = false; |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1580 | Features["avx2"] = false; |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1581 | Features["lzcnt"] = false; |
| 1582 | Features["bmi"] = false; |
| 1583 | Features["bmi2"] = false; |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1584 | Features["popcnt"] = false; |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1585 | Features["fma4"] = false; |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1586 | Features["fma"] = false; |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1587 | Features["xop"] = false; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1588 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1589 | // FIXME: This *really* should not be here. |
| 1590 | |
| 1591 | // X86_64 always has SSE2. |
| 1592 | if (PointerWidth == 64) |
| 1593 | Features["sse2"] = Features["sse"] = Features["mmx"] = true; |
| 1594 | |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1595 | switch (CPU) { |
| 1596 | case CK_Generic: |
| 1597 | case CK_i386: |
| 1598 | case CK_i486: |
| 1599 | case CK_i586: |
| 1600 | case CK_Pentium: |
| 1601 | case CK_i686: |
| 1602 | case CK_PentiumPro: |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1603 | break; |
| 1604 | case CK_PentiumMMX: |
| 1605 | case CK_Pentium2: |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1606 | setFeatureEnabled(Features, "mmx", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1607 | break; |
| 1608 | case CK_Pentium3: |
| 1609 | case CK_Pentium3M: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1610 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1611 | setFeatureEnabled(Features, "sse", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | case CK_PentiumM: |
| 1614 | case CK_Pentium4: |
| 1615 | case CK_Pentium4M: |
| 1616 | case CK_x86_64: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1617 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1618 | setFeatureEnabled(Features, "sse2", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1619 | break; |
| 1620 | case CK_Yonah: |
| 1621 | case CK_Prescott: |
| 1622 | case CK_Nocona: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1623 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1624 | setFeatureEnabled(Features, "sse3", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1625 | break; |
| 1626 | case CK_Core2: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1627 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1628 | setFeatureEnabled(Features, "ssse3", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | case CK_Penryn: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1631 | setFeatureEnabled(Features, "mmx", true); |
Benjamin Kramer | b3453a8 | 2012-01-04 14:36:57 +0000 | [diff] [blame] | 1632 | setFeatureEnabled(Features, "sse4.1", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1633 | break; |
| 1634 | case CK_Atom: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1635 | setFeatureEnabled(Features, "mmx", true); |
Chandler Carruth | 49defe6 | 2011-09-28 10:36:46 +0000 | [diff] [blame] | 1636 | setFeatureEnabled(Features, "ssse3", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | case CK_Corei7: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1639 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1640 | setFeatureEnabled(Features, "sse4", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | case CK_Corei7AVX: |
| 1643 | case CK_CoreAVXi: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1644 | setFeatureEnabled(Features, "mmx", true); |
Craig Topper | fd93630 | 2012-04-26 07:31:30 +0000 | [diff] [blame] | 1645 | setFeatureEnabled(Features, "avx", true); |
Roman Divacky | bcaa3b8 | 2011-04-05 20:32:44 +0000 | [diff] [blame] | 1646 | setFeatureEnabled(Features, "aes", true); |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1647 | setFeatureEnabled(Features, "pclmul", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1648 | break; |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1649 | case CK_CoreAVX2: |
| 1650 | setFeatureEnabled(Features, "mmx", true); |
Craig Topper | fd93630 | 2012-04-26 07:31:30 +0000 | [diff] [blame] | 1651 | setFeatureEnabled(Features, "avx2", true); |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1652 | setFeatureEnabled(Features, "aes", true); |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1653 | setFeatureEnabled(Features, "pclmul", true); |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1654 | setFeatureEnabled(Features, "lzcnt", true); |
| 1655 | setFeatureEnabled(Features, "bmi", true); |
| 1656 | setFeatureEnabled(Features, "bmi2", true); |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1657 | setFeatureEnabled(Features, "fma", true); |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1658 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1659 | case CK_K6: |
| 1660 | case CK_WinChipC6: |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1661 | setFeatureEnabled(Features, "mmx", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1662 | break; |
| 1663 | case CK_K6_2: |
| 1664 | case CK_K6_3: |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1665 | case CK_WinChip2: |
| 1666 | case CK_C3: |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1667 | setFeatureEnabled(Features, "3dnow", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1668 | break; |
Chandler Carruth | 49defe6 | 2011-09-28 10:36:46 +0000 | [diff] [blame] | 1669 | case CK_Athlon: |
| 1670 | case CK_AthlonThunderbird: |
| 1671 | case CK_Geode: |
| 1672 | setFeatureEnabled(Features, "3dnowa", true); |
| 1673 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1674 | case CK_Athlon4: |
| 1675 | case CK_AthlonXP: |
| 1676 | case CK_AthlonMP: |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1677 | setFeatureEnabled(Features, "sse", true); |
| 1678 | setFeatureEnabled(Features, "3dnowa", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | case CK_K8: |
| 1681 | case CK_Opteron: |
| 1682 | case CK_Athlon64: |
| 1683 | case CK_AthlonFX: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | setFeatureEnabled(Features, "sse2", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1685 | setFeatureEnabled(Features, "3dnowa", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1686 | break; |
| 1687 | case CK_K8SSE3: |
| 1688 | case CK_OpteronSSE3: |
| 1689 | case CK_Athlon64SSE3: |
Roman Divacky | 80b32b8 | 2011-10-30 13:47:56 +0000 | [diff] [blame] | 1690 | setFeatureEnabled(Features, "sse3", true); |
| 1691 | setFeatureEnabled(Features, "3dnowa", true); |
| 1692 | break; |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 1693 | case CK_AMDFAM10: |
Roman Divacky | c8b09a1 | 2010-12-29 13:28:29 +0000 | [diff] [blame] | 1694 | setFeatureEnabled(Features, "sse3", true); |
Roman Divacky | 80b32b8 | 2011-10-30 13:47:56 +0000 | [diff] [blame] | 1695 | setFeatureEnabled(Features, "sse4a", true); |
Roman Divacky | c8b09a1 | 2010-12-29 13:28:29 +0000 | [diff] [blame] | 1696 | setFeatureEnabled(Features, "3dnowa", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1697 | break; |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 1698 | case CK_BTVER1: |
| 1699 | setFeatureEnabled(Features, "ssse3", true); |
| 1700 | setFeatureEnabled(Features, "sse4a", true); |
Craig Topper | 90ea036 | 2012-05-30 05:54:54 +0000 | [diff] [blame] | 1701 | break; |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1702 | case CK_BDVER1: |
| 1703 | case CK_BDVER2: |
Craig Topper | 70d9b16 | 2012-05-01 07:18:03 +0000 | [diff] [blame] | 1704 | setFeatureEnabled(Features, "avx", true); |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1705 | setFeatureEnabled(Features, "xop", true); |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1706 | setFeatureEnabled(Features, "aes", true); |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1707 | setFeatureEnabled(Features, "pclmul", true); |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 1708 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1709 | case CK_C3_2: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1710 | setFeatureEnabled(Features, "mmx", true); |
Daniel Dunbar | 3ac7904 | 2009-05-06 21:56:32 +0000 | [diff] [blame] | 1711 | setFeatureEnabled(Features, "sse", true); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1712 | break; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1713 | } |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1716 | bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features, |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1717 | StringRef Name, |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1718 | bool Enabled) const { |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1719 | // FIXME: This *really* should not be here. We need some way of translating |
| 1720 | // options into llvm subtarget features. |
| 1721 | if (!Features.count(Name) && |
| 1722 | (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1")) |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1723 | return false; |
| 1724 | |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1725 | // FIXME: this should probably use a switch with fall through. |
| 1726 | |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1727 | if (Enabled) { |
| 1728 | if (Name == "mmx") |
| 1729 | Features["mmx"] = true; |
| 1730 | else if (Name == "sse") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1731 | Features["mmx"] = Features["sse"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1732 | else if (Name == "sse2") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1733 | Features["mmx"] = Features["sse"] = Features["sse2"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1734 | else if (Name == "sse3") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1735 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1736 | true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1737 | else if (Name == "ssse3") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1738 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1739 | Features["ssse3"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1740 | else if (Name == "sse4" || Name == "sse4.2") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1741 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1742 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
| 1743 | Features["popcnt"] = true; |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1744 | else if (Name == "sse4.1") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1745 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Eric Christopher | d39ebe2 | 2010-03-04 02:26:37 +0000 | [diff] [blame] | 1746 | Features["ssse3"] = Features["sse41"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1747 | else if (Name == "3dnow") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1748 | Features["mmx"] = Features["3dnow"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1749 | else if (Name == "3dnowa") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1750 | Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1751 | else if (Name == "aes") |
Craig Topper | a7463c3 | 2012-06-03 21:56:22 +0000 | [diff] [blame] | 1752 | Features["sse"] = Features["sse2"] = Features["aes"] = true; |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1753 | else if (Name == "pclmul") |
Craig Topper | a7463c3 | 2012-06-03 21:56:22 +0000 | [diff] [blame] | 1754 | Features["sse"] = Features["sse2"] = Features["pclmul"] = true; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1755 | else if (Name == "avx") |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 1756 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1757 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1758 | Features["popcnt"] = Features["avx"] = true; |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1759 | else if (Name == "avx2") |
| 1760 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1761 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1762 | Features["popcnt"] = Features["avx"] = Features["avx2"] = true; |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1763 | else if (Name == "fma") |
| 1764 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1765 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
| 1766 | Features["popcnt"] = Features["avx"] = Features["fma"] = true; |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1767 | else if (Name == "fma4") |
| 1768 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1769 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
Craig Topper | 90ea036 | 2012-05-30 05:54:54 +0000 | [diff] [blame] | 1770 | Features["popcnt"] = Features["avx"] = Features["sse4a"] = |
| 1771 | Features["fma4"] = true; |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1772 | else if (Name == "xop") |
| 1773 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
| 1774 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
| 1775 | Features["popcnt"] = Features["avx"] = Features["sse4a"] = |
| 1776 | Features["fma4"] = Features["xop"] = true; |
Roman Divacky | 80b32b8 | 2011-10-30 13:47:56 +0000 | [diff] [blame] | 1777 | else if (Name == "sse4a") |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1778 | Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] = |
Craig Topper | 90ea036 | 2012-05-30 05:54:54 +0000 | [diff] [blame] | 1779 | Features["sse4a"] = true; |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1780 | else if (Name == "lzcnt") |
| 1781 | Features["lzcnt"] = true; |
| 1782 | else if (Name == "bmi") |
| 1783 | Features["bmi"] = true; |
| 1784 | else if (Name == "bmi2") |
| 1785 | Features["bmi2"] = true; |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1786 | else if (Name == "popcnt") |
| 1787 | Features["popcnt"] = true; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1788 | } else { |
| 1789 | if (Name == "mmx") |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1790 | Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1791 | else if (Name == "sse") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1792 | Features["sse"] = Features["sse2"] = Features["sse3"] = |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1793 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1794 | Features["sse4a"] = Features["avx"] = Features["avx2"] = |
| 1795 | Features["fma"] = Features["fma4"] = Features["aes"] = |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1796 | Features["pclmul"] = Features["xop"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1797 | else if (Name == "sse2") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | Features["sse2"] = Features["sse3"] = Features["ssse3"] = |
Craig Topper | a7463c3 | 2012-06-03 21:56:22 +0000 | [diff] [blame] | 1799 | Features["sse41"] = Features["sse42"] = Features["sse4a"] = |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1800 | Features["avx"] = Features["avx2"] = Features["fma"] = |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1801 | Features["fma4"] = Features["aes"] = Features["pclmul"] = |
| 1802 | Features["xop"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1803 | else if (Name == "sse3") |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | Features["sse3"] = Features["ssse3"] = Features["sse41"] = |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1805 | Features["sse42"] = Features["sse4a"] = Features["avx"] = |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1806 | Features["avx2"] = Features["fma"] = Features["fma4"] = |
| 1807 | Features["xop"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1808 | else if (Name == "ssse3") |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1809 | Features["ssse3"] = Features["sse41"] = Features["sse42"] = |
| 1810 | Features["avx"] = Features["avx2"] = Features["fma"] = false; |
Michael J. Spencer | b24bac9 | 2011-04-17 19:22:03 +0000 | [diff] [blame] | 1811 | else if (Name == "sse4" || Name == "sse4.1") |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1812 | Features["sse41"] = Features["sse42"] = Features["avx"] = |
| 1813 | Features["avx2"] = Features["fma"] = false; |
Eric Christopher | d41b4ec | 2010-03-04 02:31:44 +0000 | [diff] [blame] | 1814 | else if (Name == "sse4.2") |
Craig Topper | 31380fb | 2012-06-03 22:23:42 +0000 | [diff] [blame] | 1815 | Features["sse42"] = Features["avx"] = Features["avx2"] = |
| 1816 | Features["fma"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1817 | else if (Name == "3dnow") |
| 1818 | Features["3dnow"] = Features["3dnowa"] = false; |
| 1819 | else if (Name == "3dnowa") |
| 1820 | Features["3dnowa"] = false; |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1821 | else if (Name == "aes") |
| 1822 | Features["aes"] = false; |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1823 | else if (Name == "pclmul") |
| 1824 | Features["pclmul"] = false; |
Bruno Cardoso Lopes | 7377ed9 | 2010-08-04 22:29:13 +0000 | [diff] [blame] | 1825 | else if (Name == "avx") |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1826 | Features["avx"] = Features["avx2"] = Features["fma"] = |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1827 | Features["fma4"] = Features["xop"] = false; |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 1828 | else if (Name == "avx2") |
| 1829 | Features["avx2"] = false; |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1830 | else if (Name == "fma") |
| 1831 | Features["fma"] = false; |
Roman Divacky | 80b32b8 | 2011-10-30 13:47:56 +0000 | [diff] [blame] | 1832 | else if (Name == "sse4a") |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1833 | Features["sse4a"] = Features["fma4"] = Features["xop"] = false; |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1834 | else if (Name == "lzcnt") |
| 1835 | Features["lzcnt"] = false; |
| 1836 | else if (Name == "bmi") |
| 1837 | Features["bmi"] = false; |
| 1838 | else if (Name == "bmi2") |
| 1839 | Features["bmi2"] = false; |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1840 | else if (Name == "popcnt") |
| 1841 | Features["popcnt"] = false; |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1842 | else if (Name == "fma4") |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1843 | Features["fma4"] = Features["xop"] = false; |
| 1844 | else if (Name == "xop") |
| 1845 | Features["xop"] = false; |
Daniel Dunbar | 17ca363 | 2009-05-06 21:07:50 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | return true; |
| 1849 | } |
| 1850 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1851 | /// HandleTargetOptions - Perform initialization based on the user |
| 1852 | /// configured set of features. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 1853 | void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1854 | // Remember the maximum enabled sselevel. |
| 1855 | for (unsigned i = 0, e = Features.size(); i !=e; ++i) { |
| 1856 | // Ignore disabled features. |
| 1857 | if (Features[i][0] == '-') |
| 1858 | continue; |
| 1859 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1860 | StringRef Feature = StringRef(Features[i]).substr(1); |
| 1861 | |
| 1862 | if (Feature == "aes") { |
Eric Christopher | eea12d1 | 2010-04-02 23:50:19 +0000 | [diff] [blame] | 1863 | HasAES = true; |
| 1864 | continue; |
| 1865 | } |
| 1866 | |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 1867 | if (Feature == "pclmul") { |
| 1868 | HasPCLMUL = true; |
| 1869 | continue; |
| 1870 | } |
| 1871 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1872 | if (Feature == "lzcnt") { |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1873 | HasLZCNT = true; |
| 1874 | continue; |
| 1875 | } |
| 1876 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1877 | if (Feature == "bmi") { |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1878 | HasBMI = true; |
| 1879 | continue; |
| 1880 | } |
| 1881 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1882 | if (Feature == "bmi2") { |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 1883 | HasBMI2 = true; |
| 1884 | continue; |
| 1885 | } |
| 1886 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1887 | if (Feature == "popcnt") { |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 1888 | HasPOPCNT = true; |
| 1889 | continue; |
| 1890 | } |
| 1891 | |
Benjamin Kramer | 4dfa5ad | 2012-05-29 17:48:39 +0000 | [diff] [blame] | 1892 | if (Feature == "sse4a") { |
| 1893 | HasSSE4a = true; |
| 1894 | continue; |
| 1895 | } |
| 1896 | |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1897 | if (Feature == "fma4") { |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 1898 | HasFMA4 = true; |
| 1899 | continue; |
| 1900 | } |
| 1901 | |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 1902 | if (Feature == "fma") { |
| 1903 | HasFMA = true; |
| 1904 | continue; |
| 1905 | } |
| 1906 | |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 1907 | if (Feature == "xop") { |
| 1908 | HasXOP = true; |
| 1909 | continue; |
| 1910 | } |
| 1911 | |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1912 | assert(Features[i][0] == '+' && "Invalid target feature!"); |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1913 | X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature) |
Craig Topper | 05fe4b5 | 2012-01-09 09:19:09 +0000 | [diff] [blame] | 1914 | .Case("avx2", AVX2) |
| 1915 | .Case("avx", AVX) |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1916 | .Case("sse42", SSE42) |
| 1917 | .Case("sse41", SSE41) |
| 1918 | .Case("ssse3", SSSE3) |
Nuno Lopes | 33d3bca | 2010-03-12 10:20:09 +0000 | [diff] [blame] | 1919 | .Case("sse3", SSE3) |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1920 | .Case("sse2", SSE2) |
| 1921 | .Case("sse", SSE1) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1922 | .Default(NoSSE); |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1923 | SSELevel = std::max(SSELevel, Level); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1924 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1925 | MMX3DNowEnum ThreeDNowLevel = |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 1926 | llvm::StringSwitch<MMX3DNowEnum>(Feature) |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 1927 | .Case("3dnowa", AMD3DNowAthlon) |
| 1928 | .Case("3dnow", AMD3DNow) |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1929 | .Case("mmx", MMX) |
| 1930 | .Default(NoMMX3DNow); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1931 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1932 | MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel); |
Daniel Dunbar | 29a790b | 2009-11-11 09:38:56 +0000 | [diff] [blame] | 1933 | } |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 1934 | |
| 1935 | // Don't tell the backend if we're turning off mmx; it will end up disabling |
| 1936 | // SSE, which we don't want. |
| 1937 | std::vector<std::string>::iterator it; |
| 1938 | it = std::find(Features.begin(), Features.end(), "-mmx"); |
| 1939 | if (it != Features.end()) |
| 1940 | Features.erase(it); |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 1941 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1942 | |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 1943 | /// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro |
| 1944 | /// definitions for this particular subtarget. |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 1945 | void X86TargetInfo::getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1946 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1947 | // Target identification. |
| 1948 | if (PointerWidth == 64) { |
Aaron Ballman | c0765a0 | 2012-03-14 20:50:57 +0000 | [diff] [blame] | 1949 | if (getLongWidth() == 64) { |
| 1950 | Builder.defineMacro("_LP64"); |
| 1951 | Builder.defineMacro("__LP64__"); |
| 1952 | } |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1953 | Builder.defineMacro("__amd64__"); |
| 1954 | Builder.defineMacro("__amd64"); |
| 1955 | Builder.defineMacro("__x86_64"); |
| 1956 | Builder.defineMacro("__x86_64__"); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1957 | } else { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 1958 | DefineStd(Builder, "i386", Opts); |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1959 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 1960 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 1961 | // Subtarget options. |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 1962 | // FIXME: We are hard-coding the tune parameters based on the CPU, but they |
| 1963 | // truly should be based on -mtune options. |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1964 | switch (CPU) { |
| 1965 | case CK_Generic: |
| 1966 | break; |
| 1967 | case CK_i386: |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 1968 | // The rest are coming from the i386 define above. |
| 1969 | Builder.defineMacro("__tune_i386__"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | case CK_i486: |
| 1972 | case CK_WinChipC6: |
| 1973 | case CK_WinChip2: |
| 1974 | case CK_C3: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 1975 | defineCPUMacros(Builder, "i486"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1976 | break; |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 1977 | case CK_PentiumMMX: |
| 1978 | Builder.defineMacro("__pentium_mmx__"); |
| 1979 | Builder.defineMacro("__tune_pentium_mmx__"); |
| 1980 | // Fallthrough |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1981 | case CK_i586: |
| 1982 | case CK_Pentium: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 1983 | defineCPUMacros(Builder, "i586"); |
| 1984 | defineCPUMacros(Builder, "pentium"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1985 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1986 | case CK_Pentium3: |
| 1987 | case CK_Pentium3M: |
| 1988 | case CK_PentiumM: |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 1989 | Builder.defineMacro("__tune_pentium3__"); |
| 1990 | // Fallthrough |
| 1991 | case CK_Pentium2: |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 1992 | case CK_C3_2: |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 1993 | Builder.defineMacro("__tune_pentium2__"); |
| 1994 | // Fallthrough |
| 1995 | case CK_PentiumPro: |
| 1996 | Builder.defineMacro("__tune_i686__"); |
| 1997 | Builder.defineMacro("__tune_pentiumpro__"); |
| 1998 | // Fallthrough |
| 1999 | case CK_i686: |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 2000 | Builder.defineMacro("__i686"); |
| 2001 | Builder.defineMacro("__i686__"); |
| 2002 | // Strangely, __tune_i686__ isn't defined by GCC when CPU == i686. |
| 2003 | Builder.defineMacro("__pentiumpro"); |
| 2004 | Builder.defineMacro("__pentiumpro__"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2005 | break; |
| 2006 | case CK_Pentium4: |
| 2007 | case CK_Pentium4M: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2008 | defineCPUMacros(Builder, "pentium4"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2009 | break; |
| 2010 | case CK_Yonah: |
| 2011 | case CK_Prescott: |
| 2012 | case CK_Nocona: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2013 | defineCPUMacros(Builder, "nocona"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2014 | break; |
| 2015 | case CK_Core2: |
| 2016 | case CK_Penryn: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2017 | defineCPUMacros(Builder, "core2"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | case CK_Atom: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2020 | defineCPUMacros(Builder, "atom"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2021 | break; |
| 2022 | case CK_Corei7: |
| 2023 | case CK_Corei7AVX: |
| 2024 | case CK_CoreAVXi: |
Craig Topper | 2b03bb0 | 2011-12-17 19:55:21 +0000 | [diff] [blame] | 2025 | case CK_CoreAVX2: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2026 | defineCPUMacros(Builder, "corei7"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2027 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2028 | case CK_K6_2: |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 2029 | Builder.defineMacro("__k6_2__"); |
| 2030 | Builder.defineMacro("__tune_k6_2__"); |
| 2031 | // Fallthrough |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2032 | case CK_K6_3: |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 2033 | if (CPU != CK_K6_2) { // In case of fallthrough |
| 2034 | // FIXME: GCC may be enabling these in cases where some other k6 |
| 2035 | // architecture is specified but -m3dnow is explicitly provided. The |
| 2036 | // exact semantics need to be determined and emulated here. |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 2037 | Builder.defineMacro("__k6_3__"); |
| 2038 | Builder.defineMacro("__tune_k6_3__"); |
| 2039 | } |
Chandler Carruth | f17ba33 | 2011-09-28 09:45:05 +0000 | [diff] [blame] | 2040 | // Fallthrough |
| 2041 | case CK_K6: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2042 | defineCPUMacros(Builder, "k6"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | case CK_Athlon: |
| 2045 | case CK_AthlonThunderbird: |
| 2046 | case CK_Athlon4: |
| 2047 | case CK_AthlonXP: |
| 2048 | case CK_AthlonMP: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2049 | defineCPUMacros(Builder, "athlon"); |
Chandler Carruth | 53bf4f9 | 2011-09-28 09:54:11 +0000 | [diff] [blame] | 2050 | if (SSELevel != NoSSE) { |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 2051 | Builder.defineMacro("__athlon_sse__"); |
Chandler Carruth | 53bf4f9 | 2011-09-28 09:54:11 +0000 | [diff] [blame] | 2052 | Builder.defineMacro("__tune_athlon_sse__"); |
| 2053 | } |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2054 | break; |
| 2055 | case CK_K8: |
| 2056 | case CK_K8SSE3: |
| 2057 | case CK_x86_64: |
| 2058 | case CK_Opteron: |
| 2059 | case CK_OpteronSSE3: |
| 2060 | case CK_Athlon64: |
| 2061 | case CK_Athlon64SSE3: |
| 2062 | case CK_AthlonFX: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2063 | defineCPUMacros(Builder, "k8"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2064 | break; |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 2065 | case CK_AMDFAM10: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2066 | defineCPUMacros(Builder, "amdfam10"); |
Roman Divacky | 01c770d | 2011-10-30 07:48:46 +0000 | [diff] [blame] | 2067 | break; |
Benjamin Kramer | 5660aa6 | 2012-01-10 11:50:18 +0000 | [diff] [blame] | 2068 | case CK_BTVER1: |
| 2069 | defineCPUMacros(Builder, "btver1"); |
| 2070 | break; |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 2071 | case CK_BDVER1: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2072 | defineCPUMacros(Builder, "bdver1"); |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 2073 | break; |
| 2074 | case CK_BDVER2: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2075 | defineCPUMacros(Builder, "bdver2"); |
Benjamin Kramer | 61ea4fe | 2011-12-01 18:23:59 +0000 | [diff] [blame] | 2076 | break; |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2077 | case CK_Geode: |
Benjamin Kramer | 448f68d | 2012-01-10 11:50:09 +0000 | [diff] [blame] | 2078 | defineCPUMacros(Builder, "geode"); |
Chandler Carruth | d9d3ddf | 2011-09-28 08:55:37 +0000 | [diff] [blame] | 2079 | break; |
Chandler Carruth | f6cf1c2 | 2011-09-28 02:59:25 +0000 | [diff] [blame] | 2080 | } |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2081 | |
Chandler Carruth | 88c75b0 | 2011-09-28 09:54:07 +0000 | [diff] [blame] | 2082 | // Target properties. |
| 2083 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
| 2084 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 2085 | |
Chris Lattner | 5417544 | 2009-04-19 17:32:33 +0000 | [diff] [blame] | 2086 | // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline |
| 2087 | // functions in glibc header files that use FP Stack inline asm which the |
| 2088 | // backend can't deal with (PR879). |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2089 | Builder.defineMacro("__NO_MATH_INLINES"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2090 | |
Chandler Carruth | 88c75b0 | 2011-09-28 09:54:07 +0000 | [diff] [blame] | 2091 | if (HasAES) |
| 2092 | Builder.defineMacro("__AES__"); |
| 2093 | |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 2094 | if (HasPCLMUL) |
| 2095 | Builder.defineMacro("__PCLMUL__"); |
| 2096 | |
Craig Topper | 31ceea0 | 2011-12-25 05:06:45 +0000 | [diff] [blame] | 2097 | if (HasLZCNT) |
| 2098 | Builder.defineMacro("__LZCNT__"); |
| 2099 | |
| 2100 | if (HasBMI) |
| 2101 | Builder.defineMacro("__BMI__"); |
| 2102 | |
| 2103 | if (HasBMI2) |
| 2104 | Builder.defineMacro("__BMI2__"); |
| 2105 | |
Craig Topper | e14e08b | 2011-12-29 16:10:46 +0000 | [diff] [blame] | 2106 | if (HasPOPCNT) |
| 2107 | Builder.defineMacro("__POPCNT__"); |
| 2108 | |
Benjamin Kramer | 4dfa5ad | 2012-05-29 17:48:39 +0000 | [diff] [blame] | 2109 | if (HasSSE4a) |
| 2110 | Builder.defineMacro("__SSE4A__"); |
| 2111 | |
Craig Topper | 6a511e1 | 2011-12-30 07:33:42 +0000 | [diff] [blame] | 2112 | if (HasFMA4) |
| 2113 | Builder.defineMacro("__FMA4__"); |
| 2114 | |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 2115 | if (HasFMA) |
| 2116 | Builder.defineMacro("__FMA__"); |
| 2117 | |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 2118 | if (HasXOP) |
| 2119 | Builder.defineMacro("__XOP__"); |
| 2120 | |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2121 | // Each case falls through to the previous one here. |
| 2122 | switch (SSELevel) { |
Craig Topper | 05fe4b5 | 2012-01-09 09:19:09 +0000 | [diff] [blame] | 2123 | case AVX2: |
| 2124 | Builder.defineMacro("__AVX2__"); |
| 2125 | case AVX: |
| 2126 | Builder.defineMacro("__AVX__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2127 | case SSE42: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2128 | Builder.defineMacro("__SSE4_2__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2129 | case SSE41: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2130 | Builder.defineMacro("__SSE4_1__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2131 | case SSSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2132 | Builder.defineMacro("__SSSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2133 | case SSE3: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2134 | Builder.defineMacro("__SSE3__"); |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2135 | case SSE2: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2136 | Builder.defineMacro("__SSE2__"); |
| 2137 | Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied. |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2138 | case SSE1: |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2139 | Builder.defineMacro("__SSE__"); |
| 2140 | Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied. |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 2141 | case NoSSE: |
Chris Lattner | 84f0ea8 | 2009-03-02 22:40:39 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | } |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 2144 | |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 2145 | if (Opts.MicrosoftExt && PointerWidth == 32) { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2146 | switch (SSELevel) { |
Craig Topper | 05fe4b5 | 2012-01-09 09:19:09 +0000 | [diff] [blame] | 2147 | case AVX2: |
| 2148 | case AVX: |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2149 | case SSE42: |
| 2150 | case SSE41: |
| 2151 | case SSSE3: |
| 2152 | case SSE3: |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2153 | case SSE2: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2154 | Builder.defineMacro("_M_IX86_FP", Twine(2)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2155 | break; |
| 2156 | case SSE1: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2157 | Builder.defineMacro("_M_IX86_FP", Twine(1)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2158 | break; |
| 2159 | default: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2160 | Builder.defineMacro("_M_IX86_FP", Twine(0)); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 2164 | // Each case falls through to the previous one here. |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 2165 | switch (MMX3DNowLevel) { |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 2166 | case AMD3DNowAthlon: |
| 2167 | Builder.defineMacro("__3dNOW_A__"); |
| 2168 | case AMD3DNow: |
| 2169 | Builder.defineMacro("__3dNOW__"); |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 2170 | case MMX: |
| 2171 | Builder.defineMacro("__MMX__"); |
| 2172 | case NoMMX3DNow: |
Anders Carlsson | 9b0fb62 | 2010-01-27 03:47:49 +0000 | [diff] [blame] | 2173 | break; |
| 2174 | } |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 2175 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2176 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2177 | bool X86TargetInfo::hasFeature(StringRef Feature) const { |
| 2178 | return llvm::StringSwitch<bool>(Feature) |
| 2179 | .Case("aes", HasAES) |
| 2180 | .Case("avx", SSELevel >= AVX) |
| 2181 | .Case("avx2", SSELevel >= AVX2) |
| 2182 | .Case("bmi", HasBMI) |
| 2183 | .Case("bmi2", HasBMI2) |
Craig Topper | 2ae9507 | 2012-06-03 21:46:30 +0000 | [diff] [blame] | 2184 | .Case("fma", HasFMA) |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2185 | .Case("fma4", HasFMA4) |
| 2186 | .Case("lzcnt", HasLZCNT) |
| 2187 | .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow) |
| 2188 | .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon) |
| 2189 | .Case("mmx", MMX3DNowLevel >= MMX) |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 2190 | .Case("pclmul", HasPCLMUL) |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2191 | .Case("popcnt", HasPOPCNT) |
| 2192 | .Case("sse", SSELevel >= SSE1) |
| 2193 | .Case("sse2", SSELevel >= SSE2) |
| 2194 | .Case("sse3", SSELevel >= SSE3) |
| 2195 | .Case("ssse3", SSELevel >= SSSE3) |
| 2196 | .Case("sse41", SSELevel >= SSE41) |
| 2197 | .Case("sse42", SSELevel >= SSE42) |
Craig Topper | 3c0bc15 | 2012-05-31 05:18:48 +0000 | [diff] [blame] | 2198 | .Case("sse4a", HasSSE4a) |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2199 | .Case("x86", true) |
| 2200 | .Case("x86_32", PointerWidth == 32) |
| 2201 | .Case("x86_64", PointerWidth == 64) |
Craig Topper | b6af69e | 2012-06-09 22:24:14 +0000 | [diff] [blame^] | 2202 | .Case("xop", HasXOP) |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2203 | .Default(false); |
| 2204 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2205 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2206 | bool |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2207 | X86TargetInfo::validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 2208 | TargetInfo::ConstraintInfo &Info) const { |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2209 | switch (*Name) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2210 | default: return false; |
Dale Johannesen | 545be51 | 2010-08-24 22:33:12 +0000 | [diff] [blame] | 2211 | case 'Y': // first letter of a pair: |
| 2212 | switch (*(Name+1)) { |
| 2213 | default: return false; |
| 2214 | case '0': // First SSE register. |
| 2215 | case 't': // Any SSE register, when SSE2 is enabled. |
| 2216 | case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled. |
| 2217 | case 'm': // any MMX register, when inter-unit moves enabled. |
| 2218 | break; // falls through to setAllowsRegister. |
| 2219 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2220 | case 'a': // eax. |
| 2221 | case 'b': // ebx. |
| 2222 | case 'c': // ecx. |
| 2223 | case 'd': // edx. |
| 2224 | case 'S': // esi. |
| 2225 | case 'D': // edi. |
| 2226 | case 'A': // edx:eax. |
Dale Johannesen | 545be51 | 2010-08-24 22:33:12 +0000 | [diff] [blame] | 2227 | case 'f': // any x87 floating point stack register. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2228 | case 't': // top of floating point stack. |
| 2229 | case 'u': // second from top of floating point stack. |
| 2230 | 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] | 2231 | case 'y': // Any MMX register. |
Anders Carlsson | a7406d4 | 2008-10-06 19:17:39 +0000 | [diff] [blame] | 2232 | case 'x': // Any SSE register. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2233 | 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] | 2234 | case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp. |
| 2235 | case 'l': // "Index" registers: any general register that can be used as an |
| 2236 | // index in a base+index memory access. |
| 2237 | Info.setAllowsRegister(); |
| 2238 | return true; |
| 2239 | case 'C': // SSE floating point constant. |
| 2240 | case 'G': // x87 floating point constant. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2241 | case 'e': // 32-bit signed integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 2242 | // x86_64 instructions. |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2243 | case 'Z': // 32-bit unsigned integer constant for use with zero-extending |
Anders Carlsson | 79bc64c | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 2244 | // x86_64 instructions. |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2245 | return true; |
| 2246 | } |
| 2247 | } |
| 2248 | |
Dale Johannesen | f6e2c20 | 2010-10-29 23:12:32 +0000 | [diff] [blame] | 2249 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2250 | std::string |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2251 | X86TargetInfo::convertConstraint(const char *&Constraint) const { |
| 2252 | switch (*Constraint) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2253 | case 'a': return std::string("{ax}"); |
| 2254 | case 'b': return std::string("{bx}"); |
| 2255 | case 'c': return std::string("{cx}"); |
| 2256 | case 'd': return std::string("{dx}"); |
| 2257 | case 'S': return std::string("{si}"); |
| 2258 | case 'D': return std::string("{di}"); |
Dale Johannesen | cee5501 | 2010-10-22 21:07:10 +0000 | [diff] [blame] | 2259 | case 'p': // address |
| 2260 | return std::string("im"); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2261 | case 't': // top of floating point stack. |
| 2262 | return std::string("{st}"); |
| 2263 | case 'u': // second from top of floating point stack. |
| 2264 | return std::string("{st(1)}"); // second from top of floating point stack. |
| 2265 | default: |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2266 | return std::string(1, *Constraint); |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2267 | } |
| 2268 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2269 | } // end anonymous namespace |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2270 | |
| 2271 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2272 | // X86-32 generic target |
| 2273 | class X86_32TargetInfo : public X86TargetInfo { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2274 | public: |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2275 | X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { |
| 2276 | DoubleAlign = LongLongAlign = 32; |
| 2277 | LongDoubleWidth = 96; |
| 2278 | LongDoubleAlign = 32; |
Nick Lewycky | 9bddf43 | 2011-12-21 04:25:47 +0000 | [diff] [blame] | 2279 | SuitableAlign = 128; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 2280 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 2281 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
Lang Hames | 567c600 | 2011-10-11 00:52:51 +0000 | [diff] [blame] | 2282 | "a0:0:64-f80:32:32-n8:16:32-S128"; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 2283 | SizeType = UnsignedInt; |
| 2284 | PtrDiffType = SignedInt; |
| 2285 | IntPtrType = SignedInt; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 2286 | RegParmMax = 3; |
Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Use fpret for all types. |
| 2289 | RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) | |
| 2290 | (1 << TargetInfo::Double) | |
| 2291 | (1 << TargetInfo::LongDouble)); |
Eli Friedman | 2be4607 | 2011-10-14 20:59:01 +0000 | [diff] [blame] | 2292 | |
| 2293 | // x86-32 has atomics up to 8 bytes |
| 2294 | // FIXME: Check that we actually have cmpxchg8b before setting |
| 2295 | // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.) |
| 2296 | MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2297 | } |
| 2298 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2299 | return "typedef char* __builtin_va_list;"; |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2300 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2301 | |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 2302 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 2303 | if (RegNo == 0) return 0; |
| 2304 | if (RegNo == 1) return 2; |
| 2305 | return -1; |
| 2306 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2307 | }; |
| 2308 | } // end anonymous namespace |
| 2309 | |
| 2310 | namespace { |
Joerg Sonnenberger | 42378be | 2012-01-06 18:32:26 +0000 | [diff] [blame] | 2311 | class NetBSDI386TargetInfo : public NetBSDTargetInfo<X86_32TargetInfo> { |
| 2312 | public: |
| 2313 | NetBSDI386TargetInfo(const std::string &triple) : |
| 2314 | NetBSDTargetInfo<X86_32TargetInfo>(triple) { |
| 2315 | } |
| 2316 | |
| 2317 | virtual unsigned getFloatEvalMethod() const { |
| 2318 | // NetBSD defaults to "double" rounding |
| 2319 | return 1; |
| 2320 | } |
| 2321 | }; |
| 2322 | } // end anonymous namespace |
| 2323 | |
| 2324 | namespace { |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 2325 | class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> { |
| 2326 | public: |
| 2327 | OpenBSDI386TargetInfo(const std::string& triple) : |
| 2328 | OpenBSDTargetInfo<X86_32TargetInfo>(triple) { |
| 2329 | SizeType = UnsignedLong; |
| 2330 | IntPtrType = SignedLong; |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 2331 | PtrDiffType = SignedLong; |
Eli Friedman | 624c146 | 2009-07-05 18:47:56 +0000 | [diff] [blame] | 2332 | } |
| 2333 | }; |
| 2334 | } // end anonymous namespace |
| 2335 | |
| 2336 | namespace { |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2337 | class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2338 | public: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 2339 | DarwinI386TargetInfo(const std::string& triple) : |
| 2340 | DarwinTargetInfo<X86_32TargetInfo>(triple) { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2341 | LongDoubleWidth = 128; |
| 2342 | LongDoubleAlign = 128; |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 2343 | SuitableAlign = 128; |
Eli Friedman | 1afabd9 | 2009-03-29 20:31:09 +0000 | [diff] [blame] | 2344 | SizeType = UnsignedLong; |
| 2345 | IntPtrType = SignedLong; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 2346 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 2347 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2348 | "a0:0:64-f80:128:128-n8:16:32-S128"; |
Daniel Dunbar | 613fd67 | 2010-05-27 00:35:16 +0000 | [diff] [blame] | 2349 | HasAlignMac68kSupport = true; |
Torok Edwin | b0a5b24 | 2009-06-30 17:00:25 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2352 | }; |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2353 | } // end anonymous namespace |
| 2354 | |
| 2355 | namespace { |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 2356 | // x86-32 Windows target |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2357 | class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> { |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 2358 | public: |
| 2359 | WindowsX86_32TargetInfo(const std::string& triple) |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2360 | : WindowsTargetInfo<X86_32TargetInfo>(triple) { |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 2361 | TLSSupported = false; |
Chris Lattner | 85de9e7 | 2009-06-24 17:12:15 +0000 | [diff] [blame] | 2362 | WCharType = UnsignedShort; |
Eli Friedman | 9c2f84e | 2009-06-08 21:16:17 +0000 | [diff] [blame] | 2363 | DoubleAlign = LongLongAlign = 64; |
| 2364 | 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] | 2365 | "i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2366 | "v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"; |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 2367 | } |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2368 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2369 | MacroBuilder &Builder) const { |
| 2370 | WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder); |
| 2371 | } |
| 2372 | }; |
| 2373 | } // end anonymous namespace |
| 2374 | |
| 2375 | namespace { |
| 2376 | |
| 2377 | // x86-32 Windows Visual Studio target |
| 2378 | class VisualStudioWindowsX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 2379 | public: |
| 2380 | VisualStudioWindowsX86_32TargetInfo(const std::string& triple) |
| 2381 | : WindowsX86_32TargetInfo(triple) { |
Eli Friedman | d9c3fa3 | 2011-03-22 21:25:11 +0000 | [diff] [blame] | 2382 | LongDoubleWidth = LongDoubleAlign = 64; |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2383 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
| 2384 | } |
| 2385 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2386 | MacroBuilder &Builder) const { |
| 2387 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 2388 | WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder); |
| 2389 | // The value of the following reflects processor type. |
| 2390 | // 300=386, 400=486, 500=Pentium, 600=Blend (default) |
| 2391 | // We lost the original triple, so we use the default. |
| 2392 | Builder.defineMacro("_M_IX86", "600"); |
| 2393 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2394 | }; |
| 2395 | } // end anonymous namespace |
| 2396 | |
| 2397 | namespace { |
| 2398 | // x86-32 MinGW target |
| 2399 | class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo { |
| 2400 | public: |
| 2401 | MinGWX86_32TargetInfo(const std::string& triple) |
| 2402 | : WindowsX86_32TargetInfo(triple) { |
| 2403 | } |
| 2404 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2405 | MacroBuilder &Builder) const { |
| 2406 | WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2407 | DefineStd(Builder, "WIN32", Opts); |
| 2408 | DefineStd(Builder, "WINNT", Opts); |
| 2409 | Builder.defineMacro("_X86_"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2410 | Builder.defineMacro("__MSVCRT__"); |
| 2411 | Builder.defineMacro("__MINGW32__"); |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 2412 | |
| 2413 | // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). |
| 2414 | // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 2415 | if (Opts.MicrosoftExt) |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 2416 | // Provide "as-is" __declspec. |
| 2417 | Builder.defineMacro("__declspec", "__declspec"); |
| 2418 | else |
| 2419 | // Provide alias of __attribute__ like mingw32-gcc. |
| 2420 | Builder.defineMacro("__declspec(a)", "__attribute__((a))"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2421 | } |
| 2422 | }; |
| 2423 | } // end anonymous namespace |
| 2424 | |
| 2425 | namespace { |
| 2426 | // x86-32 Cygwin target |
| 2427 | class CygwinX86_32TargetInfo : public X86_32TargetInfo { |
| 2428 | public: |
| 2429 | CygwinX86_32TargetInfo(const std::string& triple) |
| 2430 | : X86_32TargetInfo(triple) { |
| 2431 | TLSSupported = false; |
| 2432 | WCharType = UnsignedShort; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2433 | DoubleAlign = LongLongAlign = 64; |
| 2434 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 2435 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2436 | "a0:0:64-f80:32:32-n8:16:32-S32"; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2437 | } |
| 2438 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2439 | MacroBuilder &Builder) const { |
| 2440 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 2441 | Builder.defineMacro("__CYGWIN__"); |
| 2442 | Builder.defineMacro("__CYGWIN32__"); |
| 2443 | DefineStd(Builder, "unix", Opts); |
Douglas Gregor | 2b003fd | 2010-04-21 05:52:38 +0000 | [diff] [blame] | 2444 | if (Opts.CPlusPlus) |
| 2445 | Builder.defineMacro("_GNU_SOURCE"); |
Eli Friedman | abc4e32 | 2009-06-08 06:11:14 +0000 | [diff] [blame] | 2446 | } |
Eli Friedman | 29a3050 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 2447 | }; |
| 2448 | } // end anonymous namespace |
| 2449 | |
| 2450 | namespace { |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 2451 | // x86-32 Haiku target |
| 2452 | class HaikuX86_32TargetInfo : public X86_32TargetInfo { |
| 2453 | public: |
| 2454 | HaikuX86_32TargetInfo(const std::string& triple) |
| 2455 | : X86_32TargetInfo(triple) { |
| 2456 | SizeType = UnsignedLong; |
Chris Lattner | fe1ea7b | 2010-04-22 17:48:00 +0000 | [diff] [blame] | 2457 | IntPtrType = SignedLong; |
| 2458 | PtrDiffType = SignedLong; |
Rafael Espindola | 19ddda8 | 2010-11-09 16:41:02 +0000 | [diff] [blame] | 2459 | this->UserLabelPrefix = ""; |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 2460 | } |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 2461 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2462 | MacroBuilder &Builder) const { |
| 2463 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 2464 | Builder.defineMacro("__INTEL__"); |
| 2465 | Builder.defineMacro("__HAIKU__"); |
| 2466 | } |
| 2467 | }; |
| 2468 | } // end anonymous namespace |
| 2469 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 2470 | // RTEMS Target |
| 2471 | template<typename Target> |
| 2472 | class RTEMSTargetInfo : public OSTargetInfo<Target> { |
| 2473 | protected: |
| 2474 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 2475 | MacroBuilder &Builder) const { |
| 2476 | // RTEMS defines; list based off of gcc output |
| 2477 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 2478 | Builder.defineMacro("__rtems__"); |
| 2479 | Builder.defineMacro("__ELF__"); |
| 2480 | } |
| 2481 | public: |
| 2482 | RTEMSTargetInfo(const std::string &triple) |
| 2483 | : OSTargetInfo<Target>(triple) { |
| 2484 | this->UserLabelPrefix = ""; |
| 2485 | |
| 2486 | llvm::Triple Triple(triple); |
| 2487 | switch (Triple.getArch()) { |
| 2488 | default: |
| 2489 | case llvm::Triple::x86: |
| 2490 | // this->MCountName = ".mcount"; |
| 2491 | break; |
| 2492 | case llvm::Triple::mips: |
| 2493 | case llvm::Triple::mipsel: |
| 2494 | case llvm::Triple::ppc: |
| 2495 | case llvm::Triple::ppc64: |
| 2496 | // this->MCountName = "_mcount"; |
| 2497 | break; |
| 2498 | case llvm::Triple::arm: |
| 2499 | // this->MCountName = "__mcount"; |
| 2500 | break; |
| 2501 | } |
| 2502 | |
| 2503 | } |
| 2504 | }; |
| 2505 | |
| 2506 | namespace { |
| 2507 | // x86-32 RTEMS target |
| 2508 | class RTEMSX86_32TargetInfo : public X86_32TargetInfo { |
| 2509 | public: |
| 2510 | RTEMSX86_32TargetInfo(const std::string& triple) |
| 2511 | : X86_32TargetInfo(triple) { |
| 2512 | SizeType = UnsignedLong; |
| 2513 | IntPtrType = SignedLong; |
| 2514 | PtrDiffType = SignedLong; |
| 2515 | this->UserLabelPrefix = ""; |
| 2516 | } |
| 2517 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2518 | MacroBuilder &Builder) const { |
| 2519 | X86_32TargetInfo::getTargetDefines(Opts, Builder); |
| 2520 | Builder.defineMacro("__INTEL__"); |
| 2521 | Builder.defineMacro("__rtems__"); |
| 2522 | } |
| 2523 | }; |
| 2524 | } // end anonymous namespace |
| 2525 | |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 2526 | namespace { |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2527 | // x86-64 generic target |
| 2528 | class X86_64TargetInfo : public X86TargetInfo { |
| 2529 | public: |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 2530 | X86_64TargetInfo(const std::string &triple) : X86TargetInfo(triple) { |
Chris Lattner | f291b10 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 2531 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2532 | LongDoubleWidth = 128; |
| 2533 | LongDoubleAlign = 128; |
Rafael Espindola | 6deecb0 | 2010-06-04 23:15:27 +0000 | [diff] [blame] | 2534 | LargeArrayMinWidth = 128; |
| 2535 | LargeArrayAlign = 128; |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 2536 | SuitableAlign = 128; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 2537 | IntMaxType = SignedLong; |
| 2538 | UIntMaxType = UnsignedLong; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 2539 | Int64Type = SignedLong; |
Anton Korobeynikov | 264a76c | 2009-04-03 23:38:25 +0000 | [diff] [blame] | 2540 | RegParmMax = 6; |
Chris Lattner | 06ebe86 | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 2541 | |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 2542 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 2543 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2544 | "a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"; |
Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 2545 | |
| 2546 | // Use fpret only for long double. |
| 2547 | RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble); |
Eli Friedman | 2be4607 | 2011-10-14 20:59:01 +0000 | [diff] [blame] | 2548 | |
Anders Carlsson | eea6480 | 2011-10-31 16:27:11 +0000 | [diff] [blame] | 2549 | // Use fp2ret for _Complex long double. |
| 2550 | ComplexLongDoubleUsesFP2Ret = true; |
| 2551 | |
Eli Friedman | 2be4607 | 2011-10-14 20:59:01 +0000 | [diff] [blame] | 2552 | // x86-64 has atomics up to 16 bytes. |
| 2553 | // FIXME: Once the backend is fixed, increase MaxAtomicInlineWidth to 128 |
| 2554 | // on CPUs with cmpxchg16b |
| 2555 | MaxAtomicPromoteWidth = 128; |
| 2556 | MaxAtomicInlineWidth = 64; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2557 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 2558 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 2559 | return "typedef struct __va_list_tag {" |
| 2560 | " unsigned gp_offset;" |
| 2561 | " unsigned fp_offset;" |
| 2562 | " void* overflow_arg_area;" |
| 2563 | " void* reg_save_area;" |
John McCall | 2b7baf0 | 2010-05-28 18:25:28 +0000 | [diff] [blame] | 2564 | "} __va_list_tag;" |
Eli Friedman | dc04316 | 2009-07-03 00:45:06 +0000 | [diff] [blame] | 2565 | "typedef __va_list_tag __builtin_va_list[1];"; |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 2566 | } |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 2567 | |
Chris Lattner | 21fb98e | 2009-09-23 06:06:36 +0000 | [diff] [blame] | 2568 | int getEHDataRegisterNumber(unsigned RegNo) const { |
| 2569 | if (RegNo == 0) return 0; |
| 2570 | if (RegNo == 1) return 1; |
| 2571 | return -1; |
| 2572 | } |
Eli Friedman | 618234a | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 2573 | }; |
| 2574 | } // end anonymous namespace |
| 2575 | |
| 2576 | namespace { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2577 | // x86-64 Windows target |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2578 | class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2579 | public: |
| 2580 | WindowsX86_64TargetInfo(const std::string& triple) |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2581 | : WindowsTargetInfo<X86_64TargetInfo>(triple) { |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2582 | TLSSupported = false; |
| 2583 | WCharType = UnsignedShort; |
Mike Stump | a55cce8 | 2009-10-08 23:00:00 +0000 | [diff] [blame] | 2584 | LongWidth = LongAlign = 32; |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 2585 | DoubleAlign = LongLongAlign = 64; |
Nate Begeman | dbf8ea4 | 2010-07-21 02:02:56 +0000 | [diff] [blame] | 2586 | IntMaxType = SignedLongLong; |
| 2587 | UIntMaxType = UnsignedLongLong; |
| 2588 | Int64Type = SignedLongLong; |
Cameron Esfahani | 1484e0d | 2010-09-15 00:28:12 +0000 | [diff] [blame] | 2589 | SizeType = UnsignedLongLong; |
| 2590 | PtrDiffType = SignedLongLong; |
| 2591 | IntPtrType = SignedLongLong; |
NAKAMURA Takumi | 8c959d9 | 2011-01-17 22:56:08 +0000 | [diff] [blame] | 2592 | this->UserLabelPrefix = ""; |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2593 | } |
| 2594 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2595 | MacroBuilder &Builder) const { |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2596 | WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2597 | Builder.defineMacro("_WIN64"); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2598 | } |
NAKAMURA Takumi | 7952199 | 2011-01-17 22:56:23 +0000 | [diff] [blame] | 2599 | virtual const char *getVAListDeclaration() const { |
| 2600 | return "typedef char* __builtin_va_list;"; |
| 2601 | } |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2602 | }; |
| 2603 | } // end anonymous namespace |
| 2604 | |
| 2605 | namespace { |
| 2606 | // x86-64 Windows Visual Studio target |
| 2607 | class VisualStudioWindowsX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 2608 | public: |
| 2609 | VisualStudioWindowsX86_64TargetInfo(const std::string& triple) |
| 2610 | : WindowsX86_64TargetInfo(triple) { |
Eli Friedman | d9c3fa3 | 2011-03-22 21:25:11 +0000 | [diff] [blame] | 2611 | LongDoubleWidth = LongDoubleAlign = 64; |
| 2612 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2613 | } |
| 2614 | virtual void getTargetDefines(const LangOptions &Opts, |
| 2615 | MacroBuilder &Builder) const { |
| 2616 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
| 2617 | WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2618 | Builder.defineMacro("_M_X64"); |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 2619 | Builder.defineMacro("_M_AMD64"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2620 | } |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2621 | }; |
| 2622 | } // end anonymous namespace |
| 2623 | |
| 2624 | namespace { |
| 2625 | // x86-64 MinGW target |
| 2626 | class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo { |
| 2627 | public: |
| 2628 | MinGWX86_64TargetInfo(const std::string& triple) |
| 2629 | : WindowsX86_64TargetInfo(triple) { |
| 2630 | } |
| 2631 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2632 | MacroBuilder &Builder) const { |
| 2633 | WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder); |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 2634 | DefineStd(Builder, "WIN64", Opts); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2635 | Builder.defineMacro("__MSVCRT__"); |
NAKAMURA Takumi | 17c964a | 2011-03-08 12:06:46 +0000 | [diff] [blame] | 2636 | Builder.defineMacro("__MINGW32__"); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2637 | Builder.defineMacro("__MINGW64__"); |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 2638 | |
| 2639 | // mingw32-gcc provides __declspec(a) as alias of __attribute__((a)). |
| 2640 | // In contrast, clang-cc1 provides __declspec(a) with -fms-extensions. |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 2641 | if (Opts.MicrosoftExt) |
NAKAMURA Takumi | 853134a | 2011-03-15 02:32:50 +0000 | [diff] [blame] | 2642 | // Provide "as-is" __declspec. |
| 2643 | Builder.defineMacro("__declspec", "__declspec"); |
| 2644 | else |
| 2645 | // Provide alias of __attribute__ like mingw32-gcc. |
| 2646 | Builder.defineMacro("__declspec(a)", "__attribute__((a))"); |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 2647 | } |
| 2648 | }; |
| 2649 | } // end anonymous namespace |
| 2650 | |
| 2651 | namespace { |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 2652 | class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> { |
| 2653 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2654 | DarwinX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 2655 | : DarwinTargetInfo<X86_64TargetInfo>(triple) { |
| 2656 | Int64Type = SignedLongLong; |
| 2657 | } |
| 2658 | }; |
| 2659 | } // end anonymous namespace |
| 2660 | |
| 2661 | namespace { |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 2662 | class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> { |
| 2663 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2664 | OpenBSDX86_64TargetInfo(const std::string& triple) |
Eli Friedman | 6036ebe | 2009-07-05 22:31:18 +0000 | [diff] [blame] | 2665 | : OpenBSDTargetInfo<X86_64TargetInfo>(triple) { |
| 2666 | IntMaxType = SignedLongLong; |
| 2667 | UIntMaxType = UnsignedLongLong; |
| 2668 | Int64Type = SignedLongLong; |
| 2669 | } |
| 2670 | }; |
| 2671 | } // end anonymous namespace |
| 2672 | |
| 2673 | namespace { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2674 | class ARMTargetInfo : public TargetInfo { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2675 | // Possible FPU choices. |
| 2676 | enum FPUMode { |
| 2677 | NoFPU, |
| 2678 | VFP2FPU, |
| 2679 | VFP3FPU, |
| 2680 | NeonFPU |
| 2681 | }; |
| 2682 | |
| 2683 | static bool FPUModeIsVFP(FPUMode Mode) { |
| 2684 | return Mode >= VFP2FPU && Mode <= NeonFPU; |
| 2685 | } |
| 2686 | |
| 2687 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 2688 | static const char * const GCCRegNames[]; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2689 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2690 | std::string ABI, CPU; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2691 | |
| 2692 | unsigned FPU : 3; |
| 2693 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2694 | unsigned IsThumb : 1; |
| 2695 | |
| 2696 | // Initialized via features. |
| 2697 | unsigned SoftFloat : 1; |
| 2698 | unsigned SoftFloatABI : 1; |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 2699 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2700 | static const Builtin::Info BuiltinInfo[]; |
| 2701 | |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2702 | public: |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2703 | ARMTargetInfo(const std::string &TripleStr) |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2704 | : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s") |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 2705 | { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 2706 | BigEndian = false; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2707 | SizeType = UnsignedInt; |
| 2708 | PtrDiffType = SignedInt; |
James Molloy | a6d81f9 | 2011-11-23 13:35:08 +0000 | [diff] [blame] | 2709 | // AAPCS 7.1.1, ARM-Linux ABI 2.4: type of wchar_t is unsigned int. |
| 2710 | WCharType = UnsignedInt; |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2711 | |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 2712 | // {} in inline assembly are neon specifiers, not assembly variant |
| 2713 | // specifiers. |
| 2714 | NoAsmVariants = true; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2715 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2716 | // FIXME: Should we just treat this as a feature? |
Daniel Dunbar | 0791aa5 | 2009-12-18 19:57:13 +0000 | [diff] [blame] | 2717 | IsThumb = getTriple().getArchName().startswith("thumb"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2718 | if (IsThumb) { |
Sandeep Patel | 3a41d14 | 2011-04-04 22:58:12 +0000 | [diff] [blame] | 2719 | // Thumb1 add sp, #imm requires the immediate value be multiple of 4, |
| 2720 | // so set preferred for small types to 32. |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2721 | DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-" |
| 2722 | "i64:64:64-f32:32:32-f64:64:64-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2723 | "v64:64:64-v128:64:128-a0:0:32-n32-S64"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2724 | } else { |
| 2725 | DescriptionString = ("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 2726 | "i64:64:64-f32:32:32-f64:64:64-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2727 | "v64:64:64-v128:64:128-a0:0:64-n32-S64"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2728 | } |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 2729 | |
| 2730 | // ARM targets default to using the ARM C++ ABI. |
| 2731 | CXXABI = CXXABI_ARM; |
Eli Friedman | 2be4607 | 2011-10-14 20:59:01 +0000 | [diff] [blame] | 2732 | |
| 2733 | // ARM has atomics up to 8 bytes |
| 2734 | // FIXME: Set MaxAtomicInlineWidth if we have the feature v6e |
| 2735 | MaxAtomicPromoteWidth = 64; |
James Molloy | e45b9b7 | 2012-03-12 09:14:10 +0000 | [diff] [blame] | 2736 | |
| 2737 | // Do force alignment of members that follow zero length bitfields. If |
| 2738 | // the alignment of the zero-length bitfield is greater than the member |
| 2739 | // that follows it, `bar', `bar' will be aligned as the type of the |
| 2740 | // zero length bitfield. |
| 2741 | UseZeroLengthBitfieldAlignment = true; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 2742 | } |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 2743 | virtual const char *getABI() const { return ABI.c_str(); } |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2744 | virtual bool setABI(const std::string &Name) { |
Daniel Dunbar | 018ba5a | 2009-09-14 00:35:03 +0000 | [diff] [blame] | 2745 | ABI = Name; |
| 2746 | |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2747 | // The defaults (above) are for AAPCS, check if we need to change them. |
| 2748 | // |
| 2749 | // FIXME: We need support for -meabi... we could just mangle it into the |
| 2750 | // name. |
| 2751 | if (Name == "apcs-gnu") { |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 2752 | DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2753 | SizeType = UnsignedLong; |
| 2754 | |
James Molloy | a6d81f9 | 2011-11-23 13:35:08 +0000 | [diff] [blame] | 2755 | // Revert to using SignedInt on apcs-gnu to comply with existing behaviour. |
| 2756 | WCharType = SignedInt; |
| 2757 | |
Daniel Dunbar | 684de63 | 2010-04-22 16:14:54 +0000 | [diff] [blame] | 2758 | // Do not respect the alignment of bit-field types when laying out |
| 2759 | // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc. |
| 2760 | UseBitFieldTypeAlignment = false; |
| 2761 | |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 2762 | /// 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] | 2763 | /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in |
| 2764 | /// gcc. |
Chad Rosier | 61a6221 | 2011-08-04 01:21:14 +0000 | [diff] [blame] | 2765 | ZeroLengthBitfieldBoundary = 32; |
| 2766 | |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2767 | if (IsThumb) { |
Sandeep Patel | 3a41d14 | 2011-04-04 22:58:12 +0000 | [diff] [blame] | 2768 | // Thumb1 add sp, #imm requires the immediate value be multiple of 4, |
| 2769 | // so set preferred for small types to 32. |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2770 | 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] | 2771 | "i64:32:64-f32:32:32-f64:32:64-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2772 | "v64:32:64-v128:32:128-a0:0:32-n32-S32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2773 | } else { |
| 2774 | 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] | 2775 | "i64:32:64-f32:32:32-f64:32:64-" |
Lang Hames | f4f5003 | 2011-10-10 23:44:43 +0000 | [diff] [blame] | 2776 | "v64:32:64-v128:32:128-a0:0:32-n32-S32"); |
Daniel Dunbar | dff10dc | 2009-09-22 21:44:58 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
Chad Rosier | 9f1210c | 2011-07-26 07:03:04 +0000 | [diff] [blame] | 2779 | // FIXME: Override "preferred align" for double and long long. |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2780 | } else if (Name == "aapcs") { |
| 2781 | // FIXME: Enumerated types are variable width in straight AAPCS. |
| 2782 | } else if (Name == "aapcs-linux") { |
Chad Rosier | 9f1210c | 2011-07-26 07:03:04 +0000 | [diff] [blame] | 2783 | ; |
Daniel Dunbar | a2a4161 | 2009-09-14 00:02:24 +0000 | [diff] [blame] | 2784 | } else |
| 2785 | return false; |
| 2786 | |
| 2787 | return true; |
| 2788 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2789 | |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 2790 | void getDefaultFeatures(llvm::StringMap<bool> &Features) const { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2791 | if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore") |
| 2792 | Features["vfp2"] = true; |
| 2793 | else if (CPU == "cortex-a8" || CPU == "cortex-a9") |
| 2794 | Features["neon"] = true; |
| 2795 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2796 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2797 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 2798 | StringRef Name, |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2799 | bool Enabled) const { |
Evan Cheng | f972b26 | 2011-07-08 06:40:11 +0000 | [diff] [blame] | 2800 | if (Name == "soft-float" || Name == "soft-float-abi" || |
Chad Rosier | 7a938fa | 2012-04-04 20:39:32 +0000 | [diff] [blame] | 2801 | Name == "vfp2" || Name == "vfp3" || Name == "neon" || Name == "d16" || |
| 2802 | Name == "neonfp") { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2803 | Features[Name] = Enabled; |
| 2804 | } else |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2805 | return false; |
| 2806 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2807 | return true; |
| 2808 | } |
| 2809 | |
| 2810 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2811 | FPU = NoFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2812 | SoftFloat = SoftFloatABI = false; |
| 2813 | for (unsigned i = 0, e = Features.size(); i != e; ++i) { |
| 2814 | if (Features[i] == "+soft-float") |
| 2815 | SoftFloat = true; |
| 2816 | else if (Features[i] == "+soft-float-abi") |
| 2817 | SoftFloatABI = true; |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2818 | else if (Features[i] == "+vfp2") |
| 2819 | FPU = VFP2FPU; |
| 2820 | else if (Features[i] == "+vfp3") |
| 2821 | FPU = VFP3FPU; |
| 2822 | else if (Features[i] == "+neon") |
| 2823 | FPU = NeonFPU; |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | // Remove front-end specific options which the backend handles differently. |
| 2827 | std::vector<std::string>::iterator it; |
| 2828 | it = std::find(Features.begin(), Features.end(), "+soft-float"); |
| 2829 | if (it != Features.end()) |
| 2830 | Features.erase(it); |
| 2831 | it = std::find(Features.begin(), Features.end(), "+soft-float-abi"); |
| 2832 | if (it != Features.end()) |
| 2833 | Features.erase(it); |
| 2834 | } |
| 2835 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 2836 | virtual bool hasFeature(StringRef Feature) const { |
| 2837 | return llvm::StringSwitch<bool>(Feature) |
| 2838 | .Case("arm", true) |
| 2839 | .Case("softfloat", SoftFloat) |
| 2840 | .Case("thumb", IsThumb) |
| 2841 | .Case("neon", FPU == NeonFPU && !SoftFloat && |
| 2842 | StringRef(getCPUDefineSuffix(CPU)).startswith("7")) |
| 2843 | .Default(false); |
| 2844 | } |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2845 | static const char *getCPUDefineSuffix(StringRef Name) { |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2846 | return llvm::StringSwitch<const char*>(Name) |
| 2847 | .Cases("arm8", "arm810", "4") |
| 2848 | .Cases("strongarm", "strongarm110", "strongarm1100", "strongarm1110", "4") |
| 2849 | .Cases("arm7tdmi", "arm7tdmi-s", "arm710t", "arm720t", "arm9", "4T") |
| 2850 | .Cases("arm9tdmi", "arm920", "arm920t", "arm922t", "arm940t", "4T") |
| 2851 | .Case("ep9312", "4T") |
| 2852 | .Cases("arm10tdmi", "arm1020t", "5T") |
| 2853 | .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "5TE") |
| 2854 | .Case("arm926ej-s", "5TEJ") |
| 2855 | .Cases("arm10e", "arm1020e", "arm1022e", "5TE") |
| 2856 | .Cases("xscale", "iwmmxt", "5TE") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2857 | .Case("arm1136j-s", "6J") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2858 | .Cases("arm1176jz-s", "arm1176jzf-s", "6ZK") |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2859 | .Cases("arm1136jf-s", "mpcorenovfp", "mpcore", "6K") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2860 | .Cases("arm1156t2-s", "arm1156t2f-s", "6T2") |
| 2861 | .Cases("cortex-a8", "cortex-a9", "7A") |
Bob Wilson | 06f4563 | 2011-01-06 16:57:20 +0000 | [diff] [blame] | 2862 | .Case("cortex-m3", "7M") |
Jim Grosbach | 6903313 | 2012-03-29 19:53:34 +0000 | [diff] [blame] | 2863 | .Case("cortex-m4", "7M") |
Bob Wilson | a291d5f | 2011-03-21 21:55:25 +0000 | [diff] [blame] | 2864 | .Case("cortex-m0", "6M") |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2865 | .Default(0); |
| 2866 | } |
| 2867 | virtual bool setCPU(const std::string &Name) { |
| 2868 | if (!getCPUDefineSuffix(Name)) |
| 2869 | return false; |
| 2870 | |
| 2871 | CPU = Name; |
| 2872 | return true; |
| 2873 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 2874 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2875 | MacroBuilder &Builder) const { |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 2876 | // Target identification. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2877 | Builder.defineMacro("__arm"); |
| 2878 | Builder.defineMacro("__arm__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2879 | |
Chris Lattner | c0f5921 | 2009-03-02 22:27:17 +0000 | [diff] [blame] | 2880 | // Target properties. |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2881 | Builder.defineMacro("__ARMEL__"); |
| 2882 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
| 2883 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2884 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2885 | StringRef CPUArch = getCPUDefineSuffix(CPU); |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2886 | Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__"); |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2887 | |
Mike Stump | 437bb4b | 2009-04-08 02:07:04 +0000 | [diff] [blame] | 2888 | // Subtarget options. |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2889 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2890 | // FIXME: It's more complicated than this and we don't really support |
| 2891 | // interworking. |
| 2892 | if ('5' <= CPUArch[0] && CPUArch[0] <= '7') |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2893 | Builder.defineMacro("__THUMB_INTERWORK__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2894 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2895 | if (ABI == "aapcs" || ABI == "aapcs-linux") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2896 | Builder.defineMacro("__ARM_EABI__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2897 | |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 2898 | if (SoftFloat) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2899 | Builder.defineMacro("__SOFTFP__"); |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 2900 | |
| 2901 | if (CPU == "xscale") |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2902 | Builder.defineMacro("__XSCALE__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2903 | |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2904 | bool IsARMv7 = CPUArch.startswith("7"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2905 | if (IsThumb) { |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2906 | Builder.defineMacro("__THUMBEL__"); |
| 2907 | Builder.defineMacro("__thumb__"); |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2908 | if (CPUArch == "6T2" || IsARMv7) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2909 | Builder.defineMacro("__thumb2__"); |
Daniel Dunbar | e1f63b3 | 2009-09-17 16:21:10 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | // 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] | 2913 | Builder.defineMacro("__APCS_32__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2914 | |
| 2915 | if (FPUModeIsVFP((FPUMode) FPU)) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2916 | Builder.defineMacro("__VFP_FP__"); |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 2917 | |
| 2918 | // This only gets set when Neon instructions are actually available, unlike |
| 2919 | // the VFP define, hence the soft float and arch check. This is subtly |
| 2920 | // different from gcc, we follow the intent which was that it should be set |
| 2921 | // when Neon instructions are actually available. |
Bob Wilson | 84f95cf | 2011-05-13 18:56:03 +0000 | [diff] [blame] | 2922 | if (FPU == NeonFPU && !SoftFloat && IsARMv7) |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 2923 | Builder.defineMacro("__ARM_NEON__"); |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2924 | } |
| 2925 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 2926 | unsigned &NumRecords) const { |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2927 | Records = BuiltinInfo; |
| 2928 | NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2929 | } |
Bob Wilson | 8b30a93 | 2012-01-26 22:14:27 +0000 | [diff] [blame] | 2930 | virtual bool isCLZForZeroUndef() const { return false; } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2931 | virtual const char *getVAListDeclaration() const { |
John McCall | 0e9972c | 2011-05-09 02:19:37 +0000 | [diff] [blame] | 2932 | return "typedef void* __builtin_va_list;"; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2933 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2934 | virtual void getGCCRegNames(const char * const *&Names, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2935 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 2936 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2937 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2938 | virtual bool validateAsmConstraint(const char *&Name, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 2939 | TargetInfo::ConstraintInfo &Info) const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2940 | // FIXME: Check if this is complete |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 2941 | switch (*Name) { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2942 | default: |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2943 | case 'l': // r0-r7 |
| 2944 | case 'h': // r8-r15 |
| 2945 | case 'w': // VFP Floating point register single precision |
| 2946 | case 'P': // VFP Floating point register double precision |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 2947 | Info.setAllowsRegister(); |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2948 | return true; |
Eric Christopher | 895d422 | 2011-07-29 21:20:35 +0000 | [diff] [blame] | 2949 | case 'Q': // A memory address that is a single base register. |
| 2950 | Info.setAllowsMemory(); |
| 2951 | return true; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2952 | case 'U': // a memory reference... |
| 2953 | switch (Name[1]) { |
| 2954 | case 'q': // ...ARMV4 ldrsb |
| 2955 | case 'v': // ...VFP load/store (reg+constant offset) |
| 2956 | case 'y': // ...iWMMXt load/store |
Eric Christopher | dda231a | 2011-06-17 01:40:49 +0000 | [diff] [blame] | 2957 | case 't': // address valid for load/store opaque types wider |
| 2958 | // than 128-bits |
| 2959 | case 'n': // valid address for Neon doubleword vector load/store |
| 2960 | case 'm': // valid address for Neon element and structure load/store |
| 2961 | case 's': // valid address for non-offset loads/stores of quad-word |
| 2962 | // values in four ARM registers |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2963 | Info.setAllowsMemory(); |
| 2964 | Name++; |
| 2965 | return true; |
| 2966 | } |
Nate Begeman | ad487f4 | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 2967 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2968 | return false; |
| 2969 | } |
Evan Cheng | 8bfa257 | 2011-06-16 19:13:15 +0000 | [diff] [blame] | 2970 | virtual std::string convertConstraint(const char *&Constraint) const { |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2971 | std::string R; |
| 2972 | switch (*Constraint) { |
| 2973 | case 'U': // Two-character constraint; add "^" hint for later parsing. |
Stuart Hastings | 6ce33d6 | 2011-06-08 16:06:31 +0000 | [diff] [blame] | 2974 | R = std::string("^") + std::string(Constraint, 2); |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2975 | Constraint++; |
| 2976 | break; |
Eric Christopher | 283f447 | 2011-06-17 00:40:18 +0000 | [diff] [blame] | 2977 | case 'p': // 'p' should be translated to 'r' by default. |
| 2978 | R = std::string("r"); |
| 2979 | break; |
Stuart Hastings | 002333f | 2011-06-07 23:45:05 +0000 | [diff] [blame] | 2980 | default: |
| 2981 | return std::string(1, *Constraint); |
| 2982 | } |
| 2983 | return R; |
| 2984 | } |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2985 | virtual const char *getClobbers() const { |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 2986 | // FIXME: Is this really right? |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 2987 | return ""; |
| 2988 | } |
| 2989 | }; |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2990 | |
| 2991 | const char * const ARMTargetInfo::GCCRegNames[] = { |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 2992 | // Integer registers |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 2993 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 2994 | "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc", |
| 2995 | |
| 2996 | // Float registers |
| 2997 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 2998 | "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", |
| 2999 | "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 3000 | "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", |
Daniel Dunbar | bf3d552 | 2010-08-11 02:17:20 +0000 | [diff] [blame] | 3001 | |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 3002 | // Double registers |
| 3003 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", |
| 3004 | "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", |
Dale Johannesen | d145535 | 2010-10-28 01:05:37 +0000 | [diff] [blame] | 3005 | "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", |
| 3006 | "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 3007 | |
| 3008 | // Quad registers |
Dale Johannesen | d145535 | 2010-10-28 01:05:37 +0000 | [diff] [blame] | 3009 | "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", |
| 3010 | "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 3011 | }; |
| 3012 | |
| 3013 | void ARMTargetInfo::getGCCRegNames(const char * const *&Names, |
Daniel Dunbar | 1fd7171 | 2010-08-11 02:17:11 +0000 | [diff] [blame] | 3014 | unsigned &NumNames) const { |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 3015 | Names = GCCRegNames; |
| 3016 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 3017 | } |
| 3018 | |
| 3019 | const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = { |
Daniel Dunbar | c1f2cdd | 2009-09-17 07:03:19 +0000 | [diff] [blame] | 3020 | { { "a1" }, "r0" }, |
| 3021 | { { "a2" }, "r1" }, |
| 3022 | { { "a3" }, "r2" }, |
| 3023 | { { "a4" }, "r3" }, |
| 3024 | { { "v1" }, "r4" }, |
| 3025 | { { "v2" }, "r5" }, |
| 3026 | { { "v3" }, "r6" }, |
| 3027 | { { "v4" }, "r7" }, |
| 3028 | { { "v5" }, "r8" }, |
| 3029 | { { "v6", "rfp" }, "r9" }, |
| 3030 | { { "sl" }, "r10" }, |
| 3031 | { { "fp" }, "r11" }, |
| 3032 | { { "ip" }, "r12" }, |
Daniel Dunbar | 1fd7171 | 2010-08-11 02:17:11 +0000 | [diff] [blame] | 3033 | { { "r13" }, "sp" }, |
| 3034 | { { "r14" }, "lr" }, |
| 3035 | { { "r15" }, "pc" }, |
Dale Johannesen | 20eb49b | 2010-10-27 23:34:42 +0000 | [diff] [blame] | 3036 | // The S, D and Q registers overlap, but aren't really aliases; we |
| 3037 | // 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] | 3038 | }; |
| 3039 | |
| 3040 | void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3041 | unsigned &NumAliases) const { |
| 3042 | Aliases = GCCRegAliases; |
| 3043 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 3044 | } |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3045 | |
| 3046 | const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 3047 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
Fariborz Jahanian | 67aba81 | 2010-11-30 17:35:24 +0000 | [diff] [blame] | 3048 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
Eli Friedman | e7e66f7 | 2011-07-05 21:53:01 +0000 | [diff] [blame] | 3049 | ALL_LANGUAGES }, |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3050 | #include "clang/Basic/BuiltinsARM.def" |
| 3051 | }; |
Chris Lattner | 393ff04 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 3052 | } // end anonymous namespace. |
| 3053 | |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 3054 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3055 | class DarwinARMTargetInfo : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 3056 | public DarwinTargetInfo<ARMTargetInfo> { |
| 3057 | protected: |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 3058 | virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 3059 | MacroBuilder &Builder) const { |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 3060 | getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion); |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 3061 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 3062 | |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 3063 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3064 | DarwinARMTargetInfo(const std::string& triple) |
Daniel Dunbar | 350b9f3 | 2010-05-27 07:00:26 +0000 | [diff] [blame] | 3065 | : DarwinTargetInfo<ARMTargetInfo>(triple) { |
| 3066 | HasAlignMac68kSupport = true; |
Eli Friedman | 2be4607 | 2011-10-14 20:59:01 +0000 | [diff] [blame] | 3067 | // iOS always has 64-bit atomic instructions. |
| 3068 | // FIXME: This should be based off of the target features in ARMTargetInfo. |
| 3069 | MaxAtomicInlineWidth = 64; |
Daniel Dunbar | 350b9f3 | 2010-05-27 07:00:26 +0000 | [diff] [blame] | 3070 | } |
Eli Friedman | a9f5496 | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 3071 | }; |
| 3072 | } // end anonymous namespace. |
| 3073 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3074 | |
| 3075 | namespace { |
| 3076 | // Hexagon abstract base class |
| 3077 | class HexagonTargetInfo : public TargetInfo { |
| 3078 | static const Builtin::Info BuiltinInfo[]; |
| 3079 | static const char * const GCCRegNames[]; |
| 3080 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 3081 | std::string CPU; |
| 3082 | public: |
| 3083 | HexagonTargetInfo(const std::string& triple) : TargetInfo(triple) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 3084 | BigEndian = false; |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3085 | DescriptionString = ("e-p:32:32:32-" |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 3086 | "i64:64:64-i32:32:32-i16:16:16-i1:32:32" |
| 3087 | "f64:64:64-f32:32:32-a0:0-n32"); |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3088 | |
| 3089 | // {} in inline assembly are packet specifiers, not assembly variant |
| 3090 | // specifiers. |
| 3091 | NoAsmVariants = true; |
| 3092 | } |
| 3093 | |
| 3094 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3095 | unsigned &NumRecords) const { |
| 3096 | Records = BuiltinInfo; |
| 3097 | NumRecords = clang::Hexagon::LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 3098 | } |
| 3099 | |
| 3100 | virtual bool validateAsmConstraint(const char *&Name, |
| 3101 | TargetInfo::ConstraintInfo &Info) const { |
| 3102 | return true; |
| 3103 | } |
| 3104 | |
| 3105 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3106 | MacroBuilder &Builder) const; |
| 3107 | |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3108 | virtual bool hasFeature(StringRef Feature) const { |
| 3109 | return Feature == "hexagon"; |
| 3110 | } |
| 3111 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3112 | virtual const char *getVAListDeclaration() const { |
| 3113 | return "typedef char* __builtin_va_list;"; |
| 3114 | } |
| 3115 | virtual void getGCCRegNames(const char * const *&Names, |
| 3116 | unsigned &NumNames) const; |
| 3117 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3118 | unsigned &NumAliases) const; |
| 3119 | virtual const char *getClobbers() const { |
| 3120 | return ""; |
| 3121 | } |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3122 | |
| 3123 | static const char *getHexagonCPUSuffix(StringRef Name) { |
| 3124 | return llvm::StringSwitch<const char*>(Name) |
| 3125 | .Case("hexagonv2", "2") |
| 3126 | .Case("hexagonv3", "3") |
| 3127 | .Case("hexagonv4", "4") |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 3128 | .Case("hexagonv5", "5") |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3129 | .Default(0); |
| 3130 | } |
| 3131 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3132 | virtual bool setCPU(const std::string &Name) { |
Sebastian Pop | 43115d4 | 2012-01-13 20:37:10 +0000 | [diff] [blame] | 3133 | if (!getHexagonCPUSuffix(Name)) |
| 3134 | return false; |
| 3135 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3136 | CPU = Name; |
| 3137 | return true; |
| 3138 | } |
| 3139 | }; |
| 3140 | |
| 3141 | void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts, |
| 3142 | MacroBuilder &Builder) const { |
| 3143 | Builder.defineMacro("qdsp6"); |
| 3144 | Builder.defineMacro("__qdsp6", "1"); |
| 3145 | Builder.defineMacro("__qdsp6__", "1"); |
| 3146 | |
| 3147 | Builder.defineMacro("hexagon"); |
| 3148 | Builder.defineMacro("__hexagon", "1"); |
| 3149 | Builder.defineMacro("__hexagon__", "1"); |
| 3150 | |
| 3151 | if(CPU == "hexagonv1") { |
| 3152 | Builder.defineMacro("__HEXAGON_V1__"); |
| 3153 | Builder.defineMacro("__HEXAGON_ARCH__", "1"); |
| 3154 | if(Opts.HexagonQdsp6Compat) { |
| 3155 | Builder.defineMacro("__QDSP6_V1__"); |
| 3156 | Builder.defineMacro("__QDSP6_ARCH__", "1"); |
| 3157 | } |
| 3158 | } |
| 3159 | else if(CPU == "hexagonv2") { |
| 3160 | Builder.defineMacro("__HEXAGON_V2__"); |
| 3161 | Builder.defineMacro("__HEXAGON_ARCH__", "2"); |
| 3162 | if(Opts.HexagonQdsp6Compat) { |
| 3163 | Builder.defineMacro("__QDSP6_V2__"); |
| 3164 | Builder.defineMacro("__QDSP6_ARCH__", "2"); |
| 3165 | } |
| 3166 | } |
| 3167 | else if(CPU == "hexagonv3") { |
| 3168 | Builder.defineMacro("__HEXAGON_V3__"); |
| 3169 | Builder.defineMacro("__HEXAGON_ARCH__", "3"); |
| 3170 | if(Opts.HexagonQdsp6Compat) { |
| 3171 | Builder.defineMacro("__QDSP6_V3__"); |
| 3172 | Builder.defineMacro("__QDSP6_ARCH__", "3"); |
| 3173 | } |
| 3174 | } |
| 3175 | else if(CPU == "hexagonv4") { |
| 3176 | Builder.defineMacro("__HEXAGON_V4__"); |
| 3177 | Builder.defineMacro("__HEXAGON_ARCH__", "4"); |
| 3178 | if(Opts.HexagonQdsp6Compat) { |
| 3179 | Builder.defineMacro("__QDSP6_V4__"); |
| 3180 | Builder.defineMacro("__QDSP6_ARCH__", "4"); |
| 3181 | } |
| 3182 | } |
Sirish Pande | 5f9688b | 2012-05-10 20:19:54 +0000 | [diff] [blame] | 3183 | else if(CPU == "hexagonv5") { |
| 3184 | Builder.defineMacro("__HEXAGON_V5__"); |
| 3185 | Builder.defineMacro("__HEXAGON_ARCH__", "5"); |
| 3186 | if(Opts.HexagonQdsp6Compat) { |
| 3187 | Builder.defineMacro("__QDSP6_V5__"); |
| 3188 | Builder.defineMacro("__QDSP6_ARCH__", "5"); |
| 3189 | } |
| 3190 | } |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | const char * const HexagonTargetInfo::GCCRegNames[] = { |
| 3194 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 3195 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 3196 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 3197 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 3198 | "p0", "p1", "p2", "p3", |
| 3199 | "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp" |
| 3200 | }; |
| 3201 | |
| 3202 | void HexagonTargetInfo::getGCCRegNames(const char * const *&Names, |
| 3203 | unsigned &NumNames) const { |
| 3204 | Names = GCCRegNames; |
| 3205 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 3206 | } |
| 3207 | |
| 3208 | |
| 3209 | const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = { |
| 3210 | { { "sp" }, "r29" }, |
| 3211 | { { "fp" }, "r30" }, |
| 3212 | { { "lr" }, "r31" }, |
| 3213 | }; |
| 3214 | |
| 3215 | void HexagonTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3216 | unsigned &NumAliases) const { |
| 3217 | Aliases = GCCRegAliases; |
| 3218 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 3219 | } |
| 3220 | |
| 3221 | |
| 3222 | const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = { |
| 3223 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, |
| 3224 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ |
| 3225 | ALL_LANGUAGES }, |
| 3226 | #include "clang/Basic/BuiltinsHexagon.def" |
| 3227 | }; |
| 3228 | } |
| 3229 | |
| 3230 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3231 | namespace { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3232 | class SparcV8TargetInfo : public TargetInfo { |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3233 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 3234 | static const char * const GCCRegNames[]; |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 3235 | bool SoftFloat; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3236 | public: |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3237 | SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 3238 | // FIXME: Support Sparc quad-precision long double? |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 3239 | 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] | 3240 | "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] | 3241 | } |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 3242 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 3243 | StringRef Name, |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 3244 | bool Enabled) const { |
| 3245 | if (Name == "soft-float") |
| 3246 | Features[Name] = Enabled; |
| 3247 | else |
| 3248 | return false; |
| 3249 | |
| 3250 | return true; |
| 3251 | } |
| 3252 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
| 3253 | SoftFloat = false; |
| 3254 | for (unsigned i = 0, e = Features.size(); i != e; ++i) |
| 3255 | if (Features[i] == "+soft-float") |
| 3256 | SoftFloat = true; |
| 3257 | } |
Chris Lattner | 3332864 | 2009-03-20 15:52:06 +0000 | [diff] [blame] | 3258 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 3259 | MacroBuilder &Builder) const { |
| 3260 | DefineStd(Builder, "sparc", Opts); |
| 3261 | Builder.defineMacro("__sparcv8"); |
| 3262 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 3263 | |
| 3264 | if (SoftFloat) |
| 3265 | Builder.defineMacro("SOFT_FLOAT", "1"); |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3266 | } |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3267 | |
| 3268 | virtual bool hasFeature(StringRef Feature) const { |
| 3269 | return llvm::StringSwitch<bool>(Feature) |
| 3270 | .Case("softfloat", SoftFloat) |
| 3271 | .Case("sparc", true) |
| 3272 | .Default(false); |
| 3273 | } |
| 3274 | |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3275 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3276 | unsigned &NumRecords) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3277 | // FIXME: Implement! |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3278 | } |
| 3279 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3280 | return "typedef void* __builtin_va_list;"; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3281 | } |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 3282 | virtual void getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3283 | unsigned &NumNames) const; |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 3284 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3285 | unsigned &NumAliases) const; |
Anders Carlsson | 066d2ea | 2009-02-28 17:11:49 +0000 | [diff] [blame] | 3286 | virtual bool validateAsmConstraint(const char *&Name, |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3287 | TargetInfo::ConstraintInfo &info) const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3288 | // FIXME: Implement! |
| 3289 | return false; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3290 | } |
| 3291 | virtual const char *getClobbers() const { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3292 | // FIXME: Implement! |
| 3293 | return ""; |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3294 | } |
| 3295 | }; |
| 3296 | |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3297 | const char * const SparcV8TargetInfo::GCCRegNames[] = { |
| 3298 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 3299 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 3300 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 3301 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" |
| 3302 | }; |
| 3303 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 3304 | void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3305 | unsigned &NumNames) const { |
| 3306 | Names = GCCRegNames; |
| 3307 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 3308 | } |
| 3309 | |
| 3310 | const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 3311 | { { "g0" }, "r0" }, |
| 3312 | { { "g1" }, "r1" }, |
| 3313 | { { "g2" }, "r2" }, |
| 3314 | { { "g3" }, "r3" }, |
| 3315 | { { "g4" }, "r4" }, |
| 3316 | { { "g5" }, "r5" }, |
| 3317 | { { "g6" }, "r6" }, |
| 3318 | { { "g7" }, "r7" }, |
| 3319 | { { "o0" }, "r8" }, |
| 3320 | { { "o1" }, "r9" }, |
| 3321 | { { "o2" }, "r10" }, |
| 3322 | { { "o3" }, "r11" }, |
| 3323 | { { "o4" }, "r12" }, |
| 3324 | { { "o5" }, "r13" }, |
| 3325 | { { "o6", "sp" }, "r14" }, |
| 3326 | { { "o7" }, "r15" }, |
| 3327 | { { "l0" }, "r16" }, |
| 3328 | { { "l1" }, "r17" }, |
| 3329 | { { "l2" }, "r18" }, |
| 3330 | { { "l3" }, "r19" }, |
| 3331 | { { "l4" }, "r20" }, |
| 3332 | { { "l5" }, "r21" }, |
| 3333 | { { "l6" }, "r22" }, |
| 3334 | { { "l7" }, "r23" }, |
| 3335 | { { "i0" }, "r24" }, |
| 3336 | { { "i1" }, "r25" }, |
| 3337 | { { "i2" }, "r26" }, |
| 3338 | { { "i3" }, "r27" }, |
| 3339 | { { "i4" }, "r28" }, |
| 3340 | { { "i5" }, "r29" }, |
| 3341 | { { "i6", "fp" }, "r30" }, |
| 3342 | { { "i7" }, "r31" }, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3343 | }; |
| 3344 | |
Anton Korobeynikov | a7c4717 | 2009-05-03 13:42:53 +0000 | [diff] [blame] | 3345 | void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | e957f53 | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 3346 | unsigned &NumAliases) const { |
| 3347 | Aliases = GCCRegAliases; |
| 3348 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 3349 | } |
Gabor Greif | 2665867 | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 3350 | } // end anonymous namespace. |
| 3351 | |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3352 | namespace { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 3353 | class AuroraUXSparcV8TargetInfo : public AuroraUXTargetInfo<SparcV8TargetInfo> { |
| 3354 | public: |
| 3355 | AuroraUXSparcV8TargetInfo(const std::string& triple) : |
| 3356 | AuroraUXTargetInfo<SparcV8TargetInfo>(triple) { |
| 3357 | SizeType = UnsignedInt; |
| 3358 | PtrDiffType = SignedInt; |
| 3359 | } |
| 3360 | }; |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 3361 | class SolarisSparcV8TargetInfo : public SolarisTargetInfo<SparcV8TargetInfo> { |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3362 | public: |
| 3363 | SolarisSparcV8TargetInfo(const std::string& triple) : |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 3364 | SolarisTargetInfo<SparcV8TargetInfo>(triple) { |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 3365 | SizeType = UnsignedInt; |
| 3366 | PtrDiffType = SignedInt; |
Eli Friedman | 01b8668 | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 3367 | } |
| 3368 | }; |
| 3369 | } // end anonymous namespace. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3370 | |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 3371 | namespace { |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3372 | class MSP430TargetInfo : public TargetInfo { |
| 3373 | static const char * const GCCRegNames[]; |
| 3374 | public: |
| 3375 | MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 3376 | BigEndian = false; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3377 | TLSSupported = false; |
Anton Korobeynikov | 09f52a6 | 2010-01-30 12:55:11 +0000 | [diff] [blame] | 3378 | IntWidth = 16; IntAlign = 16; |
| 3379 | LongWidth = 32; LongLongWidth = 64; |
| 3380 | LongAlign = LongLongAlign = 16; |
| 3381 | PointerWidth = 16; PointerAlign = 16; |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 3382 | SuitableAlign = 16; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3383 | SizeType = UnsignedInt; |
| 3384 | IntMaxType = SignedLong; |
| 3385 | UIntMaxType = UnsignedLong; |
| 3386 | IntPtrType = SignedShort; |
| 3387 | PtrDiffType = SignedInt; |
Edward O'Callaghan | 9cf910e | 2009-11-21 00:49:54 +0000 | [diff] [blame] | 3388 | SigAtomicType = SignedLong; |
Anton Korobeynikov | 5d7c251 | 2009-12-19 01:32:37 +0000 | [diff] [blame] | 3389 | 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] | 3390 | } |
| 3391 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 3392 | MacroBuilder &Builder) const { |
| 3393 | Builder.defineMacro("MSP430"); |
| 3394 | Builder.defineMacro("__MSP430__"); |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3395 | // FIXME: defines for different 'flavours' of MCU |
| 3396 | } |
| 3397 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3398 | unsigned &NumRecords) const { |
| 3399 | // FIXME: Implement. |
| 3400 | Records = 0; |
| 3401 | NumRecords = 0; |
| 3402 | } |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3403 | virtual bool hasFeature(StringRef Feature) const { |
| 3404 | return Feature == "msp430"; |
| 3405 | } |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3406 | virtual void getGCCRegNames(const char * const *&Names, |
| 3407 | unsigned &NumNames) const; |
| 3408 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3409 | unsigned &NumAliases) const { |
| 3410 | // No aliases. |
| 3411 | Aliases = 0; |
| 3412 | NumAliases = 0; |
| 3413 | } |
| 3414 | virtual bool validateAsmConstraint(const char *&Name, |
| 3415 | TargetInfo::ConstraintInfo &info) const { |
Anton Korobeynikov | 03265b6 | 2009-10-15 23:17:13 +0000 | [diff] [blame] | 3416 | // No target constraints for now. |
| 3417 | return false; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3418 | } |
| 3419 | virtual const char *getClobbers() const { |
| 3420 | // FIXME: Is this really right? |
| 3421 | return ""; |
| 3422 | } |
| 3423 | virtual const char *getVAListDeclaration() const { |
| 3424 | // FIXME: implement |
Anton Korobeynikov | eb71685 | 2009-05-08 18:24:57 +0000 | [diff] [blame] | 3425 | return "typedef char* __builtin_va_list;"; |
Anton Korobeynikov | 73c64e5 | 2009-05-03 13:43:08 +0000 | [diff] [blame] | 3426 | } |
| 3427 | }; |
| 3428 | |
| 3429 | const char * const MSP430TargetInfo::GCCRegNames[] = { |
| 3430 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 3431 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 3432 | }; |
| 3433 | |
| 3434 | void MSP430TargetInfo::getGCCRegNames(const char * const *&Names, |
| 3435 | unsigned &NumNames) const { |
| 3436 | Names = GCCRegNames; |
| 3437 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 3438 | } |
| 3439 | } |
| 3440 | |
Jakob Stoklund Olesen | 1eb4343 | 2009-08-17 20:08:44 +0000 | [diff] [blame] | 3441 | namespace { |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3442 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3443 | // LLVM and Clang cannot be used directly to output native binaries for |
| 3444 | // 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] | 3445 | // type and alignment information. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3446 | // |
| 3447 | // TCE uses the llvm bitcode as input and uses it for generating customized |
| 3448 | // target processor and program binary. TCE co-design environment is |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3449 | // publicly available in http://tce.cs.tut.fi |
| 3450 | |
Eli Friedman | 209f5bb | 2011-10-07 19:51:42 +0000 | [diff] [blame] | 3451 | static const unsigned TCEOpenCLAddrSpaceMap[] = { |
| 3452 | 3, // opencl_global |
| 3453 | 4, // opencl_local |
Peter Collingbourne | 4dc34eb | 2012-05-20 21:08:35 +0000 | [diff] [blame] | 3454 | 5, // opencl_constant |
| 3455 | 0, // cuda_device |
| 3456 | 0, // cuda_constant |
| 3457 | 0 // cuda_shared |
Eli Friedman | 209f5bb | 2011-10-07 19:51:42 +0000 | [diff] [blame] | 3458 | }; |
| 3459 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3460 | class TCETargetInfo : public TargetInfo{ |
| 3461 | public: |
| 3462 | TCETargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 3463 | TLSSupported = false; |
| 3464 | IntWidth = 32; |
| 3465 | LongWidth = LongLongWidth = 32; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3466 | PointerWidth = 32; |
| 3467 | IntAlign = 32; |
| 3468 | LongAlign = LongLongAlign = 32; |
| 3469 | PointerAlign = 32; |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 3470 | SuitableAlign = 32; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3471 | SizeType = UnsignedInt; |
| 3472 | IntMaxType = SignedLong; |
| 3473 | UIntMaxType = UnsignedLong; |
| 3474 | IntPtrType = SignedInt; |
| 3475 | PtrDiffType = SignedInt; |
| 3476 | FloatWidth = 32; |
| 3477 | FloatAlign = 32; |
| 3478 | DoubleWidth = 32; |
| 3479 | DoubleAlign = 32; |
| 3480 | LongDoubleWidth = 32; |
| 3481 | LongDoubleAlign = 32; |
| 3482 | FloatFormat = &llvm::APFloat::IEEEsingle; |
| 3483 | DoubleFormat = &llvm::APFloat::IEEEsingle; |
| 3484 | LongDoubleFormat = &llvm::APFloat::IEEEsingle; |
Chris Lattner | 3a47c4e | 2010-03-04 21:07:38 +0000 | [diff] [blame] | 3485 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-" |
| 3486 | "i16:16:32-i32:32:32-i64:32:32-" |
NAKAMURA Takumi | c910929 | 2011-02-18 08:44:38 +0000 | [diff] [blame] | 3487 | "f32:32:32-f64:32:32-v64:32:32-" |
| 3488 | "v128:32:32-a0:0:32-n32"; |
Eli Friedman | 209f5bb | 2011-10-07 19:51:42 +0000 | [diff] [blame] | 3489 | AddrSpaceMap = &TCEOpenCLAddrSpaceMap; |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | virtual void getTargetDefines(const LangOptions &Opts, |
Benjamin Kramer | a999277 | 2010-01-09 17:55:51 +0000 | [diff] [blame] | 3493 | MacroBuilder &Builder) const { |
| 3494 | DefineStd(Builder, "tce", Opts); |
| 3495 | Builder.defineMacro("__TCE__"); |
| 3496 | Builder.defineMacro("__TCE_V1__"); |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3497 | } |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3498 | virtual bool hasFeature(StringRef Feature) const { |
| 3499 | return Feature == "tce"; |
| 3500 | } |
| 3501 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3502 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3503 | unsigned &NumRecords) const {} |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3504 | virtual const char *getClobbers() const { |
| 3505 | return ""; |
| 3506 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3507 | virtual const char *getVAListDeclaration() const { |
| 3508 | return "typedef void* __builtin_va_list;"; |
| 3509 | } |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 3510 | virtual void getGCCRegNames(const char * const *&Names, |
| 3511 | unsigned &NumNames) const {} |
| 3512 | virtual bool validateAsmConstraint(const char *&Name, |
| 3513 | TargetInfo::ConstraintInfo &info) const { |
| 3514 | return true; |
| 3515 | } |
| 3516 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3517 | unsigned &NumAliases) const {} |
| 3518 | }; |
| 3519 | } |
| 3520 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3521 | namespace { |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3522 | class MipsTargetInfoBase : public TargetInfo { |
| 3523 | std::string CPU; |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3524 | bool SoftFloat; |
| 3525 | bool SingleFloat; |
| 3526 | |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3527 | protected: |
| 3528 | std::string ABI; |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3529 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3530 | public: |
Simon Atanasyan | 10e1629d | 2012-04-12 19:59:24 +0000 | [diff] [blame] | 3531 | MipsTargetInfoBase(const std::string& triple, |
| 3532 | const std::string& ABIStr, |
| 3533 | const std::string& CPUStr) |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3534 | : TargetInfo(triple), |
Simon Atanasyan | 10e1629d | 2012-04-12 19:59:24 +0000 | [diff] [blame] | 3535 | CPU(CPUStr), |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3536 | SoftFloat(false), SingleFloat(false), |
| 3537 | ABI(ABIStr) |
| 3538 | {} |
| 3539 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 3540 | virtual const char *getABI() const { return ABI.c_str(); } |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3541 | virtual bool setABI(const std::string &Name) = 0; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 3542 | virtual bool setCPU(const std::string &Name) { |
| 3543 | CPU = Name; |
| 3544 | return true; |
| 3545 | } |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 3546 | void getDefaultFeatures(llvm::StringMap<bool> &Features) const { |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 3547 | Features[ABI] = true; |
| 3548 | Features[CPU] = true; |
| 3549 | } |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3550 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 3551 | virtual void getArchDefines(const LangOptions &Opts, |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3552 | MacroBuilder &Builder) const { |
Simon Atanasyan | 3dbcc88 | 2012-06-05 13:06:56 +0000 | [diff] [blame] | 3553 | if (SoftFloat && SingleFloat) |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3554 | llvm_unreachable("Invalid float ABI for Mips."); |
Simon Atanasyan | 3dbcc88 | 2012-06-05 13:06:56 +0000 | [diff] [blame] | 3555 | else if (SoftFloat) |
| 3556 | Builder.defineMacro("__mips_soft_float", Twine(1)); |
| 3557 | else { |
| 3558 | Builder.defineMacro("__mips_hard_float", Twine(1)); |
| 3559 | if (SingleFloat) |
| 3560 | Builder.defineMacro("__mips_single_float", Twine(1)); |
| 3561 | } |
Simon Atanasyan | 9091389 | 2012-04-05 19:28:31 +0000 | [diff] [blame] | 3562 | |
| 3563 | Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0))); |
| 3564 | Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth())); |
| 3565 | Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth())); |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3568 | virtual void getTargetDefines(const LangOptions &Opts, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3569 | MacroBuilder &Builder) const = 0; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3570 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3571 | unsigned &NumRecords) const { |
| 3572 | // FIXME: Implement! |
| 3573 | } |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3574 | virtual bool hasFeature(StringRef Feature) const { |
| 3575 | return Feature == "mips"; |
| 3576 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3577 | virtual const char *getVAListDeclaration() const { |
| 3578 | return "typedef void* __builtin_va_list;"; |
| 3579 | } |
| 3580 | virtual void getGCCRegNames(const char * const *&Names, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3581 | unsigned &NumNames) const { |
| 3582 | static const char * const GCCRegNames[] = { |
Eric Christopher | d1f853d | 2012-03-27 19:56:11 +0000 | [diff] [blame] | 3583 | // CPU register names |
| 3584 | // Must match second column of GCCRegAliases |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3585 | "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7", |
| 3586 | "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", |
| 3587 | "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23", |
Eric Christopher | d1f853d | 2012-03-27 19:56:11 +0000 | [diff] [blame] | 3588 | "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31", |
| 3589 | // Floating point register names |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3590 | "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", |
| 3591 | "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15", |
| 3592 | "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23", |
| 3593 | "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31", |
Eric Christopher | d1f853d | 2012-03-27 19:56:11 +0000 | [diff] [blame] | 3594 | // Hi/lo and condition register names |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3595 | "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4", |
| 3596 | "$fcc5","$fcc6","$fcc7" |
| 3597 | }; |
| 3598 | Names = GCCRegNames; |
| 3599 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 3600 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3601 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3602 | unsigned &NumAliases) const = 0; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3603 | virtual bool validateAsmConstraint(const char *&Name, |
| 3604 | TargetInfo::ConstraintInfo &Info) const { |
| 3605 | switch (*Name) { |
| 3606 | default: |
Douglas Gregor | 21a2516 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 3607 | return false; |
| 3608 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3609 | case 'r': // CPU registers. |
| 3610 | case 'd': // Equivalent to "r" unless generating MIPS16 code. |
| 3611 | case 'y': // Equivalent to "r", backwards compatibility only. |
| 3612 | case 'f': // floating-point registers. |
Eric Christopher | 0ea6164 | 2012-04-03 01:16:32 +0000 | [diff] [blame] | 3613 | case 'c': // $25 for indirect jumps |
| 3614 | case 'l': // lo register |
| 3615 | case 'x': // hilo register pair |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3616 | Info.setAllowsRegister(); |
| 3617 | return true; |
| 3618 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | virtual const char *getClobbers() const { |
| 3622 | // FIXME: Implement! |
| 3623 | return ""; |
| 3624 | } |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3625 | |
| 3626 | virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, |
| 3627 | StringRef Name, |
| 3628 | bool Enabled) const { |
Simon Atanasyan | 8b2a5d2 | 2012-04-18 12:00:11 +0000 | [diff] [blame] | 3629 | if (Name == "soft-float" || Name == "single-float" || |
| 3630 | Name == "o32" || Name == "n32" || Name == "n64" || Name == "eabi" || |
| 3631 | Name == "mips32" || Name == "mips32r2" || |
| 3632 | Name == "mips64" || Name == "mips64r2") { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3633 | Features[Name] = Enabled; |
| 3634 | return true; |
| 3635 | } |
| 3636 | return false; |
| 3637 | } |
| 3638 | |
| 3639 | virtual void HandleTargetFeatures(std::vector<std::string> &Features) { |
| 3640 | SoftFloat = false; |
| 3641 | SingleFloat = false; |
| 3642 | |
| 3643 | for (std::vector<std::string>::iterator it = Features.begin(), |
| 3644 | ie = Features.end(); it != ie; ++it) { |
| 3645 | if (*it == "+single-float") { |
| 3646 | SingleFloat = true; |
| 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | if (*it == "+soft-float") { |
| 3651 | SoftFloat = true; |
| 3652 | // This option is front-end specific. |
| 3653 | // Do not need to pass it to the backend. |
| 3654 | Features.erase(it); |
| 3655 | break; |
| 3656 | } |
| 3657 | } |
| 3658 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3659 | }; |
| 3660 | |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3661 | class Mips32TargetInfoBase : public MipsTargetInfoBase { |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3662 | public: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3663 | Mips32TargetInfoBase(const std::string& triple) : |
Simon Atanasyan | 10e1629d | 2012-04-12 19:59:24 +0000 | [diff] [blame] | 3664 | MipsTargetInfoBase(triple, "o32", "mips32") { |
Akira Hatanaka | 148735e | 2011-11-05 01:48:34 +0000 | [diff] [blame] | 3665 | SizeType = UnsignedInt; |
| 3666 | PtrDiffType = SignedInt; |
| 3667 | } |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3668 | virtual bool setABI(const std::string &Name) { |
| 3669 | if ((Name == "o32") || (Name == "eabi")) { |
| 3670 | ABI = Name; |
| 3671 | return true; |
| 3672 | } else |
| 3673 | return false; |
| 3674 | } |
| 3675 | virtual void getArchDefines(const LangOptions &Opts, |
| 3676 | MacroBuilder &Builder) const { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3677 | MipsTargetInfoBase::getArchDefines(Opts, Builder); |
| 3678 | |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3679 | if (ABI == "o32") { |
| 3680 | Builder.defineMacro("__mips_o32"); |
| 3681 | Builder.defineMacro("_ABIO32", "1"); |
| 3682 | Builder.defineMacro("_MIPS_SIM", "_ABIO32"); |
| 3683 | } |
| 3684 | else if (ABI == "eabi") |
| 3685 | Builder.defineMacro("__mips_eabi"); |
| 3686 | else |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3687 | llvm_unreachable("Invalid ABI for Mips32."); |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3688 | } |
| 3689 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3690 | unsigned &NumAliases) const { |
| 3691 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 3692 | { { "at" }, "$1" }, |
| 3693 | { { "v0" }, "$2" }, |
| 3694 | { { "v1" }, "$3" }, |
| 3695 | { { "a0" }, "$4" }, |
| 3696 | { { "a1" }, "$5" }, |
| 3697 | { { "a2" }, "$6" }, |
| 3698 | { { "a3" }, "$7" }, |
| 3699 | { { "t0" }, "$8" }, |
| 3700 | { { "t1" }, "$9" }, |
| 3701 | { { "t2" }, "$10" }, |
| 3702 | { { "t3" }, "$11" }, |
| 3703 | { { "t4" }, "$12" }, |
| 3704 | { { "t5" }, "$13" }, |
| 3705 | { { "t6" }, "$14" }, |
| 3706 | { { "t7" }, "$15" }, |
| 3707 | { { "s0" }, "$16" }, |
| 3708 | { { "s1" }, "$17" }, |
| 3709 | { { "s2" }, "$18" }, |
| 3710 | { { "s3" }, "$19" }, |
| 3711 | { { "s4" }, "$20" }, |
| 3712 | { { "s5" }, "$21" }, |
| 3713 | { { "s6" }, "$22" }, |
| 3714 | { { "s7" }, "$23" }, |
| 3715 | { { "t8" }, "$24" }, |
| 3716 | { { "t9" }, "$25" }, |
| 3717 | { { "k0" }, "$26" }, |
| 3718 | { { "k1" }, "$27" }, |
| 3719 | { { "gp" }, "$28" }, |
Eric Christopher | d1f853d | 2012-03-27 19:56:11 +0000 | [diff] [blame] | 3720 | { { "sp","$sp" }, "$29" }, |
| 3721 | { { "fp","$fp" }, "$30" }, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3722 | { { "ra" }, "$31" } |
| 3723 | }; |
| 3724 | Aliases = GCCRegAliases; |
| 3725 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 3726 | } |
| 3727 | }; |
| 3728 | |
| 3729 | class Mips32EBTargetInfo : public Mips32TargetInfoBase { |
| 3730 | public: |
| 3731 | Mips32EBTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) { |
| 3732 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
| 3733 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32"; |
| 3734 | } |
| 3735 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3736 | MacroBuilder &Builder) const { |
| 3737 | DefineStd(Builder, "mips", Opts); |
| 3738 | Builder.defineMacro("_mips"); |
| 3739 | DefineStd(Builder, "MIPSEB", Opts); |
| 3740 | Builder.defineMacro("_MIPSEB"); |
| 3741 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 3742 | getArchDefines(Opts, Builder); |
| 3743 | } |
| 3744 | }; |
| 3745 | |
| 3746 | class Mips32ELTargetInfo : public Mips32TargetInfoBase { |
| 3747 | public: |
| 3748 | Mips32ELTargetInfo(const std::string& triple) : Mips32TargetInfoBase(triple) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 3749 | BigEndian = false; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3750 | 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] | 3751 | "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] | 3752 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3753 | virtual void getTargetDefines(const LangOptions &Opts, |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 3754 | MacroBuilder &Builder) const { |
| 3755 | DefineStd(Builder, "mips", Opts); |
| 3756 | Builder.defineMacro("_mips"); |
| 3757 | DefineStd(Builder, "MIPSEL", Opts); |
| 3758 | Builder.defineMacro("_MIPSEL"); |
| 3759 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 3760 | getArchDefines(Opts, Builder); |
| 3761 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3762 | }; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3763 | |
| 3764 | class Mips64TargetInfoBase : public MipsTargetInfoBase { |
| 3765 | virtual void SetDescriptionString(const std::string &Name) = 0; |
| 3766 | public: |
| 3767 | Mips64TargetInfoBase(const std::string& triple) : |
Simon Atanasyan | 10e1629d | 2012-04-12 19:59:24 +0000 | [diff] [blame] | 3768 | MipsTargetInfoBase(triple, "n64", "mips64") { |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3769 | LongWidth = LongAlign = 64; |
| 3770 | PointerWidth = PointerAlign = 64; |
| 3771 | LongDoubleWidth = LongDoubleAlign = 128; |
| 3772 | LongDoubleFormat = &llvm::APFloat::IEEEquad; |
Nick Lewycky | 7ec59c7 | 2011-12-16 22:34:14 +0000 | [diff] [blame] | 3773 | SuitableAlign = 128; |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3774 | } |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3775 | virtual bool setABI(const std::string &Name) { |
| 3776 | SetDescriptionString(Name); |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3777 | |
| 3778 | if (Name != "n32" && Name != "n64") |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3779 | return false; |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3780 | |
| 3781 | ABI = Name; |
| 3782 | |
| 3783 | if (Name == "n32") { |
| 3784 | LongWidth = LongAlign = 32; |
| 3785 | PointerWidth = PointerAlign = 32; |
| 3786 | } |
| 3787 | |
| 3788 | return true; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3789 | } |
| 3790 | virtual void getArchDefines(const LangOptions &Opts, |
| 3791 | MacroBuilder &Builder) const { |
Akira Hatanaka | ad8d8a3 | 2012-03-23 23:07:09 +0000 | [diff] [blame] | 3792 | MipsTargetInfoBase::getArchDefines(Opts, Builder); |
| 3793 | |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3794 | if (ABI == "n32") { |
| 3795 | Builder.defineMacro("__mips_n32"); |
| 3796 | Builder.defineMacro("_ABIN32", "2"); |
| 3797 | Builder.defineMacro("_MIPS_SIM", "_ABIN32"); |
| 3798 | } |
| 3799 | else if (ABI == "n64") { |
| 3800 | Builder.defineMacro("__mips_n64"); |
| 3801 | Builder.defineMacro("_ABI64", "3"); |
| 3802 | Builder.defineMacro("_MIPS_SIM", "_ABI64"); |
| 3803 | } |
| 3804 | else |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3805 | llvm_unreachable("Invalid ABI for Mips64."); |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3806 | } |
| 3807 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3808 | unsigned &NumAliases) const { |
| 3809 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 3810 | { { "at" }, "$1" }, |
| 3811 | { { "v0" }, "$2" }, |
| 3812 | { { "v1" }, "$3" }, |
| 3813 | { { "a0" }, "$4" }, |
| 3814 | { { "a1" }, "$5" }, |
| 3815 | { { "a2" }, "$6" }, |
| 3816 | { { "a3" }, "$7" }, |
| 3817 | { { "a4" }, "$8" }, |
| 3818 | { { "a5" }, "$9" }, |
| 3819 | { { "a6" }, "$10" }, |
| 3820 | { { "a7" }, "$11" }, |
| 3821 | { { "t0" }, "$12" }, |
| 3822 | { { "t1" }, "$13" }, |
| 3823 | { { "t2" }, "$14" }, |
| 3824 | { { "t3" }, "$15" }, |
| 3825 | { { "s0" }, "$16" }, |
| 3826 | { { "s1" }, "$17" }, |
| 3827 | { { "s2" }, "$18" }, |
| 3828 | { { "s3" }, "$19" }, |
| 3829 | { { "s4" }, "$20" }, |
| 3830 | { { "s5" }, "$21" }, |
| 3831 | { { "s6" }, "$22" }, |
| 3832 | { { "s7" }, "$23" }, |
| 3833 | { { "t8" }, "$24" }, |
| 3834 | { { "t9" }, "$25" }, |
| 3835 | { { "k0" }, "$26" }, |
| 3836 | { { "k1" }, "$27" }, |
| 3837 | { { "gp" }, "$28" }, |
Eric Christopher | d1f853d | 2012-03-27 19:56:11 +0000 | [diff] [blame] | 3838 | { { "sp","$sp" }, "$29" }, |
| 3839 | { { "fp","$fp" }, "$30" }, |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3840 | { { "ra" }, "$31" } |
| 3841 | }; |
| 3842 | Aliases = GCCRegAliases; |
| 3843 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 3844 | } |
| 3845 | }; |
| 3846 | |
| 3847 | class Mips64EBTargetInfo : public Mips64TargetInfoBase { |
| 3848 | virtual void SetDescriptionString(const std::string &Name) { |
| 3849 | // Change DescriptionString only if ABI is n32. |
| 3850 | if (Name == "n32") |
| 3851 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3852 | "i64:64:64-f32:32:32-f64:64:64-f128:128:128-" |
| 3853 | "v64:64:64-n32"; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3854 | } |
| 3855 | public: |
| 3856 | Mips64EBTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) { |
| 3857 | // Default ABI is n64. |
| 3858 | DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3859 | "i64:64:64-f32:32:32-f64:64:64-f128:128:128-" |
| 3860 | "v64:64:64-n32"; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3861 | } |
| 3862 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3863 | MacroBuilder &Builder) const { |
| 3864 | DefineStd(Builder, "mips", Opts); |
| 3865 | Builder.defineMacro("_mips"); |
| 3866 | DefineStd(Builder, "MIPSEB", Opts); |
| 3867 | Builder.defineMacro("_MIPSEB"); |
| 3868 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 3869 | getArchDefines(Opts, Builder); |
| 3870 | } |
| 3871 | }; |
| 3872 | |
| 3873 | class Mips64ELTargetInfo : public Mips64TargetInfoBase { |
| 3874 | virtual void SetDescriptionString(const std::string &Name) { |
| 3875 | // Change DescriptionString only if ABI is n32. |
| 3876 | if (Name == "n32") |
| 3877 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3878 | "i64:64:64-f32:32:32-f64:64:64-f128:128:128" |
| 3879 | "-v64:64:64-n32"; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3880 | } |
| 3881 | public: |
| 3882 | Mips64ELTargetInfo(const std::string& triple) : Mips64TargetInfoBase(triple) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 3883 | // Default ABI is n64. |
| 3884 | BigEndian = false; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3885 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:32-i16:16:32-i32:32:32-" |
Akira Hatanaka | c7d0ab1 | 2011-10-22 00:07:27 +0000 | [diff] [blame] | 3886 | "i64:64:64-f32:32:32-f64:64:64-f128:128:128-" |
| 3887 | "v64:64:64-n32"; |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 3888 | } |
| 3889 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3890 | MacroBuilder &Builder) const { |
| 3891 | DefineStd(Builder, "mips", Opts); |
| 3892 | Builder.defineMacro("_mips"); |
| 3893 | DefineStd(Builder, "MIPSEL", Opts); |
| 3894 | Builder.defineMacro("_MIPSEL"); |
| 3895 | Builder.defineMacro("__REGISTER_PREFIX__", ""); |
| 3896 | getArchDefines(Opts, Builder); |
| 3897 | } |
| 3898 | }; |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 3899 | } // end anonymous namespace. |
| 3900 | |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3901 | namespace { |
| 3902 | class PNaClTargetInfo : public TargetInfo { |
| 3903 | public: |
| 3904 | PNaClTargetInfo(const std::string& triple) : TargetInfo(triple) { |
Eli Friedman | e6a24e8 | 2011-12-22 03:51:45 +0000 | [diff] [blame] | 3905 | BigEndian = false; |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3906 | this->UserLabelPrefix = ""; |
| 3907 | this->LongAlign = 32; |
| 3908 | this->LongWidth = 32; |
| 3909 | this->PointerAlign = 32; |
| 3910 | this->PointerWidth = 32; |
| 3911 | this->IntMaxType = TargetInfo::SignedLongLong; |
| 3912 | this->UIntMaxType = TargetInfo::UnsignedLongLong; |
| 3913 | this->Int64Type = TargetInfo::SignedLongLong; |
Ivan Krasin | f619cdc | 2011-08-29 22:39:12 +0000 | [diff] [blame] | 3914 | this->DoubleAlign = 64; |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3915 | this->LongDoubleWidth = 64; |
Ivan Krasin | f619cdc | 2011-08-29 22:39:12 +0000 | [diff] [blame] | 3916 | this->LongDoubleAlign = 64; |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3917 | this->SizeType = TargetInfo::UnsignedInt; |
| 3918 | this->PtrDiffType = TargetInfo::SignedInt; |
| 3919 | this->IntPtrType = TargetInfo::SignedInt; |
David Meyer | dd4a889 | 2011-10-11 03:12:01 +0000 | [diff] [blame] | 3920 | this->RegParmMax = 2; |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3921 | DescriptionString = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" |
| 3922 | "f32:32:32-f64:64:64-p:32:32:32-v128:32:32"; |
| 3923 | } |
| 3924 | |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 3925 | void getDefaultFeatures(llvm::StringMap<bool> &Features) const { |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3926 | } |
| 3927 | virtual void getArchDefines(const LangOptions &Opts, |
| 3928 | MacroBuilder &Builder) const { |
| 3929 | Builder.defineMacro("__le32__"); |
| 3930 | Builder.defineMacro("__pnacl__"); |
| 3931 | } |
| 3932 | virtual void getTargetDefines(const LangOptions &Opts, |
| 3933 | MacroBuilder &Builder) const { |
Ivan Krasin | 089ee11 | 2011-08-25 23:49:20 +0000 | [diff] [blame] | 3934 | DefineStd(Builder, "unix", Opts); |
| 3935 | Builder.defineMacro("__ELF__"); |
| 3936 | if (Opts.POSIXThreads) |
| 3937 | Builder.defineMacro("_REENTRANT"); |
| 3938 | if (Opts.CPlusPlus) |
| 3939 | Builder.defineMacro("_GNU_SOURCE"); |
| 3940 | |
Jan Wen Voung | dde3bdb | 2012-03-29 00:05:59 +0000 | [diff] [blame] | 3941 | Builder.defineMacro("__LITTLE_ENDIAN__"); |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3942 | Builder.defineMacro("__native_client__"); |
| 3943 | getArchDefines(Opts, Builder); |
| 3944 | } |
Douglas Gregor | e727d21 | 2012-01-30 06:38:25 +0000 | [diff] [blame] | 3945 | virtual bool hasFeature(StringRef Feature) const { |
| 3946 | return Feature == "pnacl"; |
| 3947 | } |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3948 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 3949 | unsigned &NumRecords) const { |
| 3950 | } |
| 3951 | virtual const char *getVAListDeclaration() const { |
Ivan Krasin | 68018db | 2011-09-20 14:56:54 +0000 | [diff] [blame] | 3952 | return "typedef int __builtin_va_list[4];"; |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 3953 | } |
| 3954 | virtual void getGCCRegNames(const char * const *&Names, |
| 3955 | unsigned &NumNames) const; |
| 3956 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3957 | unsigned &NumAliases) const; |
| 3958 | virtual bool validateAsmConstraint(const char *&Name, |
| 3959 | TargetInfo::ConstraintInfo &Info) const { |
| 3960 | return false; |
| 3961 | } |
| 3962 | |
| 3963 | virtual const char *getClobbers() const { |
| 3964 | return ""; |
| 3965 | } |
| 3966 | }; |
| 3967 | |
| 3968 | void PNaClTargetInfo::getGCCRegNames(const char * const *&Names, |
| 3969 | unsigned &NumNames) const { |
| 3970 | Names = NULL; |
| 3971 | NumNames = 0; |
| 3972 | } |
| 3973 | |
| 3974 | void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 3975 | unsigned &NumAliases) const { |
| 3976 | Aliases = NULL; |
| 3977 | NumAliases = 0; |
| 3978 | } |
| 3979 | } // end anonymous namespace. |
| 3980 | |
| 3981 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3982 | //===----------------------------------------------------------------------===// |
| 3983 | // Driver code |
| 3984 | //===----------------------------------------------------------------------===// |
| 3985 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 3986 | static TargetInfo *AllocateTarget(const std::string &T) { |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3987 | llvm::Triple Triple(T); |
| 3988 | llvm::Triple::OSType os = Triple.getOS(); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3989 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3990 | switch (Triple.getArch()) { |
| 3991 | default: |
| 3992 | return NULL; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 3993 | |
Tony Linthicum | 9631939 | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 3994 | case llvm::Triple::hexagon: |
| 3995 | return new HexagonTargetInfo(T); |
| 3996 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 3997 | case llvm::Triple::arm: |
Daniel Dunbar | f4aa4f61 | 2009-09-11 01:14:50 +0000 | [diff] [blame] | 3998 | case llvm::Triple::thumb: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3999 | if (Triple.isOSDarwin()) |
| 4000 | return new DarwinARMTargetInfo(T); |
| 4001 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4002 | switch (os) { |
Rafael Espindola | 022a8a5 | 2010-06-10 00:46:51 +0000 | [diff] [blame] | 4003 | case llvm::Triple::Linux: |
| 4004 | return new LinuxTargetInfo<ARMTargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4005 | case llvm::Triple::FreeBSD: |
Torok Edwin | 5f6c194 | 2009-06-30 17:10:35 +0000 | [diff] [blame] | 4006 | return new FreeBSDTargetInfo<ARMTargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4007 | case llvm::Triple::NetBSD: |
| 4008 | return new NetBSDTargetInfo<ARMTargetInfo>(T); |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 4009 | case llvm::Triple::RTEMS: |
| 4010 | return new RTEMSTargetInfo<ARMTargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4011 | default: |
| 4012 | return new ARMTargetInfo(T); |
| 4013 | } |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 4014 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4015 | case llvm::Triple::msp430: |
| 4016 | return new MSP430TargetInfo(T); |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 4017 | |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 4018 | case llvm::Triple::mips: |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4019 | switch (os) { |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4020 | case llvm::Triple::Linux: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4021 | return new LinuxTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4022 | case llvm::Triple::RTEMS: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4023 | return new RTEMSTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4024 | case llvm::Triple::FreeBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4025 | return new FreeBSDTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4026 | case llvm::Triple::NetBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4027 | return new NetBSDTargetInfo<Mips32EBTargetInfo>(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4028 | default: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4029 | return new Mips32EBTargetInfo(T); |
Joerg Sonnenberger | fa9772b | 2011-07-05 18:05:54 +0000 | [diff] [blame] | 4030 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 4031 | |
| 4032 | case llvm::Triple::mipsel: |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4033 | switch (os) { |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4034 | case llvm::Triple::Linux: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4035 | return new LinuxTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4036 | case llvm::Triple::RTEMS: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4037 | return new RTEMSTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4038 | case llvm::Triple::FreeBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4039 | return new FreeBSDTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4040 | case llvm::Triple::NetBSD: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4041 | return new NetBSDTargetInfo<Mips32ELTargetInfo>(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4042 | default: |
Akira Hatanaka | b6a37b3 | 2011-09-20 19:00:23 +0000 | [diff] [blame] | 4043 | return new Mips32ELTargetInfo(T); |
Joerg Sonnenberger | 94c9ce5 | 2011-07-05 18:24:04 +0000 | [diff] [blame] | 4044 | } |
Edward O'Callaghan | 84423a8 | 2009-11-15 10:22:07 +0000 | [diff] [blame] | 4045 | |
Akira Hatanaka | bf5851a | 2011-09-20 19:21:49 +0000 | [diff] [blame] | 4046 | case llvm::Triple::mips64: |
| 4047 | switch (os) { |
| 4048 | case llvm::Triple::Linux: |
| 4049 | return new LinuxTargetInfo<Mips64EBTargetInfo>(T); |
| 4050 | case llvm::Triple::RTEMS: |
| 4051 | return new RTEMSTargetInfo<Mips64EBTargetInfo>(T); |
| 4052 | case llvm::Triple::FreeBSD: |
| 4053 | return new FreeBSDTargetInfo<Mips64EBTargetInfo>(T); |
| 4054 | case llvm::Triple::NetBSD: |
| 4055 | return new NetBSDTargetInfo<Mips64EBTargetInfo>(T); |
| 4056 | default: |
| 4057 | return new Mips64EBTargetInfo(T); |
| 4058 | } |
| 4059 | |
| 4060 | case llvm::Triple::mips64el: |
| 4061 | switch (os) { |
| 4062 | case llvm::Triple::Linux: |
| 4063 | return new LinuxTargetInfo<Mips64ELTargetInfo>(T); |
| 4064 | case llvm::Triple::RTEMS: |
| 4065 | return new RTEMSTargetInfo<Mips64ELTargetInfo>(T); |
| 4066 | case llvm::Triple::FreeBSD: |
| 4067 | return new FreeBSDTargetInfo<Mips64ELTargetInfo>(T); |
| 4068 | case llvm::Triple::NetBSD: |
| 4069 | return new NetBSDTargetInfo<Mips64ELTargetInfo>(T); |
| 4070 | default: |
| 4071 | return new Mips64ELTargetInfo(T); |
| 4072 | } |
| 4073 | |
Ivan Krasin | ef05abd | 2011-08-24 20:22:22 +0000 | [diff] [blame] | 4074 | case llvm::Triple::le32: |
| 4075 | switch (os) { |
| 4076 | case llvm::Triple::NativeClient: |
| 4077 | return new PNaClTargetInfo(T); |
| 4078 | default: |
| 4079 | return NULL; |
| 4080 | } |
| 4081 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4082 | case llvm::Triple::ppc: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 4083 | if (Triple.isOSDarwin()) |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 4084 | return new DarwinPPC32TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4085 | switch (os) { |
Anton Korobeynikov | 7e1812f | 2011-10-12 09:30:58 +0000 | [diff] [blame] | 4086 | case llvm::Triple::Linux: |
| 4087 | return new LinuxTargetInfo<PPC32TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4088 | case llvm::Triple::FreeBSD: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 4089 | return new FreeBSDTargetInfo<PPC32TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4090 | case llvm::Triple::NetBSD: |
| 4091 | return new NetBSDTargetInfo<PPC32TargetInfo>(T); |
| 4092 | case llvm::Triple::RTEMS: |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 4093 | return new RTEMSTargetInfo<PPC32TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4094 | default: |
| 4095 | return new PPC32TargetInfo(T); |
| 4096 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4097 | |
| 4098 | case llvm::Triple::ppc64: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 4099 | if (Triple.isOSDarwin()) |
Daniel Dunbar | 4c6a226 | 2010-05-30 00:07:30 +0000 | [diff] [blame] | 4100 | return new DarwinPPC64TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4101 | switch (os) { |
Anton Korobeynikov | 7e1812f | 2011-10-12 09:30:58 +0000 | [diff] [blame] | 4102 | case llvm::Triple::Linux: |
| 4103 | return new LinuxTargetInfo<PPC64TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4104 | case llvm::Triple::Lv2: |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 4105 | return new PS3PPUTargetInfo<PPC64TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4106 | case llvm::Triple::FreeBSD: |
Chris Lattner | e03ae30 | 2010-02-16 18:14:57 +0000 | [diff] [blame] | 4107 | return new FreeBSDTargetInfo<PPC64TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4108 | case llvm::Triple::NetBSD: |
| 4109 | return new NetBSDTargetInfo<PPC64TargetInfo>(T); |
| 4110 | default: |
| 4111 | return new PPC64TargetInfo(T); |
| 4112 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4113 | |
Peter Collingbourne | edb66f3 | 2012-05-20 23:28:41 +0000 | [diff] [blame] | 4114 | case llvm::Triple::nvptx: |
| 4115 | return new NVPTX32TargetInfo(T); |
| 4116 | case llvm::Triple::nvptx64: |
| 4117 | return new NVPTX64TargetInfo(T); |
| 4118 | |
Chris Lattner | 9cbeb63 | 2010-03-06 21:21:27 +0000 | [diff] [blame] | 4119 | case llvm::Triple::mblaze: |
| 4120 | return new MBlazeTargetInfo(T); |
| 4121 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4122 | case llvm::Triple::sparc: |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4123 | switch (os) { |
Anton Korobeynikov | 7e1812f | 2011-10-12 09:30:58 +0000 | [diff] [blame] | 4124 | case llvm::Triple::Linux: |
| 4125 | return new LinuxTargetInfo<SparcV8TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4126 | case llvm::Triple::AuroraUX: |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 4127 | return new AuroraUXSparcV8TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4128 | case llvm::Triple::Solaris: |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4129 | return new SolarisSparcV8TargetInfo(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4130 | case llvm::Triple::NetBSD: |
| 4131 | return new NetBSDTargetInfo<SparcV8TargetInfo>(T); |
| 4132 | case llvm::Triple::RTEMS: |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 4133 | return new RTEMSTargetInfo<SparcV8TargetInfo>(T); |
Joerg Sonnenberger | 9a11b74 | 2011-07-04 21:59:44 +0000 | [diff] [blame] | 4134 | default: |
| 4135 | return new SparcV8TargetInfo(T); |
| 4136 | } |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4137 | |
John Thompson | 3f6918a | 2009-11-19 17:18:50 +0000 | [diff] [blame] | 4138 | // FIXME: Need a real SPU target. |
| 4139 | case llvm::Triple::cellspu: |
| 4140 | return new PS3SPUTargetInfo<PPC64TargetInfo>(T); |
| 4141 | |
Eli Friedman | b63decf | 2009-08-19 20:47:07 +0000 | [diff] [blame] | 4142 | case llvm::Triple::tce: |
| 4143 | return new TCETargetInfo(T); |
| 4144 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4145 | case llvm::Triple::x86: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 4146 | if (Triple.isOSDarwin()) |
| 4147 | return new DarwinI386TargetInfo(T); |
| 4148 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4149 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 4150 | case llvm::Triple::AuroraUX: |
| 4151 | return new AuroraUXTargetInfo<X86_32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4152 | case llvm::Triple::Linux: |
| 4153 | return new LinuxTargetInfo<X86_32TargetInfo>(T); |
| 4154 | case llvm::Triple::DragonFly: |
| 4155 | return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(T); |
| 4156 | case llvm::Triple::NetBSD: |
Joerg Sonnenberger | 42378be | 2012-01-06 18:32:26 +0000 | [diff] [blame] | 4157 | return new NetBSDI386TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4158 | case llvm::Triple::OpenBSD: |
| 4159 | return new OpenBSDI386TargetInfo(T); |
| 4160 | case llvm::Triple::FreeBSD: |
| 4161 | return new FreeBSDTargetInfo<X86_32TargetInfo>(T); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4162 | case llvm::Triple::Minix: |
| 4163 | return new MinixTargetInfo<X86_32TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4164 | case llvm::Triple::Solaris: |
| 4165 | return new SolarisTargetInfo<X86_32TargetInfo>(T); |
| 4166 | case llvm::Triple::Cygwin: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 4167 | return new CygwinX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4168 | case llvm::Triple::MinGW32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 4169 | return new MinGWX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4170 | case llvm::Triple::Win32: |
Michael J. Spencer | a764e83 | 2010-10-21 08:22:51 +0000 | [diff] [blame] | 4171 | return new VisualStudioWindowsX86_32TargetInfo(T); |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 4172 | case llvm::Triple::Haiku: |
| 4173 | return new HaikuX86_32TargetInfo(T); |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 4174 | case llvm::Triple::RTEMS: |
| 4175 | return new RTEMSX86_32TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4176 | default: |
| 4177 | return new X86_32TargetInfo(T); |
| 4178 | } |
| 4179 | |
| 4180 | case llvm::Triple::x86_64: |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 4181 | if (Triple.isOSDarwin() || Triple.getEnvironment() == llvm::Triple::MachO) |
| 4182 | return new DarwinX86_64TargetInfo(T); |
| 4183 | |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4184 | switch (os) { |
Edward O'Callaghan | 991f9a7 | 2009-10-18 13:33:59 +0000 | [diff] [blame] | 4185 | case llvm::Triple::AuroraUX: |
| 4186 | return new AuroraUXTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4187 | case llvm::Triple::Linux: |
| 4188 | return new LinuxTargetInfo<X86_64TargetInfo>(T); |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 4189 | case llvm::Triple::DragonFly: |
| 4190 | return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4191 | case llvm::Triple::NetBSD: |
| 4192 | return new NetBSDTargetInfo<X86_64TargetInfo>(T); |
| 4193 | case llvm::Triple::OpenBSD: |
| 4194 | return new OpenBSDX86_64TargetInfo(T); |
| 4195 | case llvm::Triple::FreeBSD: |
| 4196 | return new FreeBSDTargetInfo<X86_64TargetInfo>(T); |
| 4197 | case llvm::Triple::Solaris: |
| 4198 | return new SolarisTargetInfo<X86_64TargetInfo>(T); |
NAKAMURA Takumi | 0aa2057 | 2011-02-17 08:51:38 +0000 | [diff] [blame] | 4199 | case llvm::Triple::MinGW32: |
Daniel Dunbar | 9fe4a5d | 2009-09-23 07:31:35 +0000 | [diff] [blame] | 4200 | return new MinGWX86_64TargetInfo(T); |
| 4201 | case llvm::Triple::Win32: // This is what Triple.h supports now. |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 4202 | return new VisualStudioWindowsX86_64TargetInfo(T); |
Daniel Dunbar | 9d6fa61 | 2009-08-18 05:47:58 +0000 | [diff] [blame] | 4203 | default: |
| 4204 | return new X86_64TargetInfo(T); |
| 4205 | } |
| 4206 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4207 | } |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4208 | |
| 4209 | /// CreateTargetInfo - Return the target info object for the specified target |
| 4210 | /// triple. |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 4211 | TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 4212 | TargetOptions &Opts) { |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4213 | llvm::Triple Triple(Opts.Triple); |
| 4214 | |
| 4215 | // Construct the target |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 4216 | OwningPtr<TargetInfo> Target(AllocateTarget(Triple.str())); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4217 | if (!Target) { |
| 4218 | Diags.Report(diag::err_target_unknown_triple) << Triple.str(); |
| 4219 | return 0; |
| 4220 | } |
| 4221 | |
Daniel Dunbar | eac7c53 | 2009-12-18 18:42:37 +0000 | [diff] [blame] | 4222 | // Set the target CPU if specified. |
| 4223 | if (!Opts.CPU.empty() && !Target->setCPU(Opts.CPU)) { |
| 4224 | Diags.Report(diag::err_target_unknown_cpu) << Opts.CPU; |
| 4225 | return 0; |
| 4226 | } |
| 4227 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4228 | // Set the target ABI if specified. |
| 4229 | if (!Opts.ABI.empty() && !Target->setABI(Opts.ABI)) { |
| 4230 | Diags.Report(diag::err_target_unknown_abi) << Opts.ABI; |
| 4231 | return 0; |
| 4232 | } |
| 4233 | |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 4234 | // Set the target C++ ABI. |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 4235 | if (!Opts.CXXABI.empty() && !Target->setCXXABI(Opts.CXXABI)) { |
Charles Davis | 98b7c5c | 2010-06-11 01:06:47 +0000 | [diff] [blame] | 4236 | Diags.Report(diag::err_target_unknown_cxxabi) << Opts.CXXABI; |
| 4237 | return 0; |
| 4238 | } |
| 4239 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4240 | // Compute the default target features, we need the target to handle this |
| 4241 | // because features may have dependencies on one another. |
| 4242 | llvm::StringMap<bool> Features; |
Chandler Carruth | c3a2e65 | 2011-09-28 05:56:05 +0000 | [diff] [blame] | 4243 | Target->getDefaultFeatures(Features); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4244 | |
| 4245 | // Apply the user specified deltas. |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 4246 | // First the enables. |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4247 | for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), |
| 4248 | ie = Opts.Features.end(); it != ie; ++it) { |
| 4249 | const char *Name = it->c_str(); |
| 4250 | |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 4251 | if (Name[0] != '+') |
| 4252 | continue; |
| 4253 | |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4254 | // Apply the feature via the target. |
Rafael Espindola | 53ac3d8 | 2011-11-27 20:00:43 +0000 | [diff] [blame] | 4255 | if (!Target->setFeatureEnabled(Features, Name + 1, true)) { |
| 4256 | Diags.Report(diag::err_target_invalid_feature) << Name; |
| 4257 | return 0; |
| 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | // Then the disables. |
| 4262 | for (std::vector<std::string>::const_iterator it = Opts.Features.begin(), |
| 4263 | ie = Opts.Features.end(); it != ie; ++it) { |
| 4264 | const char *Name = it->c_str(); |
| 4265 | |
| 4266 | if (Name[0] == '+') |
| 4267 | continue; |
| 4268 | |
| 4269 | // Apply the feature via the target. |
| 4270 | if (Name[0] != '-' || |
| 4271 | !Target->setFeatureEnabled(Features, Name + 1, false)) { |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4272 | Diags.Report(diag::err_target_invalid_feature) << Name; |
| 4273 | return 0; |
| 4274 | } |
| 4275 | } |
| 4276 | |
| 4277 | // Add the features to the compile options. |
| 4278 | // |
| 4279 | // FIXME: If we are completely confident that we have the right set, we only |
| 4280 | // need to pass the minuses. |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 4281 | Opts.Features.clear(); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4282 | for (llvm::StringMap<bool>::const_iterator it = Features.begin(), |
| 4283 | ie = Features.end(); it != ie; ++it) |
Benjamin Kramer | 713575a | 2012-03-05 15:10:44 +0000 | [diff] [blame] | 4284 | Opts.Features.push_back((it->second ? "+" : "-") + it->first().str()); |
Daniel Dunbar | b93292a | 2009-12-19 03:30:57 +0000 | [diff] [blame] | 4285 | Target->HandleTargetFeatures(Opts.Features); |
Daniel Dunbar | d58c03f | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 4286 | |
| 4287 | return Target.take(); |
| 4288 | } |