10b57cec5SDimitry Andric /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- 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 provides public interface to an abstract link time optimization*| 110b57cec5SDimitry Andric |* library. LLVM provides an implementation of this interface for use with *| 120b57cec5SDimitry Andric |* llvm bitcode files. *| 130b57cec5SDimitry Andric |* *| 140b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/ 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #ifndef LLVM_C_LTO_H 170b57cec5SDimitry Andric #define LLVM_C_LTO_H 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric #ifdef __cplusplus 200b57cec5SDimitry Andric #include <cstddef> 210b57cec5SDimitry Andric #else 220b57cec5SDimitry Andric #include <stddef.h> 230b57cec5SDimitry Andric #endif 240b57cec5SDimitry Andric #include <sys/types.h> 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric #ifndef __cplusplus 270b57cec5SDimitry Andric #if !defined(_MSC_VER) 280b57cec5SDimitry Andric #include <stdbool.h> 290b57cec5SDimitry Andric typedef bool lto_bool_t; 300b57cec5SDimitry Andric #else 310b57cec5SDimitry Andric /* MSVC in particular does not have anything like _Bool or bool in C, but we can 320b57cec5SDimitry Andric at least make sure the type is the same size. The implementation side will 330b57cec5SDimitry Andric use C++ bool. */ 340b57cec5SDimitry Andric typedef unsigned char lto_bool_t; 350b57cec5SDimitry Andric #endif 360b57cec5SDimitry Andric #else 370b57cec5SDimitry Andric typedef bool lto_bool_t; 380b57cec5SDimitry Andric #endif 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric /** 410b57cec5SDimitry Andric * @defgroup LLVMCLTO LTO 420b57cec5SDimitry Andric * @ingroup LLVMC 430b57cec5SDimitry Andric * 440b57cec5SDimitry Andric * @{ 450b57cec5SDimitry Andric */ 460b57cec5SDimitry Andric 47*8bcb0991SDimitry Andric #define LTO_API_VERSION 25 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric /** 500b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 510b57cec5SDimitry Andric */ 520b57cec5SDimitry Andric typedef enum { 530b57cec5SDimitry Andric LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ 540b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, 550b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, 560b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, 570b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, 580b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_MASK = 0x00000700, 590b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, 600b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, 610b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, 620b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, 630b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, 640b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_MASK = 0x00003800, 650b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, 660b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, 670b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, 680b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, 690b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800, 700b57cec5SDimitry Andric LTO_SYMBOL_COMDAT = 0x00004000, 710b57cec5SDimitry Andric LTO_SYMBOL_ALIAS = 0x00008000 720b57cec5SDimitry Andric } lto_symbol_attributes; 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric /** 750b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 760b57cec5SDimitry Andric */ 770b57cec5SDimitry Andric typedef enum { 780b57cec5SDimitry Andric LTO_DEBUG_MODEL_NONE = 0, 790b57cec5SDimitry Andric LTO_DEBUG_MODEL_DWARF = 1 800b57cec5SDimitry Andric } lto_debug_model; 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric /** 830b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 840b57cec5SDimitry Andric */ 850b57cec5SDimitry Andric typedef enum { 860b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_STATIC = 0, 870b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, 880b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, 890b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DEFAULT = 3 900b57cec5SDimitry Andric } lto_codegen_model; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric /** opaque reference to a loaded object module */ 930b57cec5SDimitry Andric typedef struct LLVMOpaqueLTOModule *lto_module_t; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric /** opaque reference to a code generator */ 960b57cec5SDimitry Andric typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric /** opaque reference to a thin code generator */ 990b57cec5SDimitry Andric typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t; 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric #ifdef __cplusplus 1020b57cec5SDimitry Andric extern "C" { 1030b57cec5SDimitry Andric #endif 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric /** 1060b57cec5SDimitry Andric * Returns a printable string. 1070b57cec5SDimitry Andric * 1080b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1090b57cec5SDimitry Andric */ 1100b57cec5SDimitry Andric extern const char* 1110b57cec5SDimitry Andric lto_get_version(void); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric /** 1140b57cec5SDimitry Andric * Returns the last error string or NULL if last operation was successful. 1150b57cec5SDimitry Andric * 1160b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1170b57cec5SDimitry Andric */ 1180b57cec5SDimitry Andric extern const char* 1190b57cec5SDimitry Andric lto_get_error_message(void); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric /** 1220b57cec5SDimitry Andric * Checks if a file is a loadable object file. 1230b57cec5SDimitry Andric * 1240b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1250b57cec5SDimitry Andric */ 1260b57cec5SDimitry Andric extern lto_bool_t 1270b57cec5SDimitry Andric lto_module_is_object_file(const char* path); 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric /** 1300b57cec5SDimitry Andric * Checks if a file is a loadable object compiled for requested target. 1310b57cec5SDimitry Andric * 1320b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1330b57cec5SDimitry Andric */ 1340b57cec5SDimitry Andric extern lto_bool_t 1350b57cec5SDimitry Andric lto_module_is_object_file_for_target(const char* path, 1360b57cec5SDimitry Andric const char* target_triple_prefix); 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric /** 1390b57cec5SDimitry Andric * Return true if \p Buffer contains a bitcode file with ObjC code (category 1400b57cec5SDimitry Andric * or class) in it. 1410b57cec5SDimitry Andric * 1420b57cec5SDimitry Andric * \since LTO_API_VERSION=20 1430b57cec5SDimitry Andric */ 1440b57cec5SDimitry Andric extern lto_bool_t 1450b57cec5SDimitry Andric lto_module_has_objc_category(const void *mem, size_t length); 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric /** 1480b57cec5SDimitry Andric * Checks if a buffer is a loadable object file. 1490b57cec5SDimitry Andric * 1500b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1510b57cec5SDimitry Andric */ 1520b57cec5SDimitry Andric extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem, 1530b57cec5SDimitry Andric size_t length); 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric /** 1560b57cec5SDimitry Andric * Checks if a buffer is a loadable object compiled for requested target. 1570b57cec5SDimitry Andric * 1580b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1590b57cec5SDimitry Andric */ 1600b57cec5SDimitry Andric extern lto_bool_t 1610b57cec5SDimitry Andric lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 1620b57cec5SDimitry Andric const char* target_triple_prefix); 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric /** 1650b57cec5SDimitry Andric * Loads an object file from disk. 1660b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 1670b57cec5SDimitry Andric * 1680b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1690b57cec5SDimitry Andric */ 1700b57cec5SDimitry Andric extern lto_module_t 1710b57cec5SDimitry Andric lto_module_create(const char* path); 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andric /** 1740b57cec5SDimitry Andric * Loads an object file from memory. 1750b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 1760b57cec5SDimitry Andric * 1770b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 1780b57cec5SDimitry Andric */ 1790b57cec5SDimitry Andric extern lto_module_t 1800b57cec5SDimitry Andric lto_module_create_from_memory(const void* mem, size_t length); 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric /** 1830b57cec5SDimitry Andric * Loads an object file from memory with an extra path argument. 1840b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 1850b57cec5SDimitry Andric * 1860b57cec5SDimitry Andric * \since LTO_API_VERSION=9 1870b57cec5SDimitry Andric */ 1880b57cec5SDimitry Andric extern lto_module_t 1890b57cec5SDimitry Andric lto_module_create_from_memory_with_path(const void* mem, size_t length, 1900b57cec5SDimitry Andric const char *path); 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric /** 1930b57cec5SDimitry Andric * Loads an object file in its own context. 1940b57cec5SDimitry Andric * 1950b57cec5SDimitry Andric * Loads an object file in its own LLVMContext. This function call is 1960b57cec5SDimitry Andric * thread-safe. However, modules created this way should not be merged into an 1970b57cec5SDimitry Andric * lto_code_gen_t using \a lto_codegen_add_module(). 1980b57cec5SDimitry Andric * 1990b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 2000b57cec5SDimitry Andric * 2010b57cec5SDimitry Andric * \since LTO_API_VERSION=11 2020b57cec5SDimitry Andric */ 2030b57cec5SDimitry Andric extern lto_module_t 2040b57cec5SDimitry Andric lto_module_create_in_local_context(const void *mem, size_t length, 2050b57cec5SDimitry Andric const char *path); 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andric /** 2080b57cec5SDimitry Andric * Loads an object file in the codegen context. 2090b57cec5SDimitry Andric * 2100b57cec5SDimitry Andric * Loads an object file into the same context as \c cg. The module is safe to 2110b57cec5SDimitry Andric * add using \a lto_codegen_add_module(). 2120b57cec5SDimitry Andric * 2130b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 2140b57cec5SDimitry Andric * 2150b57cec5SDimitry Andric * \since LTO_API_VERSION=11 2160b57cec5SDimitry Andric */ 2170b57cec5SDimitry Andric extern lto_module_t 2180b57cec5SDimitry Andric lto_module_create_in_codegen_context(const void *mem, size_t length, 2190b57cec5SDimitry Andric const char *path, lto_code_gen_t cg); 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric /** 2220b57cec5SDimitry Andric * Loads an object file from disk. The seek point of fd is not preserved. 2230b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 2240b57cec5SDimitry Andric * 2250b57cec5SDimitry Andric * \since LTO_API_VERSION=5 2260b57cec5SDimitry Andric */ 2270b57cec5SDimitry Andric extern lto_module_t 2280b57cec5SDimitry Andric lto_module_create_from_fd(int fd, const char *path, size_t file_size); 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric /** 2310b57cec5SDimitry Andric * Loads an object file from disk. The seek point of fd is not preserved. 2320b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 2330b57cec5SDimitry Andric * 2340b57cec5SDimitry Andric * \since LTO_API_VERSION=5 2350b57cec5SDimitry Andric */ 2360b57cec5SDimitry Andric extern lto_module_t 2370b57cec5SDimitry Andric lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, 2380b57cec5SDimitry Andric size_t map_size, off_t offset); 2390b57cec5SDimitry Andric 2400b57cec5SDimitry Andric /** 2410b57cec5SDimitry Andric * Frees all memory internally allocated by the module. 2420b57cec5SDimitry Andric * Upon return the lto_module_t is no longer valid. 2430b57cec5SDimitry Andric * 2440b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 2450b57cec5SDimitry Andric */ 2460b57cec5SDimitry Andric extern void 2470b57cec5SDimitry Andric lto_module_dispose(lto_module_t mod); 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andric /** 2500b57cec5SDimitry Andric * Returns triple string which the object module was compiled under. 2510b57cec5SDimitry Andric * 2520b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 2530b57cec5SDimitry Andric */ 2540b57cec5SDimitry Andric extern const char* 2550b57cec5SDimitry Andric lto_module_get_target_triple(lto_module_t mod); 2560b57cec5SDimitry Andric 2570b57cec5SDimitry Andric /** 2580b57cec5SDimitry Andric * Sets triple string with which the object will be codegened. 2590b57cec5SDimitry Andric * 2600b57cec5SDimitry Andric * \since LTO_API_VERSION=4 2610b57cec5SDimitry Andric */ 2620b57cec5SDimitry Andric extern void 2630b57cec5SDimitry Andric lto_module_set_target_triple(lto_module_t mod, const char *triple); 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andric /** 2660b57cec5SDimitry Andric * Returns the number of symbols in the object module. 2670b57cec5SDimitry Andric * 2680b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 2690b57cec5SDimitry Andric */ 2700b57cec5SDimitry Andric extern unsigned int 2710b57cec5SDimitry Andric lto_module_get_num_symbols(lto_module_t mod); 2720b57cec5SDimitry Andric 2730b57cec5SDimitry Andric /** 2740b57cec5SDimitry Andric * Returns the name of the ith symbol in the object module. 2750b57cec5SDimitry Andric * 2760b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 2770b57cec5SDimitry Andric */ 2780b57cec5SDimitry Andric extern const char* 2790b57cec5SDimitry Andric lto_module_get_symbol_name(lto_module_t mod, unsigned int index); 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric /** 2820b57cec5SDimitry Andric * Returns the attributes of the ith symbol in the object module. 2830b57cec5SDimitry Andric * 2840b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 2850b57cec5SDimitry Andric */ 2860b57cec5SDimitry Andric extern lto_symbol_attributes 2870b57cec5SDimitry Andric lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); 2880b57cec5SDimitry Andric 2890b57cec5SDimitry Andric /** 2900b57cec5SDimitry Andric * Returns the module's linker options. 2910b57cec5SDimitry Andric * 2920b57cec5SDimitry Andric * The linker options may consist of multiple flags. It is the linker's 2930b57cec5SDimitry Andric * responsibility to split the flags using a platform-specific mechanism. 2940b57cec5SDimitry Andric * 2950b57cec5SDimitry Andric * \since LTO_API_VERSION=16 2960b57cec5SDimitry Andric */ 2970b57cec5SDimitry Andric extern const char* 2980b57cec5SDimitry Andric lto_module_get_linkeropts(lto_module_t mod); 2990b57cec5SDimitry Andric 3000b57cec5SDimitry Andric /** 3010b57cec5SDimitry Andric * Diagnostic severity. 3020b57cec5SDimitry Andric * 3030b57cec5SDimitry Andric * \since LTO_API_VERSION=7 3040b57cec5SDimitry Andric */ 3050b57cec5SDimitry Andric typedef enum { 3060b57cec5SDimitry Andric LTO_DS_ERROR = 0, 3070b57cec5SDimitry Andric LTO_DS_WARNING = 1, 3080b57cec5SDimitry Andric LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10. 3090b57cec5SDimitry Andric LTO_DS_NOTE = 2 3100b57cec5SDimitry Andric } lto_codegen_diagnostic_severity_t; 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andric /** 3130b57cec5SDimitry Andric * Diagnostic handler type. 3140b57cec5SDimitry Andric * \p severity defines the severity. 3150b57cec5SDimitry Andric * \p diag is the actual diagnostic. 3160b57cec5SDimitry Andric * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '. 3170b57cec5SDimitry Andric * \p ctxt is used to pass the context set with the diagnostic handler. 3180b57cec5SDimitry Andric * 3190b57cec5SDimitry Andric * \since LTO_API_VERSION=7 3200b57cec5SDimitry Andric */ 3210b57cec5SDimitry Andric typedef void (*lto_diagnostic_handler_t)( 3220b57cec5SDimitry Andric lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt); 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric /** 3250b57cec5SDimitry Andric * Set a diagnostic handler and the related context (void *). 3260b57cec5SDimitry Andric * This is more general than lto_get_error_message, as the diagnostic handler 3270b57cec5SDimitry Andric * can be called at anytime within lto. 3280b57cec5SDimitry Andric * 3290b57cec5SDimitry Andric * \since LTO_API_VERSION=7 3300b57cec5SDimitry Andric */ 3310b57cec5SDimitry Andric extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t, 3320b57cec5SDimitry Andric lto_diagnostic_handler_t, 3330b57cec5SDimitry Andric void *); 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric /** 3360b57cec5SDimitry Andric * Instantiates a code generator. 3370b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 3380b57cec5SDimitry Andric * 3390b57cec5SDimitry Andric * All modules added using \a lto_codegen_add_module() must have been created 3400b57cec5SDimitry Andric * in the same context as the codegen. 3410b57cec5SDimitry Andric * 3420b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 3430b57cec5SDimitry Andric */ 3440b57cec5SDimitry Andric extern lto_code_gen_t 3450b57cec5SDimitry Andric lto_codegen_create(void); 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric /** 3480b57cec5SDimitry Andric * Instantiate a code generator in its own context. 3490b57cec5SDimitry Andric * 3500b57cec5SDimitry Andric * Instantiates a code generator in its own context. Modules added via \a 3510b57cec5SDimitry Andric * lto_codegen_add_module() must have all been created in the same context, 3520b57cec5SDimitry Andric * using \a lto_module_create_in_codegen_context(). 3530b57cec5SDimitry Andric * 3540b57cec5SDimitry Andric * \since LTO_API_VERSION=11 3550b57cec5SDimitry Andric */ 3560b57cec5SDimitry Andric extern lto_code_gen_t 3570b57cec5SDimitry Andric lto_codegen_create_in_local_context(void); 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andric /** 3600b57cec5SDimitry Andric * Frees all code generator and all memory it internally allocated. 3610b57cec5SDimitry Andric * Upon return the lto_code_gen_t is no longer valid. 3620b57cec5SDimitry Andric * 3630b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 3640b57cec5SDimitry Andric */ 3650b57cec5SDimitry Andric extern void 3660b57cec5SDimitry Andric lto_codegen_dispose(lto_code_gen_t); 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric /** 3690b57cec5SDimitry Andric * Add an object module to the set of modules for which code will be generated. 3700b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 3710b57cec5SDimitry Andric * 3720b57cec5SDimitry Andric * \c cg and \c mod must both be in the same context. See \a 3730b57cec5SDimitry Andric * lto_codegen_create_in_local_context() and \a 3740b57cec5SDimitry Andric * lto_module_create_in_codegen_context(). 3750b57cec5SDimitry Andric * 3760b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 3770b57cec5SDimitry Andric */ 3780b57cec5SDimitry Andric extern lto_bool_t 3790b57cec5SDimitry Andric lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric /** 3820b57cec5SDimitry Andric * Sets the object module for code generation. This will transfer the ownership 3830b57cec5SDimitry Andric * of the module to the code generator. 3840b57cec5SDimitry Andric * 3850b57cec5SDimitry Andric * \c cg and \c mod must both be in the same context. 3860b57cec5SDimitry Andric * 3870b57cec5SDimitry Andric * \since LTO_API_VERSION=13 3880b57cec5SDimitry Andric */ 3890b57cec5SDimitry Andric extern void 3900b57cec5SDimitry Andric lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod); 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andric /** 3930b57cec5SDimitry Andric * Sets if debug info should be generated. 3940b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 3950b57cec5SDimitry Andric * 3960b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 3970b57cec5SDimitry Andric */ 3980b57cec5SDimitry Andric extern lto_bool_t 3990b57cec5SDimitry Andric lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric /** 4020b57cec5SDimitry Andric * Sets which PIC code model to generated. 4030b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 4040b57cec5SDimitry Andric * 4050b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 4060b57cec5SDimitry Andric */ 4070b57cec5SDimitry Andric extern lto_bool_t 4080b57cec5SDimitry Andric lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric /** 4110b57cec5SDimitry Andric * Sets the cpu to generate code for. 4120b57cec5SDimitry Andric * 4130b57cec5SDimitry Andric * \since LTO_API_VERSION=4 4140b57cec5SDimitry Andric */ 4150b57cec5SDimitry Andric extern void 4160b57cec5SDimitry Andric lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); 4170b57cec5SDimitry Andric 4180b57cec5SDimitry Andric /** 4190b57cec5SDimitry Andric * Sets the location of the assembler tool to run. If not set, libLTO 4200b57cec5SDimitry Andric * will use gcc to invoke the assembler. 4210b57cec5SDimitry Andric * 4220b57cec5SDimitry Andric * \since LTO_API_VERSION=3 4230b57cec5SDimitry Andric */ 4240b57cec5SDimitry Andric extern void 4250b57cec5SDimitry Andric lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric /** 4280b57cec5SDimitry Andric * Sets extra arguments that libLTO should pass to the assembler. 4290b57cec5SDimitry Andric * 4300b57cec5SDimitry Andric * \since LTO_API_VERSION=4 4310b57cec5SDimitry Andric */ 4320b57cec5SDimitry Andric extern void 4330b57cec5SDimitry Andric lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, 4340b57cec5SDimitry Andric int nargs); 4350b57cec5SDimitry Andric 4360b57cec5SDimitry Andric /** 4370b57cec5SDimitry Andric * Adds to a list of all global symbols that must exist in the final generated 4380b57cec5SDimitry Andric * code. If a function is not listed there, it might be inlined into every usage 4390b57cec5SDimitry Andric * and optimized away. 4400b57cec5SDimitry Andric * 4410b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 4420b57cec5SDimitry Andric */ 4430b57cec5SDimitry Andric extern void 4440b57cec5SDimitry Andric lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric /** 4470b57cec5SDimitry Andric * Writes a new object file at the specified path that contains the 4480b57cec5SDimitry Andric * merged contents of all modules added so far. 4490b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 4500b57cec5SDimitry Andric * 4510b57cec5SDimitry Andric * \since LTO_API_VERSION=5 4520b57cec5SDimitry Andric */ 4530b57cec5SDimitry Andric extern lto_bool_t 4540b57cec5SDimitry Andric lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andric /** 4570b57cec5SDimitry Andric * Generates code for all added modules into one native object file. 4580b57cec5SDimitry Andric * This calls lto_codegen_optimize then lto_codegen_compile_optimized. 4590b57cec5SDimitry Andric * 4600b57cec5SDimitry Andric * On success returns a pointer to a generated mach-o/ELF buffer and 4610b57cec5SDimitry Andric * length set to the buffer size. The buffer is owned by the 4620b57cec5SDimitry Andric * lto_code_gen_t and will be freed when lto_codegen_dispose() 4630b57cec5SDimitry Andric * is called, or lto_codegen_compile() is called again. 4640b57cec5SDimitry Andric * On failure, returns NULL (check lto_get_error_message() for details). 4650b57cec5SDimitry Andric * 4660b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 4670b57cec5SDimitry Andric */ 4680b57cec5SDimitry Andric extern const void* 4690b57cec5SDimitry Andric lto_codegen_compile(lto_code_gen_t cg, size_t* length); 4700b57cec5SDimitry Andric 4710b57cec5SDimitry Andric /** 4720b57cec5SDimitry Andric * Generates code for all added modules into one native object file. 4730b57cec5SDimitry Andric * This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead 4740b57cec5SDimitry Andric * of returning a generated mach-o/ELF buffer, it writes to a file). 4750b57cec5SDimitry Andric * 4760b57cec5SDimitry Andric * The name of the file is written to name. Returns true on error. 4770b57cec5SDimitry Andric * 4780b57cec5SDimitry Andric * \since LTO_API_VERSION=5 4790b57cec5SDimitry Andric */ 4800b57cec5SDimitry Andric extern lto_bool_t 4810b57cec5SDimitry Andric lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); 4820b57cec5SDimitry Andric 4830b57cec5SDimitry Andric /** 4840b57cec5SDimitry Andric * Runs optimization for the merged module. Returns true on error. 4850b57cec5SDimitry Andric * 4860b57cec5SDimitry Andric * \since LTO_API_VERSION=12 4870b57cec5SDimitry Andric */ 4880b57cec5SDimitry Andric extern lto_bool_t 4890b57cec5SDimitry Andric lto_codegen_optimize(lto_code_gen_t cg); 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric /** 4920b57cec5SDimitry Andric * Generates code for the optimized merged module into one native object file. 4930b57cec5SDimitry Andric * It will not run any IR optimizations on the merged module. 4940b57cec5SDimitry Andric * 4950b57cec5SDimitry Andric * On success returns a pointer to a generated mach-o/ELF buffer and length set 4960b57cec5SDimitry Andric * to the buffer size. The buffer is owned by the lto_code_gen_t and will be 4970b57cec5SDimitry Andric * freed when lto_codegen_dispose() is called, or 4980b57cec5SDimitry Andric * lto_codegen_compile_optimized() is called again. On failure, returns NULL 4990b57cec5SDimitry Andric * (check lto_get_error_message() for details). 5000b57cec5SDimitry Andric * 5010b57cec5SDimitry Andric * \since LTO_API_VERSION=12 5020b57cec5SDimitry Andric */ 5030b57cec5SDimitry Andric extern const void* 5040b57cec5SDimitry Andric lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length); 5050b57cec5SDimitry Andric 5060b57cec5SDimitry Andric /** 5070b57cec5SDimitry Andric * Returns the runtime API version. 5080b57cec5SDimitry Andric * 5090b57cec5SDimitry Andric * \since LTO_API_VERSION=12 5100b57cec5SDimitry Andric */ 5110b57cec5SDimitry Andric extern unsigned int 5120b57cec5SDimitry Andric lto_api_version(void); 5130b57cec5SDimitry Andric 5140b57cec5SDimitry Andric /** 5150b57cec5SDimitry Andric * Sets options to help debug codegen bugs. 5160b57cec5SDimitry Andric * 5170b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 5180b57cec5SDimitry Andric */ 5190b57cec5SDimitry Andric extern void 5200b57cec5SDimitry Andric lto_codegen_debug_options(lto_code_gen_t cg, const char *); 5210b57cec5SDimitry Andric 5220b57cec5SDimitry Andric /** 5230b57cec5SDimitry Andric * Initializes LLVM disassemblers. 5240b57cec5SDimitry Andric * FIXME: This doesn't really belong here. 5250b57cec5SDimitry Andric * 5260b57cec5SDimitry Andric * \since LTO_API_VERSION=5 5270b57cec5SDimitry Andric */ 5280b57cec5SDimitry Andric extern void 5290b57cec5SDimitry Andric lto_initialize_disassembler(void); 5300b57cec5SDimitry Andric 5310b57cec5SDimitry Andric /** 5320b57cec5SDimitry Andric * Sets if we should run internalize pass during optimization and code 5330b57cec5SDimitry Andric * generation. 5340b57cec5SDimitry Andric * 5350b57cec5SDimitry Andric * \since LTO_API_VERSION=14 5360b57cec5SDimitry Andric */ 5370b57cec5SDimitry Andric extern void 5380b57cec5SDimitry Andric lto_codegen_set_should_internalize(lto_code_gen_t cg, 5390b57cec5SDimitry Andric lto_bool_t ShouldInternalize); 5400b57cec5SDimitry Andric 5410b57cec5SDimitry Andric /** 5420b57cec5SDimitry Andric * Set whether to embed uselists in bitcode. 5430b57cec5SDimitry Andric * 5440b57cec5SDimitry Andric * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in 5450b57cec5SDimitry Andric * output bitcode. This should be turned on for all -save-temps output. 5460b57cec5SDimitry Andric * 5470b57cec5SDimitry Andric * \since LTO_API_VERSION=15 5480b57cec5SDimitry Andric */ 5490b57cec5SDimitry Andric extern void 5500b57cec5SDimitry Andric lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, 5510b57cec5SDimitry Andric lto_bool_t ShouldEmbedUselists); 5520b57cec5SDimitry Andric 553*8bcb0991SDimitry Andric /** Opaque reference to an LTO input file */ 554*8bcb0991SDimitry Andric typedef struct LLVMOpaqueLTOInput *lto_input_t; 555*8bcb0991SDimitry Andric 556*8bcb0991SDimitry Andric /** 557*8bcb0991SDimitry Andric * Creates an LTO input file from a buffer. The path 558*8bcb0991SDimitry Andric * argument is used for diagnotics as this function 559*8bcb0991SDimitry Andric * otherwise does not know which file the given buffer 560*8bcb0991SDimitry Andric * is associated with. 561*8bcb0991SDimitry Andric * 562*8bcb0991SDimitry Andric * \since LTO_API_VERSION=24 563*8bcb0991SDimitry Andric */ 564*8bcb0991SDimitry Andric extern lto_input_t lto_input_create(const void *buffer, 565*8bcb0991SDimitry Andric size_t buffer_size, 566*8bcb0991SDimitry Andric const char *path); 567*8bcb0991SDimitry Andric 568*8bcb0991SDimitry Andric /** 569*8bcb0991SDimitry Andric * Frees all memory internally allocated by the LTO input file. 570*8bcb0991SDimitry Andric * Upon return the lto_module_t is no longer valid. 571*8bcb0991SDimitry Andric * 572*8bcb0991SDimitry Andric * \since LTO_API_VERSION=24 573*8bcb0991SDimitry Andric */ 574*8bcb0991SDimitry Andric extern void lto_input_dispose(lto_input_t input); 575*8bcb0991SDimitry Andric 576*8bcb0991SDimitry Andric /** 577*8bcb0991SDimitry Andric * Returns the number of dependent library specifiers 578*8bcb0991SDimitry Andric * for the given LTO input file. 579*8bcb0991SDimitry Andric * 580*8bcb0991SDimitry Andric * \since LTO_API_VERSION=24 581*8bcb0991SDimitry Andric */ 582*8bcb0991SDimitry Andric extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input); 583*8bcb0991SDimitry Andric 584*8bcb0991SDimitry Andric /** 585*8bcb0991SDimitry Andric * Returns the ith dependent library specifier 586*8bcb0991SDimitry Andric * for the given LTO input file. The returned 587*8bcb0991SDimitry Andric * string is not null-terminated. 588*8bcb0991SDimitry Andric * 589*8bcb0991SDimitry Andric * \since LTO_API_VERSION=24 590*8bcb0991SDimitry Andric */ 591*8bcb0991SDimitry Andric extern const char * lto_input_get_dependent_library(lto_input_t input, 592*8bcb0991SDimitry Andric size_t index, 593*8bcb0991SDimitry Andric size_t *size); 594*8bcb0991SDimitry Andric 595*8bcb0991SDimitry Andric /** 596*8bcb0991SDimitry Andric * Returns the list of libcall symbols that can be generated by LTO 597*8bcb0991SDimitry Andric * that might not be visible from the symbol table of bitcode files. 598*8bcb0991SDimitry Andric * 599*8bcb0991SDimitry Andric * \since prior to LTO_API_VERSION=25 600*8bcb0991SDimitry Andric */ 601*8bcb0991SDimitry Andric extern const char *const *lto_runtime_lib_symbols_list(size_t *size); 602*8bcb0991SDimitry Andric 6030b57cec5SDimitry Andric /** 6040b57cec5SDimitry Andric * @} // endgoup LLVMCLTO 6050b57cec5SDimitry Andric * @defgroup LLVMCTLTO ThinLTO 6060b57cec5SDimitry Andric * @ingroup LLVMC 6070b57cec5SDimitry Andric * 6080b57cec5SDimitry Andric * @{ 6090b57cec5SDimitry Andric */ 6100b57cec5SDimitry Andric 6110b57cec5SDimitry Andric /** 6120b57cec5SDimitry Andric * Type to wrap a single object returned by ThinLTO. 6130b57cec5SDimitry Andric * 6140b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6150b57cec5SDimitry Andric */ 6160b57cec5SDimitry Andric typedef struct { 6170b57cec5SDimitry Andric const char *Buffer; 6180b57cec5SDimitry Andric size_t Size; 6190b57cec5SDimitry Andric } LTOObjectBuffer; 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andric /** 6220b57cec5SDimitry Andric * Instantiates a ThinLTO code generator. 6230b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 6240b57cec5SDimitry Andric * 6250b57cec5SDimitry Andric * 6260b57cec5SDimitry Andric * The ThinLTOCodeGenerator is not intended to be reuse for multiple 6270b57cec5SDimitry Andric * compilation: the model is that the client adds modules to the generator and 6280b57cec5SDimitry Andric * ask to perform the ThinLTO optimizations / codegen, and finally destroys the 6290b57cec5SDimitry Andric * codegenerator. 6300b57cec5SDimitry Andric * 6310b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6320b57cec5SDimitry Andric */ 6330b57cec5SDimitry Andric extern thinlto_code_gen_t thinlto_create_codegen(void); 6340b57cec5SDimitry Andric 6350b57cec5SDimitry Andric /** 6360b57cec5SDimitry Andric * Frees the generator and all memory it internally allocated. 6370b57cec5SDimitry Andric * Upon return the thinlto_code_gen_t is no longer valid. 6380b57cec5SDimitry Andric * 6390b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6400b57cec5SDimitry Andric */ 6410b57cec5SDimitry Andric extern void thinlto_codegen_dispose(thinlto_code_gen_t cg); 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andric /** 6440b57cec5SDimitry Andric * Add a module to a ThinLTO code generator. Identifier has to be unique among 6450b57cec5SDimitry Andric * all the modules in a code generator. The data buffer stays owned by the 6460b57cec5SDimitry Andric * client, and is expected to be available for the entire lifetime of the 6470b57cec5SDimitry Andric * thinlto_code_gen_t it is added to. 6480b57cec5SDimitry Andric * 6490b57cec5SDimitry Andric * On failure, returns NULL (check lto_get_error_message() for details). 6500b57cec5SDimitry Andric * 6510b57cec5SDimitry Andric * 6520b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6530b57cec5SDimitry Andric */ 6540b57cec5SDimitry Andric extern void thinlto_codegen_add_module(thinlto_code_gen_t cg, 6550b57cec5SDimitry Andric const char *identifier, const char *data, 6560b57cec5SDimitry Andric int length); 6570b57cec5SDimitry Andric 6580b57cec5SDimitry Andric /** 6590b57cec5SDimitry Andric * Optimize and codegen all the modules added to the codegenerator using 6600b57cec5SDimitry Andric * ThinLTO. Resulting objects are accessible using thinlto_module_get_object(). 6610b57cec5SDimitry Andric * 6620b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6630b57cec5SDimitry Andric */ 6640b57cec5SDimitry Andric extern void thinlto_codegen_process(thinlto_code_gen_t cg); 6650b57cec5SDimitry Andric 6660b57cec5SDimitry Andric /** 6670b57cec5SDimitry Andric * Returns the number of object files produced by the ThinLTO CodeGenerator. 6680b57cec5SDimitry Andric * 6690b57cec5SDimitry Andric * It usually matches the number of input files, but this is not a guarantee of 6700b57cec5SDimitry Andric * the API and may change in future implementation, so the client should not 6710b57cec5SDimitry Andric * assume it. 6720b57cec5SDimitry Andric * 6730b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6740b57cec5SDimitry Andric */ 6750b57cec5SDimitry Andric extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg); 6760b57cec5SDimitry Andric 6770b57cec5SDimitry Andric /** 6780b57cec5SDimitry Andric * Returns a reference to the ith object file produced by the ThinLTO 6790b57cec5SDimitry Andric * CodeGenerator. 6800b57cec5SDimitry Andric * 6810b57cec5SDimitry Andric * Client should use \p thinlto_module_get_num_objects() to get the number of 6820b57cec5SDimitry Andric * available objects. 6830b57cec5SDimitry Andric * 6840b57cec5SDimitry Andric * \since LTO_API_VERSION=18 6850b57cec5SDimitry Andric */ 6860b57cec5SDimitry Andric extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg, 6870b57cec5SDimitry Andric unsigned int index); 6880b57cec5SDimitry Andric 6890b57cec5SDimitry Andric /** 6900b57cec5SDimitry Andric * Returns the number of object files produced by the ThinLTO CodeGenerator. 6910b57cec5SDimitry Andric * 6920b57cec5SDimitry Andric * It usually matches the number of input files, but this is not a guarantee of 6930b57cec5SDimitry Andric * the API and may change in future implementation, so the client should not 6940b57cec5SDimitry Andric * assume it. 6950b57cec5SDimitry Andric * 6960b57cec5SDimitry Andric * \since LTO_API_VERSION=21 6970b57cec5SDimitry Andric */ 6980b57cec5SDimitry Andric unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg); 6990b57cec5SDimitry Andric 7000b57cec5SDimitry Andric /** 7010b57cec5SDimitry Andric * Returns the path to the ith object file produced by the ThinLTO 7020b57cec5SDimitry Andric * CodeGenerator. 7030b57cec5SDimitry Andric * 7040b57cec5SDimitry Andric * Client should use \p thinlto_module_get_num_object_files() to get the number 7050b57cec5SDimitry Andric * of available objects. 7060b57cec5SDimitry Andric * 7070b57cec5SDimitry Andric * \since LTO_API_VERSION=21 7080b57cec5SDimitry Andric */ 7090b57cec5SDimitry Andric const char *thinlto_module_get_object_file(thinlto_code_gen_t cg, 7100b57cec5SDimitry Andric unsigned int index); 7110b57cec5SDimitry Andric 7120b57cec5SDimitry Andric /** 7130b57cec5SDimitry Andric * Sets which PIC code model to generate. 7140b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 7150b57cec5SDimitry Andric * 7160b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7170b57cec5SDimitry Andric */ 7180b57cec5SDimitry Andric extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, 7190b57cec5SDimitry Andric lto_codegen_model); 7200b57cec5SDimitry Andric 7210b57cec5SDimitry Andric /** 7220b57cec5SDimitry Andric * Sets the path to a directory to use as a storage for temporary bitcode files. 7230b57cec5SDimitry Andric * The intention is to make the bitcode files available for debugging at various 7240b57cec5SDimitry Andric * stage of the pipeline. 7250b57cec5SDimitry Andric * 7260b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7270b57cec5SDimitry Andric */ 7280b57cec5SDimitry Andric extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, 7290b57cec5SDimitry Andric const char *save_temps_dir); 7300b57cec5SDimitry Andric 7310b57cec5SDimitry Andric /** 7320b57cec5SDimitry Andric * Set the path to a directory where to save generated object files. This 7330b57cec5SDimitry Andric * path can be used by a linker to request on-disk files instead of in-memory 7340b57cec5SDimitry Andric * buffers. When set, results are available through 7350b57cec5SDimitry Andric * thinlto_module_get_object_file() instead of thinlto_module_get_object(). 7360b57cec5SDimitry Andric * 7370b57cec5SDimitry Andric * \since LTO_API_VERSION=21 7380b57cec5SDimitry Andric */ 7390b57cec5SDimitry Andric void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg, 7400b57cec5SDimitry Andric const char *save_temps_dir); 7410b57cec5SDimitry Andric 7420b57cec5SDimitry Andric /** 7430b57cec5SDimitry Andric * Sets the cpu to generate code for. 7440b57cec5SDimitry Andric * 7450b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7460b57cec5SDimitry Andric */ 7470b57cec5SDimitry Andric extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu); 7480b57cec5SDimitry Andric 7490b57cec5SDimitry Andric /** 7500b57cec5SDimitry Andric * Disable CodeGen, only run the stages till codegen and stop. The output will 7510b57cec5SDimitry Andric * be bitcode. 7520b57cec5SDimitry Andric * 7530b57cec5SDimitry Andric * \since LTO_API_VERSION=19 7540b57cec5SDimitry Andric */ 7550b57cec5SDimitry Andric extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg, 7560b57cec5SDimitry Andric lto_bool_t disable); 7570b57cec5SDimitry Andric 7580b57cec5SDimitry Andric /** 7590b57cec5SDimitry Andric * Perform CodeGen only: disable all other stages. 7600b57cec5SDimitry Andric * 7610b57cec5SDimitry Andric * \since LTO_API_VERSION=19 7620b57cec5SDimitry Andric */ 7630b57cec5SDimitry Andric extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg, 7640b57cec5SDimitry Andric lto_bool_t codegen_only); 7650b57cec5SDimitry Andric 7660b57cec5SDimitry Andric /** 7670b57cec5SDimitry Andric * Parse -mllvm style debug options. 7680b57cec5SDimitry Andric * 7690b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7700b57cec5SDimitry Andric */ 7710b57cec5SDimitry Andric extern void thinlto_debug_options(const char *const *options, int number); 7720b57cec5SDimitry Andric 7730b57cec5SDimitry Andric /** 7740b57cec5SDimitry Andric * Test if a module has support for ThinLTO linking. 7750b57cec5SDimitry Andric * 7760b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7770b57cec5SDimitry Andric */ 7780b57cec5SDimitry Andric extern lto_bool_t lto_module_is_thinlto(lto_module_t mod); 7790b57cec5SDimitry Andric 7800b57cec5SDimitry Andric /** 7810b57cec5SDimitry Andric * Adds a symbol to the list of global symbols that must exist in the final 7820b57cec5SDimitry Andric * generated code. If a function is not listed there, it might be inlined into 7830b57cec5SDimitry Andric * every usage and optimized away. For every single module, the functions 7840b57cec5SDimitry Andric * referenced from code outside of the ThinLTO modules need to be added here. 7850b57cec5SDimitry Andric * 7860b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7870b57cec5SDimitry Andric */ 7880b57cec5SDimitry Andric extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg, 7890b57cec5SDimitry Andric const char *name, 7900b57cec5SDimitry Andric int length); 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric /** 7930b57cec5SDimitry Andric * Adds a symbol to the list of global symbols that are cross-referenced between 7940b57cec5SDimitry Andric * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every 7950b57cec5SDimitry Andric * references from a ThinLTO module to this symbol is optimized away, then 7960b57cec5SDimitry Andric * the symbol can be discarded. 7970b57cec5SDimitry Andric * 7980b57cec5SDimitry Andric * \since LTO_API_VERSION=18 7990b57cec5SDimitry Andric */ 8000b57cec5SDimitry Andric extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg, 8010b57cec5SDimitry Andric const char *name, 8020b57cec5SDimitry Andric int length); 8030b57cec5SDimitry Andric 8040b57cec5SDimitry Andric /** 8050b57cec5SDimitry Andric * @} // endgoup LLVMCTLTO 8060b57cec5SDimitry Andric * @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control 8070b57cec5SDimitry Andric * @ingroup LLVMCTLTO 8080b57cec5SDimitry Andric * 8090b57cec5SDimitry Andric * These entry points control the ThinLTO cache. The cache is intended to 8100b57cec5SDimitry Andric * support incremental builds, and thus needs to be persistent across builds. 8110b57cec5SDimitry Andric * The client enables the cache by supplying a path to an existing directory. 8120b57cec5SDimitry Andric * The code generator will use this to store objects files that may be reused 8130b57cec5SDimitry Andric * during a subsequent build. 8140b57cec5SDimitry Andric * To avoid filling the disk space, a few knobs are provided: 8150b57cec5SDimitry Andric * - The pruning interval limits the frequency at which the garbage collector 8160b57cec5SDimitry Andric * will try to scan the cache directory to prune expired entries. 8170b57cec5SDimitry Andric * Setting to a negative number disables the pruning. 8180b57cec5SDimitry Andric * - The pruning expiration time indicates to the garbage collector how old an 8190b57cec5SDimitry Andric * entry needs to be to be removed. 8200b57cec5SDimitry Andric * - Finally, the garbage collector can be instructed to prune the cache until 8210b57cec5SDimitry Andric * the occupied space goes below a threshold. 8220b57cec5SDimitry Andric * @{ 8230b57cec5SDimitry Andric */ 8240b57cec5SDimitry Andric 8250b57cec5SDimitry Andric /** 8260b57cec5SDimitry Andric * Sets the path to a directory to use as a cache storage for incremental build. 8270b57cec5SDimitry Andric * Setting this activates caching. 8280b57cec5SDimitry Andric * 8290b57cec5SDimitry Andric * \since LTO_API_VERSION=18 8300b57cec5SDimitry Andric */ 8310b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg, 8320b57cec5SDimitry Andric const char *cache_dir); 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric /** 8350b57cec5SDimitry Andric * Sets the cache pruning interval (in seconds). A negative value disables the 8360b57cec5SDimitry Andric * pruning. An unspecified default value will be applied, and a value of 0 will 8370b57cec5SDimitry Andric * force prunning to occur. 8380b57cec5SDimitry Andric * 8390b57cec5SDimitry Andric * \since LTO_API_VERSION=18 8400b57cec5SDimitry Andric */ 8410b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg, 8420b57cec5SDimitry Andric int interval); 8430b57cec5SDimitry Andric 8440b57cec5SDimitry Andric /** 8450b57cec5SDimitry Andric * Sets the maximum cache size that can be persistent across build, in terms of 8460b57cec5SDimitry Andric * percentage of the available space on the disk. Set to 100 to indicate 8470b57cec5SDimitry Andric * no limit, 50 to indicate that the cache size will not be left over half the 8480b57cec5SDimitry Andric * available space. A value over 100 will be reduced to 100, a value of 0 will 8490b57cec5SDimitry Andric * be ignored. An unspecified default value will be applied. 8500b57cec5SDimitry Andric * 8510b57cec5SDimitry Andric * The formula looks like: 8520b57cec5SDimitry Andric * AvailableSpace = FreeSpace + ExistingCacheSize 8530b57cec5SDimitry Andric * NewCacheSize = AvailableSpace * P/100 8540b57cec5SDimitry Andric * 8550b57cec5SDimitry Andric * \since LTO_API_VERSION=18 8560b57cec5SDimitry Andric */ 8570b57cec5SDimitry Andric extern void thinlto_codegen_set_final_cache_size_relative_to_available_space( 8580b57cec5SDimitry Andric thinlto_code_gen_t cg, unsigned percentage); 8590b57cec5SDimitry Andric 8600b57cec5SDimitry Andric /** 8610b57cec5SDimitry Andric * Sets the expiration (in seconds) for an entry in the cache. An unspecified 8620b57cec5SDimitry Andric * default value will be applied. A value of 0 will be ignored. 8630b57cec5SDimitry Andric * 8640b57cec5SDimitry Andric * \since LTO_API_VERSION=18 8650b57cec5SDimitry Andric */ 8660b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, 8670b57cec5SDimitry Andric unsigned expiration); 8680b57cec5SDimitry Andric 8690b57cec5SDimitry Andric /** 8700b57cec5SDimitry Andric * Sets the maximum size of the cache directory (in bytes). A value over the 8710b57cec5SDimitry Andric * amount of available space on the disk will be reduced to the amount of 8720b57cec5SDimitry Andric * available space. An unspecified default value will be applied. A value of 0 8730b57cec5SDimitry Andric * will be ignored. 8740b57cec5SDimitry Andric * 8750b57cec5SDimitry Andric * \since LTO_API_VERSION=22 8760b57cec5SDimitry Andric */ 8770b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg, 8780b57cec5SDimitry Andric unsigned max_size_bytes); 8790b57cec5SDimitry Andric 8800b57cec5SDimitry Andric /** 8810b57cec5SDimitry Andric * Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in 8820b57cec5SDimitry Andric * megabytes (2^20 bytes). 8830b57cec5SDimitry Andric * 8840b57cec5SDimitry Andric * \since LTO_API_VERSION=23 8850b57cec5SDimitry Andric */ 8860b57cec5SDimitry Andric extern void 8870b57cec5SDimitry Andric thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg, 8880b57cec5SDimitry Andric unsigned max_size_megabytes); 8890b57cec5SDimitry Andric 8900b57cec5SDimitry Andric /** 8910b57cec5SDimitry Andric * Sets the maximum number of files in the cache directory. An unspecified 8920b57cec5SDimitry Andric * default value will be applied. A value of 0 will be ignored. 8930b57cec5SDimitry Andric * 8940b57cec5SDimitry Andric * \since LTO_API_VERSION=22 8950b57cec5SDimitry Andric */ 8960b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg, 8970b57cec5SDimitry Andric unsigned max_size_files); 8980b57cec5SDimitry Andric 8990b57cec5SDimitry Andric /** 9000b57cec5SDimitry Andric * @} // endgroup LLVMCTLTO_CACHING 9010b57cec5SDimitry Andric */ 9020b57cec5SDimitry Andric 9030b57cec5SDimitry Andric #ifdef __cplusplus 9040b57cec5SDimitry Andric } 9050b57cec5SDimitry Andric #endif 9060b57cec5SDimitry Andric 9070b57cec5SDimitry Andric #endif /* LLVM_C_LTO_H */ 908