TargetInfo.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //===---- TargetInfo.h - Encapsulate target details -------------*- 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. // These classes wrap the information about a call or function
  11. // definition used to handle ABI compliancy.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
  15. #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
  16. #include "CGValue.h"
  17. #include "clang/AST/Type.h"
  18. #include "clang/Basic/LLVM.h"
  19. #include "llvm/ADT/SmallString.h"
  20. #include "llvm/ADT/StringRef.h"
  21. namespace llvm {
  22. class Constant;
  23. class GlobalValue;
  24. class Type;
  25. class Value;
  26. }
  27. namespace clang {
  28. class ABIInfo;
  29. class Decl;
  30. namespace CodeGen {
  31. class CallArgList;
  32. class CodeGenModule;
  33. class CodeGenFunction;
  34. class CGFunctionInfo;
  35. }
  36. /// TargetCodeGenInfo - This class organizes various target-specific
  37. /// codegeneration issues, like target-specific attributes, builtins and so
  38. /// on.
  39. class TargetCodeGenInfo {
  40. ABIInfo *Info;
  41. public:
  42. // WARNING: Acquires the ownership of ABIInfo.
  43. TargetCodeGenInfo(ABIInfo *info = 0) : Info(info) {}
  44. virtual ~TargetCodeGenInfo();
  45. /// getABIInfo() - Returns ABI info helper for the target.
  46. const ABIInfo &getABIInfo() const { return *Info; }
  47. /// setTargetAttributes - Provides a convenient hook to handle extra
  48. /// target-specific attributes for the given global.
  49. virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
  50. CodeGen::CodeGenModule &M) const {}
  51. /// emitTargetMD - Provides a convenient hook to handle extra
  52. /// target-specific metadata for the given global.
  53. virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
  54. CodeGen::CodeGenModule &M) const {}
  55. /// Determines the size of struct _Unwind_Exception on this platform,
  56. /// in 8-bit units. The Itanium ABI defines this as:
  57. /// struct _Unwind_Exception {
  58. /// uint64 exception_class;
  59. /// _Unwind_Exception_Cleanup_Fn exception_cleanup;
  60. /// uint64 private_1;
  61. /// uint64 private_2;
  62. /// };
  63. virtual unsigned getSizeOfUnwindException() const;
  64. /// Controls whether __builtin_extend_pointer should sign-extend
  65. /// pointers to uint64_t or zero-extend them (the default). Has
  66. /// no effect for targets:
  67. /// - that have 64-bit pointers, or
  68. /// - that cannot address through registers larger than pointers, or
  69. /// - that implicitly ignore/truncate the top bits when addressing
  70. /// through such registers.
  71. virtual bool extendPointerWithSExt() const { return false; }
  72. /// Determines the DWARF register number for the stack pointer, for
  73. /// exception-handling purposes. Implements __builtin_dwarf_sp_column.
  74. ///
  75. /// Returns -1 if the operation is unsupported by this target.
  76. virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
  77. return -1;
  78. }
  79. /// Initializes the given DWARF EH register-size table, a char*.
  80. /// Implements __builtin_init_dwarf_reg_size_table.
  81. ///
  82. /// Returns true if the operation is unsupported by this target.
  83. virtual bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
  84. llvm::Value *Address) const {
  85. return true;
  86. }
  87. /// Performs the code-generation required to convert a return
  88. /// address as stored by the system into the actual address of the
  89. /// next instruction that will be executed.
  90. ///
  91. /// Used by __builtin_extract_return_addr().
  92. virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
  93. llvm::Value *Address) const {
  94. return Address;
  95. }
  96. /// Performs the code-generation required to convert the address
  97. /// of an instruction into a return address suitable for storage
  98. /// by the system in a return slot.
  99. ///
  100. /// Used by __builtin_frob_return_addr().
  101. virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
  102. llvm::Value *Address) const {
  103. return Address;
  104. }
  105. /// Corrects the low-level LLVM type for a given constraint and "usual"
  106. /// type.
  107. ///
  108. /// \returns A pointer to a new LLVM type, possibly the same as the original
  109. /// on success; 0 on failure.
  110. virtual llvm::Type *adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
  111. StringRef Constraint,
  112. llvm::Type *Ty) const {
  113. return Ty;
  114. }
  115. /// Adds constraints and types for result registers.
  116. virtual void addReturnRegisterOutputs(
  117. CodeGen::CodeGenFunction &CGF, CodeGen::LValue ReturnValue,
  118. std::string &Constraints, std::vector<llvm::Type *> &ResultRegTypes,
  119. std::vector<llvm::Type *> &ResultTruncRegTypes,
  120. std::vector<CodeGen::LValue> &ResultRegDests, std::string &AsmString,
  121. unsigned NumOutputs) const {}
  122. /// doesReturnSlotInterfereWithArgs - Return true if the target uses an
  123. /// argument slot for an 'sret' type.
  124. virtual bool doesReturnSlotInterfereWithArgs() const { return true; }
  125. /// Retrieve the address of a function to call immediately before
  126. /// calling objc_retainAutoreleasedReturnValue. The
  127. /// implementation of objc_autoreleaseReturnValue sniffs the
  128. /// instruction stream following its return address to decide
  129. /// whether it's a call to objc_retainAutoreleasedReturnValue.
  130. /// This can be prohibitively expensive, depending on the
  131. /// relocation model, and so on some targets it instead sniffs for
  132. /// a particular instruction sequence. This functions returns
  133. /// that instruction sequence in inline assembly, which will be
  134. /// empty if none is required.
  135. virtual StringRef getARCRetainAutoreleasedReturnValueMarker() const {
  136. return "";
  137. }
  138. /// Return a constant used by UBSan as a signature to identify functions
  139. /// possessing type information, or 0 if the platform is unsupported.
  140. virtual llvm::Constant *
  141. getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const {
  142. return nullptr;
  143. }
  144. /// Determine whether a call to an unprototyped functions under
  145. /// the given calling convention should use the variadic
  146. /// convention or the non-variadic convention.
  147. ///
  148. /// There's a good reason to make a platform's variadic calling
  149. /// convention be different from its non-variadic calling
  150. /// convention: the non-variadic arguments can be passed in
  151. /// registers (better for performance), and the variadic arguments
  152. /// can be passed on the stack (also better for performance). If
  153. /// this is done, however, unprototyped functions *must* use the
  154. /// non-variadic convention, because C99 states that a call
  155. /// through an unprototyped function type must succeed if the
  156. /// function was defined with a non-variadic prototype with
  157. /// compatible parameters. Therefore, splitting the conventions
  158. /// makes it impossible to call a variadic function through an
  159. /// unprototyped type. Since function prototypes came out in the
  160. /// late 1970s, this is probably an acceptable trade-off.
  161. /// Nonetheless, not all platforms are willing to make it, and in
  162. /// particularly x86-64 bends over backwards to make the
  163. /// conventions compatible.
  164. ///
  165. /// The default is false. This is correct whenever:
  166. /// - the conventions are exactly the same, because it does not
  167. /// matter and the resulting IR will be somewhat prettier in
  168. /// certain cases; or
  169. /// - the conventions are substantively different in how they pass
  170. /// arguments, because in this case using the variadic convention
  171. /// will lead to C99 violations.
  172. ///
  173. /// However, some platforms make the conventions identical except
  174. /// for passing additional out-of-band information to a variadic
  175. /// function: for example, x86-64 passes the number of SSE
  176. /// arguments in %al. On these platforms, it is desirable to
  177. /// call unprototyped functions using the variadic convention so
  178. /// that unprototyped calls to varargs functions still succeed.
  179. ///
  180. /// Relatedly, platforms which pass the fixed arguments to this:
  181. /// A foo(B, C, D);
  182. /// differently than they would pass them to this:
  183. /// A foo(B, C, D, ...);
  184. /// may need to adjust the debugger-support code in Sema to do the
  185. /// right thing when calling a function with no know signature.
  186. virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args,
  187. const FunctionNoProtoType *fnType) const;
  188. /// Gets the linker options necessary to link a dependent library on this
  189. /// platform.
  190. virtual void getDependentLibraryOption(llvm::StringRef Lib,
  191. llvm::SmallString<24> &Opt) const;
  192. /// Gets the linker options necessary to detect object file mismatches on
  193. /// this platform.
  194. virtual void getDetectMismatchOption(llvm::StringRef Name,
  195. llvm::StringRef Value,
  196. llvm::SmallString<32> &Opt) const {}
  197. };
  198. }
  199. #endif