Stream: cranelift

Topic: ✔ Any way to check if a block is filled with FunctionBuil...


view this post on Zulip Raekye (Feb 03 2023 at 23:39):

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!

view this post on Zulip Jamey Sharp (Feb 03 2023 at 23:48):

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.

view this post on Zulip Raekye (Feb 04 2023 at 17:54):

Great, thank you! That's what I was looking for (although as you said, maybe it's better I keep track of things separately)

view this post on Zulip Notification Bot (Feb 04 2023 at 17:54):

Raekye has marked this topic as resolved.


Last updated: Oct 23 2024 at 20:03 UTC