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
67 unsigned char PointerWidth, PointerAlign;
68 unsigned char BoolWidth, BoolAlign;
69 unsigned char IntWidth, IntAlign;
70 unsigned char HalfWidth, HalfAlign;
71 unsigned char FloatWidth, FloatAlign;
72 unsigned char DoubleWidth, DoubleAlign;
73 unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align;
74 unsigned char LargeArrayMinWidth, LargeArrayAlign;
75 unsigned char LongWidth, LongAlign;
76 unsigned char LongLongWidth, LongLongAlign;
78 // Fixed point bit widths
79 unsigned char ShortAccumWidth, ShortAccumAlign;
80 unsigned char AccumWidth, AccumAlign;
81 unsigned char LongAccumWidth, LongAccumAlign;
82 unsigned char ShortFractWidth, ShortFractAlign;
83 unsigned char FractWidth, FractAlign;
84 unsigned char LongFractWidth, LongFractAlign;
86 // If true, unsigned fixed point types have the same number of fractional bits
87 // as their signed counterparts, forcing the unsigned types to have one extra
88 // bit of padding. Otherwise, unsigned fixed point types have
89 // one more fractional bit than its corresponding signed type. This is false
91 bool PaddingOnUnsignedFixedPoint;
93 // Fixed point integral and fractional bit sizes
94 // Saturated types share the same integral/fractional bits as their
95 // corresponding unsaturated types.
96 // For simplicity, the fractional bits in a _Fract type will be one less the
97 // width of that _Fract type. This leaves all signed _Fract types having no
98 // padding and unsigned _Fract types will only have 1 bit of padding after the
99 // sign if PaddingOnUnsignedFixedPoint is set.
100 unsigned char ShortAccumScale;
101 unsigned char AccumScale;
102 unsigned char LongAccumScale;
104 unsigned char SuitableAlign;
105 unsigned char DefaultAlignForAttributeAligned;
106 unsigned char MinGlobalAlign;
107 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
108 unsigned short MaxVectorAlign;
109 unsigned short MaxTLSAlign;
110 unsigned short SimdDefaultAlign;
111 unsigned short NewAlign;
112 std::unique_ptr<llvm::DataLayout> DataLayout;
113 const char *MCountName;
114 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
115 *LongDoubleFormat, *Float128Format;
116 unsigned char RegParmMax, SSERegParmMax;
117 TargetCXXABI TheCXXABI;
118 const LangASMap *AddrSpaceMap;
120 mutable StringRef PlatformName;
121 mutable VersionTuple PlatformMinVersion;
123 unsigned HasAlignMac68kSupport : 1;
124 unsigned RealTypeUsesObjCFPRet : 3;
125 unsigned ComplexLongDoubleUsesFP2Ret : 1;
127 unsigned HasBuiltinMSVaList : 1;
129 unsigned IsRenderScriptTarget : 1;
131 // TargetInfo Constructor. Default initializes all fields.
132 TargetInfo(const llvm::Triple &T);
134 void resetDataLayout(StringRef DL) {
135 DataLayout.reset(new llvm::DataLayout(DL));
139 /// Construct a target for the given options.
141 /// \param Opts - The options to use to initialize the target. The target may
142 /// modify the options to canonicalize the target feature information to match
143 /// what the backend expects.
145 CreateTargetInfo(DiagnosticsEngine &Diags,
146 const std::shared_ptr<TargetOptions> &Opts);
148 virtual ~TargetInfo();
150 /// Retrieve the target options.
151 TargetOptions &getTargetOpts() const {
152 assert(TargetOpts && "Missing target options");
156 ///===---- Target Data Type Query Methods -------------------------------===//
179 /// The different kinds of __builtin_va_list types defined by
180 /// the target implementation.
181 enum BuiltinVaListKind {
182 /// typedef char* __builtin_va_list;
183 CharPtrBuiltinVaList = 0,
185 /// typedef void* __builtin_va_list;
186 VoidPtrBuiltinVaList,
188 /// __builtin_va_list as defined by the AArch64 ABI
189 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
190 AArch64ABIBuiltinVaList,
192 /// __builtin_va_list as defined by the PNaCl ABI:
193 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
194 PNaClABIBuiltinVaList,
196 /// __builtin_va_list as defined by the Power ABI:
197 /// https://www.power.org
198 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
199 PowerABIBuiltinVaList,
201 /// __builtin_va_list as defined by the x86-64 ABI:
202 /// http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
203 X86_64ABIBuiltinVaList,
205 /// __builtin_va_list as defined by ARM AAPCS ABI
206 /// http://infocenter.arm.com
207 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
208 AAPCSABIBuiltinVaList,
210 // typedef struct __va_list_tag
214 // void *__overflow_arg_area;
215 // void *__reg_save_area;
221 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
222 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
225 /// Whether Objective-C's built-in boolean type should be signed char.
227 /// Otherwise, when this flag is not set, the normal built-in boolean type is
229 unsigned UseSignedCharForObjCBool : 1;
231 /// Control whether the alignment of bit-field types is respected when laying
232 /// out structures. If true, then the alignment of the bit-field type will be
233 /// used to (a) impact the alignment of the containing structure, and (b)
234 /// ensure that the individual bit-field will not straddle an alignment
236 unsigned UseBitFieldTypeAlignment : 1;
238 /// Whether zero length bitfields (e.g., int : 0;) force alignment of
239 /// the next bitfield.
241 /// If the alignment of the zero length bitfield is greater than the member
242 /// that follows it, `bar', `bar' will be aligned as the type of the
243 /// zero-length bitfield.
244 unsigned UseZeroLengthBitfieldAlignment : 1;
246 /// Whether explicit bit field alignment attributes are honored.
247 unsigned UseExplicitBitFieldAlignment : 1;
249 /// If non-zero, specifies a fixed alignment value for bitfields that follow
250 /// zero length bitfield, regardless of the zero length bitfield type.
251 unsigned ZeroLengthBitfieldBoundary;
253 /// Specify if mangling based on address space map should be used or
254 /// not for language specific address spaces
255 bool UseAddrSpaceMapMangling;
258 IntType getSizeType() const { return SizeType; }
259 IntType getSignedSizeType() const {
267 case UnsignedLongLong:
268 return SignedLongLong;
270 llvm_unreachable("Invalid SizeType");
273 IntType getIntMaxType() const { return IntMaxType; }
274 IntType getUIntMaxType() const {
275 return getCorrespondingUnsignedType(IntMaxType);
277 IntType getPtrDiffType(unsigned AddrSpace) const {
278 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
280 IntType getUnsignedPtrDiffType(unsigned AddrSpace) const {
281 return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
283 IntType getIntPtrType() const { return IntPtrType; }
284 IntType getUIntPtrType() const {
285 return getCorrespondingUnsignedType(IntPtrType);
287 IntType getWCharType() const { return WCharType; }
288 IntType getWIntType() const { return WIntType; }
289 IntType getChar16Type() const { return Char16Type; }
290 IntType getChar32Type() const { return Char32Type; }
291 IntType getInt64Type() const { return Int64Type; }
292 IntType getUInt64Type() const {
293 return getCorrespondingUnsignedType(Int64Type);
295 IntType getSigAtomicType() const { return SigAtomicType; }
296 IntType getProcessIDType() const { return ProcessIDType; }
298 static IntType getCorrespondingUnsignedType(IntType T) {
303 return UnsignedShort;
309 return UnsignedLongLong;
311 llvm_unreachable("Unexpected signed integer type");
315 /// Return the width (in bits) of the specified integer type enum.
317 /// For example, SignedInt -> getIntWidth().
318 unsigned getTypeWidth(IntType T) const;
320 /// Return integer type with specified width.
321 virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
323 /// Return the smallest integer type with at least the specified width.
324 virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
325 bool IsSigned) const;
327 /// Return floating point type with specified width.
328 RealType getRealTypeByWidth(unsigned BitWidth) const;
330 /// Return the alignment (in bits) of the specified integer type enum.
332 /// For example, SignedInt -> getIntAlign().
333 unsigned getTypeAlign(IntType T) const;
335 /// Returns true if the type is signed; false otherwise.
336 static bool isTypeSigned(IntType T);
338 /// Return the width of pointers on this target, for the
339 /// specified address space.
340 uint64_t getPointerWidth(unsigned AddrSpace) const {
341 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
343 uint64_t getPointerAlign(unsigned AddrSpace) const {
344 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
347 /// Return the maximum width of pointers on this target.
348 virtual uint64_t getMaxPointerWidth() const {
352 /// Get integer value for null pointer.
353 /// \param AddrSpace address space of pointee in source language.
354 virtual uint64_t getNullPointerValue(LangAS AddrSpace) const { return 0; }
356 /// Return the size of '_Bool' and C++ 'bool' for this target, in bits.
357 unsigned getBoolWidth() const { return BoolWidth; }
359 /// Return the alignment of '_Bool' and C++ 'bool' for this target.
360 unsigned getBoolAlign() const { return BoolAlign; }
362 unsigned getCharWidth() const { return 8; } // FIXME
363 unsigned getCharAlign() const { return 8; } // FIXME
365 /// Return the size of 'signed short' and 'unsigned short' for this
367 unsigned getShortWidth() const { return 16; } // FIXME
369 /// Return the alignment of 'signed short' and 'unsigned short' for
371 unsigned getShortAlign() const { return 16; } // FIXME
373 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
374 /// this target, in bits.
375 unsigned getIntWidth() const { return IntWidth; }
376 unsigned getIntAlign() const { return IntAlign; }
378 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
379 /// for this target, in bits.
380 unsigned getLongWidth() const { return LongWidth; }
381 unsigned getLongAlign() const { return LongAlign; }
383 /// getLongLongWidth/Align - Return the size of 'signed long long' and
384 /// 'unsigned long long' for this target, in bits.
385 unsigned getLongLongWidth() const { return LongLongWidth; }
386 unsigned getLongLongAlign() const { return LongLongAlign; }
388 /// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
389 /// 'unsigned short _Accum' for this target, in bits.
390 unsigned getShortAccumWidth() const { return ShortAccumWidth; }
391 unsigned getShortAccumAlign() const { return ShortAccumAlign; }
393 /// getAccumWidth/Align - Return the size of 'signed _Accum' and
394 /// 'unsigned _Accum' for this target, in bits.
395 unsigned getAccumWidth() const { return AccumWidth; }
396 unsigned getAccumAlign() const { return AccumAlign; }
398 /// getLongAccumWidth/Align - Return the size of 'signed long _Accum' and
399 /// 'unsigned long _Accum' for this target, in bits.
400 unsigned getLongAccumWidth() const { return LongAccumWidth; }
401 unsigned getLongAccumAlign() const { return LongAccumAlign; }
403 /// getShortFractWidth/Align - Return the size of 'signed short _Fract' and
404 /// 'unsigned short _Fract' for this target, in bits.
405 unsigned getShortFractWidth() const { return ShortFractWidth; }
406 unsigned getShortFractAlign() const { return ShortFractAlign; }
408 /// getFractWidth/Align - Return the size of 'signed _Fract' and
409 /// 'unsigned _Fract' for this target, in bits.
410 unsigned getFractWidth() const { return FractWidth; }
411 unsigned getFractAlign() const { return FractAlign; }
413 /// getLongFractWidth/Align - Return the size of 'signed long _Fract' and
414 /// 'unsigned long _Fract' for this target, in bits.
415 unsigned getLongFractWidth() const { return LongFractWidth; }
416 unsigned getLongFractAlign() const { return LongFractAlign; }
418 /// getShortAccumScale/IBits - Return the number of fractional/integral bits
419 /// in a 'signed short _Accum' type.
420 unsigned getShortAccumScale() const { return ShortAccumScale; }
421 unsigned getShortAccumIBits() const {
422 return ShortAccumWidth - ShortAccumScale - 1;
425 /// getAccumScale/IBits - Return the number of fractional/integral bits
426 /// in a 'signed _Accum' type.
427 unsigned getAccumScale() const { return AccumScale; }
428 unsigned getAccumIBits() const { return AccumWidth - AccumScale - 1; }
430 /// getLongAccumScale/IBits - Return the number of fractional/integral bits
431 /// in a 'signed long _Accum' type.
432 unsigned getLongAccumScale() const { return LongAccumScale; }
433 unsigned getLongAccumIBits() const {
434 return LongAccumWidth - LongAccumScale - 1;
437 /// getUnsignedShortAccumScale/IBits - Return the number of
438 /// fractional/integral bits in a 'unsigned short _Accum' type.
439 unsigned getUnsignedShortAccumScale() const {
440 return PaddingOnUnsignedFixedPoint ? ShortAccumScale : ShortAccumScale + 1;
442 unsigned getUnsignedShortAccumIBits() const {
443 return PaddingOnUnsignedFixedPoint
444 ? getShortAccumIBits()
445 : ShortAccumWidth - getUnsignedShortAccumScale();
448 /// getUnsignedAccumScale/IBits - Return the number of fractional/integral
449 /// bits in a 'unsigned _Accum' type.
450 unsigned getUnsignedAccumScale() const {
451 return PaddingOnUnsignedFixedPoint ? AccumScale : AccumScale + 1;
453 unsigned getUnsignedAccumIBits() const {
454 return PaddingOnUnsignedFixedPoint ? getAccumIBits()
455 : AccumWidth - getUnsignedAccumScale();
458 /// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral
459 /// bits in a 'unsigned long _Accum' type.
460 unsigned getUnsignedLongAccumScale() const {
461 return PaddingOnUnsignedFixedPoint ? LongAccumScale : LongAccumScale + 1;
463 unsigned getUnsignedLongAccumIBits() const {
464 return PaddingOnUnsignedFixedPoint
465 ? getLongAccumIBits()
466 : LongAccumWidth - getUnsignedLongAccumScale();
469 /// getShortFractScale - Return the number of fractional bits
470 /// in a 'signed short _Fract' type.
471 unsigned getShortFractScale() const { return ShortFractWidth - 1; }
473 /// getFractScale - Return the number of fractional bits
474 /// in a 'signed _Fract' type.
475 unsigned getFractScale() const { return FractWidth - 1; }
477 /// getLongFractScale - Return the number of fractional bits
478 /// in a 'signed long _Fract' type.
479 unsigned getLongFractScale() const { return LongFractWidth - 1; }
481 /// getUnsignedShortFractScale - Return the number of fractional bits
482 /// in a 'unsigned short _Fract' type.
483 unsigned getUnsignedShortFractScale() const {
484 return PaddingOnUnsignedFixedPoint ? getShortFractScale()
485 : getShortFractScale() + 1;
488 /// getUnsignedFractScale - Return the number of fractional bits
489 /// in a 'unsigned _Fract' type.
490 unsigned getUnsignedFractScale() const {
491 return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1;
494 /// getUnsignedLongFractScale - Return the number of fractional bits
495 /// in a 'unsigned long _Fract' type.
496 unsigned getUnsignedLongFractScale() const {
497 return PaddingOnUnsignedFixedPoint ? getLongFractScale()
498 : getLongFractScale() + 1;
501 /// Determine whether the __int128 type is supported on this target.
502 virtual bool hasInt128Type() const {
503 return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128;
506 /// Determine whether _Float16 is supported on this target.
507 virtual bool hasLegalHalfType() const { return HasLegalHalfType; }
509 /// Determine whether the __float128 type is supported on this target.
510 virtual bool hasFloat128Type() const { return HasFloat128; }
512 /// Return the alignment that is suitable for storing any
513 /// object with a fundamental alignment requirement.
514 unsigned getSuitableAlign() const { return SuitableAlign; }
516 /// Return the default alignment for __attribute__((aligned)) on
517 /// this target, to be used if no alignment value is specified.
518 unsigned getDefaultAlignForAttributeAligned() const {
519 return DefaultAlignForAttributeAligned;
522 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
523 /// unless its alignment is explicitly reduced via attributes.
524 unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
526 /// Return the largest alignment for which a suitably-sized allocation with
527 /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
529 unsigned getNewAlign() const {
530 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
533 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
535 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
536 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
538 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
540 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
541 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
543 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
545 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
546 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
548 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
549 unsigned getHalfWidth() const { return HalfWidth; }
550 unsigned getHalfAlign() const { return HalfAlign; }
551 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
553 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
554 unsigned getFloatWidth() const { return FloatWidth; }
555 unsigned getFloatAlign() const { return FloatAlign; }
556 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
558 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
559 unsigned getDoubleWidth() const { return DoubleWidth; }
560 unsigned getDoubleAlign() const { return DoubleAlign; }
561 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
563 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
565 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
566 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
567 const llvm::fltSemantics &getLongDoubleFormat() const {
568 return *LongDoubleFormat;
571 /// getFloat128Width/Align/Format - Return the size/align/format of
573 unsigned getFloat128Width() const { return 128; }
574 unsigned getFloat128Align() const { return Float128Align; }
575 const llvm::fltSemantics &getFloat128Format() const {
576 return *Float128Format;
579 /// Return true if the 'long double' type should be mangled like
581 virtual bool useFloat128ManglingForLongDouble() const { return false; }
583 /// Return the value for the C99 FLT_EVAL_METHOD macro.
584 virtual unsigned getFloatEvalMethod() const { return 0; }
586 // getLargeArrayMinWidth/Align - Return the minimum array size that is
587 // 'large' and its alignment.
588 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
589 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
591 /// Return the maximum width lock-free atomic operation which will
592 /// ever be supported for the given target
593 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
594 /// Return the maximum width lock-free atomic operation which can be
595 /// inlined given the supported features of the given target.
596 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
597 /// Set the maximum inline or promote width lock-free atomic operation
598 /// for the given target.
599 virtual void setMaxAtomicWidth() {}
600 /// Returns true if the given target supports lock-free atomic
601 /// operations at the specified width and alignment.
602 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
603 uint64_t AlignmentInBits) const {
604 return AtomicSizeInBits <= AlignmentInBits &&
605 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
606 (AtomicSizeInBits <= getCharWidth() ||
607 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
610 /// Return the maximum vector alignment supported for the given target.
611 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
612 /// Return default simd alignment for the given target. Generally, this
613 /// value is type-specific, but this alignment can be used for most of the
614 /// types for the given target.
615 unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
617 /// Return the size of intmax_t and uintmax_t for this target, in bits.
618 unsigned getIntMaxTWidth() const {
619 return getTypeWidth(IntMaxType);
622 // Return the size of unwind_word for this target.
623 virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
625 /// Return the "preferred" register width on this target.
626 virtual unsigned getRegisterWidth() const {
627 // Currently we assume the register width on the target matches the pointer
628 // width, we can introduce a new variable for this if/when some target wants
633 /// Returns the name of the mcount instrumentation function.
634 const char *getMCountName() const {
638 /// Check if the Objective-C built-in boolean type should be signed
641 /// Otherwise, if this returns false, the normal built-in boolean type
642 /// should also be used for Objective-C.
643 bool useSignedCharForObjCBool() const {
644 return UseSignedCharForObjCBool;
646 void noSignedCharForObjCBool() {
647 UseSignedCharForObjCBool = false;
650 /// Check whether the alignment of bit-field types is respected
651 /// when laying out structures.
652 bool useBitFieldTypeAlignment() const {
653 return UseBitFieldTypeAlignment;
656 /// Check whether zero length bitfields should force alignment of
658 bool useZeroLengthBitfieldAlignment() const {
659 return UseZeroLengthBitfieldAlignment;
662 /// Get the fixed alignment value in bits for a member that follows
663 /// a zero length bitfield.
664 unsigned getZeroLengthBitfieldBoundary() const {
665 return ZeroLengthBitfieldBoundary;
668 /// Check whether explicit bitfield alignment attributes should be
669 // honored, as in "__attribute__((aligned(2))) int b : 1;".
670 bool useExplicitBitFieldAlignment() const {
671 return UseExplicitBitFieldAlignment;
674 /// Check whether this target support '\#pragma options align=mac68k'.
675 bool hasAlignMac68kSupport() const {
676 return HasAlignMac68kSupport;
679 /// Return the user string for the specified integer type enum.
681 /// For example, SignedShort -> "short".
682 static const char *getTypeName(IntType T);
684 /// Return the constant suffix for the specified integer type enum.
686 /// For example, SignedLong -> "L".
687 const char *getTypeConstantSuffix(IntType T) const;
689 /// Return the printf format modifier for the specified
690 /// integer type enum.
692 /// For example, SignedLong -> "l".
693 static const char *getTypeFormatModifier(IntType T);
695 /// Check whether the given real type should use the "fpret" flavor of
696 /// Objective-C message passing on this target.
697 bool useObjCFPRetForRealType(RealType T) const {
698 return RealTypeUsesObjCFPRet & (1 << T);
701 /// Check whether _Complex long double should use the "fp2ret" flavor
702 /// of Objective-C message passing on this target.
703 bool useObjCFP2RetForComplexLongDouble() const {
704 return ComplexLongDoubleUsesFP2Ret;
707 /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
708 /// to convert to and from __fp16.
709 /// FIXME: This function should be removed once all targets stop using the
710 /// conversion intrinsics.
711 virtual bool useFP16ConversionIntrinsics() const {
715 /// Specify if mangling based on address space map should be used or
716 /// not for language specific address spaces
717 bool useAddressSpaceMapMangling() const {
718 return UseAddrSpaceMapMangling;
721 ///===---- Other target property query methods --------------------------===//
723 /// Appends the target-specific \#define values for this
724 /// target set to the specified buffer.
725 virtual void getTargetDefines(const LangOptions &Opts,
726 MacroBuilder &Builder) const = 0;
729 /// Return information about target-specific builtins for
730 /// the current primary target, and info about which builtins are non-portable
731 /// across the current set of primary and secondary targets.
732 virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0;
734 /// The __builtin_clz* and __builtin_ctz* built-in
735 /// functions are specified to have undefined results for zero inputs, but
736 /// on targets that support these operations in a way that provides
737 /// well-defined results for zero without loss of performance, it is a good
738 /// idea to avoid optimizing based on that undef behavior.
739 virtual bool isCLZForZeroUndef() const { return true; }
741 /// Returns the kind of __builtin_va_list type that should be used
742 /// with this target.
743 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
745 /// Returns whether or not type \c __builtin_ms_va_list type is
746 /// available on this target.
747 bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
749 /// Returns true for RenderScript.
750 bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
752 /// Returns whether the passed in string is a valid clobber in an
753 /// inline asm statement.
755 /// This is used by Sema.
756 bool isValidClobber(StringRef Name) const;
758 /// Returns whether the passed in string is a valid register name
759 /// according to GCC.
761 /// This is used by Sema for inline asm statements.
762 virtual bool isValidGCCRegisterName(StringRef Name) const;
764 /// Returns the "normalized" GCC register name.
766 /// ReturnCannonical true will return the register name without any additions
767 /// such as "{}" or "%" in it's canonical form, for example:
768 /// ReturnCanonical = true and Name = "rax", will return "ax".
769 StringRef getNormalizedGCCRegisterName(StringRef Name,
770 bool ReturnCanonical = false) const;
772 /// Extracts a register from the passed constraint (if it is a
773 /// single-register constraint) and the asm label expression related to a
774 /// variable in the input or output list of an inline asm statement.
776 /// This function is used by Sema in order to diagnose conflicts between
777 /// the clobber list and the input/output lists.
778 virtual StringRef getConstraintRegister(StringRef Constraint,
779 StringRef Expression) const {
783 struct ConstraintInfo {
786 CI_AllowsMemory = 0x01,
787 CI_AllowsRegister = 0x02,
788 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
789 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
790 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
791 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
799 llvm::SmallSet<int, 4> ImmSet;
801 std::string ConstraintStr; // constraint: "=rm"
802 std::string Name; // Operand name: [foo] with no []'s.
804 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
805 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
807 ImmRange.Min = ImmRange.Max = 0;
810 const std::string &getConstraintStr() const { return ConstraintStr; }
811 const std::string &getName() const { return Name; }
812 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
813 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
814 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
815 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
817 /// Return true if this output operand has a matching
818 /// (tied) input operand.
819 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
821 /// Return true if this input operand is a matching
822 /// constraint that ties it to an output operand.
824 /// If this returns true then getTiedOperand will indicate which output
825 /// operand this is tied to.
826 bool hasTiedOperand() const { return TiedOperand != -1; }
827 unsigned getTiedOperand() const {
828 assert(hasTiedOperand() && "Has no tied operand!");
829 return (unsigned)TiedOperand;
832 bool requiresImmediateConstant() const {
833 return (Flags & CI_ImmediateConstant) != 0;
835 bool isValidAsmImmediate(const llvm::APInt &Value) const {
836 return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) ||
837 ImmSet.count(Value.getZExtValue()) != 0;
840 void setIsReadWrite() { Flags |= CI_ReadWrite; }
841 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
842 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
843 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
844 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
845 void setRequiresImmediate(int Min, int Max) {
846 Flags |= CI_ImmediateConstant;
850 void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
851 Flags |= CI_ImmediateConstant;
852 for (int Exact : Exacts)
853 ImmSet.insert(Exact);
855 void setRequiresImmediate(int Exact) {
856 Flags |= CI_ImmediateConstant;
857 ImmSet.insert(Exact);
859 void setRequiresImmediate() {
860 Flags |= CI_ImmediateConstant;
861 ImmRange.Min = INT_MIN;
862 ImmRange.Max = INT_MAX;
865 /// Indicate that this is an input operand that is tied to
866 /// the specified output operand.
868 /// Copy over the various constraint information from the output.
869 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
870 Output.setHasMatchingInput();
871 Flags = Output.Flags;
873 // Don't copy Name or constraint string.
877 /// Validate register name used for global register variables.
879 /// This function returns true if the register passed in RegName can be used
880 /// for global register variables on this target. In addition, it returns
881 /// true in HasSizeMismatch if the size of the register doesn't match the
882 /// variable size passed in RegSize.
883 virtual bool validateGlobalRegisterVariable(StringRef RegName,
885 bool &HasSizeMismatch) const {
886 HasSizeMismatch = false;
890 // validateOutputConstraint, validateInputConstraint - Checks that
891 // a constraint is valid and provides information about it.
892 // FIXME: These should return a real error instead of just true/false.
893 bool validateOutputConstraint(ConstraintInfo &Info) const;
894 bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints,
895 ConstraintInfo &info) const;
897 virtual bool validateOutputSize(StringRef /*Constraint*/,
898 unsigned /*Size*/) const {
902 virtual bool validateInputSize(StringRef /*Constraint*/,
903 unsigned /*Size*/) const {
907 validateConstraintModifier(StringRef /*Constraint*/,
910 std::string &/*SuggestedModifier*/) const {
914 validateAsmConstraint(const char *&Name,
915 TargetInfo::ConstraintInfo &info) const = 0;
917 bool resolveSymbolicName(const char *&Name,
918 ArrayRef<ConstraintInfo> OutputConstraints,
919 unsigned &Index) const;
921 // Constraint parm will be left pointing at the last character of
922 // the constraint. In practice, it won't be changed unless the
923 // constraint is longer than one character.
924 virtual std::string convertConstraint(const char *&Constraint) const {
925 // 'p' defaults to 'r', but can be overridden by targets.
926 if (*Constraint == 'p')
927 return std::string("r");
928 return std::string(1, *Constraint);
931 /// Returns a string of target-specific clobbers, in LLVM format.
932 virtual const char *getClobbers() const = 0;
934 /// Returns true if NaN encoding is IEEE 754-2008.
935 /// Only MIPS allows a different encoding.
936 virtual bool isNan2008() const {
940 /// Returns the target triple of the primary target.
941 const llvm::Triple &getTriple() const {
945 const llvm::DataLayout &getDataLayout() const {
946 assert(DataLayout && "Uninitialized DataLayout!");
951 const char * const Aliases[5];
952 const char * const Register;
956 const char * const Names[5];
957 const unsigned RegNum;
960 /// Does this target support "protected" visibility?
962 /// Any target which dynamic libraries will naturally support
963 /// something like "default" (meaning that the symbol is visible
964 /// outside this shared object) and "hidden" (meaning that it isn't)
965 /// visibilities, but "protected" is really an ELF-specific concept
966 /// with weird semantics designed around the convenience of dynamic
967 /// linker implementations. Which is not to suggest that there's
968 /// consistent target-independent semantics for "default" visibility
969 /// either; the entire thing is pretty badly mangled.
970 virtual bool hasProtectedVisibility() const { return true; }
972 /// An optional hook that targets can implement to perform semantic
973 /// checking on attribute((section("foo"))) specifiers.
975 /// In this case, "foo" is passed in to be checked. If the section
976 /// specifier is invalid, the backend should return a non-empty string
977 /// that indicates the problem.
979 /// This hook is a simple quality of implementation feature to catch errors
980 /// and give good diagnostics in cases when the assembler or code generator
981 /// would otherwise reject the section specifier.
983 virtual std::string isValidSectionSpecifier(StringRef SR) const {
987 /// Set forced language options.
989 /// Apply changes to the target information with respect to certain
990 /// language options which change the target configuration and adjust
991 /// the language based on the target options where applicable.
992 virtual void adjust(LangOptions &Opts);
994 /// Adjust target options based on codegen options.
995 virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
996 TargetOptions &TargetOpts) const {}
998 /// Initialize the map with the default set of target features for the
999 /// CPU this should include all legal feature strings on the target.
1001 /// \return False on error (invalid features).
1002 virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
1003 DiagnosticsEngine &Diags, StringRef CPU,
1004 const std::vector<std::string> &FeatureVec) const;
1006 /// Get the ABI currently in use.
1007 virtual StringRef getABI() const { return StringRef(); }
1009 /// Get the C++ ABI currently in use.
1010 TargetCXXABI getCXXABI() const {
1014 /// Target the specified CPU.
1016 /// \return False on error (invalid CPU name).
1017 virtual bool setCPU(const std::string &Name) {
1021 /// Fill a SmallVectorImpl with the valid values to setCPU.
1022 virtual void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {}
1024 /// brief Determine whether this TargetInfo supports the given CPU name.
1025 virtual bool isValidCPUName(StringRef Name) const {
1029 /// Use the specified ABI.
1031 /// \return False on error (invalid ABI name).
1032 virtual bool setABI(const std::string &Name) {
1036 /// Use the specified unit for FP math.
1038 /// \return False on error (invalid unit name).
1039 virtual bool setFPMath(StringRef Name) {
1043 /// Enable or disable a specific target feature;
1044 /// the feature name must be valid.
1045 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
1047 bool Enabled) const {
1048 Features[Name] = Enabled;
1051 /// Determine whether this TargetInfo supports the given feature.
1052 virtual bool isValidFeatureName(StringRef Feature) const {
1056 /// Perform initialization based on the user configured
1057 /// set of features (e.g., +sse4).
1059 /// The list is guaranteed to have at most one entry per feature.
1061 /// The target may modify the features list, to change which options are
1062 /// passed onwards to the backend.
1063 /// FIXME: This part should be fixed so that we can change handleTargetFeatures
1064 /// to merely a TargetInfo initialization routine.
1066 /// \return False on error.
1067 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
1068 DiagnosticsEngine &Diags) {
1072 /// Determine whether the given target has the given feature.
1073 virtual bool hasFeature(StringRef Feature) const {
1077 /// Identify whether this taret supports multiversioning of functions,
1078 /// which requires support for cpu_supports and cpu_is functionality.
1079 virtual bool supportsMultiVersioning() const { return false; }
1081 // Validate the contents of the __builtin_cpu_supports(const char*)
1083 virtual bool validateCpuSupports(StringRef Name) const { return false; }
1085 // Return the target-specific priority for features/cpus/vendors so
1086 // that they can be properly sorted for checking.
1087 virtual unsigned multiVersionSortPriority(StringRef Name) const {
1091 // Validate the contents of the __builtin_cpu_is(const char*)
1093 virtual bool validateCpuIs(StringRef Name) const { return false; }
1095 // Validate a cpu_dispatch/cpu_specific CPU option, which is a different list
1096 // from cpu_is, since it checks via features rather than CPUs directly.
1097 virtual bool validateCPUSpecificCPUDispatch(StringRef Name) const {
1101 // Get the character to be added for mangling purposes for cpu_specific.
1102 virtual char CPUSpecificManglingCharacter(StringRef Name) const {
1104 "cpu_specific Multiversioning not implemented on this target");
1107 // Get a list of the features that make up the CPU option for
1108 // cpu_specific/cpu_dispatch so that it can be passed to llvm as optimization
1110 virtual void getCPUSpecificCPUDispatchFeatures(
1111 StringRef Name, llvm::SmallVectorImpl<StringRef> &Features) const {
1113 "cpu_specific Multiversioning not implemented on this target");
1116 // Returns maximal number of args passed in registers.
1117 unsigned getRegParmMax() const {
1118 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
1122 /// Whether the target supports thread-local storage.
1123 bool isTLSSupported() const {
1124 return TLSSupported;
1127 /// Return the maximum alignment (in bits) of a TLS variable
1129 /// Gets the maximum alignment (in bits) of a TLS variable on this target.
1130 /// Returns zero if there is no such constraint.
1131 unsigned short getMaxTLSAlign() const {
1135 /// Whether target supports variable-length arrays.
1136 bool isVLASupported() const { return VLASupported; }
1138 /// Whether the target supports SEH __try.
1139 bool isSEHTrySupported() const {
1140 return getTriple().isOSWindows() &&
1141 (getTriple().getArch() == llvm::Triple::x86 ||
1142 getTriple().getArch() == llvm::Triple::x86_64 ||
1143 getTriple().getArch() == llvm::Triple::aarch64);
1146 /// Return true if {|} are normal characters in the asm string.
1148 /// If this returns false (the default), then {abc|xyz} is syntax
1149 /// that says that when compiling for asm variant #0, "abc" should be
1150 /// generated, but when compiling for asm variant #1, "xyz" should be
1152 bool hasNoAsmVariants() const {
1153 return NoAsmVariants;
1156 /// Return the register number that __builtin_eh_return_regno would
1157 /// return with the specified argument.
1158 /// This corresponds with TargetLowering's getExceptionPointerRegister
1159 /// and getExceptionSelectorRegister in the backend.
1160 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
1164 /// Return the section to use for C++ static initialization functions.
1165 virtual const char *getStaticInitSectionSpecifier() const {
1169 const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; }
1171 /// Return an AST address space which can be used opportunistically
1172 /// for constant global memory. It must be possible to convert pointers into
1173 /// this address space to LangAS::Default. If no such address space exists,
1174 /// this may return None, and such optimizations will be disabled.
1175 virtual llvm::Optional<LangAS> getConstantAddressSpace() const {
1176 return LangAS::Default;
1179 /// Retrieve the name of the platform as it is used in the
1180 /// availability attribute.
1181 StringRef getPlatformName() const { return PlatformName; }
1183 /// Retrieve the minimum desired version of the platform, to
1184 /// which the program should be compiled.
1185 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
1187 bool isBigEndian() const { return BigEndian; }
1188 bool isLittleEndian() const { return !BigEndian; }
1190 enum CallingConvMethodType {
1196 /// Gets the default calling convention for the given target and
1197 /// declaration context.
1198 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
1199 // Not all targets will specify an explicit calling convention that we can
1200 // express. This will always do the right thing, even though it's not
1201 // an explicit calling convention.
1205 enum CallingConvCheckResult {
1211 /// Determines whether a given calling convention is valid for the
1212 /// target. A calling convention can either be accepted, produce a warning
1213 /// and be substituted with the default calling convention, or (someday)
1214 /// produce an error (such as using thiscall on a non-instance function).
1215 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1218 return CCCR_Warning;
1224 enum CallingConvKind {
1230 virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
1232 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
1233 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
1234 virtual bool hasSjLjLowering() const {
1238 /// Check if the target supports CFProtection branch.
1240 checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const;
1242 /// Check if the target supports CFProtection branch.
1244 checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const;
1246 /// Whether target allows to overalign ABI-specified preferred alignment
1247 virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1249 /// Set supported OpenCL extensions and optional core features.
1250 virtual void setSupportedOpenCLOpts() {}
1252 /// Set supported OpenCL extensions as written on command line
1253 virtual void setOpenCLExtensionOpts() {
1254 for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1255 getTargetOpts().SupportedOpenCLOptions.support(Ext);
1259 /// Get supported OpenCL extensions and optional core features.
1260 OpenCLOptions &getSupportedOpenCLOpts() {
1261 return getTargetOpts().SupportedOpenCLOptions;
1264 /// Get const supported OpenCL extensions and optional core features.
1265 const OpenCLOptions &getSupportedOpenCLOpts() const {
1266 return getTargetOpts().SupportedOpenCLOptions;
1269 enum OpenCLTypeKind {
1280 /// Get address space for OpenCL type.
1281 virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
1283 /// \returns Target specific vtbl ptr address space.
1284 virtual unsigned getVtblPtrAddressSpace() const {
1288 /// \returns If a target requires an address within a target specific address
1289 /// space \p AddressSpace to be converted in order to be used, then return the
1290 /// corresponding target specific DWARF address space.
1292 /// \returns Otherwise return None and no conversion will be emitted in the
1294 virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
1298 /// Check the target is valid after it is fully initialized.
1299 virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1304 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1305 return PointerWidth;
1307 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1308 return PointerAlign;
1310 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1313 virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1314 virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1315 virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1320 // Assert the values for the fractional and integral bits for each fixed point
1321 // type follow the restrictions given in clause 6.2.6.3 of N1169.
1322 void CheckFixedPointBits() const;
1325 } // end namespace clang