[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
This commit is contained in:
parent
f95d9c95bb
commit
e7fc254875
|
@ -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) {}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue