llvm.org GIT mirror llvm / fcee722
Style update: don't duplicate comments, they were getting out of sync. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207909 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
2 changed file(s) with 3 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
402402 int nargs);
403403
404404 /**
405 * Tells LTO optimization passes that this symbol must be preserved
406 * because it is referenced by native code or a command line option.
405 * Adds to a list of all global symbols that must exist in the final generated
406 * code. If a function is not listed there, it might be inlined into every usage
407 * and optimized away.
407408 *
408409 * \since prior to LTO_API_VERSION=3
409410 */
6969 }
7070 }
7171
72 /// lto_get_version - Returns a printable string.
7372 extern const char* lto_get_version() {
7473 return LTOCodeGenerator::getVersionString();
7574 }
7675
77 /// lto_get_error_message - Returns the last error string or NULL if last
78 /// operation was successful.
7976 const char* lto_get_error_message() {
8077 return sLastErrorString.c_str();
8178 }
8279
83 /// lto_module_is_object_file - Validates if a file is a loadable object file.
8480 bool lto_module_is_object_file(const char* path) {
8581 return LTOModule::isBitcodeFile(path);
8682 }
8783
88 /// lto_module_is_object_file_for_target - Validates if a file is a loadable
89 /// object file compilable for requested target.
9084 bool lto_module_is_object_file_for_target(const char* path,
9185 const char* target_triplet_prefix) {
9286 return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix);
9387 }
9488
95 /// lto_module_is_object_file_in_memory - Validates if a buffer is a loadable
96 /// object file.
9789 bool lto_module_is_object_file_in_memory(const void* mem, size_t length) {
9890 return LTOModule::isBitcodeFile(mem, length);
9991 }
10092
101 /// lto_module_is_object_file_in_memory_for_target - Validates if a buffer is a
102 /// loadable object file compilable for the target.
10393 bool
10494 lto_module_is_object_file_in_memory_for_target(const void* mem,
10595 size_t length,
10797 return LTOModule::isBitcodeFileForTarget(mem, length, target_triplet_prefix);
10898 }
10999
110 /// lto_module_create - Loads an object file from disk. Returns NULL on error
111 /// (check lto_get_error_message() for details).
112100 lto_module_t lto_module_create(const char* path) {
113101 lto_initialize();
114102 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
115103 return LTOModule::makeLTOModule(path, Options, sLastErrorString);
116104 }
117105
118 /// lto_module_create_from_fd - Loads an object file from disk. Returns NULL on
119 /// error (check lto_get_error_message() for details).
120106 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
121107 lto_initialize();
122108 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
123109 return LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString);
124110 }
125111
126 /// lto_module_create_from_fd_at_offset - Loads an object file from disk.
127 /// Returns NULL on error (check lto_get_error_message() for details).
128112 lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
129113 size_t file_size,
130114 size_t map_size,
135119 sLastErrorString);
136120 }
137121
138 /// lto_module_create_from_memory - Loads an object file from memory. Returns
139 /// NULL on error (check lto_get_error_message() for details).
140122 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
141123 lto_initialize();
142124 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
143125 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString);
144126 }
145127
146 /// Loads an object file from memory with an extra path argument.
147 /// Returns NULL on error (check lto_get_error_message() for details).
148128 lto_module_t lto_module_create_from_memory_with_path(const void* mem,
149129 size_t length,
150130 const char *path) {
153133 return LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path);
154134 }
155135
156 /// lto_module_dispose - Frees all memory for a module. Upon return the
157 /// lto_module_t is no longer valid.
158136 void lto_module_dispose(lto_module_t mod) {
159137 delete mod;
160138 }
161139
162 /// lto_module_get_target_triple - Returns triplet string which the object
163 /// module was compiled under.
164140 const char* lto_module_get_target_triple(lto_module_t mod) {
165141 return mod->getTargetTriple();
166142 }
167143
168 /// lto_module_set_target_triple - Sets triple string with which the object will
169 /// be codegened.
170144 void lto_module_set_target_triple(lto_module_t mod, const char *triple) {
171145 return mod->setTargetTriple(triple);
172146 }
173147
174 /// lto_module_get_num_symbols - Returns the number of symbols in the object
175 /// module.
176148 unsigned int lto_module_get_num_symbols(lto_module_t mod) {
177149 return mod->getSymbolCount();
178150 }
179151
180 /// lto_module_get_symbol_name - Returns the name of the ith symbol in the
181 /// object module.
182152 const char* lto_module_get_symbol_name(lto_module_t mod, unsigned int index) {
183153 return mod->getSymbolName(index);
184154 }
185155
186 /// lto_module_get_symbol_attribute - Returns the attributes of the ith symbol
187 /// in the object module.
188156 lto_symbol_attributes lto_module_get_symbol_attribute(lto_module_t mod,
189157 unsigned int index) {
190158 return mod->getSymbolAttributes(index);
191159 }
192160
193 /// lto_module_get_num_deplibs - Returns the number of dependent libraries in
194 /// the object module.
195161 unsigned int lto_module_get_num_deplibs(lto_module_t mod) {
196162 return mod->getDependentLibraryCount();
197163 }
198164
199 /// lto_module_get_deplib - Returns the ith dependent library in the module.
200165 const char* lto_module_get_deplib(lto_module_t mod, unsigned int index) {
201166 return mod->getDependentLibrary(index);
202167 }
203168
204 /// lto_module_get_num_linkeropts - Returns the number of linker options in the
205 /// object module.
206169 unsigned int lto_module_get_num_linkeropts(lto_module_t mod) {
207170 return mod->getLinkerOptCount();
208171 }
209172
210 /// lto_module_get_linkeropt - Returns the ith linker option in the module.
211173 const char* lto_module_get_linkeropt(lto_module_t mod, unsigned int index) {
212174 return mod->getLinkerOpt(index);
213175 }
214176
215 /// Set a diagnostic handler.
216177 void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg,
217178 lto_diagnostic_handler_t diag_handler,
218179 void *ctxt) {
219180 cg->setDiagnosticHandler(diag_handler, ctxt);
220181 }
221182
222 /// lto_codegen_create - Instantiates a code generator. Returns NULL if there
223 /// is an error.
224183 lto_code_gen_t lto_codegen_create(void) {
225184 lto_initialize();
226185
232191 return CodeGen;
233192 }
234193
235 /// lto_codegen_dispose - Frees all memory for a code generator. Upon return the
236 /// lto_code_gen_t is no longer valid.
237194 void lto_codegen_dispose(lto_code_gen_t cg) {
238195 delete cg;
239196 }
240197
241 /// lto_codegen_add_module - Add an object module to the set of modules for
242 /// which code will be generated. Returns true on error (check
243 /// lto_get_error_message() for details).
244198 bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {
245199 return !cg->addModule(mod, sLastErrorString);
246200 }
247201
248 /// lto_codegen_set_debug_model - Sets what if any format of debug info should
249 /// be generated. Returns true on error (check lto_get_error_message() for
250 /// details).
251202 bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {
252203 cg->setDebugInfo(debug);
253204 return false;
254205 }
255206
256 /// lto_codegen_set_pic_model - Sets what code model to generated. Returns true
257 /// on error (check lto_get_error_message() for details).
258207 bool lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model model) {
259208 cg->setCodePICModel(model);
260209 return false;
261210 }
262211
263 /// lto_codegen_set_cpu - Sets the cpu to generate code for.
264212 void lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu) {
265213 return cg->setCpu(cpu);
266214 }
267215
268 /// lto_codegen_set_attr - Sets the attr to generate code for.
269216 void lto_codegen_set_attr(lto_code_gen_t cg, const char *attr) {
270217 return cg->setAttr(attr);
271218 }
272219
273 /// lto_codegen_set_assembler_path - Sets the path to the assembler tool.
274220 void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char *path) {
275221 // In here only for backwards compatibility. We use MC now.
276222 }
277223
278 /// lto_codegen_set_assembler_args - Sets extra arguments that libLTO should
279 /// pass to the assembler.
280224 void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args,
281225 int nargs) {
282226 // In here only for backwards compatibility. We use MC now.
283227 }
284228
285 /// lto_codegen_add_must_preserve_symbol - Adds to a list of all global symbols
286 /// that must exist in the final generated code. If a function is not listed
287 /// there, it might be inlined into every usage and optimized away.
288229 void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg,
289230 const char *symbol) {
290231 cg->addMustPreserveSymbol(symbol);
291232 }
292233
293 /// lto_codegen_write_merged_modules - Writes a new file at the specified path
294 /// that contains the merged contents of all modules added so far. Returns true
295 /// on error (check lto_get_error_message() for details).
296234 bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
297235 if (!parsedOptions) {
298236 cg->parseCodeGenDebugOptions();
302240 return !cg->writeMergedModules(path, sLastErrorString);
303241 }
304242
305 /// lto_codegen_compile - Generates code for all added modules into one native
306 /// object file. On success returns a pointer to a generated mach-o/ELF buffer
307 /// and length set to the buffer size. The buffer is owned by the lto_code_gen_t
308 /// object and will be freed when lto_codegen_dispose() is called, or
309 /// lto_codegen_compile() is called again. On failure, returns NULL (check
310 /// lto_get_error_message() for details).
311243 const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
312244 if (!parsedOptions) {
313245 cg->parseCodeGenDebugOptions();
318250 sLastErrorString);
319251 }
320252
321 /// lto_codegen_compile_to_file - Generates code for all added modules into one
322 /// native object file. The name of the file is written to name. Returns true on
323 /// error.
324253 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
325254 if (!parsedOptions) {
326255 cg->parseCodeGenDebugOptions();
331260 sLastErrorString);
332261 }
333262
334 /// lto_codegen_debug_options - Used to pass extra options to the code
335 /// generator.
336263 void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {
337264 cg->setCodeGenDebugOptions(opt);
338265 }