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