e21899cb61a8ebc62767f694c543cfbb4e1fa335
[oota-llvm.git] / include / llvm / Linker / IRMover.h
1 //===- IRMover.h ------------------------------------------------*- 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_IRMOVER_H
11 #define LLVM_LINKER_IRMOVER_H
12
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseSet.h"
15
16 namespace llvm {
17 class GlobalValue;
18 class Module;
19 class StructType;
20 class Type;
21
22 class IRMover {
23   struct StructTypeKeyInfo {
24     struct KeyTy {
25       ArrayRef<Type *> ETypes;
26       bool IsPacked;
27       KeyTy(ArrayRef<Type *> E, bool P);
28       KeyTy(const StructType *ST);
29       bool operator==(const KeyTy &that) const;
30       bool operator!=(const KeyTy &that) const;
31     };
32     static StructType *getEmptyKey();
33     static StructType *getTombstoneKey();
34     static unsigned getHashValue(const KeyTy &Key);
35     static unsigned getHashValue(const StructType *ST);
36     static bool isEqual(const KeyTy &LHS, const StructType *RHS);
37     static bool isEqual(const StructType *LHS, const StructType *RHS);
38   };
39
40 public:
41   class IdentifiedStructTypeSet {
42     // The set of opaque types is the composite module.
43     DenseSet<StructType *> OpaqueStructTypes;
44
45     // The set of identified but non opaque structures in the composite module.
46     DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
47
48   public:
49     void addNonOpaque(StructType *Ty);
50     void switchToNonOpaque(StructType *Ty);
51     void addOpaque(StructType *Ty);
52     StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
53     bool hasType(StructType *Ty);
54   };
55
56   IRMover(Module &M);
57
58   typedef std::function<void(GlobalValue &)> ValueAdder;
59   /// Move in the provide values. The source is destroyed.
60   /// Returns true on error.
61   bool move(Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
62             std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor);
63   Module &getModule() { return Composite; }
64
65 private:
66   Module &Composite;
67   IdentifiedStructTypeSet IdentifiedStructTypes;
68 };
69
70 } // End llvm namespace
71
72 #endif