[clang] [CIR] handle __builtin_coro_noop (PR #222928)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 04:36:16 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
@llvm/pr-subscribers-clang
Author: Letu Ren (FantasqueX)
<details>
<summary>Changes</summary>
Add cir.coro.intrinsic.noop Op.
Assisted-by: Cursor / grok-4.6
---
Full diff: https://github.com/llvm/llvm-project/pull/222928.diff
5 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+14)
- (modified) clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp (+1-2)
- (modified) clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp (+5)
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+1)
- (modified) clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp (+3-2)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 449af063cf9ac..cf23a39981f97 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5062,6 +5062,20 @@ def CIR_CoroDoneOp : CIR_CoroIntrinsicOp<"done", (ins CIR_VoidPtrType:$handle),
let llvmOp = "CoroDoneOp";
}
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic NoopOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CoroNoopOp : CIR_CoroIntrinsicOp<"noop", (ins),
+ (outs CIR_VoidPtrType:$result)> {
+ let summary = "Represents llvm.coro.noop";
+ let description = [{
+ Returns a handle to a coroutine that does nothing when resumed or
+ destroyed.
+ }];
+ let llvmOp = "CoroNoopOp";
+}
+
//===----------------------------------------------------------------------===//
// CopyOp
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index ee0b4fa49d4c6..afd1251c7d6a8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -1740,8 +1740,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
return RValue::get(nullptr);
}
case Builtin::BI__builtin_coro_noop:
- cgm.errorNYI(e->getSourceRange(), "BI__builtin_coro_noop NYI");
- return getUndefRValue(e->getType());
+ return RValue::get(emitCoroNoopBuiltinCall(e).getResult());
case Builtin::BI__builtin_coro_destroy: {
emitCoroDestroyBuiltinCall(e);
return RValue::get(nullptr);
diff --git a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
index 6f2c0e33ce1d9..24de5e81fdb5b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
@@ -309,6 +309,11 @@ cir::CoroSizeOp CIRGenFunction::emitCoroSizeBuiltinCall(const CallExpr *e) {
return cir::CoroSizeOp::create(cgm.getBuilder(), loc);
}
+cir::CoroNoopOp CIRGenFunction::emitCoroNoopBuiltinCall(const CallExpr *e) {
+ mlir::Location loc = getLoc(e->getBeginLoc());
+ return cir::CoroNoopOp::create(cgm.getBuilder(), loc);
+}
+
cir::CoroPromiseOp
CIRGenFunction::emitCoroPromiseBuiltinCall(const CallExpr *e) {
mlir::Location loc = getLoc(e->getBeginLoc());
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 5a4529821f5ef..c9c79fd920cd0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -1921,6 +1921,7 @@ class CIRGenFunction : public CIRGenTypeCache {
cir::CoroDestroyOp emitCoroDestroyBuiltinCall(const CallExpr *e);
cir::CoroSizeOp emitCoroSizeBuiltinCall(const CallExpr *e);
+ cir::CoroNoopOp emitCoroNoopBuiltinCall(const CallExpr *e);
cir::CoroFreeOp emitCoroFreeBuiltin(const CallExpr *e);
RValue emitCoroutineFrame();
diff --git a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
index db22a0fbaee8b..acf0ba03a2fa5 100644
--- a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
+++ b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
@@ -29,8 +29,9 @@ void f(int n) {
// LLVM: call i1 @llvm.coro.alloc(token %[[COROID]])
- // TODO
- //__builtin_coro_noop();
+ __builtin_coro_noop();
+ // CIR: cir.coro.intrinsic.noop()
+ // LLVM: call ptr @llvm.coro.noop()
__builtin_coro_begin(myAlloc(__builtin_coro_size()));
// TODO(CIR): Support both variants of the coroutine size intrinsic, matching
``````````
</details>
https://github.com/llvm/llvm-project/pull/222928
More information about the cfe-commits
mailing list