Path: blob/main/contrib/llvm-project/lld/MachO/SectionPriorities.h
34907 views
//===- SectionPriorities.h --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_MACHO_SECTION_PRIORITIES_H9#define LLD_MACHO_SECTION_PRIORITIES_H1011#include "InputSection.h"12#include "llvm/ADT/DenseMap.h"13#include "llvm/ADT/MapVector.h"1415namespace lld::macho {1617using SectionPair = std::pair<const InputSection *, const InputSection *>;1819class PriorityBuilder {20public:21// Reads every input section's call graph profile, and combines them into22// callGraphProfile. If an order file is present, any edges where one or both23// of the vertices are specified in the order file are discarded.24void extractCallGraphProfile();2526// Reads the order file at `path` into config->priorities.27//28// An order file has one entry per line, in the following format:29//30// <cpu>:<object file>:<symbol name>31//32// <cpu> and <object file> are optional. If not specified, then that entry33// matches any symbol of that name. Parsing this format is not quite34// straightforward because the symbol name itself can contain colons, so when35// encountering a colon, we consider the preceding characters to decide if it36// can be a valid CPU type or file path.37//38// If a symbol is matched by multiple entries, then it takes the39// lowest-ordered entry (the one nearest to the front of the list.)40//41// The file can also have line comments that start with '#'.42void parseOrderFile(StringRef path);4344// Returns layout priorities for some or all input sections. Sections are laid45// out in decreasing order; that is, a higher priority section will be closer46// to the beginning of its output section.47//48// If either an order file or a call graph profile are present, this is used49// as the source of priorities. If both are present, the order file takes50// precedence, but the call graph profile is still used for symbols that don't51// appear in the order file. If neither is present, an empty map is returned.52//53// Each section gets assigned the priority of the highest-priority symbol it54// contains.55llvm::DenseMap<const InputSection *, size_t> buildInputSectionPriorities();5657private:58// The symbol with the highest priority should be ordered first in the output59// section (modulo input section contiguity constraints). Using priority60// (highest first) instead of order (lowest first) has the convenient property61// that the default-constructed zero priority -- for symbols/sections without62// a user-defined order -- naturally ends up putting them at the end of the63// output.64struct SymbolPriorityEntry {65// The priority given to a matching symbol, regardless of which object file66// it originated from.67size_t anyObjectFile = 0;68// The priority given to a matching symbol from a particular object file.69llvm::DenseMap<llvm::StringRef, size_t> objectFiles;70};7172std::optional<size_t> getSymbolPriority(const Defined *sym);73llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;74llvm::MapVector<SectionPair, uint64_t> callGraphProfile;75};7677extern PriorityBuilder priorityBuilder;78} // namespace lld::macho7980#endif818283