[Mlir-commits] [mlir] 3a77eb6 - [mlir/unittests] Use std::nullopt instead of None (NFC)

Kazu Hirata llvmlistbot at llvm.org
Sat Dec 3 19:08:08 PST 2022


Author: Kazu Hirata
Date: 2022-12-03T19:07:59-08:00
New Revision: 3a77eb669894f77ef30f61d3a4f9767596fd0fcd

URL: https://github.com/llvm/llvm-project/commit/3a77eb669894f77ef30f61d3a4f9767596fd0fcd
DIFF: https://github.com/llvm/llvm-project/commit/3a77eb669894f77ef30f61d3a4f9767596fd0fcd.diff

LOG: [mlir/unittests] 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: 
    mlir/unittests/IR/OperationSupportTest.cpp
    mlir/unittests/Pass/AnalysisManagerTest.cpp
    mlir/unittests/Pass/PassManagerTest.cpp
    mlir/unittests/TableGen/EnumsGenTest.cpp
    mlir/unittests/Transforms/DialectConversion.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp
index ff9ab385893b7..03cdb4b3776f8 100644
--- a/mlir/unittests/IR/OperationSupportTest.cpp
+++ b/mlir/unittests/IR/OperationSupportTest.cpp
@@ -18,13 +18,13 @@ using namespace mlir;
 using namespace mlir::detail;
 
 static Operation *createOp(MLIRContext *context,
-                           ArrayRef<Value> operands = llvm::None,
-                           ArrayRef<Type> resultTypes = llvm::None,
+                           ArrayRef<Value> operands = std::nullopt,
+                           ArrayRef<Type> resultTypes = std::nullopt,
                            unsigned int numRegions = 0) {
   context->allowUnregisteredDialects();
   return Operation::create(UnknownLoc::get(context),
                            OperationName("foo.bar", context), resultTypes,
-                           operands, llvm::None, llvm::None, numRegions);
+                           operands, std::nullopt, std::nullopt, numRegions);
 }
 
 namespace {
@@ -33,7 +33,7 @@ TEST(OperandStorageTest, NonResizable) {
   Builder builder(&context);
 
   Operation *useOp =
-      createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
+      createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
   Value operand = useOp->getResult(0);
 
   // Create a non-resizable operation with one operand.
@@ -44,7 +44,7 @@ TEST(OperandStorageTest, NonResizable) {
   EXPECT_EQ(user->getNumOperands(), 1u);
 
   // Removing is okay.
-  user->setOperands(llvm::None);
+  user->setOperands(std::nullopt);
   EXPECT_EQ(user->getNumOperands(), 0u);
 
   // Destroy the operations.
@@ -57,7 +57,7 @@ TEST(OperandStorageTest, Resizable) {
   Builder builder(&context);
 
   Operation *useOp =
-      createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
+      createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
   Value operand = useOp->getResult(0);
 
   // Create a resizable operation with one operand.
@@ -68,7 +68,7 @@ TEST(OperandStorageTest, Resizable) {
   EXPECT_EQ(user->getNumOperands(), 1u);
 
   // Removing is okay.
-  user->setOperands(llvm::None);
+  user->setOperands(std::nullopt);
   EXPECT_EQ(user->getNumOperands(), 0u);
 
   // Adding more operands is okay.
@@ -85,7 +85,7 @@ TEST(OperandStorageTest, RangeReplace) {
   Builder builder(&context);
 
   Operation *useOp =
-      createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
+      createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
   Value operand = useOp->getResult(0);
 
   // Create a resizable operation with one operand.
@@ -121,7 +121,7 @@ TEST(OperandStorageTest, MutableRange) {
   Builder builder(&context);
 
   Operation *useOp =
-      createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
+      createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
   Value operand = useOp->getResult(0);
 
   // Create a resizable operation with one operand.
@@ -158,7 +158,8 @@ TEST(OperandStorageTest, RangeErase) {
   Builder builder(&context);
 
   Type type = builder.getNoneType();
-  Operation *useOp = createOp(&context, /*operands=*/llvm::None, {type, type});
+  Operation *useOp =
+      createOp(&context, /*operands=*/std::nullopt, {type, type});
   Value operand1 = useOp->getResult(0);
   Value operand2 = useOp->getResult(1);
 
@@ -188,9 +189,9 @@ TEST(OperationOrderTest, OrderIsAlwaysValid) {
   MLIRContext context;
   Builder builder(&context);
 
-  Operation *containerOp =
-      createOp(&context, /*operands=*/llvm::None, /*resultTypes=*/llvm::None,
-               /*numRegions=*/1);
+  Operation *containerOp = createOp(&context, /*operands=*/std::nullopt,
+                                    /*resultTypes=*/std::nullopt,
+                                    /*numRegions=*/1);
   Region &region = containerOp->getRegion(0);
   Block *block = new Block();
   region.push_back(block);

diff  --git a/mlir/unittests/Pass/AnalysisManagerTest.cpp b/mlir/unittests/Pass/AnalysisManagerTest.cpp
index 5fa17f3ccd1a9..d494db86a9de9 100644
--- a/mlir/unittests/Pass/AnalysisManagerTest.cpp
+++ b/mlir/unittests/Pass/AnalysisManagerTest.cpp
@@ -65,7 +65,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
   OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
   func::FuncOp func1 =
       func::FuncOp::create(builder.getUnknownLoc(), "foo",
-                           builder.getFunctionType(llvm::None, llvm::None));
+                           builder.getFunctionType(std::nullopt, std::nullopt));
   func1.setPrivate();
   module->push_back(func1);
 
@@ -96,7 +96,7 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
   OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
   func::FuncOp func1 =
       func::FuncOp::create(builder.getUnknownLoc(), "foo",
-                           builder.getFunctionType(llvm::None, llvm::None));
+                           builder.getFunctionType(std::nullopt, std::nullopt));
   func1.setPrivate();
   module->push_back(func1);
 

diff  --git a/mlir/unittests/Pass/PassManagerTest.cpp b/mlir/unittests/Pass/PassManagerTest.cpp
index 079be46dd1de8..9ed49c8100c7e 100644
--- a/mlir/unittests/Pass/PassManagerTest.cpp
+++ b/mlir/unittests/Pass/PassManagerTest.cpp
@@ -60,9 +60,9 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
   // Create a module with 2 functions.
   OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
   for (StringRef name : {"secret", "not_secret"}) {
-    auto func =
-        func::FuncOp::create(builder.getUnknownLoc(), name,
-                             builder.getFunctionType(llvm::None, llvm::None));
+    auto func = func::FuncOp::create(
+        builder.getUnknownLoc(), name,
+        builder.getFunctionType(std::nullopt, std::nullopt));
     func.setPrivate();
     module->push_back(func);
   }

diff  --git a/mlir/unittests/TableGen/EnumsGenTest.cpp b/mlir/unittests/TableGen/EnumsGenTest.cpp
index 1a16b0683d922..bf6b6d3a9c0fe 100644
--- a/mlir/unittests/TableGen/EnumsGenTest.cpp
+++ b/mlir/unittests/TableGen/EnumsGenTest.cpp
@@ -56,7 +56,7 @@ TEST(EnumsGenTest, GeneratedSymbolToStringFn) {
 TEST(EnumsGenTest, GeneratedStringToSymbolFn) {
   EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseA), ConvertToEnum("CaseA"));
   EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseB), ConvertToEnum("CaseB"));
-  EXPECT_EQ(llvm::None, ConvertToEnum("X"));
+  EXPECT_EQ(std::nullopt, ConvertToEnum("X"));
 }
 
 TEST(EnumsGenTest, GeneratedUnderlyingType) {
@@ -94,10 +94,10 @@ TEST(EnumsGenTest, GeneratedStringToSymbolForBitEnum) {
   EXPECT_EQ(symbolizeBitEnumWithNone("Bit3|Bit0"),
             BitEnumWithNone::Bit3 | BitEnumWithNone::Bit0);
 
-  EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), llvm::None);
-  EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), llvm::None);
+  EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), std::nullopt);
+  EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), std::nullopt);
 
