Skip to content

Commit e324a80

Browse files
[BOLT] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
1 parent c68af42 commit e324a80

19 files changed

+71
-71
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class BinaryContext {
323323
if (FileBuildID)
324324
return StringRef(*FileBuildID);
325325

326-
return None;
326+
return std::nullopt;
327327
}
328328
void setFileBuildID(StringRef ID) { FileBuildID = std::string(ID); }
329329

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ class BinaryFunction {
980980
if (Callback(StringRef(Name)))
981981
return StringRef(Name);
982982

983-
return None;
983+
return std::nullopt;
984984
}
985985

986986
/// Check if (possibly one out of many) function name matches the given
@@ -1318,7 +1318,7 @@ class BinaryFunction {
13181318
/// Return the name of the section this function originated from.
13191319
Optional<StringRef> getOriginSectionName() const {
13201320
if (!OriginSection)
1321-
return None;
1321+
return std::nullopt;
13221322
return OriginSection->getName();
13231323
}
13241324

bolt/include/bolt/Core/DebugData.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ class DebugAbbrevWriter {
10161016
/// Most of the time, using type units with DWO is not a good idea.
10171017
/// If type units are used, the caller is responsible for verifying
10181018
/// that abbreviations are shared by CU and TUs.
1019-
DebugAbbrevWriter(DWARFContext &Context, Optional<uint64_t> DWOId = None)
1019+
DebugAbbrevWriter(DWARFContext &Context,
1020+
Optional<uint64_t> DWOId = std::nullopt)
10201021
: Context(Context), DWOId(DWOId) {}
10211022

10221023
DebugAbbrevWriter(const DebugAbbrevWriter &) = delete;

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class MCPlusBuilder {
136136
unsigned Index) const {
137137
const MCInst *AnnotationInst = getAnnotationInst(Inst);
138138
if (!AnnotationInst)
139-
return None;
139+
return std::nullopt;
140140

141141
for (int I = AnnotationInst->getNumOperands() - 1; I >= 0; --I) {
142142
int64_t ImmValue = AnnotationInst->getOperand(I).getImm();
@@ -145,7 +145,7 @@ class MCPlusBuilder {
145145
}
146146
}
147147

148-
return None;
148+
return std::nullopt;
149149
}
150150

151151
protected:
@@ -1670,7 +1670,7 @@ class MCPlusBuilder {
16701670
auto AI = AnnotationNameIndexMap.find(Name);
16711671
if (AI != AnnotationNameIndexMap.end())
16721672
return AI->second;
1673-
return None;
1673+
return std::nullopt;
16741674
}
16751675

16761676
/// Return annotation index matching the \p Name. Create a new index if the

bolt/include/bolt/Passes/ReachingDefOrUse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ReachingDefOrUse
3434

3535
public:
3636
ReachingDefOrUse(const RegAnalysis &RA, BinaryFunction &BF,
37-
Optional<MCPhysReg> TrackingReg = None,
37+
Optional<MCPhysReg> TrackingReg = std::nullopt,
3838
MCPlusBuilder::AllocatorIdTy AllocId = 0)
3939
: InstrsDataflowAnalysis<ReachingDefOrUse<Def>, !Def>(BF, AllocId),
4040
RA(RA), TrackingReg(TrackingReg) {}
@@ -125,7 +125,7 @@ class ReachingDefOrUse
125125
}
126126
// Gen
127127
if (!this->BC.MIB->isCFI(Point)) {
128-
if (TrackingReg == None) {
128+
if (TrackingReg == std::nullopt) {
129129
// Track all instructions
130130
Next.set(this->ExprToIdx[&Point]);
131131
} else {

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class DWARFRewriter {
9898
DebugAbbrevWriter &AbbrevWriter,
9999
DebugLocWriter &DebugLocWriter,
100100
DebugRangesSectionWriter &RangesWriter,
101-
Optional<uint64_t> RangesBase = None);
101+
Optional<uint64_t> RangesBase = std::nullopt);
102102

103103
/// Patches the binary for an object's address ranges to be updated.
104104
/// The object can be anything that has associated address ranges via either
@@ -109,12 +109,10 @@ class DWARFRewriter {
109109
/// \p DIE is the object's DIE in the input binary.
110110
/// \p RangesBase if present, update \p DIE to use DW_AT_GNU_ranges_base
111111
/// attribute.
112-
void updateDWARFObjectAddressRanges(const DWARFDie DIE,
113-
uint64_t DebugRangesOffset,
114-
SimpleBinaryPatcher &DebugInfoPatcher,
115-
DebugAbbrevWriter &AbbrevWriter,
116-
uint64_t LowPCToUse,
117-
Optional<uint64_t> RangesBase = None);
112+
void updateDWARFObjectAddressRanges(
113+
const DWARFDie DIE, uint64_t DebugRangesOffset,
114+
SimpleBinaryPatcher &DebugInfoPatcher, DebugAbbrevWriter &AbbrevWriter,
115+
uint64_t LowPCToUse, Optional<uint64_t> RangesBase = std::nullopt);
118116

119117
std::unique_ptr<DebugBufferVector>
120118
makeFinalLocListsSection(DebugInfoBinaryPatcher &DebugInfoPatcher,
@@ -165,15 +163,16 @@ class DWARFRewriter {
165163
void convertToRangesPatchAbbrev(const DWARFUnit &Unit,
166164
const DWARFAbbreviationDeclaration *Abbrev,
167165
DebugAbbrevWriter &AbbrevWriter,
168-
Optional<uint64_t> RangesBase = None);
166+
Optional<uint64_t> RangesBase = std::nullopt);
169167

170168
/// Update \p DIE that was using DW_AT_(low|high)_pc with DW_AT_ranges offset.
171169
/// Updates to the DIE should be synced with abbreviation updates using the
172170
/// function above.
173-
void convertToRangesPatchDebugInfo(DWARFDie DIE, uint64_t RangesSectionOffset,
174-
SimpleBinaryPatcher &DebugInfoPatcher,
175-
uint64_t LowPCToUse,
176-
Optional<uint64_t> RangesBase = None);
171+
void
172+
convertToRangesPatchDebugInfo(DWARFDie DIE, uint64_t RangesSectionOffset,
173+
SimpleBinaryPatcher &DebugInfoPatcher,
174+
uint64_t LowPCToUse,
175+
Optional<uint64_t> RangesBase = std::nullopt);
177176

178177
/// Helper function for creating and returning per-DWO patchers/writers.
179178
template <class T, class Patcher>

bolt/lib/Core/BinaryContext.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,8 @@ unsigned BinaryContext::addDebugFilenameToUnit(const uint32_t DestCUID,
14941494
FileName = *FName;
14951495
assert(FileName != "");
14961496
DWARFCompileUnit *DstUnit = DwCtx->getCompileUnitForOffset(DestCUID);
1497-
return cantFail(getDwarfFile(Dir, FileName, 0, None, None, DestCUID,
1498-
DstUnit->getVersion()));
1497+
return cantFail(getDwarfFile(Dir, FileName, 0, std::nullopt, std::nullopt,
1498+
DestCUID, DstUnit->getVersion()));
14991499
}
15001500

15011501
std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
@@ -1530,7 +1530,7 @@ std::vector<BinaryFunction *> BinaryContext::getAllBinaryFunctions() {
15301530
Optional<DWARFUnit *> BinaryContext::getDWOCU(uint64_t DWOId) {
15311531
auto Iter = DWOCUs.find(DWOId);
15321532
if (Iter == DWOCUs.end())
1533-
return None;
1533+
return std::nullopt;
15341534

15351535
return Iter->second;
15361536
}
@@ -1657,16 +1657,16 @@ void BinaryContext::preprocessDebugInfo() {
16571657
Iter->second->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
16581658
}
16591659
BinaryLineTable.setRootFile(CU->getCompilationDir(), *Name, Checksum,
1660-
None);
1660+
std::nullopt);
16611661
}
16621662

16631663
BinaryLineTable.setDwarfVersion(DwarfVersion);
16641664

16651665
// Assign a unique label to every line table, one per CU.
16661666
// Make sure empty debug line tables are registered too.
16671667
if (FileNames.empty()) {
1668-
cantFail(
1669-
getDwarfFile("", "<unknown>", 0, None, None, CUID, DwarfVersion));
1668+
cantFail(getDwarfFile("", "<unknown>", 0, std::nullopt, std::nullopt,
1669+
CUID, DwarfVersion));
16701670
continue;
16711671
}
16721672
const uint32_t Offset = DwarfVersion < 5 ? 1 : 0;
@@ -1686,8 +1686,8 @@ void BinaryContext::preprocessDebugInfo() {
16861686
Optional<MD5::MD5Result> Checksum;
16871687
if (DwarfVersion >= 5 && LineTable->Prologue.ContentTypes.HasMD5)
16881688
Checksum = LineTable->Prologue.FileNames[I].Checksum;
1689-
cantFail(
1690-
getDwarfFile(Dir, FileName, 0, Checksum, None, CUID, DwarfVersion));
1689+
cantFail(getDwarfFile(Dir, FileName, 0, Checksum, std::nullopt, CUID,
1690+
DwarfVersion));
16911691
}
16921692
}
16931693
}
@@ -1897,7 +1897,7 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress,
18971897
}
18981898
}
18991899

