clang API Documentation

include/clang/Basic/TargetInfo.h
Go to the documentation of this file.
00001 //===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Defines the clang::TargetInfo interface.
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
00016 #define LLVM_CLANG_BASIC_TARGETINFO_H
00017 
00018 #include "clang/Basic/AddressSpaces.h"
00019 #include "clang/Basic/LLVM.h"
00020 #include "clang/Basic/Specifiers.h"
00021 #include "clang/Basic/TargetCXXABI.h"
00022 #include "clang/Basic/TargetOptions.h"
00023 #include "clang/Basic/VersionTuple.h"
00024 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00025 #include "llvm/ADT/StringMap.h"
00026 #include "llvm/ADT/StringRef.h"
00027 #include "llvm/ADT/StringSwitch.h"
00028 #include "llvm/ADT/Triple.h"
00029 #include "llvm/Support/DataTypes.h"
00030 #include <cassert>
00031 #include <string>
00032 #include <vector>
00033 
00034 namespace llvm {
00035 struct fltSemantics;
00036 }
00037 
00038 namespace clang {
00039 class DiagnosticsEngine;
00040 class LangOptions;
00041 class MacroBuilder;
00042 class SourceLocation;
00043 class SourceManager;
00044 
00045 namespace Builtin { struct Info; }
00046 
00047 /// \brief Exposes information about the current target.
00048 ///
00049 class TargetInfo : public RefCountedBase<TargetInfo> {
00050   std::shared_ptr<TargetOptions> TargetOpts;
00051   llvm::Triple Triple;
00052 protected:
00053   // Target values set by the ctor of the actual target implementation.  Default
00054   // values are specified by the TargetInfo constructor.
00055   bool BigEndian;
00056   bool TLSSupported;
00057   bool NoAsmVariants;  // True if {|} are normal characters.
00058   unsigned char PointerWidth, PointerAlign;
00059   unsigned char BoolWidth, BoolAlign;
00060   unsigned char IntWidth, IntAlign;
00061   unsigned char HalfWidth, HalfAlign;
00062   unsigned char FloatWidth, FloatAlign;
00063   unsigned char DoubleWidth, DoubleAlign;
00064   unsigned char LongDoubleWidth, LongDoubleAlign;
00065   unsigned char LargeArrayMinWidth, LargeArrayAlign;
00066   unsigned char LongWidth, LongAlign;
00067   unsigned char LongLongWidth, LongLongAlign;
00068   unsigned char SuitableAlign;
00069   unsigned char MinGlobalAlign;
00070   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
00071   unsigned short MaxVectorAlign;
00072   const char *DescriptionString;
00073   const char *UserLabelPrefix;
00074   const char *MCountName;
00075   const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
00076     *LongDoubleFormat;
00077   unsigned char RegParmMax, SSERegParmMax;
00078   TargetCXXABI TheCXXABI;
00079   const LangAS::Map *AddrSpaceMap;
00080 
00081   mutable StringRef PlatformName;
00082   mutable VersionTuple PlatformMinVersion;
00083 
00084   unsigned HasAlignMac68kSupport : 1;
00085   unsigned RealTypeUsesObjCFPRet : 3;
00086   unsigned ComplexLongDoubleUsesFP2Ret : 1;
00087 
00088   // TargetInfo Constructor.  Default initializes all fields.
00089   TargetInfo(const llvm::Triple &T);
00090 
00091 public:
00092   /// \brief Construct a target for the given options.
00093   ///
00094   /// \param Opts - The options to use to initialize the target. The target may
00095   /// modify the options to canonicalize the target feature information to match
00096   /// what the backend expects.
00097   static TargetInfo *
00098   CreateTargetInfo(DiagnosticsEngine &Diags,
00099                    const std::shared_ptr<TargetOptions> &Opts);
00100 
00101   virtual ~TargetInfo();
00102 
00103   /// \brief Retrieve the target options.
00104   TargetOptions &getTargetOpts() const { 
00105     assert(TargetOpts && "Missing target options");
00106     return *TargetOpts; 
00107   }
00108 
00109   ///===---- Target Data Type Query Methods -------------------------------===//
00110   enum IntType {
00111     NoInt = 0,
00112     SignedChar,
00113     UnsignedChar,
00114     SignedShort,
00115     UnsignedShort,
00116     SignedInt,
00117     UnsignedInt,
00118     SignedLong,
00119     UnsignedLong,
00120     SignedLongLong,
00121     UnsignedLongLong
00122   };
00123 
00124   enum RealType {
00125     NoFloat = 255,
00126     Float = 0,
00127     Double,
00128     LongDouble
00129   };
00130 
00131   /// \brief The different kinds of __builtin_va_list types defined by
00132   /// the target implementation.
00133   enum BuiltinVaListKind {
00134     /// typedef char* __builtin_va_list;
00135     CharPtrBuiltinVaList = 0,
00136 
00137     /// typedef void* __builtin_va_list;
00138     VoidPtrBuiltinVaList,
00139 
00140     /// __builtin_va_list as defind by the AArch64 ABI
00141     /// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055a/IHI0055A_aapcs64.pdf
00142     AArch64ABIBuiltinVaList,
00143 
00144     /// __builtin_va_list as defined by the PNaCl ABI:
00145     /// http://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Machine-Types
00146     PNaClABIBuiltinVaList,
00147 
00148     /// __builtin_va_list as defined by the Power ABI:
00149     /// https://www.power.org
00150     ///        /resources/downloads/Power-Arch-32-bit-ABI-supp-1.0-Embedded.pdf
00151     PowerABIBuiltinVaList,
00152 
00153     /// __builtin_va_list as defined by the x86-64 ABI:
00154     /// http://www.x86-64.org/documentation/abi.pdf
00155     X86_64ABIBuiltinVaList,
00156 
00157     /// __builtin_va_list as defined by ARM AAPCS ABI
00158     /// http://infocenter.arm.com
00159     //        /help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
00160     AAPCSABIBuiltinVaList,
00161 
00162     // typedef struct __va_list_tag
00163     //   {
00164     //     long __gpr;
00165     //     long __fpr;
00166     //     void *__overflow_arg_area;
00167     //     void *__reg_save_area;
00168     //   } va_list[1];
00169     SystemZBuiltinVaList
00170   };
00171 
00172 protected:
00173   IntType SizeType, IntMaxType, PtrDiffType, IntPtrType, WCharType,
00174           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType,
00175           ProcessIDType;
00176 
00177   /// \brief Whether Objective-C's built-in boolean type should be signed char.
00178   ///
00179   /// Otherwise, when this flag is not set, the normal built-in boolean type is
00180   /// used.
00181   unsigned UseSignedCharForObjCBool : 1;
00182 
00183   /// Control whether the alignment of bit-field types is respected when laying
00184   /// out structures. If true, then the alignment of the bit-field type will be
00185   /// used to (a) impact the alignment of the containing structure, and (b)
00186   /// ensure that the individual bit-field will not straddle an alignment
00187   /// boundary.
00188   unsigned UseBitFieldTypeAlignment : 1;
00189 
00190   /// \brief Whether zero length bitfields (e.g., int : 0;) force alignment of
00191   /// the next bitfield.
00192   ///
00193   /// If the alignment of the zero length bitfield is greater than the member
00194   /// that follows it, `bar', `bar' will be aligned as the type of the
00195   /// zero-length bitfield.
00196   unsigned UseZeroLengthBitfieldAlignment : 1;
00197 
00198   /// If non-zero, specifies a fixed alignment value for bitfields that follow
00199   /// zero length bitfield, regardless of the zero length bitfield type.
00200   unsigned ZeroLengthBitfieldBoundary;
00201 
00202   /// \brief Specify if mangling based on address space map should be used or
00203   /// not for language specific address spaces
00204   bool UseAddrSpaceMapMangling;
00205 
00206 public:
00207   IntType getSizeType() const { return SizeType; }
00208   IntType getIntMaxType() const { return IntMaxType; }
00209   IntType getUIntMaxType() const {
00210     return getCorrespondingUnsignedType(IntMaxType);
00211   }
00212   IntType getPtrDiffType(unsigned AddrSpace) const {
00213     return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
00214   }
00215   IntType getIntPtrType() const { return IntPtrType; }
00216   IntType getUIntPtrType() const {
00217     return getCorrespondingUnsignedType(IntPtrType);
00218   }
00219   IntType getWCharType() const { return WCharType; }
00220   IntType getWIntType() const { return WIntType; }
00221   IntType getChar16Type() const { return Char16Type; }
00222   IntType getChar32Type() const { return Char32Type; }
00223   IntType getInt64Type() const { return Int64Type; }
00224   IntType getUInt64Type() const {
00225     return getCorrespondingUnsignedType(Int64Type);
00226   }
00227   IntType getSigAtomicType() const { return SigAtomicType; }
00228   IntType getProcessIDType() const { return ProcessIDType; }
00229 
00230   static IntType getCorrespondingUnsignedType(IntType T) {
00231     switch (T) {
00232     case SignedChar:
00233       return UnsignedChar;
00234     case SignedShort:
00235       return UnsignedShort;
00236     case SignedInt:
00237       return UnsignedInt;
00238     case SignedLong:
00239       return UnsignedLong;
00240     case SignedLongLong:
00241       return UnsignedLongLong;
00242     default:
00243       llvm_unreachable("Unexpected signed integer type");
00244     }
00245   }
00246 
00247   /// \brief Return the width (in bits) of the specified integer type enum.
00248   ///
00249   /// For example, SignedInt -> getIntWidth().
00250   unsigned getTypeWidth(IntType T) const;
00251 
00252   /// \brief Return integer type with specified width.
00253   IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
00254 
00255   /// \brief Return the smallest integer type with at least the specified width.
00256   IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
00257 
00258   /// \brief Return floating point type with specified width.
00259   RealType getRealTypeByWidth(unsigned BitWidth) const;
00260 
00261   /// \brief Return the alignment (in bits) of the specified integer type enum.
00262   ///
00263   /// For example, SignedInt -> getIntAlign().
00264   unsigned getTypeAlign(IntType T) const;
00265 
00266   /// \brief Returns true if the type is signed; false otherwise.
00267   static bool isTypeSigned(IntType T);
00268 
00269   /// \brief Return the width of pointers on this target, for the
00270   /// specified address space.
00271   uint64_t getPointerWidth(unsigned AddrSpace) const {
00272     return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
00273   }
00274   uint64_t getPointerAlign(unsigned AddrSpace) const {
00275     return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
00276   }
00277 
00278   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
00279   unsigned getBoolWidth() const { return BoolWidth; }
00280 
00281   /// \brief Return the alignment of '_Bool' and C++ 'bool' for this target.
00282   unsigned getBoolAlign() const { return BoolAlign; }
00283 
00284   unsigned getCharWidth() const { return 8; } // FIXME
00285   unsigned getCharAlign() const { return 8; } // FIXME
00286 
00287   /// \brief Return the size of 'signed short' and 'unsigned short' for this
00288   /// target, in bits.
00289   unsigned getShortWidth() const { return 16; } // FIXME
00290 
00291   /// \brief Return the alignment of 'signed short' and 'unsigned short' for
00292   /// this target.
00293   unsigned getShortAlign() const { return 16; } // FIXME
00294 
00295   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
00296   /// this target, in bits.
00297   unsigned getIntWidth() const { return IntWidth; }
00298   unsigned getIntAlign() const { return IntAlign; }
00299 
00300   /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
00301   /// for this target, in bits.
00302   unsigned getLongWidth() const { return LongWidth; }
00303   unsigned getLongAlign() const { return LongAlign; }
00304 
00305   /// getLongLongWidth/Align - Return the size of 'signed long long' and
00306   /// 'unsigned long long' for this target, in bits.
00307   unsigned getLongLongWidth() const { return LongLongWidth; }
00308   unsigned getLongLongAlign() const { return LongLongAlign; }
00309 
00310   /// \brief Determine whether the __int128 type is supported on this target.
00311   virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
00312 
00313   /// \brief Return the alignment that is suitable for storing any
00314   /// object with a fundamental alignment requirement.
00315   unsigned getSuitableAlign() const { return SuitableAlign; }
00316 
00317   /// getMinGlobalAlign - Return the minimum alignment of a global variable,
00318   /// unless its alignment is explicitly reduced via attributes.
00319   unsigned getMinGlobalAlign() const { return MinGlobalAlign; }
00320 
00321   /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
00322   /// bits.
00323   unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
00324   unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
00325 
00326   /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
00327   /// bits.
00328   unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
00329   unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
00330 
00331   /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
00332   /// bits.
00333   unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
00334   unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
00335 
00336   /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
00337   unsigned getHalfWidth() const { return HalfWidth; }
00338   unsigned getHalfAlign() const { return HalfAlign; }
00339   const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
00340 
00341   /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
00342   unsigned getFloatWidth() const { return FloatWidth; }
00343   unsigned getFloatAlign() const { return FloatAlign; }
00344   const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
00345 
00346   /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
00347   unsigned getDoubleWidth() const { return DoubleWidth; }
00348   unsigned getDoubleAlign() const { return DoubleAlign; }
00349   const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
00350 
00351   /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
00352   /// double'.
00353   unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
00354   unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
00355   const llvm::fltSemantics &getLongDoubleFormat() const {
00356     return *LongDoubleFormat;
00357   }
00358 
00359   /// \brief Return the value for the C99 FLT_EVAL_METHOD macro.
00360   virtual unsigned getFloatEvalMethod() const { return 0; }
00361 
00362   // getLargeArrayMinWidth/Align - Return the minimum array size that is
00363   // 'large' and its alignment.
00364   unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
00365   unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
00366 
00367   /// \brief Return the maximum width lock-free atomic operation which will
00368   /// ever be supported for the given target
00369   unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
00370   /// \brief Return the maximum width lock-free atomic operation which can be
00371   /// inlined given the supported features of the given target.
00372   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
00373 
00374   /// \brief Return the maximum vector alignment supported for the given target.
00375   unsigned getMaxVectorAlign() const { return MaxVectorAlign; }
00376 
00377   /// \brief Return the size of intmax_t and uintmax_t for this target, in bits.
00378   unsigned getIntMaxTWidth() const {
00379     return getTypeWidth(IntMaxType);
00380   }
00381 
00382   // Return the size of unwind_word for this target.
00383   unsigned getUnwindWordWidth() const { return getPointerWidth(0); }
00384 
00385   /// \brief Return the "preferred" register width on this target.
00386   unsigned getRegisterWidth() const {
00387     // Currently we assume the register width on the target matches the pointer
00388     // width, we can introduce a new variable for this if/when some target wants
00389     // it.
00390     return PointerWidth;
00391   }
00392 
00393   /// \brief Returns the default value of the __USER_LABEL_PREFIX__ macro,
00394   /// which is the prefix given to user symbols by default.
00395   ///
00396   /// On most platforms this is "_", but it is "" on some, and "." on others.
00397   const char *getUserLabelPrefix() const {
00398     return UserLabelPrefix;
00399   }
00400 
00401   /// \brief Returns the name of the mcount instrumentation function.
00402   const char *getMCountName() const {
00403     return MCountName;
00404   }
00405 
00406   /// \brief Check if the Objective-C built-in boolean type should be signed
00407   /// char.
00408   ///
00409   /// Otherwise, if this returns false, the normal built-in boolean type
00410   /// should also be used for Objective-C.
00411   bool useSignedCharForObjCBool() const {
00412     return UseSignedCharForObjCBool;
00413   }
00414   void noSignedCharForObjCBool() {
00415     UseSignedCharForObjCBool = false;
00416   }
00417 
00418   /// \brief Check whether the alignment of bit-field types is respected
00419   /// when laying out structures.
00420   bool useBitFieldTypeAlignment() const {
00421     return UseBitFieldTypeAlignment;
00422   }
00423 
00424   /// \brief Check whether zero length bitfields should force alignment of
00425   /// the next member.
00426   bool useZeroLengthBitfieldAlignment() const {
00427     return UseZeroLengthBitfieldAlignment;
00428   }
00429 
00430   /// \brief Get the fixed alignment value in bits for a member that follows
00431   /// a zero length bitfield.
00432   unsigned getZeroLengthBitfieldBoundary() const {
00433     return ZeroLengthBitfieldBoundary;
00434   }
00435 
00436   /// \brief Check whether this target support '\#pragma options align=mac68k'.
00437   bool hasAlignMac68kSupport() const {
00438     return HasAlignMac68kSupport;
00439   }
00440 
00441   /// \brief Return the user string for the specified integer type enum.
00442   ///
00443   /// For example, SignedShort -> "short".
00444   static const char *getTypeName(IntType T);
00445 
00446   /// \brief Return the constant suffix for the specified integer type enum.
00447   ///
00448   /// For example, SignedLong -> "L".
00449   const char *getTypeConstantSuffix(IntType T) const;
00450 
00451   /// \brief Return the printf format modifier for the specified
00452   /// integer type enum.
00453   ///
00454   /// For example, SignedLong -> "l".
00455   static const char *getTypeFormatModifier(IntType T);
00456 
00457   /// \brief Check whether the given real type should use the "fpret" flavor of
00458   /// Objective-C message passing on this target.
00459   bool useObjCFPRetForRealType(RealType T) const {
00460     return RealTypeUsesObjCFPRet & (1 << T);
00461   }
00462 
00463   /// \brief Check whether _Complex long double should use the "fp2ret" flavor
00464   /// of Objective-C message passing on this target.
00465   bool useObjCFP2RetForComplexLongDouble() const {
00466     return ComplexLongDoubleUsesFP2Ret;
00467   }
00468 
00469   /// \brief Specify if mangling based on address space map should be used or
00470   /// not for language specific address spaces
00471   bool useAddressSpaceMapMangling() const {
00472     return UseAddrSpaceMapMangling;
00473   }
00474 
00475   ///===---- Other target property query methods --------------------------===//
00476 
00477   /// \brief Appends the target-specific \#define values for this
00478   /// target set to the specified buffer.
00479   virtual void getTargetDefines(const LangOptions &Opts,
00480                                 MacroBuilder &Builder) const = 0;
00481 
00482 
00483   /// Return information about target-specific builtins for
00484   /// the current primary target, and info about which builtins are non-portable
00485   /// across the current set of primary and secondary targets.
00486   virtual void getTargetBuiltins(const Builtin::Info *&Records,
00487                                  unsigned &NumRecords) const = 0;
00488 
00489   /// The __builtin_clz* and __builtin_ctz* built-in
00490   /// functions are specified to have undefined results for zero inputs, but
00491   /// on targets that support these operations in a way that provides
00492   /// well-defined results for zero without loss of performance, it is a good
00493   /// idea to avoid optimizing based on that undef behavior.
00494   virtual bool isCLZForZeroUndef() const { return true; }
00495 
00496   /// \brief Returns the kind of __builtin_va_list type that should be used
00497   /// with this target.
00498   virtual BuiltinVaListKind getBuiltinVaListKind() const = 0;
00499 
00500   /// \brief Returns whether the passed in string is a valid clobber in an
00501   /// inline asm statement.
00502   ///
00503   /// This is used by Sema.
00504   bool isValidClobber(StringRef Name) const;
00505 
00506   /// \brief Returns whether the passed in string is a valid register name
00507   /// according to GCC.
00508   ///
00509   /// This is used by Sema for inline asm statements.
00510   bool isValidGCCRegisterName(StringRef Name) const;
00511 
00512   /// \brief Returns the "normalized" GCC register name.
00513   ///
00514   /// For example, on x86 it will return "ax" when "eax" is passed in.
00515   StringRef getNormalizedGCCRegisterName(StringRef Name) const;
00516 
00517   struct ConstraintInfo {
00518     enum {
00519       CI_None = 0x00,
00520       CI_AllowsMemory = 0x01,
00521       CI_AllowsRegister = 0x02,
00522       CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
00523       CI_HasMatchingInput = 0x08 // This output operand has a matching input.
00524     };
00525     unsigned Flags;
00526     int TiedOperand;
00527 
00528     std::string ConstraintStr;  // constraint: "=rm"
00529     std::string Name;           // Operand name: [foo] with no []'s.
00530   public:
00531     ConstraintInfo(StringRef ConstraintStr, StringRef Name)
00532       : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
00533       Name(Name.str()) {}
00534 
00535     const std::string &getConstraintStr() const { return ConstraintStr; }
00536     const std::string &getName() const { return Name; }
00537     bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
00538     bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
00539     bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
00540 
00541     /// \brief Return true if this output operand has a matching
00542     /// (tied) input operand.
00543     bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
00544 
00545     /// \brief Return true if this input operand is a matching
00546     /// constraint that ties it to an output operand.
00547     ///
00548     /// If this returns true then getTiedOperand will indicate which output
00549     /// operand this is tied to.
00550     bool hasTiedOperand() const { return TiedOperand != -1; }
00551     unsigned getTiedOperand() const {
00552       assert(hasTiedOperand() && "Has no tied operand!");
00553       return (unsigned)TiedOperand;
00554     }
00555 
00556     void setIsReadWrite() { Flags |= CI_ReadWrite; }
00557     void setAllowsMemory() { Flags |= CI_AllowsMemory; }
00558     void setAllowsRegister() { Flags |= CI_AllowsRegister; }
00559     void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
00560 
00561     /// \brief Indicate that this is an input operand that is tied to
00562     /// the specified output operand. 
00563     ///
00564     /// Copy over the various constraint information from the output.
00565     void setTiedOperand(unsigned N, ConstraintInfo &Output) {
00566       Output.setHasMatchingInput();
00567       Flags = Output.Flags;
00568       TiedOperand = N;
00569       // Don't copy Name or constraint string.
00570     }
00571   };
00572 
00573   // validateOutputConstraint, validateInputConstraint - Checks that
00574   // a constraint is valid and provides information about it.
00575   // FIXME: These should return a real error instead of just true/false.
00576   bool validateOutputConstraint(ConstraintInfo &Info) const;
00577   bool validateInputConstraint(ConstraintInfo *OutputConstraints,
00578                                unsigned NumOutputs,
00579                                ConstraintInfo &info) const;
00580 
00581   virtual bool validateOutputSize(StringRef /*Constraint*/,
00582                                   unsigned /*Size*/) const {
00583     return true;
00584   }
00585 
00586   virtual bool validateInputSize(StringRef /*Constraint*/,
00587                                  unsigned /*Size*/) const {
00588     return true;
00589   }
00590   virtual bool
00591   validateConstraintModifier(StringRef /*Constraint*/,
00592                              char /*Modifier*/,
00593                              unsigned /*Size*/,
00594                              std::string &/*SuggestedModifier*/) const {
00595     return true;
00596   }
00597   bool resolveSymbolicName(const char *&Name,
00598                            ConstraintInfo *OutputConstraints,
00599                            unsigned NumOutputs, unsigned &Index) const;
00600 
00601   // Constraint parm will be left pointing at the last character of
00602   // the constraint.  In practice, it won't be changed unless the
00603   // constraint is longer than one character.
00604   virtual std::string convertConstraint(const char *&Constraint) const {
00605     // 'p' defaults to 'r', but can be overridden by targets.
00606     if (*Constraint == 'p')
00607       return std::string("r");
00608     return std::string(1, *Constraint);
00609   }
00610 
00611   /// \brief Returns a string of target-specific clobbers, in LLVM format.
00612   virtual const char *getClobbers() const = 0;
00613 
00614 
00615   /// \brief Returns the target triple of the primary target.
00616   const llvm::Triple &getTriple() const {
00617     return Triple;
00618   }
00619 
00620   const char *getTargetDescription() const {
00621     assert(DescriptionString);
00622     return DescriptionString;
00623   }
00624 
00625   struct GCCRegAlias {
00626     const char * const Aliases[5];
00627     const char * const Register;
00628   };
00629 
00630   struct AddlRegName {
00631     const char * const Names[5];
00632     const unsigned RegNum;
00633   };
00634 
00635   /// \brief Does this target support "protected" visibility?
00636   ///
00637   /// Any target which dynamic libraries will naturally support
00638   /// something like "default" (meaning that the symbol is visible
00639   /// outside this shared object) and "hidden" (meaning that it isn't)
00640   /// visibilities, but "protected" is really an ELF-specific concept
00641   /// with weird semantics designed around the convenience of dynamic
00642   /// linker implementations.  Which is not to suggest that there's
00643   /// consistent target-independent semantics for "default" visibility
00644   /// either; the entire thing is pretty badly mangled.
00645   virtual bool hasProtectedVisibility() const { return true; }
00646 
00647   /// \brief An optional hook that targets can implement to perform semantic
00648   /// checking on attribute((section("foo"))) specifiers.
00649   ///
00650   /// In this case, "foo" is passed in to be checked.  If the section
00651   /// specifier is invalid, the backend should return a non-empty string
00652   /// that indicates the problem.
00653   ///
00654   /// This hook is a simple quality of implementation feature to catch errors
00655   /// and give good diagnostics in cases when the assembler or code generator
00656   /// would otherwise reject the section specifier.
00657   ///
00658   virtual std::string isValidSectionSpecifier(StringRef SR) const {
00659     return "";
00660   }
00661 
00662   /// \brief Set forced language options.
00663   ///
00664   /// Apply changes to the target information with respect to certain
00665   /// language options which change the target configuration.
00666   virtual void adjust(const LangOptions &Opts);
00667 
00668   /// \brief Get the default set of target features for the CPU;
00669   /// this should include all legal feature strings on the target.
00670   virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
00671   }
00672 
00673   /// \brief Get the ABI currently in use.
00674   virtual StringRef getABI() const { return StringRef(); }
00675 
00676   /// \brief Get the C++ ABI currently in use.
00677   TargetCXXABI getCXXABI() const {
00678     return TheCXXABI;
00679   }
00680 
00681   /// \brief Target the specified CPU.
00682   ///
00683   /// \return  False on error (invalid CPU name).
00684   virtual bool setCPU(const std::string &Name) {
00685     return false;
00686   }
00687 
00688   /// \brief Use the specified ABI.
00689   ///
00690   /// \return False on error (invalid ABI name).
00691   virtual bool setABI(const std::string &Name) {
00692     return false;
00693   }
00694 
00695   /// \brief Use the specified unit for FP math.
00696   ///
00697   /// \return False on error (invalid unit name).
00698   virtual bool setFPMath(StringRef Name) {
00699     return false;
00700   }
00701 
00702   /// \brief Use this specified C++ ABI.
00703   ///
00704   /// \return False on error (invalid C++ ABI name).
00705   bool setCXXABI(llvm::StringRef name) {
00706     TargetCXXABI ABI;
00707     if (!ABI.tryParse(name)) return false;
00708     return setCXXABI(ABI);
00709   }
00710 
00711   /// \brief Set the C++ ABI to be used by this implementation.
00712   ///
00713   /// \return False on error (ABI not valid on this target)
00714   virtual bool setCXXABI(TargetCXXABI ABI) {
00715     TheCXXABI = ABI;
00716     return true;
00717   }
00718 
00719   /// \brief Enable or disable a specific target feature;
00720   /// the feature name must be valid.
00721   virtual void setFeatureEnabled(llvm::StringMap<bool> &Features,
00722                                  StringRef Name,
00723                                  bool Enabled) const {
00724     Features[Name] = Enabled;
00725   }
00726 
00727   /// \brief Perform initialization based on the user configured
00728   /// set of features (e.g., +sse4).
00729   ///
00730   /// The list is guaranteed to have at most one entry per feature.
00731   ///
00732   /// The target may modify the features list, to change which options are
00733   /// passed onwards to the backend.
00734   ///
00735   /// \return  False on error.
00736   virtual bool handleTargetFeatures(std::vector<std::string> &Features,
00737                                     DiagnosticsEngine &Diags) {
00738     return true;
00739   }
00740 
00741   /// \brief Determine whether the given target has the given feature.
00742   virtual bool hasFeature(StringRef Feature) const {
00743     return false;
00744   }
00745   
00746   // \brief Returns maximal number of args passed in registers.
00747   unsigned getRegParmMax() const {
00748     assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
00749     return RegParmMax;
00750   }
00751 
00752   /// \brief Whether the target supports thread-local storage.
00753   bool isTLSSupported() const {
00754     return TLSSupported;
00755   }
00756 
00757   /// \brief Return true if {|} are normal characters in the asm string.
00758   ///
00759   /// If this returns false (the default), then {abc|xyz} is syntax
00760   /// that says that when compiling for asm variant #0, "abc" should be
00761   /// generated, but when compiling for asm variant #1, "xyz" should be
00762   /// generated.
00763   bool hasNoAsmVariants() const {
00764     return NoAsmVariants;
00765   }
00766 
00767   /// \brief Return the register number that __builtin_eh_return_regno would
00768   /// return with the specified argument.
00769   virtual int getEHDataRegisterNumber(unsigned RegNo) const {
00770     return -1;
00771   }
00772 
00773   /// \brief Return the section to use for C++ static initialization functions.
00774   virtual const char *getStaticInitSectionSpecifier() const {
00775     return nullptr;
00776   }
00777 
00778   const LangAS::Map &getAddressSpaceMap() const {
00779     return *AddrSpaceMap;
00780   }
00781 
00782   /// \brief Retrieve the name of the platform as it is used in the
00783   /// availability attribute.
00784   StringRef getPlatformName() const { return PlatformName; }
00785 
00786   /// \brief Retrieve the minimum desired version of the platform, to
00787   /// which the program should be compiled.
00788   VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
00789 
00790   bool isBigEndian() const { return BigEndian; }
00791 
00792   enum CallingConvMethodType {
00793     CCMT_Unknown,
00794     CCMT_Member,
00795     CCMT_NonMember
00796   };
00797 
00798   /// \brief Gets the default calling convention for the given target and
00799   /// declaration context.
00800   virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const {
00801     // Not all targets will specify an explicit calling convention that we can
00802     // express.  This will always do the right thing, even though it's not
00803     // an explicit calling convention.
00804     return CC_C;
00805   }
00806 
00807   enum CallingConvCheckResult {
00808     CCCR_OK,
00809     CCCR_Warning
00810   };
00811 
00812   /// \brief Determines whether a given calling convention is valid for the
00813   /// target. A calling convention can either be accepted, produce a warning 
00814   /// and be substituted with the default calling convention, or (someday)
00815   /// produce an error (such as using thiscall on a non-instance function).
00816   virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {
00817     switch (CC) {
00818       default:
00819         return CCCR_Warning;
00820       case CC_C:
00821         return CCCR_OK;
00822     }
00823   }
00824 
00825 protected:
00826   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
00827     return PointerWidth;
00828   }
00829   virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
00830     return PointerAlign;
00831   }
00832   virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
00833     return PtrDiffType;
00834   }
00835   virtual void getGCCRegNames(const char * const *&Names,
00836                               unsigned &NumNames) const = 0;
00837   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
00838                                 unsigned &NumAliases) const = 0;
00839   virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
00840                                   unsigned &NumAddl) const {
00841     Addl = nullptr;
00842     NumAddl = 0;
00843   }
00844   virtual bool validateAsmConstraint(const char *&Name,
00845                                      TargetInfo::ConstraintInfo &info) const= 0;
00846 };
00847 
00848 }  // end namespace clang
00849 
00850 #endif