@@ -423,24 +423,12 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
423
423
}
424
424
}
425
425
426
- // Now we found a bunch of sets of globals used together. We accumulated
427
- // the number of times we encountered the sets (i.e., the number of functions
428
- // that use that exact set of globals).
429
- //
430
- // Multiply that by the size of the set to give us a crude profitability
431
- // metric.
432
- llvm::stable_sort (UsedGlobalSets,
433
- [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
434
- return UGS1.Globals .count () * UGS1.UsageCount <
435
- UGS2.Globals .count () * UGS2.UsageCount ;
436
- });
437
-
438
426
// We can choose to merge all globals together, but ignore globals never used
439
427
// with another global. This catches the obviously non-profitable cases of
440
428
// having a single global, but is aggressive enough for any other case.
441
429
if (GlobalMergeIgnoreSingleUse) {
442
430
BitVector AllGlobals (Globals.size ());
443
- for (const UsedGlobalSet &UGS : llvm::reverse ( UsedGlobalSets) ) {
431
+ for (const UsedGlobalSet &UGS : UsedGlobalSets) {
444
432
if (UGS.UsageCount == 0 )
445
433
continue ;
446
434
if (UGS.Globals .count () > 1 )
@@ -449,6 +437,18 @@ bool GlobalMergeImpl::doMerge(SmallVectorImpl<GlobalVariable *> &Globals,
449
437
return doMerge (Globals, AllGlobals, M, isConst, AddrSpace);
450
438
}
451
439
440
+ // Now we found a bunch of sets of globals used together. We accumulated
441
+ // the number of times we encountered the sets (i.e., the number of functions
442
+ // that use that exact set of globals).
443
+ //
444
+ // Multiply that by the size of the set to give us a crude profitability
445
+ // metric.
446
+ llvm::stable_sort (UsedGlobalSets,
447
+ [](const UsedGlobalSet &UGS1, const UsedGlobalSet &UGS2) {
448
+ return UGS1.Globals .count () * UGS1.UsageCount <
449
+ UGS2.Globals .count () * UGS2.UsageCount ;
450
+ });
451
+
452
452
// Starting from the sets with the best (=biggest) profitability, find a
453
453
// good combination.
454
454
// The ideal (and expensive) solution can only be found by trying all
0 commit comments