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/Linker/IRMover.h" 14 15 namespace llvm { 16 class Module; 17 class StructType; 18 class Type; 19 20 /// This class provides the core functionality of linking in LLVM. It keeps a 21 /// pointer to the merged module so far. It doesn't take ownership of the 22 /// module since it is assumed that the user of this class will want to do 23 /// something with it after the linking. 24 class Linker { 25 IRMover Mover; 26 27 public: 28 enum Flags { 29 None = 0, 30 OverrideFromSrc = (1 << 0), 31 LinkOnlyNeeded = (1 << 1), 32 InternalizeLinkedSymbols = (1 << 2), 33 /// Don't force link referenced linkonce definitions, import declaration. 34 DontForceLinkLinkonceODR = (1 << 3) 35 36 }; 37 38 Linker(Module &M); 39 40 /// \brief Link \p Src into the composite. 41 /// 42 /// Passing OverrideSymbols as true will have symbols from Src 43 /// shadow those in the Dest. 44 /// For ThinLTO function importing/exporting the \p ModuleSummaryIndex 45 /// is passed. If \p GlobalsToImport is provided, only the globals that 46 /// are part of the set will be imported from the source module. 47 /// 48 /// Returns true on error. 49 bool linkInModule(std::unique_ptr<Module> Src, unsigned Flags = Flags::None, 50 DenseSet<const GlobalValue *> *GlobalsToImport = nullptr); 51 52 static bool linkModules(Module &Dest, std::unique_ptr<Module> Src, 53 unsigned Flags = Flags::None); 54 }; 55 56 } // End llvm namespace 57 58 #endif 59