Slit lib/Linker in two.
[oota-llvm.git] / include / llvm / Linker / Linker.h
1 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_LINKER_LINKER_H
11 #define LLVM_LINKER_LINKER_H
12
13 #include "llvm/IR/DiagnosticInfo.h"
14 #include "llvm/IR/FunctionInfo.h"
15 #include "llvm/Linker/IRMover.h"
16
17 namespace llvm {
18 class Module;
19 class StructType;
20 class Type;
21
22 /// This class provides the core functionality of linking in LLVM. It keeps a
23 /// pointer to the merged module so far. It doesn't take ownership of the
24 /// module since it is assumed that the user of this class will want to do
25 /// something with it after the linking.
26 class Linker {
27   IRMover Mover;
28
29 public:
30   enum Flags {
31     None = 0,
32     OverrideFromSrc = (1 << 0),
33     LinkOnlyNeeded = (1 << 1),
34     InternalizeLinkedSymbols = (1 << 2)
35   };
36
37   Linker(Module &M, DiagnosticHandlerFunction DiagnosticHandler);
38
39   /// \brief Link \p Src into the composite. The source is destroyed.
40   ///
41   /// Passing OverrideSymbols as true will have symbols from Src
42   /// shadow those in the Dest.
43   /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
44   /// is passed. If \p FunctionsToImport is provided, only the functions that
45   /// are part of the set will be imported from the source module.
46   ///
47   /// Returns true on error.
48   bool linkInModule(Module &Src, unsigned Flags = Flags::None,
49                     const FunctionInfoIndex *Index = nullptr,
50                     DenseSet<const GlobalValue *> *FunctionsToImport = nullptr);
51
52   static bool linkModules(Module &Dest, Module &Src,
53                           DiagnosticHandlerFunction DiagnosticHandler,
54                           unsigned Flags = Flags::None);
55
56   DiagnosticHandlerFunction getDiagnosticHandler() const {
57     return Mover.getDiagnosticHandler();
58   }
59 };
60
61 /// Create a new module with exported local functions renamed and promoted
62 /// for ThinLTO.
63 std::unique_ptr<Module>
64 renameModuleForThinLTO(std::unique_ptr<Module> &M,
65                        const FunctionInfoIndex *Index,
66                        DiagnosticHandlerFunction DiagnosticHandler);
67
68 } // End llvm namespace
69
70 #endif