blob: 7afaef15c419cd990d89d9889d026affcd72643c [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
Chris Lattner25963c62010-01-09 22:27:07 +000029enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000030
31typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +000032typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000033typedef struct LLVMStructLayout *LLVMStructLayoutRef;
34
Bob Wilson5a495fe2009-06-23 23:59:40 +000035/* Declare all of the target-initialization functions that are available. */
Eric Christopher135de902010-07-12 05:13:35 +000036#define LLVM_TARGET(TargetName) \
37 void LLVMInitialize##TargetName##TargetInfo(void);
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000038#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000039#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
40
Chris Lattneree3576e2010-04-28 20:24:45 +000041#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
Bob Wilson5a495fe2009-06-23 23:59:40 +000042#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000043#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000044
Evan Cheng1705ab02011-07-14 23:50:31 +000045#define LLVM_TARGET(TargetName) \
Evan Cheng8c886a42011-07-22 21:58:54 +000046 void LLVMInitialize##TargetName##TargetMC(void);
Evan Cheng2129f592011-07-19 06:37:02 +000047#include "llvm/Config/Targets.def"
48#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
49
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000050/** LLVMInitializeAllTargetInfos - The main program should call this function if
51 it wants access to all available targets that LLVM is configured to
52 support. */
Chris Lattner9d186472010-04-29 23:27:32 +000053static inline void LLVMInitializeAllTargetInfos(void) {
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000054#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
55#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000056#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Daniel Dunbarf4e7b6c2009-08-18 03:03:27 +000057}
58
Bob Wilson5a495fe2009-06-23 23:59:40 +000059/** LLVMInitializeAllTargets - The main program should call this function if it
60 wants to link in all available targets that LLVM is configured to
61 support. */
Chris Lattner9d186472010-04-29 23:27:32 +000062static inline void LLVMInitializeAllTargets(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +000063#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
64#include "llvm/Config/Targets.def"
Chris Lattnera0a51c72009-12-21 07:52:40 +000065#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
Bob Wilson5a495fe2009-06-23 23:59:40 +000066}
67
68/** LLVMInitializeNativeTarget - The main program should call this function to
69 initialize the native target corresponding to the host. This is useful
70 for JIT applications to ensure that the target gets linked in correctly. */
Chris Lattner9d186472010-04-29 23:27:32 +000071static inline LLVMBool LLVMInitializeNativeTarget(void) {
Bob Wilson5a495fe2009-06-23 23:59:40 +000072 /* If we have a native target, initialize it to ensure it is linked in. */
Eric Christophere7a9db12010-08-30 18:34:48 +000073#ifdef LLVM_NATIVE_TARGET
74 LLVM_NATIVE_TARGETINFO();
75 LLVM_NATIVE_TARGET();
Evan Cheng8c886a42011-07-22 21:58:54 +000076 LLVM_NATIVE_TARGETMC();
Bob Wilson5a495fe2009-06-23 23:59:40 +000077 return 0;
Bob Wilson5a495fe2009-06-23 23:59:40 +000078#else
79 return 1;
80#endif
81}
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000082
83/*===-- Target Data -------------------------------------------------------===*/
84
85/** Creates target data from a target layout string.
86 See the constructor llvm::TargetData::TargetData. */
87LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
88
89/** Adds target data information to a pass manager. This does not take ownership
90 of the target data.
91 See the method llvm::PassManagerBase::add. */
92void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
93
Rafael Espindolae96fd5a2011-07-25 21:20:54 +000094/** Adds target library information to a pass manager. This does not take
95 ownership of the target library info.
96 See the method llvm::PassManagerBase::add. */
97void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef);
98
Gordon Henriksenab4b7d32008-03-16 20:08:03 +000099/** Converts target data to a target layout string. The string must be disposed
100 with LLVMDisposeMessage.
101 See the constructor llvm::TargetData::TargetData. */
102char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
103
104/** Returns the byte order of a target, either LLVMBigEndian or
105 LLVMLittleEndian.
106 See the method llvm::TargetData::isLittleEndian. */
Chris Lattner51c49962010-01-09 23:25:21 +0000107enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000108
109/** Returns the pointer size in bytes for a target.
110 See the method llvm::TargetData::getPointerSize. */
111unsigned LLVMPointerSize(LLVMTargetDataRef);
112
113/** Returns the integer type that is the same size as a pointer on a target.
114 See the method llvm::TargetData::getIntPtrType. */
115LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
116
117/** Computes the size of a type in bytes for a target.
118 See the method llvm::TargetData::getTypeSizeInBits. */
119unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
120
121/** Computes the storage size of a type in bytes for a target.
122 See the method llvm::TargetData::getTypeStoreSize. */
123unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
124
125/** Computes the ABI size of a type in bytes for a target.
Duncan Sandsaf9eaa82009-05-09 07:06:46 +0000126 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000127unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
128
129/** Computes the ABI alignment of a type in bytes for a target.
130 See the method llvm::TargetData::getTypeABISize. */
131unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
132
133/** Computes the call frame alignment of a type in bytes for a target.
134 See the method llvm::TargetData::getTypeABISize. */
135unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
136
137/** Computes the preferred alignment of a type in bytes for a target.
138 See the method llvm::TargetData::getTypeABISize. */
139unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
140
141/** Computes the preferred alignment of a global variable in bytes for a target.
142 See the method llvm::TargetData::getPreferredAlignment. */
143unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
144 LLVMValueRef GlobalVar);
145
146/** Computes the structure element that contains the byte offset for a target.
147 See the method llvm::StructLayout::getElementContainingOffset. */
148unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
149 unsigned long long Offset);
150
151/** Computes the byte offset of the indexed struct element for a target.
152 See the method llvm::StructLayout::getElementContainingOffset. */
153unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
154 unsigned Element);
155
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000156/** Deallocates a TargetData.
157 See the destructor llvm::TargetData::~TargetData. */
158void LLVMDisposeTargetData(LLVMTargetDataRef);
159
160
161#ifdef __cplusplus
162}
163
164namespace llvm {
165 class TargetData;
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000166 class TargetLibraryInfo;
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000167
168 inline TargetData *unwrap(LLVMTargetDataRef P) {
169 return reinterpret_cast<TargetData*>(P);
170 }
171
172 inline LLVMTargetDataRef wrap(const TargetData *P) {
173 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
174 }
Rafael Espindolae96fd5a2011-07-25 21:20:54 +0000175
176 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
177 return reinterpret_cast<TargetLibraryInfo*>(P);
178 }
179
180 inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
181 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
182 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
183 }
Gordon Henriksenab4b7d32008-03-16 20:08:03 +0000184}
185
186#endif /* defined(__cplusplus) */
187
188#endif