[llvm-commits] Handle nested try-catch statements

Duncan Sands baldrick at free.fr
Wed Jul 4 04:36:11 PDT 2007


These patches, to LLVM and llvm-gcc, add support for nested
try-catch statements.  Previously, only the inner most
catch or filter was being taken into account.  Thanks to
inlining it is possible for a function to contain any
number of filters and catches nested within each other
(without inlining filters only occur outermost).  To support
this I've junked the eh.filter intrinsic and extended the
eh.selector intrinsic so it can simultaneously contain catches
and filters.  To indicate a filter, the number of typeinfos
in the filter is given as an argument, followed by the typeinfos
themselves.  For example,
	%s = eh.selector(exception,personality,t1,2,t2,t3,t4);
has a catch (typeinfo t1) followed by a filter of length 2
(typeinfos t2 and t3) followed by another catch (typeinfo t4).
This is not very beautiful but it is simple, effective and
unambiguous.

An alternative would have been to keep eh.filter and output
multiple filter/selector intrinsics like this:
	%s1 = eh.selector(exception,personality,t4);
	%s2 = eh.filter(exception,personality,t2,t3);
	%s3 = eh.selector(exception,personality,t1);
(yes, in reverse order).  Then %s1 and %s2 would never be used,
and %s3 would be tested against the various typeinfos, even if
they were never mentioned in the %s3 selector itself (eg t4).
It also requires extra mucking around with the live-in markings
for the exception and selector registers produced during codegen.
I decided it was better to enhance eh.selector and get rid of
eh.filter.  Note that this means that eh.selector now corresponds
directly to the action sequence in the dwarf eh table.

The testcase shows the difference before and after (I've simplified
the output a bit):
Before:
  %eh_select = call @llvm.eh.filter(%eh_ptr, @__gxx_personality_v0,
        null)	; "empty" filter [the "null" should not be here - also fixed in this patch]
After:
  %eh_select = call @llvm.eh.selector(%eh_ptr, @__gxx_personality_v0,
	i32 0,				; empty filter
	@_ZTI3One,			; catch
	i32 1, @_ZTI3Two,		; filter of length 1
	@_ZTI5Three, @_ZTI4Four,	; two catches
	i32 2, @_ZTI4Five, @_ZTI3Six,	; filter of length 2
	null)				; catch-all

Ciao,

Duncan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm_part.diff
Type: text/x-diff
Size: 14442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070704/55365299/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc_part.diff
Type: text/x-diff
Size: 8422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070704/55365299/attachment-0001.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2007-07-04-NestedCatches.cpp
Type: text/x-c++src
Size: 533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070704/55365299/attachment.cpp>


More information about the llvm-commits mailing list