Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/TargetInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
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
/// \file
10
/// Defines the clang::TargetInfo interface.
11
///
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_BASIC_TARGETINFO_H
15
#define LLVM_CLANG_BASIC_TARGETINFO_H
16
17
#include "clang/Basic/AddressSpaces.h"
18
#include "clang/Basic/LLVM.h"
19
#include "clang/Basic/Specifiers.h"
20
#include "clang/Basic/TargetCXXABI.h"
21
#include "clang/Basic/TargetOptions.h"
22
#include "llvm/ADT/APInt.h"
23
#include "llvm/ADT/IntrusiveRefCntPtr.h"
24
#include "llvm/ADT/Optional.h"
25
#include "llvm/ADT/SmallSet.h"
26
#include "llvm/ADT/StringMap.h"
27
#include "llvm/ADT/StringRef.h"
28
#include "llvm/ADT/Triple.h"
29
#include "llvm/IR/DataLayout.h"
30
#include "llvm/Support/DataTypes.h"
31
#include "llvm/Support/VersionTuple.h"
32
#include <cassert>
33
#include <string>
34
#include <vector>
35
36
namespace llvm {
37
struct fltSemantics;
38
}
39
40
namespace clang {
41
class DiagnosticsEngine;
42
class LangOptions;
43
class CodeGenOptions;
44
class MacroBuilder;
45
class QualType;
46
class SourceLocation;
47
class SourceManager;
48
49
namespace Builtin { struct Info; }
50
51
/// Fields controlling how types are laid out in memory; these may need to
52
/// be copied for targets like AMDGPU that base their ABIs on an auxiliary
53
/// CPU target.
54
struct TransferrableTargetInfo {
55
  unsigned char PointerWidth, PointerAlign;
56
  unsigned char BoolWidth, BoolAlign;
57
  unsigned char IntWidth, IntAlign;
58
  unsigned char HalfWidth, HalfAlign;
59
  unsigned char FloatWidth, FloatAlign;
60
  unsigned char DoubleWidth, DoubleAlign;
61
  unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align;
62
  unsigned char LargeArrayMinWidth, LargeArrayAlign;
63
  unsigned char LongWidth, LongAlign;
64
  unsigned char LongLongWidth, LongLongAlign;
65
66
  // Fixed point bit widths
67
  unsigned char ShortAccumWidth, ShortAccumAlign;
68
  unsigned char AccumWidth, AccumAlign;
69
  unsigned char LongAccumWidth, LongAccumAlign;
70
  unsigned char ShortFractWidth, ShortFractAlign;
71
  unsigned char FractWidth, FractAlign;
72
  unsigned char LongFractWidth, LongFractAlign;
73
74
  // If true, unsigned fixed point types have the same number of fractional bits
75
  // as their signed counterparts, forcing the unsigned types to have one extra
76
  // bit of padding. Otherwise, unsigned fixed point types have
77
  // one more fractional bit than its corresponding signed type. This is false
78
  // by default.
79
  bool PaddingOnUnsignedFixedPoint;
80
81
  // Fixed point integral and fractional bit sizes
82
  // Saturated types share the same integral/fractional bits as their
83
  // corresponding unsaturated types.
84
  // For simplicity, the fractional bits in a _Fract type will be one less the
85
  // width of that _Fract type. This leaves all signed _Fract types having no
86
  // padding and unsigned _Fract types will only have 1 bit of padding after the
87
  // sign if PaddingOnUnsignedFixedPoint is set.
88
  unsigned char ShortAccumScale;
89
  unsigned char AccumScale;
90
  unsigned char LongAccumScale;
91
92
  unsigned char SuitableAlign;
93
  unsigned char DefaultAlignForAttributeAligned;
94
  unsigned char MinGlobalAlign;
95
96
  unsigned short NewAlign;
97
  unsigned short MaxVectorAlign;
98
  unsigned short MaxTLSAlign;
99
100
  const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
101
    *LongDoubleFormat, *Float128Format;
102
103
  ///===---- Target Data Type Query Methods -------------------------------===//
104
  enum IntType {
105
    NoInt = 0,
106
    SignedChar,
107
    UnsignedChar,
108
    SignedShort,
109
    UnsignedShort,
110
    SignedInt,
111
    UnsignedInt,
112
    SignedLong,
113
    UnsignedLong,
114
    SignedLongLong,
115
    UnsignedLongLong
116
  };
117
118
  enum RealType {
119
    NoFloat = 255,
120
    Float = 0,
121
    Double,
122
    LongDouble,
123
    Float128
124
  };
125
protected:
126
  IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
127
          WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
128
          ProcessIDType;
129
130
  /// Whether Objective-C's built-in boolean type should be signed char.
131
  ///
132
  /// Otherwise, when this flag is not set, the normal built-in boolean type is
133
  /// used.
134
  unsigned UseSignedCharForObjCBool : 1;
135
136
  /// Control whether the alignment of bit-field types is respected when laying
137
  /// out structures. If true, then the alignment of the bit-field type will be
138
  /// used to (a) impact the alignment of the containing structure, and (b)
139
  /// ensure that the individual bit-field will not straddle an alignment
140
  /// boundary.
141
  unsigned UseBitFieldTypeAlignment : 1;
142
143
  /// Whether zero length bitfields (e.g., int : 0;) force alignment of
144
  /// the next bitfield.
145
  ///
146
  /// If the alignment of the zero length bitfield is greater than the member
147
  /// that follows it, `bar', `bar' will be aligned as the type of the
148
  /// zero-length bitfield.
149
  unsigned UseZeroLengthBitfieldAlignment : 1;
150
151
  ///  Whether explicit bit field alignment attributes are honored.
152
  unsigned UseExplicitBitFieldAlignment : 1;
153
154
  /// If non-zero, specifies a fixed alignment value for bitfields that follow
155
  /// zero length bitfield, regardless of the zero length bitfield type.
156
  unsigned ZeroLengthBitfieldBoundary;
157
};
158
159
/// Exposes information about the current target.
160
///
161
class TargetInfo : public virtual TransferrableTargetInfo,
162
                   public RefCountedBase<TargetInfo> {
163
  std::shared_ptr<TargetOptions> TargetOpts;
164
  llvm::Triple Triple;
165
protected:
166
  // Target values set by the ctor of the actual target implementation.  Default
167
  // values are specified by the TargetInfo constructor.
168
  bool BigEndian;
169
  bool TLSSupported;
170
  bool VLASupported;
171
  bool NoAsmVariants;  // True if {|} are normal characters.
172
  bool HasLegalHalfType; // True if the backend supports operations on the half
173
                         // LLVM IR type.
174
  bool HasFloat128;
175
  bool HasFloat16;
176
177
  unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
178
  unsigned short SimdDefaultAlign;
179
  std::unique_ptr<llvm::DataLayout> DataLayout;
180
  const char *MCountName;
181
  unsigned char RegParmMax, SSERegParmMax;
182
  TargetCXXABI TheCXXABI;
183
  const LangASMap *AddrSpaceMap;
184
185
  mutable StringRef PlatformName;
186
  mutable VersionTuple PlatformMinVersion;
187
188
  unsigned HasAlignMac68kSupport : 1;
189
  unsigned RealTypeUsesObjCFPRet : 3;
190
  unsigned ComplexLongDoubleUsesFP2Ret : 1;
191
192
  unsigned HasBuiltinMSVaList : 1;
193
194
  unsigned IsRenderScriptTarget : 1;
195
196
  // TargetInfo Constructor.  Default initializes all fields.
197
  TargetInfo(const llvm::Triple &T);
198
199
78.3k
  void resetDataLayout(StringRef DL) {
200
78.3k
    DataLayout.reset(new llvm::DataLayout(DL));
201
78.3k
  }
202
203
public:
204
  /// Construct a target for the given options.
205
  ///
206
  /// \param Opts - The options to use to initialize the target. The target may
207
  /// modify the options to canonicalize the target feature information to match
208
  /// what the backend expects.
209
  static TargetInfo *
210
  CreateTargetInfo(DiagnosticsEngine &Diags,
211
                   const std::shared_ptr<TargetOptions> &Opts);
212
213
  virtual ~TargetInfo();
214
215
  /// Retrieve the target options.
216
2.04M
  TargetOptions &getTargetOpts() const {
217
2.04M
    assert(TargetOpts && "Missing target options");
218
2.04M
    return *TargetOpts;
219
2.04M
  }
220
221
  /// The different kinds of __builtin_va_list types defined by
222
  /// the target implementation.
223
  enum BuiltinVaListKind {
224
    /// typedef char* __builtin_va_list;
225
    CharPtrBuiltinVaList = 0,
226
227
    /// typedef void* __builtin_va_list;
228
    VoidPtrBuiltinVaList,
229
230
    /// __builtin_va_list as defined by the AArch64 ABI
231
    /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
232
    AArch64ABIBuiltinVaList,
233
234
    /// __builtin_va_list as defined by the PNaCl ABI:
235
    /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
236
    PNaClABIBuiltinVaList,
237
238
    /// __builtin_va_list as defined by the Power ABI:
239
    /// https://www.power.org
240
    ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
241
    PowerABIBuiltinVaList,
242
243
    /// __builtin_va_list as defined by the x86-64 ABI:
244
    /// http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
245
    X86_64ABIBuiltinVaList,
246
247
    /// __builtin_va_list as defined by ARM AAPCS ABI
248
    /// http://infocenter.arm.com
249
    //        /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
250
    AAPCSABIBuiltinVaList,
251
252
    // typedef struct __va_list_tag
253
    //   {
254
    //     long __gpr;
255
    //     long __fpr;
256
    //     void *__overflow_arg_area;
257
    //     void *__reg_save_area;
258
    //   } va_list[1];
259
    SystemZBuiltinVaList
260
  };
261
262
protected:
263
  /// Specify if mangling based on address space map should be used or
264
  /// not for language specific address spaces
265
  bool UseAddrSpaceMapMangling;
266
267
public:
268
1.57M
  IntType getSizeType() const { return SizeType; }
269
38
  IntType getSignedSizeType() const {
270
38
    switch (SizeType) {
271
38
    case UnsignedShort:
272
0
      return SignedShort;
273
38
    case UnsignedInt:
274
0
      return SignedInt;
275
38
    case UnsignedLong:
276
38
      return SignedLong;
277
38
    case UnsignedLongLong:
278
0
      return SignedLongLong;
279
38
    default:
280
0
      llvm_unreachable("Invalid SizeType");
281
38
    }
282
38
  }
283
220k
  IntType getIntMaxType() const { return IntMaxType; }
284
220k
  IntType getUIntMaxType() const {
285
220k
    return getCorrespondingUnsignedType(IntMaxType);
286
220k
  }
287
436k
  IntType getPtrDiffType(unsigned AddrSpace) const {
288
436k
    return AddrSpace == 0 ? PtrDiffType : 
getPtrDiffTypeV(AddrSpace)0
;
289
436k
  }
290
16
  IntType getUnsignedPtrDiffType(unsigned AddrSpace) const {
291
16
    return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
292
16
  }
293
1.01M
  IntType getIntPtrType() const { return IntPtrType; }
294
176k
  IntType getUIntPtrType() const {
295
176k
    return getCorrespondingUnsignedType(IntPtrType);
296
176k
  }
297
278k
  IntType getWCharType() const { return WCharType; }
298
262k
  IntType getWIntType() const { return WIntType; }
299
59.8k
  IntType getChar16Type() const { return Char16Type; }
300
59.8k
  IntType getChar32Type() const { return Char32Type; }
301
142k
  IntType getInt64Type() const { return Int64Type; }
302
88.2k
  IntType getUInt64Type() const {
303
88.2k
    return getCorrespondingUnsignedType(Int64Type);
304
88.2k
  }
305
88.3k
  IntType getSigAtomicType() const { return SigAtomicType; }
306
654
  IntType getProcessIDType() const { return ProcessIDType; }
307
308
485k
  static IntType getCorrespondingUnsignedType(IntType T) {
309
485k
    switch (T) {
310
485k
    case SignedChar:
311
0
      return UnsignedChar;
312
485k
    case SignedShort:
313
0
      return UnsignedShort;
314
485k
    case SignedInt:
315
25.4k
      return UnsignedInt;
316
485k
    case SignedLong:
317
322k
      return UnsignedLong;
318
485k
    case SignedLongLong:
319
137k
      return UnsignedLongLong;
320
485k
    default:
321
0
      llvm_unreachable("Unexpected signed integer type");
322
485k
    }
323
485k
  }
324
325
  /// In the event this target uses the same number of fractional bits for its
326
  /// unsigned types as it does with its signed counterparts, there will be
327
  /// exactly one bit of padding.
328
  /// Return true if unsigned fixed point types have padding for this target.
329
1.09k
  bool doUnsignedFixedPointTypesHavePadding() const {
330
1.09k
    return PaddingOnUnsignedFixedPoint;
331
1.09k
  }
332
333
  /// Return the width (in bits) of the specified integer type enum.
334
  ///
335
  /// For example, SignedInt -> getIntWidth().
336
  unsigned getTypeWidth(IntType T) const;
337
338
  /// Return integer type with specified width.
339
  virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
340
341
  /// Return the smallest integer type with at least the specified width.
342
  virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
343
                                         bool IsSigned) const;
344
345
  /// Return floating point type with specified width.
346
  RealType getRealTypeByWidth(unsigned BitWidth) const;
347
348
  /// Return the alignment (in bits) of the specified integer type enum.
349
  ///
350
  /// For example, SignedInt -> getIntAlign().
351
  unsigned getTypeAlign(IntType T) const;
352
353
  /// Returns true if the type is signed; false otherwise.
354
  static bool isTypeSigned(IntType T);
355
356
  /// Return the width of pointers on this target, for the
357
  /// specified address space.
358
1.04M
  uint64_t getPointerWidth(unsigned AddrSpace) const {
359
1.04M
    return AddrSpace == 0 ? 
PointerWidth1.04M
:
getPointerWidthV(AddrSpace)923
;
360
1.04M
  }
361
486k
  uint64_t getPointerAlign(unsigned AddrSpace) const {
362
486k
    return AddrSpace == 0 ? 
PointerAlign485k
:
getPointerAlignV(AddrSpace)830
;
363
486k
  }
364
365
  /// Return the maximum width of pointers on this target.
366
3.67M
  virtual uint64_t getMaxPointerWidth() const {
367
3.67M
    return PointerWidth;
368
3.67M
  }
369
370
  /// Get integer value for null pointer.
371
  /// \param AddrSpace address space of pointee in source language.
372
203k
  virtual uint64_t getNullPointerValue(LangAS AddrSpace) const { return 0; }
373
374
  /// Return the size of '_Bool' and C++ 'bool' for this target, in bits.
375
90.8k
  unsigned getBoolWidth() const { return BoolWidth; }
376
377
  /// Return the alignment of '_Bool' and C++ 'bool' for this target.
378
90.8k
  unsigned getBoolAlign() const { return BoolAlign; }
379
380
11.3M
  unsigned getCharWidth() const { return 8; } // FIXME
381
270k
  unsigned getCharAlign() const { return 8; } // FIXME
382
383
  /// Return the size of 'signed short' and 'unsigned short' for this
384
  /// target, in bits.
385
1.82M
  unsigned getShortWidth() const { return 16; } // FIXME
386
387
  /// Return the alignment of 'signed short' and 'unsigned short' for
388
  /// this target.
389
185k
  unsigned getShortAlign() const { return 16; } // FIXME
390
391
  /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
392
  /// this target, in bits.
393
9.42M
  unsigned getIntWidth() const { return IntWidth; }
394
320k
  unsigned getIntAlign() const { return IntAlign; }
395
396
  /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
397
  /// for this target, in bits.
398
6.72M
  unsigned getLongWidth() const { return LongWidth; }
399
131k
  unsigned getLongAlign() const { return LongAlign; }
400
401
  /// getLongLongWidth/Align - Return the size of 'signed long long' and
402
  /// 'unsigned long long' for this target, in bits.
403
1.60M
  unsigned getLongLongWidth() const { return LongLongWidth; }
404
102k
  unsigned getLongLongAlign() const { return LongLongAlign; }
405
406
  /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
407
  /// 'unsigned short _Accum' for this target, in bits.
408
61
  unsigned getShortAccumWidth() const { return ShortAccumWidth; }
409
61
  unsigned getShortAccumAlign() const { return ShortAccumAlign; }
410
411
  /// getAccumWidth/Align - Return the size of 'signed _Accum' and
412
  /// 'unsigned _Accum' for this target, in bits.
413
63
  unsigned getAccumWidth() const { return AccumWidth; }
414
63
  unsigned getAccumAlign() const { return AccumAlign; }
415
416
  /// getLongAccumWidth/Align - Return the size of 'signed long _Accum' and
417
  /// 'unsigned long _Accum' for this target, in bits.
418
51
  unsigned getLongAccumWidth() const { return LongAccumWidth; }
419
51
  unsigned getLongAccumAlign() const { return LongAccumAlign; }
420
421
  /// getShortFractWidth/Align - Return the size of 'signed short _Fract' and
422
  /// 'unsigned short _Fract' for this target, in bits.
423
40
  unsigned getShortFractWidth() const { return ShortFractWidth; }
424
40
  unsigned getShortFractAlign() const { return ShortFractAlign; }
425
426
  /// getFractWidth/Align - Return the size of 'signed _Fract' and
427
  /// 'unsigned _Fract' for this target, in bits.
428
50
  unsigned getFractWidth() const { return FractWidth; }
429
50
  unsigned getFractAlign() const { return FractAlign; }
430
431
  /// getLongFractWidth/Align - Return the size of 'signed long _Fract' and
432
  /// 'unsigned long _Fract' for this target, in bits.
433
40
  unsigned getLongFractWidth() const { return LongFractWidth; }
434
40
  unsigned getLongFractAlign() const { return LongFractAlign; }
435
436
  /// getShortAccumScale/IBits - Return the number of fractional/integral bits
437
  /// in a 'signed short _Accum' type.
438
1.46k
  unsigned getShortAccumScale() const { return ShortAccumScale; }
439
0
  unsigned getShortAccumIBits() const {
440
0
    return ShortAccumWidth - ShortAccumScale - 1;
441
0
  }
442
443
  /// getAccumScale/IBits - Return the number of fractional/integral bits
444
  /// in a 'signed _Accum' type.
445
594
  unsigned getAccumScale() const { return AccumScale; }
446
0
  unsigned getAccumIBits() const { return AccumWidth - AccumScale - 1; }
447
448
  /// getLongAccumScale/IBits - Return the number of fractional/integral bits
449
  /// in a 'signed long _Accum' type.
450
92
  unsigned getLongAccumScale() const { return LongAccumScale; }
451
0
  unsigned getLongAccumIBits() const {
452
0
    return LongAccumWidth - LongAccumScale - 1;
453
0
  }
454
455
  /// getUnsignedShortAccumScale/IBits - Return the number of
456
  /// fractional/integral bits in a 'unsigned short _Accum' type.
457
817
  unsigned getUnsignedShortAccumScale() const {
458
817
    return PaddingOnUnsignedFixedPoint ? 
ShortAccumScale394
:
ShortAccumScale + 1423
;
459
817
  }
460
0
  unsigned getUnsignedShortAccumIBits() const {
461
0
    return PaddingOnUnsignedFixedPoint
462
0
               ? getShortAccumIBits()
463
0
               : ShortAccumWidth - getUnsignedShortAccumScale();
464
0
  }
465
466
  /// getUnsignedAccumScale/IBits - Return the number of fractional/integral
467
  /// bits in a 'unsigned _Accum' type.
468
182
  unsigned getUnsignedAccumScale() const {
469
182
    return PaddingOnUnsignedFixedPoint ? 
AccumScale73
:
AccumScale + 1109
;
470
182
  }
471
0
  unsigned getUnsignedAccumIBits() const {
472
0
    return PaddingOnUnsignedFixedPoint ? getAccumIBits()
473
0
                                       : AccumWidth - getUnsignedAccumScale();
474
0
  }
475
476
  /// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral
477
  /// bits in a 'unsigned long _Accum' type.
478
37
  unsigned getUnsignedLongAccumScale() const {
479
37
    return PaddingOnUnsignedFixedPoint ? 
LongAccumScale6
:
LongAccumScale + 131
;
480
37
  }
481
0
  unsigned getUnsignedLongAccumIBits() const {
482
0
    return PaddingOnUnsignedFixedPoint
483
0
               ? getLongAccumIBits()
484
0
               : LongAccumWidth - getUnsignedLongAccumScale();
485
0
  }
486
487
  /// getShortFractScale - Return the number of fractional bits
488
  /// in a 'signed short _Fract' type.
489
151
  unsigned getShortFractScale() const { return ShortFractWidth - 1; }
490
491
  /// getFractScale - Return the number of fractional bits
492
  /// in a 'signed _Fract' type.
493
198
  unsigned getFractScale() const { return FractWidth - 1; }
494
495
  /// getLongFractScale - Return the number of fractional bits
496
  /// in a 'signed long _Fract' type.
497
161
  unsigned getLongFractScale() const { return LongFractWidth - 1; }
498
499
  /// getUnsignedShortFractScale - Return the number of fractional bits
500
  /// in a 'unsigned short _Fract' type.
501
55
  unsigned getUnsignedShortFractScale() const {
502
55
    return PaddingOnUnsignedFixedPoint ? 
getShortFractScale()9
503
55
                                       : 
getShortFractScale() + 146
;
504
55
  }
505
506
  /// getUnsignedFractScale - Return the number of fractional bits
507
  /// in a 'unsigned _Fract' type.
508
91
  unsigned getUnsignedFractScale() const {
509
91
    return PaddingOnUnsignedFixedPoint ? 
getFractScale()27
:
getFractScale() + 164
;
510
91
  }
511
512
  /// getUnsignedLongFractScale - Return the number of fractional bits
513
  /// in a 'unsigned long _Fract' type.
514
51
  unsigned getUnsignedLongFractScale() const {
515
51
    return PaddingOnUnsignedFixedPoint ? 
getLongFractScale()7
516
51
                                       : 
getLongFractScale() + 144
;
517
51
  }
518
519
  /// Determine whether the __int128 type is supported on this target.
520
330k
  virtual bool hasInt128Type() const {
521
330k
    return (getPointerWidth(0) >= 64) || 
getTargetOpts().ForceEnableInt12873.3k
;
522
330k
  } // FIXME
523
524
  /// Determine whether _Float16 is supported on this target.
525
5.93k
  virtual bool hasLegalHalfType() const { return HasLegalHalfType; }
526
527
  /// Determine whether the __float128 type is supported on this target.
528
190k
  virtual bool hasFloat128Type() const { return HasFloat128; }
529
530
  /// Determine whether the _Float16 type is supported on this target.
531
209k
  virtual bool hasFloat16Type() const { return HasFloat16; }
532
533
  /// Return the alignment that is suitable for storing any
534
  /// object with a fundamental alignment requirement.
535
44.2k
  unsigned getSuitableAlign() const { return SuitableAlign; }
536
537
  /// Return the default alignment for __attribute__((aligned)) on
538
  /// this target, to be used if no alignment value is specified.
539
3.24k
  unsigned getDefaultAlignForAttributeAligned() const {
540
3.24k
    return DefaultAlignForAttributeAligned;
541
3.24k
  }
542
543
  /// getMinGlobalAlign - Return the minimum alignment of a global variable,
544
  /// unless its alignment is explicitly reduced via attributes.
545
548k
  virtual unsigned getMinGlobalAlign (uint64_t) const {
546
548k
    return MinGlobalAlign;
547
548k
  }
548
549
  /// Return the largest alignment for which a suitably-sized allocation with
550
  /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
551
  /// pointer.
552
55.7k
  unsigned getNewAlign() const {
553
55.7k
    return NewAlign ? 
NewAlign2.35k
:
std::max(LongDoubleAlign, LongLongAlign)53.4k
;
554
55.7k
  }
555
556
  /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
557
  /// bits.
558
99.3k
  unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
559
95.4k
  unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
560
561
  /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
562
  /// bits.
563
87.0k
  unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
564
86.8k
  unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
565
566
  /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
567
  /// bits.
568
87.0k
  unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
569
86.8k
  unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
570
571
  /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
572
263
  unsigned getHalfWidth() const { return HalfWidth; }
573
263
  unsigned getHalfAlign() const { return HalfAlign; }
574
9.87k
  const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
575
576
  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
577
50.2k
  unsigned getFloatWidth() const { return FloatWidth; }
578
6.09k
  unsigned getFloatAlign() const { return FloatAlign; }
579
434k
  const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
580
581
  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
582
49.5k
  unsigned getDoubleWidth() const { return DoubleWidth; }
583
5.39k
  unsigned getDoubleAlign() const { return DoubleAlign; }
584
310k
  const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
585
586
  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
587
  /// double'.
588
46.0k
  unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
589
1.94k
  unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
590
113k
  const llvm::fltSemantics &getLongDoubleFormat() const {
591
113k
    return *LongDoubleFormat;
592
113k
  }
593
594
  /// getFloat128Width/Align/Format - Return the size/align/format of
595
  /// '__float128'.
596
17
  unsigned getFloat128Width() const { return 128; }
597
17
  unsigned getFloat128Align() const { return Float128Align; }
598
376
  const llvm::fltSemantics &getFloat128Format() const {
599
376
    return *Float128Format;
600
376
  }
601
602
  /// Return the mangled code of long double.
603
113k
  virtual const char *getLongDoubleMangling() const { return "e"; }
604
605
  /// Return the mangled code of __float128.
606
212
  virtual const char *getFloat128Mangling() const { return "g"; }
607
608
  /// Return the value for the C99 FLT_EVAL_METHOD macro.
609
11.1k
  virtual unsigned getFloatEvalMethod() const { return 0; }
610
611
  // getLargeArrayMinWidth/Align - Return the minimum array size that is
612
  // 'large' and its alignment.
613
71.6k
  unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
614
12.4k
  unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
615
616
  /// Return the maximum width lock-free atomic operation which will
617
  /// ever be supported for the given target
618
901
  unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
619
  /// Return the maximum width lock-free atomic operation which can be
620
  /// inlined given the supported features of the given target.
621
88.9k
  unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
622
  /// Set the maximum inline or promote width lock-free atomic operation
623
  /// for the given target.
624
15.3k
  virtual void setMaxAtomicWidth() {}
625
  /// Returns true if the given target supports lock-free atomic
626
  /// operations at the specified width and alignment.
627
  virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
628
1.72k
                                uint64_t AlignmentInBits) const {
629
1.72k
    return AtomicSizeInBits <= AlignmentInBits &&
630
1.72k
           
AtomicSizeInBits <= getMaxAtomicInlineWidth()1.53k
&&
631
1.72k
           
(1.40k
AtomicSizeInBits <= getCharWidth()1.40k
||
632
1.40k
            
llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth())1.14k
);
633
1.72k
  }
