[llvm] e9e64f7 - [Bitcode] Use std::nullopt instead of None (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 20:36:18 PST 2022
Author: Kazu Hirata
Date: 2022-12-02T20:36:05-08:00
New Revision: e9e64f7c9e8af778faa62d1b412f190bb3e85f3c
URL: https://github.com/llvm/llvm-project/commit/e9e64f7c9e8af778faa62d1b412f190bb3e85f3c
DIFF: https://github.com/llvm/llvm-project/commit/e9e64f7c9e8af778faa62d1b412f190bb3e85f3c.diff
LOG: [Bitcode] 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
Added:
Modified:
llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
llvm/include/llvm/Bitcode/BitcodeReader.h
llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
index 102e2257abccc..c345563b6d1a3 100644
--- a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
+++ b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
@@ -85,18 +85,19 @@ class BitcodeAnalyzer {
std::map<unsigned, PerBlockIDStats> BlockIDStats;
public:
- BitcodeAnalyzer(StringRef Buffer, Optional<StringRef> BlockInfoBuffer = None);
+ BitcodeAnalyzer(StringRef Buffer,
+ Optional<StringRef> BlockInfoBuffer = std::nullopt);
/// Analyze the bitcode file.
- Error analyze(Optional<BCDumpOptions> O = None,
- Optional<StringRef> CheckHash = None);
+ Error analyze(Optional<BCDumpOptions> O = std::nullopt,
+ Optional<StringRef> CheckHash = std::nullopt);
/// Print stats about the bitcode file.
- void printStats(BCDumpOptions O, Optional<StringRef> Filename = None);
+ void printStats(BCDumpOptions O, Optional<StringRef> Filename = std::nullopt);
private:
/// Read a block, updating statistics, etc.
Error parseBlock(unsigned BlockID, unsigned IndentLevel,
- Optional<BCDumpOptions> O = None,
- Optional<StringRef> CheckHash = None);
+ Optional<BCDumpOptions> O = std::nullopt,
+ Optional<StringRef> CheckHash = std::nullopt);
Error decodeMetadataStringsBlob(StringRef Indent, ArrayRef<uint64_t> Record,
StringRef Blob, raw_ostream &OS);
diff --git a/llvm/include/llvm/Bitcode/BitcodeReader.h b/llvm/include/llvm/Bitcode/BitcodeReader.h
index bc1f88f732290..2a49341c8df75 100644
--- a/llvm/include/llvm/Bitcode/BitcodeReader.h
+++ b/llvm/include/llvm/Bitcode/BitcodeReader.h
@@ -107,7 +107,7 @@ typedef llvm::function_ref<Optional<std::string>(StringRef)>
/// Read the entire bitcode module and return it.
Expected<std::unique_ptr<Module>> parseModule(
LLVMContext &Context, DataLayoutCallbackTy DataLayoutCallback =
- [](StringRef) { return None; });
+ [](StringRef) { return std::nullopt; });
/// Returns information about the module to be used for LTO: whether to
/// compile with ThinLTO, and whether it has a summary.
@@ -175,7 +175,7 @@ typedef llvm::function_ref<Optional<std::string>(StringRef)>
Expected<std::unique_ptr<Module>> parseBitcodeFile(
MemoryBufferRef Buffer, LLVMContext &Context,
DataLayoutCallbackTy DataLayoutCallback = [](StringRef) {
- return None;
+ return std::nullopt;
});
/// Returns LTO information for the specified bitcode file.
diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
index 97bc828066a50..bd80ee4efa585 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
@@ -28,7 +28,7 @@ static Optional<const char *> GetBlockName(unsigned BlockID,
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID)
return "BLOCKINFO_BLOCK";
- return None;
+ return std::nullopt;
}
// Check to see if we have a blockinfo record for this block, with a name.
@@ -39,11 +39,11 @@ static Optional<const char *> GetBlockName(unsigned BlockID,
}
if (CurStreamType != LLVMIRBitstream)
- return None;
+ return std::nullopt;
switch (BlockID) {
default:
- return None;
+ return std::nullopt;
case bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID:
return "OPERAND_BUNDLE_TAGS_BLOCK";
case bitc::MODULE_BLOCK_ID:
@@ -92,7 +92,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::BLOCKINFO_CODE_SETBID:
return "SETBID";
case bitc::BLOCKINFO_CODE_BLOCKNAME:
@@ -101,7 +101,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
return "SETRECORDNAME";
}
}
- return None;
+ return std::nullopt;
}
// Check to see if we have a blockinfo record for this record, with a name.
@@ -113,18 +113,18 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
}
if (CurStreamType != LLVMIRBitstream)
- return None;
+ return std::nullopt;
#define STRINGIFY_CODE(PREFIX, CODE) \
case bitc::PREFIX##_##CODE: \
return #CODE;
switch (BlockID) {
default:
- return None;
+ return std::nullopt;
case bitc::MODULE_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(MODULE_CODE, VERSION)
STRINGIFY_CODE(MODULE_CODE, TRIPLE)
STRINGIFY_CODE(MODULE_CODE, DATALAYOUT)
@@ -144,14 +144,14 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::IDENTIFICATION_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(IDENTIFICATION_CODE, STRING)
STRINGIFY_CODE(IDENTIFICATION_CODE, EPOCH)
}
case bitc::PARAMATTR_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
// FIXME: Should these be
diff erent?
case bitc::PARAMATTR_CODE_ENTRY_OLD:
return "ENTRY";
@@ -161,14 +161,14 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::PARAMATTR_GROUP_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::PARAMATTR_GRP_CODE_ENTRY:
return "ENTRY";
}
case bitc::TYPE_BLOCK_ID_NEW:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(TYPE_CODE, NUMENTRY)
STRINGIFY_CODE(TYPE_CODE, VOID)
STRINGIFY_CODE(TYPE_CODE, FLOAT)
@@ -196,7 +196,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::CONSTANTS_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(CST_CODE, SETTYPE)
STRINGIFY_CODE(CST_CODE, NULL)
STRINGIFY_CODE(CST_CODE, UNDEF)
@@ -227,7 +227,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::FUNCTION_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(FUNC_CODE, DECLAREBLOCKS)
STRINGIFY_CODE(FUNC_CODE, INST_BINOP)
STRINGIFY_CODE(FUNC_CODE, INST_CAST)
@@ -272,7 +272,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::VALUE_SYMTAB_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(VST_CODE, ENTRY)
STRINGIFY_CODE(VST_CODE, BBENTRY)
STRINGIFY_CODE(VST_CODE, FNENTRY)
@@ -281,7 +281,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::MODULE_STRTAB_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(MST_CODE, ENTRY)
STRINGIFY_CODE(MST_CODE, HASH)
}
@@ -289,7 +289,7 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(FS, PERMODULE)
STRINGIFY_CODE(FS, PERMODULE_PROFILE)
STRINGIFY_CODE(FS, PERMODULE_RELBF)
@@ -324,13 +324,13 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::METADATA_ATTACHMENT_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(METADATA, ATTACHMENT)
}
case bitc::METADATA_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(METADATA, STRING_OLD)
STRINGIFY_CODE(METADATA, VALUE)
STRINGIFY_CODE(METADATA, NODE)
@@ -374,13 +374,13 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::METADATA_KIND_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
STRINGIFY_CODE(METADATA, KIND)
}
case bitc::USELIST_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::USELIST_CODE_DEFAULT:
return "USELIST_CODE_DEFAULT";
case bitc::USELIST_CODE_BB:
@@ -390,21 +390,21 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
case bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::OPERAND_BUNDLE_TAG:
return "OPERAND_BUNDLE_TAG";
}
case bitc::STRTAB_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::STRTAB_BLOB:
return "BLOB";
}
case bitc::SYMTAB_BLOCK_ID:
switch (CodeID) {
default:
- return None;
+ return std::nullopt;
case bitc::SYMTAB_BLOB:
return "BLOB";
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 0b6c509d76866..1d5d10a22728b 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -554,7 +554,7 @@ class BitcodeConstant final : public Value,
Optional<unsigned> getInRangeIndex() const {
assert(Opcode == Instruction::GetElementPtr);
if (Extra == (unsigned)-1)
- return None;
+ return std::nullopt;
return Extra;
}
@@ -822,7 +822,9 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
Error parseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
Error parseModule(
uint64_t ResumeBit, bool ShouldLazyLoadMetadata = false,
- DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
+ DataLayoutCallbackTy DataLayoutCallback = [](StringRef) {
+ return std::nullopt;
+ });
Error parseComdatRecord(ArrayRef<uint64_t> Record);
Error parseGlobalVarRecord(ArrayRef<uint64_t> Record);
@@ -7915,7 +7917,7 @@ Expected<std::unique_ptr<Module>>
BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata,
bool IsImporting) {
return getModuleImpl(Context, false, ShouldLazyLoadMetadata, IsImporting,
- [](StringRef) { return None; });
+ [](StringRef) { return std::nullopt; });
}
// Parse the specified bitcode buffer and merge the index into CombinedIndex.
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 1ac1502e8aefb..fd493a5df3528 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -222,7 +222,7 @@ Metadata *BitcodeReaderMetadataList::getMetadataFwdRef(unsigned Idx) {
// Create and return a placeholder, which will later be RAUW'd.
++NumMDNodeTemporary;
- Metadata *MD = MDNode::getTemporary(Context, None).release();
+ Metadata *MD = MDNode::getTemporary(Context, std::nullopt).release();
MetadataPtrs[Idx].reset(MD);
return MD;
}
@@ -304,7 +304,7 @@ Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) {
auto &Ref = OldTypeRefs.Unknown[UUID];
if (!Ref)
- Ref = MDNode::getTemporary(Context, None);
+ Ref = MDNode::getTemporary(Context, std::nullopt);
return Ref.get();
}
@@ -321,7 +321,7 @@ Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) {
// resolveTypeRefArrays() will be resolve this forward reference.
OldTypeRefs.Arrays.emplace_back(
std::piecewise_construct, std::forward_as_tuple(Tuple),
- std::forward_as_tuple(MDTuple::getTemporary(Context, None)));
+ std::forward_as_tuple(MDTuple::getTemporary(Context, std::nullopt)));
return OldTypeRefs.Arrays.back().second.get();
}
@@ -1212,7 +1212,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
// If this isn't a LocalAsMetadata record, we're dropping it. This used
// to be legal, but there's no upgrade path.
auto dropRecord = [&] {
- MetadataList.assignValue(MDNode::get(Context, None), NextMetadataNo);
+ MetadataList.assignValue(MDNode::get(Context, std::nullopt),
+ NextMetadataNo);
NextMetadataNo++;
};
if (Record.size() != 2) {
@@ -1624,7 +1625,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
DIFile,
(Context, getMDString(Record[1]), getMDString(Record[2]), Checksum,
Record.size() > 5 ? Optional<MDString *>(getMDString(Record[5]))
- : None)),
+ : std::nullopt)),
NextMetadataNo);
NextMetadataNo++;
break;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index bed9d6db2c79a..ff64435e75881 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -528,7 +528,7 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
Optional<unsigned> getValueId(GlobalValue::GUID ValGUID) {
auto VMI = GUIDToValueIdMap.find(ValGUID);
if (VMI == GUIDToValueIdMap.end())
- return None;
+ return std::nullopt;
return VMI->second;
}
@@ -4431,7 +4431,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
auto GetValueId = [&](const ValueInfo &VI) -> Optional<unsigned> {
if (!VI)
- return None;
+ return std::nullopt;
return getValueId(VI.getGUID());
};
More information about the llvm-commits
mailing list