@@ -256,18 +256,11 @@ namespace {
256
256
Use *UseInDest;
257
257
unsigned SourceIndex;
258
258
unsigned Priority;
259
- unsigned Serial;
260
259
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 ; }
271
264
};
272
265
273
266
struct PhiCopy {
@@ -473,8 +466,9 @@ bool GenXCoalescing::runOnFunctionGroup(FunctionGroup &FG)
473
466
recordCallCandidates (&FG);
474
467
475
468
// 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 ());
478
472
for (unsigned i = 0 ; i != NormalCandidates.size (); ++i)
479
473
processCandidate (&NormalCandidates[i]);
480
474
@@ -787,8 +781,8 @@ void GenXCoalescing::recordCallArgCandidates(Value *Dest, unsigned ArgNum,
787
781
SmallVector<CallArg, 8 > CallArgs;
788
782
for (unsigned i = 0 , ie = Insts.size (); i != ie; ++i) {
789
783
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)));
792
786
}
793
787
for (unsigned i = 0 , ie = CallArgs.size (); i != ie; ++i) {
794
788
LiveRange *LR = CallArgs[i].LR ;
@@ -867,8 +861,7 @@ void GenXCoalescing::recordCandidate(SimpleValue Dest, Use *UseInDest,
867
861
if (UseInDest && isa<UndefValue>(*UseInDest))
868
862
return ;
869
863
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);
872
865
}
873
866
874
867
/* **********************************************************************
@@ -1048,9 +1041,8 @@ void GenXCoalescing::processCandidate(Candidate *Cand, bool IsCopy)
1048
1041
1049
1042
// Store info for two address op copy
1050
1043
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 ());
1054
1046
}
1055
1047
1056
1048
/* **********************************************************************
@@ -1133,7 +1125,7 @@ void GenXCoalescing::analysePhiCopies(PHINode *Phi,
1133
1125
LLVM_DEBUG (dbgs () << " Need phi copy " << Incoming->getName () << " -> "
1134
1126
<< Phi->getName () << " in " << IncomingBlock->getName ()
1135
1127
<< " \n " );
1136
- ToProcess.push_back ( PhiCopy ( Phi, i) );
1128
+ ToProcess.emplace_back ( Phi, i);
1137
1129
}
1138
1130
}
1139
1131
@@ -1180,9 +1172,9 @@ void GenXCoalescing::processPhiCopy(PHINode *Phi, unsigned Inc,
1180
1172
}
1181
1173
1182
1174
// 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 ());
1186
1178
}
1187
1179
1188
1180
/* **********************************************************************
@@ -1240,10 +1232,10 @@ void GenXCoalescing::processPhiBranchingJoinLabelCopy(
1240
1232
}
1241
1233
1242
1234
// 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 ());
1247
1239
}
1248
1240
1249
1241
/* **********************************************************************
@@ -1523,7 +1515,7 @@ void GenXCoalescing::processKernelArgs(FunctionGroup *FG)
1523
1515
**ui = Copy;
1524
1516
auto NewLR = Liveness->getOrCreateLiveRange (Arg);
1525
1517
NewLR->setCategory (LR->getCategory ());
1526
- NewLR->push_back (Segment ( Numbering->getNumber (F), Num) );
1518
+ NewLR->push_back (Numbering->getNumber (F), Num);
1527
1519
NewLR->Offset = LR->Offset ;
1528
1520
LR->Offset = 0 ;
1529
1521
}
0 commit comments