remove old piece of the V9 backend.
[oota-llvm.git] / include / llvm / LinkTimeOptimizer.h
1 //===-- llvm/LinkTimeOptimizer.h - Public Interface  ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
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.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef __LTO_H__
16 #define __LTO_H__
17
18 #include <string>
19 #include <vector>
20 #include <set>
21 #include <llvm/ADT/hash_map>
22
23 namespace llvm {
24
25   class Module;
26   class GlobalValue;
27
28   enum LTOStatus {
29     LTO_UNKNOWN,
30     LTO_OPT_SUCCESS,
31     LTO_READ_SUCCESS,
32     LTO_READ_FAILURE,
33     LTO_WRITE_FAILURE,
34     LTO_NO_TARGET,
35     LTO_NO_WORK,
36     LTO_MODULE_MERGE_FAILURE,
37     LTO_ASM_FAILURE
38   };
39  
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)
45   };
46
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 
50   /// the symbol name.
51   class LLVMSymbol {
52
53   public:
54
55     LTOLinkageTypes getLinkage() const { return linkage; }
56     void mayBeNotUsed();
57
58   LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
59
60   private:
61     enum LTOLinkageTypes linkage;
62     GlobalValue *gv;
63   };
64
65   class string_compare {
66   public:
67     bool operator()(const char* left, const char* right) const { 
68       return (strcmp(left, right) == 0); 
69     }
70   };
71   
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 {
75
76   public:
77     typedef hash_map<const char*, LLVMSymbol*, hash<const char*>, 
78                      string_compare> NameToSymbolMap;
79
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);
85
86   private:
87     std::vector<Module *> modules;
88     NameToSymbolMap allSymbols;
89   };
90
91 } // End llvm namespace
92
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.
96 extern "C"
97 llvm::LinkTimeOptimizer *createLLVMOptimizer();
98
99 #endif