44
44
#include " llvm/Transforms/Scalar.h"
45
45
#include " llvm/Transforms/Utils/Cloning.h"
46
46
47
+ #include < algorithm>
47
48
#include < memory>
48
49
49
50
using namespace llvm ;
@@ -297,7 +298,8 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
297
298
// false - if there are definetely no assertions in underlying functions.
298
299
static std::map<llvm::Function *, bool > hasAssertionInCallGraphMap;
299
300
std::vector<llvm::Function *> FuncCallStack;
300
- bool HasIndirectlyCalledAssert = false ;
301
+
302
+ static std::vector<llvm::Function *> isIndirectlyCalledInGraph;
301
303
302
304
std::vector<llvm::Function *> Workstack;
303
305
Workstack.push_back (Func);
@@ -308,9 +310,11 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
308
310
if (F != Func)
309
311
FuncCallStack.push_back (F);
310
312
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
+ }
314
318
315
319
bool IsLeaf = true ;
316
320
for (auto &I : instructions (F)) {
@@ -321,6 +325,12 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
321
325
if (!CF)
322
326
continue ;
323
327
328
+ bool IsIndirectlyCalled =
329
+ HasIndirectlyCalledAttr ||
330
+ std::find (isIndirectlyCalledInGraph.begin (),
331
+ isIndirectlyCalledInGraph.end (),
332
+ CF) != isIndirectlyCalledInGraph.end ();
333
+
324
334
// Return if we've already discovered if there are asserts in the
325
335
// function call graph.
326
336
auto HasAssert = hasAssertionInCallGraphMap.find (CF);
@@ -330,8 +340,7 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
330
340
if (!HasAssert->second )
331
341
continue ;
332
342
333
- return HasIndirectlyCalledAssert ? Assert_Indirect : Assert;
334
- ;
343
+ return IsIndirectlyCalled ? Assert_Indirect : Assert;
335
344
}
336
345
337
346
if (CF->getName ().startswith (" __devicelib_assert_fail" )) {
@@ -343,12 +352,14 @@ static HasAssertStatus hasAssertInFunctionCallGraph(llvm::Function *Func) {
343
352
hasAssertionInCallGraphMap[Func] = true ;
344
353
hasAssertionInCallGraphMap[CF] = true ;
345
354
346
- return HasIndirectlyCalledAssert ? Assert_Indirect : Assert;
355
+ return IsIndirectlyCalled ? Assert_Indirect : Assert;
347
356
}
348
357
349
358
if (!CF->isDeclaration ()) {
350
359
Workstack.push_back (CF);
351
360
IsLeaf = false ;
361
+ if (HasIndirectlyCalledAttr)
362
+ isIndirectlyCalledInGraph.push_back (CF);
352
363
}
353
364
}
354
365
@@ -560,23 +571,24 @@ static string_vector saveDeviceImageProperty(
560
571
for (auto &F : M->functions ()) {
561
572
// TODO: handle SYCL_EXTERNAL functions for dynamic linkage.
562
573
// 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 ;
580
592
}
581
593
}
582
594
0 commit comments