[llvm] Reapply [AMDGPU] Avoid resource propagation for recursion through multiple functions (PR #112251)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 09:56:36 PDT 2024


================
@@ -163,23 +139,31 @@ void MCResourceInfo::assignResourceInfoExpr(
   MCSymbol *Sym = getSymbol(MF.getName(), RIK, OutContext);
   if (!Callees.empty()) {
     SmallVector<const MCExpr *, 8> ArgExprs;
-    // Avoid recursive symbol assignment.
     SmallPtrSet<const Function *, 8> Seen;
     ArgExprs.push_back(LocalConstExpr);
-    const Function &F = MF.getFunction();
-    Seen.insert(&F);
 
     for (const Function *Callee : Callees) {
       if (!Seen.insert(Callee).second)
         continue;
+
+      SmallPtrSet<const MCExpr *, 8> WorkSet;
       MCSymbol *CalleeValSym = getSymbol(Callee->getName(), RIK, OutContext);
-      bool CalleeIsVar = CalleeValSym->isVariable();
-      if (!CalleeIsVar ||
-          (CalleeIsVar &&
-           !foundRecursiveSymbolDef(
-               Sym, CalleeValSym->getVariableValue(/*IsUsed=*/false)))) {
+      if (CalleeValSym->isVariable())
+        WorkSet.insert(CalleeValSym->getVariableValue(/*IsUsed=*/false));
+      else
         ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
+
+      bool FoundRecursion = false;
+      while (!WorkSet.empty() && !FoundRecursion) {
+        auto It = WorkSet.begin();
+        const MCExpr *Expr = *It;
+        WorkSet.erase(Expr);
+
+        FoundRecursion = findSymbolInExpr(Sym, Expr, WorkSet);
----------------
arsenm wrote:

Looking explicitly for recursion as a case to handle still does not make sense to me. I expect a recursive visitor function that handles the recursive naturally, without trying to treat it as a special case. Have the function return null if it isn't resolvable? 

https://github.com/llvm/llvm-project/pull/112251


More information about the llvm-commits mailing list