Skip to content

Commit 7602d81

Browse files
dlei6gigcbot
authored andcommitted
Fixed stack call implicit arg mismatch between caller/callee.
We are asserting in AddImplicitArgs pass due to the caller and callee not having the same set of implicit args. Since stack calls do not inherently support implicit args, we inline them in BuiltinCallGraphAnalysis pass. However, we still need to add implicit args to their function signature in order for the Resolve passes to work before the inlining occurs. The following two changes are needed to fix the mismatch: 1. BuiltinCallGraphAnalysis itself will change the implicit arg metadata, so we need to move the callgraph pruning function, which inlines stack functions that use implicit args, to the end of the pass, where it will not get affected by the rest of the pass. 2. We cannot remove the "visaStackCall" attribute inside the pruning loop, otherwise another search path in the DFS will miss it. Instead, save all pruned functions and process them outside the loop.
1 parent b0596c5 commit 7602d81

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

IGC/AdaptorCommon/AddImplicitArgs.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,6 @@ bool BuiltinCallGraphAnalysis::runOnModule(Module &M)
519519
m_pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
520520
CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph();
521521

522-
// Detect stack calls that use implicit args, and force inline them, since they are not supported
523-
if (IGC_IS_FLAG_ENABLED(ForceInlineStackCallWithImplArg))
524-
{
525-
pruneCallGraphForStackCalls(CG);
526-
}
527-
528522
if (IGC_GET_FLAG_VALUE(FunctionControl) == FLAG_FCALL_FORCE_INLINE)
529523
{
530524
return false;
@@ -537,6 +531,12 @@ bool BuiltinCallGraphAnalysis::runOnModule(Module &M)
537531
traveseCallGraphSCC(SCCNodes);
538532
}
539533

534+
// Detect stack calls that use implicit args, and force inline them, since they are not supported
535+
if (IGC_IS_FLAG_ENABLED(ForceInlineStackCallWithImplArg))
536+
{
537+
pruneCallGraphForStackCalls(CG);
538+
}
539+
540540
return false;
541541
}
542542

@@ -545,6 +545,7 @@ bool BuiltinCallGraphAnalysis::runOnModule(Module &M)
545545
bool BuiltinCallGraphAnalysis::pruneCallGraphForStackCalls(CallGraph& CG)
546546
{
547547
bool changed = false;
548+
llvm::SmallSet<Function*, 16> PrunedFuncs;
548549
for (auto IT = df_begin(&CG), EI = df_end(&CG); IT != EI; IT++)
549550
{
550551
Function* F = IT->getFunction();
@@ -556,22 +557,26 @@ bool BuiltinCallGraphAnalysis::pruneCallGraphForStackCalls(CallGraph& CG)
556557
for (unsigned i = 0; i < IT.getPathLength(); i++)
557558
{
558559
Function* pFuncOnPath = IT.getPath(i)->getFunction();
559-
if (pFuncOnPath && pFuncOnPath->hasFnAttribute("visaStackCall"))
560+
if (pFuncOnPath)
560561
{
561562
if (pFuncOnPath->hasFnAttribute("forceRecurse"))
562563
{
563564
IGC_ASSERT_MESSAGE(0, "Cannot inline for recursion!");
564565
return false;
565566
}
566-
pFuncOnPath->removeFnAttr("visaStackCall");
567-
pFuncOnPath->removeFnAttr(llvm::Attribute::NoInline);
568-
pFuncOnPath->addFnAttr(llvm::Attribute::AlwaysInline);
567+
PrunedFuncs.insert(pFuncOnPath);
569568
changed = true;
570569
}
571570
}
572571
}
573572
}
574573
}
574+
for (auto pF : PrunedFuncs)
575+
{
576+
pF->removeFnAttr("visaStackCall");
577+
pF->removeFnAttr(llvm::Attribute::NoInline);
578+
pF->addFnAttr(llvm::Attribute::AlwaysInline);
579+
}
575580
return changed;
576581
}
577582

0 commit comments

Comments
 (0)