1 //===- IRMover.h ------------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LINKER_IRMOVER_H
10 #define LLVM_LINKER_IRMOVER_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/DenseSet.h"
26 struct StructTypeKeyInfo {
28 ArrayRef<Type *> ETypes;
30 KeyTy(ArrayRef<Type *> E, bool P);
31 KeyTy(const StructType *ST);
32 bool operator==(const KeyTy &that) const;
33 bool operator!=(const KeyTy &that) const;
35 static StructType *getEmptyKey();
36 static StructType *getTombstoneKey();
37 static unsigned getHashValue(const KeyTy &Key);
38 static unsigned getHashValue(const StructType *ST);
39 static bool isEqual(const KeyTy &LHS, const StructType *RHS);
40 static bool isEqual(const StructType *LHS, const StructType *RHS);
43 /// Type of the Metadata map in \a ValueToValueMapTy.
44 typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
47 class IdentifiedStructTypeSet {
48 // The set of opaque types is the composite module.
49 DenseSet<StructType *> OpaqueStructTypes;
51 // The set of identified but non opaque structures in the composite module.
52 DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
55 void addNonOpaque(StructType *Ty);
56 void switchToNonOpaque(StructType *Ty);
57 void addOpaque(StructType *Ty);
58 StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
59 bool hasType(StructType *Ty);
64 typedef std::function<void(GlobalValue &)> ValueAdder;
66 /// Move in the provide values in \p ValuesToLink from \p Src.
68 /// - \p AddLazyFor is a call back that the IRMover will call when a global
69 /// value is referenced by one of the ValuesToLink (transitively) but was
70 /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
71 /// are passed as an argument, and the callback is expected to be called
72 /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
73 /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
74 /// function importing from Src.
75 Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
76 std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
77 bool IsPerformingImport);
78 Module &getModule() { return Composite; }
82 IdentifiedStructTypeSet IdentifiedStructTypes;
83 MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
86 } // End llvm namespace