blob: 71a24819eac9fb04bb2816aea6cea94d43a5cbc6 [file] [log] [blame]
Eric Christopherf24446d2010-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 Henriksenab4b7d32008-03-16 20:08:03 +000018
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
Eric Christopherf24446d2010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000024
NAKAMURA Takumifb9c2412013-10-23 17:56:52 +000025#if defined(_MSC_VER) && !defined(inline)
26#define inline __inline
27#endif
28
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000029#ifdef __cplusplus
30extern "C" {
31#endif
32
Gregory Szorc34c863a2012-03-21 03:54:29 +000033/**
34 * @defgroup LLVMCTarget Target information
35 * @ingroup LLVMC
36 *
37 * @{
38 */
39
Chris Lattner25963c62010-01-09 22:27:07 +000040enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000041
42typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +000043typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000044typedef struct LLVMStructLayout *LLVMStructLayoutRef;
45
Bob Wilson5a495fe2009-06-23 23:59:40 +000046/* Declare all of the target-initialization functions that are available. */
Eric Christopher135de902010-07-12 05:13:35 +000047#define LLVM_TARGET(TargetName) \
48 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000049#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000050#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000051
Chris Lattneree3576e2010-04-28 20:24:45 +000052#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilson5a495fe2009-06-23 23:59:40 +000053#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000054#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000055
Evan Cheng1705ab02011-07-14 23:50:31 +000056#define LLVM_TARGET(TargetName) \
Evan Cheng8c886a42011-07-22 21:58:54 +000057 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng2129f592011-07-19 06:37:02 +000058#include "llvm/Config/Targets.def"
59#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000060
Daniel Dunbar69987ab2011-11-29 00:06:55 +000061/* Declare all of the available assembly printer initialization functions. */
62#define LLVM_ASM_PRINTER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000063 void LLVMInitialize##TargetName##AsmPrinter(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000064#include "llvm/Config/AsmPrinters.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000065#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000066
67/* Declare all of the available assembly parser initialization functions. */
68#define LLVM_ASM_PARSER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000069 void LLVMInitialize##TargetName##AsmParser(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000070#include "llvm/Config/AsmParsers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000071#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000072
73/* Declare all of the available disassembler initialization functions. */
74#define LLVM_DISASSEMBLER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000075 void LLVMInitialize##TargetName##Disassembler(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000076#include "llvm/Config/Disassemblers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000077#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000078
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000079/** LLVMInitializeAllTargetInfos - The main program should call this function if
80 it wants access to all available targets that LLVM is configured to
81 support. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +000082static inline void LLVMInitializeAllTargetInfos(void) {
83#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
84#include "llvm/Config/Targets.def"
85#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
86}
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000087
Bob Wilson5a495fe2009-06-23 23:59:40 +000088/** LLVMInitializeAllTargets - The main program should call this function if it
89 wants to link in all available targets that LLVM is configured to
90 support. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +000091static inline void LLVMInitializeAllTargets(void) {
92#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
93#include "llvm/Config/Targets.def"
94#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
95}
Daniel Dunbar69987ab2011-11-29 00:06:55 +000096
97/** LLVMInitializeAllTargetMCs - The main program should call this function if
98 it wants access to all available target MC that LLVM is configured to
99 support. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000100static inline void LLVMInitializeAllTargetMCs(void) {
101#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
102#include "llvm/Config/Targets.def"
103#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
104}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000105
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000106/** LLVMInitializeAllAsmPrinters - The main program should call this function if
107 it wants all asm printers that LLVM is configured to support, to make them
108 available via the TargetRegistry. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000109static inline void LLVMInitializeAllAsmPrinters(void) {
110#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
111#include "llvm/Config/AsmPrinters.def"
112#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
113}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000114
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000115/** LLVMInitializeAllAsmParsers - The main program should call this function if
116 it wants all asm parsers that LLVM is configured to support, to make them
117 available via the TargetRegistry. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000118static inline void LLVMInitializeAllAsmParsers(void) {
119#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
120#include "llvm/Config/AsmParsers.def"
121#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
122}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000123
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000124/** LLVMInitializeAllDisassemblers - The main program should call this function
125 if it wants all disassemblers that LLVM is configured to support, to make
126 them available via the TargetRegistry. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000127static inline void LLVMInitializeAllDisassemblers(void) {
128#define LLVM_DISASSEMBLER(TargetName) \
129 LLVMInitialize##TargetName##Disassembler();
130#include "llvm/Config/Disassemblers.def"
131#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
132}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000133
Bob Wilson5a495fe2009-06-23 23:59:40 +0000134/** LLVMInitializeNativeTarget - The main program should call this function to
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000135 initialize the native target corresponding to the host. This is useful
Bob Wilson5a495fe2009-06-23 23:59:40 +0000136 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattner9d186472010-04-29 23:27:32 +0000137static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +0000138 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christophere7a9db12010-08-30 18:34:48 +0000139#ifdef LLVM_NATIVE_TARGET
140 LLVM_NATIVE_TARGETINFO();
141 LLVM_NATIVE_TARGET();
Evan Cheng8c886a42011-07-22 21:58:54 +0000142 LLVM_NATIVE_TARGETMC();
Bob Wilson5a495fe2009-06-23 23:59:40 +0000143 return 0;
Bob Wilson5a495fe2009-06-23 23:59:40 +0000144#else
145 return 1;
146#endif
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000147}
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000148
149/*===-- Target Data -------------------------------------------------------===*/
150
151/** Creates target data from a target layout string.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000152 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000153LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
154
155/** Adds target data information to a pass manager. This does not take ownership
156 of the target data.
157 See the method llvm::PassManagerBase::add. */
158void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
159
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000160/** Adds target library information to a pass manager. This does not take
161 ownership of the target library info.
162 See the method llvm::PassManagerBase::add. */
163void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
164
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000165/** Converts target data to a target layout string. The string must be disposed
166 with LLVMDisposeMessage.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000167 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000168char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
169
170/** Returns the byte order of a target, either LLVMBigEndian or
171 LLVMLittleEndian.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000172 See the method llvm::DataLayout::isLittleEndian. */
Chris Lattner51c49962010-01-09 23:25:21 +0000173enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000174
175/** Returns the pointer size in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000176 See the method llvm::DataLayout::getPointerSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000177unsigned LLVMPointerSize(LLVMTargetDataRef);
178
Micah Villmow4bb926d2012-10-15 16:24:29 +0000179/** Returns the pointer size in bytes for a target for a specified
180 address space.
181 See the method llvm::DataLayout::getPointerSize. */
182unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS);
183
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000184/** Returns the integer type that is the same size as a pointer on a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000185 See the method llvm::DataLayout::getIntPtrType. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000186LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
187
Micah Villmow4bb926d2012-10-15 16:24:29 +0000188/** Returns the integer type that is the same size as a pointer on a target.
189 This version allows the address space to be specified.
190 See the method llvm::DataLayout::getIntPtrType. */
191LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS);
192
Anders Waldenborg959f0402013-10-17 18:51:01 +0000193/** Returns the integer type that is the same size as a pointer on a target.
194 See the method llvm::DataLayout::getIntPtrType. */
195LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef, LLVMTargetDataRef);
196
197/** Returns the integer type that is the same size as a pointer on a target.
198 This version allows the address space to be specified.
199 See the method llvm::DataLayout::getIntPtrType. */
200LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef, LLVMTargetDataRef, unsigned AS);
201
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000202/** Computes the size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000203 See the method llvm::DataLayout::getTypeSizeInBits. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000204unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
205
206/** Computes the storage size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000207 See the method llvm::DataLayout::getTypeStoreSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000208unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
209
210/** Computes the ABI size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000211 See the method llvm::DataLayout::getTypeAllocSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000212unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
213
214/** Computes the ABI alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000215 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000216unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
217
218/** Computes the call frame alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000219 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000220unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
221
222/** Computes the preferred alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000223 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000224unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
225
226/** Computes the preferred alignment of a global variable in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000227 See the method llvm::DataLayout::getPreferredAlignment. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000228unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
229 LLVMValueRef GlobalVar);
230
231/** Computes the structure element that contains the byte offset for a target.
232 See the method llvm::StructLayout::getElementContainingOffset. */
233unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
234 unsigned long long Offset);
235
236/** Computes the byte offset of the indexed struct element for a target.
237 See the method llvm::StructLayout::getElementContainingOffset. */
238unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
239 unsigned Element);
240
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000241/** Deallocates a TargetData.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000242 See the destructor llvm::DataLayout::~DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000243void LLVMDisposeTargetData(LLVMTargetDataRef);
244
Gregory Szorc34c863a2012-03-21 03:54:29 +0000245/**
246 * @}
247 */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000248
249#ifdef __cplusplus
250}
Evan Cheng2e254d02013-04-04 17:40:53 +0000251#endif /* defined(__cplusplus) */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000252
253#endif