Skip to content

Commit 70aa3f3

Browse files
pratikasharigcbot
authored andcommitted
Allow spills to spill again in fail safe iteration
Due to constraints, spilled variables may spill again in fail safe iteration. This generates extra code but it guarantees completion of compilation.
1 parent 035b1f3 commit 70aa3f3

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

visa/G4_Register.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,7 @@ class G4_RegVarTmp : public G4_RegVar {
393393

394394
public:
395395
G4_RegVarTmp(G4_Declare *d, G4_RegVar *base)
396-
: G4_RegVar(d, RegVarType::GRFSpillTmp), baseRegVar(base) {
397-
vASSERT(base->isRegVarTransient() == false);
398-
vASSERT(base == base->getBaseRegVar());
399-
}
396+
: G4_RegVar(d, RegVarType::GRFSpillTmp), baseRegVar(base) {}
400397
void *operator new(size_t sz, Mem_Manager &m) { return m.alloc(sz); }
401398

402399
G4_RegVar *getBaseRegVar() { return baseRegVar; }

visa/GraphColor.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6566,7 +6566,16 @@ void GraphColor::computeSpillCosts(bool useSplitLLRHeuristic, const RPE *rpe) {
65666566
lrs[i]->getVar()->isSpilled() == false) ||
65676567
dcl == gra.getOldFPDcl() ||
65686568
(!builder.canReadR0() && dcl == builder.getBuiltinR0())) {
6569-
lrs[i]->setSpillCost(MAXSPILLCOST);
6569+
if (failSafeIter) {
6570+
// Allow spills to again spill in fail safe iteration in order to
6571+
// guarantee compilation succeeds.
6572+
if (lrs[i]->getVar()->isRegVarTransient() == true ||
6573+
lrs[i]->getVar()->isRegVarTmp() == true) {
6574+
lrs[i]->setSpillCost(0.99f * MAXSPILLCOST);
6575+
} else
6576+
lrs[i]->setSpillCost(MAXSPILLCOST);
6577+
} else
6578+
lrs[i]->setSpillCost(MAXSPILLCOST);
65706579
} else if (dcl->isDoNotSpill()) {
65716580
lrs[i]->setSpillCost(MAXSPILLCOST);
65726581
}
@@ -6763,7 +6772,7 @@ void GraphColor::removeConstrained() {
67636772
void GraphColor::determineColorOrdering() {
67646773
numColor = 0;
67656774
if (liveAnalysis.livenessClass(G4_GRF))
6766-
numColor = totalGRFRegCount - reserveSpillGRFCount;
6775+
numColor = totalGRFRegCount;
67676776
else if (liveAnalysis.livenessClass(G4_ADDRESS))
67686777
numColor = builder.getNumAddrRegisters();
67696778
else if (liveAnalysis.livenessClass(G4_FLAG))
@@ -11201,6 +11210,7 @@ bool GlobalRA::setupFailSafeIfNeeded(bool fastCompile, bool hasStackCall,
1120111210
}
1120211211
}
1120311212
}
11213+
1120411214
return reserveSpillReg;
1120511215
}
1120611216

visa/RADebug.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ bool Interference::dumpIntf(const char *s) const {
10371037
if (interfereBetween(i, j)) {
10381038
std::cout << "\t";
10391039
lrs[j]->getVar()->emit(std::cout);
1040+
if (lrs[j]->getPhyReg()) {
1041+
std::cout << "(r" << lrs[j]->getPhyReg()->asGreg()->getRegNum()
1042+
<< ")\n";
1043+
}
10401044
}
10411045
}
10421046
std::cout << "\n";

visa/SpillManagerGMRF.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,11 @@ bool SpillManagerGRF::shouldSpillRegister(G4_RegVar *regVar) const {
293293
: regVar;
294294
if (actualRegVar->getId() == UNDEFINED_VAL)
295295
return false;
296-
else if (regVar->isRegVarTransient() || regVar->isRegVarTmp())
297-
return false;
296+
else if (regVar->isRegVarTransient() || regVar->isRegVarTmp()) {
297+
if (!failSafeSpill_)
298+
return false;
299+
return true;
300+
}
298301
#ifndef ADDRESS_SENSITIVE_SPILLS_IMPLEMENTED
299302
else if (lvInfo_->isAddressSensitive(regVar->getId()))
300303
return false;

0 commit comments

Comments
 (0)