[ThinLTO] Refactor some common code into getGlobalValueInfo method (NFC)

Refactor common code that queries the ModuleSummaryIndex for a value's
GlobalValueInfo struct into getGlobalValueInfo helper methods, which
will also be used by D18763.

llvm-svn: 265370
This commit is contained in:
Teresa Johnson 2016-04-05 00:40:16 +00:00
parent f164daa424
commit 1c906c4f8e
3 changed files with 28 additions and 12 deletions

View File

@ -309,6 +309,20 @@ public:
GlobalValueMap[ValueGUID].push_back(std::move(Info)); GlobalValueMap[ValueGUID].push_back(std::move(Info));
} }
/// Returns the first GlobalValueInfo for \p GV, asserting that there
/// is only one if \p PerModuleIndex.
GlobalValueInfo *getGlobalValueInfo(const GlobalValue &GV,
bool PerModuleIndex = true) const {
assert(GV.hasName() && "Can't get GlobalValueInfo for GV with no name");
return getGlobalValueInfo(GlobalValue::getGUID(GV.getName()),
PerModuleIndex);
}
/// Returns the first GlobalValueInfo for \p ValueGUID, asserting that there
/// is only one if \p PerModuleIndex.
GlobalValueInfo *getGlobalValueInfo(GlobalValue::GUID ValueGUID,
bool PerModuleIndex = true) const;
/// Table of modules, containing module hash and id. /// Table of modules, containing module hash and id.
const StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() const { const StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() const {
return ModulePathStringTable; return ModulePathStringTable;

View File

@ -5824,12 +5824,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
CalleeInfo(CallsiteCount, ProfileCount)); CalleeInfo(CallsiteCount, ProfileCount));
} }
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID); GlobalValue::GUID GUID = getGUIDFromValueId(ValueID);
auto InfoList = TheIndex->findGlobalValueInfoList(GUID); auto *Info = TheIndex->getGlobalValueInfo(GUID);
assert(InfoList != TheIndex->end() &&
"Expected VST parse to create GlobalValueInfo entry");
assert(InfoList->second.size() == 1 &&
"Expected a single GlobalValueInfo per GUID in module");
auto &Info = InfoList->second[0];
assert(!Info->summary() && "Expected a single summary per VST entry"); assert(!Info->summary() && "Expected a single summary per VST entry");
Info->setSummary(std::move(FS)); Info->setSummary(std::move(FS));
break; break;
@ -5848,12 +5843,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
FS->addRefEdge(RefGUID); FS->addRefEdge(RefGUID);
} }
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID); GlobalValue::GUID GUID = getGUIDFromValueId(ValueID);
auto InfoList = TheIndex->findGlobalValueInfoList(GUID); auto *Info = TheIndex->getGlobalValueInfo(GUID);
assert(InfoList != TheIndex->end() &&
"Expected VST parse to create GlobalValueInfo entry");
assert(InfoList->second.size() == 1 &&
"Expected a single GlobalValueInfo per GUID in module");
auto &Info = InfoList->second[0];
assert(!Info->summary() && "Expected a single summary per VST entry"); assert(!Info->summary() && "Expected a single summary per VST entry");
Info->setSummary(std::move(FS)); Info->setSummary(std::move(FS));
break; break;

View File

@ -68,3 +68,15 @@ void ModuleSummaryIndex::removeEmptySummaryEntries() {
++MI; ++MI;
} }
} }
GlobalValueInfo *
ModuleSummaryIndex::getGlobalValueInfo(uint64_t ValueGUID,
bool PerModuleIndex) const {
auto InfoList = findGlobalValueInfoList(ValueGUID);
assert(InfoList != end() && "GlobalValue not found in index");
assert(!PerModuleIndex ||
InfoList->second.size() == 1 &&
"Expected a single entry per global value in per-module index");
auto &Info = InfoList->second[0];
return Info.get();
}