[IRLinker] make IRLinker::AddLazyFor optional (llvm::unique_function). NFC

2 of the 3 callsite of IRMover::move() pass empty lambda functions. Just
make this parameter llvm::unique_function.

Came about via discussion in D120781. Probably worth making this change
regardless of the resolution of D120781.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D121630
This commit is contained in:
Nick Desaulniers 2022-03-14 14:08:25 -07:00
parent e049a87f04
commit 236695e70c
5 changed files with 26 additions and 24 deletions

View File

@ -11,6 +11,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FunctionExtras.h"
#include <functional>
namespace llvm {
@ -62,6 +63,8 @@ public:
IRMover(Module &M);
typedef std::function<void(GlobalValue &)> ValueAdder;
using LazyCallback =
llvm::unique_function<void(GlobalValue &GV, ValueAdder Add)>;
/// Move in the provide values in \p ValuesToLink from \p Src.
///
@ -70,11 +73,11 @@ public:
/// 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.
/// Pass nullptr if there's no work to be done in such cases.
/// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
/// function importing from Src.
Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
bool IsPerformingImport);
LazyCallback AddLazyFor, bool IsPerformingImport);
Module &getModule() { return Composite; }
private:

View File

@ -885,8 +885,7 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
Keep.push_back(GV);
}
return RegularLTO.Mover->move(std::move(Mod.M), Keep,
[](GlobalValue &, IRMover::ValueAdder) {},
return RegularLTO.Mover->move(std::move(Mod.M), Keep, nullptr,
/* IsPerformingImport */ false);
}

View File

@ -381,7 +381,7 @@ class IRLinker {
std::unique_ptr<Module> SrcM;
/// See IRMover::move().
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
IRMover::LazyCallback AddLazyFor;
TypeMapTy TypeMap;
GlobalValueMaterializer GValMaterializer;
@ -524,8 +524,7 @@ public:
IRLinker(Module &DstM, MDMapT &SharedMDs,
IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor,
bool IsPerformingImport)
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),
@ -987,10 +986,11 @@ bool IRLinker::shouldLink(GlobalValue *DGV, GlobalValue &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;
});
if (AddLazyFor)
AddLazyFor(SGV, [this, &LazilyAdded](GlobalValue &GV) {
maybeAdd(&GV);
LazilyAdded = true;
});
return LazilyAdded;
}
@ -1673,10 +1673,9 @@ IRMover::IRMover(Module &M) : Composite(M) {
}
}
Error IRMover::move(
std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor,
bool IsPerformingImport) {
Error IRMover::move(std::unique_ptr<Module> Src,
ArrayRef<GlobalValue *> ValuesToLink,
LazyCallback AddLazyFor, bool IsPerformingImport) {
IRLinker TheIRLinker(Composite, SharedMDs, IdentifiedStructTypes,
std::move(Src), ValuesToLink, std::move(AddLazyFor),
IsPerformingImport);

View File

@ -573,11 +573,13 @@ bool ModuleLinker::run() {
// FIXME: Propagate Errors through to the caller instead of emitting
// diagnostics.
bool HasErrors = false;
if (Error E = Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
addLazyFor(GV, Add);
},
/* IsPerformingImport */ false)) {
if (Error E =
Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
IRMover::LazyCallback(
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
addLazyFor(GV, Add);
}),
/* IsPerformingImport */ false)) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
DstM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, EIB.message()));
HasErrors = true;

View File

@ -1331,10 +1331,9 @@ Expected<bool> FunctionImporter::importFunctions(
<< " from " << SrcModule->getSourceFileName() << "\n";
}
if (Error Err = Mover.move(
std::move(SrcModule), GlobalsToImport.getArrayRef(),
[](GlobalValue &, IRMover::ValueAdder) {},
/*IsPerformingImport=*/true))
if (Error Err = Mover.move(std::move(SrcModule),
GlobalsToImport.getArrayRef(), nullptr,
/*IsPerformingImport=*/true))
report_fatal_error(Twine("Function Import: link error: ") +
toString(std::move(Err)));