LLVM API Documentation

lto.h

Go to the documentation of this file.
00001 /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header provides public interface to an abstract link time optimization*|
00011 |* library.  LLVM provides an implementation of this interface for use with   *|
00012 |* llvm bitcode files.                                                        *|
00013 |*                                                                            *|
00014 \*===----------------------------------------------------------------------===*/
00015 
00016 #ifndef LTO_H
00017 #define LTO_H  1
00018 
00019 #include <stdbool.h>
00020 #include <stddef.h>
00021 
00022 typedef enum {
00023     LTO_SYMBOL_ALIGNMENT_MASK         = 0x0000001F,    /* log2 of alignment */
00024     LTO_SYMBOL_PERMISSIONS_MASK       = 0x000000E0,    
00025     LTO_SYMBOL_PERMISSIONS_CODE       = 0x000000A0,    
00026     LTO_SYMBOL_PERMISSIONS_DATA       = 0x000000C0,    
00027     LTO_SYMBOL_PERMISSIONS_RODATA     = 0x00000080,    
00028     LTO_SYMBOL_DEFINITION_MASK        = 0x00000700,    
00029     LTO_SYMBOL_DEFINITION_REGULAR     = 0x00000100,    
00030     LTO_SYMBOL_DEFINITION_TENTATIVE   = 0x00000200,    
00031     LTO_SYMBOL_DEFINITION_WEAK        = 0x00000300,    
00032     LTO_SYMBOL_DEFINITION_UNDEFINED   = 0x00000400,    
00033     LTO_SYMBOL_SCOPE_MASK             = 0x00003800,    
00034     LTO_SYMBOL_SCOPE_INTERNAL         = 0x00000800,    
00035     LTO_SYMBOL_SCOPE_HIDDEN           = 0x00001000,    
00036     LTO_SYMBOL_SCOPE_PROTECTED        = 0x00002000,    
00037     LTO_SYMBOL_SCOPE_DEFAULT          = 0x00001800    
00038 } lto_symbol_attributes;
00039 
00040 typedef enum {
00041     LTO_DEBUG_MODEL_NONE         = 0,
00042     LTO_DEBUG_MODEL_DWARF        = 1
00043 } lto_debug_model;
00044 
00045 typedef enum {
00046     LTO_CODEGEN_PIC_MODEL_STATIC         = 0,
00047     LTO_CODEGEN_PIC_MODEL_DYNAMIC        = 1,
00048     LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
00049 } lto_codegen_model;
00050 
00051 
00052 /** opaque reference to a loaded object module */
00053 typedef struct LTOModule*         lto_module_t;
00054 
00055 /** opaque reference to a code generator */
00056 typedef struct LTOCodeGenerator*  lto_code_gen_t;
00057 
00058 
00059 #ifdef __cplusplus
00060 extern "C" {
00061 #endif
00062 
00063 /**
00064  * Returns a printable string.
00065  */
00066 extern const char*
00067 lto_get_version(void);
00068 
00069 
00070 /**
00071  * Returns the last error string or NULL if last operation was sucessful.
00072  */
00073 extern const char*
00074 lto_get_error_message(void);
00075 
00076 
00077 /**
00078  * Checks if a file is a loadable object file.
00079  */
00080 extern bool
00081 lto_module_is_object_file(const char* path);
00082 
00083 
00084 /**
00085  * Checks if a file is a loadable object compiled for requested target.
00086  */
00087 extern bool
00088 lto_module_is_object_file_for_target(const char* path, 
00089                                             const char* target_triple_prefix);
00090 
00091 
00092 /**
00093  * Checks if a buffer is a loadable object file.
00094  */
00095 extern bool
00096 lto_module_is_object_file_in_memory(const void* mem, size_t length);
00097 
00098 
00099 /**
00100  * Checks if a buffer is a loadable object compiled for requested target.
00101  */
00102 extern bool
00103 lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 
00104                                                const char* target_triple_prefix);
00105 
00106 
00107 /**
00108  * Loads an object file from disk.
00109  * Returns NULL on error (check lto_get_error_message() for details).
00110  */
00111 extern lto_module_t
00112 lto_module_create(const char* path);
00113 
00114 
00115 /**
00116  * Loads an object file from memory.
00117  * Returns NULL on error (check lto_get_error_message() for details).
00118  */
00119 extern lto_module_t
00120 lto_module_create_from_memory(const void* mem, size_t length);
00121 
00122 
00123 /**
00124  * Frees all memory internally allocated by the module.
00125  * Upon return the lto_module_t is no longer valid.
00126  */
00127 extern void
00128 lto_module_dispose(lto_module_t mod);
00129 
00130 
00131 /**
00132  * Returns triple string which the object module was compiled under.
00133  */
00134 extern const char*
00135 lto_module_get_target_triple(lto_module_t mod);
00136 
00137 
00138 /**
00139  * Returns the number of symbols in the object module.
00140  */
00141 extern unsigned int
00142 lto_module_get_num_symbols(lto_module_t mod);
00143 
00144 
00145 /**
00146  * Returns the name of the ith symbol in the object module.
00147  */
00148 extern const char*
00149 lto_module_get_symbol_name(lto_module_t mod, unsigned int index);
00150 
00151 
00152 /**
00153  * Returns the attributes of the ith symbol in the object module.
00154  */
00155 extern lto_symbol_attributes
00156 lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index);
00157 
00158 
00159 /**
00160  * Instantiates a code generator.
00161  * Returns NULL on error (check lto_get_error_message() for details).
00162  */
00163 extern lto_code_gen_t
00164 lto_codegen_create(void);
00165 
00166 
00167 /**
00168  * Frees all code generator and all memory it internally allocated.
00169  * Upon return the lto_code_gen_t is no longer valid.
00170  */
00171 extern void
00172 lto_codegen_dispose(lto_code_gen_t);
00173 
00174 
00175 
00176 /**
00177  * Add an object module to the set of modules for which code will be generated.
00178  * Returns true on error (check lto_get_error_message() for details).
00179  */
00180 extern bool
00181 lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod);
00182 
00183 
00184 
00185 /**
00186  * Sets if debug info should be generated.
00187  * Returns true on error (check lto_get_error_message() for details).
00188  */
00189 extern bool
00190 lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model);
00191 
00192 
00193 /**
00194  * Sets which PIC code model to generated.
00195  * Returns true on error (check lto_get_error_message() for details).
00196  */
00197 extern bool
00198 lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
00199 
00200 
00201 /**
00202  * Adds to a list of all global symbols that must exist in the final
00203  * generated code.  If a function is not listed, it might be
00204  * inlined into every usage and optimized away.
00205  */
00206 extern void
00207 lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol);
00208 
00209 
00210 /**
00211  * Writes a new object file at the specified path that contains the
00212  * merged contents of all modules added so far.
00213  * Returns true on error (check lto_get_error_message() for details).
00214  */
00215 extern bool
00216 lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path);
00217 
00218 
00219 /**
00220  * Generates code for all added modules into one native object file.
00221  * On sucess returns a pointer to a generated mach-o/ELF buffer and
00222  * length set to the buffer size.  The buffer is owned by the 
00223  * lto_code_gen_t and will be freed when lto_codegen_dispose()
00224  * is called, or lto_codegen_compile() is called again.
00225  * On failure, returns NULL (check lto_get_error_message() for details).
00226  */
00227 extern const void*
00228 lto_codegen_compile(lto_code_gen_t cg, size_t* length);
00229 
00230 
00231 /**
00232  * Sets options to help debug codegen bugs.
00233  */
00234 extern void
00235 lto_codegen_debug_options(lto_code_gen_t cg, const char *);
00236 #ifdef __cplusplus
00237 }
00238 #endif
00239 
00240 
00241 #endif



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.