https://github.com/amanmaurya92 updated https://github.com/llvm/llvm-project/pull/227573
>From 8af219d094c3fad3dda852c611e4372afabc7f4c Mon Sep 17 00:00:00 2001 From: amanmaurya92 <[email protected]> Date: Wed, 30 Sep 2026 11:32:34 +0530 Subject: [PATCH] [ClangIR] Support __builtin_coro_noop Support __builtin_coro_noop in CIRGen and define cir.coro.intrinsic.noop with lowering to llvm.coro.noop. Closes #227561 Assisted-by: Antigravity --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 13 +++++++++++++ clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 3 +-- clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp | 5 +++++ clang/lib/CIR/CodeGen/CIRGenFunction.h | 1 + clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp | 6 ++++-- clang/test/CIR/IR/coro-noop.cir | 11 +++++++++++ clang/test/CIR/Lowering/coro-noop.cir | 11 +++++++++++ 7 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 clang/test/CIR/IR/coro-noop.cir create mode 100644 clang/test/CIR/Lowering/coro-noop.cir diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index de805d4c642a2..6272ecfd21f4b 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -5162,6 +5162,19 @@ 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 coroutine handle to a no-op coroutine. + }]; + let llvmOp = "CoroNoopOp"; +} + //===----------------------------------------------------------------------===// // CopyOp //===----------------------------------------------------------------------===// diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 245708691b7d9..87ddb54b57c32 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -1811,8 +1811,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 b0e03ce10d5a6..5677fbdb04163 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp @@ -340,6 +340,11 @@ CIRGenFunction::emitCoroDestroyBuiltinCall(const CallExpr *e) { emitScalarExpr(e->getArg(0))); } +cir::CoroNoopOp CIRGenFunction::emitCoroNoopBuiltinCall(const CallExpr *e) { + mlir::Location loc = getLoc(e->getBeginLoc()); + return cir::CoroNoopOp::create(cgm.getBuilder(), loc); +} + static mlir::LogicalResult coroutineBodyExceptionHelper(CIRGenFunction &cgf, const CoroutineBodyStmt &s) { diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index b232abf5d9299..f603cb770b333 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -2012,6 +2012,7 @@ class CIRGenFunction : public CIRGenTypeCache { cir::CoroDoneOp emitCoroDoneBuiltinCall(const CallExpr *e); cir::CoroResumeOp emitCoroResumeBuiltinCall(const CallExpr *e); cir::CoroDestroyOp emitCoroDestroyBuiltinCall(const CallExpr *e); + cir::CoroNoopOp emitCoroNoopBuiltinCall(const CallExpr *e); cir::CoroSizeOp emitCoroSizeBuiltinCall(const CallExpr *e); cir::CoroFreeOp emitCoroFreeBuiltin(const CallExpr *e); diff --git a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp index db22a0fbaee8b..539151dbd633d 100644 --- a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp +++ b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp @@ -29,8 +29,10 @@ void f(int n) { // LLVM: call i1 @llvm.coro.alloc(token %[[COROID]]) - // TODO - //__builtin_coro_noop(); + __builtin_coro_noop(); + // CIR: %[[NOOP:.*]] = cir.coro.intrinsic.noop() : () -> !cir.ptr<!void> + + // LLVM: %[[NOOP:.*]] = call ptr @llvm.coro.noop() __builtin_coro_begin(myAlloc(__builtin_coro_size())); // TODO(CIR): Support both variants of the coroutine size intrinsic, matching diff --git a/clang/test/CIR/IR/coro-noop.cir b/clang/test/CIR/IR/coro-noop.cir new file mode 100644 index 0000000000000..353e5f8d409f1 --- /dev/null +++ b/clang/test/CIR/IR/coro-noop.cir @@ -0,0 +1,11 @@ +// RUN: cir-opt %s --verify-roundtrip | FileCheck %s + +!void = !cir.void + +module { + cir.func @test_coro_noop() -> !cir.ptr<!void> { + // CHECK: %0 = cir.coro.intrinsic.noop() : () -> !cir.ptr<!void> + %0 = cir.coro.intrinsic.noop() : () -> !cir.ptr<!void> + cir.return %0 : !cir.ptr<!void> + } +} diff --git a/clang/test/CIR/Lowering/coro-noop.cir b/clang/test/CIR/Lowering/coro-noop.cir new file mode 100644 index 0000000000000..6625ac4142117 --- /dev/null +++ b/clang/test/CIR/Lowering/coro-noop.cir @@ -0,0 +1,11 @@ +// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s + +!void = !cir.void + +module attributes {cir.triple = "x86_64-unknown-linux-gnu"} { + cir.func @test_coro_noop() -> !cir.ptr<!void> { + // CHECK: %0 = llvm.intr.coro.noop : !llvm.ptr + %0 = cir.coro.intrinsic.noop() : () -> !cir.ptr<!void> + cir.return %0 : !cir.ptr<!void> + } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
