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/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/DenseSet.h"
16 #include "llvm/IR/DiagnosticInfo.h"
17 #include "llvm/IR/FunctionInfo.h"
24 /// This class provides the core functionality of linking in LLVM. It keeps a
25 /// pointer to the merged module so far. It doesn't take ownership of the
26 /// module since it is assumed that the user of this class will want to do
27 /// something with it after the linking.
30 struct StructTypeKeyInfo {
32 ArrayRef<Type *> ETypes;
34 KeyTy(ArrayRef<Type *> E, bool P);
35 KeyTy(const StructType *ST);
36 bool operator==(const KeyTy &that) const;
37 bool operator!=(const KeyTy &that) const;
39 static StructType *getEmptyKey();
40 static StructType *getTombstoneKey();
41 static unsigned getHashValue(const KeyTy &Key);
42 static unsigned getHashValue(const StructType *ST);
43 static bool isEqual(const KeyTy &LHS, const StructType *RHS);
44 static bool isEqual(const StructType *LHS, const StructType *RHS);
47 typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet;
48 typedef DenseSet<StructType *> OpaqueStructTypeSet;
50 struct IdentifiedStructTypeSet {
51 // The set of opaque types is the composite module.
52 OpaqueStructTypeSet OpaqueStructTypes;
54 // The set of identified but non opaque structures in the composite module.
55 NonOpaqueStructTypeSet NonOpaqueStructTypes;
57 void addNonOpaque(StructType *Ty);
58 void switchToNonOpaque(StructType *Ty);
59 void addOpaque(StructType *Ty);
60 StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
61 bool hasType(StructType *Ty);
66 OverrideFromSrc = (1 << 0),
67 LinkOnlyNeeded = (1 << 1),
68 InternalizeLinkedSymbols = (1 << 2)
71 Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
74 Module *getModule() const { return Composite; }
76 /// \brief Link \p Src into the composite. The source is destroyed.
77 /// Passing OverrideSymbols as true will have symbols from Src
78 /// shadow those in the Dest.
79 /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
80 /// is passed. If a \p FuncToImport is provided, only that single
81 /// function is imported from the source module.
82 /// Returns true on error.
83 bool linkInModule(Module *Src, unsigned Flags = Flags::None,
84 const FunctionInfoIndex *Index = nullptr,
85 Function *FuncToImport = nullptr);
87 static bool LinkModules(Module *Dest, Module *Src,
88 DiagnosticHandlerFunction DiagnosticHandler,
89 unsigned Flags = Flags::None);
91 static bool LinkModules(Module *Dest, Module *Src,
92 unsigned Flags = Flags::None);
97 IdentifiedStructTypeSet IdentifiedStructTypes;
99 DiagnosticHandlerFunction DiagnosticHandler;
102 } // End llvm namespace