[llvm] r263304 - Minor cleanup and documentation to IRMover (NFC)
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 14:19:06 PST 2016
Author: mehdi_amini
Date: Fri Mar 11 16:19:06 2016
New Revision: 263304
URL: http://llvm.org/viewvc/llvm-project?rev=263304&view=rev
Log:
Minor cleanup and documentation to IRMover (NFC)
From: Mehdi Amini <mehdi.amini at apple.com>
Modified:
llvm/trunk/include/llvm/Linker/IRMover.h
llvm/trunk/lib/Linker/IRMover.cpp
Modified: llvm/trunk/include/llvm/Linker/IRMover.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/IRMover.h?rev=263304&r1=263303&r2=263304&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Linker/IRMover.h (original)
+++ llvm/trunk/include/llvm/Linker/IRMover.h Fri Mar 11 16:19:06 2016
@@ -58,7 +58,15 @@ public:
IRMover(Module &M);
typedef std::function<void(GlobalValue &)> ValueAdder;
- /// Move in the provide values.
+
+ /// 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
+ /// value is referenced by one of the ValuesToLink (transitively) but was
+ /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
+ /// are passed as an argument, and the callback is expected to be called
+ /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
+ ///
/// Returns true on error.
bool move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=263304&r1=263303&r2=263304&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Fri Mar 11 16:19:06 2016
@@ -345,10 +345,10 @@ class IRLinker;
/// speeds up linking for modules with many/ lazily linked functions of which
/// few get used.
class GlobalValueMaterializer final : public ValueMaterializer {
- IRLinker *TheIRLinker;
+ IRLinker &TheIRLinker;
public:
- GlobalValueMaterializer(IRLinker *TheIRLinker) : TheIRLinker(TheIRLinker) {}
+ GlobalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
Value *materializeDeclFor(Value *V) override;
void materializeInitFor(GlobalValue *New, GlobalValue *Old) override;
Metadata *mapTemporaryMetadata(Metadata *MD) override;
@@ -358,10 +358,10 @@ public:
};
class LocalValueMaterializer final : public ValueMaterializer {
- IRLinker *TheIRLinker;
+ IRLinker &TheIRLinker;
public:
- LocalValueMaterializer(IRLinker *TheIRLinker) : TheIRLinker(TheIRLinker) {}
+ LocalValueMaterializer(IRLinker &TheIRLinker) : TheIRLinker(TheIRLinker) {}
Value *materializeDeclFor(Value *V) override;
void materializeInitFor(GlobalValue *New, GlobalValue *Old) override;
Metadata *mapTemporaryMetadata(Metadata *MD) override;
@@ -376,6 +376,7 @@ class IRLinker {
Module &DstM;
std::unique_ptr<Module> SrcM;
+ /// See IRMover::move().
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
TypeMapTy TypeMap;
@@ -477,6 +478,11 @@ class IRLinker {
Constant *linkAppendingVarProto(GlobalVariable *DstGV,
const GlobalVariable *SrcGV);
+ /// Given the GlobaValue \p SGV in the source module, and the matching
+ /// GlobalValue \p DGV (if any), return true if the linker will pull \p SGV
+ /// into the destination module.
+ ///
+ /// Note this code may call the client-provided \p AddLazyFor.
bool shouldLink(GlobalValue *DGV, GlobalValue &SGV);
Constant *linkGlobalValueProto(GlobalValue *GV, bool ForAlias);
@@ -518,7 +524,7 @@ public:
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
bool IsMetadataLinkingPostpass = false)
: DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(AddLazyFor), TypeMap(Set),
- GValMaterializer(this), LValMaterializer(this),
+ GValMaterializer(*this), LValMaterializer(*this),
IsMetadataLinkingPostpass(IsMetadataLinkingPostpass),
ValIDToTempMDMap(ValIDToTempMDMap) {
for (GlobalValue *GV : ValuesToLink)
@@ -590,47 +596,47 @@ static void forceRenaming(GlobalValue *G
}
Value *GlobalValueMaterializer::materializeDeclFor(Value *V) {
- return TheIRLinker->materializeDeclFor(V, false);
+ return TheIRLinker.materializeDeclFor(V, false);
}
void GlobalValueMaterializer::materializeInitFor(GlobalValue *New,
GlobalValue *Old) {
- TheIRLinker->materializeInitFor(New, Old, false);
+ TheIRLinker.materializeInitFor(New, Old, false);
}
Metadata *GlobalValueMaterializer::mapTemporaryMetadata(Metadata *MD) {
- return TheIRLinker->mapTemporaryMetadata(MD);
+ return TheIRLinker.mapTemporaryMetadata(MD);
}
void GlobalValueMaterializer::replaceTemporaryMetadata(const Metadata *OrigMD,
Metadata *NewMD) {
- TheIRLinker->replaceTemporaryMetadata(OrigMD, NewMD);
+ TheIRLinker.replaceTemporaryMetadata(OrigMD, NewMD);
}
bool GlobalValueMaterializer::isMetadataNeeded(Metadata *MD) {
- return TheIRLinker->isMetadataNeeded(MD);
+ return TheIRLinker.isMetadataNeeded(MD);
}
Value *LocalValueMaterializer::materializeDeclFor(Value *V) {
- return TheIRLinker->materializeDeclFor(V, true);
+ return TheIRLinker.materializeDeclFor(V, true);
}
void LocalValueMaterializer::materializeInitFor(GlobalValue *New,
GlobalValue *Old) {
- TheIRLinker->materializeInitFor(New, Old, true);
+ TheIRLinker.materializeInitFor(New, Old, true);
}
Metadata *LocalValueMaterializer::mapTemporaryMetadata(Metadata *MD) {
- return TheIRLinker->mapTemporaryMetadata(MD);
+ return TheIRLinker.mapTemporaryMetadata(MD);
}
void LocalValueMaterializer::replaceTemporaryMetadata(const Metadata *OrigMD,
Metadata *NewMD) {
- TheIRLinker->replaceTemporaryMetadata(OrigMD, NewMD);
+ TheIRLinker.replaceTemporaryMetadata(OrigMD, NewMD);
}
bool LocalValueMaterializer::isMetadataNeeded(Metadata *MD) {
- return TheIRLinker->isMetadataNeeded(MD);
+ return TheIRLinker.isMetadataNeeded(MD);
}
Value *IRLinker::materializeDeclFor(Value *V, bool ForAlias) {
@@ -1034,8 +1040,15 @@ bool IRLinker::shouldLink(GlobalValue *D
if (DoneLinkingBodies)
return false;
- AddLazyFor(SGV, [this](GlobalValue &GV) { maybeAdd(&GV); });
- return ValuesToLink.count(&SGV);
+
+ // Callback to the client to give a chance to lazily add the Global to the
+ // list of value to link.
+ bool LazilyAdded = false;
+ AddLazyFor(SGV, [this, &LazilyAdded](GlobalValue &GV) {
+ maybeAdd(&GV);
+ LazilyAdded = true;
+ });
+ return LazilyAdded;
}
Constant *IRLinker::linkGlobalValueProto(GlobalValue *SGV, bool ForAlias) {
@@ -1054,9 +1067,8 @@ Constant *IRLinker::linkGlobalValueProto
return cast<Constant>(I->second);
}
- DGV = nullptr;
- if (ShouldLink || !ForAlias)
- DGV = getLinkedToGlobal(SGV);
+ if (!ShouldLink && ForAlias)
+ DGV = nullptr;
// Handle the ultra special appending linkage case first.
assert(!DGV || SGV->hasAppendingLinkage() == DGV->hasAppendingLinkage());
More information about the llvm-commits
mailing list