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