Skip to content

Commit bc39367

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: If62da38b116a2bb4f9e8c877dd268c2556833ae1
2 parents 55f1846 + 9d0fa42 commit bc39367

File tree

15 files changed

+78
-45
lines changed

15 files changed

+78
-45
lines changed

lld/Common/BPSectionOrdererBase.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ BPSectionBase::reorderSectionsByBalancedPartitioning(
109109

110110
// Process input sections
111111
for (const auto &isec : inputSections) {
112-
if (!isec->hasValidData())
113-
continue;
114-
115112
unsigned sectionIdx = sections.size();
116113
sectionToIdx.try_emplace(isec->getSection(), sectionIdx);
117114
sections.emplace_back(isec.get());
@@ -371,4 +368,4 @@ BPSectionBase::reorderSectionsByBalancedPartitioning(
371368
for (const auto *isec : orderedSections)
372369
sectionPriorities[isec] = --highestAvailablePriority;
373370
return sectionPriorities;
374-
}
371+
}

lld/ELF/CallGraphSort.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ DenseMap<const InputSectionBase *, int> CallGraphSort::run() {
235235
});
236236

237237
DenseMap<const InputSectionBase *, int> orderMap;
238-
int curOrder = 1;
238+
int curOrder = -clusters.size();
239239
for (int leader : sorted) {
240240
for (int i = leader;;) {
241241
orderMap[sections[i]] = curOrder++;
@@ -276,8 +276,8 @@ DenseMap<const InputSectionBase *, int> CallGraphSort::run() {
276276
// Sort sections by the profile data using the Cache-Directed Sort algorithm.
277277
// The placement is done by optimizing the locality by co-locating frequently
278278
// executed code sections together.
279-
DenseMap<const InputSectionBase *, int>
280-
elf::computeCacheDirectedSortOrder(Ctx &ctx) {
279+
static DenseMap<const InputSectionBase *, int>
280+
computeCacheDirectedSortOrder(Ctx &ctx) {
281281
SmallVector<uint64_t, 0> funcSizes;
282282
SmallVector<uint64_t, 0> funcCounts;
283283
SmallVector<codelayout::EdgeCount, 0> callCounts;
@@ -328,7 +328,7 @@ elf::computeCacheDirectedSortOrder(Ctx &ctx) {
328328

329329
// Create the final order.
330330
DenseMap<const InputSectionBase *, int> orderMap;
331-
int curOrder = 1;
331+
int curOrder = -sortedSections.size();
332332
for (uint64_t secIdx : sortedSections)
333333
orderMap[sections[secIdx]] = curOrder++;
334334

lld/ELF/CallGraphSort.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namespace lld::elf {
1515
struct Ctx;
1616
class InputSectionBase;
1717

18-
llvm::DenseMap<const InputSectionBase *, int>
19-
computeCacheDirectedSortOrder(Ctx &);
20-
2118
llvm::DenseMap<const InputSectionBase *, int>
2219
computeCallGraphProfileOrder(Ctx &);
2320
} // namespace lld::elf

lld/ELF/Driver.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,13 +1759,8 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
17591759
if (args.hasArg(OPT_call_graph_ordering_file))
17601760
ErrAlways(ctx) << "--symbol-ordering-file and --call-graph-order-file "
17611761
"may not be used together";
1762-
if (std::optional<MemoryBufferRef> buffer =
1763-
readFile(ctx, arg->getValue())) {
1762+
if (auto buffer = readFile(ctx, arg->getValue()))
17641763
ctx.arg.symbolOrderingFile = getSymbolOrderingFile(ctx, *buffer);
1765-
// Also need to disable CallGraphProfileSort to prevent
1766-
// LLD order symbols with CGProfile
1767-
ctx.arg.callGraphProfileSort = CGProfileSortKind::None;
1768-
}
17691764
}
17701765

17711766
assert(ctx.arg.versionDefinitions.empty());

lld/ELF/Writer.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,14 @@ static void maybeShuffle(Ctx &ctx,
10801080
}
10811081
}
10821082

1083-
// Builds section order for handling --symbol-ordering-file.
1083+
// Return section order within an InputSectionDescription.
1084+
// If both --symbol-ordering-file and call graph profile are present, the order
1085+
// file takes precedence, but the call graph profile is still used for symbols
1086+
// that don't appear in the order file.
10841087
static DenseMap<const InputSectionBase *, int> buildSectionOrder(Ctx &ctx) {
10851088
DenseMap<const InputSectionBase *, int> sectionOrder;
1086-
// Use the rarely used option --call-graph-ordering-file to sort sections.
10871089
if (!ctx.arg.callGraphProfile.empty())
1088-
return computeCallGraphProfileOrder(ctx);
1090+
sectionOrder = computeCallGraphProfileOrder(ctx);
10891091

10901092
if (ctx.arg.symbolOrderingFile.empty())
10911093
return sectionOrder;
@@ -1099,7 +1101,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder(Ctx &ctx) {
10991101
// appear in the symbol ordering file have the lowest priority 0.
11001102
// All explicitly mentioned symbols have negative (higher) priorities.
11011103
DenseMap<CachedHashStringRef, SymbolOrderEntry> symbolOrder;
1102-
int priority = -ctx.arg.symbolOrderingFile.size();
1104+
int priority = -sectionOrder.size() - ctx.arg.symbolOrderingFile.size();
11031105
for (StringRef s : ctx.arg.symbolOrderingFile)
11041106
symbolOrder.insert({CachedHashStringRef(s), {priority++, false}});
11051107

@@ -1255,11 +1257,11 @@ static void sortSection(Ctx &ctx, OutputSection &osec,
12551257
}
12561258
}
12571259

1258-
// If no layout was provided by linker script, we want to apply default
1259-
// sorting for special input sections. This also handles --symbol-ordering-file.
1260+
// Sort sections within each InputSectionDescription.
12601261
template <class ELFT> void Writer<ELFT>::sortInputSections() {
1261-
// Build the order once since it is expensive.
1262+
// Assign negative priorities.
12621263
DenseMap<const InputSectionBase *, int> order = buildSectionOrder(ctx);
1264+
// Assign non-negative priorities due to --shuffle-sections.
12631265
maybeShuffle(ctx, order);
12641266
for (SectionCommand *cmd : ctx.script->sectionCommands)
12651267
if (auto *osd = dyn_cast<OutputDesc>(cmd))

lld/MachO/BPSectionOrderer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ class BPSectionMacho : public BPSectionBase {
6868

6969
bool isCodeSection() const override { return macho::isCodeSection(isec); }
7070

71-
bool hasValidData() const override {
72-
return isec && !isec->data.empty() && isec->data.data();
73-
}
74-
7571
SmallVector<std::unique_ptr<BPSymbol>> getSymbols() const override {
7672
SmallVector<std::unique_ptr<BPSymbol>> symbols;
7773
for (auto *sym : isec->symbols)

lld/include/lld/Common/BPSectionOrdererBase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class BPSectionBase {
3737
public:
3838
virtual ~BPSectionBase() = default;
3939
virtual uint64_t getSize() const = 0;
40-
virtual bool hasValidData() const = 0;
4140
virtual bool isCodeSection() const = 0;
4241
virtual llvm::SmallVector<std::unique_ptr<BPSymbol>> getSymbols() const = 0;
4342
virtual const void *getSection() const = 0;

lld/test/ELF/cgprofile-orderfile.s

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# REQUIRES: x86
2+
3+
# RUN: rm -rf %t && split-file %s %t && cd %t
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
5+
6+
# RUN: ld.lld -e A a.o --symbol-ordering-file=order --call-graph-profile-sort=hfsort -o out
7+
# RUN: llvm-nm --numeric-sort out | FileCheck %s
8+
# RUN: ld.lld -e A a.o --call-graph-profile-sort=hfsort -o out1
9+
# RUN: llvm-nm --numeric-sort out1 | FileCheck %s --check-prefix=ONLY-CG
10+
11+
#--- order
12+
B
13+
A
14+
15+
#--- a.s
16+
.section .text.D,"ax"; .globl D; D:
17+
retq
18+
19+
.section .text.C,"ax"; .globl C; C:
20+
call D
21+
22+
.section .text.B,"ax"; .globl B; B:
23+
retq
24+
25+
.section .text.A,"ax"; .globl A; A:
26+
call B
27+
call C
28+
29+
.cg_profile A, B, 100
30+
.cg_profile A, C, 40
31+
.cg_profile C, D, 61
32+
33+
# CHECK: T B
34+
# CHECK-NEXT: T A
35+
# CHECK-NEXT: T C
36+
# CHECK-NEXT: T D
37+
38+
# ONLY-CG: T A
39+
# ONLY-CG-NEXT: T B
40+
# ONLY-CG-NEXT: T C
41+
# ONLY-CG-NEXT: T D

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ class VPBuilder {
243243
}
244244

245245
VPScalarCastRecipe *createScalarCast(Instruction::CastOps Opcode, VPValue *Op,
246-
Type *ResultTy) {
247-
return tryInsertInstruction(new VPScalarCastRecipe(Opcode, Op, ResultTy));
246+
Type *ResultTy, DebugLoc DL) {
247+
return tryInsertInstruction(
248+
new VPScalarCastRecipe(Opcode, Op, ResultTy, DL));
248249
}
249250

250251
VPWidenCastRecipe *createWidenCast(Instruction::CastOps Opcode, VPValue *Op,

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8903,7 +8903,8 @@ static VPValue *addResumePhiRecipeForInduction(VPWidenInductionRecipe *WideIV,
89038903
Type *ScalarTypeOfWideIV = TypeInfo.inferScalarType(WideIV);
89048904
if (ScalarTypeOfWideIV != TypeInfo.inferScalarType(EndValue)) {
89058905
EndValue = VectorPHBuilder.createScalarCast(Instruction::Trunc, EndValue,
8906-
ScalarTypeOfWideIV);
8906+
ScalarTypeOfWideIV,
8907+
WideIV->getDebugLoc());
89078908
}
89088909

89098910
auto *ResumePhiRecipe =

0 commit comments

Comments
 (0)