LLVM  10.0.0svn
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/Types.h"
23 #include "llvm/Config/llvm-config.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * @defgroup LLVMCTarget Target information
31  * @ingroup LLVMC
32  *
33  * @{
34  */
35 
37 
38 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
39 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
40 
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 */
46 
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 */
50 
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 */
55 
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 */
61 
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 */
67 
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 */
73 
74 /** LLVMInitializeAllTargetInfos - The main program should call this function if
75  it wants access to all available targets that LLVM is configured to
76  support. */
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 */
81 }
82 
83 /** LLVMInitializeAllTargets - The main program should call this function if it
84  wants to link in all available targets that LLVM is configured to
85  support. */
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 */
90 }
91 
92 /** LLVMInitializeAllTargetMCs - The main program should call this function if
93  it wants access to all available target MC that LLVM is configured to
94  support. */
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 */
99 }
100 
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 */
108 }
109 
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 */
117 }
118 
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 */
127 }
128 
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. */
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();
138  return 0;
139 #else
140  return 1;
141 #endif
142 }
143 
144 /** LLVMInitializeNativeTargetAsmParser - The main program should call this
145  function to initialize the parser for the native target corresponding to the
146  host. */
148 #ifdef LLVM_NATIVE_ASMPARSER
149  LLVM_NATIVE_ASMPARSER();
150  return 0;
151 #else
152  return 1;
153 #endif
154 }
155 
156 /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
157  function to initialize the printer for the native target corresponding to
158  the host. */
160 #ifdef LLVM_NATIVE_ASMPRINTER
161  LLVM_NATIVE_ASMPRINTER();
162  return 0;
163 #else
164  return 1;
165 #endif
166 }
167 
168 /** LLVMInitializeNativeTargetDisassembler - The main program should call this
169  function to initialize the disassembler for the native target corresponding
170  to the host. */
172 #ifdef LLVM_NATIVE_DISASSEMBLER
173  LLVM_NATIVE_DISASSEMBLER();
174  return 0;
175 #else
176  return 1;
177 #endif
178 }
179 
180 /*===-- Target Data -------------------------------------------------------===*/
181 
182 /**
183  * Obtain the data layout for a module.
184  *
185  * @see Module::getDataLayout()
186  */
187 LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
188 
189 /**
190  * Set the data layout for a module.
191  *
192  * @see Module::setDataLayout()
193  */
194 void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
195 
196 /** Creates target data from a target layout string.
197  See the constructor llvm::DataLayout::DataLayout. */
198 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
199 
200 /** Deallocates a TargetData.
201  See the destructor llvm::DataLayout::~DataLayout. */
202 void LLVMDisposeTargetData(LLVMTargetDataRef TD);
203 
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);
209 
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);
214 
215 /** Returns the byte order of a target, either LLVMBigEndian or
216  LLVMLittleEndian.
217  See the method llvm::DataLayout::isLittleEndian. */
218 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
219 
220 /** Returns the pointer size in bytes for a target.
221  See the method llvm::DataLayout::getPointerSize. */
222 unsigned LLVMPointerSize(LLVMTargetDataRef TD);
223 
224 /** Returns the pointer size in bytes for a target for a specified
225  address space.
226  See the method llvm::DataLayout::getPointerSize. */
227 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
228 
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);
232 
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);
237 
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);
241 
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. */
246  unsigned AS);
247 
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);
251 
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);
255 
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);
259 
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);
263 
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);
267 
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);
271 
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,
276 
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);
281 
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);
286 
287 /**
288  * @}
289  */
290 
291 #ifdef __cplusplus
292 }
293 #endif /* defined(__cplusplus) */
294 
295 #endif
enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:73
uint64_t CallInst * C
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD, LLVMValueRef GlobalVar)
Computes the preferred alignment of a global variable in bytes for a target.
Definition: Target.cpp:125
static void LLVMInitializeAllTargets(void)
LLVMInitializeAllTargets - The main program should call this function if it wants to link in all avai...
Definition: Target.h:86
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:38
static void LLVMInitializeAllAsmParsers(void)
LLVMInitializeAllAsmParsers - The main program should call this function if it wants all asm parsers ...
Definition: Target.h:113
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:85
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:109
static LLVMBool LLVMInitializeNativeAsmParser(void)
LLVMInitializeNativeTargetAsmParser - The main program should call this function to initialize the pa...
Definition: Target.h:147
LLVMByteOrdering
Definition: Target.h:36
static void LLVMInitializeAllAsmPrinters(void)
LLVMInitializeAllAsmPrinters - The main program should call this function if it wants all asm printer...
Definition: Target.h:104
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:69
static LLVMBool LLVMInitializeNativeAsmPrinter(void)
LLVMInitializeNativeTargetAsmPrinter - The main program should call this function to initialize the p...
Definition: Target.h:159
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:54
static void LLVMInitializeAllDisassemblers(void)
LLVMInitializeAllDisassemblers - The main program should call this function if it wants all disassemb...
Definition: Target.h:122
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:136
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:130
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:101
static void LLVMInitializeAllTargetMCs(void)
LLVMInitializeAllTargetMCs - The main program should call this function if it wants access to all ava...
Definition: Target.h:95
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition: Target.cpp:81
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:97
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Target.cpp:47
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:59
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:121
int LLVMBool
Definition: Types.h:29
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:105
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:68
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:77
static LLVMBool LLVMInitializeNativeTarget(void)
LLVMInitializeNativeTarget - The main program should call this function to initialize the native targ...
Definition: Target.h:132
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition: Target.cpp:51
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:39
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:55
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:128
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:117
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:89
static void LLVMInitializeAllTargetInfos(void)
LLVMInitializeAllTargetInfos - The main program should call this function if it wants access to all a...
Definition: Target.h:77
static LLVMBool LLVMInitializeNativeDisassembler(void)
LLVMInitializeNativeTargetDisassembler - The main program should call this function to initialize the...
Definition: Target.h:171
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:63
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:113
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:93
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76