Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/TargetInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- TargetInfo.cpp - Information about Target machine ----------------===//
2
//
3
// 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
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
//  This file implements the TargetInfo and TargetInfoImpl interfaces.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Basic/TargetInfo.h"
14
#include "clang/Basic/AddressSpaces.h"
15
#include "clang/Basic/CharInfo.h"
16
#include "clang/Basic/Diagnostic.h"
17
#include "clang/Basic/LangOptions.h"
18
#include "llvm/ADT/APFloat.h"
19
#include "llvm/ADT/STLExtras.h"
20
#include "llvm/Support/ErrorHandling.h"
21
#include "llvm/Support/TargetParser.h"
22
#include <cstdlib>
23
using namespace clang;
24
25
static const LangASMap DefaultAddrSpaceMap = {0};
26
27
// TargetInfo Constructor.
28
96.0k
TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
29
  // 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.
31
96.0k
  BigEndian = !T.isLittleEndian();
32
96.0k
  TLSSupported = true;
33
96.0k
  VLASupported = true;
34
96.0k
  NoAsmVariants = false;
35
96.0k
  HasLegalHalfType = false;
36
96.0k
  HasFloat128 = false;
37
96.0k
  HasIbm128 = false;
38
96.0k
  HasFloat16 = false;
39
96.0k
  HasBFloat16 = false;
40
96.0k
  HasLongDouble = true;
41
96.0k
  HasFPReturn = true;
42
96.0k
  HasStrictFP = false;
43
96.0k
  PointerWidth = PointerAlign = 32;
44
96.0k
  BoolWidth = BoolAlign = 8;
45
96.0k
  IntWidth = IntAlign = 32;
46
96.0k
  LongWidth = LongAlign = 32;
47
96.0k
  LongLongWidth = LongLongAlign = 64;
48
49
  // Fixed point default bit widths
50
96.0k
  ShortAccumWidth = ShortAccumAlign = 16;
51
96.0k
  AccumWidth = AccumAlign = 32;
52
96.0k
  LongAccumWidth = LongAccumAlign = 64;
53
96.0k
  ShortFractWidth = ShortFractAlign = 8;
54
96.0k
  FractWidth = FractAlign = 16;
55
96.0k
  LongFractWidth = LongFractAlign = 32;
56
57
  // Fixed point default integral and fractional bit sizes
58
  // We give the _Accum 1 fewer fractional bits than their corresponding _Fract
59
  // types by default to have the same number of fractional bits between _Accum
60
  // and _Fract types.
61
96.0k
  PaddingOnUnsignedFixedPoint = false;
62
96.0k
  ShortAccumScale = 7;
63
96.0k
  AccumScale = 15;
64
96.0k
  LongAccumScale = 31;
65
66
96.0k
  SuitableAlign = 64;
67
96.0k
  DefaultAlignForAttributeAligned = 128;
68
96.0k
  MinGlobalAlign = 0;
69
  // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
70
  // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
71
  // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
72
  // This alignment guarantee also applies to Windows and Android. On Darwin,
73
  // the alignment is 16 bytes on both 64-bit and 32-bit systems.
74
96.0k
  if (T.isGNUEnvironment() || 
T.isWindowsMSVCEnvironment()89.2k
||
T.isAndroid()80.5k
)
75
18.4E
    
NewAlign = 15.5k
Triple.isArch64Bit()15.5k
?
12814.1k
:
Triple.isArch32Bit()1.44k
?
641.44k
: 0;
76
80.4k
  else if (T.isOSDarwin())
77
58.6k
    NewAlign = 128;
78
21.7k
  else
79
21.7k
    NewAlign = 0; // Infer from basic type alignment.
80
96.0k
  HalfWidth = 16;
81
96.0k
  HalfAlign = 16;
82
96.0k
  FloatWidth = 32;
83
96.0k
  FloatAlign = 32;
84
96.0k
  DoubleWidth = 64;
85
96.0k
  DoubleAlign = 64;
86
96.0k
  LongDoubleWidth = 64;
87
96.0k
  LongDoubleAlign = 64;
88
96.0k
  Float128Align = 128;
89
96.0k
  Ibm128Align = 128;
90
96.0k
  LargeArrayMinWidth = 0;
91
96.0k
  LargeArrayAlign = 0;
92
96.0k
  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
93
96.0k
  MaxVectorAlign = 0;
94
96.0k
  MaxTLSAlign = 0;
95
96.0k
  SimdDefaultAlign = 0;
96
96.0k
  SizeType = UnsignedLong;
97
96.0k
  PtrDiffType = SignedLong;
98
96.0k
  IntMaxType = SignedLongLong;
99
96.0k
  IntPtrType = SignedLong;
100
96.0k
  WCharType = SignedInt;
101
96.0k
  WIntType = SignedInt;
102
96.0k
  Char16Type = UnsignedShort;
103
96.0k
  Char32Type = UnsignedInt;
104
96.0k
  Int64Type = SignedLongLong;
