Skip to content

Commit 10382ea

Browse files
committed
Feedback, use WorkList instead of recurse, llvm_unreachable instead of
assert
1 parent 2dc357c commit 10382ea

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr,
9898
SmallPtrSetImpl<const MCExpr *> &Visited) {
9999
// Assert if any of the expressions is already visited (i.e., there is
100100
// existing recursion).
101-
assert(!Visited.contains(Expr) &&
102-
"Expr should not exist in Visited as we're avoiding recursion");
103-
Visited.insert(Expr);
101+
if (!Visited.insert(Expr).second)
102+
llvm_unreachable("already visited expression");
104103

105104
switch (Expr->getKind()) {
106105
default:
@@ -116,19 +115,19 @@ static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr,
116115
}
117116
case MCExpr::ExprKind::Binary: {
118117
const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr);
119-
return findSymbolInExpr(Sym, BExpr->getLHS(), Exprs, Visited) ||
120-
findSymbolInExpr(Sym, BExpr->getRHS(), Exprs, Visited);
118+
Exprs.push_back(BExpr->getLHS());
119+
Exprs.push_back(BExpr->getRHS());
120+
return false;
121121
}
122122
case MCExpr::ExprKind::Unary: {
123123
const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr);
124-
return findSymbolInExpr(Sym, UExpr->getSubExpr(), Exprs, Visited);
124+
Exprs.push_back(UExpr->getSubExpr());
125+
return false;
125126
}
126127
case MCExpr::ExprKind::Target: {
127128
const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr);
128-
for (const MCExpr *E : AGVK->getArgs()) {
129-
if (findSymbolInExpr(Sym, E, Exprs, Visited))
130-
return true;
131-
}
129+
for (const MCExpr *E : AGVK->getArgs())
130+
Exprs.push_back(E);
132131
return false;
133132
}
134133
}

0 commit comments

Comments
 (0)