Skip to content

Commit 58b9ff6

Browse files
authored
merge main into amd-staging (llvm#2106)
2 parents 340e3cd + 51545e2 commit 58b9ff6

File tree

70 files changed

+304
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+304
-243
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ class BinaryContext {
14991499
MCEInstance.LocalCtx.reset(
15001500
new MCContext(*TheTriple, AsmInfo.get(), MRI.get(), STI.get()));
15011501
MCEInstance.LocalMOFI.reset(
1502-
TheTarget->createMCObjectFileInfo(*MCEInstance.LocalCtx.get(),
1502+
TheTarget->createMCObjectFileInfo(*MCEInstance.LocalCtx,
15031503
/*PIC=*/!HasFixedLoadAddress));
15041504
MCEInstance.LocalCtx->setObjectFileInfo(MCEInstance.LocalMOFI.get());
15051505
MCEInstance.MCE.reset(

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,15 @@ class BinaryFunction {
867867
/// Returns if BinaryDominatorTree has been constructed for this function.
868868
bool hasDomTree() const { return BDT != nullptr; }
869869

870-
BinaryDominatorTree &getDomTree() { return *BDT.get(); }
870+
BinaryDominatorTree &getDomTree() { return *BDT; }
871871

872872
/// Constructs DomTree for this function.
873873
void constructDomTree();
874874

875875
/// Returns if loop detection has been run for this function.
876876
bool hasLoopInfo() const { return BLI != nullptr; }
877877

878-
const BinaryLoopInfo &getLoopInfo() { return *BLI.get(); }
878+
const BinaryLoopInfo &getLoopInfo() { return *BLI; }
879879

880880
bool isLoopFree() {
881881
if (!hasLoopInfo())

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DIEBuilder {
137137
std::unordered_map<std::string, uint32_t> NameToIndexMap;
138138

139139
/// Returns current state of the DIEBuilder
140-
State &getState() { return *BuilderState.get(); }
140+
State &getState() { return *BuilderState; }
141141

142142
/// Resolve the reference in DIE, if target is not loaded into IR,
143143
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p

bolt/include/bolt/Passes/FrameAnalysis.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define BOLT_PASSES_FRAMEANALYSIS_H
1111

1212
#include "bolt/Passes/StackPointerTracking.h"
13+
#include <tuple>
1314

1415
namespace llvm {
1516
namespace bolt {
@@ -53,9 +54,7 @@ struct ArgInStackAccess {
5354
uint8_t Size;
5455

5556
bool operator<(const ArgInStackAccess &RHS) const {
56-
if (StackOffset != RHS.StackOffset)
57-
return StackOffset < RHS.StackOffset;
58-
return Size < RHS.Size;
57+
return std::tie(StackOffset, Size) < std::tie(RHS.StackOffset, RHS.Size);
5958
}
6059
};
6160

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ struct MCInstInBBReference {
4343
return BB == RHS.BB && BBIndex == RHS.BBIndex;
4444
}
4545
bool operator<(const MCInstInBBReference &RHS) const {
46-
if (BB != RHS.BB)
47-
return BB < RHS.BB;
48-
return BBIndex < RHS.BBIndex;
46+
return std::tie(BB, BBIndex) < std::tie(RHS.BB, RHS.BBIndex);
4947
}
5048
operator MCInst &() const {
5149
assert(BB != nullptr);

bolt/include/bolt/Profile/DataReader.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,7 @@ struct BranchInfo {
9090
}
9191

9292
bool operator<(const BranchInfo &RHS) const {
93-
if (From < RHS.From)
94-
return true;
95-
96-
if (From == RHS.From)
97-
return (To < RHS.To);
98-
99-
return false;
93+
return std::tie(From, To) < std::tie(RHS.From, RHS.To);
10094
}
10195

10296
/// Merges branch and misprediction counts of \p BI with those of this object.
@@ -252,6 +246,9 @@ struct FuncSampleData {
252246
/// Get the number of samples recorded in [Start, End)
253247
uint64_t getSamples(uint64_t Start, uint64_t End) const;
254248

249+
/// Returns the total number of samples recorded in this function.
250+
uint64_t getSamples() const;
251+
255252
/// Aggregation helper
256253
DenseMap<uint64_t, size_t> Index;
257254

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
292292

293293
getState().Type = ProcessingType::DWARF4TUs;
294294
for (std::unique_ptr<DWARFUnit> &DU : CU4TURanges)
295-
registerUnit(*DU.get(), false);
295+
registerUnit(*DU, false);
296296

297297
for (std::unique_ptr<DWARFUnit> &DU : CU4TURanges)
298-
constructFromUnit(*DU.get());
298+
constructFromUnit(*DU);
299299

300300
DWARFContext::unit_iterator_range CURanges =
301301
isDWO() ? DwarfContext->dwo_info_section_units()
@@ -308,7 +308,7 @@ void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
308308
for (std::unique_ptr<DWARFUnit> &DU : CURanges) {
309309
if (!DU->isTypeUnit())
310310
continue;
311-
registerUnit(*DU.get(), false);
311+
registerUnit(*DU, false);
312312
}
313313

314314
for (DWARFUnit *DU : getState().DWARF5TUVector) {
@@ -335,7 +335,7 @@ void DIEBuilder::buildCompileUnits(const bool Init) {
335335
for (std::unique_ptr<DWARFUnit> &DU : CURanges) {
336336
if (DU->isTypeUnit())
337337
continue;
338-
registerUnit(*DU.get(), false);
338+
registerUnit(*DU, false);
339339
}
340340

341341
// Using DULIst since it can be modified by cross CU refrence resolution.

bolt/lib/Core/DebugData.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ DebugRangesSectionWriter::DebugRangesSectionWriter() {
142142

143143
void DebugRangesSectionWriter::initSection() {
144144
// Adds an empty range to the buffer.
145-
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
145+
writeAddressRanges(*RangesStream, DebugAddressRangesVector{});
146146
}
147147

148148
uint64_t DebugRangesSectionWriter::addRanges(
@@ -169,7 +169,7 @@ uint64_t DebugRangesSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
169169
// unique and correct offsets in patches.
170170
std::lock_guard<std::mutex> Lock(WriterMutex);
171171
const uint32_t EntryOffset = RangesBuffer->size();
172-
writeAddressRanges(*RangesStream.get(), Ranges);
172+
writeAddressRanges(*RangesStream, Ranges);
173173

174174
return EntryOffset;
175175
}
@@ -321,8 +321,8 @@ void DebugRangeListsSectionWriter::finalizeSection() {
321321
llvm::endianness::little);
322322

323323
std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
324-
{static_cast<uint32_t>(SizeOfArraySection + CUBodyBuffer.get()->size()),
325-
5, 8, 0, static_cast<uint32_t>(RangeEntries.size())});
324+
{static_cast<uint32_t>(SizeOfArraySection + CUBodyBuffer->size()), 5, 8,
325+
0, static_cast<uint32_t>(RangeEntries.size())});
326326
*RangesStream << *Header;
327327
*RangesStream << *CUArrayBuffer;
328328
*RangesStream << *CUBodyBuffer;
@@ -747,8 +747,8 @@ void DebugLoclistWriter::finalizeDWARF5(DIEBuilder &DIEBldr, DIE &Die) {
747747
llvm::endianness::little);
748748

749749
std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
750-
{static_cast<uint32_t>(SizeOfArraySection + LocBodyBuffer.get()->size()),
751-
5, 8, 0, NumberOfEntries});
750+
{static_cast<uint32_t>(SizeOfArraySection + LocBodyBuffer->size()), 5, 8,
751+
0, NumberOfEntries});
752752
*LocStream << *Header;
753753
*LocStream << *LocArrayBuffer;
754754
*LocStream << *LocBodyBuffer;

bolt/lib/Core/DebugNames.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ void DWARF5AcceleratorTable::writeEntries() {
648648
if (const auto Iter = EntryRelativeOffsets.find(*ParentOffset);
649649
Iter != EntryRelativeOffsets.end()) {
650650
const uint64_t PatchOffset = Entry->getPatchOffset();
651-
uint32_t *Ptr = reinterpret_cast<uint32_t *>(
652-
&EntriesBuffer.get()->data()[PatchOffset]);
651+
uint32_t *Ptr =
652+
reinterpret_cast<uint32_t *>(&EntriesBuffer->data()[PatchOffset]);
653653
*Ptr = Iter->second;
654654
} else {
655655
BC.errs() << "BOLT-WARNING: [internal-dwarf-warning]: Could not find "

bolt/lib/Core/ParallelUtilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,
103103
} // namespace
104104

105105
ThreadPoolInterface &getThreadPool(const unsigned ThreadsCount) {
106-
if (ThreadPoolPtr.get())
106+
if (ThreadPoolPtr)
107107
return *ThreadPoolPtr;
108108

109109
if (ThreadsCount > 1)

bolt/lib/Passes/AsmDump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void dumpFunction(const BinaryFunction &BF) {
175175
// Dump pseudo instructions (CFI)
176176
if (BC.MIB->isPseudo(Instr)) {
177177
if (BC.MIB->isCFI(Instr))
178-
dumpCFI(BF, Instr, *MAP.get());
178+
dumpCFI(BF, Instr, *MAP);
179179
continue;
180180
}
181181

@@ -227,7 +227,7 @@ void dumpFunction(const BinaryFunction &BF) {
227227
OS << "# Jump tables\n";
228228
// Print all jump tables.
229229
for (auto &JTI : BF.jumpTables())
230-
dumpJumpTableSymbols(OS, JTI.second, *MAP.get(), LastSection);
230+
dumpJumpTableSymbols(OS, JTI.second, *MAP, LastSection);
231231

232232
OS << "# BinaryData\n";
233233
// Print data references.

bolt/lib/Passes/RetpolineInsertion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ BinaryFunction *createNewRetpoline(BinaryContext &BC,
7878
const IndirectBranchInfo &BrInfo,
7979
bool R11Available) {
8080
auto &MIB = *BC.MIB;
81-
MCContext &Ctx = *BC.Ctx.get();
81+
MCContext &Ctx = *BC.Ctx;
8282
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: Creating a new retpoline function["
8383
<< RetpolineTag << "]\n");
8484

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,14 @@ void DataAggregator::processProfile(BinaryContext &BC) {
565565
processMemEvents();
566566

567567
// Mark all functions with registered events as having a valid profile.
568-
const auto Flags = opts::BasicAggregation ? BinaryFunction::PF_SAMPLE
569-
: BinaryFunction::PF_LBR;
570568
for (auto &BFI : BC.getBinaryFunctions()) {
571569
BinaryFunction &BF = BFI.second;
572-
FuncBranchData *FBD = getBranchData(BF);
573-
if (FBD || getFuncSampleData(BF.getNames())) {
574-
BF.markProfiled(Flags);
575-
if (FBD)
576-
BF.RawBranchCount = FBD->getNumExecutedBranches();
570+
if (FuncBranchData *FBD = getBranchData(BF)) {
571+
BF.markProfiled(BinaryFunction::PF_LBR);
572+
BF.RawBranchCount = FBD->getNumExecutedBranches();
573+
} else if (FuncSampleData *FSD = getFuncSampleData(BF.getNames())) {
574+
BF.markProfiled(BinaryFunction::PF_SAMPLE);
575+
BF.RawBranchCount = FSD->getSamples();
577576
}
578577
}
579578

@@ -630,10 +629,18 @@ StringRef DataAggregator::getLocationName(const BinaryFunction &Func,
630629

631630
bool DataAggregator::doSample(BinaryFunction &OrigFunc, uint64_t Address,
632631
uint64_t Count) {
632+
// To record executed bytes, use basic block size as is regardless of BAT.
633+
uint64_t BlockSize = 0;
634+
if (BinaryBasicBlock *BB = OrigFunc.getBasicBlockContainingOffset(
635+
Address - OrigFunc.getAddress()))
636+
BlockSize = BB->getOriginalSize();
637+
633638
BinaryFunction *ParentFunc = getBATParentFunction(OrigFunc);
634639
BinaryFunction &Func = ParentFunc ? *ParentFunc : OrigFunc;
635-
if (ParentFunc || (BAT && !BAT->isBATFunction(OrigFunc.getAddress())))
640+
if (ParentFunc || (BAT && !BAT->isBATFunction(Func.getAddress())))
636641
NumColdSamples += Count;
642+
// Attach executed bytes to parent function in case of cold fragment.
643+
Func.SampleCountInBytes += Count * BlockSize;
637644

638645
auto I = NamesToSamples.find(Func.getOneName());
639646
if (I == NamesToSamples.end()) {

bolt/lib/Profile/DataReader.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ uint64_t FuncSampleData::getSamples(uint64_t Start, uint64_t End) const {
128128
return Result;
129129
}
130130

131+
uint64_t FuncSampleData::getSamples() const {
132+
uint64_t Result = 0;
133+
for (const SampleInfo &I : Data)
134+
Result += I.Hits;
135+
return Result;
136+
}
137+
131138
void FuncSampleData::bumpCount(uint64_t Offset, uint64_t Count) {
132139
auto Iter = Index.find(Offset);
133140
if (Iter == Index.end()) {
@@ -1028,9 +1035,8 @@ ErrorOr<SampleInfo> DataReader::parseSampleInfo() {
10281035
}
10291036

10301037
ErrorOr<bool> DataReader::maybeParseNoLBRFlag() {
1031-
if (ParsingBuf.size() < 6 || ParsingBuf.substr(0, 6) != "no_lbr")
1038+
if (!ParsingBuf.consume_front("no_lbr"))
10321039
return false;
1033-
ParsingBuf = ParsingBuf.drop_front(6);
10341040
Col += 6;
10351041

10361042
if (ParsingBuf.size() > 0 && ParsingBuf[0] == ' ')
@@ -1051,9 +1057,8 @@ ErrorOr<bool> DataReader::maybeParseNoLBRFlag() {
10511057
}
10521058

10531059
ErrorOr<bool> DataReader::maybeParseBATFlag() {
1054-
if (ParsingBuf.size() < 16 || ParsingBuf.substr(0, 16) != "boltedcollection")
1060+
if (!ParsingBuf.consume_front("boltedcollection"))
10551061
return false;
1056-
ParsingBuf = ParsingBuf.drop_front(16);
10571062
Col += 16;
10581063

10591064
if (!checkAndConsumeNewLine()) {

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ static void emitDWOBuilder(const std::string &DWOName,
500500
SplitCU.getContext().dwo_info_section_units()) {
501501
if (!CU->isTypeUnit())
502502
continue;
503-
emitUnit(DWODIEBuilder, *Streamer, *CU.get());
503+
emitUnit(DWODIEBuilder, *Streamer, *CU);
504504
}
505505
emitUnit(DWODIEBuilder, *Streamer, SplitCU);
506506
} else {
507507
for (std::unique_ptr<llvm::DWARFUnit> &CU :
508508
SplitCU.getContext().dwo_compile_units())
509-
emitUnit(DWODIEBuilder, *Streamer, *CU.get());
509+
emitUnit(DWODIEBuilder, *Streamer, *CU);
510510

511511
// emit debug_types sections for dwarf4
512512
for (DWARFUnit *CU : DWODIEBuilder.getDWARF4TUVector())
@@ -685,8 +685,8 @@ void DWARFRewriter::updateDebugInfo() {
685685
DebugLocWriter &DebugLocWriter =
686686
*LocListWritersByCU[LocListWritersIndexByCU[Unit.getOffset()]].get();
687687
DebugRangesSectionWriter &RangesSectionWriter =
688-
Unit.getVersion() >= 5 ? *RangeListsSectionWriter.get()
689-
: *LegacyRangesSectionWriter.get();
688+
Unit.getVersion() >= 5 ? *RangeListsSectionWriter
689+
: *LegacyRangesSectionWriter;
690690
DebugAddrWriter &AddressWriter =
691691
*AddressWritersByCU[Unit.getOffset()].get();
692692
if (Unit.getVersion() >= 5)
@@ -698,7 +698,7 @@ void DWARFRewriter::updateDebugInfo() {
698698
if (!SplitCU)
699699
StrOffstsWriter->finalizeSection(Unit, DIEBlder);
700700
} else if (SplitCU) {
701-
RangesBase = LegacyRangesSectionWriter.get()->getSectionOffset();
701+
RangesBase = LegacyRangesSectionWriter->getSectionOffset();
702702
}
703703

704704
updateUnitDebugInfo(Unit, DIEBlder, DebugLocWriter, RangesSectionWriter,
@@ -750,7 +750,7 @@ void DWARFRewriter::updateDebugInfo() {
750750
auto DWODIEBuilderPtr = std::make_unique<DIEBuilder>(
751751
BC, &(**SplitCU).getContext(), DebugNamesTable, CU);
752752
DIEBuilder &DWODIEBuilder =
753-
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr)).get();
753+
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr));
754754
if (CU->getVersion() >= 5)
755755
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
756756
// Important to capture CU and SplitCU by value here, otherwise when the
@@ -1403,7 +1403,7 @@ void DWARFRewriter::updateLineTableOffsets(const MCAssembler &Asm) {
14031403
continue;
14041404

14051405
std::optional<uint64_t> StmtOffset =
1406-
GetStatementListValue(CU.get()->getUnitDIE());
1406+
GetStatementListValue(CU->getUnitDIE());
14071407
if (!StmtOffset)
14081408
continue;
14091409

@@ -1479,13 +1479,13 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
14791479
for (std::unique_ptr<llvm::DWARFUnit> &CU : BC.DwCtx->info_section_units()) {
14801480
if (!CU->isTypeUnit())
14811481
continue;
1482-
updateLineTable(*CU.get());
1483-
emitUnit(DIEBlder, Streamer, *CU.get());
1482+
updateLineTable(*CU);
1483+
emitUnit(DIEBlder, Streamer, *CU);
14841484
uint32_t StartOffset = CUOffset;
1485-
DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit(*CU.get());
1486-
CUOffset += CU.get()->getHeaderSize();
1485+
DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit(*CU);
1486+
CUOffset += CU->getHeaderSize();
14871487
CUOffset += UnitDIE->getSize();
1488-
CUMap[CU.get()->getOffset()] = {StartOffset, CUOffset - StartOffset - 4};
1488+
CUMap[CU->getOffset()] = {StartOffset, CUOffset - StartOffset - 4};
14891489
}
14901490

14911491
// Emit Type Unit of DWARF 4 to .debug_type section

bolt/lib/Rewrite/MachORewriteInstance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,21 @@ Error MachORewriteInstance::setProfile(StringRef Filename) {
108108
void MachORewriteInstance::preprocessProfileData() {
109109
if (!ProfileReader)
110110
return;
111-
if (Error E = ProfileReader->preprocessProfile(*BC.get()))
111+
if (Error E = ProfileReader->preprocessProfile(*BC))
112112
report_error("cannot pre-process profile", std::move(E));
113113
}
114114

115115
void MachORewriteInstance::processProfileDataPreCFG() {
116116
if (!ProfileReader)
117117
return;
118-
if (Error E = ProfileReader->readProfilePreCFG(*BC.get()))
118+
if (Error E = ProfileReader->readProfilePreCFG(*BC))
119119
report_error("cannot read profile pre-CFG", std::move(E));
120120
}
121121

122122
void MachORewriteInstance::processProfileData() {
123123
if (!ProfileReader)
124124
return;
125-
if (Error E = ProfileReader->readProfile(*BC.get()))
125+
if (Error E = ProfileReader->readProfile(*BC))
126126
report_error("cannot read profile", std::move(E));
127127
}
128128

0 commit comments

Comments
 (0)