105
96.0k
  Int16Type = SignedShort;
106
96.0k
  SigAtomicType = SignedInt;
107
96.0k
  ProcessIDType = SignedInt;
108
96.0k
  UseSignedCharForObjCBool = true;
109
96.0k
  UseBitFieldTypeAlignment = true;
110
96.0k
  UseZeroLengthBitfieldAlignment = false;
111
96.0k
  UseLeadingZeroLengthBitfield = true;
112
96.0k
  UseExplicitBitFieldAlignment = true;
113
96.0k
  ZeroLengthBitfieldBoundary = 0;
114
96.0k
  MaxAlignedAttribute = 0;
115
96.0k
  HalfFormat = &llvm::APFloat::IEEEhalf();
116
96.0k
  FloatFormat = &llvm::APFloat::IEEEsingle();
117
96.0k
  DoubleFormat = &llvm::APFloat::IEEEdouble();
118
96.0k
  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
119
96.0k
  Float128Format = &llvm::APFloat::IEEEquad();
120
96.0k
  Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
121
96.0k
  MCountName = "mcount";
122
96.0k
  UserLabelPrefix = "_";
123
96.0k
  RegParmMax = 0;
124
96.0k
  SSERegParmMax = 0;
125
96.0k
  HasAlignMac68kSupport = false;
126
96.0k
  HasBuiltinMSVaList = false;
127
96.0k
  IsRenderScriptTarget = false;
128
96.0k
  HasAArch64SVETypes = false;
129
96.0k
  HasRISCVVTypes = false;
130
96.0k
  AllowAMDGPUUnsafeFPAtomics = false;
131
96.0k
  ARMCDECoprocMask = 0;
132
133
  // Default to no types using fpret.
134
96.0k
  RealTypeUsesObjCFPRet = 0;
135
136
  // Default to not using fp2ret for __Complex long double
137
96.0k
  ComplexLongDoubleUsesFP2Ret = false;
138
139
  // Set the C++ ABI based on the triple.
140
96.0k
  TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
141
96.0k
                    ? 
TargetCXXABI::Microsoft8.74k
142
96.0k
                    : 
TargetCXXABI::GenericItanium87.3k
);
143
144
  // Default to an empty address space map.
145
96.0k
  AddrSpaceMap = &DefaultAddrSpaceMap;
146
96.0k
  UseAddrSpaceMapMangling = false;
147
148
  // Default to an unknown platform name.
149
96.0k
  PlatformName = "unknown";
150
96.0k
  PlatformMinVersion = VersionTuple();
151
152
96.0k
  MaxOpenCLWorkGroupSize = 1024;
153
96.0k
  ProgramAddrSpace = 0;
154
96.0k
}
155
156
// Out of line virtual dtor for TargetInfo.
157
90.2k
TargetInfo::~TargetInfo() {}
158
159
155k
void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
160
155k
  DataLayoutString = DL.str();
161
155k
  UserLabelPrefix = ULP;
162
155k
}
163
164
bool
165
0
TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const {
166
0
  Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch";
167
0
  return false;
168
0
}
169
170
bool
171
0
TargetInfo::checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const {
172
0
  Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=return";
173
0
  return false;
174
0
}
175
176
/// getTypeName - Return the user string for the specified integer type enum.
177
/// For example, SignedShort -> "short".
178
2.98M
const char *TargetInfo::getTypeName(IntType T) {
179
2.98M
  switch (T) {
180
0
  default: llvm_unreachable("not an integer!");
181
263k
  case SignedChar:       return "signed char";
182
263k
  case UnsignedChar:     return "unsigned char";
183
263k
  case SignedShort:      return "short";
184
369k
  case UnsignedShort:    return "unsigned short";
185
441k
  case SignedInt:        return "int";
186
394k
  case UnsignedInt:      return "unsigned int";
187
226k
  case SignedLong:       return "long int";
188
227k
  case UnsignedLong:     return "long unsigned int";
189
267k
  case SignedLongLong:   return "long long int";
190
267k
  case UnsignedLongLong: return "long long unsigned int";
191
2.98M
  }
192
2.98M
}
193
194
/// getTypeConstantSuffix - Return the constant suffix for the specified
195
/// integer type enum. For example, SignedLong -> "L".
196
4.28M
const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
197
4.28M
  switch (T) {
198
0
  default: llvm_unreachable("not an integer!");
199
438k
  case SignedChar:
200
877k
  case SignedShort:
201
1.58M
  case SignedInt:        return "";
202
389k
  case SignedLong:       return "L";
203
457k
  case SignedLongLong:   return "LL";
204
351k
  case UnsignedChar:
205
351k
    if (getCharWidth() < getIntWidth())
206
351k
      return "";
207
351k
    
LLVM_FALLTHROUGH0
;0
208
369k
  case UnsignedShort:
209
369k
    if (getShortWidth() < getIntWidth())
210
369k
      return "";
211
369k
    
LLVM_FALLTHROUGH68
;68
212
407k
  case UnsignedInt:      return "U";
213
349k
  case UnsignedLong:     return "UL";
214
376k
  case UnsignedLongLong: return "ULL";
215
4.28M
  }
