@@ -245,6 +245,13 @@ bool isKernelLDS(const Function *F) {
245
245
return AMDGPU::isKernel (F->getCallingConv ());
246
246
}
247
247
248
+ template <typename T> std::vector<T> sortByName (std::vector<T> &&V) {
249
+ llvm::sort (V.begin (), V.end (), [](const auto *L, const auto *R) {
250
+ return L->getName () < R->getName ();
251
+ });
252
+ return {std::move (V)};
253
+ }
254
+
248
255
class AMDGPULowerModuleLDS : public ModulePass {
249
256
250
257
static void
@@ -733,10 +740,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
733
740
}
734
741
735
742
// Put them in an arbitrary but reproducible order
736
- llvm::sort (OrderedKernels.begin (), OrderedKernels.end (),
737
- [](const Function *lhs, const Function *rhs) -> bool {
738
- return lhs->getName () < rhs->getName ();
739
- });
743
+ OrderedKernels = sortByName (std::move (OrderedKernels));
740
744
741
745
// Annotate the kernels with their order in this vector
742
746
LLVMContext &Ctx = M->getContext ();
@@ -1185,13 +1189,8 @@ class AMDGPULowerModuleLDS : public ModulePass {
1185
1189
1186
1190
// The order must be consistent between lookup table and accesses to
1187
1191
// lookup table
1188
- std::vector<GlobalVariable *> TableLookupVariablesOrdered (
1189
- TableLookupVariables.begin (), TableLookupVariables.end ());
1190
- llvm::sort (TableLookupVariablesOrdered.begin (),
1191
- TableLookupVariablesOrdered.end (),
1192
- [](const GlobalVariable *lhs, const GlobalVariable *rhs) {
1193
- return lhs->getName () < rhs->getName ();
1194
- });
1192
+ auto TableLookupVariablesOrdered = sortByName (std::vector (
1193
+ TableLookupVariables.begin (), TableLookupVariables.end ()));
1195
1194
1196
1195
GlobalVariable *LookupTable = buildLookupTable (
1197
1196
M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
@@ -1338,12 +1337,9 @@ class AMDGPULowerModuleLDS : public ModulePass {
1338
1337
// The order of fields in this struct depends on the order of
1339
1338
// varables in the argument which varies when changing how they
1340
1339
// are identified, leading to spurious test breakage.
1341
- std::vector<GlobalVariable *> Sorted (LDSVarsToTransform.begin (),
1342
- LDSVarsToTransform.end ());
1343
- llvm::sort (Sorted.begin (), Sorted.end (),
1344
- [](const GlobalVariable *lhs, const GlobalVariable *rhs) {
1345
- return lhs->getName () < rhs->getName ();
1346
- });
1340
+ auto Sorted = sortByName (
1341
+ std::vector (LDSVarsToTransform.begin (), LDSVarsToTransform.end ()));
1342
+
1347
1343
for (GlobalVariable *GV : Sorted) {
1348
1344
OptimizedStructLayoutField F (GV,
1349
1345
DL.getTypeAllocSize (GV->getValueType ()),
@@ -1424,19 +1420,15 @@ class AMDGPULowerModuleLDS : public ModulePass {
1424
1420
template <typename PredicateTy>
1425
1421
static void replaceLDSVariablesWithStruct (
1426
1422
Module &M, DenseSet<GlobalVariable *> const &LDSVarsToTransformArg,
1427
- LDSVariableReplacement Replacement, PredicateTy Predicate) {
1423
+ const LDSVariableReplacement & Replacement, PredicateTy Predicate) {
1428
1424
LLVMContext &Ctx = M.getContext ();
1429
1425
const DataLayout &DL = M.getDataLayout ();
1430
1426
1431
1427
// A hack... we need to insert the aliasing info in a predictable order for
1432
1428
// lit tests. Would like to have them in a stable order already, ideally the
1433
1429
// same order they get allocated, which might mean an ordered set container
1434
- std::vector<GlobalVariable *> LDSVarsToTransform (
1435
- LDSVarsToTransformArg.begin (), LDSVarsToTransformArg.end ());
1436
- llvm::sort (LDSVarsToTransform.begin (), LDSVarsToTransform.end (),
1437
- [](const GlobalVariable *lhs, const GlobalVariable *rhs) {
1438
- return lhs->getName () < rhs->getName ();
1439
- });
1430
+ std::vector<GlobalVariable *> LDSVarsToTransform = sortByName (std::vector (
1431
+ LDSVarsToTransformArg.begin (), LDSVarsToTransformArg.end ()));
1440
1432
1441
1433
// Create alias.scope and their lists. Each field in the new structure
1442
1434
// does not alias with all other fields.
@@ -1458,7 +1450,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
1458
1450
// field of the instance that will be allocated by AMDGPUMachineFunction
1459
1451
for (size_t I = 0 ; I < NumberVars; I++) {
1460
1452
GlobalVariable *GV = LDSVarsToTransform[I];
1461
- Constant *GEP = Replacement.LDSVarsToConstantGEP [GV] ;
1453
+ Constant *GEP = Replacement.LDSVarsToConstantGEP . at (GV) ;
1462
1454
1463
1455
GV->replaceUsesWithIf (GEP, Predicate);
1464
1456
0 commit comments