Skip to content

Commit e146785

Browse files
pratikasharigcbot
authored andcommitted
Pre-assign GRF to spillHeader in fail safe RA iteration
spillHeader may be used to store offset for spill/fill instruction. It must be infinite spill cost variable. If spillHeader gets assigned to a register that causes fragmentation, then it could cause previously spilled variables to not get an allocation in fail safe RA iteration. With this change, we find first GRF candidate that can be assigned to spillHeader. This way, we avoid fragmenting free GRF space.
1 parent 6105eaf commit e146785

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

visa/GraphColor.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6763,7 +6763,7 @@ void GraphColor::removeConstrained() {
67636763
void GraphColor::determineColorOrdering() {
67646764
numColor = 0;
67656765
if (liveAnalysis.livenessClass(G4_GRF))
6766-
numColor = totalGRFRegCount - reserveSpillGRFCount;
6766+
numColor = totalGRFRegCount;
67676767
else if (liveAnalysis.livenessClass(G4_ADDRESS))
67686768
numColor = builder.getNumAddrRegisters();
67696769
else if (liveAnalysis.livenessClass(G4_FLAG))
@@ -7628,6 +7628,10 @@ bool GraphColor::regAlloc(bool doBankConflictReduction,
76287628
intf.init();
76297629
intf.computeInterference();
76307630

7631+
if (reserveSpillGRFCount) {
7632+
preAssignSpillHeader();
7633+
}
7634+
76317635
builder.getFreqInfoManager().initForRegAlloc(&liveAnalysis);
76327636

76337637
// If option is true, try to get extra interference info from file
@@ -10917,6 +10921,49 @@ std::pair<unsigned, unsigned> GlobalRA::reserveGRFSpillReg(GraphColor &coloring)
1091710921
return std::make_pair(spillRegSize, indrSpillRegSize);
1091810922
}
1091910923

10924+
void GraphColor::preAssignSpillHeader() {
10925+
// If spill header is used for spill/fill offset, it must have infinite spill
10926+
// cost. When running fail safe RA, if we assign this range to middle of free
10927+
// GRF space, it could cause fragmentation and other spilled ranges may not
10928+
// get an allocation. So, we pre-assign this variable at first candidate GRF
10929+
// to avoid fragmentation. This is relevant only in fail safe RA iteration.
10930+
if (!builder.hasValidSpillFillHeader())
10931+
return;
10932+
10933+
std::vector<bool> FreeGRFs(kernel.getNumRegTotal(), true);
10934+
auto *spillHeader = builder.getSpillFillHeader();
10935+
if (spillHeader->getRegVar()->getPhyReg())
10936+
return;
10937+
unsigned spillHeaderId = spillHeader->getRootDeclare()->getRegVar()->getId();
10938+
// Compute free GRFs
10939+
const auto *intf = getIntf();
10940+
for (auto neighbor : intf->getSparseIntfForVar(spillHeaderId)) {
10941+
auto *neighborLR = getLiveRanges()[neighbor];
10942+
auto *neighborGRF = neighborLR->getPhyReg();
10943+
if (!neighborGRF)
10944+
continue;
10945+
unsigned int neighborGRFStart = neighborGRF->asGreg()->getRegNum();
10946+
unsigned int neighborLastGRF =
10947+
neighborGRFStart + neighborLR->getNumRegNeeded();
10948+
for (unsigned int i = neighborGRFStart; i != neighborLastGRF; ++i) {
10949+
FreeGRFs[i] = false;
10950+
}
10951+
}
10952+
10953+
// Find a GRF r1 onwards that can be pre-assigned to spillHeader.
10954+
// r0 is usually reserved.
10955+
for (unsigned int i = 1; i != FreeGRFs.size(); ++i) {
10956+
if (FreeGRFs[i]) {
10957+
// Attach assignment to temp LR and to G4_RegVar
10958+
getLiveRanges()[spillHeaderId]->setPhyReg(regPool.getGreg(i), 0);
10959+
spillHeader->getRegVar()->setPhyReg(regPool.getGreg(i), 0);
10960+
// Decrement counter as this is used later in determineColorOrdering
10961+
liveAnalysis.reduceNumUnassignedVar();
10962+
break;
10963+
}
10964+
}
10965+
}
10966+
1092010967
// pre-allocate the bits for forbidden registers which will not be used in
1092110968
// register assignment.
1092210969
// Note that the order of the calls matters, as all RCs inherit from RESERVEDGRF

visa/GraphColor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ class GraphColor {
11651165
unsigned execSize);
11661166

11671167
void gatherScatterForbiddenWA();
1168+
void preAssignSpillHeader();
11681169

11691170
public:
11701171
void getExtraInterferenceInfo();

visa/RegAlloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class LivenessAnalysis {
152152
unsigned getNumSplitVar() const { return numSplitVar; }
153153
unsigned getNumSplitStartID() const { return numSplitStartID; }
154154
unsigned getNumUnassignedVar() const { return numUnassignedVarId; }
155+
void reduceNumUnassignedVar() { --numUnassignedVarId; }
155156
void dump() const;
156157
void dumpBB(G4_BB *bb) const;
157158
void dumpLive(BitSet &live) const;

0 commit comments

Comments
 (0)