Skip to content

Commit f68aa25

Browse files
pratikasharigcbot
authored andcommitted
Disable conversion of current RA iter to fail safe in -O0
Disable conversion of current RA iter to fail safe in -O0
1 parent 35e0779 commit f68aa25

File tree

6 files changed

+806
-28
lines changed

6 files changed

+806
-28
lines changed

visa/BuildIR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ class IR_Builder
641641
void createBuiltinDecls();
642642

643643
G4_Declare* getSpillFillHeader();
644+
bool hasValidSpillFillHeader() { return spillFillHeader; }
644645

645646
G4_Declare* getEUFusionWATmpVar();
646647

visa/GraphColor.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7534,7 +7534,17 @@ bool GraphColor::regAlloc(
75347534
if (reserveSpillReg)
75357535
{
75367536
failSafeIter = reserveSpillReg;
7537-
gra.determineSpillRegSize(spillRegSize, indrSpillRegSize);
7537+
7538+
if (kernel.getOption(vISA_NewFailSafeRA))
7539+
{
7540+
spillRegSize = gra.getNumReservedGRFs();
7541+
indrSpillRegSize = 0;
7542+
}
7543+
else
7544+
{
7545+
gra.determineSpillRegSize(spillRegSize, indrSpillRegSize);
7546+
}
7547+
75387548
reserveSpillSize = spillRegSize + indrSpillRegSize;
75397549
MUST_BE_TRUE(reserveSpillSize < kernel.getNumCalleeSaveRegs(), "Invalid reserveSpillSize in fail-safe RA!");
75407550
totalGRFRegCount -= reserveSpillSize;
@@ -10908,6 +10918,36 @@ int GlobalRA::coloringRegAlloc()
1090810918
loopSplit.run();
1090910919
}
1091010920

10921+
// Very few spills in this iter. Check if we can convert this to fail safe iter.
10922+
// By converting this iter to fail safe we can save (at least) 1 additional iter
10923+
// to allocate spilled temps. But converting to fail safe needs extra checks
10924+
// because no reserved GRF may exist at this point. So push/pop needs to succeed
10925+
// without additional GRF potentially.
10926+
if (!kernel.getOption(vISA_Debug) &&
10927+
iterationNo >= 1 && kernel.getOption(vISA_NewFailSafeRA) && !reserveSpillReg &&
10928+
coloring.getSpilledLiveRanges().size() <= BoundedRA::MaxSpillNumVars &&
10929+
liveAnalysis.getNumSelectedVar() > BoundedRA::LargeProgramSize)
10930+
{
10931+
// Stack call always has free GRF so it is safe to convert this iter to fail safe
10932+
if (builder.usesStack() ||
10933+
// If LSC has to be used for spill/fill then we need to ensure spillHeader is created
10934+
(!useLscForNonStackCallSpillFill || builder.hasValidSpillFillHeader()) ||
10935+
// If scratch is to be used then max spill offset must be within addressable range
10936+
((nextSpillOffset + BoundedRA::getNumPhyVarSlots(kernel)) < SCRATCH_MSG_LIMIT))
10937+
{
10938+
// Few ranges are spilled but this was not executed as fail
10939+
// safe iteration. However, we've the capability of doing
10940+
// push/pop with new fail safe RA implementation. So for very
10941+
// few spills, we insert push/pop to free up some GRFs rather
10942+
// than executing a new RA iteration. When doing so, we mark
10943+
// this RA iteration as fail safe.
10944+
reserveSpillReg = true;
10945+
coloring.markFailSafeIter(true);
10946+
// No reserved GRFs
10947+
setNumReservedGRFsFailSafe(0);
10948+
}
10949+
}
10950+
1091110951
//Calculate the spill caused by send to decide if global splitting is required or not
1091210952
for (auto spilled : coloring.getSpilledLiveRanges())
1091310953
{
@@ -11037,6 +11077,10 @@ int GlobalRA::coloringRegAlloc()
1103711077

1103811078
if (!reserveSpillReg && !disableSpillCoalecse && builder.useSends())
1103911079
{
11080+
if (builder.getOption(vISA_RATrace))
11081+
{
11082+
std::cout << "\t--spill/fill cleanup\n";
11083+
}
1104011084
CoalesceSpillFills c(kernel, liveAnalysis, coloring, spillGRF, iterationNo, rpe, *this);
1104111085
c.run();
1104211086
}

visa/GraphColor.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ namespace vISA
611611
G4_SrcRegRegion* getScratchSurface() const;
612612
LiveRange** getLRs() const { return lrs; }
613613
unsigned int getNumVars() const { return numVar; }
614+
void markFailSafeIter(bool f) { failSafeIter = f; }
614615
};
615616

616617
struct BundleConflict
@@ -797,6 +798,8 @@ namespace vISA
797798
uint32_t numGRFSpill = 0;
798799
uint32_t numGRFFill = 0;
799800

801+
unsigned int numReservedGRFsFailSafe = BoundedRA::NOT_FOUND;
802+
800803
bool spillFillIntrinUsesLSC(G4_INST* spillFillIntrin);
801804
void expandFillLSC(G4_BB* bb, INST_LIST_ITER& instIt);
802805
void expandSpillLSC(G4_BB* bb, INST_LIST_ITER& instIt);
@@ -1310,6 +1313,27 @@ namespace vISA
13101313
{
13111314
dontRemat.insert(inst);
13121315
}
1316+
1317+
unsigned int getNumReservedGRFs()
1318+
{
1319+
// Return # GRFs reserved for new fail safe mechanism
1320+
// 1. If fail safe mechanism is invoked before coloring then
1321+
// # reserved GRFs is updated explicitly before this method
1322+
// is invoked.
1323+
// 2. If a regular (ie, non-fail safe) RA iteration spill
1324+
// very little then we may convert it to fail safe but with
1325+
// 0 reserved GRFs as it it too late to reserve a GRF after
1326+
// coloring.
1327+
if (numReservedGRFsFailSafe == BoundedRA::NOT_FOUND)
1328+
numReservedGRFsFailSafe = kernel.getSimdSize() == kernel.numEltPerGRF<Type_UD>() ? 1 : 2;
1329+
1330+
return numReservedGRFsFailSafe;
1331+
}
1332+
1333+
void setNumReservedGRFsFailSafe(unsigned int num)
1334+
{
1335+
numReservedGRFsFailSafe = num;
1336+
}
13131337
};
13141338

13151339
inline G4_Declare* Interference::getGRFDclForHRA(int GRFNum) const

0 commit comments

Comments
 (0)