Coverage Report

Created: 2020-09-19 12:23

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