Skip to content

Commit 98abacc

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I23aa425a53065ad350af26613770156993adc296
2 parents a7dcd1e + eb1f9cc commit 98abacc

24 files changed

+261
-205
lines changed

bolt/test/merge-fdata-lbr-mode.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# RUN: FileCheck %s --input-file %t/merged.fdata
88

99
# CHECK-NOT: no_lbr
10-
# CHECK: main 2
10+
# CHECK: 1 main 0 1 main 2 1 3
1111

1212
#--- a.fdata
13-
main 1
13+
1 main 0 1 main 2 0 1
1414
#--- b.fdata
15-
main 1
15+
1 main 0 1 main 2 1 2

bolt/test/merge-fdata-mixed-bat-no-lbr.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# RUN: split-file %s %t
66
# RUN: not merge-fdata %t/a.fdata %t/b.fdata 2>&1 | FileCheck %s
77

8-
# CHECK: cannot mix profile collected in BOLT and non-BOLT deployments
8+
# CHECK: cannot mix profile with and without boltedcollection
99

1010
#--- a.fdata
1111
boltedcollection

bolt/test/merge-fdata-mixed-mode.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# RUN: split-file %s %t
77
# RUN: not merge-fdata %t/a.fdata %t/b.fdata 2>&1 | FileCheck %s
88

9-
# CHECK: cannot mix 'no_lbr' and 'lbr' profiles.
9+
# CHECK: cannot mix profile with and without no_lbr
1010

1111
#--- a.fdata
1212
no_lbr

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/Support/Signals.h"
2323
#include "llvm/Support/ThreadPool.h"
2424
#include <algorithm>
25+
#include <fstream>
2526
#include <mutex>
2627
#include <unordered_map>
2728

@@ -267,69 +268,68 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
267268
std::optional<bool> BoltedCollection;
268269
std::optional<bool> NoLBRCollection;
269270
std::mutex BoltedCollectionMutex;
270-
typedef StringMap<uint64_t> ProfileTy;
271+
struct CounterTy {
272+
uint64_t Exec{0};
273+
uint64_t Mispred{0};
274+
CounterTy &operator+=(const CounterTy &O) {
275+
Exec += O.Exec;
276+
Mispred += O.Mispred;
277+
return *this;
278+
}
279+
CounterTy operator+(const CounterTy &O) { return *this += O; }
280+
};
281+
typedef StringMap<CounterTy> ProfileTy;
271282

