-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Reapply [AMDGPU] Avoid resource propagation for recursion through multiple functions #112251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1b88285
Reapply [AMDGPU] Avoid resource propagation for recursion through mul…
JanekvO 5463971
Feedback, merge WorkList iteration in Callee iteration
JanekvO ba27cd9
Recursive walk instead of iterative over a WorkSet
JanekvO f99b859
Feedback: remove redundant check
JanekvO b18ed55
Move isSymbolUsedInExpression to MCExpr, use for recursion detection …
JanekvO a72d1ef
Merge remote-tracking branch 'fork-github/main' into reapply-fix-recu…
JanekvO a60c29f
Conservative register count for recursion, comments, add reg usage in…
JanekvO 8a38d54
Add register use for introduced tests
JanekvO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,34 +96,48 @@ MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) { | |
| // true if Sym is found within Expr (i.e., has a recurrance of Sym found), false | ||
| // otherwise. | ||
| static bool findSymbolInExpr(MCSymbol *Sym, const MCExpr *Expr, | ||
| SmallPtrSetImpl<const MCExpr *> &Exprs) { | ||
| SmallPtrSetImpl<const MCExpr *> &Visited) { | ||
|
|
||
| if (Expr->getKind() == MCExpr::ExprKind::SymbolRef) { | ||
| const MCSymbolRefExpr *SymRefExpr = cast<MCSymbolRefExpr>(Expr); | ||
| const MCSymbol &SymRef = SymRefExpr->getSymbol(); | ||
| if (Sym == &SymRef) | ||
| return true; | ||
| } | ||
|
|
||
| if (!Visited.insert(Expr).second) | ||
| return false; | ||
|
|
||
| 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.insert(SymRef.getVariableValue(/*isUsed=*/false)); | ||
| if (SymRef.isVariable()) { | ||
| return findSymbolInExpr(Sym, SymRef.getVariableValue(/*isUsed=*/false), | ||
| Visited); | ||
| } | ||
| return false; | ||
| } | ||
| case MCExpr::ExprKind::Binary: { | ||
| const MCBinaryExpr *BExpr = cast<MCBinaryExpr>(Expr); | ||
| Exprs.insert(BExpr->getLHS()); | ||
| Exprs.insert(BExpr->getRHS()); | ||
| if (findSymbolInExpr(Sym, BExpr->getLHS(), Visited) || | ||
| findSymbolInExpr(Sym, BExpr->getRHS(), Visited)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| case MCExpr::ExprKind::Unary: { | ||
| const MCUnaryExpr *UExpr = cast<MCUnaryExpr>(Expr); | ||
| Exprs.insert(UExpr->getSubExpr()); | ||
| return false; | ||
| return findSymbolInExpr(Sym, UExpr->getSubExpr(), Visited); | ||
| } | ||
| case MCExpr::ExprKind::Target: { | ||
| const AMDGPUMCExpr *AGVK = cast<AMDGPUMCExpr>(Expr); | ||
| for (const MCExpr *E : AGVK->getArgs()) | ||
| Exprs.insert(E); | ||
| for (const MCExpr *E : AGVK->getArgs()) { | ||
| if (findSymbolInExpr(Sym, E, Visited)) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
@@ -146,24 +160,17 @@ void MCResourceInfo::assignResourceInfoExpr( | |
| if (!Seen.insert(Callee).second) | ||
| continue; | ||
|
|
||
| SmallPtrSet<const MCExpr *, 8> WorkSet; | ||
| SmallPtrSet<const MCExpr *, 8> Visited; | ||
| MCSymbol *CalleeValSym = getSymbol(Callee->getName(), RIK, OutContext); | ||
| if (CalleeValSym->isVariable()) | ||
| WorkSet.insert(CalleeValSym->getVariableValue(/*IsUsed=*/false)); | ||
| else | ||
| ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
|
|
||
| bool FoundRecursion = false; | ||
| while (!WorkSet.empty() && !FoundRecursion) { | ||
| auto It = WorkSet.begin(); | ||
| const MCExpr *Expr = *It; | ||
| WorkSet.erase(Expr); | ||
|
|
||
| FoundRecursion = findSymbolInExpr(Sym, Expr, WorkSet); | ||
| } | ||
| bool CalleeIsVar = CalleeValSym->isVariable(); | ||
|
|
||
| if (CalleeValSym->isVariable() && !FoundRecursion) | ||
| if (!CalleeIsVar || | ||
| (CalleeIsVar && | ||
| !findSymbolInExpr(Sym, | ||
| CalleeValSym->getVariableValue(/*IsUsed=*/false), | ||
| Visited))) { | ||
| ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
| } | ||
| } | ||
| if (ArgExprs.size() > 1) | ||
| SymVal = AMDGPUMCExpr::create(Kind, ArgExprs, OutContext); | ||
|
|
@@ -219,24 +226,18 @@ void MCResourceInfo::gatherResourceInfo( | |
| if (!Seen.insert(Callee).second) | ||
| continue; | ||
| if (!Callee->isDeclaration()) { | ||
| SmallPtrSet<const MCExpr *, 8> WorkSet; | ||
| SmallPtrSet<const MCExpr *, 8> Visited; | ||
| MCSymbol *CalleeValSym = | ||
| getSymbol(Callee->getName(), RIK_PrivateSegSize, OutContext); | ||
| if (CalleeValSym->isVariable()) | ||
| WorkSet.insert(CalleeValSym->getVariableValue(/*IsUsed=*/false)); | ||
| else | ||
| ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
| bool CalleeIsVar = CalleeValSym->isVariable(); | ||
|
|
||
| bool FoundRecursion = false; | ||
| while (!WorkSet.empty() && !FoundRecursion) { | ||
| auto It = WorkSet.begin(); | ||
| const MCExpr *Expr = *It; | ||
| WorkSet.erase(Expr); | ||
|
|
||
| FoundRecursion = findSymbolInExpr(Sym, Expr, WorkSet); | ||
| } | ||
| if (CalleeValSym->isVariable() && !FoundRecursion) | ||
| if (!CalleeIsVar || | ||
| (CalleeIsVar && | ||
|
||
| !findSymbolInExpr(Sym, | ||
| CalleeValSym->getVariableValue(/*IsUsed=*/false), | ||
| Visited))) { | ||
| ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
| } | ||
| } | ||
| } | ||
| const MCExpr *localConstExpr = | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CalleeIsVar &&redundant