LLVM  3.7.0
Linker/Linker.h
Go to the documentation of this file.
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/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/DenseSet.h"
16 #include "llvm/IR/DiagnosticInfo.h"
17 
18 namespace llvm {
19 class Module;
20 class StructType;
21 class Type;
22 
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.
27 class Linker {
28 public:
30  struct KeyTy {
32  bool IsPacked;
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;
37  };
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);
44  };
45 
48 
50  // The set of opaque types is the composite module.
52 
53  // The set of identified but non opaque structures in the composite module.
55 
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);
61  };
62 
63  Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
64  Linker(Module *M);
65  ~Linker();
66 
67  Module *getModule() const { return Composite; }
68  void deleteModule();
69 
70  /// \brief Link \p Src into the composite. The source is destroyed.
71  /// Passing OverrideSymbols as true will have symbols from Src
72  /// shadow those in the Dest.
73  /// Returns true on error.
74  bool linkInModule(Module *Src, bool OverrideSymbols = false);
75 
76  /// \brief Set the composite to the passed-in module.
77  void setModule(Module *Dst);
78 
79  static bool LinkModules(Module *Dest, Module *Src,
80  DiagnosticHandlerFunction DiagnosticHandler);
81 
82  static bool LinkModules(Module *Dest, Module *Src);
83 
84 private:
85  void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
86  Module *Composite;
87 
88  IdentifiedStructTypeSet IdentifiedStructTypes;
89 
90  DiagnosticHandlerFunction DiagnosticHandler;
91 };
92 
93 } // End llvm namespace
94 
95 #endif
bool operator!=(const KeyTy &that) const
bool operator==(const KeyTy &that) const
static bool LinkModules(Module *Dest, Module *Src, DiagnosticHandlerFunction DiagnosticHandler)
This function links two modules together, with the resulting Dest module modified to be the composite...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
void deleteModule()
static StructType * getEmptyKey()
DenseSet< StructType *, StructTypeKeyInfo > NonOpaqueStructTypeSet
Definition: Linker/Linker.h:46
StructType - Class to represent struct types.
Definition: DerivedTypes.h:191
Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler)
This class provides the core functionality of linking in LLVM.
Definition: Linker/Linker.h:27
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
NonOpaqueStructTypeSet NonOpaqueStructTypes
Definition: Linker/Linker.h:54
bool linkInModule(Module *Src, bool OverrideSymbols=false)
Link Src into the composite.
#define P(N)
KeyTy(ArrayRef< Type * > E, bool P)
void setModule(Module *Dst)
Set the composite to the passed-in module.
static unsigned getHashValue(const KeyTy &Key)
std::function< void(const DiagnosticInfo &)> DiagnosticHandlerFunction
static bool isEqual(const KeyTy &LHS, const StructType *RHS)
DenseSet< StructType * > OpaqueStructTypeSet
Definition: Linker/Linker.h:47
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Module * getModule() const
Definition: Linker/Linker.h:67
static StructType * getTombstoneKey()