[llvm] e7fc254 - [BitcodeAnalyzer] allow a motivated user to dump BLOCKINFO

Shivam Gupta via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 9 21:51:47 PDT 2021


Author: william woodruff
Date: 2021-10-10T10:15:14+05:30
New Revision: e7fc254875ca9e82b899d5354fae9b5b779ff485

URL: https://github.com/llvm/llvm-project/commit/e7fc254875ca9e82b899d5354fae9b5b779ff485
DIFF: https://github.com/llvm/llvm-project/commit/e7fc254875ca9e82b899d5354fae9b5b779ff485.diff

LOG: [BitcodeAnalyzer] allow a motivated user to dump BLOCKINFO

This adds the `--dump-blockinfo` flag to `llvm-bcanalyzer`, allowing a sufficiently motivated user to dump (parts of) the `BLOCKINFO_BLOCK` block. The default behavior is unchanged, and `--dump-blockinfo` only takes effect in the same context as other flags that control dump behavior (i.e., requires that `--dump` is also passed).

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D107536

Added: 
    llvm/test/Other/bcanalyzer-dump-blockinfo-option.txt

Modified: 
    llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
    llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
    llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
index de828be3bf1b1..f6fc284da33fc 100644
--- a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
+++ b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
@@ -42,6 +42,8 @@ struct BCDumpOptions {
   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
index f577d3886e015..7777c5d9b1dcd 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
@@ -744,7 +744,7 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
   // 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 << "<BLOCKINFO_BLOCK/>\n";
     Expected<Optional<BitstreamBlockInfo>> MaybeNewBlockInfo =
         Stream.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true);
@@ -758,8 +758,8 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
     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/Other/bcanalyzer-dump-blockinfo-option.txt b/llvm/test/Other/bcanalyzer-dump-blockinfo-option.txt
new file mode 100644
index 0000000000000..4fdc06f95fd0d
--- /dev/null
+++ b/llvm/test/Other/bcanalyzer-dump-blockinfo-option.txt
@@ -0,0 +1,12 @@
+# RUN: llvm-bcanalyzer --dump --dump-blockinfo %S/Inputs/has-block-info.bc | FileCheck %s
+
+# CHECK: <BLOCKINFO_BLOCK NumWords=13 BlockCodeSize=2>
+# CHECK:   <SETBID op0=8/>
+# CHECK:   <BLOCKNAME op0=65 op1=66 op2=67 op3=0/>
+# CHECK:   <SETRECORDNAME op0=0 op1=65 op2=65 op3=65 op4=0/>
+# CHECK:   <SETRECORDNAME op0=1 op1=66 op2=66 op3=66 op4=0/>
+# CHECK:   <SETBID op0=9/>
+# CHECK:   <BLOCKNAME op0=88 op1=89 op2=90 op3=0/>
+# CHECK:   <SETRECORDNAME op0=0 op1=88 op2=88 op3=88 op4=0/>
+# CHECK:   <SETRECORDNAME op0=1 op1=89 op2=89 op3=89 op4=0/>
+# CHECK: </BLOCKINFO_BLOCK>

diff  --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index f4851bfb2a9cf..a238b0cf59224 100644
--- 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<std::string> InputFilename(cl::Positional,
 static cl::opt<bool> Dump("dump", cl::desc("Dump low level bitcode trace"),
                           cl::cat(BCAnalyzerCategory));
 
+static cl::opt<bool> DumpBlockinfo("dump-blockinfo",
+                                   cl::desc("Include BLOCKINFO details in low"
+                                            " level dump"),
+                                   cl::cat(BCAnalyzerCategory));
+
 //===----------------------------------------------------------------------===//
 // Bitcode specific analysis.
 //===----------------------------------------------------------------------===//
@@ -114,6 +120,7 @@ int main(int argc, char **argv) {
   O.Histogram = !NoHistogram;
   O.Symbolic = !NonSymbolic;
   O.ShowBinaryBlobs = ShowBinaryBlobs;
+  O.DumpBlockinfo = DumpBlockinfo;
 
   ExitOnErr(BA.analyze(
       Dump ? Optional<BCDumpOptions>(O) : Optional<BCDumpOptions>(None),


        


More information about the llvm-commits mailing list