From 3a77eb669894f77ef30f61d3a4f9767596fd0fcd Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 3 Dec 2022 19:07:59 -0800 Subject: [PATCH] [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 --- mlir/unittests/IR/OperationSupportTest.cpp | 27 ++++++++++--------- mlir/unittests/Pass/AnalysisManagerTest.cpp | 4 +-- mlir/unittests/Pass/PassManagerTest.cpp | 6 ++--- mlir/unittests/TableGen/EnumsGenTest.cpp | 10 +++---- .../Transforms/DialectConversion.cpp | 14 +++++----- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp index ff9ab385893b..03cdb4b3776f 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 operands = llvm::None, - ArrayRef resultTypes = llvm::None, + ArrayRef operands = std::nullopt, + ArrayRef 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 ®ion = 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 5fa17f3ccd1a..d494db86a9de 100644 --- a/mlir/unittests/Pass/AnalysisManagerTest.cpp +++ b/mlir/unittests/Pass/AnalysisManagerTest.cpp @@ -65,7 +65,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) { OwningOpRef 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 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 079be46dd1de..9ed49c8100c7 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 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 1a16b0683d92..bf6b6d3a9c0f 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::CaseA), ConvertToEnum("CaseA")); EXPECT_EQ(llvm::Optional(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 79a02702b48a..0cac2975ea91 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([&](Operation *) -> Optional { callbackCalled2 = ++index; - return llvm::None; + return std::nullopt; }); auto *op = createOp(&context); @@ -60,7 +60,7 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackSkip) { int callbackCalled = 0; target.addDynamicallyLegalOp([&](Operation *) -> Optional { 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 { callbackCalled2 = ++index; - return llvm::None; + return std::nullopt; }); auto *op = createOp(&context); @@ -103,7 +103,7 @@ TEST(DialectConversionTest, DynamicallyLegalReturnNone) { ConversionTarget target(context); target.addDynamicallyLegalOp( - [&](Operation *) -> Optional { return llvm::None; }); + [&](Operation *) -> Optional { 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 { return llvm::None; }); + [&](Operation *) -> Optional { return std::nullopt; }); auto *op = createOp(&context); EXPECT_FALSE(target.isLegal(op));