Skip to content

Commit ffacf61

Browse files
committed
Fix handling
1 parent c961ef7 commit ffacf61

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

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

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Transforms/Scalar.h"
4545
#include "llvm/Transforms/Utils/Cloning.h"
4646

47+
#include <algorithm>
4748
#include <memory>
4849

4950
using namespace llvm;
@@ -297,7 +298,8 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
297298
// false - if there are definetely no assertions in underlying functions.
298299
static std::map<llvm::Function *, bool> hasAssertionInCallGraphMap;
299300
std::vector<llvm::Function *> FuncCallStack;
300-
bool HasIndirectlyCalledAssert = false;
301+
302+
static std::vector<llvm::Function *> isIndirectlyCalledInGraph;
301303

302304
std::vector<llvm::Function *> Workstack;
303305
Workstack.push_back(Func);
@@ -308,9 +310,11 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
308310
if (F != Func)
309311
FuncCallStack.push_back(F);
310312

311-
if (!HasIndirectlyCalledAssert &&
312-
F->hasFnAttribute("referenced-indirectly"))
313-
HasIndirectlyCalledAssert = true;
313+
bool HasIndirectlyCalledAttr = false;
314+
if (F->hasFnAttribute("referenced-indirectly")) {
315+
HasIndirectlyCalledAttr = true;
316+
isIndirectlyCalledInGraph.push_back(F);
317+
}
314318

315319
bool IsLeaf = true;
316320
for (auto &I : instructions(F)) {
@@ -321,6 +325,12 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
321325
if (!CF)
322326
continue;
323327

328+
bool IsIndirectlyCalled =
329+
HasIndirectlyCalledAttr ||
330+
std::find(isIndirectlyCalledInGraph.begin(),
331+
isIndirectlyCalledInGraph.end(),
332+
CF) != isIndirectlyCalledInGraph.end();
333+
324334
// Return if we've already discovered if there are asserts in the
325335
// function call graph.
326336
auto HasAssert = hasAssertionInCallGraphMap.find(CF);
@@ -330,8 +340,7 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
330340
if (!HasAssert->second)
331341
continue;
332342

333-
return HasIndirectlyCalledAssert ? Assert_Indirect : Assert;
334-
;
343+
return IsIndirectlyCalled ? Assert_Indirect : Assert;
335344
}
336345

337346
if (CF->getName().startswith("__devicelib_assert_fail")) {
@@ -343,12 +352,14 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
343352
hasAssertionInCallGraphMap[Func] = true;
344353
hasAssertionInCallGraphMap[CF] = true;
345354

346-
return HasIndirectlyCalledAssert ? Assert_Indirect : Assert;
355+
return IsIndirectlyCalled ? Assert_Indirect : Assert;
347356
}
348357

349358
if (!CF->isDeclaration()) {
350359
Workstack.push_back(CF);
351360
IsLeaf = false;
361+
if (HasIndirectlyCalledAttr)
362+
isIndirectlyCalledInGraph.push_back(CF);
352363
}
353364
}
354365

@@ -560,23 +571,24 @@ static string_vector saveDeviceImageProperty(
560571
for (auto &F : M->functions()) {
561572
// TODO: handle SYCL_EXTERNAL functions for dynamic linkage.
562573
// TODO: handle function pointers.
563-
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
564-
Kernels.push_back(&F);
565-
if (HasIndirectlyCalledAssert)
566-
continue;
567-
568-
HasAssertStatus HasAssert = hasAssertInFunctionCallGraph(&F);
569-
switch (HasAssert) {
570-
case Assert:
571-
PropSet[llvm::util::PropertySetRegistry::SYCL_ASSERT_USED].insert(
572-
{F.getName(), true});
573-
break;
574-
case Assert_Indirect:
575-
HasIndirectlyCalledAssert = true;
576-
break;
577-
case No_Assert:
578-
break;
579-
}
574+
if (F.getCallingConv() != CallingConv::SPIR_KERNEL)
575+
continue;
576+
577+
Kernels.push_back(&F);
578+
if (HasIndirectlyCalledAssert)
579+
continue;
580+
581+
HasAssertStatus HasAssert = hasAssertInFunctionCallGraph(&F);
582+
switch (HasAssert) {
583+
case Assert:
584+
PropSet[llvm::util::PropertySetRegistry::SYCL_ASSERT_USED].insert(
585+
{F.getName(), true});
586+
break;
587+
case Assert_Indirect:
588+
HasIndirectlyCalledAssert = true;
589+
break;
590+
case No_Assert:
591+
break;
580592
}
581593
}
582594

0 commit comments

Comments
 (0)