blob: c7a87b20eb8fbff209530d672e1419c37a13ba8d [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- TargetInfo.cpp - Information about Target machine ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetInfo and TargetInfoImpl interfaces.
11//
12//===----------------------------------------------------------------------===//
13
Peter Collingbourne207f4d82011-03-18 22:38:29 +000014#include "clang/Basic/AddressSpaces.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000015#include "clang/Basic/TargetInfo.h"
John Thompsona6fda122009-11-05 20:14:16 +000016#include "clang/Basic/LangOptions.h"
Chris Lattner525a0502007-09-22 18:29:59 +000017#include "llvm/ADT/APFloat.h"
Anders Carlsson6fa90862007-11-25 00:25:21 +000018#include "llvm/ADT/STLExtras.h"
Nick Lewycky403ba352010-12-19 20:49:25 +000019#include <cctype>
Chris Lattner5483bdf2008-04-06 04:02:29 +000020#include <cstdlib>
Reid Spencer5f016e22007-07-11 17:01:13 +000021using namespace clang;
22
Peter Collingbourne207f4d82011-03-18 22:38:29 +000023static const LangAS::Map DefaultAddrSpaceMap = { 0 };
24
Chris Lattnercd4fc422008-03-08 08:59:43 +000025// TargetInfo Constructor.
26TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
Daniel Dunbarb6a16932010-04-15 06:18:39 +000027 // 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 Friedmanb030f022009-04-19 21:38:35 +000029 TLSSupported = true;
Chris Lattner9bffb072010-04-23 16:29:58 +000030 NoAsmVariants = false;
Chris Lattner927686f2008-05-09 06:08:39 +000031 PointerWidth = PointerAlign = 32;
Roman Divackyc81f2a22011-01-06 08:27:10 +000032 BoolWidth = BoolAlign = 8;
Chris Lattner2621fd12008-05-08 05:58:21 +000033 IntWidth = IntAlign = 32;
Chris Lattnerec10f582008-05-09 05:50:02 +000034 LongWidth = LongAlign = 32;
35 LongLongWidth = LongLongAlign = 64;
Eli Friedman61538a72008-05-20 14:21:01 +000036 FloatWidth = 32;
37 FloatAlign = 32;
Nate Begeman3d292062008-04-18 17:17:24 +000038 DoubleWidth = 64;
Eli Friedman61538a72008-05-20 14:21:01 +000039 DoubleAlign = 64;
40 LongDoubleWidth = 64;
41 LongDoubleAlign = 64;
Rafael Espindola6deecb02010-06-04 23:15:27 +000042 LargeArrayMinWidth = 0;
43 LargeArrayAlign = 0;
Anders Carlsson6a3615c2008-10-31 16:05:19 +000044 SizeType = UnsignedLong;
Eli Friedmanf509d732008-11-02 02:43:55 +000045 PtrDiffType = SignedLong;
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +000046 IntMaxType = SignedLongLong;
47 UIntMaxType = UnsignedLongLong;
Chris Lattner6ad474f2009-02-13 22:28:55 +000048 IntPtrType = SignedLong;
Eli Friedmanf509d732008-11-02 02:43:55 +000049 WCharType = SignedInt;
Chris Lattnere64ef802009-10-21 04:59:34 +000050 WIntType = SignedInt;
Alisdair Meredithf5c209d2009-07-14 06:30:34 +000051 Char16Type = UnsignedShort;
52 Char32Type = UnsignedInt;
Eli Friedman3c7b6e42009-07-01 03:36:11 +000053 Int64Type = SignedLongLong;
Edward O'Callaghan9cf910e2009-11-21 00:49:54 +000054 SigAtomicType = SignedInt;
Daniel Dunbarb6830d62010-04-15 15:06:18 +000055 UseBitFieldTypeAlignment = true;
Chris Lattnercd4fc422008-03-08 08:59:43 +000056 FloatFormat = &llvm::APFloat::IEEEsingle;
57 DoubleFormat = &llvm::APFloat::IEEEdouble;
58 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Eli Friedmaned855cb2008-08-21 00:13:15 +000059 DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
Chris Lattner1932e122009-11-07 18:59:41 +000060 "i64:64:64-f32:32:32-f64:64:64-n32";
Chris Lattner3fdf4672008-10-05 19:22:37 +000061 UserLabelPrefix = "_";
Roman Divackybe4c8702011-02-10 16:52:03 +000062 MCountName = "mcount";
Daniel Dunbar613fd672010-05-27 00:35:16 +000063 HasAlignMac68kSupport = false;
Daniel Dunbardacf9dd2010-07-14 23:39:36 +000064
65 // Default to no types using fpret.
66 RealTypeUsesObjCFPRet = 0;
John McCallee79a4c2010-08-21 22:46:04 +000067
Chad Rosier822f54a2011-07-25 19:39:39 +000068 // Default to using preferred type alignment.
69 UsePreferredTypeAlign = true;
70
John McCallee79a4c2010-08-21 22:46:04 +000071 // Default to using the Itanium ABI.
72 CXXABI = CXXABI_Itanium;
Peter Collingbourne207f4d82011-03-18 22:38:29 +000073
74 // Default to an empty address space map.
75 AddrSpaceMap = &DefaultAddrSpaceMap;
Douglas Gregor0a0d2b12011-03-23 00:50:03 +000076
77 // Default to an unknown platform name.
78 PlatformName = "unknown";
79 PlatformMinVersion = VersionTuple();
Chris Lattnercd4fc422008-03-08 08:59:43 +000080}
81
Chris Lattner0eaed122008-03-08 08:24:01 +000082// Out of line virtual dtor for TargetInfo.
83TargetInfo::~TargetInfo() {}
Reid Spencer5f016e22007-07-11 17:01:13 +000084
Chris Lattner2b5abf52009-02-06 05:04:11 +000085/// getTypeName - Return the user string for the specified integer type enum.
86/// For example, SignedShort -> "short".
87const char *TargetInfo::getTypeName(IntType T) {
88 switch (T) {
89 default: assert(0 && "not an integer!");
90 case SignedShort: return "short";
91 case UnsignedShort: return "unsigned short";
92 case SignedInt: return "int";
93 case UnsignedInt: return "unsigned int";
94 case SignedLong: return "long int";
95 case UnsignedLong: return "long unsigned int";
96 case SignedLongLong: return "long long int";
97 case UnsignedLongLong: return "long long unsigned int";
98 }
99}
100
Chris Lattnerb304f772009-10-21 06:24:21 +0000101/// getTypeConstantSuffix - Return the constant suffix for the specified
102/// integer type enum. For example, SignedLong -> "L".
103const char *TargetInfo::getTypeConstantSuffix(IntType T) {
104 switch (T) {
105 default: assert(0 && "not an integer!");
106 case SignedShort:
107 case SignedInt: return "";
108 case SignedLong: return "L";
109 case SignedLongLong: return "LL";
110 case UnsignedShort:
111 case UnsignedInt: return "U";
112 case UnsignedLong: return "UL";
113 case UnsignedLongLong: return "ULL";
114 }
115}
116
Michael J. Spencer237cf582010-10-18 07:10:59 +0000117/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattnerb304f772009-10-21 06:24:21 +0000118/// enum. For example, SignedInt -> getIntWidth().
119unsigned TargetInfo::getTypeWidth(IntType T) const {
120 switch (T) {
121 default: assert(0 && "not an integer!");
Chris Lattner9099e7b2009-11-05 21:21:32 +0000122 case SignedShort:
Chris Lattnerb304f772009-10-21 06:24:21 +0000123 case UnsignedShort: return getShortWidth();
Chris Lattner9099e7b2009-11-05 21:21:32 +0000124 case SignedInt:
Chris Lattnerb304f772009-10-21 06:24:21 +0000125 case UnsignedInt: return getIntWidth();
Chris Lattner9099e7b2009-11-05 21:21:32 +0000126 case SignedLong:
Chris Lattnerb304f772009-10-21 06:24:21 +0000127 case UnsignedLong: return getLongWidth();
Chris Lattner9099e7b2009-11-05 21:21:32 +0000128 case SignedLongLong:
Chris Lattnerb304f772009-10-21 06:24:21 +0000129 case UnsignedLongLong: return getLongLongWidth();
130 };
131}
132
Michael J. Spencer237cf582010-10-18 07:10:59 +0000133/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattner9099e7b2009-11-05 21:21:32 +0000134/// enum. For example, SignedInt -> getIntAlign().
135unsigned TargetInfo::getTypeAlign(IntType T) const {
136 switch (T) {
137 default: assert(0 && "not an integer!");
138 case SignedShort:
139 case UnsignedShort: return getShortAlign();
140 case SignedInt:
141 case UnsignedInt: return getIntAlign();
142 case SignedLong:
143 case UnsignedLong: return getLongAlign();
144 case SignedLongLong:
145 case UnsignedLongLong: return getLongLongAlign();
146 };
147}
148
Chris Lattner961f0702009-10-25 22:49:18 +0000149/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattnerb304f772009-10-21 06:24:21 +0000150/// the type is signed; false otherwise.
Chris Lattner3f59c972010-12-25 23:25:43 +0000151bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattnerb304f772009-10-21 06:24:21 +0000152 switch (T) {
153 default: assert(0 && "not an integer!");
154 case SignedShort:
155 case SignedInt:
156 case SignedLong:
Michael J. Spencer237cf582010-10-18 07:10:59 +0000157 case SignedLongLong:
Chris Lattnerb304f772009-10-21 06:24:21 +0000158 return true;
159 case UnsignedShort:
160 case UnsignedInt:
161 case UnsignedLong:
Michael J. Spencer237cf582010-10-18 07:10:59 +0000162 case UnsignedLongLong:
Chris Lattnerb304f772009-10-21 06:24:21 +0000163 return false;
164 };
165}
166
John Thompsona6fda122009-11-05 20:14:16 +0000167/// setForcedLangOptions - Set forced language options.
168/// Apply changes to the target information with respect to certain
169/// language options which change the target configuration.
170void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
Daniel Dunbarfb937b82010-04-15 15:06:22 +0000171 if (Opts.NoBitFieldTypeAlign)
172 UseBitFieldTypeAlignment = false;
173 if (Opts.ShortWChar)
John Thompsona6fda122009-11-05 20:14:16 +0000174 WCharType = UnsignedShort;
John Thompsona6fda122009-11-05 20:14:16 +0000175}
Chris Lattnerb304f772009-10-21 06:24:21 +0000176
Chris Lattner525a0502007-09-22 18:29:59 +0000177//===----------------------------------------------------------------------===//
Chris Lattner525a0502007-09-22 18:29:59 +0000178
Reid Spencer5f016e22007-07-11 17:01:13 +0000179
Chris Lattner5f9e2722011-07-23 10:55:15 +0000180static StringRef removeGCCRegisterPrefix(StringRef Name) {
Anders Carlssonea041752008-02-06 00:11:32 +0000181 if (Name[0] == '%' || Name[0] == '#')
Anders Carlsson83c021c2010-01-30 19:12:25 +0000182 Name = Name.substr(1);
Michael J. Spencer237cf582010-10-18 07:10:59 +0000183
Anders Carlsson83c021c2010-01-30 19:12:25 +0000184 return Name;
Anders Carlssonea041752008-02-06 00:11:32 +0000185}
186
Eric Christopherde31fd72011-06-28 18:20:53 +0000187/// isValidClobber - Returns whether the passed in string is
188/// a valid clobber in an inline asm statement. This is used by
189/// Sema.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000190bool TargetInfo::isValidClobber(StringRef Name) const {
Eric Christopherde31fd72011-06-28 18:20:53 +0000191 return (isValidGCCRegisterName(Name) ||
192 Name == "memory" || Name == "cc");
193}
194
Anders Carlsson3346ae62007-11-24 23:38:12 +0000195/// isValidGCCRegisterName - Returns whether the passed in string
196/// is a valid register name according to GCC. This is used by Sema for
197/// inline asm statements.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000198bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
Anders Carlsson83c021c2010-01-30 19:12:25 +0000199 if (Name.empty())
200 return false;
Michael J. Spencer237cf582010-10-18 07:10:59 +0000201
Anders Carlsson6fa90862007-11-25 00:25:21 +0000202 const char * const *Names;
203 unsigned NumNames;
Mike Stump1eb44332009-09-09 15:08:12 +0000204
Anders Carlsson6fa90862007-11-25 00:25:21 +0000205 // Get rid of any register prefix.
Anders Carlsson83c021c2010-01-30 19:12:25 +0000206 Name = removeGCCRegisterPrefix(Name);
Anders Carlssonea041752008-02-06 00:11:32 +0000207
Chris Lattner0eaed122008-03-08 08:24:01 +0000208 getGCCRegNames(Names, NumNames);
Mike Stump1eb44332009-09-09 15:08:12 +0000209
Anders Carlsson6fa90862007-11-25 00:25:21 +0000210 // If we have a number it maps to an entry in the register name array.
211 if (isdigit(Name[0])) {
Anders Carlsson83c021c2010-01-30 19:12:25 +0000212 int n;
213 if (!Name.getAsInteger(0, n))
Anders Carlsson6fa90862007-11-25 00:25:21 +0000214 return n >= 0 && (unsigned)n < NumNames;
215 }
216
217 // Check register names.
218 for (unsigned i = 0; i < NumNames; i++) {
Anders Carlsson83c021c2010-01-30 19:12:25 +0000219 if (Name == Names[i])
Anders Carlsson6fa90862007-11-25 00:25:21 +0000220 return true;
221 }
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Eric Christophercfd323d2011-06-21 00:05:20 +0000223 // Check any additional names that we have.
224 const AddlRegName *AddlNames;
225 unsigned NumAddlNames;
226 getGCCAddlRegNames(AddlNames, NumAddlNames);
227 for (unsigned i = 0; i < NumAddlNames; i++)
228 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
229 if (!AddlNames[i].Names[j])
230 break;
231 // Make sure the register that the additional name is for is within
232 // the bounds of the register names from above.
233 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
234 return true;
235 }
236
Anders Carlsson6fa90862007-11-25 00:25:21 +0000237 // Now check aliases.
Chris Lattner0eaed122008-03-08 08:24:01 +0000238 const GCCRegAlias *Aliases;
Anders Carlsson6fa90862007-11-25 00:25:21 +0000239 unsigned NumAliases;
Mike Stump1eb44332009-09-09 15:08:12 +0000240
Chris Lattner0eaed122008-03-08 08:24:01 +0000241 getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson6fa90862007-11-25 00:25:21 +0000242 for (unsigned i = 0; i < NumAliases; i++) {
243 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
244 if (!Aliases[i].Aliases[j])
245 break;
Anders Carlsson83c021c2010-01-30 19:12:25 +0000246 if (Aliases[i].Aliases[j] == Name)
Anders Carlsson6fa90862007-11-25 00:25:21 +0000247 return true;
248 }
249 }
Mike Stump1eb44332009-09-09 15:08:12 +0000250
Anders Carlsson3346ae62007-11-24 23:38:12 +0000251 return false;
252}
Anders Carlssond04c6e22007-11-27 04:11:28 +0000253
Chris Lattner5f9e2722011-07-23 10:55:15 +0000254StringRef
255TargetInfo::getNormalizedGCCRegisterName(StringRef Name) const {
Anders Carlssond04c6e22007-11-27 04:11:28 +0000256 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Anders Carlsson83c021c2010-01-30 19:12:25 +0000258 // Get rid of any register prefix.
259 Name = removeGCCRegisterPrefix(Name);
Mike Stump1eb44332009-09-09 15:08:12 +0000260
Anders Carlssond04c6e22007-11-27 04:11:28 +0000261 const char * const *Names;
262 unsigned NumNames;
263
Chris Lattner0eaed122008-03-08 08:24:01 +0000264 getGCCRegNames(Names, NumNames);
Anders Carlssond04c6e22007-11-27 04:11:28 +0000265
266 // First, check if we have a number.
267 if (isdigit(Name[0])) {
Anders Carlsson83c021c2010-01-30 19:12:25 +0000268 int n;
269 if (!Name.getAsInteger(0, n)) {
Mike Stump1eb44332009-09-09 15:08:12 +0000270 assert(n >= 0 && (unsigned)n < NumNames &&
Anders Carlssond04c6e22007-11-27 04:11:28 +0000271 "Out of bounds register number!");
272 return Names[n];
273 }
274 }
Mike Stump1eb44332009-09-09 15:08:12 +0000275
Eric Christophercfd323d2011-06-21 00:05:20 +0000276 // Check any additional names that we have.
277 const AddlRegName *AddlNames;
278 unsigned NumAddlNames;
279 getGCCAddlRegNames(AddlNames, NumAddlNames);
280 for (unsigned i = 0; i < NumAddlNames; i++)
281 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
282 if (!AddlNames[i].Names[j])
283 break;
284 // Make sure the register that the additional name is for is within
285 // the bounds of the register names from above.
286 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
287 return Name;
288 }
289
Anders Carlssond04c6e22007-11-27 04:11:28 +0000290 // Now check aliases.
Chris Lattner0eaed122008-03-08 08:24:01 +0000291 const GCCRegAlias *Aliases;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000292 unsigned NumAliases;
Mike Stump1eb44332009-09-09 15:08:12 +0000293
Chris Lattner0eaed122008-03-08 08:24:01 +0000294 getGCCRegAliases(Aliases, NumAliases);
Anders Carlssond04c6e22007-11-27 04:11:28 +0000295 for (unsigned i = 0; i < NumAliases; i++) {
296 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
297 if (!Aliases[i].Aliases[j])
298 break;
Anders Carlsson83c021c2010-01-30 19:12:25 +0000299 if (Aliases[i].Aliases[j] == Name)
Anders Carlssond04c6e22007-11-27 04:11:28 +0000300 return Aliases[i].Register;
301 }
302 }
Mike Stump1eb44332009-09-09 15:08:12 +0000303
Anders Carlssond04c6e22007-11-27 04:11:28 +0000304 return Name;
305}
306
Chris Lattner432c8692009-04-26 17:19:08 +0000307bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
308 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000309 // An output constraint must start with '=' or '+'
310 if (*Name != '=' && *Name != '+')
311 return false;
312
313 if (*Name == '+')
Chris Lattner44def072009-04-26 07:16:29 +0000314 Info.setIsReadWrite();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000315
316 Name++;
317 while (*Name) {
318 switch (*Name) {
319 default:
Chris Lattner44def072009-04-26 07:16:29 +0000320 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenek5ab201a2008-04-24 16:36:38 +0000321 // FIXME: We temporarily return false
Anders Carlssond04c6e22007-11-27 04:11:28 +0000322 // so we can add more constraints as we hit it.
323 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenek5ab201a2008-04-24 16:36:38 +0000324 return false;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000325 }
326 case '&': // early clobber.
327 break;
Chris Lattner40539832009-10-13 04:32:07 +0000328 case '%': // commutative.
329 // FIXME: Check that there is a another register after this one.
330 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000331 case 'r': // general register.
Chris Lattner44def072009-04-26 07:16:29 +0000332 Info.setAllowsRegister();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000333 break;
334 case 'm': // memory operand.
Dale Johannesen0f048a42010-09-07 18:40:41 +0000335 case 'o': // offsetable memory operand.
336 case 'V': // non-offsetable memory operand.
337 case '<': // autodecrement memory operand.
338 case '>': // autoincrement memory operand.
Chris Lattner44def072009-04-26 07:16:29 +0000339 Info.setAllowsMemory();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000340 break;
341 case 'g': // general register, memory operand or immediate integer.
Anders Carlsson775841f2009-01-18 02:12:04 +0000342 case 'X': // any operand.
Chris Lattner44def072009-04-26 07:16:29 +0000343 Info.setAllowsRegister();
344 Info.setAllowsMemory();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000345 break;
John Thompsonef44e112010-08-10 19:20:14 +0000346 case ',': // multiple alternative constraint. Pass it.
John Thompson6f158032010-08-11 00:58:20 +0000347 // Handle additional optional '=' or '+' modifiers.
John Thompson2f474ea2010-09-18 01:15:13 +0000348 if (Name[1] == '=' || Name[1] == '+')
John Thompson6f158032010-08-11 00:58:20 +0000349 Name++;
John Thompsonef44e112010-08-10 19:20:14 +0000350 break;
351 case '?': // Disparage slightly code.
Dale Johannesen0f048a42010-09-07 18:40:41 +0000352 case '!': // Disparage severely.
John Thompsonef44e112010-08-10 19:20:14 +0000353 break; // Pass them.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000354 }
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Anders Carlssond04c6e22007-11-27 04:11:28 +0000356 Name++;
357 }
Mike Stump1eb44332009-09-09 15:08:12 +0000358
Anders Carlssond04c6e22007-11-27 04:11:28 +0000359 return true;
360}
361
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000362bool TargetInfo::resolveSymbolicName(const char *&Name,
Chris Lattner2819fa82009-04-26 17:57:12 +0000363 ConstraintInfo *OutputConstraints,
364 unsigned NumOutputs,
Chris Lattner44def072009-04-26 07:16:29 +0000365 unsigned &Index) const {
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000366 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000367 Name++;
368 const char *Start = Name;
369 while (*Name && *Name != ']')
370 Name++;
Mike Stump1eb44332009-09-09 15:08:12 +0000371
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000372 if (!*Name) {
373 // Missing ']'
374 return false;
375 }
Mike Stump1eb44332009-09-09 15:08:12 +0000376
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000377 std::string SymbolicName(Start, Name - Start);
Mike Stump1eb44332009-09-09 15:08:12 +0000378
Chris Lattner2819fa82009-04-26 17:57:12 +0000379 for (Index = 0; Index != NumOutputs; ++Index)
380 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000381 return true;
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000382
383 return false;
384}
385
Chris Lattner2819fa82009-04-26 17:57:12 +0000386bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
387 unsigned NumOutputs,
Chris Lattner44def072009-04-26 07:16:29 +0000388 ConstraintInfo &Info) const {
Chris Lattner432c8692009-04-26 17:19:08 +0000389 const char *Name = Info.ConstraintStr.c_str();
390
Anders Carlssond04c6e22007-11-27 04:11:28 +0000391 while (*Name) {
392 switch (*Name) {
393 default:
394 // Check if we have a matching constraint
395 if (*Name >= '0' && *Name <= '9') {
396 unsigned i = *Name - '0';
Mike Stump1eb44332009-09-09 15:08:12 +0000397
Anders Carlssond04c6e22007-11-27 04:11:28 +0000398 // Check if matching constraint is out of bounds.
399 if (i >= NumOutputs)
400 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000401
Anders Carlsson86eda392010-11-03 02:22:29 +0000402 // A number must refer to an output only operand.
403 if (OutputConstraints[i].isReadWrite())
404 return false;
405
Anders Carlsson79ca1ee2010-11-03 02:54:51 +0000406 // If the constraint is already tied, it must be tied to the
407 // same operand referenced to by the number.
408 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
409 return false;
410
Mike Stump1eb44332009-09-09 15:08:12 +0000411 // The constraint should have the same info as the respective
Anders Carlsson03eb5432009-01-27 20:38:24 +0000412 // output constraint.
Chris Lattnerd6887612009-04-26 18:05:25 +0000413 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattner44def072009-04-26 07:16:29 +0000414 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar302684c2008-08-25 09:46:27 +0000415 // FIXME: This error return is in place temporarily so we can
416 // add more constraints as we hit it. Eventually, an unknown
417 // constraint should just be treated as 'g'.
418 return false;
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000419 }
420 break;
421 case '[': {
422 unsigned Index = 0;
Chris Lattner2819fa82009-04-26 17:57:12 +0000423 if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000424 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000425
Anders Carlsson79ca1ee2010-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() != Index)
429 return false;
430
Eli Friedman0eff4e72010-08-11 23:03:37 +0000431 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlsson42e1ee02009-01-18 01:56:57 +0000432 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000433 }
Anders Carlsson44fe49c2007-12-08 19:32:57 +0000434 case '%': // commutative
435 // FIXME: Fail if % is used with the last operand.
436 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000437 case 'i': // immediate integer.
Anders Carlssonefdfa772008-03-09 06:02:02 +0000438 case 'n': // immediate integer with a known value.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000439 break;
Chris Lattner1d138792009-05-06 04:33:31 +0000440 case 'I': // Various constant constraints with target-specific meanings.
441 case 'J':
442 case 'K':
443 case 'L':
444 case 'M':
445 case 'N':
446 case 'O':
447 case 'P':
448 break;
Anders Carlssond04c6e22007-11-27 04:11:28 +0000449 case 'r': // general register.
Chris Lattner44def072009-04-26 07:16:29 +0000450 Info.setAllowsRegister();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000451 break;
452 case 'm': // memory operand.
Dale Johannesen0f048a42010-09-07 18:40:41 +0000453 case 'o': // offsettable memory operand.
454 case 'V': // non-offsettable memory operand.
455 case '<': // autodecrement memory operand.
456 case '>': // autoincrement memory operand.
Chris Lattner44def072009-04-26 07:16:29 +0000457 Info.setAllowsMemory();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000458 break;
459 case 'g': // general register, memory operand or immediate integer.
Anders Carlsson775841f2009-01-18 02:12:04 +0000460 case 'X': // any operand.
Chris Lattner44def072009-04-26 07:16:29 +0000461 Info.setAllowsRegister();
462 Info.setAllowsMemory();
Anders Carlssond04c6e22007-11-27 04:11:28 +0000463 break;
John Thompson7ccc58f2010-09-21 22:04:54 +0000464 case 'E': // immediate floating point.
465 case 'F': // immediate floating point.
466 case 'p': // address operand.
467 break;
John Thompsonef44e112010-08-10 19:20:14 +0000468 case ',': // multiple alternative constraint. Ignore comma.
469 break;
470 case '?': // Disparage slightly code.
Chris Lattnerfc8f0e12011-04-15 05:22:18 +0000471 case '!': // Disparage severely.
John Thompsonef44e112010-08-10 19:20:14 +0000472 break; // Pass them.
Anders Carlssond04c6e22007-11-27 04:11:28 +0000473 }
Mike Stump1eb44332009-09-09 15:08:12 +0000474
Anders Carlssond04c6e22007-11-27 04:11:28 +0000475 Name++;
476 }
Mike Stump1eb44332009-09-09 15:08:12 +0000477
Anders Carlssond04c6e22007-11-27 04:11:28 +0000478 return true;
479}