216
4.28M
}
217
218
/// getTypeFormatModifier - Return the printf format modifier for the
219
/// specified integer type enum. For example, SignedLong -> "l".
220
221
2.63M
const char *TargetInfo::getTypeFormatModifier(IntType T) {
222
2.63M
  switch (T) {
223
0
  default: llvm_unreachable("not an integer!");
224
263k
  case SignedChar:
225
526k
  case UnsignedChar:     return "hh";
226
263k
  case SignedShort:
227
526k
  case UnsignedShort:    return "h";
228
295k
  case SignedInt:
229
591k
  case UnsignedInt:      return "";
230
226k
  case SignedLong:
231
453k
  case UnsignedLong:     return "l";
232
267k
  case SignedLongLong:
233
535k
  case UnsignedLongLong: return "ll";
234
2.63M
  }
235
2.63M
}
236
237
/// getTypeWidth - Return the width (in bits) of the specified integer type
238
/// enum. For example, SignedInt -> getIntWidth().
239
15.9M
unsigned TargetInfo::getTypeWidth(IntType T) const {
240
15.9M
  switch (T) {
241
0
  default: llvm_unreachable("not an integer!");
242
702k
  case SignedChar:
243
1.14M
  case UnsignedChar:     return getCharWidth();
244
702k
  case SignedShort:
245
1.33M
  case UnsignedShort:    return getShortWidth();
246
2.16M
  case SignedInt:
247
3.07M
  case UnsignedInt:      return getIntWidth();
248
6.87M
  case SignedLong:
249
8.90M
  case UnsignedLong:     return getLongWidth();
250
1.05M
  case SignedLongLong:
251
1.49M
  case UnsignedLongLong: return getLongLongWidth();
252
15.9M
  };
253
0
}
254
255
TargetInfo::IntType TargetInfo::getIntTypeByWidth(
256
864k
    unsigned BitWidth, bool IsSigned) const {
257
864k
  if (getCharWidth() == BitWidth)
258
52.0k
    return IsSigned ? 
SignedChar26.5k
:
UnsignedChar25.4k
;
259
812k
  if (getShortWidth() == BitWidth)
260
61.0k
    return IsSigned ? 
SignedShort32.6k
:
UnsignedShort28.3k
;
261
751k
  if (getIntWidth() == BitWidth)
262
472k
    return IsSigned ? 
SignedInt430k
:
UnsignedInt42.3k
;
263
278k
  if (getLongWidth() == BitWidth)
264
269k
    return IsSigned ? 
SignedLong183k
:
UnsignedLong86.2k
;
265
8.79k
  if (getLongLongWidth() == BitWidth)
266
8.77k
    return IsSigned ? 
SignedLongLong8.68k
:
UnsignedLongLong83
;
267
25
  return NoInt;
268
8.79k
}
269
270
TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
271
1.20M
                                                       bool IsSigned) const {
272
1.20M
  if (getCharWidth() >= BitWidth)
273
351k
    return IsSigned ? 
SignedChar175k
:
UnsignedChar175k
;
274
849k
  if (getShortWidth() >= BitWidth)
275
350k
    return IsSigned ? 
SignedShort175k
:
UnsignedShort175k
;
276
498k
  if (getIntWidth() >= BitWidth)
277
350k
    return IsSigned ? 
SignedInt175k
:
UnsignedInt175k
;
278
147k
  if (getLongWidth() >= BitWidth)
279
50.8k
    return IsSigned ? 
SignedLong25.4k
:
UnsignedLong25.4k
;
280
96.7k
  if (getLongLongWidth() >= BitWidth)
281
96.7k
    return IsSigned ? 
SignedLongLong48.3k
:
UnsignedLongLong48.3k
;
282
27
  return NoInt;
283
96.7k
}
284
285
FloatModeKind TargetInfo::getRealTypeByWidth(unsigned BitWidth,
286
78
                                             FloatModeKind ExplicitType) const {
287
78
  if (getFloatWidth() == BitWidth)
288
26
    return FloatModeKind::Float;
289
52
  if (getDoubleWidth() == BitWidth)
290
31
    return FloatModeKind::Double;
291
292
21
  switch (BitWidth) {
293
5
  case 96:
294
5
    if (&getLongDoubleFormat() == &llvm::APFloat::x87DoubleExtended())
295
5
      return FloatModeKind::LongDouble;
296
0
    break;
297
14
  case 128:
298
    // The caller explicitly asked for an IEEE compliant type but we still
299
    // have to check if the target supports it.
300
14
    if (ExplicitType == FloatModeKind::Float128)
301
3
      return hasFloat128Type() ? FloatModeKind::Float128
302
3
                               : 
FloatModeKind::NoFloat0
;
303
11
    if (ExplicitType == FloatModeKind::Ibm128)
304
6
      return hasIbm128Type() ? FloatModeKind::Ibm128
305
6
                             : 
FloatModeKind::NoFloat0
;
306
5
    if (&getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble() ||
307
5
        
&getLongDoubleFormat() == &llvm::APFloat::IEEEquad()3
)
308
2
      return FloatModeKind::LongDouble;
309
3
    if (hasFloat128Type())
310
3
      return FloatModeKind::Float128;
311
0
    break;
312
21
  }
313
314
2
  return FloatModeKind::NoFloat;
315
21
}
316
317
/// getTypeAlign - Return the alignment (in bits) of the specified integer type
318
/// enum. For example, SignedInt -> getIntAlign().
319
374k
unsigned TargetInfo::getTypeAlign(IntType T) const {
320
374k
  switch (T) {
321
0
  default: llvm_unreachable("not an integer!");
322
0
  case SignedChar:
323
28
  case UnsignedChar:     return getCharAlign();
324
0
  case SignedShort:
325
125k
  case UnsignedShort:    return getShortAlign();
326
126k
  case SignedInt:
327
248k
  case UnsignedInt:      return getIntAlign();
328
390
  case SignedLong:
329
412
  case UnsignedLong:     return getLongAlign();
330
55
  case SignedLongLong:
331
55
  case UnsignedLongLong: return getLongLongAlign();
332
374k
  };
333
0
}
334
335
/// isTypeSigned - Return whether an integer types is signed. Returns true if
336
/// the type is signed; false otherwise.
337
7.64M
bool TargetInfo::isTypeSigned(IntType T) {
338
7.64M
  switch (T) {
339
0
  default: llvm_unreachable("not an integer!");
340
789k
  case SignedChar:
341
1.57M
  case SignedShort:
342
2.89M
  case SignedInt:
343
3.56M
  case SignedLong:
344
4.23M
  case SignedLongLong:
345
4.23M
    return true;
346
702k
  case UnsignedChar:
347
1.44M
  case UnsignedShort:
348
2.24M
  case UnsignedInt:
349
2.82M
  case UnsignedLong:
350
3.40M
  case UnsignedLongLong:
351
3.40M
    return false;
352
7.64M
  };
353
0
}
354
355
/// adjust - Set forced language options.
356
/// Apply changes to the target information with respect to certain
357
/// language options which change the target configuration and adjust
358
/// the language based on the target options where applicable.
359
175k
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
360
175k
  if (Opts.NoBitFieldTypeAlign)
