[LLVMdev] [Caml-list] Ocaml(opt) & llvm
Gordon Henriksen
gordonhenriksen at mac.com
Wed Nov 28 22:16:55 PST 2007
On Nov 28, 2007, at 15:18, Chris Lattner wrote:
> On Tue, 27 Nov 2007, Gordon Henriksen wrote:
>>
>
>> The codegen for raise is simple. It just reads a saved return
>> address from the caml_exception_pointer global and returns through
>> several stack frames in one go.
>
> Nice.
Yup.
>> The try-with expression is where the trickery lies. The expression
>> try body with pattern1 -> catch1 | patternN -> catchN is compiled to:
>
> This seems pretty straight-forward to normal landing pads.
Certainly the primitives are more or less identical to LLVM's. There
is a strict stack of handlers, though, and I'm not sure how easy that
is to reconstruct.
> The only significant difference is how it dynamically registers the
> callback and how it continues unwinding.
I thought the implications with respect to frame object displacements
seemed rather invasive. Within the try block, frame offsets are
progressively increased with each level of nesting.
> If you were interested in adding this to llvm as some new EH
> intrinsics, I wouldn't be opposed to that.
Okay. I imagine the SJLJ EH would be a good place to start poking
around if I were to give it a shot?
> It's basically a form of sjlj exceptions.
Right.
> It only works if values are not held in registers across throws
> though, which is kinda lame ...
Though I'm primarily interested in this model only from an
interoperability perspective, reloading the register file for a throw
seems a comparatively small price to pay compared to, say,
symbolically unwinding the stack. :) More importantly, the common case
through code does not require a register file save/restore.
— Gordon
More information about the llvm-dev
mailing list