TargetInfo.h revision 264a76cdf382c507f4d43e64c89f1503f003ac95
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#include "llvm/Support/DataTypes.h" 18#include <vector> 19#include <string> 20 21namespace llvm { struct fltSemantics; } 22 23namespace clang { 24 25class Diagnostic; 26class SourceManager; 27class LangOptions; 28 29namespace Builtin { struct Info; } 30 31/// TargetInfo - This class exposes information about the current target. 32/// 33class TargetInfo { 34 std::string Triple; 35protected: 36 // Target values set by the ctor of the actual target implementation. Default 37 // values are specified by the TargetInfo constructor. 38 bool CharIsSigned; 39 unsigned char PointerWidth, PointerAlign; 40 unsigned char WCharWidth, WCharAlign; 41 unsigned char IntWidth, IntAlign; 42 unsigned char FloatWidth, FloatAlign; 43 unsigned char DoubleWidth, DoubleAlign; 44 unsigned char LongDoubleWidth, LongDoubleAlign; 45 unsigned char LongWidth, LongAlign; 46 unsigned char LongLongWidth, LongLongAlign; 47 unsigned char IntMaxTWidth; 48 const char *DescriptionString; 49 const char *UserLabelPrefix; 50 const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; 51 unsigned char RegParmMax, SSERegParmMax; 52 53 // TargetInfo Constructor. Default initializes all fields. 54 TargetInfo(const std::string &T); 55 56public: 57 /// CreateTargetInfo - Return the target info object for the specified target 58 /// triple. 59 static TargetInfo* CreateTargetInfo(const std::string &Triple); 60 61 virtual ~TargetInfo(); 62 63 ///===---- Target Data Type Query Methods -------------------------------===// 64 enum IntType { 65 NoInt = 0, 66 SignedShort, 67 UnsignedShort, 68 SignedInt, 69 UnsignedInt, 70 SignedLong, 71 UnsignedLong, 72 SignedLongLong, 73 UnsignedLongLong 74 }; 75protected: 76 IntType SizeType, IntMaxType, UIntMaxType, PtrDiffType, IntPtrType, WCharType; 77public: 78 IntType getSizeType() const { return SizeType; } 79 IntType getIntMaxType() const { return IntMaxType; } 80 IntType getUIntMaxType() const { return UIntMaxType; } 81 IntType getPtrDiffType(unsigned AddrSpace) const { 82 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); 83 } 84 IntType getIntPtrType() const { return IntPtrType; } 85 IntType getWCharType() const { return WCharType; } 86 87 /// isCharSigned - Return true if 'char' is 'signed char' or false if it is 88 /// treated as 'unsigned char'. This is implementation defined according to 89 /// C99 6.2.5p15. In our implementation, this is target-specific. 90 bool isCharSigned() const { return CharIsSigned; } 91 92 /// getPointerWidth - Return the width of pointers on this target, for the 93 /// specified address space. 94 uint64_t getPointerWidth(unsigned AddrSpace) const { 95 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); 96 } 97 uint64_t getPointerAlign(unsigned AddrSpace) const { 98 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); 99 } 100 101 /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this 102 /// target, in bits. 103 unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME 104 unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME 105 106 unsigned getCharWidth(bool isWide = false) const { 107 return isWide ? getWCharWidth() : 8; // FIXME 108 } 109 unsigned getCharAlign(bool isWide = false) const { 110 return isWide ? getWCharAlign() : 8; // FIXME 111 } 112 113 /// getShortWidth/Align - Return the size of 'signed short' and 114 /// 'unsigned short' for this target, in bits. 115 unsigned getShortWidth() const { return 16; } // FIXME 116 unsigned getShortAlign() const { return 16; } // FIXME 117 118 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for 119 /// this target, in bits. 120 unsigned getIntWidth() const { return IntWidth; } 121 unsigned getIntAlign() const { return IntAlign; } 122 123 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' 124 /// for this target, in bits. 125 unsigned getLongWidth() const { return LongWidth; } 126 unsigned getLongAlign() const { return LongAlign; } 127 128 /// getLongLongWidth/Align - Return the size of 'signed long long' and 129 /// 'unsigned long long' for this target, in bits. 130 unsigned getLongLongWidth() const { return LongLongWidth; } 131 unsigned getLongLongAlign() const { return LongLongAlign; } 132 133 /// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in 134 /// bits. 135 unsigned getWCharWidth() const { return WCharWidth; } 136 unsigned getWCharAlign() const { return WCharAlign; } 137 138 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. 139 unsigned getFloatWidth() const { return FloatWidth; } 140 unsigned getFloatAlign() const { return FloatAlign; } 141 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } 142 143 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. 144 unsigned getDoubleWidth() const { return DoubleWidth; } 145 unsigned getDoubleAlign() const { return DoubleAlign; } 146 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } 147 148 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long 149 /// double'. 150 unsigned getLongDoubleWidth() const { return LongDoubleWidth; } 151 unsigned getLongDoubleAlign() const { return LongDoubleAlign; } 152 const llvm::fltSemantics &getLongDoubleFormat() const { 153 return *LongDoubleFormat; 154 } 155 156 /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this 157 /// target, in bits. 158 unsigned getIntMaxTWidth() const { 159 return IntMaxTWidth; 160 } 161 162 /// getUserLabelPrefix - This returns the default value of the 163 /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by 164 /// default. On most platforms this is "_", but it is "" on some, and "." on 165 /// others. 166 const char *getUserLabelPrefix() const { 167 return UserLabelPrefix; 168 } 169 170 /// getTypeName - Return the user string for the specified integer type enum. 171 /// For example, SignedShort -> "short". 172 static const char *getTypeName(IntType T); 173 174 ///===---- Other target property query methods --------------------------===// 175 176 /// getTargetDefines - Appends the target-specific #define values for this 177 /// target set to the specified buffer. 178 virtual void getTargetDefines(const LangOptions &Opts, 179 std::vector<char> &DefineBuffer) const = 0; 180 181 /// getTargetBuiltins - Return information about target-specific builtins for 182 /// the current primary target, and info about which builtins are non-portable 183 /// across the current set of primary and secondary targets. 184 virtual void getTargetBuiltins(const Builtin::Info *&Records, 185 unsigned &NumRecords) const = 0; 186 187 /// getVAListDeclaration - Return the declaration to use for 188 /// __builtin_va_list, which is target-specific. 189 virtual const char *getVAListDeclaration() const = 0; 190 191 /// isValidGCCRegisterName - Returns whether the passed in string 192 /// is a valid register name according to GCC. This is used by Sema for 193 /// inline asm statements. 194 bool isValidGCCRegisterName(const char *Name) const; 195 196 // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name. 197 // For example, on x86 it will return "ax" when "eax" is passed in. 198 const char *getNormalizedGCCRegisterName(const char *Name) const; 199 200 enum ConstraintInfo { 201 CI_None = 0x00, 202 CI_AllowsMemory = 0x01, 203 CI_AllowsRegister = 0x02, 204 CI_ReadWrite = 0x04 205 }; 206 207 // validateOutputConstraint, validateInputConstraint - Checks that 208 // a constraint is valid and provides information about it. 209 // FIXME: These should return a real error instead of just true/false. 210 bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const; 211 bool validateInputConstraint(const char *Name, 212 const std::string *OutputNamesBegin, 213 const std::string *OutputNamesEnd, 214 ConstraintInfo* OutputConstraints, 215 ConstraintInfo &info) const; 216 bool resolveSymbolicName(const char *&Name, 217 const std::string *OutputNamesBegin, 218 const std::string *OutputNamesEnd, 219 unsigned &Index) const; 220 221 virtual std::string convertConstraint(const char Constraint) const { 222 return std::string(1, Constraint); 223 } 224 225 // Returns a string of target-specific clobbers, in LLVM format. 226 virtual const char *getClobbers() const = 0; 227 228 229 /// getTargetPrefix - Return the target prefix used for identifying 230 /// llvm intrinsics. 231 virtual const char *getTargetPrefix() const = 0; 232 233 /// getTargetTriple - Return the target triple of the primary target. 234 const char *getTargetTriple() const { 235 return Triple.c_str(); 236 } 237 238 const char *getTargetDescription() const { 239 return DescriptionString; 240 } 241 242 struct GCCRegAlias { 243 const char * const Aliases[5]; 244 const char * const Register; 245 }; 246 247 virtual bool useGlobalsForAutomaticVariables() const { return false; } 248 249 /// getStringSymbolPrefix - Get the default symbol prefix to 250 /// use for string literals. 251 virtual const char *getStringSymbolPrefix(bool IsConstant) const { 252 return ".str"; 253 } 254 255 /// getCFStringSymbolPrefix - Get the default symbol prefix 256 /// to use for CFString literals. 257 virtual const char *getCFStringSymbolPrefix() const { 258 return ""; 259 } 260 261 /// getUnicodeStringSymbolPrefix - Get the default symbol prefix to 262 /// use for string literals. 263 virtual const char *getUnicodeStringSymbolPrefix() const { 264 return ".str"; 265 } 266 267 /// getUnicodeStringSection - Return the section to use for unicode 268 /// string literals, or 0 if no special section is used. 269 virtual const char *getUnicodeStringSection() const { 270 return 0; 271 } 272 273 /// getCFStringSection - Return the section to use for CFString 274 /// literals, or 0 if no special section is used. 275 virtual const char *getCFStringSection() const { 276 return "__DATA,__cfstring"; 277 } 278 279 /// getCFStringDataSection - Return the section to use for the 280 /// constant string data associated with a CFString literal, or 0 if 281 /// no special section is used. 282 virtual const char *getCFStringDataSection() const { 283 return "__TEXT,__cstring,cstring_literals"; 284 } 285 286 /// getDefaultLangOptions - Allow the target to specify default settings for 287 /// various language options. These may be overridden by command line 288 /// options. 289 virtual void getDefaultLangOptions(LangOptions &Opts) {} 290 291 /// HandleTargetFeatures - Handle target-specific options like -mattr=+sse2 292 /// and friends. An array of arguments is passed in: if they are all valid, 293 /// this should handle them and return -1. If there is an error, the index of 294 /// the invalid argument should be returned along with an optional error 295 /// string. 296 /// 297 /// Note that the driver should have already consolidated all the 298 /// target-feature settings and passed them to us in the -mattr list. The 299 /// -mattr list is treated by the code generator as a diff against the -mcpu 300 /// setting, but the driver should pass all enabled options as "+" settings. 301 /// This means that the target should only look at + settings. 302 virtual int HandleTargetFeatures(std::string *StrArray, unsigned NumStrs, 303 std::string &ErrorReason) { 304 if (NumStrs == 0) 305 return -1; 306 return 0; 307 } 308 309 // getRegParmMax - Returns maximal number of args passed in registers. 310 unsigned getRegParmMax() const { 311 return RegParmMax; 312 } 313 314protected: 315 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { 316 return PointerWidth; 317 } 318 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { 319 return PointerAlign; 320 } 321 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { 322 return PtrDiffType; 323 } 324 virtual void getGCCRegNames(const char * const *&Names, 325 unsigned &NumNames) const = 0; 326 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 327 unsigned &NumAliases) const = 0; 328 virtual bool validateAsmConstraint(const char *&Name, 329 TargetInfo::ConstraintInfo &info) const= 0; 330}; 331 332} // end namespace clang 333 334#endif 335