1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                                                                            *|
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                     The LLVM Compiler Infrastructure                       *|
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                                                                            *|
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|* This file is distributed under the University of Illinois Open Source      *|
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|* License. See LICENSE.TXT for details.                                      *|
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                                                                            *|
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*===----------------------------------------------------------------------===*|
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                                                                            *|
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|* This header provides public interface to an abstract link time optimization*|
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|* library.  LLVM provides an implementation of this interface for use with   *|
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|* llvm bitcode files.                                                        *|
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman|*                                                                            *|
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman\*===----------------------------------------------------------------------===*/
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LTO_H
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LTO_H  1
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <stdbool.h>
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <stddef.h>
2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include <unistd.h>
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#define LTO_API_VERSION 4
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantypedef enum {
2619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_ALIGNMENT_MASK              = 0x0000001F, /* log2 of alignment */
2719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_PERMISSIONS_MASK            = 0x000000E0,
2819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_PERMISSIONS_CODE            = 0x000000A0,
2919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_PERMISSIONS_DATA            = 0x000000C0,
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_PERMISSIONS_RODATA          = 0x00000080,
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_MASK             = 0x00000700,
3219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_REGULAR          = 0x00000100,
3319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_TENTATIVE        = 0x00000200,
3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_WEAK             = 0x00000300,
3519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_UNDEFINED        = 0x00000400,
3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_DEFINITION_WEAKUNDEF        = 0x00000500,
3719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_MASK                  = 0x00003800,
3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_INTERNAL              = 0x00000800,
3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_HIDDEN                = 0x00001000,
4019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_PROTECTED             = 0x00002000,
4119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_DEFAULT               = 0x00001800,
4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} lto_symbol_attributes;
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantypedef enum {
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    LTO_DEBUG_MODEL_NONE         = 0,
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    LTO_DEBUG_MODEL_DWARF        = 1
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} lto_debug_model;
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantypedef enum {
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    LTO_CODEGEN_PIC_MODEL_STATIC         = 0,
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    LTO_CODEGEN_PIC_MODEL_DYNAMIC        = 1,
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} lto_codegen_model;
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/** opaque reference to a loaded object module */
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantypedef struct LTOModule*         lto_module_t;
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/** opaque reference to a code generator */
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumantypedef struct LTOCodeGenerator*  lto_code_gen_t;
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifdef __cplusplus
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern "C" {
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns a printable string.
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern const char*
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_get_version(void);
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Returns the last error string or NULL if last operation was successful.
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern const char*
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_get_error_message(void);
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Checks if a file is a loadable object file.
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_is_object_file(const char* path);
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Checks if a file is a loadable object compiled for requested target.
89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_is_object_file_for_target(const char* path,
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                     const char* target_triple_prefix);
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Checks if a buffer is a loadable object file.
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_is_object_file_in_memory(const void* mem, size_t length);
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Checks if a buffer is a loadable object compiled for requested target.
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                              const char* target_triple_prefix);
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Loads an object file from disk.
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns NULL on error (check lto_get_error_message() for details).
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern lto_module_t
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_create(const char* path);
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Loads an object file from memory.
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns NULL on error (check lto_get_error_message() for details).
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern lto_module_t
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_create_from_memory(const void* mem, size_t length);
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
12519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/**
12619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Loads an object file from disk. The seek point of fd is not preserved.
12719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Returns NULL on error (check lto_get_error_message() for details).
12819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman */
12919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanextern lto_module_t
13019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanlto_module_create_from_fd(int fd, const char *path, size_t file_size);
13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/**
13319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Loads an object file from disk. The seek point of fd is not preserved.
13419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Returns NULL on error (check lto_get_error_message() for details).
13519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman */
13619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanextern lto_module_t
13719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanlto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size,
13819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                                    size_t map_size, off_t offset);
13919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Frees all memory internally allocated by the module.
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Upon return the lto_module_t is no longer valid.
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_dispose(lto_module_t mod);
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns triple string which the object module was compiled under.
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern const char*
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_get_target_triple(lto_module_t mod);
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets triple string with which the object will be codegened.
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_set_target_triple(lto_module_t mod, const char *triple);
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns the number of symbols in the object module.
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern unsigned int
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_get_num_symbols(lto_module_t mod);
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns the name of the ith symbol in the object module.
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern const char*
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_get_symbol_name(lto_module_t mod, unsigned int index);
174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns the attributes of the ith symbol in the object module.
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern lto_symbol_attributes
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Instantiates a code generator.
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns NULL on error (check lto_get_error_message() for details).
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern lto_code_gen_t
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_create(void);
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Frees all code generator and all memory it internally allocated.
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Upon return the lto_code_gen_t is no longer valid.
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_dispose(lto_code_gen_t);
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Add an object module to the set of modules for which code will be generated.
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns true on error (check lto_get_error_message() for details).
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets if debug info should be generated.
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns true on error (check lto_get_error_message() for details).
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets which PIC code model to generated.
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns true on error (check lto_get_error_message() for details).
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets the cpu to generate code for.
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets the location of the assembler tool to run. If not set, libLTO
234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * will use gcc to invoke the assembler.
235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets extra arguments that libLTO should pass to the assembler.
241894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                               int nargs);
245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Adds to a list of all global symbols that must exist in the final
248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * generated code.  If a function is not listed, it might be
249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * inlined into every usage and optimized away.
250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Writes a new object file at the specified path that contains the
257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * merged contents of all modules added so far.
258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Returns true on error (check lto_get_error_message() for details).
259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern bool
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Generates code for all added modules into one native object file.
26619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * On success returns a pointer to a generated mach-o/ELF buffer and
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * length set to the buffer size.  The buffer is owned by the
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * lto_code_gen_t and will be freed when lto_codegen_dispose()
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * is called, or lto_codegen_compile() is called again.
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * On failure, returns NULL (check lto_get_error_message() for details).
271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern const void*
273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_compile(lto_code_gen_t cg, size_t* length);
274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman/**
27619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * Generates code for all added modules into one native object file.
27719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman * The name of the file is written to name. Returns true on error.
27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman */
27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanextern bool
28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanlto_codegen_compile_to_file(lto_code_gen_t cg, const char** name);
28119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/**
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman * Sets options to help debug codegen bugs.
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman */
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanextern void
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanlto_codegen_debug_options(lto_code_gen_t cg, const char *);
288894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifdef __cplusplus
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
294