LLVM 19.0.0git
Target.h
Go to the documentation of this file.
1/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
2/* */
3/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
4/* Exceptions. */
5/* See https://llvm.org/LICENSE.txt for license information. */
6/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
7/* */
8/*===----------------------------------------------------------------------===*/
9/* */
10/* This header declares the C interface to libLLVMTarget.a, which */
11/* implements target information. */
12/* */
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. */
16/* */
17/*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/ExternC.h"
23#include "llvm-c/Types.h"
24#include "llvm/Config/llvm-config.h"
25
27
28/**
29 * @defgroup LLVMCTarget Target information
30 * @ingroup LLVMC
31 *
32 * @{
33 */
34
36
37typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
38typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
39
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 */
45
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 */
49
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 */
54
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 */
60
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 */
66
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 */
72
73/** LLVMInitializeAllTargetInfos - The main program should call this function if
74 it wants access to all available targets that LLVM is configured to
75 support. */
76static 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 */
80}
81
82/** LLVMInitializeAllTargets - The main program should call this function if it
83 wants to link in all available targets that LLVM is configured to
84 support. */
85static 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 */
89}
90
91/** LLVMInitializeAllTargetMCs - The main program should call this function if
92 it wants access to all available target MC that LLVM is configured to
93 support. */
94static 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 */
98}
99
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. */
103static 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 */
107}
108
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. */
112static 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 */
116}
117
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. */
121static 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 */
126}
127
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. */
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();
137 return 0;
138#else
139 return 1;
140#endif
141}
142
143/** LLVMInitializeNativeTargetAsmParser - The main program should call this
144 function to initialize the parser for the native target corresponding to the
145 host. */
147#ifdef LLVM_NATIVE_ASMPARSER
148 LLVM_NATIVE_ASMPARSER();
149 return 0;
150#else
151 return 1;
152#endif
153}
154
155/** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
156 function to initialize the printer for the native target corresponding to
157 the host. */
159#ifdef LLVM_NATIVE_ASMPRINTER
160 LLVM_NATIVE_ASMPRINTER();
161 return 0;
162#else
163 return 1;
164#endif
165}
166
167/** LLVMInitializeNativeTargetDisassembler - The main program should call this
168 function to initialize the disassembler for the native target corresponding
169 to the host. */
171#ifdef LLVM_NATIVE_DISASSEMBLER
172 LLVM_NATIVE_DISASSEMBLER();
173 return 0;
174#else
175 return 1;
176#endif
177}
178
179/*===-- Target Data -------------------------------------------------------===*/
180
181/**
182 * Obtain the data layout for a module.
183 *
184 * @see Module::getDataLayout()
185 */
187
188/**
189 * Set the data layout for a module.
190 *
191 * @see Module::setDataLayout()
192 */
194
195/** Creates target data from a target layout string.
196 See the constructor llvm::DataLayout::DataLayout. */
197LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
198
199/** Deallocates a TargetData.
200 See the destructor llvm::DataLayout::~DataLayout. */
202
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. */
208
209/** Converts target data to a target layout string. The string must be disposed
210 with LLVMDisposeMessage.
211 See the constructor llvm::DataLayout::DataLayout. */
213
214/** Returns the byte order of a target, either LLVMBigEndian or
215 LLVMLittleEndian.
216 See the method llvm::DataLayout::isLittleEndian. */
218
219/** Returns the pointer size in bytes for a target.
220 See the method llvm::DataLayout::getPointerSize. */
222
223/** Returns the pointer size in bytes for a target for a specified
224 address space.
225 See the method llvm::DataLayout::getPointerSize. */
226unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
227
228/** Returns the integer type that is the same size as a pointer on a target.
229 See the method llvm::DataLayout::getIntPtrType. */
231
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. */
236
237/** Returns the integer type that is the same size as a pointer on a target.
238 See the method llvm::DataLayout::getIntPtrType. */
240
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. */
245 unsigned AS);
246
247/** Computes the size of a type in bytes for a target.
248 See the method llvm::DataLayout::getTypeSizeInBits. */
249unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
250
251/** Computes the storage size of a type in bytes for a target.
252 See the method llvm::DataLayout::getTypeStoreSize. */
253unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
254
255/** Computes the ABI size of a type in bytes for a target.
256 See the method llvm::DataLayout::getTypeAllocSize. */
257unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
258
259/** Computes the ABI alignment of a type in bytes for a target.
260 See the method llvm::DataLayout::getTypeABISize. */
262
263/** Computes the call frame alignment of a type in bytes for a target.
264 See the method llvm::DataLayout::getTypeABISize. */
266
267/** Computes the preferred alignment of a type in bytes for a target.
268 See the method llvm::DataLayout::getTypeABISize. */
270
271/** Computes the preferred alignment of a global variable in bytes for a target.
272 See the method llvm::DataLayout::getPreferredAlignment. */
274 LLVMValueRef GlobalVar);
275
276/** Computes the structure element that contains the byte offset for a target.
277 See the method llvm::StructLayout::getElementContainingOffset. */
279 unsigned long long Offset);
280
281/** Computes the byte offset of the indexed struct element for a target.
282 See the method llvm::StructLayout::getElementContainingOffset. */
283unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
284 LLVMTypeRef StructTy, unsigned Element);
285
286/**
287 * @}
288 */
289
291
292#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
uint64_t Offset
Definition: ELF_riscv.cpp:478
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:127
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:68
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
static LLVMBool LLVMInitializeNativeAsmParser(void)
LLVMInitializeNativeTargetAsmParser - The main program should call this function to initialize the pa...
Definition: Target.h:146
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition: Target.cpp:46
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Target.cpp:42
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition: Target.cpp:120
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:54
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:63
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:88
static void LLVMInitializeAllTargetInfos(void)
LLVMInitializeAllTargetInfos - The main program should call this function if it wants access to all a...
Definition: Target.h:76
LLVMByteOrdering
Definition: Target.h:35
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:108
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:100
enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:68
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:80
static LLVMBool LLVMInitializeNativeAsmPrinter(void)
LLVMInitializeNativeTargetAsmPrinter - The main program should call this function to initialize the p...
Definition: Target.h:158
static LLVMBool LLVMInitializeNativeDisassembler(void)
LLVMInitializeNativeTargetDisassembler - The main program should call this function to initialize the...
Definition: Target.h:170
static void LLVMInitializeAllTargetMCs(void)
LLVMInitializeAllTargetMCs - The main program should call this function if it wants access to all ava...
Definition: Target.h:94
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition: Target.cpp:76
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:112
unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy, unsigned Element)
Computes the byte offset of the indexed struct element for a target.
Definition: Target.cpp:133
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:96
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:58
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:38
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:72
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:84
static void LLVMInitializeAllAsmParsers(void)
LLVMInitializeAllAsmParsers - The main program should call this function if it wants all asm parsers ...
Definition: Target.h:112
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:104
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:50
static LLVMBool LLVMInitializeNativeTarget(void)
LLVMInitializeNativeTarget - The main program should call this function to initialize the native targ...
Definition: Target.h:131
static void LLVMInitializeAllTargets(void)
LLVMInitializeAllTargets - The main program should call this function if it wants to link in all avai...
Definition: Target.h:85
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:37
LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:92
static void LLVMInitializeAllAsmPrinters(void)
LLVMInitializeAllAsmPrinters - The main program should call this function if it wants all asm printer...
Definition: Target.h:103
static void LLVMInitializeAllDisassemblers(void)
LLVMInitializeAllDisassemblers - The main program should call this function if it wants all disassemb...
Definition: Target.h:121
unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy, unsigned long long Offset)
Computes the structure element that contains the byte offset for a target.
Definition: Target.cpp:127
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:116
@ LLVMBigEndian
Definition: Target.h:35
@ LLVMLittleEndian
Definition: Target.h:35