@@ -629,12 +629,19 @@ namespace IGC
629
629
return MD->functionType == KernelFunction;
630
630
}
631
631
632
- static void findCallingKernels
633
- (const CodeGenContext *ctx, const llvm::Function *F, llvm::SmallPtrSetImpl<const llvm::Function *> &kernels)
632
+ static void findCallingKernels ( const CodeGenContext *ctx,
633
+ const llvm::Function *F,
634
+ llvm::SmallPtrSetImpl<const llvm::Function *> &kernels,
635
+ SmallPtrSet<const llvm::Function*, 32 >& visited)
634
636
{
635
637
if (F == nullptr || kernels.count (F))
636
638
return ;
637
639
640
+ // Check if function was already visited during search
641
+ if (visited.find (F) != visited.end ())
642
+ return ;
643
+ visited.insert (F);
644
+
638
645
for (const llvm::User *U : F->users ()) {
639
646
auto *CI = llvm::dyn_cast<llvm::CallInst>(U);
640
647
if (CI == nullptr )
@@ -650,8 +657,7 @@ namespace IGC
650
657
}
651
658
// Caller is not a kernel, try to check which kerneles might
652
659
// be calling it:
653
- if (F != caller)
654
- findCallingKernels (ctx, caller, kernels);
660
+ findCallingKernels (ctx, caller, kernels, visited);
655
661
}
656
662
}
657
663
@@ -742,7 +748,8 @@ namespace IGC
742
748
// might be using this function.
743
749
} else {
744
750
llvm::SmallPtrSet<const llvm::Function *, 16 > kernels;
745
- findCallingKernels (this , F, kernels);
751
+ llvm::SmallPtrSet<const llvm::Function*, 32 > visited;
752
+ findCallingKernels (this , F, kernels, visited);
746
753
747
754
const size_t kernelsCount = kernels.size ();
748
755
OS << " \n in function: '" << demangleFuncName (std::string (F->getName ())) << " ' " ;
0 commit comments