LinuxCommandLibrary

llvm-bcanalyzer

Analyze LLVM bitcode file content

TLDR

Print statistics about a Bitcode file

$ llvm-bcanalyzer [path/to/file.bc]
copy

Print an SGML representation and statistics about a Bitcode file
$ llvm-bcanalyzer -dump [path/to/file.bc]
copy

Read a Bitcode file from stdin and analyze it
$ cat [path/to/file.bc] | llvm-bcanalyzer
copy

SYNOPSIS

llvm-bcanalyzer [options] <input bitcode file>

PARAMETERS

<input bitcode file>
    The path to the LLVM bitcode file (.bc) to be analyzed.

-help
    Displays a summary of command-line options.

-version
    Displays the version of llvm-bcanalyzer.

-analyze
    Analyzes the bitcode file and prints statistical information about its structure and content. This is often the default mode of operation.

-dump
    Dumps the raw bitcode records and their values in a verbose, human-readable format. Useful for deep inspection.

-disable-verify
    Disables bitcode verification. Useful when trying to analyze a malformed or incomplete bitcode file that would otherwise cause a verification error.

-disable-block-info
    Disables parsing of block info records. Can speed up processing of very large bitcode files if only block-level statistics are needed.

-show-binary-blobs
    When dumping, shows the raw binary contents of data blobs within the bitcode records.

DESCRIPTION

llvm-bcanalyzer is a command-line utility within the LLVM project designed for analyzing the structure and content of LLVM bitcode files. It provides a detailed, human-readable summary of a bitcode file, which is the intermediate representation (IR) used by LLVM compilers.

This tool is invaluable for developers, researchers, and anyone working with the LLVM toolchain who needs to understand the internal layout of bitcode. It can help debug issues with bitcode generation, verify the correctness of bitcode, or simply explore how different language constructs are represented in LLVM IR.

The analyzer provides information such as the total size of the bitcode file, the size of various blocks (e.g., module, function, constants), the number and types of records within those blocks, and other statistical data. It can also be used to dump the raw bitcode records for low-level inspection. Its output helps in identifying large sections, unoptimized parts, or potentially malformed bitcode structures.

CAVEATS

The LLVM bitcode format can evolve between LLVM versions. An llvm-bcanalyzer from an older LLVM release might not fully understand bitcode generated by a newer compiler, and vice versa. While it attempts to be forward-compatible, certain features or record types might not be correctly interpreted.

This tool is primarily for diagnostic and informational purposes; it does not modify the bitcode file. Its output can be very verbose, especially when using the -dump option on large files.

TYPICAL USAGE

A common use case is simply running llvm-bcanalyzer mymodule.bc to get a high-level overview. For more detailed inspection of specific blocks or records, llvm-bcanalyzer -dump mymodule.bc is used. If a bitcode file is suspected to be corrupted or malformed, llvm-bcanalyzer -disable-verify -dump mymodule.bc can help extract as much information as possible without crashing due to verification errors.

OUTPUT DETAILS

The output typically begins with a summary of the bitcode file, including its total size. It then lists information about various top-level blocks like MODULE_BLOCK, FUNCTION_BLOCK, and CONSTANTS_BLOCK. For each block, it provides its size, the number of records it contains, and often a breakdown of common records within that block. The -dump option provides an extremely granular view, showing each record ID, its contents, and the raw byte size, making it suitable for bitcode format specification debugging.

HISTORY

llvm-bcanalyzer is an integral part of the LLVM compiler infrastructure, which was originally developed at the University of Illinois Urbana-Champaign. Its development has closely paralleled the evolution of the LLVM bitcode format itself, serving as a crucial tool for debugging and understanding the intermediate representation used by LLVM-based compilers and tools.

From its early days, its purpose has remained consistent: to provide deep insight into the structure of LLVM bitcode files, aiding in the development, optimization, and verification of LLVM components and generated code.

SEE ALSO

llvm-as(1), llvm-dis(1), llvm-link(1), opt(1), llc(1)

Copied to clipboard