From fb44b9db95a333efdfa9a33ddc1778f97428f5f5 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Wed, 29 Jan 2020 14:11:37 -0500 Subject: [OpenCL][CUDA][HIP][SYCL] Add norecurse norecurse function attr indicates the function is not called recursively directly or indirectly. Add norecurse to OpenCL functions, SYCL functions in device compilation and CUDA/HIP kernels. Although there is LLVM pass adding norecurse to functions, it only works for whole-program compilation. Also FE adding norecurse can make that pass run faster since functions with norecurse do not need to be checked again. Differential Revision: https://reviews.llvm.org/D73651 --- clang/lib/CodeGen/CodeGenFunction.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index bcd9366..d6c2afc 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -918,10 +918,20 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, // If we're in C++ mode and the function name is "main", it is guaranteed // to be norecurse by the standard (3.6.1.3 "The function main shall not be // used within a program"). - if (getLangOpts().CPlusPlus) - if (const FunctionDecl *FD = dyn_cast_or_null(D)) - if (FD->isMain()) - Fn->addFnAttr(llvm::Attribute::NoRecurse); + // + // OpenCL C 2.0 v2.2-11 s6.9.i: + // Recursion is not supported. + // + // SYCL v1.2.1 s3.10: + // kernels cannot include RTTI information, exception classes, + // recursive code, virtual functions or make use of C++ libraries that + // are not compiled for the device. + if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if ((getLangOpts().CPlusPlus && FD->isMain()) || getLangOpts().OpenCL || + getLangOpts().SYCLIsDevice || + (getLangOpts().CUDA && FD->hasAttr())) + Fn->addFnAttr(llvm::Attribute::NoRecurse); + } if (const FunctionDecl *FD = dyn_cast_or_null(D)) if (FD->usesFPIntrin()) -- cgit v1.1