blob: 1d7884f14247d7821c5534f6a7f92e7346b6f25f [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
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 +000040typedef struct LLVMStructLayout *LLVMStructLayoutRef;
41
Bob Wilson5a495fe2009-06-23 23:59:40 +000042/* Declare all of the target-initialization functions that are available. */
Eric Christopher135de902010-07-12 05:13:35 +000043#define LLVM_TARGET(TargetName) \
44 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000045#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000046#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
47
Chris Lattneree3576e2010-04-28 20:24:45 +000048#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilson5a495fe2009-06-23 23:59:40 +000049#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000050#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000051
Evan Cheng1705ab02011-07-14 23:50:31 +000052#define LLVM_TARGET(TargetName) \
Evan Cheng8c886a42011-07-22 21:58:54 +000053 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng2129f592011-07-19 06:37:02 +000054#include "llvm/Config/Targets.def"
55#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
56
Daniel Dunbar69987ab2011-11-29 00:06:55 +000057/* Declare all of the available assembly printer initialization functions. */
58#define LLVM_ASM_PRINTER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000059 void LLVMInitialize##TargetName##AsmPrinter(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000060#include "llvm/Config/AsmPrinters.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000061#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000062
63/* Declare all of the available assembly parser initialization functions. */
64#define LLVM_ASM_PARSER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000065 void LLVMInitialize##TargetName##AsmParser(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000066#include "llvm/Config/AsmParsers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000067#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */
Daniel Dunbar69987ab2011-11-29 00:06:55 +000068
69/* Declare all of the available disassembler initialization functions. */
70#define LLVM_DISASSEMBLER(TargetName) \
Anders Waldenborg38ce8612012-05-02 16:15:32 +000071 void LLVMInitialize##TargetName##Disassembler(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000072#include "llvm/Config/Disassemblers.def"
Bill Wendling12a98c92012-03-26 22:15:12 +000073#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000074
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000075/** LLVMInitializeAllTargetInfos - The main program should call this function if
76 it wants access to all available targets that LLVM is configured to
77 support. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000078void LLVMInitializeAllTargetInfos(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000079
Bob Wilson5a495fe2009-06-23 23:59:40 +000080/** LLVMInitializeAllTargets - The main program should call this function if it
81 wants to link in all available targets that LLVM is configured to
82 support. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000083void LLVMInitializeAllTargets(void);
Daniel Dunbar69987ab2011-11-29 00:06:55 +000084
85/** LLVMInitializeAllTargetMCs - The main program should call this function if
86 it wants access to all available target MC that LLVM is configured to
87 support. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000088void LLVMInitializeAllTargetMCs(void);
89
Daniel Dunbar69987ab2011-11-29 00:06:55 +000090/** LLVMInitializeAllAsmPrinters - The main program should call this function if
91 it wants all asm printers that LLVM is configured to support, to make them
92 available via the TargetRegistry. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000093void LLVMInitializeAllAsmPrinters(void);
94
Daniel Dunbar69987ab2011-11-29 00:06:55 +000095/** LLVMInitializeAllAsmParsers - The main program should call this function if
96 it wants all asm parsers that LLVM is configured to support, to make them
97 available via the TargetRegistry. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +000098void LLVMInitializeAllAsmParsers(void);
99
Daniel Dunbar69987ab2011-11-29 00:06:55 +0000100/** LLVMInitializeAllDisassemblers - The main program should call this function
101 if it wants all disassemblers that LLVM is configured to support, to make
102 them available via the TargetRegistry. */
Anders Waldenborg1d9cb432013-10-15 12:08:59 +0000103void LLVMInitializeAllDisassemblers(void);
104
Bob Wilson5a495fe2009-06-23 23:59:40 +0000105/** LLVMInitializeNativeTarget - The main program should call this function to
106 initialize the native target corresponding to the host. This is useful
107 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattner9d186472010-04-29 23:27:32 +0000108static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +0000109 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christophere7a9db12010-08-30 18:34:48 +0000110#ifdef LLVM_NATIVE_TARGET
111 LLVM_NATIVE_TARGETINFO();
112 LLVM_NATIVE_TARGET();
Evan Cheng8c886a42011-07-22 21:58:54 +0000113 LLVM_NATIVE_TARGETMC();
Bob Wilson5a495fe2009-06-23 23:59:40 +0000114 return 0;
Bob Wilson5a495fe2009-06-23 23:59:40 +0000115#else
116 return 1;
117#endif
118}
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000119
120/*===-- Target Data -------------------------------------------------------===*/
121
122/** Creates target data from a target layout string.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000123 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000124LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
125
126/** Adds target data information to a pass manager. This does not take ownership
127 of the target data.
128 See the method llvm::PassManagerBase::add. */
129void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
130
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000131/** Adds target library information to a pass manager. This does not take
132 ownership of the target library info.
133 See the method llvm::PassManagerBase::add. */
134void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
135
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000136/** Converts target data to a target layout string. The string must be disposed
137 with LLVMDisposeMessage.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000138 See the constructor llvm::DataLayout::DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000139char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
140
141/** Returns the byte order of a target, either LLVMBigEndian or
142 LLVMLittleEndian.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000143 See the method llvm::DataLayout::isLittleEndian. */
Chris Lattner51c49962010-01-09 23:25:21 +0000144enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000145
146/** Returns the pointer size in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000147 See the method llvm::DataLayout::getPointerSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000148unsigned LLVMPointerSize(LLVMTargetDataRef);
149
Micah Villmow4bb926d2012-10-15 16:24:29 +0000150/** Returns the pointer size in bytes for a target for a specified
151 address space.
152 See the method llvm::DataLayout::getPointerSize. */
153unsigned LLVMPointerSizeForAS(LLVMTargetDataRef, unsigned AS);
154
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000155/** Returns the integer type that is the same size as a pointer on a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000156 See the method llvm::DataLayout::getIntPtrType. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000157LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
158
Micah Villmow4bb926d2012-10-15 16:24:29 +0000159/** Returns the integer type that is the same size as a pointer on a target.
160 This version allows the address space to be specified.
161 See the method llvm::DataLayout::getIntPtrType. */
162LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef, unsigned AS);
163
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000164/** Computes the size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000165 See the method llvm::DataLayout::getTypeSizeInBits. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000166unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
167
168/** Computes the storage size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000169 See the method llvm::DataLayout::getTypeStoreSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000170unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
171
172/** Computes the ABI size of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000173 See the method llvm::DataLayout::getTypeAllocSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000174unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
175
176/** Computes the ABI alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000177 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000178unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
179
180/** Computes the call frame alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000181 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000182unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
183
184/** Computes the preferred alignment of a type in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000185 See the method llvm::DataLayout::getTypeABISize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000186unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
187
188/** Computes the preferred alignment of a global variable in bytes for a target.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000189 See the method llvm::DataLayout::getPreferredAlignment. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000190unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
191 LLVMValueRef GlobalVar);
192
193/** Computes the structure element that contains the byte offset for a target.
194 See the method llvm::StructLayout::getElementContainingOffset. */
195unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
196 unsigned long long Offset);
197
198/** Computes the byte offset of the indexed struct element for a target.
199 See the method llvm::StructLayout::getElementContainingOffset. */
200unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
201 unsigned Element);
202
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000203/** Deallocates a TargetData.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000204 See the destructor llvm::DataLayout::~DataLayout. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000205void LLVMDisposeTargetData(LLVMTargetDataRef);
206
Gregory Szorc34c863a2012-03-21 03:54:29 +0000207/**
208 * @}
209 */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000210
211#ifdef __cplusplus
212}
Evan Cheng2e254d02013-04-04 17:40:53 +0000213#endif /* defined(__cplusplus) */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000214
215#endif