TargetSelect.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file provides utilities to make sure that certain classes of targets are
  15. // linked into the main application executable, and initialize them as
  16. // appropriate.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_SUPPORT_TARGETSELECT_H
  20. #define LLVM_SUPPORT_TARGETSELECT_H
  21. #include "llvm/Config/llvm-config.h"
  22. extern "C" {
  23. // Declare all of the target-initialization functions that are available.
  24. #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
  25. #include "llvm/Config/Targets.def"
  26. #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
  27. #include "llvm/Config/Targets.def"
  28. // Declare all of the target-MC-initialization functions that are available.
  29. #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
  30. #include "llvm/Config/Targets.def"
  31. // Declare all of the available assembly printer initialization functions.
  32. #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
  33. #include "llvm/Config/AsmPrinters.def"
  34. // Declare all of the available assembly parser initialization functions.
  35. #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
  36. #include "llvm/Config/AsmParsers.def"
  37. // Declare all of the available disassembler initialization functions.
  38. #define LLVM_DISASSEMBLER(TargetName) \
  39. void LLVMInitialize##TargetName##Disassembler();
  40. #include "llvm/Config/Disassemblers.def"
  41. // Declare all of the available TargetMCA initialization functions.
  42. #define LLVM_TARGETMCA(TargetName) void LLVMInitialize##TargetName##TargetMCA();
  43. #include "llvm/Config/TargetMCAs.def"
  44. }
  45. namespace llvm {
  46. /// InitializeAllTargetInfos - The main program should call this function if
  47. /// it wants access to all available targets that LLVM is configured to
  48. /// support, to make them available via the TargetRegistry.
  49. ///
  50. /// It is legal for a client to make multiple calls to this function.
  51. inline void InitializeAllTargetInfos() {
  52. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
  53. #include "llvm/Config/Targets.def"
  54. }
  55. /// InitializeAllTargets - The main program should call this function if it
  56. /// wants access to all available target machines that LLVM is configured to
  57. /// support, to make them available via the TargetRegistry.
  58. ///
  59. /// It is legal for a client to make multiple calls to this function.
  60. inline void InitializeAllTargets() {
  61. // FIXME: Remove this, clients should do it.
  62. InitializeAllTargetInfos();
  63. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
  64. #include "llvm/Config/Targets.def"
  65. }
  66. /// InitializeAllTargetMCs - The main program should call this function if it
  67. /// wants access to all available target MC that LLVM is configured to
  68. /// support, to make them available via the TargetRegistry.
  69. ///
  70. /// It is legal for a client to make multiple calls to this function.
  71. inline void InitializeAllTargetMCs() {
  72. #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
  73. #include "llvm/Config/Targets.def"
  74. }
  75. /// InitializeAllAsmPrinters - The main program should call this function if
  76. /// it wants all asm printers that LLVM is configured to support, to make them
  77. /// available via the TargetRegistry.
  78. ///
  79. /// It is legal for a client to make multiple calls to this function.
  80. inline void InitializeAllAsmPrinters() {
  81. #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
  82. #include "llvm/Config/AsmPrinters.def"
  83. }
  84. /// InitializeAllAsmParsers - The main program should call this function if it
  85. /// wants all asm parsers that LLVM is configured to support, to make them
  86. /// available via the TargetRegistry.
  87. ///
  88. /// It is legal for a client to make multiple calls to this function.
  89. inline void InitializeAllAsmParsers() {
  90. #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
  91. #include "llvm/Config/AsmParsers.def"
  92. }
  93. /// InitializeAllDisassemblers - The main program should call this function if
  94. /// it wants all disassemblers that LLVM is configured to support, to make
  95. /// them available via the TargetRegistry.
  96. ///
  97. /// It is legal for a client to make multiple calls to this function.
  98. inline void InitializeAllDisassemblers() {
  99. #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
  100. #include "llvm/Config/Disassemblers.def"
  101. }
  102. /// InitializeNativeTarget - The main program should call this function to
  103. /// initialize the native target corresponding to the host. This is useful
  104. /// for JIT applications to ensure that the target gets linked in correctly.
  105. ///
  106. /// It is legal for a client to make multiple calls to this function.
  107. inline bool InitializeNativeTarget() {
  108. // If we have a native target, initialize it to ensure it is linked in.
  109. #ifdef LLVM_NATIVE_TARGET
  110. LLVM_NATIVE_TARGETINFO();
  111. LLVM_NATIVE_TARGET();
  112. LLVM_NATIVE_TARGETMC();
  113. return false;
  114. #else
  115. return true;
  116. #endif
  117. }
  118. /// InitializeNativeTargetAsmPrinter - The main program should call
  119. /// this function to initialize the native target asm printer.
  120. inline bool InitializeNativeTargetAsmPrinter() {
  121. // If we have a native target, initialize the corresponding asm printer.
  122. #ifdef LLVM_NATIVE_ASMPRINTER
  123. LLVM_NATIVE_ASMPRINTER();
  124. return false;
  125. #else
  126. return true;
  127. #endif
  128. }
  129. /// InitializeNativeTargetAsmParser - The main program should call
  130. /// this function to initialize the native target asm parser.
  131. inline bool InitializeNativeTargetAsmParser() {
  132. // If we have a native target, initialize the corresponding asm parser.
  133. #ifdef LLVM_NATIVE_ASMPARSER
  134. LLVM_NATIVE_ASMPARSER();
  135. return false;
  136. #else
  137. return true;
  138. #endif
  139. }
  140. /// InitializeNativeTargetDisassembler - The main program should call
  141. /// this function to initialize the native target disassembler.
  142. inline bool InitializeNativeTargetDisassembler() {
  143. // If we have a native target, initialize the corresponding disassembler.
  144. #ifdef LLVM_NATIVE_DISASSEMBLER
  145. LLVM_NATIVE_DISASSEMBLER();
  146. return false;
  147. #else
  148. return true;
  149. #endif
  150. }
  151. /// InitializeAllTargetMCAs - The main program should call
  152. /// this function to initialize the target CustomBehaviour and
  153. /// InstrPostProcess classes.
  154. inline void InitializeAllTargetMCAs() {
  155. #define LLVM_TARGETMCA(TargetName) LLVMInitialize##TargetName##TargetMCA();
  156. #include "llvm/Config/TargetMCAs.def"
  157. }
  158. }
  159. #endif
  160. #ifdef __GNUC__
  161. #pragma GCC diagnostic pop
  162. #endif