Coverage Report

Created: 2022-05-17 06:19

/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
97.5k
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
97.5k
  BigEndian = !T.isLittleEndian();
32
97.5k
  TLSSupported = true;
33
97.5k
  VLASupported = true;
34
97.5k
  NoAsmVariants = false;
35
97.5k
  HasLegalHalfType = false;
36
97.5k
  HasFloat128 = false;
37
97.5k
  HasIbm128 = false;
38
97.5k
  HasFloat16 = false;
39
97.5k
  HasBFloat16 = false;
40
97.5k
  HasLongDouble = true;
41
97.5k
  HasFPReturn = true;
42
97.5k
  HasStrictFP = false;
43
97.5k
  PointerWidth = PointerAlign = 32;
44
97.5k
  BoolWidth = BoolAlign = 8;
45
97.5k
  IntWidth = IntAlign = 32;
46
97.5k
  LongWidth = LongAlign = 32;
47
97.5k
  LongLongWidth = LongLongAlign = 64;
48
49
  // Fixed point default bit widths
50
97.5k
  ShortAccumWidth = ShortAccumAlign = 16;
51
97.5k
  AccumWidth = AccumAlign = 32;
52
97.5k
  LongAccumWidth = LongAccumAlign = 64;
53
97.5k
  ShortFractWidth = ShortFractAlign = 8;
54
97.5k
  FractWidth = FractAlign = 16;
55
97.5k
  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
97.5k
  PaddingOnUnsignedFixedPoint = false;
62
97.5k
  ShortAccumScale = 7;
63
97.5k
  AccumScale = 15;
64
97.5k
  LongAccumScale = 31;
65
66
97.5k
  SuitableAlign = 64;
67
97.5k
  DefaultAlignForAttributeAligned = 128;
68
97.5k
  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
  // and OpenBSD, the alignment is 16 bytes on both 64-bit and 32-bit systems.
74
97.5k
  if (T.isGNUEnvironment() || 
T.isWindowsMSVCEnvironment()91.0k
||
T.isAndroid()82.2k
)
75
18.4E
    
NewAlign = 15.2k
Triple.isArch64Bit()15.2k
?
12813.8k
:
Triple.isArch32Bit()1.47k
?
641.47k
: 0;
76
82.2k
  else if (T.isOSDarwin() || 
T.isOSOpenBSD()22.1k
)
77
60.1k
    NewAlign = 128;
78
22.0k
  else
79
22.0k
    NewAlign = 0; // Infer from basic type alignment.
80
97.5k
  HalfWidth = 16;
81
97.5k
  HalfAlign = 16;
82
97.5k
  FloatWidth = 32;
83
97.5k
  FloatAlign = 32;
84
97.5k
  DoubleWidth = 64;
85
97.5k
  DoubleAlign = 64;
86
97.5k
  LongDoubleWidth = 64;
87
97.5k
  LongDoubleAlign = 64;
88
97.5k
  Float128Align = 128;
89
97.5k
  Ibm128Align = 128;
90
97.5k
  LargeArrayMinWidth = 0;
91
97.5k
  LargeArrayAlign = 0;
92
97.5k
  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
93
97.5k
  MaxVectorAlign = 0;
94
97.5k
  MaxTLSAlign = 0;
95
97.5k
  SimdDefaultAlign = 0;
96
97.5k
  SizeType = UnsignedLong;
97
97.5k
  PtrDiffType = SignedLong;
98
97.5k
  IntMaxType = SignedLongLong;
99
97.5k
  IntPtrType = SignedLong;
100
97.5k
  WCharType = SignedInt;
101
97.5k
  WIntType = SignedInt;
102
97.5k
  Char16Type = UnsignedShort;
103
97.5k
  Char32Type = UnsignedInt;
104
97.5k
  Int64Type = SignedLongLong;
105
97.5k
  Int16Type = SignedShort;
106
97.5k
  SigAtomicType = SignedInt;
107
97.5k
  ProcessIDType = SignedInt;
108
97.5k
  UseSignedCharForObjCBool = true;
109
97.5k
  UseBitFieldTypeAlignment = true;
110
97.5k
  UseZeroLengthBitfieldAlignment = false;
111
97.5k
  UseLeadingZeroLengthBitfield = true;
112
97.5k
  UseExplicitBitFieldAlignment = true;
113
97.5k
  ZeroLengthBitfieldBoundary = 0;
114
97.5k
  MaxAlignedAttribute = 0;
115
97.5k
  HalfFormat = &llvm::APFloat::IEEEhalf();
116
97.5k
  FloatFormat = &llvm::APFloat::IEEEsingle();
