blob: 3a21a19e1f19a20b77670ceb233933b424667e1a [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"
Bjorn Pettersson78424e52019-10-21 17:58:14 +000020#include "llvm/IR/DataLayout.h"
David Blaikie76bd3c82011-09-23 05:35:21 +000021#include "llvm/Support/ErrorHandling.h"
Saleem Abdulrasool729379a2017-10-06 23:09:55 +000022#include "llvm/Support/TargetParser.h"
Chris Lattnerc4f02b62008-04-06 04:02:29 +000023#include <cstdlib>
Chris Lattner1e27fe12006-10-14 07:06:20 +000024using namespace clang;
25
Alexander Richardson6d989432017-10-15 18:48:14 +000026static const LangASMap DefaultAddrSpaceMap = {0};
Peter Collingbourne599cb8e2011-03-18 22:38:29 +000027
Chris Lattner1df27862008-03-08 08:59:43 +000028// TargetInfo Constructor.
Benjamin Kramerb1276b42013-06-29 16:37:14 +000029TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
Daniel Dunbar3d9289c2010-04-15 06:18:39 +000030 // Set defaults. Defaults are set for a 32-bit RISC platform, like PPC or
31 // SPARC. These should be overridden by concrete targets as needed.
Matt Arsenaultf333de32016-09-07 07:08:02 +000032 BigEndian = !T.isLittleEndian();
Eli Friedmand88c8a12009-04-19 21:38:35 +000033 TLSSupported = true;
Jonas Hahnfeld87d44262017-11-18 21:00:46 +000034 VLASupported = true;
Chris Lattner1a8f3942010-04-23 16:29:58 +000035 NoAsmVariants = false;
Sjoerd Meijer87793e72018-03-19 13:22:49 +000036 HasLegalHalfType = false;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +000037 HasFloat128 = false;
Erich Keane1d1d4382019-01-25 17:27:57 +000038 HasFloat16 = false;
Chris Lattner5e2ef0c2008-05-09 06:08:39 +000039 PointerWidth = PointerAlign = 32;
Roman Divacky965b0b72011-01-06 08:27:10 +000040 BoolWidth = BoolAlign = 8;
Chris Lattnerb781dc792008-05-08 05:58:21 +000041 IntWidth = IntAlign = 32;
Chris Lattner5a9aaaf2008-05-09 05:50:02 +000042 LongWidth = LongAlign = 32;
43 LongLongWidth = LongLongAlign = 64;
Leonard Chandb01c3a2018-06-20 17:19:40 +000044
45 // Fixed point default bit widths
Leonard Chanf921d852018-06-04 16:07:52 +000046 ShortAccumWidth = ShortAccumAlign = 16;
47 AccumWidth = AccumAlign = 32;
48 LongAccumWidth = LongAccumAlign = 64;
Leonard Chandb01c3a2018-06-20 17:19:40 +000049 ShortFractWidth = ShortFractAlign = 8;
50 FractWidth = FractAlign = 16;
51 LongFractWidth = LongFractAlign = 32;
52
53 // Fixed point default integral and fractional bit sizes
54 // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
55 // types by default to have the same number of fractional bits between _Accum
56 // and _Fract types.
Leonard Chan6e16c602018-06-29 17:08:19 +000057 PaddingOnUnsignedFixedPoint = false;
Leonard Chandb01c3a2018-06-20 17:19:40 +000058 ShortAccumScale = 7;
59 AccumScale = 15;
60 LongAccumScale = 31;
61
Nick Lewyckyf59e1292011-12-16 22:34:14 +000062 SuitableAlign = 64;
Ulrich Weigandca3cb7f2015-04-21 17:29:35 +000063 DefaultAlignForAttributeAligned = 128;
Ulrich Weigandfa806422013-05-06 16:23:57 +000064 MinGlobalAlign = 0;
Richard Smith59139022016-09-30 22:41:36 +000065 // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
66 // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
Pirama Arumuga Nainarb8183472018-08-01 17:55:34 +000067 // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
68 // This alignment guarantee also applies to Windows and Android.
69 if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
Richard Smith59139022016-09-30 22:41:36 +000070 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
71 else
72 NewAlign = 0; // Infer from basic type alignment.
Anton Korobeynikovf0c267e2011-10-14 23:23:15 +000073 HalfWidth = 16;
74 HalfAlign = 16;
Eli Friedmanb5366062008-05-20 14:21:01 +000075 FloatWidth = 32;
76 FloatAlign = 32;
Nate Begeman65bea232008-04-18 17:17:24 +000077 DoubleWidth = 64;
Eli Friedmanb5366062008-05-20 14:21:01 +000078 DoubleAlign = 64;
79 LongDoubleWidth = 64;
80 LongDoubleAlign = 64;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +000081 Float128Align = 128;
Rafael Espindolae971b9a2010-06-04 23:15:27 +000082 LargeArrayMinWidth = 0;
83 LargeArrayAlign = 0;
Eli Friedman4b72fdd2011-10-14 20:59:01 +000084 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
Chad Rosiercc40ea72012-07-13 23:57:43 +000085 MaxVectorAlign = 0;
Paul Robinsond30e2ee2015-07-14 20:52:32 +000086 MaxTLSAlign = 0;
Alexey Bataev00396512015-07-02 03:40:19 +000087 SimdDefaultAlign = 0;
Anders Carlsson2a79a902008-10-31 16:05:19 +000088 SizeType = UnsignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000089 PtrDiffType = SignedLong;
Sanjiv Guptad7959242008-10-31 09:52:39 +000090 IntMaxType = SignedLongLong;
Chris Lattner7e4c81c2009-02-13 22:28:55 +000091 IntPtrType = SignedLong;
Eli Friedmand50881c2008-11-02 02:43:55 +000092 WCharType = SignedInt;
Chris Lattner67204922009-10-21 04:59:34 +000093 WIntType = SignedInt;
Alisdair Mereditha9ad47d2009-07-14 06:30:34 +000094 Char16Type = UnsignedShort;
95 Char32Type = UnsignedInt;
Eli Friedman2857ccb2009-07-01 03:36:11 +000096 Int64Type = SignedLongLong;
Edward O'Callaghan847f2a12009-11-21 00:49:54 +000097 SigAtomicType = SignedInt;
Eli Friedman4e91899e2012-11-27 02:58:24 +000098 ProcessIDType = SignedInt;
Fariborz Jahanian29898f42012-04-16 21:03:30 +000099 UseSignedCharForObjCBool = true;
Daniel Dunbar1da65112010-04-15 15:06:18 +0000100 UseBitFieldTypeAlignment = true;
Chad Rosier18903ee2011-08-04 01:21:14 +0000101 UseZeroLengthBitfieldAlignment = false;
Sunil Srivastava0ce2f222016-02-05 20:50:02 +0000102 UseExplicitBitFieldAlignment = true;
Chad Rosier18903ee2011-08-04 01:21:14 +0000103 ZeroLengthBitfieldBoundary = 0;
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000104 HalfFormat = &llvm::APFloat::IEEEhalf();
105 FloatFormat = &llvm::APFloat::IEEEsingle();
106 DoubleFormat = &llvm::APFloat::IEEEdouble();
107 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
108 Float128Format = &llvm::APFloat::IEEEquad();
Roman Divacky178e01602011-02-10 16:52:03 +0000109 MCountName = "mcount";
Abramo Bagnara41bfb662011-09-08 14:20:25 +0000110 RegParmMax = 0;
111 SSERegParmMax = 0;
Daniel Dunbarbd606522010-05-27 00:35:16 +0000112 HasAlignMac68kSupport = false;
Charles Davisc7d5c942015-09-17 20:55:33 +0000113 HasBuiltinMSVaList = false;
Pirama Arumuga Nainarbb846a32016-07-27 19:01:51 +0000114 IsRenderScriptTarget = false;
Richard Sandifordeb485fb2019-08-09 08:52:54 +0000115 HasAArch64SVETypes = false;
Daniel Dunbar6f2e8392010-07-14 23:39:36 +0000116
117 // Default to no types using fpret.
118 RealTypeUsesObjCFPRet = 0;
John McCall86353412010-08-21 22:46:04 +0000119
Anders Carlsson2f1a6c32011-10-31 16:27:11 +0000120 // Default to not using fp2ret for __Complex long double
121 ComplexLongDoubleUsesFP2Ret = false;
122
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000123 // Set the C++ ABI based on the triple.
Saleem Abdulrasool377066a2014-03-27 22:50:18 +0000124 TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
Hans Wennborgc9bd88e2014-01-14 19:35:09 +0000125 ? TargetCXXABI::Microsoft
126 : TargetCXXABI::GenericItanium);
Peter Collingbourne599cb8e2011-03-18 22:38:29 +0000127
128 // Default to an empty address space map.
129 AddrSpaceMap = &DefaultAddrSpaceMap;
David Tweed31d09b02013-09-13 12:04:22 +0000130 UseAddrSpaceMapMangling = false;
Douglas Gregor20b2ebd2011-03-23 00:50:03 +0000131
132 // Default to an unknown platform name.
133 PlatformName = "unknown";
134 PlatformMinVersion = VersionTuple();
Chris Lattner1df27862008-03-08 08:59:43 +0000135}
136
Chris Lattnerc3a669b2008-03-08 08:24:01 +0000137// Out of line virtual dtor for TargetInfo.
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000138TargetInfo::~TargetInfo() {}
Chris Lattner2194ddc2006-10-14 18:32:26 +0000139
Bjorn Pettersson78424e52019-10-21 17:58:14 +0000140void TargetInfo::resetDataLayout(StringRef DL) {
141 DataLayout.reset(new llvm::DataLayout(DL));
142}
143
Alexander Ivchenko0fb8c872018-05-18 11:56:21 +0000144bool
145TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
146 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
147 return false;
148}
149
150bool
151TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const {
152 Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
153 return false;
154}
155
Chris Lattnera91c30f2009-02-06 05:04:11 +0000156/// getTypeName - Return the user string for the specified integer type enum.
157/// For example, SignedShort -> "short".
158const char *TargetInfo::getTypeName(IntType T) {
159 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000160 default: llvm_unreachable("not an integer!");
Joerg Sonnenberger3d9478c2014-07-28 21:06:22 +0000161 case SignedChar: return "signed char";
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000162 case UnsignedChar: return "unsigned char";
Chris Lattnera91c30f2009-02-06 05:04:11 +0000163 case SignedShort: return "short";
164 case UnsignedShort: return "unsigned short";
165 case SignedInt: return "int";
166 case UnsignedInt: return "unsigned int";
167 case SignedLong: return "long int";
168 case UnsignedLong: return "long unsigned int";
169 case SignedLongLong: return "long long int";
170 case UnsignedLongLong: return "long long unsigned int";
171 }
172}
173
Chris Lattner72cdcac2009-10-21 06:24:21 +0000174/// getTypeConstantSuffix - Return the constant suffix for the specified
175/// integer type enum. For example, SignedLong -> "L".
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000176const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000177 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000178 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000179 case SignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000180 case SignedShort:
181 case SignedInt: return "";
182 case SignedLong: return "L";
183 case SignedLongLong: return "LL";
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000184 case UnsignedChar:
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000185 if (getCharWidth() < getIntWidth())
186 return "";
Galina Kistanova96088f42017-06-03 06:38:22 +0000187 LLVM_FALLTHROUGH;
Chris Lattner72cdcac2009-10-21 06:24:21 +0000188 case UnsignedShort:
Joerg Sonnenberger587deea2014-07-17 20:12:32 +0000189 if (getShortWidth() < getIntWidth())
190 return "";
Galina Kistanova96088f42017-06-03 06:38:22 +0000191 LLVM_FALLTHROUGH;
Chris Lattner72cdcac2009-10-21 06:24:21 +0000192 case UnsignedInt: return "U";
193 case UnsignedLong: return "UL";
194 case UnsignedLongLong: return "ULL";
195 }
196}
197
Joerg Sonnenbergerbe324f92014-07-15 11:30:00 +0000198/// getTypeFormatModifier - Return the printf format modifier for the
199/// specified integer type enum. For example, SignedLong -> "l".
200
201const char *TargetInfo::getTypeFormatModifier(IntType T) {
202 switch (T) {
203 default: llvm_unreachable("not an integer!");
204 case SignedChar:
205 case UnsignedChar: return "hh";
206 case SignedShort:
207 case UnsignedShort: return "h";
208 case SignedInt:
209 case UnsignedInt: return "";
210 case SignedLong:
211 case UnsignedLong: return "l";
212 case SignedLongLong:
213 case UnsignedLongLong: return "ll";
214 }
215}
216
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000217/// getTypeWidth - Return the width (in bits) of the specified integer type
Chris Lattner72cdcac2009-10-21 06:24:21 +0000218/// enum. For example, SignedInt -> getIntWidth().
219unsigned TargetInfo::getTypeWidth(IntType T) const {
220 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000221 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000222 case SignedChar:
223 case UnsignedChar: return getCharWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000224 case SignedShort:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000225 case UnsignedShort: return getShortWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000226 case SignedInt:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000227 case UnsignedInt: return getIntWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000228 case SignedLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000229 case UnsignedLong: return getLongWidth();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000230 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000231 case UnsignedLongLong: return getLongLongWidth();
232 };
233}
234
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000235TargetInfo::IntType TargetInfo::getIntTypeByWidth(
236 unsigned BitWidth, bool IsSigned) const {
237 if (getCharWidth() == BitWidth)
238 return IsSigned ? SignedChar : UnsignedChar;
239 if (getShortWidth() == BitWidth)
240 return IsSigned ? SignedShort : UnsignedShort;
241 if (getIntWidth() == BitWidth)
242 return IsSigned ? SignedInt : UnsignedInt;
243 if (getLongWidth() == BitWidth)
244 return IsSigned ? SignedLong : UnsignedLong;
245 if (getLongLongWidth() == BitWidth)
246 return IsSigned ? SignedLongLong : UnsignedLongLong;
247 return NoInt;
248}
249
JF Bastienab8d0a02014-06-25 01:31:33 +0000250TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
251 bool IsSigned) const {
252 if (getCharWidth() >= BitWidth)
253 return IsSigned ? SignedChar : UnsignedChar;
254 if (getShortWidth() >= BitWidth)
255 return IsSigned ? SignedShort : UnsignedShort;
256 if (getIntWidth() >= BitWidth)
257 return IsSigned ? SignedInt : UnsignedInt;
258 if (getLongWidth() >= BitWidth)
259 return IsSigned ? SignedLong : UnsignedLong;
260 if (getLongLongWidth() >= BitWidth)
261 return IsSigned ? SignedLongLong : UnsignedLongLong;
262 return NoInt;
263}
264
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000265TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth) const {
266 if (getFloatWidth() == BitWidth)
267 return Float;
268 if (getDoubleWidth() == BitWidth)
269 return Double;
270
271 switch (BitWidth) {
272 case 96:
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000273 if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000274 return LongDouble;
275 break;
276 case 128:
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000277 if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
278 &getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000279 return LongDouble;
Nemanja Ivanovicbb1ea2d2016-05-09 08:52:33 +0000280 if (hasFloat128Type())
281 return Float128;
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000282 break;
283 }
284
285 return NoFloat;
286}
287
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000288/// getTypeAlign - Return the alignment (in bits) of the specified integer type
Chris Lattnere4a8c642009-11-05 21:21:32 +0000289/// enum. For example, SignedInt -> getIntAlign().
290unsigned TargetInfo::getTypeAlign(IntType T) const {
291 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000292 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000293 case SignedChar:
294 case UnsignedChar: return getCharAlign();
Chris Lattnere4a8c642009-11-05 21:21:32 +0000295 case SignedShort:
296 case UnsignedShort: return getShortAlign();
297 case SignedInt:
298 case UnsignedInt: return getIntAlign();
299 case SignedLong:
300 case UnsignedLong: return getLongAlign();
301 case SignedLongLong:
302 case UnsignedLongLong: return getLongLongAlign();
303 };
304}
305
Chris Lattnerc0c04392009-10-25 22:49:18 +0000306/// isTypeSigned - Return whether an integer types is signed. Returns true if
Chris Lattner72cdcac2009-10-21 06:24:21 +0000307/// the type is signed; false otherwise.
Chris Lattnerad3467e2010-12-25 23:25:43 +0000308bool TargetInfo::isTypeSigned(IntType T) {
Chris Lattner72cdcac2009-10-21 06:24:21 +0000309 switch (T) {
David Blaikie83d382b2011-09-23 05:06:16 +0000310 default: llvm_unreachable("not an integer!");
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000311 case SignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000312 case SignedShort:
313 case SignedInt:
314 case SignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000315 case SignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000316 return true;
Stepan Dyatkovskiy5a637922013-09-05 11:23:21 +0000317 case UnsignedChar:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000318 case UnsignedShort:
319 case UnsignedInt:
320 case UnsignedLong:
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000321 case UnsignedLongLong:
Chris Lattner72cdcac2009-10-21 06:24:21 +0000322 return false;
323 };
324}
325
Alp Toker74437972014-07-06 05:14:24 +0000326/// adjust - Set forced language options.
John Thompsoned4e2952009-11-05 20:14:16 +0000327/// Apply changes to the target information with respect to certain
Eric Christopher3646e622017-03-22 06:36:09 +0000328/// language options which change the target configuration and adjust
329/// the language based on the target options where applicable.
330void TargetInfo::adjust(LangOptions &Opts) {
Daniel Dunbar9302f602010-04-15 15:06:22 +0000331 if (Opts.NoBitFieldTypeAlign)
332 UseBitFieldTypeAlignment = false;
Saleem Abdulrasool729379a2017-10-06 23:09:55 +0000333
334 switch (Opts.WCharSize) {
335 default: llvm_unreachable("invalid wchar_t width");
336 case 0: break;
337 case 1: WCharType = Opts.WCharIsSigned ? SignedChar : UnsignedChar; break;
338 case 2: WCharType = Opts.WCharIsSigned ? SignedShort : UnsignedShort; break;
339 case 4: WCharType = Opts.WCharIsSigned ? SignedInt : UnsignedInt; break;
340 }
341
Reid Kleckner8195f692016-05-04 02:58:24 +0000342 if (Opts.AlignDouble) {
343 DoubleAlign = LongLongAlign = 64;
344 LongDoubleAlign = 64;
345 }
David Tweed2da64382013-09-09 09:17:24 +0000346
347 if (Opts.OpenCL) {
348 // OpenCL C requires specific widths for types, irrespective of
349 // what these normally are for the target.
350 // We also define long long and long double here, although the
351 // OpenCL standard only mentions these as "reserved".
352 IntWidth = IntAlign = 32;
353 LongWidth = LongAlign = 64;
354 LongLongWidth = LongLongAlign = 128;
355 HalfWidth = HalfAlign = 16;
356 FloatWidth = FloatAlign = 32;
Eric Christopherb093d692015-10-09 18:39:59 +0000357
358 // Embedded 32-bit targets (OpenCL EP) might have double C type
359 // defined as float. Let's not override this as it might lead
Pekka Jaaskelainen43c39d52013-12-18 18:15:03 +0000360 // to generating illegal code that uses 64bit doubles.
361 if (DoubleWidth != FloatWidth) {
362 DoubleWidth = DoubleAlign = 64;
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000363 DoubleFormat = &llvm::APFloat::IEEEdouble();
Pekka Jaaskelainen43c39d52013-12-18 18:15:03 +0000364 }
David Tweed2da64382013-09-09 09:17:24 +0000365 LongDoubleWidth = LongDoubleAlign = 128;
366
Yaxun Liu26f75662016-08-19 05:17:25 +0000367 unsigned MaxPointerWidth = getMaxPointerWidth();
368 assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
369 bool Is32BitArch = MaxPointerWidth == 32;
David Tweed6c2149b2013-09-10 08:00:34 +0000370 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
371 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
372 IntPtrType = Is32BitArch ? SignedInt : SignedLong;
David Tweed2da64382013-09-09 09:17:24 +0000373
374 IntMaxType = SignedLongLong;
David Tweed2da64382013-09-09 09:17:24 +0000375 Int64Type = SignedLong;
376
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000377 HalfFormat = &llvm::APFloat::IEEEhalf();
378 FloatFormat = &llvm::APFloat::IEEEsingle();
379 LongDoubleFormat = &llvm::APFloat::IEEEquad();
David Tweed2da64382013-09-09 09:17:24 +0000380 }
Richard Smith59139022016-09-30 22:41:36 +0000381
Fangrui Songc46d78d2019-07-12 02:32:15 +0000382 if (Opts.LongDoubleSize) {
383 if (Opts.LongDoubleSize == DoubleWidth) {
384 LongDoubleWidth = DoubleWidth;
385 LongDoubleAlign = DoubleAlign;
386 LongDoubleFormat = DoubleFormat;
387 } else if (Opts.LongDoubleSize == 128) {
388 LongDoubleWidth = LongDoubleAlign = 128;
389 LongDoubleFormat = &llvm::APFloat::IEEEquad();
390 }
Fangrui Song11cb39c2019-07-09 00:27:43 +0000391 }
392
Richard Smith59139022016-09-30 22:41:36 +0000393 if (Opts.NewAlignOverride)
394 NewAlign = Opts.NewAlignOverride * getCharWidth();
Leonard Chandb01c3a2018-06-20 17:19:40 +0000395
396 // Each unsigned fixed point type has the same number of fractional bits as
397 // its corresponding signed type.
Leonard Chan6e16c602018-06-29 17:08:19 +0000398 PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
Leonard Chandb01c3a2018-06-20 17:19:40 +0000399 CheckFixedPointBits();
John Thompsoned4e2952009-11-05 20:14:16 +0000400}
Chris Lattner72cdcac2009-10-21 06:24:21 +0000401
Eric Christopher8c47b422015-10-09 18:39:55 +0000402bool TargetInfo::initFeatureMap(
403 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
404 const std::vector<std::string> &FeatureVec) const {
Eric Christophere9cdcae2015-09-01 18:13:20 +0000405 for (const auto &F : FeatureVec) {
Craig Topper8459aa82015-10-21 16:31:31 +0000406 StringRef Name = F;
Eric Christophere9cdcae2015-09-01 18:13:20 +0000407 // Apply the feature via the target.
408 bool Enabled = Name[0] == '+';
Craig Topper8459aa82015-10-21 16:31:31 +0000409 setFeatureEnabled(Features, Name.substr(1), Enabled);
Eric Christophere9cdcae2015-09-01 18:13:20 +0000410 }
411 return true;
412}
413
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000414TargetInfo::CallingConvKind
415TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
416 if (getCXXABI() != TargetCXXABI::Microsoft &&
417 (ClangABICompat4 || getTriple().getOS() == llvm::Triple::PS4))
418 return CCK_ClangABI4OrPS4;
419 return CCK_Default;
420}
421
Sven van Haastregt3bb7eaf2017-12-06 10:11:28 +0000422LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
423 switch (TK) {
424 case OCLTK_Image:
425 case OCLTK_Pipe:
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000426 return LangAS::opencl_global;
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000427
Sven van Haastregt3bb7eaf2017-12-06 10:11:28 +0000428 case OCLTK_Sampler:
Sven van Haastregtefb4d4c2017-08-15 09:38:18 +0000429 return LangAS::opencl_constant;
430
431 default:
432 return LangAS::Default;
433 }
434}
435
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000436//===----------------------------------------------------------------------===//
Chris Lattnerec0a6d92007-09-22 18:29:59 +0000437
Chris Lattner10a5b382007-01-29 05:24:35 +0000438
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000439static StringRef removeGCCRegisterPrefix(StringRef Name) {
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000440 if (Name[0] == '%' || Name[0] == '#')
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000441 Name = Name.substr(1);
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000442
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000443 return Name;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000444}
445
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000446/// isValidClobber - Returns whether the passed in string is
447/// a valid clobber in an inline asm statement. This is used by
448/// Sema.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000449bool TargetInfo::isValidClobber(StringRef Name) const {
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000450 return (isValidGCCRegisterName(Name) ||
Eric Christopherb093d692015-10-09 18:39:59 +0000451 Name == "memory" || Name == "cc");
Eric Christopherfd9a5f42011-06-28 18:20:53 +0000452}
453
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000454/// isValidGCCRegisterName - Returns whether the passed in string
455/// is a valid register name according to GCC. This is used by Sema for
456/// inline asm statements.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000457bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000458 if (Name.empty())
459 return false;
Michael J. Spencerfeb799c2010-10-18 07:10:59 +0000460
Anders Carlsson290aa852007-11-25 00:25:21 +0000461 // Get rid of any register prefix.
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000462 Name = removeGCCRegisterPrefix(Name);
Olivier Goffartfc8f8932014-08-17 13:19:48 +0000463 if (Name.empty())
Craig Topperde330c72015-10-21 04:52:34 +0000464 return false;
Anders Carlsson3ed4aea2008-02-06 00:11:32 +0000465
Craig Topperf054e3a2015-10-19 03:52:27 +0000466 ArrayRef<const char *> Names = getGCCRegNames();
Mike Stump11289f42009-09-09 15:08:12 +0000467
Anders Carlsson290aa852007-11-25 00:25:21 +0000468 // If we have a number it maps to an entry in the register name array.
Jordan Rosea7d03842013-02-08 22:30:41 +0000469 if (isDigit(Name[0])) {
Craig Topper67288a92015-10-21 04:52:36 +0000470 unsigned n;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000471 if (!Name.getAsInteger(0, n))
Craig Topper67288a92015-10-21 04:52:36 +0000472 return n < Names.size();
Anders Carlsson290aa852007-11-25 00:25:21 +0000473 }
474
475 // Check register names.
Fangrui Song9ac13a12019-02-10 05:54:57 +0000476 if (llvm::is_contained(Names, Name))
Craig Topper335c8f92015-10-21 04:52:38 +0000477 return true;
Mike Stump11289f42009-09-09 15:08:12 +0000478
Eric Christophercdd36352011-06-21 00:05:20 +0000479 // Check any additional names that we have.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000480 for (const AddlRegName &ARN : getGCCAddlRegNames())
481 for (const char *AN : ARN.Names) {
482 if (!AN)
Eric Christopherb093d692015-10-09 18:39:59 +0000483 break;
Eric Christophercdd36352011-06-21 00:05:20 +0000484 // Make sure the register that the additional name is for is within
485 // the bounds of the register names from above.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000486 if (AN == Name && ARN.RegNum < Names.size())
Anders Carlsson290aa852007-11-25 00:25:21 +0000487 return true;
488 }
Craig Topperdd2b74a2015-10-21 04:52:40 +0000489
490 // Now check aliases.
491 for (const GCCRegAlias &GRA : getGCCRegAliases())
492 for (const char *A : GRA.Aliases) {
493 if (!A)
494 break;
495 if (A == Name)
496 return true;
497 }
Mike Stump11289f42009-09-09 15:08:12 +0000498
Anders Carlsson5fa3f342007-11-24 23:38:12 +0000499 return false;
500}
Anders Carlssonf511f642007-11-27 04:11:28 +0000501
Marina Yatsinac42fd032016-12-26 12:23:42 +0000502StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
503 bool ReturnCanonical) const {
Anders Carlssonf511f642007-11-27 04:11:28 +0000504 assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
Mike Stump11289f42009-09-09 15:08:12 +0000505
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000506 // Get rid of any register prefix.
507 Name = removeGCCRegisterPrefix(Name);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Craig Topperf054e3a2015-10-19 03:52:27 +0000509 ArrayRef<const char *> Names = getGCCRegNames();
Anders Carlssonf511f642007-11-27 04:11:28 +0000510
511 // First, check if we have a number.
Jordan Rosea7d03842013-02-08 22:30:41 +0000512 if (isDigit(Name[0])) {
Craig Topper67288a92015-10-21 04:52:36 +0000513 unsigned n;
Anders Carlssonc7c5baa2010-01-30 19:12:25 +0000514 if (!Name.getAsInteger(0, n)) {
Craig Topper67288a92015-10-21 04:52:36 +0000515 assert(n < Names.size() && "Out of bounds register number!");
Anders Carlssonf511f642007-11-27 04:11:28 +0000516 return Names[n];
517 }
518 }
Mike Stump11289f42009-09-09 15:08:12 +0000519
Eric Christophercdd36352011-06-21 00:05:20 +0000520 // Check any additional names that we have.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000521 for (const AddlRegName &ARN : getGCCAddlRegNames())
522 for (const char *AN : ARN.Names) {
523 if (!AN)
Eric Christopherb093d692015-10-09 18:39:59 +0000524 break;
Eric Christophercdd36352011-06-21 00:05:20 +0000525 // Make sure the register that the additional name is for is within
526 // the bounds of the register names from above.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000527 if (AN == Name && ARN.RegNum < Names.size())
Marina Yatsinac42fd032016-12-26 12:23:42 +0000528 return ReturnCanonical ? Names[ARN.RegNum] : Name;
Eric Christophercdd36352011-06-21 00:05:20 +0000529 }
530
Anders Carlssonf511f642007-11-27 04:11:28 +0000531 // Now check aliases.
Craig Topperdd2b74a2015-10-21 04:52:40 +0000532 for (const GCCRegAlias &RA : getGCCRegAliases())
533 for (const char *A : RA.Aliases) {
534 if (!A)
Anders Carlssonf511f642007-11-27 04:11:28 +0000535 break;
Craig Topperdd2b74a2015-10-21 04:52:40 +0000536 if (A == Name)
537 return RA.Register;
Anders Carlssonf511f642007-11-27 04:11:28 +0000538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
Anders Carlssonf511f642007-11-27 04:11:28 +0000540 return Name;
541}
542
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000543bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
544 const char *Name = Info.getConstraintStr().c_str();
Anders Carlssonf511f642007-11-27 04:11:28 +0000545 // An output constraint must start with '=' or '+'
546 if (*Name != '=' && *Name != '+')
547 return false;
548
549 if (*Name == '+')
Chris Lattnerd9725f72009-04-26 07:16:29 +0000550 Info.setIsReadWrite();
Anders Carlssonf511f642007-11-27 04:11:28 +0000551
552 Name++;
553 while (*Name) {
554 switch (*Name) {
555 default:
Chris Lattnerd9725f72009-04-26 07:16:29 +0000556 if (!validateAsmConstraint(Name, Info)) {
Ted Kremenekb44485b2008-04-24 16:36:38 +0000557 // FIXME: We temporarily return false
Anders Carlssonf511f642007-11-27 04:11:28 +0000558 // so we can add more constraints as we hit it.
559 // Eventually, an unknown constraint should just be treated as 'g'.
Ted Kremenekb44485b2008-04-24 16:36:38 +0000560 return false;
Anders Carlssonf511f642007-11-27 04:11:28 +0000561 }
David Majnemera0040df2015-01-10 10:43:19 +0000562 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000563 case '&': // early clobber.
David Majnemera0040df2015-01-10 10:43:19 +0000564 Info.setEarlyClobber();
Anders Carlssonf511f642007-11-27 04:11:28 +0000565 break;
Chris Lattnerf3154712009-10-13 04:32:07 +0000566 case '%': // commutative.
567 // FIXME: Check that there is a another register after this one.
568 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000569 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000570 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000571 break;
572 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000573 case 'o': // offsetable memory operand.
574 case 'V': // non-offsetable memory operand.
575 case '<': // autodecrement memory operand.
576 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000577 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000578 break;
579 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000580 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000581 Info.setAllowsRegister();
582 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000583 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000584 case ',': // multiple alternative constraint. Pass it.
John Thompson46667af2010-08-11 00:58:20 +0000585 // Handle additional optional '=' or '+' modifiers.
John Thompson12240612010-09-18 01:15:13 +0000586 if (Name[1] == '=' || Name[1] == '+')
John Thompson46667af2010-08-11 00:58:20 +0000587 Name++;
John Thompsona5c7d702010-08-10 19:20:14 +0000588 break;
David Majnemer50cb0552015-01-11 08:52:38 +0000589 case '#': // Ignore as constraint.
590 while (Name[1] && Name[1] != ',')
591 Name++;
David Majnemerc71a5662015-01-11 09:39:03 +0000592 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000593 case '?': // Disparage slightly code.
Dale Johannesen8499f472010-09-07 18:40:41 +0000594 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000595 case '*': // Ignore for choosing register preferences.
Marina Yatsina33eb7752017-06-26 15:55:51 +0000596 case 'i': // Ignore i,n,E,F as output constraints (match from the other
597 // chars)
598 case 'n':
599 case 'E':
600 case 'F':
John Thompsona5c7d702010-08-10 19:20:14 +0000601 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000602 }
Mike Stump11289f42009-09-09 15:08:12 +0000603
Anders Carlssonf511f642007-11-27 04:11:28 +0000604 Name++;
605 }
Mike Stump11289f42009-09-09 15:08:12 +0000606
David Majnemera0040df2015-01-10 10:43:19 +0000607 // Early clobber with a read-write constraint which doesn't permit registers
608 // is invalid.
609 if (Info.earlyClobber() && Info.isReadWrite() && !Info.allowsRegister())
610 return false;
611
Benjamin Kramer1e4a8862013-04-18 22:49:48 +0000612 // If a constraint allows neither memory nor register operands it contains
613 // only modifiers. Reject it.
Benjamin Kramer7ee3b9c2013-04-18 13:23:23 +0000614 return Info.allowsMemory() || Info.allowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000615}
616
Anders Carlssona79203b2009-01-18 01:56:57 +0000617bool TargetInfo::resolveSymbolicName(const char *&Name,
Craig Topper55765ca2015-10-21 02:34:10 +0000618 ArrayRef<ConstraintInfo> OutputConstraints,
Chris Lattnerd9725f72009-04-26 07:16:29 +0000619 unsigned &Index) const {
Anders Carlssona79203b2009-01-18 01:56:57 +0000620 assert(*Name == '[' && "Symbolic name did not start with '['");
Anders Carlssona79203b2009-01-18 01:56:57 +0000621 Name++;
622 const char *Start = Name;
623 while (*Name && *Name != ']')
624 Name++;
Mike Stump11289f42009-09-09 15:08:12 +0000625
Anders Carlssona79203b2009-01-18 01:56:57 +0000626 if (!*Name) {
627 // Missing ']'
628 return false;
629 }
Mike Stump11289f42009-09-09 15:08:12 +0000630
Anders Carlssona79203b2009-01-18 01:56:57 +0000631 std::string SymbolicName(Start, Name - Start);
Mike Stump11289f42009-09-09 15:08:12 +0000632
Craig Topper55765ca2015-10-21 02:34:10 +0000633 for (Index = 0; Index != OutputConstraints.size(); ++Index)
Chris Lattnerc16d4762009-04-26 17:57:12 +0000634 if (SymbolicName == OutputConstraints[Index].getName())
Anders Carlssona79203b2009-01-18 01:56:57 +0000635 return true;
Anders Carlssona79203b2009-01-18 01:56:57 +0000636
637 return false;
638}
639
Craig Topper55765ca2015-10-21 02:34:10 +0000640bool TargetInfo::validateInputConstraint(
641 MutableArrayRef<ConstraintInfo> OutputConstraints,
642 ConstraintInfo &Info) const {
Chris Lattnerc3f4c7b2009-04-26 17:19:08 +0000643 const char *Name = Info.ConstraintStr.c_str();
644
Duncan P. N. Exon Smithd68c7aa2013-12-16 03:20:06 +0000645 if (!*Name)
646 return false;
647
Anders Carlssonf511f642007-11-27 04:11:28 +0000648 while (*Name) {
649 switch (*Name) {
650 default:
651 // Check if we have a matching constraint
652 if (*Name >= '0' && *Name <= '9') {
David Majnemerb6b56432015-01-11 10:22:41 +0000653 const char *DigitStart = Name;
654 while (Name[1] >= '0' && Name[1] <= '9')
655 Name++;
656 const char *DigitEnd = Name;
657 unsigned i;
658 if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
659 .getAsInteger(10, i))
660 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000661
Anders Carlssonf511f642007-11-27 04:11:28 +0000662 // Check if matching constraint is out of bounds.
Craig Topper55765ca2015-10-21 02:34:10 +0000663 if (i >= OutputConstraints.size()) return false;
Mike Stump11289f42009-09-09 15:08:12 +0000664
Anders Carlssonda1f5fc2010-11-03 02:22:29 +0000665 // A number must refer to an output only operand.
666 if (OutputConstraints[i].isReadWrite())
667 return false;
668
Eric Christopherb093d692015-10-09 18:39:59 +0000669 // If the constraint is already tied, it must be tied to the
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000670 // same operand referenced to by the number.
671 if (Info.hasTiedOperand() && Info.getTiedOperand() != i)
672 return false;
673
Mike Stump11289f42009-09-09 15:08:12 +0000674 // The constraint should have the same info as the respective
Anders Carlsson570c3572009-01-27 20:38:24 +0000675 // output constraint.
Chris Lattner4c92b512009-04-26 18:05:25 +0000676 Info.setTiedOperand(i, OutputConstraints[i]);
Chris Lattnerd9725f72009-04-26 07:16:29 +0000677 } else if (!validateAsmConstraint(Name, Info)) {
Daniel Dunbar81128e02008-08-25 09:46:27 +0000678 // FIXME: This error return is in place temporarily so we can
679 // add more constraints as we hit it. Eventually, an unknown
680 // constraint should just be treated as 'g'.
681 return false;
Anders Carlssona79203b2009-01-18 01:56:57 +0000682 }
683 break;
684 case '[': {
685 unsigned Index = 0;
Craig Topper55765ca2015-10-21 02:34:10 +0000686 if (!resolveSymbolicName(Name, OutputConstraints, Index))
Anders Carlssona79203b2009-01-18 01:56:57 +0000687 return false;
Mike Stump11289f42009-09-09 15:08:12 +0000688
Eric Christopherb093d692015-10-09 18:39:59 +0000689 // If the constraint is already tied, it must be tied to the
Anders Carlsson2d5f8b42010-11-03 02:54:51 +0000690 // same operand referenced to by the number.
691 if (Info.hasTiedOperand() && Info.getTiedOperand() != Index)
692 return false;
693
David Majnemer55164f92015-01-11 09:57:13 +0000694 // A number must refer to an output only operand.
695 if (OutputConstraints[Index].isReadWrite())
696 return false;
697
Eli Friedman854f1102010-08-11 23:03:37 +0000698 Info.setTiedOperand(Index, OutputConstraints[Index]);
Anders Carlssona79203b2009-01-18 01:56:57 +0000699 break;
Mike Stump11289f42009-09-09 15:08:12 +0000700 }
Anders Carlsson050f4942007-12-08 19:32:57 +0000701 case '%': // commutative
702 // FIXME: Fail if % is used with the last operand.
703 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000704 case 'i': // immediate integer.
Bill Wendlingaa775132018-12-18 22:54:03 +0000705 break;
Anders Carlssona3a96af2008-03-09 06:02:02 +0000706 case 'n': // immediate integer with a known value.
Bill Wendlingaa775132018-12-18 22:54:03 +0000707 Info.setRequiresImmediate();
Anders Carlssonf511f642007-11-27 04:11:28 +0000708 break;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000709 case 'I': // Various constant constraints with target-specific meanings.
710 case 'J':
711 case 'K':
712 case 'L':
713 case 'M':
714 case 'N':
715 case 'O':
716 case 'P':
Saleem Abdulrasoola2823572015-01-06 04:26:34 +0000717 if (!validateAsmConstraint(Name, Info))
718 return false;
Chris Lattnerdbcc5ca2009-05-06 04:33:31 +0000719 break;
Anders Carlssonf511f642007-11-27 04:11:28 +0000720 case 'r': // general register.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000721 Info.setAllowsRegister();
Anders Carlssonf511f642007-11-27 04:11:28 +0000722 break;
723 case 'm': // memory operand.
Dale Johannesen8499f472010-09-07 18:40:41 +0000724 case 'o': // offsettable memory operand.
725 case 'V': // non-offsettable memory operand.
726 case '<': // autodecrement memory operand.
727 case '>': // autoincrement memory operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000728 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000729 break;
730 case 'g': // general register, memory operand or immediate integer.
Anders Carlssone70cde12009-01-18 02:12:04 +0000731 case 'X': // any operand.
Chris Lattnerd9725f72009-04-26 07:16:29 +0000732 Info.setAllowsRegister();
733 Info.setAllowsMemory();
Anders Carlssonf511f642007-11-27 04:11:28 +0000734 break;
John Thompsonc467aa22010-09-21 22:04:54 +0000735 case 'E': // immediate floating point.
736 case 'F': // immediate floating point.
737 case 'p': // address operand.
738 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000739 case ',': // multiple alternative constraint. Ignore comma.
740 break;
David Majnemerc71a5662015-01-11 09:39:03 +0000741 case '#': // Ignore as constraint.
742 while (Name[1] && Name[1] != ',')
743 Name++;
David Majnemerc71a5662015-01-11 09:39:03 +0000744 break;
John Thompsona5c7d702010-08-10 19:20:14 +0000745 case '?': // Disparage slightly code.
Chris Lattner57540c52011-04-15 05:22:18 +0000746 case '!': // Disparage severely.
Ulrich Weigand7bcc7ec2012-10-29 12:20:54 +0000747 case '*': // Ignore for choosing register preferences.
John Thompsona5c7d702010-08-10 19:20:14 +0000748 break; // Pass them.
Anders Carlssonf511f642007-11-27 04:11:28 +0000749 }
Mike Stump11289f42009-09-09 15:08:12 +0000750
Anders Carlssonf511f642007-11-27 04:11:28 +0000751 Name++;
752 }
Mike Stump11289f42009-09-09 15:08:12 +0000753
Anders Carlssonf511f642007-11-27 04:11:28 +0000754 return true;
755}
Leonard Chandb01c3a2018-06-20 17:19:40 +0000756
757void TargetInfo::CheckFixedPointBits() const {
758 // Check that the number of fractional and integral bits (and maybe sign) can
759 // fit into the bits given for a fixed point type.
760 assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth);
761 assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
762 assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth);
763 assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
764 ShortAccumWidth);
765 assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth);
766 assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
767 LongAccumWidth);
768
769 assert(getShortFractScale() + 1 <= ShortFractWidth);
770 assert(getFractScale() + 1 <= FractWidth);
771 assert(getLongFractScale() + 1 <= LongFractWidth);
772 assert(getUnsignedShortFractScale() <= ShortFractWidth);
773 assert(getUnsignedFractScale() <= FractWidth);
774 assert(getUnsignedLongFractScale() <= LongFractWidth);
775
776 // Each unsigned fract type has either the same number of fractional bits
777 // as, or one more fractional bit than, its corresponding signed fract type.
778 assert(getShortFractScale() == getUnsignedShortFractScale() ||
779 getShortFractScale() == getUnsignedShortFractScale() - 1);
780 assert(getFractScale() == getUnsignedFractScale() ||
781 getFractScale() == getUnsignedFractScale() - 1);
782 assert(getLongFractScale() == getUnsignedLongFractScale() ||
783 getLongFractScale() == getUnsignedLongFractScale() - 1);
784
785 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
786 // fractional bits is nondecreasing for each of the following sets of
787 // fixed-point types:
788 // - signed fract types
789 // - unsigned fract types
790 // - signed accum types
791 // - unsigned accum types.
792 assert(getLongFractScale() >= getFractScale() &&
793 getFractScale() >= getShortFractScale());
794 assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
795 getUnsignedFractScale() >= getUnsignedShortFractScale());
796 assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale);
797 assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
798 getUnsignedAccumScale() >= getUnsignedShortAccumScale());
799
800 // When arranged in order of increasing rank (see 6.3.1.3a), the number of
801 // integral bits is nondecreasing for each of the following sets of
802 // fixed-point types:
803 // - signed accum types
804 // - unsigned accum types
805 assert(getLongAccumIBits() >= getAccumIBits() &&
806 getAccumIBits() >= getShortAccumIBits());
807 assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
808 getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
809
810 // Each signed accum type has at least as many integral bits as its
811 // corresponding unsigned accum type.
812 assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
813 assert(getAccumIBits() >= getUnsignedAccumIBits());
814 assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
815}
Yaxun Liu95f2ca52019-01-30 12:26:54 +0000816
817void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
818 auto *Target = static_cast<TransferrableTargetInfo*>(this);
819 auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
820 *Target = *Src;
821}