Coverage Report

Created: 2020-09-22 08:39

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