diff --git a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h --- a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h +++ b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h @@ -42,6 +42,8 @@ bool Symbolic = false; /// Print binary blobs using hex escapes. bool ShowBinaryBlobs = false; + /// Print BLOCKINFO block details. + bool DumpBlockinfo = false; BCDumpOptions(raw_ostream &OS) : OS(OS) {} }; diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp @@ -744,7 +744,7 @@ // BLOCKINFO is a special part of the stream. bool DumpRecords = O.hasValue(); if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { - if (O) + if (O && !O->DumpBlockinfo) O->OS << Indent << "\n"; Expected> MaybeNewBlockInfo = Stream.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true); @@ -758,8 +758,8 @@ if (Error Err = Stream.JumpToBit(BlockBitStart)) return Err; // It's not really interesting to dump the contents of the blockinfo - // block. - DumpRecords = false; + // block, so only do it if the user explicitly requests it. + DumpRecords = O && O->DumpBlockinfo; } unsigned NumWords = 0; diff --git a/llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test b/llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test @@ -0,0 +1,6 @@ +# RUN: llvm-stress | llvm-as - | llvm-bcanalyzer --dump --dump-blockinfo | FileCheck %s + +# CHECK: +# CHECK-NOT: +# CHECK: + diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -11,8 +11,9 @@ // llvm-bcanalyzer [options] x.bc - Read LLVM bitcode from the x.bc file // // Options: -// --help - Output information about command line switches -// --dump - Dump low-level bitcode structure in readable format +// --help - Output information about command line switches +// --dump - Dump low-level bitcode structure in readable format +// --dump-blockinfo - Dump the BLOCKINFO_BLOCK, when used with --dump // // This tool provides analytical information about a bitcode file. It is // intended as an aid to developers of bitcode reading and writing software. It @@ -47,6 +48,11 @@ static cl::opt Dump("dump", cl::desc("Dump low level bitcode trace"), cl::cat(BCAnalyzerCategory)); +static cl::opt DumpBlockinfo("dump-blockinfo", + cl::desc("Include BLOCKINFO details in low" + " level dump"), + cl::cat(BCAnalyzerCategory)); + //===----------------------------------------------------------------------===// // Bitcode specific analysis. //===----------------------------------------------------------------------===// @@ -114,6 +120,7 @@ O.Histogram = !NoHistogram; O.Symbolic = !NonSymbolic; O.ShowBinaryBlobs = ShowBinaryBlobs; + O.DumpBlockinfo = DumpBlockinfo; ExitOnErr(BA.analyze( Dump ? Optional(O) : Optional(None),