Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/lto.h
35233 views
/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header provides public interface to an abstract link time optimization*|10|* library. LLVM provides an implementation of this interface for use with *|11|* llvm bitcode files. *|12|* *|13\*===----------------------------------------------------------------------===*/1415#ifndef LLVM_C_LTO_H16#define LLVM_C_LTO_H1718#include "llvm-c/ExternC.h"1920#ifdef __cplusplus21#include <cstddef>22#else23#include <stddef.h>24#endif25#include <sys/types.h>2627#ifndef __cplusplus28#if !defined(_MSC_VER)29#include <stdbool.h>30typedef bool lto_bool_t;31#else32/* MSVC in particular does not have anything like _Bool or bool in C, but we can33at least make sure the type is the same size. The implementation side will34use C++ bool. */35typedef unsigned char lto_bool_t;36#endif37#else38typedef bool lto_bool_t;39#endif4041/**42* @defgroup LLVMCLTO LTO43* @ingroup LLVMC44*45* @{46*/4748#define LTO_API_VERSION 294950/**51* \since prior to LTO_API_VERSION=352*/53typedef enum {54LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */55LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0,56LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0,57LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0,58LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080,59LTO_SYMBOL_DEFINITION_MASK = 0x00000700,60LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100,61LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200,62LTO_SYMBOL_DEFINITION_WEAK = 0x00000300,63LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400,64LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500,65LTO_SYMBOL_SCOPE_MASK = 0x00003800,66LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800,67LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000,68LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000,69LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800,70LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800,71LTO_SYMBOL_COMDAT = 0x00004000,72LTO_SYMBOL_ALIAS = 0x0000800073} lto_symbol_attributes;7475/**76* \since prior to LTO_API_VERSION=377*/78typedef enum {79LTO_DEBUG_MODEL_NONE = 0,80LTO_DEBUG_MODEL_DWARF = 181} lto_debug_model;8283/**84* \since prior to LTO_API_VERSION=385*/86typedef enum {87LTO_CODEGEN_PIC_MODEL_STATIC = 0,88LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1,89LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2,90LTO_CODEGEN_PIC_MODEL_DEFAULT = 391} lto_codegen_model;9293/** opaque reference to a loaded object module */94typedef struct LLVMOpaqueLTOModule *lto_module_t;9596/** opaque reference to a code generator */97typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t;9899/** opaque reference to a thin code generator */100typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t;101102LLVM_C_EXTERN_C_BEGIN103104/**105* Returns a printable string.106*107* \since prior to LTO_API_VERSION=3108*/109extern const char*110lto_get_version(void);111112/**113* Returns the last error string or NULL if last operation was successful.114*115* \since prior to LTO_API_VERSION=3116*/117extern const char*118lto_get_error_message(void);119120/**121* Checks if a file is a loadable object file.122*123* \since prior to LTO_API_VERSION=3124*/125extern lto_bool_t126lto_module_is_object_file(const char* path);127128/**129* Checks if a file is a loadable object compiled for requested target.130*131* \since prior to LTO_API_VERSION=3132*/133extern lto_bool_t134lto_module_is_object_file_for_target(const char* path,135const char* target_triple_prefix);136137/**138* Return true if \p Buffer contains a bitcode file with ObjC code (category139* or class) in it.140*141* \since LTO_API_VERSION=20142*/143extern lto_bool_t144lto_module_has_objc_category(const void *mem, size_t length);145146/**147* Checks if a buffer is a loadable object file.148*149* \since prior to LTO_API_VERSION=3150*/151extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem,152size_t length);153154/**155* Checks if a buffer is a loadable object compiled for requested target.156*157* \since prior to LTO_API_VERSION=3158*/159extern lto_bool_t160lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,161const char* target_triple_prefix);162163/**164* Loads an object file from disk.165* Returns NULL on error (check lto_get_error_message() for details).166*167* \since prior to LTO_API_VERSION=3168*/169extern lto_module_t170lto_module_create(const char* path);171172/**173* Loads an object file from memory.174* Returns NULL on error (check lto_get_error_message() for details).175*176* \since prior to LTO_API_VERSION=3177*/178extern lto_module_t179lto_module_create_from_memory(const void* mem, size_t length);180181/**182* Loads an object file from memory with an extra path argument.183* Returns NULL on error (check lto_get_error_message() for details).184*185* \since LTO_API_VERSION=9186*/187extern lto_module_t188lto_module_create_from_memory_with_path(const void* mem, size_t length,189const char *path);190191/**192* Loads an object file in its own context.193*194* Loads an object file in its own LLVMContext. This function call is195* thread-safe. However, modules created this way should not be merged into an196* lto_code_gen_t using \a lto_codegen_add_module().197*198* Returns NULL on error (check lto_get_error_message() for details).199*200* \since LTO_API_VERSION=11201*/202extern lto_module_t203lto_module_create_in_local_context(const void *mem, size_t length,204const char *path);205206/**207* Loads an object file in the codegen context.208*209* Loads an object file into the same context as \c cg. The module is safe to210* add using \a lto_codegen_add_module().211*212* Returns NULL on error (check lto_get_error_message() for details).213*214* \since LTO_API_VERSION=11215*/216extern lto_module_t217lto_module_create_in_codegen_context(const void *mem, size_t length,218const char *path, lto_code_gen_t cg);219220/**221* Loads an object file from disk. The seek point of fd is not preserved.222* Returns NULL on error (check lto_get_error_message() for details).223*224* \since LTO_API_VERSION=5225*/226extern lto_module_t227lto_module_create_from_fd(int fd, const char *path, size_t file_size);228229/**230* Loads an object file from disk. The seek point of fd is not preserved.231* Returns NULL on error (check lto_get_error_message() for details).232*233* \since LTO_API_VERSION=5234*/235extern lto_module_t236lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,237size_t map_size, off_t offset);238239/**240* Frees all memory internally allocated by the module.241* Upon return the lto_module_t is no longer valid.242*243* \since prior to LTO_API_VERSION=3244*/245extern void246lto_module_dispose(lto_module_t mod);247248/**249* Returns triple string which the object module was compiled under.250*251* \since prior to LTO_API_VERSION=3252*/253extern const char*254lto_module_get_target_triple(lto_module_t mod);255256/**257* Sets triple string with which the object will be codegened.258*259* \since LTO_API_VERSION=4260*/261extern void262lto_module_set_target_triple(lto_module_t mod, const char *triple);263264/**265* Returns the number of symbols in the object module.266*267* \since prior to LTO_API_VERSION=3268*/269extern unsigned int270lto_module_get_num_symbols(lto_module_t mod);271272/**273* Returns the name of the ith symbol in the object module.274*275* \since prior to LTO_API_VERSION=3276*/277extern const char*278lto_module_get_symbol_name(lto_module_t mod, unsigned int index);279280/**281* Returns the attributes of the ith symbol in the object module.282*283* \since prior to LTO_API_VERSION=3284*/285extern lto_symbol_attributes286lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);287288/**289* Returns the module's linker options.290*291* The linker options may consist of multiple flags. It is the linker's292* responsibility to split the flags using a platform-specific mechanism.293*294* \since LTO_API_VERSION=16295*/296extern const char*297lto_module_get_linkeropts(lto_module_t mod);298299/**300* If targeting mach-o on darwin, this function gets the CPU type and subtype301* that will end up being encoded in the mach-o header. These are the values302* that can be found in mach/machine.h.303*304* \p out_cputype and \p out_cpusubtype must be non-NULL.305*306* Returns true on error (check lto_get_error_message() for details).307*308* \since LTO_API_VERSION=27309*/310extern lto_bool_t lto_module_get_macho_cputype(lto_module_t mod,311unsigned int *out_cputype,312unsigned int *out_cpusubtype);313314/**315* This function can be used by the linker to check if a given module has316* any constructor or destructor functions.317*318* Returns true if the module has either the @llvm.global_ctors or the319* @llvm.global_dtors symbol. Otherwise returns false.320*321* \since LTO_API_VERSION=29322*/323extern lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod);324/**325* Diagnostic severity.326*327* \since LTO_API_VERSION=7328*/329typedef enum {330LTO_DS_ERROR = 0,331LTO_DS_WARNING = 1,332LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10.333LTO_DS_NOTE = 2334} lto_codegen_diagnostic_severity_t;335336/**337* Diagnostic handler type.338* \p severity defines the severity.339* \p diag is the actual diagnostic.340* The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '.341* \p ctxt is used to pass the context set with the diagnostic handler.342*343* \since LTO_API_VERSION=7344*/345typedef void (*lto_diagnostic_handler_t)(346lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt);347348/**349* Set a diagnostic handler and the related context (void *).350* This is more general than lto_get_error_message, as the diagnostic handler351* can be called at anytime within lto.352*353* \since LTO_API_VERSION=7354*/355extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t,356lto_diagnostic_handler_t,357void *);358359/**360* Instantiates a code generator.361* Returns NULL on error (check lto_get_error_message() for details).362*363* All modules added using \a lto_codegen_add_module() must have been created364* in the same context as the codegen.365*366* \since prior to LTO_API_VERSION=3367*/368extern lto_code_gen_t369lto_codegen_create(void);370371/**372* Instantiate a code generator in its own context.373*374* Instantiates a code generator in its own context. Modules added via \a375* lto_codegen_add_module() must have all been created in the same context,376* using \a lto_module_create_in_codegen_context().377*378* \since LTO_API_VERSION=11379*/380extern lto_code_gen_t381lto_codegen_create_in_local_context(void);382383/**384* Frees all code generator and all memory it internally allocated.385* Upon return the lto_code_gen_t is no longer valid.386*387* \since prior to LTO_API_VERSION=3388*/389extern void390lto_codegen_dispose(lto_code_gen_t);391392/**393* Add an object module to the set of modules for which code will be generated.394* Returns true on error (check lto_get_error_message() for details).395*396* \c cg and \c mod must both be in the same context. See \a397* lto_codegen_create_in_local_context() and \a398* lto_module_create_in_codegen_context().399*400* \since prior to LTO_API_VERSION=3401*/402extern lto_bool_t403lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);404405/**406* Sets the object module for code generation. This will transfer the ownership407* of the module to the code generator.408*409* \c cg and \c mod must both be in the same context.410*411* \since LTO_API_VERSION=13412*/413extern void414lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod);415416/**417* Sets if debug info should be generated.418* Returns true on error (check lto_get_error_message() for details).419*420* \since prior to LTO_API_VERSION=3421*/422extern lto_bool_t423lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);424425/**426* Sets which PIC code model to generated.427* Returns true on error (check lto_get_error_message() for details).428*429* \since prior to LTO_API_VERSION=3430*/431extern lto_bool_t432lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);433434/**435* Sets the cpu to generate code for.436*437* \since LTO_API_VERSION=4438*/439extern void440lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);441442/**443* Sets the location of the assembler tool to run. If not set, libLTO444* will use gcc to invoke the assembler.445*446* \since LTO_API_VERSION=3447*/448extern void449lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);450451/**452* Sets extra arguments that libLTO should pass to the assembler.453*454* \since LTO_API_VERSION=4455*/456extern void457lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,458int nargs);459460/**461* Adds to a list of all global symbols that must exist in the final generated462* code. If a function is not listed there, it might be inlined into every usage463* and optimized away.464*465* \since prior to LTO_API_VERSION=3466*/467extern void468lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);469470/**471* Writes a new object file at the specified path that contains the472* merged contents of all modules added so far.473* Returns true on error (check lto_get_error_message() for details).474*475* \since LTO_API_VERSION=5476*/477extern lto_bool_t478lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);479480/**481* Generates code for all added modules into one native object file.482* This calls lto_codegen_optimize then lto_codegen_compile_optimized.483*484* On success returns a pointer to a generated mach-o/ELF buffer and485* length set to the buffer size. The buffer is owned by the486* lto_code_gen_t and will be freed when lto_codegen_dispose()487* is called, or lto_codegen_compile() is called again.488* On failure, returns NULL (check lto_get_error_message() for details).489*490* \since prior to LTO_API_VERSION=3491*/492extern const void*493lto_codegen_compile(lto_code_gen_t cg, size_t* length);494495/**496* Generates code for all added modules into one native object file.497* This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead498* of returning a generated mach-o/ELF buffer, it writes to a file).499*500* The name of the file is written to name. Returns true on error.501*502* \since LTO_API_VERSION=5503*/504extern lto_bool_t505lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);506507/**508* Runs optimization for the merged module. Returns true on error.509*510* \since LTO_API_VERSION=12511*/512extern lto_bool_t513lto_codegen_optimize(lto_code_gen_t cg);514515/**516* Generates code for the optimized merged module into one native object file.517* It will not run any IR optimizations on the merged module.518*519* On success returns a pointer to a generated mach-o/ELF buffer and length set520* to the buffer size. The buffer is owned by the lto_code_gen_t and will be521* freed when lto_codegen_dispose() is called, or522* lto_codegen_compile_optimized() is called again. On failure, returns NULL523* (check lto_get_error_message() for details).524*525* \since LTO_API_VERSION=12526*/527extern const void*528lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length);529530/**531* Returns the runtime API version.532*533* \since LTO_API_VERSION=12534*/535extern unsigned int536lto_api_version(void);537538/**539* Parses options immediately, making them available as early as possible. For540* example during executing codegen::InitTargetOptionsFromCodeGenFlags. Since541* parsing shud only happen once, only one of lto_codegen_debug_options or542* lto_set_debug_options should be called.543*544* This function takes one or more options separated by spaces.545* Warning: passing file paths through this function may confuse the argument546* parser if the paths contain spaces.547*548* \since LTO_API_VERSION=28549*/550extern void lto_set_debug_options(const char *const *options, int number);551552/**553* Sets options to help debug codegen bugs. Since parsing shud only happen once,554* only one of lto_codegen_debug_options or lto_set_debug_options555* should be called.556*557* This function takes one or more options separated by spaces.558* Warning: passing file paths through this function may confuse the argument559* parser if the paths contain spaces.560*561* \since prior to LTO_API_VERSION=3562*/563extern void564lto_codegen_debug_options(lto_code_gen_t cg, const char *);565566/**567* Same as the previous function, but takes every option separately through an568* array.569*570* \since prior to LTO_API_VERSION=26571*/572extern void lto_codegen_debug_options_array(lto_code_gen_t cg,573const char *const *, int number);574575/**576* Initializes LLVM disassemblers.577* FIXME: This doesn't really belong here.578*579* \since LTO_API_VERSION=5580*/581extern void582lto_initialize_disassembler(void);583584/**585* Sets if we should run internalize pass during optimization and code586* generation.587*588* \since LTO_API_VERSION=14589*/590extern void591lto_codegen_set_should_internalize(lto_code_gen_t cg,592lto_bool_t ShouldInternalize);593594/**595* Set whether to embed uselists in bitcode.596*597* Sets whether \a lto_codegen_write_merged_modules() should embed uselists in598* output bitcode. This should be turned on for all -save-temps output.599*600* \since LTO_API_VERSION=15601*/602extern void603lto_codegen_set_should_embed_uselists(lto_code_gen_t cg,604lto_bool_t ShouldEmbedUselists);605606/** Opaque reference to an LTO input file */607typedef struct LLVMOpaqueLTOInput *lto_input_t;608609/**610* Creates an LTO input file from a buffer. The path611* argument is used for diagnotics as this function612* otherwise does not know which file the given buffer613* is associated with.614*615* \since LTO_API_VERSION=24616*/617extern lto_input_t lto_input_create(const void *buffer,618size_t buffer_size,619const char *path);620621/**622* Frees all memory internally allocated by the LTO input file.623* Upon return the lto_module_t is no longer valid.624*625* \since LTO_API_VERSION=24626*/627extern void lto_input_dispose(lto_input_t input);628629/**630* Returns the number of dependent library specifiers631* for the given LTO input file.632*633* \since LTO_API_VERSION=24634*/635extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input);636637/**638* Returns the ith dependent library specifier639* for the given LTO input file. The returned640* string is not null-terminated.641*642* \since LTO_API_VERSION=24643*/644extern const char * lto_input_get_dependent_library(lto_input_t input,645size_t index,646size_t *size);647648/**649* Returns the list of libcall symbols that can be generated by LTO650* that might not be visible from the symbol table of bitcode files.651*652* \since prior to LTO_API_VERSION=25653*/654extern const char *const *lto_runtime_lib_symbols_list(size_t *size);655656/**657* @} // endgoup LLVMCLTO658* @defgroup LLVMCTLTO ThinLTO659* @ingroup LLVMC660*661* @{662*/663664/**665* Type to wrap a single object returned by ThinLTO.666*667* \since LTO_API_VERSION=18668*/669typedef struct {670const char *Buffer;671size_t Size;672} LTOObjectBuffer;673674/**675* Instantiates a ThinLTO code generator.676* Returns NULL on error (check lto_get_error_message() for details).677*678*679* The ThinLTOCodeGenerator is not intended to be reuse for multiple680* compilation: the model is that the client adds modules to the generator and681* ask to perform the ThinLTO optimizations / codegen, and finally destroys the682* codegenerator.683*684* \since LTO_API_VERSION=18685*/686extern thinlto_code_gen_t thinlto_create_codegen(void);687688/**689* Frees the generator and all memory it internally allocated.690* Upon return the thinlto_code_gen_t is no longer valid.691*692* \since LTO_API_VERSION=18693*/694extern void thinlto_codegen_dispose(thinlto_code_gen_t cg);695696/**697* Add a module to a ThinLTO code generator. Identifier has to be unique among698* all the modules in a code generator. The data buffer stays owned by the699* client, and is expected to be available for the entire lifetime of the700* thinlto_code_gen_t it is added to.701*702* On failure, returns NULL (check lto_get_error_message() for details).703*704*705* \since LTO_API_VERSION=18706*/707extern void thinlto_codegen_add_module(thinlto_code_gen_t cg,708const char *identifier, const char *data,709int length);710711/**712* Optimize and codegen all the modules added to the codegenerator using713* ThinLTO. Resulting objects are accessible using thinlto_module_get_object().714*715* \since LTO_API_VERSION=18716*/717extern void thinlto_codegen_process(thinlto_code_gen_t cg);718719/**720* Returns the number of object files produced by the ThinLTO CodeGenerator.721*722* It usually matches the number of input files, but this is not a guarantee of723* the API and may change in future implementation, so the client should not724* assume it.725*726* \since LTO_API_VERSION=18727*/728extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg);729730/**731* Returns a reference to the ith object file produced by the ThinLTO732* CodeGenerator.733*734* Client should use \p thinlto_module_get_num_objects() to get the number of735* available objects.736*737* \since LTO_API_VERSION=18738*/739extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg,740unsigned int index);741742/**743* Returns the number of object files produced by the ThinLTO CodeGenerator.744*745* It usually matches the number of input files, but this is not a guarantee of746* the API and may change in future implementation, so the client should not747* assume it.748*749* \since LTO_API_VERSION=21750*/751unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg);752753/**754* Returns the path to the ith object file produced by the ThinLTO755* CodeGenerator.756*757* Client should use \p thinlto_module_get_num_object_files() to get the number758* of available objects.759*760* \since LTO_API_VERSION=21761*/762const char *thinlto_module_get_object_file(thinlto_code_gen_t cg,763unsigned int index);764765/**766* Sets which PIC code model to generate.767* Returns true on error (check lto_get_error_message() for details).768*769* \since LTO_API_VERSION=18770*/771extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg,772lto_codegen_model);773774/**775* Sets the path to a directory to use as a storage for temporary bitcode files.776* The intention is to make the bitcode files available for debugging at various777* stage of the pipeline.778*779* \since LTO_API_VERSION=18780*/781extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg,782const char *save_temps_dir);783784/**785* Set the path to a directory where to save generated object files. This786* path can be used by a linker to request on-disk files instead of in-memory787* buffers. When set, results are available through788* thinlto_module_get_object_file() instead of thinlto_module_get_object().789*790* \since LTO_API_VERSION=21791*/792void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg,793const char *save_temps_dir);794795/**796* Sets the cpu to generate code for.797*798* \since LTO_API_VERSION=18799*/800extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu);801802/**803* Disable CodeGen, only run the stages till codegen and stop. The output will804* be bitcode.805*806* \since LTO_API_VERSION=19807*/808extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg,809lto_bool_t disable);810811/**812* Perform CodeGen only: disable all other stages.813*814* \since LTO_API_VERSION=19815*/816extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg,817lto_bool_t codegen_only);818819/**820* Parse -mllvm style debug options.821*822* \since LTO_API_VERSION=18823*/824extern void thinlto_debug_options(const char *const *options, int number);825826/**827* Test if a module has support for ThinLTO linking.828*829* \since LTO_API_VERSION=18830*/831extern lto_bool_t lto_module_is_thinlto(lto_module_t mod);832833/**834* Adds a symbol to the list of global symbols that must exist in the final835* generated code. If a function is not listed there, it might be inlined into836* every usage and optimized away. For every single module, the functions837* referenced from code outside of the ThinLTO modules need to be added here.838*839* \since LTO_API_VERSION=18840*/841extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg,842const char *name,843int length);844845/**846* Adds a symbol to the list of global symbols that are cross-referenced between847* ThinLTO files. If the ThinLTO CodeGenerator can ensure that every848* references from a ThinLTO module to this symbol is optimized away, then849* the symbol can be discarded.850*851* \since LTO_API_VERSION=18852*/853extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg,854const char *name,855int length);856857/**858* @} // endgoup LLVMCTLTO859* @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control860* @ingroup LLVMCTLTO861*862* These entry points control the ThinLTO cache. The cache is intended to863* support incremental builds, and thus needs to be persistent across builds.864* The client enables the cache by supplying a path to an existing directory.865* The code generator will use this to store objects files that may be reused866* during a subsequent build.867* To avoid filling the disk space, a few knobs are provided:868* - The pruning interval limits the frequency at which the garbage collector869* will try to scan the cache directory to prune expired entries.870* Setting to a negative number disables the pruning.871* - The pruning expiration time indicates to the garbage collector how old an872* entry needs to be to be removed.873* - Finally, the garbage collector can be instructed to prune the cache until874* the occupied space goes below a threshold.875* @{876*/877878/**879* Sets the path to a directory to use as a cache storage for incremental build.880* Setting this activates caching.881*882* \since LTO_API_VERSION=18883*/884extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,885const char *cache_dir);886887/**888* Sets the cache pruning interval (in seconds). A negative value disables the889* pruning. An unspecified default value will be applied, and a value of 0 will890* force prunning to occur.891*892* \since LTO_API_VERSION=18893*/894extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg,895int interval);896897/**898* Sets the maximum cache size that can be persistent across build, in terms of899* percentage of the available space on the disk. Set to 100 to indicate900* no limit, 50 to indicate that the cache size will not be left over half the901* available space. A value over 100 will be reduced to 100, a value of 0 will902* be ignored. An unspecified default value will be applied.903*904* The formula looks like:905* AvailableSpace = FreeSpace + ExistingCacheSize906* NewCacheSize = AvailableSpace * P/100907*908* \since LTO_API_VERSION=18909*/910extern void thinlto_codegen_set_final_cache_size_relative_to_available_space(911thinlto_code_gen_t cg, unsigned percentage);912913/**914* Sets the expiration (in seconds) for an entry in the cache. An unspecified915* default value will be applied. A value of 0 will be ignored.916*917* \since LTO_API_VERSION=18918*/919extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg,920unsigned expiration);921922/**923* Sets the maximum size of the cache directory (in bytes). A value over the924* amount of available space on the disk will be reduced to the amount of925* available space. An unspecified default value will be applied. A value of 0926* will be ignored.927*928* \since LTO_API_VERSION=22929*/930extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg,931unsigned max_size_bytes);932933/**934* Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in935* megabytes (2^20 bytes).936*937* \since LTO_API_VERSION=23938*/939extern void940thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg,941unsigned max_size_megabytes);942943/**944* Sets the maximum number of files in the cache directory. An unspecified945* default value will be applied. A value of 0 will be ignored.946*947* \since LTO_API_VERSION=22948*/949extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg,950unsigned max_size_files);951952/**953* @} // endgroup LLVMCTLTO_CACHING954*/955956LLVM_C_EXTERN_C_END957958#endif /* LLVM_C_LTO_H */959960961