Page MenuHomePhabricator

[IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas
ClosedPublic

Authored by erik.pilkington on Feb 5 2020, 3:09 PM.

Details

Summary

These temporaries are only used in the callee, and their memory can be reused after the call is complete.

rdar://58552124

Diff Detail

Event Timeline

erik.pilkington created this revision.Feb 5 2020, 3:09 PM
rjmccall added inline comments.Feb 6 2020, 11:12 AM
clang/lib/CodeGen/CGCall.cpp
3697

If the argument type has a C++ destructor, will we end its lifetime before we call destructors at the end of the full-expression?

erik.pilkington planned changes to this revision.Feb 6 2020, 12:03 PM
erik.pilkington marked an inline comment as done.
erik.pilkington added inline comments.
clang/lib/CodeGen/CGCall.cpp
3697

Yeah, this is broken :/

rjmccall added inline comments.Feb 6 2020, 12:31 PM
clang/lib/CodeGen/CGCall.cpp
3697

Well, we could at least do it for trivially-destructible types. That probably needs to include all kinds of non-trivial destructibility, not just C++, though.

erik.pilkington marked 2 inline comments as done.

Disable the optimization for non-trivially destructible types.

thegameg added inline comments.Feb 7 2020, 11:30 AM
clang/lib/CodeGen/CGCall.cpp
3687

Is there any other use of EmitAnyExprToTemp that can benefit from this?

erik.pilkington marked an inline comment as done.Feb 7 2020, 11:35 AM
erik.pilkington added inline comments.
clang/lib/CodeGen/CGCall.cpp
3687

Right now, the only other user of that function is CodeGenFunction::EmitStmtExprLValue, which doesn't seem all that interesting. There are a lot of places that do create temporary allocas that would be worth looking into in the future though.

This revision is now accepted and ready to land.Feb 7 2020, 12:16 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2020, 2:43 PM