[llvm] [AMDGPU] Avoid resource propagation for recursion through multiple functions (PR #111004)
Janek van Oirschot via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 05:23:40 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);
----------------
JanekvO wrote:
I assume the `getConstantAccess` example walks over an already completed expression. My approach here is more preventative in terms of recursion so no recursion should exist, at all. I've added a Visited set but more so to ensure the invariant of no recursion to be upheld + added more comments that hopefully explain that this walk is to avoid recursion rather than detect and remove recursion.
https://github.com/llvm/llvm-project/pull/111004
More information about the llvm-commits
mailing list