Skip to content

[LTO] Make getImportType a proper function (NFC) #106450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
4 changes: 4 additions & 0 deletions llvm/include/llvm/Transforms/IPO/FunctionImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class FunctionImporter {
// order.
SmallVector<StringRef, 0> getSourceModules() const;

std::optional<GlobalValueSummary::ImportKind>
getImportType(const FunctionsToImportTy &GUIDToImportType,
GlobalValue::GUID GUID) const;

const ImportMapTyImpl &getImportMap() const { return ImportMap; }

private:
Expand Down
24 changes: 12 additions & 12 deletions llvm/lib/Transforms/IPO/FunctionImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ FunctionImporter::ImportMapTy::getSourceModules() const {
return Modules;
}

std::optional<GlobalValueSummary::ImportKind>
FunctionImporter::ImportMapTy::getImportType(
const FunctionsToImportTy &GUIDToImportType, GlobalValue::GUID GUID) const {
auto Iter = GUIDToImportType.find(GUID);
if (Iter == GUIDToImportType.end())
return std::nullopt;
return Iter->second;
}

/// Import globals referenced by a function or other globals that are being
/// imported, if importing such global is possible.
class GlobalsImporter final {
Expand Down Expand Up @@ -1800,15 +1809,6 @@ Expected<bool> FunctionImporter::importFunctions(

IRMover Mover(DestModule);

auto getImportType = [&](const FunctionsToImportTy &GUIDToImportType,
GlobalValue::GUID GUID)
-> std::optional<GlobalValueSummary::ImportKind> {
auto Iter = GUIDToImportType.find(GUID);
if (Iter == GUIDToImportType.end())
return std::nullopt;
return Iter->second;
};

// Do the actual import of functions now, one Module at a time
for (const auto &Name : ImportList.getSourceModules()) {
// Get the module for the import
Expand All @@ -1835,7 +1835,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!F.hasName())
continue;
auto GUID = F.getGUID();
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;

LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
Expand Down Expand Up @@ -1871,7 +1871,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!GV.hasName())
continue;
auto GUID = GV.getGUID();
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;

LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
Expand All @@ -1891,7 +1891,7 @@ Expected<bool> FunctionImporter::importFunctions(
if (!GA.hasName() || isa<GlobalIFunc>(GA.getAliaseeObject()))
continue;
auto GUID = GA.getGUID();
auto MaybeImportType = getImportType(ImportGUIDs, GUID);
auto MaybeImportType = ImportList.getImportType(ImportGUIDs, GUID);
bool ImportDefinition = MaybeImportType == GlobalValueSummary::Definition;

LLVM_DEBUG(dbgs() << (MaybeImportType ? "Is" : "Not")
Expand Down
Loading