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