This is an archive of the discontinued LLVM Phabricator instance.

[coroutines] Store an address of destroy OR cleanup part in the coroutine frame.
ClosedPublic

Authored by GorNishanov on Oct 7 2016, 12:36 PM.
Tokens
"Mountain of Wealth" token, awarded by GorNishanov.

Details

Summary

If heap allocation of a coroutine is elided, we need to make sure that we will update an address stored in the coroutine frame from f.destroy to f.cleanup.
Before this change, CoroSplit synthesized these stores after coro.begin:

store void (%f.Frame*)* @f.resume, void (%f.Frame*)** %resume.addr
store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** %destroy.addr

In those cases where we did heap elision, but were not able to devirtualize all indirect calls, destroy call will attempt to "free" the coroutine frame stored on the stack. Oops.

Now we use select to put an appropriate coroutine subfunction in the destroy slot. As bellow:

store void (%f.Frame*)* @f.resume, void (%f.Frame*)** %resume.addr
%0 = select i1 %need.alloc, void (%f.Frame*)* @f.destroy, void (%f.Frame*)* @f.cleanup
store void (%f.Frame*)* %0, void (%f.Frame*)** %destroy.addr

Diff Detail

Event Timeline

GorNishanov retitled this revision from to [coroutines] Store an address of destroy OR cleanup part in the coroutine frame..
GorNishanov updated this object.
GorNishanov added a reviewer: majnemer.
GorNishanov added a subscriber: llvm-commits.
GorNishanov updated this object.

ran through clang-format

Removed unused function that sneaked in here

Remove unused #include InstIterator.h

majnemer accepted this revision.Oct 7 2016, 4:30 PM
majnemer edited edge metadata.

LGTM

lib/Transforms/Coroutines/CoroInstr.h
84–86

Couldn't you do:

if (auto *CA = dyn_cast<CoroAllocInst>(II))
  return CA;
This revision is now accepted and ready to land.Oct 7 2016, 4:30 PM
GorNishanov marked an inline comment as done.Oct 7 2016, 4:53 PM
GorNishanov added inline comments.
lib/Transforms/Coroutines/CoroInstr.h
84–86

I can and I will!

:)

Thank you for the review!

GorNishanov updated this revision to Diff 74002.Oct 7 2016, 4:59 PM
GorNishanov edited edge metadata.
GorNishanov marked an inline comment as done.

Simplifed getCoroAllocInstr in CoroInstr.h and preparing to land

GorNishanov closed this revision.Oct 7 2016, 6:18 PM

Closed by commit: [llvm] r283625 - [coroutines] Store an address of destroy OR cleanup part in the coroutine frame.