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