TargetMachine.h 6.7 KB

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