Skip to content

Commit 9c2f5bd

Browse files
committed
Simplify
1 parent 4dd0768 commit 9c2f5bd

File tree

3 files changed

+74
-78
lines changed

3 files changed

+74
-78
lines changed

lld/ELF/BPSectionOrderer.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "lld/Common/BPSectionOrdererBase.inc"
1515
#include "llvm/Support/Endian.h"
1616

17-
#define DEBUG_TYPE "bp-section-orderer"
18-
1917
using namespace llvm;
2018
using namespace lld::elf;
2119

@@ -86,24 +84,22 @@ DenseMap<const InputSectionBase *, int> lld::elf::runBalancedPartitioning(
8684
DenseSet<const InputSectionBase *> seenSections;
8785

8886
auto addSection = [&](Symbol &sym) {
89-
if (sym.getSize() == 0)
87+
auto *d = dyn_cast<Defined>(&sym);
88+
if (!d || d->size == 0)
9089
return;
91-
if (auto *d = dyn_cast<Defined>(&sym))
92-
if (auto *sec = dyn_cast_or_null<InputSectionBase>(d->section))
93-
if (seenSections.insert(sec).second) {
94-
size_t idx = sections.size();
95-
sections.emplace_back(sec);
96-
auto rootName = getRootSymbol(sym.getName());
97-
rootSymbolToSectionIdxs[CachedHashStringRef(rootName)].insert(idx);
98-
if (auto linkageName = BPOrdererELF::getResolvedLinkageName(rootName))
99-
rootSymbolToSectionIdxs[CachedHashStringRef(*linkageName)].insert(
100-
idx);
101-
}
90+
auto *sec = dyn_cast_or_null<InputSectionBase>(d->section);
91+
if (!sec)
92+
return;
93+
if (seenSections.insert(sec).second) {
94+
size_t idx = sections.size();
95+
sections.emplace_back(sec);
96+
rootSymbolToSectionIdxs[CachedHashStringRef(getRootSymbol(sym.getName()))]
97+
.insert(idx);
98+
}
10299
};
103100

104101
for (Symbol *sym : ctx.symtab->getSymbols())
105102
addSection(*sym);
106-
107103
for (ELFFileBase *file : ctx.objectFiles)
108104
for (Symbol *sym : file->getLocalSymbols())
109105
addSection(*sym);

lld/ELF/Driver.cpp

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,59 @@ static CGProfileSortKind getCGProfileSortKind(Ctx &ctx,
11181118
return CGProfileSortKind::None;
11191119
}
11201120

1121+
static void parseBPOrdererOptions(Ctx &ctx, opt::InputArgList &args) {
1122+
if (auto *arg = args.getLastArg(OPT_bp_startup_sort)) {
1123+
StringRef startupSortStr = arg->getValue();
1124+
if (startupSortStr == "function") {
1125+
ctx.arg.bpStartupFunctionSort = true;
1126+
} else if (startupSortStr != "none") {
1127+
ErrAlways(ctx) << "unknown value '" + startupSortStr + "' for " +
1128+
arg->getSpelling();
1129+
}
1130+
if (startupSortStr != "none")
1131+
if (args.hasArg(OPT_call_graph_ordering_file))
1132+
ErrAlways(ctx) << "--bp-startup-sort=function is incompatible with "
1133+
"--call-graph-ordering-file";
1134+
}
1135+
ctx.arg.bpCompressionSortStartupFunctions =
1136+
args.hasFlag(OPT_bp_compression_sort_startup_functions,
1137+
OPT_no_bp_compression_sort_startup_functions, false);
1138+
1139+
ctx.arg.irpgoProfilePath = args.getLastArgValue(OPT_irpgo_profile);
1140+
if (ctx.arg.irpgoProfilePath.empty()) {
1141+
if (ctx.arg.bpStartupFunctionSort)
1142+
ErrAlways(ctx) << "--bp-startup-sort=function must be used with "
1143+
"--irpgo-profile";
1144+
if (ctx.arg.bpCompressionSortStartupFunctions)
1145+
ErrAlways(ctx)
1146+
<< "--bp-compression-sort-startup-functions must be used with "
1147+
"--irpgo-profile";
1148+
}
1149+
1150+
if (auto *arg = args.getLastArg(OPT_bp_compression_sort)) {
1151+
StringRef s = arg->getValue();
1152+
if (s == "function") {
1153+
ctx.arg.bpFunctionOrderForCompression = true;
1154+
} else if (s == "data") {
1155+
ctx.arg.bpDataOrderForCompression = true;
1156+
} else if (s == "both") {
1157+
ctx.arg.bpFunctionOrderForCompression = true;
1158+
ctx.arg.bpDataOrderForCompression = true;
1159+
} else if (s != "none") {
1160+
ErrAlways(ctx) << "unknown value '" + s + "' for " +
1161+
arg->getSpelling();
1162+
}
1163+
if (ctx.arg.bpDataOrderForCompression ||
1164+
ctx.arg.bpFunctionOrderForCompression) {
1165+
if (args.getLastArg(OPT_call_graph_ordering_file) != nullptr) {
1166+
ErrAlways(ctx) << "--bp-compression-sort is incompatible with "
1167+
"--call-graph-ordering-file";
1168+
}
1169+
}
1170+
}
1171+
ctx.arg.bpVerboseSectionOrderer = args.hasArg(OPT_verbose_bp_section_orderer);
1172+
}
1173+
11211174
static DebugCompressionType getCompressionType(Ctx &ctx, StringRef s,
11221175
StringRef option) {
11231176
DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
@@ -1259,55 +1312,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
12591312
ctx.arg.bsymbolic = BsymbolicKind::All;
12601313
}
12611314
ctx.arg.callGraphProfileSort = getCGProfileSortKind(ctx, args);
1262-
ctx.arg.irpgoProfilePath = args.getLastArgValue(OPT_irpgo_profile);
1263-
ctx.arg.bpCompressionSortStartupFunctions =
1264-
args.hasFlag(OPT_bp_compression_sort_startup_functions,
1265-
OPT_no_bp_compression_sort_startup_functions, false);
1266-
if (auto *arg = args.getLastArg(OPT_bp_startup_sort)) {
1267-
StringRef startupSortStr = arg->getValue();
1268-
if (startupSortStr == "function") {
1269-
ctx.arg.bpStartupFunctionSort = true;
1270-
} else if (startupSortStr != "none") {
1271-
ErrAlways(ctx) << "unknown value '" + startupSortStr + "' for " +
1272-
arg->getSpelling();
1273-
}
1274-
if (startupSortStr != "none")
1275-
if (args.hasArg(OPT_call_graph_ordering_file))
1276-
ErrAlways(ctx) << "--bp-startup-sort=function is incompatible with "
1277-
"--call-graph-ordering-file";
1278-
}
1279-
if (ctx.arg.irpgoProfilePath.empty()) {
1280-
if (ctx.arg.bpStartupFunctionSort)
1281-
ErrAlways(ctx) << "--bp-startup-sort=function must be used with "
1282-
"--irpgo-profile";
1283-
if (ctx.arg.bpCompressionSortStartupFunctions)
1284-
ErrAlways(ctx)
1285-
<< "--bp-compression-sort-startup-functions must be used with "
1286-
"--irpgo-profile";
1287-
}
1288-
1289-
if (auto *arg = args.getLastArg(OPT_bp_compression_sort)) {
1290-
StringRef compressionSortStr = arg->getValue();
1291-
if (compressionSortStr == "function") {
1292-
ctx.arg.bpFunctionOrderForCompression = true;
1293-
} else if (compressionSortStr == "data") {
1294-
ctx.arg.bpDataOrderForCompression = true;
1295-
} else if (compressionSortStr == "both") {
1296-
ctx.arg.bpFunctionOrderForCompression = true;
1297-
ctx.arg.bpDataOrderForCompression = true;
1298-
} else if (compressionSortStr != "none") {
1299-
ErrAlways(ctx) << "unknown value '" + compressionSortStr + "' for " +
1300-
arg->getSpelling();
1301-
}
1302-
if (ctx.arg.bpDataOrderForCompression ||
1303-
ctx.arg.bpFunctionOrderForCompression) {
1304-
if (args.getLastArg(OPT_call_graph_ordering_file) != nullptr) {
1305-
ErrAlways(ctx) << "--bp-compression-sort is incompatible with "
1306-
"--call-graph-ordering-file";
1307-
}
1308-
}
1309-
}
1310-
ctx.arg.bpVerboseSectionOrderer = args.hasArg(OPT_verbose_bp_section_orderer);
1315+
parseBPOrdererOptions(ctx, args);
13111316
ctx.arg.checkSections =
13121317
args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);
13131318
ctx.arg.chroot = args.getLastArgValue(OPT_chroot);

