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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259965 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Richard Smith 2016-02-06 00:46:09 +00:00
parent 04de74cc79
commit 0f73f7ad3b

View File

@ -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 << "<BLOCKINFO_BLOCK/>\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 << "</";
if (BlockName)
outs() << BlockName << ">\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))