Skip to content

[sycl-post-link] Fix call graph traversal for assert property generation #3998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions llvm/test/tools/sycl-post-link/assert-property-2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,26 @@
; void G() { common3(); }
; void H() { common3(); }
;
; void no_assert_func() {
; return;
; }
; void common4() {
; assert_func();
; no_assert_func();
; }
; void J() {
; common4();
; }
;
; int main() {
; queue Q;
; Q.submit([&] (handler& CGH) {
; CGH.parallel_for<class Kernel9>(range<1>{1}, [=](id<1> i) {
; J();
; });
; CGH.parallel_for<class Kernel10>(range<1>{1}, [=](id<1> i) {
; common4();
; });
; CGH.parallel_for<class Kernel>(range<1>{1}, [=](id<1> i) {
; A_excl();
; B_incl();
Expand Down Expand Up @@ -90,6 +107,43 @@ target triple = "spir64_x86_64-unknown-unknown-sycldevice"

; CHECK: [SYCL/assert used]

; Function Attrs: convergent noinline norecurse optnone mustprogress
define dso_local spir_func void @_Z1Jv() #3 {
entry:
call spir_func void @_Z7common4v()
ret void
}

; Function Attrs: convergent noinline norecurse optnone mustprogress
define dso_local spir_func void @_Z7common4v() #3 {
entry:
call spir_func void @_Z11assert_funcv()
call spir_func void @_Z14no_assert_funcv()
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:
call spir_func void @_Z1Jv()
ret void
}

; CHECK: _ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10
; Function Attrs: convergent noinline norecurse optnone mustprogress
define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN2cl4sycl7handlerEE_clES2_E8Kernel10() #0 {
entry:
call spir_func void @_Z7common4v()
ret void
}

; Function Attrs: convergent noinline norecurse nounwind optnone mustprogress
define dso_local spir_func void @_Z14no_assert_funcv() #2 {
entry:
ret void
}

; Function Attrs: convergent norecurse nounwind mustprogress
define dso_local spir_func void @_Z6B_inclv() local_unnamed_addr {
entry:
Expand Down
12 changes: 6 additions & 6 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ static bool hasAssertInFunctionCallGraph(llvm::Function *Func) {

// Return if we've already discovered if there are asserts in the
// function call graph.
if (hasAssertionInCallGraphMap.count(CF)) {
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 (!hasAssertionInCallGraphMap[CF])
if (!HasAssert->second)
continue;

return true;
Expand All @@ -343,10 +344,9 @@ static bool hasAssertInFunctionCallGraph(llvm::Function *Func) {
}
}

if (IsLeaf) {
// Mark the above functions as ones that definetely do not call assert.
for (auto *It : FuncCallStack)
hasAssertionInCallGraphMap[It] = false;
if (IsLeaf && !FuncCallStack.empty()) {
// Mark the leaf function as one that definetely does not call assert.
hasAssertionInCallGraphMap[FuncCallStack.back()] = false;
FuncCallStack.clear();
}
}
Expand Down