From 28e457bccd6d1dd6ba91d36253073372a1bb5d75 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Sun, 24 Apr 2016 14:57:11 +0000 Subject: [ThinLTO] Remove GlobalValueInfo class from index Summary: Remove the GlobalValueInfo and change the ModuleSummaryIndex to directly reference summary objects. The info structure was there to support lazy parsing of the combined index summary objects, which is no longer needed and not supported. Reviewers: joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D19462 llvm-svn: 267344 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 77 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 715d66f052e..c68a2929dbe 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -246,7 +246,7 @@ private: DenseMap &FunctionToBitcodeIndex); void writeBlockInfo(); void writePerModuleFunctionSummaryRecord(SmallVector &NameVals, - GlobalValueInfo *Info, + GlobalValueSummary *Summary, unsigned ValueID, unsigned FSCallsAbbrev, unsigned FSCallsProfileAbbrev, @@ -270,6 +270,10 @@ class IndexBitcodeWriter : public BitcodeWriter { /// Tracks the last value id recorded in the GUIDToValueMap. unsigned GlobalValueId = 0; + /// Record the starting offset of each summary entry for use in the VST + /// entry, and for any possible alias. + DenseMap SummaryToOffsetMap; + public: /// Constructs a IndexBitcodeWriter object for the given combined index, /// writing to the provided \p Buffer. @@ -2639,15 +2643,17 @@ void IndexBitcodeWriter::writeCombinedValueSymbolTable() { SmallVector NameVals; - for (const auto &FII : Index) { - GlobalValue::GUID FuncGUID = FII.first; - unsigned ValueId = popValueId(FuncGUID); + for (const auto &GSI : Index) { + GlobalValue::GUID ValGUID = GSI.first; + unsigned ValueId = popValueId(ValGUID); - for (const auto &FI : FII.second) { + for (const auto &SI : GSI.second) { // VST_CODE_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid] NameVals.push_back(ValueId); - NameVals.push_back(FI->bitcodeIndex()); - NameVals.push_back(FuncGUID); + auto Offset = SummaryToOffsetMap[SI.get()]; + assert(Offset); + NameVals.push_back(Offset); + NameVals.push_back(ValGUID); // Emit the finished record. Stream.EmitRecord(bitc::VST_CODE_COMBINED_GVDEFENTRY, NameVals, @@ -3031,12 +3037,12 @@ void IndexBitcodeWriter::writeModStrings() { // Helper to emit a single function summary record. void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord( - SmallVector &NameVals, GlobalValueInfo *Info, + SmallVector &NameVals, GlobalValueSummary *Summary, unsigned ValueID, unsigned FSCallsAbbrev, unsigned FSCallsProfileAbbrev, const Function &F) { NameVals.push_back(ValueID); - FunctionSummary *FS = cast(Info->summary()); + FunctionSummary *FS = cast(Summary); NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); NameVals.push_back(FS->instCount()); NameVals.push_back(FS->refs().size()); @@ -3072,8 +3078,8 @@ void ModuleBitcodeWriter::writeModuleLevelReferences( return; NameVals.push_back(VE.getValueID(&V)); NameVals.push_back(getEncodedGVSummaryFlags(V)); - auto *Info = Index->getGlobalValueInfo(V); - GlobalVarSummary *VS = cast(Info->summary()); + auto *Summary = Index->getGlobalValueSummary(V); + GlobalVarSummary *VS = cast(Summary); for (auto Ref : VS->refs()) NameVals.push_back(VE.getValueID(Ref.getValue())); Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals, @@ -3151,9 +3157,9 @@ void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() { if (!F.hasName()) report_fatal_error("Unexpected anonymous function when writing summary"); - auto *Info = Index->getGlobalValueInfo(F); + auto *Summary = Index->getGlobalValueSummary(F); writePerModuleFunctionSummaryRecord( - NameVals, Info, + NameVals, Summary, VE.getValueID(M.getValueSymbolTable().lookup(F.getName())), FSCallsAbbrev, FSCallsProfileAbbrev, F); } @@ -3227,10 +3233,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { unsigned FSAliasAbbrev = Stream.EmitAbbrev(Abbv); // The aliases are emitted as a post-pass, and will point to the summary - // offset id of the aliasee. For this purpose we need to be able to get back - // from the summary to the offset - SmallVector Aliases; - DenseMap SummaryToOffsetMap; + // offset id of the aliasee. Save them in a vector for post-processing. + SmallVector Aliases; SmallVector NameVals; @@ -3244,14 +3248,14 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.clear(); }; - for (const auto &FII : Index) { - for (auto &FI : FII.second) { - GlobalValueSummary *S = FI->summary(); + for (const auto &GSI : Index) { + for (auto &SI : GSI.second) { + GlobalValueSummary *S = SI.get(); assert(S); - if (isa(S)) { + if (auto *AS = dyn_cast(S)) { // Will process aliases as a post-pass because the reader wants all // global to be loaded first. - Aliases.push_back(FI.get()); + Aliases.push_back(AS); continue; } @@ -3262,13 +3266,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.push_back(getValueId(RI.getGUID())); } - // Record the starting offset of this summary entry for use - // in the VST entry. Add the current code size since the - // reader will invoke readRecord after the abbrev id read. - FI->setBitcodeIndex(Stream.GetCurrentBitNo() + - Stream.GetAbbrevIDWidth()); - // Store temporarily the offset in the map for a possible alias. - SummaryToOffsetMap[S] = FI->bitcodeIndex(); + // Record the starting offset of this summary entry for use in the VST + // entry, and for any possible alias. Add the current code size since + // the reader will invoke readRecord after the abbrev id read. + SummaryToOffsetMap[S] = + Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth(); // Emit the finished record. Stream.EmitRecord(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS, NameVals, @@ -3307,12 +3309,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.push_back(EI.second.ProfileCount); } - // Record the starting offset of this summary entry for use - // in the VST entry. Add the current code size since the - // reader will invoke readRecord after the abbrev id read. - FI->setBitcodeIndex(Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth()); - // Store temporarily the offset in the map for a possible alias. - SummaryToOffsetMap[S] = FI->bitcodeIndex(); + // Record the starting offset of this summary entry for use in the VST + // entry, and for any possible alias. Add the current code size since + // the reader will invoke readRecord after the abbrev id read. + SummaryToOffsetMap[S] = + Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth(); unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev); @@ -3326,8 +3327,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { } } - for (auto GVI : Aliases) { - AliasSummary *AS = cast(GVI->summary()); + for (auto *AS : Aliases) { NameVals.push_back(Index.getModuleId(AS->modulePath())); NameVals.push_back(getEncodedGVSummaryFlags(AS->flags())); auto AliaseeOffset = SummaryToOffsetMap[&AS->getAliasee()]; @@ -3337,7 +3337,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { // Record the starting offset of this summary entry for use // in the VST entry. Add the current code size since the // reader will invoke readRecord after the abbrev id read. - GVI->setBitcodeIndex(Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth()); + SummaryToOffsetMap[AS] = + Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth(); // Emit the finished record. Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev); -- cgit v1.2.3