634
635
  /// Return the maximum vector alignment supported for the given target.
636
12.9k
  unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
637
  /// Return default simd alignment for the given target. Generally, this
638
  /// value is type-specific, but this alignment can be used for most of the
639
  /// types for the given target.
640
293
  unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
641
642
  /// Return the alignment (in bits) of the thrown exception object. This is
643
  /// only meaningful for targets that allocate C++ exceptions in a system
644
  /// runtime, such as those using the Itanium C++ ABI.
645
3.13k
  virtual unsigned getExnObjectAlignment() const {
646
3.13k
    // Itanium says that an _Unwind_Exception has to be "double-word"
647
3.13k
    // aligned (and thus the end of it is also so-aligned), meaning 16
648
3.13k
    // bytes.  Of course, that was written for the actual Itanium,
649
3.13k
    // which is a 64-bit platform.  Classically, the ABI doesn't really
650
3.13k
    // specify the alignment on other platforms, but in practice
651
3.13k
    // libUnwind declares the struct with __attribute__((aligned)), so
652
3.13k
    // we assume that alignment here.  (It's generally 16 bytes, but
653
3.13k
    // some targets overwrite it.)
654
3.13k
    return getDefaultAlignForAttributeAligned();
655
3.13k
  }
656
657
  /// Return the size of intmax_t and uintmax_t for this target, in bits.
