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