Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ class BinaryContext {
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(
Expand Down
4 changes: 2 additions & 2 deletions bolt/include/bolt/Core/BinaryFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,15 +867,15 @@ class BinaryFunction {
/// 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();

/// 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())
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/DIEBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class DIEBuilder {
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
Expand Down
8 changes: 4 additions & 4 deletions bolt/lib/Core/DIEBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Core/DebugNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Core/ParallelUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Passes/AsmDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/RetpolineInsertion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
24 changes: 12 additions & 12 deletions bolt/lib/Rewrite/DWARFRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Rewrite/MachORewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand Down Expand Up @@ -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));
}

Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions bolt/lib/RuntimeLibs/RuntimeLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Target/AArch64/AArch64MCSymbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AArch64MCSymbolizer : public MCSymbolizer {

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;
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Target/X86/X86MCSymbolizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class X86MCSymbolizer : public MCSymbolizer {

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;
Expand Down
4 changes: 2 additions & 2 deletions bolt/unittests/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ struct BinaryContextTester : public testing::TestWithParam<Triple::ArchType> {
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);
}

Expand Down
4 changes: 2 additions & 2 deletions bolt/unittests/Core/MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ struct MCPlusBuilderTester : public testing::TestWithParam<Triple::ArchType> {
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(),
Expand Down
4 changes: 2 additions & 2 deletions bolt/unittests/Core/MemoryMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ struct MemoryMapsTester : public testing::TestWithParam<Triple::ArchType> {
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);
}

Expand Down
Loading