117
97.5k
  DoubleFormat = &llvm::APFloat::IEEEdouble();
118
97.5k
  LongDoubleFormat = &llvm::APFloat::IEEEdouble();
119
97.5k
  Float128Format = &llvm::APFloat::IEEEquad();
120
97.5k
  Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
121
97.5k
  MCountName = "mcount";
122
97.5k
  UserLabelPrefix = "_";
123
97.5k
  RegParmMax = 0;
124
97.5k
  SSERegParmMax = 0;
125
97.5k
  HasAlignMac68kSupport = false;
126
97.5k
  HasBuiltinMSVaList = false;
127
97.5k
  IsRenderScriptTarget = false;
128
97.5k
  HasAArch64SVETypes = false;
129
97.5k
  HasRISCVVTypes = false;
130
97.5k
  AllowAMDGPUUnsafeFPAtomics = false;
131
97.5k
  ARMCDECoprocMask = 0;
132
133
  // Default to no types using fpret.
134
97.5k
  RealTypeUsesObjCFPRet = 0;
135
136
  // Default to not using fp2ret for __Complex long double
137
97.5k
  ComplexLongDoubleUsesFP2Ret = false;
138
139
  // Set the C++ ABI based on the triple.
140
97.5k
  TheCXXABI.set(Triple.isKnownWindowsMSVCEnvironment()
141
97.5k
                    ? 
TargetCXXABI::Microsoft8.80k
142
97.5k
                    : 
TargetCXXABI::GenericItanium88.7k
);
143
144
  // Default to an empty address space map.
145
97.5k
  AddrSpaceMap = &DefaultAddrSpaceMap;
146
97.5k
  UseAddrSpaceMapMangling = false;
147
148
  // Default to an unknown platform name.
149
97.5k
  PlatformName = "unknown";
150
97.5k
  PlatformMinVersion = VersionTuple();
151
152
97.5k
  MaxOpenCLWorkGroupSize = 1024;
153
97.5k
  ProgramAddrSpace = 0;
154
97.5k
}
155
156
// Out of line virtual dtor for TargetInfo.
157
91.5k
TargetInfo::~TargetInfo() {}
158
159
158k
void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
160
158k
  DataLayoutString = DL.str();
161
158k
  UserLabelPrefix = ULP;
162
158k
}
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
3.01M
const char *TargetInfo::getTypeName(IntType T) {
179
3.01M
  switch (T) {
180
0
  default: llvm_unreachable("not an integer!");
181
266k
  case SignedChar:       return "signed char";
182
266k
  case UnsignedChar:     return "unsigned char";
183
266k
  case SignedShort:      return "short";
184
373k
  case UnsignedShort:    return "unsigned short";
185
447k
  case SignedInt:        return "int";
186
398k
  case UnsignedInt:      return "unsigned int";
187
228k
  case SignedLong:       return "long int";
188
229k
  case UnsignedLong:     return "long unsigned int";
189
271k
  case SignedLongLong:   return "long long int";
190
271k
  case UnsignedLongLong: return "long long unsigned int";
191
3.01M
  }
192
3.01M
}
193
194
/// getTypeConstantSuffix - Return the constant suffix for the specified
195
/// integer type enum. For example, SignedLong -> "L".
196
4.33M
const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
197
4.33M
  switch (T) {
198
0
  default: llvm_unreachable("not an integer!");
199
443k
  case SignedChar:
200
887k
  case SignedShort:
201
1.60M
  case SignedInt:        return "";
202
392k
  case SignedLong:       return "L";
203
463k
  case SignedLongLong:   return "LL";
204
355k
  case UnsignedChar:
205
355k
    if (getCharWidth() < getIntWidth())
206
355k
      return "";
207
355k
    
LLVM_FALLTHROUGH0
;0
208
373k
  case UnsignedShort:
209
373k
    if (getShortWidth() < getIntWidth())
210
373k
      return "";
211
373k
    
LLVM_FALLTHROUGH76
;76
212
410k
  case UnsignedInt:      return "U";
213
353k
  case UnsignedLong:     return "UL";
214
382k
  case UnsignedLongLong: return "ULL";
215
4.33M
  }
