From 144f3acb631f9ad0272e5ec64a5097fd2d170459 Mon Sep 17 00:00:00 2001 From: Easwaran Raman Date: Wed, 24 Jan 2018 18:15:29 +0000 Subject: [PATCH] Revert "[ThinLTO] Add call edges' relative block frequency to per-module summary." Causes buildbot regressions. llvm-svn: 323358 --- include/llvm/Bitcode/LLVMBitCodes.h | 5 --- include/llvm/IR/ModuleSummaryIndex.h | 21 ++-------- lib/Analysis/ModuleSummaryAnalysis.cpp | 21 ++-------- lib/Bitcode/Reader/BitcodeReader.cpp | 23 +++-------- lib/Bitcode/Writer/BitcodeWriter.cpp | 40 +++++++------------ ...hinlto-function-summary-callgraph-relbf.ll | 35 ---------------- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 1 - 7 files changed, 27 insertions(+), 119 deletions(-) delete mode 100644 test/Bitcode/thinlto-function-summary-callgraph-relbf.ll diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h index 7a457744db7..70194c04347 100644 --- a/include/llvm/Bitcode/LLVMBitCodes.h +++ b/include/llvm/Bitcode/LLVMBitCodes.h @@ -256,11 +256,6 @@ enum GlobalValueSummarySymtabCodes { // strings in strtab. // [n * name] FS_CFI_FUNCTION_DECLS = 18, - // Per-module summary that also adds relative block frequency to callee info. - // PERMODULE_RELBF: [valueid, flags, instcount, numrefs, - // numrefs x valueid, - // n x (valueid, relblockfreq)] - FS_PERMODULE_RELBF = 19, }; enum MetadataCodes { diff --git a/include/llvm/IR/ModuleSummaryIndex.h b/include/llvm/IR/ModuleSummaryIndex.h index 8ca6de49c32..17f8951bf0e 100644 --- a/include/llvm/IR/ModuleSummaryIndex.h +++ b/include/llvm/IR/ModuleSummaryIndex.h @@ -25,7 +25,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" -#include "llvm/Support/MathExtras.h" #include #include #include @@ -55,28 +54,14 @@ struct CalleeInfo { Hot = 3, Critical = 4 }; + HotnessType Hotness = HotnessType::Unknown; - // The size of the bit-field might need to be adjusted if more values are - // added to HotnessType enum. - HotnessType Hotness : 3; - uint32_t RelBlockFreq : 29; - static constexpr uint64_t MaxRelBlockFreq = (1 << 29) - 1; - - CalleeInfo() : Hotness(HotnessType::Unknown), RelBlockFreq(0) {} - explicit CalleeInfo(HotnessType Hotness, uint64_t RelBF) - : Hotness(Hotness), RelBlockFreq(RelBF) {} + CalleeInfo() = default; + explicit CalleeInfo(HotnessType Hotness) : Hotness(Hotness) {} void updateHotness(const HotnessType OtherHotness) { Hotness = std::max(Hotness, OtherHotness); } - - // When there are multiple edges between the same (caller, callee) pair, the - // relative block frequencies are summed up. - void updateRelBlockFreq(uint64_t RBF) { - uint64_t Sum = SaturatingAdd(RelBlockFreq, RBF); - Sum = std::min(Sum, uint64_t(MaxRelBlockFreq)); - RelBlockFreq = static_cast(Sum); - } }; class GlobalValueSummary; diff --git a/lib/Analysis/ModuleSummaryAnalysis.cpp b/lib/Analysis/ModuleSummaryAnalysis.cpp index e4a18b7bd45..cf2fe7776dd 100644 --- a/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -273,24 +273,9 @@ computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M, // to record the call edge to the alias in that case. Eventually // an alias summary will be created to associate the alias and // aliasee. - auto &ValueInfo = CallGraphEdges[Index.getOrInsertValueInfo( - cast(CalledValue))]; - ValueInfo.updateHotness(Hotness); - // Add the relative block frequency to CalleeInfo if there is no profile - // information. - if (BFI != nullptr && Hotness == CalleeInfo::HotnessType::Unknown) { - auto BBFreq = BFI->getBlockFreq(CI->getParent()).getFrequency(); - // FIXME: This might need some scaling to prevent BBFreq values from - // being rounded down to 0. - auto EntryFreq = BFI->getEntryFreq(); - // Block frequencies can be directly set for a block and so we need to - // handle the case of entry frequency being 0. - if (EntryFreq) - BBFreq /= EntryFreq; - else - BBFreq = 0; - ValueInfo.updateRelBlockFreq(BBFreq); - } + CallGraphEdges[Index.getOrInsertValueInfo( + cast(CalledValue))] + .updateHotness(Hotness); } else { // Skip inline assembly calls. if (CI && CI->isInlineAsm()) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 9cf1302b030..7ffa6248879 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -743,8 +743,7 @@ private: std::vector makeRefList(ArrayRef Record); std::vector makeCallList(ArrayRef Record, bool IsOldProfileFormat, - bool HasProfile, - bool HasRelBF); + bool HasProfile); Error parseEntireSummary(unsigned ID); Error parseModuleStringTable(); @@ -5048,15 +5047,12 @@ ModuleSummaryIndexBitcodeReader::makeRefList(ArrayRef Record) { return Ret; } -std::vector -ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef Record, - bool IsOldProfileFormat, - bool HasProfile, bool HasRelBF) { +std::vector ModuleSummaryIndexBitcodeReader::makeCallList( + ArrayRef Record, bool IsOldProfileFormat, bool HasProfile) { std::vector Ret; Ret.reserve(Record.size()); for (unsigned I = 0, E = Record.size(); I != E; ++I) { CalleeInfo::HotnessType Hotness = CalleeInfo::HotnessType::Unknown; - uint64_t RelBF = 0; ValueInfo Callee = getValueInfoFromValueId(Record[I]).first; if (IsOldProfileFormat) { I += 1; // Skip old callsitecount field @@ -5064,9 +5060,7 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef Record, I += 1; // Skip old profilecount field } else if (HasProfile) Hotness = static_cast(Record[++I]); - else if (HasRelBF) - RelBF = Record[++I]; - Ret.push_back(FunctionSummary::EdgeTy{Callee, CalleeInfo(Hotness, RelBF)}); + Ret.push_back(FunctionSummary::EdgeTy{Callee, CalleeInfo{Hotness}}); } return Ret; } @@ -5145,11 +5139,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { // FS_PERMODULE_PROFILE: [valueid, flags, instcount, fflags, numrefs, // numrefs x valueid, // n x (valueid, hotness)] - // FS_PERMODULE_RELBF: [valueid, flags, instcount, fflags, numrefs, - // numrefs x valueid, - // n x (valueid, relblockfreq)] case bitc::FS_PERMODULE: - case bitc::FS_PERMODULE_RELBF: case bitc::FS_PERMODULE_PROFILE: { unsigned ValueID = Record[0]; uint64_t RawFlags = Record[1]; @@ -5175,10 +5165,9 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { std::vector Refs = makeRefList( ArrayRef(Record).slice(RefListStartIndex, NumRefs)); bool HasProfile = (BitCode == bitc::FS_PERMODULE_PROFILE); - bool HasRelBF = (BitCode == bitc::FS_PERMODULE_RELBF); std::vector Calls = makeCallList( ArrayRef(Record).slice(CallGraphEdgeStartIndex), - IsOldProfileFormat, HasProfile, HasRelBF); + IsOldProfileFormat, HasProfile); auto FS = llvm::make_unique( Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs), std::move(Calls), std::move(PendingTypeTests), @@ -5270,7 +5259,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { bool HasProfile = (BitCode == bitc::FS_COMBINED_PROFILE); std::vector Edges = makeCallList( ArrayRef(Record).slice(CallGraphEdgeStartIndex), - IsOldProfileFormat, HasProfile, false); + IsOldProfileFormat, HasProfile); ValueInfo VI = getValueInfoFromValueId(ValueID).first; auto FS = llvm::make_unique( Flags, InstCount, getDecodedFFlags(RawFunFlags), std::move(Refs), diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 1b31cd90d6d..3876b5ffe35 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -86,9 +86,6 @@ static cl::opt cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading")); -cl::opt WriteRelBFToSummary( - "write-relbf-to-summary", cl::Hidden, cl::init(false), - cl::desc("Write relative block frequency to function summary ")); namespace { /// These are manifest constants used by the bitcode writer. They do not need to @@ -3381,15 +3378,11 @@ void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord( NameVals.push_back(getValueId(ECI.first)); if (HasProfileData) NameVals.push_back(static_cast(ECI.second.Hotness)); - else if (WriteRelBFToSummary) - NameVals.push_back(ECI.second.RelBlockFreq); } unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev); unsigned Code = - (HasProfileData ? bitc::FS_PERMODULE_PROFILE - : (WriteRelBFToSummary ? bitc::FS_PERMODULE_RELBF - : bitc::FS_PERMODULE)); + (HasProfileData ? bitc::FS_PERMODULE_PROFILE : bitc::FS_PERMODULE); // Emit the finished record. Stream.EmitRecord(Code, NameVals, FSAbbrev); @@ -3455,8 +3448,21 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { ArrayRef{GVI.second, GVI.first}); } - // Abbrev for FS_PERMODULE_PROFILE. + // Abbrev for FS_PERMODULE. auto Abbv = std::make_shared(); + Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // instcount + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // fflags + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // numrefs + // numrefs x valueid, n x (valueid) + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + unsigned FSCallsAbbrev = Stream.EmitAbbrev(std::move(Abbv)); + + // Abbrev for FS_PERMODULE_PROFILE. + Abbv = std::make_shared(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags @@ -3468,22 +3474,6 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); unsigned FSCallsProfileAbbrev = Stream.EmitAbbrev(std::move(Abbv)); - // Abbrev for FS_PERMODULE or FS_PERMODULE_RELBF. - Abbv = std::make_shared(); - if (WriteRelBFToSummary) - Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_RELBF)); - else - Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // instcount - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // fflags - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // numrefs - // numrefs x valueid, n x (valueid [, rel_block_freq]) - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); - unsigned FSCallsAbbrev = Stream.EmitAbbrev(std::move(Abbv)); - // Abbrev for FS_PERMODULE_GLOBALVAR_INIT_REFS. Abbv = std::make_shared(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS)); diff --git a/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll b/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll deleted file mode 100644 index 779acada520..00000000000 --- a/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll +++ /dev/null @@ -1,35 +0,0 @@ -; Test to check the callgraph in summary -; RUN: opt -write-relbf-to-summary -module-summary %s -o %t.o -; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s - - -; CHECK: -; CHECK: