[PATCH] D107536: [BitcodeAnalyzer] allow a motivated user to dump BLOCKINFO
William Woodruff via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 9 13:54:34 PDT 2021
woodruffw updated this revision to Diff 378473.
woodruffw added a comment.
Avoid `llvm-stress` in test, more detailed checks.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107536/new/
https://reviews.llvm.org/D107536
Files:
llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
llvm/test/tools/llvm-bcanalyzer/Inputs/has-block-info.bc
llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test
llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
Index: llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
===================================================================
--- llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ 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<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 @@
O.Histogram = !NoHistogram;
O.Symbolic = !NonSymbolic;
O.ShowBinaryBlobs = ShowBinaryBlobs;
+ O.DumpBlockinfo = DumpBlockinfo;
ExitOnErr(BA.analyze(
Dump ? Optional<BCDumpOptions>(O) : Optional<BCDumpOptions>(None),
Index: llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-bcanalyzer/dump-blockinfo.test
@@ -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>
Index: llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ 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 << "<BLOCKINFO_BLOCK/>\n";
Expected<Optional<BitstreamBlockInfo>> 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;
Index: llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
===================================================================
--- llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
+++ 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) {}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107536.378473.patch
Type: text/x-patch
Size: 3940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211009/0b927f87/attachment.bin>
More information about the llvm-commits
mailing list