blob: 1696cae840ce5787679f3ceca8b65216690d4e6d [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
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000014#include "clang/Basic/AddressSpaces.h"
Chris Lattner1e27fe12006-10-14 07:06:20 +000015#include "clang/Basic/TargetInfo.h"
John Thompsoned4e2952009-11-05 20:14:16 +000016#include "clang/Basic/LangOptions.h"
Chris Lattnerec0a6d92007-09-22 18:29:59 +000017#include "llvm/ADT/APFloat.h"
Anders Carlsson290aa852007-11-25 00:25:21 +000018#include "llvm/ADT/STLExtras.h"
Nick Lewycky2e998b72010-12-19 20:49:25 +000019#include <cctype>
Chris Lattnerc4f02b62008-04-06 04:02:29 +000020#include <cstdlib>
Chris Lattner1e27fe12006-10-14 07:06:20 +000021using namespace clang;
22
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000023static const LangAS::Map DefaultAddrSpaceMap = { 0 };
24
Chris Lattner1df27862008-03-08 08:59:43 +000025// TargetInfo Constructor.
26TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
Daniel Dunbar3d9289c2010-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 Friedmand88c8a12009-04-19 21:38:35 +000029 TLSSupported = true;
Chris Lattner1a8f3942010-04-23 16:29:58 +000030 NoAsmVariants = false;
Chris Lattner5e2ef0c2008-05-09 06:08:39 +000031 PointerWidth = PointerAlign = 32;
Roman Divacky965b0b72011-01-06 08:27:10 +000032 BoolWidth = BoolAlign = 8;
Chris Lattnerb781dc792008-05-08 05:58:21 +000033 IntWidth = IntAlign = 32;
Chris Lattner5a9aaaf2008-05-09 05:50:02 +000034 LongWidth = LongAlign = 32;
35 LongLongWidth = LongLongAlign = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000036 FloatWidth = 32;
37 FloatAlign = 32;
Nate Begeman65bea232008-04-18 17:17:24 +000038 DoubleWidth = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000039 DoubleAlign = 64;
40 LongDoubleWidth = 64;
41 LongDoubleAlign = 64;
Rafael Espindolae971b9a2010-06-04 23:15:27 +000042 LargeArrayMinWidth = 0;
43 LargeArrayAlign = 0;
Anders Carlsson2a79a902008-10-31 16:05:19 +000044 SizeType = UnsignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000045 PtrDiffType = SignedLong;
Sanjiv Guptad7959242008-10-31 09:52:39 +000046 IntMaxType = SignedLongLong;
47 UIntMaxType = UnsignedLongLong;
Chris Lattner7e4c81c2009-02-13 22:28:55 +000048 IntPtrType = SignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000049 WCharType = SignedInt;
Chris Lattner67204922009-10-21 04:59:34 +000050 WIntType = SignedInt;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +000051 Char16Type = UnsignedShort;
52 Char32Type = UnsignedInt;
Eli Friedman2857ccb2009-07-01 03:36:11 +000053 Int64Type = SignedLongLong;
Edward O'Callaghan847f2a12009-11-21 00:49:54 +000054 SigAtomicType = SignedInt;
Daniel Dunbar1da65112010-04-15 15:06:18 +000055 UseBitFieldTypeAlignment = true;
Chris Lattner1df27862008-03-08 08:59:43 +000056 FloatFormat = &llvm::APFloat::IEEEsingle;
57 DoubleFormat = &llvm::APFloat::IEEEdouble;
58 LongDoubleFormat = &llvm::APFloat::IEEEdouble;
Eli Friedman873f65a2008-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 Lattner5c67237f2009-11-07 18:59:41 +000060 "i64:64:64-f32:32:32-f64:64:64-n32";
Chris Lattnerf37bafc2008-10-05 19:22:37 +000061 UserLabelPrefix = "_";
Roman Divacky178e01602011-02-10 16:52:03 +000062 MCountName = "mcount";
Daniel Dunbarbd606522010-05-27 00:35:16 +000063 HasAlignMac68kSupport = false;
Daniel Dunbar6f2e8392010-07-14 23:39:36 +000064
65 // Default to no types using fpret.
66 RealTypeUsesObjCFPRet = 0;
John McCall86353412010-08-21 22:46:04 +000067
68 // Default to using the Itanium ABI.
69 CXXABI = CXXABI_Itanium;
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000070
71 // Default to an empty address space map.
72 AddrSpaceMap = &DefaultAddrSpaceMap;
Chris Lattner1df27862008-03-08 08:59:43 +000073}
74
Chris Lattnerc3a669b2008-03-08 08:24:01 +000075// Out of line virtual dtor for TargetInfo.
76TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +000077
Chris Lattnera91c30f2009-02-06 05:04:11 +000078/// getTypeName - Return the user string for the specified integer type enum.
79/// For example, SignedShort -> "short".
80const char *TargetInfo::getTypeName(IntType T) {
81 switch (T) {
82 default: assert(0 && "not an integer!");
83 case SignedShort: return "short";
84 case UnsignedShort: return "unsigned short";
85 case SignedInt: return "int";
86 case UnsignedInt: return "unsigned int";
87 case SignedLong: return "long int";
88 case UnsignedLong: return "long unsigned int";
89 case SignedLongLong: return "long long int";
90 case UnsignedLongLong: return "long long unsigned int";
91 }
92}
93
Chris Lattner72cdcac2009-10-21 06:24:21 +000094/// getTypeConstantSuffix - Return the constant suffix for the specified
95/// integer type enum. For example, SignedLong -> "L".
96const char *TargetInfo::getTypeConstantSuffix(IntType T) {
97 switch (T) {
98 default: assert(0 && "not an integer!");
99 case SignedShort:
100 case SignedInt: return "";
101 case SignedLong: return "L";
102 case SignedLongLong: return "LL";
103 case UnsignedShort:
104 case UnsignedInt: return "U";
105 case UnsignedLong: return "UL";
106 case UnsignedLongLong: return "ULL";
107 }
108}
109
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000110/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000111/// enum. For example, SignedInt -> getIntWidth().
112unsigned TargetInfo::getTypeWidth(IntType T) const {
113 switch (T) {
114 default: assert(0 && "not an integer!");
Chris Lattnere4a8c642009-11-05 21:21:32 +0000115 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000116 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000117 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000118 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000119 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000120 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000121 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000122 case UnsignedLongLong: return getLongLongWidth();
123 };
124}
125
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000126/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000127/// enum. For example, SignedInt -> getIntAlign().
128unsigned TargetInfo::getTypeAlign(IntType T) const {
129 switch (T) {
130 default: assert(0 && "not an integer!");
131 case SignedShort:
132 case UnsignedShort: return getShortAlign();
133 case SignedInt:
134 case UnsignedInt: return getIntAlign();
135 case SignedLong:
136 case UnsignedLong: return getLongAlign();
137 case SignedLongLong:
138 case UnsignedLongLong: return getLongLongAlign();
139 };
140}
141
Chris Lattnerc0c04392009-10-25 22:49:18 +0000142/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000143/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000144bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000145 switch (T) {
146 default: assert(0 && "not an integer!");
147 case SignedShort:
148 case SignedInt:
149 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000150 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000151 return true;
152 case UnsignedShort:
153 case UnsignedInt:
154 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000155 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000156 return false;
157 };
158}
159
John Thompsoned4e2952009-11-05 20:14:16 +0000160/// setForcedLangOptions - Set forced language options.
161/// Apply changes to the target information with respect to certain
162/// language options which change the target configuration.
163void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000164 if (Opts.NoBitFieldTypeAlign)
165 UseBitFieldTypeAlignment = false;
166 if (Opts.ShortWChar)
John Thompsoned4e2952009-11-05 20:14:16 +0000167 WCharType = UnsignedShort;
John Thompsoned4e2952009-11-05 20:14:16 +0000168}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000169
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000170//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000171
Chris Lattner10a5b382007-01-29 05:24:35 +0000172
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000173static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000174 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000175 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000176
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000177 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000178}
179
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000180/// isValidGCCRegisterName - Returns whether the passed in string
181/// is a valid register name according to GCC. This is used by Sema for
182/// inline asm statements.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000183bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const {
184 if (Name.empty())
185 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000186
Anders Carlsson290aa852007-11-25 00:25:21 +0000187 const char * const *Names;
188 unsigned NumNames;
Mike Stump11289f42009-09-09 15:08:12 +0000189
Anders Carlsson290aa852007-11-25 00:25:21 +0000190 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000191 Name = removeGCCRegisterPrefix(Name);
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000192
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000193 if (Name == "memory" || Name == "cc")
Anders Carlsson290aa852007-11-25 00:25:21 +0000194 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000195
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000196 getGCCRegNames(Names, NumNames);
Mike Stump11289f42009-09-09 15:08:12 +0000197
Anders Carlsson290aa852007-11-25 00:25:21 +0000198 // If we have a number it maps to an entry in the register name array.
199 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000200 int n;
201 if (!Name.getAsInteger(0, n))
Anders Carlsson290aa852007-11-25 00:25:21 +0000202 return n >= 0 && (unsigned)n < NumNames;
203 }
204
205 // Check register names.
206 for (unsigned i = 0; i < NumNames; i++) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000207 if (Name == Names[i])
Anders Carlsson290aa852007-11-25 00:25:21 +0000208 return true;
209 }
Mike Stump11289f42009-09-09 15:08:12 +0000210
Anders Carlsson290aa852007-11-25 00:25:21 +0000211 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000212 const GCCRegAlias *Aliases;
Anders Carlsson290aa852007-11-25 00:25:21 +0000213 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000214
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000215 getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson290aa852007-11-25 00:25:21 +0000216 for (unsigned i = 0; i < NumAliases; i++) {
217 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
218 if (!Aliases[i].Aliases[j])
219 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000220 if (Aliases[i].Aliases[j] == Name)
Anders Carlsson290aa852007-11-25 00:25:21 +0000221 return true;
222 }
223 }
Mike Stump11289f42009-09-09 15:08:12 +0000224
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000225 return false;
226}
Anders Carlssonf511f642007-11-27 04:11:28 +0000227
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000228llvm::StringRef
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000229TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000230 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000231
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000232 // Get rid of any register prefix.
233 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Anders Carlssonf511f642007-11-27 04:11:28 +0000235 const char * const *Names;
236 unsigned NumNames;
237
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000238 getGCCRegNames(Names, NumNames);
Anders Carlssonf511f642007-11-27 04:11:28 +0000239
240 // First, check if we have a number.
241 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000242 int n;
243 if (!Name.getAsInteger(0, n)) {
Mike Stump11289f42009-09-09 15:08:12 +0000244 assert(n >= 0 && (unsigned)n < NumNames &&
Anders Carlssonf511f642007-11-27 04:11:28 +0000245 "Out of bounds register number!");
246 return Names[n];
247 }
248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Anders Carlssonf511f642007-11-27 04:11:28 +0000250 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000251 const GCCRegAlias *Aliases;
Anders Carlssonf511f642007-11-27 04:11:28 +0000252 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000253
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000254 getGCCRegAliases(Aliases, NumAliases);
Anders Carlssonf511f642007-11-27 04:11:28 +0000255 for (unsigned i = 0; i < NumAliases; i++) {
256 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
257 if (!Aliases[i].Aliases[j])
258 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000259 if (Aliases[i].Aliases[j] == Name)
Anders Carlssonf511f642007-11-27 04:11:28 +0000260 return Aliases[i].Register;
261 }
262 }
Mike Stump11289f42009-09-09 15:08:12 +0000263
Anders Carlssonf511f642007-11-27 04:11:28 +0000264 return Name;
265}
266
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000267bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
268 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000269 // An output constraint must start with '=' or '+'
270 if (*Name != '=' && *Name != '+')
271 return false;
272
273 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000274 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000275
276 Name++;
277 while (*Name) {
278 switch (*Name) {
279 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000280 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000281 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000282 // so we can add more constraints as we hit it.
283 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000284 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000285 }
286 case '&': // early clobber.
287 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000288 case '%': // commutative.
289 // FIXME: Check that there is a another register after this one.
290 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000291 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000292 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000293 break;
294 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000295 case 'o': // offsetable memory operand.
296 case 'V': // non-offsetable memory operand.
297 case '<': // autodecrement memory operand.
298 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000299 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000300 break;
301 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000302 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000303 Info.setAllowsRegister();
304 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000305 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000306 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000307 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000308 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000309 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000310 break;
311 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000312 case '!': // Disparage severely.
John Thompsona5c7d702010-08-10 19:20:14 +0000313 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000314 }
Mike Stump11289f42009-09-09 15:08:12 +0000315
Anders Carlssonf511f642007-11-27 04:11:28 +0000316 Name++;
317 }
Mike Stump11289f42009-09-09 15:08:12 +0000318
Anders Carlssonf511f642007-11-27 04:11:28 +0000319 return true;
320}
321
Anders Carlssona79203b2009-01-18 01:56:57 +0000322bool TargetInfo::resolveSymbolicName(const char *&Name,
Chris Lattnerc16d4762009-04-26 17:57:12 +0000323 ConstraintInfo *OutputConstraints,
324 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000325 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000326 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000327 Name++;
328 const char *Start = Name;
329 while (*Name && *Name != ']')
330 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000331
Anders Carlssona79203b2009-01-18 01:56:57 +0000332 if (!*Name) {
333 // Missing ']'
334 return false;
335 }
Mike Stump11289f42009-09-09 15:08:12 +0000336
Anders Carlssona79203b2009-01-18 01:56:57 +0000337 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000338
Chris Lattnerc16d4762009-04-26 17:57:12 +0000339 for (Index = 0; Index != NumOutputs; ++Index)
340 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000341 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000342
343 return false;
344}
345
Chris Lattnerc16d4762009-04-26 17:57:12 +0000346bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
347 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000348 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000349 const char *Name = Info.ConstraintStr.c_str();
350
Anders Carlssonf511f642007-11-27 04:11:28 +0000351 while (*Name) {
352 switch (*Name) {
353 default:
354 // Check if we have a matching constraint
355 if (*Name >= '0' && *Name <= '9') {
356 unsigned i = *Name - '0';
Mike Stump11289f42009-09-09 15:08:12 +0000357
Anders Carlssonf511f642007-11-27 04:11:28 +0000358 // Check if matching constraint is out of bounds.
359 if (i >= NumOutputs)
360 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000361
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000362 // A number must refer to an output only operand.
363 if (OutputConstraints[i].isReadWrite())
364 return false;
365
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000366 // If the constraint is already tied, it must be tied to the
367 // same operand referenced to by the number.
368 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
369 return false;
370
Mike Stump11289f42009-09-09 15:08:12 +0000371 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000372 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000373 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000374 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000375 // FIXME: This error return is in place temporarily so we can
376 // add more constraints as we hit it. Eventually, an unknown
377 // constraint should just be treated as 'g'.
378 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000379 }
380 break;
381 case '[': {
382 unsigned Index = 0;
Chris Lattnerc16d4762009-04-26 17:57:12 +0000383 if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000384 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000385
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000386 // If the constraint is already tied, it must be tied to the
387 // same operand referenced to by the number.
388 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
389 return false;
390
Eli Friedman854f1102010-08-11 23:03:37 +0000391 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000392 break;
Mike Stump11289f42009-09-09 15:08:12 +0000393 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000394 case '%': // commutative
395 // FIXME: Fail if % is used with the last operand.
396 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000397 case 'i': // immediate integer.
Anders Carlssona3a96af2008-03-09 06:02:02 +0000398 case 'n': // immediate integer with a known value.
Anders Carlssonf511f642007-11-27 04:11:28 +0000399 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000400 case 'I': // Various constant constraints with target-specific meanings.
401 case 'J':
402 case 'K':
403 case 'L':
404 case 'M':
405 case 'N':
406 case 'O':
407 case 'P':
408 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000409 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000410 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000411 break;
412 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000413 case 'o': // offsettable memory operand.
414 case 'V': // non-offsettable memory operand.
415 case '<': // autodecrement memory operand.
416 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000417 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000418 break;
419 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000420 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000421 Info.setAllowsRegister();
422 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000423 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000424 case 'E': // immediate floating point.
425 case 'F': // immediate floating point.
426 case 'p': // address operand.
427 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000428 case ',': // multiple alternative constraint. Ignore comma.
429 break;
430 case '?': // Disparage slightly code.
431 case '!': // Disparage severly.
432 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000433 }
Mike Stump11289f42009-09-09 15:08:12 +0000434
Anders Carlssonf511f642007-11-27 04:11:28 +0000435 Name++;
436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Anders Carlssonf511f642007-11-27 04:11:28 +0000438 return true;
439}