658
6.25M
  unsigned getIntMaxTWidth() const {
659
6.25M
    return getTypeWidth(IntMaxType);
660
6.25M
  }
661
662
  // Return the size of unwind_word for this target.
663
10
  virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
664
665
  /// Return the "preferred" register width on this target.
666
9
  virtual unsigned getRegisterWidth() const {
667
9
    // Currently we assume the register width on the target matches the pointer
668
9
    // width, we can introduce a new variable for this if/when some target wants
669
9
    // it.
670
9
    return PointerWidth;
671
9
  }
672
673
  /// Returns the name of the mcount instrumentation function.
674
90
  const char *getMCountName() const {
675
90
    return MCountName;
676
90
  }
677
678
  /// Check if the Objective-C built-in boolean type should be signed
679
  /// char.
680
  ///
681
  /// Otherwise, if this returns false, the normal built-in boolean type
682
  /// should also be used for Objective-C.
683
85.8k
  bool useSignedCharForObjCBool() const {
684
85.8k
    return UseSignedCharForObjCBool;
685
85.8k
  }
686
164
  void noSignedCharForObjCBool() {
687
164
    UseSignedCharForObjCBool = false;
688
164
  }
689
690
  /// Check whether the alignment of bit-field types is respected
691
  /// when laying out structures.
