1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
3 /* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
5 /* See https://llvm.org/LICENSE.txt for license information. */
6 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
8 /*===----------------------------------------------------------------------===*/
10 /* This header declares the C interface to libLLVMTarget.a, which */
11 /* implements target information. */
13 /* Many exotic languages can interoperate with C code but have a harder time */
14 /* with C++ due to name mangling. So in addition to C, this interface enables */
15 /* tools written in such languages. */
17 /*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_TARGET_H
20 #define LLVM_C_TARGET_H
22 #include "llvm-c/Types.h"
23 #include "llvm/Config/llvm-config.h"
30 * @defgroup LLVMCTarget Target information
36 enum LLVMByteOrdering
{ LLVMBigEndian
, LLVMLittleEndian
};
38 typedef struct LLVMOpaqueTargetData
*LLVMTargetDataRef
;
39 typedef struct LLVMOpaqueTargetLibraryInfotData
*LLVMTargetLibraryInfoRef
;
41 /* Declare all of the target-initialization functions that are available. */
42 #define LLVM_TARGET(TargetName) \
43 void LLVMInitialize##TargetName##TargetInfo(void);
44 #include "llvm/Config/Targets.def"
45 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
47 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
48 #include "llvm/Config/Targets.def"
49 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
51 #define LLVM_TARGET(TargetName) \
52 void LLVMInitialize##TargetName##TargetMC(void);
53 #include "llvm/Config/Targets.def"
54 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
56 /* Declare all of the available assembly printer initialization functions. */
57 #define LLVM_ASM_PRINTER(TargetName) \
58 void LLVMInitialize##TargetName##AsmPrinter(void);
59 #include "llvm/Config/AsmPrinters.def"
60 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
62 /* Declare all of the available assembly parser initialization functions. */
63 #define LLVM_ASM_PARSER(TargetName) \
64 void LLVMInitialize##TargetName##AsmParser(void);
65 #include "llvm/Config/AsmParsers.def"
66 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
68 /* Declare all of the available disassembler initialization functions. */
69 #define LLVM_DISASSEMBLER(TargetName) \
70 void LLVMInitialize##TargetName##Disassembler(void);
71 #include "llvm/Config/Disassemblers.def"
72 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
74 /** LLVMInitializeAllTargetInfos - The main program should call this function if
75 it wants access to all available targets that LLVM is configured to
77 static inline void LLVMInitializeAllTargetInfos(void) {
78 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
79 #include "llvm/Config/Targets.def"
80 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
83 /** LLVMInitializeAllTargets - The main program should call this function if it
84 wants to link in all available targets that LLVM is configured to
86 static inline void LLVMInitializeAllTargets(void) {
87 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
88 #include "llvm/Config/Targets.def"
89 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
92 /** LLVMInitializeAllTargetMCs - The main program should call this function if
93 it wants access to all available target MC that LLVM is configured to
95 static inline void LLVMInitializeAllTargetMCs(void) {
96 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
97 #include "llvm/Config/Targets.def"
98 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
101 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
102 it wants all asm printers that LLVM is configured to support, to make them
103 available via the TargetRegistry. */
104 static inline void LLVMInitializeAllAsmPrinters(void) {
105 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
106 #include "llvm/Config/AsmPrinters.def"
107 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
110 /** LLVMInitializeAllAsmParsers - The main program should call this function if
111 it wants all asm parsers that LLVM is configured to support, to make them
112 available via the TargetRegistry. */
113 static inline void LLVMInitializeAllAsmParsers(void) {
114 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
115 #include "llvm/Config/AsmParsers.def"
116 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
119 /** LLVMInitializeAllDisassemblers - The main program should call this function
120 if it wants all disassemblers that LLVM is configured to support, to make
121 them available via the TargetRegistry. */
122 static inline void LLVMInitializeAllDisassemblers(void) {
123 #define LLVM_DISASSEMBLER(TargetName) \
124 LLVMInitialize##TargetName##Disassembler();
125 #include "llvm/Config/Disassemblers.def"
126 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
129 /** LLVMInitializeNativeTarget - The main program should call this function to
130 initialize the native target corresponding to the host. This is useful
131 for JIT applications to ensure that the target gets linked in correctly. */
132 static inline LLVMBool
LLVMInitializeNativeTarget(void) {
133 /* If we have a native target, initialize it to ensure it is linked in. */
134 #ifdef LLVM_NATIVE_TARGET
135 LLVM_NATIVE_TARGETINFO();
136 LLVM_NATIVE_TARGET();
137 LLVM_NATIVE_TARGETMC();
144 /** LLVMInitializeNativeTargetAsmParser - The main program should call this
145 function to initialize the parser for the native target corresponding to the
147 static inline LLVMBool
LLVMInitializeNativeAsmParser(void) {
148 #ifdef LLVM_NATIVE_ASMPARSER
149 LLVM_NATIVE_ASMPARSER();
156 /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
157 function to initialize the printer for the native target corresponding to
159 static inline LLVMBool
LLVMInitializeNativeAsmPrinter(void) {
160 #ifdef LLVM_NATIVE_ASMPRINTER
161 LLVM_NATIVE_ASMPRINTER();
168 /** LLVMInitializeNativeTargetDisassembler - The main program should call this
169 function to initialize the disassembler for the native target corresponding
171 static inline LLVMBool
LLVMInitializeNativeDisassembler(void) {
172 #ifdef LLVM_NATIVE_DISASSEMBLER
173 LLVM_NATIVE_DISASSEMBLER();
180 /*===-- Target Data -------------------------------------------------------===*/
183 * Obtain the data layout for a module.
185 * @see Module::getDataLayout()
187 LLVMTargetDataRef
LLVMGetModuleDataLayout(LLVMModuleRef M
);
190 * Set the data layout for a module.
192 * @see Module::setDataLayout()
194 void LLVMSetModuleDataLayout(LLVMModuleRef M
, LLVMTargetDataRef DL
);
196 /** Creates target data from a target layout string.
197 See the constructor llvm::DataLayout::DataLayout. */
198 LLVMTargetDataRef
LLVMCreateTargetData(const char *StringRep
);
200 /** Deallocates a TargetData.
201 See the destructor llvm::DataLayout::~DataLayout. */
202 void LLVMDisposeTargetData(LLVMTargetDataRef TD
);
204 /** Adds target library information to a pass manager. This does not take
205 ownership of the target library info.
206 See the method llvm::PassManagerBase::add. */
207 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI
,
208 LLVMPassManagerRef PM
);
210 /** Converts target data to a target layout string. The string must be disposed
211 with LLVMDisposeMessage.
212 See the constructor llvm::DataLayout::DataLayout. */
213 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD
);
215 /** Returns the byte order of a target, either LLVMBigEndian or
217 See the method llvm::DataLayout::isLittleEndian. */
218 enum LLVMByteOrdering
LLVMByteOrder(LLVMTargetDataRef TD
);
220 /** Returns the pointer size in bytes for a target.
221 See the method llvm::DataLayout::getPointerSize. */
222 unsigned LLVMPointerSize(LLVMTargetDataRef TD
);
224 /** Returns the pointer size in bytes for a target for a specified
226 See the method llvm::DataLayout::getPointerSize. */
227 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD
, unsigned AS
);
229 /** Returns the integer type that is the same size as a pointer on a target.
230 See the method llvm::DataLayout::getIntPtrType. */
231 LLVMTypeRef
LLVMIntPtrType(LLVMTargetDataRef TD
);
233 /** Returns the integer type that is the same size as a pointer on a target.
234 This version allows the address space to be specified.
235 See the method llvm::DataLayout::getIntPtrType. */
236 LLVMTypeRef
LLVMIntPtrTypeForAS(LLVMTargetDataRef TD
, unsigned AS
);
238 /** Returns the integer type that is the same size as a pointer on a target.
239 See the method llvm::DataLayout::getIntPtrType. */
240 LLVMTypeRef
LLVMIntPtrTypeInContext(LLVMContextRef C
, LLVMTargetDataRef TD
);
242 /** Returns the integer type that is the same size as a pointer on a target.
243 This version allows the address space to be specified.
244 See the method llvm::DataLayout::getIntPtrType. */
245 LLVMTypeRef
LLVMIntPtrTypeForASInContext(LLVMContextRef C
, LLVMTargetDataRef TD
,
248 /** Computes the size of a type in bytes for a target.
249 See the method llvm::DataLayout::getTypeSizeInBits. */
250 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
252 /** Computes the storage size of a type in bytes for a target.
253 See the method llvm::DataLayout::getTypeStoreSize. */
254 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
256 /** Computes the ABI size of a type in bytes for a target.
257 See the method llvm::DataLayout::getTypeAllocSize. */
258 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
260 /** Computes the ABI alignment of a type in bytes for a target.
261 See the method llvm::DataLayout::getTypeABISize. */
262 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
264 /** Computes the call frame alignment of a type in bytes for a target.
265 See the method llvm::DataLayout::getTypeABISize. */
266 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
268 /** Computes the preferred alignment of a type in bytes for a target.
269 See the method llvm::DataLayout::getTypeABISize. */
270 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
272 /** Computes the preferred alignment of a global variable in bytes for a target.
273 See the method llvm::DataLayout::getPreferredAlignment. */
274 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD
,
275 LLVMValueRef GlobalVar
);
277 /** Computes the structure element that contains the byte offset for a target.
278 See the method llvm::StructLayout::getElementContainingOffset. */
279 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD
, LLVMTypeRef StructTy
,
280 unsigned long long Offset
);
282 /** Computes the byte offset of the indexed struct element for a target.
283 See the method llvm::StructLayout::getElementContainingOffset. */
284 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD
,
285 LLVMTypeRef StructTy
, unsigned Element
);
293 #endif /* defined(__cplusplus) */