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"
23 /// This class provides the core functionality of linking in LLVM. It keeps a
24 /// pointer to the merged module so far. It doesn't take ownership of the
25 /// module since it is assumed that the user of this class will want to do
26 /// something with it after the linking.
29 struct StructTypeKeyInfo {
31 ArrayRef<Type *> ETypes;
33 KeyTy(ArrayRef<Type *> E, bool P);
34 KeyTy(const StructType *ST);
35 bool operator==(const KeyTy &that) const;
36 bool operator!=(const KeyTy &that) const;
38 static StructType *getEmptyKey();
39 static StructType *getTombstoneKey();
40 static unsigned getHashValue(const KeyTy &Key);
41 static unsigned getHashValue(const StructType *ST);
42 static bool isEqual(const KeyTy &LHS, const StructType *RHS);
43 static bool isEqual(const StructType *LHS, const StructType *RHS);
46 typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet;
47 typedef DenseSet<StructType *> OpaqueStructTypeSet;
49 struct IdentifiedStructTypeSet {
50 // The set of opaque types is the composite module.
51 OpaqueStructTypeSet OpaqueStructTypes;
53 // The set of identified but non opaque structures in the composite module.
54 NonOpaqueStructTypeSet NonOpaqueStructTypes;
56 void addNonOpaque(StructType *Ty);
57 void switchToNonOpaque(StructType *Ty);
58 void addOpaque(StructType *Ty);
59 StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
60 bool hasType(StructType *Ty);
65 OverrideFromSrc = (1 << 0),
66 LinkOnlyNeeded = (1 << 1),
67 InternalizeLinkedSymbols = (1 << 2)
70 Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
73 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 /// Returns true on error.
80 bool linkInModule(Module *Src, unsigned Flags = Flags::None);
82 /// \brief Set the composite to the passed-in module.
83 void setModule(Module *Dst);
85 static bool LinkModules(Module *Dest, Module *Src,
86 DiagnosticHandlerFunction DiagnosticHandler,
87 unsigned Flags = Flags::None);
89 static bool LinkModules(Module *Dest, Module *Src,
90 unsigned Flags = Flags::None);
93 void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
96 IdentifiedStructTypeSet IdentifiedStructTypes;
98 DiagnosticHandlerFunction DiagnosticHandler;
101 } // End llvm namespace