Skip to content

Commit f3c4b58

Browse files
committed
Revert "[ELF] Add BPSectionOrderer options (#120514)"
The ELF/bp-section-orderer.s test is failing on some buildbots due to what seems like non-determinism issues, see comments on the original PR and #125450 Reverting to green the build. This reverts commit 0154dce and follow-up commits 046dd4b and c92f204.
1 parent 6a2ce34 commit f3c4b58

11 files changed

+10
-667
lines changed

lld/ELF/BPSectionOrderer.cpp

-95
This file was deleted.

lld/ELF/BPSectionOrderer.h

-37
This file was deleted.

lld/ELF/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ add_lld_library(lldELF
3737
Arch/X86.cpp
3838
Arch/X86_64.cpp
3939
ARMErrataFix.cpp
40-
BPSectionOrderer.cpp
4140
CallGraphSort.cpp
4241
DWARF.cpp
4342
Driver.cpp
@@ -73,7 +72,6 @@ add_lld_library(lldELF
7372
Object
7473
Option
7574
Passes
76-
ProfileData
7775
Support
7876
TargetParser
7977
TransformUtils

lld/ELF/Config.h

-6
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,6 @@ struct Config {
264264
bool armBe8 = false;
265265
BsymbolicKind bsymbolic = BsymbolicKind::None;
266266
CGProfileSortKind callGraphProfileSort;
267-
llvm::StringRef irpgoProfilePath;
268-
bool bpStartupFunctionSort = false;
269-
bool bpCompressionSortStartupFunctions = false;
270-
bool bpFunctionOrderForCompression = false;
271-
bool bpDataOrderForCompression = false;
272-
bool bpVerboseSectionOrderer = false;
273267
bool checkSections;
274268
bool checkDynamicRelocs;
275269
std::optional<llvm::DebugCompressionType> compressDebugSections;

lld/ELF/Driver.cpp

-48
Original file line numberDiff line numberDiff line change
@@ -1121,53 +1121,6 @@ static CGProfileSortKind getCGProfileSortKind(Ctx &ctx,
11211121
return CGProfileSortKind::None;
11221122
}
11231123

1124-
static void parseBPOrdererOptions(Ctx &ctx, opt::InputArgList &args) {
1125-
if (auto *arg = args.getLastArg(OPT_bp_compression_sort)) {
1126-
StringRef s = arg->getValue();
1127-
if (s == "function") {
1128-
ctx.arg.bpFunctionOrderForCompression = true;
1129-
} else if (s == "data") {
1130-
ctx.arg.bpDataOrderForCompression = true;
1131-
} else if (s == "both") {
1132-
ctx.arg.bpFunctionOrderForCompression = true;
1133-
ctx.arg.bpDataOrderForCompression = true;
1134-
} else if (s != "none") {
1135-
ErrAlways(ctx) << arg->getSpelling()
1136-
<< ": expected [none|function|data|both]";
1137-
}
1138-
if (s != "none" && args.hasArg(OPT_call_graph_ordering_file))
1139-
ErrAlways(ctx) << "--bp-compression-sort is incompatible with "
1140-
"--call-graph-ordering-file";
1141-
}
1142-
if (auto *arg = args.getLastArg(OPT_bp_startup_sort)) {
1143-
StringRef s = arg->getValue();
1144-
if (s == "function") {
1145-
ctx.arg.bpStartupFunctionSort = true;
1146-
} else if (s != "none") {
1147-
ErrAlways(ctx) << arg->getSpelling() << ": expected [none|function]";
1148-
}
1149-
if (s != "none" && args.hasArg(OPT_call_graph_ordering_file))
1150-
ErrAlways(ctx) << "--bp-startup-sort=function is incompatible with "
1151-
"--call-graph-ordering-file";
1152-
}
1153-
1154-
ctx.arg.bpCompressionSortStartupFunctions =
1155-
args.hasFlag(OPT_bp_compression_sort_startup_functions,
1156-
OPT_no_bp_compression_sort_startup_functions, false);
1157-
ctx.arg.bpVerboseSectionOrderer = args.hasArg(OPT_verbose_bp_section_orderer);
1158-
1159-
ctx.arg.irpgoProfilePath = args.getLastArgValue(OPT_irpgo_profile);
1160-
if (ctx.arg.irpgoProfilePath.empty()) {
1161-
if (ctx.arg.bpStartupFunctionSort)
1162-
ErrAlways(ctx) << "--bp-startup-sort=function must be used with "
1163-
"--irpgo-profile";
1164-
if (ctx.arg.bpCompressionSortStartupFunctions)
1165-
ErrAlways(ctx)
1166-
<< "--bp-compression-sort-startup-functions must be used with "
1167-
"--irpgo-profile";
1168-
}
1169-
}
1170-
11711124
static DebugCompressionType getCompressionType(Ctx &ctx, StringRef s,
11721125
StringRef option) {
11731126
DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
@@ -1309,7 +1262,6 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
13091262
ctx.arg.bsymbolic = BsymbolicKind::All;
13101263
}
13111264
ctx.arg.callGraphProfileSort = getCGProfileSortKind(ctx, args);
1312-
parseBPOrdererOptions(ctx, args);
13131265
ctx.arg.checkSections =
13141266
args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);
13151267
ctx.arg.chroot = args.getLastArgValue(OPT_chroot);

lld/ELF/Options.td

-13
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,6 @@ def call_graph_profile_sort: JJ<"call-graph-profile-sort=">,
141141
def : FF<"no-call-graph-profile-sort">, Alias<call_graph_profile_sort>, AliasArgs<["none"]>,
142142
Flags<[HelpHidden]>;
143143

144-
defm irpgo_profile: EEq<"irpgo-profile",
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">;
150-
151-
// Auxiliary options related to balanced partition
152-
defm bp_compression_sort_startup_functions: BB<"bp-compression-sort-startup-functions",
153-
"When --irpgo-profile is pecified, prioritize function similarity for compression in addition to startup time", "">;
154-
def verbose_bp_section_orderer: FF<"verbose-bp-section-orderer">,
155-
HelpText<"Print information on balanced partitioning">;
156-
157144
// --chroot doesn't have a help text because it is an internal option.
158145
def chroot: Separate<["--"], "chroot">;
159146

lld/ELF/Writer.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "Writer.h"
1010
#include "AArch64ErrataFix.h"
1111
#include "ARMErrataFix.h"
12-
#include "BPSectionOrderer.h"
1312
#include "CallGraphSort.h"
1413
#include "Config.h"
1514
#include "InputFiles.h"
@@ -1081,18 +1080,8 @@ static void maybeShuffle(Ctx &ctx,
10811080
// that don't appear in the order file.
10821081
static DenseMap<const InputSectionBase *, int> buildSectionOrder(Ctx &ctx) {
10831082
DenseMap<const InputSectionBase *, int> sectionOrder;
1084-
if (ctx.arg.bpStartupFunctionSort || ctx.arg.bpFunctionOrderForCompression ||
1085-
ctx.arg.bpDataOrderForCompression) {
1086-
TimeTraceScope timeScope("Balanced Partitioning Section Orderer");
1087-
sectionOrder = runBalancedPartitioning(
1088-
ctx, ctx.arg.bpStartupFunctionSort ? ctx.arg.irpgoProfilePath : "",
1089-
ctx.arg.bpFunctionOrderForCompression,
1090-
ctx.arg.bpDataOrderForCompression,
1091-
ctx.arg.bpCompressionSortStartupFunctions,
1092-
ctx.arg.bpVerboseSectionOrderer);
1093-
} else if (!ctx.arg.callGraphProfile.empty()) {
1083+
if (!ctx.arg.callGraphProfile.empty())
10941084
sectionOrder = computeCallGraphProfileOrder(ctx);
1095-
}
10961085

10971086
if (ctx.arg.symbolOrderingFile.empty())
10981087
return sectionOrder;

lld/MachO/BPSectionOrderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
110110
bool compressionSortStartupFunctions, bool verbose) {
111111
// Collect candidate sections and associated symbols.
112112
SmallVector<InputSection *> sections;
113-
DenseMap<CachedHashStringRef, std::set<unsigned>> rootSymbolToSectionIdxs;
113+
DenseMap<CachedHashStringRef, DenseSet<unsigned>> rootSymbolToSectionIdxs;
114114
for (const auto *file : inputFiles) {
115115
for (auto *sec : file->sections) {
116116
for (auto &subsec : sec->subsections) {

lld/include/lld/Common/BPSectionOrdererBase.inc

+8-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "lld/Common/ErrorHandler.h"
2323
#include "llvm/ADT/CachedHashString.h"
2424
#include "llvm/ADT/DenseMap.h"
25-
#include "llvm/ADT/MapVector.h"
25+
#include "llvm/ADT/DenseSet.h"
2626
#include "llvm/ADT/SetVector.h"
2727
#include "llvm/ADT/SmallSet.h"
2828
#include "llvm/ADT/SmallVector.h"
@@ -35,7 +35,6 @@
3535
#include "llvm/Support/VirtualFileSystem.h"
3636
#include <memory>
3737
#include <optional>
38-
#include <set>
3938

4039
#define DEBUG_TYPE "bp-section-orderer"
4140

@@ -61,13 +60,9 @@ template <class D> struct BPOrderer {
6160
bool forDataCompression,
6261
bool compressionSortStartupFunctions, bool verbose,
6362
llvm::ArrayRef<Section *> sections,
64-
const DenseMap<CachedHashStringRef, std::set<unsigned>>
63+
const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
6564
&rootSymbolToSectionIdxs)
6665
-> llvm::DenseMap<const Section *, int>;
67-
68-
std::optional<StringRef> static getResolvedLinkageName(llvm::StringRef name) {
69-
return {};
70-
}
7166
};
7267
} // namespace lld
7368

@@ -78,7 +73,7 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
7873
ArrayRef<const typename D::Section *> sections,
7974
const DenseMap<const void *, uint64_t> &sectionToIdx,
8075
ArrayRef<unsigned> sectionIdxs,
81-
DenseMap<unsigned, SmallVector<unsigned, 0>> *duplicateSectionIdxs,
76+
DenseMap<unsigned, SmallVector<unsigned>> *duplicateSectionIdxs,
8277
BPFunctionNode::UtilityNodeT &maxUN) {
8378
TimeTraceScope timeScope("Build nodes for compression");
8479

@@ -93,7 +88,7 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
9388
hashes.clear();
9489
}
9590

96-
MapVector<uint64_t, unsigned> hashFrequency;
91+
DenseMap<uint64_t, unsigned> hashFrequency;
9792
for (auto &[sectionIdx, hashes] : sectionHashes)
9893
for (auto hash : hashes)
9994
++hashFrequency[hash];
@@ -102,11 +97,10 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
10297
// Merge sections that are nearly identical
10398
SmallVector<std::pair<unsigned, SmallVector<uint64_t>>> newSectionHashes;
10499
DenseMap<uint64_t, unsigned> wholeHashToSectionIdx;
105-
unsigned threshold = sectionHashes.size() > 10000 ? 5 : 0;
106100
for (auto &[sectionIdx, hashes] : sectionHashes) {
107101
uint64_t wholeHash = 0;
108102
for (auto hash : hashes)
109-
if (hashFrequency[hash] > threshold)
103+
if (hashFrequency[hash] > 5)
110104
wholeHash ^= hash;
111105
auto [it, wasInserted] =
112106
wholeHashToSectionIdx.insert(std::make_pair(wholeHash, sectionIdx));
@@ -162,7 +156,7 @@ auto BPOrderer<D>::computeOrder(
162156
StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
163157
bool compressionSortStartupFunctions, bool verbose,
164158
ArrayRef<Section *> sections,
165-
const DenseMap<CachedHashStringRef, std::set<unsigned>>
159+
const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
166160
&rootSymbolToSectionIdxs) -> DenseMap<const Section *, int> {
167161
TimeTraceScope timeScope("Setup Balanced Partitioning");
168162
DenseMap<const void *, uint64_t> sectionToIdx;
@@ -186,7 +180,7 @@ auto BPOrderer<D>::computeOrder(
186180
}
187181
auto &traces = reader->getTemporalProfTraces();
188182

189-
MapVector<unsigned, BPFunctionNode::UtilityNodeT> sectionIdxToFirstUN;
183+
DenseMap<unsigned, BPFunctionNode::UtilityNodeT> sectionIdxToFirstUN;
190184
for (size_t traceIdx = 0; traceIdx < traces.size(); traceIdx++) {
191185
uint64_t currentSize = 0, cutoffSize = 1;
192186
size_t cutoffTimestamp = 1;
@@ -263,7 +257,7 @@ auto BPOrderer<D>::computeOrder(
263257

264258
// Map a section index (order directly) to a list of duplicate section indices
265259
// (not ordered directly).
266-
DenseMap<unsigned, SmallVector<unsigned, 0>> duplicateSectionIdxs;
260+
DenseMap<unsigned, SmallVector<unsigned>> duplicateSectionIdxs;
267261
auto unsForFunctionCompression = getUnsForCompression<D>(
268262
sections, sectionToIdx, sectionIdxsForFunctionCompression,
269263
&duplicateSectionIdxs, maxUN);

0 commit comments

Comments
 (0)