-  EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), llvm::None);
+  EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), std::nullopt);
 }
 
 TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) {
@@ -115,7 +115,7 @@ TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) {
 TEST(EnumsGenTest, GeneratedStringToSymbolForGroupedBitEnum) {
   EXPECT_EQ(symbolizeBitEnumWithGroup("Bit0"), BitEnumWithGroup::Bit0);
   EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3"), BitEnumWithGroup::Bit3);
-  EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), llvm::None);
+  EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), std::nullopt);
   EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3|Bit0"),
             BitEnumWithGroup::Bit3 | BitEnumWithGroup::Bit0);
 }

diff  --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp
index 79a02702b48a6..0cac2975ea91c 100644
--- a/mlir/unittests/Transforms/DialectConversion.cpp
+++ b/mlir/unittests/Transforms/DialectConversion.cpp
@@ -14,8 +14,8 @@ using namespace mlir;
 static Operation *createOp(MLIRContext *context) {
   context->allowUnregisteredDialects();
   return Operation::create(UnknownLoc::get(context),
-                           OperationName("foo.bar", context), llvm::None,
-                           llvm::None, llvm::None, llvm::None, 0);
+                           OperationName("foo.bar", context), std::nullopt,
+                           std::nullopt, std::nullopt, std::nullopt, 0);
 }
 
 namespace {
@@ -39,7 +39,7 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackOrder) {
   int callbackCalled2 = 0;
   target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
     callbackCalled2 = ++index;
-    return llvm::None;
+    return std::nullopt;
   });
 
   auto *op = createOp(&context);
@@ -60,7 +60,7 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackSkip) {
   int callbackCalled = 0;
   target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
     callbackCalled = ++index;
-    return llvm::None;
+    return std::nullopt;
   });
 
   auto *op = createOp(&context);
@@ -85,7 +85,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownOpCallbackOrder) {
   int callbackCalled2 = 0;
   target.markUnknownOpDynamicallyLegal([&](Operation *) -> Optional<bool> {
     callbackCalled2 = ++index;
-    return llvm::None;
+    return std::nullopt;
   });
 
   auto *op = createOp(&context);
@@ -103,7 +103,7 @@ TEST(DialectConversionTest, DynamicallyLegalReturnNone) {
   ConversionTarget target(context);
 
   target.addDynamicallyLegalOp<DummyOp>(
-      [&](Operation *) -> Optional<bool> { return llvm::None; });
+      [&](Operation *) -> Optional<bool> { return std::nullopt; });
 
   auto *op = createOp(&context);
   EXPECT_FALSE(target.isLegal(op));
@@ -120,7 +120,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownReturnNone) {
   ConversionTarget target(context);
 
   target.markUnknownOpDynamicallyLegal(
-      [&](Operation *) -> Optional<bool> { return llvm::None; });
+      [&](Operation *) -> Optional<bool> { return std::nullopt; });
 
   auto *op = createOp(&context);
   EXPECT_FALSE(target.isLegal(op));


        


More information about the Mlir-commits mailing list