361
2
    UseBitFieldTypeAlignment = false;
362
363
175k
  switch (Opts.WCharSize) {
364
0
  default: llvm_unreachable("invalid wchar_t width");
365
175k
  case 0: break;
366
2
  case 1: WCharType = Opts.WCharIsSigned ? 
SignedChar0
: UnsignedChar; break;
367
56
  case 2: WCharType = Opts.WCharIsSigned ? 
SignedShort0
: UnsignedShort; break;
368
18
  case 4: WCharType = Opts.WCharIsSigned ? 
SignedInt14
:
UnsignedInt4
; break;
369
175k
  }
370
371
175k
  if (Opts.AlignDouble) {
372
10
    DoubleAlign = LongLongAlign = 64;
373
10
    LongDoubleAlign = 64;
374
10
  }
375
376
175k
  if (Opts.OpenCL) {
377
    // OpenCL C requires specific widths for types, irrespective of
378
    // what these normally are for the target.
379
    // We also define long long and long double here, although the
380
    // OpenCL standard only mentions these as "reserved".
381
1.28k
    IntWidth = IntAlign = 32;
382
1.28k
    LongWidth = LongAlign = 64;
383
1.28k
    LongLongWidth = LongLongAlign = 128;
384
1.28k
    HalfWidth = HalfAlign = 16;
385
1.28k
    FloatWidth = FloatAlign = 32;
386
387
    // Embedded 32-bit targets (OpenCL EP) might have double C type
388
    // defined as float. Let's not override this as it might lead
389
    // to generating illegal code that uses 64bit doubles.
390
1.28k
    if (DoubleWidth != FloatWidth) {
391
1.28k
      DoubleWidth = DoubleAlign = 64;
392
1.28k
      DoubleFormat = &llvm::APFloat::IEEEdouble();
393
1.28k
    }
394
1.28k
    LongDoubleWidth = LongDoubleAlign = 128;
395
396
1.28k
    unsigned MaxPointerWidth = getMaxPointerWidth();
397
1.28k
    assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
398
0
    bool Is32BitArch = MaxPointerWidth == 32;
399
1.28k
    SizeType = Is32BitArch ? 
UnsignedInt506
:
UnsignedLong778
;
400
1.28k
    PtrDiffType = Is32BitArch ? 
SignedInt506
:
SignedLong778
;
401
1.28k
    IntPtrType = Is32BitArch ? 
SignedInt506
:
SignedLong778
;
402
403
1.28k
    IntMaxType = SignedLongLong;
404
1.28k
    Int64Type = SignedLong;
405
406
1.28k
    HalfFormat = &llvm::APFloat::IEEEhalf();
407
1.28k
    FloatFormat = &llvm::APFloat::IEEEsingle();
408
1.28k
    LongDoubleFormat = &llvm::APFloat::IEEEquad();
409
410
    // OpenCL C v3.0 s6.7.5 - The generic address space requires support for
411
    // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space
412
    // feature
413
    // OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0
414
    // or later and __opencl_c_pipes feature
415
    // FIXME: These language options are also defined in setLangDefaults()
416
    // for OpenCL C 2.0 but with no access to target capabilities. Target
417
    // should be immutable once created and thus these language options need
418
    // to be defined only once.
419
1.28k
    if (Opts.getOpenCLCompatibleVersion() == 300) {
420
222
      const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
421
222
      Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
422
222
          OpenCLFeaturesMap, "__opencl_c_generic_address_space");
423
222
      Opts.OpenCLPipes =
424
222
          hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
425
222
    }
