Peter Lawrence via llvm-dev
2017-Jun-07 17:33 UTC
[llvm-dev] RE: Function with multi return path?
Tongari, Another possibility, if you don’t like the function returning an index which is switched on, is that the function returns an address that you do an IR ‘indirectbr’ (indirect branch) on. Note that the ‘indirectbr’ Instruction requires a list of all possible destination labels, or else the Compiler can’t correctly optimize the surrounding code. I think the possible return addresses will have to have been passed in to the function as arguments, or else have been made available through global variables (which would be way beyond ugly). But if you actually modify the called function's return address register the optimizer won’t be able to construct an accurate control-flow-graph of the calling function, and the optimizer will corrupt its code. To fix that would require a new IR call instruction that incorporates the indirect-branch instruction’s list of all possible destination labels, but I don’t think you’re going to get much support for such a request. Note that Fortran-77 has “alternate returns” which seem to be what you are asking for, but AFAIK every Fortran-77 compiler inserts a “switch” statement following the call, so that the optimizers know where all the possible destination labels are. Peter Lawrence.> On Jun 2, 2017, at 12:44 AM, via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > Message: 4 > Date: Fri, 2 Jun 2017 10:38:19 +0800 > From: TONGARI J via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> > To: llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > Subject: Re: [llvm-dev] Function with multi return path? > Message-ID: > <CANCwVhfUxdmwRiG83cNED2vHxs-FMBqC-TQ1HDUnm3OrDk8hzA at mail.gmail.com <mailto:CANCwVhfUxdmwRiG83cNED2vHxs-FMBqC-TQ1HDUnm3OrDk8hzA at mail.gmail.com>> > Content-Type: text/plain; charset="utf-8" > > Hi Reid, > > I'm aware of the invoke instruction and landingpad. But it's too heavy > weight for control flow. It's quite expensive to take the exceptional path > in C++. > > What I want is a more lightweight approach, to pass the return address to > the callee, and let the callee jump to that address directly.-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170607/145e1fdb/attachment.html>