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 //  This file defines the TargetInfo interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
00015 #define LLVM_CLANG_BASIC_TARGETINFO_H
00016 
00017 #include "clang/Basic/LLVM.h"
00018 #include "llvm/ADT/IntrusiveRefCntPtr.h"
00019 #include "llvm/ADT/StringMap.h"
00020 #include "llvm/ADT/StringRef.h"
00021 #include "llvm/ADT/StringSwitch.h"
00022 #include "llvm/ADT/Triple.h"
00023 #include "llvm/Support/DataTypes.h"
00024 #include "clang/Basic/AddressSpaces.h"
00025 #include "clang/Basic/VersionTuple.h"
00026 #include <cassert>
00027 #include <vector>
00028 #include <string>
00029 
00030 namespace llvm {
00031 struct fltSemantics;
00032 }
00033 
00034 namespace clang {
00035 class DiagnosticsEngine;
00036 class LangOptions;
00037 class MacroBuilder;
00038 class SourceLocation;
00039 class SourceManager;
00040 class TargetOptions;
00041 
00042 namespace Builtin { struct Info; }
00043 
00044 /// TargetCXXABI - The types of C++ ABIs for which we can generate code.
00045 enum TargetCXXABI {
00046   /// The generic ("Itanium") C++ ABI, documented at:
00047   ///   http://www.codesourcery.com/public/cxx-abi/
00048   CXXABI_Itanium,
00049 
00050   /// The ARM C++ ABI, based largely on the Itanium ABI but with
00051   /// significant differences.
00052   ///    http://infocenter.arm.com
00053   ///                    /help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
00054   CXXABI_ARM,
00055 
00056   /// The Visual Studio ABI.  Only scattered official documentation exists.
00057   CXXABI_Microsoft
00058 };
00059 
00060 /// TargetInfo - This class exposes information about the current target.
00061 ///
00062 class TargetInfo : public RefCountedBase<TargetInfo> {
00063   llvm::Triple Triple;
00064 protected:
00065   // Target values set by the ctor of the actual target implementation.  Default
00066   // values are specified by the TargetInfo constructor.
00067   bool BigEndian;
00068   bool TLSSupported;
00069   bool NoAsmVariants;  // True if {|} are normal characters.
00070   unsigned char PointerWidth, PointerAlign;
00071   unsigned char BoolWidth, BoolAlign;
00072   unsigned char IntWidth, IntAlign;
00073   unsigned char HalfWidth, HalfAlign;
00074   unsigned char FloatWidth, FloatAlign;
00075   unsigned char DoubleWidth, DoubleAlign;
00076   unsigned char LongDoubleWidth, LongDoubleAlign;
00077   unsigned char LargeArrayMinWidth, LargeArrayAlign;
00078   unsigned char LongWidth, LongAlign;
00079   unsigned char LongLongWidth, LongLongAlign;
00080   unsigned char SuitableAlign;
00081   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
00082   const char *DescriptionString;
00083   const char *UserLabelPrefix;
00084   const char *MCountName;
00085   const llvm::fltSemantics *HalfFormat, *FloatFormat, *DoubleFormat,
00086     *LongDoubleFormat;
00087   unsigned char RegParmMax, SSERegParmMax;
00088   TargetCXXABI CXXABI;
00089   const LangAS::Map *AddrSpaceMap;
00090 
00091   mutable StringRef PlatformName;
00092   mutable VersionTuple PlatformMinVersion;
00093 
00094   unsigned HasAlignMac68kSupport : 1;
00095   unsigned RealTypeUsesObjCFPRet : 3;
00096   unsigned ComplexLongDoubleUsesFP2Ret : 1;
00097 
00098   // TargetInfo Constructor.  Default initializes all fields.
00099   TargetInfo(const std::string &T);
00100 
00101 public:
00102   /// CreateTargetInfo - Construct a target for the given options.
00103   ///
00104   /// \param Opts - The options to use to initialize the target. The target may
00105   /// modify the options to canonicalize the target feature information to match
00106   /// what the backend expects.
00107   static TargetInfo* CreateTargetInfo(DiagnosticsEngine &Diags,
00108                                       TargetOptions &Opts);
00109 
00110   virtual ~TargetInfo();
00111 
00112   ///===---- Target Data Type Query Methods -------------------------------===//
00113   enum IntType {
00114     NoInt = 0,
00115     SignedShort,
00116     UnsignedShort,
00117     SignedInt,
00118     UnsignedInt,
00119     SignedLong,
00120     UnsignedLong,
00121     SignedLongLong,
00122     UnsignedLongLong
00123   };
00124 
00125   enum RealType {
00126     Float = 0,
00127     Double,
00128     LongDouble
00129   };
00130 
00131 protected:
00132   IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
00133           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
00134 
00135   /// Flag whether the Objective-C built-in boolean type should be signed char.
00136   /// Otherwise, when this flag is not set, the normal built-in boolean type is
00137   /// used.
00138   unsigned UseSignedCharForObjCBool : 1;
00139 
00140   /// Control whether the alignment of bit-field types is respected when laying
00141   /// out structures. If true, then the alignment of the bit-field type will be
00142   /// used to (a) impact the alignment of the containing structure, and (b)
00143   /// ensure that the individual bit-field will not straddle an alignment
00144   /// boundary.
00145   unsigned UseBitFieldTypeAlignment : 1;
00146 
00147   /// Control whether zero length bitfields (e.g., int : 0;) force alignment of
00148   /// the next bitfield.  If the alignment of the zero length bitfield is 
00149   /// greater than the member that follows it, `bar', `bar' will be aligned as
00150   /// the type of the zero-length bitfield.
00151   unsigned UseZeroLengthBitfieldAlignment : 1;
00152 
00153   /// If non-zero, specifies a fixed alignment value for bitfields that follow
00154   /// zero length bitfield, regardless of the zero length bitfield type.
00155   unsigned ZeroLengthBitfieldBoundary;
00156 
00157 public:
00158   IntType getSizeType() const { return SizeType; }
00159   IntType getIntMaxType() const { return IntMaxType; }
00160   IntType getUIntMaxType() const { return UIntMaxType; }
00161   IntType getPtrDiffType(unsigned AddrSpace) const {
00162     return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
00163   }
00164   IntType getIntPtrType() const { return IntPtrType; }
00165   IntType getWCharType() const { return WCharType; }
00166   IntType getWIntType() const { return WIntType; }
00167   IntType getChar16Type() const { return Char16Type; }
00168   IntType getChar32Type() const { return Char32Type; }
00169   IntType getInt64Type() const { return Int64Type; }
00170   IntType getSigAtomicType() const { return SigAtomicType; }
00171 
00172 
00173   /// getTypeWidth - Return the width (in bits) of the specified integer type
00174   /// enum. For example, SignedInt -> getIntWidth().
00175   unsigned getTypeWidth(IntType T) const;
00176 
00177   /// getTypeAlign - Return the alignment (in bits) of the specified integer
00178   /// type enum. For example, SignedInt -> getIntAlign().
00179   unsigned getTypeAlign(IntType T) const;
00180 
00181   /// isTypeSigned - Return whether an integer types is signed. Returns true if
00182   /// the type is signed; false otherwise.
00183   static bool isTypeSigned(IntType T);
00184 
00185   /// getPointerWidth - Return the width of pointers on this target, for the
00186   /// specified address space.
00187   uint64_t getPointerWidth(unsigned AddrSpace) const {
00188     return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
00189   }
00190   uint64_t getPointerAlign(unsigned AddrSpace) const {
00191     return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
00192   }
00193 
00194   /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
00195   /// target, in bits.
00196   unsigned getBoolWidth() const { return BoolWidth; }
00197   unsigned getBoolAlign() const { return BoolAlign; }
00198 
00199   unsigned getCharWidth() const { return 8; } // FIXME
00200   unsigned getCharAlign() const { return 8; } // FIXME
00201 
00202   /// getShortWidth/Align - Return the size of 'signed short' and
00203   /// 'unsigned short' for this target, in bits.
00204   unsigned getShortWidth() const { return 16; } // FIXME
00205   unsigned getShortAlign() const { return 16; } // FIXME
00206 
00207   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
00208   /// this target, in bits.
00209   unsigned getIntWidth() const { return IntWidth; }
00210   unsigned getIntAlign() const { return IntAlign; }
00211 
00212   /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
00213   /// for this target, in bits.
00214   unsigned getLongWidth() const { return LongWidth; }
00215   unsigned getLongAlign() const { return LongAlign; }
00216 
00217   /// getLongLongWidth/Align - Return the size of 'signed long long' and
00218   /// 'unsigned long long' for this target, in bits.
00219   unsigned getLongLongWidth() const { return LongLongWidth; }
00220   unsigned getLongLongAlign() const { return LongLongAlign; }
00221 
00222   /// getSuitableAlign - Return the alignment that is suitable for storing any
00223   /// object with a fundamental alignment requirement.
00224   unsigned getSuitableAlign() const { return SuitableAlign; }
00225 
00226   /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
00227   /// bits.
00228   unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
00229   unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
00230 
00231   /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
00232   /// bits.
00233   unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
00234   unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
00235 
00236   /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
00237   /// bits.
00238   unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
00239   unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
00240 
00241   /// getHalfWidth/Align/Format - Return the size/align/format of 'half'.
00242   unsigned getHalfWidth() const { return HalfWidth; }
00243   unsigned getHalfAlign() const { return HalfAlign; }
00244   const llvm::fltSemantics &getHalfFormat() const { return *HalfFormat; }
00245 
00246   /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
00247   unsigned getFloatWidth() const { return FloatWidth; }
00248   unsigned getFloatAlign() const { return FloatAlign; }
00249   const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
00250 
00251   /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
00252   unsigned getDoubleWidth() const { return DoubleWidth; }
00253   unsigned getDoubleAlign() const { return DoubleAlign; }
00254   const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
00255 
00256   /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
00257   /// double'.
00258   unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
00259   unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
00260   const llvm::fltSemantics &getLongDoubleFormat() const {
00261     return *LongDoubleFormat;
00262   }
00263 
00264   /// getFloatEvalMethod - Return the value for the C99 FLT_EVAL_METHOD macro.
00265   virtual unsigned getFloatEvalMethod() const { return 0; }
00266 
00267   // getLargeArrayMinWidth/Align - Return the minimum array size that is
00268   // 'large' and its alignment.
00269   unsigned getLargeArrayMinWidth() const { return LargeArrayMinWidth; }
00270   unsigned getLargeArrayAlign() const { return LargeArrayAlign; }
00271 
00272   /// getMaxAtomicPromoteWidth - Return the maximum width lock-free atomic
00273   /// operation which will ever be supported for the given target
00274   unsigned getMaxAtomicPromoteWidth() const { return MaxAtomicPromoteWidth; }
00275   /// getMaxAtomicInlineWidth - Return the maximum width lock-free atomic
00276   /// operation which can be inlined given the supported features of the
00277   /// given target.
00278   unsigned getMaxAtomicInlineWidth() const { return MaxAtomicInlineWidth; }
00279 
00280   /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
00281   /// target, in bits.
00282   unsigned getIntMaxTWidth() const {
00283     return getTypeWidth(IntMaxType);
00284   }
00285 
00286   /// getRegisterWidth - Return the "preferred" register width on this target.
00287   uint64_t getRegisterWidth() const {
00288     // Currently we assume the register width on the target matches the pointer
00289     // width, we can introduce a new variable for this if/when some target wants
00290     // it.
00291     return LongWidth; 
00292   }
00293 
00294   /// getUserLabelPrefix - This returns the default value of the
00295   /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by
00296   /// default.  On most platforms this is "_", but it is "" on some, and "." on
00297   /// others.
00298   const char *getUserLabelPrefix() const {
00299     return UserLabelPrefix;
00300   }
00301 
00302   /// MCountName - This returns name of the mcount instrumentation function.
00303   const char *getMCountName() const {
00304     return MCountName;
00305   }
00306 
00307   /// useSignedCharForObjCBool - Check if the Objective-C built-in boolean
00308   /// type should be signed char.  Otherwise, if this returns false, the
00309   /// normal built-in boolean type should also be used for Objective-C.
00310   bool useSignedCharForObjCBool() const {
00311     return UseSignedCharForObjCBool;
00312   }
00313   void noSignedCharForObjCBool() {
00314     UseSignedCharForObjCBool = false;
00315   }
00316 
00317   /// useBitFieldTypeAlignment() - Check whether the alignment of bit-field 
00318   /// types is respected when laying out structures.
00319   bool useBitFieldTypeAlignment() const {
00320     return UseBitFieldTypeAlignment;
00321   }
00322 
00323   /// useZeroLengthBitfieldAlignment() - Check whether zero length bitfields 
00324   /// should force alignment of the next member.
00325   bool useZeroLengthBitfieldAlignment() const {
00326     return UseZeroLengthBitfieldAlignment;
00327   }
00328 
00329   /// getZeroLengthBitfieldBoundary() - Get the fixed alignment value in bits
00330   /// for a member that follows a zero length bitfield.
00331   unsigned getZeroLengthBitfieldBoundary() const {
00332     return ZeroLengthBitfieldBoundary;
00333   }
00334 
00335   /// hasAlignMac68kSupport - Check whether this target support '#pragma options
00336   /// align=mac68k'.
00337   bool hasAlignMac68kSupport() const {
00338     return HasAlignMac68kSupport;
00339   }
00340 
00341   /// getTypeName - Return the user string for the specified integer type enum.
00342   /// For example, SignedShort -> "short".
00343   static const char *getTypeName(IntType T);
00344 
00345   /// getTypeConstantSuffix - Return the constant suffix for the specified
00346   /// integer type enum. For example, SignedLong -> "L".
00347   static const char *getTypeConstantSuffix(IntType T);
00348 
00349   /// \brief Check whether the given real type should use the "fpret" flavor of
00350   /// Obj-C message passing on this target.
00351   bool useObjCFPRetForRealType(RealType T) const {
00352     return RealTypeUsesObjCFPRet & (1 << T);
00353   }
00354 
00355   /// \brief Check whether _Complex long double should use the "fp2ret" flavor
00356   /// of Obj-C message passing on this target.
00357   bool useObjCFP2RetForComplexLongDouble() const {
00358     return ComplexLongDoubleUsesFP2Ret;
00359   }
00360 
00361   ///===---- Other target property query methods --------------------------===//
00362 
00363   /// getTargetDefines - Appends the target-specific #define values for this
00364   /// target set to the specified buffer.
00365   virtual void getTargetDefines(const LangOptions &Opts,
00366                                 MacroBuilder &Builder) const = 0;
00367 
00368 
00369   /// getTargetBuiltins - Return information about target-specific builtins for
00370   /// the current primary target, and info about which builtins are non-portable
00371   /// across the current set of primary and secondary targets.
00372   virtual void getTargetBuiltins(const Builtin::Info *&Records,
00373                                  unsigned &NumRecords) const = 0;
00374 
00375   /// isCLZForZeroUndef - The __builtin_clz* and __builtin_ctz* built-in
00376   /// functions are specified to have undefined results for zero inputs, but
00377   /// on targets that support these operations in a way that provides
00378   /// well-defined results for zero without loss of performance, it is a good
00379   /// idea to avoid optimizing based on that undef behavior.
00380   virtual bool isCLZForZeroUndef() const { return true; }
00381 
00382   /// getVAListDeclaration - Return the declaration to use for
00383   /// __builtin_va_list, which is target-specific.
00384   virtual const char *getVAListDeclaration() const = 0;
00385 
00386   /// isValidClobber - Returns whether the passed in string is
00387   /// a valid clobber in an inline asm statement. This is used by
00388   /// Sema.
00389   bool isValidClobber(StringRef Name) const;
00390 
00391   /// isValidGCCRegisterName - Returns whether the passed in string
00392   /// is a valid register name according to GCC. This is used by Sema for
00393   /// inline asm statements.
00394   bool isValidGCCRegisterName(StringRef Name) const;
00395 
00396   // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name.
00397   // For example, on x86 it will return "ax" when "eax" is passed in.
00398   StringRef getNormalizedGCCRegisterName(StringRef Name) const;
00399 
00400   struct ConstraintInfo {
00401     enum {
00402       CI_None = 0x00,
00403       CI_AllowsMemory = 0x01,
00404       CI_AllowsRegister = 0x02,
00405       CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
00406       CI_HasMatchingInput = 0x08 // This output operand has a matching input.
00407     };
00408     unsigned Flags;
00409     int TiedOperand;
00410 
00411     std::string ConstraintStr;  // constraint: "=rm"
00412     std::string Name;           // Operand name: [foo] with no []'s.
00413   public:
00414     ConstraintInfo(StringRef ConstraintStr, StringRef Name)
00415       : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
00416       Name(Name.str()) {}
00417 
00418     const std::string &getConstraintStr() const { return ConstraintStr; }
00419     const std::string &getName() const { return Name; }
00420     bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
00421     bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
00422     bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
00423 
00424     /// hasMatchingInput - Return true if this output operand has a matching
00425     /// (tied) input operand.
00426     bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
00427 
00428     /// hasTiedOperand() - Return true if this input operand is a matching
00429     /// constraint that ties it to an output operand.  If this returns true,
00430     /// then getTiedOperand will indicate which output operand this is tied to.
00431     bool hasTiedOperand() const { return TiedOperand != -1; }
00432     unsigned getTiedOperand() const {
00433       assert(hasTiedOperand() && "Has no tied operand!");
00434       return (unsigned)TiedOperand;
00435     }
00436 
00437     void setIsReadWrite() { Flags |= CI_ReadWrite; }
00438     void setAllowsMemory() { Flags |= CI_AllowsMemory; }
00439     void setAllowsRegister() { Flags |= CI_AllowsRegister; }
00440     void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
00441 
00442     /// setTiedOperand - Indicate that this is an input operand that is tied to
00443     /// the specified output operand.  Copy over the various constraint
00444     /// information from the output.
00445     void setTiedOperand(unsigned N, ConstraintInfo &Output) {
00446       Output.setHasMatchingInput();
00447       Flags = Output.Flags;
00448       TiedOperand = N;
00449       // Don't copy Name or constraint string.
00450     }
00451   };
00452 
00453   // validateOutputConstraint, validateInputConstraint - Checks that
00454   // a constraint is valid and provides information about it.
00455   // FIXME: These should return a real error instead of just true/false.
00456   bool validateOutputConstraint(ConstraintInfo &Info) const;
00457   bool validateInputConstraint(ConstraintInfo *OutputConstraints,
00458                                unsigned NumOutputs,
00459                                ConstraintInfo &info) const;
00460   bool resolveSymbolicName(const char *&Name,
00461                            ConstraintInfo *OutputConstraints,
00462                            unsigned NumOutputs, unsigned &Index) const;
00463 
00464   // Constraint parm will be left pointing at the last character of
00465   // the constraint.  In practice, it won't be changed unless the
00466   // constraint is longer than one character.
00467   virtual std::string convertConstraint(const char *&Constraint) const {
00468     // 'p' defaults to 'r', but can be overridden by targets.
00469     if (*Constraint == 'p')
00470       return std::string("r");
00471     return std::string(1, *Constraint);
00472   }
00473 
00474   // Returns a string of target-specific clobbers, in LLVM format.
00475   virtual const char *getClobbers() const = 0;
00476 
00477 
00478   /// getTriple - Return the target triple of the primary target.
00479   const llvm::Triple &getTriple() const {
00480     return Triple;
00481   }
00482 
00483   const char *getTargetDescription() const {
00484     return DescriptionString;
00485   }
00486 
00487   struct GCCRegAlias {
00488     const char * const Aliases[5];
00489     const char * const Register;
00490   };
00491 
00492   struct AddlRegName {
00493     const char * const Names[5];
00494     const unsigned RegNum;
00495   };
00496 
00497   /// hasProtectedVisibility - Does this target support "protected"
00498   /// visibility?
00499   ///
00500   /// Any target which dynamic libraries will naturally support
00501   /// something like "default" (meaning that the symbol is visible
00502   /// outside this shared object) and "hidden" (meaning that it isn't)
00503   /// visibilities, but "protected" is really an ELF-specific concept
00504   /// with wierd semantics designed around the convenience of dynamic
00505   /// linker implementations.  Which is not to suggest that there's
00506   /// consistent target-independent semantics for "default" visibility
00507   /// either; the entire thing is pretty badly mangled.
00508   virtual bool hasProtectedVisibility() const { return true; }
00509 
00510   virtual bool useGlobalsForAutomaticVariables() const { return false; }
00511 
00512   /// getCFStringSection - Return the section to use for CFString
00513   /// literals, or 0 if no special section is used.
00514   virtual const char *getCFStringSection() const {
00515     return "__DATA,__cfstring";
00516   }
00517 
00518   /// getNSStringSection - Return the section to use for NSString
00519   /// literals, or 0 if no special section is used.
00520   virtual const char *getNSStringSection() const {
00521     return "__OBJC,__cstring_object,regular,no_dead_strip";
00522   }
00523 
00524   /// getNSStringNonFragileABISection - Return the section to use for
00525   /// NSString literals, or 0 if no special section is used (NonFragile ABI).
00526   virtual const char *getNSStringNonFragileABISection() const {
00527     return "__DATA, __objc_stringobj, regular, no_dead_strip";
00528   }
00529 
00530   /// isValidSectionSpecifier - This is an optional hook that targets can
00531   /// implement to perform semantic checking on attribute((section("foo")))
00532   /// specifiers.  In this case, "foo" is passed in to be checked.  If the
00533   /// section specifier is invalid, the backend should return a non-empty string
00534   /// that indicates the problem.
00535   ///
00536   /// This hook is a simple quality of implementation feature to catch errors
00537   /// and give good diagnostics in cases when the assembler or code generator
00538   /// would otherwise reject the section specifier.
00539   ///
00540   virtual std::string isValidSectionSpecifier(StringRef SR) const {
00541     return "";
00542   }
00543 
00544   /// setForcedLangOptions - Set forced language options.
00545   /// Apply changes to the target information with respect to certain
00546   /// language options which change the target configuration.
00547   virtual void setForcedLangOptions(LangOptions &Opts);
00548 
00549   /// getDefaultFeatures - Get the default set of target features for the CPU;
00550   /// this should include all legal feature strings on the target.
00551   virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const {
00552   }
00553 
00554   /// getABI - Get the ABI in use.
00555   virtual const char *getABI() const {
00556     return "";
00557   }
00558 
00559   /// getCXXABI - Get the C++ ABI in use.
00560   virtual TargetCXXABI getCXXABI() const {
00561     return CXXABI;
00562   }
00563 
00564   /// setCPU - Target the specific CPU.
00565   ///
00566   /// \return - False on error (invalid CPU name).
00567   virtual bool setCPU(const std::string &Name) {
00568     return false;
00569   }
00570 
00571   /// setABI - Use the specific ABI.
00572   ///
00573   /// \return - False on error (invalid ABI name).
00574   virtual bool setABI(const std::string &Name) {
00575     return false;
00576   }
00577 
00578   /// setCXXABI - Use this specific C++ ABI.
00579   ///
00580   /// \return - False on error (invalid C++ ABI name).
00581   bool setCXXABI(const std::string &Name) {
00582     static const TargetCXXABI Unknown = static_cast<TargetCXXABI>(-1);
00583     TargetCXXABI ABI = llvm::StringSwitch<TargetCXXABI>(Name)
00584       .Case("arm", CXXABI_ARM)
00585       .Case("itanium", CXXABI_Itanium)
00586       .Case("microsoft", CXXABI_Microsoft)
00587       .Default(Unknown);
00588     if (ABI == Unknown) return false;
00589     return setCXXABI(ABI);
00590   }
00591 
00592   /// setCXXABI - Set the C++ ABI to be used by this implementation.
00593   ///
00594   /// \return - False on error (ABI not valid on this target)
00595   virtual bool setCXXABI(TargetCXXABI ABI) {
00596     CXXABI = ABI;
00597     return true;
00598   }
00599 
00600   /// setFeatureEnabled - Enable or disable a specific target feature,
00601   /// the feature name must be valid.
00602   ///
00603   /// \return - False on error (invalid feature name).
00604   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
00605                                  StringRef Name,
00606                                  bool Enabled) const {
00607     return false;
00608   }
00609 
00610   /// HandleTargetOptions - Perform initialization based on the user configured
00611   /// set of features (e.g., +sse4). The list is guaranteed to have at most one
00612   /// entry per feature.
00613   ///
00614   /// The target may modify the features list, to change which options are
00615   /// passed onwards to the backend.
00616   virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
00617   }
00618 
00619   /// \brief Determine whether the given target has the given feature.
00620   virtual bool hasFeature(StringRef Feature) const {
00621     return false;
00622   }
00623   
00624   // getRegParmMax - Returns maximal number of args passed in registers.
00625   unsigned getRegParmMax() const {
00626     assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
00627     return RegParmMax;
00628   }
00629 
00630   /// isTLSSupported - Whether the target supports thread-local storage.
00631   bool isTLSSupported() const {
00632     return TLSSupported;
00633   }
00634 
00635   /// hasNoAsmVariants - Return true if {|} are normal characters in the
00636   /// asm string.  If this returns false (the default), then {abc|xyz} is syntax
00637   /// that says that when compiling for asm variant #0, "abc" should be
00638   /// generated, but when compiling for asm variant #1, "xyz" should be
00639   /// generated.
00640   bool hasNoAsmVariants() const {
00641     return NoAsmVariants;
00642   }
00643 
00644   /// getEHDataRegisterNumber - Return the register number that
00645   /// __builtin_eh_return_regno would return with the specified argument.
00646   virtual int getEHDataRegisterNumber(unsigned RegNo) const {
00647     return -1;
00648   }
00649 
00650   /// getStaticInitSectionSpecifier - Return the section to use for C++ static
00651   /// initialization functions.
00652   virtual const char *getStaticInitSectionSpecifier() const {
00653     return 0;
00654   }
00655 
00656   const LangAS::Map &getAddressSpaceMap() const {
00657     return *AddrSpaceMap;
00658   }
00659 
00660   /// \brief Retrieve the name of the platform as it is used in the
00661   /// availability attribute.
00662   StringRef getPlatformName() const { return PlatformName; }
00663 
00664   /// \brief Retrieve the minimum desired version of the platform, to
00665   /// which the program should be compiled.
00666   VersionTuple getPlatformMinVersion() const { return PlatformMinVersion; }
00667 
00668   bool isBigEndian() const { return BigEndian; }
00669 
00670 protected:
00671   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
00672     return PointerWidth;
00673   }
00674   virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
00675     return PointerAlign;
00676   }
00677   virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
00678     return PtrDiffType;
00679   }
00680   virtual void getGCCRegNames(const char * const *&Names,
00681                               unsigned &NumNames) const = 0;
00682   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
00683                                 unsigned &NumAliases) const = 0;
00684   virtual void getGCCAddlRegNames(const AddlRegName *&Addl,
00685           unsigned &NumAddl) const {
00686     Addl = 0;
00687     NumAddl = 0;
00688   }
00689   virtual bool validateAsmConstraint(const char *&Name,
00690                                      TargetInfo::ConstraintInfo &info) const= 0;
00691 };
00692 
00693 }  // end namespace clang
00694 
00695 #endif