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