From 70fe44ca777f179e3de9aa42afc14cd5f86abd34 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 9 Dec 2022 19:14:05 -0800 Subject: [PATCH] [libc] Use std::nullopt instead of None (NFC) 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 --- .../include/automemcpy/RandomFunctionGenerator.h | 2 +- libc/benchmarks/automemcpy/lib/CodeGen.cpp | 6 ++-- .../automemcpy/lib/RandomFunctionGenerator.cpp | 2 +- .../automemcpy/unittests/CodeGenTest.cpp | 33 +++++++++++----------- .../utils/tools/WrapperGen/wrappergen_test.cpp | 33 +++++++++++----------- libc/utils/LibcTableGenUtil/APIIndexer.h | 3 +- 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/libc/benchmarks/automemcpy/include/automemcpy/RandomFunctionGenerator.h b/libc/benchmarks/automemcpy/include/automemcpy/RandomFunctionGenerator.h index 48e8815..4fa1c38 100644 --- a/libc/benchmarks/automemcpy/include/automemcpy/RandomFunctionGenerator.h +++ b/libc/benchmarks/automemcpy/include/automemcpy/RandomFunctionGenerator.h @@ -26,7 +26,7 @@ namespace automemcpy { struct RandomFunctionGenerator { RandomFunctionGenerator(); - // Get the next valid FunctionDescriptor or llvm::None. + // Get the next valid FunctionDescriptor or std::nullopt. Optional next(); private: diff --git a/libc/benchmarks/automemcpy/lib/CodeGen.cpp b/libc/benchmarks/automemcpy/lib/CodeGen.cpp index cf196b1..7f7d2b5 100644 --- a/libc/benchmarks/automemcpy/lib/CodeGen.cpp +++ b/libc/benchmarks/automemcpy/lib/CodeGen.cpp @@ -310,8 +310,8 @@ namespace descriptors { // e.g. // ArrayRef getFunctionDescriptors() { // static constexpr NamedFunctionDescriptor kDescriptors[] = { -// {"memcpy_0xE00E29EE73994E2B",{FunctionType::MEMCPY,llvm::None,llvm::None,llvm::None,llvm::None,Accelerator{{0,kMaxSize}},ElementTypeClass::NATIVE}}, -// {"memcpy_0x8661D80472487AB5",{FunctionType::MEMCPY,Contiguous{{0,1}},llvm::None,llvm::None,llvm::None,Accelerator{{1,kMaxSize}},ElementTypeClass::NATIVE}}, +// {"memcpy_0xE00E29EE73994E2B",{FunctionType::MEMCPY,std::nullopt,std::nullopt,std::nullopt,std::nullopt,Accelerator{{0,kMaxSize}},ElementTypeClass::NATIVE}}, +// {"memcpy_0x8661D80472487AB5",{FunctionType::MEMCPY,Contiguous{{0,1}},std::nullopt,std::nullopt,std::nullopt,Accelerator{{1,kMaxSize}},ElementTypeClass::NATIVE}}, // ... // }; // return makeArrayRef(kDescriptors); @@ -380,7 +380,7 @@ static raw_ostream &operator<<(raw_ostream &Stream, const llvm::Optional &MaybeT) { if (MaybeT) return Stream << *MaybeT; - return Stream << "llvm::None"; + return Stream << "std::nullopt"; } static raw_ostream &operator<<(raw_ostream &Stream, const FunctionDescriptor &FD) { diff --git a/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp b/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp index 763fbc6..c8ceecc 100644 --- a/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp +++ b/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp @@ -156,7 +156,7 @@ RandomFunctionGenerator::RandomFunctionGenerator() } // Creates SizeSpan from Begin/End values. -// Returns llvm::None if Begin==End. +// Returns std::nullopt if Begin==End. static Optional AsSizeSpan(size_t Begin, size_t End) { if (Begin == End) return None; diff --git a/libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp b/libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp index ef16a61..1d8df11 100644 --- a/libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp +++ b/libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp @@ -10,6 +10,7 @@ #include "automemcpy/RandomFunctionGenerator.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include using testing::AllOf; using testing::AnyOf; @@ -25,22 +26,22 @@ namespace { TEST(Automemcpy, Codegen) { static constexpr FunctionDescriptor kDescriptors[] = { - {FunctionType::MEMCPY, llvm::None, llvm::None, llvm::None, llvm::None, + {FunctionType::MEMCPY, std::nullopt, std::nullopt, std::nullopt, std::nullopt, Accelerator{{0, kMaxSize}}, ElementTypeClass::NATIVE}, {FunctionType::MEMCPY, Contiguous{{0, 4}}, Overlap{{4, 256}}, - Loop{{256, kMaxSize}, 64}, llvm::None, llvm::None, + Loop{{256, kMaxSize}, 64}, std::nullopt, std::nullopt, ElementTypeClass::NATIVE}, - {FunctionType::MEMCMP, Contiguous{{0, 2}}, Overlap{{2, 64}}, llvm::None, - AlignedLoop{Loop{{64, kMaxSize}, 16}, 16, AlignArg::_1}, llvm::None, + {FunctionType::MEMCMP, Contiguous{{0, 2}}, Overlap{{2, 64}}, std::nullopt, + AlignedLoop{Loop{{64, kMaxSize}, 16}, 16, AlignArg::_1}, std::nullopt, ElementTypeClass::NATIVE}, - {FunctionType::MEMSET, Contiguous{{0, 2}}, Overlap{{2, 256}}, llvm::None, - AlignedLoop{Loop{{256, kMaxSize}, 32}, 16, AlignArg::_1}, llvm::None, + {FunctionType::MEMSET, Contiguous{{0, 2}}, Overlap{{2, 256}}, std::nullopt, + AlignedLoop{Loop{{256, kMaxSize}, 32}, 16, AlignArg::_1}, std::nullopt, ElementTypeClass::NATIVE}, - {FunctionType::MEMSET, Contiguous{{0, 2}}, Overlap{{2, 256}}, llvm::None, - AlignedLoop{Loop{{256, kMaxSize}, 32}, 32, AlignArg::_1}, llvm::None, + {FunctionType::MEMSET, Contiguous{{0, 2}}, Overlap{{2, 256}}, std::nullopt, + AlignedLoop{Loop{{256, kMaxSize}, 32}, 32, AlignArg::_1}, std::nullopt, ElementTypeClass::NATIVE}, - {FunctionType::BZERO, Contiguous{{0, 4}}, Overlap{{4, 128}}, llvm::None, - AlignedLoop{Loop{{128, kMaxSize}, 32}, 32, AlignArg::_1}, llvm::None, + {FunctionType::BZERO, Contiguous{{0, 4}}, Overlap{{4, 128}}, std::nullopt, + AlignedLoop{Loop{{128, kMaxSize}, 32}, 32, AlignArg::_1}, std::nullopt, ElementTypeClass::NATIVE}, }; @@ -140,12 +141,12 @@ namespace automemcpy { ArrayRef getFunctionDescriptors() { static constexpr NamedFunctionDescriptor kDescriptors[] = { - {"memcpy_0xE00E29EE73994E2B",{FunctionType::MEMCPY,llvm::None,llvm::None,llvm::None,llvm::None,Accelerator{{0,kMaxSize}},ElementTypeClass::NATIVE}}, - {"memcpy_0x7381B60C7BE75EF9",{FunctionType::MEMCPY,Contiguous{{0,4}},Overlap{{4,256}},Loop{{256,kMaxSize},64},llvm::None,llvm::None,ElementTypeClass::NATIVE}}, - {"memcmp_0x348D7BA6DB0EE033",{FunctionType::MEMCMP,Contiguous{{0,2}},Overlap{{2,64}},llvm::None,AlignedLoop{Loop{{64,kMaxSize},16},16,AlignArg::_1},llvm::None,ElementTypeClass::NATIVE}}, - {"memset_0x71E761699B999863",{FunctionType::MEMSET,Contiguous{{0,2}},Overlap{{2,256}},llvm::None,AlignedLoop{Loop{{256,kMaxSize},32},16,AlignArg::_1},llvm::None,ElementTypeClass::NATIVE}}, - {"memset_0x3DF0F44E2ED6A50F",{FunctionType::MEMSET,Contiguous{{0,2}},Overlap{{2,256}},llvm::None,AlignedLoop{Loop{{256,kMaxSize},32},32,AlignArg::_1},llvm::None,ElementTypeClass::NATIVE}}, - {"bzero_0x475977492C218AD4",{FunctionType::BZERO,Contiguous{{0,4}},Overlap{{4,128}},llvm::None,AlignedLoop{Loop{{128,kMaxSize},32},32,AlignArg::_1},llvm::None,ElementTypeClass::NATIVE}}, + {"memcpy_0xE00E29EE73994E2B",{FunctionType::MEMCPY,std::nullopt,std::nullopt,std::nullopt,std::nullopt,Accelerator{{0,kMaxSize}},ElementTypeClass::NATIVE}}, + {"memcpy_0x7381B60C7BE75EF9",{FunctionType::MEMCPY,Contiguous{{0,4}},Overlap{{4,256}},Loop{{256,kMaxSize},64},std::nullopt,std::nullopt,ElementTypeClass::NATIVE}}, + {"memcmp_0x348D7BA6DB0EE033",{FunctionType::MEMCMP,Contiguous{{0,2}},Overlap{{2,64}},std::nullopt,AlignedLoop{Loop{{64,kMaxSize},16},16,AlignArg::_1},std::nullopt,ElementTypeClass::NATIVE}}, + {"memset_0x71E761699B999863",{FunctionType::MEMSET,Contiguous{{0,2}},Overlap{{2,256}},std::nullopt,AlignedLoop{Loop{{256,kMaxSize},32},16,AlignArg::_1},std::nullopt,ElementTypeClass::NATIVE}}, + {"memset_0x3DF0F44E2ED6A50F",{FunctionType::MEMSET,Contiguous{{0,2}},Overlap{{2,256}},std::nullopt,AlignedLoop{Loop{{256,kMaxSize},32},32,AlignArg::_1},std::nullopt,ElementTypeClass::NATIVE}}, + {"bzero_0x475977492C218AD4",{FunctionType::BZERO,Contiguous{{0,4}},Overlap{{4,128}},std::nullopt,AlignedLoop{Loop{{128,kMaxSize},32},32,AlignArg::_1},std::nullopt,ElementTypeClass::NATIVE}}, }; return makeArrayRef(kDescriptors); } diff --git a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp index b0b2440..1408fc6 100644 --- a/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp +++ b/libc/test/utils/tools/WrapperGen/wrappergen_test.cpp @@ -19,6 +19,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include +#include llvm::cl::opt LibcPath("path", llvm::cl::desc("Path to the top level libc directory."), @@ -71,7 +72,7 @@ using LlvmLibcWrapperGenTest = WrapperGenTest; TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenAndGetNoErrors) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef ArgV[] = {ProgPath, @@ -82,7 +83,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenAndGetNoErrors) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 0); @@ -93,7 +94,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenAndGetNoErrors) { TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlen) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef ArgV[] = {ProgPath, @@ -104,7 +105,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlen) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 0); @@ -128,7 +129,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlen) { TEST_F(LlvmLibcWrapperGenTest, GenAliasForStrlen) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef ArgV[] = {ProgPath, @@ -141,7 +142,7 @@ TEST_F(LlvmLibcWrapperGenTest, GenAliasForStrlen) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 0); @@ -164,7 +165,7 @@ TEST_F(LlvmLibcWrapperGenTest, GenAliasForStrlen) { TEST_F(LlvmLibcWrapperGenTest, DeclStrlenAliasUsingMangledNameFile) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; const char *MangledNameFileContent = @@ -189,7 +190,7 @@ TEST_F(LlvmLibcWrapperGenTest, DeclStrlenAliasUsingMangledNameFile) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 0); @@ -217,7 +218,7 @@ TEST_F(LlvmLibcWrapperGenTest, DeclStrlenAliasUsingMangledNameFile) { TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlenWithMangledNameAndMangledNameFile) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef ArgV[] = {ProgPath, @@ -232,7 +233,7 @@ TEST_F(LlvmLibcWrapperGenTest, "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 1); @@ -251,7 +252,7 @@ TEST_F(LlvmLibcWrapperGenTest, TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnBadFuncName) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef BadFuncName = "FAKE_TEST_FUNC"; @@ -264,7 +265,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnBadFuncName) { BadFuncName}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 1); @@ -283,7 +284,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnBadFuncName) { TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlenWithBadMangledNameFile) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::StringRef BadMangledNameFileName = "FILE_THAT_DOESNT_EXIST.txt"; @@ -298,7 +299,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlenWithBadMangledNameFile) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_EQ(ExitCode, 1); @@ -317,7 +318,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWrapperGenOnStrlenWithBadMangledNameFile) { TEST_F(LlvmLibcWrapperGenTest, RunWithMangledNameFileMissingLLVMLibcName) { std::optional Redirects[] = { - llvm::None, llvm::StringRef(STDOutFile.get().TmpName), + std::nullopt, llvm::StringRef(STDOutFile.get().TmpName), llvm::StringRef(STDErrFile.get().TmpName)}; llvm::SmallVector MangledNameFilePath; @@ -336,7 +337,7 @@ TEST_F(LlvmLibcWrapperGenTest, RunWithMangledNameFileMissingLLVMLibcName) { "strlen"}; int ExitCode = - llvm::sys::ExecuteAndWait(ProgPath, ArgV, llvm::None, Redirects); + llvm::sys::ExecuteAndWait(ProgPath, ArgV, std::nullopt, Redirects); EXPECT_NE(ExitCode, 0); diff --git a/libc/utils/LibcTableGenUtil/APIIndexer.h b/libc/utils/LibcTableGenUtil/APIIndexer.h index 26c8130..12dab0f 100644 --- a/libc/utils/LibcTableGenUtil/APIIndexer.h +++ b/libc/utils/LibcTableGenUtil/APIIndexer.h @@ -12,6 +12,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/TableGen/Record.h" +#include #include #include #include @@ -48,7 +49,7 @@ public: using NameSet = std::unordered_set; // This indexes all headers, not just a specified one. - explicit APIIndexer(llvm::RecordKeeper &Records) : StdHeader(llvm::None) { + explicit APIIndexer(llvm::RecordKeeper &Records) : StdHeader(std::nullopt) { index(Records); } -- 2.7.4