[llvm] [AMDGPU] Avoid resource propagation for recursion through multiple functions (PR #111004)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 08:04:12 PDT 2024
================
@@ -91,8 +91,17 @@ MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
return OutContext.getOrCreateSymbol("amdgpu.max_num_sgpr");
}
+// The (partially complete) expression should have no recursion in it. After
+// all, we're trying to avoid recursion using this codepath.
static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr,
- SmallVectorImpl<const MCExpr *> &Exprs) {
+ SmallVectorImpl<const MCExpr *> &Exprs,
+ SmallPtrSetImpl<const MCExpr *> &Visited) {
+ // Assert if any of the expressions is already visited (i.e., there is
+ // existing recursion).
+ assert(!Visited.contains(Expr) &&
+ "Expr should not exist in Visited as we're avoiding recursion");
+ Visited.insert(Expr);
----------------
arsenm wrote:
```suggestion
if (!Visited.insert(Expr).second)
llvm_unreachable("already visited expression");
```
https://github.com/llvm/llvm-project/pull/111004
More information about the llvm-commits
mailing list