TargetInfo.h revision 239462
1193326Sed//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9239462Sdim/// 10239462Sdim/// \file 11239462Sdim/// \brief Defines the clang::TargetInfo interface. 12239462Sdim/// 13193326Sed//===----------------------------------------------------------------------===// 14193326Sed 15193326Sed#ifndef LLVM_CLANG_BASIC_TARGETINFO_H 16193326Sed#define LLVM_CLANG_BASIC_TARGETINFO_H 17193326Sed 18226633Sdim#include "clang/Basic/LLVM.h" 19221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 20193326Sed#include "llvm/ADT/StringMap.h" 21221345Sdim#include "llvm/ADT/StringRef.h" 22212904Sdim#include "llvm/ADT/StringSwitch.h" 23198092Srdivacky#include "llvm/ADT/Triple.h" 24218893Sdim#include "llvm/Support/DataTypes.h" 25221345Sdim#include "clang/Basic/AddressSpaces.h" 26221345Sdim#include "clang/Basic/VersionTuple.h" 27193326Sed#include <cassert> 28193326Sed#include <vector> 29193326Sed#include <string> 30193326Sed 31198092Srdivackynamespace llvm { 32198092Srdivackystruct fltSemantics; 33198092Srdivacky} 34193326Sed 35193326Sednamespace clang { 36226633Sdimclass DiagnosticsEngine; 37199482Srdivackyclass LangOptions; 38202379Srdivackyclass MacroBuilder; 39198092Srdivackyclass SourceLocation; 40193326Sedclass SourceManager; 41199482Srdivackyclass TargetOptions; 42199482Srdivacky 43193326Sednamespace Builtin { struct Info; } 44198092Srdivacky 45239462Sdim/// \brief The types of C++ ABIs for which we can generate code. 46212904Sdimenum TargetCXXABI { 47212904Sdim /// The generic ("Itanium") C++ ABI, documented at: 48212904Sdim /// http://www.codesourcery.com/public/cxx-abi/ 49212904Sdim CXXABI_Itanium, 50212904Sdim 51212904Sdim /// The ARM C++ ABI, based largely on the Itanium ABI but with 52212904Sdim /// significant differences. 53212904Sdim /// http://infocenter.arm.com 54212904Sdim /// /help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf 55212904Sdim CXXABI_ARM, 56212904Sdim 57212904Sdim /// The Visual Studio ABI. Only scattered official documentation exists. 58212904Sdim CXXABI_Microsoft 59212904Sdim}; 60212904Sdim 61239462Sdim/// \brief Exposes information about the current target. 62193326Sed/// 63234353Sdimclass TargetInfo : public RefCountedBase<TargetInfo> { 64198092Srdivacky llvm::Triple Triple; 65193326Sedprotected: 66193326Sed // Target values set by the ctor of the actual target implementation. Default 67193326Sed // values are specified by the TargetInfo constructor. 68234353Sdim bool BigEndian; 69193326Sed bool TLSSupported; 70207619Srdivacky bool NoAsmVariants; // True if {|} are normal characters. 71193326Sed unsigned char PointerWidth, PointerAlign; 72218893Sdim unsigned char BoolWidth, BoolAlign; 73193326Sed unsigned char IntWidth, IntAlign; 74226633Sdim unsigned char HalfWidth, HalfAlign; 75193326Sed unsigned char FloatWidth, FloatAlign; 76193326Sed unsigned char DoubleWidth, DoubleAlign; 77193326Sed unsigned char LongDoubleWidth, LongDoubleAlign; 78210299Sed unsigned char LargeArrayMinWidth, LargeArrayAlign; 79193326Sed unsigned char LongWidth, LongAlign; 80193326Sed unsigned char LongLongWidth, LongLongAlign; 81234353Sdim unsigned char SuitableAlign; 82226633Sdim unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; 83239462Sdim unsigned short MaxVectorAlign; 84193326Sed const char *DescriptionString; 85193326Sed const char *UserLabelPrefix; 86218893Sdim const char *MCountName; 87226633Sdim const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat, 88226633Sdim *LongDoubleFormat; 89193326Sed unsigned char RegParmMax, SSERegParmMax; 90212904Sdim TargetCXXABI CXXABI; 91221345Sdim const LangAS::Map *AddrSpaceMap; 92193326Sed 93226633Sdim mutable StringRef PlatformName; 94221345Sdim mutable VersionTuple PlatformMinVersion; 95221345Sdim 96208600Srdivacky unsigned HasAlignMac68kSupport : 1; 97210299Sed unsigned RealTypeUsesObjCFPRet : 3; 98234353Sdim unsigned ComplexLongDoubleUsesFP2Ret : 1; 99208600Srdivacky 100193326Sed // TargetInfo Constructor. Default initializes all fields. 101193326Sed TargetInfo(const std::string &T); 102198092Srdivacky 103198092Srdivackypublic: 104239462Sdim /// \brief Construct a target for the given options. 105201361Srdivacky /// 106201361Srdivacky /// \param Opts - The options to use to initialize the target. The target may 107201361Srdivacky /// modify the options to canonicalize the target feature information to match 108201361Srdivacky /// what the backend expects. 109226633Sdim static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags, 110226633Sdim TargetOptions &Opts); 111193326Sed 112193326Sed virtual ~TargetInfo(); 113193326Sed 114193326Sed ///===---- Target Data Type Query Methods -------------------------------===// 115193326Sed enum IntType { 116193326Sed NoInt = 0, 117193326Sed SignedShort, 118193326Sed UnsignedShort, 119193326Sed SignedInt, 120193326Sed UnsignedInt, 121193326Sed SignedLong, 122193326Sed UnsignedLong, 123193326Sed SignedLongLong, 124193326Sed UnsignedLongLong 125193326Sed }; 126210299Sed 127210299Sed enum RealType { 128210299Sed Float = 0, 129210299Sed Double, 130210299Sed LongDouble 131210299Sed }; 132210299Sed 133239462Sdim /// \brief The different kinds of __builtin_va_list types defined by 134239462Sdim /// the target implementation. 135239462Sdim enum BuiltinVaListKind { 136239462Sdim /// typedef char* __builtin_va_list; 137239462Sdim CharPtrBuiltinVaList = 0, 138239462Sdim 139239462Sdim /// typedef void* __builtin_va_list; 140239462Sdim VoidPtrBuiltinVaList, 141239462Sdim 142239462Sdim /// __builtin_va_list as defined by the PNaCl ABI: 143239462Sdim /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types 144239462Sdim PNaClABIBuiltinVaList, 145239462Sdim 146239462Sdim /// __builtin_va_list as defined by the Power ABI: 147239462Sdim /// https://www.power.org 148239462Sdim /// /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf 149239462Sdim PowerABIBuiltinVaList, 150239462Sdim 151239462Sdim /// __builtin_va_list as defined by the x86-64 ABI: 152239462Sdim /// http://www.x86-64.org/documentation/abi.pdf 153239462Sdim X86_64ABIBuiltinVaList 154239462Sdim }; 155239462Sdim 156193326Sedprotected: 157195341Sed IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType, 158199990Srdivacky WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType; 159207619Srdivacky 160239462Sdim /// \brief Whether Objective-C's built-in boolean type should be signed char. 161239462Sdim /// 162234982Sdim /// Otherwise, when this flag is not set, the normal built-in boolean type is 163234982Sdim /// used. 164234982Sdim unsigned UseSignedCharForObjCBool : 1; 165234982Sdim 166207619Srdivacky /// Control whether the alignment of bit-field types is respected when laying 167207619Srdivacky /// out structures. If true, then the alignment of the bit-field type will be 168207619Srdivacky /// used to (a) impact the alignment of the containing structure, and (b) 169207619Srdivacky /// ensure that the individual bit-field will not straddle an alignment 170207619Srdivacky /// boundary. 171207619Srdivacky unsigned UseBitFieldTypeAlignment : 1; 172207619Srdivacky 173239462Sdim /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of 174239462Sdim /// the next bitfield. 175239462Sdim /// 176239462Sdim /// If the alignment of the zero length bitfield is greater than the member 177239462Sdim /// that follows it, `bar', `bar' will be aligned as the type of the 178239462Sdim /// zero-length bitfield. 179226633Sdim unsigned UseZeroLengthBitfieldAlignment : 1; 180226633Sdim 181226633Sdim /// If non-zero, specifies a fixed alignment value for bitfields that follow 182226633Sdim /// zero length bitfield, regardless of the zero length bitfield type. 183226633Sdim unsigned ZeroLengthBitfieldBoundary; 184226633Sdim 185193326Sedpublic: 186193326Sed IntType getSizeType() const { return SizeType; } 187193326Sed IntType getIntMaxType() const { return IntMaxType; } 188193326Sed IntType getUIntMaxType() const { return UIntMaxType; } 189193326Sed IntType getPtrDiffType(unsigned AddrSpace) const { 190193326Sed return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); 191193326Sed } 192193326Sed IntType getIntPtrType() const { return IntPtrType; } 193193326Sed IntType getWCharType() const { return WCharType; } 194198398Srdivacky IntType getWIntType() const { return WIntType; } 195198092Srdivacky IntType getChar16Type() const { return Char16Type; } 196198092Srdivacky IntType getChar32Type() const { return Char32Type; } 197195341Sed IntType getInt64Type() const { return Int64Type; } 198199990Srdivacky IntType getSigAtomicType() const { return SigAtomicType; } 199193326Sed 200198398Srdivacky 201239462Sdim /// \brief Return the width (in bits) of the specified integer type enum. 202239462Sdim /// 203239462Sdim /// For example, SignedInt -> getIntWidth(). 204198398Srdivacky unsigned getTypeWidth(IntType T) const; 205198398Srdivacky 206239462Sdim /// \brief Return the alignment (in bits) of the specified integer type enum. 207239462Sdim /// 208239462Sdim /// For example, SignedInt -> getIntAlign(). 209199482Srdivacky unsigned getTypeAlign(IntType T) const; 210199482Srdivacky 211239462Sdim /// \brief Returns true if the type is signed; false otherwise. 212218893Sdim static bool isTypeSigned(IntType T); 213198398Srdivacky 214239462Sdim /// \brief Return the width of pointers on this target, for the 215193326Sed /// specified address space. 216193326Sed uint64_t getPointerWidth(unsigned AddrSpace) const { 217193326Sed return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); 218193326Sed } 219193326Sed uint64_t getPointerAlign(unsigned AddrSpace) const { 220193326Sed return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); 221193326Sed } 222198092Srdivacky 223239462Sdim /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits. 224218893Sdim unsigned getBoolWidth() const { return BoolWidth; } 225239462Sdim 226239462Sdim /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target. 227218893Sdim unsigned getBoolAlign() const { return BoolAlign; } 228198092Srdivacky 229198092Srdivacky unsigned getCharWidth() const { return 8; } // FIXME 230198092Srdivacky unsigned getCharAlign() const { return 8; } // FIXME 231198092Srdivacky 232239462Sdim /// \brief Return the size of 'signed short' and 'unsigned short' for this 233239462Sdim /// target, in bits. 234193326Sed unsigned getShortWidth() const { return 16; } // FIXME 235239462Sdim 236239462Sdim /// \brief Return the alignment of 'signed short' and 'unsigned short' for 237239462Sdim /// this target. 238193326Sed unsigned getShortAlign() const { return 16; } // FIXME 239198092Srdivacky 240193326Sed /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for 241193326Sed /// this target, in bits. 242193326Sed unsigned getIntWidth() const { return IntWidth; } 243193326Sed unsigned getIntAlign() const { return IntAlign; } 244198092Srdivacky 245193326Sed /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' 246193326Sed /// for this target, in bits. 247193326Sed unsigned getLongWidth() const { return LongWidth; } 248193326Sed unsigned getLongAlign() const { return LongAlign; } 249198092Srdivacky 250193326Sed /// getLongLongWidth/Align - Return the size of 'signed long long' and 251193326Sed /// 'unsigned long long' for this target, in bits. 252193326Sed unsigned getLongLongWidth() const { return LongLongWidth; } 253193326Sed unsigned getLongLongAlign() const { return LongLongAlign; } 254198092Srdivacky 255239462Sdim /// \brief Return the alignment that is suitable for storing any 256234353Sdim /// object with a fundamental alignment requirement. 257234353Sdim unsigned getSuitableAlign() const { return SuitableAlign; } 258234353Sdim 259198092Srdivacky /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in 260193326Sed /// bits. 261199482Srdivacky unsigned getWCharWidth() const { return getTypeWidth(WCharType); } 262199482Srdivacky unsigned getWCharAlign() const { return getTypeAlign(WCharType); } 263193326Sed 264198092Srdivacky /// getChar16Width/Align - Return the size of 'char16_t' for this target, in 265198092Srdivacky /// bits. 266199482Srdivacky unsigned getChar16Width() const { return getTypeWidth(Char16Type); } 267199482Srdivacky unsigned getChar16Align() const { return getTypeAlign(Char16Type); } 268198092Srdivacky 269198092Srdivacky /// getChar32Width/Align - Return the size of 'char32_t' for this target, in 270198092Srdivacky /// bits. 271199482Srdivacky unsigned getChar32Width() const { return getTypeWidth(Char32Type); } 272199482Srdivacky unsigned getChar32Align() const { return getTypeAlign(Char32Type); } 273198092Srdivacky 274226633Sdim /// getHalfWidth/Align/Format - Return the size/align/format of 'half'. 275226633Sdim unsigned getHalfWidth() const { return HalfWidth; } 276226633Sdim unsigned getHalfAlign() const { return HalfAlign; } 277226633Sdim const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; } 278226633Sdim 279193326Sed /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. 280193326Sed unsigned getFloatWidth() const { return FloatWidth; } 281193326Sed unsigned getFloatAlign() const { return FloatAlign; } 282193326Sed const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } 283193326Sed 284193326Sed /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. 285193326Sed unsigned getDoubleWidth() const { return DoubleWidth; } 286193326Sed unsigned getDoubleAlign() const { return DoubleAlign; } 287193326Sed const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } 288193326Sed 289193326Sed /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long 290193326Sed /// double'. 291193326Sed unsigned getLongDoubleWidth() const { return LongDoubleWidth; } 292193326Sed unsigned getLongDoubleAlign() const { return LongDoubleAlign; } 293193326Sed const llvm::fltSemantics &getLongDoubleFormat() const { 294193326Sed return *LongDoubleFormat; 295193326Sed } 296198092Srdivacky 297239462Sdim /// \brief Return the value for the C99 FLT_EVAL_METHOD macro. 298234353Sdim virtual unsigned getFloatEvalMethod() const { return 0; } 299234353Sdim 300210299Sed // getLargeArrayMinWidth/Align - Return the minimum array size that is 301210299Sed // 'large' and its alignment. 302210299Sed unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; } 303210299Sed unsigned getLargeArrayAlign() const { return LargeArrayAlign; } 304210299Sed 305239462Sdim /// \brief Return the maximum width lock-free atomic operation which will 306239462Sdim /// ever be supported for the given target 307226633Sdim unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; } 308239462Sdim /// \brief Return the maximum width lock-free atomic operation which can be 309239462Sdim /// inlined given the supported features of the given target. 310226633Sdim unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; } 311226633Sdim 312239462Sdim /// \brief Return the maximum vector alignment supported for the given target. 313239462Sdim unsigned getMaxVectorAlign() const { return MaxVectorAlign; } 314239462Sdim 315239462Sdim /// \brief Return the size of intmax_t and uintmax_t for this target, in bits. 316193326Sed unsigned getIntMaxTWidth() const { 317199482Srdivacky return getTypeWidth(IntMaxType); 318193326Sed } 319198092Srdivacky 320239462Sdim /// \brief Return the "preferred" register width on this target. 321224145Sdim uint64_t getRegisterWidth() const { 322224145Sdim // Currently we assume the register width on the target matches the pointer 323224145Sdim // width, we can introduce a new variable for this if/when some target wants 324224145Sdim // it. 325224145Sdim return LongWidth; 326224145Sdim } 327224145Sdim 328239462Sdim /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro, 329239462Sdim /// which is the prefix given to user symbols by default. 330239462Sdim /// 331239462Sdim /// On most platforms this is "_", but it is "" on some, and "." on others. 332193326Sed const char *getUserLabelPrefix() const { 333193326Sed return UserLabelPrefix; 334193326Sed } 335198092Srdivacky 336239462Sdim /// \brief Returns the name of the mcount instrumentation function. 337218893Sdim const char *getMCountName() const { 338218893Sdim return MCountName; 339218893Sdim } 340218893Sdim 341239462Sdim /// \brief Check if the Objective-C built-in boolean type should be signed 342239462Sdim /// char. 343239462Sdim /// 344239462Sdim /// Otherwise, if this returns false, the normal built-in boolean type 345239462Sdim /// should also be used for Objective-C. 346234982Sdim bool useSignedCharForObjCBool() const { 347234982Sdim return UseSignedCharForObjCBool; 348234982Sdim } 349234982Sdim void noSignedCharForObjCBool() { 350234982Sdim UseSignedCharForObjCBool = false; 351234982Sdim } 352234982Sdim 353239462Sdim /// \brief Check whether the alignment of bit-field types is respected 354239462Sdim /// when laying out structures. 355207619Srdivacky bool useBitFieldTypeAlignment() const { 356207619Srdivacky return UseBitFieldTypeAlignment; 357207619Srdivacky } 358207619Srdivacky 359239462Sdim /// \brief Check whether zero length bitfields should force alignment of 360239462Sdim /// the next member. 361226633Sdim bool useZeroLengthBitfieldAlignment() const { 362226633Sdim return UseZeroLengthBitfieldAlignment; 363226633Sdim } 364226633Sdim 365239462Sdim /// \brief Get the fixed alignment value in bits for a member that follows 366239462Sdim /// a zero length bitfield. 367226633Sdim unsigned getZeroLengthBitfieldBoundary() const { 368226633Sdim return ZeroLengthBitfieldBoundary; 369226633Sdim } 370226633Sdim 371239462Sdim /// \brief Check whether this target support '\#pragma options align=mac68k'. 372208600Srdivacky bool hasAlignMac68kSupport() const { 373208600Srdivacky return HasAlignMac68kSupport; 374208600Srdivacky } 375208600Srdivacky 376239462Sdim /// \brief Return the user string for the specified integer type enum. 377239462Sdim /// 378193326Sed /// For example, SignedShort -> "short". 379193326Sed static const char *getTypeName(IntType T); 380198092Srdivacky 381239462Sdim /// \brief Return the constant suffix for the specified integer type enum. 382239462Sdim /// 383239462Sdim /// For example, SignedLong -> "L". 384198398Srdivacky static const char *getTypeConstantSuffix(IntType T); 385198398Srdivacky 386210299Sed /// \brief Check whether the given real type should use the "fpret" flavor of 387239462Sdim /// Objective-C message passing on this target. 388210299Sed bool useObjCFPRetForRealType(RealType T) const { 389210299Sed return RealTypeUsesObjCFPRet & (1 << T); 390210299Sed } 391210299Sed 392234353Sdim /// \brief Check whether _Complex long double should use the "fp2ret" flavor 393239462Sdim /// of Objective-C message passing on this target. 394234353Sdim bool useObjCFP2RetForComplexLongDouble() const { 395234353Sdim return ComplexLongDoubleUsesFP2Ret; 396234353Sdim } 397234353Sdim 398193326Sed ///===---- Other target property query methods --------------------------===// 399198092Srdivacky 400239462Sdim /// \brief Appends the target-specific \#define values for this 401193326Sed /// target set to the specified buffer. 402193326Sed virtual void getTargetDefines(const LangOptions &Opts, 403202379Srdivacky MacroBuilder &Builder) const = 0; 404198092Srdivacky 405198398Srdivacky 406239462Sdim /// Return information about target-specific builtins for 407193326Sed /// the current primary target, and info about which builtins are non-portable 408193326Sed /// across the current set of primary and secondary targets. 409198092Srdivacky virtual void getTargetBuiltins(const Builtin::Info *&Records, 410193326Sed unsigned &NumRecords) const = 0; 411193326Sed 412239462Sdim /// The __builtin_clz* and __builtin_ctz* built-in 413234353Sdim /// functions are specified to have undefined results for zero inputs, but 414234353Sdim /// on targets that support these operations in a way that provides 415234353Sdim /// well-defined results for zero without loss of performance, it is a good 416234353Sdim /// idea to avoid optimizing based on that undef behavior. 417234353Sdim virtual bool isCLZForZeroUndef() const { return true; } 418234353Sdim 419239462Sdim /// \brief Returns the kind of __builtin_va_list type that should be used 420239462Sdim /// with this target. 421239462Sdim virtual BuiltinVaListKind getBuiltinVaListKind() const = 0; 422193326Sed 423239462Sdim /// \brief Returns whether the passed in string is a valid clobber in an 424239462Sdim /// inline asm statement. 425239462Sdim /// 426239462Sdim /// This is used by Sema. 427226633Sdim bool isValidClobber(StringRef Name) const; 428224145Sdim 429239462Sdim /// \brief Returns whether the passed in string is a valid register name 430239462Sdim /// according to GCC. 431239462Sdim /// 432239462Sdim /// This is used by Sema for inline asm statements. 433226633Sdim bool isValidGCCRegisterName(StringRef Name) const; 434193326Sed 435239462Sdim /// \brief Returns the "normalized" GCC register name. 436239462Sdim /// 437239462Sdim /// For example, on x86 it will return "ax" when "eax" is passed in. 438226633Sdim StringRef getNormalizedGCCRegisterName(StringRef Name) const; 439198092Srdivacky 440193326Sed struct ConstraintInfo { 441193326Sed enum { 442193326Sed CI_None = 0x00, 443193326Sed CI_AllowsMemory = 0x01, 444193326Sed CI_AllowsRegister = 0x02, 445193326Sed CI_ReadWrite = 0x04, // "+r" output constraint (read and write). 446193326Sed CI_HasMatchingInput = 0x08 // This output operand has a matching input. 447193326Sed }; 448193326Sed unsigned Flags; 449193326Sed int TiedOperand; 450198092Srdivacky 451193326Sed std::string ConstraintStr; // constraint: "=rm" 452193326Sed std::string Name; // Operand name: [foo] with no []'s. 453193326Sed public: 454226633Sdim ConstraintInfo(StringRef ConstraintStr, StringRef Name) 455218893Sdim : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()), 456203955Srdivacky Name(Name.str()) {} 457193326Sed 458193326Sed const std::string &getConstraintStr() const { return ConstraintStr; } 459193326Sed const std::string &getName() const { return Name; } 460193326Sed bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; } 461193326Sed bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; } 462193326Sed bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; } 463198092Srdivacky 464239462Sdim /// \brief Return true if this output operand has a matching 465193326Sed /// (tied) input operand. 466193326Sed bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; } 467198092Srdivacky 468239462Sdim /// \brief Return true if this input operand is a matching 469239462Sdim /// constraint that ties it to an output operand. 470239462Sdim /// 471239462Sdim /// If this returns true then getTiedOperand will indicate which output 472239462Sdim /// operand this is tied to. 473193326Sed bool hasTiedOperand() const { return TiedOperand != -1; } 474193326Sed unsigned getTiedOperand() const { 475193326Sed assert(hasTiedOperand() && "Has no tied operand!"); 476193326Sed return (unsigned)TiedOperand; 477193326Sed } 478198092Srdivacky 479193326Sed void setIsReadWrite() { Flags |= CI_ReadWrite; } 480193326Sed void setAllowsMemory() { Flags |= CI_AllowsMemory; } 481193326Sed void setAllowsRegister() { Flags |= CI_AllowsRegister; } 482193326Sed void setHasMatchingInput() { Flags |= CI_HasMatchingInput; } 483198092Srdivacky 484239462Sdim /// \brief Indicate that this is an input operand that is tied to 485239462Sdim /// the specified output operand. 486239462Sdim /// 487239462Sdim /// Copy over the various constraint information from the output. 488193326Sed void setTiedOperand(unsigned N, ConstraintInfo &Output) { 489193326Sed Output.setHasMatchingInput(); 490193326Sed Flags = Output.Flags; 491193326Sed TiedOperand = N; 492193326Sed // Don't copy Name or constraint string. 493193326Sed } 494193326Sed }; 495193326Sed 496193326Sed // validateOutputConstraint, validateInputConstraint - Checks that 497193326Sed // a constraint is valid and provides information about it. 498193326Sed // FIXME: These should return a real error instead of just true/false. 499193326Sed bool validateOutputConstraint(ConstraintInfo &Info) const; 500193326Sed bool validateInputConstraint(ConstraintInfo *OutputConstraints, 501193326Sed unsigned NumOutputs, 502193326Sed ConstraintInfo &info) const; 503193326Sed bool resolveSymbolicName(const char *&Name, 504193326Sed ConstraintInfo *OutputConstraints, 505193326Sed unsigned NumOutputs, unsigned &Index) const; 506198092Srdivacky 507223017Sdim // Constraint parm will be left pointing at the last character of 508223017Sdim // the constraint. In practice, it won't be changed unless the 509223017Sdim // constraint is longer than one character. 510223017Sdim virtual std::string convertConstraint(const char *&Constraint) const { 511218893Sdim // 'p' defaults to 'r', but can be overridden by targets. 512223017Sdim if (*Constraint == 'p') 513218893Sdim return std::string("r"); 514223017Sdim return std::string(1, *Constraint); 515193326Sed } 516198092Srdivacky 517239462Sdim /// \brief Returns a string of target-specific clobbers, in LLVM format. 518193326Sed virtual const char *getClobbers() const = 0; 519193326Sed 520198092Srdivacky 521239462Sdim /// \brief Returns the target triple of the primary target. 522198092Srdivacky const llvm::Triple &getTriple() const { 523198092Srdivacky return Triple; 524193326Sed } 525198092Srdivacky 526193326Sed const char *getTargetDescription() const { 527193326Sed return DescriptionString; 528193326Sed } 529193326Sed 530193326Sed struct GCCRegAlias { 531193326Sed const char * const Aliases[5]; 532193326Sed const char * const Register; 533193326Sed }; 534193326Sed 535224145Sdim struct AddlRegName { 536224145Sdim const char * const Names[5]; 537224145Sdim const unsigned RegNum; 538224145Sdim }; 539224145Sdim 540239462Sdim /// \brief Does this target support "protected" visibility? 541234353Sdim /// 542234353Sdim /// Any target which dynamic libraries will naturally support 543234353Sdim /// something like "default" (meaning that the symbol is visible 544234353Sdim /// outside this shared object) and "hidden" (meaning that it isn't) 545234353Sdim /// visibilities, but "protected" is really an ELF-specific concept 546239462Sdim /// with weird semantics designed around the convenience of dynamic 547234353Sdim /// linker implementations. Which is not to suggest that there's 548234353Sdim /// consistent target-independent semantics for "default" visibility 549234353Sdim /// either; the entire thing is pretty badly mangled. 550234353Sdim virtual bool hasProtectedVisibility() const { return true; } 551234353Sdim 552193326Sed virtual bool useGlobalsForAutomaticVariables() const { return false; } 553193326Sed 554239462Sdim /// \brief Return the section to use for CFString literals, or 0 if no 555239462Sdim /// special section is used. 556198092Srdivacky virtual const char *getCFStringSection() const { 557193326Sed return "__DATA,__cfstring"; 558193326Sed } 559193326Sed 560239462Sdim /// \brief Return the section to use for NSString literals, or 0 if no 561239462Sdim /// special section is used. 562207619Srdivacky virtual const char *getNSStringSection() const { 563207619Srdivacky return "__OBJC,__cstring_object,regular,no_dead_strip"; 564207619Srdivacky } 565207619Srdivacky 566239462Sdim /// \brief Return the section to use for NSString literals, or 0 if no 567239462Sdim /// special section is used (NonFragile ABI). 568207619Srdivacky virtual const char *getNSStringNonFragileABISection() const { 569207619Srdivacky return "__DATA, __objc_stringobj, regular, no_dead_strip"; 570207619Srdivacky } 571207619Srdivacky 572239462Sdim /// \brief An optional hook that targets can implement to perform semantic 573239462Sdim /// checking on attribute((section("foo"))) specifiers. 574239462Sdim /// 575239462Sdim /// In this case, "foo" is passed in to be checked. If the section 576239462Sdim /// specifier is invalid, the backend should return a non-empty string 577198092Srdivacky /// that indicates the problem. 578198092Srdivacky /// 579198092Srdivacky /// This hook is a simple quality of implementation feature to catch errors 580198092Srdivacky /// and give good diagnostics in cases when the assembler or code generator 581198092Srdivacky /// would otherwise reject the section specifier. 582198092Srdivacky /// 583226633Sdim virtual std::string isValidSectionSpecifier(StringRef SR) const { 584198092Srdivacky return ""; 585193326Sed } 586193326Sed 587239462Sdim /// \brief Set forced language options. 588239462Sdim /// 589199482Srdivacky /// Apply changes to the target information with respect to certain 590199482Srdivacky /// language options which change the target configuration. 591199482Srdivacky virtual void setForcedLangOptions(LangOptions &Opts); 592193326Sed 593239462Sdim /// \brief Get the default set of target features for the CPU; 594226633Sdim /// this should include all legal feature strings on the target. 595226633Sdim virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const { 596193326Sed } 597193326Sed 598239462Sdim /// \brief Get the ABI currently in use. 599198092Srdivacky virtual const char *getABI() const { 600198092Srdivacky return ""; 601198092Srdivacky } 602198092Srdivacky 603239462Sdim /// \brief Get the C++ ABI currently in use. 604212904Sdim virtual TargetCXXABI getCXXABI() const { 605210299Sed return CXXABI; 606210299Sed } 607210299Sed 608239462Sdim /// \brief Target the specified CPU. 609201361Srdivacky /// 610239462Sdim /// \return False on error (invalid CPU name). 611201361Srdivacky virtual bool setCPU(const std::string &Name) { 612226633Sdim return false; 613201361Srdivacky } 614201361Srdivacky 615239462Sdim /// \brief Use the specified ABI. 616198092Srdivacky /// 617239462Sdim /// \return False on error (invalid ABI name). 618198092Srdivacky virtual bool setABI(const std::string &Name) { 619198092Srdivacky return false; 620198092Srdivacky } 621198092Srdivacky 622239462Sdim /// \brief Use this specified C++ ABI. 623210299Sed /// 624239462Sdim /// \return False on error (invalid C++ ABI name). 625212904Sdim bool setCXXABI(const std::string &Name) { 626212904Sdim static const TargetCXXABI Unknown = static_cast<TargetCXXABI>(-1); 627212904Sdim TargetCXXABI ABI = llvm::StringSwitch<TargetCXXABI>(Name) 628212904Sdim .Case("arm", CXXABI_ARM) 629212904Sdim .Case("itanium", CXXABI_Itanium) 630212904Sdim .Case("microsoft", CXXABI_Microsoft) 631212904Sdim .Default(Unknown); 632212904Sdim if (ABI == Unknown) return false; 633212904Sdim return setCXXABI(ABI); 634212904Sdim } 635212904Sdim 636239462Sdim /// \brief Set the C++ ABI to be used by this implementation. 637212904Sdim /// 638239462Sdim /// \return False on error (ABI not valid on this target) 639212904Sdim virtual bool setCXXABI(TargetCXXABI ABI) { 640212904Sdim CXXABI = ABI; 641210299Sed return true; 642210299Sed } 643210299Sed 644239462Sdim /// \brief Enable or disable a specific target feature; 645193326Sed /// the feature name must be valid. 646193326Sed /// 647239462Sdim /// \return False on error (invalid feature name). 648193326Sed virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 649234353Sdim StringRef Name, 650193326Sed bool Enabled) const { 651193326Sed return false; 652193326Sed } 653193326Sed 654239462Sdim /// \brief Perform initialization based on the user configured 655239462Sdim /// set of features (e.g., +sse4). 656201361Srdivacky /// 657239462Sdim /// The list is guaranteed to have at most one entry per feature. 658239462Sdim /// 659201361Srdivacky /// The target may modify the features list, to change which options are 660201361Srdivacky /// passed onwards to the backend. 661201361Srdivacky virtual void HandleTargetFeatures(std::vector<std::string> &Features) { 662193326Sed } 663193326Sed 664234353Sdim /// \brief Determine whether the given target has the given feature. 665234353Sdim virtual bool hasFeature(StringRef Feature) const { 666234353Sdim return false; 667234353Sdim } 668234353Sdim 669239462Sdim // \brief Returns maximal number of args passed in registers. 670193326Sed unsigned getRegParmMax() const { 671224145Sdim assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle"); 672193326Sed return RegParmMax; 673193326Sed } 674193326Sed 675239462Sdim /// \brief Whether the target supports thread-local storage. 676198092Srdivacky bool isTLSSupported() const { 677193326Sed return TLSSupported; 678193326Sed } 679218893Sdim 680239462Sdim /// \brief Return true if {|} are normal characters in the asm string. 681239462Sdim /// 682239462Sdim /// If this returns false (the default), then {abc|xyz} is syntax 683207619Srdivacky /// that says that when compiling for asm variant #0, "abc" should be 684207619Srdivacky /// generated, but when compiling for asm variant #1, "xyz" should be 685207619Srdivacky /// generated. 686207619Srdivacky bool hasNoAsmVariants() const { 687207619Srdivacky return NoAsmVariants; 688207619Srdivacky } 689218893Sdim 690239462Sdim /// \brief Return the register number that __builtin_eh_return_regno would 691239462Sdim /// return with the specified argument. 692198092Srdivacky virtual int getEHDataRegisterNumber(unsigned RegNo) const { 693218893Sdim return -1; 694198092Srdivacky } 695218893Sdim 696239462Sdim /// \brief Return the section to use for C++ static initialization functions. 697210299Sed virtual const char *getStaticInitSectionSpecifier() const { 698210299Sed return 0; 699210299Sed } 700221345Sdim 701221345Sdim const LangAS::Map &getAddressSpaceMap() const { 702221345Sdim return *AddrSpaceMap; 703221345Sdim } 704221345Sdim 705221345Sdim /// \brief Retrieve the name of the platform as it is used in the 706221345Sdim /// availability attribute. 707226633Sdim StringRef getPlatformName() const { return PlatformName; } 708221345Sdim 709221345Sdim /// \brief Retrieve the minimum desired version of the platform, to 710221345Sdim /// which the program should be compiled. 711221345Sdim VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; } 712221345Sdim 713234353Sdim bool isBigEndian() const { return BigEndian; } 714234353Sdim 715193326Sedprotected: 716193326Sed virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { 717193326Sed return PointerWidth; 718193326Sed } 719193326Sed virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { 720193326Sed return PointerAlign; 721193326Sed } 722193326Sed virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { 723193326Sed return PtrDiffType; 724193326Sed } 725198092Srdivacky virtual void getGCCRegNames(const char * const *&Names, 726193326Sed unsigned &NumNames) const = 0; 727198092Srdivacky virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 728193326Sed unsigned &NumAliases) const = 0; 729224145Sdim virtual void getGCCAddlRegNames(const AddlRegName *&Addl, 730224145Sdim unsigned &NumAddl) const { 731224145Sdim Addl = 0; 732224145Sdim NumAddl = 0; 733224145Sdim } 734198092Srdivacky virtual bool validateAsmConstraint(const char *&Name, 735193326Sed TargetInfo::ConstraintInfo &info) const= 0; 736193326Sed}; 737193326Sed 738193326Sed} // end namespace clang 739193326Sed 740193326Sed#endif 741