Skip to content

Commit b5d7f52

Browse files
bcheng0127igcbot
authored andcommitted
Enable abort on spill for linear Scan RA
Enable abort on spill for linear Scan RA Adape the same abort on spill mechanism to linear Scan RA, for the case in which the regsiter pressure is too high and spill cannot make RA success, abort on spill
1 parent 8ef7add commit b5d7f52

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,15 @@ namespace IGC
40504050
{
40514051
SaveOption(vISA_ScheduleEndBBID, Val);
40524052
}
4053+
if (uint32_t Val = IGC_GET_FLAG_VALUE(VISAPostScheduleStartBBID))
4054+
{
4055+
SaveOption(vISA_LocalSchedulingStartBB, Val);
4056+
}
4057+
4058+
if (uint32_t Val = IGC_GET_FLAG_VALUE(VISAPostScheduleEndBBID))
4059+
{
4060+
SaveOption(vISA_LocalSchedulingEndBB, Val);
4061+
}
40534062
}
40544063
else
40554064
{

IGC/common/igc_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ DECLARE_IGC_REGKEY(bool, ForceVISAPreSched, false, "Force enabling o
2222
DECLARE_IGC_REGKEY(DWORD, VISAPreSchedRPThreshold, 0, "Configure how aggressive pre-RA Scheduler is, 0 for the default", false)
2323
DECLARE_IGC_REGKEY(DWORD, VISAScheduleStartBBID, 0, "The ID of BB which will be first scheduled", false)
2424
DECLARE_IGC_REGKEY(DWORD, VISAScheduleEndBBID, 0, "The ID of BB which will be last scheduled", false)
25+
DECLARE_IGC_REGKEY(DWORD, VISAPostScheduleStartBBID, 0, "The ID of BB which will be first scheduled", false)
26+
DECLARE_IGC_REGKEY(DWORD, VISAPostScheduleEndBBID, 0, "The ID of BB which will be last scheduled", false)
2527
DECLARE_IGC_REGKEY(DWORD, SIMD8_SpillThreshold, 2, "Percentage of instructions allowed for spilling", false)
2628
DECLARE_IGC_REGKEY(DWORD, SIMD16_SpillThreshold, 1, "Percentage of instructions allowed for spilling", false)
2729
DECLARE_IGC_REGKEY(bool, DisableCSEL, false, "disable csel peep-hole", false)

visa/LinearScanRA.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,43 @@ int LinearScanRA::linearScanRA()
979979
globalLinearScan ra(gra, &l, globalLiveIntervals, &preAssignedLiveIntervals, inputIntervals, pregManager,
980980
mem, numRegLRA, numRowsEOT, latestLexID,
981981
doBCR, highInternalConflict);
982-
if (!ra.runLinearScan(builder, globalLiveIntervals, spillLRs))
982+
983+
bool success = ra.runLinearScan(builder, globalLiveIntervals, spillLRs);
984+
985+
auto underSpillThreshold = [this](int numSpill, int asmCount)
986+
{
987+
int threshold = std::min(builder.getOptions()->getuInt32Option(vISA_AbortOnSpillThreshold), 200u);
988+
return (numSpill * 200) < (threshold * asmCount);
989+
};
990+
991+
for (auto lr : spillLRs)
992+
{
993+
GRFSpillFillCount += lr->getNumRefs();
994+
}
995+
996+
int instNum = 0;
997+
for (auto bb : kernel.fg)
998+
{
999+
instNum += (int)bb->size();
1000+
}
1001+
if (GRFSpillFillCount && builder.getOption(vISA_AbortOnSpill) && !underSpillThreshold(GRFSpillFillCount, instNum))
1002+
{
1003+
// update jit metadata information
1004+
if (auto jitInfo = builder.getJitInfo())
1005+
{
1006+
jitInfo->isSpill = true;
1007+
jitInfo->spillMemUsed = 0;
1008+
jitInfo->numAsmCount = instNum;
1009+
jitInfo->numGRFSpillFill = GRFSpillFillCount;
1010+
}
1011+
1012+
// Early exit when -abortonspill is passed, instead of
1013+
// spending time inserting spill code and then aborting.
1014+
return VISA_SPILL;
1015+
}
1016+
1017+
//Try other graphcoloring
1018+
if (!success)
9831019
{
9841020
undoLinearScanRAAssignments();
9851021
return VISA_FAILURE;
@@ -1019,10 +1055,6 @@ int LinearScanRA::linearScanRA()
10191055
COUT_ERROR << "===== printSpillLiveIntervals============" << std::endl;
10201056
printSpillLiveIntervals(spillLRs);
10211057
#endif
1022-
for (auto lr : spillLRs)
1023-
{
1024-
GRFSpillFillCount += lr->getNumRefs();
1025-
}
10261058

10271059
// update jit metadata information for spill
10281060
if (auto jitInfo = builder.getJitInfo())
@@ -1066,33 +1098,6 @@ int LinearScanRA::linearScanRA()
10661098
std::cout << "\t\tGRFSpillFillCount: " << GRFSpillFillCount << "\n";
10671099
}
10681100

1069-
auto underSpillThreshold = [this](int numSpill, int asmCount)
1070-
{
1071-
int threshold = std::min(builder.getOptions()->getuInt32Option(vISA_AbortOnSpillThreshold), 200u);
1072-
return (numSpill * 200) < (threshold * asmCount);
1073-
};
1074-
1075-
int instNum = 0;
1076-
for (auto bb : kernel.fg)
1077-
{
1078-
instNum += (int)bb->size();
1079-
}
1080-
if (GRFSpillFillCount && builder.getOption(vISA_AbortOnSpill) && !underSpillThreshold(GRFSpillFillCount, instNum))
1081-
{
1082-
// update jit metadata information
1083-
if (auto jitInfo = builder.getJitInfo())
1084-
{
1085-
jitInfo->isSpill = true;
1086-
jitInfo->spillMemUsed = 0;
1087-
jitInfo->numAsmCount = instNum;
1088-
jitInfo->numGRFSpillFill = GRFSpillFillCount;
1089-
}
1090-
1091-
// Early exit when -abortonspill is passed, instead of
1092-
// spending time inserting spill code and then aborting.
1093-
return VISA_SPILL;
1094-
}
1095-
10961101
iterator++;
10971102
} while (spillLRs.size() && iterator < MAXIMAL_ITERATIONS);
10981103

@@ -2279,7 +2284,7 @@ bool globalLinearScan::runLinearScan(IR_Builder& builder, std::vector<LSLiveRang
22792284
COUT_ERROR << "Failed to spill registers for " << lr->getTopDcl()->getName() << ", rows :" << lr->getTopDcl()->getNumRows() << std::endl;
22802285
printActives();
22812286
#endif
2282-
spillLRs.push_back(lr);
2287+
return false;
22832288
}
22842289
}
22852290
}

0 commit comments

Comments
 (0)