692
9.77k
  bool useBitFieldTypeAlignment() const {
693
9.77k
    return UseBitFieldTypeAlignment;
694
9.77k
  }
695
696
  /// Check whether zero length bitfields should force alignment of
697
  /// the next member.
698
9.82k
  bool useZeroLengthBitfieldAlignment() const {
699
9.82k
    return UseZeroLengthBitfieldAlignment;
700
9.82k
  }
701
702
  /// Get the fixed alignment value in bits for a member that follows
703
  /// a zero length bitfield.
704
105
  unsigned getZeroLengthBitfieldBoundary() const {
705
105
    return ZeroLengthBitfieldBoundary;
706
105
  }
707
708
  /// Check whether explicit bitfield alignment attributes should be
709
  //  honored, as in "__attribute__((aligned(2))) int b : 1;".
710
293
  bool useExplicitBitFieldAlignment() const {
711
293
    return UseExplicitBitFieldAlignment;
712
293
  }
713
714
  /// Check whether this target support '\#pragma options align=mac68k'.
715
7
  bool hasAlignMac68kSupport() const {
716
7
    return HasAlignMac68kSupport;
717
7
  }
718
719
  /// Return the user string for the specified integer type enum.
720
  ///
721
  /// For example, SignedShort -> "short".
722
  static const char *getTypeName(IntType T);
