@@ -92,7 +92,8 @@ MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
9292}
9393
9494// The (partially complete) expression should have no recursion in it. After
95- // all, we're trying to avoid recursion using this codepath.
95+ // all, we're trying to avoid recursion using this codepath. Returns true if
96+ // Sym is found within Expr without recursing on Expr, false otherwise.
9697static bool findSymbolInExpr (MCSymbol *Sym, const MCExpr *Expr,
9798 SmallVectorImpl<const MCExpr *> &Exprs,
9899 SmallPtrSetImpl<const MCExpr *> &Visited) {
@@ -137,7 +138,8 @@ static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr,
137138// recursive) must be avoided. Do a walk over Expr to see if Sym will occur in
138139// it. The Expr is an MCExpr given through a callee's equivalent MCSymbol so if
139140// no recursion is found Sym can be safely assigned to a (sub-)expr which
140- // contains the symbol Expr is associated with.
141+ // contains the symbol Expr is associated with. Returns true if Sym exists
142+ // in Expr or its sub-expressions, false otherwise.
141143static bool foundRecursiveSymbolDef (MCSymbol *Sym, const MCExpr *Expr) {
142144 SmallVector<const MCExpr *, 8 > WorkList;
143145 SmallPtrSet<const MCExpr *, 8 > Visited;
@@ -172,12 +174,8 @@ void MCResourceInfo::assignResourceInfoExpr(
172174 if (!Seen.insert (Callee).second )
173175 continue ;
174176 MCSymbol *CalleeValSym = getSymbol (Callee->getName (), RIK, OutContext);
175- if (CalleeValSym->isVariable ()) {
176- if (!foundRecursiveSymbolDef (
177- Sym, CalleeValSym->getVariableValue (/* isUsed=*/ false ))) {
178- ArgExprs.push_back (MCSymbolRefExpr::create (CalleeValSym, OutContext));
179- }
180- } else {
177+ bool CalleeIsVar = CalleeValSym->isVariable ();
178+ if (!CalleeIsVar || (CalleeIsVar && !foundRecursiveSymbolDef (Sym, CalleeValSym->getVariableValue (/* IsUsed=*/ false )))) {
181179 ArgExprs.push_back (MCSymbolRefExpr::create (CalleeValSym, OutContext));
182180 }
183181 }
@@ -235,16 +233,11 @@ void MCResourceInfo::gatherResourceInfo(
235233 if (!Seen.insert (Callee).second )
236234 continue ;
237235 if (!Callee->isDeclaration ()) {
238- MCSymbol *calleeValSym =
236+ MCSymbol *CalleeValSym =
239237 getSymbol (Callee->getName (), RIK_PrivateSegSize, OutContext);
240- if (calleeValSym->isVariable ()) {
241- if (!foundRecursiveSymbolDef (
242- Sym, calleeValSym->getVariableValue (/* isUsed=*/ false ))) {
243- ArgExprs.push_back (
244- MCSymbolRefExpr::create (calleeValSym, OutContext));
245- }
246- } else {
247- ArgExprs.push_back (MCSymbolRefExpr::create (calleeValSym, OutContext));
238+ bool CalleeIsVar = CalleeValSym->isVariable ();
239+ if (!CalleeIsVar || (CalleeIsVar && !foundRecursiveSymbolDef (Sym, CalleeValSym->getVariableValue (/* IsUsed=*/ false )))) {
240+ ArgExprs.push_back (MCSymbolRefExpr::create (CalleeValSym, OutContext));
248241 }
249242 }
250243 }
0 commit comments