1 //===-- llvm/LinkTimeOptimizer.h - Public Interface ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header provides public interface to use LLVM link time optimization
11 // library. This is intended to be used by linker to do link time optimization.
13 //===----------------------------------------------------------------------===//
21 #include <llvm/ADT/hash_map>
36 LTO_MODULE_MERGE_FAILURE,
40 enum LTOLinkageTypes {
41 LTOExternalLinkage, // Externally visible function
42 LTOLinkOnceLinkage, // Keep one copy of named function when linking (inline)
43 LTOWeakLinkage, // Keep one copy of named function when linking (weak)
44 LTOInternalLinkage // Rename collisions when linking (static functions)
47 /// This class represents LLVM symbol information without exposing details
48 /// of LLVM global values. It encapsulates symbol linkage information. This
49 /// is typically used in hash_map where associated name identifies the
55 LTOLinkageTypes getLinkage() const { return linkage; }
58 LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
61 enum LTOLinkageTypes linkage;
65 class string_compare {
67 bool operator()(const char* left, const char* right) const {
68 return (strcmp(left, right) == 0);
72 /// This is the main link time optimization class. It exposes simple API
73 /// to perform link time optimization using LLVM intermodular optimizer.
74 class LinkTimeOptimizer {
77 typedef hash_map<const char*, LLVMSymbol*, hash<const char*>,
78 string_compare> NameToSymbolMap;
80 enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
81 NameToSymbolMap &symbols,
82 std::set<const char*> &references);
83 enum LTOStatus optimizeModules(const std::string &OutputFilename,
84 std::vector<const char*> &exportList);
87 std::vector<Module *> modules;
88 NameToSymbolMap allSymbols;
91 } // End llvm namespace
93 /// This provides C interface to initialize link time optimizer. This allows
94 /// linker to use dlopen() interface to dynamically load LinkTimeOptimizer.
95 /// extern "C" helps, because dlopen() interface uses name to find the symbol.
97 llvm::LinkTimeOptimizer *createLLVMOptimizer();