17330f729Sjoerg /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\ 27330f729Sjoerg |* *| 37330f729Sjoerg |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 47330f729Sjoerg |* Exceptions. *| 57330f729Sjoerg |* See https://llvm.org/LICENSE.txt for license information. *| 67330f729Sjoerg |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 77330f729Sjoerg |* *| 87330f729Sjoerg |*===----------------------------------------------------------------------===*| 97330f729Sjoerg |* *| 107330f729Sjoerg |* This header provides public interface to an abstract link time optimization*| 117330f729Sjoerg |* library. LLVM provides an implementation of this interface for use with *| 127330f729Sjoerg |* llvm bitcode files. *| 137330f729Sjoerg |* *| 147330f729Sjoerg \*===----------------------------------------------------------------------===*/ 157330f729Sjoerg 167330f729Sjoerg #ifndef LLVM_C_LTO_H 177330f729Sjoerg #define LLVM_C_LTO_H 187330f729Sjoerg 19*82d56013Sjoerg #include "llvm-c/ExternC.h" 20*82d56013Sjoerg 217330f729Sjoerg #ifdef __cplusplus 227330f729Sjoerg #include <cstddef> 237330f729Sjoerg #else 247330f729Sjoerg #include <stddef.h> 257330f729Sjoerg #endif 267330f729Sjoerg #include <sys/types.h> 277330f729Sjoerg 287330f729Sjoerg #ifndef __cplusplus 297330f729Sjoerg #if !defined(_MSC_VER) 307330f729Sjoerg #include <stdbool.h> 317330f729Sjoerg typedef bool lto_bool_t; 327330f729Sjoerg #else 337330f729Sjoerg /* MSVC in particular does not have anything like _Bool or bool in C, but we can 347330f729Sjoerg at least make sure the type is the same size. The implementation side will 357330f729Sjoerg use C++ bool. */ 367330f729Sjoerg typedef unsigned char lto_bool_t; 377330f729Sjoerg #endif 387330f729Sjoerg #else 397330f729Sjoerg typedef bool lto_bool_t; 407330f729Sjoerg #endif 417330f729Sjoerg 427330f729Sjoerg /** 437330f729Sjoerg * @defgroup LLVMCLTO LTO 447330f729Sjoerg * @ingroup LLVMC 457330f729Sjoerg * 467330f729Sjoerg * @{ 477330f729Sjoerg */ 487330f729Sjoerg 49*82d56013Sjoerg #define LTO_API_VERSION 28 507330f729Sjoerg 517330f729Sjoerg /** 527330f729Sjoerg * \since prior to LTO_API_VERSION=3 537330f729Sjoerg */ 547330f729Sjoerg typedef enum { 557330f729Sjoerg LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ 567330f729Sjoerg LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, 577330f729Sjoerg LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, 587330f729Sjoerg LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, 597330f729Sjoerg LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, 607330f729Sjoerg LTO_SYMBOL_DEFINITION_MASK = 0x00000700, 617330f729Sjoerg LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, 627330f729Sjoerg LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, 637330f729Sjoerg LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, 647330f729Sjoerg LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, 657330f729Sjoerg LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, 667330f729Sjoerg LTO_SYMBOL_SCOPE_MASK = 0x00003800, 677330f729Sjoerg LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, 687330f729Sjoerg LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, 697330f729Sjoerg LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, 707330f729Sjoerg LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, 717330f729Sjoerg LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800, 727330f729Sjoerg LTO_SYMBOL_COMDAT = 0x00004000, 737330f729Sjoerg LTO_SYMBOL_ALIAS = 0x00008000 747330f729Sjoerg } lto_symbol_attributes; 757330f729Sjoerg 767330f729Sjoerg /** 777330f729Sjoerg * \since prior to LTO_API_VERSION=3 787330f729Sjoerg */ 797330f729Sjoerg typedef enum { 807330f729Sjoerg LTO_DEBUG_MODEL_NONE = 0, 817330f729Sjoerg LTO_DEBUG_MODEL_DWARF = 1 827330f729Sjoerg } lto_debug_model; 837330f729Sjoerg 847330f729Sjoerg /** 857330f729Sjoerg * \since prior to LTO_API_VERSION=3 867330f729Sjoerg */ 877330f729Sjoerg typedef enum { 887330f729Sjoerg LTO_CODEGEN_PIC_MODEL_STATIC = 0, 897330f729Sjoerg LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, 907330f729Sjoerg LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, 917330f729Sjoerg LTO_CODEGEN_PIC_MODEL_DEFAULT = 3 927330f729Sjoerg } lto_codegen_model; 937330f729Sjoerg 947330f729Sjoerg /** opaque reference to a loaded object module */ 957330f729Sjoerg typedef struct LLVMOpaqueLTOModule *lto_module_t; 967330f729Sjoerg 977330f729Sjoerg /** opaque reference to a code generator */ 987330f729Sjoerg typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t; 997330f729Sjoerg 1007330f729Sjoerg /** opaque reference to a thin code generator */ 1017330f729Sjoerg typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t; 1027330f729Sjoerg 103*82d56013Sjoerg LLVM_C_EXTERN_C_BEGIN 1047330f729Sjoerg 1057330f729Sjoerg /** 1067330f729Sjoerg * Returns a printable string. 1077330f729Sjoerg * 1087330f729Sjoerg * \since prior to LTO_API_VERSION=3 1097330f729Sjoerg */ 1107330f729Sjoerg extern const char* 1117330f729Sjoerg lto_get_version(void); 1127330f729Sjoerg 1137330f729Sjoerg /** 1147330f729Sjoerg * Returns the last error string or NULL if last operation was successful. 1157330f729Sjoerg * 1167330f729Sjoerg * \since prior to LTO_API_VERSION=3 1177330f729Sjoerg */ 1187330f729Sjoerg extern const char* 1197330f729Sjoerg lto_get_error_message(void); 1207330f729Sjoerg 1217330f729Sjoerg /** 1227330f729Sjoerg * Checks if a file is a loadable object file. 1237330f729Sjoerg * 1247330f729Sjoerg * \since prior to LTO_API_VERSION=3 1257330f729Sjoerg */ 1267330f729Sjoerg extern lto_bool_t 1277330f729Sjoerg lto_module_is_object_file(const char* path); 1287330f729Sjoerg 1297330f729Sjoerg /** 1307330f729Sjoerg * Checks if a file is a loadable object compiled for requested target. 1317330f729Sjoerg * 1327330f729Sjoerg * \since prior to LTO_API_VERSION=3 1337330f729Sjoerg */ 1347330f729Sjoerg extern lto_bool_t 1357330f729Sjoerg lto_module_is_object_file_for_target(const char* path, 1367330f729Sjoerg const char* target_triple_prefix); 1377330f729Sjoerg 1387330f729Sjoerg /** 1397330f729Sjoerg * Return true if \p Buffer contains a bitcode file with ObjC code (category 1407330f729Sjoerg * or class) in it. 1417330f729Sjoerg * 1427330f729Sjoerg * \since LTO_API_VERSION=20 1437330f729Sjoerg */ 1447330f729Sjoerg extern lto_bool_t 1457330f729Sjoerg lto_module_has_objc_category(const void *mem, size_t length); 1467330f729Sjoerg 1477330f729Sjoerg /** 1487330f729Sjoerg * Checks if a buffer is a loadable object file. 1497330f729Sjoerg * 1507330f729Sjoerg * \since prior to LTO_API_VERSION=3 1517330f729Sjoerg */ 1527330f729Sjoerg extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem, 1537330f729Sjoerg size_t length); 1547330f729Sjoerg 1557330f729Sjoerg /** 1567330f729Sjoerg * Checks if a buffer is a loadable object compiled for requested target. 1577330f729Sjoerg * 1587330f729Sjoerg * \since prior to LTO_API_VERSION=3 1597330f729Sjoerg */ 1607330f729Sjoerg extern lto_bool_t 1617330f729Sjoerg lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 1627330f729Sjoerg const char* target_triple_prefix); 1637330f729Sjoerg 1647330f729Sjoerg /** 1657330f729Sjoerg * Loads an object file from disk. 1667330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 1677330f729Sjoerg * 1687330f729Sjoerg * \since prior to LTO_API_VERSION=3 1697330f729Sjoerg */ 1707330f729Sjoerg extern lto_module_t 1717330f729Sjoerg lto_module_create(const char* path); 1727330f729Sjoerg 1737330f729Sjoerg /** 1747330f729Sjoerg * Loads an object file from memory. 1757330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 1767330f729Sjoerg * 1777330f729Sjoerg * \since prior to LTO_API_VERSION=3 1787330f729Sjoerg */ 1797330f729Sjoerg extern lto_module_t 1807330f729Sjoerg lto_module_create_from_memory(const void* mem, size_t length); 1817330f729Sjoerg 1827330f729Sjoerg /** 1837330f729Sjoerg * Loads an object file from memory with an extra path argument. 1847330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 1857330f729Sjoerg * 1867330f729Sjoerg * \since LTO_API_VERSION=9 1877330f729Sjoerg */ 1887330f729Sjoerg extern lto_module_t 1897330f729Sjoerg lto_module_create_from_memory_with_path(const void* mem, size_t length, 1907330f729Sjoerg const char *path); 1917330f729Sjoerg 1927330f729Sjoerg /** 1937330f729Sjoerg * Loads an object file in its own context. 1947330f729Sjoerg * 1957330f729Sjoerg * Loads an object file in its own LLVMContext. This function call is 1967330f729Sjoerg * thread-safe. However, modules created this way should not be merged into an 1977330f729Sjoerg * lto_code_gen_t using \a lto_codegen_add_module(). 1987330f729Sjoerg * 1997330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 2007330f729Sjoerg * 2017330f729Sjoerg * \since LTO_API_VERSION=11 2027330f729Sjoerg */ 2037330f729Sjoerg extern lto_module_t 2047330f729Sjoerg lto_module_create_in_local_context(const void *mem, size_t length, 2057330f729Sjoerg const char *path); 2067330f729Sjoerg 2077330f729Sjoerg /** 2087330f729Sjoerg * Loads an object file in the codegen context. 2097330f729Sjoerg * 2107330f729Sjoerg * Loads an object file into the same context as \c cg. The module is safe to 2117330f729Sjoerg * add using \a lto_codegen_add_module(). 2127330f729Sjoerg * 2137330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 2147330f729Sjoerg * 2157330f729Sjoerg * \since LTO_API_VERSION=11 2167330f729Sjoerg */ 2177330f729Sjoerg extern lto_module_t 2187330f729Sjoerg lto_module_create_in_codegen_context(const void *mem, size_t length, 2197330f729Sjoerg const char *path, lto_code_gen_t cg); 2207330f729Sjoerg 2217330f729Sjoerg /** 2227330f729Sjoerg * Loads an object file from disk. The seek point of fd is not preserved. 2237330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 2247330f729Sjoerg * 2257330f729Sjoerg * \since LTO_API_VERSION=5 2267330f729Sjoerg */ 2277330f729Sjoerg extern lto_module_t 2287330f729Sjoerg lto_module_create_from_fd(int fd, const char *path, size_t file_size); 2297330f729Sjoerg 2307330f729Sjoerg /** 2317330f729Sjoerg * Loads an object file from disk. The seek point of fd is not preserved. 2327330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 2337330f729Sjoerg * 2347330f729Sjoerg * \since LTO_API_VERSION=5 2357330f729Sjoerg */ 2367330f729Sjoerg extern lto_module_t 2377330f729Sjoerg lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, 2387330f729Sjoerg size_t map_size, off_t offset); 2397330f729Sjoerg 2407330f729Sjoerg /** 2417330f729Sjoerg * Frees all memory internally allocated by the module. 2427330f729Sjoerg * Upon return the lto_module_t is no longer valid. 2437330f729Sjoerg * 2447330f729Sjoerg * \since prior to LTO_API_VERSION=3 2457330f729Sjoerg */ 2467330f729Sjoerg extern void 2477330f729Sjoerg lto_module_dispose(lto_module_t mod); 2487330f729Sjoerg 2497330f729Sjoerg /** 2507330f729Sjoerg * Returns triple string which the object module was compiled under. 2517330f729Sjoerg * 2527330f729Sjoerg * \since prior to LTO_API_VERSION=3 2537330f729Sjoerg */ 2547330f729Sjoerg extern const char* 2557330f729Sjoerg lto_module_get_target_triple(lto_module_t mod); 2567330f729Sjoerg 2577330f729Sjoerg /** 2587330f729Sjoerg * Sets triple string with which the object will be codegened. 2597330f729Sjoerg * 2607330f729Sjoerg * \since LTO_API_VERSION=4 2617330f729Sjoerg */ 2627330f729Sjoerg extern void 2637330f729Sjoerg lto_module_set_target_triple(lto_module_t mod, const char *triple); 2647330f729Sjoerg 2657330f729Sjoerg /** 2667330f729Sjoerg * Returns the number of symbols in the object module. 2677330f729Sjoerg * 2687330f729Sjoerg * \since prior to LTO_API_VERSION=3 2697330f729Sjoerg */ 2707330f729Sjoerg extern unsigned int 2717330f729Sjoerg lto_module_get_num_symbols(lto_module_t mod); 2727330f729Sjoerg 2737330f729Sjoerg /** 2747330f729Sjoerg * Returns the name of the ith symbol in the object module. 2757330f729Sjoerg * 2767330f729Sjoerg * \since prior to LTO_API_VERSION=3 2777330f729Sjoerg */ 2787330f729Sjoerg extern const char* 2797330f729Sjoerg lto_module_get_symbol_name(lto_module_t mod, unsigned int index); 2807330f729Sjoerg 2817330f729Sjoerg /** 2827330f729Sjoerg * Returns the attributes of the ith symbol in the object module. 2837330f729Sjoerg * 2847330f729Sjoerg * \since prior to LTO_API_VERSION=3 2857330f729Sjoerg */ 2867330f729Sjoerg extern lto_symbol_attributes 2877330f729Sjoerg lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); 2887330f729Sjoerg 2897330f729Sjoerg /** 2907330f729Sjoerg * Returns the module's linker options. 2917330f729Sjoerg * 2927330f729Sjoerg * The linker options may consist of multiple flags. It is the linker's 2937330f729Sjoerg * responsibility to split the flags using a platform-specific mechanism. 2947330f729Sjoerg * 2957330f729Sjoerg * \since LTO_API_VERSION=16 2967330f729Sjoerg */ 2977330f729Sjoerg extern const char* 2987330f729Sjoerg lto_module_get_linkeropts(lto_module_t mod); 2997330f729Sjoerg 3007330f729Sjoerg /** 301*82d56013Sjoerg * If targeting mach-o on darwin, this function gets the CPU type and subtype 302*82d56013Sjoerg * that will end up being encoded in the mach-o header. These are the values 303*82d56013Sjoerg * that can be found in mach/machine.h. 304*82d56013Sjoerg * 305*82d56013Sjoerg * \p out_cputype and \p out_cpusubtype must be non-NULL. 306*82d56013Sjoerg * 307*82d56013Sjoerg * Returns true on error (check lto_get_error_message() for details). 308*82d56013Sjoerg * 309*82d56013Sjoerg * \since LTO_API_VERSION=27 310*82d56013Sjoerg */ 311*82d56013Sjoerg extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod, 312*82d56013Sjoerg unsigned int *out_cputype, 313*82d56013Sjoerg unsigned int *out_cpusubtype); 314*82d56013Sjoerg 315*82d56013Sjoerg /** 3167330f729Sjoerg * Diagnostic severity. 3177330f729Sjoerg * 3187330f729Sjoerg * \since LTO_API_VERSION=7 3197330f729Sjoerg */ 3207330f729Sjoerg typedef enum { 3217330f729Sjoerg LTO_DS_ERROR = 0, 3227330f729Sjoerg LTO_DS_WARNING = 1, 3237330f729Sjoerg LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10. 3247330f729Sjoerg LTO_DS_NOTE = 2 3257330f729Sjoerg } lto_codegen_diagnostic_severity_t; 3267330f729Sjoerg 3277330f729Sjoerg /** 3287330f729Sjoerg * Diagnostic handler type. 3297330f729Sjoerg * \p severity defines the severity. 3307330f729Sjoerg * \p diag is the actual diagnostic. 3317330f729Sjoerg * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '. 3327330f729Sjoerg * \p ctxt is used to pass the context set with the diagnostic handler. 3337330f729Sjoerg * 3347330f729Sjoerg * \since LTO_API_VERSION=7 3357330f729Sjoerg */ 3367330f729Sjoerg typedef void (*lto_diagnostic_handler_t)( 3377330f729Sjoerg lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt); 3387330f729Sjoerg 3397330f729Sjoerg /** 3407330f729Sjoerg * Set a diagnostic handler and the related context (void *). 3417330f729Sjoerg * This is more general than lto_get_error_message, as the diagnostic handler 3427330f729Sjoerg * can be called at anytime within lto. 3437330f729Sjoerg * 3447330f729Sjoerg * \since LTO_API_VERSION=7 3457330f729Sjoerg */ 3467330f729Sjoerg extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t, 3477330f729Sjoerg lto_diagnostic_handler_t, 3487330f729Sjoerg void *); 3497330f729Sjoerg 3507330f729Sjoerg /** 3517330f729Sjoerg * Instantiates a code generator. 3527330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 3537330f729Sjoerg * 3547330f729Sjoerg * All modules added using \a lto_codegen_add_module() must have been created 3557330f729Sjoerg * in the same context as the codegen. 3567330f729Sjoerg * 3577330f729Sjoerg * \since prior to LTO_API_VERSION=3 3587330f729Sjoerg */ 3597330f729Sjoerg extern lto_code_gen_t 3607330f729Sjoerg lto_codegen_create(void); 3617330f729Sjoerg 3627330f729Sjoerg /** 3637330f729Sjoerg * Instantiate a code generator in its own context. 3647330f729Sjoerg * 3657330f729Sjoerg * Instantiates a code generator in its own context. Modules added via \a 3667330f729Sjoerg * lto_codegen_add_module() must have all been created in the same context, 3677330f729Sjoerg * using \a lto_module_create_in_codegen_context(). 3687330f729Sjoerg * 3697330f729Sjoerg * \since LTO_API_VERSION=11 3707330f729Sjoerg */ 3717330f729Sjoerg extern lto_code_gen_t 3727330f729Sjoerg lto_codegen_create_in_local_context(void); 3737330f729Sjoerg 3747330f729Sjoerg /** 3757330f729Sjoerg * Frees all code generator and all memory it internally allocated. 3767330f729Sjoerg * Upon return the lto_code_gen_t is no longer valid. 3777330f729Sjoerg * 3787330f729Sjoerg * \since prior to LTO_API_VERSION=3 3797330f729Sjoerg */ 3807330f729Sjoerg extern void 3817330f729Sjoerg lto_codegen_dispose(lto_code_gen_t); 3827330f729Sjoerg 3837330f729Sjoerg /** 3847330f729Sjoerg * Add an object module to the set of modules for which code will be generated. 3857330f729Sjoerg * Returns true on error (check lto_get_error_message() for details). 3867330f729Sjoerg * 3877330f729Sjoerg * \c cg and \c mod must both be in the same context. See \a 3887330f729Sjoerg * lto_codegen_create_in_local_context() and \a 3897330f729Sjoerg * lto_module_create_in_codegen_context(). 3907330f729Sjoerg * 3917330f729Sjoerg * \since prior to LTO_API_VERSION=3 3927330f729Sjoerg */ 3937330f729Sjoerg extern lto_bool_t 3947330f729Sjoerg lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); 3957330f729Sjoerg 3967330f729Sjoerg /** 3977330f729Sjoerg * Sets the object module for code generation. This will transfer the ownership 3987330f729Sjoerg * of the module to the code generator. 3997330f729Sjoerg * 4007330f729Sjoerg * \c cg and \c mod must both be in the same context. 4017330f729Sjoerg * 4027330f729Sjoerg * \since LTO_API_VERSION=13 4037330f729Sjoerg */ 4047330f729Sjoerg extern void 4057330f729Sjoerg lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod); 4067330f729Sjoerg 4077330f729Sjoerg /** 4087330f729Sjoerg * Sets if debug info should be generated. 4097330f729Sjoerg * Returns true on error (check lto_get_error_message() for details). 4107330f729Sjoerg * 4117330f729Sjoerg * \since prior to LTO_API_VERSION=3 4127330f729Sjoerg */ 4137330f729Sjoerg extern lto_bool_t 4147330f729Sjoerg lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); 4157330f729Sjoerg 4167330f729Sjoerg /** 4177330f729Sjoerg * Sets which PIC code model to generated. 4187330f729Sjoerg * Returns true on error (check lto_get_error_message() for details). 4197330f729Sjoerg * 4207330f729Sjoerg * \since prior to LTO_API_VERSION=3 4217330f729Sjoerg */ 4227330f729Sjoerg extern lto_bool_t 4237330f729Sjoerg lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); 4247330f729Sjoerg 4257330f729Sjoerg /** 4267330f729Sjoerg * Sets the cpu to generate code for. 4277330f729Sjoerg * 4287330f729Sjoerg * \since LTO_API_VERSION=4 4297330f729Sjoerg */ 4307330f729Sjoerg extern void 4317330f729Sjoerg lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); 4327330f729Sjoerg 4337330f729Sjoerg /** 4347330f729Sjoerg * Sets the location of the assembler tool to run. If not set, libLTO 4357330f729Sjoerg * will use gcc to invoke the assembler. 4367330f729Sjoerg * 4377330f729Sjoerg * \since LTO_API_VERSION=3 4387330f729Sjoerg */ 4397330f729Sjoerg extern void 4407330f729Sjoerg lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); 4417330f729Sjoerg 4427330f729Sjoerg /** 4437330f729Sjoerg * Sets extra arguments that libLTO should pass to the assembler. 4447330f729Sjoerg * 4457330f729Sjoerg * \since LTO_API_VERSION=4 4467330f729Sjoerg */ 4477330f729Sjoerg extern void 4487330f729Sjoerg lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, 4497330f729Sjoerg int nargs); 4507330f729Sjoerg 4517330f729Sjoerg /** 4527330f729Sjoerg * Adds to a list of all global symbols that must exist in the final generated 4537330f729Sjoerg * code. If a function is not listed there, it might be inlined into every usage 4547330f729Sjoerg * and optimized away. 4557330f729Sjoerg * 4567330f729Sjoerg * \since prior to LTO_API_VERSION=3 4577330f729Sjoerg */ 4587330f729Sjoerg extern void 4597330f729Sjoerg lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); 4607330f729Sjoerg 4617330f729Sjoerg /** 4627330f729Sjoerg * Writes a new object file at the specified path that contains the 4637330f729Sjoerg * merged contents of all modules added so far. 4647330f729Sjoerg * Returns true on error (check lto_get_error_message() for details). 4657330f729Sjoerg * 4667330f729Sjoerg * \since LTO_API_VERSION=5 4677330f729Sjoerg */ 4687330f729Sjoerg extern lto_bool_t 4697330f729Sjoerg lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); 4707330f729Sjoerg 4717330f729Sjoerg /** 4727330f729Sjoerg * Generates code for all added modules into one native object file. 4737330f729Sjoerg * This calls lto_codegen_optimize then lto_codegen_compile_optimized. 4747330f729Sjoerg * 4757330f729Sjoerg * On success returns a pointer to a generated mach-o/ELF buffer and 4767330f729Sjoerg * length set to the buffer size. The buffer is owned by the 4777330f729Sjoerg * lto_code_gen_t and will be freed when lto_codegen_dispose() 4787330f729Sjoerg * is called, or lto_codegen_compile() is called again. 4797330f729Sjoerg * On failure, returns NULL (check lto_get_error_message() for details). 4807330f729Sjoerg * 4817330f729Sjoerg * \since prior to LTO_API_VERSION=3 4827330f729Sjoerg */ 4837330f729Sjoerg extern const void* 4847330f729Sjoerg lto_codegen_compile(lto_code_gen_t cg, size_t* length); 4857330f729Sjoerg 4867330f729Sjoerg /** 4877330f729Sjoerg * Generates code for all added modules into one native object file. 4887330f729Sjoerg * This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead 4897330f729Sjoerg * of returning a generated mach-o/ELF buffer, it writes to a file). 4907330f729Sjoerg * 4917330f729Sjoerg * The name of the file is written to name. Returns true on error. 4927330f729Sjoerg * 4937330f729Sjoerg * \since LTO_API_VERSION=5 4947330f729Sjoerg */ 4957330f729Sjoerg extern lto_bool_t 4967330f729Sjoerg lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); 4977330f729Sjoerg 4987330f729Sjoerg /** 4997330f729Sjoerg * Runs optimization for the merged module. Returns true on error. 5007330f729Sjoerg * 5017330f729Sjoerg * \since LTO_API_VERSION=12 5027330f729Sjoerg */ 5037330f729Sjoerg extern lto_bool_t 5047330f729Sjoerg lto_codegen_optimize(lto_code_gen_t cg); 5057330f729Sjoerg 5067330f729Sjoerg /** 5077330f729Sjoerg * Generates code for the optimized merged module into one native object file. 5087330f729Sjoerg * It will not run any IR optimizations on the merged module. 5097330f729Sjoerg * 5107330f729Sjoerg * On success returns a pointer to a generated mach-o/ELF buffer and length set 5117330f729Sjoerg * to the buffer size. The buffer is owned by the lto_code_gen_t and will be 5127330f729Sjoerg * freed when lto_codegen_dispose() is called, or 5137330f729Sjoerg * lto_codegen_compile_optimized() is called again. On failure, returns NULL 5147330f729Sjoerg * (check lto_get_error_message() for details). 5157330f729Sjoerg * 5167330f729Sjoerg * \since LTO_API_VERSION=12 5177330f729Sjoerg */ 5187330f729Sjoerg extern const void* 5197330f729Sjoerg lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length); 5207330f729Sjoerg 5217330f729Sjoerg /** 5227330f729Sjoerg * Returns the runtime API version. 5237330f729Sjoerg * 5247330f729Sjoerg * \since LTO_API_VERSION=12 5257330f729Sjoerg */ 5267330f729Sjoerg extern unsigned int 5277330f729Sjoerg lto_api_version(void); 5287330f729Sjoerg 5297330f729Sjoerg /** 530*82d56013Sjoerg * Parses options immediately, making them available as early as possible. For 531*82d56013Sjoerg * example during executing codegen::InitTargetOptionsFromCodeGenFlags. Since 532*82d56013Sjoerg * parsing shud only happen once, only one of lto_codegen_debug_options or 533*82d56013Sjoerg * lto_set_debug_options should be called. 534*82d56013Sjoerg * 535*82d56013Sjoerg * This function takes one or more options separated by spaces. 536*82d56013Sjoerg * Warning: passing file paths through this function may confuse the argument 537*82d56013Sjoerg * parser if the paths contain spaces. 538*82d56013Sjoerg * 539*82d56013Sjoerg * \since LTO_API_VERSION=28 540*82d56013Sjoerg */ 541*82d56013Sjoerg extern void lto_set_debug_options(const char *const *options, int number); 542*82d56013Sjoerg 543*82d56013Sjoerg /** 544*82d56013Sjoerg * Sets options to help debug codegen bugs. Since parsing shud only happen once, 545*82d56013Sjoerg * only one of lto_codegen_debug_options or lto_set_debug_options 546*82d56013Sjoerg * should be called. 547*82d56013Sjoerg * 548*82d56013Sjoerg * This function takes one or more options separated by spaces. 549*82d56013Sjoerg * Warning: passing file paths through this function may confuse the argument 550*82d56013Sjoerg * parser if the paths contain spaces. 5517330f729Sjoerg * 5527330f729Sjoerg * \since prior to LTO_API_VERSION=3 5537330f729Sjoerg */ 5547330f729Sjoerg extern void 5557330f729Sjoerg lto_codegen_debug_options(lto_code_gen_t cg, const char *); 5567330f729Sjoerg 5577330f729Sjoerg /** 558*82d56013Sjoerg * Same as the previous function, but takes every option separately through an 559*82d56013Sjoerg * array. 560*82d56013Sjoerg * 561*82d56013Sjoerg * \since prior to LTO_API_VERSION=26 562*82d56013Sjoerg */ 563*82d56013Sjoerg extern void lto_codegen_debug_options_array(lto_code_gen_t cg, 564*82d56013Sjoerg const char *const *, int number); 565*82d56013Sjoerg 566*82d56013Sjoerg /** 5677330f729Sjoerg * Initializes LLVM disassemblers. 5687330f729Sjoerg * FIXME: This doesn't really belong here. 5697330f729Sjoerg * 5707330f729Sjoerg * \since LTO_API_VERSION=5 5717330f729Sjoerg */ 5727330f729Sjoerg extern void 5737330f729Sjoerg lto_initialize_disassembler(void); 5747330f729Sjoerg 5757330f729Sjoerg /** 5767330f729Sjoerg * Sets if we should run internalize pass during optimization and code 5777330f729Sjoerg * generation. 5787330f729Sjoerg * 5797330f729Sjoerg * \since LTO_API_VERSION=14 5807330f729Sjoerg */ 5817330f729Sjoerg extern void 5827330f729Sjoerg lto_codegen_set_should_internalize(lto_code_gen_t cg, 5837330f729Sjoerg lto_bool_t ShouldInternalize); 5847330f729Sjoerg 5857330f729Sjoerg /** 5867330f729Sjoerg * Set whether to embed uselists in bitcode. 5877330f729Sjoerg * 5887330f729Sjoerg * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in 5897330f729Sjoerg * output bitcode. This should be turned on for all -save-temps output. 5907330f729Sjoerg * 5917330f729Sjoerg * \since LTO_API_VERSION=15 5927330f729Sjoerg */ 5937330f729Sjoerg extern void 5947330f729Sjoerg lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, 5957330f729Sjoerg lto_bool_t ShouldEmbedUselists); 5967330f729Sjoerg 5977330f729Sjoerg /** Opaque reference to an LTO input file */ 5987330f729Sjoerg typedef struct LLVMOpaqueLTOInput *lto_input_t; 5997330f729Sjoerg 6007330f729Sjoerg /** 6017330f729Sjoerg * Creates an LTO input file from a buffer. The path 6027330f729Sjoerg * argument is used for diagnotics as this function 6037330f729Sjoerg * otherwise does not know which file the given buffer 6047330f729Sjoerg * is associated with. 6057330f729Sjoerg * 6067330f729Sjoerg * \since LTO_API_VERSION=24 6077330f729Sjoerg */ 6087330f729Sjoerg extern lto_input_t lto_input_create(const void *buffer, 6097330f729Sjoerg size_t buffer_size, 6107330f729Sjoerg const char *path); 6117330f729Sjoerg 6127330f729Sjoerg /** 6137330f729Sjoerg * Frees all memory internally allocated by the LTO input file. 6147330f729Sjoerg * Upon return the lto_module_t is no longer valid. 6157330f729Sjoerg * 6167330f729Sjoerg * \since LTO_API_VERSION=24 6177330f729Sjoerg */ 6187330f729Sjoerg extern void lto_input_dispose(lto_input_t input); 6197330f729Sjoerg 6207330f729Sjoerg /** 6217330f729Sjoerg * Returns the number of dependent library specifiers 6227330f729Sjoerg * for the given LTO input file. 6237330f729Sjoerg * 6247330f729Sjoerg * \since LTO_API_VERSION=24 6257330f729Sjoerg */ 6267330f729Sjoerg extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input); 6277330f729Sjoerg 6287330f729Sjoerg /** 6297330f729Sjoerg * Returns the ith dependent library specifier 6307330f729Sjoerg * for the given LTO input file. The returned 6317330f729Sjoerg * string is not null-terminated. 6327330f729Sjoerg * 6337330f729Sjoerg * \since LTO_API_VERSION=24 6347330f729Sjoerg */ 6357330f729Sjoerg extern const char * lto_input_get_dependent_library(lto_input_t input, 6367330f729Sjoerg size_t index, 6377330f729Sjoerg size_t *size); 6387330f729Sjoerg 6397330f729Sjoerg /** 6407330f729Sjoerg * Returns the list of libcall symbols that can be generated by LTO 6417330f729Sjoerg * that might not be visible from the symbol table of bitcode files. 6427330f729Sjoerg * 6437330f729Sjoerg * \since prior to LTO_API_VERSION=25 6447330f729Sjoerg */ 6457330f729Sjoerg extern const char *const *lto_runtime_lib_symbols_list(size_t *size); 6467330f729Sjoerg 6477330f729Sjoerg /** 6487330f729Sjoerg * @} // endgoup LLVMCLTO 6497330f729Sjoerg * @defgroup LLVMCTLTO ThinLTO 6507330f729Sjoerg * @ingroup LLVMC 6517330f729Sjoerg * 6527330f729Sjoerg * @{ 6537330f729Sjoerg */ 6547330f729Sjoerg 6557330f729Sjoerg /** 6567330f729Sjoerg * Type to wrap a single object returned by ThinLTO. 6577330f729Sjoerg * 6587330f729Sjoerg * \since LTO_API_VERSION=18 6597330f729Sjoerg */ 6607330f729Sjoerg typedef struct { 6617330f729Sjoerg const char *Buffer; 6627330f729Sjoerg size_t Size; 6637330f729Sjoerg } LTOObjectBuffer; 6647330f729Sjoerg 6657330f729Sjoerg /** 6667330f729Sjoerg * Instantiates a ThinLTO code generator. 6677330f729Sjoerg * Returns NULL on error (check lto_get_error_message() for details). 6687330f729Sjoerg * 6697330f729Sjoerg * 6707330f729Sjoerg * The ThinLTOCodeGenerator is not intended to be reuse for multiple 6717330f729Sjoerg * compilation: the model is that the client adds modules to the generator and 6727330f729Sjoerg * ask to perform the ThinLTO optimizations / codegen, and finally destroys the 6737330f729Sjoerg * codegenerator. 6747330f729Sjoerg * 6757330f729Sjoerg * \since LTO_API_VERSION=18 6767330f729Sjoerg */ 6777330f729Sjoerg extern thinlto_code_gen_t thinlto_create_codegen(void); 6787330f729Sjoerg 6797330f729Sjoerg /** 6807330f729Sjoerg * Frees the generator and all memory it internally allocated. 6817330f729Sjoerg * Upon return the thinlto_code_gen_t is no longer valid. 6827330f729Sjoerg * 6837330f729Sjoerg * \since LTO_API_VERSION=18 6847330f729Sjoerg */ 6857330f729Sjoerg extern void thinlto_codegen_dispose(thinlto_code_gen_t cg); 6867330f729Sjoerg 6877330f729Sjoerg /** 6887330f729Sjoerg * Add a module to a ThinLTO code generator. Identifier has to be unique among 6897330f729Sjoerg * all the modules in a code generator. The data buffer stays owned by the 6907330f729Sjoerg * client, and is expected to be available for the entire lifetime of the 6917330f729Sjoerg * thinlto_code_gen_t it is added to. 6927330f729Sjoerg * 6937330f729Sjoerg * On failure, returns NULL (check lto_get_error_message() for details). 6947330f729Sjoerg * 6957330f729Sjoerg * 6967330f729Sjoerg * \since LTO_API_VERSION=18 6977330f729Sjoerg */ 6987330f729Sjoerg extern void thinlto_codegen_add_module(thinlto_code_gen_t cg, 6997330f729Sjoerg const char *identifier, const char *data, 7007330f729Sjoerg int length); 7017330f729Sjoerg 7027330f729Sjoerg /** 7037330f729Sjoerg * Optimize and codegen all the modules added to the codegenerator using 7047330f729Sjoerg * ThinLTO. Resulting objects are accessible using thinlto_module_get_object(). 7057330f729Sjoerg * 7067330f729Sjoerg * \since LTO_API_VERSION=18 7077330f729Sjoerg */ 7087330f729Sjoerg extern void thinlto_codegen_process(thinlto_code_gen_t cg); 7097330f729Sjoerg 7107330f729Sjoerg /** 7117330f729Sjoerg * Returns the number of object files produced by the ThinLTO CodeGenerator. 7127330f729Sjoerg * 7137330f729Sjoerg * It usually matches the number of input files, but this is not a guarantee of 7147330f729Sjoerg * the API and may change in future implementation, so the client should not 7157330f729Sjoerg * assume it. 7167330f729Sjoerg * 7177330f729Sjoerg * \since LTO_API_VERSION=18 7187330f729Sjoerg */ 7197330f729Sjoerg extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg); 7207330f729Sjoerg 7217330f729Sjoerg /** 7227330f729Sjoerg * Returns a reference to the ith object file produced by the ThinLTO 7237330f729Sjoerg * CodeGenerator. 7247330f729Sjoerg * 7257330f729Sjoerg * Client should use \p thinlto_module_get_num_objects() to get the number of 7267330f729Sjoerg * available objects. 7277330f729Sjoerg * 7287330f729Sjoerg * \since LTO_API_VERSION=18 7297330f729Sjoerg */ 7307330f729Sjoerg extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg, 7317330f729Sjoerg unsigned int index); 7327330f729Sjoerg 7337330f729Sjoerg /** 7347330f729Sjoerg * Returns the number of object files produced by the ThinLTO CodeGenerator. 7357330f729Sjoerg * 7367330f729Sjoerg * It usually matches the number of input files, but this is not a guarantee of 7377330f729Sjoerg * the API and may change in future implementation, so the client should not 7387330f729Sjoerg * assume it. 7397330f729Sjoerg * 7407330f729Sjoerg * \since LTO_API_VERSION=21 7417330f729Sjoerg */ 7427330f729Sjoerg unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg); 7437330f729Sjoerg 7447330f729Sjoerg /** 7457330f729Sjoerg * Returns the path to the ith object file produced by the ThinLTO 7467330f729Sjoerg * CodeGenerator. 7477330f729Sjoerg * 7487330f729Sjoerg * Client should use \p thinlto_module_get_num_object_files() to get the number 7497330f729Sjoerg * of available objects. 7507330f729Sjoerg * 7517330f729Sjoerg * \since LTO_API_VERSION=21 7527330f729Sjoerg */ 7537330f729Sjoerg const char *thinlto_module_get_object_file(thinlto_code_gen_t cg, 7547330f729Sjoerg unsigned int index); 7557330f729Sjoerg 7567330f729Sjoerg /** 7577330f729Sjoerg * Sets which PIC code model to generate. 7587330f729Sjoerg * Returns true on error (check lto_get_error_message() for details). 7597330f729Sjoerg * 7607330f729Sjoerg * \since LTO_API_VERSION=18 7617330f729Sjoerg */ 7627330f729Sjoerg extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, 7637330f729Sjoerg lto_codegen_model); 7647330f729Sjoerg 7657330f729Sjoerg /** 7667330f729Sjoerg * Sets the path to a directory to use as a storage for temporary bitcode files. 7677330f729Sjoerg * The intention is to make the bitcode files available for debugging at various 7687330f729Sjoerg * stage of the pipeline. 7697330f729Sjoerg * 7707330f729Sjoerg * \since LTO_API_VERSION=18 7717330f729Sjoerg */ 7727330f729Sjoerg extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, 7737330f729Sjoerg const char *save_temps_dir); 7747330f729Sjoerg 7757330f729Sjoerg /** 7767330f729Sjoerg * Set the path to a directory where to save generated object files. This 7777330f729Sjoerg * path can be used by a linker to request on-disk files instead of in-memory 7787330f729Sjoerg * buffers. When set, results are available through 7797330f729Sjoerg * thinlto_module_get_object_file() instead of thinlto_module_get_object(). 7807330f729Sjoerg * 7817330f729Sjoerg * \since LTO_API_VERSION=21 7827330f729Sjoerg */ 7837330f729Sjoerg void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg, 7847330f729Sjoerg const char *save_temps_dir); 7857330f729Sjoerg 7867330f729Sjoerg /** 7877330f729Sjoerg * Sets the cpu to generate code for. 7887330f729Sjoerg * 7897330f729Sjoerg * \since LTO_API_VERSION=18 7907330f729Sjoerg */ 7917330f729Sjoerg extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu); 7927330f729Sjoerg 7937330f729Sjoerg /** 7947330f729Sjoerg * Disable CodeGen, only run the stages till codegen and stop. The output will 7957330f729Sjoerg * be bitcode. 7967330f729Sjoerg * 7977330f729Sjoerg * \since LTO_API_VERSION=19 7987330f729Sjoerg */ 7997330f729Sjoerg extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg, 8007330f729Sjoerg lto_bool_t disable); 8017330f729Sjoerg 8027330f729Sjoerg /** 8037330f729Sjoerg * Perform CodeGen only: disable all other stages. 8047330f729Sjoerg * 8057330f729Sjoerg * \since LTO_API_VERSION=19 8067330f729Sjoerg */ 8077330f729Sjoerg extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg, 8087330f729Sjoerg lto_bool_t codegen_only); 8097330f729Sjoerg 8107330f729Sjoerg /** 8117330f729Sjoerg * Parse -mllvm style debug options. 8127330f729Sjoerg * 8137330f729Sjoerg * \since LTO_API_VERSION=18 8147330f729Sjoerg */ 8157330f729Sjoerg extern void thinlto_debug_options(const char *const *options, int number); 8167330f729Sjoerg 8177330f729Sjoerg /** 8187330f729Sjoerg * Test if a module has support for ThinLTO linking. 8197330f729Sjoerg * 8207330f729Sjoerg * \since LTO_API_VERSION=18 8217330f729Sjoerg */ 8227330f729Sjoerg extern lto_bool_t lto_module_is_thinlto(lto_module_t mod); 8237330f729Sjoerg 8247330f729Sjoerg /** 8257330f729Sjoerg * Adds a symbol to the list of global symbols that must exist in the final 8267330f729Sjoerg * generated code. If a function is not listed there, it might be inlined into 8277330f729Sjoerg * every usage and optimized away. For every single module, the functions 8287330f729Sjoerg * referenced from code outside of the ThinLTO modules need to be added here. 8297330f729Sjoerg * 8307330f729Sjoerg * \since LTO_API_VERSION=18 8317330f729Sjoerg */ 8327330f729Sjoerg extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg, 8337330f729Sjoerg const char *name, 8347330f729Sjoerg int length); 8357330f729Sjoerg 8367330f729Sjoerg /** 8377330f729Sjoerg * Adds a symbol to the list of global symbols that are cross-referenced between 8387330f729Sjoerg * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every 8397330f729Sjoerg * references from a ThinLTO module to this symbol is optimized away, then 8407330f729Sjoerg * the symbol can be discarded. 8417330f729Sjoerg * 8427330f729Sjoerg * \since LTO_API_VERSION=18 8437330f729Sjoerg */ 8447330f729Sjoerg extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg, 8457330f729Sjoerg const char *name, 8467330f729Sjoerg int length); 8477330f729Sjoerg 8487330f729Sjoerg /** 8497330f729Sjoerg * @} // endgoup LLVMCTLTO 8507330f729Sjoerg * @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control 8517330f729Sjoerg * @ingroup LLVMCTLTO 8527330f729Sjoerg * 8537330f729Sjoerg * These entry points control the ThinLTO cache. The cache is intended to 8547330f729Sjoerg * support incremental builds, and thus needs to be persistent across builds. 8557330f729Sjoerg * The client enables the cache by supplying a path to an existing directory. 8567330f729Sjoerg * The code generator will use this to store objects files that may be reused 8577330f729Sjoerg * during a subsequent build. 8587330f729Sjoerg * To avoid filling the disk space, a few knobs are provided: 8597330f729Sjoerg * - The pruning interval limits the frequency at which the garbage collector 8607330f729Sjoerg * will try to scan the cache directory to prune expired entries. 8617330f729Sjoerg * Setting to a negative number disables the pruning. 8627330f729Sjoerg * - The pruning expiration time indicates to the garbage collector how old an 8637330f729Sjoerg * entry needs to be to be removed. 8647330f729Sjoerg * - Finally, the garbage collector can be instructed to prune the cache until 8657330f729Sjoerg * the occupied space goes below a threshold. 8667330f729Sjoerg * @{ 8677330f729Sjoerg */ 8687330f729Sjoerg 8697330f729Sjoerg /** 8707330f729Sjoerg * Sets the path to a directory to use as a cache storage for incremental build. 8717330f729Sjoerg * Setting this activates caching. 8727330f729Sjoerg * 8737330f729Sjoerg * \since LTO_API_VERSION=18 8747330f729Sjoerg */ 8757330f729Sjoerg extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg, 8767330f729Sjoerg const char *cache_dir); 8777330f729Sjoerg 8787330f729Sjoerg /** 8797330f729Sjoerg * Sets the cache pruning interval (in seconds). A negative value disables the 8807330f729Sjoerg * pruning. An unspecified default value will be applied, and a value of 0 will 8817330f729Sjoerg * force prunning to occur. 8827330f729Sjoerg * 8837330f729Sjoerg * \since LTO_API_VERSION=18 8847330f729Sjoerg */ 8857330f729Sjoerg extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg, 8867330f729Sjoerg int interval); 8877330f729Sjoerg 8887330f729Sjoerg /** 8897330f729Sjoerg * Sets the maximum cache size that can be persistent across build, in terms of 8907330f729Sjoerg * percentage of the available space on the disk. Set to 100 to indicate 8917330f729Sjoerg * no limit, 50 to indicate that the cache size will not be left over half the 8927330f729Sjoerg * available space. A value over 100 will be reduced to 100, a value of 0 will 8937330f729Sjoerg * be ignored. An unspecified default value will be applied. 8947330f729Sjoerg * 8957330f729Sjoerg * The formula looks like: 8967330f729Sjoerg * AvailableSpace = FreeSpace + ExistingCacheSize 8977330f729Sjoerg * NewCacheSize = AvailableSpace * P/100 8987330f729Sjoerg * 8997330f729Sjoerg * \since LTO_API_VERSION=18 9007330f729Sjoerg */ 9017330f729Sjoerg extern void thinlto_codegen_set_final_cache_size_relative_to_available_space( 9027330f729Sjoerg thinlto_code_gen_t cg, unsigned percentage); 9037330f729Sjoerg 9047330f729Sjoerg /** 9057330f729Sjoerg * Sets the expiration (in seconds) for an entry in the cache. An unspecified 9067330f729Sjoerg * default value will be applied. A value of 0 will be ignored. 9077330f729Sjoerg * 9087330f729Sjoerg * \since LTO_API_VERSION=18 9097330f729Sjoerg */ 9107330f729Sjoerg extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, 9117330f729Sjoerg unsigned expiration); 9127330f729Sjoerg 9137330f729Sjoerg /** 9147330f729Sjoerg * Sets the maximum size of the cache directory (in bytes). A value over the 9157330f729Sjoerg * amount of available space on the disk will be reduced to the amount of 9167330f729Sjoerg * available space. An unspecified default value will be applied. A value of 0 9177330f729Sjoerg * will be ignored. 9187330f729Sjoerg * 9197330f729Sjoerg * \since LTO_API_VERSION=22 9207330f729Sjoerg */ 9217330f729Sjoerg extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg, 9227330f729Sjoerg unsigned max_size_bytes); 9237330f729Sjoerg 9247330f729Sjoerg /** 9257330f729Sjoerg * Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in 9267330f729Sjoerg * megabytes (2^20 bytes). 9277330f729Sjoerg * 9287330f729Sjoerg * \since LTO_API_VERSION=23 9297330f729Sjoerg */ 9307330f729Sjoerg extern void 9317330f729Sjoerg thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg, 9327330f729Sjoerg unsigned max_size_megabytes); 9337330f729Sjoerg 9347330f729Sjoerg /** 9357330f729Sjoerg * Sets the maximum number of files in the cache directory. An unspecified 9367330f729Sjoerg * default value will be applied. A value of 0 will be ignored. 9377330f729Sjoerg * 9387330f729Sjoerg * \since LTO_API_VERSION=22 9397330f729Sjoerg */ 9407330f729Sjoerg extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg, 9417330f729Sjoerg unsigned max_size_files); 9427330f729Sjoerg 9437330f729Sjoerg /** 9447330f729Sjoerg * @} // endgroup LLVMCTLTO_CACHING 9457330f729Sjoerg */ 9467330f729Sjoerg 947*82d56013Sjoerg LLVM_C_EXTERN_C_END 9487330f729Sjoerg 9497330f729Sjoerg #endif /* LLVM_C_LTO_H */ 950