From 9340c957c479a0260f16bf760cb98e02fc7f73fb Mon Sep 17 00:00:00 2001 From: seven-mile Date: Mon, 30 Sep 2024 00:52:55 +0800 Subject: [PATCH] [CIR][CodeGen] Add `nothrow` for functions in OpenCL languages --- clang/lib/CIR/CodeGen/CIRGenCall.cpp | 10 ++++++++ clang/test/CIR/CodeGen/OpenCL/convergent.cl | 5 ++-- clang/test/CIR/CodeGen/OpenCL/nothrow.cl | 26 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 clang/test/CIR/CodeGen/OpenCL/nothrow.cl diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index c5b7e2a2edae..2deb709e38f4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -1591,6 +1591,16 @@ static void getTrivialDefaultFunctionAttributes( auto convgt = mlir::cir::ConvergentAttr::get(CGM.getBuilder().getContext()); funcAttrs.set(convgt.getMnemonic(), convgt); } + + // TODO: NoThrow attribute should be added for other GPU modes CUDA, SYCL, + // HIP, OpenMP offload. + // AFAIK, neither of them support exceptions in device code. + if ((langOpts.CUDA && langOpts.CUDAIsDevice) || langOpts.SYCLIsDevice) + llvm_unreachable("NYI"); + if (langOpts.OpenCL) { + auto noThrow = mlir::cir::NoThrowAttr::get(CGM.getBuilder().getContext()); + funcAttrs.set(noThrow.getMnemonic(), noThrow); + } } void CIRGenModule::getTrivialDefaultFunctionAttributes( diff --git a/clang/test/CIR/CodeGen/OpenCL/convergent.cl b/clang/test/CIR/CodeGen/OpenCL/convergent.cl index d953aa799307..a2d4a910004c 100644 --- a/clang/test/CIR/CodeGen/OpenCL/convergent.cl +++ b/clang/test/CIR/CodeGen/OpenCL/convergent.cl @@ -8,7 +8,6 @@ // CIR: #fn_attr[[CONV_NOINLINE_ATTR:[0-9]*]] = #cir // CIR-NEXT: #fn_attr[[CONV_DECL_ATTR:[0-9]*]] = #cir