Skip to content

Commit e80b105

Browse files
skachkov-inteligcbot
authored andcommitted
Use stable_sort instead of manual
sequentional numbers assigned
1 parent 679efc8 commit e80b105

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXCoalescing.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,11 @@ namespace {
256256
Use *UseInDest;
257257
unsigned SourceIndex;
258258
unsigned Priority;
259-
unsigned Serial;
260259
Candidate(SimpleValue Dest, Use *UseInDest, unsigned SourceIndex,
261-
unsigned Priority, unsigned Serial)
262-
: Dest(Dest), UseInDest(UseInDest), SourceIndex(SourceIndex),
263-
Priority(Priority), Serial(Serial) {}
264-
bool operator<(const Candidate &C2) const {
265-
if (Priority != C2.Priority)
266-
return Priority > C2.Priority;
267-
// Make the sort order preserving for equal priority, to get consistent
268-
// results across different runs.
269-
return Serial < C2.Serial;
270-
}
260+
unsigned Priority)
261+
: Dest(Dest), UseInDest(UseInDest), SourceIndex(SourceIndex),
262+
Priority(Priority) {}
263+
bool operator<(const Candidate &C2) const { return Priority > C2.Priority; }
271264
};
272265

273266
struct PhiCopy {
@@ -473,8 +466,9 @@ bool GenXCoalescing::runOnFunctionGroup(FunctionGroup &FG)
473466
recordCallCandidates(&FG);
474467

475468
// Sort the array of normal coalescing candidates (including phi ones) then
476-
// process them.
477-
std::sort(NormalCandidates.begin(), NormalCandidates.end());
469+
// process them. Preserve original ordering for equal priority candidates
470+
// to get consistent results across different runs.
471+
std::stable_sort(NormalCandidates.begin(), NormalCandidates.end());
478472
for (unsigned i = 0; i != NormalCandidates.size(); ++i)
479473
processCandidate(&NormalCandidates[i]);
480474

@@ -787,8 +781,8 @@ void GenXCoalescing::recordCallArgCandidates(Value *Dest, unsigned ArgNum,
787781
SmallVector<CallArg, 8> CallArgs;
788782
for (unsigned i = 0, ie = Insts.size(); i != ie; ++i) {
789783
Use *U = &Insts[i]->getOperandUse(ArgNum);
790-
CallArgs.push_back(CallArg(U,
791-
Liveness->getLiveRangeOrNull(SimpleValue(*U, StructIdx))));
784+
CallArgs.emplace_back(
785+
U, Liveness->getLiveRangeOrNull(SimpleValue(*U, StructIdx)));
792786
}
793787
for (unsigned i = 0, ie = CallArgs.size(); i != ie; ++i) {
794788
LiveRange *LR = CallArgs[i].LR;
@@ -867,8 +861,7 @@ void GenXCoalescing::recordCandidate(SimpleValue Dest, Use *UseInDest,
867861
if (UseInDest && isa<UndefValue>(*UseInDest))
868862
return;
869863
IGC_ASSERT(!UseInDest || !isa<Constant>(*UseInDest));
870-
Candidates->push_back(Candidate(Dest, UseInDest, SourceIndex, Priority,
871-
Candidates->size()));
864+
Candidates->emplace_back(Dest, UseInDest, SourceIndex, Priority);
872865
}
873866

874867
/***********************************************************************
@@ -1048,9 +1041,8 @@ void GenXCoalescing::processCandidate(Candidate *Cand, bool IsCopy)
10481041

10491042
// Store info for two address op copy
10501043
Instruction *DestInst = cast<Instruction>(Dest.getValue());
1051-
ToCopy.push_back(CopyData(Dest, Source, Cand->UseInDest, DestInst,
1052-
TWOADDRCOPY, Numbering->getNumber(DestInst),
1053-
ToCopy.size()));
1044+
ToCopy.emplace_back(Dest, Source, Cand->UseInDest, DestInst, TWOADDRCOPY,
1045+
Numbering->getNumber(DestInst), ToCopy.size());
10541046
}
10551047

10561048
/***********************************************************************
@@ -1133,7 +1125,7 @@ void GenXCoalescing::analysePhiCopies(PHINode *Phi,
11331125
LLVM_DEBUG(dbgs() << "Need phi copy " << Incoming->getName() << " -> "
11341126
<< Phi->getName() << " in " << IncomingBlock->getName()
11351127
<< "\n");
1136-
ToProcess.push_back(PhiCopy(Phi, i));
1128+
ToProcess.emplace_back(Phi, i);
11371129
}
11381130
}
11391131

@@ -1180,9 +1172,9 @@ void GenXCoalescing::processPhiCopy(PHINode *Phi, unsigned Inc,
11801172
}
11811173

11821174
// Store info for copy
1183-
ToCopy.push_back(CopyData(SimpleValue(Phi), SimpleValue(Incoming),
1184-
&Phi->getOperandUse(Inc), InsertPoint, PHICOPY,
1185-
Numbering->getNumber(InsertPoint), ToCopy.size()));
1175+
ToCopy.emplace_back(SimpleValue(Phi), SimpleValue(Incoming),
1176+
&Phi->getOperandUse(Inc), InsertPoint, PHICOPY,
1177+
Numbering->getNumber(InsertPoint), ToCopy.size());
11861178
}
11871179

11881180
/***********************************************************************
@@ -1240,10 +1232,10 @@ void GenXCoalescing::processPhiBranchingJoinLabelCopy(
12401232
}
12411233

12421234
// Store info for copy
1243-
ToCopy.push_back(CopyData(SimpleValue(Phi), SimpleValue(Incoming),
1244-
&Phi->getOperandUse(Inc), InsertPoint,
1245-
PHICOPY_BRANCHING_JP,
1246-
Numbering->getNumber(InsertPoint), ToCopy.size()));
1235+
ToCopy.emplace_back(SimpleValue(Phi), SimpleValue(Incoming),
1236+
&Phi->getOperandUse(Inc), InsertPoint,
1237+
PHICOPY_BRANCHING_JP, Numbering->getNumber(InsertPoint),
1238+
ToCopy.size());
12471239
}
12481240

12491241
/***********************************************************************
@@ -1523,7 +1515,7 @@ void GenXCoalescing::processKernelArgs(FunctionGroup *FG)
15231515
**ui = Copy;
15241516
auto NewLR = Liveness->getOrCreateLiveRange(Arg);
15251517
NewLR->setCategory(LR->getCategory());
1526-
NewLR->push_back(Segment(Numbering->getNumber(F), Num));
1518+
NewLR->push_back(Numbering->getNumber(F), Num);
15271519
NewLR->Offset = LR->Offset;
15281520
LR->Offset = 0;
15291521
}

0 commit comments

Comments
 (0)