[LLVMdev] Re: Newbie questions

Vikram Adve
Thu, 27 Apr 2006 05:12:19 -0000

On Apr 26, 2006, at 2:42 PM, Vikram Adve wrote:

>> libgcj has two different approaches.
>>
>> On some platforms we generate explicit checks for null pointer
>> dereferences and for division by zero (division is a bit different in
>> that we also have to handle java's special rule for dividing -1 by
>> the
>> minimum integer -- I think most platforms actually call the helper
>> function).
>>
>> On other platforms, we don't generate explicit checks but instead
let
>> them signal, and then we have special code in the runtime to turn a
>> signal into an exception.  The second part here is that GCC knows
>> about implicitly trapping instructions (the -fnon-call-exceptions
>> flag, which we pass to all compilations for these targets).
>
> Ok, this makes sense.  But I was actually asking how you deal with
> this in the LLVM JIT for libgcj (I guess it is too early for you to
> have an answer).
>
> Specifically, I don't think either of these approaches will be
> sufficient when using LLVM as a JIT in libgcj.  In either case, an
> LLVM optimization could still reorder trapping instructions.  In
> the first approach, this is less likely to occur but is possible.


Just a correction, for the record:  The first approach should work,
i.e., the two trapping instructions will not be reordered by LLVM
opts (unless the reordering was harmless even if the exceptions
occur, e.g., if the handlers were  inlined and had no side-effects).


> The second approach of course wouldn't work because LLVM doesn't
> have a notion of implicitly trapping instructions and could merrily
> reorder such operations.

That is still correct.