I use the following code to print the basicblocks in my LLVM module’s object ID. To my surprise, different basicblocks share the same object ID, how could that be possible?
I got
foo
Block ID: 140516957688448
Block ID: 140516957688544
Block ID: 140516957688448
Block ID: 140516957688544
Block ID: 140516957688448
Block ID: 140516957688544
printf
main
Block ID: 140516957688448
So, the function main’s basicblock and function foo’s first basicblock have the same ID. Also, some basicblocks in foo have the same ID too. Is it a bug in my program below?
from llvmlite import binding as llvm
# Initialize the LLVM system
llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()
def find_basic_block_ids(ir):
# Parse the LLVM IR
llvm_module = llvm.parse_assembly(ir)
llvm_module.verify()
for function in llvm_module.functions:
print (function.name)
for block in function.blocks:
block_id = id(block)
print(f"Block ID: {block_id}")
if __name__ == "__main__":
with open("mycode.ll", "r") as f:
llvm_ir = f.read()
find_basic_block_ids(llvm_ir)