1 //===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// \brief Defines the clang::TargetInfo interface. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H 16 #define LLVM_CLANG_BASIC_TARGETINFO_H 17 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" 30 #include <cassert> 31 #include <string> 32 #include <vector> 33 34 namespace llvm { 35 struct fltSemantics; 36 } 37 38 namespace clang { 39 class DiagnosticsEngine; 40 class LangOptions; 41 class MacroBuilder; 42 class SourceLocation; 43 class SourceManager; 44 45 namespace Builtin { struct Info; } 46 47 /// \brief Exposes information about the current target. 48 /// 49 class TargetInfo : public RefCountedBase<TargetInfo> { 50 std::shared_ptr<TargetOptions> TargetOpts; 51 llvm::Triple Triple; 52 protected: 53 // Target values set by the ctor of the actual target implementation. Default 54 // values are specified by the TargetInfo constructor. 55 bool BigEndian; 56 bool TLSSupported; 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 MinGlobalAlign; 70 unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; 71 unsigned short MaxVectorAlign; 72 const char *DescriptionString; 73 const char *UserLabelPrefix; 74 const char *MCountName; 75 const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat, 76 *LongDoubleFormat; 77 unsigned char RegParmMax, SSERegParmMax; 78 TargetCXXABI TheCXXABI; 79 const LangAS::Map *AddrSpaceMap; 80 81 mutable StringRef PlatformName; 82 mutable VersionTuple PlatformMinVersion; 83 84 unsigned HasAlignMac68kSupport : 1; 85 unsigned RealTypeUsesObjCFPRet : 3; 86 unsigned ComplexLongDoubleUsesFP2Ret : 1; 87 88 // TargetInfo Constructor. Default initializes all fields. 89 TargetInfo(const llvm::Triple &T); 90 91 public: 92 /// \brief Construct a target for the given options. 93 /// 94 /// \param Opts - The options to use to initialize the target. The target may 95 /// modify the options to canonicalize the target feature information to match 96 /// what the backend expects. 97 static TargetInfo * 98 CreateTargetInfo(DiagnosticsEngine &Diags, 99 const std::shared_ptr<TargetOptions> &Opts); 100 101 virtual ~TargetInfo(); 102 103 /// \brief Retrieve the target options. 104 TargetOptions &getTargetOpts() const { 105 assert(TargetOpts && "Missing target options"); 106 return *TargetOpts; 107 } 108 109 ///===---- Target Data Type Query Methods -------------------------------===// 110 enum IntType { 111 NoInt = 0, 112 SignedChar, 113 UnsignedChar, 114 SignedShort, 115 UnsignedShort, 116 SignedInt, 117 UnsignedInt, 118 SignedLong, 119 UnsignedLong, 120 SignedLongLong, 121 UnsignedLongLong 122 }; 123 124 enum RealType { 125 NoFloat = 255, 126 Float = 0, 127 Double, 128 LongDouble 129 }; 130 131 /// \brief The different kinds of __builtin_va_list types defined by 132 /// the target implementation. 133 enum BuiltinVaListKind { 134 /// typedef char* __builtin_va_list; 135 CharPtrBuiltinVaList = 0, 136 137 /// typedef void* __builtin_va_list; 138 VoidPtrBuiltinVaList, 139 140 /// __builtin_va_list as defind by the AArch64 ABI 141 /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf 142 AArch64ABIBuiltinVaList, 143 144 /// __builtin_va_list as defined by the PNaCl ABI: 145 /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types 146 PNaClABIBuiltinVaList, 147 148 /// __builtin_va_list as defined by the Power ABI: 149 /// https://www.power.org 150 /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf 151 PowerABIBuiltinVaList, 152 153 /// __builtin_va_list as defined by the x86-64 ABI: 154 /// http://www.x86-64.org/documentation/abi.pdf 155 X86_64ABIBuiltinVaList, 156 157 /// __builtin_va_list as defined by ARM AAPCS ABI 158 /// http://infocenter.arm.com 159 // /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf 160 AAPCSABIBuiltinVaList, 161 162 // typedef struct __va_list_tag 163 // { 164 // long __gpr; 165 // long __fpr; 166 // void *__overflow_arg_area; 167 // void *__reg_save_area; 168 // } va_list[1]; 169 SystemZBuiltinVaList 170 }; 171 172 protected: 173 IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType, 174 WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType, 175 ProcessIDType; 176 177 /// \brief Whether Objective-C's built-in boolean type should be signed char. 178 /// 179 /// Otherwise, when this flag is not set, the normal built-in boolean type is 180 /// used. 181 unsigned UseSignedCharForObjCBool : 1; 182 183 /// Control whether the alignment of bit-field types is respected when laying 184 /// out structures. If true, then the alignment of the bit-field type will be 185 /// used to (a) impact the alignment of the containing structure, and (b) 186 /// ensure that the individual bit-field will not straddle an alignment 187 /// boundary. 188 unsigned UseBitFieldTypeAlignment : 1; 189 190 /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of 191 /// the next bitfield. 192 /// 193 /// If the alignment of the zero length bitfield is greater than the member 194 /// that follows it, `bar', `bar' will be aligned as the type of the 195 /// zero-length bitfield. 196 unsigned UseZeroLengthBitfieldAlignment : 1; 197 198 /// If non-zero, specifies a fixed alignment value for bitfields that follow 199 /// zero length bitfield, regardless of the zero length bitfield type. 200 unsigned ZeroLengthBitfieldBoundary; 201 202 /// \brief Specify if mangling based on address space map should be used or 203 /// not for language specific address spaces 204 bool UseAddrSpaceMapMangling; 205 206 public: 207 IntType getSizeType() const { return SizeType; } 208 IntType getIntMaxType() const { return IntMaxType; } 209 IntType getUIntMaxType() const { return UIntMaxType; } 210 IntType getPtrDiffType(unsigned AddrSpace) const { 211 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); 212 } 213 IntType getIntPtrType() const { return IntPtrType; } 214 IntType getUIntPtrType() const { 215 return getIntTypeByWidth(getTypeWidth(IntPtrType), false); 216 } 217 IntType getWCharType() const { return WCharType; } 218 IntType getWIntType() const { return WIntType; } 219 IntType getChar16Type() const { return Char16Type; } 220 IntType getChar32Type() const { return Char32Type; } 221 IntType getInt64Type() const { return Int64Type; } 222 IntType getSigAtomicType() const { return SigAtomicType; } 223 IntType getProcessIDType() const { return ProcessIDType; } 224 225 /// \brief Return the width (in bits) of the specified integer type enum. 226 /// 227 /// For example, SignedInt -> getIntWidth(). 228 unsigned getTypeWidth(IntType T) const; 229 230 /// \brief Return integer type with specified width. 231 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; 232 233 /// \brief Return the smallest integer type with at least the specified width. 234 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const; 235 236 /// \brief Return floating point type with specified width. 237 RealType getRealTypeByWidth(unsigned BitWidth) const; 238 239 /// \brief Return the alignment (in bits) of the specified integer type enum. 240 /// 241 /// For example, SignedInt -> getIntAlign(). 242 unsigned getTypeAlign(IntType T) const; 243 244 /// \brief Returns true if the type is signed; false otherwise. 245 static bool isTypeSigned(IntType T); 246 247 /// \brief Return the width of pointers on this target, for the 248 /// specified address space. 249 uint64_t getPointerWidth(unsigned AddrSpace) const { 250 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); 251 } 252 uint64_t getPointerAlign(unsigned AddrSpace) const { 253 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); 254 } 255 256 /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits. 257 unsigned getBoolWidth() const { return BoolWidth; } 258 259 /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target. 260 unsigned getBoolAlign() const { return BoolAlign; } 261 262 unsigned getCharWidth() const { return 8; } // FIXME 263 unsigned getCharAlign() const { return 8; } // FIXME 264 265 /// \brief Return the size of 'signed short' and 'unsigned short' for this 266 /// target, in bits. 267 unsigned getShortWidth() const { return 16; } // FIXME 268 269 /// \brief Return the alignment of 'signed short' and 'unsigned short' for 270 /// this target. 271 unsigned getShortAlign() const { return 16; } // FIXME 272 273 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for 274 /// this target, in bits. 275 unsigned getIntWidth() const { return IntWidth; } 276 unsigned getIntAlign() const { return IntAlign; } 277 278 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' 279 /// for this target, in bits. 280 unsigned getLongWidth() const { return LongWidth; } 281 unsigned getLongAlign() const { return LongAlign; } 282 283 /// getLongLongWidth/Align - Return the size of 'signed long long' and 284 /// 'unsigned long long' for this target, in bits. 285 unsigned getLongLongWidth() const { return LongLongWidth; } 286 unsigned getLongLongAlign() const { return LongLongAlign; } 287 288 /// \brief Determine whether the __int128 type is supported on this target. 289 virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME 290 291 /// \brief Return the alignment that is suitable for storing any 292 /// object with a fundamental alignment requirement. 293 unsigned getSuitableAlign() const { return SuitableAlign; } 294 295 /// getMinGlobalAlign - Return the minimum alignment of a global variable, 296 /// unless its alignment is explicitly reduced via attributes. 297 unsigned getMinGlobalAlign() const { return MinGlobalAlign; } 298 299 /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in 300 /// bits. 301 unsigned getWCharWidth() const { return getTypeWidth(WCharType); } 302 unsigned getWCharAlign() const { return getTypeAlign(WCharType); } 303 304 /// getChar16Width/Align - Return the size of 'char16_t' for this target, in 305 /// bits. 306 unsigned getChar16Width() const { return getTypeWidth(Char16Type); } 307 unsigned getChar16Align() const { return getTypeAlign(Char16Type); } 308 309 /// getChar32Width/Align - Return the size of 'char32_t' for this target, in 310 /// bits. 311 unsigned getChar32Width() const { return getTypeWidth(Char32Type); } 312 unsigned getChar32Align() const { return getTypeAlign(Char32Type); } 313 314 /// getHalfWidth/Align/Format - Return the size/align/format of 'half'. 315 unsigned getHalfWidth() const { return HalfWidth; } 316 unsigned getHalfAlign() const { return HalfAlign; } 317 const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; } 318 319 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. 320 unsigned getFloatWidth() const { return FloatWidth; } 321 unsigned getFloatAlign() const { return FloatAlign; } 322 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } 323 324 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. 325 unsigned getDoubleWidth() const { return DoubleWidth; } 326 unsigned getDoubleAlign() const { return DoubleAlign; } 327 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } 328 329 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long 330 /// double'. 331 unsigned getLongDoubleWidth() const { return LongDoubleWidth; } 332 unsigned getLongDoubleAlign() const { return LongDoubleAlign; } 333 const llvm::fltSemantics &getLongDoubleFormat() const { 334 return *LongDoubleFormat; 335 } 336 337 /// \brief Return the value for the C99 FLT_EVAL_METHOD macro. 338 virtual unsigned getFloatEvalMethod() const { return 0; } 339 340 // getLargeArrayMinWidth/Align - Return the minimum array size that is 341 // 'large' and its alignment. 342 unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; } 343 unsigned getLargeArrayAlign() const { return LargeArrayAlign; } 344 345 /// \brief Return the maximum width lock-free atomic operation which will 346 /// ever be supported for the given target 347 unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; } 348 /// \brief Return the maximum width lock-free atomic operation which can be 349 /// inlined given the supported features of the given target. 350 unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; } 351 352 /// \brief Return the maximum vector alignment supported for the given target. 353 unsigned getMaxVectorAlign() const { return MaxVectorAlign; } 354 355 /// \brief Return the size of intmax_t and uintmax_t for this target, in bits. 356 unsigned getIntMaxTWidth() const { 357 return getTypeWidth(IntMaxType); 358 } 359 360 // Return the size of unwind_word for this target. 361 unsigned getUnwindWordWidth() const { return getPointerWidth(0); } 362 363 /// \brief Return the "preferred" register width on this target. 364 unsigned getRegisterWidth() const { 365 // Currently we assume the register width on the target matches the pointer 366 // width, we can introduce a new variable for this if/when some target wants 367 // it. 368 return PointerWidth; 369 } 370 371 /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro, 372 /// which is the prefix given to user symbols by default. 373 /// 374 /// On most platforms this is "_", but it is "" on some, and "." on others. 375 const char *getUserLabelPrefix() const { 376 return UserLabelPrefix; 377 } 378 379 /// \brief Returns the name of the mcount instrumentation function. 380 const char *getMCountName() const { 381 return MCountName; 382 } 383 384 /// \brief Check if the Objective-C built-in boolean type should be signed 385 /// char. 386 /// 387 /// Otherwise, if this returns false, the normal built-in boolean type 388 /// should also be used for Objective-C. 389 bool useSignedCharForObjCBool() const { 390 return UseSignedCharForObjCBool; 391 } 392 void noSignedCharForObjCBool() { 393 UseSignedCharForObjCBool = false; 394 } 395 396 /// \brief Check whether the alignment of bit-field types is respected 397 /// when laying out structures. 398 bool useBitFieldTypeAlignment() const { 399 return UseBitFieldTypeAlignment; 400 } 401 402 /// \brief Check whether zero length bitfields should force alignment of 403 /// the next member. 404 bool useZeroLengthBitfieldAlignment() const { 405 return UseZeroLengthBitfieldAlignment; 406 } 407 408 /// \brief Get the fixed alignment value in bits for a member that follows 409 /// a zero length bitfield. 410 unsigned getZeroLengthBitfieldBoundary() const { 411 return ZeroLengthBitfieldBoundary; 412 } 413 414 /// \brief Check whether this target support '\#pragma options align=mac68k'. 415 bool hasAlignMac68kSupport() const { 416 return HasAlignMac68kSupport; 417 } 418 419 /// \brief Return the user string for the specified integer type enum. 420 /// 421 /// For example, SignedShort -> "short". 422 static const char *getTypeName(IntType T); 423 424 /// \brief Return the constant suffix for the specified integer type enum. 425 /// 426 /// For example, SignedLong -> "L". 427 static const char *getTypeConstantSuffix(IntType T); 428 429 /// \brief Check whether the given real type should use the "fpret" flavor of 430 /// Objective-C message passing on this target. 431 bool useObjCFPRetForRealType(RealType T) const { 432 return RealTypeUsesObjCFPRet & (1 << T); 433 } 434 435 /// \brief Check whether _Complex long double should use the "fp2ret" flavor 436 /// of Objective-C message passing on this target. 437 bool useObjCFP2RetForComplexLongDouble() const { 438 return ComplexLongDoubleUsesFP2Ret; 439 } 440 441 /// \brief Specify if mangling based on address space map should be used or 442 /// not for language specific address spaces 443 bool useAddressSpaceMapMangling() const { 444 return UseAddrSpaceMapMangling; 445 } 446 447 ///===---- Other target property query methods --------------------------===// 448 449 /// \brief Appends the target-specific \#define values for this 450 /// target set to the specified buffer. 451 virtual void getTargetDefines(const LangOptions &Opts, 452 MacroBuilder &Builder) const = 0; 453 454 455 /// Return information about target-specific builtins for 456 /// the current primary target, and info about which builtins are non-portable 457 /// across the current set of primary and secondary targets. 458 virtual void getTargetBuiltins(const Builtin::Info *&Records, 459 unsigned &NumRecords) const = 0; 460 461 /// The __builtin_clz* and __builtin_ctz* built-in 462 /// functions are specified to have undefined results for zero inputs, but 463 /// on targets that support these operations in a way that provides 464 /// well-defined results for zero without loss of performance, it is a good 465 /// idea to avoid optimizing based on that undef behavior. 466 virtual bool isCLZForZeroUndef() const { return true; } 467 468 /// \brief Returns the kind of __builtin_va_list type that should be used 469 /// with this target. 470 virtual BuiltinVaListKind getBuiltinVaListKind() const = 0; 471 472 /// \brief Returns whether the passed in string is a valid clobber in an 473 /// inline asm statement. 474 /// 475 /// This is used by Sema. 476 bool isValidClobber(StringRef Name) const; 477 478 /// \brief Returns whether the passed in string is a valid register name 479 /// according to GCC. 480 /// 481 /// This is used by Sema for inline asm statements. 482 bool isValidGCCRegisterName(StringRef Name) const; 483 484 /// \brief Returns the "normalized" GCC register name. 485 /// 486 /// For example, on x86 it will return "ax" when "eax" is passed in. 487 StringRef getNormalizedGCCRegisterName(StringRef Name) const; 488 489 struct ConstraintInfo { 490 enum { 491 CI_None = 0x00, 492 CI_AllowsMemory = 0x01, 493 CI_AllowsRegister = 0x02, 494 CI_ReadWrite = 0x04, // "+r" output constraint (read and write). 495 CI_HasMatchingInput = 0x08 // This output operand has a matching input. 496 }; 497 unsigned Flags; 498 int TiedOperand; 499 500 std::string ConstraintStr; // constraint: "=rm" 501 std::string Name; // Operand name: [foo] with no []'s. 502 public: 503 ConstraintInfo(StringRef ConstraintStr, StringRef Name) 504 : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()), 505 Name(Name.str()) {} 506 507 const std::string &getConstraintStr() const { return ConstraintStr; } 508 const std::string &getName() const { return Name; } 509 bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; } 510 bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; } 511 bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; } 512 513 /// \brief Return true if this output operand has a matching 514 /// (tied) input operand. 515 bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; } 516 517 /// \brief Return true if this input operand is a matching 518 /// constraint that ties it to an output operand. 519 /// 520 /// If this returns true then getTiedOperand will indicate which output 521 /// operand this is tied to. 522 bool hasTiedOperand() const { return TiedOperand != -1; } 523 unsigned getTiedOperand() const { 524 assert(hasTiedOperand() && "Has no tied operand!"); 525 return (unsigned)TiedOperand; 526 } 527 528 void setIsReadWrite() { Flags |= CI_ReadWrite; } 529 void setAllowsMemory() { Flags |= CI_AllowsMemory; } 530 void setAllowsRegister() { Flags |= CI_AllowsRegister; } 531 void setHasMatchingInput() { Flags |= CI_HasMatchingInput; } 532 533 /// \brief Indicate that this is an input operand that is tied to 534 /// the specified output operand. 535 /// 536 /// Copy over the various constraint information from the output. 537 void setTiedOperand(unsigned N, ConstraintInfo &Output) { 538 Output.setHasMatchingInput(); 539 Flags = Output.Flags; 540 TiedOperand = N; 541 // Don't copy Name or constraint string. 542 } 543 }; 544 545 // validateOutputConstraint, validateInputConstraint - Checks that 546 // a constraint is valid and provides information about it. 547 // FIXME: These should return a real error instead of just true/false. 548 bool validateOutputConstraint(ConstraintInfo &Info) const; 549 bool validateInputConstraint(ConstraintInfo *OutputConstraints, 550 unsigned NumOutputs, 551 ConstraintInfo &info) const; 552 virtual bool validateInputSize(StringRef /*Constraint*/, 553 unsigned /*Size*/) const { 554 return true; 555 } 556 virtual bool validateConstraintModifier(StringRef /*Constraint*/, 557 const char /*Modifier*/, 558 unsigned /*Size*/) const { 559 return true; 560 } 561 bool resolveSymbolicName(const char *&Name, 562 ConstraintInfo *OutputConstraints, 563 unsigned NumOutputs, unsigned &Index) const; 564 565 // Constraint parm will be left pointing at the last character of 566 // the constraint. In practice, it won't be changed unless the 567 // constraint is longer than one character. 568 virtual std::string convertConstraint(const char *&Constraint) const { 569 // 'p' defaults to 'r', but can be overridden by targets. 570 if (*Constraint == 'p') 571 return std::string("r"); 572 return std::string(1, *Constraint); 573 } 574 575 /// \brief Returns a string of target-specific clobbers, in LLVM format. 576 virtual const char *getClobbers() const = 0; 577 578 579 /// \brief Returns the target triple of the primary target. 580 const llvm::Triple &getTriple() const { 581 return Triple; 582 } 583 584 const char *getTargetDescription() const { 585 assert(DescriptionString); 586 return DescriptionString; 587 } 588 589 struct GCCRegAlias { 590 const char * const Aliases[5]; 591 const char * const Register; 592 }; 593 594 struct AddlRegName { 595 const char * const Names[5]; 596 const unsigned RegNum; 597 }; 598 599 /// \brief Does this target support "protected" visibility? 600 /// 601 /// Any target which dynamic libraries will naturally support 602 /// something like "default" (meaning that the symbol is visible 603 /// outside this shared object) and "hidden" (meaning that it isn't) 604 /// visibilities, but "protected" is really an ELF-specific concept 605 /// with weird semantics designed around the convenience of dynamic 606 /// linker implementations. Which is not to suggest that there's 607 /// consistent target-independent semantics for "default" visibility 608 /// either; the entire thing is pretty badly mangled. 609 virtual bool hasProtectedVisibility() const { return true; } 610 611 /// \brief An optional hook that targets can implement to perform semantic 612 /// checking on attribute((section("foo"))) specifiers. 613 /// 614 /// In this case, "foo" is passed in to be checked. If the section 615 /// specifier is invalid, the backend should return a non-empty string 616 /// that indicates the problem. 617 /// 618 /// This hook is a simple quality of implementation feature to catch errors 619 /// and give good diagnostics in cases when the assembler or code generator 620 /// would otherwise reject the section specifier. 621 /// 622 virtual std::string isValidSectionSpecifier(StringRef SR) const { 623 return ""; 624 } 625 626 /// \brief Set forced language options. 627 /// 628 /// Apply changes to the target information with respect to certain 629 /// language options which change the target configuration. 630 virtual void adjust(const LangOptions &Opts); 631 632 /// \brief Get the default set of target features for the CPU; 633 /// this should include all legal feature strings on the target. 634 virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const { 635 } 636 637 /// \brief Get the ABI currently in use. 638 virtual StringRef getABI() const { return StringRef(); } 639 640 /// \brief Get the C++ ABI currently in use. 641 TargetCXXABI getCXXABI() const { 642 return TheCXXABI; 643 } 644 645 /// \brief Target the specified CPU. 646 /// 647 /// \return False on error (invalid CPU name). 648 virtual bool setCPU(const std::string &Name) { 649 return false; 650 } 651 652 /// \brief Use the specified ABI. 653 /// 654 /// \return False on error (invalid ABI name). 655 virtual bool setABI(const std::string &Name) { 656 return false; 657 } 658 659 /// \brief Use the specified unit for FP math. 660 /// 661 /// \return False on error (invalid unit name). 662 virtual bool setFPMath(StringRef Name) { 663 return false; 664 } 665 666 /// \brief Use this specified C++ ABI. 667 /// 668 /// \return False on error (invalid C++ ABI name). 669 bool setCXXABI(llvm::StringRef name) { 670 TargetCXXABI ABI; 671 if (!ABI.tryParse(name)) return false; 672 return setCXXABI(ABI); 673 } 674 675 /// \brief Set the C++ ABI to be used by this implementation. 676 /// 677 /// \return False on error (ABI not valid on this target) 678 virtual bool setCXXABI(TargetCXXABI ABI) { 679 TheCXXABI = ABI; 680 return true; 681 } 682 683 /// \brief Enable or disable a specific target feature; 684 /// the feature name must be valid. 685 virtual void setFeatureEnabled(llvm::StringMap<bool> &Features, 686 StringRef Name, 687 bool Enabled) const { 688 Features[Name] = Enabled; 689 } 690 691 /// \brief Perform initialization based on the user configured 692 /// set of features (e.g., +sse4). 693 /// 694 /// The list is guaranteed to have at most one entry per feature. 695 /// 696 /// The target may modify the features list, to change which options are 697 /// passed onwards to the backend. 698 /// 699 /// \return False on error. 700 virtual bool handleTargetFeatures(std::vector<std::string> &Features, 701 DiagnosticsEngine &Diags) { 702 return true; 703 } 704 705 /// \brief Determine whether the given target has the given feature. 706 virtual bool hasFeature(StringRef Feature) const { 707 return false; 708 } 709 710 // \brief Returns maximal number of args passed in registers. 711 unsigned getRegParmMax() const { 712 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle"); 713 return RegParmMax; 714 } 715 716 /// \brief Whether the target supports thread-local storage. 717 bool isTLSSupported() const { 718 return TLSSupported; 719 } 720 721 /// \brief Return true if {|} are normal characters in the asm string. 722 /// 723 /// If this returns false (the default), then {abc|xyz} is syntax 724 /// that says that when compiling for asm variant #0, "abc" should be 725 /// generated, but when compiling for asm variant #1, "xyz" should be 726 /// generated. 727 bool hasNoAsmVariants() const { 728 return NoAsmVariants; 729 } 730 731 /// \brief Return the register number that __builtin_eh_return_regno would 732 /// return with the specified argument. 733 virtual int getEHDataRegisterNumber(unsigned RegNo) const { 734 return -1; 735 } 736 737 /// \brief Return the section to use for C++ static initialization functions. 738 virtual const char *getStaticInitSectionSpecifier() const { 739 return nullptr; 740 } 741 742 const LangAS::Map &getAddressSpaceMap() const { 743 return *AddrSpaceMap; 744 } 745 746 /// \brief Retrieve the name of the platform as it is used in the 747 /// availability attribute. 748 StringRef getPlatformName() const { return PlatformName; } 749 750 /// \brief Retrieve the minimum desired version of the platform, to 751 /// which the program should be compiled. 752 VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; } 753 754 bool isBigEndian() const { return BigEndian; } 755 756 enum CallingConvMethodType { 757 CCMT_Unknown, 758 CCMT_Member, 759 CCMT_NonMember 760 }; 761 762 /// \brief Gets the default calling convention for the given target and 763 /// declaration context. 764 virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const { 765 // Not all targets will specify an explicit calling convention that we can 766 // express. This will always do the right thing, even though it's not 767 // an explicit calling convention. 768 return CC_C; 769 } 770 771 enum CallingConvCheckResult { 772 CCCR_OK, 773 CCCR_Warning 774 }; 775 776 /// \brief Determines whether a given calling convention is valid for the 777 /// target. A calling convention can either be accepted, produce a warning 778 /// and be substituted with the default calling convention, or (someday) 779 /// produce an error (such as using thiscall on a non-instance function). 780 virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const { 781 switch (CC) { 782 default: 783 return CCCR_Warning; 784 case CC_C: 785 return CCCR_OK; 786 } 787 } 788 789 protected: 790 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { 791 return PointerWidth; 792 } 793 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { 794 return PointerAlign; 795 } 796 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { 797 return PtrDiffType; 798 } 799 virtual void getGCCRegNames(const char * const *&Names, 800 unsigned &NumNames) const = 0; 801 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 802 unsigned &NumAliases) const = 0; 803 virtual void getGCCAddlRegNames(const AddlRegName *&Addl, 804 unsigned &NumAddl) const { 805 Addl = nullptr; 806 NumAddl = 0; 807 } 808 virtual bool validateAsmConstraint(const char *&Name, 809 TargetInfo::ConstraintInfo &info) const= 0; 810 }; 811 812 } // end namespace clang 813 814 #endif 815