mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 19:46:06 +00:00

PR #117514 refactored BPSectionOrderer to be used by the ELF port but introduced some inefficiency: * BPSectionBase/BPSymbol are wrappers around a single pointer. The numbers of sections and symbols could be huge, and the extra allocations are memory inefficient. * Reconstructing the returned DenseMap (since BPSectionBase != InputSectin) is wasteful. This patch refactors BPSectionOrderer with Curiously Recurring Template Pattern and eliminates the inefficiency. In addition, `symbolToSectionIdxs` is removed and `rootSymbolToSectionIdxs` building is moved to lld/MachO: while getting sections for symbols is cheap in Mach-O, it is awkward and inefficient in the ELF port. While here, add a file-level comment and replace some `StringMap<*>` (which copies strings) with `DenseMap<CachedHashStringRef, *>`. Pull Request: https://github.com/llvm/llvm-project/pull/124482
36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
//===- BPSectionOrderer.h -------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// This file uses Balanced Partitioning to order sections to improve startup
|
|
/// time and compressed size.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_MACHO_BPSECTION_ORDERER_H
|
|
#define LLD_MACHO_BPSECTION_ORDERER_H
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
namespace lld::macho {
|
|
class InputSection;
|
|
|
|
/// Run Balanced Partitioning to find the optimal function and data order to
|
|
/// improve startup time and compressed size.
|
|
///
|
|
/// It is important that .subsections_via_symbols is used to ensure functions
|
|
/// and data are in their own sections and thus can be reordered.
|
|
llvm::DenseMap<const InputSection *, int>
|
|
runBalancedPartitioning(llvm::StringRef profilePath,
|
|
bool forFunctionCompression, bool forDataCompression,
|
|
bool compressionSortStartupFunctions, bool verbose);
|
|
|
|
} // namespace lld::macho
|
|
|
|
#endif
|