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 /// \brief 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 "clang/Basic/VersionTuple.h"
24 #include "llvm/ADT/APInt.h"
25 #include "llvm/ADT/IntrusiveRefCntPtr.h"
26 #include "llvm/ADT/Optional.h"
27 #include "llvm/ADT/SmallSet.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/ADT/Triple.h"
31 #include "llvm/IR/DataLayout.h"
32 #include "llvm/Support/DataTypes.h"
42 class DiagnosticsEngine;
50 namespace Builtin { struct Info; }
52 /// \brief 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.
65 unsigned char PointerWidth, PointerAlign;
66 unsigned char BoolWidth, BoolAlign;
67 unsigned char IntWidth, IntAlign;
68 unsigned char HalfWidth, HalfAlign;
69 unsigned char FloatWidth, FloatAlign;
70 unsigned char DoubleWidth, DoubleAlign;
71 unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align;
72 unsigned char LargeArrayMinWidth, LargeArrayAlign;
73 unsigned char LongWidth, LongAlign;
74 unsigned char LongLongWidth, LongLongAlign;
75 unsigned char SuitableAlign;
76 unsigned char DefaultAlignForAttributeAligned;
77 unsigned char MinGlobalAlign;
78 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
79 unsigned short MaxVectorAlign;
80 unsigned short MaxTLSAlign;
81 unsigned short SimdDefaultAlign;
82 unsigned short NewAlign;
83 std::unique_ptr<llvm::DataLayout> DataLayout;
84 const char *MCountName;
85 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
86 *LongDoubleFormat, *Float128Format;
87 unsigned char RegParmMax, SSERegParmMax;
88 TargetCXXABI TheCXXABI;
89 const LangASMap *AddrSpaceMap;
91 mutable StringRef PlatformName;
92 mutable VersionTuple PlatformMinVersion;
94 unsigned HasAlignMac68kSupport : 1;
95 unsigned RealTypeUsesObjCFPRet : 3;
96 unsigned ComplexLongDoubleUsesFP2Ret : 1;
98 unsigned HasBuiltinMSVaList : 1;
100 unsigned IsRenderScriptTarget : 1;
102 // TargetInfo Constructor. Default initializes all fields.
103 TargetInfo(const llvm::Triple &T);
105 void resetDataLayout(StringRef DL) {
106 DataLayout.reset(new llvm::DataLayout(DL));
110 /// \brief Construct a target for the given options.
112 /// \param Opts - The options to use to initialize the target. The target may
113 /// modify the options to canonicalize the target feature information to match
114 /// what the backend expects.
116 CreateTargetInfo(DiagnosticsEngine &Diags,
117 const std::shared_ptr<TargetOptions> &Opts);
119 virtual ~TargetInfo();
121 /// \brief Retrieve the target options.
122 TargetOptions &getTargetOpts() const {
123 assert(TargetOpts && "Missing target options");
127 ///===---- Target Data Type Query Methods -------------------------------===//
150 /// \brief The different kinds of __builtin_va_list types defined by
151 /// the target implementation.
152 enum BuiltinVaListKind {
153 /// typedef char* __builtin_va_list;
154 CharPtrBuiltinVaList = 0,
156 /// typedef void* __builtin_va_list;
157 VoidPtrBuiltinVaList,
159 /// __builtin_va_list as defined by the AArch64 ABI
160 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
161 AArch64ABIBuiltinVaList,
163 /// __builtin_va_list as defined by the PNaCl ABI:
164 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
165 PNaClABIBuiltinVaList,
167 /// __builtin_va_list as defined by the Power ABI:
168 /// https://www.power.org
169 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
170 PowerABIBuiltinVaList,
172 /// __builtin_va_list as defined by the x86-64 ABI:
173 /// http://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf
174 X86_64ABIBuiltinVaList,
176 /// __builtin_va_list as defined by ARM AAPCS ABI
177 /// http://infocenter.arm.com
178 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
179 AAPCSABIBuiltinVaList,
181 // typedef struct __va_list_tag
185 // void *__overflow_arg_area;
186 // void *__reg_save_area;
192 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
193 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
196 /// \brief Whether Objective-C's built-in boolean type should be signed char.
198 /// Otherwise, when this flag is not set, the normal built-in boolean type is
200 unsigned UseSignedCharForObjCBool : 1;
202 /// Control whether the alignment of bit-field types is respected when laying
203 /// out structures. If true, then the alignment of the bit-field type will be
204 /// used to (a) impact the alignment of the containing structure, and (b)
205 /// ensure that the individual bit-field will not straddle an alignment
207 unsigned UseBitFieldTypeAlignment : 1;
209 /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
210 /// the next bitfield.
212 /// If the alignment of the zero length bitfield is greater than the member
213 /// that follows it, `bar', `bar' will be aligned as the type of the
214 /// zero-length bitfield.
215 unsigned UseZeroLengthBitfieldAlignment : 1;
217 /// \brief Whether explicit bit field alignment attributes are honored.
218 unsigned UseExplicitBitFieldAlignment : 1;
220 /// If non-zero, specifies a fixed alignment value for bitfields that follow
221 /// zero length bitfield, regardless of the zero length bitfield type.
222 unsigned ZeroLengthBitfieldBoundary;
224 /// \brief Specify if mangling based on address space map should be used or
225 /// not for language specific address spaces
226 bool UseAddrSpaceMapMangling;
229 IntType getSizeType() const { return SizeType; }
230 IntType getSignedSizeType() const {
238 case UnsignedLongLong:
239 return SignedLongLong;
241 llvm_unreachable("Invalid SizeType");
244 IntType getIntMaxType() const { return IntMaxType; }
245 IntType getUIntMaxType() const {
246 return getCorrespondingUnsignedType(IntMaxType);
248 IntType getPtrDiffType(unsigned AddrSpace) const {
249 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
251 IntType getUnsignedPtrDiffType(unsigned AddrSpace) const {
252 return getCorrespondingUnsignedType(getPtrDiffType(AddrSpace));
254 IntType getIntPtrType() const { return IntPtrType; }
255 IntType getUIntPtrType() const {
256 return getCorrespondingUnsignedType(IntPtrType);
258 IntType getWCharType() const { return WCharType; }
259 IntType getWIntType() const { return WIntType; }
260 IntType getChar16Type() const { return Char16Type; }
261 IntType getChar32Type() const { return Char32Type; }
262 IntType getInt64Type() const { return Int64Type; }
263 IntType getUInt64Type() const {
264 return getCorrespondingUnsignedType(Int64Type);
266 IntType getSigAtomicType() const { return SigAtomicType; }
267 IntType getProcessIDType() const { return ProcessIDType; }
269 static IntType getCorrespondingUnsignedType(IntType T) {
274 return UnsignedShort;
280 return UnsignedLongLong;
282 llvm_unreachable("Unexpected signed integer type");
286 /// \brief Return the width (in bits) of the specified integer type enum.
288 /// For example, SignedInt -> getIntWidth().
289 unsigned getTypeWidth(IntType T) const;
291 /// \brief Return integer type with specified width.
292 virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
294 /// \brief Return the smallest integer type with at least the specified width.
295 virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
296 bool IsSigned) const;
298 /// \brief Return floating point type with specified width.
299 RealType getRealTypeByWidth(unsigned BitWidth) const;
301 /// \brief Return the alignment (in bits) of the specified integer type enum.
303 /// For example, SignedInt -> getIntAlign().
304 unsigned getTypeAlign(IntType T) const;
306 /// \brief Returns true if the type is signed; false otherwise.
307 static bool isTypeSigned(IntType T);
309 /// \brief Return the width of pointers on this target, for the
310 /// specified address space.
311 uint64_t getPointerWidth(unsigned AddrSpace) const {
312 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
314 uint64_t getPointerAlign(unsigned AddrSpace) const {
315 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
318 /// \brief Return the maximum width of pointers on this target.
319 virtual uint64_t getMaxPointerWidth() const {
323 /// \brief Get integer value for null pointer.
324 /// \param AddrSpace address space of pointee in source language.
325 virtual uint64_t getNullPointerValue(LangAS AddrSpace) const { return 0; }
327 /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
328 unsigned getBoolWidth() const { return BoolWidth; }
330 /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
331 unsigned getBoolAlign() const { return BoolAlign; }
333 unsigned getCharWidth() const { return 8; } // FIXME
334 unsigned getCharAlign() const { return 8; } // FIXME
336 /// \brief Return the size of 'signed short' and 'unsigned short' for this
338 unsigned getShortWidth() const { return 16; } // FIXME
340 /// \brief Return the alignment of 'signed short' and 'unsigned short' for
342 unsigned getShortAlign() const { return 16; } // FIXME
344 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
345 /// this target, in bits.
346 unsigned getIntWidth() const { return IntWidth; }
347 unsigned getIntAlign() const { return IntAlign; }
349 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
350 /// for this target, in bits.
351 unsigned getLongWidth() const { return LongWidth; }
352 unsigned getLongAlign() const { return LongAlign; }
354 /// getLongLongWidth/Align - Return the size of 'signed long long' and
355 /// 'unsigned long long' for this target, in bits.
356 unsigned getLongLongWidth() const { return LongLongWidth; }
357 unsigned getLongLongAlign() const { return LongLongAlign; }
359 /// \brief Determine whether the __int128 type is supported on this target.
360 virtual bool hasInt128Type() const {
361 return getPointerWidth(0) >= 64;
364 /// \brief Determine whether the __float128 type is supported on this target.
365 virtual bool hasFloat128Type() const { return HasFloat128; }
367 /// \brief Return the alignment that is suitable for storing any
368 /// object with a fundamental alignment requirement.
369 unsigned getSuitableAlign() const { return SuitableAlign; }
371 /// \brief Return the default alignment for __attribute__((aligned)) on
372 /// this target, to be used if no alignment value is specified.
373 unsigned getDefaultAlignForAttributeAligned() const {
374 return DefaultAlignForAttributeAligned;
377 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
378 /// unless its alignment is explicitly reduced via attributes.
379 unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
381 /// Return the largest alignment for which a suitably-sized allocation with
382 /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
384 unsigned getNewAlign() const {
385 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
388 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
390 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
391 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
393 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
395 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
396 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
398 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
400 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
401 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
403 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
404 unsigned getHalfWidth() const { return HalfWidth; }
405 unsigned getHalfAlign() const { return HalfAlign; }
406 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
408 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
409 unsigned getFloatWidth() const { return FloatWidth; }
410 unsigned getFloatAlign() const { return FloatAlign; }
411 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
413 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
414 unsigned getDoubleWidth() const { return DoubleWidth; }
415 unsigned getDoubleAlign() const { return DoubleAlign; }
416 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
418 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
420 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
421 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
422 const llvm::fltSemantics &getLongDoubleFormat() const {
423 return *LongDoubleFormat;
426 /// getFloat128Width/Align/Format - Return the size/align/format of
428 unsigned getFloat128Width() const { return 128; }
429 unsigned getFloat128Align() const { return Float128Align; }
430 const llvm::fltSemantics &getFloat128Format() const {
431 return *Float128Format;
434 /// \brief Return true if the 'long double' type should be mangled like
436 virtual bool useFloat128ManglingForLongDouble() const { return false; }
438 /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
439 virtual unsigned getFloatEvalMethod() const { return 0; }
441 // getLargeArrayMinWidth/Align - Return the minimum array size that is
442 // 'large' and its alignment.
443 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
444 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
446 /// \brief Return the maximum width lock-free atomic operation which will
447 /// ever be supported for the given target
448 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
449 /// \brief Return the maximum width lock-free atomic operation which can be
450 /// inlined given the supported features of the given target.
451 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
452 /// \brief Set the maximum inline or promote width lock-free atomic operation
453 /// for the given target.
454 virtual void setMaxAtomicWidth() {}
455 /// \brief Returns true if the given target supports lock-free atomic
456 /// operations at the specified width and alignment.
457 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
458 uint64_t AlignmentInBits) const {
459 return AtomicSizeInBits <= AlignmentInBits &&
460 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
461 (AtomicSizeInBits <= getCharWidth() ||
462 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
465 /// \brief Return the maximum vector alignment supported for the given target.
466 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
467 /// \brief Return default simd alignment for the given target. Generally, this
468 /// value is type-specific, but this alignment can be used for most of the
469 /// types for the given target.
470 unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
472 /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
473 unsigned getIntMaxTWidth() const {
474 return getTypeWidth(IntMaxType);
477 // Return the size of unwind_word for this target.
478 virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
480 /// \brief Return the "preferred" register width on this target.
481 virtual unsigned getRegisterWidth() const {
482 // Currently we assume the register width on the target matches the pointer
483 // width, we can introduce a new variable for this if/when some target wants
488 /// \brief Returns the name of the mcount instrumentation function.
489 const char *getMCountName() const {
493 /// \brief Check if the Objective-C built-in boolean type should be signed
496 /// Otherwise, if this returns false, the normal built-in boolean type
497 /// should also be used for Objective-C.
498 bool useSignedCharForObjCBool() const {
499 return UseSignedCharForObjCBool;
501 void noSignedCharForObjCBool() {
502 UseSignedCharForObjCBool = false;
505 /// \brief Check whether the alignment of bit-field types is respected
506 /// when laying out structures.
507 bool useBitFieldTypeAlignment() const {
508 return UseBitFieldTypeAlignment;
511 /// \brief Check whether zero length bitfields should force alignment of
513 bool useZeroLengthBitfieldAlignment() const {
514 return UseZeroLengthBitfieldAlignment;
517 /// \brief Get the fixed alignment value in bits for a member that follows
518 /// a zero length bitfield.
519 unsigned getZeroLengthBitfieldBoundary() const {
520 return ZeroLengthBitfieldBoundary;
523 /// \brief Check whether explicit bitfield alignment attributes should be
524 // honored, as in "__attribute__((aligned(2))) int b : 1;".
525 bool useExplicitBitFieldAlignment() const {
526 return UseExplicitBitFieldAlignment;
529 /// \brief Check whether this target support '\#pragma options align=mac68k'.
530 bool hasAlignMac68kSupport() const {
531 return HasAlignMac68kSupport;
534 /// \brief Return the user string for the specified integer type enum.
536 /// For example, SignedShort -> "short".
537 static const char *getTypeName(IntType T);
539 /// \brief Return the constant suffix for the specified integer type enum.
541 /// For example, SignedLong -> "L".
542 const char *getTypeConstantSuffix(IntType T) const;
544 /// \brief Return the printf format modifier for the specified
545 /// integer type enum.
547 /// For example, SignedLong -> "l".
548 static const char *getTypeFormatModifier(IntType T);
550 /// \brief Check whether the given real type should use the "fpret" flavor of
551 /// Objective-C message passing on this target.
552 bool useObjCFPRetForRealType(RealType T) const {
553 return RealTypeUsesObjCFPRet & (1 << T);
556 /// \brief Check whether _Complex long double should use the "fp2ret" flavor
557 /// of Objective-C message passing on this target.
558 bool useObjCFP2RetForComplexLongDouble() const {
559 return ComplexLongDoubleUsesFP2Ret;
562 /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
563 /// to convert to and from __fp16.
564 /// FIXME: This function should be removed once all targets stop using the
565 /// conversion intrinsics.
566 virtual bool useFP16ConversionIntrinsics() const {
570 /// \brief Specify if mangling based on address space map should be used or
571 /// not for language specific address spaces
572 bool useAddressSpaceMapMangling() const {
573 return UseAddrSpaceMapMangling;
576 ///===---- Other target property query methods --------------------------===//
578 /// \brief Appends the target-specific \#define values for this
579 /// target set to the specified buffer.
580 virtual void getTargetDefines(const LangOptions &Opts,
581 MacroBuilder &Builder) const = 0;
584 /// Return information about target-specific builtins for
585 /// the current primary target, and info about which builtins are non-portable
586 /// across the current set of primary and secondary targets.
587 virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0;
589 /// The __builtin_clz* and __builtin_ctz* built-in
590 /// functions are specified to have undefined results for zero inputs, but
591 /// on targets that support these operations in a way that provides
592 /// well-defined results for zero without loss of performance, it is a good
593 /// idea to avoid optimizing based on that undef behavior.
594 virtual bool isCLZForZeroUndef() const { return true; }
596 /// \brief Returns the kind of __builtin_va_list type that should be used
597 /// with this target.
598 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
600 /// Returns whether or not type \c __builtin_ms_va_list type is
601 /// available on this target.
602 bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
604 /// Returns true for RenderScript.
605 bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
607 /// \brief Returns whether the passed in string is a valid clobber in an
608 /// inline asm statement.
610 /// This is used by Sema.
611 bool isValidClobber(StringRef Name) const;
613 /// \brief Returns whether the passed in string is a valid register name
614 /// according to GCC.
616 /// This is used by Sema for inline asm statements.
617 bool isValidGCCRegisterName(StringRef Name) const;
619 /// \brief Returns the "normalized" GCC register name.
621 /// ReturnCannonical true will return the register name without any additions
622 /// such as "{}" or "%" in it's canonical form, for example:
623 /// ReturnCanonical = true and Name = "rax", will return "ax".
624 StringRef getNormalizedGCCRegisterName(StringRef Name,
625 bool ReturnCanonical = false) const;
627 virtual StringRef getConstraintRegister(const StringRef &Constraint,
628 const StringRef &Expression) const {
632 struct ConstraintInfo {
635 CI_AllowsMemory = 0x01,
636 CI_AllowsRegister = 0x02,
637 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
638 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
639 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
640 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
648 llvm::SmallSet<int, 4> ImmSet;
650 std::string ConstraintStr; // constraint: "=rm"
651 std::string Name; // Operand name: [foo] with no []'s.
653 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
654 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
656 ImmRange.Min = ImmRange.Max = 0;
659 const std::string &getConstraintStr() const { return ConstraintStr; }
660 const std::string &getName() const { return Name; }
661 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
662 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
663 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
664 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
666 /// \brief Return true if this output operand has a matching
667 /// (tied) input operand.
668 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
670 /// \brief Return true if this input operand is a matching
671 /// constraint that ties it to an output operand.
673 /// If this returns true then getTiedOperand will indicate which output
674 /// operand this is tied to.
675 bool hasTiedOperand() const { return TiedOperand != -1; }
676 unsigned getTiedOperand() const {
677 assert(hasTiedOperand() && "Has no tied operand!");
678 return (unsigned)TiedOperand;
681 bool requiresImmediateConstant() const {
682 return (Flags & CI_ImmediateConstant) != 0;
684 bool isValidAsmImmediate(const llvm::APInt &Value) const {
685 return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) ||
686 ImmSet.count(Value.getZExtValue()) != 0;
689 void setIsReadWrite() { Flags |= CI_ReadWrite; }
690 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
691 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
692 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
693 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
694 void setRequiresImmediate(int Min, int Max) {
695 Flags |= CI_ImmediateConstant;
699 void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
700 Flags |= CI_ImmediateConstant;
701 for (int Exact : Exacts)
702 ImmSet.insert(Exact);
704 void setRequiresImmediate(int Exact) {
705 Flags |= CI_ImmediateConstant;
706 ImmSet.insert(Exact);
708 void setRequiresImmediate() {
709 Flags |= CI_ImmediateConstant;
710 ImmRange.Min = INT_MIN;
711 ImmRange.Max = INT_MAX;
714 /// \brief Indicate that this is an input operand that is tied to
715 /// the specified output operand.
717 /// Copy over the various constraint information from the output.
718 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
719 Output.setHasMatchingInput();
720 Flags = Output.Flags;
722 // Don't copy Name or constraint string.
726 /// \brief Validate register name used for global register variables.
728 /// This function returns true if the register passed in RegName can be used
729 /// for global register variables on this target. In addition, it returns
730 /// true in HasSizeMismatch if the size of the register doesn't match the
731 /// variable size passed in RegSize.
732 virtual bool validateGlobalRegisterVariable(StringRef RegName,
734 bool &HasSizeMismatch) const {
735 HasSizeMismatch = false;
739 // validateOutputConstraint, validateInputConstraint - Checks that
740 // a constraint is valid and provides information about it.
741 // FIXME: These should return a real error instead of just true/false.
742 bool validateOutputConstraint(ConstraintInfo &Info) const;
743 bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints,
744 ConstraintInfo &info) const;
746 virtual bool validateOutputSize(StringRef /*Constraint*/,
747 unsigned /*Size*/) const {
751 virtual bool validateInputSize(StringRef /*Constraint*/,
752 unsigned /*Size*/) const {
756 validateConstraintModifier(StringRef /*Constraint*/,
759 std::string &/*SuggestedModifier*/) const {
763 validateAsmConstraint(const char *&Name,
764 TargetInfo::ConstraintInfo &info) const = 0;
766 bool resolveSymbolicName(const char *&Name,
767 ArrayRef<ConstraintInfo> OutputConstraints,
768 unsigned &Index) const;
770 // Constraint parm will be left pointing at the last character of
771 // the constraint. In practice, it won't be changed unless the
772 // constraint is longer than one character.
773 virtual std::string convertConstraint(const char *&Constraint) const {
774 // 'p' defaults to 'r', but can be overridden by targets.
775 if (*Constraint == 'p')
776 return std::string("r");
777 return std::string(1, *Constraint);
780 /// \brief Returns a string of target-specific clobbers, in LLVM format.
781 virtual const char *getClobbers() const = 0;
783 /// \brief Returns true if NaN encoding is IEEE 754-2008.
784 /// Only MIPS allows a different encoding.
785 virtual bool isNan2008() const {
789 /// \brief Returns the target triple of the primary target.
790 const llvm::Triple &getTriple() const {
794 const llvm::DataLayout &getDataLayout() const {
795 assert(DataLayout && "Uninitialized DataLayout!");
800 const char * const Aliases[5];
801 const char * const Register;
805 const char * const Names[5];
806 const unsigned RegNum;
809 /// \brief Does this target support "protected" visibility?
811 /// Any target which dynamic libraries will naturally support
812 /// something like "default" (meaning that the symbol is visible
813 /// outside this shared object) and "hidden" (meaning that it isn't)
814 /// visibilities, but "protected" is really an ELF-specific concept
815 /// with weird semantics designed around the convenience of dynamic
816 /// linker implementations. Which is not to suggest that there's
817 /// consistent target-independent semantics for "default" visibility
818 /// either; the entire thing is pretty badly mangled.
819 virtual bool hasProtectedVisibility() const { return true; }
821 /// \brief An optional hook that targets can implement to perform semantic
822 /// checking on attribute((section("foo"))) specifiers.
824 /// In this case, "foo" is passed in to be checked. If the section
825 /// specifier is invalid, the backend should return a non-empty string
826 /// that indicates the problem.
828 /// This hook is a simple quality of implementation feature to catch errors
829 /// and give good diagnostics in cases when the assembler or code generator
830 /// would otherwise reject the section specifier.
832 virtual std::string isValidSectionSpecifier(StringRef SR) const {
836 /// \brief Set forced language options.
838 /// Apply changes to the target information with respect to certain
839 /// language options which change the target configuration and adjust
840 /// the language based on the target options where applicable.
841 virtual void adjust(LangOptions &Opts);
843 /// \brief Adjust target options based on codegen options.
844 virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
845 TargetOptions &TargetOpts) const {}
847 /// \brief Initialize the map with the default set of target features for the
848 /// CPU this should include all legal feature strings on the target.
850 /// \return False on error (invalid features).
851 virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
852 DiagnosticsEngine &Diags, StringRef CPU,
853 const std::vector<std::string> &FeatureVec) const;
855 /// \brief Get the ABI currently in use.
856 virtual StringRef getABI() const { return StringRef(); }
858 /// \brief Get the C++ ABI currently in use.
859 TargetCXXABI getCXXABI() const {
863 /// \brief Target the specified CPU.
865 /// \return False on error (invalid CPU name).
866 virtual bool setCPU(const std::string &Name) {
870 /// brief Determine whether this TargetInfo supports the given CPU name.
871 virtual bool isValidCPUName(StringRef Name) const {
875 /// \brief Use the specified ABI.
877 /// \return False on error (invalid ABI name).
878 virtual bool setABI(const std::string &Name) {
882 /// \brief Use the specified unit for FP math.
884 /// \return False on error (invalid unit name).
885 virtual bool setFPMath(StringRef Name) {
889 /// \brief Enable or disable a specific target feature;
890 /// the feature name must be valid.
891 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
893 bool Enabled) const {
894 Features[Name] = Enabled;
897 /// \brief Determine whether this TargetInfo supports the given feature.
898 virtual bool isValidFeatureName(StringRef Feature) const {
902 /// \brief Perform initialization based on the user configured
903 /// set of features (e.g., +sse4).
905 /// The list is guaranteed to have at most one entry per feature.
907 /// The target may modify the features list, to change which options are
908 /// passed onwards to the backend.
909 /// FIXME: This part should be fixed so that we can change handleTargetFeatures
910 /// to merely a TargetInfo initialization routine.
912 /// \return False on error.
913 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
914 DiagnosticsEngine &Diags) {
918 /// \brief Determine whether the given target has the given feature.
919 virtual bool hasFeature(StringRef Feature) const {
923 // \brief Validate the contents of the __builtin_cpu_supports(const char*)
925 virtual bool validateCpuSupports(StringRef Name) const { return false; }
927 // \brief Validate the contents of the __builtin_cpu_is(const char*)
929 virtual bool validateCpuIs(StringRef Name) const { return false; }
931 // \brief Returns maximal number of args passed in registers.
932 unsigned getRegParmMax() const {
933 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
937 /// \brief Whether the target supports thread-local storage.
938 bool isTLSSupported() const {
942 /// \brief Return the maximum alignment (in bits) of a TLS variable
944 /// Gets the maximum alignment (in bits) of a TLS variable on this target.
945 /// Returns zero if there is no such constraint.
946 unsigned short getMaxTLSAlign() const {
950 /// \brief Whether target supports variable-length arrays.
951 bool isVLASupported() const { return VLASupported; }
953 /// \brief Whether the target supports SEH __try.
954 bool isSEHTrySupported() const {
955 return getTriple().isOSWindows() &&
956 (getTriple().getArch() == llvm::Triple::x86 ||
957 getTriple().getArch() == llvm::Triple::x86_64);
960 /// \brief Return true if {|} are normal characters in the asm string.
962 /// If this returns false (the default), then {abc|xyz} is syntax
963 /// that says that when compiling for asm variant #0, "abc" should be
964 /// generated, but when compiling for asm variant #1, "xyz" should be
966 bool hasNoAsmVariants() const {
967 return NoAsmVariants;
970 /// \brief Return the register number that __builtin_eh_return_regno would
971 /// return with the specified argument.
972 /// This corresponds with TargetLowering's getExceptionPointerRegister
973 /// and getExceptionSelectorRegister in the backend.
974 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
978 /// \brief Return the section to use for C++ static initialization functions.
979 virtual const char *getStaticInitSectionSpecifier() const {
983 const LangASMap &getAddressSpaceMap() const { return *AddrSpaceMap; }
985 /// \brief Return an AST address space which can be used opportunistically
986 /// for constant global memory. It must be possible to convert pointers into
987 /// this address space to LangAS::Default. If no such address space exists,
988 /// this may return None, and such optimizations will be disabled.
989 virtual llvm::Optional<LangAS> getConstantAddressSpace() const {
990 return LangAS::Default;
993 /// \brief Retrieve the name of the platform as it is used in the
994 /// availability attribute.
995 StringRef getPlatformName() const { return PlatformName; }
997 /// \brief Retrieve the minimum desired version of the platform, to
998 /// which the program should be compiled.
999 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
1001 bool isBigEndian() const { return BigEndian; }
1002 bool isLittleEndian() const { return !BigEndian; }
1004 enum CallingConvMethodType {
1010 /// \brief Gets the default calling convention for the given target and
1011 /// declaration context.
1012 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
1013 // Not all targets will specify an explicit calling convention that we can
1014 // express. This will always do the right thing, even though it's not
1015 // an explicit calling convention.
1019 enum CallingConvCheckResult {
1025 /// \brief Determines whether a given calling convention is valid for the
1026 /// target. A calling convention can either be accepted, produce a warning
1027 /// and be substituted with the default calling convention, or (someday)
1028 /// produce an error (such as using thiscall on a non-instance function).
1029 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1032 return CCCR_Warning;
1038 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
1039 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
1040 virtual bool hasSjLjLowering() const {
1044 /// \brief Whether target allows to overalign ABI-specified preferred alignment
1045 virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1047 /// \brief Set supported OpenCL extensions and optional core features.
1048 virtual void setSupportedOpenCLOpts() {}
1050 /// \brief Set supported OpenCL extensions as written on command line
1051 virtual void setOpenCLExtensionOpts() {
1052 for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1053 getTargetOpts().SupportedOpenCLOptions.support(Ext);
1057 /// \brief Get supported OpenCL extensions and optional core features.
1058 OpenCLOptions &getSupportedOpenCLOpts() {
1059 return getTargetOpts().SupportedOpenCLOptions;
1062 /// \brief Get const supported OpenCL extensions and optional core features.
1063 const OpenCLOptions &getSupportedOpenCLOpts() const {
1064 return getTargetOpts().SupportedOpenCLOptions;
1067 enum OpenCLTypeKind {
1078 /// \brief Get address space for OpenCL type.
1079 virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
1081 /// \returns Target specific vtbl ptr address space.
1082 virtual unsigned getVtblPtrAddressSpace() const {
1086 /// \returns If a target requires an address within a target specific address
1087 /// space \p AddressSpace to be converted in order to be used, then return the
1088 /// corresponding target specific DWARF address space.
1090 /// \returns Otherwise return None and no conversion will be emitted in the
1092 virtual Optional<unsigned> getDWARFAddressSpace(unsigned AddressSpace) const {
1096 /// \brief Check the target is valid after it is fully initialized.
1097 virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1102 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1103 return PointerWidth;
1105 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1106 return PointerAlign;
1108 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1111 virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1112 virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1113 virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1118 } // end namespace clang