109467b48Spatrick /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\ 209467b48Spatrick |* *| 309467b48Spatrick |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 409467b48Spatrick |* Exceptions. *| 509467b48Spatrick |* See https://llvm.org/LICENSE.txt for license information. *| 609467b48Spatrick |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 709467b48Spatrick |* *| 809467b48Spatrick |*===----------------------------------------------------------------------===*| 909467b48Spatrick |* *| 1009467b48Spatrick |* This header provides public interface to an abstract link time optimization*| 1109467b48Spatrick |* library. LLVM provides an implementation of this interface for use with *| 1209467b48Spatrick |* llvm bitcode files. *| 1309467b48Spatrick |* *| 1409467b48Spatrick \*===----------------------------------------------------------------------===*/ 1509467b48Spatrick 1609467b48Spatrick #ifndef LLVM_C_LTO_H 1709467b48Spatrick #define LLVM_C_LTO_H 1809467b48Spatrick 1909467b48Spatrick #include "llvm-c/ExternC.h" 2009467b48Spatrick 2109467b48Spatrick #ifdef __cplusplus 2209467b48Spatrick #include <cstddef> 2309467b48Spatrick #else 2409467b48Spatrick #include <stddef.h> 2509467b48Spatrick #endif 2609467b48Spatrick #include <sys/types.h> 2709467b48Spatrick 2809467b48Spatrick #ifndef __cplusplus 2909467b48Spatrick #if !defined(_MSC_VER) 3009467b48Spatrick #include <stdbool.h> 3109467b48Spatrick typedef bool lto_bool_t; 3209467b48Spatrick #else 3309467b48Spatrick /* MSVC in particular does not have anything like _Bool or bool in C, but we can 3409467b48Spatrick at least make sure the type is the same size. The implementation side will 3509467b48Spatrick use C++ bool. */ 3609467b48Spatrick typedef unsigned char lto_bool_t; 3709467b48Spatrick #endif 3809467b48Spatrick #else 3909467b48Spatrick typedef bool lto_bool_t; 4009467b48Spatrick #endif 4109467b48Spatrick 4209467b48Spatrick /** 4309467b48Spatrick * @defgroup LLVMCLTO LTO 4409467b48Spatrick * @ingroup LLVMC 4509467b48Spatrick * 4609467b48Spatrick * @{ 4709467b48Spatrick */ 4809467b48Spatrick 49*d415bd75Srobert #define LTO_API_VERSION 29 5009467b48Spatrick 5109467b48Spatrick /** 5209467b48Spatrick * \since prior to LTO_API_VERSION=3 5309467b48Spatrick */ 5409467b48Spatrick typedef enum { 5509467b48Spatrick LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ 5609467b48Spatrick LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, 5709467b48Spatrick LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, 5809467b48Spatrick LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, 5909467b48Spatrick LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, 6009467b48Spatrick LTO_SYMBOL_DEFINITION_MASK = 0x00000700, 6109467b48Spatrick LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, 6209467b48Spatrick LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, 6309467b48Spatrick LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, 6409467b48Spatrick LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, 6509467b48Spatrick LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, 6609467b48Spatrick LTO_SYMBOL_SCOPE_MASK = 0x00003800, 6709467b48Spatrick LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, 6809467b48Spatrick LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, 6909467b48Spatrick LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, 7009467b48Spatrick LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, 7109467b48Spatrick LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800, 7209467b48Spatrick LTO_SYMBOL_COMDAT = 0x00004000, 7309467b48Spatrick LTO_SYMBOL_ALIAS = 0x00008000 7409467b48Spatrick } lto_symbol_attributes; 7509467b48Spatrick 7609467b48Spatrick /** 7709467b48Spatrick * \since prior to LTO_API_VERSION=3 7809467b48Spatrick */ 7909467b48Spatrick typedef enum { 8009467b48Spatrick LTO_DEBUG_MODEL_NONE = 0, 8109467b48Spatrick LTO_DEBUG_MODEL_DWARF = 1 8209467b48Spatrick } lto_debug_model; 8309467b48Spatrick 8409467b48Spatrick /** 8509467b48Spatrick * \since prior to LTO_API_VERSION=3 8609467b48Spatrick */ 8709467b48Spatrick typedef enum { 8809467b48Spatrick LTO_CODEGEN_PIC_MODEL_STATIC = 0, 8909467b48Spatrick LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, 9009467b48Spatrick LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, 9109467b48Spatrick LTO_CODEGEN_PIC_MODEL_DEFAULT = 3 9209467b48Spatrick } lto_codegen_model; 9309467b48Spatrick 9409467b48Spatrick /** opaque reference to a loaded object module */ 9509467b48Spatrick typedef struct LLVMOpaqueLTOModule *lto_module_t; 9609467b48Spatrick 9709467b48Spatrick /** opaque reference to a code generator */ 9809467b48Spatrick typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t; 9909467b48Spatrick 10009467b48Spatrick /** opaque reference to a thin code generator */ 10109467b48Spatrick typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t; 10209467b48Spatrick 10309467b48Spatrick LLVM_C_EXTERN_C_BEGIN 10409467b48Spatrick 10509467b48Spatrick /** 10609467b48Spatrick * Returns a printable string. 10709467b48Spatrick * 10809467b48Spatrick * \since prior to LTO_API_VERSION=3 10909467b48Spatrick */ 11009467b48Spatrick extern const char* 11109467b48Spatrick lto_get_version(void); 11209467b48Spatrick 11309467b48Spatrick /** 11409467b48Spatrick * Returns the last error string or NULL if last operation was successful. 11509467b48Spatrick * 11609467b48Spatrick * \since prior to LTO_API_VERSION=3 11709467b48Spatrick */ 11809467b48Spatrick extern const char* 11909467b48Spatrick lto_get_error_message(void); 12009467b48Spatrick 12109467b48Spatrick /** 12209467b48Spatrick * Checks if a file is a loadable object file. 12309467b48Spatrick * 12409467b48Spatrick * \since prior to LTO_API_VERSION=3 12509467b48Spatrick */ 12609467b48Spatrick extern lto_bool_t 12709467b48Spatrick lto_module_is_object_file(const char* path); 12809467b48Spatrick 12909467b48Spatrick /** 13009467b48Spatrick * Checks if a file is a loadable object compiled for requested target. 13109467b48Spatrick * 13209467b48Spatrick * \since prior to LTO_API_VERSION=3 13309467b48Spatrick */ 13409467b48Spatrick extern lto_bool_t 13509467b48Spatrick lto_module_is_object_file_for_target(const char* path, 13609467b48Spatrick const char* target_triple_prefix); 13709467b48Spatrick 13809467b48Spatrick /** 13909467b48Spatrick * Return true if \p Buffer contains a bitcode file with ObjC code (category 14009467b48Spatrick * or class) in it. 14109467b48Spatrick * 14209467b48Spatrick * \since LTO_API_VERSION=20 14309467b48Spatrick */ 14409467b48Spatrick extern lto_bool_t 14509467b48Spatrick lto_module_has_objc_category(const void *mem, size_t length); 14609467b48Spatrick 14709467b48Spatrick /** 14809467b48Spatrick * Checks if a buffer is a loadable object file. 14909467b48Spatrick * 15009467b48Spatrick * \since prior to LTO_API_VERSION=3 15109467b48Spatrick */ 15209467b48Spatrick extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem, 15309467b48Spatrick size_t length); 15409467b48Spatrick 15509467b48Spatrick /** 15609467b48Spatrick * Checks if a buffer is a loadable object compiled for requested target. 15709467b48Spatrick * 15809467b48Spatrick * \since prior to LTO_API_VERSION=3 15909467b48Spatrick */ 16009467b48Spatrick extern lto_bool_t 16109467b48Spatrick lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 16209467b48Spatrick const char* target_triple_prefix); 16309467b48Spatrick 16409467b48Spatrick /** 16509467b48Spatrick * Loads an object file from disk. 16609467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 16709467b48Spatrick * 16809467b48Spatrick * \since prior to LTO_API_VERSION=3 16909467b48Spatrick */ 17009467b48Spatrick extern lto_module_t 17109467b48Spatrick lto_module_create(const char* path); 17209467b48Spatrick 17309467b48Spatrick /** 17409467b48Spatrick * Loads an object file from memory. 17509467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 17609467b48Spatrick * 17709467b48Spatrick * \since prior to LTO_API_VERSION=3 17809467b48Spatrick */ 17909467b48Spatrick extern lto_module_t 18009467b48Spatrick lto_module_create_from_memory(const void* mem, size_t length); 18109467b48Spatrick 18209467b48Spatrick /** 18309467b48Spatrick * Loads an object file from memory with an extra path argument. 18409467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 18509467b48Spatrick * 18609467b48Spatrick * \since LTO_API_VERSION=9 18709467b48Spatrick */ 18809467b48Spatrick extern lto_module_t 18909467b48Spatrick lto_module_create_from_memory_with_path(const void* mem, size_t length, 19009467b48Spatrick const char *path); 19109467b48Spatrick 19209467b48Spatrick /** 19309467b48Spatrick * Loads an object file in its own context. 19409467b48Spatrick * 19509467b48Spatrick * Loads an object file in its own LLVMContext. This function call is 19609467b48Spatrick * thread-safe. However, modules created this way should not be merged into an 19709467b48Spatrick * lto_code_gen_t using \a lto_codegen_add_module(). 19809467b48Spatrick * 19909467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 20009467b48Spatrick * 20109467b48Spatrick * \since LTO_API_VERSION=11 20209467b48Spatrick */ 20309467b48Spatrick extern lto_module_t 20409467b48Spatrick lto_module_create_in_local_context(const void *mem, size_t length, 20509467b48Spatrick const char *path); 20609467b48Spatrick 20709467b48Spatrick /** 20809467b48Spatrick * Loads an object file in the codegen context. 20909467b48Spatrick * 21009467b48Spatrick * Loads an object file into the same context as \c cg. The module is safe to 21109467b48Spatrick * add using \a lto_codegen_add_module(). 21209467b48Spatrick * 21309467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 21409467b48Spatrick * 21509467b48Spatrick * \since LTO_API_VERSION=11 21609467b48Spatrick */ 21709467b48Spatrick extern lto_module_t 21809467b48Spatrick lto_module_create_in_codegen_context(const void *mem, size_t length, 21909467b48Spatrick const char *path, lto_code_gen_t cg); 22009467b48Spatrick 22109467b48Spatrick /** 22209467b48Spatrick * Loads an object file from disk. The seek point of fd is not preserved. 22309467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 22409467b48Spatrick * 22509467b48Spatrick * \since LTO_API_VERSION=5 22609467b48Spatrick */ 22709467b48Spatrick extern lto_module_t 22809467b48Spatrick lto_module_create_from_fd(int fd, const char *path, size_t file_size); 22909467b48Spatrick 23009467b48Spatrick /** 23109467b48Spatrick * Loads an object file from disk. The seek point of fd is not preserved. 23209467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 23309467b48Spatrick * 23409467b48Spatrick * \since LTO_API_VERSION=5 23509467b48Spatrick */ 23609467b48Spatrick extern lto_module_t 23709467b48Spatrick lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, 23809467b48Spatrick size_t map_size, off_t offset); 23909467b48Spatrick 24009467b48Spatrick /** 24109467b48Spatrick * Frees all memory internally allocated by the module. 24209467b48Spatrick * Upon return the lto_module_t is no longer valid. 24309467b48Spatrick * 24409467b48Spatrick * \since prior to LTO_API_VERSION=3 24509467b48Spatrick */ 24609467b48Spatrick extern void 24709467b48Spatrick lto_module_dispose(lto_module_t mod); 24809467b48Spatrick 24909467b48Spatrick /** 25009467b48Spatrick * Returns triple string which the object module was compiled under. 25109467b48Spatrick * 25209467b48Spatrick * \since prior to LTO_API_VERSION=3 25309467b48Spatrick */ 25409467b48Spatrick extern const char* 25509467b48Spatrick lto_module_get_target_triple(lto_module_t mod); 25609467b48Spatrick 25709467b48Spatrick /** 25809467b48Spatrick * Sets triple string with which the object will be codegened. 25909467b48Spatrick * 26009467b48Spatrick * \since LTO_API_VERSION=4 26109467b48Spatrick */ 26209467b48Spatrick extern void 26309467b48Spatrick lto_module_set_target_triple(lto_module_t mod, const char *triple); 26409467b48Spatrick 26509467b48Spatrick /** 26609467b48Spatrick * Returns the number of symbols in the object module. 26709467b48Spatrick * 26809467b48Spatrick * \since prior to LTO_API_VERSION=3 26909467b48Spatrick */ 27009467b48Spatrick extern unsigned int 27109467b48Spatrick lto_module_get_num_symbols(lto_module_t mod); 27209467b48Spatrick 27309467b48Spatrick /** 27409467b48Spatrick * Returns the name of the ith symbol in the object module. 27509467b48Spatrick * 27609467b48Spatrick * \since prior to LTO_API_VERSION=3 27709467b48Spatrick */ 27809467b48Spatrick extern const char* 27909467b48Spatrick lto_module_get_symbol_name(lto_module_t mod, unsigned int index); 28009467b48Spatrick 28109467b48Spatrick /** 28209467b48Spatrick * Returns the attributes of the ith symbol in the object module. 28309467b48Spatrick * 28409467b48Spatrick * \since prior to LTO_API_VERSION=3 28509467b48Spatrick */ 28609467b48Spatrick extern lto_symbol_attributes 28709467b48Spatrick lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); 28809467b48Spatrick 28909467b48Spatrick /** 29009467b48Spatrick * Returns the module's linker options. 29109467b48Spatrick * 29209467b48Spatrick * The linker options may consist of multiple flags. It is the linker's 29309467b48Spatrick * responsibility to split the flags using a platform-specific mechanism. 29409467b48Spatrick * 29509467b48Spatrick * \since LTO_API_VERSION=16 29609467b48Spatrick */ 29709467b48Spatrick extern const char* 29809467b48Spatrick lto_module_get_linkeropts(lto_module_t mod); 29909467b48Spatrick 30009467b48Spatrick /** 301097a140dSpatrick * If targeting mach-o on darwin, this function gets the CPU type and subtype 302097a140dSpatrick * that will end up being encoded in the mach-o header. These are the values 303097a140dSpatrick * that can be found in mach/machine.h. 304097a140dSpatrick * 305097a140dSpatrick * \p out_cputype and \p out_cpusubtype must be non-NULL. 306097a140dSpatrick * 307097a140dSpatrick * Returns true on error (check lto_get_error_message() for details). 308097a140dSpatrick * 309097a140dSpatrick * \since LTO_API_VERSION=27 310097a140dSpatrick */ 311097a140dSpatrick extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod, 312097a140dSpatrick unsigned int *out_cputype, 313097a140dSpatrick unsigned int *out_cpusubtype); 314097a140dSpatrick 315097a140dSpatrick /** 316*d415bd75Srobert * This function can be used by the linker to check if a given module has 317*d415bd75Srobert * any constructor or destructor functions. 318*d415bd75Srobert * 319*d415bd75Srobert * Returns true if the module has either the @llvm.global_ctors or the 320*d415bd75Srobert * @llvm.global_dtors symbol. Otherwise returns false. 321*d415bd75Srobert * 322*d415bd75Srobert * \since LTO_API_VERSION=29 323*d415bd75Srobert */ 324*d415bd75Srobert extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod); 325*d415bd75Srobert /** 32609467b48Spatrick * Diagnostic severity. 32709467b48Spatrick * 32809467b48Spatrick * \since LTO_API_VERSION=7 32909467b48Spatrick */ 33009467b48Spatrick typedef enum { 33109467b48Spatrick LTO_DS_ERROR = 0, 33209467b48Spatrick LTO_DS_WARNING = 1, 33309467b48Spatrick LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10. 33409467b48Spatrick LTO_DS_NOTE = 2 33509467b48Spatrick } lto_codegen_diagnostic_severity_t; 33609467b48Spatrick 33709467b48Spatrick /** 33809467b48Spatrick * Diagnostic handler type. 33909467b48Spatrick * \p severity defines the severity. 34009467b48Spatrick * \p diag is the actual diagnostic. 34109467b48Spatrick * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '. 34209467b48Spatrick * \p ctxt is used to pass the context set with the diagnostic handler. 34309467b48Spatrick * 34409467b48Spatrick * \since LTO_API_VERSION=7 34509467b48Spatrick */ 34609467b48Spatrick typedef void (*lto_diagnostic_handler_t)( 34709467b48Spatrick lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt); 34809467b48Spatrick 34909467b48Spatrick /** 35009467b48Spatrick * Set a diagnostic handler and the related context (void *). 35109467b48Spatrick * This is more general than lto_get_error_message, as the diagnostic handler 35209467b48Spatrick * can be called at anytime within lto. 35309467b48Spatrick * 35409467b48Spatrick * \since LTO_API_VERSION=7 35509467b48Spatrick */ 35609467b48Spatrick extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t, 35709467b48Spatrick lto_diagnostic_handler_t, 35809467b48Spatrick void *); 35909467b48Spatrick 36009467b48Spatrick /** 36109467b48Spatrick * Instantiates a code generator. 36209467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 36309467b48Spatrick * 36409467b48Spatrick * All modules added using \a lto_codegen_add_module() must have been created 36509467b48Spatrick * in the same context as the codegen. 36609467b48Spatrick * 36709467b48Spatrick * \since prior to LTO_API_VERSION=3 36809467b48Spatrick */ 36909467b48Spatrick extern lto_code_gen_t 37009467b48Spatrick lto_codegen_create(void); 37109467b48Spatrick 37209467b48Spatrick /** 37309467b48Spatrick * Instantiate a code generator in its own context. 37409467b48Spatrick * 37509467b48Spatrick * Instantiates a code generator in its own context. Modules added via \a 37609467b48Spatrick * lto_codegen_add_module() must have all been created in the same context, 37709467b48Spatrick * using \a lto_module_create_in_codegen_context(). 37809467b48Spatrick * 37909467b48Spatrick * \since LTO_API_VERSION=11 38009467b48Spatrick */ 38109467b48Spatrick extern lto_code_gen_t 38209467b48Spatrick lto_codegen_create_in_local_context(void); 38309467b48Spatrick 38409467b48Spatrick /** 38509467b48Spatrick * Frees all code generator and all memory it internally allocated. 38609467b48Spatrick * Upon return the lto_code_gen_t is no longer valid. 38709467b48Spatrick * 38809467b48Spatrick * \since prior to LTO_API_VERSION=3 38909467b48Spatrick */ 39009467b48Spatrick extern void 39109467b48Spatrick lto_codegen_dispose(lto_code_gen_t); 39209467b48Spatrick 39309467b48Spatrick /** 39409467b48Spatrick * Add an object module to the set of modules for which code will be generated. 39509467b48Spatrick * Returns true on error (check lto_get_error_message() for details). 39609467b48Spatrick * 39709467b48Spatrick * \c cg and \c mod must both be in the same context. See \a 39809467b48Spatrick * lto_codegen_create_in_local_context() and \a 39909467b48Spatrick * lto_module_create_in_codegen_context(). 40009467b48Spatrick * 40109467b48Spatrick * \since prior to LTO_API_VERSION=3 40209467b48Spatrick */ 40309467b48Spatrick extern lto_bool_t 40409467b48Spatrick lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); 40509467b48Spatrick 40609467b48Spatrick /** 40709467b48Spatrick * Sets the object module for code generation. This will transfer the ownership 40809467b48Spatrick * of the module to the code generator. 40909467b48Spatrick * 41009467b48Spatrick * \c cg and \c mod must both be in the same context. 41109467b48Spatrick * 41209467b48Spatrick * \since LTO_API_VERSION=13 41309467b48Spatrick */ 41409467b48Spatrick extern void 41509467b48Spatrick lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod); 41609467b48Spatrick 41709467b48Spatrick /** 41809467b48Spatrick * Sets if debug info should be generated. 41909467b48Spatrick * Returns true on error (check lto_get_error_message() for details). 42009467b48Spatrick * 42109467b48Spatrick * \since prior to LTO_API_VERSION=3 42209467b48Spatrick */ 42309467b48Spatrick extern lto_bool_t 42409467b48Spatrick lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); 42509467b48Spatrick 42609467b48Spatrick /** 42709467b48Spatrick * Sets which PIC code model to generated. 42809467b48Spatrick * Returns true on error (check lto_get_error_message() for details). 42909467b48Spatrick * 43009467b48Spatrick * \since prior to LTO_API_VERSION=3 43109467b48Spatrick */ 43209467b48Spatrick extern lto_bool_t 43309467b48Spatrick lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); 43409467b48Spatrick 43509467b48Spatrick /** 43609467b48Spatrick * Sets the cpu to generate code for. 43709467b48Spatrick * 43809467b48Spatrick * \since LTO_API_VERSION=4 43909467b48Spatrick */ 44009467b48Spatrick extern void 44109467b48Spatrick lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); 44209467b48Spatrick 44309467b48Spatrick /** 44409467b48Spatrick * Sets the location of the assembler tool to run. If not set, libLTO 44509467b48Spatrick * will use gcc to invoke the assembler. 44609467b48Spatrick * 44709467b48Spatrick * \since LTO_API_VERSION=3 44809467b48Spatrick */ 44909467b48Spatrick extern void 45009467b48Spatrick lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); 45109467b48Spatrick 45209467b48Spatrick /** 45309467b48Spatrick * Sets extra arguments that libLTO should pass to the assembler. 45409467b48Spatrick * 45509467b48Spatrick * \since LTO_API_VERSION=4 45609467b48Spatrick */ 45709467b48Spatrick extern void 45809467b48Spatrick lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, 45909467b48Spatrick int nargs); 46009467b48Spatrick 46109467b48Spatrick /** 46209467b48Spatrick * Adds to a list of all global symbols that must exist in the final generated 46309467b48Spatrick * code. If a function is not listed there, it might be inlined into every usage 46409467b48Spatrick * and optimized away. 46509467b48Spatrick * 46609467b48Spatrick * \since prior to LTO_API_VERSION=3 46709467b48Spatrick */ 46809467b48Spatrick extern void 46909467b48Spatrick lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); 47009467b48Spatrick 47109467b48Spatrick /** 47209467b48Spatrick * Writes a new object file at the specified path that contains the 47309467b48Spatrick * merged contents of all modules added so far. 47409467b48Spatrick * Returns true on error (check lto_get_error_message() for details). 47509467b48Spatrick * 47609467b48Spatrick * \since LTO_API_VERSION=5 47709467b48Spatrick */ 47809467b48Spatrick extern lto_bool_t 47909467b48Spatrick lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); 48009467b48Spatrick 48109467b48Spatrick /** 48209467b48Spatrick * Generates code for all added modules into one native object file. 48309467b48Spatrick * This calls lto_codegen_optimize then lto_codegen_compile_optimized. 48409467b48Spatrick * 48509467b48Spatrick * On success returns a pointer to a generated mach-o/ELF buffer and 48609467b48Spatrick * length set to the buffer size. The buffer is owned by the 48709467b48Spatrick * lto_code_gen_t and will be freed when lto_codegen_dispose() 48809467b48Spatrick * is called, or lto_codegen_compile() is called again. 48909467b48Spatrick * On failure, returns NULL (check lto_get_error_message() for details). 49009467b48Spatrick * 49109467b48Spatrick * \since prior to LTO_API_VERSION=3 49209467b48Spatrick */ 49309467b48Spatrick extern const void* 49409467b48Spatrick lto_codegen_compile(lto_code_gen_t cg, size_t* length); 49509467b48Spatrick 49609467b48Spatrick /** 49709467b48Spatrick * Generates code for all added modules into one native object file. 49809467b48Spatrick * This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead 49909467b48Spatrick * of returning a generated mach-o/ELF buffer, it writes to a file). 50009467b48Spatrick * 50109467b48Spatrick * The name of the file is written to name. Returns true on error. 50209467b48Spatrick * 50309467b48Spatrick * \since LTO_API_VERSION=5 50409467b48Spatrick */ 50509467b48Spatrick extern lto_bool_t 50609467b48Spatrick lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); 50709467b48Spatrick 50809467b48Spatrick /** 50909467b48Spatrick * Runs optimization for the merged module. Returns true on error. 51009467b48Spatrick * 51109467b48Spatrick * \since LTO_API_VERSION=12 51209467b48Spatrick */ 51309467b48Spatrick extern lto_bool_t 51409467b48Spatrick lto_codegen_optimize(lto_code_gen_t cg); 51509467b48Spatrick 51609467b48Spatrick /** 51709467b48Spatrick * Generates code for the optimized merged module into one native object file. 51809467b48Spatrick * It will not run any IR optimizations on the merged module. 51909467b48Spatrick * 52009467b48Spatrick * On success returns a pointer to a generated mach-o/ELF buffer and length set 52109467b48Spatrick * to the buffer size. The buffer is owned by the lto_code_gen_t and will be 52209467b48Spatrick * freed when lto_codegen_dispose() is called, or 52309467b48Spatrick * lto_codegen_compile_optimized() is called again. On failure, returns NULL 52409467b48Spatrick * (check lto_get_error_message() for details). 52509467b48Spatrick * 52609467b48Spatrick * \since LTO_API_VERSION=12 52709467b48Spatrick */ 52809467b48Spatrick extern const void* 52909467b48Spatrick lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length); 53009467b48Spatrick 53109467b48Spatrick /** 53209467b48Spatrick * Returns the runtime API version. 53309467b48Spatrick * 53409467b48Spatrick * \since LTO_API_VERSION=12 53509467b48Spatrick */ 53609467b48Spatrick extern unsigned int 53709467b48Spatrick lto_api_version(void); 53809467b48Spatrick 53909467b48Spatrick /** 54073471bf0Spatrick * Parses options immediately, making them available as early as possible. For 54173471bf0Spatrick * example during executing codegen::InitTargetOptionsFromCodeGenFlags. Since 54273471bf0Spatrick * parsing shud only happen once, only one of lto_codegen_debug_options or 54373471bf0Spatrick * lto_set_debug_options should be called. 54473471bf0Spatrick * 54573471bf0Spatrick * This function takes one or more options separated by spaces. 54673471bf0Spatrick * Warning: passing file paths through this function may confuse the argument 54773471bf0Spatrick * parser if the paths contain spaces. 54873471bf0Spatrick * 54973471bf0Spatrick * \since LTO_API_VERSION=28 55073471bf0Spatrick */ 55173471bf0Spatrick extern void lto_set_debug_options(const char *const *options, int number); 55273471bf0Spatrick 55373471bf0Spatrick /** 55473471bf0Spatrick * Sets options to help debug codegen bugs. Since parsing shud only happen once, 55573471bf0Spatrick * only one of lto_codegen_debug_options or lto_set_debug_options 55673471bf0Spatrick * should be called. 55709467b48Spatrick * 55809467b48Spatrick * This function takes one or more options separated by spaces. 55909467b48Spatrick * Warning: passing file paths through this function may confuse the argument 56009467b48Spatrick * parser if the paths contain spaces. 56109467b48Spatrick * 56209467b48Spatrick * \since prior to LTO_API_VERSION=3 56309467b48Spatrick */ 56409467b48Spatrick extern void 56509467b48Spatrick lto_codegen_debug_options(lto_code_gen_t cg, const char *); 56609467b48Spatrick 56709467b48Spatrick /** 56809467b48Spatrick * Same as the previous function, but takes every option separately through an 56909467b48Spatrick * array. 57009467b48Spatrick * 57109467b48Spatrick * \since prior to LTO_API_VERSION=26 57209467b48Spatrick */ 57309467b48Spatrick extern void lto_codegen_debug_options_array(lto_code_gen_t cg, 57409467b48Spatrick const char *const *, int number); 57509467b48Spatrick 57609467b48Spatrick /** 57709467b48Spatrick * Initializes LLVM disassemblers. 57809467b48Spatrick * FIXME: This doesn't really belong here. 57909467b48Spatrick * 58009467b48Spatrick * \since LTO_API_VERSION=5 58109467b48Spatrick */ 58209467b48Spatrick extern void 58309467b48Spatrick lto_initialize_disassembler(void); 58409467b48Spatrick 58509467b48Spatrick /** 58609467b48Spatrick * Sets if we should run internalize pass during optimization and code 58709467b48Spatrick * generation. 58809467b48Spatrick * 58909467b48Spatrick * \since LTO_API_VERSION=14 59009467b48Spatrick */ 59109467b48Spatrick extern void 59209467b48Spatrick lto_codegen_set_should_internalize(lto_code_gen_t cg, 59309467b48Spatrick lto_bool_t ShouldInternalize); 59409467b48Spatrick 59509467b48Spatrick /** 59609467b48Spatrick * Set whether to embed uselists in bitcode. 59709467b48Spatrick * 59809467b48Spatrick * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in 59909467b48Spatrick * output bitcode. This should be turned on for all -save-temps output. 60009467b48Spatrick * 60109467b48Spatrick * \since LTO_API_VERSION=15 60209467b48Spatrick */ 60309467b48Spatrick extern void 60409467b48Spatrick lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, 60509467b48Spatrick lto_bool_t ShouldEmbedUselists); 60609467b48Spatrick 60709467b48Spatrick /** Opaque reference to an LTO input file */ 60809467b48Spatrick typedef struct LLVMOpaqueLTOInput *lto_input_t; 60909467b48Spatrick 61009467b48Spatrick /** 61109467b48Spatrick * Creates an LTO input file from a buffer. The path 61209467b48Spatrick * argument is used for diagnotics as this function 61309467b48Spatrick * otherwise does not know which file the given buffer 61409467b48Spatrick * is associated with. 61509467b48Spatrick * 61609467b48Spatrick * \since LTO_API_VERSION=24 61709467b48Spatrick */ 61809467b48Spatrick extern lto_input_t lto_input_create(const void *buffer, 61909467b48Spatrick size_t buffer_size, 62009467b48Spatrick const char *path); 62109467b48Spatrick 62209467b48Spatrick /** 62309467b48Spatrick * Frees all memory internally allocated by the LTO input file. 62409467b48Spatrick * Upon return the lto_module_t is no longer valid. 62509467b48Spatrick * 62609467b48Spatrick * \since LTO_API_VERSION=24 62709467b48Spatrick */ 62809467b48Spatrick extern void lto_input_dispose(lto_input_t input); 62909467b48Spatrick 63009467b48Spatrick /** 63109467b48Spatrick * Returns the number of dependent library specifiers 63209467b48Spatrick * for the given LTO input file. 63309467b48Spatrick * 63409467b48Spatrick * \since LTO_API_VERSION=24 63509467b48Spatrick */ 63609467b48Spatrick extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input); 63709467b48Spatrick 63809467b48Spatrick /** 63909467b48Spatrick * Returns the ith dependent library specifier 64009467b48Spatrick * for the given LTO input file. The returned 64109467b48Spatrick * string is not null-terminated. 64209467b48Spatrick * 64309467b48Spatrick * \since LTO_API_VERSION=24 64409467b48Spatrick */ 64509467b48Spatrick extern const char * lto_input_get_dependent_library(lto_input_t input, 64609467b48Spatrick size_t index, 64709467b48Spatrick size_t *size); 64809467b48Spatrick 64909467b48Spatrick /** 65009467b48Spatrick * Returns the list of libcall symbols that can be generated by LTO 65109467b48Spatrick * that might not be visible from the symbol table of bitcode files. 65209467b48Spatrick * 65309467b48Spatrick * \since prior to LTO_API_VERSION=25 65409467b48Spatrick */ 65509467b48Spatrick extern const char *const *lto_runtime_lib_symbols_list(size_t *size); 65609467b48Spatrick 65709467b48Spatrick /** 65809467b48Spatrick * @} // endgoup LLVMCLTO 65909467b48Spatrick * @defgroup LLVMCTLTO ThinLTO 66009467b48Spatrick * @ingroup LLVMC 66109467b48Spatrick * 66209467b48Spatrick * @{ 66309467b48Spatrick */ 66409467b48Spatrick 66509467b48Spatrick /** 66609467b48Spatrick * Type to wrap a single object returned by ThinLTO. 66709467b48Spatrick * 66809467b48Spatrick * \since LTO_API_VERSION=18 66909467b48Spatrick */ 67009467b48Spatrick typedef struct { 67109467b48Spatrick const char *Buffer; 67209467b48Spatrick size_t Size; 67309467b48Spatrick } LTOObjectBuffer; 67409467b48Spatrick 67509467b48Spatrick /** 67609467b48Spatrick * Instantiates a ThinLTO code generator. 67709467b48Spatrick * Returns NULL on error (check lto_get_error_message() for details). 67809467b48Spatrick * 67909467b48Spatrick * 68009467b48Spatrick * The ThinLTOCodeGenerator is not intended to be reuse for multiple 68109467b48Spatrick * compilation: the model is that the client adds modules to the generator and 68209467b48Spatrick * ask to perform the ThinLTO optimizations / codegen, and finally destroys the 68309467b48Spatrick * codegenerator. 68409467b48Spatrick * 68509467b48Spatrick * \since LTO_API_VERSION=18 68609467b48Spatrick */ 68709467b48Spatrick extern thinlto_code_gen_t thinlto_create_codegen(void); 68809467b48Spatrick 68909467b48Spatrick /** 69009467b48Spatrick * Frees the generator and all memory it internally allocated. 69109467b48Spatrick * Upon return the thinlto_code_gen_t is no longer valid. 69209467b48Spatrick * 69309467b48Spatrick * \since LTO_API_VERSION=18 69409467b48Spatrick */ 69509467b48Spatrick extern void thinlto_codegen_dispose(thinlto_code_gen_t cg); 69609467b48Spatrick 69709467b48Spatrick /** 69809467b48Spatrick * Add a module to a ThinLTO code generator. Identifier has to be unique among 69909467b48Spatrick * all the modules in a code generator. The data buffer stays owned by the 70009467b48Spatrick * client, and is expected to be available for the entire lifetime of the 70109467b48Spatrick * thinlto_code_gen_t it is added to. 70209467b48Spatrick * 70309467b48Spatrick * On failure, returns NULL (check lto_get_error_message() for details). 70409467b48Spatrick * 70509467b48Spatrick * 70609467b48Spatrick * \since LTO_API_VERSION=18 70709467b48Spatrick */ 70809467b48Spatrick extern void thinlto_codegen_add_module(thinlto_code_gen_t cg, 70909467b48Spatrick const char *identifier, const char *data, 71009467b48Spatrick int length); 71109467b48Spatrick 71209467b48Spatrick /** 71309467b48Spatrick * Optimize and codegen all the modules added to the codegenerator using 71409467b48Spatrick * ThinLTO. Resulting objects are accessible using thinlto_module_get_object(). 71509467b48Spatrick * 71609467b48Spatrick * \since LTO_API_VERSION=18 71709467b48Spatrick */ 71809467b48Spatrick extern void thinlto_codegen_process(thinlto_code_gen_t cg); 71909467b48Spatrick 72009467b48Spatrick /** 72109467b48Spatrick * Returns the number of object files produced by the ThinLTO CodeGenerator. 72209467b48Spatrick * 72309467b48Spatrick * It usually matches the number of input files, but this is not a guarantee of 72409467b48Spatrick * the API and may change in future implementation, so the client should not 72509467b48Spatrick * assume it. 72609467b48Spatrick * 72709467b48Spatrick * \since LTO_API_VERSION=18 72809467b48Spatrick */ 72909467b48Spatrick extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg); 73009467b48Spatrick 73109467b48Spatrick /** 73209467b48Spatrick * Returns a reference to the ith object file produced by the ThinLTO 73309467b48Spatrick * CodeGenerator. 73409467b48Spatrick * 73509467b48Spatrick * Client should use \p thinlto_module_get_num_objects() to get the number of 73609467b48Spatrick * available objects. 73709467b48Spatrick * 73809467b48Spatrick * \since LTO_API_VERSION=18 73909467b48Spatrick */ 74009467b48Spatrick extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg, 74109467b48Spatrick unsigned int index); 74209467b48Spatrick 74309467b48Spatrick /** 74409467b48Spatrick * Returns the number of object files produced by the ThinLTO CodeGenerator. 74509467b48Spatrick * 74609467b48Spatrick * It usually matches the number of input files, but this is not a guarantee of 74709467b48Spatrick * the API and may change in future implementation, so the client should not 74809467b48Spatrick * assume it. 74909467b48Spatrick * 75009467b48Spatrick * \since LTO_API_VERSION=21 75109467b48Spatrick */ 75209467b48Spatrick unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg); 75309467b48Spatrick 75409467b48Spatrick /** 75509467b48Spatrick * Returns the path to the ith object file produced by the ThinLTO 75609467b48Spatrick * CodeGenerator. 75709467b48Spatrick * 75809467b48Spatrick * Client should use \p thinlto_module_get_num_object_files() to get the number 75909467b48Spatrick * of available objects. 76009467b48Spatrick * 76109467b48Spatrick * \since LTO_API_VERSION=21 76209467b48Spatrick */ 76309467b48Spatrick const char *thinlto_module_get_object_file(thinlto_code_gen_t cg, 76409467b48Spatrick unsigned int index); 76509467b48Spatrick 76609467b48Spatrick /** 76709467b48Spatrick * Sets which PIC code model to generate. 76809467b48Spatrick * Returns true on error (check lto_get_error_message() for details). 76909467b48Spatrick * 77009467b48Spatrick * \since LTO_API_VERSION=18 77109467b48Spatrick */ 77209467b48Spatrick extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, 77309467b48Spatrick lto_codegen_model); 77409467b48Spatrick 77509467b48Spatrick /** 77609467b48Spatrick * Sets the path to a directory to use as a storage for temporary bitcode files. 77709467b48Spatrick * The intention is to make the bitcode files available for debugging at various 77809467b48Spatrick * stage of the pipeline. 77909467b48Spatrick * 78009467b48Spatrick * \since LTO_API_VERSION=18 78109467b48Spatrick */ 78209467b48Spatrick extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, 78309467b48Spatrick const char *save_temps_dir); 78409467b48Spatrick 78509467b48Spatrick /** 78609467b48Spatrick * Set the path to a directory where to save generated object files. This 78709467b48Spatrick * path can be used by a linker to request on-disk files instead of in-memory 78809467b48Spatrick * buffers. When set, results are available through 78909467b48Spatrick * thinlto_module_get_object_file() instead of thinlto_module_get_object(). 79009467b48Spatrick * 79109467b48Spatrick * \since LTO_API_VERSION=21 79209467b48Spatrick */ 79309467b48Spatrick void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg, 79409467b48Spatrick const char *save_temps_dir); 79509467b48Spatrick 79609467b48Spatrick /** 79709467b48Spatrick * Sets the cpu to generate code for. 79809467b48Spatrick * 79909467b48Spatrick * \since LTO_API_VERSION=18 80009467b48Spatrick */ 80109467b48Spatrick extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu); 80209467b48Spatrick 80309467b48Spatrick /** 80409467b48Spatrick * Disable CodeGen, only run the stages till codegen and stop. The output will 80509467b48Spatrick * be bitcode. 80609467b48Spatrick * 80709467b48Spatrick * \since LTO_API_VERSION=19 80809467b48Spatrick */ 80909467b48Spatrick extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg, 81009467b48Spatrick lto_bool_t disable); 81109467b48Spatrick 81209467b48Spatrick /** 81309467b48Spatrick * Perform CodeGen only: disable all other stages. 81409467b48Spatrick * 81509467b48Spatrick * \since LTO_API_VERSION=19 81609467b48Spatrick */ 81709467b48Spatrick extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg, 81809467b48Spatrick lto_bool_t codegen_only); 81909467b48Spatrick 82009467b48Spatrick /** 82109467b48Spatrick * Parse -mllvm style debug options. 82209467b48Spatrick * 82309467b48Spatrick * \since LTO_API_VERSION=18 82409467b48Spatrick */ 82509467b48Spatrick extern void thinlto_debug_options(const char *const *options, int number); 82609467b48Spatrick 82709467b48Spatrick /** 82809467b48Spatrick * Test if a module has support for ThinLTO linking. 82909467b48Spatrick * 83009467b48Spatrick * \since LTO_API_VERSION=18 83109467b48Spatrick */ 83209467b48Spatrick extern lto_bool_t lto_module_is_thinlto(lto_module_t mod); 83309467b48Spatrick 83409467b48Spatrick /** 83509467b48Spatrick * Adds a symbol to the list of global symbols that must exist in the final 83609467b48Spatrick * generated code. If a function is not listed there, it might be inlined into 83709467b48Spatrick * every usage and optimized away. For every single module, the functions 83809467b48Spatrick * referenced from code outside of the ThinLTO modules need to be added here. 83909467b48Spatrick * 84009467b48Spatrick * \since LTO_API_VERSION=18 84109467b48Spatrick */ 84209467b48Spatrick extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg, 84309467b48Spatrick const char *name, 84409467b48Spatrick int length); 84509467b48Spatrick 84609467b48Spatrick /** 84709467b48Spatrick * Adds a symbol to the list of global symbols that are cross-referenced between 84809467b48Spatrick * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every 84909467b48Spatrick * references from a ThinLTO module to this symbol is optimized away, then 85009467b48Spatrick * the symbol can be discarded. 85109467b48Spatrick * 85209467b48Spatrick * \since LTO_API_VERSION=18 85309467b48Spatrick */ 85409467b48Spatrick extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg, 85509467b48Spatrick const char *name, 85609467b48Spatrick int length); 85709467b48Spatrick 85809467b48Spatrick /** 85909467b48Spatrick * @} // endgoup LLVMCTLTO 86009467b48Spatrick * @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control 86109467b48Spatrick * @ingroup LLVMCTLTO 86209467b48Spatrick * 86309467b48Spatrick * These entry points control the ThinLTO cache. The cache is intended to 86409467b48Spatrick * support incremental builds, and thus needs to be persistent across builds. 86509467b48Spatrick * The client enables the cache by supplying a path to an existing directory. 86609467b48Spatrick * The code generator will use this to store objects files that may be reused 86709467b48Spatrick * during a subsequent build. 86809467b48Spatrick * To avoid filling the disk space, a few knobs are provided: 86909467b48Spatrick * - The pruning interval limits the frequency at which the garbage collector 87009467b48Spatrick * will try to scan the cache directory to prune expired entries. 87109467b48Spatrick * Setting to a negative number disables the pruning. 87209467b48Spatrick * - The pruning expiration time indicates to the garbage collector how old an 87309467b48Spatrick * entry needs to be to be removed. 87409467b48Spatrick * - Finally, the garbage collector can be instructed to prune the cache until 87509467b48Spatrick * the occupied space goes below a threshold. 87609467b48Spatrick * @{ 87709467b48Spatrick */ 87809467b48Spatrick 87909467b48Spatrick /** 88009467b48Spatrick * Sets the path to a directory to use as a cache storage for incremental build. 88109467b48Spatrick * Setting this activates caching. 88209467b48Spatrick * 88309467b48Spatrick * \since LTO_API_VERSION=18 88409467b48Spatrick */ 88509467b48Spatrick extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg, 88609467b48Spatrick const char *cache_dir); 88709467b48Spatrick 88809467b48Spatrick /** 88909467b48Spatrick * Sets the cache pruning interval (in seconds). A negative value disables the 89009467b48Spatrick * pruning. An unspecified default value will be applied, and a value of 0 will 89109467b48Spatrick * force prunning to occur. 89209467b48Spatrick * 89309467b48Spatrick * \since LTO_API_VERSION=18 89409467b48Spatrick */ 89509467b48Spatrick extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg, 89609467b48Spatrick int interval); 89709467b48Spatrick 89809467b48Spatrick /** 89909467b48Spatrick * Sets the maximum cache size that can be persistent across build, in terms of 90009467b48Spatrick * percentage of the available space on the disk. Set to 100 to indicate 90109467b48Spatrick * no limit, 50 to indicate that the cache size will not be left over half the 90209467b48Spatrick * available space. A value over 100 will be reduced to 100, a value of 0 will 90309467b48Spatrick * be ignored. An unspecified default value will be applied. 90409467b48Spatrick * 90509467b48Spatrick * The formula looks like: 90609467b48Spatrick * AvailableSpace = FreeSpace + ExistingCacheSize 90709467b48Spatrick * NewCacheSize = AvailableSpace * P/100 90809467b48Spatrick * 90909467b48Spatrick * \since LTO_API_VERSION=18 91009467b48Spatrick */ 91109467b48Spatrick extern void thinlto_codegen_set_final_cache_size_relative_to_available_space( 91209467b48Spatrick thinlto_code_gen_t cg, unsigned percentage); 91309467b48Spatrick 91409467b48Spatrick /** 91509467b48Spatrick * Sets the expiration (in seconds) for an entry in the cache. An unspecified 91609467b48Spatrick * default value will be applied. A value of 0 will be ignored. 91709467b48Spatrick * 91809467b48Spatrick * \since LTO_API_VERSION=18 91909467b48Spatrick */ 92009467b48Spatrick extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, 92109467b48Spatrick unsigned expiration); 92209467b48Spatrick 92309467b48Spatrick /** 92409467b48Spatrick * Sets the maximum size of the cache directory (in bytes). A value over the 92509467b48Spatrick * amount of available space on the disk will be reduced to the amount of 92609467b48Spatrick * available space. An unspecified default value will be applied. A value of 0 92709467b48Spatrick * will be ignored. 92809467b48Spatrick * 92909467b48Spatrick * \since LTO_API_VERSION=22 93009467b48Spatrick */ 93109467b48Spatrick extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg, 93209467b48Spatrick unsigned max_size_bytes); 93309467b48Spatrick 93409467b48Spatrick /** 93509467b48Spatrick * Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in 93609467b48Spatrick * megabytes (2^20 bytes). 93709467b48Spatrick * 93809467b48Spatrick * \since LTO_API_VERSION=23 93909467b48Spatrick */ 94009467b48Spatrick extern void 94109467b48Spatrick thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg, 94209467b48Spatrick unsigned max_size_megabytes); 94309467b48Spatrick 94409467b48Spatrick /** 94509467b48Spatrick * Sets the maximum number of files in the cache directory. An unspecified 94609467b48Spatrick * default value will be applied. A value of 0 will be ignored. 94709467b48Spatrick * 94809467b48Spatrick * \since LTO_API_VERSION=22 94909467b48Spatrick */ 95009467b48Spatrick extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg, 95109467b48Spatrick unsigned max_size_files); 95209467b48Spatrick 95309467b48Spatrick /** 95409467b48Spatrick * @} // endgroup LLVMCTLTO_CACHING 95509467b48Spatrick */ 95609467b48Spatrick 95709467b48Spatrick LLVM_C_EXTERN_C_END 95809467b48Spatrick 95909467b48Spatrick #endif /* LLVM_C_LTO_H */ 960