TargetInfo.h revision 31fc07df7f0fc89ebf83ca05a20b29de45a7598d
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; 27 28namespace Builtin { struct Info; } 29 30/// TargetInfo - This class exposes information about the current target. 31/// 32class TargetInfo { 33 std::string Triple; 34protected: 35 // Target values set by the ctor of the actual target implementation. Default 36 // values are specified by the TargetInfo constructor. 37 bool CharIsSigned; 38 unsigned char PointerWidth, PointerAlign; 39 unsigned char WCharWidth, WCharAlign; 40 unsigned char IntWidth, IntAlign; 41 unsigned char FloatWidth, FloatAlign; 42 unsigned char DoubleWidth, DoubleAlign; 43 unsigned char LongDoubleWidth, LongDoubleAlign; 44 unsigned char LongWidth, LongAlign; 45 unsigned char LongLongWidth, LongLongAlign; 46 const char *DescriptionString; 47 const char *UserLabelPrefix; 48 const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; 49 50 // TargetInfo Constructor. Default initializes all fields. 51 TargetInfo(const std::string &T); 52 53public: 54 /// CreateTargetInfo - Return the target info object for the specified target 55 /// triple. 56 static TargetInfo* CreateTargetInfo(const std::string &Triple); 57 58 virtual ~TargetInfo(); 59 60 ///===---- Target Data Type Query Methods -------------------------------===// 61 enum IntType { 62 NoInt = 0x0, 63 SignedShort, 64 UnsignedShort, 65 SignedInt, 66 UnsignedInt, 67 SignedLong, 68 UnsignedLong, 69 SignedLongLong, 70 UnsignedLongLong 71 } SizeType, IntMaxType, UIntMaxType, PtrDiffType, WCharType; 72 enum IntType getSizeType() const {return SizeType;} 73 enum IntType getIntMaxType() const {return IntMaxType;} 74 enum IntType getUIntMaxType() const {return UIntMaxType;} 75 enum IntType getPtrDiffType(unsigned AddrSpace) const { 76 return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace); 77 } 78 enum IntType getWCharType() const {return WCharType;} 79 80 /// isCharSigned - Return true if 'char' is 'signed char' or false if it is 81 /// treated as 'unsigned char'. This is implementation defined according to 82 /// C99 6.2.5p15. In our implementation, this is target-specific. 83 bool isCharSigned() const { return CharIsSigned; } 84 85 /// getPointerWidth - Return the width of pointers on this target, for the 86 /// specified address space. 87 uint64_t getPointerWidth(unsigned AddrSpace) const { 88 return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace); 89 } 90 uint64_t getPointerAlign(unsigned AddrSpace) const { 91 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); 92 } 93 94 /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this 95 /// target, in bits. 96 unsigned getBoolWidth(bool isWide = false) const { return 8; } // FIXME 97 unsigned getBoolAlign(bool isWide = false) const { return 8; } // FIXME 98 99 unsigned getCharWidth(bool isWide = false) const { 100 return isWide ? getWCharWidth() : 8; // FIXME 101 } 102 unsigned getCharAlign(bool isWide = false) const { 103 return isWide ? getWCharAlign() : 8; // FIXME 104 } 105 106 /// getShortWidth/Align - Return the size of 'signed short' and 107 /// 'unsigned short' for this target, in bits. 108 unsigned getShortWidth() const { return 16; } // FIXME 109 unsigned getShortAlign() const { return 16; } // FIXME 110 111 /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for 112 /// this target, in bits. 113 unsigned getIntWidth() const { return IntWidth; } 114 unsigned getIntAlign() const { return IntAlign; } 115 116 /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' 117 /// for this target, in bits. 118 unsigned getLongWidth() const { return LongWidth; } 119 unsigned getLongAlign() const { return LongAlign; } 120 121 /// getLongLongWidth/Align - Return the size of 'signed long long' and 122 /// 'unsigned long long' for this target, in bits. 123 unsigned getLongLongWidth() const { return LongLongWidth; } 124 unsigned getLongLongAlign() const { return LongLongAlign; } 125 126 /// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in 127 /// bits. 128 unsigned getWCharWidth() const { return WCharWidth; } 129 unsigned getWCharAlign() const { return WCharAlign; } 130 131 /// getFloatWidth/Align/Format - Return the size/align/format of 'float'. 132 unsigned getFloatWidth() const { return FloatWidth; } 133 unsigned getFloatAlign() const { return FloatAlign; } 134 const llvm::fltSemantics &getFloatFormat() const { return *FloatFormat; } 135 136 /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'. 137 unsigned getDoubleWidth() const { return DoubleWidth; } 138 unsigned getDoubleAlign() const { return DoubleAlign; } 139 const llvm::fltSemantics &getDoubleFormat() const { return *DoubleFormat; } 140 141 /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long 142 /// double'. 143 unsigned getLongDoubleWidth() const { return LongDoubleWidth; } 144 unsigned getLongDoubleAlign() const { return LongDoubleAlign; } 145 const llvm::fltSemantics &getLongDoubleFormat() const { 146 return *LongDoubleFormat; 147 } 148 149 /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this 150 /// target, in bits. 151 unsigned getIntMaxTWidth() const { 152 // FIXME: implement correctly. 153 return 64; 154 } 155 156 /// getUserLabelPrefix - This returns the default value of the 157 /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by 158 /// default. On most platforms this is "_", but it is "" on some, and "." on 159 /// others. 160 const char *getUserLabelPrefix() const { 161 return UserLabelPrefix; 162 } 163 164 ///===---- Other target property query methods --------------------------===// 165 166 /// getTargetDefines - Appends the target-specific #define values for this 167 /// target set to the specified buffer. 168 virtual void getTargetDefines(std::vector<char> &DefineBuffer) const = 0; 169 170 /// getTargetBuiltins - Return information about target-specific builtins for 171 /// the current primary target, and info about which builtins are non-portable 172 /// across the current set of primary and secondary targets. 173 virtual void getTargetBuiltins(const Builtin::Info *&Records, 174 unsigned &NumRecords) const = 0; 175 176 /// getVAListDeclaration - Return the declaration to use for 177 /// __builtin_va_list, which is target-specific. 178 virtual const char *getVAListDeclaration() const = 0; 179 180 /// isValidGCCRegisterName - Returns whether the passed in string 181 /// is a valid register name according to GCC. This is used by Sema for 182 /// inline asm statements. 183 bool isValidGCCRegisterName(const char *Name) const; 184 185 // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name. 186 // For example, on x86 it will return "ax" when "eax" is passed in. 187 const char *getNormalizedGCCRegisterName(const char *Name) const; 188 189 enum ConstraintInfo { 190 CI_None = 0x00, 191 CI_AllowsMemory = 0x01, 192 CI_AllowsRegister = 0x02, 193 CI_ReadWrite = 0x04 194 }; 195 196 // validateOutputConstraint, validateInputConstraint - Checks that 197 // a constraint is valid and provides information about it. 198 // FIXME: These should return a real error instead of just true/false. 199 bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const; 200 bool validateInputConstraint (const char *Name, unsigned NumOutputs, 201 ConstraintInfo &info) const; 202 203 virtual std::string convertConstraint(const char Constraint) const { 204 return std::string(1, Constraint); 205 } 206 207 // Returns a string of target-specific clobbers, in LLVM format. 208 virtual const char *getClobbers() const = 0; 209 210 211 /// getTargetPrefix - Return the target prefix used for identifying 212 /// llvm intrinsics. 213 virtual const char *getTargetPrefix() const = 0; 214 215 /// getTargetTriple - Return the target triple of the primary target. 216 const char *getTargetTriple() const { 217 return Triple.c_str(); 218 } 219 220 const char *getTargetDescription() const { 221 return DescriptionString; 222 } 223 224 struct GCCRegAlias { 225 const char * const Aliases[5]; 226 const char * const Register; 227 }; 228 229 virtual bool useGlobalsForAutomaticVariables() const { return false; } 230 231 virtual bool useNeXTRuntimeAsDefault() const { return false; } 232 233protected: 234 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { 235 return PointerWidth; 236 } 237 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { 238 return PointerAlign; 239 } 240 virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { 241 return PtrDiffType; 242 } 243 virtual void getGCCRegNames(const char * const *&Names, 244 unsigned &NumNames) const = 0; 245 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 246 unsigned &NumAliases) const = 0; 247 virtual bool validateAsmConstraint(char c, 248 TargetInfo::ConstraintInfo &info) const= 0; 249}; 250 251} // end namespace clang 252 253#endif 254