Deleted Added
sdiff udiff text old ( 198090 ) new ( 201360 )
full compact
1/*===-- 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\*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
23#include "llvm/Config/config.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29enum { LLVMBigEndian, LLVMLittleEndian };
30typedef int LLVMByteOrdering;
31
32typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
33typedef struct LLVMStructLayout *LLVMStructLayoutRef;
34
35/* Declare all of the target-initialization functions that are available. */
36#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
37#include "llvm/Config/Targets.def"
38
39#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
40#include "llvm/Config/Targets.def"
41
42/** LLVMInitializeAllTargetInfos - The main program should call this function if
43 it wants access to all available targets that LLVM is configured to
44 support. */
45static inline void LLVMInitializeAllTargetInfos() {
46#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
47#include "llvm/Config/Targets.def"
48}
49
50/** LLVMInitializeAllTargets - The main program should call this function if it
51 wants to link in all available targets that LLVM is configured to
52 support. */
53static inline void LLVMInitializeAllTargets() {
54#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
55#include "llvm/Config/Targets.def"
56}
57
58/** LLVMInitializeNativeTarget - The main program should call this function to
59 initialize the native target corresponding to the host. This is useful
60 for JIT applications to ensure that the target gets linked in correctly. */
61static inline int LLVMInitializeNativeTarget() {
62 /* If we have a native target, initialize it to ensure it is linked in. */
63#ifdef LLVM_NATIVE_ARCH
64#define DoInit2(TARG) \
65 LLVMInitialize ## TARG ## Info (); \
66 LLVMInitialize ## TARG ()
67#define DoInit(T) DoInit2(T)
68 DoInit(LLVM_NATIVE_ARCH);
69 return 0;
70#undef DoInit
71#undef DoInit2
72#else
73 return 1;
74#endif
75}
76
77/*===-- Target Data -------------------------------------------------------===*/
78
79/** Creates target data from a target layout string.
80 See the constructor llvm::TargetData::TargetData. */
81LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
82
83/** Adds target data information to a pass manager. This does not take ownership
84 of the target data.
85 See the method llvm::PassManagerBase::add. */
86void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
87
88/** Converts target data to a target layout string. The string must be disposed
89 with LLVMDisposeMessage.
90 See the constructor llvm::TargetData::TargetData. */
91char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
92
93/** Returns the byte order of a target, either LLVMBigEndian or
94 LLVMLittleEndian.
95 See the method llvm::TargetData::isLittleEndian. */
96LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
97
98/** Returns the pointer size in bytes for a target.
99 See the method llvm::TargetData::getPointerSize. */
100unsigned LLVMPointerSize(LLVMTargetDataRef);
101
102/** Returns the integer type that is the same size as a pointer on a target.
103 See the method llvm::TargetData::getIntPtrType. */
104LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
105
106/** Computes the size of a type in bytes for a target.
107 See the method llvm::TargetData::getTypeSizeInBits. */
108unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
109
110/** Computes the storage size of a type in bytes for a target.
111 See the method llvm::TargetData::getTypeStoreSize. */
112unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
113
114/** Computes the ABI size of a type in bytes for a target.
115 See the method llvm::TargetData::getTypeAllocSize. */
116unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
117
118/** Computes the ABI alignment of a type in bytes for a target.
119 See the method llvm::TargetData::getTypeABISize. */
120unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
121
122/** Computes the call frame alignment of a type in bytes for a target.
123 See the method llvm::TargetData::getTypeABISize. */
124unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
125
126/** Computes the preferred alignment of a type in bytes for a target.
127 See the method llvm::TargetData::getTypeABISize. */
128unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
129
130/** Computes the preferred alignment of a global variable in bytes for a target.
131 See the method llvm::TargetData::getPreferredAlignment. */
132unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
133 LLVMValueRef GlobalVar);
134
135/** Computes the structure element that contains the byte offset for a target.
136 See the method llvm::StructLayout::getElementContainingOffset. */
137unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
138 unsigned long long Offset);
139
140/** Computes the byte offset of the indexed struct element for a target.
141 See the method llvm::StructLayout::getElementContainingOffset. */
142unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
143 unsigned Element);
144
145/** Struct layouts are speculatively cached. If a TargetDataRef is alive when
146 types are being refined and removed, this method must be called whenever a
147 struct type is removed to avoid a dangling pointer in this cache.
148 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
149void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
150
151/** Deallocates a TargetData.
152 See the destructor llvm::TargetData::~TargetData. */
153void LLVMDisposeTargetData(LLVMTargetDataRef);
154
155
156#ifdef __cplusplus
157}
158
159namespace llvm {
160 class TargetData;
161
162 inline TargetData *unwrap(LLVMTargetDataRef P) {
163 return reinterpret_cast<TargetData*>(P);
164 }
165
166 inline LLVMTargetDataRef wrap(const TargetData *P) {
167 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
168 }
169}
170
171#endif /* defined(__cplusplus) */
172
173#endif