summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-02-10 21:55:02 +0000
committerTeresa Johnson <tejohnson@google.com>2016-02-10 21:55:02 +0000
commite1164de5d0c9ae28a943d07eaf8e75f24bfb2d4a (patch)
tree7b7037f3104679a3f051dd24575543e75180b572 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent3e58a6a7b2b6f6af9ac2b091909e829fe5a21a99 (diff)
downloadbcm5719-llvm-e1164de5d0c9ae28a943d07eaf8e75f24bfb2d4a.tar.gz
bcm5719-llvm-e1164de5d0c9ae28a943d07eaf8e75f24bfb2d4a.zip
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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 36eff135395..fbe9391a69a 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -458,6 +458,9 @@ class FunctionIndexBitcodeReader {
/// summary records.
DenseMap<uint64_t, StringRef> 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<FunctionInfo> FuncInfo =
- llvm::make_unique<FunctionInfo>(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<uint64_t, std::unique_ptr<FunctionSummary>>::iterator SMI =
SummaryMap.find(ValueID);
assert(SMI != SummaryMap.end() && "Summary info not found");
+ std::unique_ptr<FunctionInfo> FuncInfo =
+ llvm::make_unique<FunctionInfo>(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<FunctionInfo> FuncInfo =
llvm::make_unique<FunctionInfo>(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<uint64_t, 64> 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;
}
}
OpenPOWER on IntegriCloud