LLVM  4.0.0
IRMover.h
Go to the documentation of this file.
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 Error;
19 class GlobalValue;
20 class Metadata;
21 class Module;
22 class StructType;
23 class TrackingMDRef;
24 class Type;
25 
26 class IRMover {
27  struct StructTypeKeyInfo {
28  struct KeyTy {
30  bool IsPacked;
31  KeyTy(ArrayRef<Type *> E, bool P);
32  KeyTy(const StructType *ST);
33  bool operator==(const KeyTy &that) const;
34  bool operator!=(const KeyTy &that) const;
35  };
36  static StructType *getEmptyKey();
37  static StructType *getTombstoneKey();
38  static unsigned getHashValue(const KeyTy &Key);
39  static unsigned getHashValue(const StructType *ST);
40  static bool isEqual(const KeyTy &LHS, const StructType *RHS);
41  static bool isEqual(const StructType *LHS, const StructType *RHS);
42  };
43 
44  /// Type of the Metadata map in \a ValueToValueMapTy.
46 
47 public:
49  // The set of opaque types is the composite module.
50  DenseSet<StructType *> OpaqueStructTypes;
51 
52  // The set of identified but non opaque structures in the composite module.
53  DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
54 
55  public:
56  void addNonOpaque(StructType *Ty);
57  void switchToNonOpaque(StructType *Ty);
58  void addOpaque(StructType *Ty);
59  StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
60  bool hasType(StructType *Ty);
61  };
62 
63  IRMover(Module &M);
64 
65  typedef std::function<void(GlobalValue &)> ValueAdder;
66 
67  /// Move in the provide values in \p ValuesToLink from \p Src.
68  ///
69  /// - \p AddLazyFor is a call back that the IRMover will call when a global
70  /// value is referenced by one of the ValuesToLink (transitively) but was
71  /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
72  /// are passed as an argument, and the callback is expected to be called
73  /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
74  /// - \p LinkModuleInlineAsm is true if the ModuleInlineAsm string in Src
75  /// should be linked with (concatenated into) the ModuleInlineAsm string
76  /// for the destination module. It should be true for full LTO, but not
77  /// when importing for ThinLTO, otherwise we can have duplicate symbols.
78  /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
79  /// function importing from Src.
80  Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
81  std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
82  bool LinkModuleInlineAsm, bool IsPerformingImport);
83  Module &getModule() { return Composite; }
84 
85 private:
86  Module &Composite;
87  IdentifiedStructTypeSet IdentifiedStructTypes;
88  MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
89 };
90 
91 } // End llvm namespace
92 
93 #endif
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
bool operator!=(const KeyTy &that) const
Definition: IRMover.cpp:1351
Implements a dense probed hash-table based set.
Definition: DenseSet.h:202
StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Definition: IRMover.cpp:1405
void switchToNonOpaque(StructType *Ty)
Definition: IRMover.cpp:1391
Class to represent struct types.
Definition: DerivedTypes.h:199
Module & getModule()
Definition: IRMover.h:83
static bool isEqual(const Function &Caller, const Function &Callee)
bool operator==(const KeyTy &that) const
Definition: IRMover.cpp:1347
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, std::function< void(GlobalValue &GV, ValueAdder Add)> AddLazyFor, bool LinkModuleInlineAsm, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
Definition: IRMover.cpp:1436
#define P(N)
KeyTy(ArrayRef< Type * > E, bool P)
Definition: IRMover.cpp:1341
IRMover(Module &M)
Definition: IRMover.cpp:1419
std::function< void(GlobalValue &)> ValueAdder
Definition: IRMover.h:65
Lightweight error class with error context and mandatory checking.
print Print MemDeps of function