[llvm-dev] Structurizing multi-exit regions

Christian König via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 2 08:08:15 PST 2017


Hi Matt,

one prerequisite for the algorithm is that each function has exactly one 
entry and one exit node.

If I remember correctly there was a LLVM pass called mergereturn or 
something like that which made sure that you have at most one ret 
instruction for each function.

Using that used to be a prerequisite for running the transformation, but 
that obviously won't work for unreachable instructions.

The only doable approach I can see is to make the annotator able to 
handle those. Otherwise you could also have a BB existing a function 
using ret and another one running into an unreachable.

Regards,
Christian.

Am 02.03.2017 um 02:39 schrieb Matt Arsenault:
> Hi,
>
> I'm trying to solve a problem from StructurizeCFG not actually 
> handling regions with multiple exits. Sample IR attached.
>
> StructurizeCFG doesn't touch this function, exiting early on the 
> isTopLevelRegion check. SIAnnotateControlFlow then gets confused and 
> ends up inserting an if into one of the blocks, and the matching 
> end.cf into one of the return/unreachable blocks. The input to the 
> end.cf is then not dominated by the condition which fails the verifier.
>
> I'm not sure exactly about how to go about fixing this. I see a few 
> options:
>
> - Try to make the annotator aware of multi exit regions and insert the 
> necessary phis for the input mask values for the end.cf calls. This 
> seems undesirable and I'm not sure works in all cases.
>
> - Make StructurizeCFG duplicate blocks to get simple regions. Is there 
> already code to do this somewhere? CodeExtractor seems to do something 
> similar, but not quite the same. Can this be done in the region pass, 
> or does StructurizeCFG need to be converted to a function pass? 
> RegionInfo mentions support for "extended" regions with multiple 
> exits, but I don't think this helps any here.
>
> -Matt
>



More information about the llvm-dev mailing list