--order_file, call graph profile, and BalancedPartitioning currently build the section order vector by decreasing priority (from SIZE_MAX to 0). However, it's conventional to use an increasing key (see OutputSection::inputOrder). Switch to increasing priorities, remove the global variable highestAvailablePriority, and remove the highestAvailablePriority parameter from BPSectionOrderer. Change size_t to int. This improves consistenty with the ELF and COFF ports. The ELF port utilizes negative priorities for --symbol-ordering-file and call graph profile, and non-negative priorities for --shuffle-sections (no Mach-O counterpart yet). Pull Request: https://github.com/llvm/llvm-project/pull/121727
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
//===- BPSectionOrderer.cpp -----------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "BPSectionOrderer.h"
|
|
#include "InputSection.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#define DEBUG_TYPE "bp-section-orderer"
|
|
|
|
using namespace llvm;
|
|
using namespace lld::macho;
|
|
|
|
DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
|
|
StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
|
|
bool compressionSortStartupFunctions, bool verbose) {
|
|
|
|
SmallVector<std::unique_ptr<BPSectionBase>> sections;
|
|
for (const auto *file : inputFiles) {
|
|
for (auto *sec : file->sections) {
|
|
for (auto &subsec : sec->subsections) {
|
|
auto *isec = subsec.isec;
|
|
if (!isec || isec->data.empty() || !isec->data.data())
|
|
continue;
|
|
sections.emplace_back(
|
|
std::make_unique<BPSectionMacho>(isec, sections.size()));
|
|
}
|
|
}
|
|
}
|
|
|
|
auto reorderedSections = BPSectionBase::reorderSectionsByBalancedPartitioning(
|
|
profilePath, forFunctionCompression, forDataCompression,
|
|
compressionSortStartupFunctions, verbose, sections);
|
|
|
|
DenseMap<const InputSection *, int> result;
|
|
for (const auto &[sec, priority] : reorderedSections) {
|
|
if (auto *machoSection = dyn_cast<BPSectionMacho>(sec)) {
|
|
result.try_emplace(
|
|
static_cast<const InputSection *>(machoSection->getSection()),
|
|
priority);
|
|
}
|
|
}
|
|
return result;
|
|
}
|