Coverage Report

Created: 2019-02-20 07:29

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