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