723
724
  /// Return the constant suffix for the specified integer type enum.
725
  ///
726
  /// For example, SignedLong -> "L".
727
  const char *getTypeConstantSuffix(IntType T) const;
728
729
  /// Return the printf format modifier for the specified
730
  /// integer type enum.
731
  ///
732
  /// For example, SignedLong -> "l".
733
  static const char *getTypeFormatModifier(IntType T);
734
735
  /// Check whether the given real type should use the "fpret" flavor of
736
  /// Objective-C message passing on this target.
737
49
  bool useObjCFPRetForRealType(RealType T) const {
738
49
    return RealTypeUsesObjCFPRet & (1 << T);
739
49
  }
740
741
  /// Check whether _Complex long double should use the "fp2ret" flavor
742
  /// of Objective-C message passing on this target.
743
2
  bool useObjCFP2RetForComplexLongDouble() const {
744
2
    return ComplexLongDoubleUsesFP2Ret;
745
2
  }
746
747
  /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
748
  /// to convert to and from __fp16.
749
  /// FIXME: This function should be removed once all targets stop using the
750
  /// conversion intrinsics.
751
140k
  virtual bool useFP16ConversionIntrinsics() const {
752
140k
    return true;
753
140k
  }
754
755
  /// Specify if mangling based on address space map should be used or
756
  /// not for language specific address spaces
757
41.7k
  bool useAddressSpaceMapMangling() const {
758
41.7k
    return UseAddrSpaceMapMangling;
759
41.7k
  }
760
761
  ///===---- Other target property query methods --------------------------===//
762
763
  /// Appends the target-specific \#define values for this
764
  /// target set to the specified buffer.
765
  virtual void getTargetDefines(const LangOptions &Opts,
766
                                MacroBuilder &Builder) const = 0;
767
768
769
  /// Return information about target-specific builtins for
770
  /// the current primary target, and info about which builtins are non-portable
771
  /// across the current set of primary and secondary targets.
772
  virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0;
773
774
  /// The __builtin_clz* and __builtin_ctz* built-in
775
  /// functions are specified to have undefined results for zero inputs, but
776
  /// on targets that support these operations in a way that provides
777
  /// well-defined results for zero without loss of performance, it is a good
778
  /// idea to avoid optimizing based on that undef behavior.
779
591
  virtual bool isCLZForZeroUndef() const { return true; }
780
781
  /// Returns the kind of __builtin_va_list type that should be used
782
  /// with this target.
783
  virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
784
785
  /// Returns whether or not type \c __builtin_ms_va_list type is
786
  /// available on this target.
787
42.9k
  bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
788
789
  /// Returns true for RenderScript.
790
4.49k
  bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
791
792
  /// Returns whether the passed in string is a valid clobber in an
793
  /// inline asm statement.
794
  ///
795
  /// This is used by Sema.
796
  bool isValidClobber(StringRef Name) const;
797
798
  /// Returns whether the passed in string is a valid register name
799
  /// according to GCC.
800
  ///
801
  /// This is used by Sema for inline asm statements.
802
  virtual bool isValidGCCRegisterName(StringRef Name) const;
803
804
  /// Returns the "normalized" GCC register name.
805
  ///
806
  /// ReturnCannonical true will return the register name without any additions
807
  /// such as "{}" or "%" in it's canonical form, for example:
808
  /// ReturnCanonical = true and Name = "rax", will return "ax".
809
  StringRef getNormalizedGCCRegisterName(StringRef Name,
810
                                         bool ReturnCanonical = false) const;
811
812
  /// Extracts a register from the passed constraint (if it is a
813
  /// single-register constraint) and the asm label expression related to a
814
  /// variable in the input or output list of an inline asm statement.
815
  ///
816
  /// This function is used by Sema in order to diagnose conflicts between
817
  /// the clobber list and the input/output lists.
818
  virtual StringRef getConstraintRegister(StringRef Constraint,
819
2.31k
                                          StringRef Expression) const {
820
2.31k
    return "";
821
2.31k
  }
