-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
Changes from all commits
1b88285
5463971
ba27cd9
f99b859
b18ed55
a72d1ef
a60c29f
8a38d54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,25 +101,50 @@ void MCResourceInfo::assignResourceInfoExpr( | |
const MCConstantExpr *LocalConstExpr = | ||
MCConstantExpr::create(LocalValue, OutContext); | ||
const MCExpr *SymVal = LocalConstExpr; | ||
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK, OutContext); | ||
if (!Callees.empty()) { | ||
SmallVector<const MCExpr *, 8> ArgExprs; | ||
// Avoid recursive symbol assignment. | ||
SmallPtrSet<const Function *, 8> Seen; | ||
ArgExprs.push_back(LocalConstExpr); | ||
const Function &F = MF.getFunction(); | ||
Seen.insert(&F); | ||
|
||
for (const Function *Callee : Callees) { | ||
if (!Seen.insert(Callee).second) | ||
continue; | ||
|
||
MCSymbol *CalleeFnSym = TM.getSymbol(&Callee->getFunction()); | ||
MCSymbol *CalleeValSym = | ||
getSymbol(CalleeFnSym->getName(), RIK, OutContext); | ||
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
|
||
// Avoid constructing recursive definitions by detecting whether `Sym` is | ||
// found transitively within any of its `CalleeValSym`. | ||
if (!CalleeValSym->isVariable() || | ||
!CalleeValSym->getVariableValue(/*isUsed=*/false) | ||
->isSymbolUsedInExpression(Sym)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this miss adding other functions in the path to callee that we need to still add to the expression? e.g.
From f1, we see that callee f2 appears in a recursive expression, so it is skipped. but that will mean we do not add f3 to the expression, even though it is needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sadly enough order matters in that it is possible for such a skip to occur. For now I've assumed worst case and taken the module level register maximums for recursion. Preferably I'd like to have cycle/SCC scope register maximums computed and used but I think that's out of scope for this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should try to flatten the expression to remove the recursive edges There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, will do so in a follow up PR |
||
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
} else { | ||
// In case of recursion: make sure to use conservative register counts | ||
// (i.e., specifically for VGPR/SGPR/AGPR). | ||
switch (RIK) { | ||
default: | ||
break; | ||
case RIK_NumVGPR: | ||
ArgExprs.push_back(MCSymbolRefExpr::create( | ||
getMaxVGPRSymbol(OutContext), OutContext)); | ||
break; | ||
case RIK_NumSGPR: | ||
ArgExprs.push_back(MCSymbolRefExpr::create( | ||
getMaxSGPRSymbol(OutContext), OutContext)); | ||
break; | ||
case RIK_NumAGPR: | ||
ArgExprs.push_back(MCSymbolRefExpr::create( | ||
getMaxAGPRSymbol(OutContext), OutContext)); | ||
break; | ||
} | ||
} | ||
} | ||
SymVal = AMDGPUMCExpr::create(Kind, ArgExprs, OutContext); | ||
if (ArgExprs.size() > 1) | ||
SymVal = AMDGPUMCExpr::create(Kind, ArgExprs, OutContext); | ||
} | ||
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK, OutContext); | ||
Sym->setVariableValue(SymVal); | ||
} | ||
|
||
|
@@ -163,6 +188,7 @@ void MCResourceInfo::gatherResourceInfo( | |
// The expression for private segment size should be: FRI.PrivateSegmentSize | ||
// + max(FRI.Callees, FRI.CalleeSegmentSize) | ||
SmallVector<const MCExpr *, 8> ArgExprs; | ||
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK_PrivateSegSize, OutContext); | ||
if (FRI.CalleeSegmentSize) | ||
ArgExprs.push_back( | ||
MCConstantExpr::create(FRI.CalleeSegmentSize, OutContext)); | ||
|
@@ -174,9 +200,16 @@ void MCResourceInfo::gatherResourceInfo( | |
continue; | ||
if (!Callee->isDeclaration()) { | ||
MCSymbol *CalleeFnSym = TM.getSymbol(&Callee->getFunction()); | ||
MCSymbol *calleeValSym = | ||
MCSymbol *CalleeValSym = | ||
getSymbol(CalleeFnSym->getName(), RIK_PrivateSegSize, OutContext); | ||
ArgExprs.push_back(MCSymbolRefExpr::create(calleeValSym, OutContext)); | ||
|
||
// Avoid constructing recursive definitions by detecting whether `Sym` | ||
// is found transitively within any of its `CalleeValSym`. | ||
if (!CalleeValSym->isVariable() || | ||
!CalleeValSym->getVariableValue(/*isUsed=*/false) | ||
->isSymbolUsedInExpression(Sym)) { | ||
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext)); | ||
} | ||
} | ||
} | ||
const MCExpr *localConstExpr = | ||
|
@@ -187,8 +220,7 @@ void MCResourceInfo::gatherResourceInfo( | |
localConstExpr = | ||
MCBinaryExpr::createAdd(localConstExpr, transitiveExpr, OutContext); | ||
} | ||
getSymbol(FnSym->getName(), RIK_PrivateSegSize, OutContext) | ||
->setVariableValue(localConstExpr); | ||
Sym->setVariableValue(localConstExpr); | ||
} | ||
|
||
auto SetToLocal = [&](int64_t LocalValue, ResourceInfoKind RIK) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.