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/IntrusiveRefCntPtr.h"
25 #include "llvm/ADT/StringMap.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/StringSwitch.h"
28 #include "llvm/ADT/Triple.h"
29 #include "llvm/Support/DataTypes.h"
39 class DiagnosticsEngine;
45 namespace Builtin { struct Info; }
47 /// \brief Exposes information about the current target.
49 class TargetInfo : public RefCountedBase<TargetInfo> {
50 std::shared_ptr<TargetOptions> TargetOpts;
53 // Target values set by the ctor of the actual target implementation. Default
54 // values are specified by the TargetInfo constructor.
57 bool NoAsmVariants; // True if {|} are normal characters.
58 unsigned char PointerWidth, PointerAlign;
59 unsigned char BoolWidth, BoolAlign;
60 unsigned char IntWidth, IntAlign;
61 unsigned char HalfWidth, HalfAlign;
62 unsigned char FloatWidth, FloatAlign;
63 unsigned char DoubleWidth, DoubleAlign;
64 unsigned char LongDoubleWidth, LongDoubleAlign;
65 unsigned char LargeArrayMinWidth, LargeArrayAlign;
66 unsigned char LongWidth, LongAlign;
67 unsigned char LongLongWidth, LongLongAlign;
68 unsigned char SuitableAlign;
69 unsigned char DefaultAlignForAttributeAligned;
70 unsigned char MinGlobalAlign;
71 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
72 unsigned short MaxVectorAlign;
73 unsigned short MaxTLSAlign;
74 unsigned short SimdDefaultAlign;
75 const char *DescriptionString;
76 const char *UserLabelPrefix;
77 const char *MCountName;
78 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
80 unsigned char RegParmMax, SSERegParmMax;
81 TargetCXXABI TheCXXABI;
82 const LangAS::Map *AddrSpaceMap;
84 mutable StringRef PlatformName;
85 mutable VersionTuple PlatformMinVersion;
87 unsigned HasAlignMac68kSupport : 1;
88 unsigned RealTypeUsesObjCFPRet : 3;
89 unsigned ComplexLongDoubleUsesFP2Ret : 1;
91 // TargetInfo Constructor. Default initializes all fields.
92 TargetInfo(const llvm::Triple &T);
95 /// \brief Construct a target for the given options.
97 /// \param Opts - The options to use to initialize the target. The target may
98 /// modify the options to canonicalize the target feature information to match
99 /// what the backend expects.
101 CreateTargetInfo(DiagnosticsEngine &Diags,
102 const std::shared_ptr<TargetOptions> &Opts);
104 virtual ~TargetInfo();
106 /// \brief Retrieve the target options.
107 TargetOptions &getTargetOpts() const {
108 assert(TargetOpts && "Missing target options");
112 ///===---- Target Data Type Query Methods -------------------------------===//
134 /// \brief The different kinds of __builtin_va_list types defined by
135 /// the target implementation.
136 enum BuiltinVaListKind {
137 /// typedef char* __builtin_va_list;
138 CharPtrBuiltinVaList = 0,
140 /// typedef void* __builtin_va_list;
141 VoidPtrBuiltinVaList,
143 /// __builtin_va_list as defind by the AArch64 ABI
144 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
145 AArch64ABIBuiltinVaList,
147 /// __builtin_va_list as defined by the PNaCl ABI:
148 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
149 PNaClABIBuiltinVaList,
151 /// __builtin_va_list as defined by the Power ABI:
152 /// https://www.power.org
153 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
154 PowerABIBuiltinVaList,
156 /// __builtin_va_list as defined by the x86-64 ABI:
157 /// http://www.x86-64.org/documentation/abi.pdf
158 X86_64ABIBuiltinVaList,
160 /// __builtin_va_list as defined by ARM AAPCS ABI
161 /// http://infocenter.arm.com
162 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
163 AAPCSABIBuiltinVaList,
165 // typedef struct __va_list_tag
169 // void *__overflow_arg_area;
170 // void *__reg_save_area;
176 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
177 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
180 /// \brief Whether Objective-C's built-in boolean type should be signed char.
182 /// Otherwise, when this flag is not set, the normal built-in boolean type is
184 unsigned UseSignedCharForObjCBool : 1;
186 /// Control whether the alignment of bit-field types is respected when laying
187 /// out structures. If true, then the alignment of the bit-field type will be
188 /// used to (a) impact the alignment of the containing structure, and (b)
189 /// ensure that the individual bit-field will not straddle an alignment
191 unsigned UseBitFieldTypeAlignment : 1;
193 /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
194 /// the next bitfield.
196 /// If the alignment of the zero length bitfield is greater than the member
197 /// that follows it, `bar', `bar' will be aligned as the type of the
198 /// zero-length bitfield.
199 unsigned UseZeroLengthBitfieldAlignment : 1;
201 /// If non-zero, specifies a fixed alignment value for bitfields that follow
202 /// zero length bitfield, regardless of the zero length bitfield type.
203 unsigned ZeroLengthBitfieldBoundary;
205 /// \brief Specify if mangling based on address space map should be used or
206 /// not for language specific address spaces
207 bool UseAddrSpaceMapMangling;
210 IntType getSizeType() const { return SizeType; }
211 IntType getIntMaxType() const { return IntMaxType; }
212 IntType getUIntMaxType() const {
213 return getCorrespondingUnsignedType(IntMaxType);
215 IntType getPtrDiffType(unsigned AddrSpace) const {
216 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
218 IntType getIntPtrType() const { return IntPtrType; }
219 IntType getUIntPtrType() const {
220 return getCorrespondingUnsignedType(IntPtrType);
222 IntType getWCharType() const { return WCharType; }
223 IntType getWIntType() const { return WIntType; }
224 IntType getChar16Type() const { return Char16Type; }
225 IntType getChar32Type() const { return Char32Type; }
226 IntType getInt64Type() const { return Int64Type; }
227 IntType getUInt64Type() const {
228 return getCorrespondingUnsignedType(Int64Type);
230 IntType getSigAtomicType() const { return SigAtomicType; }
231 IntType getProcessIDType() const { return ProcessIDType; }
233 static IntType getCorrespondingUnsignedType(IntType T) {
238 return UnsignedShort;
244 return UnsignedLongLong;
246 llvm_unreachable("Unexpected signed integer type");
250 /// \brief Return the width (in bits) of the specified integer type enum.
252 /// For example, SignedInt -> getIntWidth().
253 unsigned getTypeWidth(IntType T) const;
255 /// \brief Return integer type with specified width.
256 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
258 /// \brief Return the smallest integer type with at least the specified width.
259 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
261 /// \brief Return floating point type with specified width.
262 RealType getRealTypeByWidth(unsigned BitWidth) const;
264 /// \brief Return the alignment (in bits) of the specified integer type enum.
266 /// For example, SignedInt -> getIntAlign().
267 unsigned getTypeAlign(IntType T) const;
269 /// \brief Returns true if the type is signed; false otherwise.
270 static bool isTypeSigned(IntType T);
272 /// \brief Return the width of pointers on this target, for the
273 /// specified address space.
274 uint64_t getPointerWidth(unsigned AddrSpace) const {
275 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
277 uint64_t getPointerAlign(unsigned AddrSpace) const {
278 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
281 /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
282 unsigned getBoolWidth() const { return BoolWidth; }
284 /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
285 unsigned getBoolAlign() const { return BoolAlign; }
287 unsigned getCharWidth() const { return 8; } // FIXME
288 unsigned getCharAlign() const { return 8; } // FIXME
290 /// \brief Return the size of 'signed short' and 'unsigned short' for this
292 unsigned getShortWidth() const { return 16; } // FIXME
294 /// \brief Return the alignment of 'signed short' and 'unsigned short' for
296 unsigned getShortAlign() const { return 16; } // FIXME
298 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
299 /// this target, in bits.
300 unsigned getIntWidth() const { return IntWidth; }
301 unsigned getIntAlign() const { return IntAlign; }
303 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
304 /// for this target, in bits.
305 unsigned getLongWidth() const { return LongWidth; }
306 unsigned getLongAlign() const { return LongAlign; }
308 /// getLongLongWidth/Align - Return the size of 'signed long long' and
309 /// 'unsigned long long' for this target, in bits.
310 unsigned getLongLongWidth() const { return LongLongWidth; }
311 unsigned getLongLongAlign() const { return LongLongAlign; }
313 /// \brief Determine whether the __int128 type is supported on this target.
314 virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
316 /// \brief Return the alignment that is suitable for storing any
317 /// object with a fundamental alignment requirement.
318 unsigned getSuitableAlign() const { return SuitableAlign; }
320 /// \brief Return the default alignment for __attribute__((aligned)) on
321 /// this target, to be used if no alignment value is specified.
322 unsigned getDefaultAlignForAttributeAligned() const {
323 return DefaultAlignForAttributeAligned;
326 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
327 /// unless its alignment is explicitly reduced via attributes.
328 unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
330 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
332 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
333 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
335 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
337 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
338 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
340 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
342 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
343 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
345 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
346 unsigned getHalfWidth() const { return HalfWidth; }
347 unsigned getHalfAlign() const { return HalfAlign; }
348 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
350 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
351 unsigned getFloatWidth() const { return FloatWidth; }
352 unsigned getFloatAlign() const { return FloatAlign; }
353 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
355 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
356 unsigned getDoubleWidth() const { return DoubleWidth; }
357 unsigned getDoubleAlign() const { return DoubleAlign; }
358 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
360 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
362 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
363 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
364 const llvm::fltSemantics &getLongDoubleFormat() const {
365 return *LongDoubleFormat;
368 /// \brief Return true if the 'long double' type should be mangled like
370 virtual bool useFloat128ManglingForLongDouble() const { return false; }
372 /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
373 virtual unsigned getFloatEvalMethod() const { return 0; }
375 // getLargeArrayMinWidth/Align - Return the minimum array size that is
376 // 'large' and its alignment.
377 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
378 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
380 /// \brief Return the maximum width lock-free atomic operation which will
381 /// ever be supported for the given target
382 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
383 /// \brief Return the maximum width lock-free atomic operation which can be
384 /// inlined given the supported features of the given target.
385 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
386 /// \brief Returns true if the given target supports lock-free atomic
387 /// operations at the specified width and alignment.
388 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
389 uint64_t AlignmentInBits) const {
390 return AtomicSizeInBits <= AlignmentInBits &&
391 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
392 (AtomicSizeInBits <= getCharWidth() ||
393 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
396 /// \brief Return the maximum vector alignment supported for the given target.
397 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
398 /// \brief Return default simd alignment for the given target. Generally, this
399 /// value is type-specific, but this alignment can be used for most of the
400 /// types for the given target.
401 unsigned getSimdDefaultAlign() const { return SimdDefaultAlign; }
403 /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
404 unsigned getIntMaxTWidth() const {
405 return getTypeWidth(IntMaxType);
408 // Return the size of unwind_word for this target.
409 unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
411 /// \brief Return the "preferred" register width on this target.
412 unsigned getRegisterWidth() const {
413 // Currently we assume the register width on the target matches the pointer
414 // width, we can introduce a new variable for this if/when some target wants
419 /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
420 /// which is the prefix given to user symbols by default.
422 /// On most platforms this is "_", but it is "" on some, and "." on others.
423 const char *getUserLabelPrefix() const {
424 return UserLabelPrefix;
427 /// \brief Returns the name of the mcount instrumentation function.
428 const char *getMCountName() const {
432 /// \brief Check if the Objective-C built-in boolean type should be signed
435 /// Otherwise, if this returns false, the normal built-in boolean type
436 /// should also be used for Objective-C.
437 bool useSignedCharForObjCBool() const {
438 return UseSignedCharForObjCBool;
440 void noSignedCharForObjCBool() {
441 UseSignedCharForObjCBool = false;
444 /// \brief Check whether the alignment of bit-field types is respected
445 /// when laying out structures.
446 bool useBitFieldTypeAlignment() const {
447 return UseBitFieldTypeAlignment;
450 /// \brief Check whether zero length bitfields should force alignment of
452 bool useZeroLengthBitfieldAlignment() const {
453 return UseZeroLengthBitfieldAlignment;
456 /// \brief Get the fixed alignment value in bits for a member that follows
457 /// a zero length bitfield.
458 unsigned getZeroLengthBitfieldBoundary() const {
459 return ZeroLengthBitfieldBoundary;
462 /// \brief Check whether this target support '\#pragma options align=mac68k'.
463 bool hasAlignMac68kSupport() const {
464 return HasAlignMac68kSupport;
467 /// \brief Return the user string for the specified integer type enum.
469 /// For example, SignedShort -> "short".
470 static const char *getTypeName(IntType T);
472 /// \brief Return the constant suffix for the specified integer type enum.
474 /// For example, SignedLong -> "L".
475 const char *getTypeConstantSuffix(IntType T) const;
477 /// \brief Return the printf format modifier for the specified
478 /// integer type enum.
480 /// For example, SignedLong -> "l".
481 static const char *getTypeFormatModifier(IntType T);
483 /// \brief Check whether the given real type should use the "fpret" flavor of
484 /// Objective-C message passing on this target.
485 bool useObjCFPRetForRealType(RealType T) const {
486 return RealTypeUsesObjCFPRet & (1 << T);
489 /// \brief Check whether _Complex long double should use the "fp2ret" flavor
490 /// of Objective-C message passing on this target.
491 bool useObjCFP2RetForComplexLongDouble() const {
492 return ComplexLongDoubleUsesFP2Ret;
495 /// \brief Specify if mangling based on address space map should be used or
496 /// not for language specific address spaces
497 bool useAddressSpaceMapMangling() const {
498 return UseAddrSpaceMapMangling;
501 ///===---- Other target property query methods --------------------------===//
503 /// \brief Appends the target-specific \#define values for this
504 /// target set to the specified buffer.
505 virtual void getTargetDefines(const LangOptions &Opts,
506 MacroBuilder &Builder) const = 0;
509 /// Return information about target-specific builtins for
510 /// the current primary target, and info about which builtins are non-portable
511 /// across the current set of primary and secondary targets.
512 virtual void getTargetBuiltins(const Builtin::Info *&Records,
513 unsigned &NumRecords) const = 0;
515 /// The __builtin_clz* and __builtin_ctz* built-in
516 /// functions are specified to have undefined results for zero inputs, but
517 /// on targets that support these operations in a way that provides
518 /// well-defined results for zero without loss of performance, it is a good
519 /// idea to avoid optimizing based on that undef behavior.
520 virtual bool isCLZForZeroUndef() const { return true; }
522 /// \brief Returns the kind of __builtin_va_list type that should be used
523 /// with this target.
524 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
526 /// \brief Returns whether the passed in string is a valid clobber in an
527 /// inline asm statement.
529 /// This is used by Sema.
530 bool isValidClobber(StringRef Name) const;
532 /// \brief Returns whether the passed in string is a valid register name
533 /// according to GCC.
535 /// This is used by Sema for inline asm statements.
536 bool isValidGCCRegisterName(StringRef Name) const;
538 /// \brief Returns the "normalized" GCC register name.
540 /// For example, on x86 it will return "ax" when "eax" is passed in.
541 StringRef getNormalizedGCCRegisterName(StringRef Name) const;
543 struct ConstraintInfo {
546 CI_AllowsMemory = 0x01,
547 CI_AllowsRegister = 0x02,
548 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
549 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
550 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
551 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
560 std::string ConstraintStr; // constraint: "=rm"
561 std::string Name; // Operand name: [foo] with no []'s.
563 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
564 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
566 ImmRange.Min = ImmRange.Max = 0;
569 const std::string &getConstraintStr() const { return ConstraintStr; }
570 const std::string &getName() const { return Name; }
571 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
572 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
573 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
574 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
576 /// \brief Return true if this output operand has a matching
577 /// (tied) input operand.
578 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
580 /// \brief Return true if this input operand is a matching
581 /// constraint that ties it to an output operand.
583 /// If this returns true then getTiedOperand will indicate which output
584 /// operand this is tied to.
585 bool hasTiedOperand() const { return TiedOperand != -1; }
586 unsigned getTiedOperand() const {
587 assert(hasTiedOperand() && "Has no tied operand!");
588 return (unsigned)TiedOperand;
591 bool requiresImmediateConstant() const {
592 return (Flags & CI_ImmediateConstant) != 0;
594 int getImmConstantMin() const { return ImmRange.Min; }
595 int getImmConstantMax() const { return ImmRange.Max; }
597 void setIsReadWrite() { Flags |= CI_ReadWrite; }
598 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
599 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
600 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
601 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
602 void setRequiresImmediate(int Min, int Max) {
603 Flags |= CI_ImmediateConstant;
608 /// \brief Indicate that this is an input operand that is tied to
609 /// the specified output operand.
611 /// Copy over the various constraint information from the output.
612 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
613 Output.setHasMatchingInput();
614 Flags = Output.Flags;
616 // Don't copy Name or constraint string.
620 // Validate the contents of the __builtin_cpu_supports(const char*) argument.
621 virtual bool validateCpuSupports(StringRef Name) const { return false; }
623 // validateOutputConstraint, validateInputConstraint - Checks that
624 // a constraint is valid and provides information about it.
625 // FIXME: These should return a real error instead of just true/false.
626 bool validateOutputConstraint(ConstraintInfo &Info) const;
627 bool validateInputConstraint(ConstraintInfo *OutputConstraints,
629 ConstraintInfo &info) const;
631 virtual bool validateOutputSize(StringRef /*Constraint*/,
632 unsigned /*Size*/) const {
636 virtual bool validateInputSize(StringRef /*Constraint*/,
637 unsigned /*Size*/) const {
641 validateConstraintModifier(StringRef /*Constraint*/,
644 std::string &/*SuggestedModifier*/) const {
647 bool resolveSymbolicName(const char *&Name,
648 ConstraintInfo *OutputConstraints,
649 unsigned NumOutputs, unsigned &Index) const;
651 // Constraint parm will be left pointing at the last character of
652 // the constraint. In practice, it won't be changed unless the
653 // constraint is longer than one character.
654 virtual std::string convertConstraint(const char *&Constraint) const {
655 // 'p' defaults to 'r', but can be overridden by targets.
656 if (*Constraint == 'p')
657 return std::string("r");
658 return std::string(1, *Constraint);
661 /// \brief Returns true if NaN encoding is IEEE 754-2008.
662 /// Only MIPS allows a different encoding.
663 virtual bool isNan2008() const {
667 /// \brief Returns a string of target-specific clobbers, in LLVM format.
668 virtual const char *getClobbers() const = 0;
671 /// \brief Returns the target triple of the primary target.
672 const llvm::Triple &getTriple() const {
676 const char *getTargetDescription() const {
677 assert(DescriptionString);
678 return DescriptionString;
682 const char * const Aliases[5];
683 const char * const Register;
687 const char * const Names[5];
688 const unsigned RegNum;
691 /// \brief Does this target support "protected" visibility?
693 /// Any target which dynamic libraries will naturally support
694 /// something like "default" (meaning that the symbol is visible
695 /// outside this shared object) and "hidden" (meaning that it isn't)
696 /// visibilities, but "protected" is really an ELF-specific concept
697 /// with weird semantics designed around the convenience of dynamic
698 /// linker implementations. Which is not to suggest that there's
699 /// consistent target-independent semantics for "default" visibility
700 /// either; the entire thing is pretty badly mangled.
701 virtual bool hasProtectedVisibility() const { return true; }
703 /// \brief An optional hook that targets can implement to perform semantic
704 /// checking on attribute((section("foo"))) specifiers.
706 /// In this case, "foo" is passed in to be checked. If the section
707 /// specifier is invalid, the backend should return a non-empty string
708 /// that indicates the problem.
710 /// This hook is a simple quality of implementation feature to catch errors
711 /// and give good diagnostics in cases when the assembler or code generator
712 /// would otherwise reject the section specifier.
714 virtual std::string isValidSectionSpecifier(StringRef SR) const {
718 /// \brief Set forced language options.
720 /// Apply changes to the target information with respect to certain
721 /// language options which change the target configuration.
722 virtual void adjust(const LangOptions &Opts);
724 /// \brief Get the default set of target features for the CPU;
725 /// this should include all legal feature strings on the target.
726 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
729 /// \brief Get the ABI currently in use.
730 virtual StringRef getABI() const { return StringRef(); }
732 /// \brief Get the C++ ABI currently in use.
733 TargetCXXABI getCXXABI() const {
737 /// \brief Target the specified CPU.
739 /// \return False on error (invalid CPU name).
740 virtual bool setCPU(const std::string &Name) {
744 /// \brief Use the specified ABI.
746 /// \return False on error (invalid ABI name).
747 virtual bool setABI(const std::string &Name) {
751 /// \brief Use the specified unit for FP math.
753 /// \return False on error (invalid unit name).
754 virtual bool setFPMath(StringRef Name) {
758 /// \brief Use this specified C++ ABI.
760 /// \return False on error (invalid C++ ABI name).
761 bool setCXXABI(llvm::StringRef name) {
763 if (!ABI.tryParse(name)) return false;
764 return setCXXABI(ABI);
767 /// \brief Set the C++ ABI to be used by this implementation.
769 /// \return False on error (ABI not valid on this target)
770 virtual bool setCXXABI(TargetCXXABI ABI) {
775 /// \brief Enable or disable a specific target feature;
776 /// the feature name must be valid.
777 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
779 bool Enabled) const {
780 Features[Name] = Enabled;
783 /// \brief Perform initialization based on the user configured
784 /// set of features (e.g., +sse4).
786 /// The list is guaranteed to have at most one entry per feature.
788 /// The target may modify the features list, to change which options are
789 /// passed onwards to the backend.
791 /// \return False on error.
792 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
793 DiagnosticsEngine &Diags) {
797 /// \brief Determine whether the given target has the given feature.
798 virtual bool hasFeature(StringRef Feature) const {
802 // \brief Returns maximal number of args passed in registers.
803 unsigned getRegParmMax() const {
804 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
808 /// \brief Whether the target supports thread-local storage.
809 bool isTLSSupported() const {
813 /// \brief Return the maximum alignment (in bits) of a TLS variable
815 /// Gets the maximum alignment (in bits) of a TLS variable on this target.
816 /// Returns zero if there is no such constraint.
817 unsigned short getMaxTLSAlign() const {
821 /// \brief Whether the target supports SEH __try.
822 bool isSEHTrySupported() const {
823 return getTriple().isOSWindows() &&
824 (getTriple().getArch() == llvm::Triple::x86 ||
825 getTriple().getArch() == llvm::Triple::x86_64);
828 /// \brief Return true if {|} are normal characters in the asm string.
830 /// If this returns false (the default), then {abc|xyz} is syntax
831 /// that says that when compiling for asm variant #0, "abc" should be
832 /// generated, but when compiling for asm variant #1, "xyz" should be
834 bool hasNoAsmVariants() const {
835 return NoAsmVariants;
838 /// \brief Return the register number that __builtin_eh_return_regno would
839 /// return with the specified argument.
840 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
844 /// \brief Return the section to use for C++ static initialization functions.
845 virtual const char *getStaticInitSectionSpecifier() const {
849 const LangAS::Map &getAddressSpaceMap() const {
850 return *AddrSpaceMap;
853 /// \brief Retrieve the name of the platform as it is used in the
854 /// availability attribute.
855 StringRef getPlatformName() const { return PlatformName; }
857 /// \brief Retrieve the minimum desired version of the platform, to
858 /// which the program should be compiled.
859 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
861 bool isBigEndian() const { return BigEndian; }
863 enum CallingConvMethodType {
869 /// \brief Gets the default calling convention for the given target and
870 /// declaration context.
871 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
872 // Not all targets will specify an explicit calling convention that we can
873 // express. This will always do the right thing, even though it's not
874 // an explicit calling convention.
878 enum CallingConvCheckResult {
884 /// \brief Determines whether a given calling convention is valid for the
885 /// target. A calling convention can either be accepted, produce a warning
886 /// and be substituted with the default calling convention, or (someday)
887 /// produce an error (such as using thiscall on a non-instance function).
888 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
897 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
898 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
899 virtual bool hasSjLjLowering() const {
904 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
907 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
910 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
913 virtual void getGCCRegNames(const char * const *&Names,
914 unsigned &NumNames) const = 0;
915 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
916 unsigned &NumAliases) const = 0;
917 virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
918 unsigned &NumAddl) const {
922 virtual bool validateAsmConstraint(const char *&Name,
923 TargetInfo::ConstraintInfo &info) const= 0;
926 } // end namespace clang