216
4.33M
}
217
218
/// getTypeFormatModifier - Return the printf format modifier for the
219
/// specified integer type enum. For example, SignedLong -> "l".
220
221
2.66M
const char *TargetInfo::getTypeFormatModifier(IntType T) {
222
2.66M
  switch (T) {
223
0
  default: llvm_unreachable("not an integer!");
224
266k
  case SignedChar:
225
532k
  case UnsignedChar:     return "hh";
226
266k
  case SignedShort:
227
532k
  case UnsignedShort:    return "h";
228
299k
  case SignedInt:
229
597k
  case UnsignedInt:      return "";
230
228k
  case SignedLong:
231
457k
  case UnsignedLong:     return "l";
232
271k
  case SignedLongLong:
233
543k
  case UnsignedLongLong: return "ll";
234
2.66M
  }
235
2.66M
}
236
237
/// getTypeWidth - Return the width (in bits) of the specified integer type
238
/// enum. For example, SignedInt -> getIntWidth().
239
16.2M
unsigned TargetInfo::getTypeWidth(IntType T) const {
240
16.2M
  switch (T) {
241
0
  default: llvm_unreachable("not an integer!");
242
710k
  case SignedChar:
243
1.15M
  case UnsignedChar:     return getCharWidth();
244
710k
  case SignedShort:
245
1.34M
  case UnsignedShort:    return getShortWidth();
246
2.20M
  case SignedInt:
247
3.11M
  case UnsignedInt:      return getIntWidth();
248
6.90M
  case SignedLong:
249
8.95M
  case UnsignedLong:     return getLongWidth();
250
1.20M
  case SignedLongLong:
251
1.65M
  case UnsignedLongLong: return getLongLongWidth();
252
16.2M
  };
253
0
}
254
255
TargetInfo::IntType TargetInfo::getIntTypeByWidth(
256
908k
    unsigned BitWidth, bool IsSigned) const {
257
908k
  if (getCharWidth() == BitWidth)
258
53.3k
    return IsSigned ? 
SignedChar27.2k
:
UnsignedChar26.0k
;
259
854k
  if (getShortWidth() == BitWidth)
260
62.2k
    return IsSigned ? 
SignedShort33.3k
:
UnsignedShort28.9k
;
261
792k
  if (getIntWidth() == BitWidth)
262
475k
    return IsSigned ? 
SignedInt429k
:
UnsignedInt45.0k
;
263
317k
  if (getLongWidth() == BitWidth)
264
308k
    return IsSigned ? 
SignedLong184k
:
UnsignedLong123k
;
265
9.35k
  if (getLongLongWidth() == BitWidth)
266
9.31k
    return IsSigned ? 
SignedLongLong8.68k
:
UnsignedLongLong631
;
267
32
  return NoInt;
268
9.35k
}
269
270
TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
271
1.21M
                                                       bool IsSigned) const {
272
1.21M
  if (getCharWidth() >= BitWidth)
273
355k
    return IsSigned ? 
SignedChar177k
:
UnsignedChar177k
;
274
857k
  if (getShortWidth() >= BitWidth)
275
355k
    return IsSigned ? 
SignedShort177k
:
UnsignedShort177k
;
276
502k
  if (getIntWidth() >= BitWidth)
277
354k
    return IsSigned ? 
SignedInt177k
:
UnsignedInt177k
;
278
147k
  if (getLongWidth() >= BitWidth)
279
50.2k
    return IsSigned ? 
SignedLong25.1k
:
UnsignedLong25.1k
;
280
97.4k
  if (getLongLongWidth() >= BitWidth)
281
97.4k
    return IsSigned ? 
SignedLongLong48.7k
:
UnsignedLongLong48.7k
;
282
26
  return NoInt;
283
97.4k
}
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
378k
unsigned TargetInfo::getTypeAlign(IntType T) const {
320
378k
  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
127k
  case UnsignedShort:    return getShortAlign();
326
128k
  case SignedInt:
327
251k
  case UnsignedInt:      return getIntAlign();
328
390
  case SignedLong:
329
419
  case UnsignedLong:     return getLongAlign();
330
55
  case SignedLongLong:
331
55
  case UnsignedLongLong: return getLongLongAlign();
332
378k
  };
