Skip to content

Commit 8ec2c17

Browse files
pratikasharigcbot
authored andcommitted
Fix register pressure estimator pass in presence of stack
calls Register pressure estimator pass was accumulating register pressure from stack call related pseudo nodes in its computation. Given these are pseudo nodes, they don't contribute to actual program register pressure.
1 parent 83442ca commit 8ec2c17

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

visa/RPE.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SPDX-License-Identifier: MIT
1515
namespace vISA
1616
{
1717
RPE::RPE(const GlobalRA& g, const LivenessAnalysis* l, DECLARE_LIST* spills) : m(1024), gra(g), liveAnalysis(l), live(l->getNumSelectedVar()),
18-
vars(l->vars)
18+
vars(l->vars), fg(g.kernel.fg)
1919
{
2020
options = g.kernel.getOptions();
2121
if (spills)
@@ -146,6 +146,8 @@ namespace vISA
146146
G4_Declare* rootDcl = range->getDeclare()->getRootDeclare();
147147
if (isSpilled(rootDcl))
148148
continue;
149+
if (isStackPseudoVar(rootDcl))
150+
continue;
149151
if (rootDcl->getNumElems() > 1)
150152
{
151153
regPressure += rootDcl->getNumRows();
@@ -176,6 +178,8 @@ namespace vISA
176178
auto dcl = vars[id]->getDeclare();
177179
if (isSpilled(dcl))
178180
return;
181+
if (isStackPseudoVar(dcl))
182+
return;
179183
// For <1 GRF variable we have to take alignment into consideration as well when computing register pressure.
180184
// For now we double each <1GRF variable's size if its alignment also exceeds its size.
181185
// Alternative is to simply take the alignment as the size, but it might cause performance regressions

visa/RPE.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace vISA
4949
private:
5050
Mem_Manager m;
5151
const GlobalRA& gra;
52+
const FlowGraph& fg;
5253
const LivenessAnalysis* const liveAnalysis;
5354
std::unordered_map<G4_INST*, unsigned int> rp;
5455
double regPressure = 0;
@@ -66,14 +67,34 @@ namespace vISA
6667
void updateRegisterPressure(unsigned int, unsigned int, unsigned int);
6768
void updateLiveness(SparseBitSet&, uint32_t, bool);
6869

69-
7070
bool isSpilled(const G4_Declare* dcl) const
7171
{
7272
auto it = spilledVars.find(dcl);
7373
if (it == spilledVars.end())
7474
return false;
7575
return true;
7676
}
77+
78+
bool isStackPseudoVar(G4_Declare* dcl) const
79+
{
80+
bool stackCall = fg.getIsStackCallFunc() || fg.getHasStackCalls();
81+
if (stackCall)
82+
{
83+
if (fg.isPseudoDcl(dcl))
84+
return true;
85+
86+
auto phyReg = dcl->getRegVar()->getPhyReg();
87+
if (phyReg && phyReg->isGreg())
88+
{
89+
auto regNum = phyReg->asGreg()->getRegNum();
90+
// Pre-assigned variables like FP, SP from
91+
// reserved GRFs don't contribute to reg pressure.
92+
if (regNum >= fg.builder->kernel.getStackCallStartReg())
93+
return true;
94+
}
95+
}
96+
return false;
97+
}
7798
};
7899
}
79100
#endif

0 commit comments

Comments
 (0)