822
823
  struct ConstraintInfo {
824
    enum {
825
      CI_None = 0x00,
826
      CI_AllowsMemory = 0x01,
827
      CI_AllowsRegister = 0x02,
828
      CI_ReadWrite = 0x04,         // "+r" output constraint (read and write).
829
      CI_HasMatchingInput = 0x08,  // This output operand has a matching input.
830
      CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
831
      CI_EarlyClobber = 0x20,      // "&" output constraint (early clobber).
832
    };
833
    unsigned Flags;
834
    int TiedOperand;
835
    struct {
836
      int Min;
837
      int Max;
838
      bool isConstrained;
839
    } ImmRange;
840
    llvm::SmallSet<int, 4> ImmSet;
841
842
    std::string ConstraintStr;  // constraint: "=rm"
843
    std::string Name;           // Operand name: [foo] with no []'s.
844
  public:
845
    ConstraintInfo(StringRef ConstraintStr, StringRef Name)
846
        : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
847
26.5k
          Name(Name.str()) {
848
26.5k
      ImmRange.Min = ImmRange.Max = 0;
849
26.5k
      ImmRange.isConstrained = false;
850
26.5k
    }
851
852
35.9k
    const std::string &getConstraintStr() const { return ConstraintStr; }
853
164
    const std::string &getName() const { return Name; }
854
1.35k
    bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
855
13.0k
    bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
856
28.1k
    bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
857
52.0k
    bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
858
859
    /// Return true if this output operand has a matching
860
    /// (tied) input operand.
861
932
    bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
862
863
    /// Return true if this input operand is a matching
864
    /// constraint that ties it to an output operand.
865
    ///
866
    /// If this returns true then getTiedOperand will indicate which output
867
    /// operand this is tied to.
868
14.5k
    bool hasTiedOperand() const { return TiedOperand != -1; }
869
197
    unsigned getTiedOperand() const {
870
197
      assert(hasTiedOperand() && "Has no tied operand!");
871
197
      return (unsigned)TiedOperand;
872
197
    }
873
874
7.64k
    bool requiresImmediateConstant() const {
875
7.64k
      return (Flags & CI_ImmediateConstant) != 0;
876
7.64k
    }
877
130
    bool isValidAsmImmediate(const llvm::APInt &Value) const {
878
130
      if (!ImmSet.empty())
879
26
        return Value.isSignedIntN(32) &&
880
26
               
ImmSet.count(Value.getZExtValue()) != 024
;
881
104
      return !ImmRange.isConstrained ||
882
104
             
(70
Value.sge(ImmRange.Min)70
&&
Value.sle(ImmRange.Max)54
);
883
104
    }
884
885
559
    void setIsReadWrite() { Flags |= CI_ReadWrite; }
886
35
    void setEarlyClobber() { Flags |= CI_EarlyClobber; }
887
12.8k
    void setAllowsMemory() { Flags |= CI_AllowsMemory; }
888
14.8k
    void setAllowsRegister() { Flags |= CI_AllowsRegister; }
889
209
    void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
890
132
    void setRequiresImmediate(int Min, int Max) {
891
132
      Flags |= CI_ImmediateConstant;
892
132
      ImmRange.Min = Min;
893
132
      ImmRange.Max = Max;
894
132
      ImmRange.isConstrained = true;
895
132
    }
896
32
    void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
897
32
      Flags |= CI_ImmediateConstant;
898
32
      for (int Exact : Exacts)
899
96
        ImmSet.insert(Exact);
900
32
    }
901
10
    void setRequiresImmediate(int Exact) {
902
10
      Flags |= CI_ImmediateConstant;
903
10
      ImmSet.insert(Exact);
904
10
    }
905
99
    void setRequiresImmediate() {
906
99
      Flags |= CI_ImmediateConstant;
907
99
    }
908
909
    /// Indicate that this is an input operand that is tied to
910
    /// the specified output operand.
911
    ///
912
    /// Copy over the various constraint information from the output.
913
209
    void setTiedOperand(unsigned N, ConstraintInfo &Output) {
914
209
      Output.setHasMatchingInput();
915
209
      Flags = Output.Flags;
916
209
      TiedOperand = N;
917
209
      // Don't copy Name or constraint string.
918
209
    }
919
  };
920
921
  /// Validate register name used for global register variables.
922
  ///
923
  /// This function returns true if the register passed in RegName can be used
924
  /// for global register variables on this target. In addition, it returns
925
  /// true in HasSizeMismatch if the size of the register doesn't match the
926
  /// variable size passed in RegSize.
927
  virtual bool validateGlobalRegisterVariable(StringRef RegName,
928
                                              unsigned RegSize,
929
5
                                              bool &HasSizeMismatch) const {
930
5
    HasSizeMismatch = false;
931
5
    return true;
932
5
  }
933
934
  // validateOutputConstraint, validateInputConstraint - Checks that
935
  // a constraint is valid and provides information about it.
936
  // FIXME: These should return a real error instead of just true/false.
937
  bool validateOutputConstraint(ConstraintInfo &Info) const;
938
  bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints,
939
                               ConstraintInfo &info) const;
940
941
  virtual bool validateOutputSize(StringRef /*Constraint*/,
942
930
                                  unsigned /*Size*/) const {
943
930
    return true;
944
930
  }
945
946
  virtual bool validateInputSize(StringRef /*Constraint*/,
947
2.28k
                                 unsigned /*Size*/) const {
948
2.28k
    return true;
949
2.28k
  }
950
  virtual bool
951
  validateConstraintModifier(StringRef /*Constraint*/,
952
                             char /*Modifier*/,
953
                             unsigned /*Size*/,
954
11.6k
                             std::string &/*SuggestedModifier*/) const {
955
11.6k
    return true;
956
11.6k
  }
957
  virtual bool
958
  validateAsmConstraint(const char *&Name,
959
                        TargetInfo::ConstraintInfo &info) const = 0;
960
961
  bool resolveSymbolicName(const char *&Name,
962
                           ArrayRef<ConstraintInfo> OutputConstraints,
963
                           unsigned &Index) const;
964
965
  // Constraint parm will be left pointing at the last character of
966
  // the constraint.  In practice, it won't be changed unless the
967
  // constraint is longer than one character.
968
1.09k
  virtual std::string convertConstraint(const char *&Constraint) const {
969
1.09k
    // 'p' defaults to 'r', but can be overridden by targets.
970
1.09k
    if (*Constraint == 'p')
971
14
      return std::string("r");
972
1.08k
    return std::string(1, *Constraint);
973
1.08k
  }
974
975
  /// Returns a string of target-specific clobbers, in LLVM format.
976
  virtual const char *getClobbers() const = 0;
977
978
  /// Returns true if NaN encoding is IEEE 754-2008.
979
  /// Only MIPS allows a different encoding.
980
4.06k
  virtual bool isNan2008() const {
981
4.06k
    return true;
982
4.06k
  }
983
984
  /// Returns the target triple of the primary target.
985
29.5M
  const llvm::Triple &getTriple() const {
986
29.5M
    return Triple;
987
29.5M
  }
988
989
85.5k
  const llvm::DataLayout &getDataLayout() const {
990
85.5k
    assert(DataLayout && "Uninitialized DataLayout!");
991
85.5k
    return *DataLayout;
992
85.5k
  }
993
994
  struct GCCRegAlias {
995
    const char * const Aliases[5];
996
    const char * const Register;
997
  };
998
999
  struct AddlRegName {
1000
    const char * const Names[5];
1001
    const unsigned RegNum;
1002
  };
1003
1004
  /// Does this target support "protected" visibility?
1005
  ///
1006
  /// Any target which dynamic libraries will naturally support
1007
  /// something like "default" (meaning that the symbol is visible
1008
  /// outside this shared object) and "hidden" (meaning that it isn't)
1009
  /// visibilities, but "protected" is really an ELF-specific concept
1010
  /// with weird semantics designed around the convenience of dynamic
1011
  /// linker implementations.  Which is not to suggest that there's
1012
  /// consistent target-independent semantics for "default" visibility
1013
  /// either; the entire thing is pretty badly mangled.
1014
29
  virtual bool hasProtectedVisibility() const { return true; }
1015
1016
  /// An optional hook that targets can implement to perform semantic
1017
  /// checking on attribute((section("foo"))) specifiers.
1018
  ///
1019
  /// In this case, "foo" is passed in to be checked.  If the section
1020
  /// specifier is invalid, the backend should return a non-empty string
1021
  /// that indicates the problem.
1022
  ///
1023
  /// This hook is a simple quality of implementation feature to catch errors
1024
  /// and give good diagnostics in cases when the assembler or code generator
1025
  /// would otherwise reject the section specifier.
1026
  ///