333
0
}
334
335
/// isTypeSigned - Return whether an integer types is signed. Returns true if
336
/// the type is signed; false otherwise.
337
7.73M
bool TargetInfo::isTypeSigned(IntType T) {
338
7.73M
  switch (T) {
339
0
  default: llvm_unreachable("not an integer!");
340
799k
  case SignedChar:
341
1.59M
  case SignedShort:
342
2.93M
  case SignedInt:
343
3.60M
  case SignedLong:
344
4.28M
  case SignedLongLong:
345
4.28M
    return true;
346
710k
  case UnsignedChar:
347
1.46M
  case UnsignedShort:
348
2.26M
  case UnsignedInt:
349
2.85M
  case UnsignedLong:
350
3.44M
  case UnsignedLongLong:
351
3.44M
    return false;
352
7.73M
  };
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
178k
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
360
178k
  if (Opts.NoBitFieldTypeAlign)
361
2
    UseBitFieldTypeAlignment = false;
362
363
178k
  switch (Opts.WCharSize) {
364
0
  default: llvm_unreachable("invalid wchar_t width");
365
178k
  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
178k
  }
370
371
178k
  if (Opts.AlignDouble) {
372
10
    DoubleAlign = LongLongAlign = 64;
373
10
    LongDoubleAlign = 64;
374
10
  }
375
376
178k
  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.34k
    IntWidth = IntAlign = 32;
382
1.34k
    LongWidth = LongAlign = 64;
383
1.34k
    LongLongWidth = LongLongAlign = 128;
384
1.34k
    HalfWidth = HalfAlign = 16;
385
1.34k
    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.34k
    if (DoubleWidth != FloatWidth) {
391
1.34k
      DoubleWidth = DoubleAlign = 64;
392
1.34k
      DoubleFormat = &llvm::APFloat::IEEEdouble();
393
1.34k
    }
394
1.34k
    LongDoubleWidth = LongDoubleAlign = 128;
395
396
1.34k
    unsigned MaxPointerWidth = getMaxPointerWidth();
397
1.34k
    assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
398
0
    bool Is32BitArch = MaxPointerWidth == 32;
399
1.34k
    SizeType = Is32BitArch ? 
UnsignedInt532
:
UnsignedLong812
;
400
1.34k
    PtrDiffType = Is32BitArch ? 
SignedInt532
:
SignedLong812
;
401
1.34k
    IntPtrType = Is32BitArch ? 
SignedInt532
:
SignedLong812
;
402
403
1.34k
    IntMaxType = SignedLongLong;
404
1.34k
    Int64Type = SignedLong;
405
406
1.34k
    HalfFormat = &llvm::APFloat::IEEEhalf();
407
1.34k
    FloatFormat = &llvm::APFloat::IEEEsingle();
408
1.34k
    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.34k
    if (Opts.getOpenCLCompatibleVersion() == 300) {
420
272
      const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
421
272
      Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
422
272
          OpenCLFeaturesMap, "__opencl_c_generic_address_space");
423
272
      Opts.OpenCLPipes =
424
272
          hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
425
272
      Opts.Blocks =
426
272
          hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_device_enqueue");
427
272
    }
428
1.34k
  }
429
430
178k
  if (Opts.DoubleSize) {
431
4
    if (Opts.DoubleSize == 32) {
432
2
      DoubleWidth = 32;
433
2
      LongDoubleWidth = 32;
434
2
      DoubleFormat = &llvm::APFloat::IEEEsingle();
435
2
      LongDoubleFormat = &llvm::APFloat::IEEEsingle();
436
2
    } else if (Opts.DoubleSize == 64) {
437
2
      DoubleWidth = 64;
438
2
      LongDoubleWidth = 64;
439
2
      DoubleFormat = &llvm::APFloat::IEEEdouble();
440
2
      LongDoubleFormat = &llvm::APFloat::IEEEdouble();
441
2
    }
442
4
  }
443
444
178k
  if (Opts.LongDoubleSize) {
445
46
    if (Opts.LongDoubleSize == DoubleWidth) {
446
20
      LongDoubleWidth = DoubleWidth;
447
20
      LongDoubleAlign = DoubleAlign;
448
20
      LongDoubleFormat = DoubleFormat;
449
26
    } else if (Opts.LongDoubleSize == 128) {
450
16
      LongDoubleWidth = LongDoubleAlign = 128;
451
16
      LongDoubleFormat = &llvm::APFloat::IEEEquad();
452
16
    } else 
if (10
Opts.LongDoubleSize == 8010
) {
453
10
      LongDoubleFormat = &llvm::APFloat::x87DoubleExtended();
454
10
      if (getTriple().isWindowsMSVCEnvironment()) {
455
4
        LongDoubleWidth = 128;
456
4
        LongDoubleAlign = 128;
457
6
      } else { // Linux
458
6
        if (getTriple().getArch() == llvm::Triple::x86) {
459
4
          LongDoubleWidth = 96;
460
4
          LongDoubleAlign = 32;
461
4
        } else {
462
2
          LongDoubleWidth = 128;
463
2
          LongDoubleAlign = 128;
464
2
        }
465
6
      }
466
10
    }
467
46
  }
468
469
178k
  if (Opts.NewAlignOverride)
470
6
    NewAlign = Opts.NewAlignOverride * getCharWidth();
471
472
  // Each unsigned fixed point type has the same number of fractional bits as
473
  // its corresponding signed type.
474
178k
  PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint;
475
178k
  CheckFixedPointBits();
