blob: a9eeb8b4cc4e3cd79a4af3f4a23f0b4421523708 [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"
John Thompsoned4e2952009-11-05 20:14:16 +000015#include "clang/Basic/LangOptions.h"
Chris Lattnerec0a6d92007-09-22 18:29:59 +000016#include "llvm/ADT/APFloat.h"
Anders Carlsson290aa852007-11-25 00:25:21 +000017#include "llvm/ADT/STLExtras.h"
Nick Lewycky2e998b72010-12-19 20:49:25 +000018#include <cctype>
Chris Lattnerc4f02b62008-04-06 04:02:29 +000019#include <cstdlib>
Chris Lattner1e27fe12006-10-14 07:06:20 +000020using namespace clang;
21
Chris Lattner1df27862008-03-08 08:59:43 +000022// TargetInfo Constructor.
23TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
Daniel Dunbar3d9289c2010-04-15 06:18:39 +000024 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
25 // SPARC. These should be overridden by concrete targets as needed.
Eli Friedmand88c8a12009-04-19 21:38:35 +000026 TLSSupported = true;
Chris Lattner1a8f3942010-04-23 16:29:58 +000027 NoAsmVariants = false;
Chris Lattner5e2ef0c2008-05-09 06:08:39 +000028 PointerWidth = PointerAlign = 32;
Roman Divacky965b0b72011-01-06 08:27:10 +000029 BoolWidth = BoolAlign = 8;
Chris Lattnerb781dc792008-05-08 05:58:21 +000030 IntWidth = IntAlign = 32;
Chris Lattner5a9aaaf2008-05-09 05:50:02 +000031 LongWidth = LongAlign = 32;
32 LongLongWidth = LongLongAlign = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000033 FloatWidth = 32;
34 FloatAlign = 32;
Nate Begeman65bea232008-04-18 17:17:24 +000035 DoubleWidth = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000036 DoubleAlign = 64;
37 LongDoubleWidth = 64;
38 LongDoubleAlign = 64;
Rafael Espindolae971b9a2010-06-04 23:15:27 +000039 LargeArrayMinWidth = 0;
40 LargeArrayAlign = 0;
Anders Carlsson2a79a902008-10-31 16:05:19 +000041 SizeType = UnsignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000042 PtrDiffType = SignedLong;
Sanjiv Guptad7959242008-10-31 09:52:39 +000043 IntMaxType = SignedLongLong;
44 UIntMaxType = UnsignedLongLong;
Chris Lattner7e4c81c2009-02-13 22:28:55 +000045 IntPtrType = SignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000046 WCharType = SignedInt;
Chris Lattner67204922009-10-21 04:59:34 +000047 WIntType = SignedInt;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +000048 Char16Type = UnsignedShort;
49 Char32Type = UnsignedInt;
Eli Friedman2857ccb2009-07-01 03:36:11 +000050 Int64Type = SignedLongLong;
Edward O'Callaghan847f2a12009-11-21 00:49:54 +000051 SigAtomicType = SignedInt;
Daniel Dunbar1da65112010-04-15 15:06:18 +000052 UseBitFieldTypeAlignment = true;
Chris Lattner1df27862008-03-08 08:59:43 +000053 FloatFormat = &llvm::APFloat::IEEEsingle;
54 DoubleFormat = &llvm::APFloat::IEEEdouble;
55 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Eli Friedman873f65a2008-08-21 00:13:15 +000056 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 +000057 "i64:64:64-f32:32:32-f64:64:64-n32";
Chris Lattnerf37bafc2008-10-05 19:22:37 +000058 UserLabelPrefix = "_";
Roman Divacky178e01602011-02-10 16:52:03 +000059 MCountName = "mcount";
Daniel Dunbarbd606522010-05-27 00:35:16 +000060 HasAlignMac68kSupport = false;
Daniel Dunbar6f2e8392010-07-14 23:39:36 +000061
62 // Default to no types using fpret.
63 RealTypeUsesObjCFPRet = 0;
John McCall86353412010-08-21 22:46:04 +000064
65 // Default to using the Itanium ABI.
66 CXXABI = CXXABI_Itanium;
Chris Lattner1df27862008-03-08 08:59:43 +000067}
68
Chris Lattnerc3a669b2008-03-08 08:24:01 +000069// Out of line virtual dtor for TargetInfo.
70TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +000071
Chris Lattnera91c30f2009-02-06 05:04:11 +000072/// getTypeName - Return the user string for the specified integer type enum.
73/// For example, SignedShort -> "short".
74const char *TargetInfo::getTypeName(IntType T) {
75 switch (T) {
76 default: assert(0 && "not an integer!");
77 case SignedShort: return "short";
78 case UnsignedShort: return "unsigned short";
79 case SignedInt: return "int";
80 case UnsignedInt: return "unsigned int";
81 case SignedLong: return "long int";
82 case UnsignedLong: return "long unsigned int";
83 case SignedLongLong: return "long long int";
84 case UnsignedLongLong: return "long long unsigned int";
85 }
86}
87
Chris Lattner72cdcac2009-10-21 06:24:21 +000088/// getTypeConstantSuffix - Return the constant suffix for the specified
89/// integer type enum. For example, SignedLong -> "L".
90const char *TargetInfo::getTypeConstantSuffix(IntType T) {
91 switch (T) {
92 default: assert(0 && "not an integer!");
93 case SignedShort:
94 case SignedInt: return "";
95 case SignedLong: return "L";
96 case SignedLongLong: return "LL";
97 case UnsignedShort:
98 case UnsignedInt: return "U";
99 case UnsignedLong: return "UL";
100 case UnsignedLongLong: return "ULL";
101 }
102}
103
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000104/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000105/// enum. For example, SignedInt -> getIntWidth().
106unsigned TargetInfo::getTypeWidth(IntType T) const {
107 switch (T) {
108 default: assert(0 && "not an integer!");
Chris Lattnere4a8c642009-11-05 21:21:32 +0000109 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000110 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000111 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000112 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000113 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000114 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000115 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000116 case UnsignedLongLong: return getLongLongWidth();
117 };
118}
119
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000120/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000121/// enum. For example, SignedInt -> getIntAlign().
122unsigned TargetInfo::getTypeAlign(IntType T) const {
123 switch (T) {
124 default: assert(0 && "not an integer!");
125 case SignedShort:
126 case UnsignedShort: return getShortAlign();
127 case SignedInt:
128 case UnsignedInt: return getIntAlign();
129 case SignedLong:
130 case UnsignedLong: return getLongAlign();
131 case SignedLongLong:
132 case UnsignedLongLong: return getLongLongAlign();
133 };
134}
135
Chris Lattnerc0c04392009-10-25 22:49:18 +0000136/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000137/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000138bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000139 switch (T) {
140 default: assert(0 && "not an integer!");
141 case SignedShort:
142 case SignedInt:
143 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000144 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000145 return true;
146 case UnsignedShort:
147 case UnsignedInt:
148 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000149 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000150 return false;
151 };
152}
153
John Thompsoned4e2952009-11-05 20:14:16 +0000154/// setForcedLangOptions - Set forced language options.
155/// Apply changes to the target information with respect to certain
156/// language options which change the target configuration.
157void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000158 if (Opts.NoBitFieldTypeAlign)
159 UseBitFieldTypeAlignment = false;
160 if (Opts.ShortWChar)
John Thompsoned4e2952009-11-05 20:14:16 +0000161 WCharType = UnsignedShort;
John Thompsoned4e2952009-11-05 20:14:16 +0000162}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000163
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000164//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000165
Chris Lattner10a5b382007-01-29 05:24:35 +0000166
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000167static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000168 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000169 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000170
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000171 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000172}
173
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000174/// isValidGCCRegisterName - Returns whether the passed in string
175/// is a valid register name according to GCC. This is used by Sema for
176/// inline asm statements.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000177bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const {
178 if (Name.empty())
179 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000180
Anders Carlsson290aa852007-11-25 00:25:21 +0000181 const char * const *Names;
182 unsigned NumNames;
Mike Stump11289f42009-09-09 15:08:12 +0000183
Anders Carlsson290aa852007-11-25 00:25:21 +0000184 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000185 Name = removeGCCRegisterPrefix(Name);
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000186
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000187 if (Name == "memory" || Name == "cc")
Anders Carlsson290aa852007-11-25 00:25:21 +0000188 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000189
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000190 getGCCRegNames(Names, NumNames);
Mike Stump11289f42009-09-09 15:08:12 +0000191
Anders Carlsson290aa852007-11-25 00:25:21 +0000192 // If we have a number it maps to an entry in the register name array.
193 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000194 int n;
195 if (!Name.getAsInteger(0, n))
Anders Carlsson290aa852007-11-25 00:25:21 +0000196 return n >= 0 && (unsigned)n < NumNames;
197 }
198
199 // Check register names.
200 for (unsigned i = 0; i < NumNames; i++) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000201 if (Name == Names[i])
Anders Carlsson290aa852007-11-25 00:25:21 +0000202 return true;
203 }
Mike Stump11289f42009-09-09 15:08:12 +0000204
Anders Carlsson290aa852007-11-25 00:25:21 +0000205 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000206 const GCCRegAlias *Aliases;
Anders Carlsson290aa852007-11-25 00:25:21 +0000207 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000208
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000209 getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson290aa852007-11-25 00:25:21 +0000210 for (unsigned i = 0; i < NumAliases; i++) {
211 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
212 if (!Aliases[i].Aliases[j])
213 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000214 if (Aliases[i].Aliases[j] == Name)
Anders Carlsson290aa852007-11-25 00:25:21 +0000215 return true;
216 }
217 }
Mike Stump11289f42009-09-09 15:08:12 +0000218
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000219 return false;
220}
Anders Carlssonf511f642007-11-27 04:11:28 +0000221
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000222llvm::StringRef
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000223TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000224 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000225
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000226 // Get rid of any register prefix.
227 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000228
Anders Carlssonf511f642007-11-27 04:11:28 +0000229 const char * const *Names;
230 unsigned NumNames;
231
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000232 getGCCRegNames(Names, NumNames);
Anders Carlssonf511f642007-11-27 04:11:28 +0000233
234 // First, check if we have a number.
235 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000236 int n;
237 if (!Name.getAsInteger(0, n)) {
Mike Stump11289f42009-09-09 15:08:12 +0000238 assert(n >= 0 && (unsigned)n < NumNames &&
Anders Carlssonf511f642007-11-27 04:11:28 +0000239 "Out of bounds register number!");
240 return Names[n];
241 }
242 }
Mike Stump11289f42009-09-09 15:08:12 +0000243
Anders Carlssonf511f642007-11-27 04:11:28 +0000244 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000245 const GCCRegAlias *Aliases;
Anders Carlssonf511f642007-11-27 04:11:28 +0000246 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000247
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000248 getGCCRegAliases(Aliases, NumAliases);
Anders Carlssonf511f642007-11-27 04:11:28 +0000249 for (unsigned i = 0; i < NumAliases; i++) {
250 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
251 if (!Aliases[i].Aliases[j])
252 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000253 if (Aliases[i].Aliases[j] == Name)
Anders Carlssonf511f642007-11-27 04:11:28 +0000254 return Aliases[i].Register;
255 }
256 }
Mike Stump11289f42009-09-09 15:08:12 +0000257
Anders Carlssonf511f642007-11-27 04:11:28 +0000258 return Name;
259}
260
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000261bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
262 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000263 // An output constraint must start with '=' or '+'
264 if (*Name != '=' && *Name != '+')
265 return false;
266
267 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000268 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000269
270 Name++;
271 while (*Name) {
272 switch (*Name) {
273 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000274 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000275 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000276 // so we can add more constraints as we hit it.
277 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000278 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000279 }
280 case '&': // early clobber.
281 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000282 case '%': // commutative.
283 // FIXME: Check that there is a another register after this one.
284 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000285 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000286 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000287 break;
288 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000289 case 'o': // offsetable memory operand.
290 case 'V': // non-offsetable memory operand.
291 case '<': // autodecrement memory operand.
292 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000293 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000294 break;
295 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000296 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000297 Info.setAllowsRegister();
298 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000299 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000300 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000301 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000302 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000303 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000304 break;
305 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000306 case '!': // Disparage severely.
John Thompsona5c7d702010-08-10 19:20:14 +0000307 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
Anders Carlssonf511f642007-11-27 04:11:28 +0000310 Name++;
311 }
Mike Stump11289f42009-09-09 15:08:12 +0000312
Anders Carlssonf511f642007-11-27 04:11:28 +0000313 return true;
314}
315
Anders Carlssona79203b2009-01-18 01:56:57 +0000316bool TargetInfo::resolveSymbolicName(const char *&Name,
Chris Lattnerc16d4762009-04-26 17:57:12 +0000317 ConstraintInfo *OutputConstraints,
318 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000319 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000320 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000321 Name++;
322 const char *Start = Name;
323 while (*Name && *Name != ']')
324 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000325
Anders Carlssona79203b2009-01-18 01:56:57 +0000326 if (!*Name) {
327 // Missing ']'
328 return false;
329 }
Mike Stump11289f42009-09-09 15:08:12 +0000330
Anders Carlssona79203b2009-01-18 01:56:57 +0000331 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000332
Chris Lattnerc16d4762009-04-26 17:57:12 +0000333 for (Index = 0; Index != NumOutputs; ++Index)
334 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000335 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000336
337 return false;
338}
339
Chris Lattnerc16d4762009-04-26 17:57:12 +0000340bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
341 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000342 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000343 const char *Name = Info.ConstraintStr.c_str();
344
Anders Carlssonf511f642007-11-27 04:11:28 +0000345 while (*Name) {
346 switch (*Name) {
347 default:
348 // Check if we have a matching constraint
349 if (*Name >= '0' && *Name <= '9') {
350 unsigned i = *Name - '0';
Mike Stump11289f42009-09-09 15:08:12 +0000351
Anders Carlssonf511f642007-11-27 04:11:28 +0000352 // Check if matching constraint is out of bounds.
353 if (i >= NumOutputs)
354 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000355
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000356 // A number must refer to an output only operand.
357 if (OutputConstraints[i].isReadWrite())
358 return false;
359
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000360 // If the constraint is already tied, it must be tied to the
361 // same operand referenced to by the number.
362 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
363 return false;
364
Mike Stump11289f42009-09-09 15:08:12 +0000365 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000366 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000367 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000368 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000369 // FIXME: This error return is in place temporarily so we can
370 // add more constraints as we hit it. Eventually, an unknown
371 // constraint should just be treated as 'g'.
372 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000373 }
374 break;
375 case '[': {
376 unsigned Index = 0;
Chris Lattnerc16d4762009-04-26 17:57:12 +0000377 if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000378 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000379
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000380 // If the constraint is already tied, it must be tied to the
381 // same operand referenced to by the number.
382 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
383 return false;
384
Eli Friedman854f1102010-08-11 23:03:37 +0000385 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000386 break;
Mike Stump11289f42009-09-09 15:08:12 +0000387 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000388 case '%': // commutative
389 // FIXME: Fail if % is used with the last operand.
390 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000391 case 'i': // immediate integer.
Anders Carlssona3a96af2008-03-09 06:02:02 +0000392 case 'n': // immediate integer with a known value.
Anders Carlssonf511f642007-11-27 04:11:28 +0000393 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000394 case 'I': // Various constant constraints with target-specific meanings.
395 case 'J':
396 case 'K':
397 case 'L':
398 case 'M':
399 case 'N':
400 case 'O':
401 case 'P':
402 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000403 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000404 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000405 break;
406 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000407 case 'o': // offsettable memory operand.
408 case 'V': // non-offsettable memory operand.
409 case '<': // autodecrement memory operand.
410 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000411 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000412 break;
413 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000414 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000415 Info.setAllowsRegister();
416 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000417 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000418 case 'E': // immediate floating point.
419 case 'F': // immediate floating point.
420 case 'p': // address operand.
421 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000422 case ',': // multiple alternative constraint. Ignore comma.
423 break;
424 case '?': // Disparage slightly code.
425 case '!': // Disparage severly.
426 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000427 }
Mike Stump11289f42009-09-09 15:08:12 +0000428
Anders Carlssonf511f642007-11-27 04:11:28 +0000429 Name++;
430 }
Mike Stump11289f42009-09-09 15:08:12 +0000431
Anders Carlssonf511f642007-11-27 04:11:28 +0000432 return true;
433}