1027
225
  virtual std::string isValidSectionSpecifier(StringRef SR) const {
1028
225
    return "";
1029
225
  }
1030
1031
  /// Set forced language options.
1032
  ///
1033
  /// Apply changes to the target information with respect to certain
1034
  /// language options which change the target configuration and adjust
1035
  /// the language based on the target options where applicable.
1036
  virtual void adjust(LangOptions &Opts);
1037
1038
  /// Adjust target options based on codegen options.
1039
  virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
1040
41.5k
                                   TargetOptions &TargetOpts) const {}
1041
1042
  /// Initialize the map with the default set of target features for the
1043
  /// CPU this should include all legal feature strings on the target.
1044
  ///
1045
  /// \return False on error (invalid features).
1046
  virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
1047
                              DiagnosticsEngine &Diags, StringRef CPU,
1048
                              const std::vector<std::string> &FeatureVec) const;
1049
1050
  /// Get the ABI currently in use.
1051
0
  virtual StringRef getABI() const { return StringRef(); }
1052
1053
  /// Get the C++ ABI currently in use.
1054
25.0M
  TargetCXXABI getCXXABI() const {
1055
25.0M
    return TheCXXABI;
1056
25.0M
  }
1057
1058
  /// Target the specified CPU.
1059
  ///
1060
  /// \return  False on error (invalid CPU name).
1061
0
  virtual bool setCPU(const std::string &Name) {
1062
0
    return false;
1063
0
  }
1064
1065
  /// Fill a SmallVectorImpl with the valid values to setCPU.
1066
0
  virtual void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {}
1067
1068
  /// brief Determine whether this TargetInfo supports the given CPU name.
1069
0
  virtual bool isValidCPUName(StringRef Name) const {
1070
0
    return true;
1071
0
  }
1072
1073
  /// Use the specified ABI.
1074
  ///
1075
  /// \return False on error (invalid ABI name).
1076
0
  virtual bool setABI(const std::string &Name) {
1077
0
    return false;
1078
0
  }
1079
1080
  /// Use the specified unit for FP math.
1081
  ///
1082
  /// \return False on error (invalid unit name).
1083
0
  virtual bool setFPMath(StringRef Name) {
1084
0
    return false;
1085
0
  }
1086
1087
  /// Enable or disable a specific target feature;
1088
  /// the feature name must be valid.
1089
  virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
1090
                                 StringRef Name,
1091
92.3k
                                 bool Enabled) const {
1092
92.3k
    Features[Name] = Enabled;
1093
92.3k
  }
1094
1095
  /// Determine whether this TargetInfo supports the given feature.
1096
6
  virtual bool isValidFeatureName(StringRef Feature) const {
1097
6
    return true;
1098
6
  }
1099
1100
  /// Perform initialization based on the user configured
1101
  /// set of features (e.g., +sse4).
1102
  ///
1103
  /// The list is guaranteed to have at most one entry per feature.
1104
  ///
1105
  /// The target may modify the features list, to change which options are
1106
  /// passed onwards to the backend.
1107
  /// FIXME: This part should be fixed so that we can change handleTargetFeatures
1108
  /// to merely a TargetInfo initialization routine.
1109
  ///
1110
  /// \return  False on error.
1111
  virtual bool handleTargetFeatures(std::vector<std::string> &Features,
1112
810
                                    DiagnosticsEngine &Diags) {
1113
810
    return true;
1114
810
  }
1115
1116
  /// Determine whether the given target has the given feature.
1117
35
  virtual bool hasFeature(StringRef Feature) const {
1118
35
    return false;
1119
35
  }
1120
1121
  /// Identify whether this target supports multiversioning of functions,
1122
  /// which requires support for cpu_supports and cpu_is functionality.
1123
372
  bool supportsMultiVersioning() const {
1124
372
    return getTriple().getArch() == llvm::Triple::x86 ||
1125
372
           
getTriple().getArch() == llvm::Triple::x86_64369
;
1126
372
  }
1127
1128
  /// Identify whether this target supports IFuncs.
1129
288
  bool supportsIFunc() const { return getTriple().isOSBinFormatELF(); }
1130
1131
  // Validate the contents of the __builtin_cpu_supports(const char*)
1132
  // argument.
1133
0
  virtual bool validateCpuSupports(StringRef Name) const { return false; }
1134
1135
  // Return the target-specific priority for features/cpus/vendors so
1136
  // that they can be properly sorted for checking.
1137
0
  virtual unsigned multiVersionSortPriority(StringRef Name) const {
1138
0
    return 0;
1139
0
  }
1140
1141
  // Validate the contents of the __builtin_cpu_is(const char*)
1142
  // argument.
1143
0
  virtual bool validateCpuIs(StringRef Name) const { return false; }
1144
1145
  // Validate a cpu_dispatch/cpu_specific CPU option, which is a different list
1146
  // from cpu_is, since it checks via features rather than CPUs directly.
1147
0
  virtual bool validateCPUSpecificCPUDispatch(StringRef Name) const {
1148
0
    return false;
1149
0
  }
1150
1151
  // Get the character to be added for mangling purposes for cpu_specific.
1152
0
  virtual char CPUSpecificManglingCharacter(StringRef Name) const {
1153
0
    llvm_unreachable(
1154
0
        "cpu_specific Multiversioning not implemented on this target");
1155
0
  }
1156
1157
  // Get a list of the features that make up the CPU option for
1158
  // cpu_specific/cpu_dispatch so that it can be passed to llvm as optimization
1159
  // options.
1160
  virtual void getCPUSpecificCPUDispatchFeatures(
1161
0
      StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1162
0
    llvm_unreachable(
1163
0
        "cpu_specific Multiversioning not implemented on this target");
1164
0
  }
1165
1166
  // Returns maximal number of args passed in registers.
1167
136
  unsigned getRegParmMax() const {
1168
136
    assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
1169
136
    return RegParmMax;
1170
136
  }
1171
1172
  /// Whether the target supports thread-local storage.
1173
4.80M
  bool isTLSSupported() const {
1174
4.80M
    return TLSSupported;
1175
4.80M
  }
1176
1177
  /// Return the maximum alignment (in bits) of a TLS variable
1178
  ///
1179
  /// Gets the maximum alignment (in bits) of a TLS variable on this target.
1180
  /// Returns zero if there is no such constraint.
1181
2.56M
  unsigned short getMaxTLSAlign() const {
1182
2.56M
    return MaxTLSAlign;
1183
2.56M
  }
1184
1185
  /// Whether target supports variable-length arrays.
1186
5.42k
  bool isVLASupported() const { return VLASupported; }
1187
1188
  /// Whether the target supports SEH __try.
1189
258
  bool isSEHTrySupported() const {
1190
258
    return getTriple().isOSWindows() &&
1191
258
           (getTriple().getArch() == llvm::Triple::x86 ||
1192
258
            
getTriple().getArch() == llvm::Triple::x86_64217
||
1193
258
            
getTriple().getArch() == llvm::Triple::aarch6424
);
1194
258
  }
1195
1196
  /// Return true if {|} are normal characters in the asm string.
1197
  ///
1198
  /// If this returns false (the default), then {abc|xyz} is syntax
1199
  /// that says that when compiling for asm variant #0, "abc" should be
1200
  /// generated, but when compiling for asm variant #1, "xyz" should be
1201
  /// generated.
1202
30.4k
  bool hasNoAsmVariants() const {
1203
30.4k
    return NoAsmVariants;
1204
30.4k
  }
1205
1206
  /// Return the register number that __builtin_eh_return_regno would
1207
  /// return with the specified argument.
1208
  /// This corresponds with TargetLowering's getExceptionPointerRegister
1209
  /// and getExceptionSelectorRegister in the backend.
1210
0
  virtual int getEHDataRegisterNumber(unsigned RegNo) const {
1211
0
    return -1;
1212
0
  }
1213
1214
  /// Return the section to use for C++ static initialization functions.
1215
7.35k
  virtual const char *getStaticInitSectionSpecifier() const {
1216
7.35k
    return nullptr;
1217
7.35k
  }
1218
1219
41.6k
  const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; }
1220
1221
  /// Map from the address space field in builtin description strings to the
1222
  /// language address space.
1223
0
  virtual LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const {
1224
0
    return getLangASFromTargetAS(AS);
1225
0
  }
1226
1227
  /// Map from the address space field in builtin description strings to the
1228
  /// language address space.
1229
0
  virtual LangAS getCUDABuiltinAddressSpace(unsigned AS) const {
1230
0
    return getLangASFromTargetAS(AS);
1231
0
  }
1232
1233
  /// Return an AST address space which can be used opportunistically
1234
  /// for constant global memory. It must be possible to convert pointers into
1235
  /// this address space to LangAS::Default. If no such address space exists,
1236
  /// this may return None, and such optimizations will be disabled.
1237
257k
  virtual llvm::Optional<LangAS> getConstantAddressSpace() const {
1238
257k
    return LangAS::Default;
1239
257k
  }
1240
1241
  /// Retrieve the name of the platform as it is used in the
1242
  /// availability attribute.
1243
490k
  StringRef getPlatformName() const { return PlatformName; }
1244
1245
  /// Retrieve the minimum desired version of the platform, to
1246
  /// which the program should be compiled.
1247
374k
  VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
1248
1249
83.2k
  bool isBigEndian() const { return BigEndian; }
1250
821
  bool isLittleEndian() const { return !BigEndian; }
1251
1252
  enum CallingConvMethodType {
1253
    CCMT_Unknown,
1254
    CCMT_Member,
1255
    CCMT_NonMember
1256
  };
1257
1258
  /// Gets the default calling convention for the given target and
1259
  /// declaration context.
1260
4.13M
  virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
1261
4.13M
    // Not all targets will specify an explicit calling convention that we can
1262
4.13M
    // express.  This will always do the right thing, even though it's not
1263
4.13M
    // an explicit calling convention.
1264
4.13M
    return CC_C;
1265
4.13M
  }
1266
1267
  enum CallingConvCheckResult {
1268
    CCCR_OK,
1269
    CCCR_Warning,
1270
    CCCR_Ignore,
1271
    CCCR_Error,
1272
  };
1273
1274
  /// Determines whether a given calling convention is valid for the
1275
  /// target. A calling convention can either be accepted, produce a warning
1276
  /// and be substituted with the default calling convention, or (someday)
1277
  /// produce an error (such as using thiscall on a non-instance function).
1278
  virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1279
    switch (CC) {
1280
      default:
1281
        return CCCR_Warning;
1282
      case CC_C:
1283
        return CCCR_OK;
1284
    }
1285
  }
1286
1287
  enum CallingConvKind {
1288
    CCK_Default,
1289
    CCK_ClangABI4OrPS4,
1290
    CCK_MicrosoftWin64
1291
  };
1292
1293
  virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
1294
1295
  /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
1296
  /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
1297
6
  virtual bool hasSjLjLowering() const {
1298
6
    return false;
1299
6
  }
1300
1301
  /// Check if the target supports CFProtection branch.
1302
  virtual bool
1303
  checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const;
1304
1305
  /// Check if the target supports CFProtection branch.
1306
  virtual bool
1307
  checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const;
1308
1309
  /// Whether target allows to overalign ABI-specified preferred alignment
1310
1.82M
  virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1311
1312
  /// Set supported OpenCL extensions and optional core features.
1313
14.6k
  virtual void setSupportedOpenCLOpts() {}
1314
1315
  /// Set supported OpenCL extensions as written on command line
1316
48.5k
  virtual void setOpenCLExtensionOpts() {
1317
48.5k
    for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1318
28
      getTargetOpts().SupportedOpenCLOptions.support(Ext);
1319
28
    }
1320
48.5k
  }
1321
1322
  /// Get supported OpenCL extensions and optional core features.
1323
33.9k
  OpenCLOptions &getSupportedOpenCLOpts() {
1324
33.9k
    return getTargetOpts().SupportedOpenCLOptions;
1325
33.9k
  }
1326
1327
  /// Get const supported OpenCL extensions and optional core features.
1328
25.5k
  const OpenCLOptions &getSupportedOpenCLOpts() const {
1329
25.5k
      return getTargetOpts().SupportedOpenCLOptions;
1330
25.5k
  }
1331
1332
  enum OpenCLTypeKind {
1333
    OCLTK_Default,
1334
    OCLTK_ClkEvent,
1335
    OCLTK_Event,
1336
    OCLTK_Image,
1337
    OCLTK_Pipe,
1338
    OCLTK_Queue,
1339
    OCLTK_ReserveID,
1340
    OCLTK_Sampler,
1341
  };
1342
1343
  /// Get address space for OpenCL type.
1344
  virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
1345
1346
  /// \returns Target specific vtbl ptr address space.
1347
39
  virtual unsigned getVtblPtrAddressSpace() const {
1348
39
    return 0;
1349
39
  }
1350
1351
  /// \returns If a target requires an address within a target specific address
1352
  /// space \p AddressSpace to be converted in order to be used, then return the
1353
  /// corresponding target specific DWARF address space.
1354
  ///
1355
  /// \returns Otherwise return None and no conversion will be emitted in the
1356
  /// DWARF.
1357
5.72k
  virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
1358
5.72k
    return None;
1359
5.72k
  }
1360
1361
  /// \returns The version of the SDK which was used during the compilation if
1362
  /// one was specified, or an empty version otherwise.
1363
19.2k
  const llvm::VersionTuple &getSDKVersion() const {
1364
19.2k
    return getTargetOpts().SDKVersion;
1365
19.2k
  }
1366
1367
  /// Check the target is valid after it is fully initialized.
1368
48.3k
  virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1369
48.3k
    return true;
1370
48.3k
  }
1371
1372
62
  virtual void setAuxTarget(const TargetInfo *Aux) {}
1373
1374
protected:
1375
  /// Copy type and layout related info.
1376
  void copyAuxTarget(const TargetInfo *Aux);
1377
433
  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1378
433
    return PointerWidth;
1379
433
  }
1380
362
  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1381
362
    return PointerAlign;
1382
362
  }
1383
0
  virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1384
0
    return PtrDiffType;
1385
0
  }
1386
  virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1387
  virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1388
5.39k
  virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1389
5.39k
    return None;
1390
5.39k
  }
1391
1392
 private:
1393
  // Assert the values for the fractional and integral bits for each fixed point
1394
  // type follow the restrictions given in clause 6.2.6.3 of N1169.
1395
  void CheckFixedPointBits() const;
1396
};
1397
1398
}  // end namespace clang
1399
1400
#endif