Skip to content

Commit

Permalink
Bitcode: The index used by ModuleSummaryIndexBitcodeReader is now req…
Browse files Browse the repository at this point in the history
…uired, so make it a reference. NFCI.

llvm-svn: 288318
  • Loading branch information
pcc committed Dec 1, 2016
1 parent a46ec9f commit 57f9b8c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Expand Up @@ -763,7 +763,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
/// files/sections.
class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
/// The module index built during parsing.
ModuleSummaryIndex *TheIndex;
ModuleSummaryIndex &TheIndex;

/// Indicates whether we have encountered a global value summary section
/// yet during parsing.
Expand Down Expand Up @@ -797,7 +797,7 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {

public:
ModuleSummaryIndexBitcodeReader(
BitstreamCursor Stream, ModuleSummaryIndex *TheIndex);
BitstreamCursor Stream, ModuleSummaryIndex &TheIndex);

Error parseModule(StringRef ModulePath);

Expand Down Expand Up @@ -5883,7 +5883,7 @@ std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes() const {
}

ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
BitstreamCursor Cursor, ModuleSummaryIndex *TheIndex)
BitstreamCursor Cursor, ModuleSummaryIndex &TheIndex)
: BitcodeReaderBase(std::move(Cursor)), TheIndex(TheIndex) {}

std::pair<GlobalValue::GUID, GlobalValue::GUID>
Expand Down Expand Up @@ -6074,12 +6074,12 @@ Error ModuleSummaryIndexBitcodeReader::parseModule(StringRef ModulePath) {
case bitc::MODULE_CODE_HASH: {
if (Record.size() != 5)
return error("Invalid hash length " + Twine(Record.size()).str());
if (TheIndex->modulePaths().empty())
if (TheIndex.modulePaths().empty())
// We always seed the index with the module.
TheIndex->addModulePath(ModulePath, 0);
if (TheIndex->modulePaths().size() != 1)
TheIndex.addModulePath(ModulePath, 0);
if (TheIndex.modulePaths().size() != 1)
return error("Don't expect multiple modules defined?");
auto &Hash = TheIndex->modulePaths().begin()->second.second;
auto &Hash = TheIndex.modulePaths().begin()->second.second;
int Pos = 0;
for (auto &Val : Record) {
assert(!(Val >> 32) && "Unexpected high bits set");
Expand Down Expand Up @@ -6181,7 +6181,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
// to clean them up (especially since that may not run for the first
// module's index if we merge into that).
if (!Combined)
TheIndex->removeEmptySummaryEntries();
TheIndex.removeEmptySummaryEntries();
return Error::success();
case BitstreamEntry::Record:
// The interesting case.
Expand Down Expand Up @@ -6219,7 +6219,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
// 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.
FS->setModulePath(TheIndex->addModulePath(ModulePath, 0)->first());
FS->setModulePath(TheIndex.addModulePath(ModulePath, 0)->first());
static int RefListStartIndex = 4;
int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
assert(Record.size() >= RefListStartIndex + NumRefs &&
Expand All @@ -6240,7 +6240,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
}
auto GUID = getGUIDFromValueId(ValueID);
FS->setOriginalName(GUID.second);
TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
TheIndex.addGlobalValueSummary(GUID.first, std::move(FS));
break;
}
// FS_ALIAS: [valueid, flags, valueid]
Expand All @@ -6257,17 +6257,17 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
// 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(TheIndex->addModulePath(ModulePath, 0)->first());
AS->setModulePath(TheIndex.addModulePath(ModulePath, 0)->first());

GlobalValue::GUID AliaseeGUID = getGUIDFromValueId(AliaseeID).first;
auto *AliaseeSummary = TheIndex->getGlobalValueSummary(AliaseeGUID);
auto *AliaseeSummary = TheIndex.getGlobalValueSummary(AliaseeGUID);
if (!AliaseeSummary)
return error("Alias expects aliasee summary to be parsed");
AS->setAliasee(AliaseeSummary);

auto GUID = getGUIDFromValueId(ValueID);
AS->setOriginalName(GUID.second);
TheIndex->addGlobalValueSummary(GUID.first, std::move(AS));
TheIndex.addGlobalValueSummary(GUID.first, std::move(AS));
break;
}
// FS_PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, n x valueid]
Expand All @@ -6277,15 +6277,15 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
std::unique_ptr<GlobalVarSummary> FS =
llvm::make_unique<GlobalVarSummary>(Flags);
FS->setModulePath(TheIndex->addModulePath(ModulePath, 0)->first());
FS->setModulePath(TheIndex.addModulePath(ModulePath, 0)->first());
for (unsigned I = 2, E = Record.size(); I != E; ++I) {
unsigned RefValueId = Record[I];
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
FS->addRefEdge(RefGUID);
}
auto GUID = getGUIDFromValueId(ValueID);
FS->setOriginalName(GUID.second);
TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
TheIndex.addGlobalValueSummary(GUID.first, std::move(FS));
break;
}
// FS_COMBINED: [valueid, modid, flags, instcount, numrefs,
Expand Down Expand Up @@ -6324,7 +6324,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
FS->addCallGraphEdge(CalleeGUID, CalleeInfo(Hotness));
}
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
TheIndex.addGlobalValueSummary(GUID, std::move(FS));
Combined = true;
break;
}
Expand All @@ -6343,13 +6343,13 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(

auto AliaseeGUID = getGUIDFromValueId(AliaseeValueId).first;
auto AliaseeInModule =
TheIndex->findSummaryInModule(AliaseeGUID, AS->modulePath());
TheIndex.findSummaryInModule(AliaseeGUID, AS->modulePath());
if (!AliaseeInModule)
return error("Alias expects aliasee summary to be parsed");
AS->setAliasee(AliaseeInModule);

GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(AS));
TheIndex.addGlobalValueSummary(GUID, std::move(AS));
Combined = true;
break;
}
Expand All @@ -6369,7 +6369,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
FS->addRefEdge(RefGUID);
}
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
TheIndex.addGlobalValueSummary(GUID, std::move(FS));
Combined = true;
break;
}
Expand Down Expand Up @@ -6440,7 +6440,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
if (convertToString(Record, 1, ModulePath))
return error("Invalid record");

