TargetInfo.h revision 234353
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//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the TargetInfo interface. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_BASIC_TARGETINFO_H 15193326Sed#define LLVM_CLANG_BASIC_TARGETINFO_H 16193326Sed 17226633Sdim#include "clang/Basic/LLVM.h" 18221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 19193326Sed#include "llvm/ADT/StringMap.h" 20221345Sdim#include "llvm/ADT/StringRef.h" 21212904Sdim#include "llvm/ADT/StringSwitch.h" 22198092Srdivacky#include "llvm/ADT/Triple.h" 23218893Sdim#include "llvm/Support/DataTypes.h" 24221345Sdim#include "clang/Basic/AddressSpaces.h" 25221345Sdim#include "clang/Basic/VersionTuple.h" 26193326Sed#include <cassert> 27193326Sed#include <vector> 28193326Sed#include <string> 29193326Sed 30198092Srdivackynamespace llvm { 31198092Srdivackystruct fltSemantics; 32198092Srdivacky} 33193326Sed 34193326Sednamespace clang { 35226633Sdimclass DiagnosticsEngine; 36199482Srdivackyclass LangOptions; 37202379Srdivackyclass MacroBuilder; 38198092Srdivackyclass SourceLocation; 39193326Sedclass SourceManager; 40199482Srdivackyclass TargetOptions; 41199482Srdivacky 42193326Sednamespace Builtin { struct Info; } 43198092Srdivacky 44212904Sdim/// TargetCXXABI - The types of C++ ABIs for which we can generate code. 45212904Sdimenum TargetCXXABI { 46212904Sdim /// The generic ("Itanium") C++ ABI, documented at: 47212904Sdim /// http://www.codesourcery.com/public/cxx-abi/ 48212904Sdim CXXABI_Itanium, 49212904Sdim 50212904Sdim /// The ARM C++ ABI, based largely on the Itanium ABI but with 51212904Sdim /// significant differences. 52212904Sdim /// http://infocenter.arm.com 53212904Sdim /// /help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf 54212904Sdim CXXABI_ARM, 55212904Sdim 56212904Sdim /// The Visual Studio ABI. Only scattered official documentation exists. 57212904Sdim CXXABI_Microsoft 58212904Sdim}; 59212904Sdim 60193326Sed/// TargetInfo - This class exposes information about the current target. 61193326Sed/// 62234353Sdimclass TargetInfo : public RefCountedBase<TargetInfo> { 63198092Srdivacky llvm::Triple Triple; 64193326Sedprotected: 65193326Sed // Target values set by the ctor of the actual target implementation. Default 66193326Sed // values are specified by the TargetInfo constructor. 67234353Sdim bool BigEndian; 68193326Sed bool TLSSupported; 69207619Srdivacky bool NoAsmVariants; // True if {|} are normal characters. 70193326Sed unsigned char PointerWidth, PointerAlign; 71218893Sdim unsigned char BoolWidth, BoolAlign; 72193326Sed unsigned char IntWidth, IntAlign; 73226633Sdim unsigned char HalfWidth, HalfAlign; 74193326Sed unsigned char FloatWidth, FloatAlign; 75193326Sed unsigned char DoubleWidth, DoubleAlign; 76193326Sed unsigned char LongDoubleWidth, LongDoubleAlign; 77210299Sed unsigned char LargeArrayMinWidth, LargeArrayAlign; 78193326Sed unsigned char LongWidth, LongAlign; 79193326Sed unsigned char LongLongWidth, LongLongAlign; 80234353Sdim unsigned char SuitableAlign; 81226633Sdim unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; 82193326Sed const char *DescriptionString; 83193326Sed const char *UserLabelPrefix; 84218893Sdim const char *MCountName; 85226633Sdim const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat, 86226633Sdim *LongDoubleFormat; 87193326Sed unsigned char RegParmMax, SSERegParmMax; 88212904Sdim TargetCXXABI CXXABI; 89221345Sdim const LangAS::Map *AddrSpaceMap; 90193326Sed 91226633Sdim mutable StringRef PlatformName; 92221345Sdim mutable VersionTuple PlatformMinVersion; 93221345Sdim 94208600Srdivacky unsigned HasAlignMac68kSupport : 1; 95210299Sed unsigned RealTypeUsesObjCFPRet : 3; 96234353Sdim unsigned ComplexLongDoubleUsesFP2Ret : 1; 97208600Srdivacky 98193326Sed // TargetInfo Constructor. Default initializes all fields. 99193326Sed TargetInfo(const std::string &T); 100198092Srdivacky 101198092Srdivackypublic: 102199482Srdivacky /// CreateTargetInfo - Construct a target for the given options. 103201361Srdivacky /// 104201361Srdivacky /// \param Opts - The options to use to initialize the target. The target may 105201361Srdivacky /// modify the options to canonicalize the target feature information to match 106201361Srdivacky /// what the backend expects. 107226633Sdim static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags, 108226633Sdim TargetOptions &Opts); 109193326Sed 110193326Sed virtual ~TargetInfo(); 111193326Sed 112193326Sed ///===---- Target Data Type Query Methods -------------------------------===// 113193326Sed enum IntType { 114193326Sed NoInt = 0, 115193326Sed SignedShort, 116193326Sed UnsignedShort, 117193326Sed SignedInt, 118193326Sed UnsignedInt, 119193326Sed SignedLong, 120193326Sed UnsignedLong, 121193326Sed SignedLongLong, 122193326Sed UnsignedLongLong 123193326Sed }; 124210299Sed 125210299Sed enum RealType { 126210299Sed Float = 0, 127210299Sed Double, 128210299Sed LongDouble 129210299Sed }; 130210299Sed 131193326Sedprotected: 132195341Sed IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType, 133199990Srdivacky WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType; 134207619Srdivacky 135207619Srdivacky /// Control whether the alignment of bit-field types is respected when laying 136207619Srdivacky /// out structures. If true, then the alignment of the bit-field type will be 137207619Srdivacky /// used to (a) impact the alignment of the containing structure, and (b) 138207619Srdivacky /// ensure that the individual bit-field will not straddle an alignment 139207619Srdivacky /// boundary. 140207619Srdivacky unsigned UseBitFieldTypeAlignment : 1; 141207619Srdivacky 142226633Sdim /// Control whether zero length bitfields (e.g., int : 0;) force alignment of 143226633Sdim /// the next bitfield. If the alignment of the zero length bitfield is 144226633Sdim /// greater than the member that follows it, `bar', `bar' will be aligned as 145226633Sdim /// the type of the zero-length bitfield. 146226633Sdim unsigned UseZeroLengthBitfieldAlignment : 1; 147226633Sdim 148226633Sdim /// If non-zero, specifies a fixed alignment value for bitfields that follow 149226633Sdim /// zero length bitfield, regardless of the zero length bitfield type. 150226633Sdim unsigned ZeroLengthBitfieldBoundary; 151226633Sdim 152193326Sedpublic: 153193326Sed IntType getSizeType() const { return SizeType; } 154193326Sed IntType getIntMaxType() const { return IntMaxType; } 155193326Sed IntType getUIntMaxType() const { return UIntMaxType; } 156193326Sed IntType getPtrDiffType(unsigned AddrSpace) const { 157193326Sed return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); 158193326Sed } 159193326Sed IntType getIntPtrType() const { return IntPtrType; } 160193326Sed IntType getWCharType() const { return WCharType; } 161198398Srdivacky IntType getWIntType() const { return WIntType; } 162198092Srdivacky IntType getChar16Type() const { return Char16Type; } 163198092Srdivacky IntType getChar32Type() const { return Char32Type; } 164195341Sed IntType getInt64Type() const { return Int64Type; } 165199990Srdivacky IntType getSigAtomicType() const { return SigAtomicType; } 166193326Sed 167198398Srdivacky 168218893Sdim /// getTypeWidth - Return the width (in bits) of the specified integer type 169198398Srdivacky /// enum. For example, SignedInt -> getIntWidth(). 170198398Srdivacky unsigned getTypeWidth(IntType T) const; 171198398Srdivacky 172199482Srdivacky /// getTypeAlign - Return the alignment (in bits) of the specified integer 173199482Srdivacky /// type enum. For example, SignedInt -> getIntAlign(). 174199482Srdivacky unsigned getTypeAlign(IntType T) const; 175199482Srdivacky 176198893Srdivacky /// isTypeSigned - Return whether an integer types is signed. Returns true if 177198398Srdivacky /// the type is signed; false otherwise. 178218893Sdim static bool isTypeSigned(IntType T); 179198398Srdivacky 180193326Sed /// getPointerWidth - Return the width of pointers on this target, for the 181193326Sed /// specified address space. 182193326Sed uint64_t getPointerWidth(unsigned AddrSpace) const { 183193326Sed return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); 184193326Sed } 185193326Sed uint64_t getPointerAlign(unsigned AddrSpace) const { 186193326Sed return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); 187193326Sed } 188198092Srdivacky 189193326Sed /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this 190193326Sed /// target, in bits. 191218893Sdim unsigned getBoolWidth() const { return BoolWidth; } 192218893Sdim unsigned getBoolAlign() const { return BoolAlign; } 193198092Srdivacky 194198092Srdivacky unsigned getCharWidth() const { return 8; } // FIXME 195198092Srdivacky unsigned getCharAlign() const { return 8; } // FIXME 196198092Srdivacky 197193326Sed /// getShortWidth/Align - Return the size of 'signed short' and 198198092Srdivacky /// 'unsigned short' for this target, in bits. 199193326Sed unsigned getShortWidth() const { return 16; } // FIXME 200193326Sed unsigned getShortAlign() const { return 16; } // FIXME 201198092Srdivacky 202193326Sed /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for 203193326Sed /// this target, in bits. 204193326Sed unsigned getIntWidth() const { return IntWidth; } 205193326Sed unsigned getIntAlign() const { return IntAlign; } 206198092Srdivacky 207193326Sed /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' 208193326Sed /// for this target, in bits. 209193326Sed unsigned getLongWidth() const { return LongWidth; } 210193326Sed unsigned getLongAlign() const { return LongAlign; } 211198092Srdivacky 212193326Sed /// getLongLongWidth/Align - Return the size of 'signed long long' and 213193326Sed /// 'unsigned long long' for this target, in bits. 214193326Sed unsigned getLongLongWidth() const { return LongLongWidth; } 215193326Sed unsigned getLongLongAlign() const { return LongLongAlign; } 216198092Srdivacky 217234353Sdim /// getSuitableAlign - Return the alignment that is suitable for storing any 218234353Sdim /// object with a fundamental alignment requirement. 219234353Sdim unsigned getSuitableAlign() const { return SuitableAlign; } 220234353Sdim 221198092Srdivacky /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in 222193326Sed /// bits. 223199482Srdivacky unsigned getWCharWidth() const { return getTypeWidth(WCharType); } 224199482Srdivacky unsigned getWCharAlign() const { return getTypeAlign(WCharType); } 225193326Sed 226198092Srdivacky /// getChar16Width/Align - Return the size of 'char16_t' for this target, in 227198092Srdivacky /// bits. 228199482Srdivacky unsigned getChar16Width() const { return getTypeWidth(Char16Type); } 229199482Srdivacky unsigned getChar16Align() const { return getTypeAlign(Char16Type); } 230198092Srdivacky 231198092Srdivacky /// getChar32Width/Align - Return the size of 'char32_t' for this target, in 232198092Srdivacky /// bits. 233199482Srdivacky unsigned getChar32Width() const { return getTypeWidth(Char32Type); } 234199482Srdivacky unsigned getChar32Align() const { return getTypeAlign(Char32Type); } 235198092Srdivacky 236226633Sdim /// getHalfWidth/Align/Format - Return the size/align/format of 'half'. 237226633Sdim unsigned getHalfWidth() const { return HalfWidth; } 238226633Sdim unsigned getHalfAlign() const { return HalfAlign; } 239226633Sdim const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; } 240226633Sdim 241193326Sed /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. 242193326Sed unsigned getFloatWidth() const { return FloatWidth; } 243193326Sed unsigned getFloatAlign() const { return FloatAlign; } 244193326Sed const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } 245193326Sed 246193326Sed /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. 247193326Sed unsigned getDoubleWidth() const { return DoubleWidth; } 248193326Sed unsigned getDoubleAlign() const { return DoubleAlign; } 249193326Sed const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } 250193326Sed 251193326Sed /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long 252193326Sed /// double'. 253193326Sed unsigned getLongDoubleWidth() const { return LongDoubleWidth; } 254193326Sed unsigned getLongDoubleAlign() const { return LongDoubleAlign; } 255193326Sed const llvm::fltSemantics &getLongDoubleFormat() const { 256193326Sed return *LongDoubleFormat; 257193326Sed } 258198092Srdivacky 259234353Sdim /// getFloatEvalMethod - Return the value for the C99 FLT_EVAL_METHOD macro. 260234353Sdim virtual unsigned getFloatEvalMethod() const { return 0; } 261234353Sdim 262210299Sed // getLargeArrayMinWidth/Align - Return the minimum array size that is 263210299Sed // 'large' and its alignment. 264210299Sed unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; } 265210299Sed unsigned getLargeArrayAlign() const { return LargeArrayAlign; } 266210299Sed 267226633Sdim /// getMaxAtomicPromoteWidth - Return the maximum width lock-free atomic 268226633Sdim /// operation which will ever be supported for the given target 269226633Sdim unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; } 270226633Sdim /// getMaxAtomicInlineWidth - Return the maximum width lock-free atomic 271226633Sdim /// operation which can be inlined given the supported features of the 272226633Sdim /// given target. 273226633Sdim unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; } 274226633Sdim 275193326Sed /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this 276198092Srdivacky /// target, in bits. 277193326Sed unsigned getIntMaxTWidth() const { 278199482Srdivacky return getTypeWidth(IntMaxType); 279193326Sed } 280198092Srdivacky 281224145Sdim /// getRegisterWidth - Return the "preferred" register width on this target. 282224145Sdim uint64_t getRegisterWidth() const { 283224145Sdim // Currently we assume the register width on the target matches the pointer 284224145Sdim // width, we can introduce a new variable for this if/when some target wants 285224145Sdim // it. 286224145Sdim return LongWidth; 287224145Sdim } 288224145Sdim 289193326Sed /// getUserLabelPrefix - This returns the default value of the 290193326Sed /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by 291193326Sed /// default. On most platforms this is "_", but it is "" on some, and "." on 292193326Sed /// others. 293193326Sed const char *getUserLabelPrefix() const { 294193326Sed return UserLabelPrefix; 295193326Sed } 296198092Srdivacky 297218893Sdim /// MCountName - This returns name of the mcount instrumentation function. 298218893Sdim const char *getMCountName() const { 299218893Sdim return MCountName; 300218893Sdim } 301218893Sdim 302226633Sdim /// useBitFieldTypeAlignment() - Check whether the alignment of bit-field 303226633Sdim /// types is respected when laying out structures. 304207619Srdivacky bool useBitFieldTypeAlignment() const { 305207619Srdivacky return UseBitFieldTypeAlignment; 306207619Srdivacky } 307207619Srdivacky 308226633Sdim /// useZeroLengthBitfieldAlignment() - Check whether zero length bitfields 309226633Sdim /// should force alignment of the next member. 310226633Sdim bool useZeroLengthBitfieldAlignment() const { 311226633Sdim return UseZeroLengthBitfieldAlignment; 312226633Sdim } 313226633Sdim 314226633Sdim /// getZeroLengthBitfieldBoundary() - Get the fixed alignment value in bits 315226633Sdim /// for a member that follows a zero length bitfield. 316226633Sdim unsigned getZeroLengthBitfieldBoundary() const { 317226633Sdim return ZeroLengthBitfieldBoundary; 318226633Sdim } 319226633Sdim 320208600Srdivacky /// hasAlignMac68kSupport - Check whether this target support '#pragma options 321208600Srdivacky /// align=mac68k'. 322208600Srdivacky bool hasAlignMac68kSupport() const { 323208600Srdivacky return HasAlignMac68kSupport; 324208600Srdivacky } 325208600Srdivacky 326193326Sed /// getTypeName - Return the user string for the specified integer type enum. 327193326Sed /// For example, SignedShort -> "short". 328193326Sed static const char *getTypeName(IntType T); 329198092Srdivacky 330198398Srdivacky /// getTypeConstantSuffix - Return the constant suffix for the specified 331198398Srdivacky /// integer type enum. For example, SignedLong -> "L". 332198398Srdivacky static const char *getTypeConstantSuffix(IntType T); 333198398Srdivacky 334210299Sed /// \brief Check whether the given real type should use the "fpret" flavor of 335210299Sed /// Obj-C message passing on this target. 336210299Sed bool useObjCFPRetForRealType(RealType T) const { 337210299Sed return RealTypeUsesObjCFPRet & (1 << T); 338210299Sed } 339210299Sed 340234353Sdim /// \brief Check whether _Complex long double should use the "fp2ret" flavor 341234353Sdim /// of Obj-C message passing on this target. 342234353Sdim bool useObjCFP2RetForComplexLongDouble() const { 343234353Sdim return ComplexLongDoubleUsesFP2Ret; 344234353Sdim } 345234353Sdim 346193326Sed ///===---- Other target property query methods --------------------------===// 347198092Srdivacky 348193326Sed /// getTargetDefines - Appends the target-specific #define values for this 349193326Sed /// target set to the specified buffer. 350193326Sed virtual void getTargetDefines(const LangOptions &Opts, 351202379Srdivacky MacroBuilder &Builder) const = 0; 352198092Srdivacky 353198398Srdivacky 354193326Sed /// getTargetBuiltins - Return information about target-specific builtins for 355193326Sed /// the current primary target, and info about which builtins are non-portable 356193326Sed /// across the current set of primary and secondary targets. 357198092Srdivacky virtual void getTargetBuiltins(const Builtin::Info *&Records, 358193326Sed unsigned &NumRecords) const = 0; 359193326Sed 360234353Sdim /// isCLZForZeroUndef - The __builtin_clz* and __builtin_ctz* built-in 361234353Sdim /// functions are specified to have undefined results for zero inputs, but 362234353Sdim /// on targets that support these operations in a way that provides 363234353Sdim /// well-defined results for zero without loss of performance, it is a good 364234353Sdim /// idea to avoid optimizing based on that undef behavior. 365234353Sdim virtual bool isCLZForZeroUndef() const { return true; } 366234353Sdim 367193326Sed /// getVAListDeclaration - Return the declaration to use for 368193326Sed /// __builtin_va_list, which is target-specific. 369193326Sed virtual const char *getVAListDeclaration() const = 0; 370193326Sed 371224145Sdim /// isValidClobber - Returns whether the passed in string is 372224145Sdim /// a valid clobber in an inline asm statement. This is used by 373224145Sdim /// Sema. 374226633Sdim bool isValidClobber(StringRef Name) const; 375224145Sdim 376193326Sed /// isValidGCCRegisterName - Returns whether the passed in string 377193326Sed /// is a valid register name according to GCC. This is used by Sema for 378193326Sed /// inline asm statements. 379226633Sdim bool isValidGCCRegisterName(StringRef Name) const; 380193326Sed 381193326Sed // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name. 382193326Sed // For example, on x86 it will return "ax" when "eax" is passed in. 383226633Sdim StringRef getNormalizedGCCRegisterName(StringRef Name) const; 384198092Srdivacky 385193326Sed struct ConstraintInfo { 386193326Sed enum { 387193326Sed CI_None = 0x00, 388193326Sed CI_AllowsMemory = 0x01, 389193326Sed CI_AllowsRegister = 0x02, 390193326Sed CI_ReadWrite = 0x04, // "+r" output constraint (read and write). 391193326Sed CI_HasMatchingInput = 0x08 // This output operand has a matching input. 392193326Sed }; 393193326Sed unsigned Flags; 394193326Sed int TiedOperand; 395198092Srdivacky 396193326Sed std::string ConstraintStr; // constraint: "=rm" 397193326Sed std::string Name; // Operand name: [foo] with no []'s. 398193326Sed public: 399226633Sdim ConstraintInfo(StringRef ConstraintStr, StringRef Name) 400218893Sdim : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()), 401203955Srdivacky Name(Name.str()) {} 402193326Sed 403193326Sed const std::string &getConstraintStr() const { return ConstraintStr; } 404193326Sed const std::string &getName() const { return Name; } 405193326Sed bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; } 406193326Sed bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; } 407193326Sed bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; } 408198092Srdivacky 409193326Sed /// hasMatchingInput - Return true if this output operand has a matching 410193326Sed /// (tied) input operand. 411193326Sed bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; } 412198092Srdivacky 413193326Sed /// hasTiedOperand() - Return true if this input operand is a matching 414193326Sed /// constraint that ties it to an output operand. If this returns true, 415193326Sed /// then getTiedOperand will indicate which output operand this is tied to. 416193326Sed bool hasTiedOperand() const { return TiedOperand != -1; } 417193326Sed unsigned getTiedOperand() const { 418193326Sed assert(hasTiedOperand() && "Has no tied operand!"); 419193326Sed return (unsigned)TiedOperand; 420193326Sed } 421198092Srdivacky 422193326Sed void setIsReadWrite() { Flags |= CI_ReadWrite; } 423193326Sed void setAllowsMemory() { Flags |= CI_AllowsMemory; } 424193326Sed void setAllowsRegister() { Flags |= CI_AllowsRegister; } 425193326Sed void setHasMatchingInput() { Flags |= CI_HasMatchingInput; } 426198092Srdivacky 427193326Sed /// setTiedOperand - Indicate that this is an input operand that is tied to 428193326Sed /// the specified output operand. Copy over the various constraint 429193326Sed /// information from the output. 430193326Sed void setTiedOperand(unsigned N, ConstraintInfo &Output) { 431193326Sed Output.setHasMatchingInput(); 432193326Sed Flags = Output.Flags; 433193326Sed TiedOperand = N; 434193326Sed // Don't copy Name or constraint string. 435193326Sed } 436193326Sed }; 437193326Sed 438193326Sed // validateOutputConstraint, validateInputConstraint - Checks that 439193326Sed // a constraint is valid and provides information about it. 440193326Sed // FIXME: These should return a real error instead of just true/false. 441193326Sed bool validateOutputConstraint(ConstraintInfo &Info) const; 442193326Sed bool validateInputConstraint(ConstraintInfo *OutputConstraints, 443193326Sed unsigned NumOutputs, 444193326Sed ConstraintInfo &info) const; 445193326Sed bool resolveSymbolicName(const char *&Name, 446193326Sed ConstraintInfo *OutputConstraints, 447193326Sed unsigned NumOutputs, unsigned &Index) const; 448198092Srdivacky 449223017Sdim // Constraint parm will be left pointing at the last character of 450223017Sdim // the constraint. In practice, it won't be changed unless the 451223017Sdim // constraint is longer than one character. 452223017Sdim virtual std::string convertConstraint(const char *&Constraint) const { 453218893Sdim // 'p' defaults to 'r', but can be overridden by targets. 454223017Sdim if (*Constraint == 'p') 455218893Sdim return std::string("r"); 456223017Sdim return std::string(1, *Constraint); 457193326Sed } 458198092Srdivacky 459193326Sed // Returns a string of target-specific clobbers, in LLVM format. 460193326Sed virtual const char *getClobbers() const = 0; 461193326Sed 462198092Srdivacky 463198092Srdivacky /// getTriple - Return the target triple of the primary target. 464198092Srdivacky const llvm::Triple &getTriple() const { 465198092Srdivacky return Triple; 466193326Sed } 467198092Srdivacky 468193326Sed const char *getTargetDescription() const { 469193326Sed return DescriptionString; 470193326Sed } 471193326Sed 472193326Sed struct GCCRegAlias { 473193326Sed const char * const Aliases[5]; 474193326Sed const char * const Register; 475193326Sed }; 476193326Sed 477224145Sdim struct AddlRegName { 478224145Sdim const char * const Names[5]; 479224145Sdim const unsigned RegNum; 480224145Sdim }; 481224145Sdim 482234353Sdim /// hasProtectedVisibility - Does this target support "protected" 483234353Sdim /// visibility? 484234353Sdim /// 485234353Sdim /// Any target which dynamic libraries will naturally support 486234353Sdim /// something like "default" (meaning that the symbol is visible 487234353Sdim /// outside this shared object) and "hidden" (meaning that it isn't) 488234353Sdim /// visibilities, but "protected" is really an ELF-specific concept 489234353Sdim /// with wierd semantics designed around the convenience of dynamic 490234353Sdim /// linker implementations. Which is not to suggest that there's 491234353Sdim /// consistent target-independent semantics for "default" visibility 492234353Sdim /// either; the entire thing is pretty badly mangled. 493234353Sdim virtual bool hasProtectedVisibility() const { return true; } 494234353Sdim 495193326Sed virtual bool useGlobalsForAutomaticVariables() const { return false; } 496193326Sed 497193326Sed /// getCFStringSection - Return the section to use for CFString 498193326Sed /// literals, or 0 if no special section is used. 499198092Srdivacky virtual const char *getCFStringSection() const { 500193326Sed return "__DATA,__cfstring"; 501193326Sed } 502193326Sed 503207619Srdivacky /// getNSStringSection - Return the section to use for NSString 504207619Srdivacky /// literals, or 0 if no special section is used. 505207619Srdivacky virtual const char *getNSStringSection() const { 506207619Srdivacky return "__OBJC,__cstring_object,regular,no_dead_strip"; 507207619Srdivacky } 508207619Srdivacky 509218893Sdim /// getNSStringNonFragileABISection - Return the section to use for 510207619Srdivacky /// NSString literals, or 0 if no special section is used (NonFragile ABI). 511207619Srdivacky virtual const char *getNSStringNonFragileABISection() const { 512207619Srdivacky return "__DATA, __objc_stringobj, regular, no_dead_strip"; 513207619Srdivacky } 514207619Srdivacky 515198092Srdivacky /// isValidSectionSpecifier - This is an optional hook that targets can 516198092Srdivacky /// implement to perform semantic checking on attribute((section("foo"))) 517198092Srdivacky /// specifiers. In this case, "foo" is passed in to be checked. If the 518198092Srdivacky /// section specifier is invalid, the backend should return a non-empty string 519198092Srdivacky /// that indicates the problem. 520198092Srdivacky /// 521198092Srdivacky /// This hook is a simple quality of implementation feature to catch errors 522198092Srdivacky /// and give good diagnostics in cases when the assembler or code generator 523198092Srdivacky /// would otherwise reject the section specifier. 524198092Srdivacky /// 525226633Sdim virtual std::string isValidSectionSpecifier(StringRef SR) const { 526198092Srdivacky return ""; 527193326Sed } 528193326Sed 529199482Srdivacky /// setForcedLangOptions - Set forced language options. 530199482Srdivacky /// Apply changes to the target information with respect to certain 531199482Srdivacky /// language options which change the target configuration. 532199482Srdivacky virtual void setForcedLangOptions(LangOptions &Opts); 533193326Sed 534226633Sdim /// getDefaultFeatures - Get the default set of target features for the CPU; 535226633Sdim /// this should include all legal feature strings on the target. 536226633Sdim virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const { 537193326Sed } 538193326Sed 539198092Srdivacky /// getABI - Get the ABI in use. 540198092Srdivacky virtual const char *getABI() const { 541198092Srdivacky return ""; 542198092Srdivacky } 543198092Srdivacky 544210299Sed /// getCXXABI - Get the C++ ABI in use. 545212904Sdim virtual TargetCXXABI getCXXABI() const { 546210299Sed return CXXABI; 547210299Sed } 548210299Sed 549201361Srdivacky /// setCPU - Target the specific CPU. 550201361Srdivacky /// 551201361Srdivacky /// \return - False on error (invalid CPU name). 552201361Srdivacky virtual bool setCPU(const std::string &Name) { 553226633Sdim return false; 554201361Srdivacky } 555201361Srdivacky 556198092Srdivacky /// setABI - Use the specific ABI. 557198092Srdivacky /// 558198092Srdivacky /// \return - False on error (invalid ABI name). 559198092Srdivacky virtual bool setABI(const std::string &Name) { 560198092Srdivacky return false; 561198092Srdivacky } 562198092Srdivacky 563210299Sed /// setCXXABI - Use this specific C++ ABI. 564210299Sed /// 565212904Sdim /// \return - False on error (invalid C++ ABI name). 566212904Sdim bool setCXXABI(const std::string &Name) { 567212904Sdim static const TargetCXXABI Unknown = static_cast<TargetCXXABI>(-1); 568212904Sdim TargetCXXABI ABI = llvm::StringSwitch<TargetCXXABI>(Name) 569212904Sdim .Case("arm", CXXABI_ARM) 570212904Sdim .Case("itanium", CXXABI_Itanium) 571212904Sdim .Case("microsoft", CXXABI_Microsoft) 572212904Sdim .Default(Unknown); 573212904Sdim if (ABI == Unknown) return false; 574212904Sdim return setCXXABI(ABI); 575212904Sdim } 576212904Sdim 577212904Sdim /// setCXXABI - Set the C++ ABI to be used by this implementation. 578212904Sdim /// 579212904Sdim /// \return - False on error (ABI not valid on this target) 580212904Sdim virtual bool setCXXABI(TargetCXXABI ABI) { 581212904Sdim CXXABI = ABI; 582210299Sed return true; 583210299Sed } 584210299Sed 585193326Sed /// setFeatureEnabled - Enable or disable a specific target feature, 586193326Sed /// the feature name must be valid. 587193326Sed /// 588193326Sed /// \return - False on error (invalid feature name). 589193326Sed virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features, 590234353Sdim StringRef Name, 591193326Sed bool Enabled) const { 592193326Sed return false; 593193326Sed } 594193326Sed 595199482Srdivacky /// HandleTargetOptions - Perform initialization based on the user configured 596199482Srdivacky /// set of features (e.g., +sse4). The list is guaranteed to have at most one 597199482Srdivacky /// entry per feature. 598201361Srdivacky /// 599201361Srdivacky /// The target may modify the features list, to change which options are 600201361Srdivacky /// passed onwards to the backend. 601201361Srdivacky virtual void HandleTargetFeatures(std::vector<std::string> &Features) { 602193326Sed } 603193326Sed 604234353Sdim /// \brief Determine whether the given target has the given feature. 605234353Sdim virtual bool hasFeature(StringRef Feature) const { 606234353Sdim return false; 607234353Sdim } 608234353Sdim 609193326Sed // getRegParmMax - Returns maximal number of args passed in registers. 610193326Sed unsigned getRegParmMax() const { 611224145Sdim assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle"); 612193326Sed return RegParmMax; 613193326Sed } 614193326Sed 615198092Srdivacky /// isTLSSupported - Whether the target supports thread-local storage. 616198092Srdivacky bool isTLSSupported() const { 617193326Sed return TLSSupported; 618193326Sed } 619218893Sdim 620207619Srdivacky /// hasNoAsmVariants - Return true if {|} are normal characters in the 621207619Srdivacky /// asm string. If this returns false (the default), then {abc|xyz} is syntax 622207619Srdivacky /// that says that when compiling for asm variant #0, "abc" should be 623207619Srdivacky /// generated, but when compiling for asm variant #1, "xyz" should be 624207619Srdivacky /// generated. 625207619Srdivacky bool hasNoAsmVariants() const { 626207619Srdivacky return NoAsmVariants; 627207619Srdivacky } 628218893Sdim 629198092Srdivacky /// getEHDataRegisterNumber - Return the register number that 630198092Srdivacky /// __builtin_eh_return_regno would return with the specified argument. 631198092Srdivacky virtual int getEHDataRegisterNumber(unsigned RegNo) const { 632218893Sdim return -1; 633198092Srdivacky } 634218893Sdim 635218893Sdim /// getStaticInitSectionSpecifier - Return the section to use for C++ static 636210299Sed /// initialization functions. 637210299Sed virtual const char *getStaticInitSectionSpecifier() const { 638210299Sed return 0; 639210299Sed } 640221345Sdim 641221345Sdim const LangAS::Map &getAddressSpaceMap() const { 642221345Sdim return *AddrSpaceMap; 643221345Sdim } 644221345Sdim 645221345Sdim /// \brief Retrieve the name of the platform as it is used in the 646221345Sdim /// availability attribute. 647226633Sdim StringRef getPlatformName() const { return PlatformName; } 648221345Sdim 649221345Sdim /// \brief Retrieve the minimum desired version of the platform, to 650221345Sdim /// which the program should be compiled. 651221345Sdim VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; } 652221345Sdim 653234353Sdim bool isBigEndian() const { return BigEndian; } 654234353Sdim 655193326Sedprotected: 656193326Sed virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { 657193326Sed return PointerWidth; 658193326Sed } 659193326Sed virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { 660193326Sed return PointerAlign; 661193326Sed } 662193326Sed virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { 663193326Sed return PtrDiffType; 664193326Sed } 665198092Srdivacky virtual void getGCCRegNames(const char * const *&Names, 666193326Sed unsigned &NumNames) const = 0; 667198092Srdivacky virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 668193326Sed unsigned &NumAliases) const = 0; 669224145Sdim virtual void getGCCAddlRegNames(const AddlRegName *&Addl, 670224145Sdim unsigned &NumAddl) const { 671224145Sdim Addl = 0; 672224145Sdim NumAddl = 0; 673224145Sdim } 674198092Srdivacky virtual bool validateAsmConstraint(const char *&Name, 675193326Sed TargetInfo::ConstraintInfo &info) const= 0; 676193326Sed}; 677193326Sed 678193326Sed} // end namespace clang 679193326Sed 680193326Sed#endif 681