1 //===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines the clang::TargetInfo interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
16 #define LLVM_CLANG_BASIC_TARGETINFO_H
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"
42 class DiagnosticsEngine;
50 namespace Builtin { struct Info; }
52 /// Exposes information about the current target.
54 class TargetInfo : public RefCountedBase<TargetInfo> {
55 std::shared_ptr<TargetOptions> TargetOpts;
58 // Target values set by the ctor of the actual target implementation. Default
59 // values are specified by the TargetInfo constructor.
63 bool NoAsmVariants; // True if {|} are normal characters.
64 bool HasLegalHalfType; // True if the backend supports operations on the half
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;
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;
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
92 bool PaddingOnUnsignedFixedPoint;
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;
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;
121 mutable StringRef PlatformName;
122 mutable VersionTuple PlatformMinVersion;
124 unsigned HasAlignMac68kSupport : 1;
125 unsigned RealTypeUsesObjCFPRet : 3;
126 unsigned ComplexLongDoubleUsesFP2Ret : 1;
128 unsigned HasBuiltinMSVaList : 1;
130 unsigned IsRenderScriptTarget : 1;
132 // TargetInfo Constructor. Default initializes all fields.
133 TargetInfo(const llvm::Triple &T);
135 void resetDataLayout(StringRef DL) {
136 DataLayout.reset(new llvm::DataLayout(DL));
140 /// Construct a target for the given options.
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.
146 CreateTargetInfo(DiagnosticsEngine &Diags,
147 const std::shared_ptr<TargetOptions> &Opts);
149 virtual ~TargetInfo();
151 /// Retrieve the target options.
152 TargetOptions &getTargetOpts() const {
153 assert(TargetOpts && "Missing target options");
157 ///===---- Target Data Type Query Methods -------------------------------===//
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,
186 /// typedef void* __builtin_va_list;
187 VoidPtrBuiltinVaList,
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,
193 /// __builtin_va_list as defined by the PNaCl ABI:
194 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
195 PNaClABIBuiltinVaList,
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,
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,
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,
211 // typedef struct __va_list_tag
215 // void *__overflow_arg_area;
216 // void *__reg_save_area;
222 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
223 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
226 /// Whether Objective-C's built-in boolean type should be signed char.
228 /// Otherwise, when this flag is not set, the normal built-in boolean type is
230 unsigned UseSignedCharForObjCBool : 1;
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
237 unsigned UseBitFieldTypeAlignment : 1;
239 /// Whether zero length bitfields (e.g., int : 0;) force alignment of
240 /// the next bitfield.
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;
247 /// Whether explicit bit field alignment attributes are honored.
248 unsigned UseExplicitBitFieldAlignment : 1;
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;
254 /// Specify if mangling based on address space map should be used or
255 /// not for language specific address spaces
256 bool UseAddrSpaceMapMangling;
259 IntType getSizeType() const { return SizeType; }
260 IntType getSignedSizeType() const {
268 case UnsignedLongLong:
269 return SignedLongLong;
271 llvm_unreachable("Invalid SizeType");
274 IntType getIntMaxType() const { return IntMaxType; }
275 IntType getUIntMaxType() const {
276 return getCorrespondingUnsignedType(IntMaxType);
278 IntType getPtrDiffType(unsigned AddrSpace) const {
279 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
281 IntType getUnsignedPtrDiffType(unsigned AddrSpace) const {
282 return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
284 IntType getIntPtrType() const { return IntPtrType; }
285 IntType getUIntPtrType() const {
286 return getCorrespondingUnsignedType(IntPtrType);
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);
296 IntType getSigAtomicType() const { return SigAtomicType; }
297 IntType getProcessIDType() const { return ProcessIDType; }
299 static IntType getCorrespondingUnsignedType(IntType T) {
304 return UnsignedShort;
310 return UnsignedLongLong;
312 llvm_unreachable("Unexpected signed integer type");
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;
324 /// Return the width (in bits) of the specified integer type enum.
326 /// For example, SignedInt -> getIntWidth().
327 unsigned getTypeWidth(IntType T) const;
329 /// Return integer type with specified width.
330 virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
332 /// Return the smallest integer type with at least the specified width.
333 virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
334 bool IsSigned) const;
336 /// Return floating point type with specified width.
337 RealType getRealTypeByWidth(unsigned BitWidth) const;
339 /// Return the alignment (in bits) of the specified integer type enum.
341 /// For example, SignedInt -> getIntAlign().
342 unsigned getTypeAlign(IntType T) const;
344 /// Returns true if the type is signed; false otherwise.
345 static bool isTypeSigned(IntType T);
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);
352 uint64_t getPointerAlign(unsigned AddrSpace) const {
353 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
356 /// Return the maximum width of pointers on this target.
357 virtual uint64_t getMaxPointerWidth() const {
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; }
365 /// Return the size of '_Bool' and C++ 'bool' for this target, in bits.
366 unsigned getBoolWidth() const { return BoolWidth; }
368 /// Return the alignment of '_Bool' and C++ 'bool' for this target.
369 unsigned getBoolAlign() const { return BoolAlign; }
371 unsigned getCharWidth() const { return 8; } // FIXME
372 unsigned getCharAlign() const { return 8; } // FIXME
374 /// Return the size of 'signed short' and 'unsigned short' for this
376 unsigned getShortWidth() const { return 16; } // FIXME
378 /// Return the alignment of 'signed short' and 'unsigned short' for
380 unsigned getShortAlign() const { return 16; } // FIXME
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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;
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; }
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;
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;
451 unsigned getUnsignedShortAccumIBits() const {
452 return PaddingOnUnsignedFixedPoint
453 ? getShortAccumIBits()
454 : ShortAccumWidth - getUnsignedShortAccumScale();
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;
462 unsigned getUnsignedAccumIBits() const {
463 return PaddingOnUnsignedFixedPoint ? getAccumIBits()
464 : AccumWidth - getUnsignedAccumScale();
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;
472 unsigned getUnsignedLongAccumIBits() const {
473 return PaddingOnUnsignedFixedPoint
474 ? getLongAccumIBits()
475 : LongAccumWidth - getUnsignedLongAccumScale();
478 /// getShortFractScale - Return the number of fractional bits
479 /// in a 'signed short _Fract' type.
480 unsigned getShortFractScale() const { return ShortFractWidth - 1; }
482 /// getFractScale - Return the number of fractional bits
483 /// in a 'signed _Fract' type.
484 unsigned getFractScale() const { return FractWidth - 1; }
486 /// getLongFractScale - Return the number of fractional bits
487 /// in a 'signed long _Fract' type.
488 unsigned getLongFractScale() const { return LongFractWidth - 1; }
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;
497 /// getUnsignedFractScale - Return the number of fractional bits
498 /// in a 'unsigned _Fract' type.
499 unsigned getUnsignedFractScale() const {
500 return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1;
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;
510 /// Determine whether the __int128 type is supported on this target.
511 virtual bool hasInt128Type() const {
512 return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128;
515 /// Determine whether _Float16 is supported on this target.
516 virtual bool hasLegalHalfType() const { return HasLegalHalfType; }
518 /// Determine whether the __float128 type is supported on this target.
519 virtual bool hasFloat128Type() const { return HasFloat128; }
521 /// Determine whether the _Float16 type is supported on this target.
522 virtual bool hasFloat16Type() const { return HasFloat16; }
524 /// Return the alignment that is suitable for storing any
525 /// object with a fundamental alignment requirement.
526 unsigned getSuitableAlign() const { return SuitableAlign; }
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;
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; }
538 /// Return the largest alignment for which a suitably-sized allocation with
539 /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
541 unsigned getNewAlign() const {
542 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
545 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
547 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
548 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
550 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
552 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
553 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
555 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
557 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
558 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
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; }
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; }
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; }
575 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
577 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
578 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
579 const llvm::fltSemantics &getLongDoubleFormat() const {
580 return *LongDoubleFormat;
583 /// getFloat128Width/Align/Format - Return the size/align/format of
585 unsigned getFloat128Width() const { return 128; }
586 unsigned getFloat128Align() const { return Float128Align; }
587 const llvm::fltSemantics &getFloat128Format() const {
588 return *Float128Format;
591 /// Return true if the 'long double' type should be mangled like
593 virtual bool useFloat128ManglingForLongDouble() const { return false; }
595 /// Return the value for the C99 FLT_EVAL_METHOD macro.
596 virtual unsigned getFloatEvalMethod() const { return 0; }
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; }
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()));
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; }
629 /// Return the size of intmax_t and uintmax_t for this target, in bits.
630 unsigned getIntMaxTWidth() const {
631 return getTypeWidth(IntMaxType);
634 // Return the size of unwind_word for this target.
635 virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
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
645 /// Returns the name of the mcount instrumentation function.
646 const char *getMCountName() const {
650 /// Check if the Objective-C built-in boolean type should be signed
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;
658 void noSignedCharForObjCBool() {
659 UseSignedCharForObjCBool = false;
662 /// Check whether the alignment of bit-field types is respected
663 /// when laying out structures.
664 bool useBitFieldTypeAlignment() const {
665 return UseBitFieldTypeAlignment;
668 /// Check whether zero length bitfields should force alignment of
670 bool useZeroLengthBitfieldAlignment() const {
671 return UseZeroLengthBitfieldAlignment;
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;
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;
686 /// Check whether this target support '\#pragma options align=mac68k'.
687 bool hasAlignMac68kSupport() const {
688 return HasAlignMac68kSupport;
691 /// Return the user string for the specified integer type enum.
693 /// For example, SignedShort -> "short".
694 static const char *getTypeName(IntType T);
696 /// Return the constant suffix for the specified integer type enum.
698 /// For example, SignedLong -> "L".
699 const char *getTypeConstantSuffix(IntType T) const;
701 /// Return the printf format modifier for the specified
702 /// integer type enum.
704 /// For example, SignedLong -> "l".
705 static const char *getTypeFormatModifier(IntType T);
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);
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;
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 {
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;
733 ///===---- Other target property query methods --------------------------===//
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;
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;
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; }
753 /// Returns the kind of __builtin_va_list type that should be used
754 /// with this target.
755 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
757 /// Returns whether or not type \c __builtin_ms_va_list type is
758 /// available on this target.
759 bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
761 /// Returns true for RenderScript.
762 bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
764 /// Returns whether the passed in string is a valid clobber in an
765 /// inline asm statement.
767 /// This is used by Sema.
768 bool isValidClobber(StringRef Name) const;
770 /// Returns whether the passed in string is a valid register name
771 /// according to GCC.
773 /// This is used by Sema for inline asm statements.
774 virtual bool isValidGCCRegisterName(StringRef Name) const;
776 /// Returns the "normalized" GCC register name.
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;
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.
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 {
795 struct ConstraintInfo {
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).
812 llvm::SmallSet<int, 4> ImmSet;
814 std::string ConstraintStr; // constraint: "=rm"
815 std::string Name; // Operand name: [foo] with no []'s.
817 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
818 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
820 ImmRange.Min = ImmRange.Max = 0;
821 ImmRange.isConstrained = false;
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; }
831 /// Return true if this output operand has a matching
832 /// (tied) input operand.
833 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
835 /// Return true if this input operand is a matching
836 /// constraint that ties it to an output operand.
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;
846 bool requiresImmediateConstant() const {
847 return (Flags & CI_ImmediateConstant) != 0;
849 bool isValidAsmImmediate(const llvm::APInt &Value) const {
851 return ImmSet.count(Value.getZExtValue()) != 0;
852 return !ImmRange.isConstrained || (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max));
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;
864 ImmRange.isConstrained = true;
866 void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
867 Flags |= CI_ImmediateConstant;
868 for (int Exact : Exacts)
869 ImmSet.insert(Exact);
871 void setRequiresImmediate(int Exact) {
872 Flags |= CI_ImmediateConstant;
873 ImmSet.insert(Exact);
875 void setRequiresImmediate() {
876 Flags |= CI_ImmediateConstant;
879 /// Indicate that this is an input operand that is tied to
880 /// the specified output operand.
882 /// Copy over the various constraint information from the output.
883 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
884 Output.setHasMatchingInput();
885 Flags = Output.Flags;
887 // Don't copy Name or constraint string.
891 /// Validate register name used for global register variables.
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,
899 bool &HasSizeMismatch) const {
900 HasSizeMismatch = false;
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;
911 virtual bool validateOutputSize(StringRef /*Constraint*/,
912 unsigned /*Size*/) const {
916 virtual bool validateInputSize(StringRef /*Constraint*/,
917 unsigned /*Size*/) const {
921 validateConstraintModifier(StringRef /*Constraint*/,
924 std::string &/*SuggestedModifier*/) const {
928 validateAsmConstraint(const char *&Name,
929 TargetInfo::ConstraintInfo &info) const = 0;
931 bool resolveSymbolicName(const char *&Name,
932 ArrayRef<ConstraintInfo> OutputConstraints,
933 unsigned &Index) const;
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);
945 /// Returns a string of target-specific clobbers, in LLVM format.
946 virtual const char *getClobbers() const = 0;
948 /// Returns true if NaN encoding is IEEE 754-2008.
949 /// Only MIPS allows a different encoding.
950 virtual bool isNan2008() const {
954 /// Returns the target triple of the primary target.
955 const llvm::Triple &getTriple() const {
959 const llvm::DataLayout &getDataLayout() const {
960 assert(DataLayout && "Uninitialized DataLayout!");
965 const char * const Aliases[5];
966 const char * const Register;
970 const char * const Names[5];
971 const unsigned RegNum;
974 /// Does this target support "protected" visibility?
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; }
986 /// An optional hook that targets can implement to perform semantic
987 /// checking on attribute((section("foo"))) specifiers.
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.
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.
997 virtual std::string isValidSectionSpecifier(StringRef SR) const {
1001 /// Set forced language options.
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);
1008 /// Adjust target options based on codegen options.
1009 virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
1010 TargetOptions &TargetOpts) const {}
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.
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;
1020 /// Get the ABI currently in use.
1021 virtual StringRef getABI() const { return StringRef(); }
1023 /// Get the C++ ABI currently in use.
1024 TargetCXXABI getCXXABI() const {
1028 /// Target the specified CPU.
1030 /// \return False on error (invalid CPU name).
1031 virtual bool setCPU(const std::string &Name) {
1035 /// Fill a SmallVectorImpl with the valid values to setCPU.
1036 virtual void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {}
1038 /// brief Determine whether this TargetInfo supports the given CPU name.
1039 virtual bool isValidCPUName(StringRef Name) const {
1043 /// Use the specified ABI.
1045 /// \return False on error (invalid ABI name).
1046 virtual bool setABI(const std::string &Name) {
1050 /// Use the specified unit for FP math.
1052 /// \return False on error (invalid unit name).
1053 virtual bool setFPMath(StringRef Name) {
1057 /// Enable or disable a specific target feature;
1058 /// the feature name must be valid.
1059 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
1061 bool Enabled) const {
1062 Features[Name] = Enabled;
1065 /// Determine whether this TargetInfo supports the given feature.
1066 virtual bool isValidFeatureName(StringRef Feature) const {
1070 /// Perform initialization based on the user configured
1071 /// set of features (e.g., +sse4).
1073 /// The list is guaranteed to have at most one entry per feature.
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.
1080 /// \return False on error.
1081 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
1082 DiagnosticsEngine &Diags) {
1086 /// Determine whether the given target has the given feature.
1087 virtual bool hasFeature(StringRef Feature) const {
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;
1098 /// Identify whether this target supports IFuncs.
1099 bool supportsIFunc() const { return getTriple().isOSBinFormatELF(); }
1101 // Validate the contents of the __builtin_cpu_supports(const char*)
1103 virtual bool validateCpuSupports(StringRef Name) const { return false; }
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 {
1111 // Validate the contents of the __builtin_cpu_is(const char*)
1113 virtual bool validateCpuIs(StringRef Name) const { return false; }
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 {
1121 // Get the character to be added for mangling purposes for cpu_specific.
1122 virtual char CPUSpecificManglingCharacter(StringRef Name) const {
1124 "cpu_specific Multiversioning not implemented on this target");
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
1130 virtual void getCPUSpecificCPUDispatchFeatures(
1131 StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1133 "cpu_specific Multiversioning not implemented on this target");
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");
1142 /// Whether the target supports thread-local storage.
1143 bool isTLSSupported() const {
1144 return TLSSupported;
1147 /// Return the maximum alignment (in bits) of a TLS variable
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 {
1155 /// Whether target supports variable-length arrays.
1156 bool isVLASupported() const { return VLASupported; }
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);
1166 /// Return true if {|} are normal characters in the asm string.
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
1172 bool hasNoAsmVariants() const {
1173 return NoAsmVariants;
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 {
1184 /// Return the section to use for C++ static initialization functions.
1185 virtual const char *getStaticInitSectionSpecifier() const {
1189 const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; }
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);
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);
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;
1211 /// Retrieve the name of the platform as it is used in the
1212 /// availability attribute.
1213 StringRef getPlatformName() const { return PlatformName; }
1215 /// Retrieve the minimum desired version of the platform, to
1216 /// which the program should be compiled.
1217 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
1219 bool isBigEndian() const { return BigEndian; }
1220 bool isLittleEndian() const { return !BigEndian; }
1222 enum CallingConvMethodType {
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.
1237 enum CallingConvCheckResult {
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 {
1250 return CCCR_Warning;
1256 enum CallingConvKind {
1262 virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
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 {
1270 /// Check if the target supports CFProtection branch.
1272 checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const;
1274 /// Check if the target supports CFProtection branch.
1276 checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const;
1278 /// Whether target allows to overalign ABI-specified preferred alignment
1279 virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1281 /// Set supported OpenCL extensions and optional core features.
1282 virtual void setSupportedOpenCLOpts() {}
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);
1291 /// Get supported OpenCL extensions and optional core features.
1292 OpenCLOptions &getSupportedOpenCLOpts() {
1293 return getTargetOpts().SupportedOpenCLOptions;
1296 /// Get const supported OpenCL extensions and optional core features.
1297 const OpenCLOptions &getSupportedOpenCLOpts() const {
1298 return getTargetOpts().SupportedOpenCLOptions;
1301 enum OpenCLTypeKind {
1312 /// Get address space for OpenCL type.
1313 virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
1315 /// \returns Target specific vtbl ptr address space.
1316 virtual unsigned getVtblPtrAddressSpace() const {
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.
1324 /// \returns Otherwise return None and no conversion will be emitted in the
1326 virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
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;
1336 /// Check the target is valid after it is fully initialized.
1337 virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1342 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1343 return PointerWidth;
1345 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1346 return PointerAlign;
1348 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1351 virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1352 virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1353 virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
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;
1363 } // end namespace clang