Skip to content

Commit 7d4b973

Browse files
committed
fix review remarks
1 parent 747e14d commit 7d4b973

File tree

4 files changed

+49
-62
lines changed

4 files changed

+49
-62
lines changed

llvm/test/tools/sycl-post-link/assert-indirect-with-split-2.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
; marked as using asserts.
1010

1111
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
12-
; RUN: FileCheck %s -input-file=%t_0.prop
12+
; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not main_TU0_kernel1
1313

1414
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
1515
target triple = "spir64-unknown-linux"
@@ -63,6 +63,12 @@ entry:
6363
ret void
6464
}
6565

66+
define dso_local spir_kernel void @main_TU0_kernel1() #0 {
67+
entry:
68+
call spir_func void @_Z4foo1v()
69+
ret void
70+
}
71+
6672
; Function Attrs: nounwind
6773
define dso_local spir_func void @_Z4foo1v() {
6874
entry:
@@ -78,13 +84,6 @@ entry:
7884
ret void
7985
}
8086

81-
; CHECK-NOT: main_TU0_kernel1
82-
define dso_local spir_kernel void @main_TU0_kernel1() #0 {
83-
entry:
84-
call spir_func void @_Z4foo1v()
85-
ret void
86-
}
87-
8887

8988
; This function is marked with "referenced-indirectly", but it doesn't call an assert
9089
; Function Attrs: nounwind

llvm/test/tools/sycl-post-link/assert-property-2.ll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; graph.
44

55
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
6-
; RUN: FileCheck %s -input-file=%t_0.prop
6+
; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6
77

88
; SYCL source:
99
; void assert_func() {
@@ -267,6 +267,14 @@ entry:
267267
ret void
268268
}
269269

270+
; Function Attrs: convergent norecurse mustprogress
271+
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 {
272+
entry:
273+
call spir_func void @_Z6E_exclv()
274+
call spir_func void @_Z6E_exclv()
275+
ret void
276+
}
277+
270278
; Function Attrs: convergent norecurse nounwind mustprogress
271279
define dso_local spir_func void @_Z6F_inclv() local_unnamed_addr {
272280
entry:
@@ -327,15 +335,6 @@ define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7han
327335
ret void
328336
}
329337

330-
; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6
331-
; Function Attrs: convergent norecurse mustprogress
332-
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6"() local_unnamed_addr #0 {
333-
entry:
334-
call spir_func void @_Z6E_exclv()
335-
call spir_func void @_Z6E_exclv()
336-
ret void
337-
}
338-
339338
; Function Attrs: convergent norecurse mustprogress
340339
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 {
341340
entry:

llvm/test/tools/sycl-post-link/assert-property-with-split.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; in their call graph.
44

55
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.table
6-
; RUN: FileCheck %s -input-file=%t_0.prop
6+
; RUN: FileCheck %s -input-file=%t_0.prop --implicit-check-not _ZTSZ4mainE11TU0_kernel1
77

88
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
99
target triple = "spir64-unknown-linux"
@@ -36,14 +36,6 @@ entry:
3636
ret void
3737
}
3838

39-
; CHECK-DAG: _ZTSZ4mainE10TU1_kernel
40-
define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 {
41-
entry:
42-
call spir_func void @_Z4foo2v()
43-
ret void
44-
}
45-
46-
; CHECK-NOT: _ZTSZ4mainE11TU0_kernel1
4739
define dso_local spir_kernel void @_ZTSZ4mainE11TU0_kernel1() #0 {
4840
entry:
4941
call spir_func void @_Z4foo1v()
@@ -58,6 +50,13 @@ entry:
5850
ret void
5951
}
6052

