LLVM  6.0.0svn
Target.h
Go to the documentation of this file.
1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
2 /* */
3 /* The LLVM Compiler Infrastructure */
4 /* */
5 /* This file is distributed under the University of Illinois Open Source */
6 /* License. See LICENSE.TXT for details. */
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 #if defined(_MSC_VER) && !defined(inline)
26 #define inline __inline
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /**
34  * @defgroup LLVMCTarget Target information
35  * @ingroup LLVMC
36  *
37  * @{
38  */
39 
41 
42 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
43 typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
44 
45 /* Declare all of the target-initialization functions that are available. */
46 #define LLVM_TARGET(TargetName) \
47  void LLVMInitialize##TargetName##TargetInfo(void);
48 #include "llvm/Config/Targets.def"
49 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
50 
51 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
52 #include "llvm/Config/Targets.def"
53 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
54 
55 #define LLVM_TARGET(TargetName) \
56  void LLVMInitialize##TargetName##TargetMC(void);
57 #include "llvm/Config/Targets.def"
58 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
59 
60 /* Declare all of the available assembly printer initialization functions. */
61 #define LLVM_ASM_PRINTER(TargetName) \
62  void LLVMInitialize##TargetName##AsmPrinter(void);
63 #include "llvm/Config/AsmPrinters.def"
64 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
65 
66 /* Declare all of the available assembly parser initialization functions. */
67 #define LLVM_ASM_PARSER(TargetName) \
68  void LLVMInitialize##TargetName##AsmParser(void);
69 #include "llvm/Config/AsmParsers.def"
70 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
71 
72 /* Declare all of the available disassembler initialization functions. */
73 #define LLVM_DISASSEMBLER(TargetName) \
74  void LLVMInitialize##TargetName##Disassembler(void);
75 #include "llvm/Config/Disassemblers.def"
76 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
77 
78 /** LLVMInitializeAllTargetInfos - The main program should call this function if
79  it wants access to all available targets that LLVM is configured to
80  support. */
81 static inline void LLVMInitializeAllTargetInfos(void) {
82 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
83 #include "llvm/Config/Targets.def"
84 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
85 }
86 
87 /** LLVMInitializeAllTargets - The main program should call this function if it
88  wants to link in all available targets that LLVM is configured to
89  support. */
90 static inline void LLVMInitializeAllTargets(void) {
91 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
92 #include "llvm/Config/Targets.def"
93 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
94 }
95 
96 /** LLVMInitializeAllTargetMCs - The main program should call this function if
97  it wants access to all available target MC that LLVM is configured to
98  support. */
99 static inline void LLVMInitializeAllTargetMCs(void) {
100 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
101 #include "llvm/Config/Targets.def"
102 #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
103 }
104 
105 /** LLVMInitializeAllAsmPrinters - The main program should call this function if
106  it wants all asm printers that LLVM is configured to support, to make them
107  available via the TargetRegistry. */
108 static inline void LLVMInitializeAllAsmPrinters(void) {
109 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
110 #include "llvm/Config/AsmPrinters.def"
111 #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
112 }
113 
114 /** LLVMInitializeAllAsmParsers - The main program should call this function if
115  it wants all asm parsers that LLVM is configured to support, to make them
116  available via the TargetRegistry. */
117 static inline void LLVMInitializeAllAsmParsers(void) {
118 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
119 #include "llvm/Config/AsmParsers.def"
120 #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
121 }
122 
123 /** LLVMInitializeAllDisassemblers - The main program should call this function
124  if it wants all disassemblers that LLVM is configured to support, to make
125  them available via the TargetRegistry. */
126 static inline void LLVMInitializeAllDisassemblers(void) {
127 #define LLVM_DISASSEMBLER(TargetName) \
128  LLVMInitialize##TargetName##Disassembler();
129 #include "llvm/Config/Disassemblers.def"
130 #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
131 }
132 
133 /** LLVMInitializeNativeTarget - The main program should call this function to
134  initialize the native target corresponding to the host. This is useful
135  for JIT applications to ensure that the target gets linked in correctly. */
137  /* If we have a native target, initialize it to ensure it is linked in. */
138 #ifdef LLVM_NATIVE_TARGET
139  LLVM_NATIVE_TARGETINFO();
140  LLVM_NATIVE_TARGET();
141  LLVM_NATIVE_TARGETMC();
142  return 0;
143 #else
144  return 1;
145 #endif
146 }
147 
148 /** LLVMInitializeNativeTargetAsmParser - The main program should call this
149  function to initialize the parser for the native target corresponding to the
150  host. */
152 #ifdef LLVM_NATIVE_ASMPARSER
153  LLVM_NATIVE_ASMPARSER();
154  return 0;
155 #else
156  return 1;
157 #endif
158 }
159 
160 /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
161  function to initialize the printer for the native target corresponding to
162  the host. */
164 #ifdef LLVM_NATIVE_ASMPRINTER
165  LLVM_NATIVE_ASMPRINTER();
166  return 0;
167 #else
168  return 1;
169 #endif
170 }
171 
172 /** LLVMInitializeNativeTargetDisassembler - The main program should call this
173  function to initialize the disassembler for the native target corresponding
174  to the host. */
176 #ifdef LLVM_NATIVE_DISASSEMBLER
177  LLVM_NATIVE_DISASSEMBLER();
178  return 0;
179 #else
180  return 1;
181 #endif
182 }
183 
184 /*===-- Target Data -------------------------------------------------------===*/
185 
186 /**
187  * Obtain the data layout for a module.
188  *
189  * @see Module::getDataLayout()
190  */
191 LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
192 
193 /**
194  * Set the data layout for a module.
195  *
196  * @see Module::setDataLayout()
197  */
198 void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
199 
200 /** Creates target data from a target layout string.
201  See the constructor llvm::DataLayout::DataLayout. */
202 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
203 
204 /** Deallocates a TargetData.
205  See the destructor llvm::DataLayout::~DataLayout. */
206 void LLVMDisposeTargetData(LLVMTargetDataRef TD);
207 
208 /** Adds target library information to a pass manager. This does not take
209  ownership of the target library info.
210  See the method llvm::PassManagerBase::add. */
211 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
212  LLVMPassManagerRef PM);
213 
214 /** Converts target data to a target layout string. The string must be disposed
215  with LLVMDisposeMessage.
216  See the constructor llvm::DataLayout::DataLayout. */
217 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
218 
219 /** Returns the byte order of a target, either LLVMBigEndian or
220  LLVMLittleEndian.
221  See the method llvm::DataLayout::isLittleEndian. */
222 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
223 
224 /** Returns the pointer size in bytes for a target.
225  See the method llvm::DataLayout::getPointerSize. */
226 unsigned LLVMPointerSize(LLVMTargetDataRef TD);
227 
228 /** Returns the pointer size in bytes for a target for a specified
229  address space.
230  See the method llvm::DataLayout::getPointerSize. */
231 unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
232 
233 /** Returns the integer type that is the same size as a pointer on a target.
234  See the method llvm::DataLayout::getIntPtrType. */
235 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
236 
237 /** Returns the integer type that is the same size as a pointer on a target.
238  This version allows the address space to be specified.
239  See the method llvm::DataLayout::getIntPtrType. */
240 LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
241 
242 /** Returns the integer type that is the same size as a pointer on a target.
243  See the method llvm::DataLayout::getIntPtrType. */
244 LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
245 
246 /** Returns the integer type that is the same size as a pointer on a target.
247  This version allows the address space to be specified.
248  See the method llvm::DataLayout::getIntPtrType. */
250  unsigned AS);
251 
252 /** Computes the size of a type in bytes for a target.
253  See the method llvm::DataLayout::getTypeSizeInBits. */
254 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
255 
256 /** Computes the storage size of a type in bytes for a target.
257  See the method llvm::DataLayout::getTypeStoreSize. */
258 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
259 
260 /** Computes the ABI size of a type in bytes for a target.
261  See the method llvm::DataLayout::getTypeAllocSize. */
262 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
263 
264 /** Computes the ABI alignment of a type in bytes for a target.
265  See the method llvm::DataLayout::getTypeABISize. */
266 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
267 
268 /** Computes the call frame alignment of a type in bytes for a target.
269  See the method llvm::DataLayout::getTypeABISize. */
270 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
271 
272 /** Computes the preferred alignment of a type in bytes for a target.
273  See the method llvm::DataLayout::getTypeABISize. */
274 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
275 
276 /** Computes the preferred alignment of a global variable in bytes for a target.
277  See the method llvm::DataLayout::getPreferredAlignment. */
278 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
280 
281 /** Computes the structure element that contains the byte offset for a target.
282  See the method llvm::StructLayout::getElementContainingOffset. */
283 unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
284  unsigned long long Offset);
285 
286 /** Computes the byte offset of the indexed struct element for a target.
287  See the method llvm::StructLayout::getElementContainingOffset. */
288 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
289  LLVMTypeRef StructTy, unsigned Element);
290 
291 /**
292  * @}
293  */
294 
295 #ifdef __cplusplus
296 }
297 #endif /* defined(__cplusplus) */
298 
299 #endif
enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD)
Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian.
Definition: Target.cpp:74
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:126
static void LLVMInitializeAllTargets(void)
LLVMInitializeAllTargets - The main program should call this function if it wants to link in all avai...
Definition: Target.h:90
struct LLVMOpaqueTargetData * LLVMTargetDataRef
Definition: Target.h:42
static void LLVMInitializeAllAsmParsers(void)
LLVMInitializeAllAsmParsers - The main program should call this function if it wants all asm parsers ...
Definition: Target.h:117
LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:86
unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI size of a type in bytes for a target.
Definition: Target.cpp:110
static LLVMBool LLVMInitializeNativeAsmParser(void)
LLVMInitializeNativeTargetAsmParser - The main program should call this function to initialize the pa...
Definition: Target.h:151
LLVMByteOrdering
Definition: Target.h:40
static void LLVMInitializeAllAsmPrinters(void)
LLVMInitializeAllAsmPrinters - The main program should call this function if it wants all asm printer...
Definition: Target.h:108
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:163
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:126
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:137
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:131
unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the size of a type in bytes for a target.
Definition: Target.cpp:102
static void LLVMInitializeAllTargetMCs(void)
LLVMInitializeAllTargetMCs - The main program should call this function if it wants access to all ava...
Definition: Target.h:99
unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the pointer size in bytes for a target for a specified address space.
Definition: Target.cpp:82
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:98
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Target.cpp:48
void LLVMDisposeTargetData(LLVMTargetDataRef TD)
Deallocates a TargetData.
Definition: Target.cpp:60
unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the preferred alignment of a type in bytes for a target.
Definition: Target.cpp:122
int LLVMBool
Definition: Types.h:29
const AMDGPUAS & AS
unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the storage size of a type in bytes for a target.
Definition: Target.cpp:106
char * LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD)
Converts target data to a target layout string.
Definition: Target.cpp:69
unsigned LLVMPointerSize(LLVMTargetDataRef TD)
Returns the pointer size in bytes for a target.
Definition: Target.cpp:78
static LLVMBool LLVMInitializeNativeTarget(void)
LLVMInitializeNativeTarget - The main program should call this function to initialize the native targ...
Definition: Target.h:136
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL)
Set the data layout for a module.
Definition: Target.cpp:52
struct LLVMOpaqueTargetLibraryInfotData * LLVMTargetLibraryInfoRef
Definition: Target.h:43
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep)
Creates target data from a target layout string.
Definition: Target.cpp:56
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:114
unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the call frame alignment of a type in bytes for a target.
Definition: Target.cpp:118
LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:90
static void LLVMInitializeAllTargetInfos(void)
LLVMInitializeAllTargetInfos - The main program should call this function if it wants access to all a...
Definition: Target.h:81
static LLVMBool LLVMInitializeNativeDisassembler(void)
LLVMInitializeNativeTargetDisassembler - The main program should call this function to initialize the...
Definition: Target.h:175
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, LLVMPassManagerRef PM)
Adds target library information to a pass manager.
Definition: Target.cpp:64
unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty)
Computes the ABI alignment of a type in bytes for a target.
Definition: Target.cpp:114
LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD)
Returns the integer type that is the same size as a pointer on a target.
Definition: Target.cpp:94
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76