1*0b57cec5SDimitry Andric /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\ 2*0b57cec5SDimitry Andric |* *| 3*0b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4*0b57cec5SDimitry Andric |* Exceptions. *| 5*0b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information. *| 6*0b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 7*0b57cec5SDimitry Andric |* *| 8*0b57cec5SDimitry Andric |*===----------------------------------------------------------------------===*| 9*0b57cec5SDimitry Andric |* *| 10*0b57cec5SDimitry Andric |* This header provides public interface to an abstract link time optimization*| 11*0b57cec5SDimitry Andric |* library. LLVM provides an implementation of this interface for use with *| 12*0b57cec5SDimitry Andric |* llvm bitcode files. *| 13*0b57cec5SDimitry Andric |* *| 14*0b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/ 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric #ifndef LLVM_C_LTO_H 17*0b57cec5SDimitry Andric #define LLVM_C_LTO_H 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andric #ifdef __cplusplus 20*0b57cec5SDimitry Andric #include <cstddef> 21*0b57cec5SDimitry Andric #else 22*0b57cec5SDimitry Andric #include <stddef.h> 23*0b57cec5SDimitry Andric #endif 24*0b57cec5SDimitry Andric #include <sys/types.h> 25*0b57cec5SDimitry Andric 26*0b57cec5SDimitry Andric #ifndef __cplusplus 27*0b57cec5SDimitry Andric #if !defined(_MSC_VER) 28*0b57cec5SDimitry Andric #include <stdbool.h> 29*0b57cec5SDimitry Andric typedef bool lto_bool_t; 30*0b57cec5SDimitry Andric #else 31*0b57cec5SDimitry Andric /* MSVC in particular does not have anything like _Bool or bool in C, but we can 32*0b57cec5SDimitry Andric at least make sure the type is the same size. The implementation side will 33*0b57cec5SDimitry Andric use C++ bool. */ 34*0b57cec5SDimitry Andric typedef unsigned char lto_bool_t; 35*0b57cec5SDimitry Andric #endif 36*0b57cec5SDimitry Andric #else 37*0b57cec5SDimitry Andric typedef bool lto_bool_t; 38*0b57cec5SDimitry Andric #endif 39*0b57cec5SDimitry Andric 40*0b57cec5SDimitry Andric /** 41*0b57cec5SDimitry Andric * @defgroup LLVMCLTO LTO 42*0b57cec5SDimitry Andric * @ingroup LLVMC 43*0b57cec5SDimitry Andric * 44*0b57cec5SDimitry Andric * @{ 45*0b57cec5SDimitry Andric */ 46*0b57cec5SDimitry Andric 47*0b57cec5SDimitry Andric #define LTO_API_VERSION 24 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric /** 50*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 51*0b57cec5SDimitry Andric */ 52*0b57cec5SDimitry Andric typedef enum { 53*0b57cec5SDimitry Andric LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ 54*0b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, 55*0b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, 56*0b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, 57*0b57cec5SDimitry Andric LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, 58*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_MASK = 0x00000700, 59*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, 60*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, 61*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, 62*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, 63*0b57cec5SDimitry Andric LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, 64*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_MASK = 0x00003800, 65*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, 66*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, 67*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, 68*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, 69*0b57cec5SDimitry Andric LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800, 70*0b57cec5SDimitry Andric LTO_SYMBOL_COMDAT = 0x00004000, 71*0b57cec5SDimitry Andric LTO_SYMBOL_ALIAS = 0x00008000 72*0b57cec5SDimitry Andric } lto_symbol_attributes; 73*0b57cec5SDimitry Andric 74*0b57cec5SDimitry Andric /** 75*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 76*0b57cec5SDimitry Andric */ 77*0b57cec5SDimitry Andric typedef enum { 78*0b57cec5SDimitry Andric LTO_DEBUG_MODEL_NONE = 0, 79*0b57cec5SDimitry Andric LTO_DEBUG_MODEL_DWARF = 1 80*0b57cec5SDimitry Andric } lto_debug_model; 81*0b57cec5SDimitry Andric 82*0b57cec5SDimitry Andric /** 83*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 84*0b57cec5SDimitry Andric */ 85*0b57cec5SDimitry Andric typedef enum { 86*0b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_STATIC = 0, 87*0b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, 88*0b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2, 89*0b57cec5SDimitry Andric LTO_CODEGEN_PIC_MODEL_DEFAULT = 3 90*0b57cec5SDimitry Andric } lto_codegen_model; 91*0b57cec5SDimitry Andric 92*0b57cec5SDimitry Andric /** opaque reference to a loaded object module */ 93*0b57cec5SDimitry Andric typedef struct LLVMOpaqueLTOModule *lto_module_t; 94*0b57cec5SDimitry Andric 95*0b57cec5SDimitry Andric /** opaque reference to a code generator */ 96*0b57cec5SDimitry Andric typedef struct LLVMOpaqueLTOCodeGenerator *lto_code_gen_t; 97*0b57cec5SDimitry Andric 98*0b57cec5SDimitry Andric /** opaque reference to a thin code generator */ 99*0b57cec5SDimitry Andric typedef struct LLVMOpaqueThinLTOCodeGenerator *thinlto_code_gen_t; 100*0b57cec5SDimitry Andric 101*0b57cec5SDimitry Andric #ifdef __cplusplus 102*0b57cec5SDimitry Andric extern "C" { 103*0b57cec5SDimitry Andric #endif 104*0b57cec5SDimitry Andric 105*0b57cec5SDimitry Andric /** 106*0b57cec5SDimitry Andric * Returns a printable string. 107*0b57cec5SDimitry Andric * 108*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 109*0b57cec5SDimitry Andric */ 110*0b57cec5SDimitry Andric extern const char* 111*0b57cec5SDimitry Andric lto_get_version(void); 112*0b57cec5SDimitry Andric 113*0b57cec5SDimitry Andric /** 114*0b57cec5SDimitry Andric * Returns the last error string or NULL if last operation was successful. 115*0b57cec5SDimitry Andric * 116*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 117*0b57cec5SDimitry Andric */ 118*0b57cec5SDimitry Andric extern const char* 119*0b57cec5SDimitry Andric lto_get_error_message(void); 120*0b57cec5SDimitry Andric 121*0b57cec5SDimitry Andric /** 122*0b57cec5SDimitry Andric * Checks if a file is a loadable object file. 123*0b57cec5SDimitry Andric * 124*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 125*0b57cec5SDimitry Andric */ 126*0b57cec5SDimitry Andric extern lto_bool_t 127*0b57cec5SDimitry Andric lto_module_is_object_file(const char* path); 128*0b57cec5SDimitry Andric 129*0b57cec5SDimitry Andric /** 130*0b57cec5SDimitry Andric * Checks if a file is a loadable object compiled for requested target. 131*0b57cec5SDimitry Andric * 132*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 133*0b57cec5SDimitry Andric */ 134*0b57cec5SDimitry Andric extern lto_bool_t 135*0b57cec5SDimitry Andric lto_module_is_object_file_for_target(const char* path, 136*0b57cec5SDimitry Andric const char* target_triple_prefix); 137*0b57cec5SDimitry Andric 138*0b57cec5SDimitry Andric /** 139*0b57cec5SDimitry Andric * Return true if \p Buffer contains a bitcode file with ObjC code (category 140*0b57cec5SDimitry Andric * or class) in it. 141*0b57cec5SDimitry Andric * 142*0b57cec5SDimitry Andric * \since LTO_API_VERSION=20 143*0b57cec5SDimitry Andric */ 144*0b57cec5SDimitry Andric extern lto_bool_t 145*0b57cec5SDimitry Andric lto_module_has_objc_category(const void *mem, size_t length); 146*0b57cec5SDimitry Andric 147*0b57cec5SDimitry Andric /** 148*0b57cec5SDimitry Andric * Checks if a buffer is a loadable object file. 149*0b57cec5SDimitry Andric * 150*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 151*0b57cec5SDimitry Andric */ 152*0b57cec5SDimitry Andric extern lto_bool_t lto_module_is_object_file_in_memory(const void *mem, 153*0b57cec5SDimitry Andric size_t length); 154*0b57cec5SDimitry Andric 155*0b57cec5SDimitry Andric /** 156*0b57cec5SDimitry Andric * Checks if a buffer is a loadable object compiled for requested target. 157*0b57cec5SDimitry Andric * 158*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 159*0b57cec5SDimitry Andric */ 160*0b57cec5SDimitry Andric extern lto_bool_t 161*0b57cec5SDimitry Andric lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 162*0b57cec5SDimitry Andric const char* target_triple_prefix); 163*0b57cec5SDimitry Andric 164*0b57cec5SDimitry Andric /** 165*0b57cec5SDimitry Andric * Loads an object file from disk. 166*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 167*0b57cec5SDimitry Andric * 168*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 169*0b57cec5SDimitry Andric */ 170*0b57cec5SDimitry Andric extern lto_module_t 171*0b57cec5SDimitry Andric lto_module_create(const char* path); 172*0b57cec5SDimitry Andric 173*0b57cec5SDimitry Andric /** 174*0b57cec5SDimitry Andric * Loads an object file from memory. 175*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 176*0b57cec5SDimitry Andric * 177*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 178*0b57cec5SDimitry Andric */ 179*0b57cec5SDimitry Andric extern lto_module_t 180*0b57cec5SDimitry Andric lto_module_create_from_memory(const void* mem, size_t length); 181*0b57cec5SDimitry Andric 182*0b57cec5SDimitry Andric /** 183*0b57cec5SDimitry Andric * Loads an object file from memory with an extra path argument. 184*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 185*0b57cec5SDimitry Andric * 186*0b57cec5SDimitry Andric * \since LTO_API_VERSION=9 187*0b57cec5SDimitry Andric */ 188*0b57cec5SDimitry Andric extern lto_module_t 189*0b57cec5SDimitry Andric lto_module_create_from_memory_with_path(const void* mem, size_t length, 190*0b57cec5SDimitry Andric const char *path); 191*0b57cec5SDimitry Andric 192*0b57cec5SDimitry Andric /** 193*0b57cec5SDimitry Andric * Loads an object file in its own context. 194*0b57cec5SDimitry Andric * 195*0b57cec5SDimitry Andric * Loads an object file in its own LLVMContext. This function call is 196*0b57cec5SDimitry Andric * thread-safe. However, modules created this way should not be merged into an 197*0b57cec5SDimitry Andric * lto_code_gen_t using \a lto_codegen_add_module(). 198*0b57cec5SDimitry Andric * 199*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 200*0b57cec5SDimitry Andric * 201*0b57cec5SDimitry Andric * \since LTO_API_VERSION=11 202*0b57cec5SDimitry Andric */ 203*0b57cec5SDimitry Andric extern lto_module_t 204*0b57cec5SDimitry Andric lto_module_create_in_local_context(const void *mem, size_t length, 205*0b57cec5SDimitry Andric const char *path); 206*0b57cec5SDimitry Andric 207*0b57cec5SDimitry Andric /** 208*0b57cec5SDimitry Andric * Loads an object file in the codegen context. 209*0b57cec5SDimitry Andric * 210*0b57cec5SDimitry Andric * Loads an object file into the same context as \c cg. The module is safe to 211*0b57cec5SDimitry Andric * add using \a lto_codegen_add_module(). 212*0b57cec5SDimitry Andric * 213*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 214*0b57cec5SDimitry Andric * 215*0b57cec5SDimitry Andric * \since LTO_API_VERSION=11 216*0b57cec5SDimitry Andric */ 217*0b57cec5SDimitry Andric extern lto_module_t 218*0b57cec5SDimitry Andric lto_module_create_in_codegen_context(const void *mem, size_t length, 219*0b57cec5SDimitry Andric const char *path, lto_code_gen_t cg); 220*0b57cec5SDimitry Andric 221*0b57cec5SDimitry Andric /** 222*0b57cec5SDimitry Andric * Loads an object file from disk. The seek point of fd is not preserved. 223*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 224*0b57cec5SDimitry Andric * 225*0b57cec5SDimitry Andric * \since LTO_API_VERSION=5 226*0b57cec5SDimitry Andric */ 227*0b57cec5SDimitry Andric extern lto_module_t 228*0b57cec5SDimitry Andric lto_module_create_from_fd(int fd, const char *path, size_t file_size); 229*0b57cec5SDimitry Andric 230*0b57cec5SDimitry Andric /** 231*0b57cec5SDimitry Andric * Loads an object file from disk. The seek point of fd is not preserved. 232*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 233*0b57cec5SDimitry Andric * 234*0b57cec5SDimitry Andric * \since LTO_API_VERSION=5 235*0b57cec5SDimitry Andric */ 236*0b57cec5SDimitry Andric extern lto_module_t 237*0b57cec5SDimitry Andric lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, 238*0b57cec5SDimitry Andric size_t map_size, off_t offset); 239*0b57cec5SDimitry Andric 240*0b57cec5SDimitry Andric /** 241*0b57cec5SDimitry Andric * Frees all memory internally allocated by the module. 242*0b57cec5SDimitry Andric * Upon return the lto_module_t is no longer valid. 243*0b57cec5SDimitry Andric * 244*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 245*0b57cec5SDimitry Andric */ 246*0b57cec5SDimitry Andric extern void 247*0b57cec5SDimitry Andric lto_module_dispose(lto_module_t mod); 248*0b57cec5SDimitry Andric 249*0b57cec5SDimitry Andric /** 250*0b57cec5SDimitry Andric * Returns triple string which the object module was compiled under. 251*0b57cec5SDimitry Andric * 252*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 253*0b57cec5SDimitry Andric */ 254*0b57cec5SDimitry Andric extern const char* 255*0b57cec5SDimitry Andric lto_module_get_target_triple(lto_module_t mod); 256*0b57cec5SDimitry Andric 257*0b57cec5SDimitry Andric /** 258*0b57cec5SDimitry Andric * Sets triple string with which the object will be codegened. 259*0b57cec5SDimitry Andric * 260*0b57cec5SDimitry Andric * \since LTO_API_VERSION=4 261*0b57cec5SDimitry Andric */ 262*0b57cec5SDimitry Andric extern void 263*0b57cec5SDimitry Andric lto_module_set_target_triple(lto_module_t mod, const char *triple); 264*0b57cec5SDimitry Andric 265*0b57cec5SDimitry Andric /** 266*0b57cec5SDimitry Andric * Returns the number of symbols in the object module. 267*0b57cec5SDimitry Andric * 268*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 269*0b57cec5SDimitry Andric */ 270*0b57cec5SDimitry Andric extern unsigned int 271*0b57cec5SDimitry Andric lto_module_get_num_symbols(lto_module_t mod); 272*0b57cec5SDimitry Andric 273*0b57cec5SDimitry Andric /** 274*0b57cec5SDimitry Andric * Returns the name of the ith symbol in the object module. 275*0b57cec5SDimitry Andric * 276*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 277*0b57cec5SDimitry Andric */ 278*0b57cec5SDimitry Andric extern const char* 279*0b57cec5SDimitry Andric lto_module_get_symbol_name(lto_module_t mod, unsigned int index); 280*0b57cec5SDimitry Andric 281*0b57cec5SDimitry Andric /** 282*0b57cec5SDimitry Andric * Returns the attributes of the ith symbol in the object module. 283*0b57cec5SDimitry Andric * 284*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 285*0b57cec5SDimitry Andric */ 286*0b57cec5SDimitry Andric extern lto_symbol_attributes 287*0b57cec5SDimitry Andric lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); 288*0b57cec5SDimitry Andric 289*0b57cec5SDimitry Andric /** 290*0b57cec5SDimitry Andric * Returns the module's linker options. 291*0b57cec5SDimitry Andric * 292*0b57cec5SDimitry Andric * The linker options may consist of multiple flags. It is the linker's 293*0b57cec5SDimitry Andric * responsibility to split the flags using a platform-specific mechanism. 294*0b57cec5SDimitry Andric * 295*0b57cec5SDimitry Andric * \since LTO_API_VERSION=16 296*0b57cec5SDimitry Andric */ 297*0b57cec5SDimitry Andric extern const char* 298*0b57cec5SDimitry Andric lto_module_get_linkeropts(lto_module_t mod); 299*0b57cec5SDimitry Andric 300*0b57cec5SDimitry Andric /** 301*0b57cec5SDimitry Andric * Diagnostic severity. 302*0b57cec5SDimitry Andric * 303*0b57cec5SDimitry Andric * \since LTO_API_VERSION=7 304*0b57cec5SDimitry Andric */ 305*0b57cec5SDimitry Andric typedef enum { 306*0b57cec5SDimitry Andric LTO_DS_ERROR = 0, 307*0b57cec5SDimitry Andric LTO_DS_WARNING = 1, 308*0b57cec5SDimitry Andric LTO_DS_REMARK = 3, // Added in LTO_API_VERSION=10. 309*0b57cec5SDimitry Andric LTO_DS_NOTE = 2 310*0b57cec5SDimitry Andric } lto_codegen_diagnostic_severity_t; 311*0b57cec5SDimitry Andric 312*0b57cec5SDimitry Andric /** 313*0b57cec5SDimitry Andric * Diagnostic handler type. 314*0b57cec5SDimitry Andric * \p severity defines the severity. 315*0b57cec5SDimitry Andric * \p diag is the actual diagnostic. 316*0b57cec5SDimitry Andric * The diagnostic is not prefixed by any of severity keyword, e.g., 'error: '. 317*0b57cec5SDimitry Andric * \p ctxt is used to pass the context set with the diagnostic handler. 318*0b57cec5SDimitry Andric * 319*0b57cec5SDimitry Andric * \since LTO_API_VERSION=7 320*0b57cec5SDimitry Andric */ 321*0b57cec5SDimitry Andric typedef void (*lto_diagnostic_handler_t)( 322*0b57cec5SDimitry Andric lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt); 323*0b57cec5SDimitry Andric 324*0b57cec5SDimitry Andric /** 325*0b57cec5SDimitry Andric * Set a diagnostic handler and the related context (void *). 326*0b57cec5SDimitry Andric * This is more general than lto_get_error_message, as the diagnostic handler 327*0b57cec5SDimitry Andric * can be called at anytime within lto. 328*0b57cec5SDimitry Andric * 329*0b57cec5SDimitry Andric * \since LTO_API_VERSION=7 330*0b57cec5SDimitry Andric */ 331*0b57cec5SDimitry Andric extern void lto_codegen_set_diagnostic_handler(lto_code_gen_t, 332*0b57cec5SDimitry Andric lto_diagnostic_handler_t, 333*0b57cec5SDimitry Andric void *); 334*0b57cec5SDimitry Andric 335*0b57cec5SDimitry Andric /** 336*0b57cec5SDimitry Andric * Instantiates a code generator. 337*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 338*0b57cec5SDimitry Andric * 339*0b57cec5SDimitry Andric * All modules added using \a lto_codegen_add_module() must have been created 340*0b57cec5SDimitry Andric * in the same context as the codegen. 341*0b57cec5SDimitry Andric * 342*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 343*0b57cec5SDimitry Andric */ 344*0b57cec5SDimitry Andric extern lto_code_gen_t 345*0b57cec5SDimitry Andric lto_codegen_create(void); 346*0b57cec5SDimitry Andric 347*0b57cec5SDimitry Andric /** 348*0b57cec5SDimitry Andric * Instantiate a code generator in its own context. 349*0b57cec5SDimitry Andric * 350*0b57cec5SDimitry Andric * Instantiates a code generator in its own context. Modules added via \a 351*0b57cec5SDimitry Andric * lto_codegen_add_module() must have all been created in the same context, 352*0b57cec5SDimitry Andric * using \a lto_module_create_in_codegen_context(). 353*0b57cec5SDimitry Andric * 354*0b57cec5SDimitry Andric * \since LTO_API_VERSION=11 355*0b57cec5SDimitry Andric */ 356*0b57cec5SDimitry Andric extern lto_code_gen_t 357*0b57cec5SDimitry Andric lto_codegen_create_in_local_context(void); 358*0b57cec5SDimitry Andric 359*0b57cec5SDimitry Andric /** 360*0b57cec5SDimitry Andric * Frees all code generator and all memory it internally allocated. 361*0b57cec5SDimitry Andric * Upon return the lto_code_gen_t is no longer valid. 362*0b57cec5SDimitry Andric * 363*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 364*0b57cec5SDimitry Andric */ 365*0b57cec5SDimitry Andric extern void 366*0b57cec5SDimitry Andric lto_codegen_dispose(lto_code_gen_t); 367*0b57cec5SDimitry Andric 368*0b57cec5SDimitry Andric /** 369*0b57cec5SDimitry Andric * Add an object module to the set of modules for which code will be generated. 370*0b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 371*0b57cec5SDimitry Andric * 372*0b57cec5SDimitry Andric * \c cg and \c mod must both be in the same context. See \a 373*0b57cec5SDimitry Andric * lto_codegen_create_in_local_context() and \a 374*0b57cec5SDimitry Andric * lto_module_create_in_codegen_context(). 375*0b57cec5SDimitry Andric * 376*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 377*0b57cec5SDimitry Andric */ 378*0b57cec5SDimitry Andric extern lto_bool_t 379*0b57cec5SDimitry Andric lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); 380*0b57cec5SDimitry Andric 381*0b57cec5SDimitry Andric /** 382*0b57cec5SDimitry Andric * Sets the object module for code generation. This will transfer the ownership 383*0b57cec5SDimitry Andric * of the module to the code generator. 384*0b57cec5SDimitry Andric * 385*0b57cec5SDimitry Andric * \c cg and \c mod must both be in the same context. 386*0b57cec5SDimitry Andric * 387*0b57cec5SDimitry Andric * \since LTO_API_VERSION=13 388*0b57cec5SDimitry Andric */ 389*0b57cec5SDimitry Andric extern void 390*0b57cec5SDimitry Andric lto_codegen_set_module(lto_code_gen_t cg, lto_module_t mod); 391*0b57cec5SDimitry Andric 392*0b57cec5SDimitry Andric /** 393*0b57cec5SDimitry Andric * Sets if debug info should be generated. 394*0b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 395*0b57cec5SDimitry Andric * 396*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 397*0b57cec5SDimitry Andric */ 398*0b57cec5SDimitry Andric extern lto_bool_t 399*0b57cec5SDimitry Andric lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); 400*0b57cec5SDimitry Andric 401*0b57cec5SDimitry Andric /** 402*0b57cec5SDimitry Andric * Sets which PIC code model to generated. 403*0b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 404*0b57cec5SDimitry Andric * 405*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 406*0b57cec5SDimitry Andric */ 407*0b57cec5SDimitry Andric extern lto_bool_t 408*0b57cec5SDimitry Andric lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); 409*0b57cec5SDimitry Andric 410*0b57cec5SDimitry Andric /** 411*0b57cec5SDimitry Andric * Sets the cpu to generate code for. 412*0b57cec5SDimitry Andric * 413*0b57cec5SDimitry Andric * \since LTO_API_VERSION=4 414*0b57cec5SDimitry Andric */ 415*0b57cec5SDimitry Andric extern void 416*0b57cec5SDimitry Andric lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); 417*0b57cec5SDimitry Andric 418*0b57cec5SDimitry Andric /** 419*0b57cec5SDimitry Andric * Sets the location of the assembler tool to run. If not set, libLTO 420*0b57cec5SDimitry Andric * will use gcc to invoke the assembler. 421*0b57cec5SDimitry Andric * 422*0b57cec5SDimitry Andric * \since LTO_API_VERSION=3 423*0b57cec5SDimitry Andric */ 424*0b57cec5SDimitry Andric extern void 425*0b57cec5SDimitry Andric lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); 426*0b57cec5SDimitry Andric 427*0b57cec5SDimitry Andric /** 428*0b57cec5SDimitry Andric * Sets extra arguments that libLTO should pass to the assembler. 429*0b57cec5SDimitry Andric * 430*0b57cec5SDimitry Andric * \since LTO_API_VERSION=4 431*0b57cec5SDimitry Andric */ 432*0b57cec5SDimitry Andric extern void 433*0b57cec5SDimitry Andric lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, 434*0b57cec5SDimitry Andric int nargs); 435*0b57cec5SDimitry Andric 436*0b57cec5SDimitry Andric /** 437*0b57cec5SDimitry Andric * Adds to a list of all global symbols that must exist in the final generated 438*0b57cec5SDimitry Andric * code. If a function is not listed there, it might be inlined into every usage 439*0b57cec5SDimitry Andric * and optimized away. 440*0b57cec5SDimitry Andric * 441*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 442*0b57cec5SDimitry Andric */ 443*0b57cec5SDimitry Andric extern void 444*0b57cec5SDimitry Andric lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); 445*0b57cec5SDimitry Andric 446*0b57cec5SDimitry Andric /** 447*0b57cec5SDimitry Andric * Writes a new object file at the specified path that contains the 448*0b57cec5SDimitry Andric * merged contents of all modules added so far. 449*0b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 450*0b57cec5SDimitry Andric * 451*0b57cec5SDimitry Andric * \since LTO_API_VERSION=5 452*0b57cec5SDimitry Andric */ 453*0b57cec5SDimitry Andric extern lto_bool_t 454*0b57cec5SDimitry Andric lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); 455*0b57cec5SDimitry Andric 456*0b57cec5SDimitry Andric /** 457*0b57cec5SDimitry Andric * Generates code for all added modules into one native object file. 458*0b57cec5SDimitry Andric * This calls lto_codegen_optimize then lto_codegen_compile_optimized. 459*0b57cec5SDimitry Andric * 460*0b57cec5SDimitry Andric * On success returns a pointer to a generated mach-o/ELF buffer and 461*0b57cec5SDimitry Andric * length set to the buffer size. The buffer is owned by the 462*0b57cec5SDimitry Andric * lto_code_gen_t and will be freed when lto_codegen_dispose() 463*0b57cec5SDimitry Andric * is called, or lto_codegen_compile() is called again. 464*0b57cec5SDimitry Andric * On failure, returns NULL (check lto_get_error_message() for details). 465*0b57cec5SDimitry Andric * 466*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 467*0b57cec5SDimitry Andric */ 468*0b57cec5SDimitry Andric extern const void* 469*0b57cec5SDimitry Andric lto_codegen_compile(lto_code_gen_t cg, size_t* length); 470*0b57cec5SDimitry Andric 471*0b57cec5SDimitry Andric /** 472*0b57cec5SDimitry Andric * Generates code for all added modules into one native object file. 473*0b57cec5SDimitry Andric * This calls lto_codegen_optimize then lto_codegen_compile_optimized (instead 474*0b57cec5SDimitry Andric * of returning a generated mach-o/ELF buffer, it writes to a file). 475*0b57cec5SDimitry Andric * 476*0b57cec5SDimitry Andric * The name of the file is written to name. Returns true on error. 477*0b57cec5SDimitry Andric * 478*0b57cec5SDimitry Andric * \since LTO_API_VERSION=5 479*0b57cec5SDimitry Andric */ 480*0b57cec5SDimitry Andric extern lto_bool_t 481*0b57cec5SDimitry Andric lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); 482*0b57cec5SDimitry Andric 483*0b57cec5SDimitry Andric /** 484*0b57cec5SDimitry Andric * Runs optimization for the merged module. Returns true on error. 485*0b57cec5SDimitry Andric * 486*0b57cec5SDimitry Andric * \since LTO_API_VERSION=12 487*0b57cec5SDimitry Andric */ 488*0b57cec5SDimitry Andric extern lto_bool_t 489*0b57cec5SDimitry Andric lto_codegen_optimize(lto_code_gen_t cg); 490*0b57cec5SDimitry Andric 491*0b57cec5SDimitry Andric /** 492*0b57cec5SDimitry Andric * Generates code for the optimized merged module into one native object file. 493*0b57cec5SDimitry Andric * It will not run any IR optimizations on the merged module. 494*0b57cec5SDimitry Andric * 495*0b57cec5SDimitry Andric * On success returns a pointer to a generated mach-o/ELF buffer and length set 496*0b57cec5SDimitry Andric * to the buffer size. The buffer is owned by the lto_code_gen_t and will be 497*0b57cec5SDimitry Andric * freed when lto_codegen_dispose() is called, or 498*0b57cec5SDimitry Andric * lto_codegen_compile_optimized() is called again. On failure, returns NULL 499*0b57cec5SDimitry Andric * (check lto_get_error_message() for details). 500*0b57cec5SDimitry Andric * 501*0b57cec5SDimitry Andric * \since LTO_API_VERSION=12 502*0b57cec5SDimitry Andric */ 503*0b57cec5SDimitry Andric extern const void* 504*0b57cec5SDimitry Andric lto_codegen_compile_optimized(lto_code_gen_t cg, size_t* length); 505*0b57cec5SDimitry Andric 506*0b57cec5SDimitry Andric /** 507*0b57cec5SDimitry Andric * Returns the runtime API version. 508*0b57cec5SDimitry Andric * 509*0b57cec5SDimitry Andric * \since LTO_API_VERSION=12 510*0b57cec5SDimitry Andric */ 511*0b57cec5SDimitry Andric extern unsigned int 512*0b57cec5SDimitry Andric lto_api_version(void); 513*0b57cec5SDimitry Andric 514*0b57cec5SDimitry Andric /** 515*0b57cec5SDimitry Andric * Sets options to help debug codegen bugs. 516*0b57cec5SDimitry Andric * 517*0b57cec5SDimitry Andric * \since prior to LTO_API_VERSION=3 518*0b57cec5SDimitry Andric */ 519*0b57cec5SDimitry Andric extern void 520*0b57cec5SDimitry Andric lto_codegen_debug_options(lto_code_gen_t cg, const char *); 521*0b57cec5SDimitry Andric 522*0b57cec5SDimitry Andric /** 523*0b57cec5SDimitry Andric * Initializes LLVM disassemblers. 524*0b57cec5SDimitry Andric * FIXME: This doesn't really belong here. 525*0b57cec5SDimitry Andric * 526*0b57cec5SDimitry Andric * \since LTO_API_VERSION=5 527*0b57cec5SDimitry Andric */ 528*0b57cec5SDimitry Andric extern void 529*0b57cec5SDimitry Andric lto_initialize_disassembler(void); 530*0b57cec5SDimitry Andric 531*0b57cec5SDimitry Andric /** 532*0b57cec5SDimitry Andric * Sets if we should run internalize pass during optimization and code 533*0b57cec5SDimitry Andric * generation. 534*0b57cec5SDimitry Andric * 535*0b57cec5SDimitry Andric * \since LTO_API_VERSION=14 536*0b57cec5SDimitry Andric */ 537*0b57cec5SDimitry Andric extern void 538*0b57cec5SDimitry Andric lto_codegen_set_should_internalize(lto_code_gen_t cg, 539*0b57cec5SDimitry Andric lto_bool_t ShouldInternalize); 540*0b57cec5SDimitry Andric 541*0b57cec5SDimitry Andric /** 542*0b57cec5SDimitry Andric * Set whether to embed uselists in bitcode. 543*0b57cec5SDimitry Andric * 544*0b57cec5SDimitry Andric * Sets whether \a lto_codegen_write_merged_modules() should embed uselists in 545*0b57cec5SDimitry Andric * output bitcode. This should be turned on for all -save-temps output. 546*0b57cec5SDimitry Andric * 547*0b57cec5SDimitry Andric * \since LTO_API_VERSION=15 548*0b57cec5SDimitry Andric */ 549*0b57cec5SDimitry Andric extern void 550*0b57cec5SDimitry Andric lto_codegen_set_should_embed_uselists(lto_code_gen_t cg, 551*0b57cec5SDimitry Andric lto_bool_t ShouldEmbedUselists); 552*0b57cec5SDimitry Andric 553*0b57cec5SDimitry Andric /** 554*0b57cec5SDimitry Andric * @} // endgoup LLVMCLTO 555*0b57cec5SDimitry Andric * @defgroup LLVMCTLTO ThinLTO 556*0b57cec5SDimitry Andric * @ingroup LLVMC 557*0b57cec5SDimitry Andric * 558*0b57cec5SDimitry Andric * @{ 559*0b57cec5SDimitry Andric */ 560*0b57cec5SDimitry Andric 561*0b57cec5SDimitry Andric /** 562*0b57cec5SDimitry Andric * Type to wrap a single object returned by ThinLTO. 563*0b57cec5SDimitry Andric * 564*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 565*0b57cec5SDimitry Andric */ 566*0b57cec5SDimitry Andric typedef struct { 567*0b57cec5SDimitry Andric const char *Buffer; 568*0b57cec5SDimitry Andric size_t Size; 569*0b57cec5SDimitry Andric } LTOObjectBuffer; 570*0b57cec5SDimitry Andric 571*0b57cec5SDimitry Andric /** 572*0b57cec5SDimitry Andric * Instantiates a ThinLTO code generator. 573*0b57cec5SDimitry Andric * Returns NULL on error (check lto_get_error_message() for details). 574*0b57cec5SDimitry Andric * 575*0b57cec5SDimitry Andric * 576*0b57cec5SDimitry Andric * The ThinLTOCodeGenerator is not intended to be reuse for multiple 577*0b57cec5SDimitry Andric * compilation: the model is that the client adds modules to the generator and 578*0b57cec5SDimitry Andric * ask to perform the ThinLTO optimizations / codegen, and finally destroys the 579*0b57cec5SDimitry Andric * codegenerator. 580*0b57cec5SDimitry Andric * 581*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 582*0b57cec5SDimitry Andric */ 583*0b57cec5SDimitry Andric extern thinlto_code_gen_t thinlto_create_codegen(void); 584*0b57cec5SDimitry Andric 585*0b57cec5SDimitry Andric /** 586*0b57cec5SDimitry Andric * Frees the generator and all memory it internally allocated. 587*0b57cec5SDimitry Andric * Upon return the thinlto_code_gen_t is no longer valid. 588*0b57cec5SDimitry Andric * 589*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 590*0b57cec5SDimitry Andric */ 591*0b57cec5SDimitry Andric extern void thinlto_codegen_dispose(thinlto_code_gen_t cg); 592*0b57cec5SDimitry Andric 593*0b57cec5SDimitry Andric /** 594*0b57cec5SDimitry Andric * Add a module to a ThinLTO code generator. Identifier has to be unique among 595*0b57cec5SDimitry Andric * all the modules in a code generator. The data buffer stays owned by the 596*0b57cec5SDimitry Andric * client, and is expected to be available for the entire lifetime of the 597*0b57cec5SDimitry Andric * thinlto_code_gen_t it is added to. 598*0b57cec5SDimitry Andric * 599*0b57cec5SDimitry Andric * On failure, returns NULL (check lto_get_error_message() for details). 600*0b57cec5SDimitry Andric * 601*0b57cec5SDimitry Andric * 602*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 603*0b57cec5SDimitry Andric */ 604*0b57cec5SDimitry Andric extern void thinlto_codegen_add_module(thinlto_code_gen_t cg, 605*0b57cec5SDimitry Andric const char *identifier, const char *data, 606*0b57cec5SDimitry Andric int length); 607*0b57cec5SDimitry Andric 608*0b57cec5SDimitry Andric /** 609*0b57cec5SDimitry Andric * Optimize and codegen all the modules added to the codegenerator using 610*0b57cec5SDimitry Andric * ThinLTO. Resulting objects are accessible using thinlto_module_get_object(). 611*0b57cec5SDimitry Andric * 612*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 613*0b57cec5SDimitry Andric */ 614*0b57cec5SDimitry Andric extern void thinlto_codegen_process(thinlto_code_gen_t cg); 615*0b57cec5SDimitry Andric 616*0b57cec5SDimitry Andric /** 617*0b57cec5SDimitry Andric * Returns the number of object files produced by the ThinLTO CodeGenerator. 618*0b57cec5SDimitry Andric * 619*0b57cec5SDimitry Andric * It usually matches the number of input files, but this is not a guarantee of 620*0b57cec5SDimitry Andric * the API and may change in future implementation, so the client should not 621*0b57cec5SDimitry Andric * assume it. 622*0b57cec5SDimitry Andric * 623*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 624*0b57cec5SDimitry Andric */ 625*0b57cec5SDimitry Andric extern unsigned int thinlto_module_get_num_objects(thinlto_code_gen_t cg); 626*0b57cec5SDimitry Andric 627*0b57cec5SDimitry Andric /** 628*0b57cec5SDimitry Andric * Returns a reference to the ith object file produced by the ThinLTO 629*0b57cec5SDimitry Andric * CodeGenerator. 630*0b57cec5SDimitry Andric * 631*0b57cec5SDimitry Andric * Client should use \p thinlto_module_get_num_objects() to get the number of 632*0b57cec5SDimitry Andric * available objects. 633*0b57cec5SDimitry Andric * 634*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 635*0b57cec5SDimitry Andric */ 636*0b57cec5SDimitry Andric extern LTOObjectBuffer thinlto_module_get_object(thinlto_code_gen_t cg, 637*0b57cec5SDimitry Andric unsigned int index); 638*0b57cec5SDimitry Andric 639*0b57cec5SDimitry Andric /** 640*0b57cec5SDimitry Andric * Returns the number of object files produced by the ThinLTO CodeGenerator. 641*0b57cec5SDimitry Andric * 642*0b57cec5SDimitry Andric * It usually matches the number of input files, but this is not a guarantee of 643*0b57cec5SDimitry Andric * the API and may change in future implementation, so the client should not 644*0b57cec5SDimitry Andric * assume it. 645*0b57cec5SDimitry Andric * 646*0b57cec5SDimitry Andric * \since LTO_API_VERSION=21 647*0b57cec5SDimitry Andric */ 648*0b57cec5SDimitry Andric unsigned int thinlto_module_get_num_object_files(thinlto_code_gen_t cg); 649*0b57cec5SDimitry Andric 650*0b57cec5SDimitry Andric /** 651*0b57cec5SDimitry Andric * Returns the path to the ith object file produced by the ThinLTO 652*0b57cec5SDimitry Andric * CodeGenerator. 653*0b57cec5SDimitry Andric * 654*0b57cec5SDimitry Andric * Client should use \p thinlto_module_get_num_object_files() to get the number 655*0b57cec5SDimitry Andric * of available objects. 656*0b57cec5SDimitry Andric * 657*0b57cec5SDimitry Andric * \since LTO_API_VERSION=21 658*0b57cec5SDimitry Andric */ 659*0b57cec5SDimitry Andric const char *thinlto_module_get_object_file(thinlto_code_gen_t cg, 660*0b57cec5SDimitry Andric unsigned int index); 661*0b57cec5SDimitry Andric 662*0b57cec5SDimitry Andric /** 663*0b57cec5SDimitry Andric * Sets which PIC code model to generate. 664*0b57cec5SDimitry Andric * Returns true on error (check lto_get_error_message() for details). 665*0b57cec5SDimitry Andric * 666*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 667*0b57cec5SDimitry Andric */ 668*0b57cec5SDimitry Andric extern lto_bool_t thinlto_codegen_set_pic_model(thinlto_code_gen_t cg, 669*0b57cec5SDimitry Andric lto_codegen_model); 670*0b57cec5SDimitry Andric 671*0b57cec5SDimitry Andric /** 672*0b57cec5SDimitry Andric * Sets the path to a directory to use as a storage for temporary bitcode files. 673*0b57cec5SDimitry Andric * The intention is to make the bitcode files available for debugging at various 674*0b57cec5SDimitry Andric * stage of the pipeline. 675*0b57cec5SDimitry Andric * 676*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 677*0b57cec5SDimitry Andric */ 678*0b57cec5SDimitry Andric extern void thinlto_codegen_set_savetemps_dir(thinlto_code_gen_t cg, 679*0b57cec5SDimitry Andric const char *save_temps_dir); 680*0b57cec5SDimitry Andric 681*0b57cec5SDimitry Andric /** 682*0b57cec5SDimitry Andric * Set the path to a directory where to save generated object files. This 683*0b57cec5SDimitry Andric * path can be used by a linker to request on-disk files instead of in-memory 684*0b57cec5SDimitry Andric * buffers. When set, results are available through 685*0b57cec5SDimitry Andric * thinlto_module_get_object_file() instead of thinlto_module_get_object(). 686*0b57cec5SDimitry Andric * 687*0b57cec5SDimitry Andric * \since LTO_API_VERSION=21 688*0b57cec5SDimitry Andric */ 689*0b57cec5SDimitry Andric void thinlto_set_generated_objects_dir(thinlto_code_gen_t cg, 690*0b57cec5SDimitry Andric const char *save_temps_dir); 691*0b57cec5SDimitry Andric 692*0b57cec5SDimitry Andric /** 693*0b57cec5SDimitry Andric * Sets the cpu to generate code for. 694*0b57cec5SDimitry Andric * 695*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 696*0b57cec5SDimitry Andric */ 697*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu); 698*0b57cec5SDimitry Andric 699*0b57cec5SDimitry Andric /** 700*0b57cec5SDimitry Andric * Disable CodeGen, only run the stages till codegen and stop. The output will 701*0b57cec5SDimitry Andric * be bitcode. 702*0b57cec5SDimitry Andric * 703*0b57cec5SDimitry Andric * \since LTO_API_VERSION=19 704*0b57cec5SDimitry Andric */ 705*0b57cec5SDimitry Andric extern void thinlto_codegen_disable_codegen(thinlto_code_gen_t cg, 706*0b57cec5SDimitry Andric lto_bool_t disable); 707*0b57cec5SDimitry Andric 708*0b57cec5SDimitry Andric /** 709*0b57cec5SDimitry Andric * Perform CodeGen only: disable all other stages. 710*0b57cec5SDimitry Andric * 711*0b57cec5SDimitry Andric * \since LTO_API_VERSION=19 712*0b57cec5SDimitry Andric */ 713*0b57cec5SDimitry Andric extern void thinlto_codegen_set_codegen_only(thinlto_code_gen_t cg, 714*0b57cec5SDimitry Andric lto_bool_t codegen_only); 715*0b57cec5SDimitry Andric 716*0b57cec5SDimitry Andric /** 717*0b57cec5SDimitry Andric * Parse -mllvm style debug options. 718*0b57cec5SDimitry Andric * 719*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 720*0b57cec5SDimitry Andric */ 721*0b57cec5SDimitry Andric extern void thinlto_debug_options(const char *const *options, int number); 722*0b57cec5SDimitry Andric 723*0b57cec5SDimitry Andric /** 724*0b57cec5SDimitry Andric * Test if a module has support for ThinLTO linking. 725*0b57cec5SDimitry Andric * 726*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 727*0b57cec5SDimitry Andric */ 728*0b57cec5SDimitry Andric extern lto_bool_t lto_module_is_thinlto(lto_module_t mod); 729*0b57cec5SDimitry Andric 730*0b57cec5SDimitry Andric /** 731*0b57cec5SDimitry Andric * Adds a symbol to the list of global symbols that must exist in the final 732*0b57cec5SDimitry Andric * generated code. If a function is not listed there, it might be inlined into 733*0b57cec5SDimitry Andric * every usage and optimized away. For every single module, the functions 734*0b57cec5SDimitry Andric * referenced from code outside of the ThinLTO modules need to be added here. 735*0b57cec5SDimitry Andric * 736*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 737*0b57cec5SDimitry Andric */ 738*0b57cec5SDimitry Andric extern void thinlto_codegen_add_must_preserve_symbol(thinlto_code_gen_t cg, 739*0b57cec5SDimitry Andric const char *name, 740*0b57cec5SDimitry Andric int length); 741*0b57cec5SDimitry Andric 742*0b57cec5SDimitry Andric /** 743*0b57cec5SDimitry Andric * Adds a symbol to the list of global symbols that are cross-referenced between 744*0b57cec5SDimitry Andric * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every 745*0b57cec5SDimitry Andric * references from a ThinLTO module to this symbol is optimized away, then 746*0b57cec5SDimitry Andric * the symbol can be discarded. 747*0b57cec5SDimitry Andric * 748*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 749*0b57cec5SDimitry Andric */ 750*0b57cec5SDimitry Andric extern void thinlto_codegen_add_cross_referenced_symbol(thinlto_code_gen_t cg, 751*0b57cec5SDimitry Andric const char *name, 752*0b57cec5SDimitry Andric int length); 753*0b57cec5SDimitry Andric 754*0b57cec5SDimitry Andric /** 755*0b57cec5SDimitry Andric * @} // endgoup LLVMCTLTO 756*0b57cec5SDimitry Andric * @defgroup LLVMCTLTO_CACHING ThinLTO Cache Control 757*0b57cec5SDimitry Andric * @ingroup LLVMCTLTO 758*0b57cec5SDimitry Andric * 759*0b57cec5SDimitry Andric * These entry points control the ThinLTO cache. The cache is intended to 760*0b57cec5SDimitry Andric * support incremental builds, and thus needs to be persistent across builds. 761*0b57cec5SDimitry Andric * The client enables the cache by supplying a path to an existing directory. 762*0b57cec5SDimitry Andric * The code generator will use this to store objects files that may be reused 763*0b57cec5SDimitry Andric * during a subsequent build. 764*0b57cec5SDimitry Andric * To avoid filling the disk space, a few knobs are provided: 765*0b57cec5SDimitry Andric * - The pruning interval limits the frequency at which the garbage collector 766*0b57cec5SDimitry Andric * will try to scan the cache directory to prune expired entries. 767*0b57cec5SDimitry Andric * Setting to a negative number disables the pruning. 768*0b57cec5SDimitry Andric * - The pruning expiration time indicates to the garbage collector how old an 769*0b57cec5SDimitry Andric * entry needs to be to be removed. 770*0b57cec5SDimitry Andric * - Finally, the garbage collector can be instructed to prune the cache until 771*0b57cec5SDimitry Andric * the occupied space goes below a threshold. 772*0b57cec5SDimitry Andric * @{ 773*0b57cec5SDimitry Andric */ 774*0b57cec5SDimitry Andric 775*0b57cec5SDimitry Andric /** 776*0b57cec5SDimitry Andric * Sets the path to a directory to use as a cache storage for incremental build. 777*0b57cec5SDimitry Andric * Setting this activates caching. 778*0b57cec5SDimitry Andric * 779*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 780*0b57cec5SDimitry Andric */ 781*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg, 782*0b57cec5SDimitry Andric const char *cache_dir); 783*0b57cec5SDimitry Andric 784*0b57cec5SDimitry Andric /** 785*0b57cec5SDimitry Andric * Sets the cache pruning interval (in seconds). A negative value disables the 786*0b57cec5SDimitry Andric * pruning. An unspecified default value will be applied, and a value of 0 will 787*0b57cec5SDimitry Andric * force prunning to occur. 788*0b57cec5SDimitry Andric * 789*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 790*0b57cec5SDimitry Andric */ 791*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_pruning_interval(thinlto_code_gen_t cg, 792*0b57cec5SDimitry Andric int interval); 793*0b57cec5SDimitry Andric 794*0b57cec5SDimitry Andric /** 795*0b57cec5SDimitry Andric * Sets the maximum cache size that can be persistent across build, in terms of 796*0b57cec5SDimitry Andric * percentage of the available space on the disk. Set to 100 to indicate 797*0b57cec5SDimitry Andric * no limit, 50 to indicate that the cache size will not be left over half the 798*0b57cec5SDimitry Andric * available space. A value over 100 will be reduced to 100, a value of 0 will 799*0b57cec5SDimitry Andric * be ignored. An unspecified default value will be applied. 800*0b57cec5SDimitry Andric * 801*0b57cec5SDimitry Andric * The formula looks like: 802*0b57cec5SDimitry Andric * AvailableSpace = FreeSpace + ExistingCacheSize 803*0b57cec5SDimitry Andric * NewCacheSize = AvailableSpace * P/100 804*0b57cec5SDimitry Andric * 805*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 806*0b57cec5SDimitry Andric */ 807*0b57cec5SDimitry Andric extern void thinlto_codegen_set_final_cache_size_relative_to_available_space( 808*0b57cec5SDimitry Andric thinlto_code_gen_t cg, unsigned percentage); 809*0b57cec5SDimitry Andric 810*0b57cec5SDimitry Andric /** 811*0b57cec5SDimitry Andric * Sets the expiration (in seconds) for an entry in the cache. An unspecified 812*0b57cec5SDimitry Andric * default value will be applied. A value of 0 will be ignored. 813*0b57cec5SDimitry Andric * 814*0b57cec5SDimitry Andric * \since LTO_API_VERSION=18 815*0b57cec5SDimitry Andric */ 816*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_entry_expiration(thinlto_code_gen_t cg, 817*0b57cec5SDimitry Andric unsigned expiration); 818*0b57cec5SDimitry Andric 819*0b57cec5SDimitry Andric /** 820*0b57cec5SDimitry Andric * Sets the maximum size of the cache directory (in bytes). A value over the 821*0b57cec5SDimitry Andric * amount of available space on the disk will be reduced to the amount of 822*0b57cec5SDimitry Andric * available space. An unspecified default value will be applied. A value of 0 823*0b57cec5SDimitry Andric * will be ignored. 824*0b57cec5SDimitry Andric * 825*0b57cec5SDimitry Andric * \since LTO_API_VERSION=22 826*0b57cec5SDimitry Andric */ 827*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_size_bytes(thinlto_code_gen_t cg, 828*0b57cec5SDimitry Andric unsigned max_size_bytes); 829*0b57cec5SDimitry Andric 830*0b57cec5SDimitry Andric /** 831*0b57cec5SDimitry Andric * Same as thinlto_codegen_set_cache_size_bytes, except the maximum size is in 832*0b57cec5SDimitry Andric * megabytes (2^20 bytes). 833*0b57cec5SDimitry Andric * 834*0b57cec5SDimitry Andric * \since LTO_API_VERSION=23 835*0b57cec5SDimitry Andric */ 836*0b57cec5SDimitry Andric extern void 837*0b57cec5SDimitry Andric thinlto_codegen_set_cache_size_megabytes(thinlto_code_gen_t cg, 838*0b57cec5SDimitry Andric unsigned max_size_megabytes); 839*0b57cec5SDimitry Andric 840*0b57cec5SDimitry Andric /** 841*0b57cec5SDimitry Andric * Sets the maximum number of files in the cache directory. An unspecified 842*0b57cec5SDimitry Andric * default value will be applied. A value of 0 will be ignored. 843*0b57cec5SDimitry Andric * 844*0b57cec5SDimitry Andric * \since LTO_API_VERSION=22 845*0b57cec5SDimitry Andric */ 846*0b57cec5SDimitry Andric extern void thinlto_codegen_set_cache_size_files(thinlto_code_gen_t cg, 847*0b57cec5SDimitry Andric unsigned max_size_files); 848*0b57cec5SDimitry Andric 849*0b57cec5SDimitry Andric /** Opaque reference to an LTO input file */ 850*0b57cec5SDimitry Andric typedef struct LLVMOpaqueLTOInput *lto_input_t; 851*0b57cec5SDimitry Andric 852*0b57cec5SDimitry Andric /** 853*0b57cec5SDimitry Andric * Creates an LTO input file from a buffer. The path 854*0b57cec5SDimitry Andric * argument is used for diagnotics as this function 855*0b57cec5SDimitry Andric * otherwise does not know which file the given buffer 856*0b57cec5SDimitry Andric * is associated with. 857*0b57cec5SDimitry Andric * 858*0b57cec5SDimitry Andric * \since LTO_API_VERSION=24 859*0b57cec5SDimitry Andric */ 860*0b57cec5SDimitry Andric extern lto_input_t lto_input_create(const void *buffer, 861*0b57cec5SDimitry Andric size_t buffer_size, 862*0b57cec5SDimitry Andric const char *path); 863*0b57cec5SDimitry Andric 864*0b57cec5SDimitry Andric /** 865*0b57cec5SDimitry Andric * Frees all memory internally allocated by the LTO input file. 866*0b57cec5SDimitry Andric * Upon return the lto_module_t is no longer valid. 867*0b57cec5SDimitry Andric * 868*0b57cec5SDimitry Andric * \since LTO_API_VERSION=24 869*0b57cec5SDimitry Andric */ 870*0b57cec5SDimitry Andric extern void lto_input_dispose(lto_input_t input); 871*0b57cec5SDimitry Andric 872*0b57cec5SDimitry Andric /** 873*0b57cec5SDimitry Andric * Returns the number of dependent library specifiers 874*0b57cec5SDimitry Andric * for the given LTO input file. 875*0b57cec5SDimitry Andric * 876*0b57cec5SDimitry Andric * \since LTO_API_VERSION=24 877*0b57cec5SDimitry Andric */ 878*0b57cec5SDimitry Andric extern unsigned lto_input_get_num_dependent_libraries(lto_input_t input); 879*0b57cec5SDimitry Andric 880*0b57cec5SDimitry Andric /** 881*0b57cec5SDimitry Andric * Returns the ith dependent library specifier 882*0b57cec5SDimitry Andric * for the given LTO input file. The returned 883*0b57cec5SDimitry Andric * string is not null-terminated. 884*0b57cec5SDimitry Andric * 885*0b57cec5SDimitry Andric * \since LTO_API_VERSION=24 886*0b57cec5SDimitry Andric */ 887*0b57cec5SDimitry Andric extern const char * lto_input_get_dependent_library(lto_input_t input, 888*0b57cec5SDimitry Andric size_t index, 889*0b57cec5SDimitry Andric size_t *size); 890*0b57cec5SDimitry Andric 891*0b57cec5SDimitry Andric /** 892*0b57cec5SDimitry Andric * @} // endgroup LLVMCTLTO_CACHING 893*0b57cec5SDimitry Andric */ 894*0b57cec5SDimitry Andric 895*0b57cec5SDimitry Andric #ifdef __cplusplus 896*0b57cec5SDimitry Andric } 897*0b57cec5SDimitry Andric #endif 898*0b57cec5SDimitry Andric 899*0b57cec5SDimitry Andric #endif /* LLVM_C_LTO_H */ 900