lto.h revision b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5
177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\
277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                                                                            *|
377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                     The LLVM Compiler Infrastructure                       *|
477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                                                                            *|
577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|* This file is distributed under the University of Illinois Open Source      *|
677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|* License. See LICENSE.TXT for details.                                      *|
777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                                                                            *|
877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*===----------------------------------------------------------------------===*|
977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                                                                            *|
1077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|* This header provides public interface to an abstract link time optimization*|
1177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|* library.  LLVM provides an implementation of this interface for use with   *|
1277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|* llvm bitcode files.                                                        *|
1377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik|*                                                                            *|
1477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik\*===----------------------------------------------------------------------===*/
1577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
1677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#ifndef LTO_H
1777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#define LTO_H  1
1877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
1977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#include <stdbool.h>
2077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#include <stddef.h>
21b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola#include <unistd.h>
2277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
237afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling#define LTO_API_VERSION 4
24cbad58624090933cb8fb85587e03be613a481309Nick Kledzik
2577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziktypedef enum {
267afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_ALIGNMENT_MASK              = 0x0000001F, /* log2 of alignment */
277afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_PERMISSIONS_MASK            = 0x000000E0,
287afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_PERMISSIONS_CODE            = 0x000000A0,
297afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_PERMISSIONS_DATA            = 0x000000C0,
307afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_PERMISSIONS_RODATA          = 0x00000080,
317afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_MASK             = 0x00000700,
327afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_REGULAR          = 0x00000100,
337afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_TENTATIVE        = 0x00000200,
347afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_WEAK             = 0x00000300,
357afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_UNDEFINED        = 0x00000400,
367afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_DEFINITION_WEAKUNDEF        = 0x00000500,
377afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_MASK                  = 0x00003800,
387afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_INTERNAL              = 0x00000800,
397afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_HIDDEN                = 0x00001000,
407afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_PROTECTED             = 0x00002000,
417afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_DEFAULT               = 0x00001800,
427afea0cfc4abebaf4cadcc37acd30fb251a5faf3Bill Wendling    LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800
4377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik} lto_symbol_attributes;
4477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
4577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziktypedef enum {
4677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik    LTO_DEBUG_MODEL_NONE         = 0,
4777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik    LTO_DEBUG_MODEL_DWARF        = 1
4877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik} lto_debug_model;
4977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
5077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziktypedef enum {
5177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik    LTO_CODEGEN_PIC_MODEL_STATIC         = 0,
5277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik    LTO_CODEGEN_PIC_MODEL_DYNAMIC        = 1,
5377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik    LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
5477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik} lto_codegen_model;
5577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
5677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
5777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/** opaque reference to a loaded object module */
5877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziktypedef struct LTOModule*         lto_module_t;
5977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
6077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/** opaque reference to a code generator */
6177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziktypedef struct LTOCodeGenerator*  lto_code_gen_t;
6277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
6377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#ifdef __cplusplus
6477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern "C" {
6577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#endif
6677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
6777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
6877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns a printable string.
6977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
7077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern const char*
7116c1f44d91211a225497062ea508d58fd25085a9Gordon Henriksenlto_get_version(void);
7277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
7377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
7477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
7577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns the last error string or NULL if last operation was sucessful.
7677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
7777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern const char*
7816c1f44d91211a225497062ea508d58fd25085a9Gordon Henriksenlto_get_error_message(void);
7977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
8077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
8177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Checks if a file is a loadable object file.
8277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
8377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
8477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_is_object_file(const char* path);
8577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
8677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
8777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
8877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Checks if a file is a loadable object compiled for requested target.
8977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
9077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
9177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_is_object_file_for_target(const char* path,
92b454eabe7ff0824356ccdb75459a0312f43254c1Nick Lewycky                                     const char* target_triple_prefix);
9377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
9477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
9577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
9677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Checks if a buffer is a loadable object file.
9777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
9877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
9977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_is_object_file_in_memory(const void* mem, size_t length);
10077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
10177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
10277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
10377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Checks if a buffer is a loadable object compiled for requested target.
10477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
10577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
10677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_is_object_file_in_memory_for_target(const void* mem, size_t length,
107ca3ca138d88139e24a8e60fef982436575a19f38Eric Christopher                                              const char* target_triple_prefix);
10877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
10977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
11077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
11177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Loads an object file from disk.
11277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns NULL on error (check lto_get_error_message() for details).
11377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
11477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern lto_module_t
1150e7a54672cf346ee7c4aae10822c74f7c74f3fedOwen Andersonlto_module_create(const char* path);
11677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
11777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
11877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
11977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Loads an object file from memory.
12077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns NULL on error (check lto_get_error_message() for details).
12177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
12277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern lto_module_t
1230e7a54672cf346ee7c4aae10822c74f7c74f3fedOwen Andersonlto_module_create_from_memory(const void* mem, size_t length);
12477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
125b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola/**
126b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola * Loads an object file from disk. The seek point of fd is not preserved.
127b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola * Returns NULL on error (check lto_get_error_message() for details).
128b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola */
129b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindolaextern lto_module_t
130b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindolalto_module_create_from_fd(int fd, const char *path, off_t size);
131b4cc031a3e1306fea74c9211d50c5cde6d9a8cd5Rafael Espindola
13277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
13377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
13477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Frees all memory internally allocated by the module.
13577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Upon return the lto_module_t is no longer valid.
13677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
13777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern void
13877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_dispose(lto_module_t mod);
13977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
14077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
14177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
14277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns triple string which the object module was compiled under.
14377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
14477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern const char*
14577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_get_target_triple(lto_module_t mod);
14677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
147cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindola/**
148cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindola * Sets triple string with which the object will be codegened.
149cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindola */
150cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindolaextern void
151cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindolalto_module_set_target_triple(lto_module_t mod, const char *triple);
152cbb170d057aa6692b19f577b1e09a6c1c7a26969Rafael Espindola
15377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
15477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
15577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns the number of symbols in the object module.
15677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
1576a6623c596fc12f64c813ea14a006ac6da3e33feDevang Patelextern unsigned int
15877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_module_get_num_symbols(lto_module_t mod);
15977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
16077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
16177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
16277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns the name of the ith symbol in the object module.
16377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
16477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern const char*
1656a6623c596fc12f64c813ea14a006ac6da3e33feDevang Patellto_module_get_symbol_name(lto_module_t mod, unsigned int index);
16677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
16777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
16877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
16977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns the attributes of the ith symbol in the object module.
17077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
17177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern lto_symbol_attributes
1726a6623c596fc12f64c813ea14a006ac6da3e33feDevang Patellto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
17377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
17477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
17577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
17677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Instantiates a code generator.
17777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns NULL on error (check lto_get_error_message() for details).
17877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
17977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern lto_code_gen_t
1800e7a54672cf346ee7c4aae10822c74f7c74f3fedOwen Andersonlto_codegen_create(void);
18177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
18277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
18377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
18477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Frees all code generator and all memory it internally allocated.
18577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Upon return the lto_code_gen_t is no longer valid.
18677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
18777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern void
18877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_dispose(lto_code_gen_t);
18977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
19077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
19177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
19277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
19377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Add an object module to the set of modules for which code will be generated.
19477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns true on error (check lto_get_error_message() for details).
19577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
19677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
19777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
19877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
19977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
20077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
20177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
20277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Sets if debug info should be generated.
20377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns true on error (check lto_get_error_message() for details).
20477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
20577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
20677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
20777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
20877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
20977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
21077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Sets which PIC code model to generated.
21177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns true on error (check lto_get_error_message() for details).
21277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
21377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
21477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
21577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
21677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
21777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
2182d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindola * Sets the cpu to generate code for.
2192d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindola */
2202d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindolaextern void
2212d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindolalto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu);
2222d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindola
2232d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindola
2242d643ef32891859ec73b6eea2959748f5ebc3af7Rafael Espindola/**
225cbad58624090933cb8fb85587e03be613a481309Nick Kledzik * Sets the location of the assembler tool to run. If not set, libLTO
226cbad58624090933cb8fb85587e03be613a481309Nick Kledzik * will use gcc to invoke the assembler.
227cbad58624090933cb8fb85587e03be613a481309Nick Kledzik */
228cbad58624090933cb8fb85587e03be613a481309Nick Kledzikextern void
229cbad58624090933cb8fb85587e03be613a481309Nick Kledziklto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
230cbad58624090933cb8fb85587e03be613a481309Nick Kledzik
23198197e55c10176c3ef9100f7d852abbd2347225fRafael Espindola/**
23298197e55c10176c3ef9100f7d852abbd2347225fRafael Espindola * Sets extra arguments that libLTO should pass to the assembler.
23398197e55c10176c3ef9100f7d852abbd2347225fRafael Espindola */
23498197e55c10176c3ef9100f7d852abbd2347225fRafael Espindolaextern void
23598197e55c10176c3ef9100f7d852abbd2347225fRafael Espindolalto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
23698197e55c10176c3ef9100f7d852abbd2347225fRafael Espindola                               int nargs);
237cbad58624090933cb8fb85587e03be613a481309Nick Kledzik
238cbad58624090933cb8fb85587e03be613a481309Nick Kledzik/**
23977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Adds to a list of all global symbols that must exist in the final
24077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * generated code.  If a function is not listed, it might be
24177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * inlined into every usage and optimized away.
24277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
24377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern void
24477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
24577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
24677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
24777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
24877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Writes a new object file at the specified path that contains the
24977595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * merged contents of all modules added so far.
25077595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Returns true on error (check lto_get_error_message() for details).
25177595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
25277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzikextern bool
25377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
25477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
25577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
25677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik/**
25777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * Generates code for all added modules into one native object file.
25877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * On sucess returns a pointer to a generated mach-o/ELF buffer and
259ef194ed74033eba099f4f391ffdfc176f9aa6f26Nick Kledzik * length set to the buffer size.  The buffer is owned by the
260ef194ed74033eba099f4f391ffdfc176f9aa6f26Nick Kledzik * lto_code_gen_t and will be freed when lto_codegen_dispose()
261ef194ed74033eba099f4f391ffdfc176f9aa6f26Nick Kledzik * is called, or lto_codegen_compile() is called again.
26277595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik * On failure, returns NULL (check lto_get_error_message() for details).
26377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik */
264ef194ed74033eba099f4f391ffdfc176f9aa6f26Nick Kledzikextern const void*
26577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledziklto_codegen_compile(lto_code_gen_t cg, size_t* length);
26677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
26777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
268a93ae711a91dd151ca4d28e4172e0de89d1594f3Devang Patel/**
269a93ae711a91dd151ca4d28e4172e0de89d1594f3Devang Patel * Sets options to help debug codegen bugs.
270a93ae711a91dd151ca4d28e4172e0de89d1594f3Devang Patel */
271a93ae711a91dd151ca4d28e4172e0de89d1594f3Devang Patelextern void
272a93ae711a91dd151ca4d28e4172e0de89d1594f3Devang Patellto_codegen_debug_options(lto_code_gen_t cg, const char *);
27377595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#ifdef __cplusplus
27477595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik}
27577595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#endif
27677595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
27777595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik
27877595fc35642f990bfc5ad05b8e68d4056695ecaNick Kledzik#endif
279