Skip to content

Commit edee7c9

Browse files
committed
apply suggestions
1 parent fe84701 commit edee7c9

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

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

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -277,51 +277,60 @@ static bool hasAssertInFunctionCallGraph(llvm::Function *Func) {
277277
// true - if there is an assertion in underlying functions,
278278
// false - if there are definetely no assertions in underlying functions.
279279
static std::map<llvm::Function *, bool> hasAssertionInCallGraphMap;
280-
std::vector<llvm::Function *> FuncList;
280+
std::vector<llvm::Function *> FuncCallStack;
281281

282-
std::vector<llvm::Function *> Workqueue;
283-
Workqueue.push_back(Func);
282+
std::vector<llvm::Function *> Workstack;
283+
Workstack.push_back(Func);
284284

285-
while (!Workqueue.empty()) {
286-
Function *F = Workqueue.back();
287-
Workqueue.pop_back();
285+
while (!Workstack.empty()) {
286+
Function *F = Workstack.back();
287+
Workstack.pop_back();
288288
if (F != Func)
289-
FuncList.push_back(F);
289+
FuncCallStack.push_back(F);
290290

291-
bool IsVertex = true;
291+
bool IsLeaf = true;
292292
for (auto &I : instructions(F)) {
293-
if (CallBase *CB = dyn_cast<CallBase>(&I))
294-
if (Function *CF = CB->getCalledFunction()) {
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-
}
293+
if (!isa<CallBase>(&I))
294+
continue;
295+
296+
Function *CF = cast<CallBase>(&I)->getCalledFunction();
297+
if (!CF)
298+
continue;
299+
300+
// Return if we've already discovered if there are asserts in the
301+
// function call graph.
302+
if (hasAssertionInCallGraphMap.count(CF)) {
303+
// If we know, that this function does not contain assert, we still
304+
// should investigate another instructions in the function.
305+
if (!hasAssertionInCallGraphMap[CF])
306+
continue;
307+
308+
return true;
309+
}
300310

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;
311+
if (CF->getName().startswith("__devicelib_assert_fail")) {
312+
// Mark all the functions above in call graph as ones that can call
313+
// assert.
314+
for (auto *It : FuncCallStack)
315+
hasAssertionInCallGraphMap[It] = true;
306316

307-
hasAssertionInCallGraphMap[Func] = true;
308-
hasAssertionInCallGraphMap[CF] = true;
317+
hasAssertionInCallGraphMap[Func] = true;
318+
hasAssertionInCallGraphMap[CF] = true;
309319

310-
return true;
311-
}
320+
return true;
321+
}
312322

313-
if (!CF->isDeclaration()) {
314-
Workqueue.push_back(CF);
315-
IsVertex = false;
316-
}
317-
}
323+
if (!CF->isDeclaration()) {
324+
Workstack.push_back(CF);
325+
IsLeaf = false;
326+
}
318327
}
319328

320-
if (IsVertex) {
329+
if (IsLeaf) {
321330
// Mark the above functions as ones that definetely do not call assert.
322-
for (auto *It : FuncList)
331+
for (auto *It : FuncCallStack)
323332
hasAssertionInCallGraphMap[It] = false;
324-
FuncList.clear();
333+
FuncCallStack.clear();
325334
}
326335
}
327336
return false;

0 commit comments

Comments
 (0)