272283
auto ParseProfile = [&](const std::string &Filename, auto &Profiles) {
273284
const llvm::thread::id tid = llvm::this_thread::get_id();
274285

275286
if (isYAML(Filename))
276287
report_error(Filename, "cannot mix YAML and legacy formats");
277-
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
278-
MemoryBuffer::getFileOrSTDIN(Filename);
279-
if (std::error_code EC = MB.getError())
280-
report_error(Filename, EC);
281288

282-
StringRef Buf = MB.get()->getBuffer();
289+
std::ifstream FdataFile(Filename, std::ios::in);
290+
std::string FdataLine;
291+
std::getline(FdataFile, FdataLine);
292+
293+
auto checkMode = [&](const std::string &Key, std::optional<bool> &Flag) {
294+
const bool KeyIsSet = FdataLine.rfind(Key, 0) == 0;
295+
296+
if (!Flag.has_value())
297+
Flag = KeyIsSet;
298+
else if (*Flag != KeyIsSet)
299+
report_error(Filename, "cannot mix profile with and without " + Key);
300+
if (KeyIsSet)
301+
// Advance line
302+
std::getline(FdataFile, FdataLine);
303+
};
304+
283305
ProfileTy *Profile;
284306
{
285307
std::lock_guard<std::mutex> Lock(BoltedCollectionMutex);
286308
// Check if the string "boltedcollection" is in the first line
287-
if (Buf.starts_with("boltedcollection\n")) {
288-
if (!BoltedCollection.value_or(true))
289-
report_error(
290-
Filename,
291-
"cannot mix profile collected in BOLT and non-BOLT deployments");
292-
BoltedCollection = true;
293-
Buf = Buf.drop_front(17);
294-
} else {
295-
if (BoltedCollection.value_or(false))
296-
report_error(
297-
Filename,
298-
"cannot mix profile collected in BOLT and non-BOLT deployments");
299-
BoltedCollection = false;
300-
}
309+
checkMode("boltedcollection", BoltedCollection);
301310
// Check if the string "no_lbr" is in the first line
302311
// (or second line if BoltedCollection is true)
303-
size_t CheckNoLBRPos = Buf.find('\n');
304-
if (CheckNoLBRPos != StringRef::npos) {
305-
StringRef FirstLine = Buf.substr(0, CheckNoLBRPos);
306-
if (FirstLine.contains("no_lbr")) {
307-
if (!NoLBRCollection.value_or(true))
308-
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
309-
NoLBRCollection = true;
310-
Buf = Buf.drop_front(CheckNoLBRPos + 1);
311-
} else {
312-
if (NoLBRCollection.value_or(false))
313-
report_error(Filename, "cannot mix 'no_lbr' and 'lbr' profiles");
314-
NoLBRCollection = false;
315-
}
316-
}
312+
checkMode("no_lbr", NoLBRCollection);
317313
Profile = &Profiles[tid];
318314
}
319315

320-
SmallVector<StringRef> Lines;
321-
SplitString(Buf, Lines, "\n");
322-
for (StringRef Line : Lines) {
323-
size_t Pos = Line.rfind(" ");
324-
if (Pos == StringRef::npos)
325-
report_error(Filename, "Malformed / corrupted profile");
326-
StringRef Signature = Line.substr(0, Pos);
327-
uint64_t Count;
328-
if (Line.substr(Pos + 1, Line.size() - Pos).getAsInteger(10, Count))
329-
report_error(Filename, "Malformed / corrupted profile counter");
316+
do {
317+
StringRef Line(FdataLine);
318+
CounterTy Count;
319+
auto [Signature, ExecCount] = Line.rsplit(' ');
320+
if (ExecCount.getAsInteger(10, Count.Exec))
321+
report_error(Filename, "Malformed / corrupted execution count");
322+
// Only LBR profile has misprediction field
323+
if (!NoLBRCollection.value_or(false)) {
324+
auto [SignatureLBR, MispredCount] = Signature.rsplit(' ');
325+
Signature = SignatureLBR;
326+
if (MispredCount.getAsInteger(10, Count.Mispred))
327+
report_error(Filename, "Malformed / corrupted misprediction count");
328+
}
329+
330330
Count += Profile->lookup(Signature);
331331
Profile->insert_or_assign(Signature, Count);
332-
}
332+
} while (std::getline(FdataFile, FdataLine));
333333
};
334334

335335
// The final reduction has non-trivial cost, make sure each thread has at
@@ -346,16 +346,20 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
346346
ProfileTy MergedProfile;
347347
for (const auto &[Thread, Profile] : ParsedProfiles)
348348
for (const auto &[Key, Value] : Profile) {
349-
uint64_t Count = MergedProfile.lookup(Key) + Value;
349+
CounterTy Count = MergedProfile.lookup(Key) + Value;
350350
MergedProfile.insert_or_assign(Key, Count);
351351
}
352352

353353
if (BoltedCollection.value_or(false))
354354
output() << "boltedcollection\n";
355355
if (NoLBRCollection.value_or(false))
356356
output() << "no_lbr\n";
357-
for (const auto &[Key, Value] : MergedProfile)
358-
output() << Key << " " << Value << "\n";
357+
for (const auto &[Key, Value] : MergedProfile) {
358+
output() << Key << " ";
359+
if (!NoLBRCollection.value_or(false))
360+
output() << Value.Mispred << " ";
361+
output() << Value.Exec << "\n";
362+
}
359363

360364
errs() << "Profile from " << Filenames.size() << " files merged.\n";
361365
}

clang/unittests/Format/FormatTestJS.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,10 @@ TEST_F(FormatTestJS, ClassDeclarations) {
17531753
" x: {y: Z;} = {};\n"
17541754
" private y: {y: Z;} = {};\n"
17551755
"}");
1756+
verifyFormat("class Foo {\n"
1757+
" private addGrammarCheckOneboxProductInfo(\n"
1758+
" productInfo: {[key: string]: string;}) {}\n"
1759+
"}");
17561760

