blob: 0d44dc010e1a78960c5fe47efd17514489396ba7 [file] [log] [blame]
Chris Lattner1e27fe12006-10-14 07:06:20 +00001//===--- TargetInfo.cpp - Information about Target machine ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner1e27fe12006-10-14 07:06:20 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetInfo and TargetInfoImpl interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/TargetInfo.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/Basic/AddressSpaces.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000016#include "clang/Basic/CharInfo.h"
John Thompsoned4e2952009-11-05 20:14:16 +000017#include "clang/Basic/LangOptions.h"
Chris Lattnerec0a6d92007-09-22 18:29:59 +000018#include "llvm/ADT/APFloat.h"
Anders Carlsson290aa852007-11-25 00:25:21 +000019#include "llvm/ADT/STLExtras.h"
David Blaikie76bd3c82011-09-23 05:35:21 +000020#include "llvm/Support/ErrorHandling.h"
Chris Lattnerc4f02b62008-04-06 04:02:29 +000021#include <cstdlib>
Chris Lattner1e27fe12006-10-14 07:06:20 +000022using namespace clang;
23
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000024static const LangAS::Map DefaultAddrSpaceMap = { 0 };
25
Chris Lattner1df27862008-03-08 08:59:43 +000026// TargetInfo Constructor.
Douglas Gregorbc10b9f2012-10-15 16:45:32 +000027TargetInfo::TargetInfo(const std::string &T) : TargetOpts(), Triple(T)
28{
Daniel Dunbar3d9289c2010-04-15 06:18:39 +000029 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
30 // SPARC. These should be overridden by concrete targets as needed.
Eli Friedman803acb32011-12-22 03:51:45 +000031 BigEndian = true;
Eli Friedmand88c8a12009-04-19 21:38:35 +000032 TLSSupported = true;
Chris Lattner1a8f3942010-04-23 16:29:58 +000033 NoAsmVariants = false;
Chris Lattner5e2ef0c2008-05-09 06:08:39 +000034 PointerWidth = PointerAlign = 32;
Roman Divacky965b0b72011-01-06 08:27:10 +000035 BoolWidth = BoolAlign = 8;
Chris Lattnerb781dc792008-05-08 05:58:21 +000036 IntWidth = IntAlign = 32;
Chris Lattner5a9aaaf2008-05-09 05:50:02 +000037 LongWidth = LongAlign = 32;
38 LongLongWidth = LongLongAlign = 64;
Nick Lewyckyf59e1292011-12-16 22:34:14 +000039 SuitableAlign = 64;
Ulrich Weigandfa806422013-05-06 16:23:57 +000040 MinGlobalAlign = 0;
Anton Korobeynikovf0c267e2011-10-14 23:23:15 +000041 HalfWidth = 16;
42 HalfAlign = 16;
Eli Friedmanb5366062008-05-20 14:21:01 +000043 FloatWidth = 32;
44 FloatAlign = 32;
Nate Begeman65bea232008-04-18 17:17:24 +000045 DoubleWidth = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000046 DoubleAlign = 64;
47 LongDoubleWidth = 64;
48 LongDoubleAlign = 64;
Rafael Espindolae971b9a2010-06-04 23:15:27 +000049 LargeArrayMinWidth = 0;
50 LargeArrayAlign = 0;
Eli Friedman4b72fdd2011-10-14 20:59:01 +000051 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
Chad Rosiercc40ea72012-07-13 23:57:43 +000052 MaxVectorAlign = 0;
Anders Carlsson2a79a902008-10-31 16:05:19 +000053 SizeType = UnsignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000054 PtrDiffType = SignedLong;
Sanjiv Guptad7959242008-10-31 09:52:39 +000055 IntMaxType = SignedLongLong;
56 UIntMaxType = UnsignedLongLong;
Chris Lattner7e4c81c2009-02-13 22:28:55 +000057 IntPtrType = SignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000058 WCharType = SignedInt;
Chris Lattner67204922009-10-21 04:59:34 +000059 WIntType = SignedInt;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +000060 Char16Type = UnsignedShort;
61 Char32Type = UnsignedInt;
Eli Friedman2857ccb2009-07-01 03:36:11 +000062 Int64Type = SignedLongLong;
Edward O'Callaghan847f2a12009-11-21 00:49:54 +000063 SigAtomicType = SignedInt;
Eli Friedman4e91899e2012-11-27 02:58:24 +000064 ProcessIDType = SignedInt;
Fariborz Jahanian29898f42012-04-16 21:03:30 +000065 UseSignedCharForObjCBool = true;
Daniel Dunbar1da65112010-04-15 15:06:18 +000066 UseBitFieldTypeAlignment = true;
Chad Rosier18903ee2011-08-04 01:21:14 +000067 UseZeroLengthBitfieldAlignment = false;
68 ZeroLengthBitfieldBoundary = 0;
Anton Korobeynikovf0c267e2011-10-14 23:23:15 +000069 HalfFormat = &llvm::APFloat::IEEEhalf;
Chris Lattner1df27862008-03-08 08:59:43 +000070 FloatFormat = &llvm::APFloat::IEEEsingle;
71 DoubleFormat = &llvm::APFloat::IEEEdouble;
72 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Eli Friedman873f65a2008-08-21 00:13:15 +000073 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner5c67237f2009-11-07 18:59:41 +000074 "i64:64:64-f32:32:32-f64:64:64-n32";
Chris Lattnerf37bafc2008-10-05 19:22:37 +000075 UserLabelPrefix = "_";
Roman Divacky178e01602011-02-10 16:52:03 +000076 MCountName = "mcount";
Abramo Bagnara41bfb662011-09-08 14:20:25 +000077 RegParmMax = 0;
78 SSERegParmMax = 0;
Daniel Dunbarbd606522010-05-27 00:35:16 +000079 HasAlignMac68kSupport = false;
Daniel Dunbar6f2e8392010-07-14 23:39:36 +000080
81 // Default to no types using fpret.
82 RealTypeUsesObjCFPRet = 0;
John McCall86353412010-08-21 22:46:04 +000083
Anders Carlsson2f1a6c32011-10-31 16:27:11 +000084 // Default to not using fp2ret for __Complex long double
85 ComplexLongDoubleUsesFP2Ret = false;
86
John McCall86353412010-08-21 22:46:04 +000087 // Default to using the Itanium ABI.
John McCall359b8852013-01-25 22:30:49 +000088 TheCXXABI.set(TargetCXXABI::GenericItanium);
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000089
90 // Default to an empty address space map.
91 AddrSpaceMap = &DefaultAddrSpaceMap;
Douglas Gregor20b2ebd2011-03-23 00:50:03 +000092
93 // Default to an unknown platform name.
94 PlatformName = "unknown";
95 PlatformMinVersion = VersionTuple();
Chris Lattner1df27862008-03-08 08:59:43 +000096}
97
Chris Lattnerc3a669b2008-03-08 08:24:01 +000098// Out of line virtual dtor for TargetInfo.
99TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +0000100
Chris Lattnera91c30f2009-02-06 05:04:11 +0000101/// getTypeName - Return the user string for the specified integer type enum.
102/// For example, SignedShort -> "short".
103const char *TargetInfo::getTypeName(IntType T) {
104 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000105 default: llvm_unreachable("not an integer!");
Chris Lattnera91c30f2009-02-06 05:04:11 +0000106 case SignedShort: return "short";
107 case UnsignedShort: return "unsigned short";
108 case SignedInt: return "int";
109 case UnsignedInt: return "unsigned int";
110 case SignedLong: return "long int";
111 case UnsignedLong: return "long unsigned int";
112 case SignedLongLong: return "long long int";
113 case UnsignedLongLong: return "long long unsigned int";
114 }
115}
116
Chris Lattner72cdcac2009-10-21 06:24:21 +0000117/// getTypeConstantSuffix - Return the constant suffix for the specified
118/// integer type enum. For example, SignedLong -> "L".
119const char *TargetInfo::getTypeConstantSuffix(IntType T) {
120 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000121 default: llvm_unreachable("not an integer!");
Chris Lattner72cdcac2009-10-21 06:24:21 +0000122 case SignedShort:
123 case SignedInt: return "";
124 case SignedLong: return "L";
125 case SignedLongLong: return "LL";
126 case UnsignedShort:
127 case UnsignedInt: return "U";
128 case UnsignedLong: return "UL";
129 case UnsignedLongLong: return "ULL";
130 }
131}
132
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000133/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000134/// enum. For example, SignedInt -> getIntWidth().
135unsigned TargetInfo::getTypeWidth(IntType T) const {
136 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000137 default: llvm_unreachable("not an integer!");
Chris Lattnere4a8c642009-11-05 21:21:32 +0000138 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000139 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000140 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000141 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000142 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000143 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000144 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000145 case UnsignedLongLong: return getLongLongWidth();
146 };
147}
148
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000149/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000150/// enum. For example, SignedInt -> getIntAlign().
151unsigned TargetInfo::getTypeAlign(IntType T) const {
152 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000153 default: llvm_unreachable("not an integer!");
Chris Lattnere4a8c642009-11-05 21:21:32 +0000154 case SignedShort:
155 case UnsignedShort: return getShortAlign();
156 case SignedInt:
157 case UnsignedInt: return getIntAlign();
158 case SignedLong:
159 case UnsignedLong: return getLongAlign();
160 case SignedLongLong:
161 case UnsignedLongLong: return getLongLongAlign();
162 };
163}
164
Chris Lattnerc0c04392009-10-25 22:49:18 +0000165/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000166/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000167bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000168 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000169 default: llvm_unreachable("not an integer!");
Chris Lattner72cdcac2009-10-21 06:24:21 +0000170 case SignedShort:
171 case SignedInt:
172 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000173 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000174 return true;
175 case UnsignedShort:
176 case UnsignedInt:
177 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000178 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000179 return false;
180 };
181}
182
John Thompsoned4e2952009-11-05 20:14:16 +0000183/// setForcedLangOptions - Set forced language options.
184/// Apply changes to the target information with respect to certain
185/// language options which change the target configuration.
186void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000187 if (Opts.NoBitFieldTypeAlign)
188 UseBitFieldTypeAlignment = false;
189 if (Opts.ShortWChar)
John Thompsoned4e2952009-11-05 20:14:16 +0000190 WCharType = UnsignedShort;
John Thompsoned4e2952009-11-05 20:14:16 +0000191}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000192
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000193//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000194
Chris Lattner10a5b382007-01-29 05:24:35 +0000195
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000196static StringRef removeGCCRegisterPrefix(StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000197 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000198 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000199
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000200 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000201}
202
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000203/// isValidClobber - Returns whether the passed in string is
204/// a valid clobber in an inline asm statement. This is used by
205/// Sema.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000206bool TargetInfo::isValidClobber(StringRef Name) const {
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000207 return (isValidGCCRegisterName(Name) ||
208 Name == "memory" || Name == "cc");
209}
210
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000211/// isValidGCCRegisterName - Returns whether the passed in string
212/// is a valid register name according to GCC. This is used by Sema for
213/// inline asm statements.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000214bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000215 if (Name.empty())
216 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000217
Anders Carlsson290aa852007-11-25 00:25:21 +0000218 const char * const *Names;
219 unsigned NumNames;
Mike Stump11289f42009-09-09 15:08:12 +0000220
Anders Carlsson290aa852007-11-25 00:25:21 +0000221 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000222 Name = removeGCCRegisterPrefix(Name);
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000223
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000224 getGCCRegNames(Names, NumNames);
Mike Stump11289f42009-09-09 15:08:12 +0000225
Anders Carlsson290aa852007-11-25 00:25:21 +0000226 // If we have a number it maps to an entry in the register name array.
Jordan Rosea7d03842013-02-08 22:30:41 +0000227 if (isDigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000228 int n;
229 if (!Name.getAsInteger(0, n))
Anders Carlsson290aa852007-11-25 00:25:21 +0000230 return n >= 0 && (unsigned)n < NumNames;
231 }
232
233 // Check register names.
234 for (unsigned i = 0; i < NumNames; i++) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000235 if (Name == Names[i])
Anders Carlsson290aa852007-11-25 00:25:21 +0000236 return true;
237 }
Mike Stump11289f42009-09-09 15:08:12 +0000238
Eric Christophercdd36352011-06-21 00:05:20 +0000239 // Check any additional names that we have.
240 const AddlRegName *AddlNames;
241 unsigned NumAddlNames;
242 getGCCAddlRegNames(AddlNames, NumAddlNames);
243 for (unsigned i = 0; i < NumAddlNames; i++)
244 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
245 if (!AddlNames[i].Names[j])
246 break;
247 // Make sure the register that the additional name is for is within
248 // the bounds of the register names from above.
249 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
250 return true;
251 }
252
Anders Carlsson290aa852007-11-25 00:25:21 +0000253 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000254 const GCCRegAlias *Aliases;
Anders Carlsson290aa852007-11-25 00:25:21 +0000255 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000256
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000257 getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson290aa852007-11-25 00:25:21 +0000258 for (unsigned i = 0; i < NumAliases; i++) {
259 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
260 if (!Aliases[i].Aliases[j])
261 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000262 if (Aliases[i].Aliases[j] == Name)
Anders Carlsson290aa852007-11-25 00:25:21 +0000263 return true;
264 }
265 }
Mike Stump11289f42009-09-09 15:08:12 +0000266
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000267 return false;
268}
Anders Carlssonf511f642007-11-27 04:11:28 +0000269
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000270StringRef
271TargetInfo::getNormalizedGCCRegisterName(StringRef Name) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000272 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000273
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000274 // Get rid of any register prefix.
275 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000276
Anders Carlssonf511f642007-11-27 04:11:28 +0000277 const char * const *Names;
278 unsigned NumNames;
279
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000280 getGCCRegNames(Names, NumNames);
Anders Carlssonf511f642007-11-27 04:11:28 +0000281
282 // First, check if we have a number.
Jordan Rosea7d03842013-02-08 22:30:41 +0000283 if (isDigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000284 int n;
285 if (!Name.getAsInteger(0, n)) {
Mike Stump11289f42009-09-09 15:08:12 +0000286 assert(n >= 0 && (unsigned)n < NumNames &&
Anders Carlssonf511f642007-11-27 04:11:28 +0000287 "Out of bounds register number!");
288 return Names[n];
289 }
290 }
Mike Stump11289f42009-09-09 15:08:12 +0000291
Eric Christophercdd36352011-06-21 00:05:20 +0000292 // Check any additional names that we have.
293 const AddlRegName *AddlNames;
294 unsigned NumAddlNames;
295 getGCCAddlRegNames(AddlNames, NumAddlNames);
296 for (unsigned i = 0; i < NumAddlNames; i++)
297 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
298 if (!AddlNames[i].Names[j])
299 break;
300 // Make sure the register that the additional name is for is within
301 // the bounds of the register names from above.
302 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
303 return Name;
304 }
305
Anders Carlssonf511f642007-11-27 04:11:28 +0000306 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000307 const GCCRegAlias *Aliases;
Anders Carlssonf511f642007-11-27 04:11:28 +0000308 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000309
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000310 getGCCRegAliases(Aliases, NumAliases);
Anders Carlssonf511f642007-11-27 04:11:28 +0000311 for (unsigned i = 0; i < NumAliases; i++) {
312 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
313 if (!Aliases[i].Aliases[j])
314 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000315 if (Aliases[i].Aliases[j] == Name)
Anders Carlssonf511f642007-11-27 04:11:28 +0000316 return Aliases[i].Register;
317 }
318 }
Mike Stump11289f42009-09-09 15:08:12 +0000319
Anders Carlssonf511f642007-11-27 04:11:28 +0000320 return Name;
321}
322
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000323bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
324 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000325 // An output constraint must start with '=' or '+'
326 if (*Name != '=' && *Name != '+')
327 return false;
328
329 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000330 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000331
332 Name++;
333 while (*Name) {
334 switch (*Name) {
335 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000336 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000337 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000338 // so we can add more constraints as we hit it.
339 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000340 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000341 }
342 case '&': // early clobber.
343 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000344 case '%': // commutative.
345 // FIXME: Check that there is a another register after this one.
346 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000347 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000348 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000349 break;
350 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000351 case 'o': // offsetable memory operand.
352 case 'V': // non-offsetable memory operand.
353 case '<': // autodecrement memory operand.
354 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000355 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000356 break;
357 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000358 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000359 Info.setAllowsRegister();
360 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000361 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000362 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000363 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000364 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000365 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000366 break;
367 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000368 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000369 case '#': // Ignore as constraint.
370 case '*': // Ignore for choosing register preferences.
John Thompsona5c7d702010-08-10 19:20:14 +0000371 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000372 }
Mike Stump11289f42009-09-09 15:08:12 +0000373
Anders Carlssonf511f642007-11-27 04:11:28 +0000374 Name++;
375 }
Mike Stump11289f42009-09-09 15:08:12 +0000376
Benjamin Kramer1e4a8862013-04-18 22:49:48 +0000377 // If a constraint allows neither memory nor register operands it contains
378 // only modifiers. Reject it.
Benjamin Kramer7ee3b9c2013-04-18 13:23:23 +0000379 return Info.allowsMemory() || Info.allowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000380}
381
Anders Carlssona79203b2009-01-18 01:56:57 +0000382bool TargetInfo::resolveSymbolicName(const char *&Name,
Chris Lattnerc16d4762009-04-26 17:57:12 +0000383 ConstraintInfo *OutputConstraints,
384 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000385 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000386 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000387 Name++;
388 const char *Start = Name;
389 while (*Name && *Name != ']')
390 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000391
Anders Carlssona79203b2009-01-18 01:56:57 +0000392 if (!*Name) {
393 // Missing ']'
394 return false;
395 }
Mike Stump11289f42009-09-09 15:08:12 +0000396
Anders Carlssona79203b2009-01-18 01:56:57 +0000397 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Chris Lattnerc16d4762009-04-26 17:57:12 +0000399 for (Index = 0; Index != NumOutputs; ++Index)
400 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000401 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000402
403 return false;
404}
405
Chris Lattnerc16d4762009-04-26 17:57:12 +0000406bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
407 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000408 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000409 const char *Name = Info.ConstraintStr.c_str();
410
Anders Carlssonf511f642007-11-27 04:11:28 +0000411 while (*Name) {
412 switch (*Name) {
413 default:
414 // Check if we have a matching constraint
415 if (*Name >= '0' && *Name <= '9') {
416 unsigned i = *Name - '0';
Mike Stump11289f42009-09-09 15:08:12 +0000417
Anders Carlssonf511f642007-11-27 04:11:28 +0000418 // Check if matching constraint is out of bounds.
419 if (i >= NumOutputs)
420 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000421
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000422 // A number must refer to an output only operand.
423 if (OutputConstraints[i].isReadWrite())
424 return false;
425
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000426 // If the constraint is already tied, it must be tied to the
427 // same operand referenced to by the number.
428 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
429 return false;
430
Mike Stump11289f42009-09-09 15:08:12 +0000431 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000432 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000433 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000434 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000435 // FIXME: This error return is in place temporarily so we can
436 // add more constraints as we hit it. Eventually, an unknown
437 // constraint should just be treated as 'g'.
438 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000439 }
440 break;
441 case '[': {
442 unsigned Index = 0;
Chris Lattnerc16d4762009-04-26 17:57:12 +0000443 if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000444 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000445
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000446 // If the constraint is already tied, it must be tied to the
447 // same operand referenced to by the number.
448 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
449 return false;
450
Eli Friedman854f1102010-08-11 23:03:37 +0000451 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000452 break;
Mike Stump11289f42009-09-09 15:08:12 +0000453 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000454 case '%': // commutative
455 // FIXME: Fail if % is used with the last operand.
456 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000457 case 'i': // immediate integer.
Anders Carlssona3a96af2008-03-09 06:02:02 +0000458 case 'n': // immediate integer with a known value.
Anders Carlssonf511f642007-11-27 04:11:28 +0000459 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000460 case 'I': // Various constant constraints with target-specific meanings.
461 case 'J':
462 case 'K':
463 case 'L':
464 case 'M':
465 case 'N':
466 case 'O':
467 case 'P':
468 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000469 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000470 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000471 break;
472 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000473 case 'o': // offsettable memory operand.
474 case 'V': // non-offsettable memory operand.
475 case '<': // autodecrement memory operand.
476 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000477 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000478 break;
479 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000480 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000481 Info.setAllowsRegister();
482 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000483 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000484 case 'E': // immediate floating point.
485 case 'F': // immediate floating point.
486 case 'p': // address operand.
487 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000488 case ',': // multiple alternative constraint. Ignore comma.
489 break;
490 case '?': // Disparage slightly code.
Chris Lattner57540c52011-04-15 05:22:18 +0000491 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000492 case '#': // Ignore as constraint.
493 case '*': // Ignore for choosing register preferences.
John Thompsona5c7d702010-08-10 19:20:14 +0000494 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000495 }
Mike Stump11289f42009-09-09 15:08:12 +0000496
Anders Carlssonf511f642007-11-27 04:11:28 +0000497 Name++;
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
Anders Carlssonf511f642007-11-27 04:11:28 +0000500 return true;
501}
John McCall359b8852013-01-25 22:30:49 +0000502
503bool TargetCXXABI::tryParse(llvm::StringRef name) {
504 const Kind unknown = static_cast<Kind>(-1);
505 Kind kind = llvm::StringSwitch<Kind>(name)
506 .Case("arm", GenericARM)
507 .Case("ios", iOS)
508 .Case("itanium", GenericItanium)
509 .Case("microsoft", Microsoft)
510 .Default(unknown);
511 if (kind == unknown) return false;
512
513 set(kind);
514 return true;
515}