LastSeenModulePath = TheIndex->addModulePath(ModulePath, ModuleId);
LastSeenModulePath = TheIndex.addModulePath(ModulePath, ModuleId);
ModuleIdMap[ModuleId] = LastSeenModulePath->first();

ModulePath.clear();
Expand All @@ -6450,15 +6450,15 @@ Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
case bitc::MST_CODE_HASH: {
if (Record.size() != 5)
return error("Invalid hash length " + Twine(Record.size()).str());
if (LastSeenModulePath == TheIndex->modulePaths().end())
if (LastSeenModulePath == TheIndex.modulePaths().end())
return error("Invalid hash that does not follow a module path");
int Pos = 0;
for (auto &Val : Record) {
assert(!(Val >> 32) && "Unexpected high bits set");
LastSeenModulePath->second.second[Pos++] = Val;
}
// Reset LastSeenModulePath to avoid overriding the hash unexpectedly.
LastSeenModulePath = TheIndex->modulePaths().end();
LastSeenModulePath = TheIndex.modulePaths().end();
break;
}
}
Expand Down Expand Up @@ -6616,7 +6616,7 @@ Expected<std::unique_ptr<ModuleSummaryIndex>> BitcodeModule::getSummary() {
Stream.JumpToBit(ModuleBit);

auto Index = llvm::make_unique<ModuleSummaryIndex>();
ModuleSummaryIndexBitcodeReader R(std::move(Stream), Index.get());
ModuleSummaryIndexBitcodeReader R(std::move(Stream), *Index);

if (Error Err = R.parseModule(ModuleIdentifier))
return std::move(Err);
Expand Down

0 comments on commit 57f9b8c

Please sign in to comment.