476
477
178k
  if (Opts.ProtectParens && 
!checkArithmeticFenceSupported()11
) {
478
1
    Diags.Report(diag::err_opt_not_valid_on_target) << "-fprotect-parens";
479
1
    Opts.ProtectParens = false;
480
1
  }
481
178k
}
482
483
bool TargetInfo::initFeatureMap(
484
    llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
485
154k
    const std::vector<std::string> &FeatureVec) const {
486
164k
  for (const auto &F : FeatureVec) {
487
164k
    StringRef Name = F;
488
    // Apply the feature via the target.
489
164k
    bool Enabled = Name[0] == '+';
490
164k
    setFeatureEnabled(Features, Name.substr(1), Enabled);
491
164k
  }
492
154k
  return true;
493
154k
}
494
495
TargetInfo::CallingConvKind
496
1.47M
TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
497
1.47M
  if (getCXXABI() != TargetCXXABI::Microsoft &&
498
1.47M
      
(1.46M
ClangABICompat41.46M
||
getTriple().getOS() == llvm::Triple::PS41.46M
))
499
599
    return CCK_ClangABI4OrPS4;
500
1.47M
  return CCK_Default;
501
1.47M
}
502
503
211
LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
504
211
  switch (TK) {
505
62
  case OCLTK_Image:
506
108
  case OCLTK_Pipe:
507
108
    return LangAS::opencl_global;
508
509
16
  case OCLTK_Sampler:
510
16
    return LangAS::opencl_constant;
511
512
87
  default:
513
87
    return LangAS::Default;
514
211
  }
515
211
}
516
517
//===----------------------------------------------------------------------===//
518
519
520
8.50k
static StringRef removeGCCRegisterPrefix(StringRef Name) {
521
8.50k
  if (Name[0] == '%' || 
Name[0] == '#'7.88k
)
522
640
    Name = Name.substr(1);
523
524
8.50k
  return Name;
525
8.50k
}
526
527
/// isValidClobber - Returns whether the passed in string is
528
/// a valid clobber in an inline asm statement. This is used by
529
/// Sema.
530
3.36k
bool TargetInfo::isValidClobber(StringRef Name) const {
531
3.36k
  return (isValidGCCRegisterName(Name) || 
Name == "memory"2.16k
||
Name == "cc"1.20k
||
532
3.36k
          
Name == "unwind"5
);
533
3.36k
}
534
535
/// isValidGCCRegisterName - Returns whether the passed in string
536
/// is a valid register name according to GCC. This is used by Sema for
537
/// inline asm statements.
538
6.06k
bool TargetInfo::isValidGCCRegisterName(StringRef Name) const {
539
6.06k
  if (Name.empty())
540
0
    return false;
541
542
  // Get rid of any register prefix.
543
6.06k
  Name = removeGCCRegisterPrefix(Name);
544
6.06k
  if (Name.empty())
545
1
    return false;
546
547
6.06k
  ArrayRef<const char *> Names = getGCCRegNames();
548
549
  // If we have a number it maps to an entry in the register name array.
550
6.06k
  if (isDigit(Name[0])) {
551
26
    unsigned n;
552
26
    if (!Name.getAsInteger(0, n))
553
26
      return n < Names.size();
554
26
  }
555
556
  // Check register names.
557
6.03k
  if (llvm::is_contained(Names, Name))
558
3.03k
    return true;
559
560
  // Check any additional names that we have.
561
3.00k
  for (const AddlRegName &ARN : getGCCAddlRegNames())
562
140k
    
for (const char *AN : ARN.Names)35.0k
{
563
140k
      if (!AN)
564
34.6k
        break;
565
      // Make sure the register that the additional name is for is within
566
      // the bounds of the register names from above.
567
105k
      if (AN == Name && 
ARN.RegNum < Names.size()382
)
568
382
        return true;
569
105k
    }
570
571
  // Now check aliases.
572
2.62k
  for (const GCCRegAlias &GRA : getGCCRegAliases())
573
25.2k
    
for (const char *A : GRA.Aliases)12.7k
{
574
25.2k
      if (!A)
575
12.3k
        break;
576
12.9k
      if (A == Name)
577
461
        return true;
578
12.9k
    }
579
580
2.16k
  return false;
581
2.62k
}
582
583
StringRef TargetInfo::getNormalizedGCCRegisterName(StringRef Name,
584
2.43k
                                                   bool ReturnCanonical) const {
585
2.43k
  assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
586
587
  // Get rid of any register prefix.
588
0
  Name = removeGCCRegisterPrefix(Name);
589
590
2.43k
  ArrayRef<const char *> Names = getGCCRegNames();
591
592
  // First, check if we have a number.
593
2.43k
  if (isDigit(Name[0])) {
594
12
    unsigned n;
595
12
    if (!Name.getAsInteger(0, n)) {
596
12
      assert(n < Names.size() && "Out of bounds register number!");
597
0
      return Names[n];
598
12
    }
599
12
  }
600
601
  // Check any additional names that we have.
602
2.42k
  for (const AddlRegName &ARN : getGCCAddlRegNames())
603
21.5k
    
for (const char *AN : ARN.Names)5.58k
{
604
21.5k
      if (!AN)
605
5.32k
        break;
606
      // Make sure the register that the additional name is for is within
607
      // the bounds of the register names from above.
608
16.1k
      if (AN == Name && 
ARN.RegNum < Names.size()254
)
609
254
        return ReturnCanonical ? 
Names[ARN.RegNum]59
:
Name195
;
610
16.1k
    }
611
612
  // Now check aliases.
613
2.17k
  for (const GCCRegAlias &RA : getGCCRegAliases())
614
104k
    
for (const char *A : RA.Aliases)51.0k
{
615
104k
      if (!A)
616
50.8k
        break;
617
53.2k
      if (A == Name)
618
246
        return RA.Register;
619
53.2k
    }
620
621
1.92k
  return Name;
622
2.17k
}
623
624
8.66k
bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
625
8.66k
  const char *Name = Info.getConstraintStr().c_str();
626
  // An output constraint must start with '=' or '+'
627
8.66k
  if (*Name != '=' && 
*Name != '+'845
)
628
65
    return false;
629
630
8.60k
  if (*Name == '+')
631
780
    Info.setIsReadWrite();
632
633
8.60k
  Name++;
634
18.5k
  while (*Name) {
635
9.99k
    switch (*Name) {
636
5.99k
    default:
637
5.99k
      if (!validateAsmConstraint(Name, Info)) {
638
        // FIXME: We temporarily return false
639
        // so we can add more constraints as we hit it.
640
        // Eventually, an unknown constraint should just be treated as 'g'.
641
13
        return false;
642
13
      }
643
5.98k
      break;
644
5.98k
    case '&': // early clobber.
645
36
      Info.setEarlyClobber();
646
36
      break;
647
7
    case '%': // commutative.
648
      // FIXME: Check that there is a another register after this one.
649
7
      break;
650
2.71k
    case 'r': // general register.
651
2.71k
      Info.setAllowsRegister();
652
2.71k
      break;
653
526
    case 'm': // memory operand.
654
526
    case 'o': // offsetable memory operand.
655
526
    case 'V': // non-offsetable memory operand.
656
526
    case '<': // autodecrement memory operand.
657
526
    case '>': // autoincrement memory operand.
658
526
      Info.setAllowsMemory();
659
526
      break;
660
25
    case 'g': // general register, memory operand or immediate integer.
661
25
    case 'X': // any operand.
662
25
      Info.setAllowsRegister();
663
25
      Info.setAllowsMemory();
664
25
      break;
665
648
    case ',': // multiple alternative constraint.  Pass it.
666
      // Handle additional optional '=' or '+' modifiers.
667
648
      if (Name[1] == '=' || 
Name[1] == '+'643
)
668
5
        Name++;
669
648
      break;
670
2
    case '#': // Ignore as constraint.
671
3
      while (Name[1] && 
Name[1] != ','1
)
672
1
        Name++;
673
2
      break;
674
1
    case '?': // Disparage slightly code.
675
2
    case '!': // Disparage severely.
676
3
    case '*': // Ignore for choosing register preferences.
677
12
    case 'i': // Ignore i,n,E,F as output constraints (match from the other
678
              // chars)
679
21
    case 'n':
680
30
    case 'E':
681
39
    case 'F':
682
39
      break;  // Pass them.
683
9.99k
    }
684
685
9.97k
    Name++;
686
9.97k
  }
687
688
  // Early clobber with a read-write constraint which doesn't permit registers
689
  // is invalid.
690
8.58k
  if (Info.earlyClobber() && 
Info.isReadWrite()33
&&
!Info.allowsRegister()7
)
691
1
    return false;
692
693
  // If a constraint allows neither memory nor register operands it contains
694
  // only modifiers. Reject it.
695
8.58k
  return Info.allowsMemory() || 
