From 9766fd64fba0c3a8a118aee795133a3bab69a0f5 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 26 Jun 2018 01:32:58 +0000 Subject: [ThinLTO] Add per-module indexes to combined index consistently Summary: Without this change we only add module paths to the combined index when there is a module hash or at least one global value. Make this more consistent by adding the module to the index whenever there is a summary section, and it is a per-module summary (had a MODULE_CODE_SOURCE_FILENAME record). Since we will no longer add module paths lazily, add a new interface to get the module info from the index that asserts it is already added. Fixes PR37899. Reviewers: Vlad, pcc Subscribers: mehdi_amini, inglorion, steven_wu, llvm-commits Differential Revision: https://reviews.llvm.org/D48511 llvm-svn: 335567 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index a0347a154e8..ce2eb077450 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -752,7 +752,8 @@ private: std::pair getValueInfoFromValueId(unsigned ValueId); - ModuleSummaryIndex::ModuleInfo *addThisModule(); + void addThisModule(); + ModuleSummaryIndex::ModuleInfo *getThisModule(); }; } // end anonymous namespace @@ -4807,9 +4808,13 @@ ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader( : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex), ModulePath(ModulePath), ModuleId(ModuleId) {} +void ModuleSummaryIndexBitcodeReader::addThisModule() { + TheIndex.addModule(ModulePath, ModuleId); +} + ModuleSummaryIndex::ModuleInfo * -ModuleSummaryIndexBitcodeReader::addThisModule() { - return TheIndex.addModule(ModulePath, ModuleId); +ModuleSummaryIndexBitcodeReader::getThisModule() { + return TheIndex.getModule(ModulePath); } std::pair @@ -4965,6 +4970,9 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { break; case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID: + // Add the module if it is a per-module index (has a source file name). + if (!SourceFileName.empty()) + addThisModule(); assert(!SeenValueSymbolTable && "Already read VST when parsing summary block?"); // We might not have a VST if there were no values in the @@ -5010,7 +5018,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { case bitc::MODULE_CODE_HASH: { if (Record.size() != 5) return error("Invalid hash length " + Twine(Record.size()).str()); - auto &Hash = addThisModule()->second.second; + auto &Hash = getThisModule()->second.second; int Pos = 0; for (auto &Val : Record) { assert(!(Val >> 32) && "Unexpected high bits set"); @@ -5272,7 +5280,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { PendingTypeTestAssumeConstVCalls.clear(); PendingTypeCheckedLoadConstVCalls.clear(); auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID); - FS->setModulePath(addThisModule()->first()); + FS->setModulePath(getThisModule()->first()); FS->setOriginalName(VIAndOriginalGUID.second); TheIndex.addGlobalValueSummary(VIAndOriginalGUID.first, std::move(FS)); break; @@ -5291,7 +5299,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { // string table section in the per-module index, we create a single // module path string table entry with an empty (0) ID to take // ownership. - AS->setModulePath(addThisModule()->first()); + AS->setModulePath(getThisModule()->first()); GlobalValue::GUID AliaseeGUID = getValueInfoFromValueId(AliaseeID).first.getGUID(); @@ -5315,7 +5323,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { std::vector Refs = makeRefList(ArrayRef(Record).slice(2)); auto FS = llvm::make_unique(Flags, std::move(Refs)); - FS->setModulePath(addThisModule()->first()); + FS->setModulePath(getThisModule()->first()); auto GUID = getValueInfoFromValueId(ValueID); FS->setOriginalName(GUID.second); TheIndex.addGlobalValueSummary(GUID.first, std::move(FS)); -- cgit v1.2.3