Target.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
  7. /* */
  8. /* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
  9. /* Exceptions. */
  10. /* See https://llvm.org/LICENSE.txt for license information. */
  11. /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
  12. /* */
  13. /*===----------------------------------------------------------------------===*/
  14. /* */
  15. /* This header declares the C interface to libLLVMTarget.a, which */
  16. /* implements target information. */
  17. /* */
  18. /* Many exotic languages can interoperate with C code but have a harder time */
  19. /* with C++ due to name mangling. So in addition to C, this interface enables */
  20. /* tools written in such languages. */
  21. /* */
  22. /*===----------------------------------------------------------------------===*/
  23. #ifndef LLVM_C_TARGET_H
  24. #define LLVM_C_TARGET_H
  25. #include "llvm-c/ExternC.h"
  26. #include "llvm-c/Types.h"
  27. #include "llvm/Config/llvm-config.h"
  28. LLVM_C_EXTERN_C_BEGIN
  29. /**
  30. * @defgroup LLVMCTarget Target information
  31. * @ingroup LLVMC
  32. *
  33. * @{
  34. */
  35. enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
  36. typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
  37. typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
  38. /* Declare all of the target-initialization functions that are available. */
  39. #define LLVM_TARGET(TargetName) \
  40. void LLVMInitialize##TargetName##TargetInfo(void);
  41. #include "llvm/Config/Targets.def"
  42. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  43. #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
  44. #include "llvm/Config/Targets.def"
  45. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  46. #define LLVM_TARGET(TargetName) \
  47. void LLVMInitialize##TargetName##TargetMC(void);
  48. #include "llvm/Config/Targets.def"
  49. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  50. /* Declare all of the available assembly printer initialization functions. */
  51. #define LLVM_ASM_PRINTER(TargetName) \
  52. void LLVMInitialize##TargetName##AsmPrinter(void);
  53. #include "llvm/Config/AsmPrinters.def"
  54. #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
  55. /* Declare all of the available assembly parser initialization functions. */
  56. #define LLVM_ASM_PARSER(TargetName) \
  57. void LLVMInitialize##TargetName##AsmParser(void);
  58. #include "llvm/Config/AsmParsers.def"
  59. #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
  60. /* Declare all of the available disassembler initialization functions. */
  61. #define LLVM_DISASSEMBLER(TargetName) \
  62. void LLVMInitialize##TargetName##Disassembler(void);
  63. #include "llvm/Config/Disassemblers.def"
  64. #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
  65. /** LLVMInitializeAllTargetInfos - The main program should call this function if
  66. it wants access to all available targets that LLVM is configured to
  67. support. */
  68. static inline void LLVMInitializeAllTargetInfos(void) {
  69. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
  70. #include "llvm/Config/Targets.def"
  71. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  72. }
  73. /** LLVMInitializeAllTargets - The main program should call this function if it
  74. wants to link in all available targets that LLVM is configured to
  75. support. */
  76. static inline void LLVMInitializeAllTargets(void) {
  77. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
  78. #include "llvm/Config/Targets.def"
  79. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  80. }
  81. /** LLVMInitializeAllTargetMCs - The main program should call this function if
  82. it wants access to all available target MC that LLVM is configured to
  83. support. */
  84. static inline void LLVMInitializeAllTargetMCs(void) {
  85. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
  86. #include "llvm/Config/Targets.def"
  87. #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
  88. }
  89. /** LLVMInitializeAllAsmPrinters - The main program should call this function if
  90. it wants all asm printers that LLVM is configured to support, to make them
  91. available via the TargetRegistry. */
  92. static inline void LLVMInitializeAllAsmPrinters(void) {
  93. #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
  94. #include "llvm/Config/AsmPrinters.def"
  95. #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
  96. }
  97. /** LLVMInitializeAllAsmParsers - The main program should call this function if
  98. it wants all asm parsers that LLVM is configured to support, to make them
  99. available via the TargetRegistry. */
  100. static inline void LLVMInitializeAllAsmParsers(void) {
  101. #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
  102. #include "llvm/Config/AsmParsers.def"
  103. #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
  104. }
  105. /** LLVMInitializeAllDisassemblers - The main program should call this function
  106. if it wants all disassemblers that LLVM is configured to support, to make
  107. them available via the TargetRegistry. */
  108. static inline void LLVMInitializeAllDisassemblers(void) {
  109. #define LLVM_DISASSEMBLER(TargetName) \
  110. LLVMInitialize##TargetName##Disassembler();
  111. #include "llvm/Config/Disassemblers.def"
  112. #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
  113. }
  114. /** LLVMInitializeNativeTarget - The main program should call this function to
  115. initialize the native target corresponding to the host. This is useful
  116. for JIT applications to ensure that the target gets linked in correctly. */
  117. static inline LLVMBool LLVMInitializeNativeTarget(void) {
  118. /* If we have a native target, initialize it to ensure it is linked in. */
  119. #ifdef LLVM_NATIVE_TARGET
  120. LLVM_NATIVE_TARGETINFO();
  121. LLVM_NATIVE_TARGET();
  122. LLVM_NATIVE_TARGETMC();
  123. return 0;
  124. #else
  125. return 1;
  126. #endif
  127. }
  128. /** LLVMInitializeNativeTargetAsmParser - The main program should call this
  129. function to initialize the parser for the native target corresponding to the
  130. host. */
  131. static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
  132. #ifdef LLVM_NATIVE_ASMPARSER
  133. LLVM_NATIVE_ASMPARSER();
  134. return 0;
  135. #else
  136. return 1;
  137. #endif
  138. }
  139. /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
  140. function to initialize the printer for the native target corresponding to
  141. the host. */
  142. static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
  143. #ifdef LLVM_NATIVE_ASMPRINTER
  144. LLVM_NATIVE_ASMPRINTER();
  145. return 0;
  146. #else
  147. return 1;
  148. #endif
  149. }
  150. /** LLVMInitializeNativeTargetDisassembler - The main program should call this
  151. function to initialize the disassembler for the native target corresponding
  152. to the host. */
  153. static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
  154. #ifdef LLVM_NATIVE_DISASSEMBLER
  155. LLVM_NATIVE_DISASSEMBLER();
  156. return 0;
  157. #else
  158. return 1;
  159. #endif
  160. }
  161. /*===-- Target Data -------------------------------------------------------===*/
  162. /**
  163. * Obtain the data layout for a module.
  164. *
  165. * @see Module::getDataLayout()
  166. */
  167. LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
  168. /**
  169. * Set the data layout for a module.
  170. *
  171. * @see Module::setDataLayout()
  172. */
  173. void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
  174. /** Creates target data from a target layout string.
  175. See the constructor llvm::DataLayout::DataLayout. */
  176. LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
  177. /** Deallocates a TargetData.
  178. See the destructor llvm::DataLayout::~DataLayout. */
  179. void LLVMDisposeTargetData(LLVMTargetDataRef TD);
  180. /** Adds target library information to a pass manager. This does not take
  181. ownership of the target library info.
  182. See the method llvm::PassManagerBase::add. */
  183. void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
  184. LLVMPassManagerRef PM);
  185. /** Converts target data to a target layout string. The string must be disposed
  186. with LLVMDisposeMessage.
  187. See the constructor llvm::DataLayout::DataLayout. */
  188. char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
  189. /** Returns the byte order of a target, either LLVMBigEndian or
  190. LLVMLittleEndian.
  191. See the method llvm::DataLayout::isLittleEndian. */
  192. enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
  193. /** Returns the pointer size in bytes for a target.
  194. See the method llvm::DataLayout::getPointerSize. */
  195. unsigned LLVMPointerSize(LLVMTargetDataRef TD);
  196. /** Returns the pointer size in bytes for a target for a specified
  197. address space.
  198. See the method llvm::DataLayout::getPointerSize. */
  199. unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
  200. /** Returns the integer type that is the same size as a pointer on a target.
  201. See the method llvm::DataLayout::getIntPtrType. */
  202. LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
  203. /** Returns the integer type that is the same size as a pointer on a target.
  204. This version allows the address space to be specified.
  205. See the method llvm::DataLayout::getIntPtrType. */
  206. LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
  207. /** Returns the integer type that is the same size as a pointer on a target.
  208. See the method llvm::DataLayout::getIntPtrType. */
  209. LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
  210. /** Returns the integer type that is the same size as a pointer on a target.
  211. This version allows the address space to be specified.
  212. See the method llvm::DataLayout::getIntPtrType. */
  213. LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
  214. unsigned AS);
  215. /** Computes the size of a type in bytes for a target.
  216. See the method llvm::DataLayout::getTypeSizeInBits. */
  217. unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  218. /** Computes the storage size of a type in bytes for a target.
  219. See the method llvm::DataLayout::getTypeStoreSize. */
  220. unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  221. /** Computes the ABI size of a type in bytes for a target.
  222. See the method llvm::DataLayout::getTypeAllocSize. */
  223. unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  224. /** Computes the ABI alignment of a type in bytes for a target.
  225. See the method llvm::DataLayout::getTypeABISize. */
  226. unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  227. /** Computes the call frame alignment of a type in bytes for a target.
  228. See the method llvm::DataLayout::getTypeABISize. */
  229. unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  230. /** Computes the preferred alignment of a type in bytes for a target.
  231. See the method llvm::DataLayout::getTypeABISize. */
  232. unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
  233. /** Computes the preferred alignment of a global variable in bytes for a target.
  234. See the method llvm::DataLayout::getPreferredAlignment. */
  235. unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
  236. LLVMValueRef GlobalVar);
  237. /** Computes the structure element that contains the byte offset for a target.
  238. See the method llvm::StructLayout::getElementContainingOffset. */
  239. unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
  240. unsigned long long Offset);
  241. /** Computes the byte offset of the indexed struct element for a target.
  242. See the method llvm::StructLayout::getElementContainingOffset. */
  243. unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
  244. LLVMTypeRef StructTy, unsigned Element);
  245. /**
  246. * @}
  247. */
  248. LLVM_C_EXTERN_C_END
  249. #endif
  250. #ifdef __GNUC__
  251. #pragma GCC diagnostic pop
  252. #endif