From e1164de5d0c9ae28a943d07eaf8e75f24bfb2d4a Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Wed, 10 Feb 2016 21:55:02 +0000 Subject: Restore "[ThinLTO] Use MD5 hash in function index." with fix This restores commit r260408, along with a fix for a bot failure. The bot failure was caused by dereferencing a unique_ptr in the same call instruction parameter list where it was passed via std::move. Apparently due to luck this was not exposed when I built the compiler with clang, only with gcc. llvm-svn: 260442 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 53 +++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 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 36eff1353957..fbe9391a69af 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -458,6 +458,9 @@ class FunctionIndexBitcodeReader { /// summary records. DenseMap ModuleIdMap; + /// Original source file name recorded in a bitcode record. + std::string SourceFileName; + public: std::error_code error(BitcodeError E, const Twine &Message); std::error_code error(BitcodeError E); @@ -3697,6 +3700,13 @@ std::error_code BitcodeReader::parseModule(uint64_t ResumeBit, assert(MetadataList.size() == 0); MetadataList.resize(NumModuleMDs); break; + /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] + case bitc::MODULE_CODE_SOURCE_FILENAME: + SmallString<128> ValueName; + if (convertToString(Record, 0, ValueName)) + return error("Invalid record"); + TheModule->setSourceFileName(ValueName); + break; } Record.clear(); } @@ -5454,24 +5464,30 @@ std::error_code FunctionIndexBitcodeReader::parseValueSymbolTable() { return error("Invalid record"); unsigned ValueID = Record[0]; uint64_t FuncOffset = Record[1]; - std::unique_ptr FuncInfo = - llvm::make_unique(FuncOffset); - if (foundFuncSummary() && !IsLazy) { + assert(!IsLazy && "Lazy summary read only supported for combined index"); + // Gracefully handle bitcode without a function summary section, + // which will simply not populate the index. + if (foundFuncSummary()) { DenseMap>::iterator SMI = SummaryMap.find(ValueID); assert(SMI != SummaryMap.end() && "Summary info not found"); + std::unique_ptr FuncInfo = + llvm::make_unique(FuncOffset); FuncInfo->setFunctionSummary(std::move(SMI->second)); + assert(!SourceFileName.empty()); + std::string FunctionGlobalId = Function::getGlobalIdentifier( + ValueName, FuncInfo->functionSummary()->getFunctionLinkage(), + SourceFileName); + TheIndex->addFunctionInfo(FunctionGlobalId, std::move(FuncInfo)); } - TheIndex->addFunctionInfo(ValueName, std::move(FuncInfo)); ValueName.clear(); break; } case bitc::VST_CODE_COMBINED_FNENTRY: { - // VST_CODE_FNENTRY: [offset, namechar x N] - if (convertToString(Record, 1, ValueName)) - return error("Invalid record"); + // VST_CODE_COMBINED_FNENTRY: [offset, funcguid] uint64_t FuncSummaryOffset = Record[0]; + uint64_t FuncGUID = Record[1]; std::unique_ptr FuncInfo = llvm::make_unique(FuncSummaryOffset); if (foundFuncSummary() && !IsLazy) { @@ -5480,7 +5496,7 @@ std::error_code FunctionIndexBitcodeReader::parseValueSymbolTable() { assert(SMI != SummaryMap.end() && "Summary info not found"); FuncInfo->setFunctionSummary(std::move(SMI->second)); } - TheIndex->addFunctionInfo(ValueName, std::move(FuncInfo)); + TheIndex->addFunctionInfo(FuncGUID, std::move(FuncInfo)); ValueName.clear(); break; @@ -5499,6 +5515,8 @@ std::error_code FunctionIndexBitcodeReader::parseModule() { if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID)) return error("Invalid record"); + SmallVector Record; + // Read the function index for this module. while (1) { BitstreamEntry Entry = Stream.advance(); @@ -5551,7 +5569,24 @@ std::error_code FunctionIndexBitcodeReader::parseModule() { continue; case BitstreamEntry::Record: - Stream.skipRecord(Entry.ID); + // Once we find the single record of interest, skip the rest. + if (!SourceFileName.empty()) + Stream.skipRecord(Entry.ID); + else { + Record.clear(); + auto BitCode = Stream.readRecord(Entry.ID, Record); + switch (BitCode) { + default: + break; // Default behavior, ignore unknown content. + /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] + case bitc::MODULE_CODE_SOURCE_FILENAME: + SmallString<128> ValueName; + if (convertToString(Record, 0, ValueName)) + return error("Invalid record"); + SourceFileName = ValueName.c_str(); + break; + } + } continue; } } -- cgit v1.2.3