aboutsummaryrefslogtreecommitdiff
path: root/tools/lto/lto-c.cpp
blob: df9af0bef402b513c400875ca6e6dfc119c1fa38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//===- lto-c.cpp - LLVM Link Time Optimizer C Wrappers --------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file 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 bitcode 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, "")));
}