Coverage Report

Created: 2019-07-24 05:18

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