About unwind...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

About unwind...

Sebastien Loisel-2
Dear LLVM people,

I have started playing with LLVM a little bit and I am thinking of using it to write some linear algebra software for my class.

First, an off-topic "bug report" (?), I tried using llvm under cygwin with Vista 64 bits, and it hangs during the build process. It works fine under Vista 32 bits, with cygwin.

I was reading the documentation and I am very excited by the possibilities of "invoke" and "unwind". I have two questions.

1) How does the performance of "invoke" compare to the performance of "call" on a typical x86, 32 or 64 bit platform? How many isns and such?
2) When I unwind, the stack gets popped but it would make sense to pass some data to the exception handler. I guess I could use a global variable for this, but is there a way to do it on the stack? (Wouldn't that make more sense also?)

Thanks,

--
S├ębastien Loisel
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Gordon Henriksen-3
Hi Sebastien.

On Dec 15, 2007, at 19:00, Sebastien Loisel <[hidden email]> wrote:

> I have started playing with LLVM a little bit and I am thinking of  
> using it to write some linear algebra software for my class.
>
> I was reading the documentation and I am very excited by the  
> possibilities of "invoke" and "unwind". I have two questions.
>
> 1) How does the performance of "invoke" compare to the performance  
> of "call" on a typical x86, 32 or 64 bit platform? How many isns and  
> such?

With the exception of the "setjmp/longjmp" codegen that LLVM supports,  
invoke has no dynamic cost. It is used to implement C++ "zero-cost"  
exception-handling, which combine the dynamic execution stack itself  
and static metadata emitted by the compiler in order to implement  
unwinding.

> 2) When I unwind, the stack gets popped but it would make sense to  
> pass some data to the exception handler. I guess I could use a  
> global variable for this, but is there a way to do it on the stack?  
> (Wouldn't that make more sense also?)

Indeed, you should use a global (or thread-local global).

- Gordon

Sent from my iPhone...
   on United flight 339
     parked for the third hour on the tarmac
       at Logan International Airport
         still waiting for the nor'easter to blow on through
           (but I'm not bitter)
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Gordon Henriksen-3
Incidentally, the first item is discussed in the introductory text on http://llvm.org/docs/ExceptionHandling.html#itanium

- Gordon

On Dec 16, 2007, at 10:27, Gordon Henriksen <[hidden email]>  
wrote:

> Hi Sebastien.
>
> On Dec 15, 2007, at 19:00, Sebastien Loisel <[hidden email]> wrote:
>
>> I have started playing with LLVM a little bit and I am thinking of  
>> using it to write some linear algebra software for my class.
>>
>> I was reading the documentation and I am very excited by the  
>> possibilities of "invoke" and "unwind". I have two questions.
>>
>> 1) How does the performance of "invoke" compare to the performance  
>> of "call" on a typical x86, 32 or 64 bit platform? How many isns  
>> and such?
>
> With the exception of the "setjmp/longjmp" codegen that LLVM  
> supports, invoke has no dynamic cost. It is used to implement C++  
> "zero-cost" exception-handling, which combine the dynamic execution  
> stack itself and static metadata emitted by the compiler in order to  
> implement unwinding.
>
>> 2) When I unwind, the stack gets popped but it would make sense to  
>> pass some data to the exception handler. I guess I could use a  
>> global variable for this, but is there a way to do it on the stack?  
>> (Wouldn't that make more sense also?)
>
> Indeed, you should use a global (or thread-local global).
>
> - Gordon
>
> Sent from my iPhone...
>  on United flight 339
>    parked for the third hour on the tarmac
>      at Logan International Airport
>        still waiting for the nor'easter to blow on through
>          (but I'm not bitter)
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Duncan Sands
In reply to this post by Sebastien Loisel-2
> 2) When I unwind, the stack gets popped but it would make sense to pass some
> data to the exception handler. I guess I could use a global variable for
> this, but is there a way to do it on the stack? (Wouldn't that make more
> sense also?)

Passing extra info on the stack doesn't make much sense because the stack
gets popped...

Also, note that the unwind instruction is currently turned into an abort
call at codegen time!

I suggest you compile some C++ code with exception handling using
llvm-g++ -S -emit-llvm and see how it does it.  In short: throwing
an exception is done by a library call which takes an exception object.
Catching is done using the LLVM invoke instruction.  The exception
object is retrieved by an llvm.eh.exception intrinsic call.  See
http://llvm.org/docs/ExceptionHandling.html

Ciao,

Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Jonathan Brandmeyer

On Sun, 2007-12-16 at 16:57 +0100, Duncan Sands wrote:

> > 2) When I unwind, the stack gets popped but it would make sense to pass some
> > data to the exception handler. I guess I could use a global variable for
> > this, but is there a way to do it on the stack? (Wouldn't that make more
> > sense also?)
>
> Passing extra info on the stack doesn't make much sense because the stack
> gets popped...
>
> Also, note that the unwind instruction is currently turned into an abort
> call at codegen time!
>
> I suggest you compile some C++ code with exception handling using
> llvm-g++ -S -emit-llvm and see how it does it.  In short: throwing
> an exception is done by a library call which takes an exception object.
> Catching is done using the LLVM invoke instruction.  The exception
> object is retrieved by an llvm.eh.exception intrinsic call.  See
> http://llvm.org/docs/ExceptionHandling.html

The current llvm.eh intrinsics use c++ type_info objects and the c++
personality function for the Itanium ABI unwinder.  What is the best way
for a new language to portably maximize reuse of the existing C++
runtime?  Can you use a pointer to some other object and expect the
unwinder to work, or does the personality function inspect the contents
of the type_info as well as its address?  Or do you have to write a new
personality function?  Is there an example of a non-C++ llvm front-end
that also uses the llvm eh support?

Thanks,
-Jonathan

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Sebastien Loisel-2
In reply to this post by Duncan Sands
OK, I have learnt something about llvm from this thread, thanks.

As a side note:

> 2) When I unwind, the stack gets popped but it would make sense to pass some
Passing extra info on the stack doesn't make much sense because the stack
gets popped...

I don't know how llvm implements unwind, but in principle it is possible to walk (and pop) the stack to the right point, then push a parameter, then push the proper return address, then return.

But nevermind me, I don't know how llvm works anyway.

--
S├ębastien Loisel


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: About unwind...

Duncan Sands
Hi,

> > 2) When I unwind, the stack gets popped but it would make sense to pass
> > some
> > Passing extra info on the stack doesn't make much sense because the stack
> > gets popped...
> >
>
> I don't know how llvm implements unwind,

the unwinder in the gcc runtime does the unwinding.

> but in principle it is possible to
> walk (and pop) the stack to the right point, then push a parameter, then
> push the proper return address, then return.

This is what the gcc unwinder does (more or less), only it uses a register
rather than the stack: when calling the unwinder routine that does the
unwinding you give it a pointer to an exception object, and when execution
is to recommence in a landing pad it puts the value of that pointer in a special
register so you can get hold of it before jumping to the landing pad.

Ciao,

Duncan.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev