[llvm-dev] RE: Function with multi return path?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[llvm-dev] RE: Function with multi return path?

Hal Finkel via llvm-dev
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 <[hidden email]> wrote:


Message: 4
Date: Fri, 2 Jun 2017 10:38:19 +0800
From: TONGARI J via llvm-dev <[hidden email]>
To: [hidden email]
Subject: Re: [llvm-dev] Function with multi return path?
Message-ID:
<[hidden email]>
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.


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Loading...