1900-
return None;
1900+
return std::nullopt;
19011901
}
19021902

19031903
ErrorOr<BinarySection &> BinaryContext::getSectionForAddress(uint64_t Address) {

bolt/lib/Core/DebugData.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ findAttributeInfo(const DWARFDie DIE,
5252
Optional<DWARFFormValue> Value =
5353
AbbrevDecl->getAttributeValueFromOffset(Index, Offset, U);
5454
if (!Value)
55-
return None;
55+
return std::nullopt;
5656
// AttributeSpec
5757
const DWARFAbbreviationDeclaration::AttributeSpec *AttrVal =
5858
AbbrevDecl->attributes().begin() + Index;
@@ -76,14 +76,14 @@ findAttributeInfo(const DWARFDie DIE,
7676
Optional<AttrInfo> findAttributeInfo(const DWARFDie DIE,
7777
dwarf::Attribute Attr) {
7878
if (!DIE.isValid())
79-
return None;
79+
return std::nullopt;
8080
const DWARFAbbreviationDeclaration *AbbrevDecl =
8181
DIE.getAbbreviationDeclarationPtr();
8282
if (!AbbrevDecl)
83-
return None;
83+
return std::nullopt;
8484
Optional<uint32_t> Index = AbbrevDecl->findAttributeIndex(Attr);
8585
if (!Index)
86-
return None;
86+
return std::nullopt;
8787
return findAttributeInfo(DIE, AbbrevDecl, *Index);
8888
}
8989

@@ -1585,7 +1585,7 @@ void DwarfLineTable::emit(BinaryContext &BC, MCStreamer &Streamer) {
15851585
if (LineTables.empty())
15861586
return;
15871587
// In a v5 non-split line table, put the strings in a separate section.
1588-
Optional<MCDwarfLineStr> LineStr(None);
1588+
Optional<MCDwarfLineStr> LineStr(std::nullopt);
15891589
ErrorOr<BinarySection &> LineStrSection =
15901590
BC.getUniqueSectionByName(".debug_line_str");
15911591
// Some versions of GCC output DWARF5 .debug_info, but DWARF4 or lower

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ bool MCPlusBuilder::isTailCall(const MCInst &Inst) const {
135135

136136
Optional<MCLandingPad> MCPlusBuilder::getEHInfo(const MCInst &Inst) const {
137137
if (!isCall(Inst))
138-
return None;
138+
return std::nullopt;
139139
Optional<int64_t> LPSym =
140140
getAnnotationOpValue(Inst, MCAnnotation::kEHLandingPad);
141141
if (!LPSym)
142-
return None;
142+
return std::nullopt;
143143
Optional<int64_t> Action =
144144
getAnnotationOpValue(Inst, MCAnnotation::kEHAction);
145145
if (!Action)
146-
return None;
146+
return std::nullopt;
147147

148148
return std::make_pair(reinterpret_cast<const MCSymbol *>(*LPSym),
149149
static_cast<uint64_t>(*Action));
@@ -221,7 +221,7 @@ MCPlusBuilder::getConditionalTailCall(const MCInst &Inst) const {
221221
Optional<int64_t> Value =
222222
getAnnotationOpValue(Inst, MCAnnotation::kConditionalTailCall);
223223
if (!Value)
224-
return None;
224+
return std::nullopt;
225225
return static_cast<uint64_t>(*Value);
226226
}
227227

@@ -243,7 +243,7 @@ bool MCPlusBuilder::unsetConditionalTailCall(MCInst &Inst) {
243243
Optional<uint32_t> MCPlusBuilder::getOffset(const MCInst &Inst) const {
244244
Optional<int64_t> Value = getAnnotationOpValue(Inst, MCAnnotation::kOffset);
245245
if (!Value)
246-
return None;
246+
return std::nullopt;
247247
return static_cast<uint32_t>(*Value);
248248
}
249249

bolt/lib/Passes/AsmDump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void dumpFunction(const BinaryFunction &BF) {
174174
/*ShowInst=*/false));
175175
AsmStreamer->initSections(true, *BC.STI);
176176
std::unique_ptr<TargetMachine> TM(BC.TheTarget->createTargetMachine(
177-
BC.TripleName, "", "", TargetOptions(), None));
177+
BC.TripleName, "", "", TargetOptions(), std::nullopt));
178178
std::unique_ptr<AsmPrinter> MAP(
179179
BC.TheTarget->createAsmPrinter(*TM, std::move(AsmStreamer)));
180180

bolt/lib/Passes/DataflowInfoManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ReachingDefOrUse</*Def=*/true> &DataflowInfoManager::getReachingDefs() {
1919
if (RD)
2020
return *RD;
2121
assert(RA && "RegAnalysis required");
22-
RD.reset(new ReachingDefOrUse<true>(*RA, BF, None, AllocatorId));
22+
RD.reset(new ReachingDefOrUse<true>(*RA, BF, std::nullopt, AllocatorId));
2323
RD->run();
2424
return *RD;
2525
}
@@ -30,7 +30,7 @@ ReachingDefOrUse</*Def=*/false> &DataflowInfoManager::getReachingUses() {
3030
if (RU)
3131
return *RU;
3232
assert(RA && "RegAnalysis required");
33-
RU.reset(new ReachingDefOrUse<false>(*RA, BF, None, AllocatorId));
33+
RU.reset(new ReachingDefOrUse<false>(*RA, BF, std::nullopt, AllocatorId));
3434
RU->run();
3535
return *RU;
3636
}

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress,
263263

264264
auto Iter = Maps.find(FuncAddress);
265265
if (Iter == Maps.end())
266-
return None;
266+
return std::nullopt;
267267

268268
const MapTy &Map = Iter->second;
269269
auto FromIter = Map.upper_bound(From);

0 commit comments

Comments
 (0)