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/FunctionInfo.h"
14 #include "llvm/Linker/IRMover.h"
21 /// This class provides the core functionality of linking in LLVM. It keeps a
22 /// pointer to the merged module so far. It doesn't take ownership of the
23 /// module since it is assumed that the user of this class will want to do
24 /// something with it after the linking.
31 OverrideFromSrc = (1 << 0),
32 LinkOnlyNeeded = (1 << 1),
33 InternalizeLinkedSymbols = (1 << 2)
38 /// \brief Link \p Src into the composite.
40 /// Passing OverrideSymbols as true will have symbols from Src
41 /// shadow those in the Dest.
42 /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
43 /// is passed. If \p FunctionsToImport is provided, only the functions that
44 /// are part of the set will be imported from the source module.
45 /// The \p ValIDToTempMDMap is populated by the linker when function
46 /// importing is performed.
48 /// Returns true on error.
49 bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None,
50 const FunctionInfoIndex *Index = nullptr,
51 DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
52 DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr);
54 /// This exists to implement the deprecated LLVMLinkModules C api. Don't use
55 /// for anything else.
56 bool linkInModuleForCAPI(Module &Src);
58 static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
59 unsigned Flags = Flags::None);
61 /// \brief Link metadata from \p Src into the composite. The source is
64 /// The \p ValIDToTempMDMap sound have been populated earlier during function
65 /// importing from \p Src.
66 bool linkInMetadata(Module &Src,
67 DenseMap<unsigned, MDNode *> *ValIDToTempMDMap);
70 /// Create a new module with exported local functions renamed and promoted
72 std::unique_ptr<Module> renameModuleForThinLTO(std::unique_ptr<Module> M,
73 const FunctionInfoIndex *Index);
75 } // End llvm namespace