[BOLT] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139403)

This commit is contained in:
Kazu Hirata 2025-05-10 13:39:15 -07:00 committed by GitHub
parent 6fd3381639
commit d5b170c39b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 50 additions and 50 deletions

View File

@ -1499,7 +1499,7 @@ public:
MCEInstance.LocalCtx.reset(
new MCContext(*TheTriple, AsmInfo.get(), MRI.get(), STI.get()));
MCEInstance.LocalMOFI.reset(
TheTarget->createMCObjectFileInfo(*MCEInstance.LocalCtx.get(),
TheTarget->createMCObjectFileInfo(*MCEInstance.LocalCtx,
/*PIC=*/!HasFixedLoadAddress));
MCEInstance.LocalCtx->setObjectFileInfo(MCEInstance.LocalMOFI.get());
MCEInstance.MCE.reset(

View File

@ -867,7 +867,7 @@ public:
/// Returns if BinaryDominatorTree has been constructed for this function.
bool hasDomTree() const { return BDT != nullptr; }
BinaryDominatorTree &getDomTree() { return *BDT.get(); }
BinaryDominatorTree &getDomTree() { return *BDT; }
/// Constructs DomTree for this function.
void constructDomTree();
@ -875,7 +875,7 @@ public:
/// Returns if loop detection has been run for this function.
bool hasLoopInfo() const { return BLI != nullptr; }
const BinaryLoopInfo &getLoopInfo() { return *BLI.get(); }
const BinaryLoopInfo &getLoopInfo() { return *BLI; }
bool isLoopFree() {
if (!hasLoopInfo())

View File

@ -137,7 +137,7 @@ private:
std::unordered_map<std::string, uint32_t> NameToIndexMap;
/// Returns current state of the DIEBuilder
State &getState() { return *BuilderState.get(); }
State &getState() { return *BuilderState; }
/// Resolve the reference in DIE, if target is not loaded into IR,
/// pre-allocate it. \p RefCU will be updated to the Unit specific by \p

View File

@ -292,10 +292,10 @@ void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
getState().Type = ProcessingType::DWARF4TUs;
for (std::unique_ptr<DWARFUnit> &DU : CU4TURanges)
registerUnit(*DU.get(), false);
registerUnit(*DU, false);
for (std::unique_ptr<DWARFUnit> &DU : CU4TURanges)
constructFromUnit(*DU.get());
constructFromUnit(*DU);
DWARFContext::unit_iterator_range CURanges =
isDWO() ? DwarfContext->dwo_info_section_units()
@ -308,7 +308,7 @@ void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
for (std::unique_ptr<DWARFUnit> &DU : CURanges) {
if (!DU->isTypeUnit())
continue;
registerUnit(*DU.get(), false);
registerUnit(*DU, false);
}
for (DWARFUnit *DU : getState().DWARF5TUVector) {
@ -335,7 +335,7 @@ void DIEBuilder::buildCompileUnits(const bool Init) {
for (std::unique_ptr<DWARFUnit> &DU : CURanges) {
if (DU->isTypeUnit())
continue;
registerUnit(*DU.get(), false);
registerUnit(*DU, false);
}
// Using DULIst since it can be modified by cross CU refrence resolution.

View File

@ -142,7 +142,7 @@ DebugRangesSectionWriter::DebugRangesSectionWriter() {
void DebugRangesSectionWriter::initSection() {
// Adds an empty range to the buffer.
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
writeAddressRanges(*RangesStream, DebugAddressRangesVector{});
}
uint64_t DebugRangesSectionWriter::addRanges(
@ -169,7 +169,7 @@ uint64_t DebugRangesSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
// unique and correct offsets in patches.
std::lock_guard<std::mutex> Lock(WriterMutex);
const uint32_t EntryOffset = RangesBuffer->size();
writeAddressRanges(*RangesStream.get(), Ranges);
writeAddressRanges(*RangesStream, Ranges);
return EntryOffset;
}
@ -321,8 +321,8 @@ void DebugRangeListsSectionWriter::finalizeSection() {
llvm::endianness::little);
std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
{static_cast<uint32_t>(SizeOfArraySection + CUBodyBuffer.get()->size()),
5, 8, 0, static_cast<uint32_t>(RangeEntries.size())});
{static_cast<uint32_t>(SizeOfArraySection + CUBodyBuffer->size()), 5, 8,
0, static_cast<uint32_t>(RangeEntries.size())});
*RangesStream << *Header;
*RangesStream << *CUArrayBuffer;
*RangesStream << *CUBodyBuffer;
@ -747,8 +747,8 @@ void DebugLoclistWriter::finalizeDWARF5(DIEBuilder &DIEBldr, DIE &Die) {
llvm::endianness::little);
std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
{static_cast<uint32_t>(SizeOfArraySection + LocBodyBuffer.get()->size()),
5, 8, 0, NumberOfEntries});
{static_cast<uint32_t>(SizeOfArraySection + LocBodyBuffer->size()), 5, 8,
0, NumberOfEntries});
*LocStream << *Header;
*LocStream << *LocArrayBuffer;
*LocStream << *LocBodyBuffer;

View File

@ -648,8 +648,8 @@ void DWARF5AcceleratorTable::writeEntries() {
if (const auto Iter = EntryRelativeOffsets.find(*ParentOffset);
Iter != EntryRelativeOffsets.end()) {
const uint64_t PatchOffset = Entry->getPatchOffset();
uint32_t *Ptr = reinterpret_cast<uint32_t *>(
&EntriesBuffer.get()->data()[PatchOffset]);
uint32_t *Ptr =
reinterpret_cast<uint32_t *>(&EntriesBuffer->data()[PatchOffset]);
*Ptr = Iter->second;
} else {
BC.errs() << "BOLT-WARNING: [internal-dwarf-warning]: Could not find "

View File

@ -103,7 +103,7 @@ inline unsigned estimateTotalCost(const BinaryContext &BC,
} // namespace
ThreadPoolInterface &getThreadPool(const unsigned ThreadsCount) {
if (ThreadPoolPtr.get())
if (ThreadPoolPtr)
return *ThreadPoolPtr;
if (ThreadsCount > 1)

View File

@ -175,7 +175,7 @@ void dumpFunction(const BinaryFunction &BF) {
// Dump pseudo instructions (CFI)
if (BC.MIB->isPseudo(Instr)) {
if (BC.MIB->isCFI(Instr))
dumpCFI(BF, Instr, *MAP.get());
dumpCFI(BF, Instr, *MAP);
continue;
}
@ -227,7 +227,7 @@ void dumpFunction(const BinaryFunction &BF) {
OS << "# Jump tables\n";
// Print all jump tables.
for (auto &JTI : BF.jumpTables())
dumpJumpTableSymbols(OS, JTI.second, *MAP.get(), LastSection);
dumpJumpTableSymbols(OS, JTI.second, *MAP, LastSection);
OS << "# BinaryData\n";
// Print data references.

View File

@ -78,7 +78,7 @@ BinaryFunction *createNewRetpoline(BinaryContext &BC,
const IndirectBranchInfo &BrInfo,
bool R11Available) {
auto &MIB = *BC.MIB;
MCContext &Ctx = *BC.Ctx.get();
MCContext &Ctx = *BC.Ctx;
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: Creating a new retpoline function["
<< RetpolineTag << "]\n");

View File

@ -500,13 +500,13 @@ static void emitDWOBuilder(const std::string &DWOName,
SplitCU.getContext().dwo_info_section_units()) {
if (!CU->isTypeUnit())
continue;
emitUnit(DWODIEBuilder, *Streamer, *CU.get());
emitUnit(DWODIEBuilder, *Streamer, *CU);
}
emitUnit(DWODIEBuilder, *Streamer, SplitCU);
} else {
for (std::unique_ptr<llvm::DWARFUnit> &CU :
SplitCU.getContext().dwo_compile_units())
emitUnit(DWODIEBuilder, *Streamer, *CU.get());
emitUnit(DWODIEBuilder, *Streamer, *CU);
// emit debug_types sections for dwarf4
for (DWARFUnit *CU : DWODIEBuilder.getDWARF4TUVector())
@ -685,8 +685,8 @@ void DWARFRewriter::updateDebugInfo() {
DebugLocWriter &DebugLocWriter =
*LocListWritersByCU[LocListWritersIndexByCU[Unit.getOffset()]].get();
DebugRangesSectionWriter &RangesSectionWriter =
Unit.getVersion() >= 5 ? *RangeListsSectionWriter.get()
: *LegacyRangesSectionWriter.get();
Unit.getVersion() >= 5 ? *RangeListsSectionWriter
: *LegacyRangesSectionWriter;
DebugAddrWriter &AddressWriter =
*AddressWritersByCU[Unit.getOffset()].get();
if (Unit.getVersion() >= 5)
@ -698,7 +698,7 @@ void DWARFRewriter::updateDebugInfo() {
if (!SplitCU)
StrOffstsWriter->finalizeSection(Unit, DIEBlder);
} else if (SplitCU) {
RangesBase = LegacyRangesSectionWriter.get()->getSectionOffset();
RangesBase = LegacyRangesSectionWriter->getSectionOffset();
}
updateUnitDebugInfo(Unit, DIEBlder, DebugLocWriter, RangesSectionWriter,
@ -750,7 +750,7 @@ void DWARFRewriter::updateDebugInfo() {
auto DWODIEBuilderPtr = std::make_unique<DIEBuilder>(
BC, &(**SplitCU).getContext(), DebugNamesTable, CU);
DIEBuilder &DWODIEBuilder =
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr)).get();
*DWODIEBuildersByCU.emplace_back(std::move(DWODIEBuilderPtr));
if (CU->getVersion() >= 5)
StrOffstsWriter->finalizeSection(*CU, DIEBlder);
// Important to capture CU and SplitCU by value here, otherwise when the
@ -1403,7 +1403,7 @@ void DWARFRewriter::updateLineTableOffsets(const MCAssembler &Asm) {
continue;
std::optional<uint64_t> StmtOffset =
GetStatementListValue(CU.get()->getUnitDIE());
GetStatementListValue(CU->getUnitDIE());
if (!StmtOffset)
continue;
@ -1479,13 +1479,13 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
for (std::unique_ptr<llvm::DWARFUnit> &CU : BC.DwCtx->info_section_units()) {
if (!CU->isTypeUnit())
continue;
updateLineTable(*CU.get());
emitUnit(DIEBlder, Streamer, *CU.get());
updateLineTable(*CU);
emitUnit(DIEBlder, Streamer, *CU);
uint32_t StartOffset = CUOffset;
DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit(*CU.get());
CUOffset += CU.get()->getHeaderSize();
DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit(*CU);
CUOffset += CU->getHeaderSize();
CUOffset += UnitDIE->getSize();
CUMap[CU.get()->getOffset()] = {StartOffset, CUOffset - StartOffset - 4};
CUMap[CU->getOffset()] = {StartOffset, CUOffset - StartOffset - 4};
}
// Emit Type Unit of DWARF 4 to .debug_type section

View File

@ -108,21 +108,21 @@ Error MachORewriteInstance::setProfile(StringRef Filename) {
void MachORewriteInstance::preprocessProfileData() {
if (!ProfileReader)
return;
if (Error E = ProfileReader->preprocessProfile(*BC.get()))
if (Error E = ProfileReader->preprocessProfile(*BC))
report_error("cannot pre-process profile", std::move(E));
}
void MachORewriteInstance::processProfileDataPreCFG() {
if (!ProfileReader)
return;
if (Error E = ProfileReader->readProfilePreCFG(*BC.get()))
if (Error E = ProfileReader->readProfilePreCFG(*BC))
report_error("cannot read profile pre-CFG", std::move(E));
}
void MachORewriteInstance::processProfileData() {
if (!ProfileReader)
return;
if (Error E = ProfileReader->readProfile(*BC.get()))
if (Error E = ProfileReader->readProfile(*BC))
report_error("cannot read profile", std::move(E));
}

View File

@ -3280,7 +3280,7 @@ void RewriteInstance::preprocessProfileData() {
ProfileReader->setBAT(&*BAT);
}
if (Error E = ProfileReader->preprocessProfile(*BC.get()))
if (Error E = ProfileReader->preprocessProfile(*BC))
report_error("cannot pre-process profile", std::move(E));
if (!BC->hasSymbolsWithFileName() && ProfileReader->hasLocalsWithFileName() &&
@ -3335,7 +3335,7 @@ void RewriteInstance::processProfileDataPreCFG() {
NamedRegionTimer T("processprofile-precfg", "process profile data pre-CFG",
TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
if (Error E = ProfileReader->readProfilePreCFG(*BC.get()))
if (Error E = ProfileReader->readProfilePreCFG(*BC))
report_error("cannot read profile pre-CFG", std::move(E));
}
@ -3346,7 +3346,7 @@ void RewriteInstance::processProfileData() {
NamedRegionTimer T("processprofile", "process profile data", TimerGroupName,
TimerGroupDesc, opts::TimeRewrite);
if (Error E = ProfileReader->readProfile(*BC.get()))
if (Error E = ProfileReader->readProfile(*BC))
report_error("cannot read profile", std::move(E));
if (opts::PrintProfile || opts::PrintAll) {

View File

@ -96,7 +96,7 @@ void RuntimeLibrary::loadLibrary(StringRef LibPath, BOLTLinker &Linker,
if (Magic == file_magic::archive) {
Error Err = Error::success();
object::Archive Archive(B.get()->getMemBufferRef(), Err);
object::Archive Archive(B->getMemBufferRef(), Err);
for (const object::Archive::Child &C : Archive.children(Err)) {
std::unique_ptr<object::Binary> Bin = cantFail(C.getAsBinary());
if (object::ObjectFile *Obj = dyn_cast<object::ObjectFile>(&*Bin))
@ -105,9 +105,9 @@ void RuntimeLibrary::loadLibrary(StringRef LibPath, BOLTLinker &Linker,
check_error(std::move(Err), B->getBufferIdentifier());
} else if (Magic == file_magic::elf_relocatable ||
Magic == file_magic::elf_shared_object) {
std::unique_ptr<object::ObjectFile> Obj = cantFail(
object::ObjectFile::createObjectFile(B.get()->getMemBufferRef()),
"error creating in-memory object");
std::unique_ptr<object::ObjectFile> Obj =
cantFail(object::ObjectFile::createObjectFile(B->getMemBufferRef()),
"error creating in-memory object");
Linker.loadObject(Obj->getMemoryBufferRef(), MapSections);
} else {
errs() << "BOLT-ERROR: unrecognized library format: " << LibPath << "\n";

View File

@ -33,7 +33,7 @@ protected:
public:
AArch64MCSymbolizer(BinaryFunction &Function, bool CreateNewSymbols = true)
: MCSymbolizer(*Function.getBinaryContext().Ctx.get(), nullptr),
: MCSymbolizer(*Function.getBinaryContext().Ctx, nullptr),
Function(Function), CreateNewSymbols(CreateNewSymbols) {}
AArch64MCSymbolizer(const AArch64MCSymbolizer &) = delete;

View File

@ -25,7 +25,7 @@ protected:
public:
X86MCSymbolizer(BinaryFunction &Function, bool CreateNewSymbols = true)
: MCSymbolizer(*Function.getBinaryContext().Ctx.get(), nullptr),
: MCSymbolizer(*Function.getBinaryContext().Ctx, nullptr),
Function(Function), CreateNewSymbols(CreateNewSymbols) {}
X86MCSymbolizer(const X86MCSymbolizer &) = delete;

View File

@ -53,8 +53,8 @@ protected:
Relocation::Arch = ObjFile->makeTriple().getArch();
BC = cantFail(BinaryContext::createBinaryContext(
ObjFile->makeTriple(), std::make_shared<orc::SymbolStringPool>(),
ObjFile->getFileName(), nullptr, true,
DWARFContext::create(*ObjFile.get()), {llvm::outs(), llvm::errs()}));
ObjFile->getFileName(), nullptr, true, DWARFContext::create(*ObjFile),
{llvm::outs(), llvm::errs()}));
ASSERT_FALSE(!BC);
}

View File

@ -64,8 +64,8 @@ protected:
Relocation::Arch = ObjFile->makeTriple().getArch();
BC = cantFail(BinaryContext::createBinaryContext(
ObjFile->makeTriple(), std::make_shared<orc::SymbolStringPool>(),
ObjFile->getFileName(), nullptr, true,
DWARFContext::create(*ObjFile.get()), {llvm::outs(), llvm::errs()}));
ObjFile->getFileName(), nullptr, true, DWARFContext::create(*ObjFile),
{llvm::outs(), llvm::errs()}));
ASSERT_FALSE(!BC);
BC->initializeTarget(std::unique_ptr<MCPlusBuilder>(
createMCPlusBuilder(GetParam(), BC->MIA.get(), BC->MII.get(),

View File

@ -63,8 +63,8 @@ protected:
Relocation::Arch = ObjFile->makeTriple().getArch();
BC = cantFail(BinaryContext::createBinaryContext(
ObjFile->makeTriple(), std::make_shared<orc::SymbolStringPool>(),
ObjFile->getFileName(), nullptr, true,
DWARFContext::create(*ObjFile.get()), {llvm::outs(), llvm::errs()}));
ObjFile->getFileName(), nullptr, true, DWARFContext::create(*ObjFile),
{llvm::outs(), llvm::errs()}));
ASSERT_FALSE(!BC);
}