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