Delete dead code.
[oota-llvm.git] / include / llvm / Linker / Linker.h
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 #include "llvm/IR/FunctionInfo.h"
18
19 namespace llvm {
20 class Module;
21 class StructType;
22 class Type;
23
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.
28 class Linker {
29 public:
30   struct StructTypeKeyInfo {
31     struct KeyTy {
32       ArrayRef<Type *> ETypes;
33       bool IsPacked;
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;
38     };
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);
45   };
46
47   typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet;
48   typedef DenseSet<StructType *> OpaqueStructTypeSet;
49
50   struct IdentifiedStructTypeSet {
51     // The set of opaque types is the composite module.
52     OpaqueStructTypeSet OpaqueStructTypes;
53
54     // The set of identified but non opaque structures in the composite module.
55     NonOpaqueStructTypeSet NonOpaqueStructTypes;
56
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);
62   };
63
64   enum Flags {
65     None = 0,
66     OverrideFromSrc = (1 << 0),
67     LinkOnlyNeeded = (1 << 1),
68     InternalizeLinkedSymbols = (1 << 2)
69   };
70
71   Linker(Module &M, DiagnosticHandlerFunction DiagnosticHandler);
72   Linker(Module &M);
73
74   /// \brief Link \p Src into the composite. The source is destroyed.
75   ///
76   /// Passing OverrideSymbols as true will have symbols from Src
77   /// shadow those in the Dest.
78   /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
79   /// is passed. If \p FunctionsToImport is provided, only the functions that
80   /// are part of the set will be imported from the source module.
81   ///
82   /// Returns true on error.
83   bool linkInModule(Module &Src, unsigned Flags = Flags::None,
84                     const FunctionInfoIndex *Index = nullptr,
85                     DenseSet<const GlobalValue *> *FunctionsToImport = nullptr);
86
87   static bool linkModules(Module &Dest, Module &Src,
88                           DiagnosticHandlerFunction DiagnosticHandler,
89                           unsigned Flags = Flags::None);
90
91   static bool linkModules(Module &Dest, Module &Src,
92                           unsigned Flags = Flags::None);
93
94 private:
95   Module &Composite;
96
97   IdentifiedStructTypeSet IdentifiedStructTypes;
98
99   DiagnosticHandlerFunction DiagnosticHandler;
100 };
101
102 } // End llvm namespace
103
104 #endif