Files
2025-12-21 12:47:56 +01:00

29 lines
932 B
Python

import argparse
import llvm
def main():
parser = argparse.ArgumentParser(description="LLVM Bitcode Statistics Tool")
parser.add_argument("ir_file", type=str, help="Path to the LLVM bitcode file")
args = parser.parse_args()
ctx = llvm.global_context()
with open(args.ir_file, "r", encoding="utf-8") as f:
ir_text = f.read()
with ctx.parse_ir(ir_text) as mod:
for func in mod.functions:
if func.is_declaration:
continue
print(func.name)
histogram = {}
for block in func.basic_blocks:
for inst in block.instructions:
opcode = inst.opcode
histogram[opcode] = histogram.get(opcode, 0) + 1
print(" Instruction Histogram:")
for opcode, count in histogram.items():
print(f" {opcode}: {count}")
if __name__ == "__main__":
main()