Info.allowsRegister()8.06k
;
696
8.58k
}
697
698
bool TargetInfo::resolveSymbolicName(const char *&Name,
699
                                     ArrayRef<ConstraintInfo> OutputConstraints,
700
52
                                     unsigned &Index) const {
701
52
  assert(*Name == '[' && "Symbolic name did not start with '['");
702
0
  Name++;
703
52
  const char *Start = Name;
704
247
  while (*Name && 
*Name != ']'245
)
705
195
    Name++;
706
707
52
  if (!*Name) {
708
    // Missing ']'
709
2
    return false;
710
2
  }
711
712
50
  std::string SymbolicName(Start, Name - Start);
713
714
183
  for (Index = 0; Index != OutputConstraints.size(); 
++Index133
)
715
182
    if (SymbolicName == OutputConstraints[Index].getName())
716
49
      return true;
717
718
1
  return false;
719
50
}
720
721
bool TargetInfo::validateInputConstraint(
722
                              MutableArrayRef<ConstraintInfo> OutputConstraints,
723
10.6k
                              ConstraintInfo &Info) const {
724
10.6k
  const char *Name = Info.ConstraintStr.c_str();
725
726
10.6k
  if (!*Name)
727
2
    return false;
728
729
22.8k
  
while (10.6k
*Name) {
730
12.2k
    switch (*Name) {
731
6.11k
    default:
732
      // Check if we have a matching constraint
733
6.11k
      if (*Name >= '0' && *Name <= '9') {
734
179
        const char *DigitStart = Name;
735
180
        while (Name[1] >= '0' && 
Name[1] <= '9'3
)
736
1
          Name++;
737
179
        const char *DigitEnd = Name;
738
179
        unsigned i;
739
179
        if (StringRef(DigitStart, DigitEnd - DigitStart + 1)
740
179
                .getAsInteger(10, i))
741
0
          return false;
742
743
        // Check if matching constraint is out of bounds.
744
179
        if (i >= OutputConstraints.size()) 
return false1
;
745
746
        // A number must refer to an output only operand.
747
178
        if (OutputConstraints[i].isReadWrite())
748
1
          return false;
749
750
        // If the constraint is already tied, it must be tied to the
751
        // same operand referenced to by the number.
752
177
        if (Info.hasTiedOperand() && 
Info.getTiedOperand() != i1
)
753
1
          return false;
754
755
        // The constraint should have the same info as the respective
756
        // output constraint.
757
176
        Info.setTiedOperand(i, OutputConstraints[i]);
758
5.93k
      } else if (!validateAsmConstraint(Name, Info)) {
759
        // FIXME: This error return is in place temporarily so we can
760
        // add more constraints as we hit it.  Eventually, an unknown
761
        // constraint should just be treated as 'g'.
762
10
        return false;
763
10
      }
764
6.09k
      break;
765
6.09k
    case '[': {
766
46
      unsigned Index = 0;
767
46
      if (!resolveSymbolicName(Name, OutputConstraints, Index))
768
3
        return false;
769
770
      // If the constraint is already tied, it must be tied to the
771
      // same operand referenced to by the number.
772
43
      if (Info.hasTiedOperand() && 
Info.getTiedOperand() != Index1
)
773
1
        return false;
774
775
      // A number must refer to an output only operand.
776
42
      if (OutputConstraints[Index].isReadWrite())
777
1
        return false;
778
779
41
      Info.setTiedOperand(Index, OutputConstraints[Index]);
780
41
      break;
781
42
    }
782
0
    case '%': // commutative
783
      // FIXME: Fail if % is used with the last operand.
784
0
      break;
785
369
    case 'i': // immediate integer.
786
369
      break;
787
81
    case 'n': // immediate integer with a known value.
788
81
      Info.setRequiresImmediate();
789
81
      break;
790
62
    case 'I':  // Various constant constraints with target-specific meanings.
791
118
    case 'J':
792
152
    case 'K':
793
202
    case 'L':
794
222
    case 'M':
795
255
    case 'N':
796
265
    case 'O':
797
265
    case 'P':
798
265
      if (!validateAsmConstraint(Name, Info))
799
16
        return false;
800
249
      break;
801
3.38k
    case 'r': // general register.
802
3.38k
      Info.setAllowsRegister();
803
3.38k
      break;
804
435
    case 'm': // memory operand.
805
435
    case 'o': // offsettable memory operand.
806
435
    case 'V': // non-offsettable memory operand.
807
523
    case '<': // autodecrement memory operand.
808
611
    case '>': // autoincrement memory operand.
809
611
      Info.setAllowsMemory();
810
611
      break;
811
268
    case 'g': // general register, memory operand or immediate integer.
812
533
    case 'X': // any operand.
813
533
      Info.setAllowsRegister();
814
533
      Info.setAllowsMemory();
815
533
      break;
816
44
    case 'E': // immediate floating point.
817
88
    case 'F': // immediate floating point.
818
139
    case 'p': // address operand.
819
139
      break;
820
683
    case ',': // multiple alternative constraint.  Ignore comma.
821
683
      break;
822
3
    case '#': // Ignore as constraint.
823
7
      while (Name[1] && 
Name[1] != ','6
)
824
4
        Name++;
825
3
      break;
826
0
    case '?': // Disparage slightly code.
827
0
    case '!': // Disparage severely.
828
2
    case '*': // Ignore for choosing register preferences.
829
2
      break;  // Pass them.
830
12.2k
    }
831
832
12.1k
    Name++;
833
12.1k
  }
834
835
10.6k
  return true;
836
10.6k
}
837
838
275k
void TargetInfo::CheckFixedPointBits() const {
839
  // Check that the number of fractional and integral bits (and maybe sign) can
840
  // fit into the bits given for a fixed point type.
841
275k
  assert(ShortAccumScale + getShortAccumIBits() + 1 <= ShortAccumWidth);
842
0
  assert(AccumScale + getAccumIBits() + 1 <= AccumWidth);
843
0
  assert(LongAccumScale + getLongAccumIBits() + 1 <= LongAccumWidth);
844
0
  assert(getUnsignedShortAccumScale() + getUnsignedShortAccumIBits() <=
845
275k
         ShortAccumWidth);
846
0
  assert(getUnsignedAccumScale() + getUnsignedAccumIBits() <= AccumWidth);
847
0
  assert(getUnsignedLongAccumScale() + getUnsignedLongAccumIBits() <=
848
275k
         LongAccumWidth);
849
850
0
  assert(getShortFractScale() + 1 <= ShortFractWidth);
851
0
  assert(getFractScale() + 1 <= FractWidth);
852
0
  assert(getLongFractScale() + 1 <= LongFractWidth);
853
0
  assert(getUnsignedShortFractScale() <= ShortFractWidth);
854
0
  assert(getUnsignedFractScale() <= FractWidth);
855
0
  assert(getUnsignedLongFractScale() <= LongFractWidth);
856
857
  // Each unsigned fract type has either the same number of fractional bits
858
  // as, or one more fractional bit than, its corresponding signed fract type.
859
0
  assert(getShortFractScale() == getUnsignedShortFractScale() ||
860
275k
         getShortFractScale() == getUnsignedShortFractScale() - 1);
861
0
  assert(getFractScale() == getUnsignedFractScale() ||
862
275k
         getFractScale() == getUnsignedFractScale() - 1);
863
0
  assert(getLongFractScale() == getUnsignedLongFractScale() ||
864
275k
         getLongFractScale() == getUnsignedLongFractScale() - 1);
865
866
  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
867
  // fractional bits is nondecreasing for each of the following sets of
868
  // fixed-point types:
869
  // - signed fract types
870
  // - unsigned fract types
871
  // - signed accum types
872
  // - unsigned accum types.
873
0
  assert(getLongFractScale() >= getFractScale() &&
874
275k
         getFractScale() >= getShortFractScale());
875
0
  assert(getUnsignedLongFractScale() >= getUnsignedFractScale() &&
876
275k
         getUnsignedFractScale() >= getUnsignedShortFractScale());
877
0
  assert(LongAccumScale >= AccumScale && AccumScale >= ShortAccumScale);
878
0
  assert(getUnsignedLongAccumScale() >= getUnsignedAccumScale() &&
879
275k
         getUnsignedAccumScale() >= getUnsignedShortAccumScale());
880
881
  // When arranged in order of increasing rank (see 6.3.1.3a), the number of
882
  // integral bits is nondecreasing for each of the following sets of
883
  // fixed-point types:
884
  // - signed accum types
885
  // - unsigned accum types
886
0
  assert(getLongAccumIBits() >= getAccumIBits() &&
887
275k
         getAccumIBits() >= getShortAccumIBits());
888
0
  assert(getUnsignedLongAccumIBits() >= getUnsignedAccumIBits() &&
889
275k
         getUnsignedAccumIBits() >= getUnsignedShortAccumIBits());
890
891
  // Each signed accum type has at least as many integral bits as its
892
  // corresponding unsigned accum type.
893
0
  assert(getShortAccumIBits() >= getUnsignedShortAccumIBits());
894
0
  assert(getAccumIBits() >= getUnsignedAccumIBits());
895
0
  assert(getLongAccumIBits() >= getUnsignedLongAccumIBits());
896
275k
}
897
898
19
void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
899
19
  auto *Target = static_cast<TransferrableTargetInfo*>(this);
900
19
  auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
901
19
  *Target = *Src;
902
19
}