<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 19, 2016 at 4:42 AM, Jonas Maebe <span dir="ltr"><<a href="mailto:jonas-devlists@watlock.be" target="_blank">jonas-devlists@watlock.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Reid Kleckner wrote:<br>
> On Fri, Sep 16, 2016 at 10:13 AM, Jonas Maebe via llvm-dev<br>
</span><span class="">> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.<wbr>org</a>>> wrote:<br>
><br>
>     model. In order to ensure that changes performed in a try/setjmp==0<br>
>     block survive the longjmp, the changes must be done via volatile<br>
>     operations.<br>
><br>
> If you want to observe those volatile store updates, you're really going<br>
> to need to volatilize the load operations. In your example, LLVM does<br>
> not model the CFG edge from the longjmp to the setjmp. This leads LLVM<br>
> to conclude that the only reaching definition of 'loops' at the point of<br>
> the load in the else block is 'loops = 0'.<br>
<br>
</span>Ok, thanks for confirming this approach is not going to work.<br>
<span class=""><br>
> Volatilizing all operations on local variables is going to kill your<br>
> performance, obviously. You should really emit invoke instructions in<br>
> your frontend. You can either use your own EH personality, or the<br>
> existing SjLj EH personality, which will optimize on a correct CFG and<br>
> then volatilize all values live across exceptional edges. Then the LLVM<br>
> CFG will be correct, and you'll get pretty good code.<br>
<br>
</span>The main reason for using setjmp/longjmp is to maintain compatibility<br>
between code compiled with the LLVM backend and with our existing code<br>
generators . Switching to the SjLj personality would defeat that I think<br>
(it seems to use LLVM-defined internal data structures for storing the<br>
context information, such as the "five word buffer in which the calling<br>
context is saved"). In that case it would be better to immediately<br>
switch to ehframe-based exception handling so as to at least reap some<br>
benefits in the process.<br></blockquote><div><br></div><div>Sounds right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It is not clear to me from reading<br>
<a href="http://llvm.org/docs/ExceptionHandling.html" rel="noreferrer" target="_blank">http://llvm.org/docs/<wbr>ExceptionHandling.html</a> whether it is possible to<br>
use our own setjmp/longjmp infrastructure without modifying LLVM. I'm<br>
only interested in getting the LLVM CFG correct. I don't need any<br>
runtime support, data structures (ehframe) or context information from<br>
LLVM. All of our exception state is stored in TLS structures that can be<br>
obtained by calling routines in our own runtime.<br>
<br>
So, can I use invoke and landingpad without using any of the other<br>
exception handling intrinsics? (in combination with a dummy personality<br>
function) Or will LLVM in all cases insist on using ehframe information,<br>
a (C++-)ABI-compliant personality function, and possibly linking in<br>
parts of its own runtime that depend on this information being correct?<br></blockquote><div><br></div><div>I would say that the coupling between LLVM generated code and the HP unwind interface is pretty low. The only call LLVM emits is to _Unwind_Resume, so you would have to go into llvm/lib/CodeGen/DwarfEHPrepare.cpp and teach LLVM what you want it to call in your runtime for your EH personality.</div><div><br></div><div>Other than that, LLVM mostly emits ehframe unwind info and the LSDA, which describes the landingpad PCs and how to get there. You can either try to interoperate with that, or you'll have to change LLVM to emit your own LSDA format. At this point we support 3-ish distinct personalities, all with their own LSDA format, so there's a fair amount of prior art to look at in llvm/lib/CodeGen/AsmPrinter/(anything EH related).</div></div></div></div>