Coverage Report

Created: 2021-01-19 06:58

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