[llvm-dev] Structurizing multi-exit regions
Daniel Berlin via llvm-dev
llvm-dev at lists.llvm.org
Thu Mar 2 10:12:33 PST 2017
FWIW, now that postdom is fixed, all the possible "returns/exits" of the
function should be direct children of the virtual exit node in the post-dom
tree.
Thus, the following would work to detect whether each block is a real
return or not:
for (auto &PDTChild : children<DomTreeNode *>(PDT.getRootNode())) {
auto *BB = PDTChild->getBlock();
auto &Info = BlockInfo[BB];
// Real function return
if (isa<ReturnInst>(Info.Terminator)) {
DEBUG(dbgs() << "post-dom root child is a return: " << BB->getName()
<< '\n';);
continue;
}
// PDTChild is something else, like a no-return or infinite loop
}
You could also just insert a br i1 false <merged function return>,
<existing infinite loop branch> to have a single exit.
Until you simplify the cfg, it would work.
On Thu, Mar 2, 2017 at 8:08 AM, Christian König via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> 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
>>
>>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170302/6883c56e/attachment.html>
More information about the llvm-dev
mailing list