LLVM API Documentation

Target.h

Go to the documentation of this file.
00001 /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header declares the C interface to libLLVMTarget.a, which             *|
00011 |* implements target information.                                             *|
00012 |*                                                                            *|
00013 |* Many exotic languages can interoperate with C code but have a harder time  *|
00014 |* with C++ due to name mangling. So in addition to C, this interface enables *|
00015 |* tools written in such languages.                                           *|
00016 |*                                                                            *|
00017 \*===----------------------------------------------------------------------===*/
00018 
00019 #ifndef LLVM_C_TARGET_H
00020 #define LLVM_C_TARGET_H
00021 
00022 #include "llvm-c/Core.h"
00023 #include "llvm/Config/config.h"
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 enum { LLVMBigEndian, LLVMLittleEndian };
00030 typedef int LLVMByteOrdering;
00031 
00032 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
00033 typedef struct LLVMStructLayout *LLVMStructLayoutRef;
00034 
00035 /* Declare all of the target-initialization functions that are available. */
00036 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
00037 #include "llvm/Config/Targets.def"
00038 
00039 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
00040 #include "llvm/Config/Targets.def"
00041 
00042 /** LLVMInitializeAllTargetInfos - The main program should call this function if
00043     it wants access to all available targets that LLVM is configured to
00044     support. */
00045 static inline void LLVMInitializeAllTargetInfos() {
00046 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
00047 #include "llvm/Config/Targets.def"
00048 }
00049 
00050 /** LLVMInitializeAllTargets - The main program should call this function if it
00051     wants to link in all available targets that LLVM is configured to
00052     support. */
00053 static inline void LLVMInitializeAllTargets() {
00054 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
00055 #include "llvm/Config/Targets.def"
00056 }
00057   
00058 /** LLVMInitializeNativeTarget - The main program should call this function to
00059     initialize the native target corresponding to the host.  This is useful 
00060     for JIT applications to ensure that the target gets linked in correctly. */
00061 static inline int LLVMInitializeNativeTarget() {
00062   /* If we have a native target, initialize it to ensure it is linked in. */
00063 #ifdef LLVM_NATIVE_ARCH
00064 #define DoInit2(TARG) \
00065   LLVMInitialize ## TARG ## Info ();          \
00066   LLVMInitialize ## TARG ()
00067 #define DoInit(T) DoInit2(T)
00068   DoInit(LLVM_NATIVE_ARCH);
00069   return 0;
00070 #undef DoInit
00071 #undef DoInit2
00072 #else
00073   return 1;
00074 #endif
00075 }  
00076 
00077 /*===-- Target Data -------------------------------------------------------===*/
00078 
00079 /** Creates target data from a target layout string.
00080     See the constructor llvm::TargetData::TargetData. */
00081 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
00082 
00083 /** Adds target data information to a pass manager. This does not take ownership
00084     of the target data.
00085     See the method llvm::PassManagerBase::add. */
00086 void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef);
00087 
00088 /** Converts target data to a target layout string. The string must be disposed
00089     with LLVMDisposeMessage.
00090     See the constructor llvm::TargetData::TargetData. */
00091 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
00092 
00093 /** Returns the byte order of a target, either LLVMBigEndian or
00094     LLVMLittleEndian.
00095     See the method llvm::TargetData::isLittleEndian. */
00096 LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
00097 
00098 /** Returns the pointer size in bytes for a target.
00099     See the method llvm::TargetData::getPointerSize. */
00100 unsigned LLVMPointerSize(LLVMTargetDataRef);
00101 
00102 /** Returns the integer type that is the same size as a pointer on a target.
00103     See the method llvm::TargetData::getIntPtrType. */
00104 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
00105 
00106 /** Computes the size of a type in bytes for a target.
00107     See the method llvm::TargetData::getTypeSizeInBits. */
00108 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
00109 
00110 /** Computes the storage size of a type in bytes for a target.
00111     See the method llvm::TargetData::getTypeStoreSize. */
00112 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
00113 
00114 /** Computes the ABI size of a type in bytes for a target.
00115     See the method llvm::TargetData::getTypeAllocSize. */
00116 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
00117 
00118 /** Computes the ABI alignment of a type in bytes for a target.
00119     See the method llvm::TargetData::getTypeABISize. */
00120 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
00121 
00122 /** Computes the call frame alignment of a type in bytes for a target.
00123     See the method llvm::TargetData::getTypeABISize. */
00124 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
00125 
00126 /** Computes the preferred alignment of a type in bytes for a target.
00127     See the method llvm::TargetData::getTypeABISize. */
00128 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
00129 
00130 /** Computes the preferred alignment of a global variable in bytes for a target.
00131     See the method llvm::TargetData::getPreferredAlignment. */
00132 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
00133                                         LLVMValueRef GlobalVar);
00134 
00135 /** Computes the structure element that contains the byte offset for a target.
00136     See the method llvm::StructLayout::getElementContainingOffset. */
00137 unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy,
00138                              unsigned long long Offset);
00139 
00140 /** Computes the byte offset of the indexed struct element for a target.
00141     See the method llvm::StructLayout::getElementContainingOffset. */
00142 unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
00143                                        unsigned Element);
00144 
00145 /** Struct layouts are speculatively cached. If a TargetDataRef is alive when
00146     types are being refined and removed, this method must be called whenever a
00147     struct type is removed to avoid a dangling pointer in this cache.
00148     See the method llvm::TargetData::InvalidateStructLayoutInfo. */
00149 void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy);
00150 
00151 /** Deallocates a TargetData.
00152     See the destructor llvm::TargetData::~TargetData. */
00153 void LLVMDisposeTargetData(LLVMTargetDataRef);
00154 
00155 
00156 #ifdef __cplusplus
00157 }
00158 
00159 namespace llvm {
00160   class TargetData;
00161 
00162   inline TargetData *unwrap(LLVMTargetDataRef P) {
00163     return reinterpret_cast<TargetData*>(P);
00164   }
00165   
00166   inline LLVMTargetDataRef wrap(const TargetData *P) {
00167     return reinterpret_cast<LLVMTargetDataRef>(const_cast<TargetData*>(P));
00168   }
00169 }
00170 
00171 #endif /* defined(__cplusplus) */
00172 
00173 #endif