Changeset View
Changeset View
Standalone View
Standalone View
lib/Bitcode/Reader/BitcodeReader.cpp
Show First 20 Lines • Show All 5,659 Lines • ▼ Show 20 Lines | case BitstreamEntry::SubBlock: | ||||
case bitc::MODULE_STRTAB_BLOCK_ID: | case bitc::MODULE_STRTAB_BLOCK_ID: | ||||
if (std::error_code EC = parseModuleStringTable()) | if (std::error_code EC = parseModuleStringTable()) | ||||
return EC; | return EC; | ||||
break; | break; | ||||
} | } | ||||
continue; | continue; | ||||
case BitstreamEntry::Record: | case BitstreamEntry::Record: | ||||
// Once we find the last record of interest, skip the rest. | { | ||||
if (VSTOffset > 0) | |||||
Stream.skipRecord(Entry.ID); | |||||
else { | |||||
Record.clear(); | Record.clear(); | ||||
auto BitCode = Stream.readRecord(Entry.ID, Record); | auto BitCode = Stream.readRecord(Entry.ID, Record); | ||||
switch (BitCode) { | switch (BitCode) { | ||||
default: | default: | ||||
break; // Default behavior, ignore unknown content. | break; // Default behavior, ignore unknown content. | ||||
/// MODULE_CODE_SOURCE_FILENAME: [namechar x N] | /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] | ||||
case bitc::MODULE_CODE_SOURCE_FILENAME: { | case bitc::MODULE_CODE_SOURCE_FILENAME: { | ||||
SmallString<128> ValueName; | SmallString<128> ValueName; | ||||
if (convertToString(Record, 0, ValueName)) | if (convertToString(Record, 0, ValueName)) | ||||
return error("Invalid record"); | return error("Invalid record"); | ||||
SourceFileName = ValueName.c_str(); | SourceFileName = ValueName.c_str(); | ||||
break; | break; | ||||
} | } | ||||
/// MODULE_CODE_HASH: [unsigned] | |||||
tejohnson: 5*i32? Assert below checking for 5 values. And 32*5==160, so that seems like the right number. | |||||
case bitc::MODULE_CODE_HASH: { | |||||
if (Record.size() != 1) | |||||
return error("Invalid hash length"); | |||||
if (TheIndex->modulePaths().empty()) | |||||
return error("Didn't populate module info?"); | |||||
if (TheIndex->modulePaths().size() != 1) | |||||
return error("Don't expect multiple module defined?"); | |||||
TheIndex->modulePaths().begin()->second.second = Record[0]; | |||||
break; | |||||
} | |||||
/// MODULE_CODE_VSTOFFSET: [offset] | /// MODULE_CODE_VSTOFFSET: [offset] | ||||
case bitc::MODULE_CODE_VSTOFFSET: | case bitc::MODULE_CODE_VSTOFFSET: | ||||
if (Record.size() < 1) | if (Record.size() < 1) | ||||
return error("Invalid record"); | return error("Invalid record"); | ||||
VSTOffset = Record[0]; | VSTOffset = Record[0]; | ||||
break; | break; | ||||
// GLOBALVAR: [pointer type, isconst, initid, | // GLOBALVAR: [pointer type, isconst, initid, | ||||
// linkage, alignment, section, visibility, threadlocal, | // linkage, alignment, section, visibility, threadlocal, | ||||
▲ Show 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | case BitstreamEntry::Record: | ||||
break; | break; | ||||
} | } | ||||
Record.clear(); | Record.clear(); | ||||
switch (Stream.readRecord(Entry.ID, Record)) { | switch (Stream.readRecord(Entry.ID, Record)) { | ||||
default: // Default behavior: ignore. | default: // Default behavior: ignore. | ||||
break; | break; | ||||
case bitc::MST_CODE_ENTRY: { | case bitc::MST_CODE_ENTRY: { | ||||
// MST_ENTRY: [modid, namechar x N] | // MST_ENTRY: [modid, hash, namechar x N] | ||||
if (convertToString(Record, 1, ModulePath)) | if (convertToString(Record, 2, ModulePath)) | ||||
return error("Invalid record"); | return error("Invalid record"); | ||||
Why is this one 6*i32 whereas the MODULE_CODE_HASH is only expected to have 5 i32 (according to implementation, comment above incorrectly says it is 6*i32)? tejohnson: Why is this one 6*i32 whereas the MODULE_CODE_HASH is only expected to have 5 i32 (according to… | |||||
uint64_t ModuleId = Record[0]; | uint64_t ModuleId = Record[0]; | ||||
StringRef ModulePathInMap = TheIndex->addModulePath(ModulePath, ModuleId); | unsigned ModuleHash = Record[1]; | ||||
StringRef ModulePathInMap = | |||||
TheIndex->addModulePath(ModulePath, ModuleId, ModuleHash); | |||||
ModuleIdMap[ModuleId] = ModulePathInMap; | ModuleIdMap[ModuleId] = ModulePathInMap; | ||||
ModulePath.clear(); | ModulePath.clear(); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
llvm_unreachable("Exit infinite loop"); | llvm_unreachable("Exit infinite loop"); | ||||
} | } | ||||
In order for this check to work after the first module id + hash is encountered, LastSeenModulePath needs to be set to the end() after it is used in the for loop below. Otherwise it will silently overwrite the earlier module path's values if not preceded by a new module path. tejohnson: In order for this check to work after the first module id + hash is encountered… | |||||
// Parse the function info index from the bitcode streamer into the given index. | // Parse the function info index from the bitcode streamer into the given index. | ||||
std::error_code FunctionIndexBitcodeReader::parseSummaryIndexInto( | std::error_code FunctionIndexBitcodeReader::parseSummaryIndexInto( | ||||
std::unique_ptr<DataStreamer> Streamer, FunctionInfoIndex *I) { | std::unique_ptr<DataStreamer> Streamer, FunctionInfoIndex *I) { | ||||
TheIndex = I; | TheIndex = I; | ||||
if (std::error_code EC = initStream(std::move(Streamer))) | if (std::error_code EC = initStream(std::move(Streamer))) | ||||
return EC; | return EC; | ||||
Not Done ReplyInline Actionss/unexpectingly/unexpectedly/ tejohnson: s/unexpectingly/unexpectedly/ | |||||
// Sniff for the signature. | // Sniff for the signature. | ||||
if (!hasValidBitcodeHeader(Stream)) | if (!hasValidBitcodeHeader(Stream)) | ||||
return error("Invalid bitcode signature"); | return error("Invalid bitcode signature"); | ||||
// We expect a number of well-defined blocks, though we don't necessarily | // We expect a number of well-defined blocks, though we don't necessarily | ||||
// need to understand them all. | // need to understand them all. | ||||
while (1) { | while (1) { | ||||
if (Stream.AtEndOfStream()) { | if (Stream.AtEndOfStream()) { | ||||
▲ Show 20 Lines • Show All 318 Lines • Show Last 20 Lines |
5*i32? Assert below checking for 5 values. And 32*5==160, so that seems like the right number. And update the description of this record accordingly in LLVMBitCodes.h where it just says [unsigned].