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