From dc1414b3f950cb389775b634706a6635535ed825 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 6 Feb 2016 00:46:09 +0000 Subject: [PATCH] llvm-bcanalyzer: Produce summary information for the BLOCKINFO block, it can be a significant fraction of the file size (for files that otherwise have few records). Also include an average size per record in the summary information. llvm-svn: 259965 --- llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 48523f9..1a4bc9e 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -406,13 +406,13 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, BlockStats.NumInstances++; // BLOCKINFO is a special part of the stream. + bool DumpRecords = Dump; if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { if (Dump) outs() << Indent << "\n"; - if (Stream.ReadBlockInfoBlock()) + if (BitstreamCursor(Stream).ReadBlockInfoBlock()) return Error("Malformed BlockInfoBlock"); - uint64_t BlockBitEnd = Stream.GetCurrentBitNo(); - BlockStats.NumBits += BlockBitEnd-BlockBitStart; - return false; + // It's not really interesting to dump the contents of the blockinfo block. + DumpRecords = false; } unsigned NumWords = 0; @@ -420,7 +420,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, return Error("Malformed block record"); const char *BlockName = nullptr; - if (Dump) { + if (DumpRecords) { outs() << Indent << "<"; if ((BlockName = GetBlockName(BlockID, *Stream.getBitStreamReader(), CurStreamType))) @@ -453,7 +453,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, case BitstreamEntry::EndBlock: { uint64_t BlockBitEnd = Stream.GetCurrentBitNo(); BlockStats.NumBits += BlockBitEnd-BlockBitStart; - if (Dump) { + if (DumpRecords) { outs() << Indent << "\n"; @@ -503,7 +503,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, ++BlockStats.NumAbbreviatedRecords; } - if (Dump) { + if (DumpRecords) { outs() << Indent << " <"; if (const char *CodeName = GetCodeName(Code, BlockID, *Stream.getBitStreamReader(), @@ -764,7 +764,7 @@ static int AnalyzeBitcode() { std::reverse(FreqPairs.begin(), FreqPairs.end()); outs() << "\tRecord Histogram:\n"; - outs() << "\t\t Count # Bits %% Abv Record Kind\n"; + outs() << "\t\t Count # Bits b/Rec % Abv Record Kind\n"; for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; @@ -772,13 +772,20 @@ static int AnalyzeBitcode() { RecStats.NumInstances, (unsigned long)RecStats.TotalBits); + if (RecStats.NumInstances > 1) + outs() << format(" %9.1f", + (double)RecStats.TotalBits/RecStats.NumInstances); + else + outs() << " "; + if (RecStats.NumAbbrev) outs() << - format("%7.2f ", + format(" %7.2f", (double)RecStats.NumAbbrev/RecStats.NumInstances*100); else - outs() << " "; + outs() << " "; + outs() << " "; if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first, StreamFile, CurStreamType)) -- 2.7.4