How to determine whether an IR is in main function but not in control flow block?

for example, the builtinFunction() can only in main function but cannot in if/switch



The terms in main function and not in control flow block are quite fuzzy. If you mean something like there are no paths from a function entrypoint to all function returns that skip builtinFunction invocation, then dominance and post-dominance may be things you’re looking for.

I’m assuming that what you want to know is if a basic block is not contained within conditional block, such as an if, switch, or while block; in other words, what you want to ask is whether or not there are any conditions that control the execution of a block (aka, control dependence).

Two basic blocks A and B have the same control dependences if and only if A dominates B and B postdominates A. By definition, the entry block of a function dominates all other blocks in the function. Consequently, all you need to check is whether or not the block you are interested in postdominates the entry block. This will guarantee that the block, and every instruction within it, is executed exactly once every time the function is executed.

1 Like

Unfortunately, the non-entry block you’re looking at could be in a loop and still post-dominate the entry…

Yes, I want to ask is whether or not there are any conditions that control the execution of a block.
Thank you very much!

I think follows picture cannot meet this definition.
A and B have the same control dependence C, but A don’t dominates B and B don’t postdominates A.

Thank you very much!

this picture can meet your description. B postdominate entry block,but B is in loop.

So I should find the block’s control dependence, if the block’s control dependence is null, it must not be conditinal block?