Coverage Report

Created: 2020-02-15 09:57

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