Skip to content

Commit 6d8d9c5

Browse files
tuStromaigcbot
authored andcommitted
Prevent infinite indirect recursion while finding calling kernels
Vector stores visited functions to prevent infinite findCallingKernels() call over the same functions
1 parent 9ea4103 commit 6d8d9c5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

IGC/Compiler/CodeGenContext.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,19 @@ namespace IGC
629629
return MD->functionType == KernelFunction;
630630
}
631631

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)
634636
{
635637
if (F == nullptr || kernels.count(F))
636638
return;
637639

640+
// Check if function was already visited during search
641+
if (visited.find(F) != visited.end())
642+
return;
643+
visited.insert(F);
644+
638645
for (const llvm::User *U : F->users()) {
639646
auto *CI = llvm::dyn_cast<llvm::CallInst>(U);
640647
if (CI == nullptr)
@@ -650,8 +657,7 @@ namespace IGC
650657
}
651658
// Caller is not a kernel, try to check which kerneles might
652659
// be calling it:
653-
if (F != caller)
654-
findCallingKernels(ctx, caller, kernels);
660+
findCallingKernels(ctx, caller, kernels, visited);
655661
}
656662
}
657663

@@ -742,7 +748,8 @@ namespace IGC
742748
// might be using this function.
743749
} else {
744750
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);
746753

747754
const size_t kernelsCount = kernels.size();
748755
OS << "\nin function: '" << demangleFuncName(std::string(F->getName())) << "' ";

0 commit comments

Comments
 (0)