1 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LINKER_LINKER_H
11 #define LLVM_LINKER_LINKER_H
13 #include "llvm/IR/DiagnosticInfo.h"
14 #include "llvm/IR/FunctionInfo.h"
15 #include "llvm/Linker/IRMover.h"
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.
32 OverrideFromSrc = (1 << 0),
33 LinkOnlyNeeded = (1 << 1),
34 InternalizeLinkedSymbols = (1 << 2)
37 Linker(Module &M, DiagnosticHandlerFunction DiagnosticHandler);
39 /// \brief Link \p Src into the composite. The source is destroyed.
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.
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);
52 static bool linkModules(Module &Dest, Module &Src,
53 DiagnosticHandlerFunction DiagnosticHandler,
54 unsigned Flags = Flags::None);
56 DiagnosticHandlerFunction getDiagnosticHandler() const {
57 return Mover.getDiagnosticHandler();
61 /// Create a new module with exported local functions renamed and promoted
63 std::unique_ptr<Module>
64 renameModuleForThinLTO(std::unique_ptr<Module> &M,
65 const FunctionInfoIndex *Index,
66 DiagnosticHandlerFunction DiagnosticHandler);
68 } // End llvm namespace