blob: 4ef641eaf23206a2b9d12be1c84a39d750853c6b [file] [log] [blame]
Eric Christopherf24446d2010-08-08 02:44:17 +00001/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
2/* */
Chandler Carruth2946cd72019-01-19 08:50:56 +00003/* 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 */
Eric Christopherf24446d2010-08-08 02:44:17 +00007/* */
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
Eric Christophera6b96002015-12-18 01:46:52 +000022#include "llvm-c/Types.h"
Eric Christopherf24446d2010-08-08 02:44:17 +000023#include "llvm/Config/llvm-config.h"
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
Gregory Szorc34c863a2012-03-21 03:54:29 +000029/**
30 * @defgroup LLVMCTarget Target information
31 * @ingroup LLVMC
32 *
33 * @{
34 */
35
Chris Lattner25963c62010-01-09 22:27:07 +000036enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000037
38typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +000039typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000040
Bob Wilson5a495fe2009-06-23 23:59:40 +000041/* Declare all of the target-initialization functions that are available. */
Eric Christopher135de902010-07-12 05:13:35 +000042#define LLVM_TARGET(TargetName) \
43 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000044#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000045#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000046
Chris Lattneree3576e2010-04-28 20:24:45 +000047#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilson5a495fe2009-06-23 23:59:40 +000048#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000049#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000050
Evan Cheng1705ab02011-07-14 23:50:31 +000051#define LLVM_TARGET(TargetName) \
Evan Cheng8c886a42011-07-22 21:58:54 +000052 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng2129f592011-07-19 06:37:02 +000053#include "llvm/Config/Targets.def"
54#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000055
Daniel Dunbar69987ab2011-11-29 00:06:55 +000056/* Declare all of the available assembly printer initialization functions. */
57#define LLVM_ASM_PRINTER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000058 void LLVMInitialize##TargetName##AsmPrinter(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000059#include "llvm/Config/AsmPrinters.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000060#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000061
62/* Declare all of the available assembly parser initialization functions. */
63#define LLVM_ASM_PARSER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000064 void LLVMInitialize##TargetName##AsmParser(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000065#include "llvm/Config/AsmParsers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000066#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000067
68/* Declare all of the available disassembler initialization functions. */
69#define LLVM_DISASSEMBLER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000070 void LLVMInitialize##TargetName##Disassembler(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000071#include "llvm/Config/Disassemblers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000072#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
NAKAMURA Takumia3a81352013-10-23 17:56:29 +000073
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000074/** LLVMInitializeAllTargetInfos - The main program should call this function if
75 it wants access to all available targets that LLVM is configured to
76 support. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +000077static 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}
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000082
Bob Wilson5a495fe2009-06-23 23:59:40 +000083/** 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. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +000086static 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}
Daniel Dunbar69987ab2011-11-29 00:06:55 +000091
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. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +000095static 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}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000100
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000101/** 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. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000104static 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}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000109
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000110/** 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. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000113static 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}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000118
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000119/** 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. */
Anders Waldenborg0c3b6532013-10-15 13:04:27 +0000122static 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}
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000128
Bob Wilson5a495fe2009-06-23 23:59:40 +0000129/** LLVMInitializeNativeTarget - The main program should call this function to
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000130 initialize the native target corresponding to the host. This is useful
Bob Wilson5a495fe2009-06-23 23:59:40 +0000131 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattner9d186472010-04-29 23:27:32 +0000132static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +0000133 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christophere7a9db12010-08-30 18:34:48 +0000134#ifdef LLVM_NATIVE_TARGET
135 LLVM_NATIVE_TARGETINFO();
136 LLVM_NATIVE_TARGET();
Evan Cheng8c886a42011-07-22 21:58:54 +0000137 LLVM_NATIVE_TARGETMC();
Bob Wilson5a495fe2009-06-23 23:59:40 +0000138 return 0;
Bob Wilson5a495fe2009-06-23 23:59:40 +0000139#else
140 return 1;
141#endif
NAKAMURA Takumia3a81352013-10-23 17:56:29 +0000142}
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000143
Peter Zotov04f59812013-11-06 09:21:35 +0000144/** LLVMInitializeNativeTargetAsmParser - The main program should call this
145 function to initialize the parser for the native target corresponding to the
146 host. */
Peter Zotov6b5e8b92013-11-06 09:45:53 +0000147static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
148#ifdef LLVM_NATIVE_ASMPARSER
Peter Zotov04f59812013-11-06 09:21:35 +0000149 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. */
Peter Zotov6b5e8b92013-11-06 09:45:53 +0000159static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
160#ifdef LLVM_NATIVE_ASMPRINTER
Peter Zotov04f59812013-11-06 09:21:35 +0000161 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. */
Peter Zotov6b5e8b92013-11-06 09:45:53 +0000171static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
172#ifdef LLVM_NATIVE_DISASSEMBLER
Peter Zotov04f59812013-11-06 09:21:35 +0000173 LLVM_NATIVE_DISASSEMBLER();
174 return 0;
175#else
176 return 1;
177#endif
178}
179
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000180/*===-- Target Data -------------------------------------------------------===*/
181
Amaury Sechet55909672016-02-16 05:11:24 +0000182/**
183 * Obtain the data layout for a module.
184 *
185 * @see Module::getDataLayout()
186 */
187LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
188
189/**
190 * Set the data layout for a module.
191 *
192 * @see Module::setDataLayout()
193 */
194void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
195
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000196/** Creates target data from a target layout string.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000197 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000198LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
199
Amaury Sechet22d28782016-02-17 22:41:09 +0000200/** Deallocates a TargetData.
201 See the destructor llvm::DataLayout::~DataLayout. */
202void LLVMDisposeTargetData(LLVMTargetDataRef TD);
203
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000204/** 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. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000207void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
208 LLVMPassManagerRef PM);
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000209
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000210/** Converts target data to a target layout string. The string must be disposed
211 with LLVMDisposeMessage.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000212 See the constructor llvm::DataLayout::DataLayout. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000213char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000214
215/** Returns the byte order of a target, either LLVMBigEndian or
216 LLVMLittleEndian.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000217 See the method llvm::DataLayout::isLittleEndian. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000218enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000219
220/** Returns the pointer size in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000221 See the method llvm::DataLayout::getPointerSize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000222unsigned LLVMPointerSize(LLVMTargetDataRef TD);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000223
Micah Villmow4bb926d2012-10-15 16:24:29 +0000224/** Returns the pointer size in bytes for a target for a specified
225 address space.
226 See the method llvm::DataLayout::getPointerSize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000227unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
Micah Villmow4bb926d2012-10-15 16:24:29 +0000228
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000229/** Returns the integer type that is the same size as a pointer on a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000230 See the method llvm::DataLayout::getIntPtrType. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000231LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000232
Micah Villmow4bb926d2012-10-15 16:24:29 +0000233/** 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. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000236LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
Micah Villmow4bb926d2012-10-15 16:24:29 +0000237
Anders Waldenborg959f0402013-10-17 18:51:01 +0000238/** Returns the integer type that is the same size as a pointer on a target.
239 See the method llvm::DataLayout::getIntPtrType. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000240LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
Anders Waldenborg959f0402013-10-17 18:51:01 +0000241
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. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000245LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
246 unsigned AS);
Anders Waldenborg959f0402013-10-17 18:51:01 +0000247
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000248/** Computes the size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000249 See the method llvm::DataLayout::getTypeSizeInBits. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000250unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000251
252/** Computes the storage size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000253 See the method llvm::DataLayout::getTypeStoreSize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000254unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000255
256/** Computes the ABI size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000257 See the method llvm::DataLayout::getTypeAllocSize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000258unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000259
260/** Computes the ABI alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000261 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000262unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000263
264/** Computes the call frame alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000265 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000266unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000267
268/** Computes the preferred alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000269 See the method llvm::DataLayout::getTypeABISize. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000270unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000271
272/** Computes the preferred alignment of a global variable in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000273 See the method llvm::DataLayout::getPreferredAlignment. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000274unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000275 LLVMValueRef GlobalVar);
276
277/** Computes the structure element that contains the byte offset for a target.
278 See the method llvm::StructLayout::getElementContainingOffset. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000279unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000280 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. */
Peter Zotovf7e64fe2013-11-06 11:52:40 +0000284unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
285 LLVMTypeRef StructTy, unsigned Element);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000286
Gregory Szorc34c863a2012-03-21 03:54:29 +0000287/**
288 * @}
289 */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000290
291#ifdef __cplusplus
292}
Evan Cheng2e254d02013-04-04 17:40:53 +0000293#endif /* defined(__cplusplus) */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000294
295#endif