This is an archive of the discontinued LLVM Phabricator instance.

[Coroutines] Part 10: Add coroutine promise support.
ClosedPublic

Authored by GorNishanov on Aug 29 2016, 7:49 AM.

Details

Summary
  1. CoroEarly now lowers llvm.coro.promise intrinsic that allows to obtain

a coroutine promise pointer from a coroutine frame and vice versa.

  1. CoroFrame now interprets Promise argument of llvm.coro.begin to

place CoroutinPromise alloca at a deterministic offset from the coroutine frame.

Now, the coroutine promise example from docs\Coroutines.rst compiles and produces expected result (see test/Transform/Coroutines/ex4.ll).

Diff Detail

Repository
rL LLVM

Event Timeline

GorNishanov retitled this revision from to [Coroutines] Part 10: Add coroutine promise support..
GorNishanov updated this object.
GorNishanov added a reviewer: majnemer.
GorNishanov added a subscriber: llvm-commits.
majnemer added inline comments.Aug 29 2016, 8:18 PM
lib/Transforms/Coroutines/CoroEarly.cpp
66 ↗(On Diff #69571)

Builder->getInt8Ty() is a little shorter.

68 ↗(On Diff #69571)

auto *

lib/Transforms/Coroutines/CoroInstr.h
104–105 ↗(On Diff #69571)

This is weird. There can be ptrtoint/inttoptr pairs, etc. Why do you have this restriction?

108 ↗(On Diff #69571)

auto *

111–112 ↗(On Diff #69571)
242–243 ↗(On Diff #69571)

The alignment is signed?

Addressed review feedback.

GorNishanov marked 6 inline comments as done.Aug 29 2016, 9:13 PM
GorNishanov added inline comments.
lib/Transforms/Coroutines/CoroInstr.h
104–105 ↗(On Diff #69571)

Mostly I wanted to observe what else could be used to convert alloca %promise-type into void* parameter, so that I can correctly move them after coro.begin (in case when they are used by something other than coro.begin).

coro.begin marks the point where we know the address of the coroutine frame, so anything touching the coroutine frame should appear after it. Since promise alloca always goes to coroutine frame.

I'd like to keep it for now and revisit it in patch 12 where I add code to deal with various instructions that may appear before coro.begin that would need be moved after it. That will give us more tools to deal with ptrtoint/inttoptr possibility.

majnemer accepted this revision.Aug 30 2016, 11:52 AM
majnemer edited edge metadata.

LGTM

This revision is now accepted and ready to land.Aug 30 2016, 11:52 AM
This revision was automatically updated to reflect the committed changes.
GorNishanov marked an inline comment as done.