IRMover.h revision 292915
1292915Sdim//===- IRMover.h ------------------------------------------------*- C++ -*-===//
2292915Sdim//
3292915Sdim//                     The LLVM Compiler Infrastructure
4292915Sdim//
5292915Sdim// This file is distributed under the University of Illinois Open Source
6292915Sdim// License. See LICENSE.TXT for details.
7292915Sdim//
8292915Sdim//===----------------------------------------------------------------------===//
9292915Sdim
10292915Sdim#ifndef LLVM_LINKER_IRMOVER_H
11292915Sdim#define LLVM_LINKER_IRMOVER_H
12292915Sdim
13292915Sdim#include "llvm/ADT/ArrayRef.h"
14292915Sdim#include "llvm/ADT/DenseSet.h"
15292915Sdim#include <functional>
16292915Sdim
17292915Sdimnamespace llvm {
18292915Sdimclass GlobalValue;
19292915Sdimclass MDNode;
20292915Sdimclass Module;
21292915Sdimclass StructType;
22292915Sdimclass Type;
23292915Sdim
24292915Sdimclass IRMover {
25292915Sdim  struct StructTypeKeyInfo {
26292915Sdim    struct KeyTy {
27292915Sdim      ArrayRef<Type *> ETypes;
28292915Sdim      bool IsPacked;
29292915Sdim      KeyTy(ArrayRef<Type *> E, bool P);
30292915Sdim      KeyTy(const StructType *ST);
31292915Sdim      bool operator==(const KeyTy &that) const;
32292915Sdim      bool operator!=(const KeyTy &that) const;
33292915Sdim    };
34292915Sdim    static StructType *getEmptyKey();
35292915Sdim    static StructType *getTombstoneKey();
36292915Sdim    static unsigned getHashValue(const KeyTy &Key);
37292915Sdim    static unsigned getHashValue(const StructType *ST);
38292915Sdim    static bool isEqual(const KeyTy &LHS, const StructType *RHS);
39292915Sdim    static bool isEqual(const StructType *LHS, const StructType *RHS);
40292915Sdim  };
41292915Sdim
42292915Sdimpublic:
43292915Sdim  class IdentifiedStructTypeSet {
44292915Sdim    // The set of opaque types is the composite module.
45292915Sdim    DenseSet<StructType *> OpaqueStructTypes;
46292915Sdim
47292915Sdim    // The set of identified but non opaque structures in the composite module.
48292915Sdim    DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
49292915Sdim
50292915Sdim  public:
51292915Sdim    void addNonOpaque(StructType *Ty);
52292915Sdim    void switchToNonOpaque(StructType *Ty);
53292915Sdim    void addOpaque(StructType *Ty);
54292915Sdim    StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
55292915Sdim    bool hasType(StructType *Ty);
56292915Sdim  };
57292915Sdim
58292915Sdim  IRMover(Module &M);
59292915Sdim
60292915Sdim  typedef std::function<void(GlobalValue &)> ValueAdder;
61292915Sdim  /// Move in the provide values. The source is destroyed.
62292915Sdim  /// Returns true on error.
63292915Sdim  bool move(Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
64292915Sdim            std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
65292915Sdim            DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
66292915Sdim            bool IsMetadataLinkingPostpass = false);
67292915Sdim  Module &getModule() { return Composite; }
68292915Sdim
69292915Sdimprivate:
70292915Sdim  Module &Composite;
71292915Sdim  IdentifiedStructTypeSet IdentifiedStructTypes;
72292915Sdim};
73292915Sdim
74292915Sdim} // End llvm namespace
75292915Sdim
76292915Sdim#endif
77