[PATCH] D30809: [coroutines] Add codegen for await and yield expressions

Gor Nishanov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 9 21:37:29 PST 2017


GorNishanov created this revision.
Herald added a subscriber: mehdi_amini.

Emit suspend expression which roughly looks like:

  auto && x = CommonExpr();
  if (!x.await_ready()) {
     llvm_coro_save();
     x.await_suspend(...);     (*)
     llvm_coro_suspend(); (**)
  }
  x.await_resume();

where the result of the entire expression is the result of x.await_resume()

  (*) If x.await_suspend return type is bool, it allows to veto a suspend:

  if (x.await_suspend(...)) 
     llvm_coro_suspend();

(**) llvm_coro_suspend() encodes three possible continuations as a switch instruction:

  %where-to = call i8 @llvm.coro.suspend(...)
  switch i8 %where-to, label %coro.ret [ ; jump to epilogue to suspend
    i8 0, label %yield.ready   ; go here when resumed
    i8 1, label %yield.cleanup ; go here when destroyed
  ]


https://reviews.llvm.org/D30809

Files:
  lib/CodeGen/CGCoroutine.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenCoroutines/coro-await.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30809.91265.patch
Type: text/x-patch
Size: 14730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170310/2d0fdaa8/attachment-0001.bin>


More information about the cfe-commits mailing list