Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/Target.h
35234 views
/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/1/* */2/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */3/* Exceptions. */4/* See https://llvm.org/LICENSE.txt for license information. */5/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */6/* */7/*===----------------------------------------------------------------------===*/8/* */9/* This header declares the C interface to libLLVMTarget.a, which */10/* implements target information. */11/* */12/* Many exotic languages can interoperate with C code but have a harder time */13/* with C++ due to name mangling. So in addition to C, this interface enables */14/* tools written in such languages. */15/* */16/*===----------------------------------------------------------------------===*/1718#ifndef LLVM_C_TARGET_H19#define LLVM_C_TARGET_H2021#include "llvm-c/ExternC.h"22#include "llvm-c/Types.h"23#include "llvm/Config/llvm-config.h"2425LLVM_C_EXTERN_C_BEGIN2627/**28* @defgroup LLVMCTarget Target information29* @ingroup LLVMC30*31* @{32*/3334enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };3536typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;37typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;3839/* Declare all of the target-initialization functions that are available. */40#define LLVM_TARGET(TargetName) \41void LLVMInitialize##TargetName##TargetInfo(void);42#include "llvm/Config/Targets.def"43#undef LLVM_TARGET /* Explicit undef to make SWIG happier */4445#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);46#include "llvm/Config/Targets.def"47#undef LLVM_TARGET /* Explicit undef to make SWIG happier */4849#define LLVM_TARGET(TargetName) \50void LLVMInitialize##TargetName##TargetMC(void);51#include "llvm/Config/Targets.def"52#undef LLVM_TARGET /* Explicit undef to make SWIG happier */5354/* Declare all of the available assembly printer initialization functions. */55#define LLVM_ASM_PRINTER(TargetName) \56void LLVMInitialize##TargetName##AsmPrinter(void);57#include "llvm/Config/AsmPrinters.def"58#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */5960/* Declare all of the available assembly parser initialization functions. */61#define LLVM_ASM_PARSER(TargetName) \62void LLVMInitialize##TargetName##AsmParser(void);63#include "llvm/Config/AsmParsers.def"64#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */6566/* Declare all of the available disassembler initialization functions. */67#define LLVM_DISASSEMBLER(TargetName) \68void LLVMInitialize##TargetName##Disassembler(void);69#include "llvm/Config/Disassemblers.def"70#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */7172/** LLVMInitializeAllTargetInfos - The main program should call this function if73it wants access to all available targets that LLVM is configured to74support. */75static inline void LLVMInitializeAllTargetInfos(void) {76#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();77#include "llvm/Config/Targets.def"78#undef LLVM_TARGET /* Explicit undef to make SWIG happier */79}8081/** LLVMInitializeAllTargets - The main program should call this function if it82wants to link in all available targets that LLVM is configured to83support. */84static inline void LLVMInitializeAllTargets(void) {85#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();86#include "llvm/Config/Targets.def"87#undef LLVM_TARGET /* Explicit undef to make SWIG happier */88}8990/** LLVMInitializeAllTargetMCs - The main program should call this function if91it wants access to all available target MC that LLVM is configured to92support. */93static inline void LLVMInitializeAllTargetMCs(void) {94#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();95#include "llvm/Config/Targets.def"96#undef LLVM_TARGET /* Explicit undef to make SWIG happier */97}9899/** LLVMInitializeAllAsmPrinters - The main program should call this function if100it wants all asm printers that LLVM is configured to support, to make them101available via the TargetRegistry. */102static inline void LLVMInitializeAllAsmPrinters(void) {103#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();104#include "llvm/Config/AsmPrinters.def"105#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */106}107108/** LLVMInitializeAllAsmParsers - The main program should call this function if109it wants all asm parsers that LLVM is configured to support, to make them110available via the TargetRegistry. */111static inline void LLVMInitializeAllAsmParsers(void) {112#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();113#include "llvm/Config/AsmParsers.def"114#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */115}116117/** LLVMInitializeAllDisassemblers - The main program should call this function118if it wants all disassemblers that LLVM is configured to support, to make119them available via the TargetRegistry. */120static inline void LLVMInitializeAllDisassemblers(void) {121#define LLVM_DISASSEMBLER(TargetName) \122LLVMInitialize##TargetName##Disassembler();123#include "llvm/Config/Disassemblers.def"124#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */125}126127/** LLVMInitializeNativeTarget - The main program should call this function to128initialize the native target corresponding to the host. This is useful129for JIT applications to ensure that the target gets linked in correctly. */130static inline LLVMBool LLVMInitializeNativeTarget(void) {131/* If we have a native target, initialize it to ensure it is linked in. */132#ifdef LLVM_NATIVE_TARGET133LLVM_NATIVE_TARGETINFO();134LLVM_NATIVE_TARGET();135LLVM_NATIVE_TARGETMC();136return 0;137#else138return 1;139#endif140}141142/** LLVMInitializeNativeTargetAsmParser - The main program should call this143function to initialize the parser for the native target corresponding to the144host. */145static inline LLVMBool LLVMInitializeNativeAsmParser(void) {146#ifdef LLVM_NATIVE_ASMPARSER147LLVM_NATIVE_ASMPARSER();148return 0;149#else150return 1;151#endif152}153154/** LLVMInitializeNativeTargetAsmPrinter - The main program should call this155function to initialize the printer for the native target corresponding to156the host. */157static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {158#ifdef LLVM_NATIVE_ASMPRINTER159LLVM_NATIVE_ASMPRINTER();160return 0;161#else162return 1;163#endif164}165166/** LLVMInitializeNativeTargetDisassembler - The main program should call this167function to initialize the disassembler for the native target corresponding168to the host. */169static inline LLVMBool LLVMInitializeNativeDisassembler(void) {170#ifdef LLVM_NATIVE_DISASSEMBLER171LLVM_NATIVE_DISASSEMBLER();172return 0;173#else174return 1;175#endif176}177178/*===-- Target Data -------------------------------------------------------===*/179180/**181* Obtain the data layout for a module.182*183* @see Module::getDataLayout()184*/185LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);186187/**188* Set the data layout for a module.189*190* @see Module::setDataLayout()191*/192void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);193194/** Creates target data from a target layout string.195See the constructor llvm::DataLayout::DataLayout. */196LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);197198/** Deallocates a TargetData.199See the destructor llvm::DataLayout::~DataLayout. */200void LLVMDisposeTargetData(LLVMTargetDataRef TD);201202/** Adds target library information to a pass manager. This does not take203ownership of the target library info.204See the method llvm::PassManagerBase::add. */205void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,206LLVMPassManagerRef PM);207208/** Converts target data to a target layout string. The string must be disposed209with LLVMDisposeMessage.210See the constructor llvm::DataLayout::DataLayout. */211char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);212213/** Returns the byte order of a target, either LLVMBigEndian or214LLVMLittleEndian.215See the method llvm::DataLayout::isLittleEndian. */216enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);217218/** Returns the pointer size in bytes for a target.219See the method llvm::DataLayout::getPointerSize. */220unsigned LLVMPointerSize(LLVMTargetDataRef TD);221222/** Returns the pointer size in bytes for a target for a specified223address space.224See the method llvm::DataLayout::getPointerSize. */225unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);226227/** Returns the integer type that is the same size as a pointer on a target.228See the method llvm::DataLayout::getIntPtrType. */229LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);230231/** Returns the integer type that is the same size as a pointer on a target.232This version allows the address space to be specified.233See the method llvm::DataLayout::getIntPtrType. */234LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);235236/** Returns the integer type that is the same size as a pointer on a target.237See the method llvm::DataLayout::getIntPtrType. */238LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);239240/** Returns the integer type that is the same size as a pointer on a target.241This version allows the address space to be specified.242See the method llvm::DataLayout::getIntPtrType. */243LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,244unsigned AS);245246/** Computes the size of a type in bytes for a target.247See the method llvm::DataLayout::getTypeSizeInBits. */248unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);249250/** Computes the storage size of a type in bytes for a target.251See the method llvm::DataLayout::getTypeStoreSize. */252unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);253254/** Computes the ABI size of a type in bytes for a target.255See the method llvm::DataLayout::getTypeAllocSize. */256unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);257258/** Computes the ABI alignment of a type in bytes for a target.259See the method llvm::DataLayout::getTypeABISize. */260unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);261262/** Computes the call frame alignment of a type in bytes for a target.263See the method llvm::DataLayout::getTypeABISize. */264unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);265266/** Computes the preferred alignment of a type in bytes for a target.267See the method llvm::DataLayout::getTypeABISize. */268unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);269270/** Computes the preferred alignment of a global variable in bytes for a target.271See the method llvm::DataLayout::getPreferredAlignment. */272unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,273LLVMValueRef GlobalVar);274275/** Computes the structure element that contains the byte offset for a target.276See the method llvm::StructLayout::getElementContainingOffset. */277unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,278unsigned long long Offset);279280/** Computes the byte offset of the indexed struct element for a target.281See the method llvm::StructLayout::getElementContainingOffset. */282unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,283LLVMTypeRef StructTy, unsigned Element);284285/**286* @}287*/288289LLVM_C_EXTERN_C_END290291#endif292293294