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/ExternC.h"
23 #include "llvm-c/Types.h"
24 #include "llvm/Config/llvm-config.h"
29 * @defgroup LLVMCTarget Target information
35 enum LLVMByteOrdering
{ LLVMBigEndian
, LLVMLittleEndian
};
37 typedef struct LLVMOpaqueTargetData
*LLVMTargetDataRef
;
38 typedef struct LLVMOpaqueTargetLibraryInfotData
*LLVMTargetLibraryInfoRef
;
40 /* Declare all of the target-initialization functions that are available. */
41 #define LLVM_TARGET(TargetName) \
42 void LLVMInitialize##TargetName##TargetInfo(void);
43 #include "llvm/Config/Targets.def"
44 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
46 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
47 #include "llvm/Config/Targets.def"
48 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
50 #define LLVM_TARGET(TargetName) \
51 void LLVMInitialize##TargetName##TargetMC(void);
52 #include "llvm/Config/Targets.def"
53 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
55 /* Declare all of the available assembly printer initialization functions. */
56 #define LLVM_ASM_PRINTER(TargetName) \
57 void LLVMInitialize##TargetName##AsmPrinter(void);
58 #include "llvm/Config/AsmPrinters.def"
59 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
61 /* Declare all of the available assembly parser initialization functions. */
62 #define LLVM_ASM_PARSER(TargetName) \
63 void LLVMInitialize##TargetName##AsmParser(void);
64 #include "llvm/Config/AsmParsers.def"
65 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
67 /* Declare all of the available disassembler initialization functions. */
68 #define LLVM_DISASSEMBLER(TargetName) \
69 void LLVMInitialize##TargetName##Disassembler(void);
70 #include "llvm/Config/Disassemblers.def"
71 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
73 /** LLVMInitializeAllTargetInfos - The main program should call this function if
74 it wants access to all available targets that LLVM is configured to
76 static inline void LLVMInitializeAllTargetInfos(void) {
77 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
78 #include "llvm/Config/Targets.def"
79 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
82 /** LLVMInitializeAllTargets - The main program should call this function if it
83 wants to link in all available targets that LLVM is configured to
85 static inline void LLVMInitializeAllTargets(void) {
86 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
87 #include "llvm/Config/Targets.def"
88 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
91 /** LLVMInitializeAllTargetMCs - The main program should call this function if
92 it wants access to all available target MC that LLVM is configured to
94 static inline void LLVMInitializeAllTargetMCs(void) {
95 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
96 #include "llvm/Config/Targets.def"
97 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
100 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
101 it wants all asm printers that LLVM is configured to support, to make them
102 available via the TargetRegistry. */
103 static inline void LLVMInitializeAllAsmPrinters(void) {
104 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
105 #include "llvm/Config/AsmPrinters.def"
106 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
109 /** LLVMInitializeAllAsmParsers - The main program should call this function if
110 it wants all asm parsers that LLVM is configured to support, to make them
111 available via the TargetRegistry. */
112 static inline void LLVMInitializeAllAsmParsers(void) {
113 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
114 #include "llvm/Config/AsmParsers.def"
115 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
118 /** LLVMInitializeAllDisassemblers - The main program should call this function
119 if it wants all disassemblers that LLVM is configured to support, to make
120 them available via the TargetRegistry. */
121 static inline void LLVMInitializeAllDisassemblers(void) {
122 #define LLVM_DISASSEMBLER(TargetName) \
123 LLVMInitialize##TargetName##Disassembler();
124 #include "llvm/Config/Disassemblers.def"
125 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
128 /** LLVMInitializeNativeTarget - The main program should call this function to
129 initialize the native target corresponding to the host. This is useful
130 for JIT applications to ensure that the target gets linked in correctly. */
131 static inline LLVMBool
LLVMInitializeNativeTarget(void) {
132 /* If we have a native target, initialize it to ensure it is linked in. */
133 #ifdef LLVM_NATIVE_TARGET
134 LLVM_NATIVE_TARGETINFO();
135 LLVM_NATIVE_TARGET();
136 LLVM_NATIVE_TARGETMC();
143 /** LLVMInitializeNativeTargetAsmParser - The main program should call this
144 function to initialize the parser for the native target corresponding to the
146 static inline LLVMBool
LLVMInitializeNativeAsmParser(void) {
147 #ifdef LLVM_NATIVE_ASMPARSER
148 LLVM_NATIVE_ASMPARSER();
155 /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
156 function to initialize the printer for the native target corresponding to
158 static inline LLVMBool
LLVMInitializeNativeAsmPrinter(void) {
159 #ifdef LLVM_NATIVE_ASMPRINTER
160 LLVM_NATIVE_ASMPRINTER();
167 /** LLVMInitializeNativeTargetDisassembler - The main program should call this
168 function to initialize the disassembler for the native target corresponding
170 static inline LLVMBool
LLVMInitializeNativeDisassembler(void) {
171 #ifdef LLVM_NATIVE_DISASSEMBLER
172 LLVM_NATIVE_DISASSEMBLER();
179 /*===-- Target Data -------------------------------------------------------===*/
182 * Obtain the data layout for a module.
184 * @see Module::getDataLayout()
186 LLVMTargetDataRef
LLVMGetModuleDataLayout(LLVMModuleRef M
);
189 * Set the data layout for a module.
191 * @see Module::setDataLayout()
193 void LLVMSetModuleDataLayout(LLVMModuleRef M
, LLVMTargetDataRef DL
);
195 /** Creates target data from a target layout string.
196 See the constructor llvm::DataLayout::DataLayout. */
197 LLVMTargetDataRef
LLVMCreateTargetData(const char *StringRep
);
199 /** Deallocates a TargetData.
200 See the destructor llvm::DataLayout::~DataLayout. */
201 void LLVMDisposeTargetData(LLVMTargetDataRef TD
);
203 /** Adds target library information to a pass manager. This does not take
204 ownership of the target library info.
205 See the method llvm::PassManagerBase::add. */
206 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI
,
207 LLVMPassManagerRef PM
);
209 /** Converts target data to a target layout string. The string must be disposed
210 with LLVMDisposeMessage.
211 See the constructor llvm::DataLayout::DataLayout. */
212 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD
);
214 /** Returns the byte order of a target, either LLVMBigEndian or
216 See the method llvm::DataLayout::isLittleEndian. */
217 enum LLVMByteOrdering
LLVMByteOrder(LLVMTargetDataRef TD
);
219 /** Returns the pointer size in bytes for a target.
220 See the method llvm::DataLayout::getPointerSize. */
221 unsigned LLVMPointerSize(LLVMTargetDataRef TD
);
223 /** Returns the pointer size in bytes for a target for a specified
225 See the method llvm::DataLayout::getPointerSize. */
226 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD
, unsigned AS
);
228 /** Returns the integer type that is the same size as a pointer on a target.
229 See the method llvm::DataLayout::getIntPtrType. */
230 LLVMTypeRef
LLVMIntPtrType(LLVMTargetDataRef TD
);
232 /** Returns the integer type that is the same size as a pointer on a target.
233 This version allows the address space to be specified.
234 See the method llvm::DataLayout::getIntPtrType. */
235 LLVMTypeRef
LLVMIntPtrTypeForAS(LLVMTargetDataRef TD
, unsigned AS
);
237 /** Returns the integer type that is the same size as a pointer on a target.
238 See the method llvm::DataLayout::getIntPtrType. */
239 LLVMTypeRef
LLVMIntPtrTypeInContext(LLVMContextRef C
, LLVMTargetDataRef TD
);
241 /** Returns the integer type that is the same size as a pointer on a target.
242 This version allows the address space to be specified.
243 See the method llvm::DataLayout::getIntPtrType. */
244 LLVMTypeRef
LLVMIntPtrTypeForASInContext(LLVMContextRef C
, LLVMTargetDataRef TD
,
247 /** Computes the size of a type in bytes for a target.
248 See the method llvm::DataLayout::getTypeSizeInBits. */
249 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
251 /** Computes the storage size of a type in bytes for a target.
252 See the method llvm::DataLayout::getTypeStoreSize. */
253 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
255 /** Computes the ABI size of a type in bytes for a target.
256 See the method llvm::DataLayout::getTypeAllocSize. */
257 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
259 /** Computes the ABI alignment of a type in bytes for a target.
260 See the method llvm::DataLayout::getTypeABISize. */
261 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
263 /** Computes the call frame alignment of a type in bytes for a target.
264 See the method llvm::DataLayout::getTypeABISize. */
265 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
267 /** Computes the preferred alignment of a type in bytes for a target.
268 See the method llvm::DataLayout::getTypeABISize. */
269 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD
, LLVMTypeRef Ty
);
271 /** Computes the preferred alignment of a global variable in bytes for a target.
272 See the method llvm::DataLayout::getPreferredAlignment. */
273 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD
,
274 LLVMValueRef GlobalVar
);
276 /** Computes the structure element that contains the byte offset for a target.
277 See the method llvm::StructLayout::getElementContainingOffset. */
278 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD
, LLVMTypeRef StructTy
,
279 unsigned long long Offset
);
281 /** Computes the byte offset of the indexed struct element for a target.
282 See the method llvm::StructLayout::getElementContainingOffset. */
283 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD
,
284 LLVMTypeRef StructTy
, unsigned Element
);