@@ -38,9 +38,6 @@ using namespace lld::macho;
38
38
PriorityBuilder macho::priorityBuilder;
39
39
40
40
namespace {
41
-
42
- size_t highestAvailablePriority = std::numeric_limits<size_t >::max();
43
-
44
41
struct Edge {
45
42
int from;
46
43
uint64_t weight;
@@ -67,7 +64,7 @@ class CallGraphSort {
67
64
public:
68
65
CallGraphSort (const MapVector<SectionPair, uint64_t > &profile);
69
66
70
- DenseMap<const InputSection *, size_t > run ();
67
+ DenseMap<const InputSection *, int > run ();
71
68
72
69
private:
73
70
std::vector<Cluster> clusters;
@@ -157,7 +154,7 @@ static void mergeClusters(std::vector<Cluster> &cs, Cluster &into, int intoIdx,
157
154
158
155
// Group InputSections into clusters using the Call-Chain Clustering heuristic
159
156
// then sort the clusters by density.
160
- DenseMap<const InputSection *, size_t > CallGraphSort::run () {
157
+ DenseMap<const InputSection *, int > CallGraphSort::run () {
161
158
const uint64_t maxClusterSize = target->getPageSize ();
162
159
163
160
// Cluster indices sorted by density.
@@ -205,16 +202,14 @@ DenseMap<const InputSection *, size_t> CallGraphSort::run() {
205
202
return clusters[a].getDensity () > clusters[b].getDensity ();
206
203
});
207
204
208
- DenseMap<const InputSection *, size_t > orderMap;
205
+ DenseMap<const InputSection *, int > orderMap;
209
206
210
207
// Sections will be sorted by decreasing order. Absent sections will have
211
208
// priority 0 and be placed at the end of sections.
212
- // NB: This is opposite from COFF/ELF to be compatible with the existing
213
- // order-file code.
214
- int curOrder = highestAvailablePriority;
209
+ int curOrder = -clusters.size ();
215
210
for (int leader : sorted) {
216
211
for (int i = leader;;) {
217
- orderMap[sections[i]] = curOrder-- ;
212
+ orderMap[sections[i]] = curOrder++ ;
218
213
i = clusters[i].next ;
219
214
if (i == leader)
220
215
break ;
@@ -250,7 +245,7 @@ DenseMap<const InputSection *, size_t> CallGraphSort::run() {
250
245
return orderMap;
251
246
}
252
247
253
- std::optional<size_t >
248
+ std::optional<int >
254
249
macho::PriorityBuilder::getSymbolPriority (const Defined *sym) {
255
250
if (sym->isAbsolute ())
256
251
return std::nullopt ;
@@ -270,7 +265,7 @@ macho::PriorityBuilder::getSymbolPriority(const Defined *sym) {
270
265
else
271
266
filename = saver ().save (path::filename (f->archiveName ) + " (" +
272
267
path::filename (f->getName ()) + " )" );
273
- return std::max (entry.objectFiles .lookup (filename), entry.anyObjectFile );
268
+ return std::min (entry.objectFiles .lookup (filename), entry.anyObjectFile );
274
269
}
275
270
276
271
void macho::PriorityBuilder::extractCallGraphProfile () {
@@ -302,6 +297,7 @@ void macho::PriorityBuilder::parseOrderFile(StringRef path) {
302
297
return ;
303
298
}
304
299
300
+ int prio = std::numeric_limits<int >::min ();
305
301
MemoryBufferRef mbref = *buffer;
306
302
for (StringRef line : args::getLines (mbref)) {
307
303
StringRef objectFile, symbol;
@@ -339,25 +335,22 @@ void macho::PriorityBuilder::parseOrderFile(StringRef path) {
339
335
if (!symbol.empty ()) {
340
336
SymbolPriorityEntry &entry = priorities[symbol];
341
337
if (!objectFile.empty ())
342
- entry.objectFiles .insert (
343
- std::make_pair (objectFile, highestAvailablePriority));
338
+ entry.objectFiles .insert (std::make_pair (objectFile, prio));
344
339
else
345
- entry.anyObjectFile =
346
- std::max (entry.anyObjectFile , highestAvailablePriority);
340
+ entry.anyObjectFile = std::min (entry.anyObjectFile , prio);
347
341
}
348
342
349
- --highestAvailablePriority ;
343
+ ++prio ;
350
344
}
351
345
}
352
346
353
- DenseMap<const InputSection *, size_t >
347
+ DenseMap<const InputSection *, int >
354
348
macho::PriorityBuilder::buildInputSectionPriorities () {
355
- DenseMap<const InputSection *, size_t > sectionPriorities;
349
+ DenseMap<const InputSection *, int > sectionPriorities;
356
350
if (config->bpStartupFunctionSort || config->bpFunctionOrderForCompression ||
357
351
config->bpDataOrderForCompression ) {
358
352
TimeTraceScope timeScope (" Balanced Partitioning Section Orderer" );
359
353
sectionPriorities = runBalancedPartitioning (
360
- highestAvailablePriority,
361
354
config->bpStartupFunctionSort ? config->irpgoProfilePath : " " ,
362
355
config->bpFunctionOrderForCompression ,
363
356
config->bpDataOrderForCompression ,
@@ -378,11 +371,11 @@ macho::PriorityBuilder::buildInputSectionPriorities() {
378
371
return sectionPriorities;
379
372
380
373
auto addSym = [&](const Defined *sym) {
381
- std::optional<size_t > symbolPriority = getSymbolPriority (sym);
374
+ std::optional<int > symbolPriority = getSymbolPriority (sym);
382
375
if (!symbolPriority)
383
376
return ;
384
- size_t &priority = sectionPriorities[sym->isec ()];
385
- priority = std::max (priority, *symbolPriority);
377
+ int &priority = sectionPriorities[sym->isec ()];
378
+ priority = std::min (priority, *symbolPriority);
386
379
};
387
380
388
381
// TODO: Make sure this handles weak symbols correctly.
0 commit comments