From 80efdd104152559eb562e10b396623919f8fe3a8 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Tue, 28 Oct 2025 16:42:11 +0800 Subject: [PATCH 1/3] [SYCL][NFC] Extend getKernelNamesUsingAssert to support general function names Signed-off-by: jinge90 --- .../SYCLPostLink/ComputeModuleRuntimeInfo.cpp | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp index 39548ab2db82d..4d52fb4889976 100644 --- a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp +++ b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp @@ -66,11 +66,12 @@ bool isModuleUsingTsan(const Module &M) { // Optional. // Otherwise, it returns an Optional containing a list of reached // SPIR kernel function's names. -static std::optional> -traverseCGToFindSPIRKernels(const Function *StartingFunction) { +static std::optional> traverseCGToFindSPIRKernels( + const std::vector &StartingFunctionVec) { std::queue FunctionsToVisit; std::unordered_set VisitedFunctions; - FunctionsToVisit.push(StartingFunction); + for (const Function *FPtr : StartingFunctionVec) + FunctionsToVisit.push(FPtr); std::vector KernelNames; while (!FunctionsToVisit.empty()) { @@ -106,13 +107,20 @@ traverseCGToFindSPIRKernels(const Function *StartingFunction) { return {std::move(KernelNames)}; } -static std::vector getKernelNamesUsingAssert(const Module &M) { - auto *DevicelibAssertFailFunction = M.getFunction("__devicelib_assert_fail"); - if (!DevicelibAssertFailFunction) +static std::vector +getKernelNamesUsingSpecialFunctions(const Module &M, + std::vector &FNames) { + std::vector SpecialFunctionVec; + for (auto Fn : FNames) { + Function *FPtr = M.getFunction(Fn); + if (FPtr) + SpecialFunctionVec.push_back(FPtr); + } + + if (SpecialFunctionVec.size() == 0) return {}; - auto TraverseResult = - traverseCGToFindSPIRKernels(DevicelibAssertFailFunction); + auto TraverseResult = traverseCGToFindSPIRKernels(SpecialFunctionVec); if (TraverseResult.has_value()) return std::move(*TraverseResult); @@ -442,7 +450,9 @@ PropSetRegTy computeModuleProperties(const Module &M, PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "optLevel", OptLevel); } { - std::vector FuncNames = getKernelNamesUsingAssert(M); + std::vector AssertFuncNames{"__devicelib_assert_fail"}; + std::vector FuncNames = + getKernelNamesUsingSpecialFunctions(M, AssertFuncNames); for (const StringRef &FName : FuncNames) PropSet.add(PropSetRegTy::SYCL_ASSERT_USED, FName, true); } From 1d82d9d03a65822f2524c8fab5f1423d39dfff5d Mon Sep 17 00:00:00 2001 From: jinge90 Date: Wed, 29 Oct 2025 09:31:42 +0800 Subject: [PATCH 2/3] Update llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp Co-authored-by: Marcos Maronas --- llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp index 4d52fb4889976..c85b84e4e22b0 100644 --- a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp +++ b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp @@ -109,7 +109,7 @@ static std::optional> traverseCGToFindSPIRKernels( static std::vector getKernelNamesUsingSpecialFunctions(const Module &M, - std::vector &FNames) { + const std::vector &FNames) { std::vector SpecialFunctionVec; for (auto Fn : FNames) { Function *FPtr = M.getFunction(Fn); From bbabb7054e5eff0e9ac7997cb8ef639187c69bc9 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Wed, 29 Oct 2025 09:31:49 +0800 Subject: [PATCH 3/3] Update llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp Co-authored-by: Marcos Maronas --- llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp index c85b84e4e22b0..c4bd7129fefe4 100644 --- a/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp +++ b/llvm/lib/SYCLPostLink/ComputeModuleRuntimeInfo.cpp @@ -111,7 +111,7 @@ static std::vector getKernelNamesUsingSpecialFunctions(const Module &M, const std::vector &FNames) { std::vector SpecialFunctionVec; - for (auto Fn : FNames) { + for (const auto Fn : FNames) { Function *FPtr = M.getFunction(Fn); if (FPtr) SpecialFunctionVec.push_back(FPtr);