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