1 //===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Defines the clang::TargetInfo interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
15 #define LLVM_CLANG_BASIC_TARGETINFO_H
17 #include "clang/Basic/AddressSpaces.h"
18 #include "clang/Basic/CodeGenOptions.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/LangOptions.h"
21 #include "clang/Basic/Specifiers.h"
22 #include "clang/Basic/TargetCXXABI.h"
23 #include "clang/Basic/TargetOptions.h"
24 #include "llvm/ADT/APFloat.h"
25 #include "llvm/ADT/APInt.h"
26 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/ADT/IntrusiveRefCntPtr.h"
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/ADT/SmallSet.h"
30 #include "llvm/ADT/StringMap.h"
31 #include "llvm/ADT/StringRef.h"
32 #include "llvm/ADT/Triple.h"
33 #include "llvm/Frontend/OpenMP/OMPGridValues.h"
34 #include "llvm/Support/DataTypes.h"
35 #include "llvm/Support/VersionTuple.h"
46 class DiagnosticsEngine;
54 namespace Builtin { struct Info; }
56 /// Fields controlling how types are laid out in memory; these may need to
57 /// be copied for targets like AMDGPU that base their ABIs on an auxiliary
59 struct TransferrableTargetInfo {
60 unsigned char PointerWidth, PointerAlign;
61 unsigned char BoolWidth, BoolAlign;
62 unsigned char IntWidth, IntAlign;
63 unsigned char HalfWidth, HalfAlign;
64 unsigned char BFloat16Width, BFloat16Align;
65 unsigned char FloatWidth, FloatAlign;
66 unsigned char DoubleWidth, DoubleAlign;
67 unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align;
68 unsigned char LargeArrayMinWidth, LargeArrayAlign;
69 unsigned char LongWidth, LongAlign;
70 unsigned char LongLongWidth, LongLongAlign;
72 // Fixed point bit widths
73 unsigned char ShortAccumWidth, ShortAccumAlign;
74 unsigned char AccumWidth, AccumAlign;
75 unsigned char LongAccumWidth, LongAccumAlign;
76 unsigned char ShortFractWidth, ShortFractAlign;
77 unsigned char FractWidth, FractAlign;
78 unsigned char LongFractWidth, LongFractAlign;
80 // If true, unsigned fixed point types have the same number of fractional bits
81 // as their signed counterparts, forcing the unsigned types to have one extra
82 // bit of padding. Otherwise, unsigned fixed point types have
83 // one more fractional bit than its corresponding signed type. This is false
85 bool PaddingOnUnsignedFixedPoint;
87 // Fixed point integral and fractional bit sizes
88 // Saturated types share the same integral/fractional bits as their
89 // corresponding unsaturated types.
90 // For simplicity, the fractional bits in a _Fract type will be one less the
91 // width of that _Fract type. This leaves all signed _Fract types having no
92 // padding and unsigned _Fract types will only have 1 bit of padding after the
93 // sign if PaddingOnUnsignedFixedPoint is set.
94 unsigned char ShortAccumScale;
95 unsigned char AccumScale;
96 unsigned char LongAccumScale;
98 unsigned char SuitableAlign;
99 unsigned char DefaultAlignForAttributeAligned;
100 unsigned char MinGlobalAlign;
102 unsigned short NewAlign;
103 unsigned short MaxVectorAlign;
104 unsigned short MaxTLSAlign;
106 const llvm::fltSemantics *HalfFormat, *BFloat16Format, *FloatFormat,
107 *DoubleFormat, *LongDoubleFormat, *Float128Format;
109 ///===---- Target Data Type Query Methods -------------------------------===//
132 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
133 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
136 /// Whether Objective-C's built-in boolean type should be signed char.
138 /// Otherwise, when this flag is not set, the normal built-in boolean type is
140 unsigned UseSignedCharForObjCBool : 1;
142 /// Control whether the alignment of bit-field types is respected when laying
143 /// out structures. If true, then the alignment of the bit-field type will be
144 /// used to (a) impact the alignment of the containing structure, and (b)
145 /// ensure that the individual bit-field will not straddle an alignment
147 unsigned UseBitFieldTypeAlignment : 1;
149 /// Whether zero length bitfields (e.g., int : 0;) force alignment of
150 /// the next bitfield.
152 /// If the alignment of the zero length bitfield is greater than the member
153 /// that follows it, `bar', `bar' will be aligned as the type of the
154 /// zero-length bitfield.
155 unsigned UseZeroLengthBitfieldAlignment : 1;
157 /// Whether explicit bit field alignment attributes are honored.
158 unsigned UseExplicitBitFieldAlignment : 1;
160 /// If non-zero, specifies a fixed alignment value for bitfields that follow
161 /// zero length bitfield, regardless of the zero length bitfield type.
162 unsigned ZeroLengthBitfieldBoundary;
165 /// OpenCL type kinds.
166 enum OpenCLTypeKind : uint8_t {
177 /// Exposes information about the current target.
179 class TargetInfo : public virtual TransferrableTargetInfo,
180 public RefCountedBase<TargetInfo> {
181 std::shared_ptr<TargetOptions> TargetOpts;
184 // Target values set by the ctor of the actual target implementation. Default
185 // values are specified by the TargetInfo constructor.
189 bool NoAsmVariants; // True if {|} are normal characters.
190 bool HasLegalHalfType; // True if the backend supports operations on the half
197 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
198 unsigned short SimdDefaultAlign;
199 std::unique_ptr<llvm::DataLayout> DataLayout;
200 const char *MCountName;
201 unsigned char RegParmMax, SSERegParmMax;
202 TargetCXXABI TheCXXABI;
203 const LangASMap *AddrSpaceMap;
204 const unsigned *GridValues =
205 nullptr; // Array of target-specific GPU grid values that must be
206 // consistent between host RTL (plugin), device RTL, and clang.
208 mutable StringRef PlatformName;
209 mutable VersionTuple PlatformMinVersion;
211 unsigned HasAlignMac68kSupport : 1;
212 unsigned RealTypeUsesObjCFPRet : 3;
213 unsigned ComplexLongDoubleUsesFP2Ret : 1;
215 unsigned HasBuiltinMSVaList : 1;
217 unsigned IsRenderScriptTarget : 1;
219 unsigned HasAArch64SVETypes : 1;
221 unsigned ARMCDECoprocMask : 8;
223 unsigned MaxOpenCLWorkGroupSize;
225 // TargetInfo Constructor. Default initializes all fields.
226 TargetInfo(const llvm::Triple &T);
228 void resetDataLayout(StringRef DL);
231 /// Construct a target for the given options.
233 /// \param Opts - The options to use to initialize the target. The target may
234 /// modify the options to canonicalize the target feature information to match
235 /// what the backend expects.
237 CreateTargetInfo(DiagnosticsEngine &Diags,
238 const std::shared_ptr<TargetOptions> &Opts);
240 virtual ~TargetInfo();
242 /// Retrieve the target options.
243 TargetOptions &getTargetOpts() const {
244 assert(TargetOpts && "Missing target options");
248 /// The different kinds of __builtin_va_list types defined by
249 /// the target implementation.
250 enum BuiltinVaListKind {
251 /// typedef char* __builtin_va_list;
252 CharPtrBuiltinVaList = 0,
254 /// typedef void* __builtin_va_list;
255 VoidPtrBuiltinVaList,
257 /// __builtin_va_list as defined by the AArch64 ABI
258 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
259 AArch64ABIBuiltinVaList,
261 /// __builtin_va_list as defined by the PNaCl ABI:
262 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
263 PNaClABIBuiltinVaList,
265 /// __builtin_va_list as defined by the Power ABI:
266 /// https://www.power.org
267 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
268 PowerABIBuiltinVaList,
270 /// __builtin_va_list as defined by the x86-64 ABI:
271 /// http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
272 X86_64ABIBuiltinVaList,
274 /// __builtin_va_list as defined by ARM AAPCS ABI
275 /// http://infocenter.arm.com
276 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
277 AAPCSABIBuiltinVaList,
279 // typedef struct __va_list_tag
283 // void *__overflow_arg_area;
284 // void *__reg_save_area;
286 SystemZBuiltinVaList,
288 // typedef struct __va_list_tag {
289 // void *__current_saved_reg_area_pointer;
290 // void *__saved_reg_area_end_pointer;
291 // void *__overflow_area_pointer;
297 /// Specify if mangling based on address space map should be used or
298 /// not for language specific address spaces
299 bool UseAddrSpaceMapMangling;
302 IntType getSizeType() const { return SizeType; }
303 IntType getSignedSizeType() const {
311 case UnsignedLongLong:
312 return SignedLongLong;
314 llvm_unreachable("Invalid SizeType");
317 IntType getIntMaxType() const { return IntMaxType; }
318 IntType getUIntMaxType() const {
319 return getCorrespondingUnsignedType(IntMaxType);
321 IntType getPtrDiffType(unsigned AddrSpace) const {
322 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
324 IntType getUnsignedPtrDiffType(unsigned AddrSpace) const {
325 return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
327 IntType getIntPtrType() const { return IntPtrType; }
328 IntType getUIntPtrType() const {
329 return getCorrespondingUnsignedType(IntPtrType);
331 IntType getWCharType() const { return WCharType; }
332 IntType getWIntType() const { return WIntType; }
333 IntType getChar16Type() const { return Char16Type; }
334 IntType getChar32Type() const { return Char32Type; }
335 IntType getInt64Type() const { return Int64Type; }
336 IntType getUInt64Type() const {
337 return getCorrespondingUnsignedType(Int64Type);
339 IntType getSigAtomicType() const { return SigAtomicType; }
340 IntType getProcessIDType() const { return ProcessIDType; }
342 static IntType getCorrespondingUnsignedType(IntType T) {
347 return UnsignedShort;
353 return UnsignedLongLong;
355 llvm_unreachable("Unexpected signed integer type");
359 /// In the event this target uses the same number of fractional bits for its
360 /// unsigned types as it does with its signed counterparts, there will be
361 /// exactly one bit of padding.
362 /// Return true if unsigned fixed point types have padding for this target.
363 bool doUnsignedFixedPointTypesHavePadding() const {
364 return PaddingOnUnsignedFixedPoint;
367 /// Return the width (in bits) of the specified integer type enum.
369 /// For example, SignedInt -> getIntWidth().
370 unsigned getTypeWidth(IntType T) const;
372 /// Return integer type with specified width.
373 virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
375 /// Return the smallest integer type with at least the specified width.
376 virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
377 bool IsSigned) const;
379 /// Return floating point type with specified width. On PPC, there are
380 /// three possible types for 128-bit floating point: "PPC double-double",
381 /// IEEE 754R quad precision, and "long double" (which under the covers
382 /// is represented as one of those two). At this time, there is no support
383 /// for an explicit "PPC double-double" type (i.e. __ibm128) so we only
384 /// need to differentiate between "long double" and IEEE quad precision.
385 RealType getRealTypeByWidth(unsigned BitWidth, bool ExplicitIEEE) const;
387 /// Return the alignment (in bits) of the specified integer type enum.
389 /// For example, SignedInt -> getIntAlign().
390 unsigned getTypeAlign(IntType T) const;
392 /// Returns true if the type is signed; false otherwise.
393 static bool isTypeSigned(IntType T);
395 /// Return the width of pointers on this target, for the
396 /// specified address space.
397 uint64_t getPointerWidth(unsigned AddrSpace) const {
398 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
400 uint64_t getPointerAlign(unsigned AddrSpace) const {
401 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
404 /// Return the maximum width of pointers on this target.
405 virtual uint64_t getMaxPointerWidth() const {
409 /// Get integer value for null pointer.
410 /// \param AddrSpace address space of pointee in source language.
411 virtual uint64_t getNullPointerValue(LangAS AddrSpace) const { return 0; }
413 /// Return the size of '_Bool' and C++ 'bool' for this target, in bits.
414 unsigned getBoolWidth() const { return BoolWidth; }
416 /// Return the alignment of '_Bool' and C++ 'bool' for this target.
417 unsigned getBoolAlign() const { return BoolAlign; }
419 unsigned getCharWidth() const { return 8; } // FIXME
420 unsigned getCharAlign() const { return 8; } // FIXME
422 /// Return the size of 'signed short' and 'unsigned short' for this
424 unsigned getShortWidth() const { return 16; } // FIXME
426 /// Return the alignment of 'signed short' and 'unsigned short' for
428 unsigned getShortAlign() const { return 16; } // FIXME
430 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
431 /// this target, in bits.
432 unsigned getIntWidth() const { return IntWidth; }
433 unsigned getIntAlign() const { return IntAlign; }
435 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
436 /// for this target, in bits.
437 unsigned getLongWidth() const { return LongWidth; }
438 unsigned getLongAlign() const { return LongAlign; }
440 /// getLongLongWidth/Align - Return the size of 'signed long long' and
441 /// 'unsigned long long' for this target, in bits.
442 unsigned getLongLongWidth() const { return LongLongWidth; }
443 unsigned getLongLongAlign() const { return LongLongAlign; }
445 /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
446 /// 'unsigned short _Accum' for this target, in bits.
447 unsigned getShortAccumWidth() const { return ShortAccumWidth; }
448 unsigned getShortAccumAlign() const { return ShortAccumAlign; }
450 /// getAccumWidth/Align - Return the size of 'signed _Accum' and
451 /// 'unsigned _Accum' for this target, in bits.
452 unsigned getAccumWidth() const { return AccumWidth; }
453 unsigned getAccumAlign() const { return AccumAlign; }
455 /// getLongAccumWidth/Align - Return the size of 'signed long _Accum' and
456 /// 'unsigned long _Accum' for this target, in bits.
457 unsigned getLongAccumWidth() const { return LongAccumWidth; }
458 unsigned getLongAccumAlign() const { return LongAccumAlign; }
460 /// getShortFractWidth/Align - Return the size of 'signed short _Fract' and
461 /// 'unsigned short _Fract' for this target, in bits.
462 unsigned getShortFractWidth() const { return ShortFractWidth; }
463 unsigned getShortFractAlign() const { return ShortFractAlign; }
465 /// getFractWidth/Align - Return the size of 'signed _Fract' and
466 /// 'unsigned _Fract' for this target, in bits.
467 unsigned getFractWidth() const { return FractWidth; }
468 unsigned getFractAlign() const { return FractAlign; }
470 /// getLongFractWidth/Align - Return the size of 'signed long _Fract' and
471 /// 'unsigned long _Fract' for this target, in bits.
472 unsigned getLongFractWidth() const { return LongFractWidth; }
473 unsigned getLongFractAlign() const { return LongFractAlign; }
475 /// getShortAccumScale/IBits - Return the number of fractional/integral bits
476 /// in a 'signed short _Accum' type.
477 unsigned getShortAccumScale() const { return ShortAccumScale; }
478 unsigned getShortAccumIBits() const {
479 return ShortAccumWidth - ShortAccumScale - 1;
482 /// getAccumScale/IBits - Return the number of fractional/integral bits
483 /// in a 'signed _Accum' type.
484 unsigned getAccumScale() const { return AccumScale; }
485 unsigned getAccumIBits() const { return AccumWidth - AccumScale - 1; }
487 /// getLongAccumScale/IBits - Return the number of fractional/integral bits
488 /// in a 'signed long _Accum' type.
489 unsigned getLongAccumScale() const { return LongAccumScale; }
490 unsigned getLongAccumIBits() const {
491 return LongAccumWidth - LongAccumScale - 1;
494 /// getUnsignedShortAccumScale/IBits - Return the number of
495 /// fractional/integral bits in a 'unsigned short _Accum' type.
496 unsigned getUnsignedShortAccumScale() const {
497 return PaddingOnUnsignedFixedPoint ? ShortAccumScale : ShortAccumScale + 1;
499 unsigned getUnsignedShortAccumIBits() const {
500 return PaddingOnUnsignedFixedPoint
501 ? getShortAccumIBits()
502 : ShortAccumWidth - getUnsignedShortAccumScale();
505 /// getUnsignedAccumScale/IBits - Return the number of fractional/integral
506 /// bits in a 'unsigned _Accum' type.
507 unsigned getUnsignedAccumScale() const {
508 return PaddingOnUnsignedFixedPoint ? AccumScale : AccumScale + 1;
510 unsigned getUnsignedAccumIBits() const {
511 return PaddingOnUnsignedFixedPoint ? getAccumIBits()
512 : AccumWidth - getUnsignedAccumScale();
515 /// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral
516 /// bits in a 'unsigned long _Accum' type.
517 unsigned getUnsignedLongAccumScale() const {
518 return PaddingOnUnsignedFixedPoint ? LongAccumScale : LongAccumScale + 1;
520 unsigned getUnsignedLongAccumIBits() const {
521 return PaddingOnUnsignedFixedPoint
522 ? getLongAccumIBits()
523 : LongAccumWidth - getUnsignedLongAccumScale();
526 /// getShortFractScale - Return the number of fractional bits
527 /// in a 'signed short _Fract' type.
528 unsigned getShortFractScale() const { return ShortFractWidth - 1; }
530 /// getFractScale - Return the number of fractional bits
531 /// in a 'signed _Fract' type.
532 unsigned getFractScale() const { return FractWidth - 1; }
534 /// getLongFractScale - Return the number of fractional bits
535 /// in a 'signed long _Fract' type.
536 unsigned getLongFractScale() const { return LongFractWidth - 1; }
538 /// getUnsignedShortFractScale - Return the number of fractional bits
539 /// in a 'unsigned short _Fract' type.
540 unsigned getUnsignedShortFractScale() const {
541 return PaddingOnUnsignedFixedPoint ? getShortFractScale()
542 : getShortFractScale() + 1;
545 /// getUnsignedFractScale - Return the number of fractional bits
546 /// in a 'unsigned _Fract' type.
547 unsigned getUnsignedFractScale() const {
548 return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1;
551 /// getUnsignedLongFractScale - Return the number of fractional bits
552 /// in a 'unsigned long _Fract' type.
553 unsigned getUnsignedLongFractScale() const {
554 return PaddingOnUnsignedFixedPoint ? getLongFractScale()
555 : getLongFractScale() + 1;
558 /// Determine whether the __int128 type is supported on this target.
559 virtual bool hasInt128Type() const {
560 return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128;
563 /// Determine whether the _ExtInt type is supported on this target. This
564 /// limitation is put into place for ABI reasons.
565 virtual bool hasExtIntType() const {
569 /// Determine whether _Float16 is supported on this target.
570 virtual bool hasLegalHalfType() const { return HasLegalHalfType; }
572 /// Determine whether the __float128 type is supported on this target.
573 virtual bool hasFloat128Type() const { return HasFloat128; }
575 /// Determine whether the _Float16 type is supported on this target.
576 virtual bool hasFloat16Type() const { return HasFloat16; }
578 /// Determine whether the _BFloat16 type is supported on this target.
579 virtual bool hasBFloat16Type() const { return HasBFloat16; }
581 /// Determine whether constrained floating point is supported on this target.
582 virtual bool hasStrictFP() const { return HasStrictFP; }
584 /// Return the alignment that is suitable for storing any
585 /// object with a fundamental alignment requirement.
586 unsigned getSuitableAlign() const { return SuitableAlign; }
588 /// Return the default alignment for __attribute__((aligned)) on
589 /// this target, to be used if no alignment value is specified.
590 unsigned getDefaultAlignForAttributeAligned() const {
591 return DefaultAlignForAttributeAligned;
594 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
595 /// unless its alignment is explicitly reduced via attributes.
596 virtual unsigned getMinGlobalAlign (uint64_t) const {
597 return MinGlobalAlign;
600 /// Return the largest alignment for which a suitably-sized allocation with
601 /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
603 unsigned getNewAlign() const {
604 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
607 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
609 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
610 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
612 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
614 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
615 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
617 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
619 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
620 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
622 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
623 unsigned getHalfWidth() const { return HalfWidth; }
624 unsigned getHalfAlign() const { return HalfAlign; }
625 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
627 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
628 unsigned getFloatWidth() const { return FloatWidth; }
629 unsigned getFloatAlign() const { return FloatAlign; }
630 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
632 /// getBFloat16Width/Align/Format - Return the size/align/format of '__bf16'.
633 unsigned getBFloat16Width() const { return BFloat16Width; }
634 unsigned getBFloat16Align() const { return BFloat16Align; }
635 const llvm::fltSemantics &getBFloat16Format() const { return *BFloat16Format; }
637 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
638 unsigned getDoubleWidth() const { return DoubleWidth; }
639 unsigned getDoubleAlign() const { return DoubleAlign; }
640 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
642 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
644 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
645 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
646 const llvm::fltSemantics &getLongDoubleFormat() const {
647 return *LongDoubleFormat;
650 /// getFloat128Width/Align/Format - Return the size/align/format of
652 unsigned getFloat128Width() const { return 128; }
653 unsigned getFloat128Align() const { return Float128Align; }
654 const llvm::fltSemantics &getFloat128Format() const {
655 return *Float128Format;
658 /// Return the mangled code of long double.
659 virtual const char *getLongDoubleMangling() const { return "e"; }
661 /// Return the mangled code of __float128.
662 virtual const char *getFloat128Mangling() const { return "g"; }
664 /// Return the mangled code of bfloat.
665 virtual const char *getBFloat16Mangling() const {
666 llvm_unreachable("bfloat not implemented on this target");
669 /// Return the value for the C99 FLT_EVAL_METHOD macro.
670 virtual unsigned getFloatEvalMethod() const { return 0; }
672 // getLargeArrayMinWidth/Align - Return the minimum array size that is
673 // 'large' and its alignment.
674 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
675 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
677 /// Return the maximum width lock-free atomic operation which will
678 /// ever be supported for the given target
679 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
680 /// Return the maximum width lock-free atomic operation which can be
681 /// inlined given the supported features of the given target.
682 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
683 /// Set the maximum inline or promote width lock-free atomic operation
684 /// for the given target.
685 virtual void setMaxAtomicWidth() {}
686 /// Returns true if the given target supports lock-free atomic
687 /// operations at the specified width and alignment.
688 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
689 uint64_t AlignmentInBits) const {
690 return AtomicSizeInBits <= AlignmentInBits &&
691 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
692 (AtomicSizeInBits <= getCharWidth() ||
693 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
696 /// Return the maximum vector alignment supported for the given target.
697 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
698 /// Return default simd alignment for the given target. Generally, this
699 /// value is type-specific, but this alignment can be used for most of the
700 /// types for the given target.
701 unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
703 unsigned getMaxOpenCLWorkGroupSize() const { return MaxOpenCLWorkGroupSize; }
705 /// Return the alignment (in bits) of the thrown exception object. This is
706 /// only meaningful for targets that allocate C++ exceptions in a system
707 /// runtime, such as those using the Itanium C++ ABI.
708 virtual unsigned getExnObjectAlignment() const {
709 // Itanium says that an _Unwind_Exception has to be "double-word"
710 // aligned (and thus the end of it is also so-aligned), meaning 16
711 // bytes. Of course, that was written for the actual Itanium,
712 // which is a 64-bit platform. Classically, the ABI doesn't really
713 // specify the alignment on other platforms, but in practice
714 // libUnwind declares the struct with __attribute__((aligned)), so
715 // we assume that alignment here. (It's generally 16 bytes, but
716 // some targets overwrite it.)
717 return getDefaultAlignForAttributeAligned();
720 /// Return the size of intmax_t and uintmax_t for this target, in bits.
721 unsigned getIntMaxTWidth() const {
722 return getTypeWidth(IntMaxType);
725 // Return the size of unwind_word for this target.
726 virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
728 /// Return the "preferred" register width on this target.
729 virtual unsigned getRegisterWidth() const {
730 // Currently we assume the register width on the target matches the pointer
731 // width, we can introduce a new variable for this if/when some target wants
736 /// Returns the name of the mcount instrumentation function.
737 const char *getMCountName() const {
741 /// Check if the Objective-C built-in boolean type should be signed
744 /// Otherwise, if this returns false, the normal built-in boolean type
745 /// should also be used for Objective-C.
746 bool useSignedCharForObjCBool() const {
747 return UseSignedCharForObjCBool;
749 void noSignedCharForObjCBool() {
750 UseSignedCharForObjCBool = false;
753 /// Check whether the alignment of bit-field types is respected
754 /// when laying out structures.
755 bool useBitFieldTypeAlignment() const {
756 return UseBitFieldTypeAlignment;
759 /// Check whether zero length bitfields should force alignment of
761 bool useZeroLengthBitfieldAlignment() const {
762 return UseZeroLengthBitfieldAlignment;
765 /// Get the fixed alignment value in bits for a member that follows
766 /// a zero length bitfield.
767 unsigned getZeroLengthBitfieldBoundary() const {
768 return ZeroLengthBitfieldBoundary;
771 /// Check whether explicit bitfield alignment attributes should be
772 // honored, as in "__attribute__((aligned(2))) int b : 1;".
773 bool useExplicitBitFieldAlignment() const {
774 return UseExplicitBitFieldAlignment;
777 /// Check whether this target support '\#pragma options align=mac68k'.
778 bool hasAlignMac68kSupport() const {
779 return HasAlignMac68kSupport;
782 /// Return the user string for the specified integer type enum.
784 /// For example, SignedShort -> "short".
785 static const char *getTypeName(IntType T);
787 /// Return the constant suffix for the specified integer type enum.
789 /// For example, SignedLong -> "L".
790 const char *getTypeConstantSuffix(IntType T) const;
792 /// Return the printf format modifier for the specified
793 /// integer type enum.
795 /// For example, SignedLong -> "l".
796 static const char *getTypeFormatModifier(IntType T);
798 /// Check whether the given real type should use the "fpret" flavor of
799 /// Objective-C message passing on this target.
800 bool useObjCFPRetForRealType(RealType T) const {
801 return RealTypeUsesObjCFPRet & (1 << T);
804 /// Check whether _Complex long double should use the "fp2ret" flavor
805 /// of Objective-C message passing on this target.
806 bool useObjCFP2RetForComplexLongDouble() const {
807 return ComplexLongDoubleUsesFP2Ret;
810 /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
811 /// to convert to and from __fp16.
812 /// FIXME: This function should be removed once all targets stop using the
813 /// conversion intrinsics.
814 virtual bool useFP16ConversionIntrinsics() const {
818 /// Specify if mangling based on address space map should be used or
819 /// not for language specific address spaces
820 bool useAddressSpaceMapMangling() const {
821 return UseAddrSpaceMapMangling;
824 ///===---- Other target property query methods --------------------------===//
826 /// Appends the target-specific \#define values for this
827 /// target set to the specified buffer.
828 virtual void getTargetDefines(const LangOptions &Opts,
829 MacroBuilder &Builder) const = 0;
832 /// Return information about target-specific builtins for
833 /// the current primary target, and info about which builtins are non-portable
834 /// across the current set of primary and secondary targets.
835 virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0;
837 /// The __builtin_clz* and __builtin_ctz* built-in
838 /// functions are specified to have undefined results for zero inputs, but
839 /// on targets that support these operations in a way that provides
840 /// well-defined results for zero without loss of performance, it is a good
841 /// idea to avoid optimizing based on that undef behavior.
842 virtual bool isCLZForZeroUndef() const { return true; }
844 /// Returns the kind of __builtin_va_list type that should be used
845 /// with this target.
846 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
848 /// Returns whether or not type \c __builtin_ms_va_list type is
849 /// available on this target.
850 bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
852 /// Returns true for RenderScript.
853 bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
855 /// Returns whether or not the AArch64 SVE built-in types are
856 /// available on this target.
857 bool hasAArch64SVETypes() const { return HasAArch64SVETypes; }
859 /// For ARM targets returns a mask defining which coprocessors are configured
860 /// as Custom Datapath.
861 uint32_t getARMCDECoprocMask() const { return ARMCDECoprocMask; }
863 /// Returns whether the passed in string is a valid clobber in an
864 /// inline asm statement.
866 /// This is used by Sema.
867 bool isValidClobber(StringRef Name) const;
869 /// Returns whether the passed in string is a valid register name
870 /// according to GCC.
872 /// This is used by Sema for inline asm statements.
873 virtual bool isValidGCCRegisterName(StringRef Name) const;
875 /// Returns the "normalized" GCC register name.
877 /// ReturnCannonical true will return the register name without any additions
878 /// such as "{}" or "%" in it's canonical form, for example:
879 /// ReturnCanonical = true and Name = "rax", will return "ax".
880 StringRef getNormalizedGCCRegisterName(StringRef Name,
881 bool ReturnCanonical = false) const;
883 virtual bool isSPRegName(StringRef) const { return false; }
885 /// Extracts a register from the passed constraint (if it is a
886 /// single-register constraint) and the asm label expression related to a
887 /// variable in the input or output list of an inline asm statement.
889 /// This function is used by Sema in order to diagnose conflicts between
890 /// the clobber list and the input/output lists.
891 virtual StringRef getConstraintRegister(StringRef Constraint,
892 StringRef Expression) const {
896 struct ConstraintInfo {
899 CI_AllowsMemory = 0x01,
900 CI_AllowsRegister = 0x02,
901 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
902 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
903 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
904 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
913 llvm::SmallSet<int, 4> ImmSet;
915 std::string ConstraintStr; // constraint: "=rm"
916 std::string Name; // Operand name: [foo] with no []'s.
918 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
919 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
921 ImmRange.Min = ImmRange.Max = 0;
922 ImmRange.isConstrained = false;
925 const std::string &getConstraintStr() const { return ConstraintStr; }
926 const std::string &getName() const { return Name; }
927 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
928 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
929 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
930 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
932 /// Return true if this output operand has a matching
933 /// (tied) input operand.
934 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
936 /// Return true if this input operand is a matching
937 /// constraint that ties it to an output operand.
939 /// If this returns true then getTiedOperand will indicate which output
940 /// operand this is tied to.
941 bool hasTiedOperand() const { return TiedOperand != -1; }
942 unsigned getTiedOperand() const {
943 assert(hasTiedOperand() && "Has no tied operand!");
944 return (unsigned)TiedOperand;
947 bool requiresImmediateConstant() const {
948 return (Flags & CI_ImmediateConstant) != 0;
950 bool isValidAsmImmediate(const llvm::APInt &Value) const {
952 return Value.isSignedIntN(32) &&
953 ImmSet.count(Value.getZExtValue()) != 0;
954 return !ImmRange.isConstrained ||
955 (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
958 void setIsReadWrite() { Flags |= CI_ReadWrite; }
959 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
960 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
961 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
962 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
963 void setRequiresImmediate(int Min, int Max) {
964 Flags |= CI_ImmediateConstant;
967 ImmRange.isConstrained = true;
969 void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
970 Flags |= CI_ImmediateConstant;
971 for (int Exact : Exacts)
972 ImmSet.insert(Exact);
974 void setRequiresImmediate(int Exact) {
975 Flags |= CI_ImmediateConstant;
976 ImmSet.insert(Exact);
978 void setRequiresImmediate() {
979 Flags |= CI_ImmediateConstant;
982 /// Indicate that this is an input operand that is tied to
983 /// the specified output operand.
985 /// Copy over the various constraint information from the output.
986 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
987 Output.setHasMatchingInput();
988 Flags = Output.Flags;
990 // Don't copy Name or constraint string.
994 /// Validate register name used for global register variables.
996 /// This function returns true if the register passed in RegName can be used
997 /// for global register variables on this target. In addition, it returns
998 /// true in HasSizeMismatch if the size of the register doesn't match the
999 /// variable size passed in RegSize.
1000 virtual bool validateGlobalRegisterVariable(StringRef RegName,
1002 bool &HasSizeMismatch) const {
1003 HasSizeMismatch = false;
1007 // validateOutputConstraint, validateInputConstraint - Checks that
1008 // a constraint is valid and provides information about it.
1009 // FIXME: These should return a real error instead of just true/false.
1010 bool validateOutputConstraint(ConstraintInfo &Info) const;
1011 bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints,
1012 ConstraintInfo &info) const;
1014 virtual bool validateOutputSize(const llvm::StringMap<bool> &FeatureMap,
1015 StringRef /*Constraint*/,
1016 unsigned /*Size*/) const {
1020 virtual bool validateInputSize(const llvm::StringMap<bool> &FeatureMap,
1021 StringRef /*Constraint*/,
1022 unsigned /*Size*/) const {
1026 validateConstraintModifier(StringRef /*Constraint*/,
1029 std::string &/*SuggestedModifier*/) const {
1033 validateAsmConstraint(const char *&Name,
1034 TargetInfo::ConstraintInfo &info) const = 0;
1036 bool resolveSymbolicName(const char *&Name,
1037 ArrayRef<ConstraintInfo> OutputConstraints,
1038 unsigned &Index) const;
1040 // Constraint parm will be left pointing at the last character of
1041 // the constraint. In practice, it won't be changed unless the
1042 // constraint is longer than one character.
1043 virtual std::string convertConstraint(const char *&Constraint) const {
1044 // 'p' defaults to 'r', but can be overridden by targets.
1045 if (*Constraint == 'p')
1046 return std::string("r");
1047 return std::string(1, *Constraint);
1050 /// Returns a string of target-specific clobbers, in LLVM format.
1051 virtual const char *getClobbers() const = 0;
1053 /// Returns true if NaN encoding is IEEE 754-2008.
1054 /// Only MIPS allows a different encoding.
1055 virtual bool isNan2008() const {
1059 /// Returns the target triple of the primary target.
1060 const llvm::Triple &getTriple() const {
1064 const llvm::DataLayout &getDataLayout() const {
1065 assert(DataLayout && "Uninitialized DataLayout!");
1069 struct GCCRegAlias {
1070 const char * const Aliases[5];
1071 const char * const Register;
1074 struct AddlRegName {
1075 const char * const Names[5];
1076 const unsigned RegNum;
1079 /// Does this target support "protected" visibility?
1081 /// Any target which dynamic libraries will naturally support
1082 /// something like "default" (meaning that the symbol is visible
1083 /// outside this shared object) and "hidden" (meaning that it isn't)
1084 /// visibilities, but "protected" is really an ELF-specific concept
1085 /// with weird semantics designed around the convenience of dynamic
1086 /// linker implementations. Which is not to suggest that there's
1087 /// consistent target-independent semantics for "default" visibility
1088 /// either; the entire thing is pretty badly mangled.
1089 virtual bool hasProtectedVisibility() const { return true; }
1091 /// An optional hook that targets can implement to perform semantic
1092 /// checking on attribute((section("foo"))) specifiers.
1094 /// In this case, "foo" is passed in to be checked. If the section
1095 /// specifier is invalid, the backend should return a non-empty string
1096 /// that indicates the problem.
1098 /// This hook is a simple quality of implementation feature to catch errors
1099 /// and give good diagnostics in cases when the assembler or code generator
1100 /// would otherwise reject the section specifier.
1102 virtual std::string isValidSectionSpecifier(StringRef SR) const {
1106 /// Set forced language options.
1108 /// Apply changes to the target information with respect to certain
1109 /// language options which change the target configuration and adjust
1110 /// the language based on the target options where applicable.
1111 virtual void adjust(LangOptions &Opts);
1113 /// Adjust target options based on codegen options.
1114 virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
1115 TargetOptions &TargetOpts) const {}
1117 /// Initialize the map with the default set of target features for the
1118 /// CPU this should include all legal feature strings on the target.
1120 /// \return False on error (invalid features).
1121 virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
1122 DiagnosticsEngine &Diags, StringRef CPU,
1123 const std::vector<std::string> &FeatureVec) const;
1125 /// Get the ABI currently in use.
1126 virtual StringRef getABI() const { return StringRef(); }
1128 /// Get the C++ ABI currently in use.
1129 TargetCXXABI getCXXABI() const {
1133 /// Target the specified CPU.
1135 /// \return False on error (invalid CPU name).
1136 virtual bool setCPU(const std::string &Name) {
1140 /// Fill a SmallVectorImpl with the valid values to setCPU.
1141 virtual void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {}
1143 /// brief Determine whether this TargetInfo supports the given CPU name.
1144 virtual bool isValidCPUName(StringRef Name) const {
1148 /// Use the specified ABI.
1150 /// \return False on error (invalid ABI name).
1151 virtual bool setABI(const std::string &Name) {
1155 /// Use the specified unit for FP math.
1157 /// \return False on error (invalid unit name).
1158 virtual bool setFPMath(StringRef Name) {
1162 /// Enable or disable a specific target feature;
1163 /// the feature name must be valid.
1164 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
1166 bool Enabled) const {
1167 Features[Name] = Enabled;
1170 /// Determine whether this TargetInfo supports the given feature.
1171 virtual bool isValidFeatureName(StringRef Feature) const {
1175 struct BranchProtectionInfo {
1176 LangOptions::SignReturnAddressScopeKind SignReturnAddr =
1177 LangOptions::SignReturnAddressScopeKind::None;
1178 LangOptions::SignReturnAddressKeyKind SignKey =
1179 LangOptions::SignReturnAddressKeyKind::AKey;
1180 bool BranchTargetEnforcement = false;
1183 /// Determine if this TargetInfo supports the given branch protection
1185 virtual bool validateBranchProtection(StringRef Spec,
1186 BranchProtectionInfo &BPI,
1187 StringRef &Err) const {
1192 /// Perform initialization based on the user configured
1193 /// set of features (e.g., +sse4).
1195 /// The list is guaranteed to have at most one entry per feature.
1197 /// The target may modify the features list, to change which options are
1198 /// passed onwards to the backend.
1199 /// FIXME: This part should be fixed so that we can change handleTargetFeatures
1200 /// to merely a TargetInfo initialization routine.
1202 /// \return False on error.
1203 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
1204 DiagnosticsEngine &Diags) {
1208 /// Determine whether the given target has the given feature.
1209 virtual bool hasFeature(StringRef Feature) const {
1213 /// Identify whether this target supports multiversioning of functions,
1214 /// which requires support for cpu_supports and cpu_is functionality.
1215 bool supportsMultiVersioning() const { return getTriple().isX86(); }
1217 /// Identify whether this target supports IFuncs.
1218 bool supportsIFunc() const { return getTriple().isOSBinFormatELF(); }
1220 // Validate the contents of the __builtin_cpu_supports(const char*)
1222 virtual bool validateCpuSupports(StringRef Name) const { return false; }
1224 // Return the target-specific priority for features/cpus/vendors so
1225 // that they can be properly sorted for checking.
1226 virtual unsigned multiVersionSortPriority(StringRef Name) const {
1230 // Validate the contents of the __builtin_cpu_is(const char*)
1232 virtual bool validateCpuIs(StringRef Name) const { return false; }
1234 // Validate a cpu_dispatch/cpu_specific CPU option, which is a different list
1235 // from cpu_is, since it checks via features rather than CPUs directly.
1236 virtual bool validateCPUSpecificCPUDispatch(StringRef Name) const {
1240 // Get the character to be added for mangling purposes for cpu_specific.
1241 virtual char CPUSpecificManglingCharacter(StringRef Name) const {
1243 "cpu_specific Multiversioning not implemented on this target");
1246 // Get a list of the features that make up the CPU option for
1247 // cpu_specific/cpu_dispatch so that it can be passed to llvm as optimization
1249 virtual void getCPUSpecificCPUDispatchFeatures(
1250 StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1252 "cpu_specific Multiversioning not implemented on this target");
1255 // Get the cache line size of a given cpu. This method switches over
1256 // the given cpu and returns "None" if the CPU is not found.
1257 virtual Optional<unsigned> getCPUCacheLineSize() const { return None; }
1259 // Returns maximal number of args passed in registers.
1260 unsigned getRegParmMax() const {
1261 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
1265 /// Whether the target supports thread-local storage.
1266 bool isTLSSupported() const {
1267 return TLSSupported;
1270 /// Return the maximum alignment (in bits) of a TLS variable
1272 /// Gets the maximum alignment (in bits) of a TLS variable on this target.
1273 /// Returns zero if there is no such constraint.
1274 unsigned short getMaxTLSAlign() const {
1278 /// Whether target supports variable-length arrays.
1279 bool isVLASupported() const { return VLASupported; }
1281 /// Whether the target supports SEH __try.
1282 bool isSEHTrySupported() const {
1283 return getTriple().isOSWindows() &&
1284 (getTriple().isX86() ||
1285 getTriple().getArch() == llvm::Triple::aarch64);
1288 /// Return true if {|} are normal characters in the asm string.
1290 /// If this returns false (the default), then {abc|xyz} is syntax
1291 /// that says that when compiling for asm variant #0, "abc" should be
1292 /// generated, but when compiling for asm variant #1, "xyz" should be
1294 bool hasNoAsmVariants() const {
1295 return NoAsmVariants;
1298 /// Return the register number that __builtin_eh_return_regno would
1299 /// return with the specified argument.
1300 /// This corresponds with TargetLowering's getExceptionPointerRegister
1301 /// and getExceptionSelectorRegister in the backend.
1302 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
1306 /// Return the section to use for C++ static initialization functions.
1307 virtual const char *getStaticInitSectionSpecifier() const {
1311 const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; }
1313 /// Map from the address space field in builtin description strings to the
1314 /// language address space.
1315 virtual LangAS getOpenCLBuiltinAddressSpace(unsigned AS) const {
1316 return getLangASFromTargetAS(AS);
1319 /// Map from the address space field in builtin description strings to the
1320 /// language address space.
1321 virtual LangAS getCUDABuiltinAddressSpace(unsigned AS) const {
1322 return getLangASFromTargetAS(AS);
1325 /// Return an AST address space which can be used opportunistically
1326 /// for constant global memory. It must be possible to convert pointers into
1327 /// this address space to LangAS::Default. If no such address space exists,
1328 /// this may return None, and such optimizations will be disabled.
1329 virtual llvm::Optional<LangAS> getConstantAddressSpace() const {
1330 return LangAS::Default;
1333 /// Return a target-specific GPU grid value based on the GVIDX enum \p gv
1334 unsigned getGridValue(llvm::omp::GVIDX gv) const {
1335 assert(GridValues != nullptr && "GridValues not initialized");
1336 return GridValues[gv];
1339 /// Retrieve the name of the platform as it is used in the
1340 /// availability attribute.
1341 StringRef getPlatformName() const { return PlatformName; }
1343 /// Retrieve the minimum desired version of the platform, to
1344 /// which the program should be compiled.
1345 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
1347 bool isBigEndian() const { return BigEndian; }
1348 bool isLittleEndian() const { return !BigEndian; }
1350 /// Gets the default calling convention for the given target and
1351 /// declaration context.
1352 virtual CallingConv getDefaultCallingConv() const {
1353 // Not all targets will specify an explicit calling convention that we can
1354 // express. This will always do the right thing, even though it's not
1355 // an explicit calling convention.
1359 enum CallingConvCheckResult {
1366 /// Determines whether a given calling convention is valid for the
1367 /// target. A calling convention can either be accepted, produce a warning
1368 /// and be substituted with the default calling convention, or (someday)
1369 /// produce an error (such as using thiscall on a non-instance function).
1370 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1373 return CCCR_Warning;
1379 enum CallingConvKind {
1385 virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
1387 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
1388 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
1389 virtual bool hasSjLjLowering() const {
1393 /// Check if the target supports CFProtection branch.
1395 checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const;
1397 /// Check if the target supports CFProtection branch.
1399 checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const;
1401 /// Whether target allows to overalign ABI-specified preferred alignment
1402 virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1404 /// Set supported OpenCL extensions and optional core features.
1405 virtual void setSupportedOpenCLOpts() {}
1407 /// Set supported OpenCL extensions as written on command line
1408 virtual void setOpenCLExtensionOpts() {
1409 for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1410 getTargetOpts().SupportedOpenCLOptions.support(Ext);
1414 /// Get supported OpenCL extensions and optional core features.
1415 OpenCLOptions &getSupportedOpenCLOpts() {
1416 return getTargetOpts().SupportedOpenCLOptions;
1419 /// Get const supported OpenCL extensions and optional core features.
1420 const OpenCLOptions &getSupportedOpenCLOpts() const {
1421 return getTargetOpts().SupportedOpenCLOptions;
1424 /// Get address space for OpenCL type.
1425 virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
1427 /// \returns Target specific vtbl ptr address space.
1428 virtual unsigned getVtblPtrAddressSpace() const {
1432 /// \returns If a target requires an address within a target specific address
1433 /// space \p AddressSpace to be converted in order to be used, then return the
1434 /// corresponding target specific DWARF address space.
1436 /// \returns Otherwise return None and no conversion will be emitted in the
1438 virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
1442 /// \returns The version of the SDK which was used during the compilation if
1443 /// one was specified, or an empty version otherwise.
1444 const llvm::VersionTuple &getSDKVersion() const {
1445 return getTargetOpts().SDKVersion;
1448 /// Check the target is valid after it is fully initialized.
1449 virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1453 virtual void setAuxTarget(const TargetInfo *Aux) {}
1455 /// Whether target allows debuginfo types for decl only variables.
1456 virtual bool allowDebugInfoForExternalVar() const { return false; }
1459 /// Copy type and layout related info.
1460 void copyAuxTarget(const TargetInfo *Aux);
1461 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1462 return PointerWidth;
1464 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1465 return PointerAlign;
1467 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1470 virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1471 virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1472 virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1477 // Assert the values for the fractional and integral bits for each fixed point
1478 // type follow the restrictions given in clause 6.2.6.3 of N1169.
1479 void CheckFixedPointBits() const;
1482 } // end namespace clang