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