@@ -10078,7 +10078,7 @@ void VarSplit::globalSplit(IR_Builder &builder, G4_Kernel &kernel) {
1007810078 return ;
1007910079}
1008010080
10081- void VarSplit::localSplit (IR_Builder &builder, G4_BB *bb) {
10081+ int VarSplit::localSplit (IR_Builder &builder, G4_BB *bb) {
1008210082 class CmpRegVarId {
1008310083 public:
1008410084 bool operator ()(G4_RegVar *first, G4_RegVar *second) const {
@@ -10099,7 +10099,7 @@ void VarSplit::localSplit(IR_Builder &builder, G4_BB *bb) {
1009910099 bool hasSends = std::any_of (bb->begin (), bb->end (),
1010010100 [](G4_INST *inst) { return inst->isSend (); });
1010110101 if (!hasSends)
10102- return ;
10102+ return 0 ;
1010310103
1010410104 //
1010510105 // Iterate instruction in BB from back to front
@@ -10315,7 +10315,7 @@ void VarSplit::localSplit(IR_Builder &builder, G4_BB *bb) {
1031510315 toDelete.pop ();
1031610316 }
1031710317
10318- return ;
10318+ return splitid ;
1031910319}
1032010320
1032110321void GlobalRA::addrRegAlloc () {
@@ -11198,15 +11198,17 @@ bool GlobalRA::globalSplit(VarSplit& splitPass, GraphColor& coloring) {
1119811198 return false ;
1119911199}
1120011200
11201- void GlobalRA::localSplit (bool fastCompile, VarSplit& splitPass) {
11201+ int GlobalRA::localSplit (bool fastCompile, VarSplit& splitPass) {
1120211202 // Do variable splitting in each iteration
1120311203 // Don't do when fast compile is required
11204+ int splitCount = 0 ;
1120411205 if (builder.getOption (vISA_LocalDeclareSplitInGlobalRA) && !fastCompile) {
1120511206 RA_TRACE (std::cout << " \t --split local send--\n " );
1120611207 for (auto bb : kernel.fg ) {
11207- splitPass.localSplit (builder, bb);
11208+ splitCount += splitPass.localSplit (builder, bb);
1120811209 }
1120911210 }
11211+ return splitCount;
1121011212}
1121111213
1121211214std::pair<bool , bool > GlobalRA::bankConflict () {
@@ -11301,6 +11303,26 @@ bool GlobalRA::VRTIncreasedGRF(GraphColor &coloring) {
1130111303 return false ;
1130211304}
1130311305
11306+ bool GlobalRA::canVRTIncreasedGRF (GraphColor &coloring) {
11307+ if (kernel.useAutoGRFSelection ()) {
11308+ bool infCostSpilled =
11309+ coloring.getSpilledLiveRanges ().end () !=
11310+ std::find_if (coloring.getSpilledLiveRanges ().begin (),
11311+ coloring.getSpilledLiveRanges ().end (),
11312+ [](const LiveRange *spilledLR) {
11313+ return spilledLR->getSpillCost () == MAXSPILLCOST;
11314+ });
11315+ if ((infCostSpilled || kernel.grfMode .hasLargerGRFSameThreads () ||
11316+ computeSpillSize (coloring.getSpilledLiveRanges ()) >
11317+ kernel.grfMode .getSpillThreshold ())) {
11318+ if (kernel.canUpdateKernelToLargerGRF ()) {
11319+ return true ;
11320+ }
11321+ }
11322+ }
11323+ return false ;
11324+ }
11325+
1130411326void GlobalRA::splitOnSpill (bool fastCompile, GraphColor &coloring,
1130511327 LivenessAnalysis &liveAnalysis) {
1130611328 if (!kernel.getOption (vISA_Debug) && getIterNo () == 0 && !fastCompile &&
@@ -11733,6 +11755,7 @@ int GlobalRA::coloringRegAlloc() {
1173311755 }
1173411756
1173511757 bool rematDone = false , alignedScalarSplitDone = false ;
11758+ bool loadSplitTryDone = false ;
1173611759 bool reserveSpillReg = false ;
1173711760 VarSplit splitPass (*this );
1173811761 DynPerfModel perfModel (kernel);
@@ -11764,7 +11787,15 @@ int GlobalRA::coloringRegAlloc() {
1176411787 spillAnalysis->Clear ();
1176511788 }
1176611789
11767- localSplit (fastCompile, splitPass);
11790+ // 1. For legacy, always do localSpllit for old platforms.
11791+ // 2. For new platforms:
11792+ // a) Do localSplit when iteration 0 failed RA
11793+ // b) Always do localSplit for spill iterations, which may generate local
11794+ // split candidate.
11795+ if (iterationNo > 0 || loadSplitTryDone ||
11796+ !builder.onlyDoLocalVariableSplitWhenSpill ()) {
11797+ localSplit (fastCompile, splitPass);
11798+ }
1176811799
1176911800 const auto [doBankConflictReduction, highInternalConflict] = bankConflict ();
1177011801
@@ -11823,6 +11854,19 @@ int GlobalRA::coloringRegAlloc() {
1182311854 bool isColoringGood =
1182411855 coloring.regAlloc (doBankConflictReduction, highInternalConflict, &rpe);
1182511856 if (!isColoringGood) {
11857+ // Retry with local variable splitting if there is potential chance for
11858+ // VRT bump up.
11859+ if (builder.onlyDoLocalVariableSplitWhenSpill ()) {
11860+ if (!loadSplitTryDone && canVRTIncreasedGRF (coloring)) {
11861+ if (localSplit (fastCompile, splitPass) > 0 ) {
11862+ loadSplitTryDone = true ;
11863+ // Run one more iteration 0 with local split to avoid unnecessary
11864+ // bump up
11865+ continue ;
11866+ }
11867+ }
11868+ }
11869+
1182611870 // When there are spills and -abortonspill is set, vISA will bump up the
1182711871 // number of GRFs first and try to compile without spills under one of
1182811872 // the following conditions:
@@ -11849,6 +11893,15 @@ int GlobalRA::coloringRegAlloc() {
1184911893 if (rerunGRAIter (rerunGRA1 || rerunGRA2 || rerunGRA3))
1185011894 continue ;
1185111895
11896+ // For new platforms, check if there is local split space
11897+ if (!loadSplitTryDone && builder.onlyDoLocalVariableSplitWhenSpill ()) {
11898+ if (localSplit (fastCompile, splitPass) > 0 ) {
11899+ loadSplitTryDone = true ;
11900+ // Run one more iteration 0 for local split
11901+ continue ;
11902+ }
11903+ }
11904+
1185211905 splitOnSpill (fastCompile, coloring, liveAnalysis);
1185311906
1185411907 reserveSpillReg = convertToFailSafe (reserveSpillReg, coloring, liveAnalysis,
0 commit comments