426
1.28k
  }
427
428
175k
  if (Opts.DoubleSize) {
429
4
    if (Opts.DoubleSize == 32) {
430
2
      DoubleWidth = 32;
431
2
      LongDoubleWidth = 32;
432
2
      DoubleFormat = &llvm::APFloat::IEEEsingle();
433
2
      LongDoubleFormat = &llvm::APFloat::IEEEsingle();
434
2
    } else if (Opts.DoubleSize == 64) {
435
2
      DoubleWidth = 64;
436
2
      LongDoubleWidth = 64;
437
2
      DoubleFormat = &llvm::APFloat::IEEEdouble();
438
2
      LongDoubleFormat = &llvm::APFloat::IEEEdouble();
439
2
    }
440
4
  }
441
442
175k
  if (Opts.LongDoubleSize) {
443
32
    if (Opts.LongDoubleSize == DoubleWidth) {
444
18
      LongDoubleWidth = DoubleWidth;
445
18
      LongDoubleAlign = DoubleAlign;
446
18
      LongDoubleFormat = DoubleFormat;
447
18
    } else 
if (14
Opts.LongDoubleSize == 12814
) {
448
14
      LongDoubleWidth = LongDoubleAlign = 128;
449
14
      LongDoubleFormat = &llvm::APFloat::IEEEquad();
450
14
    }
451
32
  }
452
453
175k
  if (Opts.NewAlignOverride)
454
4
    NewAlign = Opts.NewAlignOverride * getCharWidth();
455
456
  // Each unsigned fixed point type has the same number of fractional bits as
457
  // its corresponding signed type.
458
175k
  PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
459
175k
  CheckFixedPointBits();
460
461
175k
  if (Opts.ProtectParens && 
!checkArithmeticFenceSupported()11
) {
462
1
    Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens";
463
1
    Opts.ProtectParens = false;
464
1
  }
465
175k
}
466
467
bool TargetInfo::initFeatureMap(
468
    llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
469
147k
    const std::vector<std::string> &FeatureVec) const {
470
153k
  for (const auto &F : FeatureVec) {
471
153k
    StringRef Name = F;
472
    // Apply the feature via the target.
473
153k
    bool Enabled = Name[0] == '+';
474
153k
    setFeatureEnabled(Features, Name.substr(1), Enabled);
475
153k
  }
476
147k
  return true;
477
147k
}
478
479
TargetInfo::CallingConvKind
480
1.44M
TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
481
1.44M
  if (getCXXABI() != TargetCXXABI::Microsoft &&
482
1.44M
      
(1.44M
ClangABICompat41.44M
||
getTriple().getOS() == llvm::Triple::PS41.44M
))
483
463
    return CCK_ClangABI4OrPS4;
484
1.44M
  return CCK_Default;
485
1.44M
}
486
487
200
LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
488
200
  switch (TK) {
489
58
  case OCLTK_Image:
490
104
  case OCLTK_Pipe:
491
104
    return LangAS::opencl_global;
492
493
21
  case OCLTK_Sampler:
494
21
    return LangAS::opencl_constant;
495
496
75
  default:
497
75
    return LangAS::Default;
498
200
  }
499
200
}
500
501
//===----------------------------------------------------------------------===//
502
503
504
8.38k
static StringRef removeGCCRegisterPrefix(StringRef Name) {
505
8.38k
  if (Name[0] == '%' || 
Name[0] == '#'7.76k
)
506
640
    Name = Name.substr(1);
507
508
8.38k
  return Name;
509
8.38k
}
510
511
/// isValidClobber - Returns whether the passed in string is
512
/// a valid clobber in an inline asm statement. This is used by
513
/// Sema.
514
3.25k
bool TargetInfo::isValidClobber(StringRef Name) const {
515
3.25k
  return (isValidGCCRegisterName(Name) || 
Name == "memory"2.04k
||
Name == "cc"1.10k
||
516
3.25k
          
Name == "unwind"5
);
517
3.25k
}
518
519
/// isValidGCCRegisterName - Returns whether the passed in string
520
/// is a valid register name according to GCC. This is used by Sema for
521
/// inline asm statements.
522
5.95k
bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
523
5.95k
  if (Name.empty())
