blob: 43ab77289b115bae9c27b60dae7bd2b7f2eaae26 [file] [log] [blame]
Chris Lattner1e27fe12006-10-14 07:06:20 +00001//===--- TargetInfo.cpp - Information about Target machine ----------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner1e27fe12006-10-14 07:06:20 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the TargetInfo and TargetInfoImpl interfaces.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Basic/TargetInfo.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000014#include "clang/Basic/AddressSpaces.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000015#include "clang/Basic/CharInfo.h"
Alexander Ivchenko0fb8c872018-05-18 11:56:21 +000016#include "clang/Basic/Diagnostic.h"
John Thompsoned4e2952009-11-05 20:14:16 +000017#include "clang/Basic/LangOptions.h"
Chris Lattnerec0a6d92007-09-22 18:29:59 +000018#include "llvm/ADT/APFloat.h"
Anders Carlsson290aa852007-11-25 00:25:21 +000019#include "llvm/ADT/STLExtras.h"
David Blaikie76bd3c82011-09-23 05:35:21 +000020#include "llvm/Support/ErrorHandling.h"
Saleem Abdulrasool729379a2017-10-06 23:09:55 +000021#include "llvm/Support/TargetParser.h"
Chris Lattnerc4f02b62008-04-06 04:02:29 +000022#include <cstdlib>
Chris Lattner1e27fe12006-10-14 07:06:20 +000023using namespace clang;
24
Alexander Richardson6d989432017-10-15 18:48:14 +000025static const LangASMap DefaultAddrSpaceMap = {0};
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000026
Chris Lattner1df27862008-03-08 08:59:43 +000027// TargetInfo Constructor.
Benjamin Kramerb1276b42013-06-29 16:37:14 +000028TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
Daniel Dunbar3d9289c2010-04-15 06:18:39 +000029 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
30 // SPARC. These should be overridden by concrete targets as needed.
Matt Arsenaultf333de32016-09-07 07:08:02 +000031 BigEndian = !T.isLittleEndian();
Eli Friedmand88c8a12009-04-19 21:38:35 +000032 TLSSupported = true;
Jonas Hahnfeld87d44262017-11-18 21:00:46 +000033 VLASupported = true;
Chris Lattner1a8f3942010-04-23 16:29:58 +000034 NoAsmVariants = false;
Sjoerd Meijer87793e72018-03-19 13:22:49 +000035 HasLegalHalfType = false;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +000036 HasFloat128 = false;
Erich Keane1d1d4382019-01-25 17:27:57 +000037 HasFloat16 = false;
Chris Lattner5e2ef0c2008-05-09 06:08:39 +000038 PointerWidth = PointerAlign = 32;
Roman Divacky965b0b72011-01-06 08:27:10 +000039 BoolWidth = BoolAlign = 8;
Chris Lattnerb781dc792008-05-08 05:58:21 +000040 IntWidth = IntAlign = 32;
Chris Lattner5a9aaaf2008-05-09 05:50:02 +000041 LongWidth = LongAlign = 32;
42 LongLongWidth = LongLongAlign = 64;
Leonard Chandb01c3a2018-06-20 17:19:40 +000043
44 // Fixed point default bit widths
Leonard Chanf921d852018-06-04 16:07:52 +000045 ShortAccumWidth = ShortAccumAlign = 16;
46 AccumWidth = AccumAlign = 32;
47 LongAccumWidth = LongAccumAlign = 64;
Leonard Chandb01c3a2018-06-20 17:19:40 +000048 ShortFractWidth = ShortFractAlign = 8;
49 FractWidth = FractAlign = 16;
50 LongFractWidth = LongFractAlign = 32;
51
52 // Fixed point default integral and fractional bit sizes
53 // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
54 // types by default to have the same number of fractional bits between _Accum
55 // and _Fract types.
Leonard Chan6e16c602018-06-29 17:08:19 +000056 PaddingOnUnsignedFixedPoint = false;
Leonard Chandb01c3a2018-06-20 17:19:40 +000057 ShortAccumScale = 7;
58 AccumScale = 15;
59 LongAccumScale = 31;
60
Nick Lewyckyf59e1292011-12-16 22:34:14 +000061 SuitableAlign = 64;
Ulrich Weigandca3cb7f2015-04-21 17:29:35 +000062 DefaultAlignForAttributeAligned = 128;
Ulrich Weigandfa806422013-05-06 16:23:57 +000063 MinGlobalAlign = 0;
Richard Smith59139022016-09-30 22:41:36 +000064 // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
65 // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
Pirama Arumuga Nainarb8183472018-08-01 17:55:34 +000066 // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
67 // This alignment guarantee also applies to Windows and Android.
68 if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
Richard Smith59139022016-09-30 22:41:36 +000069 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
70 else
71 NewAlign = 0; // Infer from basic type alignment.
Anton Korobeynikovf0c267e2011-10-14 23:23:15 +000072 HalfWidth = 16;
73 HalfAlign = 16;
Eli Friedmanb5366062008-05-20 14:21:01 +000074 FloatWidth = 32;
75 FloatAlign = 32;
Nate Begeman65bea232008-04-18 17:17:24 +000076 DoubleWidth = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000077 DoubleAlign = 64;
78 LongDoubleWidth = 64;
79 LongDoubleAlign = 64;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +000080 Float128Align = 128;
Rafael Espindolae971b9a2010-06-04 23:15:27 +000081 LargeArrayMinWidth = 0;
82 LargeArrayAlign = 0;
Eli Friedman4b72fdd2011-10-14 20:59:01 +000083 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
Chad Rosiercc40ea72012-07-13 23:57:43 +000084 MaxVectorAlign = 0;
Paul Robinsond30e2ee2015-07-14 20:52:32 +000085 MaxTLSAlign = 0;
Alexey Bataev00396512015-07-02 03:40:19 +000086 SimdDefaultAlign = 0;
Anders Carlsson2a79a902008-10-31 16:05:19 +000087 SizeType = UnsignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000088 PtrDiffType = SignedLong;
Sanjiv Guptad7959242008-10-31 09:52:39 +000089 IntMaxType = SignedLongLong;
Chris Lattner7e4c81c2009-02-13 22:28:55 +000090 IntPtrType = SignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000091 WCharType = SignedInt;
Chris Lattner67204922009-10-21 04:59:34 +000092 WIntType = SignedInt;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +000093 Char16Type = UnsignedShort;
94 Char32Type = UnsignedInt;
Eli Friedman2857ccb2009-07-01 03:36:11 +000095 Int64Type = SignedLongLong;
Edward O'Callaghan847f2a12009-11-21 00:49:54 +000096 SigAtomicType = SignedInt;
Eli Friedman4e91899e2012-11-27 02:58:24 +000097 ProcessIDType = SignedInt;
Fariborz Jahanian29898f42012-04-16 21:03:30 +000098 UseSignedCharForObjCBool = true;
Daniel Dunbar1da65112010-04-15 15:06:18 +000099 UseBitFieldTypeAlignment = true;
Chad Rosier18903ee2011-08-04 01:21:14 +0000100 UseZeroLengthBitfieldAlignment = false;
Sunil Srivastava0ce2f222016-02-05 20:50:02 +0000101 UseExplicitBitFieldAlignment = true;
Chad Rosier18903ee2011-08-04 01:21:14 +0000102 ZeroLengthBitfieldBoundary = 0;
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000103 HalfFormat = &llvm::APFloat::IEEEhalf();
104 FloatFormat = &llvm::APFloat::IEEEsingle();
105 DoubleFormat = &llvm::APFloat::IEEEdouble();
106 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
107 Float128Format = &llvm::APFloat::IEEEquad();
Roman Divacky178e01602011-02-10 16:52:03 +0000108 MCountName = "mcount";
Abramo Bagnara41bfb662011-09-08 14:20:25 +0000109 RegParmMax = 0;
110 SSERegParmMax = 0;
Daniel Dunbarbd606522010-05-27 00:35:16 +0000111 HasAlignMac68kSupport = false;
Charles Davisc7d5c942015-09-17 20:55:33 +0000112 HasBuiltinMSVaList = false;
Pirama Arumuga Nainarbb846a32016-07-27 19:01:51 +0000113 IsRenderScriptTarget = false;
Daniel Dunbar6f2e8392010-07-14 23:39:36 +0000114
115 // Default to no types using fpret.
116 RealTypeUsesObjCFPRet = 0;
John McCall86353412010-08-21 22:46:04 +0000117
Anders Carlsson2f1a6c32011-10-31 16:27:11 +0000118 // Default to not using fp2ret for __Complex long double
119 ComplexLongDoubleUsesFP2Ret = false;
120
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000121 // Set the C++ ABI based on the triple.
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000122 TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000123 ? TargetCXXABI::Microsoft
124 : TargetCXXABI::GenericItanium);
Peter Collingbourne599cb8e2011-03-18 22:38:29 +0000125
126 // Default to an empty address space map.
127 AddrSpaceMap = &DefaultAddrSpaceMap;
David Tweed31d09b02013-09-13 12:04:22 +0000128 UseAddrSpaceMapMangling = false;
Douglas Gregor20b2ebd2011-03-23 00:50:03 +0000129
130 // Default to an unknown platform name.
131 PlatformName = "unknown";
132 PlatformMinVersion = VersionTuple();
Chris Lattner1df27862008-03-08 08:59:43 +0000133}
134
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000135// Out of line virtual dtor for TargetInfo.
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000136TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +0000137
Alexander Ivchenko0fb8c872018-05-18 11:56:21 +0000138bool
139TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
140 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
141 return false;
142}
143
144bool
145TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const {
146 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
147 return false;
148}
149
Chris Lattnera91c30f2009-02-06 05:04:11 +0000150/// getTypeName - Return the user string for the specified integer type enum.
151/// For example, SignedShort -> "short".
152const char *TargetInfo::getTypeName(IntType T) {
153 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000154 default: llvm_unreachable("not an integer!");
Joerg Sonnenberger3d9478c2014-07-28 21:06:22 +0000155 case SignedChar: return "signed char";
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000156 case UnsignedChar: return "unsigned char";
Chris Lattnera91c30f2009-02-06 05:04:11 +0000157 case SignedShort: return "short";
158 case UnsignedShort: return "unsigned short";
159 case SignedInt: return "int";
160 case UnsignedInt: return "unsigned int";
161 case SignedLong: return "long int";
162 case UnsignedLong: return "long unsigned int";
163 case SignedLongLong: return "long long int";
164 case UnsignedLongLong: return "long long unsigned int";
165 }
166}
167
Chris Lattner72cdcac2009-10-21 06:24:21 +0000168/// getTypeConstantSuffix - Return the constant suffix for the specified
169/// integer type enum. For example, SignedLong -> "L".
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000170const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000171 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000172 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000173 case SignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000174 case SignedShort:
175 case SignedInt: return "";
176 case SignedLong: return "L";
177 case SignedLongLong: return "LL";
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000178 case UnsignedChar:
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000179 if (getCharWidth() < getIntWidth())
180 return "";
Galina Kistanova96088f42017-06-03 06:38:22 +0000181 LLVM_FALLTHROUGH;
Chris Lattner72cdcac2009-10-21 06:24:21 +0000182 case UnsignedShort:
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000183 if (getShortWidth() < getIntWidth())
184 return "";
Galina Kistanova96088f42017-06-03 06:38:22 +0000185 LLVM_FALLTHROUGH;
Chris Lattner72cdcac2009-10-21 06:24:21 +0000186 case UnsignedInt: return "U";
187 case UnsignedLong: return "UL";
188 case UnsignedLongLong: return "ULL";
189 }
190}
191
Joerg Sonnenbergerbe324f92014-07-15 11:30:00 +0000192/// getTypeFormatModifier - Return the printf format modifier for the
193/// specified integer type enum. For example, SignedLong -> "l".
194
195const char *TargetInfo::getTypeFormatModifier(IntType T) {
196 switch (T) {
197 default: llvm_unreachable("not an integer!");
198 case SignedChar:
199 case UnsignedChar: return "hh";
200 case SignedShort:
201 case UnsignedShort: return "h";
202 case SignedInt:
203 case UnsignedInt: return "";
204 case SignedLong:
205 case UnsignedLong: return "l";
206 case SignedLongLong:
207 case UnsignedLongLong: return "ll";
208 }
209}
210
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000211/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000212/// enum. For example, SignedInt -> getIntWidth().
213unsigned TargetInfo::getTypeWidth(IntType T) const {
214 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000215 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000216 case SignedChar:
217 case UnsignedChar: return getCharWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000218 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000219 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000220 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000221 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000222 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000223 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000224 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000225 case UnsignedLongLong: return getLongLongWidth();
226 };
227}
228
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000229TargetInfo::IntType TargetInfo::getIntTypeByWidth(
230 unsigned BitWidth, bool IsSigned) const {
231 if (getCharWidth() == BitWidth)
232 return IsSigned ? SignedChar : UnsignedChar;
233 if (getShortWidth() == BitWidth)
234 return IsSigned ? SignedShort : UnsignedShort;
235 if (getIntWidth() == BitWidth)
236 return IsSigned ? SignedInt : UnsignedInt;
237 if (getLongWidth() == BitWidth)
238 return IsSigned ? SignedLong : UnsignedLong;
239 if (getLongLongWidth() == BitWidth)
240 return IsSigned ? SignedLongLong : UnsignedLongLong;
241 return NoInt;
242}
243
JF Bastienab8d0a02014-06-25 01:31:33 +0000244TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
245 bool IsSigned) const {
246 if (getCharWidth() >= BitWidth)
247 return IsSigned ? SignedChar : UnsignedChar;
248 if (getShortWidth() >= BitWidth)
249 return IsSigned ? SignedShort : UnsignedShort;
250 if (getIntWidth() >= BitWidth)
251 return IsSigned ? SignedInt : UnsignedInt;
252 if (getLongWidth() >= BitWidth)
253 return IsSigned ? SignedLong : UnsignedLong;
254 if (getLongLongWidth() >= BitWidth)
255 return IsSigned ? SignedLongLong : UnsignedLongLong;
256 return NoInt;
257}
258
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000259TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth) const {
260 if (getFloatWidth() == BitWidth)
261 return Float;
262 if (getDoubleWidth() == BitWidth)
263 return Double;
264
265 switch (BitWidth) {
266 case 96:
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000267 if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000268 return LongDouble;
269 break;
270 case 128:
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000271 if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
272 &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000273 return LongDouble;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +0000274 if (hasFloat128Type())
275 return Float128;
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000276 break;
277 }
278
279 return NoFloat;
280}
281
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000282/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000283/// enum. For example, SignedInt -> getIntAlign().
284unsigned TargetInfo::getTypeAlign(IntType T) const {
285 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000286 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000287 case SignedChar:
288 case UnsignedChar: return getCharAlign();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000289 case SignedShort:
290 case UnsignedShort: return getShortAlign();
291 case SignedInt:
292 case UnsignedInt: return getIntAlign();
293 case SignedLong:
294 case UnsignedLong: return getLongAlign();
295 case SignedLongLong:
296 case UnsignedLongLong: return getLongLongAlign();
297 };
298}
299
Chris Lattnerc0c04392009-10-25 22:49:18 +0000300/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000301/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000302bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000303 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000304 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000305 case SignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000306 case SignedShort:
307 case SignedInt:
308 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000309 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000310 return true;
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000311 case UnsignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000312 case UnsignedShort:
313 case UnsignedInt:
314 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000315 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000316 return false;
317 };
318}
319
Alp Toker74437972014-07-06 05:14:24 +0000320/// adjust - Set forced language options.
John Thompsoned4e2952009-11-05 20:14:16 +0000321/// Apply changes to the target information with respect to certain
Eric Christopher3646e622017-03-22 06:36:09 +0000322/// language options which change the target configuration and adjust
323/// the language based on the target options where applicable.
324void TargetInfo::adjust(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000325 if (Opts.NoBitFieldTypeAlign)
326 UseBitFieldTypeAlignment = false;
Saleem Abdulrasool729379a2017-10-06 23:09:55 +0000327
328 switch (Opts.WCharSize) {
329 default: llvm_unreachable("invalid wchar_t width");
330 case 0: break;
331 case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
332 case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
333 case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
334 }
335
Reid Kleckner8195f692016-05-04 02:58:24 +0000336 if (Opts.AlignDouble) {
337 DoubleAlign = LongLongAlign = 64;
338 LongDoubleAlign = 64;
339 }
David Tweed2da64382013-09-09 09:17:24 +0000340
341 if (Opts.OpenCL) {
342 // OpenCL C requires specific widths for types, irrespective of
343 // what these normally are for the target.
344 // We also define long long and long double here, although the
345 // OpenCL standard only mentions these as "reserved".
346 IntWidth = IntAlign = 32;
347 LongWidth = LongAlign = 64;
348 LongLongWidth = LongLongAlign = 128;
349 HalfWidth = HalfAlign = 16;
350 FloatWidth = FloatAlign = 32;
Eric Christopherb093d692015-10-09 18:39:59 +0000351
352 // Embedded 32-bit targets (OpenCL EP) might have double C type
353 // defined as float. Let's not override this as it might lead
Pekka Jaaskelainen43c39d52013-12-18 18:15:03 +0000354 // to generating illegal code that uses 64bit doubles.
355 if (DoubleWidth != FloatWidth) {
356 DoubleWidth = DoubleAlign = 64;
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000357 DoubleFormat = &llvm::APFloat::IEEEdouble();
Pekka Jaaskelainen43c39d52013-12-18 18:15:03 +0000358 }
David Tweed2da64382013-09-09 09:17:24 +0000359 LongDoubleWidth = LongDoubleAlign = 128;
360
Yaxun Liu26f75662016-08-19 05:17:25 +0000361 unsigned MaxPointerWidth = getMaxPointerWidth();
362 assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
363 bool Is32BitArch = MaxPointerWidth == 32;
David Tweed6c2149b2013-09-10 08:00:34 +0000364 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
365 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
366 IntPtrType = Is32BitArch ? SignedInt : SignedLong;
David Tweed2da64382013-09-09 09:17:24 +0000367
368 IntMaxType = SignedLongLong;
David Tweed2da64382013-09-09 09:17:24 +0000369 Int64Type = SignedLong;
370
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000371 HalfFormat = &llvm::APFloat::IEEEhalf();
372 FloatFormat = &llvm::APFloat::IEEEsingle();
373 LongDoubleFormat = &llvm::APFloat::IEEEquad();
David Tweed2da64382013-09-09 09:17:24 +0000374 }
Richard Smith59139022016-09-30 22:41:36 +0000375
Fangrui Song11cb39c2019-07-09 00:27:43 +0000376 if (Opts.LongDoubleSize && Opts.LongDoubleSize == DoubleWidth) {
377 LongDoubleWidth = DoubleWidth;
378 LongDoubleAlign = DoubleAlign;
379 LongDoubleFormat = DoubleFormat;
380 }
381
Richard Smith59139022016-09-30 22:41:36 +0000382 if (Opts.NewAlignOverride)
383 NewAlign = Opts.NewAlignOverride * getCharWidth();
Leonard Chandb01c3a2018-06-20 17:19:40 +0000384
385 // Each unsigned fixed point type has the same number of fractional bits as
386 // its corresponding signed type.
Leonard Chan6e16c602018-06-29 17:08:19 +0000387 PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
Leonard Chandb01c3a2018-06-20 17:19:40 +0000388 CheckFixedPointBits();
John Thompsoned4e2952009-11-05 20:14:16 +0000389}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000390
Eric Christopher8c47b422015-10-09 18:39:55 +0000391bool TargetInfo::initFeatureMap(
392 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
393 const std::vector<std::string> &FeatureVec) const {
Eric Christophere9cdcae2015-09-01 18:13:20 +0000394 for (const auto &F : FeatureVec) {
Craig Topper8459aa82015-10-21 16:31:31 +0000395 StringRef Name = F;
Eric Christophere9cdcae2015-09-01 18:13:20 +0000396 // Apply the feature via the target.
397 bool Enabled = Name[0] == '+';
Craig Topper8459aa82015-10-21 16:31:31 +0000398 setFeatureEnabled(Features, Name.substr(1), Enabled);
Eric Christophere9cdcae2015-09-01 18:13:20 +0000399 }
400 return true;
401}
402
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000403TargetInfo::CallingConvKind
404TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
405 if (getCXXABI() != TargetCXXABI::Microsoft &&
406 (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4))
407 return CCK_ClangABI4OrPS4;
408 return CCK_Default;
409}
410
Sven van Haastregt3bb7eaf2017-12-06 10:11:28 +0000411LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
412 switch (TK) {
413 case OCLTK_Image:
414 case OCLTK_Pipe:
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000415 return LangAS::opencl_global;
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000416
Sven van Haastregt3bb7eaf2017-12-06 10:11:28 +0000417 case OCLTK_Sampler:
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000418 return LangAS::opencl_constant;
419
420 default:
421 return LangAS::Default;
422 }
423}
424
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000425//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000426
Chris Lattner10a5b382007-01-29 05:24:35 +0000427
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000428static StringRef removeGCCRegisterPrefix(StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000429 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000430 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000431
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000432 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000433}
434
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000435/// isValidClobber - Returns whether the passed in string is
436/// a valid clobber in an inline asm statement. This is used by
437/// Sema.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000438bool TargetInfo::isValidClobber(StringRef Name) const {
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000439 return (isValidGCCRegisterName(Name) ||
Eric Christopherb093d692015-10-09 18:39:59 +0000440 Name == "memory" || Name == "cc");
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000441}
442
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000443/// isValidGCCRegisterName - Returns whether the passed in string
444/// is a valid register name according to GCC. This is used by Sema for
445/// inline asm statements.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000446bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000447 if (Name.empty())
448 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000449
Anders Carlsson290aa852007-11-25 00:25:21 +0000450 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000451 Name = removeGCCRegisterPrefix(Name);
Olivier Goffartfc8f8932014-08-17 13:19:48 +0000452 if (Name.empty())
Craig Topperde330c72015-10-21 04:52:34 +0000453 return false;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000454
Craig Topperf054e3a2015-10-19 03:52:27 +0000455 ArrayRef<const char *> Names = getGCCRegNames();
Mike Stump11289f42009-09-09 15:08:12 +0000456
Anders Carlsson290aa852007-11-25 00:25:21 +0000457 // If we have a number it maps to an entry in the register name array.
Jordan Rosea7d03842013-02-08 22:30:41 +0000458 if (isDigit(Name[0])) {
Craig Topper67288a92015-10-21 04:52:36 +0000459 unsigned n;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000460 if (!Name.getAsInteger(0, n))
Craig Topper67288a92015-10-21 04:52:36 +0000461 return n < Names.size();
Anders Carlsson290aa852007-11-25 00:25:21 +0000462 }
463
464 // Check register names.
Fangrui Song9ac13a12019-02-10 05:54:57 +0000465 if (llvm::is_contained(Names, Name))
Craig Topper335c8f92015-10-21 04:52:38 +0000466 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000467
Eric Christophercdd36352011-06-21 00:05:20 +0000468 // Check any additional names that we have.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000469 for (const AddlRegName &ARN : getGCCAddlRegNames())
470 for (const char *AN : ARN.Names) {
471 if (!AN)
Eric Christopherb093d692015-10-09 18:39:59 +0000472 break;
Eric Christophercdd36352011-06-21 00:05:20 +0000473 // Make sure the register that the additional name is for is within
474 // the bounds of the register names from above.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000475 if (AN == Name && ARN.RegNum < Names.size())
Anders Carlsson290aa852007-11-25 00:25:21 +0000476 return true;
477 }
Craig Topperdd2b74a2015-10-21 04:52:40 +0000478
479 // Now check aliases.
480 for (const GCCRegAlias &GRA : getGCCRegAliases())
481 for (const char *A : GRA.Aliases) {
482 if (!A)
483 break;
484 if (A == Name)
485 return true;
486 }
Mike Stump11289f42009-09-09 15:08:12 +0000487
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000488 return false;
489}
Anders Carlssonf511f642007-11-27 04:11:28 +0000490
Marina Yatsinac42fd032016-12-26 12:23:42 +0000491StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
492 bool ReturnCanonical) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000493 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000494
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000495 // Get rid of any register prefix.
496 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000497
Craig Topperf054e3a2015-10-19 03:52:27 +0000498 ArrayRef<const char *> Names = getGCCRegNames();
Anders Carlssonf511f642007-11-27 04:11:28 +0000499
500 // First, check if we have a number.
Jordan Rosea7d03842013-02-08 22:30:41 +0000501 if (isDigit(Name[0])) {
Craig Topper67288a92015-10-21 04:52:36 +0000502 unsigned n;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000503 if (!Name.getAsInteger(0, n)) {
Craig Topper67288a92015-10-21 04:52:36 +0000504 assert(n < Names.size() && "Out of bounds register number!");
Anders Carlssonf511f642007-11-27 04:11:28 +0000505 return Names[n];
506 }
507 }
Mike Stump11289f42009-09-09 15:08:12 +0000508
Eric Christophercdd36352011-06-21 00:05:20 +0000509 // Check any additional names that we have.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000510 for (const AddlRegName &ARN : getGCCAddlRegNames())
511 for (const char *AN : ARN.Names) {
512 if (!AN)
Eric Christopherb093d692015-10-09 18:39:59 +0000513 break;
Eric Christophercdd36352011-06-21 00:05:20 +0000514 // Make sure the register that the additional name is for is within
515 // the bounds of the register names from above.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000516 if (AN == Name && ARN.RegNum < Names.size())
Marina Yatsinac42fd032016-12-26 12:23:42 +0000517 return ReturnCanonical ? Names[ARN.RegNum] : Name;
Eric Christophercdd36352011-06-21 00:05:20 +0000518 }
519
Anders Carlssonf511f642007-11-27 04:11:28 +0000520 // Now check aliases.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000521 for (const GCCRegAlias &RA : getGCCRegAliases())
522 for (const char *A : RA.Aliases) {
523 if (!A)
Anders Carlssonf511f642007-11-27 04:11:28 +0000524 break;
Craig Topperdd2b74a2015-10-21 04:52:40 +0000525 if (A == Name)
526 return RA.Register;
Anders Carlssonf511f642007-11-27 04:11:28 +0000527 }
Mike Stump11289f42009-09-09 15:08:12 +0000528
Anders Carlssonf511f642007-11-27 04:11:28 +0000529 return Name;
530}
531
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000532bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
533 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000534 // An output constraint must start with '=' or '+'
535 if (*Name != '=' && *Name != '+')
536 return false;
537
538 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000539 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000540
541 Name++;
542 while (*Name) {
543 switch (*Name) {
544 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000545 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000546 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000547 // so we can add more constraints as we hit it.
548 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000549 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000550 }
David Majnemera0040df2015-01-10 10:43:19 +0000551 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000552 case '&': // early clobber.
David Majnemera0040df2015-01-10 10:43:19 +0000553 Info.setEarlyClobber();
Anders Carlssonf511f642007-11-27 04:11:28 +0000554 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000555 case '%': // commutative.
556 // FIXME: Check that there is a another register after this one.
557 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000558 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000559 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000560 break;
561 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000562 case 'o': // offsetable memory operand.
563 case 'V': // non-offsetable memory operand.
564 case '<': // autodecrement memory operand.
565 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000566 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000567 break;
568 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000569 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000570 Info.setAllowsRegister();
571 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000572 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000573 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000574 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000575 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000576 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000577 break;
David Majnemer50cb0552015-01-11 08:52:38 +0000578 case '#': // Ignore as constraint.
579 while (Name[1] && Name[1] != ',')
580 Name++;
David Majnemerc71a5662015-01-11 09:39:03 +0000581 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000582 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000583 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000584 case '*': // Ignore for choosing register preferences.
Marina Yatsina33eb7752017-06-26 15:55:51 +0000585 case 'i': // Ignore i,n,E,F as output constraints (match from the other
586 // chars)
587 case 'n':
588 case 'E':
589 case 'F':
John Thompsona5c7d702010-08-10 19:20:14 +0000590 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000591 }
Mike Stump11289f42009-09-09 15:08:12 +0000592
Anders Carlssonf511f642007-11-27 04:11:28 +0000593 Name++;
594 }
Mike Stump11289f42009-09-09 15:08:12 +0000595
David Majnemera0040df2015-01-10 10:43:19 +0000596 // Early clobber with a read-write constraint which doesn't permit registers
597 // is invalid.
598 if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
599 return false;
600
Benjamin Kramer1e4a8862013-04-18 22:49:48 +0000601 // If a constraint allows neither memory nor register operands it contains
602 // only modifiers. Reject it.
Benjamin Kramer7ee3b9c2013-04-18 13:23:23 +0000603 return Info.allowsMemory() || Info.allowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000604}
605
Anders Carlssona79203b2009-01-18 01:56:57 +0000606bool TargetInfo::resolveSymbolicName(const char *&Name,
Craig Topper55765ca2015-10-21 02:34:10 +0000607 ArrayRef<ConstraintInfo> OutputConstraints,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000608 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000609 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000610 Name++;
611 const char *Start = Name;
612 while (*Name && *Name != ']')
613 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000614
Anders Carlssona79203b2009-01-18 01:56:57 +0000615 if (!*Name) {
616 // Missing ']'
617 return false;
618 }
Mike Stump11289f42009-09-09 15:08:12 +0000619
Anders Carlssona79203b2009-01-18 01:56:57 +0000620 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000621
Craig Topper55765ca2015-10-21 02:34:10 +0000622 for (Index = 0; Index != OutputConstraints.size(); ++Index)
Chris Lattnerc16d4762009-04-26 17:57:12 +0000623 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000624 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000625
626 return false;
627}
628
Craig Topper55765ca2015-10-21 02:34:10 +0000629bool TargetInfo::validateInputConstraint(
630 MutableArrayRef<ConstraintInfo> OutputConstraints,
631 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000632 const char *Name = Info.ConstraintStr.c_str();
633
Duncan P. N. Exon Smithd68c7aa2013-12-16 03:20:06 +0000634 if (!*Name)
635 return false;
636
Anders Carlssonf511f642007-11-27 04:11:28 +0000637 while (*Name) {
638 switch (*Name) {
639 default:
640 // Check if we have a matching constraint
641 if (*Name >= '0' && *Name <= '9') {
David Majnemerb6b56432015-01-11 10:22:41 +0000642 const char *DigitStart = Name;
643 while (Name[1] >= '0' && Name[1] <= '9')
644 Name++;
645 const char *DigitEnd = Name;
646 unsigned i;
647 if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
648 .getAsInteger(10, i))
649 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000650
Anders Carlssonf511f642007-11-27 04:11:28 +0000651 // Check if matching constraint is out of bounds.
Craig Topper55765ca2015-10-21 02:34:10 +0000652 if (i >= OutputConstraints.size()) return false;
Mike Stump11289f42009-09-09 15:08:12 +0000653
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000654 // A number must refer to an output only operand.
655 if (OutputConstraints[i].isReadWrite())
656 return false;
657
Eric Christopherb093d692015-10-09 18:39:59 +0000658 // If the constraint is already tied, it must be tied to the
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000659 // same operand referenced to by the number.
660 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
661 return false;
662
Mike Stump11289f42009-09-09 15:08:12 +0000663 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000664 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000665 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000666 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000667 // FIXME: This error return is in place temporarily so we can
668 // add more constraints as we hit it. Eventually, an unknown
669 // constraint should just be treated as 'g'.
670 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000671 }
672 break;
673 case '[': {
674 unsigned Index = 0;
Craig Topper55765ca2015-10-21 02:34:10 +0000675 if (!resolveSymbolicName(Name, OutputConstraints, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000676 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000677
Eric Christopherb093d692015-10-09 18:39:59 +0000678 // If the constraint is already tied, it must be tied to the
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000679 // same operand referenced to by the number.
680 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
681 return false;
682
David Majnemer55164f92015-01-11 09:57:13 +0000683 // A number must refer to an output only operand.
684 if (OutputConstraints[Index].isReadWrite())
685 return false;
686
Eli Friedman854f1102010-08-11 23:03:37 +0000687 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000688 break;
Mike Stump11289f42009-09-09 15:08:12 +0000689 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000690 case '%': // commutative
691 // FIXME: Fail if % is used with the last operand.
692 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000693 case 'i': // immediate integer.
Bill Wendlingaa775132018-12-18 22:54:03 +0000694 break;
Anders Carlssona3a96af2008-03-09 06:02:02 +0000695 case 'n': // immediate integer with a known value.
Bill Wendlingaa775132018-12-18 22:54:03 +0000696 Info.setRequiresImmediate();
Anders Carlssonf511f642007-11-27 04:11:28 +0000697 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000698 case 'I': // Various constant constraints with target-specific meanings.
699 case 'J':
700 case 'K':
701 case 'L':
702 case 'M':
703 case 'N':
704 case 'O':
705 case 'P':
Saleem Abdulrasoola2823572015-01-06 04:26:34 +0000706 if (!validateAsmConstraint(Name, Info))
707 return false;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000708 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000709 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000710 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000711 break;
712 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000713 case 'o': // offsettable memory operand.
714 case 'V': // non-offsettable memory operand.
715 case '<': // autodecrement memory operand.
716 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000717 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000718 break;
719 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000720 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000721 Info.setAllowsRegister();
722 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000723 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000724 case 'E': // immediate floating point.
725 case 'F': // immediate floating point.
726 case 'p': // address operand.
727 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000728 case ',': // multiple alternative constraint. Ignore comma.
729 break;
David Majnemerc71a5662015-01-11 09:39:03 +0000730 case '#': // Ignore as constraint.
731 while (Name[1] && Name[1] != ',')
732 Name++;
David Majnemerc71a5662015-01-11 09:39:03 +0000733 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000734 case '?': // Disparage slightly code.
Chris Lattner57540c52011-04-15 05:22:18 +0000735 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000736 case '*': // Ignore for choosing register preferences.
John Thompsona5c7d702010-08-10 19:20:14 +0000737 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Anders Carlssonf511f642007-11-27 04:11:28 +0000740 Name++;
741 }
Mike Stump11289f42009-09-09 15:08:12 +0000742
Anders Carlssonf511f642007-11-27 04:11:28 +0000743 return true;
744}
Leonard Chandb01c3a2018-06-20 17:19:40 +0000745
746void TargetInfo::CheckFixedPointBits() const {
747 // Check that the number of fractional and integral bits (and maybe sign) can
748 // fit into the bits given for a fixed point type.
749 assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth);
750 assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
751 assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth);
752 assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
753 ShortAccumWidth);
754 assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth);
755 assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
756 LongAccumWidth);
757
758 assert(getShortFractScale() + 1 <= ShortFractWidth);
759 assert(getFractScale() + 1 <= FractWidth);
760 assert(getLongFractScale() + 1 <= LongFractWidth);
761 assert(getUnsignedShortFractScale() <= ShortFractWidth);
762 assert(getUnsignedFractScale() <= FractWidth);
763 assert(getUnsignedLongFractScale() <= LongFractWidth);
764
765 // Each unsigned fract type has either the same number of fractional bits
766 // as, or one more fractional bit than, its corresponding signed fract type.
767 assert(getShortFractScale() == getUnsignedShortFractScale() ||
768 getShortFractScale() == getUnsignedShortFractScale() - 1);
769 assert(getFractScale() == getUnsignedFractScale() ||
770 getFractScale() == getUnsignedFractScale() - 1);
771 assert(getLongFractScale() == getUnsignedLongFractScale() ||
772 getLongFractScale() == getUnsignedLongFractScale() - 1);
773
774 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
775 // fractional bits is nondecreasing for each of the following sets of
776 // fixed-point types:
777 // - signed fract types
778 // - unsigned fract types
779 // - signed accum types
780 // - unsigned accum types.
781 assert(getLongFractScale() >= getFractScale() &&
782 getFractScale() >= getShortFractScale());
783 assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
784 getUnsignedFractScale() >= getUnsignedShortFractScale());
785 assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale);
786 assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
787 getUnsignedAccumScale() >= getUnsignedShortAccumScale());
788
789 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
790 // integral bits is nondecreasing for each of the following sets of
791 // fixed-point types:
792 // - signed accum types
793 // - unsigned accum types
794 assert(getLongAccumIBits() >= getAccumIBits() &&
795 getAccumIBits() >= getShortAccumIBits());
796 assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
797 getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
798
799 // Each signed accum type has at least as many integral bits as its
800 // corresponding unsigned accum type.
801 assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
802 assert(getAccumIBits() >= getUnsignedAccumIBits());
803 assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
804}
Yaxun Liu95f2ca52019-01-30 12:26:54 +0000805
806void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
807 auto *Target = static_cast<TransferrableTargetInfo*>(this);
808 auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
809 *Target = *Src;
810}