Sorry for the noob question, but I can't find what I want in the docs. I'm using FunctionBuilder to translate my own basic blocks to cranelift IR. Is there an easy way to check if a cranelift Block has a terminator/is filled? Or do I need to keep track of whether I have added a terminator instruction myself? Thanks!
Happy to answer questions! You can use builder.func.layout.last_inst(block)
to get the last instruction of a block (which will return None
if the block is empty). Then builder.func.dfg.insts[inst].is_terminator()
should tell you whether that instruction is valid for ending the block. But you might find it easier to keep track of this yourself.
Great, thank you! That's what I was looking for (although as you said, maybe it's better I keep track of things separately)
Raekye has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC