Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- TargetInfo.cpp - Information about Target machine ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the TargetInfo and TargetInfoImpl interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 14 | #include "clang/Basic/AddressSpaces.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "clang/Basic/TargetInfo.h" |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 16 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 525a050 | 2007-09-22 18:29:59 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/APFloat.h" |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Nick Lewycky | 403ba35 | 2010-12-19 20:49:25 +0000 | [diff] [blame] | 19 | #include <cctype> |
Chris Lattner | 5483bdf | 2008-04-06 04:02:29 +0000 | [diff] [blame] | 20 | #include <cstdlib> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 23 | static const LangAS::Map DefaultAddrSpaceMap = { 0 }; |
| 24 | |
Chris Lattner | cd4fc42 | 2008-03-08 08:59:43 +0000 | [diff] [blame] | 25 | // TargetInfo Constructor. |
| 26 | TargetInfo::TargetInfo(const std::string &T) : Triple(T) { |
Daniel Dunbar | b6a1693 | 2010-04-15 06:18:39 +0000 | [diff] [blame] | 27 | // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or |
| 28 | // SPARC. These should be overridden by concrete targets as needed. |
Eli Friedman | b030f02 | 2009-04-19 21:38:35 +0000 | [diff] [blame] | 29 | TLSSupported = true; |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 30 | NoAsmVariants = false; |
Chris Lattner | 927686f | 2008-05-09 06:08:39 +0000 | [diff] [blame] | 31 | PointerWidth = PointerAlign = 32; |
Roman Divacky | c81f2a2 | 2011-01-06 08:27:10 +0000 | [diff] [blame] | 32 | BoolWidth = BoolAlign = 8; |
Chris Lattner | 2621fd1 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 33 | IntWidth = IntAlign = 32; |
Chris Lattner | ec10f58 | 2008-05-09 05:50:02 +0000 | [diff] [blame] | 34 | LongWidth = LongAlign = 32; |
| 35 | LongLongWidth = LongLongAlign = 64; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 36 | FloatWidth = 32; |
| 37 | FloatAlign = 32; |
Nate Begeman | 3d29206 | 2008-04-18 17:17:24 +0000 | [diff] [blame] | 38 | DoubleWidth = 64; |
Eli Friedman | 61538a7 | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 39 | DoubleAlign = 64; |
| 40 | LongDoubleWidth = 64; |
| 41 | LongDoubleAlign = 64; |
Rafael Espindola | 6deecb0 | 2010-06-04 23:15:27 +0000 | [diff] [blame] | 42 | LargeArrayMinWidth = 0; |
| 43 | LargeArrayAlign = 0; |
Anders Carlsson | 6a3615c | 2008-10-31 16:05:19 +0000 | [diff] [blame] | 44 | SizeType = UnsignedLong; |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 45 | PtrDiffType = SignedLong; |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 46 | IntMaxType = SignedLongLong; |
| 47 | UIntMaxType = UnsignedLongLong; |
Chris Lattner | 6ad474f | 2009-02-13 22:28:55 +0000 | [diff] [blame] | 48 | IntPtrType = SignedLong; |
Eli Friedman | f509d73 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 49 | WCharType = SignedInt; |
Chris Lattner | e64ef80 | 2009-10-21 04:59:34 +0000 | [diff] [blame] | 50 | WIntType = SignedInt; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 51 | Char16Type = UnsignedShort; |
| 52 | Char32Type = UnsignedInt; |
Eli Friedman | 3c7b6e4 | 2009-07-01 03:36:11 +0000 | [diff] [blame] | 53 | Int64Type = SignedLongLong; |
Edward O'Callaghan | 9cf910e | 2009-11-21 00:49:54 +0000 | [diff] [blame] | 54 | SigAtomicType = SignedInt; |
Daniel Dunbar | b6830d6 | 2010-04-15 15:06:18 +0000 | [diff] [blame] | 55 | UseBitFieldTypeAlignment = true; |
Chris Lattner | cd4fc42 | 2008-03-08 08:59:43 +0000 | [diff] [blame] | 56 | FloatFormat = &llvm::APFloat::IEEEsingle; |
| 57 | DoubleFormat = &llvm::APFloat::IEEEdouble; |
| 58 | LongDoubleFormat = &llvm::APFloat::IEEEdouble; |
Eli Friedman | ed855cb | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 59 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
Chris Lattner | 1932e12 | 2009-11-07 18:59:41 +0000 | [diff] [blame] | 60 | "i64:64:64-f32:32:32-f64:64:64-n32"; |
Chris Lattner | 3fdf467 | 2008-10-05 19:22:37 +0000 | [diff] [blame] | 61 | UserLabelPrefix = "_"; |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 62 | MCountName = "mcount"; |
Daniel Dunbar | 613fd67 | 2010-05-27 00:35:16 +0000 | [diff] [blame] | 63 | HasAlignMac68kSupport = false; |
Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 64 | |
| 65 | // Default to no types using fpret. |
| 66 | RealTypeUsesObjCFPRet = 0; |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 67 | |
| 68 | // Default to using the Itanium ABI. |
| 69 | CXXABI = CXXABI_Itanium; |
Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 70 | |
| 71 | // Default to an empty address space map. |
| 72 | AddrSpaceMap = &DefaultAddrSpaceMap; |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 73 | |
| 74 | // Default to an unknown platform name. |
| 75 | PlatformName = "unknown"; |
| 76 | PlatformMinVersion = VersionTuple(); |
Chris Lattner | cd4fc42 | 2008-03-08 08:59:43 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 79 | // Out of line virtual dtor for TargetInfo. |
| 80 | TargetInfo::~TargetInfo() {} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 2b5abf5 | 2009-02-06 05:04:11 +0000 | [diff] [blame] | 82 | /// getTypeName - Return the user string for the specified integer type enum. |
| 83 | /// For example, SignedShort -> "short". |
| 84 | const char *TargetInfo::getTypeName(IntType T) { |
| 85 | switch (T) { |
| 86 | default: assert(0 && "not an integer!"); |
| 87 | case SignedShort: return "short"; |
| 88 | case UnsignedShort: return "unsigned short"; |
| 89 | case SignedInt: return "int"; |
| 90 | case UnsignedInt: return "unsigned int"; |
| 91 | case SignedLong: return "long int"; |
| 92 | case UnsignedLong: return "long unsigned int"; |
| 93 | case SignedLongLong: return "long long int"; |
| 94 | case UnsignedLongLong: return "long long unsigned int"; |
| 95 | } |
| 96 | } |
| 97 | |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 98 | /// getTypeConstantSuffix - Return the constant suffix for the specified |
| 99 | /// integer type enum. For example, SignedLong -> "L". |
| 100 | const char *TargetInfo::getTypeConstantSuffix(IntType T) { |
| 101 | switch (T) { |
| 102 | default: assert(0 && "not an integer!"); |
| 103 | case SignedShort: |
| 104 | case SignedInt: return ""; |
| 105 | case SignedLong: return "L"; |
| 106 | case SignedLongLong: return "LL"; |
| 107 | case UnsignedShort: |
| 108 | case UnsignedInt: return "U"; |
| 109 | case UnsignedLong: return "UL"; |
| 110 | case UnsignedLongLong: return "ULL"; |
| 111 | } |
| 112 | } |
| 113 | |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 114 | /// getTypeWidth - Return the width (in bits) of the specified integer type |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 115 | /// enum. For example, SignedInt -> getIntWidth(). |
| 116 | unsigned TargetInfo::getTypeWidth(IntType T) const { |
| 117 | switch (T) { |
| 118 | default: assert(0 && "not an integer!"); |
Chris Lattner | 9099e7b | 2009-11-05 21:21:32 +0000 | [diff] [blame] | 119 | case SignedShort: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 120 | case UnsignedShort: return getShortWidth(); |
Chris Lattner | 9099e7b | 2009-11-05 21:21:32 +0000 | [diff] [blame] | 121 | case SignedInt: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 122 | case UnsignedInt: return getIntWidth(); |
Chris Lattner | 9099e7b | 2009-11-05 21:21:32 +0000 | [diff] [blame] | 123 | case SignedLong: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 124 | case UnsignedLong: return getLongWidth(); |
Chris Lattner | 9099e7b | 2009-11-05 21:21:32 +0000 | [diff] [blame] | 125 | case SignedLongLong: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 126 | case UnsignedLongLong: return getLongLongWidth(); |
| 127 | }; |
| 128 | } |
| 129 | |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 130 | /// getTypeAlign - Return the alignment (in bits) of the specified integer type |
Chris Lattner | 9099e7b | 2009-11-05 21:21:32 +0000 | [diff] [blame] | 131 | /// enum. For example, SignedInt -> getIntAlign(). |
| 132 | unsigned TargetInfo::getTypeAlign(IntType T) const { |
| 133 | switch (T) { |
| 134 | default: assert(0 && "not an integer!"); |
| 135 | case SignedShort: |
| 136 | case UnsignedShort: return getShortAlign(); |
| 137 | case SignedInt: |
| 138 | case UnsignedInt: return getIntAlign(); |
| 139 | case SignedLong: |
| 140 | case UnsignedLong: return getLongAlign(); |
| 141 | case SignedLongLong: |
| 142 | case UnsignedLongLong: return getLongLongAlign(); |
| 143 | }; |
| 144 | } |
| 145 | |
Chris Lattner | 961f070 | 2009-10-25 22:49:18 +0000 | [diff] [blame] | 146 | /// isTypeSigned - Return whether an integer types is signed. Returns true if |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 147 | /// the type is signed; false otherwise. |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 148 | bool TargetInfo::isTypeSigned(IntType T) { |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 149 | switch (T) { |
| 150 | default: assert(0 && "not an integer!"); |
| 151 | case SignedShort: |
| 152 | case SignedInt: |
| 153 | case SignedLong: |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 154 | case SignedLongLong: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 155 | return true; |
| 156 | case UnsignedShort: |
| 157 | case UnsignedInt: |
| 158 | case UnsignedLong: |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 159 | case UnsignedLongLong: |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 160 | return false; |
| 161 | }; |
| 162 | } |
| 163 | |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 164 | /// setForcedLangOptions - Set forced language options. |
| 165 | /// Apply changes to the target information with respect to certain |
| 166 | /// language options which change the target configuration. |
| 167 | void TargetInfo::setForcedLangOptions(LangOptions &Opts) { |
Daniel Dunbar | fb937b8 | 2010-04-15 15:06:22 +0000 | [diff] [blame] | 168 | if (Opts.NoBitFieldTypeAlign) |
| 169 | UseBitFieldTypeAlignment = false; |
| 170 | if (Opts.ShortWChar) |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 171 | WCharType = UnsignedShort; |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 172 | } |
Chris Lattner | b304f77 | 2009-10-21 06:24:21 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 525a050 | 2007-09-22 18:29:59 +0000 | [diff] [blame] | 174 | //===----------------------------------------------------------------------===// |
Chris Lattner | 525a050 | 2007-09-22 18:29:59 +0000 | [diff] [blame] | 175 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 176 | |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 177 | static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) { |
Anders Carlsson | ea04175 | 2008-02-06 00:11:32 +0000 | [diff] [blame] | 178 | if (Name[0] == '%' || Name[0] == '#') |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 179 | Name = Name.substr(1); |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 180 | |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 181 | return Name; |
Anders Carlsson | ea04175 | 2008-02-06 00:11:32 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 184 | /// isValidGCCRegisterName - Returns whether the passed in string |
| 185 | /// is a valid register name according to GCC. This is used by Sema for |
| 186 | /// inline asm statements. |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 187 | bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const { |
| 188 | if (Name.empty()) |
| 189 | return false; |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 190 | |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 191 | const char * const *Names; |
| 192 | unsigned NumNames; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 194 | // Get rid of any register prefix. |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 195 | Name = removeGCCRegisterPrefix(Name); |
Anders Carlsson | ea04175 | 2008-02-06 00:11:32 +0000 | [diff] [blame] | 196 | |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 197 | if (Name == "memory" || Name == "cc") |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 198 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 200 | getGCCRegNames(Names, NumNames); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 202 | // If we have a number it maps to an entry in the register name array. |
| 203 | if (isdigit(Name[0])) { |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 204 | int n; |
| 205 | if (!Name.getAsInteger(0, n)) |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 206 | return n >= 0 && (unsigned)n < NumNames; |
| 207 | } |
| 208 | |
| 209 | // Check register names. |
| 210 | for (unsigned i = 0; i < NumNames; i++) { |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 211 | if (Name == Names[i]) |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 212 | return true; |
| 213 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 215 | // Check any additional names that we have. |
| 216 | const AddlRegName *AddlNames; |
| 217 | unsigned NumAddlNames; |
| 218 | getGCCAddlRegNames(AddlNames, NumAddlNames); |
| 219 | for (unsigned i = 0; i < NumAddlNames; i++) |
| 220 | for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { |
| 221 | if (!AddlNames[i].Names[j]) |
| 222 | break; |
| 223 | // Make sure the register that the additional name is for is within |
| 224 | // the bounds of the register names from above. |
| 225 | if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) |
| 226 | return true; |
| 227 | } |
| 228 | |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 229 | // Now check aliases. |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 230 | const GCCRegAlias *Aliases; |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 231 | unsigned NumAliases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 233 | getGCCRegAliases(Aliases, NumAliases); |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 234 | for (unsigned i = 0; i < NumAliases; i++) { |
| 235 | for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { |
| 236 | if (!Aliases[i].Aliases[j]) |
| 237 | break; |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 238 | if (Aliases[i].Aliases[j] == Name) |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 243 | return false; |
| 244 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 245 | |
Michael J. Spencer | 237cf58 | 2010-10-18 07:10:59 +0000 | [diff] [blame] | 246 | llvm::StringRef |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 247 | TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const { |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 248 | assert(isValidGCCRegisterName(Name) && "Invalid register passed in"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 250 | // Get rid of any register prefix. |
| 251 | Name = removeGCCRegisterPrefix(Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 252 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 253 | const char * const *Names; |
| 254 | unsigned NumNames; |
| 255 | |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 256 | getGCCRegNames(Names, NumNames); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 257 | |
| 258 | // First, check if we have a number. |
| 259 | if (isdigit(Name[0])) { |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 260 | int n; |
| 261 | if (!Name.getAsInteger(0, n)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | assert(n >= 0 && (unsigned)n < NumNames && |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 263 | "Out of bounds register number!"); |
| 264 | return Names[n]; |
| 265 | } |
| 266 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 267 | |
Eric Christopher | cfd323d | 2011-06-21 00:05:20 +0000 | [diff] [blame] | 268 | // Check any additional names that we have. |
| 269 | const AddlRegName *AddlNames; |
| 270 | unsigned NumAddlNames; |
| 271 | getGCCAddlRegNames(AddlNames, NumAddlNames); |
| 272 | for (unsigned i = 0; i < NumAddlNames; i++) |
| 273 | for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { |
| 274 | if (!AddlNames[i].Names[j]) |
| 275 | break; |
| 276 | // Make sure the register that the additional name is for is within |
| 277 | // the bounds of the register names from above. |
| 278 | if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) |
| 279 | return Name; |
| 280 | } |
| 281 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 282 | // Now check aliases. |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 283 | const GCCRegAlias *Aliases; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 284 | unsigned NumAliases; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Chris Lattner | 0eaed12 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 286 | getGCCRegAliases(Aliases, NumAliases); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 287 | for (unsigned i = 0; i < NumAliases; i++) { |
| 288 | for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { |
| 289 | if (!Aliases[i].Aliases[j]) |
| 290 | break; |
Anders Carlsson | 83c021c | 2010-01-30 19:12:25 +0000 | [diff] [blame] | 291 | if (Aliases[i].Aliases[j] == Name) |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 292 | return Aliases[i].Register; |
| 293 | } |
| 294 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 295 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 296 | return Name; |
| 297 | } |
| 298 | |
Chris Lattner | 432c869 | 2009-04-26 17:19:08 +0000 | [diff] [blame] | 299 | bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const { |
| 300 | const char *Name = Info.getConstraintStr().c_str(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 301 | // An output constraint must start with '=' or '+' |
| 302 | if (*Name != '=' && *Name != '+') |
| 303 | return false; |
| 304 | |
| 305 | if (*Name == '+') |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 306 | Info.setIsReadWrite(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 307 | |
| 308 | Name++; |
| 309 | while (*Name) { |
| 310 | switch (*Name) { |
| 311 | default: |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 312 | if (!validateAsmConstraint(Name, Info)) { |
Ted Kremenek | 5ab201a | 2008-04-24 16:36:38 +0000 | [diff] [blame] | 313 | // FIXME: We temporarily return false |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 314 | // so we can add more constraints as we hit it. |
| 315 | // Eventually, an unknown constraint should just be treated as 'g'. |
Ted Kremenek | 5ab201a | 2008-04-24 16:36:38 +0000 | [diff] [blame] | 316 | return false; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 317 | } |
| 318 | case '&': // early clobber. |
| 319 | break; |
Chris Lattner | 4053983 | 2009-10-13 04:32:07 +0000 | [diff] [blame] | 320 | case '%': // commutative. |
| 321 | // FIXME: Check that there is a another register after this one. |
| 322 | break; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 323 | case 'r': // general register. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 324 | Info.setAllowsRegister(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 325 | break; |
| 326 | case 'm': // memory operand. |
Dale Johannesen | 0f048a4 | 2010-09-07 18:40:41 +0000 | [diff] [blame] | 327 | case 'o': // offsetable memory operand. |
| 328 | case 'V': // non-offsetable memory operand. |
| 329 | case '<': // autodecrement memory operand. |
| 330 | case '>': // autoincrement memory operand. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 331 | Info.setAllowsMemory(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 332 | break; |
| 333 | case 'g': // general register, memory operand or immediate integer. |
Anders Carlsson | 775841f | 2009-01-18 02:12:04 +0000 | [diff] [blame] | 334 | case 'X': // any operand. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 335 | Info.setAllowsRegister(); |
| 336 | Info.setAllowsMemory(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 337 | break; |
John Thompson | ef44e11 | 2010-08-10 19:20:14 +0000 | [diff] [blame] | 338 | case ',': // multiple alternative constraint. Pass it. |
John Thompson | 6f15803 | 2010-08-11 00:58:20 +0000 | [diff] [blame] | 339 | // Handle additional optional '=' or '+' modifiers. |
John Thompson | 2f474ea | 2010-09-18 01:15:13 +0000 | [diff] [blame] | 340 | if (Name[1] == '=' || Name[1] == '+') |
John Thompson | 6f15803 | 2010-08-11 00:58:20 +0000 | [diff] [blame] | 341 | Name++; |
John Thompson | ef44e11 | 2010-08-10 19:20:14 +0000 | [diff] [blame] | 342 | break; |
| 343 | case '?': // Disparage slightly code. |
Dale Johannesen | 0f048a4 | 2010-09-07 18:40:41 +0000 | [diff] [blame] | 344 | case '!': // Disparage severely. |
John Thompson | ef44e11 | 2010-08-10 19:20:14 +0000 | [diff] [blame] | 345 | break; // Pass them. |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 348 | Name++; |
| 349 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 351 | return true; |
| 352 | } |
| 353 | |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 354 | bool TargetInfo::resolveSymbolicName(const char *&Name, |
Chris Lattner | 2819fa8 | 2009-04-26 17:57:12 +0000 | [diff] [blame] | 355 | ConstraintInfo *OutputConstraints, |
| 356 | unsigned NumOutputs, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 357 | unsigned &Index) const { |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 358 | assert(*Name == '[' && "Symbolic name did not start with '['"); |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 359 | Name++; |
| 360 | const char *Start = Name; |
| 361 | while (*Name && *Name != ']') |
| 362 | Name++; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 364 | if (!*Name) { |
| 365 | // Missing ']' |
| 366 | return false; |
| 367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 369 | std::string SymbolicName(Start, Name - Start); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
Chris Lattner | 2819fa8 | 2009-04-26 17:57:12 +0000 | [diff] [blame] | 371 | for (Index = 0; Index != NumOutputs; ++Index) |
| 372 | if (SymbolicName == OutputConstraints[Index].getName()) |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 373 | return true; |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 374 | |
| 375 | return false; |
| 376 | } |
| 377 | |
Chris Lattner | 2819fa8 | 2009-04-26 17:57:12 +0000 | [diff] [blame] | 378 | bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints, |
| 379 | unsigned NumOutputs, |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 380 | ConstraintInfo &Info) const { |
Chris Lattner | 432c869 | 2009-04-26 17:19:08 +0000 | [diff] [blame] | 381 | const char *Name = Info.ConstraintStr.c_str(); |
| 382 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 383 | while (*Name) { |
| 384 | switch (*Name) { |
| 385 | default: |
| 386 | // Check if we have a matching constraint |
| 387 | if (*Name >= '0' && *Name <= '9') { |
| 388 | unsigned i = *Name - '0'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 390 | // Check if matching constraint is out of bounds. |
| 391 | if (i >= NumOutputs) |
| 392 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Anders Carlsson | 86eda39 | 2010-11-03 02:22:29 +0000 | [diff] [blame] | 394 | // A number must refer to an output only operand. |
| 395 | if (OutputConstraints[i].isReadWrite()) |
| 396 | return false; |
| 397 | |
Anders Carlsson | 79ca1ee | 2010-11-03 02:54:51 +0000 | [diff] [blame] | 398 | // If the constraint is already tied, it must be tied to the |
| 399 | // same operand referenced to by the number. |
| 400 | if (Info.hasTiedOperand() && Info.getTiedOperand() != i) |
| 401 | return false; |
| 402 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | // The constraint should have the same info as the respective |
Anders Carlsson | 03eb543 | 2009-01-27 20:38:24 +0000 | [diff] [blame] | 404 | // output constraint. |
Chris Lattner | d688761 | 2009-04-26 18:05:25 +0000 | [diff] [blame] | 405 | Info.setTiedOperand(i, OutputConstraints[i]); |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 406 | } else if (!validateAsmConstraint(Name, Info)) { |
Daniel Dunbar | 302684c | 2008-08-25 09:46:27 +0000 | [diff] [blame] | 407 | // FIXME: This error return is in place temporarily so we can |
| 408 | // add more constraints as we hit it. Eventually, an unknown |
| 409 | // constraint should just be treated as 'g'. |
| 410 | return false; |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 411 | } |
| 412 | break; |
| 413 | case '[': { |
| 414 | unsigned Index = 0; |
Chris Lattner | 2819fa8 | 2009-04-26 17:57:12 +0000 | [diff] [blame] | 415 | if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index)) |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 416 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | |
Anders Carlsson | 79ca1ee | 2010-11-03 02:54:51 +0000 | [diff] [blame] | 418 | // If the constraint is already tied, it must be tied to the |
| 419 | // same operand referenced to by the number. |
| 420 | if (Info.hasTiedOperand() && Info.getTiedOperand() != Index) |
| 421 | return false; |
| 422 | |
Eli Friedman | 0eff4e7 | 2010-08-11 23:03:37 +0000 | [diff] [blame] | 423 | Info.setTiedOperand(Index, OutputConstraints[Index]); |
Anders Carlsson | 42e1ee0 | 2009-01-18 01:56:57 +0000 | [diff] [blame] | 424 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 426 | case '%': // commutative |
| 427 | // FIXME: Fail if % is used with the last operand. |
| 428 | break; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 429 | case 'i': // immediate integer. |
Anders Carlsson | efdfa77 | 2008-03-09 06:02:02 +0000 | [diff] [blame] | 430 | case 'n': // immediate integer with a known value. |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 431 | break; |
Chris Lattner | 1d13879 | 2009-05-06 04:33:31 +0000 | [diff] [blame] | 432 | case 'I': // Various constant constraints with target-specific meanings. |
| 433 | case 'J': |
| 434 | case 'K': |
| 435 | case 'L': |
| 436 | case 'M': |
| 437 | case 'N': |
| 438 | case 'O': |
| 439 | case 'P': |
| 440 | break; |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 441 | case 'r': // general register. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 442 | Info.setAllowsRegister(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 443 | break; |
| 444 | case 'm': // memory operand. |
Dale Johannesen | 0f048a4 | 2010-09-07 18:40:41 +0000 | [diff] [blame] | 445 | case 'o': // offsettable memory operand. |
| 446 | case 'V': // non-offsettable memory operand. |
| 447 | case '<': // autodecrement memory operand. |
| 448 | case '>': // autoincrement memory operand. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 449 | Info.setAllowsMemory(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 450 | break; |
| 451 | case 'g': // general register, memory operand or immediate integer. |
Anders Carlsson | 775841f | 2009-01-18 02:12:04 +0000 | [diff] [blame] | 452 | case 'X': // any operand. |
Chris Lattner | 44def07 | 2009-04-26 07:16:29 +0000 | [diff] [blame] | 453 | Info.setAllowsRegister(); |
| 454 | Info.setAllowsMemory(); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 455 | break; |
John Thompson | 7ccc58f | 2010-09-21 22:04:54 +0000 | [diff] [blame] | 456 | case 'E': // immediate floating point. |
| 457 | case 'F': // immediate floating point. |
| 458 | case 'p': // address operand. |
| 459 | break; |
John Thompson | ef44e11 | 2010-08-10 19:20:14 +0000 | [diff] [blame] | 460 | case ',': // multiple alternative constraint. Ignore comma. |
| 461 | break; |
| 462 | case '?': // Disparage slightly code. |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 463 | case '!': // Disparage severely. |
John Thompson | ef44e11 | 2010-08-10 19:20:14 +0000 | [diff] [blame] | 464 | break; // Pass them. |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 465 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 467 | Name++; |
| 468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 470 | return true; |
| 471 | } |