ModuleSummaryIndex.cpp [plain text]
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/ADT/StringMap.h"
using namespace llvm;
void ModuleSummaryIndex::mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other,
uint64_t NextModuleId) {
StringRef ModPath;
for (auto &OtherGlobalValSummaryLists : *Other) {
GlobalValue::GUID ValueGUID = OtherGlobalValSummaryLists.first;
GlobalValueSummaryList &List = OtherGlobalValSummaryLists.second;
assert(List.size() == 1);
std::unique_ptr<GlobalValueSummary> Summary = std::move(List.front());
if (ModPath.empty()) {
auto Path = Summary->modulePath();
ModPath = addModulePath(Path, NextModuleId, Other->getModuleHash(Path))
->first();
} else
assert(ModPath == Summary->modulePath() &&
"Each module in the combined map should have a unique ID");
Summary->setModulePath(ModPath);
addGlobalValueSummary(ValueGUID, std::move(Summary));
}
}
void ModuleSummaryIndex::removeEmptySummaryEntries() {
for (auto MI = begin(), MIE = end(); MI != MIE;) {
assert(MI->second.size() == 1);
if (!MI->second[0])
MI = GlobalValueMap.erase(MI);
else
++MI;
}
}
void ModuleSummaryIndex::collectDefinedFunctionsForModule(
StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
for (auto &GlobalList : *this) {
auto GUID = GlobalList.first;
for (auto &GlobSummary : GlobalList.second) {
auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
if (!Summary)
continue;
if (Summary->modulePath() != ModulePath)
continue;
GVSummaryMap[GUID] = Summary;
}
}
}
void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const {
for (auto &GlobalList : *this) {
auto GUID = GlobalList.first;
for (auto &Summary : GlobalList.second) {
ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
}
}
}
GlobalValueSummary *
ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
bool PerModuleIndex) const {
auto SummaryList = findGlobalValueSummaryList(ValueGUID);
assert(SummaryList != end() && "GlobalValue not found in index");
assert((!PerModuleIndex || SummaryList->second.size() == 1) &&
"Expected a single entry per global value in per-module index");
auto &Summary = SummaryList->second[0];
return Summary.get();
}