forked from OSchip/llvm-project
Pass a std::unique_ptr to IRMover::move.
It was already the one "destroying" the source module, now the API reflects that. llvm-svn: 260989
This commit is contained in:
parent
aadc89c25d
commit
40358fb86f
|
@ -58,9 +58,9 @@ public:
|
||||||
IRMover(Module &M);
|
IRMover(Module &M);
|
||||||
|
|
||||||
typedef std::function<void(GlobalValue &)> ValueAdder;
|
typedef std::function<void(GlobalValue &)> ValueAdder;
|
||||||
/// Move in the provide values. The source is destroyed.
|
/// Move in the provide values.
|
||||||
/// Returns true on error.
|
/// Returns true on error.
|
||||||
bool move(Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
|
bool move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
|
||||||
std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
|
std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
|
||||||
bool IsMetadataLinkingPostpass = false);
|
bool IsMetadataLinkingPostpass = false);
|
||||||
|
|
|
@ -54,12 +54,11 @@ public:
|
||||||
static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
|
static bool linkModules(Module &Dest, std::unique_ptr<Module> Src,
|
||||||
unsigned Flags = Flags::None);
|
unsigned Flags = Flags::None);
|
||||||
|
|
||||||
/// \brief Link metadata from \p Src into the composite. The source is
|
/// \brief Link metadata from \p Src into the composite.
|
||||||
/// destroyed.
|
|
||||||
///
|
///
|
||||||
/// The \p ValIDToTempMDMap sound have been populated earlier during function
|
/// The \p ValIDToTempMDMap sound have been populated earlier during function
|
||||||
/// importing from \p Src.
|
/// importing from \p Src.
|
||||||
bool linkInMetadata(Module &Src,
|
bool linkInMetadata(std::unique_ptr<Module> Src,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap);
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,7 @@ public:
|
||||||
/// from SrcM to DstM.
|
/// from SrcM to DstM.
|
||||||
class IRLinker {
|
class IRLinker {
|
||||||
Module &DstM;
|
Module &DstM;
|
||||||
Module &SrcM;
|
std::unique_ptr<Module> SrcM;
|
||||||
|
|
||||||
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
|
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor;
|
||||||
|
|
||||||
|
@ -433,13 +433,13 @@ class IRLinker {
|
||||||
|
|
||||||
/// Helper method for setting a message and returning an error code.
|
/// Helper method for setting a message and returning an error code.
|
||||||
bool emitError(const Twine &Message) {
|
bool emitError(const Twine &Message) {
|
||||||
SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
|
SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
|
||||||
HasError = true;
|
HasError = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitWarning(const Twine &Message) {
|
void emitWarning(const Twine &Message) {
|
||||||
SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));
|
SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check whether we should be linking metadata from the source module.
|
/// Check whether we should be linking metadata from the source module.
|
||||||
|
@ -512,12 +512,12 @@ class IRLinker {
|
||||||
void stripNullSubprograms(DICompileUnit *CU);
|
void stripNullSubprograms(DICompileUnit *CU);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IRLinker(Module &DstM, IRMover::IdentifiedStructTypeSet &Set, Module &SrcM,
|
IRLinker(Module &DstM, IRMover::IdentifiedStructTypeSet &Set,
|
||||||
ArrayRef<GlobalValue *> ValuesToLink,
|
std::unique_ptr<Module> SrcM, ArrayRef<GlobalValue *> ValuesToLink,
|
||||||
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor,
|
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr,
|
||||||
bool IsMetadataLinkingPostpass = false)
|
bool IsMetadataLinkingPostpass = false)
|
||||||
: DstM(DstM), SrcM(SrcM), AddLazyFor(AddLazyFor), TypeMap(Set),
|
: DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(AddLazyFor), TypeMap(Set),
|
||||||
GValMaterializer(this), LValMaterializer(this),
|
GValMaterializer(this), LValMaterializer(this),
|
||||||
IsMetadataLinkingPostpass(IsMetadataLinkingPostpass),
|
IsMetadataLinkingPostpass(IsMetadataLinkingPostpass),
|
||||||
ValIDToTempMDMap(ValIDToTempMDMap) {
|
ValIDToTempMDMap(ValIDToTempMDMap) {
|
||||||
|
@ -796,7 +796,7 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
|
||||||
/// types 'Foo' but one got renamed when the module was loaded into the same
|
/// types 'Foo' but one got renamed when the module was loaded into the same
|
||||||
/// LLVMContext.
|
/// LLVMContext.
|
||||||
void IRLinker::computeTypeMapping() {
|
void IRLinker::computeTypeMapping() {
|
||||||
for (GlobalValue &SGV : SrcM.globals()) {
|
for (GlobalValue &SGV : SrcM->globals()) {
|
||||||
GlobalValue *DGV = getLinkedToGlobal(&SGV);
|
GlobalValue *DGV = getLinkedToGlobal(&SGV);
|
||||||
if (!DGV)
|
if (!DGV)
|
||||||
continue;
|
continue;
|
||||||
|
@ -812,11 +812,11 @@ void IRLinker::computeTypeMapping() {
|
||||||
TypeMap.addTypeMapping(DAT->getElementType(), SAT->getElementType());
|
TypeMap.addTypeMapping(DAT->getElementType(), SAT->getElementType());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (GlobalValue &SGV : SrcM)
|
for (GlobalValue &SGV : *SrcM)
|
||||||
if (GlobalValue *DGV = getLinkedToGlobal(&SGV))
|
if (GlobalValue *DGV = getLinkedToGlobal(&SGV))
|
||||||
TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
|
TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
|
||||||
|
|
||||||
for (GlobalValue &SGV : SrcM.aliases())
|
for (GlobalValue &SGV : SrcM->aliases())
|
||||||
if (GlobalValue *DGV = getLinkedToGlobal(&SGV))
|
if (GlobalValue *DGV = getLinkedToGlobal(&SGV))
|
||||||
TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
|
TypeMap.addTypeMapping(DGV->getType(), SGV.getType());
|
||||||
|
|
||||||
|
@ -824,7 +824,7 @@ void IRLinker::computeTypeMapping() {
|
||||||
// At this point, the destination module may have a type "%foo = { i32 }" for
|
// At this point, the destination module may have a type "%foo = { i32 }" for
|
||||||
// example. When the source module got loaded into the same LLVMContext, if
|
// example. When the source module got loaded into the same LLVMContext, if
|
||||||
// it had the same type, it would have been renamed to "%foo.42 = { i32 }".
|
// it had the same type, it would have been renamed to "%foo.42 = { i32 }".
|
||||||
std::vector<StructType *> Types = SrcM.getIdentifiedStructTypes();
|
std::vector<StructType *> Types = SrcM->getIdentifiedStructTypes();
|
||||||
for (StructType *ST : Types) {
|
for (StructType *ST : Types) {
|
||||||
if (!ST->hasName())
|
if (!ST->hasName())
|
||||||
continue;
|
continue;
|
||||||
|
@ -1126,8 +1126,8 @@ bool IRLinker::linkFunctionBody(Function &Dst, Function &Src) {
|
||||||
// a function and before remapping metadata on instructions below
|
// a function and before remapping metadata on instructions below
|
||||||
// in RemapInstruction, as the saved mapping is used to handle
|
// in RemapInstruction, as the saved mapping is used to handle
|
||||||
// the temporary metadata hanging off instructions.
|
// the temporary metadata hanging off instructions.
|
||||||
SrcM.getMaterializer()->saveMetadataList(MetadataToIDs,
|
SrcM->getMaterializer()->saveMetadataList(MetadataToIDs,
|
||||||
/* OnlyTempMD = */ true);
|
/* OnlyTempMD = */ true);
|
||||||
|
|
||||||
// Link in the prefix data.
|
// Link in the prefix data.
|
||||||
if (Src.hasPrefixData())
|
if (Src.hasPrefixData())
|
||||||
|
@ -1218,7 +1218,7 @@ void IRLinker::findReachedSubprograms(
|
||||||
void IRLinker::findNeededSubprograms() {
|
void IRLinker::findNeededSubprograms() {
|
||||||
// Track unneeded nodes to make it simpler to handle the case
|
// Track unneeded nodes to make it simpler to handle the case
|
||||||
// where we are checking if an already-mapped SP is needed.
|
// where we are checking if an already-mapped SP is needed.
|
||||||
NamedMDNode *CompileUnits = SrcM.getNamedMetadata("llvm.dbg.cu");
|
NamedMDNode *CompileUnits = SrcM->getNamedMetadata("llvm.dbg.cu");
|
||||||
if (!CompileUnits)
|
if (!CompileUnits)
|
||||||
return;
|
return;
|
||||||
for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
|
for (unsigned I = 0, E = CompileUnits->getNumOperands(); I != E; ++I) {
|
||||||
|
@ -1290,8 +1290,8 @@ void IRLinker::stripNullSubprograms(DICompileUnit *CU) {
|
||||||
/// Insert all of the named MDNodes in Src into the Dest module.
|
/// Insert all of the named MDNodes in Src into the Dest module.
|
||||||
void IRLinker::linkNamedMDNodes() {
|
void IRLinker::linkNamedMDNodes() {
|
||||||
findNeededSubprograms();
|
findNeededSubprograms();
|
||||||
const NamedMDNode *SrcModFlags = SrcM.getModuleFlagsMetadata();
|
const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
|
||||||
for (const NamedMDNode &NMD : SrcM.named_metadata()) {
|
for (const NamedMDNode &NMD : SrcM->named_metadata()) {
|
||||||
// Don't link module flags here. Do them separately.
|
// Don't link module flags here. Do them separately.
|
||||||
if (&NMD == SrcModFlags)
|
if (&NMD == SrcModFlags)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1314,7 +1314,7 @@ void IRLinker::linkNamedMDNodes() {
|
||||||
/// Merge the linker flags in Src into the Dest module.
|
/// Merge the linker flags in Src into the Dest module.
|
||||||
bool IRLinker::linkModuleFlagsMetadata() {
|
bool IRLinker::linkModuleFlagsMetadata() {
|
||||||
// If the source module has no module flags, we are done.
|
// If the source module has no module flags, we are done.
|
||||||
const NamedMDNode *SrcModFlags = SrcM.getModuleFlagsMetadata();
|
const NamedMDNode *SrcModFlags = SrcM->getModuleFlagsMetadata();
|
||||||
if (!SrcModFlags)
|
if (!SrcModFlags)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1495,37 +1495,38 @@ bool IRLinker::run() {
|
||||||
// Inherit the target data from the source module if the destination module
|
// Inherit the target data from the source module if the destination module
|
||||||
// doesn't have one already.
|
// doesn't have one already.
|
||||||
if (DstM.getDataLayout().isDefault())
|
if (DstM.getDataLayout().isDefault())
|
||||||
DstM.setDataLayout(SrcM.getDataLayout());
|
DstM.setDataLayout(SrcM->getDataLayout());
|
||||||
|
|
||||||
if (SrcM.getDataLayout() != DstM.getDataLayout()) {
|
if (SrcM->getDataLayout() != DstM.getDataLayout()) {
|
||||||
emitWarning("Linking two modules of different data layouts: '" +
|
emitWarning("Linking two modules of different data layouts: '" +
|
||||||
SrcM.getModuleIdentifier() + "' is '" +
|
SrcM->getModuleIdentifier() + "' is '" +
|
||||||
SrcM.getDataLayoutStr() + "' whereas '" +
|
SrcM->getDataLayoutStr() + "' whereas '" +
|
||||||
DstM.getModuleIdentifier() + "' is '" +
|
DstM.getModuleIdentifier() + "' is '" +
|
||||||
DstM.getDataLayoutStr() + "'\n");
|
DstM.getDataLayoutStr() + "'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the target triple from the source to dest if the dest's is empty.
|
// Copy the target triple from the source to dest if the dest's is empty.
|
||||||
if (DstM.getTargetTriple().empty() && !SrcM.getTargetTriple().empty())
|
if (DstM.getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
|
||||||
DstM.setTargetTriple(SrcM.getTargetTriple());
|
DstM.setTargetTriple(SrcM->getTargetTriple());
|
||||||
|
|
||||||
Triple SrcTriple(SrcM.getTargetTriple()), DstTriple(DstM.getTargetTriple());
|
Triple SrcTriple(SrcM->getTargetTriple()), DstTriple(DstM.getTargetTriple());
|
||||||
|
|
||||||
if (!SrcM.getTargetTriple().empty() && !triplesMatch(SrcTriple, DstTriple))
|
if (!SrcM->getTargetTriple().empty() && !triplesMatch(SrcTriple, DstTriple))
|
||||||
emitWarning("Linking two modules of different target triples: " +
|
emitWarning("Linking two modules of different target triples: " +
|
||||||
SrcM.getModuleIdentifier() + "' is '" + SrcM.getTargetTriple() +
|
SrcM->getModuleIdentifier() + "' is '" +
|
||||||
"' whereas '" + DstM.getModuleIdentifier() + "' is '" +
|
SrcM->getTargetTriple() + "' whereas '" +
|
||||||
DstM.getTargetTriple() + "'\n");
|
DstM.getModuleIdentifier() + "' is '" + DstM.getTargetTriple() +
|
||||||
|
"'\n");
|
||||||
|
|
||||||
DstM.setTargetTriple(mergeTriples(SrcTriple, DstTriple));
|
DstM.setTargetTriple(mergeTriples(SrcTriple, DstTriple));
|
||||||
|
|
||||||
// Append the module inline asm string.
|
// Append the module inline asm string.
|
||||||
if (!SrcM.getModuleInlineAsm().empty()) {
|
if (!SrcM->getModuleInlineAsm().empty()) {
|
||||||
if (DstM.getModuleInlineAsm().empty())
|
if (DstM.getModuleInlineAsm().empty())
|
||||||
DstM.setModuleInlineAsm(SrcM.getModuleInlineAsm());
|
DstM.setModuleInlineAsm(SrcM->getModuleInlineAsm());
|
||||||
else
|
else
|
||||||
DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() + "\n" +
|
DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() + "\n" +
|
||||||
SrcM.getModuleInlineAsm());
|
SrcM->getModuleInlineAsm());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over all of the linked values to compute type mappings.
|
// Loop over all of the linked values to compute type mappings.
|
||||||
|
@ -1560,10 +1561,10 @@ bool IRLinker::run() {
|
||||||
// we don't actually link anything from source.
|
// we don't actually link anything from source.
|
||||||
if (IsMetadataLinkingPostpass) {
|
if (IsMetadataLinkingPostpass) {
|
||||||
// Ensure metadata materialized
|
// Ensure metadata materialized
|
||||||
if (SrcM.getMaterializer()->materializeMetadata())
|
if (SrcM->getMaterializer()->materializeMetadata())
|
||||||
return true;
|
return true;
|
||||||
SrcM.getMaterializer()->saveMetadataList(MetadataToIDs,
|
SrcM->getMaterializer()->saveMetadataList(MetadataToIDs,
|
||||||
/* OnlyTempMD = */ false);
|
/* OnlyTempMD = */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
linkNamedMDNodes();
|
linkNamedMDNodes();
|
||||||
|
@ -1694,12 +1695,13 @@ IRMover::IRMover(Module &M) : Composite(M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRMover::move(
|
bool IRMover::move(
|
||||||
Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
|
std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
|
||||||
std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor,
|
std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap,
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap,
|
||||||
bool IsMetadataLinkingPostpass) {
|
bool IsMetadataLinkingPostpass) {
|
||||||
IRLinker TheIRLinker(Composite, IdentifiedStructTypes, Src, ValuesToLink,
|
IRLinker TheIRLinker(Composite, IdentifiedStructTypes, std::move(Src),
|
||||||
AddLazyFor, ValIDToTempMDMap, IsMetadataLinkingPostpass);
|
ValuesToLink, AddLazyFor, ValIDToTempMDMap,
|
||||||
|
IsMetadataLinkingPostpass);
|
||||||
bool RetCode = TheIRLinker.run();
|
bool RetCode = TheIRLinker.run();
|
||||||
Composite.dropTriviallyDeadConstantArrays();
|
Composite.dropTriviallyDeadConstantArrays();
|
||||||
return RetCode;
|
return RetCode;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace {
|
||||||
/// entrypoint for this file.
|
/// entrypoint for this file.
|
||||||
class ModuleLinker {
|
class ModuleLinker {
|
||||||
IRMover &Mover;
|
IRMover &Mover;
|
||||||
Module &SrcM;
|
std::unique_ptr<Module> SrcM;
|
||||||
|
|
||||||
SetVector<GlobalValue *> ValuesToLink;
|
SetVector<GlobalValue *> ValuesToLink;
|
||||||
StringSet<> Internalize;
|
StringSet<> Internalize;
|
||||||
|
@ -71,7 +71,7 @@ class ModuleLinker {
|
||||||
|
|
||||||
/// Should we have mover and linker error diag info?
|
/// Should we have mover and linker error diag info?
|
||||||
bool emitError(const Twine &Message) {
|
bool emitError(const Twine &Message) {
|
||||||
SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
|
SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +123,11 @@ class ModuleLinker {
|
||||||
bool doImportAsDefinition(const GlobalValue *SGV);
|
bool doImportAsDefinition(const GlobalValue *SGV);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModuleLinker(IRMover &Mover, Module &SrcM, unsigned Flags,
|
ModuleLinker(IRMover &Mover, std::unique_ptr<Module> SrcM, unsigned Flags,
|
||||||
const FunctionInfoIndex *Index = nullptr,
|
const FunctionInfoIndex *Index = nullptr,
|
||||||
DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
|
DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr)
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr)
|
||||||
: Mover(Mover), SrcM(SrcM), Flags(Flags), ImportIndex(Index),
|
: Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags), ImportIndex(Index),
|
||||||
FunctionsToImport(FunctionsToImport),
|
FunctionsToImport(FunctionsToImport),
|
||||||
ValIDToTempMDMap(ValIDToTempMDMap) {
|
ValIDToTempMDMap(ValIDToTempMDMap) {
|
||||||
assert((ImportIndex || !FunctionsToImport) &&
|
assert((ImportIndex || !FunctionsToImport) &&
|
||||||
|
@ -137,7 +137,7 @@ public:
|
||||||
// backend compilation, and we need to see if it has functions that
|
// backend compilation, and we need to see if it has functions that
|
||||||
// may be exported to another backend compilation.
|
// may be exported to another backend compilation.
|
||||||
if (ImportIndex && !FunctionsToImport)
|
if (ImportIndex && !FunctionsToImport)
|
||||||
HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
|
HasExportedFunctions = ImportIndex->hasExportedFunctions(*this->SrcM);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run();
|
bool run();
|
||||||
|
@ -221,11 +221,11 @@ bool ModuleLinker::computeResultingSelectionKind(StringRef ComdatName,
|
||||||
const GlobalVariable *DstGV;
|
const GlobalVariable *DstGV;
|
||||||
const GlobalVariable *SrcGV;
|
const GlobalVariable *SrcGV;
|
||||||
if (getComdatLeader(DstM, ComdatName, DstGV) ||
|
if (getComdatLeader(DstM, ComdatName, DstGV) ||
|
||||||
getComdatLeader(SrcM, ComdatName, SrcGV))
|
getComdatLeader(*SrcM, ComdatName, SrcGV))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const DataLayout &DstDL = DstM.getDataLayout();
|
const DataLayout &DstDL = DstM.getDataLayout();
|
||||||
const DataLayout &SrcDL = SrcM.getDataLayout();
|
const DataLayout &SrcDL = SrcM->getDataLayout();
|
||||||
uint64_t DstSize = DstDL.getTypeAllocSize(DstGV->getValueType());
|
uint64_t DstSize = DstDL.getTypeAllocSize(DstGV->getValueType());
|
||||||
uint64_t SrcSize = SrcDL.getTypeAllocSize(SrcGV->getValueType());
|
uint64_t SrcSize = SrcDL.getTypeAllocSize(SrcGV->getValueType());
|
||||||
if (Result == Comdat::SelectionKind::ExactMatch) {
|
if (Result == Comdat::SelectionKind::ExactMatch) {
|
||||||
|
@ -471,7 +471,7 @@ void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModuleLinker::run() {
|
bool ModuleLinker::run() {
|
||||||
for (const auto &SMEC : SrcM.getComdatSymbolTable()) {
|
for (const auto &SMEC : SrcM->getComdatSymbolTable()) {
|
||||||
const Comdat &C = SMEC.getValue();
|
const Comdat &C = SMEC.getValue();
|
||||||
if (ComdatsChosen.count(&C))
|
if (ComdatsChosen.count(&C))
|
||||||
continue;
|
continue;
|
||||||
|
@ -482,34 +482,34 @@ bool ModuleLinker::run() {
|
||||||
ComdatsChosen[&C] = std::make_pair(SK, LinkFromSrc);
|
ComdatsChosen[&C] = std::make_pair(SK, LinkFromSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (GlobalVariable &GV : SrcM.globals())
|
for (GlobalVariable &GV : SrcM->globals())
|
||||||
if (const Comdat *SC = GV.getComdat())
|
if (const Comdat *SC = GV.getComdat())
|
||||||
ComdatMembers[SC].push_back(&GV);
|
ComdatMembers[SC].push_back(&GV);
|
||||||
|
|
||||||
for (Function &SF : SrcM)
|
for (Function &SF : *SrcM)
|
||||||
if (const Comdat *SC = SF.getComdat())
|
if (const Comdat *SC = SF.getComdat())
|
||||||
ComdatMembers[SC].push_back(&SF);
|
ComdatMembers[SC].push_back(&SF);
|
||||||
|
|
||||||
for (GlobalAlias &GA : SrcM.aliases())
|
for (GlobalAlias &GA : SrcM->aliases())
|
||||||
if (const Comdat *SC = GA.getComdat())
|
if (const Comdat *SC = GA.getComdat())
|
||||||
ComdatMembers[SC].push_back(&GA);
|
ComdatMembers[SC].push_back(&GA);
|
||||||
|
|
||||||
// Insert all of the globals in src into the DstM module... without linking
|
// Insert all of the globals in src into the DstM module... without linking
|
||||||
// initializers (which could refer to functions not yet mapped over).
|
// initializers (which could refer to functions not yet mapped over).
|
||||||
for (GlobalVariable &GV : SrcM.globals())
|
for (GlobalVariable &GV : SrcM->globals())
|
||||||
if (linkIfNeeded(GV))
|
if (linkIfNeeded(GV))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (Function &SF : SrcM)
|
for (Function &SF : *SrcM)
|
||||||
if (linkIfNeeded(SF))
|
if (linkIfNeeded(SF))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (GlobalAlias &GA : SrcM.aliases())
|
for (GlobalAlias &GA : SrcM->aliases())
|
||||||
if (linkIfNeeded(GA))
|
if (linkIfNeeded(GA))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (ImportIndex) {
|
if (ImportIndex) {
|
||||||
FunctionImportGlobalProcessing ThinLTOProcessing(SrcM, ImportIndex,
|
FunctionImportGlobalProcessing ThinLTOProcessing(*SrcM, ImportIndex,
|
||||||
FunctionsToImport);
|
FunctionsToImport);
|
||||||
if (ThinLTOProcessing.run())
|
if (ThinLTOProcessing.run())
|
||||||
return true;
|
return true;
|
||||||
|
@ -531,7 +531,7 @@ bool ModuleLinker::run() {
|
||||||
Internalize.insert(GV->getName());
|
Internalize.insert(GV->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Mover.move(SrcM, ValuesToLink.getArrayRef(),
|
if (Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
|
||||||
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
|
[this](GlobalValue &GV, IRMover::ValueAdder Add) {
|
||||||
addLazyFor(GV, Add);
|
addLazyFor(GV, Add);
|
||||||
},
|
},
|
||||||
|
@ -552,16 +552,16 @@ bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags,
|
||||||
const FunctionInfoIndex *Index,
|
const FunctionInfoIndex *Index,
|
||||||
DenseSet<const GlobalValue *> *FunctionsToImport,
|
DenseSet<const GlobalValue *> *FunctionsToImport,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
|
||||||
ModuleLinker ModLinker(Mover, *Src, Flags, Index, FunctionsToImport,
|
ModuleLinker ModLinker(Mover, std::move(Src), Flags, Index, FunctionsToImport,
|
||||||
ValIDToTempMDMap);
|
ValIDToTempMDMap);
|
||||||
return ModLinker.run();
|
return ModLinker.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Linker::linkInMetadata(Module &Src,
|
bool Linker::linkInMetadata(std::unique_ptr<Module> Src,
|
||||||
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
|
DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) {
|
||||||
SetVector<GlobalValue *> ValuesToLink;
|
SetVector<GlobalValue *> ValuesToLink;
|
||||||
if (Mover.move(
|
if (Mover.move(
|
||||||
Src, ValuesToLink.getArrayRef(),
|
std::move(Src), ValuesToLink.getArrayRef(),
|
||||||
[this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); },
|
[this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); },
|
||||||
ValIDToTempMDMap, true))
|
ValIDToTempMDMap, true))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -906,7 +906,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
|
||||||
else if (M->getTargetTriple().empty())
|
else if (M->getTargetTriple().empty())
|
||||||
M->setTargetTriple(DefaultTriple);
|
M->setTargetTriple(DefaultTriple);
|
||||||
|
|
||||||
if (L.move(*M, Keep, [](GlobalValue &, IRMover::ValueAdder) {}))
|
if (L.move(std::move(M), Keep, [](GlobalValue &, IRMover::ValueAdder) {}))
|
||||||
message(LDPL_FATAL, "Failed to link module");
|
message(LDPL_FATAL, "Failed to link module");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ static bool importFunctions(const char *argv0, LLVMContext &Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link in all necessary metadata from this module.
|
// Link in all necessary metadata from this module.
|
||||||
if (L.linkInMetadata(*M, SME.getValue().get()))
|
if (L.linkInMetadata(std::move(M), SME.getValue().get()))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue