Add const qualifier for FunctionInfoIndex in ModuleLinker and linkInModule() (NFC)
[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   Module *getModule() const { return Composite; }
75   void deleteModule();
76
77   /// \brief Link \p Src into the composite. The source is destroyed.
78   /// Passing OverrideSymbols as true will have symbols from Src
79   /// shadow those in the Dest.
80   /// For ThinLTO function importing/exporting the \p FunctionInfoIndex
81   /// is passed. If a \p FuncToImport is provided, only that single
82   /// function is imported from the source module.
83   /// Returns true on error.
84   bool linkInModule(Module *Src, unsigned Flags = Flags::None,
85                     const FunctionInfoIndex *Index = nullptr,
86                     Function *FuncToImport = nullptr);
87
88   /// \brief Set the composite to the passed-in module.
89   void setModule(Module *Dst);
90
91   static bool LinkModules(Module *Dest, Module *Src,
92                           DiagnosticHandlerFunction DiagnosticHandler,
93                           unsigned Flags = Flags::None);
94
95   static bool LinkModules(Module *Dest, Module *Src,
96                           unsigned Flags = Flags::None);
97
98 private:
99   void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
100   Module *Composite;
101
102   IdentifiedStructTypeSet IdentifiedStructTypes;
103
104   DiagnosticHandlerFunction DiagnosticHandler;
105 };
106
107 } // End llvm namespace
108
109 #endif