Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- lto-c.cpp - LLVM Link Time Optimizer C Wrappers --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5f5a573 | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements a C wrapper API for the Link Time Optimization |
| 11 | // library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm-c/LinkTimeOptimizer.h" |
| 16 | #include "llvm/LinkTimeOptimizer.h" |
| 17 | using namespace llvm; |
| 18 | |
| 19 | |
| 20 | /// Create an instance of the LLVM LTO object for performing the link |
| 21 | /// time optimizations. |
| 22 | extern "C" |
| 23 | llvm_lto_t llvm_create_optimizer() { |
| 24 | return new llvm::LTO(); |
| 25 | } |
| 26 | |
| 27 | /// Destroy an instance of the LLVM LTO object |
| 28 | extern "C" |
| 29 | void llvm_destroy_optimizer(llvm_lto_t lto) { |
| 30 | delete (llvm::LTO*)lto; |
| 31 | } |
| 32 | |
| 33 | /// Read an LLVM bitcode file using LTO::readLLVMObjectFile. |
| 34 | extern "C" |
| 35 | llvm_lto_status |
| 36 | llvm_read_object_file(llvm_lto_t lto, const char *input_filename) { |
| 37 | llvm::LTO *l = (llvm::LTO*)lto; |
| 38 | |
| 39 | if (input_filename == NULL) |
| 40 | return LLVM_LTO_READ_FAILURE; |
| 41 | |
| 42 | std::string InputFilename(input_filename); |
| 43 | llvm::LTO::NameToSymbolMap symbols; |
| 44 | std::set<std::string> references; |
| 45 | return (llvm_lto_status)((int)(l->readLLVMObjectFile(InputFilename, symbols, |
| 46 | references))); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /// Optimize and output object code using LTO::optimizeModules. |
| 51 | extern "C" |
| 52 | llvm_lto_status |
| 53 | llvm_optimize_modules(llvm_lto_t lto, const char *output_filename) { |
| 54 | llvm::LTO *l = (llvm::LTO*)lto; |
| 55 | |
| 56 | std::string OutputFilename(output_filename); |
| 57 | std::vector<const char *> exportList; |
| 58 | std::string targetTriple; |
| 59 | |
| 60 | return (llvm_lto_status)((int)( |
| 61 | l->optimizeModules(OutputFilename, exportList, |
| 62 | targetTriple, false, ""))); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | |