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/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"
41 class DiagnosticsEngine;
49 namespace Builtin { struct Info; }
51 /// \brief Exposes information about the current target.
53 class TargetInfo : public RefCountedBase<TargetInfo> {
54 std::shared_ptr<TargetOptions> TargetOpts;
57 // Target values set by the ctor of the actual target implementation. Default
58 // values are specified by the TargetInfo constructor.
61 bool NoAsmVariants; // True if {|} are normal characters.
63 unsigned char PointerWidth, PointerAlign;
64 unsigned char BoolWidth, BoolAlign;
65 unsigned char IntWidth, IntAlign;
66 unsigned char HalfWidth, HalfAlign;
67 unsigned char FloatWidth, FloatAlign;
68 unsigned char DoubleWidth, DoubleAlign;
69 unsigned char LongDoubleWidth, LongDoubleAlign, Float128Align;
70 unsigned char LargeArrayMinWidth, LargeArrayAlign;
71 unsigned char LongWidth, LongAlign;
72 unsigned char LongLongWidth, LongLongAlign;
73 unsigned char SuitableAlign;
74 unsigned char DefaultAlignForAttributeAligned;
75 unsigned char MinGlobalAlign;
76 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
77 unsigned short MaxVectorAlign;
78 unsigned short MaxTLSAlign;
79 unsigned short SimdDefaultAlign;
80 unsigned short NewAlign;
81 std::unique_ptr<llvm::DataLayout> DataLayout;
82 const char *MCountName;
83 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
84 *LongDoubleFormat, *Float128Format;
85 unsigned char RegParmMax, SSERegParmMax;
86 TargetCXXABI TheCXXABI;
87 const LangAS::Map *AddrSpaceMap;
89 mutable StringRef PlatformName;
90 mutable VersionTuple PlatformMinVersion;
92 unsigned HasAlignMac68kSupport : 1;
93 unsigned RealTypeUsesObjCFPRet : 3;
94 unsigned ComplexLongDoubleUsesFP2Ret : 1;
96 unsigned HasBuiltinMSVaList : 1;
98 unsigned IsRenderScriptTarget : 1;
100 // TargetInfo Constructor. Default initializes all fields.
101 TargetInfo(const llvm::Triple &T);
103 void resetDataLayout(StringRef DL) {
104 DataLayout.reset(new llvm::DataLayout(DL));
108 /// \brief Construct a target for the given options.
110 /// \param Opts - The options to use to initialize the target. The target may
111 /// modify the options to canonicalize the target feature information to match
112 /// what the backend expects.
114 CreateTargetInfo(DiagnosticsEngine &Diags,
115 const std::shared_ptr<TargetOptions> &Opts);
117 virtual ~TargetInfo();
119 /// \brief Retrieve the target options.
120 TargetOptions &getTargetOpts() const {
121 assert(TargetOpts && "Missing target options");
125 ///===---- Target Data Type Query Methods -------------------------------===//
148 /// \brief The different kinds of __builtin_va_list types defined by
149 /// the target implementation.
150 enum BuiltinVaListKind {
151 /// typedef char* __builtin_va_list;
152 CharPtrBuiltinVaList = 0,
154 /// typedef void* __builtin_va_list;
155 VoidPtrBuiltinVaList,
157 /// __builtin_va_list as defind by the AArch64 ABI
158 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
159 AArch64ABIBuiltinVaList,
161 /// __builtin_va_list as defined by the PNaCl ABI:
162 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
163 PNaClABIBuiltinVaList,
165 /// __builtin_va_list as defined by the Power ABI:
166 /// https://www.power.org
167 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
168 PowerABIBuiltinVaList,
170 /// __builtin_va_list as defined by the x86-64 ABI:
171 /// http://www.x86-64.org/documentation/abi.pdf
172 X86_64ABIBuiltinVaList,
174 /// __builtin_va_list as defined by ARM AAPCS ABI
175 /// http://infocenter.arm.com
176 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
177 AAPCSABIBuiltinVaList,
179 // typedef struct __va_list_tag
183 // void *__overflow_arg_area;
184 // void *__reg_save_area;
190 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
191 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
194 /// \brief Whether Objective-C's built-in boolean type should be signed char.
196 /// Otherwise, when this flag is not set, the normal built-in boolean type is
198 unsigned UseSignedCharForObjCBool : 1;
200 /// Control whether the alignment of bit-field types is respected when laying
201 /// out structures. If true, then the alignment of the bit-field type will be
202 /// used to (a) impact the alignment of the containing structure, and (b)
203 /// ensure that the individual bit-field will not straddle an alignment
205 unsigned UseBitFieldTypeAlignment : 1;
207 /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
208 /// the next bitfield.
210 /// If the alignment of the zero length bitfield is greater than the member
211 /// that follows it, `bar', `bar' will be aligned as the type of the
212 /// zero-length bitfield.
213 unsigned UseZeroLengthBitfieldAlignment : 1;
215 /// \brief Whether explicit bit field alignment attributes are honored.
216 unsigned UseExplicitBitFieldAlignment : 1;
218 /// If non-zero, specifies a fixed alignment value for bitfields that follow
219 /// zero length bitfield, regardless of the zero length bitfield type.
220 unsigned ZeroLengthBitfieldBoundary;
222 /// \brief Specify if mangling based on address space map should be used or
223 /// not for language specific address spaces
224 bool UseAddrSpaceMapMangling;
227 IntType getSizeType() const { return SizeType; }
228 IntType getIntMaxType() const { return IntMaxType; }
229 IntType getUIntMaxType() const {
230 return getCorrespondingUnsignedType(IntMaxType);
232 IntType getPtrDiffType(unsigned AddrSpace) const {
233 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
235 IntType getIntPtrType() const { return IntPtrType; }
236 IntType getUIntPtrType() const {
237 return getCorrespondingUnsignedType(IntPtrType);
239 IntType getWCharType() const { return WCharType; }
240 IntType getWIntType() const { return WIntType; }
241 IntType getChar16Type() const { return Char16Type; }
242 IntType getChar32Type() const { return Char32Type; }
243 IntType getInt64Type() const { return Int64Type; }
244 IntType getUInt64Type() const {
245 return getCorrespondingUnsignedType(Int64Type);
247 IntType getSigAtomicType() const { return SigAtomicType; }
248 IntType getProcessIDType() const { return ProcessIDType; }
250 static IntType getCorrespondingUnsignedType(IntType T) {
255 return UnsignedShort;
261 return UnsignedLongLong;
263 llvm_unreachable("Unexpected signed integer type");
267 /// \brief Return the width (in bits) of the specified integer type enum.
269 /// For example, SignedInt -> getIntWidth().
270 unsigned getTypeWidth(IntType T) const;
272 /// \brief Return integer type with specified width.
273 virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
275 /// \brief Return the smallest integer type with at least the specified width.
276 virtual IntType getLeastIntTypeByWidth(unsigned BitWidth,
277 bool IsSigned) const;
279 /// \brief Return floating point type with specified width.
280 RealType getRealTypeByWidth(unsigned BitWidth) const;
282 /// \brief Return the alignment (in bits) of the specified integer type enum.
284 /// For example, SignedInt -> getIntAlign().
285 unsigned getTypeAlign(IntType T) const;
287 /// \brief Returns true if the type is signed; false otherwise.
288 static bool isTypeSigned(IntType T);
290 /// \brief Return the width of pointers on this target, for the
291 /// specified address space.
292 uint64_t getPointerWidth(unsigned AddrSpace) const {
293 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
295 uint64_t getPointerAlign(unsigned AddrSpace) const {
296 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
299 /// \brief Return the maximum width of pointers on this target.
300 virtual uint64_t getMaxPointerWidth() const {
304 /// \brief Get integer value for null pointer.
305 /// \param AddrSpace address space of pointee in source language.
306 virtual uint64_t getNullPointerValue(unsigned AddrSpace) const {
310 /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
311 unsigned getBoolWidth() const { return BoolWidth; }
313 /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
314 unsigned getBoolAlign() const { return BoolAlign; }
316 unsigned getCharWidth() const { return 8; } // FIXME
317 unsigned getCharAlign() const { return 8; } // FIXME
319 /// \brief Return the size of 'signed short' and 'unsigned short' for this
321 unsigned getShortWidth() const { return 16; } // FIXME
323 /// \brief Return the alignment of 'signed short' and 'unsigned short' for
325 unsigned getShortAlign() const { return 16; } // FIXME
327 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
328 /// this target, in bits.
329 unsigned getIntWidth() const { return IntWidth; }
330 unsigned getIntAlign() const { return IntAlign; }
332 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
333 /// for this target, in bits.
334 unsigned getLongWidth() const { return LongWidth; }
335 unsigned getLongAlign() const { return LongAlign; }
337 /// getLongLongWidth/Align - Return the size of 'signed long long' and
338 /// 'unsigned long long' for this target, in bits.
339 unsigned getLongLongWidth() const { return LongLongWidth; }
340 unsigned getLongLongAlign() const { return LongLongAlign; }
342 /// \brief Determine whether the __int128 type is supported on this target.
343 virtual bool hasInt128Type() const {
344 return getPointerWidth(0) >= 64;
347 /// \brief Determine whether the __float128 type is supported on this target.
348 virtual bool hasFloat128Type() const { return HasFloat128; }
350 /// \brief Return the alignment that is suitable for storing any
351 /// object with a fundamental alignment requirement.
352 unsigned getSuitableAlign() const { return SuitableAlign; }
354 /// \brief Return the default alignment for __attribute__((aligned)) on
355 /// this target, to be used if no alignment value is specified.
356 unsigned getDefaultAlignForAttributeAligned() const {
357 return DefaultAlignForAttributeAligned;
360 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
361 /// unless its alignment is explicitly reduced via attributes.
362 unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
364 /// Return the largest alignment for which a suitably-sized allocation with
365 /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned
367 unsigned getNewAlign() const {
368 return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign);
371 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
373 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
374 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
376 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
378 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
379 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
381 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
383 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
384 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
386 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
387 unsigned getHalfWidth() const { return HalfWidth; }
388 unsigned getHalfAlign() const { return HalfAlign; }
389 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
391 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
392 unsigned getFloatWidth() const { return FloatWidth; }
393 unsigned getFloatAlign() const { return FloatAlign; }
394 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
396 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
397 unsigned getDoubleWidth() const { return DoubleWidth; }
398 unsigned getDoubleAlign() const { return DoubleAlign; }
399 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
401 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
403 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
404 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
405 const llvm::fltSemantics &getLongDoubleFormat() const {
406 return *LongDoubleFormat;
409 /// getFloat128Width/Align/Format - Return the size/align/format of
411 unsigned getFloat128Width() const { return 128; }
412 unsigned getFloat128Align() const { return Float128Align; }
413 const llvm::fltSemantics &getFloat128Format() const {
414 return *Float128Format;
417 /// \brief Return true if the 'long double' type should be mangled like
419 virtual bool useFloat128ManglingForLongDouble() const { return false; }
421 /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
422 virtual unsigned getFloatEvalMethod() const { return 0; }
424 // getLargeArrayMinWidth/Align - Return the minimum array size that is
425 // 'large' and its alignment.
426 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
427 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
429 /// \brief Return the maximum width lock-free atomic operation which will
430 /// ever be supported for the given target
431 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
432 /// \brief Return the maximum width lock-free atomic operation which can be
433 /// inlined given the supported features of the given target.
434 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
435 /// \brief Returns true if the given target supports lock-free atomic
436 /// operations at the specified width and alignment.
437 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
438 uint64_t AlignmentInBits) const {
439 return AtomicSizeInBits <= AlignmentInBits &&
440 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
441 (AtomicSizeInBits <= getCharWidth() ||
442 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
445 /// \brief Return the maximum vector alignment supported for the given target.
446 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
447 /// \brief Return default simd alignment for the given target. Generally, this
448 /// value is type-specific, but this alignment can be used for most of the
449 /// types for the given target.
450 unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
452 /// Return the alignment (in bits) of the thrown exception object. This is
453 /// only meaningful for targets that allocate C++ exceptions in a system
454 /// runtime, such as those using the Itanium C++ ABI.
455 virtual unsigned getExnObjectAlignment() const {
456 // Itanium says that an _Unwind_Exception has to be "double-word"
457 // aligned (and thus the end of it is also so-aligned), meaning 16
458 // bytes. Of course, that was written for the actual Itanium,
459 // which is a 64-bit platform. Classically, the ABI doesn't really
460 // specify the alignment on other platforms, but in practice
461 // libUnwind declares the struct with __attribute__((aligned)), so
462 // we assume that alignment here. (It's generally 16 bytes, but
463 // some targets overwrite it.)
464 return getDefaultAlignForAttributeAligned();
467 /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
468 unsigned getIntMaxTWidth() const {
469 return getTypeWidth(IntMaxType);
472 // Return the size of unwind_word for this target.
473 virtual unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
475 /// \brief Return the "preferred" register width on this target.
476 virtual unsigned getRegisterWidth() const {
477 // Currently we assume the register width on the target matches the pointer
478 // width, we can introduce a new variable for this if/when some target wants
483 /// \brief Returns the name of the mcount instrumentation function.
484 const char *getMCountName() const {
488 /// \brief Check if the Objective-C built-in boolean type should be signed
491 /// Otherwise, if this returns false, the normal built-in boolean type
492 /// should also be used for Objective-C.
493 bool useSignedCharForObjCBool() const {
494 return UseSignedCharForObjCBool;
496 void noSignedCharForObjCBool() {
497 UseSignedCharForObjCBool = false;
500 /// \brief Check whether the alignment of bit-field types is respected
501 /// when laying out structures.
502 bool useBitFieldTypeAlignment() const {
503 return UseBitFieldTypeAlignment;
506 /// \brief Check whether zero length bitfields should force alignment of
508 bool useZeroLengthBitfieldAlignment() const {
509 return UseZeroLengthBitfieldAlignment;
512 /// \brief Get the fixed alignment value in bits for a member that follows
513 /// a zero length bitfield.
514 unsigned getZeroLengthBitfieldBoundary() const {
515 return ZeroLengthBitfieldBoundary;
518 /// \brief Check whether explicit bitfield alignment attributes should be
519 // honored, as in "__attribute__((aligned(2))) int b : 1;".
520 bool useExplicitBitFieldAlignment() const {
521 return UseExplicitBitFieldAlignment;
524 /// \brief Check whether this target support '\#pragma options align=mac68k'.
525 bool hasAlignMac68kSupport() const {
526 return HasAlignMac68kSupport;
529 /// \brief Return the user string for the specified integer type enum.
531 /// For example, SignedShort -> "short".
532 static const char *getTypeName(IntType T);
534 /// \brief Return the constant suffix for the specified integer type enum.
536 /// For example, SignedLong -> "L".
537 const char *getTypeConstantSuffix(IntType T) const;
539 /// \brief Return the printf format modifier for the specified
540 /// integer type enum.
542 /// For example, SignedLong -> "l".
543 static const char *getTypeFormatModifier(IntType T);
545 /// \brief Check whether the given real type should use the "fpret" flavor of
546 /// Objective-C message passing on this target.
547 bool useObjCFPRetForRealType(RealType T) const {
548 return RealTypeUsesObjCFPRet & (1 << T);
551 /// \brief Check whether _Complex long double should use the "fp2ret" flavor
552 /// of Objective-C message passing on this target.
553 bool useObjCFP2RetForComplexLongDouble() const {
554 return ComplexLongDoubleUsesFP2Ret;
557 /// \brief Specify if mangling based on address space map should be used or
558 /// not for language specific address spaces
559 bool useAddressSpaceMapMangling() const {
560 return UseAddrSpaceMapMangling;
563 ///===---- Other target property query methods --------------------------===//
565 /// \brief Appends the target-specific \#define values for this
566 /// target set to the specified buffer.
567 virtual void getTargetDefines(const LangOptions &Opts,
568 MacroBuilder &Builder) const = 0;
571 /// Return information about target-specific builtins for
572 /// the current primary target, and info about which builtins are non-portable
573 /// across the current set of primary and secondary targets.
574 virtual ArrayRef<Builtin::Info> getTargetBuiltins() const = 0;
576 /// The __builtin_clz* and __builtin_ctz* built-in
577 /// functions are specified to have undefined results for zero inputs, but
578 /// on targets that support these operations in a way that provides
579 /// well-defined results for zero without loss of performance, it is a good
580 /// idea to avoid optimizing based on that undef behavior.
581 virtual bool isCLZForZeroUndef() const { return true; }
583 /// \brief Returns the kind of __builtin_va_list type that should be used
584 /// with this target.
585 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
587 /// Returns whether or not type \c __builtin_ms_va_list type is
588 /// available on this target.
589 bool hasBuiltinMSVaList() const { return HasBuiltinMSVaList; }
591 /// Returns true for RenderScript.
592 bool isRenderScriptTarget() const { return IsRenderScriptTarget; }
594 /// \brief Returns whether the passed in string is a valid clobber in an
595 /// inline asm statement.
597 /// This is used by Sema.
598 bool isValidClobber(StringRef Name) const;
600 /// \brief Returns whether the passed in string is a valid register name
601 /// according to GCC.
603 /// This is used by Sema for inline asm statements.
604 bool isValidGCCRegisterName(StringRef Name) const;
606 /// \brief Returns the "normalized" GCC register name.
608 /// ReturnCannonical true will return the register name without any additions
609 /// such as "{}" or "%" in it's canonical form, for example:
610 /// ReturnCanonical = true and Name = "rax", will return "ax".
611 StringRef getNormalizedGCCRegisterName(StringRef Name,
612 bool ReturnCanonical = false) const;
614 virtual StringRef getConstraintRegister(const StringRef &Constraint,
615 const StringRef &Expression) const {
619 struct ConstraintInfo {
622 CI_AllowsMemory = 0x01,
623 CI_AllowsRegister = 0x02,
624 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
625 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
626 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
627 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
635 llvm::SmallSet<int, 4> ImmSet;
637 std::string ConstraintStr; // constraint: "=rm"
638 std::string Name; // Operand name: [foo] with no []'s.
640 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
641 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
643 ImmRange.Min = ImmRange.Max = 0;
646 const std::string &getConstraintStr() const { return ConstraintStr; }
647 const std::string &getName() const { return Name; }
648 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
649 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
650 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
651 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
653 /// \brief Return true if this output operand has a matching
654 /// (tied) input operand.
655 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
657 /// \brief Return true if this input operand is a matching
658 /// constraint that ties it to an output operand.
660 /// If this returns true then getTiedOperand will indicate which output
661 /// operand this is tied to.
662 bool hasTiedOperand() const { return TiedOperand != -1; }
663 unsigned getTiedOperand() const {
664 assert(hasTiedOperand() && "Has no tied operand!");
665 return (unsigned)TiedOperand;
668 bool requiresImmediateConstant() const {
669 return (Flags & CI_ImmediateConstant) != 0;
671 bool isValidAsmImmediate(const llvm::APInt &Value) const {
672 return (Value.sge(ImmRange.Min) && Value.sle(ImmRange.Max)) ||
673 ImmSet.count(Value.getZExtValue()) != 0;
676 void setIsReadWrite() { Flags |= CI_ReadWrite; }
677 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
678 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
679 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
680 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
681 void setRequiresImmediate(int Min, int Max) {
682 Flags |= CI_ImmediateConstant;
686 void setRequiresImmediate(llvm::ArrayRef<int> Exacts) {
687 Flags |= CI_ImmediateConstant;
688 for (int Exact : Exacts)
689 ImmSet.insert(Exact);
691 void setRequiresImmediate(int Exact) {
692 Flags |= CI_ImmediateConstant;
693 ImmSet.insert(Exact);
695 void setRequiresImmediate() {
696 Flags |= CI_ImmediateConstant;
697 ImmRange.Min = INT_MIN;
698 ImmRange.Max = INT_MAX;
701 /// \brief Indicate that this is an input operand that is tied to
702 /// the specified output operand.
704 /// Copy over the various constraint information from the output.
705 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
706 Output.setHasMatchingInput();
707 Flags = Output.Flags;
709 // Don't copy Name or constraint string.
713 /// \brief Validate register name used for global register variables.
715 /// This function returns true if the register passed in RegName can be used
716 /// for global register variables on this target. In addition, it returns
717 /// true in HasSizeMismatch if the size of the register doesn't match the
718 /// variable size passed in RegSize.
719 virtual bool validateGlobalRegisterVariable(StringRef RegName,
721 bool &HasSizeMismatch) const {
722 HasSizeMismatch = false;
726 // validateOutputConstraint, validateInputConstraint - Checks that
727 // a constraint is valid and provides information about it.
728 // FIXME: These should return a real error instead of just true/false.
729 bool validateOutputConstraint(ConstraintInfo &Info) const;
730 bool validateInputConstraint(MutableArrayRef<ConstraintInfo> OutputConstraints,
731 ConstraintInfo &info) const;
733 virtual bool validateOutputSize(StringRef /*Constraint*/,
734 unsigned /*Size*/) const {
738 virtual bool validateInputSize(StringRef /*Constraint*/,
739 unsigned /*Size*/) const {
743 validateConstraintModifier(StringRef /*Constraint*/,
746 std::string &/*SuggestedModifier*/) const {
750 validateAsmConstraint(const char *&Name,
751 TargetInfo::ConstraintInfo &info) const = 0;
753 bool resolveSymbolicName(const char *&Name,
754 ArrayRef<ConstraintInfo> OutputConstraints,
755 unsigned &Index) const;
757 // Constraint parm will be left pointing at the last character of
758 // the constraint. In practice, it won't be changed unless the
759 // constraint is longer than one character.
760 virtual std::string convertConstraint(const char *&Constraint) const {
761 // 'p' defaults to 'r', but can be overridden by targets.
762 if (*Constraint == 'p')
763 return std::string("r");
764 return std::string(1, *Constraint);
767 /// \brief Returns a string of target-specific clobbers, in LLVM format.
768 virtual const char *getClobbers() const = 0;
770 /// \brief Returns true if NaN encoding is IEEE 754-2008.
771 /// Only MIPS allows a different encoding.
772 virtual bool isNan2008() const {
776 /// \brief Returns the target triple of the primary target.
777 const llvm::Triple &getTriple() const {
781 const llvm::DataLayout &getDataLayout() const {
782 assert(DataLayout && "Uninitialized DataLayout!");
787 const char * const Aliases[5];
788 const char * const Register;
792 const char * const Names[5];
793 const unsigned RegNum;
796 /// \brief Does this target support "protected" visibility?
798 /// Any target which dynamic libraries will naturally support
799 /// something like "default" (meaning that the symbol is visible
800 /// outside this shared object) and "hidden" (meaning that it isn't)
801 /// visibilities, but "protected" is really an ELF-specific concept
802 /// with weird semantics designed around the convenience of dynamic
803 /// linker implementations. Which is not to suggest that there's
804 /// consistent target-independent semantics for "default" visibility
805 /// either; the entire thing is pretty badly mangled.
806 virtual bool hasProtectedVisibility() const { return true; }
808 /// \brief An optional hook that targets can implement to perform semantic
809 /// checking on attribute((section("foo"))) specifiers.
811 /// In this case, "foo" is passed in to be checked. If the section
812 /// specifier is invalid, the backend should return a non-empty string
813 /// that indicates the problem.
815 /// This hook is a simple quality of implementation feature to catch errors
816 /// and give good diagnostics in cases when the assembler or code generator
817 /// would otherwise reject the section specifier.
819 virtual std::string isValidSectionSpecifier(StringRef SR) const {
823 /// \brief Set forced language options.
825 /// Apply changes to the target information with respect to certain
826 /// language options which change the target configuration.
827 virtual void adjust(const LangOptions &Opts);
829 /// \brief Adjust target options based on codegen options.
830 virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
831 TargetOptions &TargetOpts) const {}
833 /// \brief Initialize the map with the default set of target features for the
834 /// CPU this should include all legal feature strings on the target.
836 /// \return False on error (invalid features).
837 virtual bool initFeatureMap(llvm::StringMap<bool> &Features,
838 DiagnosticsEngine &Diags, StringRef CPU,
839 const std::vector<std::string> &FeatureVec) const;
841 /// \brief Get the ABI currently in use.
842 virtual StringRef getABI() const { return StringRef(); }
844 /// \brief Get the C++ ABI currently in use.
845 TargetCXXABI getCXXABI() const {
849 /// \brief Target the specified CPU.
851 /// \return False on error (invalid CPU name).
852 virtual bool setCPU(const std::string &Name) {
856 /// \brief Use the specified ABI.
858 /// \return False on error (invalid ABI name).
859 virtual bool setABI(const std::string &Name) {
863 /// \brief Use the specified unit for FP math.
865 /// \return False on error (invalid unit name).
866 virtual bool setFPMath(StringRef Name) {
870 /// \brief Enable or disable a specific target feature;
871 /// the feature name must be valid.
872 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
874 bool Enabled) const {
875 Features[Name] = Enabled;
878 /// \brief Perform initialization based on the user configured
879 /// set of features (e.g., +sse4).
881 /// The list is guaranteed to have at most one entry per feature.
883 /// The target may modify the features list, to change which options are
884 /// passed onwards to the backend.
885 /// FIXME: This part should be fixed so that we can change handleTargetFeatures
886 /// to merely a TargetInfo initialization routine.
888 /// \return False on error.
889 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
890 DiagnosticsEngine &Diags) {
894 /// \brief Determine whether the given target has the given feature.
895 virtual bool hasFeature(StringRef Feature) const {
899 // \brief Validate the contents of the __builtin_cpu_supports(const char*)
901 virtual bool validateCpuSupports(StringRef Name) const { return false; }
903 // \brief Returns maximal number of args passed in registers.
904 unsigned getRegParmMax() const {
905 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
909 /// \brief Whether the target supports thread-local storage.
910 bool isTLSSupported() const {
914 /// \brief Return the maximum alignment (in bits) of a TLS variable
916 /// Gets the maximum alignment (in bits) of a TLS variable on this target.
917 /// Returns zero if there is no such constraint.
918 unsigned short getMaxTLSAlign() const {
922 /// \brief Whether the target supports SEH __try.
923 bool isSEHTrySupported() const {
924 return getTriple().isOSWindows() &&
925 (getTriple().getArch() == llvm::Triple::x86 ||
926 getTriple().getArch() == llvm::Triple::x86_64);
929 /// \brief Return true if {|} are normal characters in the asm string.
931 /// If this returns false (the default), then {abc|xyz} is syntax
932 /// that says that when compiling for asm variant #0, "abc" should be
933 /// generated, but when compiling for asm variant #1, "xyz" should be
935 bool hasNoAsmVariants() const {
936 return NoAsmVariants;
939 /// \brief Return the register number that __builtin_eh_return_regno would
940 /// return with the specified argument.
941 /// This corresponds with TargetLowering's getExceptionPointerRegister
942 /// and getExceptionSelectorRegister in the backend.
943 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
947 /// \brief Return the section to use for C++ static initialization functions.
948 virtual const char *getStaticInitSectionSpecifier() const {
952 const LangAS::Map &getAddressSpaceMap() const {
953 return *AddrSpaceMap;
956 /// \brief Retrieve the name of the platform as it is used in the
957 /// availability attribute.
958 StringRef getPlatformName() const { return PlatformName; }
960 /// \brief Retrieve the minimum desired version of the platform, to
961 /// which the program should be compiled.
962 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
964 bool isBigEndian() const { return BigEndian; }
965 bool isLittleEndian() const { return !BigEndian; }
967 enum CallingConvMethodType {
973 /// \brief Gets the default calling convention for the given target and
974 /// declaration context.
975 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
976 // Not all targets will specify an explicit calling convention that we can
977 // express. This will always do the right thing, even though it's not
978 // an explicit calling convention.
982 enum CallingConvCheckResult {
988 /// \brief Determines whether a given calling convention is valid for the
989 /// target. A calling convention can either be accepted, produce a warning
990 /// and be substituted with the default calling convention, or (someday)
991 /// produce an error (such as using thiscall on a non-instance function).
992 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
1001 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
1002 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
1003 virtual bool hasSjLjLowering() const {
1007 /// \brief Whether target allows to overalign ABI-specified preferred alignment
1008 virtual bool allowsLargerPreferedTypeAlignment() const { return true; }
1010 /// \brief Set supported OpenCL extensions and optional core features.
1011 virtual void setSupportedOpenCLOpts() {}
1013 /// \brief Set supported OpenCL extensions as written on command line
1014 virtual void setOpenCLExtensionOpts() {
1015 for (const auto &Ext : getTargetOpts().OpenCLExtensionsAsWritten) {
1016 getTargetOpts().SupportedOpenCLOptions.support(Ext);
1020 /// \brief Get supported OpenCL extensions and optional core features.
1021 OpenCLOptions &getSupportedOpenCLOpts() {
1022 return getTargetOpts().SupportedOpenCLOptions;
1025 /// \brief Get const supported OpenCL extensions and optional core features.
1026 const OpenCLOptions &getSupportedOpenCLOpts() const {
1027 return getTargetOpts().SupportedOpenCLOptions;
1030 /// \brief Get OpenCL image type address space.
1031 virtual LangAS::ID getOpenCLImageAddrSpace() const {
1032 return LangAS::opencl_global;
1035 /// \brief Check the target is valid after it is fully initialized.
1036 virtual bool validateTarget(DiagnosticsEngine &Diags) const {
1041 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
1042 return PointerWidth;
1044 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
1045 return PointerAlign;
1047 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
1050 virtual ArrayRef<const char *> getGCCRegNames() const = 0;
1051 virtual ArrayRef<GCCRegAlias> getGCCRegAliases() const = 0;
1052 virtual ArrayRef<AddlRegName> getGCCAddlRegNames() const {
1057 } // end namespace clang