[llvm-dev] Function with multi return path?

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 1 09:44:57 PDT 2017


The closest thing LLVM has to this is the invoke instruction used for
exception handling. Using it requires reusing or building a lot of EH
runtime support, though. invoke only supports a single alternative return
destination (the landingpad), but you can use the selector value to switch
over multiple language level alternative return destinations.

On Wed, May 31, 2017 at 11:57 PM, TONGARI J via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi folks,
>
> I'm new to LLVM and non-expert in hardware architecture, so my question
> might be dumb.
>
> I'm looking for the possibility to define/call a function with multi
> return path, it might look like this:
>
> ```
> ; Define a function with 1 alternate return path
> define i32 @f(i1 %i) fork 1 {
>   br i1 %i, label %noraml, label %alternate
> noraml:
>   ...
>   setpath ret i32 42 ; take normal return path
>   br %cleanup
> alternate:
>   ...
>   setpath fork 0 ; take the alternate return path
>   br %cleanup
> cleanup: ; preds = %noraml, %alternate
>   ...
>   unwind ; return to the caller
> }
> ```
>
> And at the call side:
> ```
>   %ret = call @f(i1 %i) fork [%otherwise]
>   ...
> otherwise:
>   ...
> ```
>
> Ideally, the callee sets the return address so it returns directly to the
> desired location in the caller w/o the caller taking extra switch.
>
> The idea is to implement some non-local control flow w/o extra overhead at
> each call side.
>
> I know LLVM doesn't have something like this currently, but is it possible
> to implement?
>
> _______________________________________________
> 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/20170601/85389e86/attachment.html>


More information about the llvm-dev mailing list