305 lines · c
1/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/2/* */3/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */4/* Exceptions. */5/* See https://llvm.org/LICENSE.txt for license information. */6/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */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_H20#define LLVM_C_TARGET_H21 22#include "llvm-c/ExternC.h"23#include "llvm-c/Types.h"24#include "llvm-c/Visibility.h"25#include "llvm/Config/llvm-config.h"26 27LLVM_C_EXTERN_C_BEGIN28 29/**30 * @defgroup LLVMCTarget Target information31 * @ingroup LLVMC32 *33 * @{34 */35 36enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };37 38typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;39typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;40 41/* Declare all of the target-initialization functions that are available. */42#define LLVM_TARGET(TargetName) \43 LLVM_C_ABI void LLVMInitialize##TargetName##TargetInfo(void);44#include "llvm/Config/Targets.def"45#undef LLVM_TARGET /* Explicit undef to make SWIG happier */46 47#define LLVM_TARGET(TargetName) \48 LLVM_C_ABI void LLVMInitialize##TargetName##Target(void);49#include "llvm/Config/Targets.def"50#undef LLVM_TARGET /* Explicit undef to make SWIG happier */51 52#define LLVM_TARGET(TargetName) \53 LLVM_C_ABI void LLVMInitialize##TargetName##TargetMC(void);54#include "llvm/Config/Targets.def"55#undef LLVM_TARGET /* Explicit undef to make SWIG happier */56 57/* Declare all of the available assembly printer initialization functions. */58#define LLVM_ASM_PRINTER(TargetName) \59 LLVM_C_ABI void LLVMInitialize##TargetName##AsmPrinter(void);60#include "llvm/Config/AsmPrinters.def"61#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */62 63/* Declare all of the available assembly parser initialization functions. */64#define LLVM_ASM_PARSER(TargetName) \65 LLVM_C_ABI void LLVMInitialize##TargetName##AsmParser(void);66#include "llvm/Config/AsmParsers.def"67#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */68 69/* Declare all of the available disassembler initialization functions. */70#define LLVM_DISASSEMBLER(TargetName) \71 LLVM_C_ABI void LLVMInitialize##TargetName##Disassembler(void);72#include "llvm/Config/Disassemblers.def"73#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */74 75/** LLVMInitializeAllTargetInfos - The main program should call this function if76 it wants access to all available targets that LLVM is configured to77 support. */78static inline void LLVMInitializeAllTargetInfos(void) {79#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();80#include "llvm/Config/Targets.def"81#undef LLVM_TARGET /* Explicit undef to make SWIG happier */82}83 84/** LLVMInitializeAllTargets - The main program should call this function if it85 wants to link in all available targets that LLVM is configured to86 support. */87static inline void LLVMInitializeAllTargets(void) {88#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();89#include "llvm/Config/Targets.def"90#undef LLVM_TARGET /* Explicit undef to make SWIG happier */91}92 93/** LLVMInitializeAllTargetMCs - The main program should call this function if94 it wants access to all available target MC that LLVM is configured to95 support. */96static inline void LLVMInitializeAllTargetMCs(void) {97#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();98#include "llvm/Config/Targets.def"99#undef LLVM_TARGET /* Explicit undef to make SWIG happier */100}101 102/** LLVMInitializeAllAsmPrinters - The main program should call this function if103 it wants all asm printers that LLVM is configured to support, to make them104 available via the TargetRegistry. */105static inline void LLVMInitializeAllAsmPrinters(void) {106#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();107#include "llvm/Config/AsmPrinters.def"108#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */109}110 111/** LLVMInitializeAllAsmParsers - The main program should call this function if112 it wants all asm parsers that LLVM is configured to support, to make them113 available via the TargetRegistry. */114static inline void LLVMInitializeAllAsmParsers(void) {115#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();116#include "llvm/Config/AsmParsers.def"117#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */118}119 120/** LLVMInitializeAllDisassemblers - The main program should call this function121 if it wants all disassemblers that LLVM is configured to support, to make122 them available via the TargetRegistry. */123static inline void LLVMInitializeAllDisassemblers(void) {124#define LLVM_DISASSEMBLER(TargetName) \125 LLVMInitialize##TargetName##Disassembler();126#include "llvm/Config/Disassemblers.def"127#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */128}129 130/** LLVMInitializeNativeTarget - The main program should call this function to131 initialize the native target corresponding to the host. This is useful132 for JIT applications to ensure that the target gets linked in correctly. */133static inline LLVMBool LLVMInitializeNativeTarget(void) {134 /* If we have a native target, initialize it to ensure it is linked in. */135#ifdef LLVM_NATIVE_TARGET136 LLVM_NATIVE_TARGETINFO();137 LLVM_NATIVE_TARGET();138 LLVM_NATIVE_TARGETMC();139 return 0;140#else141 return 1;142#endif143}144 145/** LLVMInitializeNativeTargetAsmParser - The main program should call this146 function to initialize the parser for the native target corresponding to the147 host. */148static inline LLVMBool LLVMInitializeNativeAsmParser(void) {149#ifdef LLVM_NATIVE_ASMPARSER150 LLVM_NATIVE_ASMPARSER();151 return 0;152#else153 return 1;154#endif155}156 157/** LLVMInitializeNativeTargetAsmPrinter - The main program should call this158 function to initialize the printer for the native target corresponding to159 the host. */160static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {161#ifdef LLVM_NATIVE_ASMPRINTER162 LLVM_NATIVE_ASMPRINTER();163 return 0;164#else165 return 1;166#endif167}168 169/** LLVMInitializeNativeTargetDisassembler - The main program should call this170 function to initialize the disassembler for the native target corresponding171 to the host. */172static inline LLVMBool LLVMInitializeNativeDisassembler(void) {173#ifdef LLVM_NATIVE_DISASSEMBLER174 LLVM_NATIVE_DISASSEMBLER();175 return 0;176#else177 return 1;178#endif179}180 181/*===-- Target Data -------------------------------------------------------===*/182 183/**184 * Obtain the data layout for a module.185 *186 * @see Module::getDataLayout()187 */188LLVM_C_ABI LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);189 190/**191 * Set the data layout for a module.192 *193 * @see Module::setDataLayout()194 */195LLVM_C_ABI void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);196 197/** Creates target data from a target layout string.198 See the constructor llvm::DataLayout::DataLayout. */199LLVM_C_ABI LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);200 201/** Deallocates a TargetData.202 See the destructor llvm::DataLayout::~DataLayout. */203LLVM_C_ABI void LLVMDisposeTargetData(LLVMTargetDataRef TD);204 205/** Adds target library information to a pass manager. This does not take206 ownership of the target library info.207 See the method llvm::PassManagerBase::add. */208LLVM_C_ABI void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,209 LLVMPassManagerRef PM);210 211/** Converts target data to a target layout string. The string must be disposed212 with LLVMDisposeMessage.213 See the constructor llvm::DataLayout::DataLayout. */214LLVM_C_ABI char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);215 216/** Returns the byte order of a target, either LLVMBigEndian or217 LLVMLittleEndian.218 See the method llvm::DataLayout::isLittleEndian. */219LLVM_C_ABI enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);220 221/** Returns the pointer size in bytes for a target.222 See the method llvm::DataLayout::getPointerSize. */223LLVM_C_ABI unsigned LLVMPointerSize(LLVMTargetDataRef TD);224 225/** Returns the pointer size in bytes for a target for a specified226 address space.227 See the method llvm::DataLayout::getPointerSize. */228LLVM_C_ABI unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);229 230/** Returns the integer type that is the same size as a pointer on a target.231 See the method llvm::DataLayout::getIntPtrType. */232LLVM_C_ABI LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);233 234/** Returns the integer type that is the same size as a pointer on a target.235 This version allows the address space to be specified.236 See the method llvm::DataLayout::getIntPtrType. */237LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);238 239/** Returns the integer type that is the same size as a pointer on a target.240 See the method llvm::DataLayout::getIntPtrType. */241LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C,242 LLVMTargetDataRef TD);243 244/** Returns the integer type that is the same size as a pointer on a target.245 This version allows the address space to be specified.246 See the method llvm::DataLayout::getIntPtrType. */247LLVM_C_ABI LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C,248 LLVMTargetDataRef TD,249 unsigned AS);250 251/** Computes the size of a type in bits for a target.252 See the method llvm::DataLayout::getTypeSizeInBits. */253LLVM_C_ABI unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD,254 LLVMTypeRef Ty);255 256/** Computes the storage size of a type in bytes for a target.257 See the method llvm::DataLayout::getTypeStoreSize. */258LLVM_C_ABI unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD,259 LLVMTypeRef Ty);260 261/** Computes the ABI size of a type in bytes for a target.262 See the method llvm::DataLayout::getTypeAllocSize. */263LLVM_C_ABI unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD,264 LLVMTypeRef Ty);265 266/** Computes the ABI alignment of a type in bytes for a target.267 See the method llvm::DataLayout::getTypeABISize. */268LLVM_C_ABI unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD,269 LLVMTypeRef Ty);270 271/** Computes the call frame alignment of a type in bytes for a target.272 See the method llvm::DataLayout::getTypeABISize. */273LLVM_C_ABI unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD,274 LLVMTypeRef Ty);275 276/** Computes the preferred alignment of a type in bytes for a target.277 See the method llvm::DataLayout::getTypeABISize. */278LLVM_C_ABI unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD,279 LLVMTypeRef Ty);280 281/** Computes the preferred alignment of a global variable in bytes for a target.282 See the method llvm::DataLayout::getPreferredAlignment. */283LLVM_C_ABI unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,284 LLVMValueRef GlobalVar);285 286/** Computes the structure element that contains the byte offset for a target.287 See the method llvm::StructLayout::getElementContainingOffset. */288LLVM_C_ABI unsigned LLVMElementAtOffset(LLVMTargetDataRef TD,289 LLVMTypeRef StructTy,290 unsigned long long Offset);291 292/** Computes the byte offset of the indexed struct element for a target.293 See the method llvm::StructLayout::getElementContainingOffset. */294LLVM_C_ABI unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,295 LLVMTypeRef StructTy,296 unsigned Element);297 298/**299 * @}300 */301 302LLVM_C_EXTERN_C_END303 304#endif305