53+
; CHECK-DAG: _ZTSZ4mainE10TU1_kernel
54+
define dso_local spir_kernel void @_ZTSZ4mainE10TU1_kernel() #1 {
55+
entry:
56+
call spir_func void @_Z4foo2v()
57+
ret void
58+
}
59+
6160
; Function Attrs: nounwind
6261
define dso_local spir_func void @_Z4foo2v() {
6362
entry:

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ void groupEntryPoints(const Module &M, EntryPointGroupMap &EntryPointsGroups,
357357

358358
// This function traverses over reversed call graph by BFS algorithm.
359359
// It means that an edge links some function @func with functions
360-
// which contain call of function @func.It starts from
360+
// which contain call of function @func. It starts from
361361
// @StartingFunction and lifts up until it reach all reachable functions
362362
// or it reaches some function containing "referenced-indirectly" attribute.
363-
// If it reaches "referenced-indirectly" attribute than it returns true and
364-
// an empty list.
365-
// Otherwise, it returns false and a list of reached SPIR kernel function's
366-
// names.
367-
std::pair<bool, std::vector<StringRef>>
363+
// If it reaches "referenced-indirectly" attribute than it returns an empty
364+
// Optional.
365+
// Otherwise, it returns an Optional containing a list of reached
366+
// SPIR kernel function's names.
367+
Optional<std::vector<StringRef>>
368368
TraverseCGToFindSPIRKernels(const Function *StartingFunction) {
369369
std::queue<const Function *> FunctionsToVisit;
370370
std::unordered_set<const Function *> VisitedFunctions;
@@ -375,21 +375,20 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) {
375375
const Function *F = FunctionsToVisit.front();
376376
FunctionsToVisit.pop();
377377

378+
auto InsertionResult = VisitedFunctions.insert(F);
378379
// It is possible that we insert some particular function several
379380
// times in functionsToVisit queue.
380-
if (VisitedFunctions.find(F) != VisitedFunctions.end())
381+
if (!InsertionResult.second)
381382
continue;
382383

383-
VisitedFunctions.insert(F);
384-
385384
for (const auto *U : F->users()) {
386385
const Instruction *I = cast<const Instruction>(U);
387386
const Function *ParentF = I->getFunction();
388-
if (VisitedFunctions.find(ParentF) != VisitedFunctions.end())
387+
if (VisitedFunctions.count(ParentF))
389388
continue;
390389

391390
if (ParentF->hasFnAttribute("referenced-indirectly")) {
392-
return {true, {}};
391+
return {};
393392
}
394393

395394
if (ParentF->getCallingConv() == CallingConv::SPIR_KERNEL)
@@ -399,39 +398,30 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) {
399398
}
400399
}
401400

402-
return {false, std::move(KernelNames)};
401+
return std::move(KernelNames);
403402
}
404403

405404
std::vector<StringRef> getKernelNamesUsingAssert(const Module &M) {
406-
Optional<const Function *> DevicelibAssertFailFunction;
407-
std::vector<StringRef> SPIRKernelNames;
408-
// This loop finds all SPIR kernel's names and __devicelib_assert_fail
409-
// function if it is present.
410-
for (const Function &F : M) {
411-
if (F.getCallingConv() == CallingConv::SPIR_KERNEL)
412-
SPIRKernelNames.push_back(F.getName());
413-
414-
if (F.getName().startswith("__devicelib_assert_fail")) {
415-
assert(!DevicelibAssertFailFunction.hasValue());
416-
DevicelibAssertFailFunction = &F;
417-
}
418-
}
419-
405+
auto DevicelibAssertFailFunction = M.getFunction("__devicelib_assert_fail");
420406
if (!DevicelibAssertFailFunction)
421407
return {};
422408

423409
auto TraverseResult =
424-
TraverseCGToFindSPIRKernels(*DevicelibAssertFailFunction);
425-
std::vector<StringRef> Result;
426-
if (TraverseResult.first) {
427-
// If assert is met in some indirectly callable function than
428-
// we return all kernels in Module due to the current assert's design.
429-
Result = std::move(SPIRKernelNames);
430-
} else {
431-
Result = std::move(TraverseResult.second);
410+
TraverseCGToFindSPIRKernels(DevicelibAssertFailFunction);
411+
412+
if (TraverseResult.hasValue()) {
413+
return std::move(*TraverseResult);
414+
}
415+
416+
// Here we reached "referenced-indirectly", so we need to find all kernels and
417+
// return them.
418+
std::vector<StringRef> SPIRKernelNames;
419+
for (const Function &F : M) {
420+
if (F.getCallingConv() == CallingConv::SPIR_KERNEL)
421+
SPIRKernelNames.push_back(F.getName());
432422
}
433423

434-
return Result;
424+
return SPIRKernelNames;
435425
}
436426

437427
// Gets reqd_work_group_size information for function Func.

0 commit comments

Comments
 (0)