Skip to content

Commit 1930304

Browse files
committed
Re-work call graph traversal
1 parent 2b78412 commit 1930304

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,56 @@ static void collectKernelModuleMap(
273273

274274
// Go through function call graph searching for assert call.
275275
static bool hasAssertInFunctionCallGraph(llvm::Function *Func) {
276+
// Map holds the info about assertions in already examined functions:
277+
// true - if there is an assertion in underlying functions,
278+
// false - if there are definetely no assertions in underlying functions.
279+
static std::map<llvm::Function *, bool> hasAssertionInCallGraphMap;
280+
std::vector<llvm::Function *> FuncList;
281+
276282
std::vector<llvm::Function *> Workqueue;
277283
Workqueue.push_back(Func);
278284

279285
while (!Workqueue.empty()) {
280286
Function *F = Workqueue.back();
281287
Workqueue.pop_back();
288+
if (F != Func)
289+
FuncList.push_back(F);
290+
291+
bool IsVertex = true;
282292
for (auto &I : instructions(F)) {
283293
if (CallBase *CB = dyn_cast<CallBase>(&I))
284294
if (Function *CF = CB->getCalledFunction()) {
285-
if (CF->getName().startswith("__devicelib_assert_fail"))
295+
// Return if we've already discovered if there are asserts in the
296+
// function call graph.
297+
if (hasAssertionInCallGraphMap.count(CF)) {
298+
return hasAssertionInCallGraphMap[CF];
299+
}
300+
301+
if (CF->getName().startswith("__devicelib_assert_fail")) {
302+
// Mark all the functions above in call graph as ones that can call
303+
// assert.
304+
for (auto *It : FuncList)
305+
hasAssertionInCallGraphMap[It] = true;
306+
307+
hasAssertionInCallGraphMap[Func] = true;
308+
hasAssertionInCallGraphMap[CF] = true;
309+
286310
return true;
287-
if (!CF->isDeclaration())
311+
}
312+
313+
if (!CF->isDeclaration()) {
288314
Workqueue.push_back(CF);
315+
IsVertex = false;
316+
}
289317
}
290318
}
319+
320+
if (IsVertex) {
321+
// Mark the above functions as ones that definetely do not call assert.
322+
for (auto *It : FuncList)
323+
hasAssertionInCallGraphMap[It] = false;
324+
FuncList.clear();
325+
}
291326
}
292327
return false;
293328
}

0 commit comments

Comments
 (0)