diff options
author | Chris Lattner <sabre@nondot.org> | 2007-01-06 23:53:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-01-06 23:53:43 +0000 |
commit | ddc6f353c0e6746553e7042170e42d715b76a294 (patch) | |
tree | c45f7437ace0f05748f4355d98238dbaaa7fd38a /tools/lto | |
parent | 11fdadf407642167c5e2b8a1ed40c66c0c6dbdf2 (diff) | |
download | external_llvm-ddc6f353c0e6746553e7042170e42d715b76a294.zip external_llvm-ddc6f353c0e6746553e7042170e42d715b76a294.tar.gz external_llvm-ddc6f353c0e6746553e7042170e42d715b76a294.tar.bz2 |
Add C wrappers for the LTO library (PR1081). Patch by Chandler Carruth!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32966 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lto')
-rw-r--r-- | tools/lto/lto-c.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/lto/lto-c.cpp b/tools/lto/lto-c.cpp new file mode 100644 index 0000000..f89b374 --- /dev/null +++ b/tools/lto/lto-c.cpp @@ -0,0 +1,66 @@ +//===- lto-c.cpp - LLVM Link Time Optimizer C Wrappers --------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chandler Carruth and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements a C wrapper API for the Link Time Optimization +// library. +// +//===----------------------------------------------------------------------===// + +#include "llvm-c/LinkTimeOptimizer.h" +#include "llvm/LinkTimeOptimizer.h" +using namespace llvm; + + +/// Create an instance of the LLVM LTO object for performing the link +/// time optimizations. +extern "C" +llvm_lto_t llvm_create_optimizer() { + return new llvm::LTO(); +} + +/// Destroy an instance of the LLVM LTO object +extern "C" +void llvm_destroy_optimizer(llvm_lto_t lto) { + delete (llvm::LTO*)lto; +} + +/// Read an LLVM bytecode file using LTO::readLLVMObjectFile. +extern "C" +llvm_lto_status +llvm_read_object_file(llvm_lto_t lto, const char *input_filename) { + llvm::LTO *l = (llvm::LTO*)lto; + + if (input_filename == NULL) + return LLVM_LTO_READ_FAILURE; + + std::string InputFilename(input_filename); + llvm::LTO::NameToSymbolMap symbols; + std::set<std::string> references; + return (llvm_lto_status)((int)(l->readLLVMObjectFile(InputFilename, symbols, + references))); +} + + +/// Optimize and output object code using LTO::optimizeModules. +extern "C" +llvm_lto_status +llvm_optimize_modules(llvm_lto_t lto, const char *output_filename) { + llvm::LTO *l = (llvm::LTO*)lto; + + std::string OutputFilename(output_filename); + std::vector<const char *> exportList; + std::string targetTriple; + + return (llvm_lto_status)((int)( + l->optimizeModules(OutputFilename, exportList, + targetTriple, false, ""))); +} + + + |