xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm-c/Target.h (revision 5b27928474e6a4103d65b347544705c40c9618fd)
10b57cec5SDimitry Andric /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
20b57cec5SDimitry Andric /*                                                                            */
30b57cec5SDimitry Andric /* Part of the LLVM Project, under the Apache License v2.0 with LLVM          */
40b57cec5SDimitry Andric /* Exceptions.                                                                */
50b57cec5SDimitry Andric /* See https://llvm.org/LICENSE.txt for license information.                  */
60b57cec5SDimitry Andric /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    */
70b57cec5SDimitry Andric /*                                                                            */
80b57cec5SDimitry Andric /*===----------------------------------------------------------------------===*/
90b57cec5SDimitry Andric /*                                                                            */
100b57cec5SDimitry Andric /* This header declares the C interface to libLLVMTarget.a, which             */
110b57cec5SDimitry Andric /* implements target information.                                             */
120b57cec5SDimitry Andric /*                                                                            */
130b57cec5SDimitry Andric /* Many exotic languages can interoperate with C code but have a harder time  */
140b57cec5SDimitry Andric /* with C++ due to name mangling. So in addition to C, this interface enables */
150b57cec5SDimitry Andric /* tools written in such languages.                                           */
160b57cec5SDimitry Andric /*                                                                            */
170b57cec5SDimitry Andric /*===----------------------------------------------------------------------===*/
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric #ifndef LLVM_C_TARGET_H
200b57cec5SDimitry Andric #define LLVM_C_TARGET_H
210b57cec5SDimitry Andric 
22*480093f4SDimitry Andric #include "llvm-c/ExternC.h"
230b57cec5SDimitry Andric #include "llvm-c/Types.h"
240b57cec5SDimitry Andric #include "llvm/Config/llvm-config.h"
250b57cec5SDimitry Andric 
26*480093f4SDimitry Andric LLVM_C_EXTERN_C_BEGIN
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric /**
290b57cec5SDimitry Andric  * @defgroup LLVMCTarget Target information
300b57cec5SDimitry Andric  * @ingroup LLVMC
310b57cec5SDimitry Andric  *
320b57cec5SDimitry Andric  * @{
330b57cec5SDimitry Andric  */
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
380b57cec5SDimitry Andric typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric /* Declare all of the target-initialization functions that are available. */
410b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) \
420b57cec5SDimitry Andric   void LLVMInitialize##TargetName##TargetInfo(void);
430b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
440b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void);
470b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
480b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) \
510b57cec5SDimitry Andric   void LLVMInitialize##TargetName##TargetMC(void);
520b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
530b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric /* Declare all of the available assembly printer initialization functions. */
560b57cec5SDimitry Andric #define LLVM_ASM_PRINTER(TargetName) \
570b57cec5SDimitry Andric   void LLVMInitialize##TargetName##AsmPrinter(void);
580b57cec5SDimitry Andric #include "llvm/Config/AsmPrinters.def"
590b57cec5SDimitry Andric #undef LLVM_ASM_PRINTER  /* Explicit undef to make SWIG happier */
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric /* Declare all of the available assembly parser initialization functions. */
620b57cec5SDimitry Andric #define LLVM_ASM_PARSER(TargetName) \
630b57cec5SDimitry Andric   void LLVMInitialize##TargetName##AsmParser(void);
640b57cec5SDimitry Andric #include "llvm/Config/AsmParsers.def"
650b57cec5SDimitry Andric #undef LLVM_ASM_PARSER  /* Explicit undef to make SWIG happier */
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric /* Declare all of the available disassembler initialization functions. */
680b57cec5SDimitry Andric #define LLVM_DISASSEMBLER(TargetName) \
690b57cec5SDimitry Andric   void LLVMInitialize##TargetName##Disassembler(void);
700b57cec5SDimitry Andric #include "llvm/Config/Disassemblers.def"
710b57cec5SDimitry Andric #undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric /** LLVMInitializeAllTargetInfos - The main program should call this function if
740b57cec5SDimitry Andric     it wants access to all available targets that LLVM is configured to
750b57cec5SDimitry Andric     support. */
LLVMInitializeAllTargetInfos(void)760b57cec5SDimitry Andric static inline void LLVMInitializeAllTargetInfos(void) {
770b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
780b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
790b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
800b57cec5SDimitry Andric }
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric /** LLVMInitializeAllTargets - The main program should call this function if it
830b57cec5SDimitry Andric     wants to link in all available targets that LLVM is configured to
840b57cec5SDimitry Andric     support. */
LLVMInitializeAllTargets(void)850b57cec5SDimitry Andric static inline void LLVMInitializeAllTargets(void) {
860b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
870b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
880b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric /** LLVMInitializeAllTargetMCs - The main program should call this function if
920b57cec5SDimitry Andric     it wants access to all available target MC that LLVM is configured to
930b57cec5SDimitry Andric     support. */
LLVMInitializeAllTargetMCs(void)940b57cec5SDimitry Andric static inline void LLVMInitializeAllTargetMCs(void) {
950b57cec5SDimitry Andric #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
960b57cec5SDimitry Andric #include "llvm/Config/Targets.def"
970b57cec5SDimitry Andric #undef LLVM_TARGET  /* Explicit undef to make SWIG happier */
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric /** LLVMInitializeAllAsmPrinters - The main program should call this function if
1010b57cec5SDimitry Andric     it wants all asm printers that LLVM is configured to support, to make them
1020b57cec5SDimitry Andric     available via the TargetRegistry. */
LLVMInitializeAllAsmPrinters(void)1030b57cec5SDimitry Andric static inline void LLVMInitializeAllAsmPrinters(void) {
1040b57cec5SDimitry Andric #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
1050b57cec5SDimitry Andric #include "llvm/Config/AsmPrinters.def"
1060b57cec5SDimitry Andric #undef LLVM_ASM_PRINTER  /* Explicit undef to make SWIG happier */
1070b57cec5SDimitry Andric }
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric /** LLVMInitializeAllAsmParsers - The main program should call this function if
1100b57cec5SDimitry Andric     it wants all asm parsers that LLVM is configured to support, to make them
1110b57cec5SDimitry Andric     available via the TargetRegistry. */
LLVMInitializeAllAsmParsers(void)1120b57cec5SDimitry Andric static inline void LLVMInitializeAllAsmParsers(void) {
1130b57cec5SDimitry Andric #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
1140b57cec5SDimitry Andric #include "llvm/Config/AsmParsers.def"
1150b57cec5SDimitry Andric #undef LLVM_ASM_PARSER  /* Explicit undef to make SWIG happier */
1160b57cec5SDimitry Andric }
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric /** LLVMInitializeAllDisassemblers - The main program should call this function
1190b57cec5SDimitry Andric     if it wants all disassemblers that LLVM is configured to support, to make
1200b57cec5SDimitry Andric     them available via the TargetRegistry. */
LLVMInitializeAllDisassemblers(void)1210b57cec5SDimitry Andric static inline void LLVMInitializeAllDisassemblers(void) {
1220b57cec5SDimitry Andric #define LLVM_DISASSEMBLER(TargetName) \
1230b57cec5SDimitry Andric   LLVMInitialize##TargetName##Disassembler();
1240b57cec5SDimitry Andric #include "llvm/Config/Disassemblers.def"
1250b57cec5SDimitry Andric #undef LLVM_DISASSEMBLER  /* Explicit undef to make SWIG happier */
1260b57cec5SDimitry Andric }
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric /** LLVMInitializeNativeTarget - The main program should call this function to
1290b57cec5SDimitry Andric     initialize the native target corresponding to the host.  This is useful
1300b57cec5SDimitry Andric     for JIT applications to ensure that the target gets linked in correctly. */
LLVMInitializeNativeTarget(void)1310b57cec5SDimitry Andric static inline LLVMBool LLVMInitializeNativeTarget(void) {
1320b57cec5SDimitry Andric   /* If we have a native target, initialize it to ensure it is linked in. */
1330b57cec5SDimitry Andric #ifdef LLVM_NATIVE_TARGET
1340b57cec5SDimitry Andric   LLVM_NATIVE_TARGETINFO();
1350b57cec5SDimitry Andric   LLVM_NATIVE_TARGET();
1360b57cec5SDimitry Andric   LLVM_NATIVE_TARGETMC();
1370b57cec5SDimitry Andric   return 0;
1380b57cec5SDimitry Andric #else
1390b57cec5SDimitry Andric   return 1;
1400b57cec5SDimitry Andric #endif
1410b57cec5SDimitry Andric }
1420b57cec5SDimitry Andric 
1430b57cec5SDimitry Andric /** LLVMInitializeNativeTargetAsmParser - The main program should call this
1440b57cec5SDimitry Andric     function to initialize the parser for the native target corresponding to the
1450b57cec5SDimitry Andric     host. */
LLVMInitializeNativeAsmParser(void)1460b57cec5SDimitry Andric static inline LLVMBool LLVMInitializeNativeAsmParser(void) {
1470b57cec5SDimitry Andric #ifdef LLVM_NATIVE_ASMPARSER
1480b57cec5SDimitry Andric   LLVM_NATIVE_ASMPARSER();
1490b57cec5SDimitry Andric   return 0;
1500b57cec5SDimitry Andric #else
1510b57cec5SDimitry Andric   return 1;
1520b57cec5SDimitry Andric #endif
1530b57cec5SDimitry Andric }
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this
1560b57cec5SDimitry Andric     function to initialize the printer for the native target corresponding to
1570b57cec5SDimitry Andric     the host. */
LLVMInitializeNativeAsmPrinter(void)1580b57cec5SDimitry Andric static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) {
1590b57cec5SDimitry Andric #ifdef LLVM_NATIVE_ASMPRINTER
1600b57cec5SDimitry Andric   LLVM_NATIVE_ASMPRINTER();
1610b57cec5SDimitry Andric   return 0;
1620b57cec5SDimitry Andric #else
1630b57cec5SDimitry Andric   return 1;
1640b57cec5SDimitry Andric #endif
1650b57cec5SDimitry Andric }
1660b57cec5SDimitry Andric 
1670b57cec5SDimitry Andric /** LLVMInitializeNativeTargetDisassembler - The main program should call this
1680b57cec5SDimitry Andric     function to initialize the disassembler for the native target corresponding
1690b57cec5SDimitry Andric     to the host. */
LLVMInitializeNativeDisassembler(void)1700b57cec5SDimitry Andric static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
1710b57cec5SDimitry Andric #ifdef LLVM_NATIVE_DISASSEMBLER
1720b57cec5SDimitry Andric   LLVM_NATIVE_DISASSEMBLER();
1730b57cec5SDimitry Andric   return 0;
1740b57cec5SDimitry Andric #else
1750b57cec5SDimitry Andric   return 1;
1760b57cec5SDimitry Andric #endif
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric /*===-- Target Data -------------------------------------------------------===*/
1800b57cec5SDimitry Andric 
1810b57cec5SDimitry Andric /**
1820b57cec5SDimitry Andric  * Obtain the data layout for a module.
1830b57cec5SDimitry Andric  *
1840b57cec5SDimitry Andric  * @see Module::getDataLayout()
1850b57cec5SDimitry Andric  */
1860b57cec5SDimitry Andric LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
1870b57cec5SDimitry Andric 
1880b57cec5SDimitry Andric /**
1890b57cec5SDimitry Andric  * Set the data layout for a module.
1900b57cec5SDimitry Andric  *
1910b57cec5SDimitry Andric  * @see Module::setDataLayout()
1920b57cec5SDimitry Andric  */
1930b57cec5SDimitry Andric void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric /** Creates target data from a target layout string.
1960b57cec5SDimitry Andric     See the constructor llvm::DataLayout::DataLayout. */
1970b57cec5SDimitry Andric LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric /** Deallocates a TargetData.
2000b57cec5SDimitry Andric     See the destructor llvm::DataLayout::~DataLayout. */
2010b57cec5SDimitry Andric void LLVMDisposeTargetData(LLVMTargetDataRef TD);
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric /** Adds target library information to a pass manager. This does not take
2040b57cec5SDimitry Andric     ownership of the target library info.
2050b57cec5SDimitry Andric     See the method llvm::PassManagerBase::add. */
2060b57cec5SDimitry Andric void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
2070b57cec5SDimitry Andric                               LLVMPassManagerRef PM);
2080b57cec5SDimitry Andric 
2090b57cec5SDimitry Andric /** Converts target data to a target layout string. The string must be disposed
2100b57cec5SDimitry Andric     with LLVMDisposeMessage.
2110b57cec5SDimitry Andric     See the constructor llvm::DataLayout::DataLayout. */
2120b57cec5SDimitry Andric char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef TD);
2130b57cec5SDimitry Andric 
2140b57cec5SDimitry Andric /** Returns the byte order of a target, either LLVMBigEndian or
2150b57cec5SDimitry Andric     LLVMLittleEndian.
2160b57cec5SDimitry Andric     See the method llvm::DataLayout::isLittleEndian. */
2170b57cec5SDimitry Andric enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef TD);
2180b57cec5SDimitry Andric 
2190b57cec5SDimitry Andric /** Returns the pointer size in bytes for a target.
2200b57cec5SDimitry Andric     See the method llvm::DataLayout::getPointerSize. */
2210b57cec5SDimitry Andric unsigned LLVMPointerSize(LLVMTargetDataRef TD);
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric /** Returns the pointer size in bytes for a target for a specified
2240b57cec5SDimitry Andric     address space.
2250b57cec5SDimitry Andric     See the method llvm::DataLayout::getPointerSize. */
2260b57cec5SDimitry Andric unsigned LLVMPointerSizeForAS(LLVMTargetDataRef TD, unsigned AS);
2270b57cec5SDimitry Andric 
2280b57cec5SDimitry Andric /** Returns the integer type that is the same size as a pointer on a target.
2290b57cec5SDimitry Andric     See the method llvm::DataLayout::getIntPtrType. */
2300b57cec5SDimitry Andric LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD);
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric /** Returns the integer type that is the same size as a pointer on a target.
2330b57cec5SDimitry Andric     This version allows the address space to be specified.
2340b57cec5SDimitry Andric     See the method llvm::DataLayout::getIntPtrType. */
2350b57cec5SDimitry Andric LLVMTypeRef LLVMIntPtrTypeForAS(LLVMTargetDataRef TD, unsigned AS);
2360b57cec5SDimitry Andric 
2370b57cec5SDimitry Andric /** Returns the integer type that is the same size as a pointer on a target.
2380b57cec5SDimitry Andric     See the method llvm::DataLayout::getIntPtrType. */
2390b57cec5SDimitry Andric LLVMTypeRef LLVMIntPtrTypeInContext(LLVMContextRef C, LLVMTargetDataRef TD);
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric /** Returns the integer type that is the same size as a pointer on a target.
2420b57cec5SDimitry Andric     This version allows the address space to be specified.
2430b57cec5SDimitry Andric     See the method llvm::DataLayout::getIntPtrType. */
2440b57cec5SDimitry Andric LLVMTypeRef LLVMIntPtrTypeForASInContext(LLVMContextRef C, LLVMTargetDataRef TD,
2450b57cec5SDimitry Andric                                          unsigned AS);
2460b57cec5SDimitry Andric 
2470b57cec5SDimitry Andric /** Computes the size of a type in bytes for a target.
2480b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeSizeInBits. */
2490b57cec5SDimitry Andric unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric /** Computes the storage size of a type in bytes for a target.
2520b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeStoreSize. */
2530b57cec5SDimitry Andric unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2540b57cec5SDimitry Andric 
2550b57cec5SDimitry Andric /** Computes the ABI size of a type in bytes for a target.
2560b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeAllocSize. */
2570b57cec5SDimitry Andric unsigned long long LLVMABISizeOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric /** Computes the ABI alignment of a type in bytes for a target.
2600b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeABISize. */
2610b57cec5SDimitry Andric unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2620b57cec5SDimitry Andric 
2630b57cec5SDimitry Andric /** Computes the call frame alignment of a type in bytes for a target.
2640b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeABISize. */
2650b57cec5SDimitry Andric unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric /** Computes the preferred alignment of a type in bytes for a target.
2680b57cec5SDimitry Andric     See the method llvm::DataLayout::getTypeABISize. */
2690b57cec5SDimitry Andric unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef TD, LLVMTypeRef Ty);
2700b57cec5SDimitry Andric 
2710b57cec5SDimitry Andric /** Computes the preferred alignment of a global variable in bytes for a target.
2720b57cec5SDimitry Andric     See the method llvm::DataLayout::getPreferredAlignment. */
2730b57cec5SDimitry Andric unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef TD,
2740b57cec5SDimitry Andric                                         LLVMValueRef GlobalVar);
2750b57cec5SDimitry Andric 
2760b57cec5SDimitry Andric /** Computes the structure element that contains the byte offset for a target.
2770b57cec5SDimitry Andric     See the method llvm::StructLayout::getElementContainingOffset. */
2780b57cec5SDimitry Andric unsigned LLVMElementAtOffset(LLVMTargetDataRef TD, LLVMTypeRef StructTy,
2790b57cec5SDimitry Andric                              unsigned long long Offset);
2800b57cec5SDimitry Andric 
2810b57cec5SDimitry Andric /** Computes the byte offset of the indexed struct element for a target.
2820b57cec5SDimitry Andric     See the method llvm::StructLayout::getElementContainingOffset. */
2830b57cec5SDimitry Andric unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD,
2840b57cec5SDimitry Andric                                        LLVMTypeRef StructTy, unsigned Element);
2850b57cec5SDimitry Andric 
2860b57cec5SDimitry Andric /**
2870b57cec5SDimitry Andric  * @}
2880b57cec5SDimitry Andric  */
2890b57cec5SDimitry Andric 
290*480093f4SDimitry Andric LLVM_C_EXTERN_C_END
2910b57cec5SDimitry Andric 
2920b57cec5SDimitry Andric #endif
293