zcov: / include/clang/Basic/TargetInfo.h


Files: 1 Branches Taken: 42.9% 3 / 7
Generated: 2010-02-10 01:31 Branches Executed: 57.1% 4 / 7
Line Coverage: 84.6% 88 / 104


Programs: 51 Runs 100555


       1                 : //===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : //  This file defines the TargetInfo interface.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_BASIC_TARGETINFO_H
      15                 : #define LLVM_CLANG_BASIC_TARGETINFO_H
      16                 : 
      17                 : // FIXME: Daniel isn't smart enough to use a prototype for this.
      18                 : #include "llvm/ADT/StringMap.h"
      19                 : #include "llvm/ADT/Triple.h"
      20                 : #include "llvm/System/DataTypes.h"
      21                 : #include <cassert>
      22                 : #include <vector>
      23                 : #include <string>
      24                 : 
      25                 : namespace llvm {
      26                 : struct fltSemantics;
      27                 : class StringRef;
      28                 : }
      29                 : 
      30                 : namespace clang {
      31                 : class Diagnostic;
      32                 : class LangOptions;
      33                 : class MacroBuilder;
      34                 : class SourceLocation;
      35                 : class SourceManager;
      36                 : class TargetOptions;
      37                 : 
      38                 : namespace Builtin { struct Info; }
      39                 : 
      40                 : /// TargetInfo - This class exposes information about the current target.
      41                 : ///
      42                 : class TargetInfo {
      43                 :   llvm::Triple Triple;
      44                 : protected:
      45                 :   // Target values set by the ctor of the actual target implementation.  Default
      46                 :   // values are specified by the TargetInfo constructor.
      47                 :   bool TLSSupported;
      48                 :   unsigned char PointerWidth, PointerAlign;
      49                 :   unsigned char IntWidth, IntAlign;
      50                 :   unsigned char FloatWidth, FloatAlign;
      51                 :   unsigned char DoubleWidth, DoubleAlign;
      52                 :   unsigned char LongDoubleWidth, LongDoubleAlign;
      53                 :   unsigned char LongWidth, LongAlign;
      54                 :   unsigned char LongLongWidth, LongLongAlign;
      55                 :   const char *DescriptionString;
      56                 :   const char *UserLabelPrefix;
      57                 :   const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat;
      58                 :   unsigned char RegParmMax, SSERegParmMax;
      59                 : 
      60                 :   // TargetInfo Constructor.  Default initializes all fields.
      61                 :   TargetInfo(const std::string &T);
      62                 : 
      63                 : public:
      64                 :   /// CreateTargetInfo - Construct a target for the given options.
      65                 :   ///
      66                 :   /// \param Opts - The options to use to initialize the target. The target may
      67                 :   /// modify the options to canonicalize the target feature information to match
      68                 :   /// what the backend expects.
      69                 :   static TargetInfo* CreateTargetInfo(Diagnostic &Diags, TargetOptions &Opts);
      70                 : 
      71                 :   virtual ~TargetInfo();
      72                 : 
      73                 :   ///===---- Target Data Type Query Methods -------------------------------===//
      74                 :   enum IntType {
      75                 :     NoInt = 0,
      76                 :     SignedShort,
      77                 :     UnsignedShort,
      78                 :     SignedInt,
      79                 :     UnsignedInt,
      80                 :     SignedLong,
      81                 :     UnsignedLong,
      82                 :     SignedLongLong,
      83                 :     UnsignedLongLong
      84                 :   };
      85                 : protected:
      86                 :   IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType,
      87                 :           WIntType, Char16Type, Char32Type, Int64Type, SigAtomicType;
      88                 : public:
      89             6822:   IntType getSizeType() const { return SizeType; }
      90             7557:   IntType getIntMaxType() const { return IntMaxType; }
      91             2519:   IntType getUIntMaxType() const { return UIntMaxType; }
      92             5833:   IntType getPtrDiffType(unsigned AddrSpace) const {
                     5833: branch 0 taken
                        0: branch 1 not taken
      93             5833:     return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
      94                 :   }
      95             5038:   IntType getIntPtrType() const { return IntPtrType; }
      96             8959:   IntType getWCharType() const { return WCharType; }
      97             5038:   IntType getWIntType() const { return WIntType; }
      98             1402:   IntType getChar16Type() const { return Char16Type; }
      99             1402:   IntType getChar32Type() const { return Char32Type; }
     100                 :   IntType getInt64Type() const { return Int64Type; }
     101             2519:   IntType getSigAtomicType() const { return SigAtomicType; }
     102                 : 
     103                 : 
     104                 :   /// getTypeWidth - Return the width (in bits) of the specified integer type 
     105                 :   /// enum. For example, SignedInt -> getIntWidth().
     106                 :   unsigned getTypeWidth(IntType T) const;
     107                 : 
     108                 :   /// getTypeAlign - Return the alignment (in bits) of the specified integer
     109                 :   /// type enum. For example, SignedInt -> getIntAlign().
     110                 :   unsigned getTypeAlign(IntType T) const;
     111                 : 
     112                 :   /// isTypeSigned - Return whether an integer types is signed. Returns true if
     113                 :   /// the type is signed; false otherwise.
     114                 :   bool isTypeSigned(IntType T) const;
     115                 : 
     116                 :   /// getPointerWidth - Return the width of pointers on this target, for the
     117                 :   /// specified address space.
     118            36245:   uint64_t getPointerWidth(unsigned AddrSpace) const {
                    36145: branch 0 taken
                      100: branch 1 taken
     119            36245:     return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
     120                 :   }
     121            16603:   uint64_t getPointerAlign(unsigned AddrSpace) const {
                        0: branch 1 not taken
     122            16603:     return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
     123                 :   }
     124                 : 
     125                 :   /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
     126                 :   /// target, in bits.
     127              564:   unsigned getBoolWidth(bool isWide = false) const { return 8; }  // FIXME
     128              564:   unsigned getBoolAlign(bool isWide = false) const { return 8; }  // FIXME
     129                 : 
     130            26142:   unsigned getCharWidth() const { return 8; } // FIXME
     131            11078:   unsigned getCharAlign() const { return 8; } // FIXME
     132                 : 
     133                 :   /// getShortWidth/Align - Return the size of 'signed short' and
     134                 :   /// 'unsigned short' for this target, in bits.
     135            13508:   unsigned getShortWidth() const { return 16; } // FIXME
     136             2767:   unsigned getShortAlign() const { return 16; } // FIXME
     137                 : 
     138                 :   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
     139                 :   /// this target, in bits.
     140           105197:   unsigned getIntWidth() const { return IntWidth; }
     141            58841:   unsigned getIntAlign() const { return IntAlign; }
     142                 : 
     143                 :   /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
     144                 :   /// for this target, in bits.
     145            17805:   unsigned getLongWidth() const { return LongWidth; }
     146             7641:   unsigned getLongAlign() const { return LongAlign; }
     147                 : 
     148                 :   /// getLongLongWidth/Align - Return the size of 'signed long long' and
     149                 :   /// 'unsigned long long' for this target, in bits.
     150            21764:   unsigned getLongLongWidth() const { return LongLongWidth; }
     151             4829:   unsigned getLongLongAlign() const { return LongLongAlign; }
     152                 : 
     153                 :   /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in
     154                 :   /// bits.
     155              235:   unsigned getWCharWidth() const { return getTypeWidth(WCharType); }
     156                8:   unsigned getWCharAlign() const { return getTypeAlign(WCharType); }
     157                 : 
     158                 :   /// getChar16Width/Align - Return the size of 'char16_t' for this target, in
     159                 :   /// bits.
     160                0:   unsigned getChar16Width() const { return getTypeWidth(Char16Type); }
     161                0:   unsigned getChar16Align() const { return getTypeAlign(Char16Type); }
     162                 : 
     163                 :   /// getChar32Width/Align - Return the size of 'char32_t' for this target, in
     164                 :   /// bits.
     165                0:   unsigned getChar32Width() const { return getTypeWidth(Char32Type); }
     166                0:   unsigned getChar32Align() const { return getTypeAlign(Char32Type); }
     167                 : 
     168                 :   /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
     169              768:   unsigned getFloatWidth() const { return FloatWidth; }
     170              768:   unsigned getFloatAlign() const { return FloatAlign; }
     171             3076:   const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; }
     172                 : 
     173                 :   /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
     174              550:   unsigned getDoubleWidth() const { return DoubleWidth; }
     175              550:   unsigned getDoubleAlign() const { return DoubleAlign; }
     176             3395:   const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; }
     177                 : 
     178                 :   /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
     179                 :   /// double'.
     180              118:   unsigned getLongDoubleWidth() const { return LongDoubleWidth; }
     181              118:   unsigned getLongDoubleAlign() const { return LongDoubleAlign; }
     182             5094:   const llvm::fltSemantics &getLongDoubleFormat() const {
     183             5094:     return *LongDoubleFormat;
     184                 :   }
     185                 : 
     186                 :   /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
     187                 :   /// target, in bits.
     188             5855:   unsigned getIntMaxTWidth() const {
     189             5855:     return getTypeWidth(IntMaxType);
     190                 :   }
     191                 : 
     192                 :   /// getUserLabelPrefix - This returns the default value of the
     193                 :   /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by
     194                 :   /// default.  On most platforms this is "_", but it is "" on some, and "." on
     195                 :   /// others.
     196             2519:   const char *getUserLabelPrefix() const {
     197             2519:     return UserLabelPrefix;
     198                 :   }
     199                 : 
     200                 :   /// getTypeName - Return the user string for the specified integer type enum.
     201                 :   /// For example, SignedShort -> "short".
     202                 :   static const char *getTypeName(IntType T);
     203                 : 
     204                 :   /// getTypeConstantSuffix - Return the constant suffix for the specified
     205                 :   /// integer type enum. For example, SignedLong -> "L".
     206                 :   static const char *getTypeConstantSuffix(IntType T);
     207                 : 
     208                 :   ///===---- Other target property query methods --------------------------===//
     209                 : 
     210                 :   /// getTargetDefines - Appends the target-specific #define values for this
     211                 :   /// target set to the specified buffer.
     212                 :   virtual void getTargetDefines(const LangOptions &Opts,
     213                 :                                 MacroBuilder &Builder) const = 0;
     214                 : 
     215                 : 
     216                 :   /// getTargetBuiltins - Return information about target-specific builtins for
     217                 :   /// the current primary target, and info about which builtins are non-portable
     218                 :   /// across the current set of primary and secondary targets.
     219                 :   virtual void getTargetBuiltins(const Builtin::Info *&Records,
     220                 :                                  unsigned &NumRecords) const = 0;
     221                 : 
     222                 :   /// getVAListDeclaration - Return the declaration to use for
     223                 :   /// __builtin_va_list, which is target-specific.
     224                 :   virtual const char *getVAListDeclaration() const = 0;
     225                 : 
     226                 :   /// isValidGCCRegisterName - Returns whether the passed in string
     227                 :   /// is a valid register name according to GCC. This is used by Sema for
     228                 :   /// inline asm statements.
     229                 :   bool isValidGCCRegisterName(llvm::StringRef Name) const;
     230                 : 
     231                 :   // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name.
     232                 :   // For example, on x86 it will return "ax" when "eax" is passed in.
     233                 :   llvm::StringRef getNormalizedGCCRegisterName(llvm::StringRef Name) const;
     234                 : 
     235              386:   struct ConstraintInfo {
     236                 :     enum {
     237                 :       CI_None = 0x00,
     238                 :       CI_AllowsMemory = 0x01,
     239                 :       CI_AllowsRegister = 0x02,
     240                 :       CI_ReadWrite = 0x04,       // "+r" output constraint (read and write).
     241                 :       CI_HasMatchingInput = 0x08 // This output operand has a matching input.
     242                 :     };
     243                 :     unsigned Flags;
     244                 :     int TiedOperand;
     245                 : 
     246                 :     std::string ConstraintStr;  // constraint: "=rm"
     247                 :     std::string Name;           // Operand name: [foo] with no []'s.
     248                 :   public:
     249              130:     ConstraintInfo(llvm::StringRef ConstraintStr, llvm::StringRef Name)
     250                 :       : Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()), 
     251              130:       Name(Name.str()) {}
     252                 : 
     253               65:     const std::string &getConstraintStr() const { return ConstraintStr; }
     254                4:     const std::string &getName() const { return Name; }
     255               21:     bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
     256               98:     bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
     257               77:     bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
     258                 : 
     259                 :     /// hasMatchingInput - Return true if this output operand has a matching
     260                 :     /// (tied) input operand.
     261               18:     bool hasMatchingInput() const { return (Flags & CI_HasMatchingInput) != 0; }
     262                 : 
     263                 :     /// hasTiedOperand() - Return true if this input operand is a matching
     264                 :     /// constraint that ties it to an output operand.  If this returns true,
     265                 :     /// then getTiedOperand will indicate which output operand this is tied to.
     266               83:     bool hasTiedOperand() const { return TiedOperand != -1; }
     267               16:     unsigned getTiedOperand() const {
                        0: branch 1 not taken
                        0: branch 2 not taken
     268               16:       assert(hasTiedOperand() && "Has no tied operand!");
     269               16:       return (unsigned)TiedOperand;
     270                 :     }
     271                 : 
     272               18:     void setIsReadWrite() { Flags |= CI_ReadWrite; }
     273               22:     void setAllowsMemory() { Flags |= CI_AllowsMemory; }
     274               86:     void setAllowsRegister() { Flags |= CI_AllowsRegister; }
     275               11:     void setHasMatchingInput() { Flags |= CI_HasMatchingInput; }
     276                 : 
     277                 :     /// setTiedOperand - Indicate that this is an input operand that is tied to
     278                 :     /// the specified output operand.  Copy over the various constraint
     279                 :     /// information from the output.
     280               11:     void setTiedOperand(unsigned N, ConstraintInfo &Output) {
     281               11:       Output.setHasMatchingInput();
     282               11:       Flags = Output.Flags;
     283               11:       TiedOperand = N;
     284                 :       // Don't copy Name or constraint string.
     285               11:     }
     286                 :   };
     287                 : 
     288                 :   // validateOutputConstraint, validateInputConstraint - Checks that
     289                 :   // a constraint is valid and provides information about it.
     290                 :   // FIXME: These should return a real error instead of just true/false.
     291                 :   bool validateOutputConstraint(ConstraintInfo &Info) const;
     292                 :   bool validateInputConstraint(ConstraintInfo *OutputConstraints,
     293                 :                                unsigned NumOutputs,
     294                 :                                ConstraintInfo &info) const;
     295                 :   bool resolveSymbolicName(const char *&Name,
     296                 :                            ConstraintInfo *OutputConstraints,
     297                 :                            unsigned NumOutputs, unsigned &Index) const;
     298                 : 
     299                0:   virtual std::string convertConstraint(const char Constraint) const {
     300                0:     return std::string(1, Constraint);
     301                 :   }
     302                 : 
     303                 :   // Returns a string of target-specific clobbers, in LLVM format.
     304                 :   virtual const char *getClobbers() const = 0;
     305                 : 
     306                 : 
     307                 :   /// getTriple - Return the target triple of the primary target.
     308             6591:   const llvm::Triple &getTriple() const {
     309             6591:     return Triple;
     310                 :   }
     311                 : 
     312             1875:   const char *getTargetDescription() const {
     313             1875:     return DescriptionString;
     314                 :   }
     315                 : 
     316                 :   struct GCCRegAlias {
     317                 :     const char * const Aliases[5];
     318                 :     const char * const Register;
     319                 :   };
     320                 : 
     321             1256:   virtual bool useGlobalsForAutomaticVariables() const { return false; }
     322                 : 
     323                 :   /// getCFStringSection - Return the section to use for CFString
     324                 :   /// literals, or 0 if no special section is used.
     325               79:   virtual const char *getCFStringSection() const {
     326               79:     return "__DATA,__cfstring";
     327                 :   }
     328                 : 
     329                 :   /// isValidSectionSpecifier - This is an optional hook that targets can
     330                 :   /// implement to perform semantic checking on attribute((section("foo")))
     331                 :   /// specifiers.  In this case, "foo" is passed in to be checked.  If the
     332                 :   /// section specifier is invalid, the backend should return a non-empty string
     333                 :   /// that indicates the problem.
     334                 :   ///
     335                 :   /// This hook is a simple quality of implementation feature to catch errors
     336                 :   /// and give good diagnostics in cases when the assembler or code generator
     337                 :   /// would otherwise reject the section specifier.
     338                 :   ///
     339                6:   virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const {
     340                6:     return "";
     341                 :   }
     342                 : 
     343                 :   /// setForcedLangOptions - Set forced language options.
     344                 :   /// Apply changes to the target information with respect to certain
     345                 :   /// language options which change the target configuration.
     346                 :   virtual void setForcedLangOptions(LangOptions &Opts);
     347                 : 
     348                 :   /// getDefaultFeatures - Get the default set of target features for
     349                 :   /// the \args CPU; this should include all legal feature strings on
     350                 :   /// the target.
     351                 :   virtual void getDefaultFeatures(const std::string &CPU,
     352               28:                                   llvm::StringMap<bool> &Features) const {
     353               28:   }
     354                 : 
     355                 :   /// getABI - Get the ABI in use.
     356                0:   virtual const char *getABI() const {
     357                0:     return "";
     358                 :   }
     359                 : 
     360                 :   /// setCPU - Target the specific CPU.
     361                 :   ///
     362                 :   /// \return - False on error (invalid CPU name).
     363                 :   //
     364                 :   // FIXME: Remove this.
     365              149:   virtual bool setCPU(const std::string &Name) {
     366              149:     return true;
     367                 :   }
     368                 : 
     369                 :   /// setABI - Use the specific ABI.
     370                 :   ///
     371                 :   /// \return - False on error (invalid ABI name).
     372                0:   virtual bool setABI(const std::string &Name) {
     373                0:     return false;
     374                 :   }
     375                 : 
     376                 :   /// setFeatureEnabled - Enable or disable a specific target feature,
     377                 :   /// the feature name must be valid.
     378                 :   ///
     379                 :   /// \return - False on error (invalid feature name).
     380                 :   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
     381                 :                                  const std::string &Name,
     382                0:                                  bool Enabled) const {
     383                0:     return false;
     384                 :   }
     385                 : 
     386                 :   /// HandleTargetOptions - Perform initialization based on the user configured
     387                 :   /// set of features (e.g., +sse4). The list is guaranteed to have at most one
     388                 :   /// entry per feature.
     389                 :   ///
     390                 :   /// The target may modify the features list, to change which options are
     391                 :   /// passed onwards to the backend.
     392               28:   virtual void HandleTargetFeatures(std::vector<std::string> &Features) {
     393               28:   }
     394                 : 
     395                 :   // getRegParmMax - Returns maximal number of args passed in registers.
     396               12:   unsigned getRegParmMax() const {
     397               12:     return RegParmMax;
     398                 :   }
     399                 : 
     400                 :   /// isTLSSupported - Whether the target supports thread-local storage.
     401               13:   bool isTLSSupported() const {
     402               13:     return TLSSupported;
     403                 :   }
     404                 :   
     405                 :   /// getEHDataRegisterNumber - Return the register number that
     406                 :   /// __builtin_eh_return_regno would return with the specified argument.
     407                0:   virtual int getEHDataRegisterNumber(unsigned RegNo) const {
     408                0:     return -1; 
     409                 :   }
     410                 :   
     411                 : 
     412                 : protected:
     413              100:   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
     414              100:     return PointerWidth;
     415                 :   }
     416               23:   virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
     417               23:     return PointerAlign;
     418                 :   }
     419                0:   virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const {
     420                0:     return PtrDiffType;
     421                 :   }
     422                 :   virtual void getGCCRegNames(const char * const *&Names,
     423                 :                               unsigned &NumNames) const = 0;
     424                 :   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
     425                 :                                 unsigned &NumAliases) const = 0;
     426                 :   virtual bool validateAsmConstraint(const char *&Name,
     427                 :                                      TargetInfo::ConstraintInfo &info) const= 0;
     428                 : };
     429                 : 
     430                 : }  // end namespace clang
     431                 : 
     432                 : #endif

Generated: 2010-02-10 01:31 by zcov