Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/Linker/IRMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LINKER_IRMOVER_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/Support/Compiler.h"
Expand All @@ -19,6 +20,8 @@ namespace llvm {
class Error;
class GlobalValue;
class Metadata;
class MDNode;
class NamedMDNode;
class Module;
class StructType;
class TrackingMDRef;
Expand Down Expand Up @@ -67,6 +70,8 @@ class IRMover {
using LazyCallback =
llvm::unique_function<void(GlobalValue &GV, ValueAdder Add)>;

using NamedMDNodesT = DenseMap<const NamedMDNode *, DenseSet<const MDNode *>>;

/// Move in the provide values in \p ValuesToLink from \p Src.
///
/// - \p AddLazyFor is a call back that the IRMover will call when a global
Expand All @@ -86,6 +91,7 @@ class IRMover {
Module &Composite;
IdentifiedStructTypeSet IdentifiedStructTypes;
MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
NamedMDNodesT NamedMDNodes; ///< Cache for IRMover::linkNamedMDNodes().
};

} // End llvm namespace
Expand Down
16 changes: 9 additions & 7 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class IRLinker {
std::unique_ptr<Module> SrcM;

// Lookup table to optimize IRMover::linkNamedMDNodes().
DenseMap<StringRef, DenseSet<MDNode *>> NamedMDNodes;
IRMover::NamedMDNodesT &NamedMDNodes;

/// See IRMover::move().
IRMover::LazyCallback AddLazyFor;
Expand Down Expand Up @@ -440,10 +440,12 @@ class IRLinker {
IRLinker(Module &DstM, MDMapT &SharedMDs,
IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
ArrayRef<GlobalValue *> ValuesToLink,
IRMover::LazyCallback AddLazyFor, bool IsPerformingImport)
: DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this),
SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
IRMover::LazyCallback AddLazyFor, bool IsPerformingImport,
IRMover::NamedMDNodesT &NamedMDNodes)
: DstM(DstM), SrcM(std::move(SrcM)), NamedMDNodes(NamedMDNodes),
AddLazyFor(std::move(AddLazyFor)), TypeMap(Set),
GValMaterializer(*this), LValMaterializer(*this), SharedMDs(SharedMDs),
IsPerformingImport(IsPerformingImport),
Mapper(ValueMap, RF_ReuseAndMutateDistinctMDs | RF_IgnoreMissingLocals,
&TypeMap, &GValMaterializer),
IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
Expand Down Expand Up @@ -1138,7 +1140,7 @@ void IRLinker::linkNamedMDNodes() {

NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName());

auto &Inserted = NamedMDNodes[DestNMD->getName()];
auto &Inserted = NamedMDNodes[DestNMD];
if (Inserted.empty()) {
// Must be the first module, copy everything from DestNMD.
Inserted.insert(DestNMD->operands().begin(), DestNMD->operands().end());
Expand Down Expand Up @@ -1683,6 +1685,6 @@ Error IRMover::move(std::unique_ptr<Module> Src,
LazyCallback AddLazyFor, bool IsPerformingImport) {
IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
std::move(Src), ValuesToLink, std::move(AddLazyFor),
IsPerformingImport);
IsPerformingImport, NamedMDNodes);
return TheIRLinker.run();
}