[libc-commits] [libc] 660c33e - [libc] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata via libc-commits libc-commits at lists.llvm.org
Sat Jan 14 21:10:21 PST 2023


Author: Kazu Hirata
Date: 2023-01-14T21:10:14-08:00
New Revision: 660c33e51de20b5a414b029a6dbae8a33aefabd4

URL: https://github.com/llvm/llvm-project/commit/660c33e51de20b5a414b029a6dbae8a33aefabd4
DIFF: https://github.com/llvm/llvm-project/commit/660c33e51de20b5a414b029a6dbae8a33aefabd4.diff

LOG: [libc] Use std::optional instead of llvm::Optional (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

Added: 
    

Modified: 
    libc/benchmarks/JSON.cpp
    libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
    libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/JSON.cpp b/libc/benchmarks/JSON.cpp
index fd5cf4573344..6443ff4ca8ba 100644
--- a/libc/benchmarks/JSON.cpp
+++ b/libc/benchmarks/JSON.cpp
@@ -105,7 +105,7 @@ static Error fromJson(const json::Value &V,
                              "Can't parse BenchmarkLog, not a String");
   const auto String = *V.getAsString();
   auto Parsed =
-      llvm::StringSwitch<Optional<libc_benchmarks::BenchmarkLog>>(String)
+      llvm::StringSwitch<std::optional<libc_benchmarks::BenchmarkLog>>(String)
           .Case("None", libc_benchmarks::BenchmarkLog::None)
           .Case("Last", libc_benchmarks::BenchmarkLog::Last)
           .Case("Full", libc_benchmarks::BenchmarkLog::Full)

diff  --git a/libc/benchmarks/automemcpy/lib/CodeGenMain.cpp b/libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
index 618e4f1186e3..3f4e6fc0423a 100644
--- a/libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
+++ b/libc/benchmarks/automemcpy/lib/CodeGenMain.cpp
@@ -1,5 +1,6 @@
 #include "automemcpy/CodeGen.h"
 #include "automemcpy/RandomFunctionGenerator.h"
+#include <optional>
 #include <unordered_set>
 
 namespace llvm {
@@ -9,7 +10,7 @@ std::vector<FunctionDescriptor> generateFunctionDescriptors() {
   std::unordered_set<FunctionDescriptor, FunctionDescriptor::Hasher> Seen;
   std::vector<FunctionDescriptor> FunctionDescriptors;
   RandomFunctionGenerator P;
-  while (Optional<FunctionDescriptor> MaybeFD = P.next()) {
+  while (std::optional<FunctionDescriptor> MaybeFD = P.next()) {
     FunctionDescriptor FD = *MaybeFD;
     if (Seen.count(FD)) // FIXME: Z3 sometimes returns twice the same object.
       continue;

diff  --git a/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp b/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
index c362874bb45f..f438e2a405bd 100644
--- a/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
+++ b/libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
@@ -157,7 +157,7 @@ RandomFunctionGenerator::RandomFunctionGenerator()
 
 // Creates SizeSpan from Begin/End values.
 // Returns std::nullopt if Begin==End.
-static Optional<SizeSpan> AsSizeSpan(size_t Begin, size_t End) {
+static std::optional<SizeSpan> AsSizeSpan(size_t Begin, size_t End) {
   if (Begin == End)
     return std::nullopt;
   SizeSpan SS;
@@ -169,7 +169,7 @@ static Optional<SizeSpan> AsSizeSpan(size_t Begin, size_t End) {
 // Generic method to create a `Region` struct with a Span or std::nullopt if
 // span is empty.
 template <typename Region>
-static Optional<Region> As(size_t Begin, size_t End) {
+static std::optional<Region> As(size_t Begin, size_t End) {
   if (auto Span = AsSizeSpan(Begin, End)) {
     Region Output;
     Output.Span = *Span;
@@ -179,7 +179,7 @@ static Optional<Region> As(size_t Begin, size_t End) {
 }
 
 // Returns a Loop struct or std::nullopt if span is empty.
-static Optional<Loop> AsLoop(size_t Begin, size_t End, size_t BlockSize) {
+static std::optional<Loop> AsLoop(size_t Begin, size_t End, size_t BlockSize) {
   if (auto Span = AsSizeSpan(Begin, End)) {
     Loop Output;
     Output.Span = *Span;
@@ -190,9 +190,10 @@ static Optional<Loop> AsLoop(size_t Begin, size_t End, size_t BlockSize) {
 }
 
 // Returns an AlignedLoop struct or std::nullopt if span is empty.
-static Optional<AlignedLoop> AsAlignedLoop(size_t Begin, size_t End,
-                                           size_t BlockSize, size_t Alignment,
-                                           AlignArg AlignTo) {
+static std::optional<AlignedLoop> AsAlignedLoop(size_t Begin, size_t End,
+                                                size_t BlockSize,
+                                                size_t Alignment,
+                                                AlignArg AlignTo) {
   if (auto Loop = AsLoop(Begin, End, BlockSize)) {
     AlignedLoop Output;
     Output.Loop = *Loop;
@@ -203,7 +204,7 @@ static Optional<AlignedLoop> AsAlignedLoop(size_t Begin, size_t End,
   return std::nullopt;
 }
 
-Optional<FunctionDescriptor> RandomFunctionGenerator::next() {
+std::optional<FunctionDescriptor> RandomFunctionGenerator::next() {
   if (Solver.check() != z3::sat)
     return {};
 


        


More information about the libc-commits mailing list