Coverage Report

Created: 2018-09-19 20:53

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