Skip to content

Commit a3a95d1

Browse files
weiyu-chengfxbot
authored andcommitted
Clean up local RA pass (no functionality changes
Change-Id: Ide8c5c327d5b1bf77dd1c189ffca8cd7f7e15ab1
1 parent 6d2d081 commit a3a95d1

File tree

5 files changed

+61
-268
lines changed

5 files changed

+61
-268
lines changed

visa/GraphColor.cpp

Lines changed: 13 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,6 @@ void refNumBasedSort(unsigned int *refNum, unsigned int *index)
211211
return;
212212
}
213213

214-
bool BankConflictPass::hasInternalConflict2Srcs(BankConflict *srcBC)
215-
{
216-
if (((srcBC[1] == BANK_CONFLICT_SECOND_HALF_EVEN ||
217-
srcBC[1] == BANK_CONFLICT_FIRST_HALF_EVEN) &&
218-
(srcBC[2] == BANK_CONFLICT_SECOND_HALF_EVEN ||
219-
srcBC[2] == BANK_CONFLICT_FIRST_HALF_EVEN)) ||
220-
((srcBC[1] == BANK_CONFLICT_SECOND_HALF_ODD ||
221-
srcBC[1] == BANK_CONFLICT_FIRST_HALF_ODD) &&
222-
(srcBC[2] == BANK_CONFLICT_SECOND_HALF_ODD ||
223-
srcBC[2] == BANK_CONFLICT_FIRST_HALF_ODD)))
224-
{
225-
return true;
226-
}
227-
if ((srcBC[1] < BANK_CONFLICT_SECOND_HALF_EVEN &&
228-
srcBC[2] < BANK_CONFLICT_SECOND_HALF_EVEN) ||
229-
(srcBC[1] >= BANK_CONFLICT_SECOND_HALF_EVEN &&
230-
srcBC[2] >= BANK_CONFLICT_SECOND_HALF_EVEN))
231-
{
232-
return true;
233-
}
234-
235-
return false;
236-
}
237-
238214
bool BankConflictPass::hasInternalConflict3Srcs(BankConflict *srcBC)
239215
{
240216
if (((srcBC[0] == BANK_CONFLICT_SECOND_HALF_EVEN ||
@@ -265,106 +241,6 @@ bool BankConflictPass::hasInternalConflict3Srcs(BankConflict *srcBC)
265241
return false;
266242
}
267243

268-
269-
void BankConflictPass::setupBankConflictsForDecls(G4_Declare * dcl_1, G4_Declare * dcl_2,
270-
unsigned int offset1, unsigned int offset2,
271-
BankConflict &srcBC1, BankConflict &srcBC2,
272-
int &bank1RegNum, int &bank2RegNum,
273-
float GRFRatio, bool oneGRFBank)
274-
{
275-
ASSERT_USER(srcBC1 == BANK_CONFLICT_NONE, "Wrong Bank initial value");
276-
ASSERT_USER(srcBC2 == BANK_CONFLICT_NONE, "Wrong Bank initial value");
277-
278-
unsigned int regNum1 = dcl_1->getNumRows();
279-
unsigned int regNum2 = dcl_2->getNumRows();
280-
unsigned int refNum1 = gra.getNumRefs(dcl_1);
281-
unsigned int refNum2 = gra.getNumRefs(dcl_2);
282-
283-
BankConflict bank1 = BANK_CONFLICT_NONE;
284-
BankConflict bank2 = BANK_CONFLICT_NONE;
285-
bool bank1First = false;
286-
287-
if (GRFRatio == 1.0)
288-
{
289-
//For global RA: Try to reduce the size of bank 2
290-
if ((float)refNum1 / regNum1 >= (float)refNum2 / regNum2)
291-
{
292-
bank1 = BANK_CONFLICT_SECOND_HALF_EVEN;
293-
bank2 = BANK_CONFLICT_FIRST_HALF_ODD;
294-
bank1First = true;
295-
}
296-
else
297-
{
298-
bank2 = BANK_CONFLICT_SECOND_HALF_EVEN;
299-
bank1 = BANK_CONFLICT_FIRST_HALF_ODD;
300-
}
301-
}
302-
else
303-
{
304-
//For local RA: Try to balance two banks
305-
if (refNum1 >= refNum2)
306-
{
307-
bank1 = ((bank1RegNum * GRFRatio) > bank2RegNum) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
308-
bank2 = (bank1 == BANK_CONFLICT_SECOND_HALF_EVEN) ? BANK_CONFLICT_FIRST_HALF_ODD : BANK_CONFLICT_SECOND_HALF_ODD;
309-
bank1First = true;
310-
}
311-
else
312-
{
313-
bank2 = (bank1RegNum * GRFRatio) > bank2RegNum ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
314-
bank1 = (bank2 == BANK_CONFLICT_SECOND_HALF_EVEN) ? BANK_CONFLICT_FIRST_HALF_ODD : BANK_CONFLICT_SECOND_HALF_ODD;
315-
}
316-
}
317-
318-
srcBC1 = bank1;
319-
srcBC2 = bank2;
320-
321-
//Adjust only for the single bank allocation
322-
if (oneGRFBank)
323-
{
324-
if ((offset1 + offset2) % 2)
325-
{
326-
if (bank1First)
327-
{
328-
bank2 = (bank2 == BANK_CONFLICT_FIRST_HALF_ODD) ? BANK_CONFLICT_FIRST_HALF_EVEN : BANK_CONFLICT_SECOND_HALF_EVEN;
329-
}
330-
else
331-
{
332-
bank1 = (bank1 == BANK_CONFLICT_SECOND_HALF_ODD) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
333-
}
334-
}
335-
}
336-
else
337-
{
338-
if ((offset1 / 2 + offset2 / 2) % 2)
339-
{
340-
if (bank1First)
341-
{
342-
bank2 = (bank2 == BANK_CONFLICT_FIRST_HALF_ODD) ? BANK_CONFLICT_FIRST_HALF_EVEN : BANK_CONFLICT_SECOND_HALF_EVEN;
343-
}
344-
else
345-
{
346-
bank1 = (bank1 == BANK_CONFLICT_SECOND_HALF_ODD) ? BANK_CONFLICT_SECOND_HALF_EVEN : BANK_CONFLICT_FIRST_HALF_EVEN;
347-
}
348-
}
349-
}
350-
351-
if (bank1 >= BANK_CONFLICT_SECOND_HALF_EVEN)
352-
{
353-
bank2RegNum += regNum1;
354-
bank1RegNum += regNum2;
355-
}
356-
else
357-
{
358-
bank1RegNum += regNum1;
359-
bank2RegNum += regNum2;
360-
}
361-
362-
gra.setBankConflict(dcl_1, bank1);
363-
gra.setBankConflict(dcl_2, bank2);
364-
365-
return;
366-
}
367-
368244
void BankConflictPass::setupEvenOddBankConflictsForDecls(G4_Declare * dcl_1, G4_Declare * dcl_2,
369245
unsigned int offset1, unsigned int offset2,
370246
BankConflict &srcBC1, BankConflict &srcBC2)
@@ -951,7 +827,7 @@ void BankConflictPass::setupBankConflictsForBB(G4_BB* bb,
951827
GRFRatio = ((float)(numRegLRA - SECOND_HALF_BANK_START_GRF)) / SECOND_HALF_BANK_START_GRF;
952828
}
953829

954-
for (std::list<G4_INST*>::reverse_iterator i = bb->rbegin(), rend = bb->rend();
830+
for (auto i = bb->rbegin(), rend = bb->rend();
955831
i != rend;
956832
i++)
957833
{
@@ -1018,15 +894,15 @@ bool compareBBLoopLevel(G4_BB* bb1, G4_BB* bb2)
1018894
* threeSourceCandidate, if there are enough three source instructions
1019895
* return value, if do bank confliction reduction to RR RA.
1020896
*/
1021-
bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict)
897+
bool BankConflictPass::setupBankConflictsForKernel(bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict)
1022898
{
1023899
BB_LIST orderedBBs;
1024900
unsigned int threeSourceInstNumInKernel = 0;
1025901
unsigned int internalConflict = 0;
1026902
unsigned int instNumInKernel = 0;
1027903
unsigned int sendInstNumInKernel = 0;
1028904

1029-
for (auto curBB : kernel.fg.BBs)
905+
for (auto curBB : gra.kernel.fg.BBs)
1030906
{
1031907
orderedBBs.push_back(curBB);
1032908
}
@@ -1041,8 +917,7 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1041917

1042918
unsigned int loopNestLevel = 0;
1043919

1044-
setupBankConflictsForBB(bb, threeSourceInstNum, sendInstNum,
1045-
numRegLRA, conflicts);
920+
setupBankConflictsForBB(bb, threeSourceInstNum, sendInstNum, numRegLRA, conflicts);
1046921
loopNestLevel = bb->getNestLevel() + 1;
1047922

1048923
if (threeSourceInstNum)
@@ -1051,7 +926,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1051926
threeSourceInstNum = threeSourceInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1052927
sendInstNum = sendInstNum * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1053928
conflicts = conflicts * loopNestLevel * BANK_CONFLICT_HEURISTIC_LOOP_ITERATION;
1054-
1055929
internalConflict += conflicts;
1056930
threeSourceInstNumInKernel += threeSourceInstNum;
1057931
instNumInKernel += instNum;
@@ -1065,15 +939,6 @@ bool BankConflictPass::setupBankConflictsForKernel(G4_Kernel& kernel, bool doLoc
1065939
return false;
1066940
}
1067941

1068-
#ifdef DEBUG_VERBOSE_ON
1069-
for (DECLARE_LIST_ITER dcl_it = kernel.Declares.begin();
1070-
dcl_it != kernel.Declares.end();
1071-
dcl_it++)
1072-
{
1073-
printf("dcl: %s : bank: %d\n", (*dcl_it)->getName(), gra.getBankConflict((*dcl_it)));
1074-
}
1075-
#endif
1076-
1077942
highInternalConflict = ((float)internalConflict / threeSourceInstNumInKernel) > INTERNAL_CONFLICT_RATIO_HEURISTIC;
1078943

1079944
//Bank conflict reduction is done only when there is enough three source instructions.
@@ -9148,21 +9013,17 @@ int GlobalRA::coloringRegAlloc()
91489013
}
91499014
}
91509015

9151-
BankConflictPass bc(*this);
9152-
bool doBankConflictReduction = false;
9153-
bool highInternalConflict = false;
9154-
91559016
if (builder.getOption(vISA_LocalRA) && !isReRAPass() && canDoLRA(kernel))
91569017
{
91579018
startTimer(TIMER_LOCAL_RA);
9158-
bool doLocalRR = builder.getOption(vISA_LocalRARoundRobin);
9159-
LocalRA lra(kernel, highInternalConflict, bc, *this);
9160-
bool success = lra.localRA(doLocalRR, doBankConflictReduction);
9019+
BankConflictPass bc(*this);
9020+
LocalRA lra(bc, *this);
9021+
bool success = lra.localRA();
91619022
stopTimer(TIMER_LOCAL_RA);
91629023
if (!success)
91639024
{
91649025
startTimer(TIMER_HYBRID_RA);
9165-
success = hybridRA(doBankConflictReduction, highInternalConflict, lra);
9026+
success = hybridRA(lra.doHybridBCR(), lra.hasHighInternalBC(), lra);
91669027
stopTimer(TIMER_HYBRID_RA);
91679028
}
91689029
if (success)
@@ -9231,13 +9092,17 @@ int GlobalRA::coloringRegAlloc()
92319092
}
92329093
}
92339094

9095+
bool doBankConflictReduction = false;
9096+
bool highInternalConflict = false; // this is set by setupBankConflictsForKernel
9097+
92349098
if (builder.getOption(vISA_LocalBankConflictReduction) &&
92359099
builder.hasBankCollision())
92369100
{
92379101
bool reduceBCInRR = false;
92389102
bool reduceBCInTAandFF = false;
9103+
BankConflictPass bc(*this);
92399104

9240-
reduceBCInRR = bc.setupBankConflictsForKernel(kernel, true, reduceBCInTAandFF, SECOND_HALF_BANK_START_GRF * 2, highInternalConflict);
9105+
reduceBCInRR = bc.setupBankConflictsForKernel(true, reduceBCInTAandFF, SECOND_HALF_BANK_START_GRF * 2, highInternalConflict);
92419106
doBankConflictReduction = reduceBCInRR && reduceBCInTAandFF;
92429107
}
92439108

visa/GraphColor.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ namespace vISA
5252
GlobalRA& gra;
5353

5454
BankConflict setupBankAccordingToSiblingOperand(BankConflict assignedBank, unsigned int offset, bool oneGRFBank);
55-
bool hasInternalConflict2Srcs(BankConflict*srcBC);
56-
void setupBankConflictsForDecls(G4_Declare* dcl_1, G4_Declare* dcl_2, unsigned int offset1, unsigned int offset2,
57-
BankConflict &srcBC1, BankConflict &srcBC2, int &bank1RegNum, int &bank2RegNum, float GRFRatio, bool oneGRFBank);
5855
void setupEvenOddBankConflictsForDecls(G4_Declare * dcl_1, G4_Declare * dcl_2, unsigned int offset1, unsigned int offset2,
5956
BankConflict &srcBC1, BankConflict &srcBC2);
6057
void setupBankConflictsOneGRFOld(G4_INST* inst, int &bank1RegNum, int &bank2RegNum, float GRFRatio, unsigned int &internalConflict);
@@ -64,14 +61,11 @@ namespace vISA
6461
unsigned int numRegLRA, unsigned int & internalConflict);
6562
bool hasInternalConflict3Srcs(BankConflict *srcBC);
6663
void setupBankForSrc0(G4_INST* inst, G4_INST* prevInst);
67-
void setupToEvenBank(G4_INST* inst);
6864
void getBanks(G4_INST* inst, BankConflict *srcBC, G4_Declare **dcls, G4_Declare **opndDcls, unsigned int *offset);
6965
void getPrevBanks(G4_INST* inst, BankConflict *srcBC, G4_Declare **dcls, G4_Declare **opndDcls, unsigned int *offset);
7066

71-
72-
7367
public:
74-
bool setupBankConflictsForKernel(G4_Kernel& kernel, bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict);
68+
bool setupBankConflictsForKernel(bool doLocalRR, bool &threeSourceCandidate, unsigned int numRegLRA, bool &highInternalConflict);
7569

7670
BankConflictPass(GlobalRA& g) : gra(g)
7771
{
@@ -853,7 +847,7 @@ namespace vISA
853847
void updateDefSet(std::set<G4_Declare*>& defs, G4_Declare* referencedDcl);
854848
void detectUndefinedUses(LivenessAnalysis& liveAnalysis, G4_Kernel& kernel);
855849
void markBlockLocalVar(G4_RegVar* var, unsigned bbId);
856-
void markBlockLocalVars(Mem_Manager& mem, bool doLocalRA);
850+
void markBlockLocalVars(bool doLocalRA);
857851
void computePhyReg();
858852
void fixAlignment();
859853

@@ -1016,6 +1010,7 @@ namespace vISA
10161010
resize(dclid);
10171011
MUST_BE_TRUE(vars[dclid].localLR == NULL, "Local live range already allocated for declaration");
10181012
vars[dclid].localLR = lr;
1013+
lr->setTopDcl(dcl);
10191014
}
10201015

10211016
void resetLocalLR(G4_Declare* dcl)
@@ -1227,7 +1222,7 @@ namespace vISA
12271222
G4_Align getBankAlign(G4_Declare*);
12281223
bool areAllDefsNoMask(G4_Declare*);
12291224
void removeUnreferencedDcls();
1230-
LocalLiveRange* GetOrCreateLocalLiveRange(G4_Declare* topdcl, Mem_Manager& mem);
1225+
LocalLiveRange* GetOrCreateLocalLiveRange(G4_Declare* topdcl);
12311226

12321227
GlobalRA(G4_Kernel& k, PhyRegPool& r, PointsToAnalysis& p2a) : kernel(k), builder(*k.fg.builder), regPool(r),
12331228
pointsToAnalysis(p2a)

0 commit comments

Comments
 (0)