TargetMachine.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - 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 the Target and TargetMachine *|
  16. |* classes, which can be used to generate assembly or object files. *|
  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_TARGETMACHINE_H
  24. #define LLVM_C_TARGETMACHINE_H
  25. #include "llvm-c/ExternC.h"
  26. #include "llvm-c/Target.h"
  27. #include "llvm-c/Types.h"
  28. LLVM_C_EXTERN_C_BEGIN
  29. /**
  30. * @addtogroup LLVMCTarget
  31. *
  32. * @{
  33. */
  34. typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
  35. typedef struct LLVMTarget *LLVMTargetRef;
  36. typedef enum {
  37. LLVMCodeGenLevelNone,
  38. LLVMCodeGenLevelLess,
  39. LLVMCodeGenLevelDefault,
  40. LLVMCodeGenLevelAggressive
  41. } LLVMCodeGenOptLevel;
  42. typedef enum {
  43. LLVMRelocDefault,
  44. LLVMRelocStatic,
  45. LLVMRelocPIC,
  46. LLVMRelocDynamicNoPic,
  47. LLVMRelocROPI,
  48. LLVMRelocRWPI,
  49. LLVMRelocROPI_RWPI
  50. } LLVMRelocMode;
  51. typedef enum {
  52. LLVMCodeModelDefault,
  53. LLVMCodeModelJITDefault,
  54. LLVMCodeModelTiny,
  55. LLVMCodeModelSmall,
  56. LLVMCodeModelKernel,
  57. LLVMCodeModelMedium,
  58. LLVMCodeModelLarge
  59. } LLVMCodeModel;
  60. typedef enum {
  61. LLVMAssemblyFile,
  62. LLVMObjectFile
  63. } LLVMCodeGenFileType;
  64. /** Returns the first llvm::Target in the registered targets list. */
  65. LLVMTargetRef LLVMGetFirstTarget(void);
  66. /** Returns the next llvm::Target given a previous one (or null if there's none) */
  67. LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
  68. /*===-- Target ------------------------------------------------------------===*/
  69. /** Finds the target corresponding to the given name and stores it in \p T.
  70. Returns 0 on success. */
  71. LLVMTargetRef LLVMGetTargetFromName(const char *Name);
  72. /** Finds the target corresponding to the given triple and stores it in \p T.
  73. Returns 0 on success. Optionally returns any error in ErrorMessage.
  74. Use LLVMDisposeMessage to dispose the message. */
  75. LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
  76. char **ErrorMessage);
  77. /** Returns the name of a target. See llvm::Target::getName */
  78. const char *LLVMGetTargetName(LLVMTargetRef T);
  79. /** Returns the description of a target. See llvm::Target::getDescription */
  80. const char *LLVMGetTargetDescription(LLVMTargetRef T);
  81. /** Returns if the target has a JIT */
  82. LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);
  83. /** Returns if the target has a TargetMachine associated */
  84. LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);
  85. /** Returns if the target as an ASM backend (required for emitting output) */
  86. LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);
  87. /*===-- Target Machine ----------------------------------------------------===*/
  88. /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
  89. LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
  90. const char *Triple, const char *CPU, const char *Features,
  91. LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
  92. /** Dispose the LLVMTargetMachineRef instance generated by
  93. LLVMCreateTargetMachine. */
  94. void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
  95. /** Returns the Target used in a TargetMachine */
  96. LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);
  97. /** Returns the triple used creating this target machine. See
  98. llvm::TargetMachine::getTriple. The result needs to be disposed with
  99. LLVMDisposeMessage. */
  100. char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);
  101. /** Returns the cpu used creating this target machine. See
  102. llvm::TargetMachine::getCPU. The result needs to be disposed with
  103. LLVMDisposeMessage. */
  104. char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
  105. /** Returns the feature string used creating this target machine. See
  106. llvm::TargetMachine::getFeatureString. The result needs to be disposed with
  107. LLVMDisposeMessage. */
  108. char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
  109. /** Create a DataLayout based on the targetMachine. */
  110. LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
  111. /** Set the target machine's ASM verbosity. */
  112. void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
  113. LLVMBool VerboseAsm);
  114. /** Emits an asm or object file for the given module to the filename. This
  115. wraps several c++ only classes (among them a file stream). Returns any
  116. error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
  117. LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
  118. const char *Filename,
  119. LLVMCodeGenFileType codegen,
  120. char **ErrorMessage);
  121. /** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
  122. LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
  123. LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
  124. /*===-- Triple ------------------------------------------------------------===*/
  125. /** Get a triple for the host machine as a string. The result needs to be
  126. disposed with LLVMDisposeMessage. */
  127. char* LLVMGetDefaultTargetTriple(void);
  128. /** Normalize a target triple. The result needs to be disposed with
  129. LLVMDisposeMessage. */
  130. char* LLVMNormalizeTargetTriple(const char* triple);
  131. /** Get the host CPU as a string. The result needs to be disposed with
  132. LLVMDisposeMessage. */
  133. char* LLVMGetHostCPUName(void);
  134. /** Get the host CPU's features as a string. The result needs to be disposed
  135. with LLVMDisposeMessage. */
  136. char* LLVMGetHostCPUFeatures(void);
  137. /** Adds the target-specific analysis passes to the pass manager. */
  138. void LLVMAddAnalysisPasses(LLVMTargetMachineRef T, LLVMPassManagerRef PM);
  139. /**
  140. * @}
  141. */
  142. LLVM_C_EXTERN_C_END
  143. #endif
  144. #ifdef __GNUC__
  145. #pragma GCC diagnostic pop
  146. #endif