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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 09:26:03 PDT 2024


================
@@ -91,13 +91,66 @@ MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
   return OutContext.getOrCreateSymbol("amdgpu.max_num_sgpr");
 }
 
+static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr,
+                             SmallVectorImpl<const MCExpr *> &Exprs) {
+  switch (Expr->getKind()) {
+  default:
+    return false;
+  case MCExpr::ExprKind::SymbolRef: {
+    const MCSymbolRefExpr *SymRefExpr = cast<MCSymbolRefExpr>(Expr);
+    const MCSymbol &SymRef = SymRefExpr->getSymbol();
+    if (Sym == &SymRef)
+      return true;
+    if (SymRef.isVariable())
+      Exprs.push_back(SymRef.getVariableValue(/*isUsed=*/false));
+    return false;
+  }
+  case MCExpr::ExprKind::Binary: {
+    const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
+    return findSymbolInExpr(Sym, BExpr->getLHS(), Exprs) ||
+           findSymbolInExpr(Sym, BExpr->getRHS(), Exprs);
----------------
arsenm wrote:

You have the worklist, but aren't using it to avoid the recursive call? Couldn't this also add duplicate entries? 

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


More information about the llvm-commits mailing list