xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/TargetSelect.h (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
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 
20 extern "C" {
21   // Declare all of the target-initialization functions that are available.
22 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
23 #include "llvm/Config/Targets.def"
24 
25 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
26 #include "llvm/Config/Targets.def"
27 
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 
32   // Declare all of the available assembly printer initialization functions.
33 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
34 #include "llvm/Config/AsmPrinters.def"
35 
36   // Declare all of the available assembly parser initialization functions.
37 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
38 #include "llvm/Config/AsmParsers.def"
39 
40   // Declare all of the available disassembler initialization functions.
41 #define LLVM_DISASSEMBLER(TargetName) \
42   void LLVMInitialize##TargetName##Disassembler();
43 #include "llvm/Config/Disassemblers.def"
44 
45 // Declare all of the available TargetMCA initialization functions.
46 #define LLVM_TARGETMCA(TargetName) void LLVMInitialize##TargetName##TargetMCA();
47 #include "llvm/Config/TargetMCAs.def"
48 }
49 
50 namespace llvm {
51   /// InitializeAllTargetInfos - The main program should call this function if
52   /// it wants access to all available targets that LLVM is configured to
53   /// support, to make them available via the TargetRegistry.
54   ///
55   /// It is legal for a client to make multiple calls to this function.
InitializeAllTargetInfos()56   inline void InitializeAllTargetInfos() {
57 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
58 #include "llvm/Config/Targets.def"
59   }
60 
61   /// InitializeAllTargets - The main program should call this function if it
62   /// wants access to all available target machines that LLVM is configured to
63   /// support, to make them available via the TargetRegistry.
64   ///
65   /// It is legal for a client to make multiple calls to this function.
InitializeAllTargets()66   inline void InitializeAllTargets() {
67     // FIXME: Remove this, clients should do it.
68     InitializeAllTargetInfos();
69 
70 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
71 #include "llvm/Config/Targets.def"
72   }
73 
74   /// InitializeAllTargetMCs - The main program should call this function if it
75   /// wants access to all available target MC that LLVM is configured to
76   /// support, to make them available via the TargetRegistry.
77   ///
78   /// It is legal for a client to make multiple calls to this function.
InitializeAllTargetMCs()79   inline void InitializeAllTargetMCs() {
80 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
81 #include "llvm/Config/Targets.def"
82   }
83 
84   /// InitializeAllAsmPrinters - The main program should call this function if
85   /// it wants all asm printers 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.
InitializeAllAsmPrinters()89   inline void InitializeAllAsmPrinters() {
90 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
91 #include "llvm/Config/AsmPrinters.def"
92   }
93 
94   /// InitializeAllAsmParsers - The main program should call this function if it
95   /// wants all asm parsers that LLVM is configured to support, to make them
96   /// available via the TargetRegistry.
97   ///
98   /// It is legal for a client to make multiple calls to this function.
InitializeAllAsmParsers()99   inline void InitializeAllAsmParsers() {
100 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
101 #include "llvm/Config/AsmParsers.def"
102   }
103 
104   /// InitializeAllDisassemblers - The main program should call this function if
105   /// it wants all disassemblers that LLVM is configured to support, to make
106   /// them available via the TargetRegistry.
107   ///
108   /// It is legal for a client to make multiple calls to this function.
InitializeAllDisassemblers()109   inline void InitializeAllDisassemblers() {
110 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
111 #include "llvm/Config/Disassemblers.def"
112   }
113 
114   /// InitializeNativeTarget - 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   ///
118   /// It is legal for a client to make multiple calls to this function.
InitializeNativeTarget()119   inline bool InitializeNativeTarget() {
120   // If we have a native target, initialize it to ensure it is linked in.
121 #ifdef LLVM_NATIVE_TARGET
122     LLVM_NATIVE_TARGETINFO();
123     LLVM_NATIVE_TARGET();
124     LLVM_NATIVE_TARGETMC();
125     return false;
126 #else
127     return true;
128 #endif
129   }
130 
131   /// InitializeNativeTargetAsmPrinter - The main program should call
132   /// this function to initialize the native target asm printer.
InitializeNativeTargetAsmPrinter()133   inline bool InitializeNativeTargetAsmPrinter() {
134   // If we have a native target, initialize the corresponding asm printer.
135 #ifdef LLVM_NATIVE_ASMPRINTER
136     LLVM_NATIVE_ASMPRINTER();
137     return false;
138 #else
139     return true;
140 #endif
141   }
142 
143   /// InitializeNativeTargetAsmParser - The main program should call
144   /// this function to initialize the native target asm parser.
InitializeNativeTargetAsmParser()145   inline bool InitializeNativeTargetAsmParser() {
146   // If we have a native target, initialize the corresponding asm parser.
147 #ifdef LLVM_NATIVE_ASMPARSER
148     LLVM_NATIVE_ASMPARSER();
149     return false;
150 #else
151     return true;
152 #endif
153   }
154 
155   /// InitializeNativeTargetDisassembler - The main program should call
156   /// this function to initialize the native target disassembler.
InitializeNativeTargetDisassembler()157   inline bool InitializeNativeTargetDisassembler() {
158   // If we have a native target, initialize the corresponding disassembler.
159 #ifdef LLVM_NATIVE_DISASSEMBLER
160     LLVM_NATIVE_DISASSEMBLER();
161     return false;
162 #else
163     return true;
164 #endif
165   }
166 
167   /// InitializeAllTargetMCAs - The main program should call
168   /// this function to initialize the target CustomBehaviour and
169   /// InstrPostProcess classes.
InitializeAllTargetMCAs()170   inline void InitializeAllTargetMCAs() {
171 #define LLVM_TARGETMCA(TargetName) LLVMInitialize##TargetName##TargetMCA();
172 #include "llvm/Config/TargetMCAs.def"
173   }
174 }
175 
176 #endif
177