17571761
// ':' is not a type declaration here.
17581762
verifyFormat("class X {\n"

libunwind/include/__libunwind_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
# else
5454
# define _LIBUNWIND_CURSOR_SIZE 66
5555
# endif
56+
# elif defined(__ILP32__)
57+
# define _LIBUNWIND_CONTEXT_SIZE 21
58+
# define _LIBUNWIND_CURSOR_SIZE 28
5659
# else
5760
# define _LIBUNWIND_CONTEXT_SIZE 21
5861
# define _LIBUNWIND_CURSOR_SIZE 33

lld/MachO/Arch/ARM64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ InputSection *ARM64::getThunkBranchTarget(InputSection *thunk) const {
202202
assert(thunk->relocs.size() == 1 &&
203203
"expected a single reloc on ARM64 ICF thunk");
204204
auto &reloc = thunk->relocs[0];
205-
assert(reloc.referent.is<InputSection *>() &&
205+
assert(isa<InputSection *>(reloc.referent) &&
206206
"ARM64 thunk reloc is expected to point to an InputSection");
207207

208208
return reloc.referent.dyn_cast<InputSection *>();

lld/MachO/ConcatOutputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool TextOutputSection::needsThunks() const {
145145
for (Reloc &r : isec->relocs) {
146146
if (!target->hasAttr(r.type, RelocAttrBits::BRANCH))
147147
continue;
148-
auto *sym = r.referent.get<Symbol *>();
148+
auto *sym = cast<Symbol *>(r.referent);
149149
// Pre-populate the thunkMap and memoize call site counts for every
150150
// InputSection and ThunkInfo. We do this for the benefit of
151151
// estimateStubsInRangeVA().
@@ -297,7 +297,7 @@ void TextOutputSection::finalize() {
297297
backwardBranchRange < callVA ? callVA - backwardBranchRange : 0;
298298
uint64_t highVA = callVA + forwardBranchRange;
299299
// Calculate our call referent address
300-
auto *funcSym = r.referent.get<Symbol *>();
300+
auto *funcSym = cast<Symbol *>(r.referent);
301301
ThunkInfo &thunkInfo = thunkMap[funcSym];
302302
// The referent is not reachable, so we need to use a thunk ...
303303
if (funcSym->isInStubs() && callVA >= stubsInRangeVA) {

lld/MachO/EhFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void createSubtraction(PointerUnion<Symbol *, InputSection *> a,
114114
auto minuend = b;
115115
if (Invert)
116116
std::swap(subtrahend, minuend);
117-
assert(subtrahend.is<Symbol *>());
117+
assert(isa<Symbol *>(subtrahend));
118118
Reloc subtrahendReloc(target->subtractorRelocType, /*pcrel=*/false, length,
119119
off, /*addend=*/0, subtrahend);
120120
Reloc minuendReloc(target->unsignedRelocType, /*pcrel=*/false, length, off,

lld/MachO/ICF.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
115115
return false;
116116
if (ra.offset != rb.offset)
117117
return false;
118-
if (ra.referent.is<Symbol *>() != rb.referent.is<Symbol *>())
118+
if (isa<Symbol *>(ra.referent) != isa<Symbol *>(rb.referent))
119119
return false;
120120

121121
InputSection *isecA, *isecB;
122122

123123
uint64_t valueA = 0;
124124
uint64_t valueB = 0;
125-
if (ra.referent.is<Symbol *>()) {
126-
const auto *sa = ra.referent.get<Symbol *>();
127-
const auto *sb = rb.referent.get<Symbol *>();
125+
if (isa<Symbol *>(ra.referent)) {
126+
const auto *sa = cast<Symbol *>(ra.referent);
127+
const auto *sb = cast<Symbol *>(rb.referent);
128128
if (sa->kind() != sb->kind())
129129
return false;
130130
// ICF runs before Undefineds are treated (and potentially converted into
@@ -143,8 +143,8 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
143143
isecB = db->isec();
144144
valueB = db->value;
145145
} else {
146-
isecA = ra.referent.get<InputSection *>();
147-
isecB = rb.referent.get<InputSection *>();
146+
isecA = cast<InputSection *>(ra.referent);
147+
isecB = cast<InputSection *>(rb.referent);
148148
}
149149

150150
// Typically, we should not encounter sections marked with `keepUnique` at
@@ -167,7 +167,7 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
167167
return ra.addend == rb.addend;
168168
// Else we have two literal sections. References to them are equal iff their
169169
// offsets in the output section are equal.
170-
if (ra.referent.is<Symbol *>())
170+
if (isa<Symbol *>(ra.referent))
171171
// For symbol relocs, we compare the contents at the symbol address. We
172172
// don't do `getOffset(value + addend)` because value + addend may not be
173173
// a valid offset in the literal section.
@@ -195,21 +195,21 @@ bool ICF::equalsVariable(const ConcatInputSection *ia,
195195
if (ra.referent == rb.referent)
196196
return true;
197197
const ConcatInputSection *isecA, *isecB;
198-
if (ra.referent.is<Symbol *>()) {
198+
if (isa<Symbol *>(ra.referent)) {
199199
// Matching DylibSymbols are already filtered out by the
200200
// identical-referent check above. Non-matching DylibSymbols were filtered
201201
// out in equalsConstant(). So we can safely cast to Defined here.
202-
const auto *da = cast<Defined>(ra.referent.get<Symbol *>());
203-
const auto *db = cast<Defined>(rb.referent.get<Symbol *>());
202+
const auto *da = cast<Defined>(cast<Symbol *>(ra.referent));
203+
const auto *db = cast<Defined>(cast<Symbol *>(rb.referent));
204204
if (da->isAbsolute())
205205
return true;
206206
isecA = dyn_cast<ConcatInputSection>(da->isec());
207207
if (!isecA)
208208
return true; // literal sections were checked in equalsConstant.
209209
isecB = cast<ConcatInputSection>(db->isec());
210210
} else {
211-
const auto *sa = ra.referent.get<InputSection *>();
212-
const auto *sb = rb.referent.get<InputSection *>();
211+
const auto *sa = cast<InputSection *>(ra.referent);
212+
const auto *sb = cast<InputSection *>(rb.referent);
213213
isecA = dyn_cast<ConcatInputSection>(sa);
214214
if (!isecA)
215215
return true;

lld/MachO/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ static CIE parseCIE(const InputSection *isec, const EhReader &reader,
12911291
const auto *personalityReloc = isec->getRelocAt(personalityAddrOff);
12921292
if (!personalityReloc)
12931293
reader.failOn(off, "Failed to locate relocation for personality symbol");
1294-
cie.personalitySymbol = personalityReloc->referent.get<macho::Symbol *>();
1294+
cie.personalitySymbol = cast<macho::Symbol *>(personalityReloc->referent);
12951295
}
12961296
return cie;
12971297
}
@@ -1338,12 +1338,12 @@ targetSymFromCanonicalSubtractor(const InputSection *isec,
13381338
assert(target->hasAttr(minuend.type, RelocAttrBits::UNSIGNED));
13391339
// Note: pcSym may *not* be exactly at the PC; there's usually a non-zero
13401340
// addend.
1341-
auto *pcSym = cast<Defined>(subtrahend.referent.get<macho::Symbol *>());
1341+
auto *pcSym = cast<Defined>(cast<macho::Symbol *>(subtrahend.referent));
13421342
Defined *target =
13431343
cast_or_null<Defined>(minuend.referent.dyn_cast<macho::Symbol *>());
13441344
if (!pcSym) {
13451345
auto *targetIsec =
1346-
cast<ConcatInputSection>(minuend.referent.get<InputSection *>());
1346+
cast<ConcatInputSection>(cast<InputSection *>(minuend.referent));
13471347
target = findSymbolAtOffset(targetIsec, minuend.addend);
13481348
}
13491349
if (Invert)

lld/MachO/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
226226
const bool needsFixup = config->emitChainedFixups &&
227227
target->hasAttr(r.type, RelocAttrBits::UNSIGNED);
228228
if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) {
229-
const Symbol *fromSym = r.referent.get<Symbol *>();
229+
const Symbol *fromSym = cast<Symbol *>(r.referent);
230230
const Reloc &minuend = relocs[++i];
231231
uint64_t minuendVA;
232232
if (const Symbol *toSym = minuend.referent.dyn_cast<Symbol *>())
233233
minuendVA = toSym->getVA() + minuend.addend;
234234
else {
235-
auto *referentIsec = minuend.referent.get<InputSection *>();
235+
auto *referentIsec = cast<InputSection *>(minuend.referent);
236236
assert(!::shouldOmitFromOutput(referentIsec));
237237
minuendVA = referentIsec->getVA(minuend.addend);
238238
}

lld/MachO/MarkLive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() {
160160
if (auto *s = r.referent.dyn_cast<Symbol *>())
161161
addSym(s, entry);
162162
else
163-
enqueue(r.referent.get<InputSection *>(), r.addend, entry);
163+
enqueue(cast<InputSection *>(r.referent), r.addend, entry);
164164
}
165165
for (Defined *d : getInputSection(entry)->symbols)
166166
addSym(d, entry);
@@ -183,7 +183,7 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() {
183183
enqueue(isec, 0, makeEntry(referentIsec, nullptr));
184184
}
185185
} else {
186-
auto *referentIsec = r.referent.get<InputSection *>();
186+
auto *referentIsec = cast<InputSection *>(r.referent);
187187
if (referentIsec->isLive(r.addend))
188188
enqueue(isec, 0, makeEntry(referentIsec, nullptr));
189189
}

0 commit comments

Comments
 (0)