This is an archive of the discontinued LLVM Phabricator instance.

Preserve exceptions information during calls code generation.
ClosedPublic

Authored by sfantao on Nov 18 2015, 4:51 PM.

Details

Summary

This patch changes the generation of CGFunctionInfo to contain the FunctionProtoType if it is available. This enables the code generation for call instructions to look into this type for exception information and therefore generate better quality IR - it will not create invoke instructions for functions that are know not to throw.

The emission code had to be changed in a few places to keep the FunctionProtoType and, namely for the complex arithmetic library calls, create new FunctionProtoTypes with the right exception information.

This patch is just a first step to have more accurate IR, as there may be other patterns that could take advantage of extra information. I'm just covering some cases I am aware of.

Thanks!
Samuel

Diff Detail

Event Timeline

sfantao updated this revision to Diff 40579.Nov 18 2015, 4:51 PM
sfantao retitled this revision from to Preserve exceptions information during calls code generation..
sfantao updated this object.
sfantao added reviewers: rjmccall, rnk, ABataev, hfinkel.
sfantao added a subscriber: cfe-commits.
rjmccall edited edge metadata.Nov 18 2015, 5:14 PM

What I was thinking was something more along the lines of a little struct that stored either a Decl * or a FunctionType *, and you could change the TargetDecl argument to functions like EmitCall and ConstructAttributeList to that. Maybe call it something like CalleeInfo?

sfantao updated this revision to Diff 40587.Nov 18 2015, 6:18 PM
sfantao edited edge metadata.

Create CGCalleeInfo to forward the declaration and function type information during the emission of calls.

What I was thinking was something more along the lines of a little struct that stored either a Decl * or a FunctionType *, and you could change the TargetDecl argument to functions like EmitCall and ConstructAttributeList to that. Maybe call it something like CalleeInfo?

Ok, in the new diff I am encoding the declaration and type in a new struct instead of using CGFunctionInfo to keep the type.

Let me know your comments.

Thanks!
Samuel

That's exactly what I was looking for, thanks.

lib/CodeGen/CGExpr.cpp
3751

Please work the following clarification into this comment: we specifically need to preserve the non-canonical function type because things like exception specifications disappear in the canonical type.

sfantao updated this revision to Diff 40646.Nov 19 2015, 7:27 AM

Update comment as suggested by John.

sfantao added inline comments.Nov 19 2015, 7:28 AM
lib/CodeGen/CGExpr.cpp
3751

Done!

Thanks, that's great. One minor tweak, and feel free to just commit when you've done that.

lib/CodeGen/CGCall.cpp
1420

Minor tweak: "prototype".

sfantao updated this revision to Diff 40977.Nov 23 2015, 2:09 PM

Fix typo in comment.

Committed in r253926!

Thanks,
Samuel

lib/CodeGen/CGCall.cpp
1420

Done!

ABataev accepted this revision.Nov 25 2015, 2:56 AM
ABataev edited edge metadata.
This revision is now accepted and ready to land.Nov 25 2015, 2:56 AM
ABataev closed this revision.Nov 25 2015, 2:57 AM