524
0
    return false;
525
526
  // Get rid of any register prefix.
527
5.95k
  Name = removeGCCRegisterPrefix(Name);
528
5.95k
  if (Name.empty())
529
1
    return false;
530
531
5.95k
  ArrayRef<const char *> Names = getGCCRegNames();
532
533
  // If we have a number it maps to an entry in the register name array.
534
5.95k
  if (isDigit(Name[0])) {
535
26
    unsigned n;
536
26
    if (!Name.getAsInteger(0, n))
537
26
      return n < Names.size();
538
26
  }
539
540
  // Check register names.
541
5.92k
  if (llvm::is_contained(Names, Name))
542
3.03k
    return true;
543
544
  // Check any additional names that we have.
545
2.89k
  for (const AddlRegName &ARN : getGCCAddlRegNames())
546
133k
    
for (const char *AN : ARN.Names)33.2k
{
547
133k
      if (!AN)
548
32.8k
        break;
549
      // Make sure the register that the additional name is for is within
550
      // the bounds of the register names from above.
551
100k
      if (AN == Name && 
ARN.RegNum < Names.size()382
)
552
382
        return true;
553
100k
    }
554
555
  // Now check aliases.
556
2.51k
  for (const GCCRegAlias &GRA : getGCCRegAliases())
557
25.2k
    
for (const char *A : GRA.Aliases)12.7k
{
558
25.2k
      if (!A)
559
12.3k
        break;
560
12.9k
      if (A == Name)
561
461
        return true;
562
12.9k
    }
563
564
2.05k
  return false;
565
2.51k
}
566
567
StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
568
2.43k
                                                   bool ReturnCanonical) const {
569
2.43k
  assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
570
571
  // Get rid of any register prefix.
572
0
  Name = removeGCCRegisterPrefix(Name);
573
574
2.43k
  ArrayRef<const char *> Names = getGCCRegNames();
575
576
  // First, check if we have a number.
577
2.43k
  if (isDigit(Name[0])) {
578
12
    unsigned n;
579
12
    if (!Name.getAsInteger(0, n)) {
580
12
      assert(n < Names.size() && "Out of bounds register number!");
581
0
      return Names[n];
582
12
    }
583
12
  }
584
585
  // Check any additional names that we have.
586
2.42k
  for (const AddlRegName &ARN : getGCCAddlRegNames())
587
21.5k
    
for (const char *AN : ARN.Names)5.58k
{
588
21.5k
      if (!AN)
589
5.32k
        break;
590
      // Make sure the register that the additional name is for is within
591
      // the bounds of the register names from above.
592
16.1k
      if (AN == Name && 
ARN.RegNum < Names.size()254
)
593
254
        return ReturnCanonical ? 
Names[ARN.RegNum]59
:
Name195
;
594
16.1k
    }
595
596
  // Now check aliases.
597
2.17k
  for (const GCCRegAlias &RA : getGCCRegAliases())
598
104k
    
for (const char *A : RA.Aliases)51.0k
{
599
104k
      if (!A)
600
50.8k
        break;
601
53.2k
      if (A == Name)
602
246
        return RA.Register;
603
53.2k
    }
604
605
1.92k
  return Name;
606
2.17k
}
607
608
8.39k
bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
609
8.39k
  const char *Name = Info.getConstraintStr().c_str();
610
  // An output constraint must start with '=' or '+'
611
8.39k
  if (*Name != '=' && 
*Name != '+'845
)
612
65
    return false;
613
614
8.32k
  if (*Name == '+')
615
780
    Info.setIsReadWrite();
616
617
8.32k
  Name++;
618
18.0k
  while (*Name) {
619
9.70k
    switch (*Name) {
620
5.72k
    default:
621
5.72k
      if (!validateAsmConstraint(Name, Info)) {
622
        // FIXME: We temporarily return false
623
        // so we can add more constraints as we hit it.
624
        // Eventually, an unknown constraint should just be treated as 'g'.
625
13
        return false;
626
13
      }
627
5.71k
      break;
628
5.71k
    case '&': // early clobber.
629
36
      Info.setEarlyClobber();
630
36
      break;
631
7
    case '%': // commutative.
632
      // FIXME: Check that there is a another register after this one.
633
7
      break;
634
2.71k
    case 'r': // general register.
635
2.71k
      Info.setAllowsRegister();
636
2.71k
      break;
637
518
    case 'm': // memory operand.
638
518
    case 'o': // offsetable memory operand.
639
518
    case 'V': // non-offsetable memory operand.
640
518
    case '<': // autodecrement memory operand.
641
518
    case '>': // autoincrement memory operand.
642
518
      Info.setAllowsMemory();
643
518
      break;
644
25
    case 'g': // general register, memory operand or immediate integer.
645
25
    case 'X': // any operand.
646
25
      Info.setAllowsRegister();
647
25
      Info.setAllowsMemory();
648
25
      break;
649
648
    case ',': // multiple alternative constraint.  Pass it.
650
      // Handle additional optional '=' or '+' modifiers.
651
648
      if (Name[1] == '=' || 
Name[1] == '+'643
)
652
5
        Name++;
653
648
      break;
654
2
    case '#': // Ignore as constraint.
655
3
      while (Name[1] && 
Name[1] != ','1
)
656
1
        Name++;
657
2
      break;
658
1
    case '?': // Disparage slightly code.
659
2
    case '!': // Disparage severely.
660
3
    case '*': // Ignore for choosing register preferences.
661
12
    case 'i': // Ignore i,n,E,F as output constraints (match from the other
662
              // chars)
663
21
    case 'n':
664
30
    case 'E':
665
39
    case 'F':
666
39
      break;  // Pass them.
667
9.70k
    }
668
669
9.69k
    Name++;
670
9.69k
  }
671
672
  // Early clobber with a read-write constraint which doesn't permit registers
673
  // is invalid.
674
8.31k
  if (Info.earlyClobber() && 
Info.isReadWrite()33
&&
!Info.allowsRegister()7
)
675
1
    return false;
676
677
  // If a constraint allows neither memory nor register operands it contains
678
  // only modifiers. Reject it.
679
8.31k
  return Info.allowsMemory() || 
Info.allowsRegister()7.79k
;
680
8.31k
}
681
682
bool TargetInfo::resolveSymbolicName(const char *&Name,
683
                                     ArrayRef<ConstraintInfo> OutputConstraints,
684
52
                                     unsigned &Index) const {
685
52
  assert(*Name == '[' && "Symbolic name did not start with '['");
686
0
  Name++;
687
52
  const char *Start = Name;
688
247
  while (*Name && 
*Name != ']'245
)
689
195
    Name++;
690
691
52
  if (!*Name) {
692
    // Missing ']'
693
2
    return false;
694
2
  }
695
696
50
  std::string SymbolicName(Start, Name - Start);
697
698
183
  for (Index = 0; Index != OutputConstraints.size(); 
++Index133
)
699
182
    if (SymbolicName == OutputConstraints[Index].getName())
700
49
      return true;
701
702
1
  return false;
703
50
}
704
705
bool TargetInfo::validateInputConstraint(
706
                              MutableArrayRef<ConstraintInfo> OutputConstraints,
707
10.2k
                              ConstraintInfo &Info) const {
708
10.2k
  const char *Name = Info.ConstraintStr.c_str();
709
710
10.2k
  if (!*Name)
711
2
    return false;
712
713
22.1k
  
while (10.2k
*Name) {
714
11.8k
    switch (*Name) {
715
5.73k
    default:
716
      // Check if we have a matching constraint
717
5.73k
      if (*Name >= '0' && *Name <= '9') {
718
249
        const char *DigitStart = Name;
719
250
        while (Name[1] >= '0' && 
Name[1] <= '9'3
)
720
1
          Name++;
721
249
        const char *DigitEnd = Name;
722
249
        unsigned i;
723
249
        if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
724
249
                .getAsInteger(10, i))
725
0
          return false;
726
727
        // Check if matching constraint is out of bounds.
728
249
        if (i >= OutputConstraints.size()) 
return false1
;
729
730
        // A number must refer to an output only operand.
731
248
        if (OutputConstraints[i].isReadWrite())
732
1
          return false;
733
734
        // If the constraint is already tied, it must be tied to the
735
        // same operand referenced to by the number.
736
247
        if (Info.hasTiedOperand() && 
Info.getTiedOperand() != i1
)
737
1
          return false;
738
739
        // The constraint should have the same info as the respective
740
        // output constraint.
741
246
        Info.setTiedOperand(i, OutputConstraints[i]);
742
5.48k
      } else if (!validateAsmConstraint(Name, Info)) {
743
        // FIXME: This error return is in place temporarily so we can
744
        // add more constraints as we hit it.  Eventually, an unknown
745
        // constraint should just be treated as 'g'.
746
10
        return false;
747
10
      }
748
5.72k
      break;
749
5.72k
    case '[': {
750
46
      unsigned Index = 0;
751
46
      if (!resolveSymbolicName(Name, OutputConstraints, Index))
752
3
        return false;
753
754
      // If the constraint is already tied, it must be tied to the
755
      // same operand referenced to by the number.
756
43
      if (Info.hasTiedOperand() && 
Info.getTiedOperand() != Index1
)
757
1
        return false;
758
759
      // A number must refer to an output only operand.
760
42
      if (OutputConstraints[Index].isReadWrite())
761
1
        return false;
762
763
41
      Info.setTiedOperand(Index, OutputConstraints[Index]);
764
41
      break;
765
42
    }
766
0
    case '%': // commutative
767
      // FIXME: Fail if % is used with the last operand.
768
0
      break;
769
373
    case 'i': // immediate integer.
770
373
      break;
771
81
    case 'n': // immediate integer with a known value.
772
81
      Info.setRequiresImmediate();
773
81
      break;
774
62
    case 'I':  // Various constant constraints with target-specific meanings.
775
118
    case 'J':
776
152
    case 'K':
777
202
    case 'L':
778
222
    case 'M':
779
255
    case 'N':
780
265
    case 'O':
781
265
    case 'P':
782
265
      if (!validateAsmConstraint(Name, Info))
783
16
        return false;
784
249
      break;
785
3.38k
    case 'r': // general register.
786
3.38k
      Info.setAllowsRegister();
787
3.38k
      break;
788
435
    case 'm': // memory operand.
789
435
    case 'o': // offsettable memory operand.
790
435
    case 'V': // non-offsettable memory operand.
791
523
    case '<': // autodecrement memory operand.
792
611
    case '>': // autoincrement memory operand.
793
611
      Info.setAllowsMemory();
794
611
      break;
795
268
    case 'g': // general register, memory operand or immediate integer.
796
533
    case 'X': // any operand.
797
533
      Info.setAllowsRegister();
798
533
      Info.setAllowsMemory();
799
533
      break;
800
44
    case 'E': // immediate floating point.
801
88
    case 'F': // immediate floating point.
802
137
    case 'p': // address operand.
803
137
      break;
804
683
    case ',': // multiple alternative constraint.  Ignore comma.
805
683
      break;
806
3
    case '#': // Ignore as constraint.
807
7
      while (Name[1] && 
Name[1] != ','6
)
808
4
        Name++;
809
3
      break;
810
0
    case '?': // Disparage slightly code.
811
0
    case '!': // Disparage severely.
812
2
    case '*': // Ignore for choosing register preferences.
813
2
      break;  // Pass them.
814
11.8k
    }
815
816
11.8k
    Name++;
817
11.8k
  }
