[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 4 13:42:57 PST 2024
================
@@ -79,6 +79,73 @@ using namespace llvm;
namespace {
+// Created on demand if the coro-early pass has work to do.
+class Lowerer : public coro::LowererBase {
+ IRBuilder<> Builder;
+ void lowerAwaitSuspend(CoroAwaitSuspendInst *CB);
+
+public:
+ Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
+
+ void lowerAwaitSuspends(Function &F);
+};
+
+void Lowerer::lowerAwaitSuspend(CoroAwaitSuspendInst *CB) {
+ auto Helper = CB->getHelperFunction();
+ auto Awaiter = CB->getAwaiter();
+ auto FramePtr = CB->getFrame();
+
+ Builder.SetInsertPoint(CB);
+
+ CallBase *NewCall = nullptr;
+ if (auto Invoke = dyn_cast<InvokeInst>(CB)) {
+ auto HelperInvoke =
+ Builder.CreateInvoke(Helper, Invoke->getNormalDest(),
+ Invoke->getUnwindDest(), {Awaiter, FramePtr});
+
+ HelperInvoke->setCallingConv(Invoke->getCallingConv());
+ std::copy(Invoke->bundle_op_info_begin(), Invoke->bundle_op_info_end(),
+ HelperInvoke->bundle_op_info_begin());
+ AttributeList NewAttributes =
+ Invoke->getAttributes().removeParamAttributes(Context, 2);
+ HelperInvoke->setAttributes(NewAttributes);
+ HelperInvoke->setDebugLoc(Invoke->getDebugLoc());
+ NewCall = HelperInvoke;
+ } else if (auto Call = dyn_cast<CallInst>(CB)) {
+ auto HelperCall = Builder.CreateCall(Helper, {Awaiter, FramePtr});
+
+ AttributeList NewAttributes =
+ Call->getAttributes().removeParamAttributes(Context, 2);
+ HelperCall->setAttributes(NewAttributes);
+ HelperCall->setDebugLoc(Call->getDebugLoc());
+ NewCall = HelperCall;
+ }
----------------
fpasserby wrote:
Added unreachable
https://github.com/llvm/llvm-project/pull/79712
More information about the cfe-commits
mailing list