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 const char *DescriptionString;
74 const char *UserLabelPrefix;
75 const char *MCountName;
76 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
78 unsigned char RegParmMax, SSERegParmMax;
79 TargetCXXABI TheCXXABI;
80 const LangAS::Map *AddrSpaceMap;
82 mutable StringRef PlatformName;
83 mutable VersionTuple PlatformMinVersion;
85 unsigned HasAlignMac68kSupport : 1;
86 unsigned RealTypeUsesObjCFPRet : 3;
87 unsigned ComplexLongDoubleUsesFP2Ret : 1;
89 // TargetInfo Constructor. Default initializes all fields.
90 TargetInfo(const llvm::Triple &T);
93 /// \brief Construct a target for the given options.
95 /// \param Opts - The options to use to initialize the target. The target may
96 /// modify the options to canonicalize the target feature information to match
97 /// what the backend expects.
99 CreateTargetInfo(DiagnosticsEngine &Diags,
100 const std::shared_ptr<TargetOptions> &Opts);
102 virtual ~TargetInfo();
104 /// \brief Retrieve the target options.
105 TargetOptions &getTargetOpts() const {
106 assert(TargetOpts && "Missing target options");
110 ///===---- Target Data Type Query Methods -------------------------------===//
132 /// \brief The different kinds of __builtin_va_list types defined by
133 /// the target implementation.
134 enum BuiltinVaListKind {
135 /// typedef char* __builtin_va_list;
136 CharPtrBuiltinVaList = 0,
138 /// typedef void* __builtin_va_list;
139 VoidPtrBuiltinVaList,
141 /// __builtin_va_list as defind by the AArch64 ABI
142 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
143 AArch64ABIBuiltinVaList,
145 /// __builtin_va_list as defined by the PNaCl ABI:
146 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
147 PNaClABIBuiltinVaList,
149 /// __builtin_va_list as defined by the Power ABI:
150 /// https://www.power.org
151 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
152 PowerABIBuiltinVaList,
154 /// __builtin_va_list as defined by the x86-64 ABI:
155 /// http://www.x86-64.org/documentation/abi.pdf
156 X86_64ABIBuiltinVaList,
158 /// __builtin_va_list as defined by ARM AAPCS ABI
159 /// http://infocenter.arm.com
160 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
161 AAPCSABIBuiltinVaList,
163 // typedef struct __va_list_tag
167 // void *__overflow_arg_area;
168 // void *__reg_save_area;
174 IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
175 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
178 /// \brief Whether Objective-C's built-in boolean type should be signed char.
180 /// Otherwise, when this flag is not set, the normal built-in boolean type is
182 unsigned UseSignedCharForObjCBool : 1;
184 /// Control whether the alignment of bit-field types is respected when laying
185 /// out structures. If true, then the alignment of the bit-field type will be
186 /// used to (a) impact the alignment of the containing structure, and (b)
187 /// ensure that the individual bit-field will not straddle an alignment
189 unsigned UseBitFieldTypeAlignment : 1;
191 /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
192 /// the next bitfield.
194 /// If the alignment of the zero length bitfield is greater than the member
195 /// that follows it, `bar', `bar' will be aligned as the type of the
196 /// zero-length bitfield.
197 unsigned UseZeroLengthBitfieldAlignment : 1;
199 /// If non-zero, specifies a fixed alignment value for bitfields that follow
200 /// zero length bitfield, regardless of the zero length bitfield type.
201 unsigned ZeroLengthBitfieldBoundary;
203 /// \brief Specify if mangling based on address space map should be used or
204 /// not for language specific address spaces
205 bool UseAddrSpaceMapMangling;
208 IntType getSizeType() const { return SizeType; }
209 IntType getIntMaxType() const { return IntMaxType; }
210 IntType getUIntMaxType() const {
211 return getCorrespondingUnsignedType(IntMaxType);
213 IntType getPtrDiffType(unsigned AddrSpace) const {
214 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
216 IntType getIntPtrType() const { return IntPtrType; }
217 IntType getUIntPtrType() const {
218 return getCorrespondingUnsignedType(IntPtrType);
220 IntType getWCharType() const { return WCharType; }
221 IntType getWIntType() const { return WIntType; }
222 IntType getChar16Type() const { return Char16Type; }
223 IntType getChar32Type() const { return Char32Type; }
224 IntType getInt64Type() const { return Int64Type; }
225 IntType getUInt64Type() const {
226 return getCorrespondingUnsignedType(Int64Type);
228 IntType getSigAtomicType() const { return SigAtomicType; }
229 IntType getProcessIDType() const { return ProcessIDType; }
231 static IntType getCorrespondingUnsignedType(IntType T) {
236 return UnsignedShort;
242 return UnsignedLongLong;
244 llvm_unreachable("Unexpected signed integer type");
248 /// \brief Return the width (in bits) of the specified integer type enum.
250 /// For example, SignedInt -> getIntWidth().
251 unsigned getTypeWidth(IntType T) const;
253 /// \brief Return integer type with specified width.
254 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
256 /// \brief Return the smallest integer type with at least the specified width.
257 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
259 /// \brief Return floating point type with specified width.
260 RealType getRealTypeByWidth(unsigned BitWidth) const;
262 /// \brief Return the alignment (in bits) of the specified integer type enum.
264 /// For example, SignedInt -> getIntAlign().
265 unsigned getTypeAlign(IntType T) const;
267 /// \brief Returns true if the type is signed; false otherwise.
268 static bool isTypeSigned(IntType T);
270 /// \brief Return the width of pointers on this target, for the
271 /// specified address space.
272 uint64_t getPointerWidth(unsigned AddrSpace) const {
273 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
275 uint64_t getPointerAlign(unsigned AddrSpace) const {
276 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
279 /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
280 unsigned getBoolWidth() const { return BoolWidth; }
282 /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
283 unsigned getBoolAlign() const { return BoolAlign; }
285 unsigned getCharWidth() const { return 8; } // FIXME
286 unsigned getCharAlign() const { return 8; } // FIXME
288 /// \brief Return the size of 'signed short' and 'unsigned short' for this
290 unsigned getShortWidth() const { return 16; } // FIXME
292 /// \brief Return the alignment of 'signed short' and 'unsigned short' for
294 unsigned getShortAlign() const { return 16; } // FIXME
296 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
297 /// this target, in bits.
298 unsigned getIntWidth() const { return IntWidth; }
299 unsigned getIntAlign() const { return IntAlign; }
301 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
302 /// for this target, in bits.
303 unsigned getLongWidth() const { return LongWidth; }
304 unsigned getLongAlign() const { return LongAlign; }
306 /// getLongLongWidth/Align - Return the size of 'signed long long' and
307 /// 'unsigned long long' for this target, in bits.
308 unsigned getLongLongWidth() const { return LongLongWidth; }
309 unsigned getLongLongAlign() const { return LongLongAlign; }
311 /// \brief Determine whether the __int128 type is supported on this target.
312 virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
314 /// \brief Return the alignment that is suitable for storing any
315 /// object with a fundamental alignment requirement.
316 unsigned getSuitableAlign() const { return SuitableAlign; }
318 /// \brief Return the default alignment for __attribute__((aligned)) on
319 /// this target, to be used if no alignment value is specified.
320 unsigned getDefaultAlignForAttributeAligned() const {
321 return DefaultAlignForAttributeAligned;
324 /// getMinGlobalAlign - Return the minimum alignment of a global variable,
325 /// unless its alignment is explicitly reduced via attributes.
326 unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
328 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
330 unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
331 unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
333 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
335 unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
336 unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
338 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
340 unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
341 unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
343 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
344 unsigned getHalfWidth() const { return HalfWidth; }
345 unsigned getHalfAlign() const { return HalfAlign; }
346 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
348 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
349 unsigned getFloatWidth() const { return FloatWidth; }
350 unsigned getFloatAlign() const { return FloatAlign; }
351 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
353 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
354 unsigned getDoubleWidth() const { return DoubleWidth; }
355 unsigned getDoubleAlign() const { return DoubleAlign; }
356 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
358 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
360 unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
361 unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
362 const llvm::fltSemantics &getLongDoubleFormat() const {
363 return *LongDoubleFormat;
366 /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
367 virtual unsigned getFloatEvalMethod() const { return 0; }
369 // getLargeArrayMinWidth/Align - Return the minimum array size that is
370 // 'large' and its alignment.
371 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
372 unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
374 /// \brief Return the maximum width lock-free atomic operation which will
375 /// ever be supported for the given target
376 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
377 /// \brief Return the maximum width lock-free atomic operation which can be
378 /// inlined given the supported features of the given target.
379 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
380 /// \brief Returns true if the given target supports lock-free atomic
381 /// operations at the specified width and alignment.
382 virtual bool hasBuiltinAtomic(uint64_t AtomicSizeInBits,
383 uint64_t AlignmentInBits) const {
384 return AtomicSizeInBits <= AlignmentInBits &&
385 AtomicSizeInBits <= getMaxAtomicInlineWidth() &&
386 (AtomicSizeInBits <= getCharWidth() ||
387 llvm::isPowerOf2_64(AtomicSizeInBits / getCharWidth()));
390 /// \brief Return the maximum vector alignment supported for the given target.
391 unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
393 /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
394 unsigned getIntMaxTWidth() const {
395 return getTypeWidth(IntMaxType);
398 // Return the size of unwind_word for this target.
399 unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
401 /// \brief Return the "preferred" register width on this target.
402 unsigned getRegisterWidth() const {
403 // Currently we assume the register width on the target matches the pointer
404 // width, we can introduce a new variable for this if/when some target wants
409 /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
410 /// which is the prefix given to user symbols by default.
412 /// On most platforms this is "_", but it is "" on some, and "." on others.
413 const char *getUserLabelPrefix() const {
414 return UserLabelPrefix;
417 /// \brief Returns the name of the mcount instrumentation function.
418 const char *getMCountName() const {
422 /// \brief Check if the Objective-C built-in boolean type should be signed
425 /// Otherwise, if this returns false, the normal built-in boolean type
426 /// should also be used for Objective-C.
427 bool useSignedCharForObjCBool() const {
428 return UseSignedCharForObjCBool;
430 void noSignedCharForObjCBool() {
431 UseSignedCharForObjCBool = false;
434 /// \brief Check whether the alignment of bit-field types is respected
435 /// when laying out structures.
436 bool useBitFieldTypeAlignment() const {
437 return UseBitFieldTypeAlignment;
440 /// \brief Check whether zero length bitfields should force alignment of
442 bool useZeroLengthBitfieldAlignment() const {
443 return UseZeroLengthBitfieldAlignment;
446 /// \brief Get the fixed alignment value in bits for a member that follows
447 /// a zero length bitfield.
448 unsigned getZeroLengthBitfieldBoundary() const {
449 return ZeroLengthBitfieldBoundary;
452 /// \brief Check whether this target support '\#pragma options align=mac68k'.
453 bool hasAlignMac68kSupport() const {
454 return HasAlignMac68kSupport;
457 /// \brief Return the user string for the specified integer type enum.
459 /// For example, SignedShort -> "short".
460 static const char *getTypeName(IntType T);
462 /// \brief Return the constant suffix for the specified integer type enum.
464 /// For example, SignedLong -> "L".
465 const char *getTypeConstantSuffix(IntType T) const;
467 /// \brief Return the printf format modifier for the specified
468 /// integer type enum.
470 /// For example, SignedLong -> "l".
471 static const char *getTypeFormatModifier(IntType T);
473 /// \brief Check whether the given real type should use the "fpret" flavor of
474 /// Objective-C message passing on this target.
475 bool useObjCFPRetForRealType(RealType T) const {
476 return RealTypeUsesObjCFPRet & (1 << T);
479 /// \brief Check whether _Complex long double should use the "fp2ret" flavor
480 /// of Objective-C message passing on this target.
481 bool useObjCFP2RetForComplexLongDouble() const {
482 return ComplexLongDoubleUsesFP2Ret;
485 /// \brief Specify if mangling based on address space map should be used or
486 /// not for language specific address spaces
487 bool useAddressSpaceMapMangling() const {
488 return UseAddrSpaceMapMangling;
491 ///===---- Other target property query methods --------------------------===//
493 /// \brief Appends the target-specific \#define values for this
494 /// target set to the specified buffer.
495 virtual void getTargetDefines(const LangOptions &Opts,
496 MacroBuilder &Builder) const = 0;
499 /// Return information about target-specific builtins for
500 /// the current primary target, and info about which builtins are non-portable
501 /// across the current set of primary and secondary targets.
502 virtual void getTargetBuiltins(const Builtin::Info *&Records,
503 unsigned &NumRecords) const = 0;
505 /// The __builtin_clz* and __builtin_ctz* built-in
506 /// functions are specified to have undefined results for zero inputs, but
507 /// on targets that support these operations in a way that provides
508 /// well-defined results for zero without loss of performance, it is a good
509 /// idea to avoid optimizing based on that undef behavior.
510 virtual bool isCLZForZeroUndef() const { return true; }
512 /// \brief Returns the kind of __builtin_va_list type that should be used
513 /// with this target.
514 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
516 /// \brief Returns whether the passed in string is a valid clobber in an
517 /// inline asm statement.
519 /// This is used by Sema.
520 bool isValidClobber(StringRef Name) const;
522 /// \brief Returns whether the passed in string is a valid register name
523 /// according to GCC.
525 /// This is used by Sema for inline asm statements.
526 bool isValidGCCRegisterName(StringRef Name) const;
528 /// \brief Returns the "normalized" GCC register name.
530 /// For example, on x86 it will return "ax" when "eax" is passed in.
531 StringRef getNormalizedGCCRegisterName(StringRef Name) const;
533 struct ConstraintInfo {
536 CI_AllowsMemory = 0x01,
537 CI_AllowsRegister = 0x02,
538 CI_ReadWrite = 0x04, // "+r" output constraint (read and write).
539 CI_HasMatchingInput = 0x08, // This output operand has a matching input.
540 CI_ImmediateConstant = 0x10, // This operand must be an immediate constant
541 CI_EarlyClobber = 0x20, // "&" output constraint (early clobber).
550 std::string ConstraintStr; // constraint: "=rm"
551 std::string Name; // Operand name: [foo] with no []'s.
553 ConstraintInfo(StringRef ConstraintStr, StringRef Name)
554 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
556 ImmRange.Min = ImmRange.Max = 0;
559 const std::string &getConstraintStr() const { return ConstraintStr; }
560 const std::string &getName() const { return Name; }
561 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
562 bool earlyClobber() { return (Flags & CI_EarlyClobber) != 0; }
563 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
564 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
566 /// \brief Return true if this output operand has a matching
567 /// (tied) input operand.
568 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
570 /// \brief Return true if this input operand is a matching
571 /// constraint that ties it to an output operand.
573 /// If this returns true then getTiedOperand will indicate which output
574 /// operand this is tied to.
575 bool hasTiedOperand() const { return TiedOperand != -1; }
576 unsigned getTiedOperand() const {
577 assert(hasTiedOperand() && "Has no tied operand!");
578 return (unsigned)TiedOperand;
581 bool requiresImmediateConstant() const {
582 return (Flags & CI_ImmediateConstant) != 0;
584 int getImmConstantMin() const { return ImmRange.Min; }
585 int getImmConstantMax() const { return ImmRange.Max; }
587 void setIsReadWrite() { Flags |= CI_ReadWrite; }
588 void setEarlyClobber() { Flags |= CI_EarlyClobber; }
589 void setAllowsMemory() { Flags |= CI_AllowsMemory; }
590 void setAllowsRegister() { Flags |= CI_AllowsRegister; }
591 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
592 void setRequiresImmediate(int Min, int Max) {
593 Flags |= CI_ImmediateConstant;
598 /// \brief Indicate that this is an input operand that is tied to
599 /// the specified output operand.
601 /// Copy over the various constraint information from the output.
602 void setTiedOperand(unsigned N, ConstraintInfo &Output) {
603 Output.setHasMatchingInput();
604 Flags = Output.Flags;
606 // Don't copy Name or constraint string.
610 // validateOutputConstraint, validateInputConstraint - Checks that
611 // a constraint is valid and provides information about it.
612 // FIXME: These should return a real error instead of just true/false.
613 bool validateOutputConstraint(ConstraintInfo &Info) const;
614 bool validateInputConstraint(ConstraintInfo *OutputConstraints,
616 ConstraintInfo &info) const;
618 virtual bool validateOutputSize(StringRef /*Constraint*/,
619 unsigned /*Size*/) const {
623 virtual bool validateInputSize(StringRef /*Constraint*/,
624 unsigned /*Size*/) const {
628 validateConstraintModifier(StringRef /*Constraint*/,
631 std::string &/*SuggestedModifier*/) const {
634 bool resolveSymbolicName(const char *&Name,
635 ConstraintInfo *OutputConstraints,
636 unsigned NumOutputs, unsigned &Index) const;
638 // Constraint parm will be left pointing at the last character of
639 // the constraint. In practice, it won't be changed unless the
640 // constraint is longer than one character.
641 virtual std::string convertConstraint(const char *&Constraint) const {
642 // 'p' defaults to 'r', but can be overridden by targets.
643 if (*Constraint == 'p')
644 return std::string("r");
645 return std::string(1, *Constraint);
648 /// \brief Returns true if NaN encoding is IEEE 754-2008.
649 /// Only MIPS allows a different encoding.
650 virtual bool isNan2008() const {
654 /// \brief Returns a string of target-specific clobbers, in LLVM format.
655 virtual const char *getClobbers() const = 0;
658 /// \brief Returns the target triple of the primary target.
659 const llvm::Triple &getTriple() const {
663 const char *getTargetDescription() const {
664 assert(DescriptionString);
665 return DescriptionString;
669 const char * const Aliases[5];
670 const char * const Register;
674 const char * const Names[5];
675 const unsigned RegNum;
678 /// \brief Does this target support "protected" visibility?
680 /// Any target which dynamic libraries will naturally support
681 /// something like "default" (meaning that the symbol is visible
682 /// outside this shared object) and "hidden" (meaning that it isn't)
683 /// visibilities, but "protected" is really an ELF-specific concept
684 /// with weird semantics designed around the convenience of dynamic
685 /// linker implementations. Which is not to suggest that there's
686 /// consistent target-independent semantics for "default" visibility
687 /// either; the entire thing is pretty badly mangled.
688 virtual bool hasProtectedVisibility() const { return true; }
690 /// \brief An optional hook that targets can implement to perform semantic
691 /// checking on attribute((section("foo"))) specifiers.
693 /// In this case, "foo" is passed in to be checked. If the section
694 /// specifier is invalid, the backend should return a non-empty string
695 /// that indicates the problem.
697 /// This hook is a simple quality of implementation feature to catch errors
698 /// and give good diagnostics in cases when the assembler or code generator
699 /// would otherwise reject the section specifier.
701 virtual std::string isValidSectionSpecifier(StringRef SR) const {
705 /// \brief Set forced language options.
707 /// Apply changes to the target information with respect to certain
708 /// language options which change the target configuration.
709 virtual void adjust(const LangOptions &Opts);
711 /// \brief Get the default set of target features for the CPU;
712 /// this should include all legal feature strings on the target.
713 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
716 /// \brief Get the ABI currently in use.
717 virtual StringRef getABI() const { return StringRef(); }
719 /// \brief Get the C++ ABI currently in use.
720 TargetCXXABI getCXXABI() const {
724 /// \brief Target the specified CPU.
726 /// \return False on error (invalid CPU name).
727 virtual bool setCPU(const std::string &Name) {
731 /// \brief Use the specified ABI.
733 /// \return False on error (invalid ABI name).
734 virtual bool setABI(const std::string &Name) {
738 /// \brief Use the specified unit for FP math.
740 /// \return False on error (invalid unit name).
741 virtual bool setFPMath(StringRef Name) {
745 /// \brief Use this specified C++ ABI.
747 /// \return False on error (invalid C++ ABI name).
748 bool setCXXABI(llvm::StringRef name) {
750 if (!ABI.tryParse(name)) return false;
751 return setCXXABI(ABI);
754 /// \brief Set the C++ ABI to be used by this implementation.
756 /// \return False on error (ABI not valid on this target)
757 virtual bool setCXXABI(TargetCXXABI ABI) {
762 /// \brief Enable or disable a specific target feature;
763 /// the feature name must be valid.
764 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
766 bool Enabled) const {
767 Features[Name] = Enabled;
770 /// \brief Perform initialization based on the user configured
771 /// set of features (e.g., +sse4).
773 /// The list is guaranteed to have at most one entry per feature.
775 /// The target may modify the features list, to change which options are
776 /// passed onwards to the backend.
778 /// \return False on error.
779 virtual bool handleTargetFeatures(std::vector<std::string> &Features,
780 DiagnosticsEngine &Diags) {
784 /// \brief Determine whether the given target has the given feature.
785 virtual bool hasFeature(StringRef Feature) const {
789 // \brief Returns maximal number of args passed in registers.
790 unsigned getRegParmMax() const {
791 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
795 /// \brief Whether the target supports thread-local storage.
796 bool isTLSSupported() const {
800 /// \brief Return true if {|} are normal characters in the asm string.
802 /// If this returns false (the default), then {abc|xyz} is syntax
803 /// that says that when compiling for asm variant #0, "abc" should be
804 /// generated, but when compiling for asm variant #1, "xyz" should be
806 bool hasNoAsmVariants() const {
807 return NoAsmVariants;
810 /// \brief Return the register number that __builtin_eh_return_regno would
811 /// return with the specified argument.
812 virtual int getEHDataRegisterNumber(unsigned RegNo) const {
816 /// \brief Return the section to use for C++ static initialization functions.
817 virtual const char *getStaticInitSectionSpecifier() const {
821 const LangAS::Map &getAddressSpaceMap() const {
822 return *AddrSpaceMap;
825 /// \brief Retrieve the name of the platform as it is used in the
826 /// availability attribute.
827 StringRef getPlatformName() const { return PlatformName; }
829 /// \brief Retrieve the minimum desired version of the platform, to
830 /// which the program should be compiled.
831 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
833 bool isBigEndian() const { return BigEndian; }
835 enum CallingConvMethodType {
841 /// \brief Gets the default calling convention for the given target and
842 /// declaration context.
843 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
844 // Not all targets will specify an explicit calling convention that we can
845 // express. This will always do the right thing, even though it's not
846 // an explicit calling convention.
850 enum CallingConvCheckResult {
856 /// \brief Determines whether a given calling convention is valid for the
857 /// target. A calling convention can either be accepted, produce a warning
858 /// and be substituted with the default calling convention, or (someday)
859 /// produce an error (such as using thiscall on a non-instance function).
860 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
869 /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
870 /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
871 virtual bool hasSjLjLowering() const {
876 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
879 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
882 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
885 virtual void getGCCRegNames(const char * const *&Names,
886 unsigned &NumNames) const = 0;
887 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
888 unsigned &NumAliases) const = 0;
889 virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
890 unsigned &NumAddl) const {
894 virtual bool validateAsmConstraint(const char *&Name,
895 TargetInfo::ConstraintInfo &info) const= 0;
898 } // end namespace clang