[LLVMdev] unwind/invoke design
Wesley W. Terpstra
wesley at terpstra.ca
Mon Jun 15 09:46:18 PDT 2009
The documentation of unwind/invoke is quite clear and does exactly
what I need: unwinding the stack. I don't need it to carry an object
back. I don't need it to figure out what the type of the object is or
what catch() blocks it matches. I just need it to unwind the stack.
The rest is my job as a part of the runtime. Unfortunately, I have
learned that while this works with the bytecode evaluator, it doesn't
work with the JIT or native codegen [1].
There seems to have been discussion about making unwind/invoke
inter-operate with native c++ exceptions, and this complexity was
cited as being the reason it was too complex to implement. I question
whether this is actually needed. In other languages, I >do not< want
C++ exceptions to try and unwind my stack, nor do I want my exceptions
to unwind a C++ stack. The exceptions are completely incompatible and
this would not make sense.
To implement exceptions in a new frontend, unwind functionality is
required. LLVM generates all the stack frame information, so a
front-end author is not in the position to unwind the stack himself.
When I read the LLVM documentation I thought it could do this, and I
was extremely disappointed to learn that it could not.
This missing functionality means (as far as I can tell) that I will
not be able to implement a backend for ML which uses LLVM directly.
Instead I would need to use a trampoline to effectively remove LLVM
from stack control and manage a stack in the heap explicitly. This
seems quite a shame since LLVM was clearly intended to function as a
SSA backend.
I would ask that the documentation for unwind be updated to reflect
that this operation does not actually exist. Such a warning would have
saved me two weeks of wasted implementation effort.
[1] http://www.nabble.com/Unwinds-Gone-Wild-td18747589.html
More information about the llvm-dev
mailing list