Coverage Report

Created: 2020-02-25 14:32

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