lld/ELF/Options.td

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,18 @@ def : FF<"no-call-graph-profile-sort">, Alias<call_graph_profile_sort>, AliasArg
142142
Flags<[HelpHidden]>;
143143

144144
defm irpgo_profile: EEq<"irpgo-profile",
145-
"Read the IRPGO profile for use with -bp-startup-sort and other profile-guided optimizations">;
146-
147-
def bp_startup_sort: JJ<"bp-startup-sort=">,
148-
MetaVarName<"[none,function]">,
149-
HelpText<"Order sections based on profile data to improve startup time">;
145+
"Read a temporary profile file for use with --bp-startup-sort=">;
146+
def bp_compression_sort: JJ<"bp-compression-sort=">, MetaVarName<"[none,function,data,both]">,
147+
HelpText<"Improve Lempel-Ziv compression by grouping similar sections together, resulting in a smaller compressed app size">;
148+
def bp_startup_sort: JJ<"bp-startup-sort=">, MetaVarName<"[none,function]">,
149+
HelpText<"Utilize a temporal profile file to reduce page faults during program startup">;
150150

151+
// Auxiliary options related to balanced partition
151152
defm bp_compression_sort_startup_functions: BB<"bp-compression-sort-startup-functions",
152-
"Order startup functions by balanced partition to improve compressed size in addition to startup time",
153-
"Do not order startup function for compression">;
154-
155-
def bp_compression_sort: JJ<"bp-compression-sort=">,
156-
MetaVarName<"[none,function,data,both]">,
157-
HelpText<"Order sections by balanced partition to improve compressed size">;
158-
153+
"When --irpgo-profile is pecified, prioritize function similarity for compression in addition to startup time", "">;
159154
def verbose_bp_section_orderer: FF<"verbose-bp-section-orderer">,
160-
HelpText<"Print information on how many sections were ordered by balanced partitioning and a measure of the expected number of page faults">;
161-
155+
HelpText<"Print information on balanced partitioning">;
156+
162157
// --chroot doesn't have a help text because it is an internal option.
163158
def chroot: Separate<["--"], "chroot">;
164159

0 commit comments

Comments
 (0)