818
819
10.2k
  return true;
820
10.2k
}
821
822
271k
void TargetInfo::CheckFixedPointBits() const {
823
  // Check that the number of fractional and integral bits (and maybe sign) can
824
  // fit into the bits given for a fixed point type.
825
271k
  assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth);
826
0
  assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
827
0
  assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth);
828
0
  assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
829
271k
         ShortAccumWidth);
830
0
  assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth);
831
0
  assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
832
271k
         LongAccumWidth);
833
834
0
  assert(getShortFractScale() + 1 <= ShortFractWidth);
835
0
  assert(getFractScale() + 1 <= FractWidth);
836
0
  assert(getLongFractScale() + 1 <= LongFractWidth);
837
0
  assert(getUnsignedShortFractScale() <= ShortFractWidth);
838
0
  assert(getUnsignedFractScale() <= FractWidth);
839
0
  assert(getUnsignedLongFractScale() <= LongFractWidth);
840
841
  // Each unsigned fract type has either the same number of fractional bits
842
  // as, or one more fractional bit than, its corresponding signed fract type.
843
0
  assert(getShortFractScale() == getUnsignedShortFractScale() ||
844
271k
         getShortFractScale() == getUnsignedShortFractScale() - 1);
845
0
  assert(getFractScale() == getUnsignedFractScale() ||
846
271k
         getFractScale() == getUnsignedFractScale() - 1);
847
0
  assert(getLongFractScale() == getUnsignedLongFractScale() ||
848
271k
         getLongFractScale() == getUnsignedLongFractScale() - 1);
849
850
  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
851
  // fractional bits is nondecreasing for each of the following sets of
852
  // fixed-point types:
853
  // - signed fract types
854
  // - unsigned fract types
855
  // - signed accum types
856
  // - unsigned accum types.
857
0
  assert(getLongFractScale() >= getFractScale() &&
858
271k
         getFractScale() >= getShortFractScale());
859
0
  assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
860
271k
         getUnsignedFractScale() >= getUnsignedShortFractScale());
861
0
  assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale);
862
0
  assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
863
271k
         getUnsignedAccumScale() >= getUnsignedShortAccumScale());
864
865
  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
866
  // integral bits is nondecreasing for each of the following sets of
867
  // fixed-point types:
868
  // - signed accum types
869
  // - unsigned accum types
870
0
  assert(getLongAccumIBits() >= getAccumIBits() &&
871
271k
         getAccumIBits() >= getShortAccumIBits());
872
0
  assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
873
271k
         getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
874
875
  // Each signed accum type has at least as many integral bits as its
876
  // corresponding unsigned accum type.
877
0
  assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
878
0
  assert(getAccumIBits() >= getUnsignedAccumIBits());
879
0
  assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
880
271k
}
881
882
17
void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
883
17
  auto *Target = static_cast<TransferrableTargetInfo*>(this);
884
17
  auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
885
17
  *Target = *Src;
886
17
}