blob: 2d4c4a97916c711b6e54322876a21fc5e4067478 [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;
Douglas Gregor20b2ebd2011-03-23 00:50:03 +000073
74 // Default to an unknown platform name.
75 PlatformName = "unknown";
76 PlatformMinVersion = VersionTuple();
Chris Lattner1df27862008-03-08 08:59:43 +000077}
78
Chris Lattnerc3a669b2008-03-08 08:24:01 +000079// Out of line virtual dtor for TargetInfo.
80TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +000081
Chris Lattnera91c30f2009-02-06 05:04:11 +000082/// getTypeName - Return the user string for the specified integer type enum.
83/// For example, SignedShort -> "short".
84const char *TargetInfo::getTypeName(IntType T) {
85 switch (T) {
86 default: assert(0 && "not an integer!");
87 case SignedShort: return "short";
88 case UnsignedShort: return "unsigned short";
89 case SignedInt: return "int";
90 case UnsignedInt: return "unsigned int";
91 case SignedLong: return "long int";
92 case UnsignedLong: return "long unsigned int";
93 case SignedLongLong: return "long long int";
94 case UnsignedLongLong: return "long long unsigned int";
95 }
96}
97
Chris Lattner72cdcac2009-10-21 06:24:21 +000098/// getTypeConstantSuffix - Return the constant suffix for the specified
99/// integer type enum. For example, SignedLong -> "L".
100const char *TargetInfo::getTypeConstantSuffix(IntType T) {
101 switch (T) {
102 default: assert(0 && "not an integer!");
103 case SignedShort:
104 case SignedInt: return "";
105 case SignedLong: return "L";
106 case SignedLongLong: return "LL";
107 case UnsignedShort:
108 case UnsignedInt: return "U";
109 case UnsignedLong: return "UL";
110 case UnsignedLongLong: return "ULL";
111 }
112}
113
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000114/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000115/// enum. For example, SignedInt -> getIntWidth().
116unsigned TargetInfo::getTypeWidth(IntType T) const {
117 switch (T) {
118 default: assert(0 && "not an integer!");
Chris Lattnere4a8c642009-11-05 21:21:32 +0000119 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000120 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000121 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000122 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000123 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000124 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000125 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000126 case UnsignedLongLong: return getLongLongWidth();
127 };
128}
129
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000130/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000131/// enum. For example, SignedInt -> getIntAlign().
132unsigned TargetInfo::getTypeAlign(IntType T) const {
133 switch (T) {
134 default: assert(0 && "not an integer!");
135 case SignedShort:
136 case UnsignedShort: return getShortAlign();
137 case SignedInt:
138 case UnsignedInt: return getIntAlign();
139 case SignedLong:
140 case UnsignedLong: return getLongAlign();
141 case SignedLongLong:
142 case UnsignedLongLong: return getLongLongAlign();
143 };
144}
145
Chris Lattnerc0c04392009-10-25 22:49:18 +0000146/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000147/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000148bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000149 switch (T) {
150 default: assert(0 && "not an integer!");
151 case SignedShort:
152 case SignedInt:
153 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000154 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000155 return true;
156 case UnsignedShort:
157 case UnsignedInt:
158 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000159 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000160 return false;
161 };
162}
163
John Thompsoned4e2952009-11-05 20:14:16 +0000164/// setForcedLangOptions - Set forced language options.
165/// Apply changes to the target information with respect to certain
166/// language options which change the target configuration.
167void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000168 if (Opts.NoBitFieldTypeAlign)
169 UseBitFieldTypeAlignment = false;
170 if (Opts.ShortWChar)
John Thompsoned4e2952009-11-05 20:14:16 +0000171 WCharType = UnsignedShort;
John Thompsoned4e2952009-11-05 20:14:16 +0000172}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000173
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000174//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000175
Chris Lattner10a5b382007-01-29 05:24:35 +0000176
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000177static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000178 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000179 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000180
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000181 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000182}
183
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000184/// isValidGCCRegisterName - Returns whether the passed in string
185/// is a valid register name according to GCC. This is used by Sema for
186/// inline asm statements.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000187bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const {
188 if (Name.empty())
189 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000190
Anders Carlsson290aa852007-11-25 00:25:21 +0000191 const char * const *Names;
192 unsigned NumNames;
Mike Stump11289f42009-09-09 15:08:12 +0000193
Anders Carlsson290aa852007-11-25 00:25:21 +0000194 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000195 Name = removeGCCRegisterPrefix(Name);
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000196
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000197 if (Name == "memory" || Name == "cc")
Anders Carlsson290aa852007-11-25 00:25:21 +0000198 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000199
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000200 getGCCRegNames(Names, NumNames);
Mike Stump11289f42009-09-09 15:08:12 +0000201
Anders Carlsson290aa852007-11-25 00:25:21 +0000202 // If we have a number it maps to an entry in the register name array.
203 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000204 int n;
205 if (!Name.getAsInteger(0, n))
Anders Carlsson290aa852007-11-25 00:25:21 +0000206 return n >= 0 && (unsigned)n < NumNames;
207 }
208
209 // Check register names.
210 for (unsigned i = 0; i < NumNames; i++) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000211 if (Name == Names[i])
Anders Carlsson290aa852007-11-25 00:25:21 +0000212 return true;
213 }
Mike Stump11289f42009-09-09 15:08:12 +0000214
Eric Christophercdd36352011-06-21 00:05:20 +0000215 // Check any additional names that we have.
216 const AddlRegName *AddlNames;
217 unsigned NumAddlNames;
218 getGCCAddlRegNames(AddlNames, NumAddlNames);
219 for (unsigned i = 0; i < NumAddlNames; i++)
220 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
221 if (!AddlNames[i].Names[j])
222 break;
223 // Make sure the register that the additional name is for is within
224 // the bounds of the register names from above.
225 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
226 return true;
227 }
228
Anders Carlsson290aa852007-11-25 00:25:21 +0000229 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000230 const GCCRegAlias *Aliases;
Anders Carlsson290aa852007-11-25 00:25:21 +0000231 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000232
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000233 getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson290aa852007-11-25 00:25:21 +0000234 for (unsigned i = 0; i < NumAliases; i++) {
235 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
236 if (!Aliases[i].Aliases[j])
237 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000238 if (Aliases[i].Aliases[j] == Name)
Anders Carlsson290aa852007-11-25 00:25:21 +0000239 return true;
240 }
241 }
Mike Stump11289f42009-09-09 15:08:12 +0000242
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000243 return false;
244}
Anders Carlssonf511f642007-11-27 04:11:28 +0000245
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000246llvm::StringRef
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000247TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000248 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000249
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000250 // Get rid of any register prefix.
251 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000252
Anders Carlssonf511f642007-11-27 04:11:28 +0000253 const char * const *Names;
254 unsigned NumNames;
255
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000256 getGCCRegNames(Names, NumNames);
Anders Carlssonf511f642007-11-27 04:11:28 +0000257
258 // First, check if we have a number.
259 if (isdigit(Name[0])) {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000260 int n;
261 if (!Name.getAsInteger(0, n)) {
Mike Stump11289f42009-09-09 15:08:12 +0000262 assert(n >= 0 && (unsigned)n < NumNames &&
Anders Carlssonf511f642007-11-27 04:11:28 +0000263 "Out of bounds register number!");
264 return Names[n];
265 }
266 }
Mike Stump11289f42009-09-09 15:08:12 +0000267
Eric Christophercdd36352011-06-21 00:05:20 +0000268 // Check any additional names that we have.
269 const AddlRegName *AddlNames;
270 unsigned NumAddlNames;
271 getGCCAddlRegNames(AddlNames, NumAddlNames);
272 for (unsigned i = 0; i < NumAddlNames; i++)
273 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
274 if (!AddlNames[i].Names[j])
275 break;
276 // Make sure the register that the additional name is for is within
277 // the bounds of the register names from above.
278 if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
279 return Name;
280 }
281
Anders Carlssonf511f642007-11-27 04:11:28 +0000282 // Now check aliases.
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000283 const GCCRegAlias *Aliases;
Anders Carlssonf511f642007-11-27 04:11:28 +0000284 unsigned NumAliases;
Mike Stump11289f42009-09-09 15:08:12 +0000285
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000286 getGCCRegAliases(Aliases, NumAliases);
Anders Carlssonf511f642007-11-27 04:11:28 +0000287 for (unsigned i = 0; i < NumAliases; i++) {
288 for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
289 if (!Aliases[i].Aliases[j])
290 break;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000291 if (Aliases[i].Aliases[j] == Name)
Anders Carlssonf511f642007-11-27 04:11:28 +0000292 return Aliases[i].Register;
293 }
294 }
Mike Stump11289f42009-09-09 15:08:12 +0000295
Anders Carlssonf511f642007-11-27 04:11:28 +0000296 return Name;
297}
298
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000299bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
300 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000301 // An output constraint must start with '=' or '+'
302 if (*Name != '=' && *Name != '+')
303 return false;
304
305 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000306 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000307
308 Name++;
309 while (*Name) {
310 switch (*Name) {
311 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000312 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000313 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000314 // so we can add more constraints as we hit it.
315 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000316 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000317 }
318 case '&': // early clobber.
319 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000320 case '%': // commutative.
321 // FIXME: Check that there is a another register after this one.
322 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000323 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000324 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000325 break;
326 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000327 case 'o': // offsetable memory operand.
328 case 'V': // non-offsetable memory operand.
329 case '<': // autodecrement memory operand.
330 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000331 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000332 break;
333 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000334 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000335 Info.setAllowsRegister();
336 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000337 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000338 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000339 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000340 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000341 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000342 break;
343 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000344 case '!': // Disparage severely.
John Thompsona5c7d702010-08-10 19:20:14 +0000345 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000346 }
Mike Stump11289f42009-09-09 15:08:12 +0000347
Anders Carlssonf511f642007-11-27 04:11:28 +0000348 Name++;
349 }
Mike Stump11289f42009-09-09 15:08:12 +0000350
Anders Carlssonf511f642007-11-27 04:11:28 +0000351 return true;
352}
353
Anders Carlssona79203b2009-01-18 01:56:57 +0000354bool TargetInfo::resolveSymbolicName(const char *&Name,
Chris Lattnerc16d4762009-04-26 17:57:12 +0000355 ConstraintInfo *OutputConstraints,
356 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000357 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000358 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000359 Name++;
360 const char *Start = Name;
361 while (*Name && *Name != ']')
362 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000363
Anders Carlssona79203b2009-01-18 01:56:57 +0000364 if (!*Name) {
365 // Missing ']'
366 return false;
367 }
Mike Stump11289f42009-09-09 15:08:12 +0000368
Anders Carlssona79203b2009-01-18 01:56:57 +0000369 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000370
Chris Lattnerc16d4762009-04-26 17:57:12 +0000371 for (Index = 0; Index != NumOutputs; ++Index)
372 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000373 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000374
375 return false;
376}
377
Chris Lattnerc16d4762009-04-26 17:57:12 +0000378bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
379 unsigned NumOutputs,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000380 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000381 const char *Name = Info.ConstraintStr.c_str();
382
Anders Carlssonf511f642007-11-27 04:11:28 +0000383 while (*Name) {
384 switch (*Name) {
385 default:
386 // Check if we have a matching constraint
387 if (*Name >= '0' && *Name <= '9') {
388 unsigned i = *Name - '0';
Mike Stump11289f42009-09-09 15:08:12 +0000389
Anders Carlssonf511f642007-11-27 04:11:28 +0000390 // Check if matching constraint is out of bounds.
391 if (i >= NumOutputs)
392 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000393
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000394 // A number must refer to an output only operand.
395 if (OutputConstraints[i].isReadWrite())
396 return false;
397
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000398 // If the constraint is already tied, it must be tied to the
399 // same operand referenced to by the number.
400 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
401 return false;
402
Mike Stump11289f42009-09-09 15:08:12 +0000403 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000404 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000405 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000406 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000407 // FIXME: This error return is in place temporarily so we can
408 // add more constraints as we hit it. Eventually, an unknown
409 // constraint should just be treated as 'g'.
410 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000411 }
412 break;
413 case '[': {
414 unsigned Index = 0;
Chris Lattnerc16d4762009-04-26 17:57:12 +0000415 if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000416 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000417
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000418 // If the constraint is already tied, it must be tied to the
419 // same operand referenced to by the number.
420 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
421 return false;
422
Eli Friedman854f1102010-08-11 23:03:37 +0000423 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000424 break;
Mike Stump11289f42009-09-09 15:08:12 +0000425 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000426 case '%': // commutative
427 // FIXME: Fail if % is used with the last operand.
428 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000429 case 'i': // immediate integer.
Anders Carlssona3a96af2008-03-09 06:02:02 +0000430 case 'n': // immediate integer with a known value.
Anders Carlssonf511f642007-11-27 04:11:28 +0000431 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000432 case 'I': // Various constant constraints with target-specific meanings.
433 case 'J':
434 case 'K':
435 case 'L':
436 case 'M':
437 case 'N':
438 case 'O':
439 case 'P':
440 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000441 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000442 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000443 break;
444 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000445 case 'o': // offsettable memory operand.
446 case 'V': // non-offsettable memory operand.
447 case '<': // autodecrement memory operand.
448 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000449 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000450 break;
451 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000452 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000453 Info.setAllowsRegister();
454 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000455 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000456 case 'E': // immediate floating point.
457 case 'F': // immediate floating point.
458 case 'p': // address operand.
459 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000460 case ',': // multiple alternative constraint. Ignore comma.
461 break;
462 case '?': // Disparage slightly code.
Chris Lattner57540c52011-04-15 05:22:18 +0000463 case '!': // Disparage severely.
John Thompsona5c7d702010-08-10 19:20:14 +0000464 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000465 }
Mike Stump11289f42009-09-09 15:08:12 +0000466
Anders Carlssonf511f642007-11-27 04:11:28 +0000467 Name++;
468 }
Mike Stump11289f42009-09-09 15:08:12 +0000469
Anders Carlssonf511f642007-11-27 04:11:28 +0000470 return true;
471}