blob: bb423bbaadfc3bec18e8dc74ad55d8294a18f53e [file] [log] [blame]
Gordon Henriksen3e0c8352008-03-16 20:08:03 +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\*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_TARGET_H
20#define LLVM_C_TARGET_H
21
22#include "llvm-c/Core.h"
Bob Wilsona96751f2009-06-23 23:59:40 +000023#include "llvm/Config/config.h"
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000024
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29enum { LLVMBigEndian, LLVMLittleEndian };
30typedef int LLVMByteOrdering;
31
32typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
33typedef struct LLVMStructLayout *LLVMStructLayoutRef;
34
Bob Wilsona96751f2009-06-23 23:59:40 +000035/* 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"
38
39/** LLVMInitializeAllTargets - The main program should call this function if it
40 wants to link in all available targets that LLVM is configured to
41 support. */
42static inline void LLVMInitializeAllTargets() {
43#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
44#include "llvm/Config/Targets.def"
45}
46
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. */
50static 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);
56 return 0;
57#undef DoInit
58#undef DoInit2
59#else
60 return 1;
61#endif
62}
Gordon Henriksen3e0c8352008-03-16 20:08:03 +000063
64/*===-- Target Data -------------------------------------------------------===*/
65
66/** Creates target data from a target layout string.
67 See the constructor llvm::TargetData::TargetData. */
68LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
69
70/** Adds target data information to a pass manager. This does not take ownership
71 of the target data.
72 See the method llvm::PassManagerBase::add. */
73void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
74
75/** Converts target data to a target layout string. The string must be disposed
76 with LLVMDisposeMessage.
77 See the constructor llvm::TargetData::TargetData. */
78char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
79
80/** Returns the byte order of a target, either LLVMBigEndian or
81 LLVMLittleEndian.
82 See the method llvm::TargetData::isLittleEndian. */
83LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
84
85/** Returns the pointer size in bytes for a target.
86 See the method llvm::TargetData::getPointerSize. */
87unsigned LLVMPointerSize(LLVMTargetDataRef);
88
89/** Returns the integer type that is the same size as a pointer on a target.
90 See the method llvm::TargetData::getIntPtrType. */
91LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
92
93/** Computes the size of a type in bytes for a target.
94 See the method llvm::TargetData::getTypeSizeInBits. */
95unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
96
97/** Computes the storage size of a type in bytes for a target.
98 See the method llvm::TargetData::getTypeStoreSize. */
99unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
100
101/** Computes the ABI size of a type in bytes for a target.
Duncan Sands777d2302009-05-09 07:06:46 +0000102 See the method llvm::TargetData::getTypeAllocSize. */
Gordon Henriksen3e0c8352008-03-16 20:08:03 +0000103unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
104
105/** Computes the ABI alignment of a type in bytes for a target.
106 See the method llvm::TargetData::getTypeABISize. */
107unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
108
109/** Computes the call frame alignment of a type in bytes for a target.
110 See the method llvm::TargetData::getTypeABISize. */
111unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
112
113/** Computes the preferred alignment of a type in bytes for a target.
114 See the method llvm::TargetData::getTypeABISize. */
115unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
116
117/** Computes the preferred alignment of a global variable in bytes for a target.
118 See the method llvm::TargetData::getPreferredAlignment. */
119unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
120 LLVMValueRef GlobalVar);
121
122/** Computes the structure element that contains the byte offset for a target.
123 See the method llvm::StructLayout::getElementContainingOffset. */
124unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
125 unsigned long long Offset);
126
127/** Computes the byte offset of the indexed struct element for a target.
128 See the method llvm::StructLayout::getElementContainingOffset. */
129unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
130 unsigned Element);
131
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. */
136void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
137
138/** Deallocates a TargetData.
139 See the destructor llvm::TargetData::~TargetData. */
140void LLVMDisposeTargetData(LLVMTargetDataRef);
141
142
143#ifdef __cplusplus
144}
145
146namespace llvm {
147 class TargetData;
148
149 inline TargetData *unwrap(LLVMTargetDataRef P) {
150 return reinterpret_cast<TargetData*>(P);
151 }
152
153 inline LLVMTargetDataRef wrap(const TargetData *P) {
154 return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
155 }
156}
157
158#endif /* defined(__cplusplus) */
159
160#endif