From 747e14d308eed04a0d218706f72c4db8e9032970 Mon Sep 17 00:00:00 2001 From: Maksim Sabianin Date: Tue, 21 Dec 2021 22:47:51 +0300 Subject: [PATCH 1/5] [SYCL] optimize getKernelNamesUsingAssert Now it traverses reversed call graph by BFS algorithm from __devicelib_assert_fail function up to SPIR kernels. --- .../assert-indirect-with-split-2.ll | 14 +- .../tools/sycl-post-link/assert-property-2.ll | 36 ++-- .../assert-property-with-split.ll | 16 +- llvm/tools/sycl-post-link/sycl-post-link.cpp | 166 +++++++----------- 4 files changed, 96 insertions(+), 136 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll index bbbf417066a45..d199fd7e20321 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll @@ -63,13 +63,6 @@ entry: ret void } -; CHECK-NOT: main_TU0_kernel1 -define dso_local spir_kernel void @main_TU0_kernel1() #0 { -entry: - call spir_func void @_Z4foo1v() - ret void -} - ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo1v() { entry: @@ -85,6 +78,13 @@ entry: ret void } +; CHECK-NOT: main_TU0_kernel1 +define dso_local spir_kernel void @main_TU0_kernel1() #0 { +entry: + call spir_func void @_Z4foo1v() + ret void +} + ; This function is marked with "referenced-indirectly", but it doesn't call an assert ; Function Attrs: nounwind diff --git a/llvm/test/tools/sycl-post-link/assert-property-2.ll b/llvm/test/tools/sycl-post-link/assert-property-2.ll index 5a250734fead9..40d0682fc88ac 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-2.ll @@ -122,7 +122,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 +; CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 ; Function Attrs: convergent noinline norecurse mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9() #0 { entry: @@ -130,7 +130,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 +; CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 ; Function Attrs: convergent noinline norecurse optnone mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10() #0 { entry: @@ -164,7 +164,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 { entry: @@ -186,7 +186,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 { entry: @@ -216,7 +216,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 { entry: @@ -244,7 +244,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 { entry: @@ -252,7 +252,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 { entry: @@ -267,15 +267,6 @@ entry: ret void } -; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6E_exclv() - call spir_func void @_Z6E_exclv() - ret void -} - ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6F_inclv() local_unnamed_addr { entry: @@ -283,7 +274,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 { entry: @@ -328,7 +319,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 +; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 ; Function Attrs: convergent norecurse mustprogress define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 { call spir_func void @_Z1Gv() @@ -336,6 +327,15 @@ define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7han ret void } +; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6E_exclv() + call spir_func void @_Z6E_exclv() + ret void +} + ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll index 0da502805f4bc..0d4f84c51c826 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll @@ -18,7 +18,7 @@ target triple = "spir64-unknown-linux" ; CHECK: [SYCL/assert used] -; CHECK: _ZTSZ4mainE11TU0_kernel0 +; CHECK-DAG: _ZTSZ4mainE11TU0_kernel0 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() @@ -36,6 +36,13 @@ entry: ret void } +; CHECK-DAG: _ZTSZ4mainE10TU1_kernel +define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { +entry: + call spir_func void @_Z4foo2v() + ret void +} + ; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 { entry: @@ -51,13 +58,6 @@ entry: ret void } -; CHECK: _ZTSZ4mainE10TU1_kernel -define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { -entry: - call spir_func void @_Z4foo2v() - ret void -} - ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo2v() { entry: diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index e1f29cd1e683a..d1519d9bbb648 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -46,7 +46,10 @@ #include #include #include +#include #include +#include +#include #include using namespace llvm; @@ -352,124 +355,81 @@ void groupEntryPoints(const Module &M, EntryPointGroupMap &EntryPointsGroups, EntryPointsGroups[GLOBAL_SCOPE_NAME] = {}; } -enum HasAssertStatus { No_Assert, Assert, Assert_Indirect }; - -// Go through function call graph searching for assert call. -HasAssertStatus hasAssertInFunctionCallGraph(const Function *Func) { - // Map holds the info about assertions in already examined functions: - // true - if there is an assertion in underlying functions, - // false - if there are definetely no assertions in underlying functions. - static std::map hasAssertionInCallGraphMap; - std::vector FuncCallStack; - - static std::vector isIndirectlyCalledInGraph; - - std::vector Workstack; - Workstack.push_back(Func); - - while (!Workstack.empty()) { - const Function *F = Workstack.back(); - Workstack.pop_back(); - if (F != Func) - FuncCallStack.push_back(F); - - bool HasIndirectlyCalledAttr = false; - if (std::find(isIndirectlyCalledInGraph.begin(), - isIndirectlyCalledInGraph.end(), - F) != isIndirectlyCalledInGraph.end()) - HasIndirectlyCalledAttr = true; - else if (F->hasFnAttribute("referenced-indirectly")) { - HasIndirectlyCalledAttr = true; - isIndirectlyCalledInGraph.push_back(F); - } +// This function traverses over reversed call graph by BFS algorithm. +// It means that an edge links some function @func with functions +// which contain call of function @func.It starts from +// @StartingFunction and lifts up until it reach all reachable functions +// or it reaches some function containing "referenced-indirectly" attribute. +// If it reaches "referenced-indirectly" attribute than it returns true and +// an empty list. +// Otherwise, it returns false and a list of reached SPIR kernel function's +// names. +std::pair> +TraverseCGToFindSPIRKernels(const Function *StartingFunction) { + std::queue FunctionsToVisit; + std::unordered_set VisitedFunctions; + FunctionsToVisit.push(StartingFunction); + std::vector KernelNames; + + while (!FunctionsToVisit.empty()) { + const Function *F = FunctionsToVisit.front(); + FunctionsToVisit.pop(); + + // It is possible that we insert some particular function several + // times in functionsToVisit queue. + if (VisitedFunctions.find(F) != VisitedFunctions.end()) + continue; - bool IsLeaf = true; - for (const auto &I : instructions(F)) { - if (!isa(&I)) - continue; + VisitedFunctions.insert(F); - const Function *CF = cast(&I)->getCalledFunction(); - if (!CF) + for (const auto *U : F->users()) { + const Instruction *I = cast(U); + const Function *ParentF = I->getFunction(); + if (VisitedFunctions.find(ParentF) != VisitedFunctions.end()) continue; - bool IsIndirectlyCalled = - HasIndirectlyCalledAttr || - std::find(isIndirectlyCalledInGraph.begin(), - isIndirectlyCalledInGraph.end(), - CF) != isIndirectlyCalledInGraph.end(); - - // Return if we've already discovered if there are asserts in the - // function call graph. - auto HasAssert = hasAssertionInCallGraphMap.find(CF); - if (HasAssert != hasAssertionInCallGraphMap.end()) { - // If we know, that this function does not contain assert, we still - // should investigate another instructions in the function. - if (!HasAssert->second) - continue; - - return IsIndirectlyCalled ? Assert_Indirect : Assert; + if (ParentF->hasFnAttribute("referenced-indirectly")) { + return {true, {}}; } - if (CF->getName().startswith("__devicelib_assert_fail")) { - // Mark all the functions above in call graph as ones that can call - // assert. - for (const auto *It : FuncCallStack) - hasAssertionInCallGraphMap[It] = true; - - hasAssertionInCallGraphMap[Func] = true; - hasAssertionInCallGraphMap[CF] = true; - - return IsIndirectlyCalled ? Assert_Indirect : Assert; - } + if (ParentF->getCallingConv() == CallingConv::SPIR_KERNEL) + KernelNames.push_back(ParentF->getName()); - if (!CF->isDeclaration()) { - Workstack.push_back(CF); - IsLeaf = false; - if (HasIndirectlyCalledAttr) - isIndirectlyCalledInGraph.push_back(CF); - } - } - - if (IsLeaf && !FuncCallStack.empty()) { - // Mark the leaf function as one that definetely does not call assert. - hasAssertionInCallGraphMap[FuncCallStack.back()] = false; - FuncCallStack.clear(); + FunctionsToVisit.push(ParentF); } } - return No_Assert; + + return {false, std::move(KernelNames)}; } std::vector getKernelNamesUsingAssert(const Module &M) { - std::vector Result; - - bool HasIndirectlyCalledAssert = false; - EntryPointGroup Kernels; - for (const auto &F : M.functions()) { - // TODO: handle SYCL_EXTERNAL functions for dynamic linkage. - // TODO: handle function pointers. - if (F.getCallingConv() != CallingConv::SPIR_KERNEL) - continue; - - Kernels.push_back(&F); - if (HasIndirectlyCalledAssert) - continue; - - HasAssertStatus HasAssert = hasAssertInFunctionCallGraph(&F); - switch (HasAssert) { - case Assert: - Result.push_back(F.getName()); - break; - case Assert_Indirect: - HasIndirectlyCalledAssert = true; - break; - case No_Assert: - break; + Optional DevicelibAssertFailFunction; + std::vector SPIRKernelNames; + // This loop finds all SPIR kernel's names and __devicelib_assert_fail + // function if it is present. + for (const Function &F : M) { + if (F.getCallingConv() == CallingConv::SPIR_KERNEL) + SPIRKernelNames.push_back(F.getName()); + + if (F.getName().startswith("__devicelib_assert_fail")) { + assert(!DevicelibAssertFailFunction.hasValue()); + DevicelibAssertFailFunction = &F; } } - if (HasIndirectlyCalledAssert) - for (const auto *F : Kernels) - Result.push_back(F->getName()); + if (!DevicelibAssertFailFunction) + return {}; + + auto TraverseResult = + TraverseCGToFindSPIRKernels(*DevicelibAssertFailFunction); + std::vector Result; + if (TraverseResult.first) { + // If assert is met in some indirectly callable function than + // we return all kernels in Module due to the current assert's design. + Result = std::move(SPIRKernelNames); + } else { + Result = std::move(TraverseResult.second); + } return Result; } From 7d4b9735040880829b0403a902a83816c76b4de1 Mon Sep 17 00:00:00 2001 From: Maksim Sabianin Date: Wed, 22 Dec 2021 13:56:07 +0300 Subject: [PATCH 2/5] fix review remarks --- .../assert-indirect-with-split-2.ll | 15 +++-- .../tools/sycl-post-link/assert-property-2.ll | 19 +++--- .../assert-property-with-split.ll | 17 +++--- llvm/tools/sycl-post-link/sycl-post-link.cpp | 60 ++++++++----------- 4 files changed, 49 insertions(+), 62 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll index d199fd7e20321..0819d3d96d7d9 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll @@ -9,7 +9,7 @@ ; marked as using asserts. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not main_TU0_kernel1 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -63,6 +63,12 @@ entry: ret void } +define dso_local spir_kernel void @main_TU0_kernel1() #0 { +entry: + call spir_func void @_Z4foo1v() + ret void +} + ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo1v() { entry: @@ -78,13 +84,6 @@ entry: ret void } -; CHECK-NOT: main_TU0_kernel1 -define dso_local spir_kernel void @main_TU0_kernel1() #0 { -entry: - call spir_func void @_Z4foo1v() - ret void -} - ; This function is marked with "referenced-indirectly", but it doesn't call an assert ; Function Attrs: nounwind diff --git a/llvm/test/tools/sycl-post-link/assert-property-2.ll b/llvm/test/tools/sycl-post-link/assert-property-2.ll index 40d0682fc88ac..3820dc5f60e85 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-2.ll @@ -3,7 +3,7 @@ ; graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 ; SYCL source: ; void assert_func() { @@ -267,6 +267,14 @@ entry: ret void } +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6E_exclv() + call spir_func void @_Z6E_exclv() + ret void +} + ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6F_inclv() local_unnamed_addr { entry: @@ -327,15 +335,6 @@ define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7han ret void } -; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6E_exclv() - call spir_func void @_Z6E_exclv() - ret void -} - ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll index 0d4f84c51c826..1ed6ac4d98e7f 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll @@ -3,7 +3,7 @@ ; in their call graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZ4mainE11TU0_kernel1 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -36,14 +36,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZ4mainE10TU1_kernel -define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { -entry: - call spir_func void @_Z4foo2v() - ret void -} - -; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() @@ -58,6 +50,13 @@ entry: ret void } +; CHECK-DAG: _ZTSZ4mainE10TU1_kernel +define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { +entry: + call spir_func void @_Z4foo2v() + ret void +} + ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo2v() { entry: diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index d1519d9bbb648..bb5a506ab4410 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -357,14 +357,14 @@ void groupEntryPoints(const Module &M, EntryPointGroupMap &EntryPointsGroups, // This function traverses over reversed call graph by BFS algorithm. // It means that an edge links some function @func with functions -// which contain call of function @func.It starts from +// which contain call of function @func. It starts from // @StartingFunction and lifts up until it reach all reachable functions // or it reaches some function containing "referenced-indirectly" attribute. -// If it reaches "referenced-indirectly" attribute than it returns true and -// an empty list. -// Otherwise, it returns false and a list of reached SPIR kernel function's -// names. -std::pair> +// If it reaches "referenced-indirectly" attribute than it returns an empty +// Optional. +// Otherwise, it returns an Optional containing a list of reached +// SPIR kernel function's names. +Optional> TraverseCGToFindSPIRKernels(const Function *StartingFunction) { std::queue FunctionsToVisit; std::unordered_set VisitedFunctions; @@ -375,21 +375,20 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) { const Function *F = FunctionsToVisit.front(); FunctionsToVisit.pop(); + auto InsertionResult = VisitedFunctions.insert(F); // It is possible that we insert some particular function several // times in functionsToVisit queue. - if (VisitedFunctions.find(F) != VisitedFunctions.end()) + if (!InsertionResult.second) continue; - VisitedFunctions.insert(F); - for (const auto *U : F->users()) { const Instruction *I = cast(U); const Function *ParentF = I->getFunction(); - if (VisitedFunctions.find(ParentF) != VisitedFunctions.end()) + if (VisitedFunctions.count(ParentF)) continue; if (ParentF->hasFnAttribute("referenced-indirectly")) { - return {true, {}}; + return {}; } if (ParentF->getCallingConv() == CallingConv::SPIR_KERNEL) @@ -399,39 +398,30 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) { } } - return {false, std::move(KernelNames)}; + return std::move(KernelNames); } std::vector getKernelNamesUsingAssert(const Module &M) { - Optional DevicelibAssertFailFunction; - std::vector SPIRKernelNames; - // This loop finds all SPIR kernel's names and __devicelib_assert_fail - // function if it is present. - for (const Function &F : M) { - if (F.getCallingConv() == CallingConv::SPIR_KERNEL) - SPIRKernelNames.push_back(F.getName()); - - if (F.getName().startswith("__devicelib_assert_fail")) { - assert(!DevicelibAssertFailFunction.hasValue()); - DevicelibAssertFailFunction = &F; - } - } - + auto DevicelibAssertFailFunction = M.getFunction("__devicelib_assert_fail"); if (!DevicelibAssertFailFunction) return {}; auto TraverseResult = - TraverseCGToFindSPIRKernels(*DevicelibAssertFailFunction); - std::vector Result; - if (TraverseResult.first) { - // If assert is met in some indirectly callable function than - // we return all kernels in Module due to the current assert's design. - Result = std::move(SPIRKernelNames); - } else { - Result = std::move(TraverseResult.second); + TraverseCGToFindSPIRKernels(DevicelibAssertFailFunction); + + if (TraverseResult.hasValue()) { + return std::move(*TraverseResult); + } + + // Here we reached "referenced-indirectly", so we need to find all kernels and + // return them. + std::vector SPIRKernelNames; + for (const Function &F : M) { + if (F.getCallingConv() == CallingConv::SPIR_KERNEL) + SPIRKernelNames.push_back(F.getName()); } - return Result; + return SPIRKernelNames; } // Gets reqd_work_group_size information for function Func. From d7341187b8e9784d1b06154674f6cf328fe045a4 Mon Sep 17 00:00:00 2001 From: Maksim Sabianin Date: Wed, 22 Dec 2021 15:02:37 +0300 Subject: [PATCH 3/5] Adjust with LLVM coding style --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index bb5a506ab4410..255bd7a3f5ad4 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -387,9 +387,8 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) { if (VisitedFunctions.count(ParentF)) continue; - if (ParentF->hasFnAttribute("referenced-indirectly")) { + if (ParentF->hasFnAttribute("referenced-indirectly")) return {}; - } if (ParentF->getCallingConv() == CallingConv::SPIR_KERNEL) KernelNames.push_back(ParentF->getName()); @@ -409,9 +408,8 @@ std::vector getKernelNamesUsingAssert(const Module &M) { auto TraverseResult = TraverseCGToFindSPIRKernels(DevicelibAssertFailFunction); - if (TraverseResult.hasValue()) { + if (TraverseResult.hasValue()) return std::move(*TraverseResult); - } // Here we reached "referenced-indirectly", so we need to find all kernels and // return them. From 0a0df334838ce1ae6d4646028d427550e6ac8ce3 Mon Sep 17 00:00:00 2001 From: Maksim Sabianin Date: Fri, 24 Dec 2021 23:29:54 +0300 Subject: [PATCH 4/5] sort kernel's names which use asserts. refuse of CHECK-DAG. Kernel's names in tests are sorted so that order of checking was strictly fixed. --- .../assert-indirect-with-split-2.ll | 27 ++-- .../assert-indirect-with-split.ll | 8 +- .../tools/sycl-post-link/assert-property-1.ll | 16 +- .../tools/sycl-post-link/assert-property-2.ll | 143 +++++++++--------- .../assert-property-with-split.ll | 19 +-- llvm/tools/sycl-post-link/sycl-post-link.cpp | 9 +- 6 files changed, 118 insertions(+), 104 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll index 0819d3d96d7d9..b32a51707da7b 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll @@ -9,7 +9,7 @@ ; marked as using asserts. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not main_TU0_kernel1 +; RUN: FileCheck %s -input-file=%t_0.prop target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -24,17 +24,15 @@ target triple = "spir64-unknown-linux" ; CHECK: [SYCL/assert used] -; CHECK-DAG: main_TU1_kernel1 -define dso_local spir_kernel void @main_TU1_kernel1() #2 { +define dso_local spir_func void @foo() #2 { entry: - call spir_func void @foo() - call spir_func void @bar() + call spir_func void @_Z4foo1v() ret void } -define dso_local spir_func void @foo() #2 { -entry: - call spir_func void @_Z4foo1v() +; CHECK-NOT: empty_kernel +define dso_local spir_kernel void @empty_kernel() { + %1 = ptrtoint void ()* @bar to i64 ret void } @@ -45,13 +43,14 @@ entry: ret void } -; CHECK-DAG: main_TU0_kernel0 +; CHECK: main_TU0_kernel0 define dso_local spir_kernel void @main_TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() ; call assert ret void } + define dso_local spir_func void @_Z3foov() { entry: %a = alloca i32, align 4 @@ -63,6 +62,7 @@ entry: ret void } +; CHECK-NOT: main_TU0_kernel1 define dso_local spir_kernel void @main_TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() @@ -77,7 +77,7 @@ entry: ret void } -; CHECK-DAG: main_TU1_kernel0 +; CHECK: main_TU1_kernel0 define dso_local spir_kernel void @main_TU1_kernel0() #2 { entry: call spir_func void @_Z3foov() ; call assert @@ -96,6 +96,13 @@ entry: ret void } +; CHECK: main_TU1_kernel1 +define dso_local spir_kernel void @main_TU1_kernel1() #2 { +entry: + call spir_func void @foo() + call spir_func void @bar() + ret void +} ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll index 48c0983b3abde..c1a8481dcc9ba 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll @@ -22,7 +22,7 @@ target triple = "spir64-unknown-linux" ; CHECK: [SYCL/assert used] -; CHECK-DAG: main_TU0_kernel0 +; CHECK: main_TU0_kernel0 define dso_local spir_kernel void @main_TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() @@ -40,7 +40,7 @@ entry: ret void } -; CHECK-DAG: main_TU0_kernel1 +; CHECK: main_TU0_kernel1 define dso_local spir_kernel void @main_TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() @@ -55,14 +55,14 @@ entry: ret void } -; CHECK-DAG: main_TU1_kernel0 +; CHECK: main_TU1_kernel0 define dso_local spir_kernel void @main_TU1_kernel0() #2 { entry: call spir_func void @_Z3foov() ret void } -; CHECK-DAG: main_TU1_kernel1 +; CHECK: main_TU1_kernel1 define dso_local spir_kernel void @main_TU1_kernel1() #2 { entry: call spir_func void @_Z4foo2v() diff --git a/llvm/test/tools/sycl-post-link/assert-property-1.ll b/llvm/test/tools/sycl-post-link/assert-property-1.ll index df3bb294c6fe7..774252bad2a18 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-1.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-1.ll @@ -57,6 +57,14 @@ entry: ret void } +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3 +; Function Attrs: convergent norecurse +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3"() #0 { +entry: + call spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_4itemILi2ELb1EEEE1_clES5_"() + ret void +} + ; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel ; Function Attrs: convergent norecurse define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel"() #0 { @@ -94,14 +102,6 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3 -; Function Attrs: convergent norecurse -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3"() #0 { -entry: - call spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_4itemILi2ELb1EEEE1_clES5_"() - ret void -} - ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-2.ll b/llvm/test/tools/sycl-post-link/assert-property-2.ll index 3820dc5f60e85..fb3279a5154e4 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-2.ll @@ -3,7 +3,7 @@ ; graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 +; RUN: FileCheck %s -input-file=%t_0.prop ; SYCL source: ; void assert_func() { @@ -122,7 +122,76 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6A_exclv() + call spir_func void @_Z6B_inclv() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6A_inclv() + call spir_func void @_Z6B_exclv() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6commonv() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z7common2v() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6B_inclv() + call spir_func void @_Z6A_exclv() + ret void +} + +; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6E_exclv() + call spir_func void @_Z6E_exclv() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6F_inclv() + call spir_func void @_Z6F_inclv() + ret void +} + +; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 { + call spir_func void @_Z1Gv() + call spir_func void @_Z1Hv() + ret void +} + +; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 ; Function Attrs: convergent noinline norecurse mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9() #0 { entry: @@ -130,7 +199,7 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 +; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 ; Function Attrs: convergent noinline norecurse optnone mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10() #0 { entry: @@ -164,15 +233,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6A_exclv() - call spir_func void @_Z6B_inclv() - ret void -} - ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6A_inclv() local_unnamed_addr { entry: @@ -186,15 +246,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6A_inclv() - call spir_func void @_Z6B_exclv() - ret void -} - ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6commonv() local_unnamed_addr { entry: @@ -216,14 +267,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6commonv() - ret void -} - ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z7common2v() local_unnamed_addr { entry: @@ -244,37 +287,12 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z7common2v() - ret void -} - -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6B_inclv() - call spir_func void @_Z6A_exclv() - ret void -} - ; Function Attrs: nofree norecurse nosync nounwind readnone willreturn mustprogress define dso_local spir_func void @_Z6E_exclv() local_unnamed_addr { entry: ret void } -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6E_exclv() - call spir_func void @_Z6E_exclv() - ret void -} - ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6F_inclv() local_unnamed_addr { entry: @@ -282,15 +300,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6F_inclv() - call spir_func void @_Z6F_inclv() - ret void -} - ; Function Attrs: convergent inlinehint norecurse nounwind mustprogress define internal spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_2idILi1EEEE6_clES5_"() unnamed_addr align 2 { entry: @@ -327,14 +336,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 { - call spir_func void @_Z1Gv() - call spir_func void @_Z1Hv() - ret void -} - ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll index 1ed6ac4d98e7f..a889c528ce41c 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll @@ -3,7 +3,7 @@ ; in their call graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZ4mainE11TU0_kernel1 +; RUN: FileCheck %s -input-file=%t_0.prop target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -18,7 +18,14 @@ target triple = "spir64-unknown-linux" ; CHECK: [SYCL/assert used] -; CHECK-DAG: _ZTSZ4mainE11TU0_kernel0 +; CHECK: _ZTSZ4mainE10TU1_kernel +define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { +entry: + call spir_func void @_Z4foo2v() + ret void +} + +; CHECK: _ZTSZ4mainE11TU0_kernel0 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() @@ -36,6 +43,7 @@ entry: ret void } +; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() @@ -50,13 +58,6 @@ entry: ret void } -; CHECK-DAG: _ZTSZ4mainE10TU1_kernel -define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { -entry: - call spir_func void @_Z4foo2v() - ret void -} - ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo2v() { entry: diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 255bd7a3f5ad4..3c47270e8acff 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -382,8 +382,12 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) { continue; for (const auto *U : F->users()) { - const Instruction *I = cast(U); - const Function *ParentF = I->getFunction(); + const CallInst *CI = dyn_cast(U); + if (!CI) + continue; + + const Function *ParentF = CI->getFunction(); + if (VisitedFunctions.count(ParentF)) continue; @@ -612,6 +616,7 @@ void saveModuleProperties(Module &M, const EntryPointGroup &ModuleEntryPoints, { std::vector FuncNames = getKernelNamesUsingAssert(M); + std::sort(FuncNames.begin(), FuncNames.end()); for (const StringRef &FName : FuncNames) PropSet[PropSetRegTy::SYCL_ASSERT_USED].insert({FName, true}); } From 8350b9c8373bddabbee0f6060a7692f717bed264 Mon Sep 17 00:00:00 2001 From: Maksim Sabianin Date: Mon, 27 Dec 2021 15:53:35 +0300 Subject: [PATCH 5/5] remove sorting of kernel's names --- .../assert-indirect-with-split-2.ll | 40 ++--- .../assert-indirect-with-split.ll | 8 +- .../tools/sycl-post-link/assert-property-1.ll | 25 +-- .../tools/sycl-post-link/assert-property-2.ll | 147 +++++++++--------- .../assert-property-with-split.ll | 23 +-- llvm/tools/sycl-post-link/sycl-post-link.cpp | 1 - 6 files changed, 123 insertions(+), 121 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll index b32a51707da7b..7630225833157 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll @@ -9,7 +9,8 @@ ; marked as using asserts. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -22,7 +23,15 @@ target triple = "spir64-unknown-linux" @__spirv_BuiltInLocalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32 @_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1 -; CHECK: [SYCL/assert used] +; PRESENCE-CHECK: [SYCL/assert used] + +; PRESENCE-CHECK-DAG: main_TU1_kernel1 +define dso_local spir_kernel void @main_TU1_kernel1() #2 { +entry: + call spir_func void @foo() + call spir_func void @bar() + ret void +} define dso_local spir_func void @foo() #2 { entry: @@ -30,7 +39,7 @@ entry: ret void } -; CHECK-NOT: empty_kernel +; ABSENCE-CHECK-NOT: empty_kernel define dso_local spir_kernel void @empty_kernel() { %1 = ptrtoint void ()* @bar to i64 ret void @@ -43,14 +52,13 @@ entry: ret void } -; CHECK: main_TU0_kernel0 +; PRESENCE-CHECK-DAG: main_TU0_kernel0 define dso_local spir_kernel void @main_TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() ; call assert ret void } - define dso_local spir_func void @_Z3foov() { entry: %a = alloca i32, align 4 @@ -62,13 +70,6 @@ entry: ret void } -; CHECK-NOT: main_TU0_kernel1 -define dso_local spir_kernel void @main_TU0_kernel1() #0 { -entry: - call spir_func void @_Z4foo1v() - ret void -} - ; Function Attrs: nounwind define dso_local spir_func void @_Z4foo1v() { entry: @@ -77,13 +78,19 @@ entry: ret void } -; CHECK: main_TU1_kernel0 +; PRESENCE-CHECK-DAG: main_TU1_kernel0 define dso_local spir_kernel void @main_TU1_kernel0() #2 { entry: call spir_func void @_Z3foov() ; call assert ret void } +; ABSENCE-CHECK-NOT: main_TU0_kernel1 +define dso_local spir_kernel void @main_TU0_kernel1() #0 { +entry: + call spir_func void @_Z4foo1v() + ret void +} ; This function is marked with "referenced-indirectly", but it doesn't call an assert ; Function Attrs: nounwind @@ -96,13 +103,6 @@ entry: ret void } -; CHECK: main_TU1_kernel1 -define dso_local spir_kernel void @main_TU1_kernel1() #2 { -entry: - call spir_func void @foo() - call spir_func void @bar() - ret void -} ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { diff --git a/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll b/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll index c1a8481dcc9ba..48c0983b3abde 100644 --- a/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-indirect-with-split.ll @@ -22,7 +22,7 @@ target triple = "spir64-unknown-linux" ; CHECK: [SYCL/assert used] -; CHECK: main_TU0_kernel0 +; CHECK-DAG: main_TU0_kernel0 define dso_local spir_kernel void @main_TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() @@ -40,7 +40,7 @@ entry: ret void } -; CHECK: main_TU0_kernel1 +; CHECK-DAG: main_TU0_kernel1 define dso_local spir_kernel void @main_TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() @@ -55,14 +55,14 @@ entry: ret void } -; CHECK: main_TU1_kernel0 +; CHECK-DAG: main_TU1_kernel0 define dso_local spir_kernel void @main_TU1_kernel0() #2 { entry: call spir_func void @_Z3foov() ret void } -; CHECK: main_TU1_kernel1 +; CHECK-DAG: main_TU1_kernel1 define dso_local spir_kernel void @main_TU1_kernel1() #2 { entry: call spir_func void @_Z4foo2v() diff --git a/llvm/test/tools/sycl-post-link/assert-property-1.ll b/llvm/test/tools/sycl-post-link/assert-property-1.ll index 774252bad2a18..7a7a0024363f4 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-1.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-1.ll @@ -3,7 +3,8 @@ ; graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK ; SYCL source: ; void foo() { @@ -48,7 +49,7 @@ target triple = "spir64_x86_64-unknown-unknown" @__spirv_BuiltInLocalInvocationId = external dso_local addrspace(1) constant <3 x i64>, align 32 @_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1 -; CHECK: [SYCL/assert used] +; PRESENCE-CHECK: [SYCL/assert used] ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z3foov() { @@ -57,15 +58,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3 -; Function Attrs: convergent norecurse -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3"() #0 { -entry: - call spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_4itemILi2ELb1EEEE1_clES5_"() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel ; Function Attrs: convergent norecurse define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE9TheKernel"() #0 { entry: @@ -79,7 +72,7 @@ entry: ret void } -; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2 +; ABSENCE-CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2 ; Function Attrs: norecurse define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel2"() #1 { entry: @@ -102,6 +95,14 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3 +; Function Attrs: convergent norecurse +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE10TheKernel3"() #0 { +entry: + call spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_4itemILi2ELb1EEEE1_clES5_"() + ret void +} + ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-2.ll b/llvm/test/tools/sycl-post-link/assert-property-2.ll index fb3279a5154e4..22c7bbc837746 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-2.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-2.ll @@ -3,7 +3,8 @@ ; graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK ; SYCL source: ; void assert_func() { @@ -105,7 +106,7 @@ target triple = "spir64_x86_64-unknown-unknown" @__PRETTY_FUNCTION__._Z11assert_funcv = private unnamed_addr addrspace(1) constant [19 x i8] c"void assert_func()\00", align 1 @_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1 -; CHECK: [SYCL/assert used] +; PRESENCE-CHECK: [SYCL/assert used] ; Function Attrs: convergent noinline norecurse optnone mustprogress define dso_local spir_func void @_Z1Jv() #3 { @@ -122,76 +123,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6A_exclv() - call spir_func void @_Z6B_inclv() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6A_inclv() - call spir_func void @_Z6B_exclv() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6commonv() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z7common2v() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6B_inclv() - call spir_func void @_Z6A_exclv() - ret void -} - -; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6E_exclv() - call spir_func void @_Z6E_exclv() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 { -entry: - call spir_func void @_Z6F_inclv() - call spir_func void @_Z6F_inclv() - ret void -} - -; CHECK: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 -; Function Attrs: convergent norecurse mustprogress -define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 { - call spir_func void @_Z1Gv() - call spir_func void @_Z1Hv() - ret void -} - -; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9 ; Function Attrs: convergent noinline norecurse mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E7Kernel9() #0 { entry: @@ -199,7 +131,7 @@ entry: ret void } -; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10 ; Function Attrs: convergent noinline norecurse optnone mustprogress define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10() #0 { entry: @@ -233,6 +165,15 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE6Kernel"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6A_exclv() + call spir_func void @_Z6B_inclv() + ret void +} + ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6A_inclv() local_unnamed_addr { entry: @@ -246,6 +187,15 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel2"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6A_inclv() + call spir_func void @_Z6B_exclv() + ret void +} + ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z6commonv() local_unnamed_addr { entry: @@ -267,6 +217,14 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel3"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6commonv() + ret void +} + ; Function Attrs: convergent norecurse nounwind mustprogress define dso_local spir_func void @_Z7common2v() local_unnamed_addr { entry: @@ -287,6 +245,23 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel4"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z7common2v() + ret void +} + +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel5"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6B_inclv() + call spir_func void @_Z6A_exclv() + ret void +} + ; Function Attrs: nofree norecurse nosync nounwind readnone willreturn mustprogress define dso_local spir_func void @_Z6E_exclv() local_unnamed_addr { entry: @@ -300,6 +275,15 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel7"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6F_inclv() + call spir_func void @_Z6F_inclv() + ret void +} + ; Function Attrs: convergent inlinehint norecurse nounwind mustprogress define internal spir_func void @"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_2idILi1EEEE6_clES5_"() unnamed_addr align 2 { entry: @@ -336,6 +320,23 @@ entry: ret void } +; PRESENCE-CHECK-DAG: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 { + call spir_func void @_Z1Gv() + call spir_func void @_Z1Hv() + ret void +} + +; ABSENCE-CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6 +; Function Attrs: convergent norecurse mustprogress +define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 { +entry: + call spir_func void @_Z6E_exclv() + call spir_func void @_Z6E_exclv() + ret void +} + ; Function Attrs: convergent norecurse mustprogress define weak dso_local spir_func void @__assert_fail(i8 addrspace(4)* %expr, i8 addrspace(4)* %file, i32 %line, i8 addrspace(4)* %func) local_unnamed_addr { entry: diff --git a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll index a889c528ce41c..3209f03a56ab1 100644 --- a/llvm/test/tools/sycl-post-link/assert-property-with-split.ll +++ b/llvm/test/tools/sycl-post-link/assert-property-with-split.ll @@ -3,7 +3,8 @@ ; in their call graph. ; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table -; RUN: FileCheck %s -input-file=%t_0.prop +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=PRESENCE-CHECK +; RUN: FileCheck %s -input-file=%t_0.prop -check-prefix=ABSENCE-CHECK target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" @@ -16,16 +17,9 @@ target triple = "spir64-unknown-linux" @__spirv_BuiltInLocalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32 @_ZL10assert_fmt = internal addrspace(2) constant [85 x i8] c"%s:%d: %s: global id: [%lu,%lu,%lu], local id: [%lu,%lu,%lu] Assertion `%s` failed.\0A\00", align 1 -; CHECK: [SYCL/assert used] +; PRESENCE-CHECK: [SYCL/assert used] -; CHECK: _ZTSZ4mainE10TU1_kernel -define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { -entry: - call spir_func void @_Z4foo2v() - ret void -} - -; CHECK: _ZTSZ4mainE11TU0_kernel0 +; PRESENCE-CHECK-DAG: _ZTSZ4mainE11TU0_kernel0 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel0() #0 { entry: call spir_func void @_Z3foov() @@ -43,7 +37,14 @@ entry: ret void } -; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1 +; PRESENCE-CHECK-DAG: _ZTSZ4mainE10TU1_kernel +define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 { +entry: + call spir_func void @_Z4foo2v() + ret void +} + +; ABSENCE-CHECK-NOT: _ZTSZ4mainE11TU0_kernel1 define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 { entry: call spir_func void @_Z4foo1v() diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 3c47270e8acff..7b7cfd455bdff 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -616,7 +616,6 @@ void saveModuleProperties(Module &M, const EntryPointGroup &ModuleEntryPoints, { std::vector FuncNames = getKernelNamesUsingAssert(M); - std::sort(FuncNames.begin(), FuncNames.end()); for (const StringRef &FName : FuncNames) PropSet[PropSetRegTy::SYCL_ASSERT_USED].insert({FName, true}); }