1 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMTarget.a, which *|
11 |* implements target information. *|
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. *|
17 \*===----------------------------------------------------------------------===*/
19 #ifndef LLVM_C_TARGET_H
20 #define LLVM_C_TARGET_H
22 #include "llvm-c/Core.h"
23 #include "llvm/Config/config.h"
29 enum { LLVMBigEndian
, LLVMLittleEndian
};
30 typedef int LLVMByteOrdering
;
32 typedef struct LLVMOpaqueTargetData
*LLVMTargetDataRef
;
33 typedef struct LLVMStructLayout
*LLVMStructLayoutRef
;
35 /* Declare all of the target-initialization functions that are available. */
36 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
37 #include "llvm/Config/Targets.def"
39 /** LLVMInitializeAllTargets - The main program should call this function if it
40 wants to link in all available targets that LLVM is configured to
42 static inline void LLVMInitializeAllTargets() {
43 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
44 #include "llvm/Config/Targets.def"
47 /** LLVMInitializeNativeTarget - The main program should call this function to
48 initialize the native target corresponding to the host. This is useful
49 for JIT applications to ensure that the target gets linked in correctly. */
50 static inline int LLVMInitializeNativeTarget() {
51 /* If we have a native target, initialize it to ensure it is linked in. */
52 #ifdef LLVM_NATIVE_ARCH
53 #define DoInit2(TARG) LLVMInitialize ## TARG ()
54 #define DoInit(T) DoInit2(T)
55 DoInit(LLVM_NATIVE_ARCH
);
64 /*===-- Target Data -------------------------------------------------------===*/
66 /** Creates target data from a target layout string.
67 See the constructor llvm::TargetData::TargetData. */
68 LLVMTargetDataRef
LLVMCreateTargetData(const char *StringRep
);
70 /** Adds target data information to a pass manager. This does not take ownership
72 See the method llvm::PassManagerBase::add. */
73 void LLVMAddTargetData(LLVMTargetDataRef
, LLVMPassManagerRef
);
75 /** Converts target data to a target layout string. The string must be disposed
76 with LLVMDisposeMessage.
77 See the constructor llvm::TargetData::TargetData. */
78 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef
);
80 /** Returns the byte order of a target, either LLVMBigEndian or
82 See the method llvm::TargetData::isLittleEndian. */
83 LLVMByteOrdering
LLVMByteOrder(LLVMTargetDataRef
);
85 /** Returns the pointer size in bytes for a target.
86 See the method llvm::TargetData::getPointerSize. */
87 unsigned LLVMPointerSize(LLVMTargetDataRef
);
89 /** Returns the integer type that is the same size as a pointer on a target.
90 See the method llvm::TargetData::getIntPtrType. */
91 LLVMTypeRef
LLVMIntPtrType(LLVMTargetDataRef
);
93 /** Computes the size of a type in bytes for a target.
94 See the method llvm::TargetData::getTypeSizeInBits. */
95 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef
, LLVMTypeRef
);
97 /** Computes the storage size of a type in bytes for a target.
98 See the method llvm::TargetData::getTypeStoreSize. */
99 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef
, LLVMTypeRef
);
101 /** Computes the ABI size of a type in bytes for a target.
102 See the method llvm::TargetData::getTypeAllocSize. */
103 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef
, LLVMTypeRef
);
105 /** Computes the ABI alignment of a type in bytes for a target.
106 See the method llvm::TargetData::getTypeABISize. */
107 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
109 /** Computes the call frame alignment of a type in bytes for a target.
110 See the method llvm::TargetData::getTypeABISize. */
111 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
113 /** Computes the preferred alignment of a type in bytes for a target.
114 See the method llvm::TargetData::getTypeABISize. */
115 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef
, LLVMTypeRef
);
117 /** Computes the preferred alignment of a global variable in bytes for a target.
118 See the method llvm::TargetData::getPreferredAlignment. */
119 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef
,
120 LLVMValueRef GlobalVar
);
122 /** Computes the structure element that contains the byte offset for a target.
123 See the method llvm::StructLayout::getElementContainingOffset. */
124 unsigned LLVMElementAtOffset(LLVMTargetDataRef
, LLVMTypeRef StructTy
,
125 unsigned long long Offset
);
127 /** Computes the byte offset of the indexed struct element for a target.
128 See the method llvm::StructLayout::getElementContainingOffset. */
129 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef
, LLVMTypeRef StructTy
,
132 /** Struct layouts are speculatively cached. If a TargetDataRef is alive when
133 types are being refined and removed, this method must be called whenever a
134 struct type is removed to avoid a dangling pointer in this cache.
135 See the method llvm::TargetData::InvalidateStructLayoutInfo. */
136 void LLVMInvalidateStructLayout(LLVMTargetDataRef
, LLVMTypeRef StructTy
);
138 /** Deallocates a TargetData.
139 See the destructor llvm::TargetData::~TargetData. */
140 void LLVMDisposeTargetData(LLVMTargetDataRef
);
149 inline TargetData
*unwrap(LLVMTargetDataRef P
) {
150 return reinterpret_cast<TargetData
*>(P
);
153 inline LLVMTargetDataRef
wrap(const TargetData
*P
) {
154 return reinterpret_cast<LLVMTargetDataRef
>(const_cast<TargetData
*>(P
));
158 #endif /* defined(__cplusplus) */