blob: 03004ba5eec0c19feee23d41262d5868bde123dd [file] [log] [blame]
Eric Christophereec50082010-08-08 02:44:17 +00001/*===-- 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/*===----------------------------------------------------------------------===*/
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000018
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
Eric Christophercca8dbe2015-12-18 01:46:52 +000022#include "llvm-c/Types.h"
Eric Christophereec50082010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000024
NAKAMURA Takumi47343672013-10-23 17:56:52 +000025#if defined(_MSC_VER) && !defined(inline)
26#define inline __inline
27#endif
28
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000029#ifdef __cplusplus
30extern "C" {
31#endif
32
Gregory Szorc6244b512012-03-21 03:54:29 +000033/**
34 * @defgroup LLVMCTarget Target information
35 * @ingroup LLVMC
36 *
37 * @{
38 */
39
Chris Lattnerd686c8e2010-01-09 22:27:07 +000040enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000041
42typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindola5160d382011-07-25 21:20:54 +000043typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000044
Bob Wilsona96751f2009-06-23 23:59:40 +000045/* Declare all of the target-initialization functions that are available. */
Eric Christopherca3ca132010-07-12 05:13:35 +000046#define LLVM_TARGET(TargetName) \
47 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000048#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000049#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumie21c3132013-10-23 17:56:29 +000050
Chris Lattnerff33d832010-04-28 20:24:45 +000051#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilsona96751f2009-06-23 23:59:40 +000052#include "llvm/Config/Targets.def"
Chris Lattnerb6219ba2009-12-21 07:52:40 +000053#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilsona96751f2009-06-23 23:59:40 +000054
Evan Cheng1abf2cb2011-07-14 23:50:31 +000055#define LLVM_TARGET(TargetName) \
Evan Chenge78085a2011-07-22 21:58:54 +000056 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng43966132011-07-19 06:37:02 +000057#include "llvm/Config/Targets.def"
58#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumie21c3132013-10-23 17:56:29 +000059
Daniel Dunbar72736d12011-11-29 00:06:55 +000060/* Declare all of the available assembly printer initialization functions. */
61#define LLVM_ASM_PRINTER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000062 void LLVMInitialize##TargetName##AsmPrinter(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000063#include "llvm/Config/AsmPrinters.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000064#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
Daniel Dunbar72736d12011-11-29 00:06:55 +000065
66/* Declare all of the available assembly parser initialization functions. */
67#define LLVM_ASM_PARSER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000068 void LLVMInitialize##TargetName##AsmParser(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000069#include "llvm/Config/AsmParsers.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000070#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
Daniel Dunbar72736d12011-11-29 00:06:55 +000071
72/* Declare all of the available disassembler initialization functions. */
73#define LLVM_DISASSEMBLER(TargetName) \
Anders Waldenborg8ed99512012-05-02 16:15:32 +000074 void LLVMInitialize##TargetName##Disassembler(void);
Daniel Dunbar72736d12011-11-29 00:06:55 +000075#include "llvm/Config/Disassemblers.def"
Bill Wendling29a776b2012-03-26 22:15:12 +000076#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
NAKAMURA Takumie21c3132013-10-23 17:56:29 +000077
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000078/** LLVMInitializeAllTargetInfos - The main program should call this function if
79 it wants access to all available targets that LLVM is configured to
80 support. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +000081static 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}
Daniel Dunbarbaf3edd2009-08-18 03:03:27 +000086
Bob Wilsona96751f2009-06-23 23:59:40 +000087/** 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. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +000090static 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}
Daniel Dunbar72736d12011-11-29 00:06:55 +000095
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. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +000099static 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}
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000104
Daniel Dunbar72736d12011-11-29 00:06:55 +0000105/** 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. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +0000108static 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}
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000113
Daniel Dunbar72736d12011-11-29 00:06:55 +0000114/** 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. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +0000117static 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}
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000122
Daniel Dunbar72736d12011-11-29 00:06:55 +0000123/** 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. */
Anders Waldenborgbfcd45c2013-10-15 13:04:27 +0000126static 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}
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000132
Bob Wilsona96751f2009-06-23 23:59:40 +0000133/** LLVMInitializeNativeTarget - The main program should call this function to
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000134 initialize the native target corresponding to the host. This is useful
Bob Wilsona96751f2009-06-23 23:59:40 +0000135 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattnerc799c552010-04-29 23:27:32 +0000136static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilsona96751f2009-06-23 23:59:40 +0000137 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christopher753f3262010-08-30 18:34:48 +0000138#ifdef LLVM_NATIVE_TARGET
139 LLVM_NATIVE_TARGETINFO();
140 LLVM_NATIVE_TARGET();
Evan Chenge78085a2011-07-22 21:58:54 +0000141 LLVM_NATIVE_TARGETMC();
Bob Wilsona96751f2009-06-23 23:59:40 +0000142 return 0;
Bob Wilsona96751f2009-06-23 23:59:40 +0000143#else
144 return 1;
145#endif
NAKAMURA Takumie21c3132013-10-23 17:56:29 +0000146}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000147
Peter Zotov43b25582013-11-06 09:21:35 +0000148/** LLVMInitializeNativeTargetAsmParser - The main program should call this
149 function to initialize the parser for the native target corresponding to the
150 host. */
Peter Zotove669e092013-11-06 09:45:53 +0000151static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
152#ifdef LLVM_NATIVE_ASMPARSER
Peter Zotov43b25582013-11-06 09:21:35 +0000153 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. */
Peter Zotove669e092013-11-06 09:45:53 +0000163static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
164#ifdef LLVM_NATIVE_ASMPRINTER
Peter Zotov43b25582013-11-06 09:21:35 +0000165 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. */
Peter Zotove669e092013-11-06 09:45:53 +0000175static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
176#ifdef LLVM_NATIVE_DISASSEMBLER
Peter Zotov43b25582013-11-06 09:21:35 +0000177 LLVM_NATIVE_DISASSEMBLER();
178 return 0;
179#else
180 return 1;
181#endif
182}
183
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000184/*===-- Target Data -------------------------------------------------------===*/
185
Amaury Sechetb1fb18e2016-02-16 05:11:24 +0000186/**
187 * Obtain the data layout for a module.
188 *
189 * @see Module::getDataLayout()
190 */
191LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
192
193/**
194 * Set the data layout for a module.
195 *
196 * @see Module::setDataLayout()
197 */
198void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
199
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000200/** Creates target data from a target layout string.
Micah Villmow3574eca2012-10-08 16:38:25 +0000201 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000202LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
203
Amaury Sechet47bce89892016-02-17 22:41:09 +0000204/** Deallocates a TargetData.
205 See the destructor llvm::DataLayout::~DataLayout. */
206void LLVMDisposeTargetData(LLVMTargetDataRef TD);
207
Rafael Espindola5160d382011-07-25 21:20:54 +0000208/** 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. */
Peter Zotov573a2312013-11-06 11:52:40 +0000211void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
212 LLVMPassManagerRef PM);
Rafael Espindola5160d382011-07-25 21:20:54 +0000213
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000214/** Converts target data to a target layout string. The string must be disposed
215 with LLVMDisposeMessage.
Micah Villmow3574eca2012-10-08 16:38:25 +0000216 See the constructor llvm::DataLayout::DataLayout. */
Peter Zotov573a2312013-11-06 11:52:40 +0000217char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000218
219/** Returns the byte order of a target, either LLVMBigEndian or
220 LLVMLittleEndian.
Micah Villmow3574eca2012-10-08 16:38:25 +0000221 See the method llvm::DataLayout::isLittleEndian. */
Peter Zotov573a2312013-11-06 11:52:40 +0000222enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000223
224/** Returns the pointer size in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000225 See the method llvm::DataLayout::getPointerSize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000226unsigned LLVMPointerSize(LLVMTargetDataRef TD);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000227
Micah Villmow2c39b152012-10-15 16:24:29 +0000228/** Returns the pointer size in bytes for a target for a specified
229 address space.
230 See the method llvm::DataLayout::getPointerSize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000231unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
Micah Villmow2c39b152012-10-15 16:24:29 +0000232
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000233/** Returns the integer type that is the same size as a pointer on a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000234 See the method llvm::DataLayout::getIntPtrType. */
Peter Zotov573a2312013-11-06 11:52:40 +0000235LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000236
Micah Villmow2c39b152012-10-15 16:24:29 +0000237/** 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. */
Peter Zotov573a2312013-11-06 11:52:40 +0000240LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
Micah Villmow2c39b152012-10-15 16:24:29 +0000241
Anders Waldenborgf4094e52013-10-17 18:51:01 +0000242/** Returns the integer type that is the same size as a pointer on a target.
243 See the method llvm::DataLayout::getIntPtrType. */
Peter Zotov573a2312013-11-06 11:52:40 +0000244LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
Anders Waldenborgf4094e52013-10-17 18:51:01 +0000245
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. */
Peter Zotov573a2312013-11-06 11:52:40 +0000249LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
250 unsigned AS);
Anders Waldenborgf4094e52013-10-17 18:51:01 +0000251
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000252/** Computes the size of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000253 See the method llvm::DataLayout::getTypeSizeInBits. */
Peter Zotov573a2312013-11-06 11:52:40 +0000254unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000255
256/** Computes the storage size of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000257 See the method llvm::DataLayout::getTypeStoreSize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000258unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000259
260/** Computes the ABI size of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000261 See the method llvm::DataLayout::getTypeAllocSize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000262unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000263
264/** Computes the ABI alignment of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000265 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000266unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000267
268/** Computes the call frame alignment of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000269 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000270unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000271
272/** Computes the preferred alignment of a type in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000273 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotov573a2312013-11-06 11:52:40 +0000274unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000275
276/** Computes the preferred alignment of a global variable in bytes for a target.
Micah Villmow3574eca2012-10-08 16:38:25 +0000277 See the method llvm::DataLayout::getPreferredAlignment. */
Peter Zotov573a2312013-11-06 11:52:40 +0000278unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000279 LLVMValueRef GlobalVar);
280
281/** Computes the structure element that contains the byte offset for a target.
282 See the method llvm::StructLayout::getElementContainingOffset. */
Peter Zotov573a2312013-11-06 11:52:40 +0000283unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000284 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. */
Peter Zotov573a2312013-11-06 11:52:40 +0000288unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
289 LLVMTypeRef StructTy, unsigned Element);
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000290
Gregory Szorc6244b512012-03-21 03:54:29 +0000291/**
292 * @}
293 */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000294
295#ifdef __cplusplus
296}
Evan Cheng9313da52013-04-04 17:40:53 +0000297#endif /* defined(__cplusplus) */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000298
299#endif