xref: /freebsd/contrib/llvm-project/lld/MachO/SectionPriorities.h (revision 84823cc70824c8d842f503d8c2e6d7b0c2d95b61)
1 //===- SectionPriorities.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_MACHO_SECTION_PRIORITIES_H
10 #define LLD_MACHO_SECTION_PRIORITIES_H
11 
12 #include "InputSection.h"
13 #include "llvm/ADT/DenseMap.h"
14 
15 namespace lld {
16 namespace macho {
17 
18 // Reads every input section's call graph profile, and combines them into
19 // config->callGraphProfile. If an order file is present, any edges where one
20 // or both of the vertices are specified in the order file are discarded.
21 void extractCallGraphProfile();
22 
23 // Reads the order file at `path` into config->priorities.
24 //
25 // An order file has one entry per line, in the following format:
26 //
27 //   <cpu>:<object file>:<symbol name>
28 //
29 // <cpu> and <object file> are optional. If not specified, then that entry
30 // matches any symbol of that name. Parsing this format is not quite
31 // straightforward because the symbol name itself can contain colons, so when
32 // encountering a colon, we consider the preceding characters to decide if it
33 // can be a valid CPU type or file path.
34 //
35 // If a symbol is matched by multiple entries, then it takes the lowest-ordered
36 // entry (the one nearest to the front of the list.)
37 //
38 // The file can also have line comments that start with '#'.
39 void parseOrderFile(StringRef path);
40 
41 // Returns layout priorities for some or all input sections. Sections are laid
42 // out in decreasing order; that is, a higher priority section will be closer
43 // to the beginning of its output section.
44 //
45 // If either an order file or a call graph profile are present, this is used
46 // as the source of priorities. If both are present, the order file takes
47 // precedence. If neither is present, an empty map is returned.
48 //
49 // Each section gets assigned the priority of the highest-priority symbol it
50 // contains.
51 llvm::DenseMap<const InputSection *, size_t> buildInputSectionPriorities();
52 } // namespace macho
53 } // namespace lld
54 
55 #endif
56