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