From 0a81ace0047a2de93e71c82cdf0977fc989660df Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 14 Jan 2023 01:25:58 -0800 Subject: [PATCH] [mlir] Use std::optional instead of llvm::Optional (NFC) This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". 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/examples/toy/Ch1/include/toy/AST.h | 6 +- mlir/examples/toy/Ch1/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch2/include/toy/AST.h | 6 +- mlir/examples/toy/Ch2/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch3/include/toy/AST.h | 6 +- mlir/examples/toy/Ch3/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch4/include/toy/AST.h | 6 +- mlir/examples/toy/Ch4/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch5/include/toy/AST.h | 6 +- mlir/examples/toy/Ch5/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch6/include/toy/AST.h | 6 +- mlir/examples/toy/Ch6/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch7/include/toy/AST.h | 6 +- mlir/examples/toy/Ch7/include/toy/Parser.h | 2 +- mlir/examples/toy/Ch7/mlir/MLIRGen.cpp | 4 +- .../DataFlow/ConstantPropagationAnalysis.h | 2 +- .../mlir/Analysis/DataFlow/DeadCodeAnalysis.h | 2 +- .../mlir/Analysis/Presburger/IntegerRelation.h | 23 +++--- .../mlir/Analysis/Presburger/PWMAFunction.h | 4 +- .../mlir/Analysis/Presburger/PresburgerRelation.h | 2 +- mlir/include/mlir/Analysis/Presburger/Simplex.h | 22 ++--- mlir/include/mlir/Analysis/Presburger/Utils.h | 4 +- .../mlir/Conversion/MathToLibm/MathToLibm.h | 2 +- .../mlir/Dialect/Affine/Analysis/AffineAnalysis.h | 4 +- .../Dialect/Affine/Analysis/AffineStructures.h | 14 ++-- .../mlir/Dialect/Affine/Analysis/LoopAnalysis.h | 2 +- mlir/include/mlir/Dialect/Affine/Analysis/Utils.h | 18 ++-- mlir/include/mlir/Dialect/Affine/LoopUtils.h | 4 +- mlir/include/mlir/Dialect/Affine/Utils.h | 8 +- mlir/include/mlir/Dialect/Async/IR/AsyncOps.td | 2 +- .../Bufferization/IR/BufferizableOpInterface.h | 8 +- mlir/include/mlir/Dialect/CommonFolders.h | 22 ++--- .../Func/Transforms/DecomposeCallGraphTypes.h | 20 +++-- mlir/include/mlir/Dialect/GPU/IR/GPUOps.td | 4 +- mlir/include/mlir/Dialect/GPU/Transforms/Passes.h | 4 +- mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td | 6 +- mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h | 12 +-- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 4 +- mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h | 3 +- .../Dialect/Linalg/Analysis/DependenceAnalysis.h | 18 ++-- mlir/include/mlir/Dialect/Linalg/IR/Linalg.h | 2 +- mlir/include/mlir/Dialect/Linalg/Utils/Utils.h | 10 +-- mlir/include/mlir/Dialect/MemRef/IR/MemRef.h | 2 +- mlir/include/mlir/Dialect/PDL/IR/PDLOps.td | 6 +- mlir/include/mlir/Dialect/SCF/Utils/Utils.h | 2 +- .../mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td | 2 +- mlir/include/mlir/Dialect/SPIRV/IR/TargetAndABI.h | 4 +- .../mlir/Dialect/SparseTensor/Utils/Merger.h | 16 ++-- mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td | 2 +- .../mlir/Dialect/Tosa/Utils/ConversionUtils.h | 6 +- .../mlir/Dialect/Transform/IR/TransformDialect.h | 2 +- .../Transform/Utils/DiagnosedSilenceableFailure.h | 4 +- mlir/include/mlir/Dialect/Utils/IndexingUtils.h | 4 +- mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h | 12 +-- .../Vector/Transforms/VectorRewritePatterns.h | 6 +- .../include/mlir/ExecutionEngine/ExecutionEngine.h | 2 +- mlir/include/mlir/ExecutionEngine/MemRefUtils.h | 4 +- mlir/include/mlir/IR/AffineMap.h | 2 +- mlir/include/mlir/IR/Builders.h | 2 +- mlir/include/mlir/IR/BuiltinAttributeInterfaces.h | 4 +- mlir/include/mlir/IR/BuiltinAttributeInterfaces.td | 10 +-- mlir/include/mlir/IR/BuiltinAttributes.h | 2 +- mlir/include/mlir/IR/BuiltinAttributes.td | 6 +- mlir/include/mlir/IR/Diagnostics.h | 8 +- mlir/include/mlir/IR/DialectResourceBlobManager.h | 10 +-- mlir/include/mlir/IR/OpDefinition.h | 10 ++- mlir/include/mlir/IR/OpImplementation.h | 17 ++-- mlir/include/mlir/IR/Operation.h | 2 +- mlir/include/mlir/IR/OperationSupport.h | 24 +++--- mlir/include/mlir/IR/PatternMatch.h | 6 +- mlir/include/mlir/IR/SubElementInterfaces.h | 10 +-- mlir/include/mlir/IR/ValueRange.h | 2 +- .../mlir/Interfaces/InferIntRangeInterface.h | 2 +- mlir/include/mlir/Pass/AnalysisManager.h | 8 +- mlir/include/mlir/Pass/Pass.h | 16 ++-- mlir/include/mlir/Pass/PassInstrumentation.h | 8 +- mlir/include/mlir/Pass/PassManager.h | 6 +- mlir/include/mlir/Pass/PassRegistry.h | 8 +- mlir/include/mlir/Support/LogicalResult.h | 13 +-- mlir/include/mlir/Support/Timing.h | 4 +- mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h | 4 +- mlir/include/mlir/Tools/PDLL/AST/Nodes.h | 59 ++++++------- mlir/include/mlir/Tools/PDLL/AST/Types.h | 4 +- mlir/include/mlir/Tools/PDLL/Parser/CodeComplete.h | 4 +- .../mlir/Tools/mlir-translate/Translation.h | 14 ++-- mlir/include/mlir/Transforms/InliningUtils.h | 8 +- mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp | 10 +-- .../lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp | 2 +- mlir/lib/Analysis/Presburger/IntegerRelation.cpp | 27 +++--- mlir/lib/Analysis/Presburger/PWMAFunction.cpp | 6 +- .../lib/Analysis/Presburger/PresburgerRelation.cpp | 7 +- mlir/lib/Analysis/Presburger/Simplex.cpp | 56 +++++++------ mlir/lib/Analysis/Presburger/Utils.cpp | 4 +- mlir/lib/AsmParser/AsmParserImpl.h | 2 +- mlir/lib/AsmParser/AttributeParser.cpp | 28 +++---- mlir/lib/AsmParser/Parser.cpp | 44 +++++----- mlir/lib/AsmParser/Parser.h | 2 +- mlir/lib/AsmParser/Token.cpp | 14 ++-- mlir/lib/AsmParser/Token.h | 16 ++-- mlir/lib/AsmParser/TypeParser.cpp | 4 +- mlir/lib/Bindings/Python/DialectSparseTensor.cpp | 8 +- mlir/lib/Bindings/Python/Globals.h | 4 +- mlir/lib/Bindings/Python/IRAttributes.cpp | 7 +- mlir/lib/Bindings/Python/IRCore.cpp | 38 +++++---- mlir/lib/Bindings/Python/IRInterfaces.cpp | 6 +- mlir/lib/Bindings/Python/IRModule.cpp | 4 +- mlir/lib/Bindings/Python/IRModule.h | 26 +++--- mlir/lib/Bindings/Python/IRTypes.cpp | 6 +- mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 11 +-- mlir/lib/CAPI/IR/IR.cpp | 2 +- mlir/lib/CAPI/IR/Pass.cpp | 7 +- mlir/lib/CAPI/Interfaces/Interfaces.cpp | 6 +- .../lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp | 5 +- mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp | 8 +- mlir/lib/Conversion/MathToLibm/MathToLibm.cpp | 2 +- .../lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp | 4 +- mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp | 5 +- mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp | 8 +- mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp | 6 +- .../lib/Dialect/Affine/Analysis/AffineAnalysis.cpp | 6 +- .../Dialect/Affine/Analysis/AffineStructures.cpp | 26 +++--- mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp | 4 +- mlir/lib/Dialect/Affine/Analysis/Utils.cpp | 54 ++++++------ .../Affine/Transforms/AffineDataCopyGeneration.cpp | 2 +- mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp | 16 ++-- mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp | 4 +- mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp | 6 +- .../Dialect/Affine/Transforms/LoopUnrollAndJam.cpp | 5 +- .../Dialect/Affine/Transforms/SuperVectorize.cpp | 4 +- mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp | 4 +- mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp | 21 ++--- mlir/lib/Dialect/Affine/Utils/Utils.cpp | 9 +- .../Arith/IR/InferIntRangeInterfaceImpls.cpp | 96 +++++++++++++--------- .../Async/Transforms/AsyncToAsyncRuntime.cpp | 4 +- .../Dialect/Bufferization/IR/BufferizationOps.cpp | 4 +- .../Bufferization/Transforms/BufferUtils.cpp | 2 +- .../Dialect/Bufferization/Transforms/Bufferize.cpp | 2 +- .../Transforms/FuncBufferizableOpInterfaceImpl.cpp | 11 +-- .../Bufferization/Transforms/OneShotAnalysis.cpp | 2 +- .../Dialect/GPU/IR/InferIntRangeInterfaceImpls.cpp | 7 +- .../GPU/Transforms/LowerMemorySpaceAttributes.cpp | 2 +- .../lib/Dialect/GPU/Transforms/SerializeToBlob.cpp | 4 +- .../Dialect/GPU/Transforms/SerializeToHsaco.cpp | 6 +- mlir/lib/Dialect/Index/IR/IndexOps.cpp | 28 ++++--- mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp | 22 ++--- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 16 ++-- mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp | 16 ++-- mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 2 +- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 4 +- .../lib/Dialect/Linalg/Transforms/ConstantFold.cpp | 4 +- .../Linalg/Transforms/DataLayoutPropagation.cpp | 4 +- .../Linalg/Transforms/DecomposeLinalgOps.cpp | 2 +- .../Linalg/Transforms/ElementwiseOpFusion.cpp | 19 +++-- mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp | 8 +- .../Dialect/Linalg/Transforms/FusionOnTensors.cpp | 2 +- .../Dialect/Linalg/Transforms/SplitReduction.cpp | 4 +- .../Linalg/Transforms/TilingInterfaceImpl.cpp | 2 +- .../Dialect/Linalg/Transforms/Vectorization.cpp | 12 +-- mlir/lib/Dialect/Linalg/Utils/Utils.cpp | 14 ++-- mlir/lib/Dialect/Math/IR/MathOps.cpp | 38 ++++----- mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp | 2 +- .../MemRef/Transforms/ExpandStridedMetadata.cpp | 4 +- mlir/lib/Dialect/PDL/IR/PDL.cpp | 5 +- .../SCF/Transforms/StructuralTypeConversions.cpp | 22 ++--- .../lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp | 8 +- mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp | 4 +- .../lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp | 4 +- .../Dialect/SparseTensor/Transforms/CodegenEnv.cpp | 4 +- .../Dialect/SparseTensor/Transforms/CodegenEnv.h | 7 +- .../SparseTensor/Transforms/CodegenUtils.cpp | 2 +- .../Transforms/SparseStorageSpecifierToLLVM.cpp | 2 +- .../Transforms/SparseTensorCodegen.cpp | 5 +- .../SparseTensor/Transforms/Sparsification.cpp | 27 +++--- mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp | 12 +-- mlir/lib/Dialect/Tensor/IR/TensorOps.cpp | 2 +- mlir/lib/Dialect/Traits.cpp | 10 +-- mlir/lib/Dialect/Utils/IndexingUtils.cpp | 2 +- mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp | 25 +++--- .../VectorTransferSplitRewritePatterns.cpp | 2 +- .../lib/Dialect/Vector/Transforms/VectorUnroll.cpp | 11 +-- mlir/lib/ExecutionEngine/JitRunner.cpp | 8 +- mlir/lib/IR/AffineExpr.cpp | 2 +- mlir/lib/IR/AffineMap.cpp | 8 +- mlir/lib/IR/AsmPrinter.cpp | 13 +-- mlir/lib/IR/BuiltinAttributes.cpp | 16 ++-- mlir/lib/IR/Diagnostics.cpp | 32 ++++---- mlir/lib/IR/DialectResourceBlobManager.cpp | 2 +- mlir/lib/IR/MLIRContext.cpp | 2 +- mlir/lib/IR/OperationSupport.cpp | 14 ++-- mlir/lib/IR/SubElementInterfaces.cpp | 2 +- mlir/lib/IR/SymbolTable.cpp | 44 +++++----- mlir/lib/IR/Verifier.cpp | 3 +- mlir/lib/Interfaces/InferIntRangeInterface.cpp | 2 +- mlir/lib/Pass/Pass.cpp | 48 ++++++----- mlir/lib/Pass/PassRegistry.cpp | 4 +- mlir/lib/Pass/PassTiming.cpp | 4 +- mlir/lib/Rewrite/ByteCode.cpp | 14 ++-- mlir/lib/Rewrite/FrozenRewritePatternSet.cpp | 4 +- mlir/lib/Support/Timing.cpp | 2 +- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 4 +- .../SPIRV/Deserialization/DeserializeOps.cpp | 7 +- .../Target/SPIRV/Deserialization/Deserializer.cpp | 6 +- .../Target/SPIRV/Deserialization/Deserializer.h | 10 +-- mlir/lib/Target/SPIRV/Serialization/Serializer.cpp | 2 +- mlir/lib/Tools/PDLL/AST/NodePrinter.cpp | 10 +-- mlir/lib/Tools/PDLL/AST/Nodes.cpp | 15 ++-- mlir/lib/Tools/PDLL/AST/Types.cpp | 8 +- mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp | 2 +- mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp | 5 +- mlir/lib/Tools/PDLL/Parser/Parser.cpp | 62 +++++++------- mlir/lib/Tools/lsp-server-support/Protocol.h | 10 +-- .../Tools/lsp-server-support/SourceMgrUtils.cpp | 8 +- mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h | 4 +- mlir/lib/Tools/lsp-server-support/Transport.cpp | 4 +- mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp | 3 +- mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp | 31 +++---- mlir/lib/Tools/mlir-lsp-server/MLIRServer.h | 2 +- mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp | 3 +- mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp | 32 ++++---- mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h | 2 +- mlir/lib/Tools/mlir-translate/Translation.cpp | 10 +-- mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp | 3 +- .../lib/Tools/tblgen-lsp-server/TableGenServer.cpp | 11 +-- mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h | 2 +- mlir/lib/Transforms/LocationSnapshot.cpp | 2 +- mlir/lib/Transforms/Utils/InliningUtils.cpp | 24 +++--- mlir/lib/Transforms/ViewOpGraph.cpp | 9 +- .../DataFlow/TestDenseDataFlowAnalysis.cpp | 4 +- mlir/test/lib/Analysis/TestDataFlowFramework.cpp | 2 +- .../lib/Dialect/Shape/TestShapeMappingAnalysis.cpp | 2 +- mlir/test/lib/Dialect/Test/TestDialect.cpp | 4 +- mlir/test/lib/Dialect/Test/TestTypeDefs.td | 34 ++++---- mlir/test/lib/Dialect/Test/TestTypes.cpp | 4 +- mlir/test/lib/Dialect/Test/TestTypes.h | 6 +- .../lib/Dialect/Vector/TestVectorTransforms.cpp | 25 +++--- .../TilingInterface/TestTilingInterface.cpp | 9 +- mlir/test/lib/Transforms/TestIntRangeInference.cpp | 2 +- .../mlir-linalg-ods-yaml-gen.cpp | 16 ++-- mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp | 2 +- .../Analysis/Presburger/IntegerPolyhedronTest.cpp | 6 +- .../Analysis/Presburger/PresburgerSetTest.cpp | 4 +- mlir/unittests/Analysis/Presburger/SimplexTest.cpp | 2 +- mlir/unittests/Analysis/Presburger/Utils.h | 18 ++-- mlir/unittests/IR/AttributeTest.cpp | 2 +- 244 files changed, 1211 insertions(+), 1122 deletions(-) diff --git a/mlir/examples/toy/Ch1/include/toy/AST.h b/mlir/examples/toy/Ch1/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch1/include/toy/AST.h +++ b/mlir/examples/toy/Ch1/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch1/include/toy/Parser.h b/mlir/examples/toy/Ch1/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch1/include/toy/Parser.h +++ b/mlir/examples/toy/Ch1/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch2/include/toy/AST.h b/mlir/examples/toy/Ch2/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch2/include/toy/AST.h +++ b/mlir/examples/toy/Ch2/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch2/include/toy/Parser.h b/mlir/examples/toy/Ch2/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch2/include/toy/Parser.h +++ b/mlir/examples/toy/Ch2/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch3/include/toy/AST.h b/mlir/examples/toy/Ch3/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch3/include/toy/AST.h +++ b/mlir/examples/toy/Ch3/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch3/include/toy/Parser.h b/mlir/examples/toy/Ch3/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch3/include/toy/Parser.h +++ b/mlir/examples/toy/Ch3/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch4/include/toy/AST.h b/mlir/examples/toy/Ch4/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch4/include/toy/AST.h +++ b/mlir/examples/toy/Ch4/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch4/include/toy/Parser.h b/mlir/examples/toy/Ch4/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch4/include/toy/Parser.h +++ b/mlir/examples/toy/Ch4/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch5/include/toy/AST.h b/mlir/examples/toy/Ch5/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch5/include/toy/AST.h +++ b/mlir/examples/toy/Ch5/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch5/include/toy/Parser.h b/mlir/examples/toy/Ch5/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch5/include/toy/Parser.h +++ b/mlir/examples/toy/Ch5/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch6/include/toy/AST.h b/mlir/examples/toy/Ch6/include/toy/AST.h index 3b33231..d2ba101 100644 --- a/mlir/examples/toy/Ch6/include/toy/AST.h +++ b/mlir/examples/toy/Ch6/include/toy/AST.h @@ -129,13 +129,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch6/include/toy/Parser.h b/mlir/examples/toy/Ch6/include/toy/Parser.h index 652258e..9b0906d 100644 --- a/mlir/examples/toy/Ch6/include/toy/Parser.h +++ b/mlir/examples/toy/Ch6/include/toy/Parser.h @@ -67,7 +67,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch7/include/toy/AST.h b/mlir/examples/toy/Ch7/include/toy/AST.h index e5bd069..42d64ed 100644 --- a/mlir/examples/toy/Ch7/include/toy/AST.h +++ b/mlir/examples/toy/Ch7/include/toy/AST.h @@ -149,13 +149,13 @@ public: /// Expression class for a return operator. class ReturnExprAST : public ExprAST { - llvm::Optional> expr; + std::optional> expr; public: - ReturnExprAST(Location loc, llvm::Optional> expr) + ReturnExprAST(Location loc, std::optional> expr) : ExprAST(Expr_Return, std::move(loc)), expr(std::move(expr)) {} - llvm::Optional getExpr() { + std::optional getExpr() { if (expr.has_value()) return expr->get(); return std::nullopt; diff --git a/mlir/examples/toy/Ch7/include/toy/Parser.h b/mlir/examples/toy/Ch7/include/toy/Parser.h index 90b1eda..abfd2f5 100644 --- a/mlir/examples/toy/Ch7/include/toy/Parser.h +++ b/mlir/examples/toy/Ch7/include/toy/Parser.h @@ -82,7 +82,7 @@ private: lexer.consume(tok_return); // return takes an optional argument - llvm::Optional> expr; + std::optional> expr; if (lexer.getCurToken() != ';') { expr = parseExpression(); if (!expr) diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp index d5035ba..7f2a4c2 100644 --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -271,7 +271,7 @@ private: } /// Return the numeric member index of the given struct access expression. - llvm::Optional getMemberIndex(BinaryExprAST &accessOp) { + std::optional getMemberIndex(BinaryExprAST &accessOp) { assert(accessOp.getOp() == '.' && "expected access operation"); // Lookup the struct node for the LHS. @@ -313,7 +313,7 @@ private: // If this is an access operation, handle it immediately. if (binop.getOp() == '.') { - llvm::Optional accessIndex = getMemberIndex(binop); + std::optional accessIndex = getMemberIndex(binop); if (!accessIndex) { emitError(location, "invalid access into struct expression"); return nullptr; diff --git a/mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h index 3f5fc6b..715eae1 100644 --- a/mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h +++ b/mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h @@ -83,7 +83,7 @@ public: private: /// The constant value. - Optional constant; + std::optional constant; /// A dialect instance that can be used to materialize the constant. Dialect *dialect = nullptr; }; diff --git a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h index 6028b5b..311b81a 100644 --- a/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h +++ b/mlir/include/mlir/Analysis/DataFlow/DeadCodeAnalysis.h @@ -221,7 +221,7 @@ private: /// Get the constant values of the operands of the operation. Returns none if /// any of the operand lattices are uninitialized. - Optional> getOperandValues(Operation *op); + std::optional> getOperandValues(Operation *op); /// The top-level operation the analysis is running on. This is used to detect /// if a callable is outside the scope of the analysis and thus must be diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h index 031fb02c..527faf3 100644 --- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h @@ -362,12 +362,12 @@ public: /// /// Returns an integer sample point if one exists, or an empty Optional /// otherwise. The returned value also includes values of local ids. - Optional> findIntegerSample() const; + std::optional> findIntegerSample() const; /// Compute an overapproximation of the number of integer points in the /// relation. Symbol vars currently not supported. If the computed /// overapproximation is infinite, an empty optional is returned. - Optional computeVolume() const; + std::optional computeVolume() const; /// Returns true if the given point satisfies the constraints, or false /// otherwise. Takes the values of all vars including locals. @@ -377,9 +377,9 @@ public: } /// Given the values of non-local vars, return a satisfying assignment to the /// local if one exists, or an empty optional otherwise. - Optional> + std::optional> containsPointNoLocal(ArrayRef point) const; - Optional> + std::optional> containsPointNoLocal(ArrayRef point) const { return containsPointNoLocal(getMPIntVec(point)); } @@ -473,20 +473,20 @@ public: /// equality). Ex: if the lower bound is [(s0 + s2 - 1) floordiv 32] for a /// system with three symbolic variables, *lb = [1, 0, 1], lbDivisor = 32. See /// comments at function definition for examples. - Optional getConstantBoundOnDimSize( + std::optional getConstantBoundOnDimSize( unsigned pos, SmallVectorImpl *lb = nullptr, MPInt *boundFloorDivisor = nullptr, SmallVectorImpl *ub = nullptr, unsigned *minLbPos = nullptr, unsigned *minUbPos = nullptr) const; /// The same, but casts to int64_t. This is unsafe and will assert-fail if the /// value does not fit in an int64_t. - Optional getConstantBoundOnDimSize64( + std::optional getConstantBoundOnDimSize64( unsigned pos, SmallVectorImpl *lb = nullptr, int64_t *boundFloorDivisor = nullptr, SmallVectorImpl *ub = nullptr, unsigned *minLbPos = nullptr, unsigned *minUbPos = nullptr) const { SmallVector ubMPInt, lbMPInt; MPInt boundFloorDivisorMPInt; - Optional result = getConstantBoundOnDimSize( + std::optional result = getConstantBoundOnDimSize( pos, &lbMPInt, &boundFloorDivisorMPInt, &ubMPInt, minLbPos, minUbPos); if (lb) *lb = getInt64Vec(lbMPInt); @@ -499,10 +499,11 @@ public: /// Returns the constant bound for the pos^th variable if there is one; /// std::nullopt otherwise. - Optional getConstantBound(BoundType type, unsigned pos) const; + std::optional getConstantBound(BoundType type, unsigned pos) const; /// The same, but casts to int64_t. This is unsafe and will assert-fail if the /// value does not fit in an int64_t. - Optional getConstantBound64(BoundType type, unsigned pos) const { + std::optional getConstantBound64(BoundType type, + unsigned pos) const { return llvm::transformOptional(getConstantBound(type, pos), int64FromMPInt); } @@ -683,11 +684,11 @@ protected: /// Returns the constant lower bound bound if isLower is true, and the upper /// bound if isLower is false. template - Optional computeConstantLowerOrUpperBound(unsigned pos); + std::optional computeConstantLowerOrUpperBound(unsigned pos); /// The same, but casts to int64_t. This is unsafe and will assert-fail if the /// value does not fit in an int64_t. template - Optional computeConstantLowerOrUpperBound64(unsigned pos) { + std::optional computeConstantLowerOrUpperBound64(unsigned pos) { return computeConstantLowerOrUpperBound(pos).map(int64FromMPInt); } diff --git a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h index 566baca..4ba0f44 100644 --- a/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h +++ b/mlir/include/mlir/Analysis/Presburger/PWMAFunction.h @@ -176,8 +176,8 @@ public: PresburgerSet getDomain() const; /// Return the output of the function at the given point. - Optional> valueAt(ArrayRef point) const; - Optional> valueAt(ArrayRef point) const { + std::optional> valueAt(ArrayRef point) const; + std::optional> valueAt(ArrayRef point) const { return valueAt(getMPIntVec(point)); } diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h index 189b52c..57ffbd3 100644 --- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h @@ -121,7 +121,7 @@ public: /// This currently just sums up the overapproximations of the volumes of the /// disjuncts, so the approximation might be far from the true volume in the /// case when there is a lot of overlap between disjuncts. - Optional computeVolume() const; + std::optional computeVolume() const; /// Simplifies the representation of a PresburgerRelation. /// diff --git a/mlir/include/mlir/Analysis/Presburger/Simplex.h b/mlir/include/mlir/Analysis/Presburger/Simplex.h index 4ef4e62..5a562da 100644 --- a/mlir/include/mlir/Analysis/Presburger/Simplex.h +++ b/mlir/include/mlir/Analysis/Presburger/Simplex.h @@ -264,7 +264,7 @@ protected: /// Returns an empty optional if no pivot is possible, which happens only when /// the column unknown is a variable and no constraint has a non-zero /// coefficient for it. - Optional findAnyPivotRow(unsigned col); + std::optional findAnyPivotRow(unsigned col); /// Swap the row with the column in the tableau's data structures but not the /// tableau itself. This is used by pivot. @@ -523,11 +523,11 @@ private: /// Get a constraint row that is violated, if one exists. /// Otherwise, return an empty optional. - Optional maybeGetViolatedRow() const; + std::optional maybeGetViolatedRow() const; /// Get a row corresponding to a var that has a non-integral sample value, if /// one exists. Otherwise, return an empty optional. - Optional maybeGetNonIntegralVarRow() const; + std::optional maybeGetNonIntegralVarRow() const; }; /// Represents the result of a symbolic lexicographic minimization computation. @@ -634,11 +634,11 @@ private: LogicalResult doNonBranchingPivots(); /// Get a row that is always violated in the current domain, if one exists. - Optional maybeGetAlwaysViolatedRow(); + std::optional maybeGetAlwaysViolatedRow(); /// Get a row corresponding to a variable with non-integral sample value, if /// one exists. - Optional maybeGetNonIntegralVarRow(); + std::optional maybeGetNonIntegralVarRow(); /// Given a row that has a non-integer sample value, cut away this fractional /// sample value witahout removing any integer points, i.e., the integer @@ -782,7 +782,7 @@ public: /// Returns an integer sample point if one exists, or std::nullopt /// otherwise. This should only be called for bounded sets. - Optional> findIntegerSample(); + std::optional> findIntegerSample(); enum class IneqType { Redundant, Cut, Separate }; @@ -806,11 +806,11 @@ public: /// Returns the current sample point if it is integral. Otherwise, returns /// std::nullopt. - Optional> getSamplePointIfIntegral() const; + std::optional> getSamplePointIfIntegral() const; /// Returns the current sample point, which may contain non-integer (rational) /// coordinates. Returns an empty optional when the tableau is empty. - Optional> getRationalSample() const; + std::optional> getRationalSample() const; private: friend class GBRSimplex; @@ -829,7 +829,7 @@ private: /// /// Returns a (row, col) pair denoting a pivot, or an empty Optional if /// no valid pivot exists. - Optional findPivot(int row, Direction direction) const; + std::optional findPivot(int row, Direction direction) const; /// Find a row that can be used to pivot the column in the specified /// direction. If skipRow is not null, then this row is excluded @@ -839,8 +839,8 @@ private: /// /// Returns the row to pivot to, or an empty Optional if the column /// is unbounded in the specified direction. - Optional findPivotRow(Optional skipRow, - Direction direction, unsigned col) const; + std::optional findPivotRow(std::optional skipRow, + Direction direction, unsigned col) const; /// Undo the addition of the last constraint while preserving tableau /// consistency. diff --git a/mlir/include/mlir/Analysis/Presburger/Utils.h b/mlir/include/mlir/Analysis/Presburger/Utils.h index 775d954..592782d 100644 --- a/mlir/include/mlir/Analysis/Presburger/Utils.h +++ b/mlir/include/mlir/Analysis/Presburger/Utils.h @@ -53,7 +53,7 @@ public: bool isUnbounded() const { return kind == OptimumKind::Unbounded; } bool isEmpty() const { return kind == OptimumKind::Empty; } - Optional getOptimumIfBounded() const { return optimum; } + std::optional getOptimumIfBounded() const { return optimum; } const T &getBoundedOptimum() const { assert(kind == OptimumKind::Bounded && "This should be called only for bounded optima"); @@ -143,7 +143,7 @@ public: // For a given point containing values for each variable other than the // division variables, try to find the values for each division variable from // their division representation. - SmallVector, 4> divValuesAt(ArrayRef point) const; + SmallVector, 4> divValuesAt(ArrayRef point) const; // Get the `i^th` denominator. MPInt &getDenom(unsigned i) { return denoms[i]; } diff --git a/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h b/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h index dfb45df..cd79e8e 100644 --- a/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h +++ b/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h @@ -22,7 +22,7 @@ class OperationPass; /// If log1pBenefit is present, use it instead of benefit for the Log1p op. void populateMathToLibmConversionPatterns( RewritePatternSet &patterns, PatternBenefit benefit, - llvm::Optional log1pBenefit = std::nullopt); + std::optional log1pBenefit = std::nullopt); /// Create a pass to convert Math operations to libm calls. std::unique_ptr> createConvertMathToLibmPass(); diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h index 02a58e9..b19315e 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineAnalysis.h @@ -141,9 +141,9 @@ struct DependenceComponent { // The AffineForOp Operation associated with this dependence component. Operation *op = nullptr; // The lower bound of the dependence distance. - Optional lb; + std::optional lb; // The upper bound of the dependence distance (inclusive). - Optional ub; + std::optional ub; DependenceComponent() : lb(std::nullopt), ub(std::nullopt) {} }; diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h index de69fb8..0282d2e 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h @@ -48,7 +48,7 @@ public: unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDims, unsigned numSymbols, unsigned numLocals, - ArrayRef> valArgs = {}) + ArrayRef> valArgs = {}) : IntegerPolyhedron(numReservedInequalities, numReservedEqualities, numReservedCols, presburger::PresburgerSpace::getSetSpace( @@ -66,7 +66,7 @@ public: /// dimensions and symbols. FlatAffineValueConstraints(unsigned numDims = 0, unsigned numSymbols = 0, unsigned numLocals = 0, - ArrayRef> valArgs = {}) + ArrayRef> valArgs = {}) : FlatAffineValueConstraints(/*numReservedInequalities=*/0, /*numReservedEqualities=*/0, /*numReservedCols=*/numDims + numSymbols + @@ -74,7 +74,7 @@ public: numDims, numSymbols, numLocals, valArgs) {} FlatAffineValueConstraints(const IntegerPolyhedron &fac, - ArrayRef> valArgs = {}) + ArrayRef> valArgs = {}) : IntegerPolyhedron(fac) { assert(valArgs.empty() || valArgs.size() == getNumDimAndSymbolVars()); if (valArgs.empty()) @@ -437,11 +437,11 @@ public: getValues(0, getNumDimAndSymbolVars(), values); } - inline ArrayRef> getMaybeValues() const { + inline ArrayRef> getMaybeValues() const { return {values.data(), values.size()}; } - inline ArrayRef> + inline ArrayRef> getMaybeValues(presburger::VarKind kind) const { assert(kind != VarKind::Local && "Local variables do not have any value attached to them."); @@ -511,7 +511,7 @@ protected: /// constraint system appearing in the order the variables correspond to /// columns. Variables that aren't associated with any Value are set to /// None. - SmallVector, 8> values; + SmallVector, 8> values; }; /// A FlatAffineRelation represents a set of ordered pairs (domain -> range) @@ -525,7 +525,7 @@ public: unsigned numReservedEqualities, unsigned numReservedCols, unsigned numDomainDims, unsigned numRangeDims, unsigned numSymbols, unsigned numLocals, - ArrayRef> valArgs = {}) + ArrayRef> valArgs = {}) : FlatAffineValueConstraints( numReservedInequalities, numReservedEqualities, numReservedCols, numDomainDims + numRangeDims, numSymbols, numLocals, valArgs), diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h b/mlir/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h index 6f95f08..d0ac1a2 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/LoopAnalysis.h @@ -41,7 +41,7 @@ void getTripCountMapAndOperands(AffineForOp forOp, AffineMap *map, /// Returns the trip count of the loop if it's a constant, std::nullopt /// otherwise. This uses affine expression analysis and is able to determine /// constant trip count in non-trivial cases. -Optional getConstantTripCount(AffineForOp forOp); +std::optional getConstantTripCount(AffineForOp forOp); /// Returns the greatest known integral divisor of the trip count. Affine /// expression analysis is used (indirectly through getTripCount), and diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h index 62a8b0e..72850bf 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h @@ -115,7 +115,7 @@ struct ComputationSliceState { /// cannot determine if the slice is maximal or not. // TODO: Cache 'isMaximal' so that we don't recompute it when the slice // information hasn't changed. - Optional isMaximal() const; + std::optional isMaximal() const; /// Checks the validity of the slice computed. This is done using the /// following steps: @@ -131,7 +131,7 @@ struct ComputationSliceState { /// return false as it implies that the effective fusion results in at least /// one iteration of the slice that was not originally in the source's domain. /// If the validity cannot be determined, returns std::nullopt. - Optional isSliceValid(); + std::optional isSliceValid(); void dump() const; @@ -141,7 +141,7 @@ private: /// and the dst loops for those dimensions have the same bounds. Returns false /// if both the src and the dst loops don't have the same bounds. Returns /// std::nullopt if none of the above can be proven. - Optional isSliceMaximalFastCheck() const; + std::optional isSliceMaximalFastCheck() const; }; /// Computes the computation slice loop bounds for one loop nest as affine maps @@ -303,7 +303,7 @@ struct MemRefRegion { /// int64_t. `lbs` are set to the lower bounds for each of the rank /// dimensions, and lbDivisors contains the corresponding denominators for /// floorDivs. - Optional getConstantBoundingSizeAndShape( + std::optional getConstantBoundingSizeAndShape( SmallVectorImpl *shape = nullptr, std::vector> *lbs = nullptr, SmallVectorImpl *lbDivisors = nullptr) const; @@ -317,7 +317,7 @@ struct MemRefRegion { /// 'pos' corresponds to the position of the memref shape's dimension (major /// to minor) which matches 1:1 with the dimensional variable positions in /// 'cst'. - Optional + std::optional getConstantBoundOnDimSize(unsigned pos, SmallVectorImpl *lb = nullptr, int64_t *lbFloorDivisor = nullptr) const { @@ -326,7 +326,7 @@ struct MemRefRegion { } /// Returns the size of this MemRefRegion in bytes. - Optional getRegionSize(); + std::optional getRegionSize(); // Wrapper around FlatAffineValueConstraints::unionBoundingBox. LogicalResult unionBoundingBox(const MemRefRegion &other); @@ -357,7 +357,7 @@ struct MemRefRegion { /// Returns the size of memref data in bytes if it's statically shaped, /// std::nullopt otherwise. -Optional getMemRefSizeInBytes(MemRefType memRefType); +std::optional getMemRefSizeInBytes(MemRefType memRefType); /// Checks a load or store op for an out of bound access; returns failure if the /// access is out of bounds along any of the dimensions, success otherwise. @@ -371,8 +371,8 @@ unsigned getNumCommonSurroundingLoops(Operation &a, Operation &b); /// Gets the memory footprint of all data touched in the specified memory space /// in bytes; if the memory space is unspecified, considers all memory spaces. -Optional getMemoryFootprintBytes(AffineForOp forOp, - int memorySpace = -1); +std::optional getMemoryFootprintBytes(AffineForOp forOp, + int memorySpace = -1); /// Simplify the integer set by simplifying the underlying affine expressions by /// flattening and some simple inference. Also, drop any duplicate constraints. diff --git a/mlir/include/mlir/Dialect/Affine/LoopUtils.h b/mlir/include/mlir/Dialect/Affine/LoopUtils.h index c13cd8c..2e3a587 100644 --- a/mlir/include/mlir/Dialect/Affine/LoopUtils.h +++ b/mlir/include/mlir/Dialect/Affine/LoopUtils.h @@ -186,14 +186,14 @@ struct AffineCopyOptions { /// encountered. LogicalResult affineDataCopyGenerate(Block::iterator begin, Block::iterator end, const AffineCopyOptions ©Options, - Optional filterMemRef, + std::optional filterMemRef, DenseSet ©Nests); /// A convenience version of affineDataCopyGenerate for all ops in the body of /// an AffineForOp. LogicalResult affineDataCopyGenerate(AffineForOp forOp, const AffineCopyOptions ©Options, - Optional filterMemRef, + std::optional filterMemRef, DenseSet ©Nests); /// Result for calling generateCopyForMemRegion. diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h index 1ea6507..b6e60b0 100644 --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -301,10 +301,10 @@ Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr, /// Create a sequence of operations that implement the `affineMap` applied to /// the given `operands` (as it it were an AffineApplyOp). -Optional> expandAffineMap(OpBuilder &builder, - Location loc, - AffineMap affineMap, - ValueRange operands); +std::optional> expandAffineMap(OpBuilder &builder, + Location loc, + AffineMap affineMap, + ValueRange operands); /// Holds the result of (div a, b) and (mod a, b). struct DivModValue { diff --git a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td index 14146cd..9db2167 100644 --- a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td +++ b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td @@ -333,7 +333,7 @@ def Async_AwaitOp : Async_Op<"await"> { ]; let extraClassDeclaration = [{ - Optional getResultType() { + std::optional getResultType() { if (getResultTypes().empty()) return std::nullopt; return getResultTypes()[0]; } diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h index 2eef942..0ca2086 100644 --- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h +++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h @@ -204,9 +204,9 @@ struct BufferizationOptions { bool isOpAllowed(Operation *op) const; /// Helper functions for allocation, deallocation, memory copying. - Optional allocationFn; - Optional deallocationFn; - Optional memCpyFn; + std::optional allocationFn; + std::optional deallocationFn; + std::optional memCpyFn; /// Create a memref allocation with the given type and dynamic extents. FailureOr createAlloc(OpBuilder &b, Location loc, MemRefType type, @@ -233,7 +233,7 @@ struct BufferizationOptions { /// The default memory space that should be used when it cannot be inferred /// from the context. If case of std::nullopt, bufferization fails when the /// memory space cannot be inferred at any point. - Optional defaultMemorySpace = Attribute(); + std::optional defaultMemorySpace = Attribute(); /// Certain ops have aliasing OpOperand/OpResult invariants (e.g., scf.for). /// If this flag is set to `false`, those invariants are no longer enforced diff --git a/mlir/include/mlir/Dialect/CommonFolders.h b/mlir/include/mlir/Dialect/CommonFolders.h index a8f0a07..425a8c2 100644 --- a/mlir/include/mlir/Dialect/CommonFolders.h +++ b/mlir/include/mlir/Dialect/CommonFolders.h @@ -24,10 +24,10 @@ namespace mlir { /// Performs constant folding `calculate` with element-wise behavior on the two /// attributes in `operands` and returns the result if possible. -template < - class AttrElementT, class ElementValueT = typename AttrElementT::ValueType, - class CalculationT = - function_ref(ElementValueT, ElementValueT)>> +template (ElementValueT, ElementValueT)>> Attribute constFoldBinaryOpConditional(ArrayRef operands, const CalculationT &calculate) { assert(operands.size() == 2 && "binary op takes two operands"); @@ -96,16 +96,17 @@ Attribute constFoldBinaryOp(ArrayRef operands, const CalculationT &calculate) { return constFoldBinaryOpConditional( operands, - [&](ElementValueT a, ElementValueT b) -> Optional { + [&](ElementValueT a, ElementValueT b) -> std::optional { return calculate(a, b); }); } /// Performs constant folding `calculate` with element-wise behavior on the one /// attributes in `operands` and returns the result if possible. -template < - class AttrElementT, class ElementValueT = typename AttrElementT::ValueType, - class CalculationT = function_ref(ElementValueT)>> +template (ElementValueT)>> Attribute constFoldUnaryOpConditional(ArrayRef operands, const CalculationT &&calculate) { assert(operands.size() == 1 && "unary op takes one operands"); @@ -154,8 +155,9 @@ template operands, const CalculationT &&calculate) { return constFoldUnaryOpConditional( - operands, - [&](ElementValueT a) -> Optional { return calculate(a); }); + operands, [&](ElementValueT a) -> std::optional { + return calculate(a); + }); } template < diff --git a/mlir/include/mlir/Dialect/Func/Transforms/DecomposeCallGraphTypes.h b/mlir/include/mlir/Dialect/Func/Transforms/DecomposeCallGraphTypes.h index 6e740f3..6f27cbb 100644 --- a/mlir/include/mlir/Dialect/Func/Transforms/DecomposeCallGraphTypes.h +++ b/mlir/include/mlir/Dialect/Func/Transforms/DecomposeCallGraphTypes.h @@ -61,20 +61,22 @@ public: } private: - using DecomposeValueConversionCallFn = std::function( - OpBuilder &, Location, Type, Value, SmallVectorImpl &)>; + using DecomposeValueConversionCallFn = + std::function( + OpBuilder &, Location, Type, Value, SmallVectorImpl &)>; /// Generate a wrapper for the given decompose value conversion callback. template DecomposeValueConversionCallFn wrapDecomposeValueConversionCallback(FnT &&callback) { - return [callback = std::forward(callback)]( - OpBuilder &builder, Location loc, Type type, Value value, - SmallVectorImpl &newValues) -> Optional { - if (T derivedType = type.dyn_cast()) - return callback(builder, loc, derivedType, value, newValues); - return std::nullopt; - }; + return + [callback = std::forward(callback)]( + OpBuilder &builder, Location loc, Type type, Value value, + SmallVectorImpl &newValues) -> std::optional { + if (T derivedType = type.dyn_cast()) + return callback(builder, loc, derivedType, value, newValues); + return std::nullopt; + }; } SmallVector decomposeValueConversions; diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td index 4442307..650ebe4 100644 --- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td +++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td @@ -330,7 +330,7 @@ def GPU_GPUFuncOp : GPU_Op<"func", [ /// Returns the block size this kernel will be launched with along /// dimension `dim` if known. The value of gpu.thread_id dim will be strictly /// less than this size. - Optional getKnownBlockSize(gpu::Dimension dim) { + std::optional getKnownBlockSize(gpu::Dimension dim) { if (auto array = (*this)->getAttrOfType(getKnownBlockSizeAttrName())) { return array[static_cast(dim)]; @@ -341,7 +341,7 @@ def GPU_GPUFuncOp : GPU_Op<"func", [ /// Returns the grid size this kernel will be launched with along /// dimension `dim` if known. The value of gpu.block_id dim will be strictly /// less than this size. - Optional getKnownGridSize(gpu::Dimension dim) { + std::optional getKnownGridSize(gpu::Dimension dim) { if (auto array = (*this)->getAttrOfType(getKnownGridSizeAttrName())) { return array[static_cast(dim)]; diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h index 049dd04..594d8be 100644 --- a/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h +++ b/mlir/include/mlir/Dialect/GPU/Transforms/Passes.h @@ -107,8 +107,8 @@ private: std::unique_ptr createTargetMachine(); /// Translates the module to ISA - Optional translateToISA(llvm::Module &llvmModule, - llvm::TargetMachine &targetMachine); + std::optional translateToISA(llvm::Module &llvmModule, + llvm::TargetMachine &targetMachine); /// Serializes the target ISA to binary form. virtual std::unique_ptr> diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td index 733d573..4963bc9 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td @@ -70,9 +70,9 @@ def LoopOptionsAttr : LLVM_Attr<"LoopOptions", "loopopts"> { let extraClassDeclaration = [{ using OptionValuePair = std::pair; using OptionsArray = ArrayRef>; - Optional disableUnroll(); - Optional disableLICM(); - Optional interleaveCount(); + std::optional disableUnroll(); + std::optional disableLICM(); + std::optional interleaveCount(); }]; let builders = [ diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h index 20203a4..fd2d184 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h @@ -81,31 +81,31 @@ public: /// Set the `disable_licm` option to the provided value. If no value /// is provided the option is deleted. - LoopOptionsAttrBuilder &setDisableLICM(Optional value); + LoopOptionsAttrBuilder &setDisableLICM(std::optional value); /// Set the `interleave_count` option to the provided value. If no value /// is provided the option is deleted. - LoopOptionsAttrBuilder &setInterleaveCount(Optional count); + LoopOptionsAttrBuilder &setInterleaveCount(std::optional count); /// Set the `disable_unroll` option to the provided value. If no value /// is provided the option is deleted. - LoopOptionsAttrBuilder &setDisableUnroll(Optional value); + LoopOptionsAttrBuilder &setDisableUnroll(std::optional value); /// Set the `disable_pipeline` option to the provided value. If no value /// is provided the option is deleted. - LoopOptionsAttrBuilder &setDisablePipeline(Optional value); + LoopOptionsAttrBuilder &setDisablePipeline(std::optional value); /// Set the `pipeline_initiation_interval` option to the provided value. /// If no value is provided the option is deleted. LoopOptionsAttrBuilder & - setPipelineInitiationInterval(Optional count); + setPipelineInitiationInterval(std::optional count); /// Returns true if any option has been set. bool empty() { return options.empty(); } private: template - LoopOptionsAttrBuilder &setOption(LoopOptionCase tag, Optional value); + LoopOptionsAttrBuilder &setOption(LoopOptionCase tag, std::optional value); friend class LoopOptionsAttr; SmallVector options; diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 5f96a46..e01c6bb 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -787,7 +787,7 @@ def LLVM_CondBrOp : LLVM_TerminatorOp<"cond_br", OpBuilder<(ins "Value":$condition, "Block *":$trueDest, "ValueRange":$trueOperands, "Block *":$falseDest, "ValueRange":$falseOperands, - CArg<"Optional>", "{}">:$weights), + CArg<"std::optional>", "{}">:$weights), [{ ElementsAttr weightsAttr; if (weights) { @@ -1500,7 +1500,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [ CArg<"CConv", "CConv::C">:$cconv, CArg<"ArrayRef", "{}">:$attrs, CArg<"ArrayRef", "{}">:$argAttrs, - CArg<"Optional", "{}">:$functionEntryCount)> + CArg<"std::optional", "{}">:$functionEntryCount)> ]; let extraClassDeclaration = [{ diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h index 8cccfef..3251f2c 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h @@ -286,7 +286,8 @@ enum class PtrDLEntryPos { Size = 0, Abi = 1, Preferred = 2, Index = 3 }; /// Returns `std::nullopt` if `pos` is not present in the entry. /// Currently only `PtrDLEntryPos::Index` is optional, and all other positions /// may be assumed to be present. -Optional extractPointerSpecValue(Attribute attr, PtrDLEntryPos pos); +std::optional extractPointerSpecValue(Attribute attr, + PtrDLEntryPos pos); } // namespace LLVM } // namespace mlir diff --git a/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h b/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h index f6490f0..09ed596 100644 --- a/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h +++ b/mlir/include/mlir/Dialect/Linalg/Analysis/DependenceAnalysis.h @@ -78,7 +78,7 @@ public: } // Return the indexing map of the operand/result in `opView` specified in // the owning LinalgOp. If the owner is not a LinalgOp returns std::nullopt. - static Optional getIndexingMap(OpView opView) { + static std::optional getIndexingMap(OpView opView) { auto owner = dyn_cast(getOwner(opView)); if (!owner) return std::nullopt; @@ -89,14 +89,14 @@ public: } // Return the operand number if the `opView` is an OpOperand *. Otherwise // return std::nullopt. - static Optional getOperandNumber(OpView opView) { + static std::optional getOperandNumber(OpView opView) { if (OpOperand *operand = opView.dyn_cast()) return operand->getOperandNumber(); return std::nullopt; } // Return the result number if the `opView` is an OpResult. Otherwise return // std::nullopt. - static Optional getResultNumber(OpView opView) { + static std::optional getResultNumber(OpView opView) { if (OpResult result = opView.dyn_cast().cast()) return result.getResultNumber(); return std::nullopt; @@ -116,37 +116,37 @@ public: // If the dependent OpView is an operand, return operand number. Return // std::nullopt otherwise. - Optional getDependentOpViewOperandNum() const { + std::optional getDependentOpViewOperandNum() const { return getOperandNumber(dependentOpView); } // If the indexing OpView is an operand, return operand number. Return // std::nullopt otherwise. - Optional getIndexingOpViewOperandNum() const { + std::optional getIndexingOpViewOperandNum() const { return getOperandNumber(indexingOpView); } // If the dependent OpView is a result value, return the result // number. Return std::nullopt otherwise. - Optional getDependentOpViewResultNum() const { + std::optional getDependentOpViewResultNum() const { return getResultNumber(dependentOpView); } // If the dependent OpView is a result value, return the result // number. Return std::nullopt otherwise. - Optional getIndexingOpViewResultNum() const { + std::optional getIndexingOpViewResultNum() const { return getResultNumber(indexingOpView); } // Return the indexing map of the operand/result in the dependent OpView as // specified in the owner of the OpView. - Optional getDependentOpViewIndexingMap() const { + std::optional getDependentOpViewIndexingMap() const { return getIndexingMap(dependentOpView); } // Return the indexing map of the operand/result in the indexing OpView as // specified in the owner of the OpView. - Optional getIndexingOpViewIndexingMap() const { + std::optional getIndexingOpViewIndexingMap() const { return getIndexingMap(indexingOpView); } }; diff --git a/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h b/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h index 179a1c1..4b62805 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/Linalg.h @@ -64,7 +64,7 @@ SmallVector makeAffineDimExprs(unsigned num, unsigned &startIdx, /// Returns `maybeMap.get()` if `maybeMap` is set, otherwise returns the /// symbol-less identity map of `rank`. -AffineMap extractOrIdentityMap(Optional maybeMap, unsigned rank, +AffineMap extractOrIdentityMap(std::optional maybeMap, unsigned rank, MLIRContext *context); /// Return the vector that is the concatenation of `a` and `b`. diff --git a/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h b/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h index f0ed6d5..580620c 100644 --- a/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/Linalg/Utils/Utils.h @@ -135,12 +135,12 @@ GenericOp makeMemRefCopyOp(OpBuilder &b, Location loc, Value from, Value to); /// and offset is 0. Strictly speaking the offset 0 is not required in general, /// but non-zero offsets are not handled by SPIR-V backend at this point (and /// potentially cannot be handled). -Optional> +std::optional> getReassociationMapForFoldingUnitDims(ArrayRef mixedSizes); /// Return the identity numeric value associated to the give op. Return /// std::nullopt if there is no known neutral element. -Optional getNeutralElement(Operation *op); +std::optional getNeutralElement(Operation *op); //===----------------------------------------------------------------------===// // Fusion / Tiling utilities @@ -224,7 +224,7 @@ computeSliceParameters(OpBuilder &builder, Location loc, Value valueToTile, /// /// Some of the `valuesToTile` won't be affected by tiling. For these values, /// std::nullopt will be returned. -SmallVector> +SmallVector> computeAllSliceParameters(OpBuilder &builder, Location loc, LinalgOp linalgOp, ValueRange valuesToTile, ArrayRef ivs, ArrayRef tileSizes, @@ -397,7 +397,7 @@ public: LogicalResult tileRootOp(OpBuilder &b, ArrayRef tileSizes, ArrayRef tileInterchange, - Optional tileDistribution); + std::optional tileDistribution); /// Fuse the producer of `consumerOpOperand` into the tile loop nest. Returns /// the fused producer or fails if fusion is not possible. @@ -467,7 +467,7 @@ struct RegionMatcher { /// linalg.yield %0: /// } /// ``` - static Optional matchAsScalarBinaryOp(GenericOp op); + static std::optional matchAsScalarBinaryOp(GenericOp op); }; //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h b/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h index f330a54..b599c3c 100644 --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRef.h @@ -53,7 +53,7 @@ Type getTensorTypeFromMemRefType(Type type); /// Finds a single dealloc operation for the given allocated value. If there /// are > 1 deallocates for `allocValue`, returns std::nullopt, else returns the /// single deallocate if it exists or nullptr. -Optional findDealloc(Value allocValue); +std::optional findDealloc(Value allocValue); /// Return the dimensions of the given memref value. SmallVector getMixedSizes(OpBuilder &builder, Location loc, diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td index 6e589cb..d5b5d2b 100644 --- a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td +++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td @@ -354,7 +354,7 @@ def PDL_OperationOp : PDL_Op<"operation", [AttrSizedOperandSegments]> { }]; let builders = [ - OpBuilder<(ins CArg<"Optional", "std::nullopt">:$name, + OpBuilder<(ins CArg<"std::optional", "std::nullopt">:$name, CArg<"ValueRange", "std::nullopt">:$operandValues, CArg<"ArrayRef", "std::nullopt">:$attrNames, CArg<"ValueRange", "std::nullopt">:$attrValues, @@ -419,8 +419,8 @@ def PDL_PatternOp : PDL_Op<"pattern", [ }]; let builders = [ - OpBuilder<(ins CArg<"Optional", "1">:$benefit, - CArg<"Optional", "std::nullopt">:$name)>, + OpBuilder<(ins CArg<"std::optional", "1">:$benefit, + CArg<"std::optional", "std::nullopt">:$name)>, ]; let extraClassDeclaration = [{ //===------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/SCF/Utils/Utils.h b/mlir/include/mlir/Dialect/SCF/Utils/Utils.h index 594124d..a7fada7 100644 --- a/mlir/include/mlir/Dialect/SCF/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/SCF/Utils/Utils.h @@ -113,7 +113,7 @@ bool getInnermostParallelLoops(Operation *rootOp, /// from scf.for or scf.parallel loop. /// if `loopFilter` is passed, the filter determines which loop to consider. /// Other induction variables are ignored. -Optional> +std::optional> getSCFMinMaxExpr(Value value, SmallVectorImpl &dims, SmallVectorImpl &symbols, llvm::function_ref loopFilter = nullptr); diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td index 21a83bf..e9b3a42 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td @@ -134,7 +134,7 @@ def SPIRV_BranchConditionalOp : SPIRV_Op<"BranchConditional", [ OpBuilder<(ins "Value":$condition, "Block *":$trueBlock, "ValueRange":$trueArguments, "Block *":$falseBlock, "ValueRange":$falseArguments, - CArg<"Optional>", "{}">:$weights), + CArg<"std::optional>", "{}">:$weights), [{ ArrayAttr weightsAttr; if (weights) { diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/TargetAndABI.h b/mlir/include/mlir/Dialect/SPIRV/IR/TargetAndABI.h index ce3bc94..f2e12d3 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/TargetAndABI.h +++ b/mlir/include/mlir/Dialect/SPIRV/IR/TargetAndABI.h @@ -36,13 +36,13 @@ public: bool allows(Capability) const; /// Returns the first allowed one if any of the given capabilities is allowed. /// Returns std::nullopt otherwise. - Optional allows(ArrayRef) const; + std::optional allows(ArrayRef) const; /// Returns true if the given extension is allowed. bool allows(Extension) const; /// Returns the first allowed one if any of the given extensions is allowed. /// Returns std::nullopt otherwise. - Optional allows(ArrayRef) const; + std::optional allows(ArrayRef) const; /// Returns the vendor ID. Vendor getVendorID() const; diff --git a/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h b/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h index 7c0f3e1..c96f76e 100644 --- a/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h +++ b/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h @@ -296,19 +296,19 @@ public: return getDimLevelType(tensor(b), index(b)); } - Optional getLoopIdx(unsigned t, unsigned dim) const { + std::optional getLoopIdx(unsigned t, unsigned dim) const { assert(t < numTensors && dim < numLoops); return dimToLoopIdx[t][dim]; } /// Gets the dimension number of the the `t`th tensor on `i`th loop. - Optional getDimNum(unsigned t, unsigned i) const { + std::optional getDimNum(unsigned t, unsigned i) const { assert(t < numTensors && i < numLoops); return loopIdxToDim[t][i]; } /// Gets the dimension number of `b`. - Optional getDimNum(unsigned b) const { + std::optional getDimNum(unsigned b) const { return getDimNum(tensor(b), index(b)); } @@ -327,7 +327,7 @@ public: // corresponding tensor dimension and invokes the callback. void foreachTidDimPairInBits( const BitVector &bits, - function_ref dim, + function_ref dim, DimLevelType dlt)> cb) { for (unsigned b : bits.set_bits()) @@ -360,7 +360,7 @@ public: /// Builds a tensor expression from the given Linalg operation. /// Returns index of the root expression on success. - Optional buildTensorExpFromLinalg(linalg::GenericOp op); + std::optional buildTensorExpFromLinalg(linalg::GenericOp op); /// Rebuilds SSA format from a tensor expression. Value buildExp(RewriterBase &rewriter, Location loc, unsigned e, Value v0, @@ -373,7 +373,7 @@ private: Type inferType(unsigned e, Value src); /// Traverses the SSA tree (possibly a DAG) to build a tensor expression. - Optional buildTensorExp(linalg::GenericOp op, Value v); + std::optional buildTensorExp(linalg::GenericOp op, Value v); /// Merger data structures. const unsigned outTensor; @@ -389,10 +389,10 @@ private: // Map that converts pair to the corresponding // dimension. - std::vector>> loopIdxToDim; + std::vector>> loopIdxToDim; // Map that converts pair to the corresponding loop id. - std::vector>> dimToLoopIdx; + std::vector>> dimToLoopIdx; llvm::SmallVector tensorExps; llvm::SmallVector latPoints; diff --git a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td index ccd53b7..f0f1238 100644 --- a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td +++ b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td @@ -1761,7 +1761,7 @@ def Tensor_PackOp : Tensor_RelayoutOp<"pack", [ OpBuilder<(ins "Value":$source, "Value":$dest, "ArrayRef":$innerDimsPos, "ArrayRef":$innerTiles, - CArg<"Optional", "std::nullopt">:$paddingValue, + CArg<"std::optional", "std::nullopt">:$paddingValue, CArg<"ArrayRef", "{}">:$outerDimsPerm)> ]; diff --git a/mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h b/mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h index fd4574a..b36e40b 100644 --- a/mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h +++ b/mlir/include/mlir/Dialect/Tosa/Utils/ConversionUtils.h @@ -45,9 +45,9 @@ bool validIntegerRange(IntegerType ty, int64_t value); // Checks for a dynamic batch dim in any of the passed parameters of an op. // The batch dimention must be #0 and the rest of the dimensions must be static. template -Optional> checkHasDynamicBatchDims(PatternRewriter &rewriter, - Op op, - ArrayRef params) { +std::optional> +checkHasDynamicBatchDims(PatternRewriter &rewriter, Op op, + ArrayRef params) { SmallVector dynTypes; SmallVector dynamicDims; for (const Value ¶m : params) { diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h index 0abc006..41f3da0 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h @@ -190,7 +190,7 @@ private: template void TransformDialect::addOperationIfNotRegistered() { StringRef name = OpTy::getOperationName(); - Optional opName = + std::optional opName = RegisteredOperationName::lookup(name, getContext()); if (!opName) { addOperations(); diff --git a/mlir/include/mlir/Dialect/Transform/Utils/DiagnosedSilenceableFailure.h b/mlir/include/mlir/Dialect/Transform/Utils/DiagnosedSilenceableFailure.h index de4bce0..fcf422a 100644 --- a/mlir/include/mlir/Dialect/Transform/Utils/DiagnosedSilenceableFailure.h +++ b/mlir/include/mlir/Dialect/Transform/Utils/DiagnosedSilenceableFailure.h @@ -137,7 +137,7 @@ public: /// Attaches a note to the last diagnostic. /// Expects this object to be a silenceable failure. - Diagnostic &attachNote(Optional loc = std::nullopt) { + Diagnostic &attachNote(std::optional loc = std::nullopt) { assert(isSilenceableFailure() && "can only attach notes to silenceable failures"); return diagnostics.back().attachNote(loc); @@ -201,7 +201,7 @@ public: } /// Attaches a note to the error. - Diagnostic &attachNote(Optional loc = std::nullopt) { + Diagnostic &attachNote(std::optional loc = std::nullopt) { return diag.attachNote(loc); } diff --git a/mlir/include/mlir/Dialect/Utils/IndexingUtils.h b/mlir/include/mlir/Dialect/Utils/IndexingUtils.h index 3b4584c..64eea7e 100644 --- a/mlir/include/mlir/Dialect/Utils/IndexingUtils.h +++ b/mlir/include/mlir/Dialect/Utils/IndexingUtils.h @@ -57,8 +57,8 @@ SmallVector computeElementwiseMul(ArrayRef v1, /// derived as {42(leading shape dim), 2/2, 10/5, 32/2}. /// - shapeRatio({42, 2, 11, 32}, {2, 5, 2}) returns std::nullopt which is /// derived as {42(leading shape dim), 2/2, 11/5(not divisible), 32/2}. -Optional> computeShapeRatio(ArrayRef shape, - ArrayRef subShape); +std::optional> +computeShapeRatio(ArrayRef shape, ArrayRef subShape); /// Return the number of elements of basis (i.e. the max linear index). /// Return `0` if `basis` is empty. diff --git a/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h b/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h index b69cc1b..a6cb78b 100644 --- a/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h +++ b/mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h @@ -42,7 +42,7 @@ constexpr StringRef getReassociationAttrName() { return "reassociation"; } /// is folded into /// /// result = [[0, 1, 2], [3, 4]]. -Optional> composeReassociationIndices( +std::optional> composeReassociationIndices( ArrayRef producerReassociations, ArrayRef consumerReassociations, MLIRContext *context); @@ -67,12 +67,12 @@ SmallVector convertReassociationMapsToIndices( /// Return the reassociations maps to use to reshape given the source type and /// the target type when possible. Return std::nullopt when this computation /// failed. -Optional> +std::optional> getReassociationIndicesForReshape(ShapedType sourceType, ShapedType targetType); /// Returns the reassociation maps to collapse `sourceShape` to `targetShape` if /// possible. -Optional> +std::optional> getReassociationIndicesForCollapse(ArrayRef sourceShape, ArrayRef targetShape); @@ -186,7 +186,7 @@ struct ComposeReassociativeReshapeOps : public OpRewritePattern { hasNonIdentityLayout(reshapeOp.getResult().getType())) return failure(); - Optional> reassociationIndices = + std::optional> reassociationIndices = composeReassociationIndices(srcReshapeOp.getReassociationIndices(), reshapeOp.getReassociationIndices(), rewriter.getContext()); @@ -341,7 +341,7 @@ struct ComposeExpandOfCollapseOp : public OpRewritePattern { private: // Attempts to find a way to collapse `srcShape` to `resultShape` by // collapsing subshapes defined by the reassociation indices. - Optional> findCollapsingReassociation( + std::optional> findCollapsingReassociation( ArrayRef srcReassociation, ArrayRef resultReassociation, ArrayRef srcShape, ArrayRef resultShape) const { @@ -476,7 +476,7 @@ struct CollapseShapeRankReducingSliceSimplificationInfo { RankedTensorType sliceResultType; /// The reassociation indices for the new collapse shape op, if required. If /// `None`, the slice should replace the collapse shape op. - Optional> newReassociationIndices; + std::optional> newReassociationIndices; }; /// A collapsing reshape operation can sometimes be simplified or eliminated by diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h index b1136966..cd49eb1 100644 --- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h +++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h @@ -112,7 +112,7 @@ struct UnrollVectorOptions { } using NativeShapeFnType = - std::function>(Operation *op)>; + std::function>(Operation *op)>; /// Function that returns the shape of the vector to unroll to for a given /// operation. The unrolling is aborted if the function returns /// `std::nullopt`. @@ -125,7 +125,7 @@ struct UnrollVectorOptions { /// Set the native shape to use for unrolling. UnrollVectorOptions &setNativeShape(ArrayRef shape) { SmallVector tsShape(shape.begin(), shape.end()); - nativeShape = [=](Operation *) -> Optional> { + nativeShape = [=](Operation *) -> std::optional> { return tsShape; }; return *this; @@ -136,7 +136,7 @@ struct UnrollVectorOptions { /// be used when unrolling the given operation into units of the native vector /// size. using UnrollTraversalOrderFnType = - std::function>(Operation *op)>; + std::function>(Operation *op)>; UnrollTraversalOrderFnType traversalOrderCallback = nullptr; UnrollVectorOptions & setUnrollTraversalOrderFn(UnrollTraversalOrderFnType traversalOrderFn) { diff --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h index 48ff26c..957a4b9 100644 --- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h +++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h @@ -68,7 +68,7 @@ struct ExecutionEngineOptions { /// `jitCodeGenOptLevel`, when provided, is used as the optimization level for /// target code generation. - Optional jitCodeGenOptLevel = std::nullopt; + std::optional jitCodeGenOptLevel = std::nullopt; /// If `sharedLibPaths` are provided, the underlying JIT-compilation will /// open and link the shared libraries for symbol resolution. diff --git a/mlir/include/mlir/ExecutionEngine/MemRefUtils.h b/mlir/include/mlir/ExecutionEngine/MemRefUtils.h index 9240aae..bba002f 100644 --- a/mlir/include/mlir/ExecutionEngine/MemRefUtils.h +++ b/mlir/include/mlir/ExecutionEngine/MemRefUtils.h @@ -102,7 +102,7 @@ makeStridedMemRefDescriptor(T *ptr, T *alignedPtr, ArrayRef shape = {}, template std::pair allocAligned(size_t nElements, AllocFunType allocFun = &::malloc, - llvm::Optional alignment = llvm::Optional()) { + std::optional alignment = std::optional()) { assert(sizeof(T) <= UINT_MAX && "Elemental type overflows"); auto size = nElements * sizeof(T); auto desiredAlignment = alignment.value_or(nextPowerOf2(sizeof(T))); @@ -147,7 +147,7 @@ public: OwningMemRef( ArrayRef shape, ArrayRef shapeAlloc = {}, ElementWiseVisitor init = {}, - llvm::Optional alignment = llvm::Optional(), + std::optional alignment = std::optional(), AllocFunType allocFun = &::malloc, std::function)> freeFun = [](StridedMemRefType descriptor) { diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h index 1c0f1b2..0f4c746 100644 --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -174,7 +174,7 @@ public: /// Extracts the first result position where `input` dimension resides. /// Returns `std::nullopt` if `input` is not a dimension expression or cannot /// be found in results. - Optional getResultPosition(AffineExpr input) const; + std::optional getResultPosition(AffineExpr input) const; /// Return true if any affine expression involves AffineDimExpr `position`. bool isFunctionOfDim(unsigned position) const { diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 6c7c519..e0d33dd 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -440,7 +440,7 @@ private: /// Helper for sanity checking preconditions for create* methods below. template RegisteredOperationName getCheckRegisteredInfo(MLIRContext *ctx) { - Optional opName = + std::optional opName = RegisteredOperationName::lookup(OpT::getOperationName(), ctx); if (LLVM_UNLIKELY(!opName)) { llvm::report_fatal_error( diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h index b7deea2e..e164ef8 100644 --- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h +++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h @@ -300,7 +300,7 @@ auto ElementsAttrRange::operator[](ArrayRef index) const /// Return the elements of this attribute as a value of type 'T'. template auto ElementsAttr::value_begin() const -> DefaultValueCheckT> { - if (Optional> iterator = try_value_begin()) + if (std::optional> iterator = try_value_begin()) return std::move(*iterator); llvm::errs() << "ElementsAttr does not provide iteration facilities for type `" @@ -309,7 +309,7 @@ auto ElementsAttr::value_begin() const -> DefaultValueCheckT> { } template auto ElementsAttr::try_value_begin() const - -> DefaultValueCheckT>> { + -> DefaultValueCheckT>> { FailureOr indexer = getValuesImpl(TypeID::get()); if (failed(indexer)) diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td index 72cba52..19336e0 100644 --- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td +++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td @@ -395,18 +395,18 @@ def ElementsAttrInterface : AttrInterface<"ElementsAttr"> { /// If this attribute supports iterating over element values of type `T`, /// return the iterable range. Otherwise, return std::nullopt. template - DefaultValueCheckT>> tryGetValues() const { - if (Optional> beginIt = try_value_begin()) + DefaultValueCheckT>> tryGetValues() const { + if (std::optional> beginIt = try_value_begin()) return iterator_range(getType(), *beginIt, value_end()); return std::nullopt; } template - DefaultValueCheckT>> try_value_begin() const; + DefaultValueCheckT>> try_value_begin() const; /// If this attribute supports iterating over element values of type `T`, /// return the iterable range. Otherwise, return std::nullopt. template > - Optional> tryGetValues() const { + std::optional> tryGetValues() const { auto values = tryGetValues(); if (!values) return std::nullopt; @@ -418,7 +418,7 @@ def ElementsAttrInterface : AttrInterface<"ElementsAttr"> { ); } template > - Optional> try_value_begin() const { + std::optional> try_value_begin() const { if (auto values = tryGetValues()) return values->begin(); return std::nullopt; diff --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h index 3247da9..a23da78 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.h +++ b/mlir/include/mlir/IR/BuiltinAttributes.h @@ -786,7 +786,7 @@ public: /// Return the data of this attribute as an ArrayRef if it is present, /// returns std::nullopt otherwise. - Optional> tryGetAsArrayRef() const; + std::optional> tryGetAsArrayRef() const; /// Support for isa<>/cast<>. static bool classof(Attribute attr); diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td index 2f2d9f4..0e7b501 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.td +++ b/mlir/include/mlir/IR/BuiltinAttributes.td @@ -531,8 +531,8 @@ def Builtin_DictionaryAttr : Builtin_Attr<"Dictionary", [ Attribute get(StringAttr name) const; /// Return the specified named attribute if present, std::nullopt otherwise. - Optional getNamed(StringRef name) const; - Optional getNamed(StringAttr name) const; + std::optional getNamed(StringRef name) const; + std::optional getNamed(StringAttr name) const; /// Return whether the specified attribute is present. bool contains(StringRef name) const; @@ -560,7 +560,7 @@ def Builtin_DictionaryAttr : Builtin_Attr<"Dictionary", [ /// Returns an entry with a duplicate name in `array`, if it exists, else /// returns std::nullopt. If `isSorted` is true, the array is assumed to be /// sorted else it will be sorted in place before finding the duplicate entry. - static Optional + static std::optional findDuplicate(SmallVectorImpl &array, bool isSorted); /// Return the specified attribute if present and is an instance of diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h index 68292a8..205c5d9 100644 --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -245,7 +245,7 @@ public: /// Attaches a note to this diagnostic. A new location may be optionally /// provided, if not, then the location defaults to the one specified for this /// diagnostic. Notes may not be attached to other notes. - Diagnostic &attachNote(Optional noteLoc = std::nullopt); + Diagnostic &attachNote(std::optional noteLoc = std::nullopt); using note_iterator = llvm::pointee_iterator; using const_note_iterator = @@ -343,7 +343,7 @@ public: } /// Attaches a note to this diagnostic. - Diagnostic &attachNote(Optional noteLoc = std::nullopt) { + Diagnostic &attachNote(std::optional noteLoc = std::nullopt) { assert(isActive() && "diagnostic not active"); return impl->attachNote(noteLoc); } @@ -394,7 +394,7 @@ private: DiagnosticEngine *owner = nullptr; /// The raw diagnostic that is inflight to be reported. - Optional impl; + std::optional impl; }; //===----------------------------------------------------------------------===// @@ -596,7 +596,7 @@ private: /// Given a location, returns the first nested location (including 'loc') that /// can be shown to the user. - Optional findLocToShow(Location loc); + std::optional findLocToShow(Location loc); /// The maximum depth that a call stack will be printed. /// TODO: This should be a tunable flag. diff --git a/mlir/include/mlir/IR/DialectResourceBlobManager.h b/mlir/include/mlir/IR/DialectResourceBlobManager.h index 92f90cf..e3f32b7 100644 --- a/mlir/include/mlir/IR/DialectResourceBlobManager.h +++ b/mlir/include/mlir/IR/DialectResourceBlobManager.h @@ -53,7 +53,7 @@ public: BlobEntry &operator=(BlobEntry &&) = delete; /// Initialize this entry with the given key and blob. - void initialize(StringRef newKey, Optional newBlob) { + void initialize(StringRef newKey, std::optional newBlob) { key = newKey; blob = std::move(newBlob); } @@ -62,7 +62,7 @@ public: StringRef key; /// The blob that is referenced by this entry if it is valid. - Optional blob; + std::optional blob; /// Allow access to the constructors. friend DialectResourceBlobManager; @@ -83,12 +83,12 @@ public: /// Insert a new entry with the provided name and optional blob data. The name /// may be modified during insertion if another entry already exists with that /// name. Returns the inserted entry. - BlobEntry &insert(StringRef name, Optional blob = {}); + BlobEntry &insert(StringRef name, std::optional blob = {}); /// Insertion method that returns a dialect specific handle to the inserted /// entry. template HandleT insert(typename HandleT::Dialect *dialect, StringRef name, - Optional blob = {}) { + std::optional blob = {}) { BlobEntry &entry = insert(name, std::move(blob)); return HandleT(&entry, dialect); } @@ -154,7 +154,7 @@ public: /// data. The name may be modified during insertion if another entry already /// exists with that name. Returns a dialect specific handle to the inserted /// entry. - HandleT insert(StringRef name, Optional blob = {}) { + HandleT insert(StringRef name, std::optional blob = {}) { return getBlobManager().template insert( cast(getDialect()), name, std::move(blob)); } diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index b5c35e7..385597c 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -52,7 +52,7 @@ public: ParseResult operator*() const { return value(); } private: - Optional impl; + std::optional impl; }; // These functions are out-of-line utilities, which avoids them being template @@ -1673,8 +1673,9 @@ public: /// interfaces for the concrete operation. template static void attachInterface(MLIRContext &context) { - Optional info = RegisteredOperationName::lookup( - ConcreteType::getOperationName(), &context); + std::optional info = + RegisteredOperationName::lookup(ConcreteType::getOperationName(), + &context); if (!info) llvm::report_fatal_error( "Attempting to attach an interface to an unregistered operation " + @@ -1907,7 +1908,8 @@ protected: OperationName name = op->getName(); // Access the raw interface from the operation info. - if (Optional rInfo = name.getRegisteredInfo()) { + if (std::optional rInfo = + name.getRegisteredInfo()) { if (auto *opIface = rInfo->getInterface()) return opIface; // Fallback to the dialect to provide it with a chance to implement this diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 2cf9ed9..92f4c61 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -757,7 +757,7 @@ public: StringRef keyword; /// The result of the switch statement or none if currently unknown. - Optional result; + std::optional result; }; /// Parse a given keyword. @@ -1286,7 +1286,7 @@ public: /// which case an OpaqueLoc is set and will be resolved when parsing /// completes. virtual ParseResult - parseOptionalLocationSpecifier(Optional &result) = 0; + parseOptionalLocationSpecifier(std::optional &result) = 0; /// Return the name of the specified result in the specified syntax, as well /// as the sub-element in the name. It returns an empty string and ~0U for @@ -1340,12 +1340,13 @@ public: /// skip parsing that component. virtual ParseResult parseGenericOperationAfterOpName( OperationState &result, - Optional> parsedOperandType = std::nullopt, - Optional> parsedSuccessors = std::nullopt, - Optional>> parsedRegions = + std::optional> parsedOperandType = std::nullopt, - Optional> parsedAttributes = std::nullopt, - Optional parsedFnType = std::nullopt) = 0; + std::optional> parsedSuccessors = std::nullopt, + std::optional>> parsedRegions = + std::nullopt, + std::optional> parsedAttributes = std::nullopt, + std::optional parsedFnType = std::nullopt) = 0; /// Parse a single SSA value operand name along with a result number if /// `allowResultNumber` is true. @@ -1452,7 +1453,7 @@ public: UnresolvedOperand ssaName; // SourceLoc, SSA name, result #. Type type; // Type. DictionaryAttr attrs; // Attributes if present. - Optional sourceLoc; // Source location specifier if present. + std::optional sourceLoc; // Source location specifier if present. }; /// Parse a single argument with the following syntax: diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index ca7fed4..59d450e 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -95,7 +95,7 @@ public: /// If this operation has a registered operation description, return it. /// Otherwise return std::nullopt. - Optional getRegisteredInfo() { + std::optional getRegisteredInfo() { return getName().getRegisteredInfo(); } diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index 230df19..8ec11c1 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -172,7 +172,7 @@ public: /// If this operation is registered, returns the registered information, /// std::nullopt otherwise. - Optional getRegisteredInfo() const; + std::optional getRegisteredInfo() const; /// This hook implements a generalized folder for this operation. Operations /// can implement this to provide simplifications rules that are applied by @@ -412,8 +412,8 @@ public: /// Lookup the registered operation information for the given operation. /// Returns std::nullopt if the operation isn't registered. - static Optional lookup(StringRef name, - MLIRContext *ctx); + static std::optional lookup(StringRef name, + MLIRContext *ctx); /// Register a new operation in a Dialect object. /// This constructor is used by Dialect objects when they register the list @@ -446,10 +446,10 @@ private: friend OperationName; }; -inline Optional +inline std::optional OperationName::getRegisteredInfo() const { return isRegistered() ? RegisteredOperationName(impl) - : Optional(); + : std::optional(); } //===----------------------------------------------------------------------===// @@ -518,10 +518,10 @@ Attribute getAttrFromSortedRange(IteratorT first, IteratorT last, NameT name) { /// Get an attribute from a sorted range of named attributes. Returns /// std::nullopt if the attribute was not found. template -Optional +std::optional getNamedAttrFromSortedRange(IteratorT first, IteratorT last, NameT name) { std::pair result = findAttrSorted(first, last, name); - return result.second ? *result.first : Optional(); + return result.second ? *result.first : std::optional(); } } // namespace impl @@ -606,7 +606,7 @@ public: /// Returns an entry with a duplicate name the list, if it exists, else /// returns std::nullopt. - Optional findDuplicate() const; + std::optional findDuplicate() const; /// Return a dictionary attribute for the underlying dictionary. This will /// return an empty dictionary attribute if empty rather than null. @@ -620,8 +620,8 @@ public: Attribute get(StringRef name) const; /// Return the specified named attribute if present, std::nullopt otherwise. - Optional getNamed(StringRef name) const; - Optional getNamed(StringAttr name) const; + std::optional getNamed(StringRef name) const; + std::optional getNamed(StringAttr name) const; /// If the an attribute exists with the specified name, change it to the new /// value. Otherwise, add a new attribute with the specified name/value. @@ -844,7 +844,7 @@ public: bool shouldElideElementsAttr(ElementsAttr attr) const; /// Return the size limit for printing large ElementsAttr. - Optional getLargeElementsAttrLimit() const; + std::optional getLargeElementsAttrLimit() const; /// Return if debug information should be printed. bool shouldPrintDebugInfo() const; @@ -867,7 +867,7 @@ public: private: /// Elide large elements attributes if the number of elements is larger than /// the upper limit. - Optional elementsAttrElementLimit; + std::optional elementsAttrElementLimit; /// Print debug information. bool printDebugInfoFlag : 1; diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h index 08e249c..5c7c96f 100644 --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -99,7 +99,7 @@ public: /// Return the interface ID used to match the root operation of this pattern. /// If the pattern does not use an interface ID for deciding the root match, /// this returns std::nullopt. - Optional getRootInterfaceID() const { + std::optional getRootInterfaceID() const { if (rootKind == RootKind::InterfaceID) return TypeID::getFromOpaquePointer(rootValue); return std::nullopt; @@ -108,7 +108,7 @@ public: /// Return the trait ID used to match the root operation of this pattern. /// If the pattern does not use a trait ID for deciding the root match, this /// returns std::nullopt. - Optional getRootTraitID() const { + std::optional getRootTraitID() const { if (rootKind == RootKind::TraitID) return TypeID::getFromOpaquePointer(rootValue); return std::nullopt; @@ -655,7 +655,7 @@ public: /// value is not an instance of `T`. template ::value, T, Optional>> + std::is_convertible::value, T, std::optional>> ResultT dyn_cast() const { return isa() ? castImpl() : ResultT(); } diff --git a/mlir/include/mlir/IR/SubElementInterfaces.h b/mlir/include/mlir/IR/SubElementInterfaces.h index 85a6ba7..935d7fc 100644 --- a/mlir/include/mlir/IR/SubElementInterfaces.h +++ b/mlir/include/mlir/IR/SubElementInterfaces.h @@ -61,7 +61,7 @@ public: /// signal the element wasn't handled), or a pair of the replacement element /// and a WalkResult. template - using ReplaceFnResult = Optional>; + using ReplaceFnResult = std::optional>; template using ReplaceFn = std::function(T)>; @@ -70,13 +70,13 @@ public: /// forms(where `T` is a class derived from `Type` or `Attribute`, and `BaseT` /// is either `Type` or `Attribute` respectively): /// - /// * Optional(T) + /// * std::optional(T) /// - This either returns a valid Attribute/Type in the case of success, /// nullptr in the case of failure, or `std::nullopt` to signify that /// additional replacement functions may be applied (i.e. this function /// doesn't handle that instance). /// - /// * Optional>(T) + /// * std::optional>(T) /// - Similar to the above, but also allows specifying a WalkResult to /// control the replacement of sub elements of a given attribute or /// type. Returning a `skip` result, for example, will not recursively @@ -106,8 +106,8 @@ public: addReplacement([callback = std::forward(callback)]( BaseT base) -> ReplaceFnResult { if (auto derived = dyn_cast(base)) { - if constexpr (std::is_convertible_v>) { - Optional result = callback(derived); + if constexpr (std::is_convertible_v>) { + std::optional result = callback(derived); return result ? std::make_pair(*result, WalkResult::advance()) : ReplaceFnResult(); } else { diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h index a39e50d..8873260 100644 --- a/mlir/include/mlir/IR/ValueRange.h +++ b/mlir/include/mlir/IR/ValueRange.h @@ -129,7 +129,7 @@ public: /// Slice this range into a sub range, with the additional operand segment. MutableOperandRange slice(unsigned subStart, unsigned subLen, - Optional segment = std::nullopt) const; + std::optional segment = std::nullopt) const; /// Append the given values to the range. void append(ValueRange values); diff --git a/mlir/include/mlir/Interfaces/InferIntRangeInterface.h b/mlir/include/mlir/Interfaces/InferIntRangeInterface.h index 48a3264..7df4cc8 100644 --- a/mlir/include/mlir/Interfaces/InferIntRangeInterface.h +++ b/mlir/include/mlir/Interfaces/InferIntRangeInterface.h @@ -94,7 +94,7 @@ public: /// If either the signed or unsigned interpretations of the range /// indicate that the value it bounds is a constant, return that constant /// value. - Optional getConstantValue() const; + std::optional getConstantValue() const; friend raw_ostream &operator<<(raw_ostream &os, const ConstantIntRanges &range); diff --git a/mlir/include/mlir/Pass/AnalysisManager.h b/mlir/include/mlir/Pass/AnalysisManager.h index fb8375a..9821a68 100644 --- a/mlir/include/mlir/Pass/AnalysisManager.h +++ b/mlir/include/mlir/Pass/AnalysisManager.h @@ -169,7 +169,7 @@ public: /// Get a cached analysis instance if one exists, otherwise return null. template - Optional> getCachedAnalysis() const { + std::optional> getCachedAnalysis() const { auto res = analyses.find(TypeID::get()); if (res == analyses.end()) return std::nullopt; @@ -302,7 +302,7 @@ public: /// Query for a cached analysis on the given parent operation. The analysis /// may not exist and if it does it may be out-of-date. template - Optional> + std::optional> getCachedParentAnalysis(Operation *parentOp) const { const detail::NestedAnalysisMap *curParent = impl; while (auto *parentAM = curParent->getParent()) { @@ -329,7 +329,7 @@ public: /// Query for a cached entry of the given analysis on the current operation. template - Optional> getCachedAnalysis() const { + std::optional> getCachedAnalysis() const { return impl->analyses.getCachedAnalysis(); } @@ -348,7 +348,7 @@ public: /// Query for a cached analysis of a child operation, or return null. template - Optional> + std::optional> getCachedChildAnalysis(Operation *op) const { assert(op->getParentOp() == impl->getOperation()); auto it = impl->childAnalyses.find(op); diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index 3eace7d..714667c 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -83,7 +83,7 @@ public: /// Returns the name of the operation that this pass operates on, or /// std::nullopt if this is a generic OperationPass. - Optional getOpName() const { return opName; } + std::optional getOpName() const { return opName; } //===--------------------------------------------------------------------===// // Options @@ -160,7 +160,7 @@ public: } protected: - explicit Pass(TypeID passID, Optional opName = std::nullopt) + explicit Pass(TypeID passID, std::optional opName = std::nullopt) : passID(passID), opName(opName) {} Pass(const Pass &other) : Pass(other.passID, other.opName) {} @@ -228,7 +228,7 @@ protected: /// Query a cached instance of an analysis for the current ir unit if one /// exists. template - Optional> getCachedAnalysis() { + std::optional> getCachedAnalysis() { return getAnalysisManager().getCachedAnalysis(); } @@ -248,21 +248,21 @@ protected: /// Returns the analysis for the given parent operation if it exists. template - Optional> + std::optional> getCachedParentAnalysis(Operation *parent) { return getAnalysisManager().getCachedParentAnalysis(parent); } /// Returns the analysis for the parent operation if it exists. template - Optional> getCachedParentAnalysis() { + std::optional> getCachedParentAnalysis() { return getAnalysisManager().getCachedParentAnalysis( getOperation()->getParentOp()); } /// Returns the analysis for the given child operation if it exists. template - Optional> + std::optional> getCachedChildAnalysis(Operation *child) { return getAnalysisManager().getCachedChildAnalysis(child); } @@ -303,10 +303,10 @@ private: /// The name of the operation that this pass operates on, or std::nullopt if /// this is a generic OperationPass. - Optional opName; + std::optional opName; /// The current execution state for the pass. - Optional passState; + std::optional passState; /// The set of statistics held by this pass. std::vector statistics; diff --git a/mlir/include/mlir/Pass/PassInstrumentation.h b/mlir/include/mlir/Pass/PassInstrumentation.h index 8db982e..917bac4 100644 --- a/mlir/include/mlir/Pass/PassInstrumentation.h +++ b/mlir/include/mlir/Pass/PassInstrumentation.h @@ -45,14 +45,14 @@ public: /// the name of the operation type being operated on, or std::nullopt if the /// pipeline is op-agnostic, and information related to the parent that /// spawned this pipeline. - virtual void runBeforePipeline(Optional name, + virtual void runBeforePipeline(std::optional name, const PipelineParentInfo &parentInfo); /// A callback to run after a pass pipeline has executed. This function takes /// the name of the operation type being operated on, or std::nullopt if the /// pipeline is op-agnostic, and information related to the parent that /// spawned this pipeline. - virtual void runAfterPipeline(Optional name, + virtual void runAfterPipeline(std::optional name, const PipelineParentInfo &parentInfo); /// A callback to run before a pass is executed. This function takes a pointer @@ -93,12 +93,12 @@ public: /// See PassInstrumentation::runBeforePipeline for details. void - runBeforePipeline(Optional name, + runBeforePipeline(std::optional name, const PassInstrumentation::PipelineParentInfo &parentInfo); /// See PassInstrumentation::runAfterPipeline for details. void - runAfterPipeline(Optional name, + runAfterPipeline(std::optional name, const PassInstrumentation::PipelineParentInfo &parentInfo); /// See PassInstrumentation::runBeforePass for details. diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h index 877b867..62dc532 100644 --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -128,11 +128,11 @@ public: /// Return the operation name that this pass manager operates on, or /// std::nullopt if this is an op-agnostic pass manager. - Optional getOpName(MLIRContext &context) const; + std::optional getOpName(MLIRContext &context) const; /// Return the operation name that this pass manager operates on, or /// std::nullopt if this is an op-agnostic pass manager. - Optional getOpName() const; + std::optional getOpName() const; /// Return the name used to anchor this pass manager. This is either the name /// of an operation, or the result of `getAnyOpAnchorName()` in the case of an @@ -429,7 +429,7 @@ private: MLIRContext *context; /// Flag that specifies if pass statistics should be dumped. - Optional passStatisticsMode; + std::optional passStatisticsMode; /// A manager for pass instrumentations. std::unique_ptr instrumentor; diff --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h index c454152..db6d9dc 100644 --- a/mlir/include/mlir/Pass/PassRegistry.h +++ b/mlir/include/mlir/Pass/PassRegistry.h @@ -260,7 +260,7 @@ private: std::unique_ptr impl; llvm::cl::opt passPipeline; - Optional passPipelineAlias; + std::optional passPipelineAlias; }; /// This class implements a command-line parser specifically for MLIR pass @@ -296,9 +296,9 @@ struct PassReproducerOptions { LogicalResult apply(PassManager &pm) const; private: - Optional pipeline; - Optional verifyEach; - Optional disableThreading; + std::optional pipeline; + std::optional verifyEach; + std::optional disableThreading; }; } // namespace mlir diff --git a/mlir/include/mlir/Support/LogicalResult.h b/mlir/include/mlir/Support/LogicalResult.h index fa7bd6e..ebb1464 100644 --- a/mlir/include/mlir/Support/LogicalResult.h +++ b/mlir/include/mlir/Support/LogicalResult.h @@ -76,7 +76,7 @@ inline bool failed(LogicalResult result) { return result.failed(); } /// value of type `T`. This allows for integrating with LogicalResult, while /// also providing a value on the success path. template -class [[nodiscard]] FailureOr : public Optional { +class [[nodiscard]] FailureOr : public std::optional { public: /// Allow constructing from a LogicalResult. The result *must* be a failure. /// Success results should use a proper instance of type `T`. @@ -85,19 +85,20 @@ public: "success should be constructed with an instance of 'T'"); } FailureOr() : FailureOr(failure()) {} - FailureOr(T &&y) : Optional(std::forward(y)) {} - FailureOr(const T &y) : Optional(y) {} + FailureOr(T &&y) : std::optional(std::forward(y)) {} + FailureOr(const T &y) : std::optional(y) {} template ::value> * = nullptr> FailureOr(const FailureOr &other) - : Optional(failed(other) ? Optional() : Optional(*other)) {} + : std::optional(failed(other) ? std::optional() + : std::optional(*other)) {} operator LogicalResult() const { return success(this->has_value()); } private: /// Hide the bool conversion as it easily creates confusion. - using Optional::operator bool; - using Optional::has_value; + using std::optional::operator bool; + using std::optional::has_value; }; /// Wrap a value on the success path in a FailureOr of the same value type. diff --git a/mlir/include/mlir/Support/Timing.h b/mlir/include/mlir/Support/Timing.h index 3c7335c..bc3a642 100644 --- a/mlir/include/mlir/Support/Timing.h +++ b/mlir/include/mlir/Support/Timing.h @@ -141,7 +141,7 @@ protected: /// collection of timing samples is disabled. This will cause the timers /// constructed from the manager to be tombstones which can be skipped /// quickly. - virtual Optional rootTimer() = 0; + virtual std::optional rootTimer() = 0; /// Start the timer with the given handle. virtual void startTimer(void *handle) = 0; @@ -399,7 +399,7 @@ public: protected: // `TimingManager` callbacks - Optional rootTimer() override; + std::optional rootTimer() override; void startTimer(void *handle) override; void stopTimer(void *handle) override; void *nestTimer(void *handle, const void *id, diff --git a/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h b/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h index 896767a..a8bae32 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h @@ -45,7 +45,7 @@ public: /// Attach a note to this diagnostic. Diagnostic &attachNote(const Twine &msg, - Optional noteLoc = std::nullopt) { + std::optional noteLoc = std::nullopt) { assert(getSeverity() != Severity::DK_Note && "cannot attach a Note to a Note"); notes.emplace_back( @@ -129,7 +129,7 @@ private: DiagnosticEngine *owner = nullptr; /// The raw diagnostic that is inflight to be reported. - Optional impl; + std::optional impl; }; //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Tools/PDLL/AST/Nodes.h b/mlir/include/mlir/Tools/PDLL/AST/Nodes.h index 51092d5..8a07cf9 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Nodes.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Nodes.h @@ -510,7 +510,7 @@ public: ArrayRef attributes); /// Return the name of the operation, or std::nullopt if there isn't one. - Optional getName() const; + std::optional getName() const; /// Return the declaration of the operation name. const OpNameDecl *getNameDecl() const { return nameDecl; } @@ -670,7 +670,7 @@ public: /// Return the documentation comment attached to this decl if it has been set. /// Otherwise, returns std::nullopt. - Optional getDocComment() const { return docComment; } + std::optional getDocComment() const { return docComment; } protected: Decl(TypeID typeID, SMRange loc, const Name *name = nullptr) @@ -683,7 +683,7 @@ private: /// The documentation comment attached to this decl. Defaults to None if /// the comment is unset/unknown. - Optional docComment; + std::optional docComment; }; //===----------------------------------------------------------------------===// @@ -766,7 +766,7 @@ public: const OpNameDecl *nameDecl = nullptr); /// Return the name of the operation, or std::nullopt if there isn't one. - Optional getName() const; + std::optional getName() const; /// Return the declaration of the operation name. const OpNameDecl *getNameDecl() const { return nameDecl; } @@ -875,8 +875,9 @@ public: /// Create a native constraint with the given optional code block. static UserConstraintDecl * createNative(Context &ctx, const Name &name, ArrayRef inputs, - ArrayRef results, Optional codeBlock, - Type resultType, ArrayRef nativeInputTypes = {}) { + ArrayRef results, + std::optional codeBlock, Type resultType, + ArrayRef nativeInputTypes = {}) { return createImpl(ctx, name, inputs, nativeInputTypes, results, codeBlock, /*body=*/nullptr, resultType); } @@ -904,7 +905,7 @@ public: /// Return the explicit native type to use for the given input. Returns /// std::nullopt if no explicit type was set. - Optional getNativeInputType(unsigned index) const; + std::optional getNativeInputType(unsigned index) const; /// Return the explicit results of the constraint declaration. May be empty, /// even if the constraint has results (e.g. in the case of inferred results). @@ -917,7 +918,7 @@ public: /// Return the optional code block of this constraint, if this is a native /// constraint with a provided implementation. - Optional getCodeBlock() const { return codeBlock; } + std::optional getCodeBlock() const { return codeBlock; } /// Return the body of this constraint if this constraint is a PDLL /// constraint, otherwise returns nullptr. @@ -932,16 +933,18 @@ public: private: /// Create either a PDLL constraint or a native constraint with the given /// components. - static UserConstraintDecl * - createImpl(Context &ctx, const Name &name, ArrayRef inputs, - ArrayRef nativeInputTypes, - ArrayRef results, Optional codeBlock, - const CompoundStmt *body, Type resultType); + static UserConstraintDecl *createImpl(Context &ctx, const Name &name, + ArrayRef inputs, + ArrayRef nativeInputTypes, + ArrayRef results, + std::optional codeBlock, + const CompoundStmt *body, + Type resultType); UserConstraintDecl(const Name &name, unsigned numInputs, bool hasNativeInputTypes, unsigned numResults, - Optional codeBlock, const CompoundStmt *body, - Type resultType) + std::optional codeBlock, + const CompoundStmt *body, Type resultType) : Base(name.getLoc(), &name), numInputs(numInputs), numResults(numResults), codeBlock(codeBlock), constraintBody(body), resultType(resultType), hasNativeInputTypes(hasNativeInputTypes) {} @@ -953,7 +956,7 @@ private: unsigned numResults; /// The optional code block of this constraint. - Optional codeBlock; + std::optional codeBlock; /// The optional body of this constraint. const CompoundStmt *constraintBody; @@ -1007,9 +1010,9 @@ public: static OpNameDecl *create(Context &ctx, SMRange loc); /// Return the name of this operation, or none if the name is unknown. - Optional getName() const { + std::optional getName() const { const Name *name = Decl::getName(); - return name ? Optional(name->getName()) : std::nullopt; + return name ? std::optional(name->getName()) : std::nullopt; } private: @@ -1025,12 +1028,12 @@ private: class PatternDecl : public Node::NodeBase { public: static PatternDecl *create(Context &ctx, SMRange location, const Name *name, - Optional benefit, + std::optional benefit, bool hasBoundedRecursion, const CompoundStmt *body); /// Return the benefit of this pattern if specified, or std::nullopt. - Optional getBenefit() const { return benefit; } + std::optional getBenefit() const { return benefit; } /// Return if this pattern has bounded rewrite recursion. bool hasBoundedRewriteRecursion() const { return hasBoundedRecursion; } @@ -1044,13 +1047,13 @@ public: } private: - PatternDecl(SMRange loc, const Name *name, Optional benefit, + PatternDecl(SMRange loc, const Name *name, std::optional benefit, bool hasBoundedRecursion, const CompoundStmt *body) : Base(loc, name), benefit(benefit), hasBoundedRecursion(hasBoundedRecursion), patternBody(body) {} /// The benefit of the pattern if it was explicitly specified, None otherwise. - Optional benefit; + std::optional benefit; /// If the pattern has properly bounded rewrite recursion or not. bool hasBoundedRecursion; @@ -1082,7 +1085,7 @@ public: static UserRewriteDecl *createNative(Context &ctx, const Name &name, ArrayRef inputs, ArrayRef results, - Optional codeBlock, + std::optional codeBlock, Type resultType) { return createImpl(ctx, name, inputs, results, codeBlock, /*body=*/nullptr, resultType); @@ -1120,7 +1123,7 @@ public: /// Return the optional code block of this rewrite, if this is a native /// rewrite with a provided implementation. - Optional getCodeBlock() const { return codeBlock; } + std::optional getCodeBlock() const { return codeBlock; } /// Return the body of this rewrite if this rewrite is a PDLL rewrite, /// otherwise returns nullptr. @@ -1138,11 +1141,11 @@ private: static UserRewriteDecl *createImpl(Context &ctx, const Name &name, ArrayRef inputs, ArrayRef results, - Optional codeBlock, + std::optional codeBlock, const CompoundStmt *body, Type resultType); UserRewriteDecl(const Name &name, unsigned numInputs, unsigned numResults, - Optional codeBlock, const CompoundStmt *body, + std::optional codeBlock, const CompoundStmt *body, Type resultType) : Base(name.getLoc(), &name), numInputs(numInputs), numResults(numResults), codeBlock(codeBlock), rewriteBody(body), @@ -1155,7 +1158,7 @@ private: unsigned numResults; /// The optional code block of this rewrite. - Optional codeBlock; + std::optional codeBlock; /// The optional body of this rewrite. const CompoundStmt *rewriteBody; @@ -1207,7 +1210,7 @@ public: /// Return the optional code block of this callable, if this is a native /// callable with a provided implementation. - Optional getCodeBlock() const { + std::optional getCodeBlock() const { if (const auto *cst = dyn_cast(this)) return cst->getCodeBlock(); return cast(this)->getCodeBlock(); diff --git a/mlir/include/mlir/Tools/PDLL/AST/Types.h b/mlir/include/mlir/Tools/PDLL/AST/Types.h index e9f5259..03252e9 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Types.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Types.h @@ -162,12 +162,12 @@ public: /// Return an instance of the Operation type with an optional operation name. /// If no name is provided, this type may refer to any operation. static OperationType get(Context &context, - Optional name = std::nullopt, + std::optional name = std::nullopt, const ods::Operation *odsOp = nullptr); /// Return the name of this operation type, or std::nullopt if it doesn't have /// on. - Optional getName() const; + std::optional getName() const; /// Return the ODS operation that this type refers to, or nullptr if the ODS /// operation is unknown. diff --git a/mlir/include/mlir/Tools/PDLL/Parser/CodeComplete.h b/mlir/include/mlir/Tools/PDLL/Parser/CodeComplete.h index 237aed1..3c6d941 100644 --- a/mlir/include/mlir/Tools/PDLL/Parser/CodeComplete.h +++ b/mlir/include/mlir/Tools/PDLL/Parser/CodeComplete.h @@ -77,12 +77,12 @@ public: /// Signal code completion for the signature of an operation's operands. virtual void - codeCompleteOperationOperandsSignature(Optional opName, + codeCompleteOperationOperandsSignature(std::optional opName, unsigned currentNumOperands) {} /// Signal code completion for the signature of an operation's results. virtual void - codeCompleteOperationResultsSignature(Optional opName, + codeCompleteOperationResultsSignature(std::optional opName, unsigned currentNumResults) {} protected: diff --git a/mlir/include/mlir/Tools/mlir-translate/Translation.h b/mlir/include/mlir/Tools/mlir-translate/Translation.h index d80d538..88c94a1 100644 --- a/mlir/include/mlir/Tools/mlir-translate/Translation.h +++ b/mlir/include/mlir/Tools/mlir-translate/Translation.h @@ -62,7 +62,7 @@ class Translation { public: Translation() = default; Translation(TranslateFunction function, StringRef description, - Optional inputAlignment) + std::optional inputAlignment) : function(std::move(function)), description(description), inputAlignment(inputAlignment) {} @@ -70,7 +70,9 @@ public: StringRef getDescription() const { return description; } /// Return the optional alignment desired for the input of the translation. - Optional getInputAlignment() const { return inputAlignment; } + std::optional getInputAlignment() const { + return inputAlignment; + } /// Invoke the translation function with the given input and output streams. LogicalResult operator()(const std::shared_ptr &sourceMgr, @@ -87,7 +89,7 @@ private: StringRef description; /// An optional alignment desired for the input of the translation. - Optional inputAlignment; + std::optional inputAlignment; }; /// Use Translate[ToMLIR|FromMLIR]Registration as an initializer that @@ -111,19 +113,19 @@ struct TranslateToMLIRRegistration { const TranslateSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration = [](DialectRegistry &) {}, - Optional inputAlignment = std::nullopt); + std::optional inputAlignment = std::nullopt); TranslateToMLIRRegistration( llvm::StringRef name, llvm::StringRef description, const TranslateRawSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration = [](DialectRegistry &) {}, - Optional inputAlignment = std::nullopt); + std::optional inputAlignment = std::nullopt); TranslateToMLIRRegistration( llvm::StringRef name, llvm::StringRef description, const TranslateStringRefToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration = [](DialectRegistry &) {}, - Optional inputAlignment = std::nullopt); + std::optional inputAlignment = std::nullopt); }; struct TranslateFromMLIRRegistration { diff --git a/mlir/include/mlir/Transforms/InliningUtils.h b/mlir/include/mlir/Transforms/InliningUtils.h index c388f14a..241983e 100644 --- a/mlir/include/mlir/Transforms/InliningUtils.h +++ b/mlir/include/mlir/Transforms/InliningUtils.h @@ -209,13 +209,13 @@ LogicalResult inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc = std::nullopt, + std::optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); LogicalResult inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock, Block::iterator inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc = std::nullopt, + std::optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); /// This function is an overload of the above 'inlineRegion' that allows for @@ -224,13 +224,13 @@ LogicalResult inlineRegion(InlinerInterface &interface, Region *src, LogicalResult inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, ValueRange inlinedOperands, ValueRange resultsToReplace, - Optional inlineLoc = std::nullopt, + std::optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); LogicalResult inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock, Block::iterator inlinePoint, ValueRange inlinedOperands, ValueRange resultsToReplace, - Optional inlineLoc = std::nullopt, + std::optional inlineLoc = std::nullopt, bool shouldCloneInlinedRegion = true); /// This function inlines a given region, 'src', of a callable operation, diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp index 6ccc6b8..2415ff4 100644 --- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp @@ -311,7 +311,7 @@ void DeadCodeAnalysis::visitCallOperation(CallOpInterface call) { /// Get the constant values of the operands of an operation. If any of the /// constant value lattices are uninitialized, return none to indicate the /// analysis should bail out. -static Optional> getOperandValuesImpl( +static std::optional> getOperandValuesImpl( Operation *op, function_ref *(Value)> getLattice) { SmallVector operands; @@ -326,7 +326,7 @@ static Optional> getOperandValuesImpl( return operands; } -Optional> +std::optional> DeadCodeAnalysis::getOperandValues(Operation *op) { return getOperandValuesImpl(op, [&](Value value) { auto *lattice = getOrCreate>(value); @@ -337,7 +337,7 @@ DeadCodeAnalysis::getOperandValues(Operation *op) { void DeadCodeAnalysis::visitBranchOperation(BranchOpInterface branch) { // Try to deduce a single successor for the branch. - Optional> operands = getOperandValues(branch); + std::optional> operands = getOperandValues(branch); if (!operands) return; @@ -353,7 +353,7 @@ void DeadCodeAnalysis::visitBranchOperation(BranchOpInterface branch) { void DeadCodeAnalysis::visitRegionBranchOperation( RegionBranchOpInterface branch) { // Try to deduce which regions are executable. - Optional> operands = getOperandValues(branch); + std::optional> operands = getOperandValues(branch); if (!operands) return; @@ -377,7 +377,7 @@ void DeadCodeAnalysis::visitRegionBranchOperation( void DeadCodeAnalysis::visitRegionTerminator(Operation *op, RegionBranchOpInterface branch) { - Optional> operands = getOperandValues(op); + std::optional> operands = getOperandValues(op); if (!operands) return; diff --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp index 95a8c61..2823f27 100644 --- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp @@ -40,7 +40,7 @@ void IntegerValueRangeLattice::onUpdate(DataFlowSolver *solver) const { // If the integer range can be narrowed to a constant, update the constant // value of the SSA value. - Optional constant = getValue().getValue().getConstantValue(); + std::optional constant = getValue().getValue().getConstantValue(); auto value = point.get(); auto *cv = solver->getOrCreateState>(value); if (!constant) diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp index 7423744..f421d05 100644 --- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp @@ -764,7 +764,8 @@ bool IntegerRelation::isIntegerEmpty() const { return !findIntegerSample(); } /// /// Concatenating the samples from B and C gives a sample v in S*T, so the /// returned sample T*v is a sample in S. -Optional> IntegerRelation::findIntegerSample() const { +std::optional> +IntegerRelation::findIntegerSample() const { // First, try the GCD test heuristic. if (isEmptyByGCDTest()) return {}; @@ -803,7 +804,7 @@ Optional> IntegerRelation::findIntegerSample() const { boundedSet.removeVarRange(numBoundedDims, boundedSet.getNumVars()); // 3) Try to obtain a sample from the bounded set. - Optional> boundedSample = + std::optional> boundedSample = Simplex(boundedSet).findIntegerSample(); if (!boundedSample) return {}; @@ -902,7 +903,7 @@ bool IntegerRelation::containsPoint(ArrayRef point) const { /// compute the values of the locals that have division representations and /// only use the integer emptiness check for the locals that don't have this. /// Handling this correctly requires ordering the divs, though. -Optional> +std::optional> IntegerRelation::containsPointNoLocal(ArrayRef point) const { assert(point.size() == getNumVars() - getNumLocalVars() && "Point should contain all vars except locals!"); @@ -1081,7 +1082,7 @@ void IntegerRelation::removeRedundantConstraints() { equalities.resizeVertically(pos); } -Optional IntegerRelation::computeVolume() const { +std::optional IntegerRelation::computeVolume() const { assert(getNumSymbolVars() == 0 && "Symbols are not yet supported!"); Simplex simplex(*this); @@ -1391,7 +1392,7 @@ void IntegerRelation::constantFoldVarRange(unsigned pos, unsigned num) { // s0 + s1 + 16 <= d0 <= s0 + s1 + 31, returns 16. // s0 - 7 <= 8*j <= s0 returns 1 with lb = s0, lbDivisor = 8 (since lb = // ceil(s0 - 7 / 8) = floor(s0 / 8)). -Optional IntegerRelation::getConstantBoundOnDimSize( +std::optional IntegerRelation::getConstantBoundOnDimSize( unsigned pos, SmallVectorImpl *lb, MPInt *boundFloorDivisor, SmallVectorImpl *ub, unsigned *minLbPos, unsigned *minUbPos) const { assert(pos < getNumDimVars() && "Invalid variable position"); @@ -1456,7 +1457,7 @@ Optional IntegerRelation::getConstantBoundOnDimSize( /*eqIndices=*/nullptr, /*offset=*/0, /*num=*/getNumDimVars()); - Optional minDiff; + std::optional minDiff; unsigned minLbPosition = 0, minUbPosition = 0; for (auto ubPos : ubIndices) { for (auto lbPos : lbIndices) { @@ -1517,7 +1518,7 @@ Optional IntegerRelation::getConstantBoundOnDimSize( } template -Optional +std::optional IntegerRelation::computeConstantLowerOrUpperBound(unsigned pos) { assert(pos < getNumVars() && "invalid position"); // Project to 'pos'. @@ -1539,7 +1540,7 @@ IntegerRelation::computeConstantLowerOrUpperBound(unsigned pos) { // If it doesn't, there isn't a bound on it. return std::nullopt; - Optional minOrMaxConst; + std::optional minOrMaxConst; // Take the max across all const lower bounds (or min across all constant // upper bounds). @@ -1574,8 +1575,8 @@ IntegerRelation::computeConstantLowerOrUpperBound(unsigned pos) { return minOrMaxConst; } -Optional IntegerRelation::getConstantBound(BoundType type, - unsigned pos) const { +std::optional IntegerRelation::getConstantBound(BoundType type, + unsigned pos) const { if (type == BoundType::LB) return IntegerRelation(*this) .computeConstantLowerOrUpperBound(pos); @@ -1584,13 +1585,13 @@ Optional IntegerRelation::getConstantBound(BoundType type, .computeConstantLowerOrUpperBound(pos); assert(type == BoundType::EQ && "expected EQ"); - Optional lb = + std::optional lb = IntegerRelation(*this).computeConstantLowerOrUpperBound( pos); - Optional ub = + std::optional ub = IntegerRelation(*this) .computeConstantLowerOrUpperBound(pos); - return (lb && ub && *lb == *ub) ? Optional(*ub) : std::nullopt; + return (lb && ub && *lb == *ub) ? std::optional(*ub) : std::nullopt; } // A simple (naive and conservative) check for hyper-rectangularity. diff --git a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp index 413d9a0..c31d50a 100644 --- a/mlir/lib/Analysis/Presburger/PWMAFunction.cpp +++ b/mlir/lib/Analysis/Presburger/PWMAFunction.cpp @@ -63,11 +63,11 @@ MultiAffineFunction::valueAt(ArrayRef point) const { SmallVector pointHomogenous{llvm::to_vector(point)}; // Get the division values at this point. - SmallVector, 8> divValues = divs.divValuesAt(point); + SmallVector, 8> divValues = divs.divValuesAt(point); // The given point didn't include the values of the divs which the output is a // function of; we have computed one possible set of values and use them here. pointHomogenous.reserve(pointHomogenous.size() + divValues.size()); - for (const Optional &divVal : divValues) + for (const std::optional &divVal : divValues) pointHomogenous.push_back(*divVal); // The matrix `output` has an affine expression in the ith row, corresponding // to the expression for the ith value in the output vector. The last column @@ -424,7 +424,7 @@ void PWMAFunction::removeOutputs(unsigned start, unsigned end) { piece.output.removeOutputs(start, end); } -Optional> +std::optional> PWMAFunction::valueAt(ArrayRef point) const { assert(point.size() == getNumDomainVars() + getNumSymbolVars()); diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp index 37fdf38..9c95670 100644 --- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp @@ -463,7 +463,8 @@ bool PresburgerRelation::isIntegerEmpty() const { bool PresburgerRelation::findIntegerSample(SmallVectorImpl &sample) { // A sample exists iff any of the disjuncts contains a sample. for (const IntegerRelation &disjunct : disjuncts) { - if (Optional> opt = disjunct.findIntegerSample()) { + if (std::optional> opt = + disjunct.findIntegerSample()) { sample = std::move(*opt); return true; } @@ -471,13 +472,13 @@ bool PresburgerRelation::findIntegerSample(SmallVectorImpl &sample) { return false; } -Optional PresburgerRelation::computeVolume() const { +std::optional PresburgerRelation::computeVolume() const { assert(getNumSymbolVars() == 0 && "Symbols are not yet supported!"); // The sum of the volumes of the disjuncts is a valid overapproximation of the // volume of their union, even if they overlap. MPInt result(0); for (const IntegerRelation &disjunct : disjuncts) { - Optional volume = disjunct.computeVolume(); + std::optional volume = disjunct.computeVolume(); if (!volume) return {}; result += *volume; diff --git a/mlir/lib/Analysis/Presburger/Simplex.cpp b/mlir/lib/Analysis/Presburger/Simplex.cpp index 0bcc8ee..228f041 100644 --- a/mlir/lib/Analysis/Presburger/Simplex.cpp +++ b/mlir/lib/Analysis/Presburger/Simplex.cpp @@ -272,7 +272,7 @@ LogicalResult LexSimplexBase::addCut(unsigned row) { return moveRowUnknownToColumn(cutRow); } -Optional LexSimplex::maybeGetNonIntegralVarRow() const { +std::optional LexSimplex::maybeGetNonIntegralVarRow() const { for (const Unknown &u : var) { if (u.orientation == Orientation::Column) continue; @@ -292,7 +292,7 @@ MaybeOptimum> LexSimplex::findIntegerLexMin() { return OptimumKind::Empty; // Then, if the sample value is integral, we are done. - while (Optional maybeRow = maybeGetNonIntegralVarRow()) { + while (std::optional maybeRow = maybeGetNonIntegralVarRow()) { // Otherwise, for the variable whose row has a non-integral sample value, // we add a cut, a constraint that remove this rational point // while preserving all integer points, thus keeping the lexmin the same. @@ -478,7 +478,7 @@ void SymbolicLexSimplex::recordOutput(SymbolicLexMin &result) const { MultiAffineFunction(funcSpace, output, domainPoly.getLocalReprs())}); } -Optional SymbolicLexSimplex::maybeGetAlwaysViolatedRow() { +std::optional SymbolicLexSimplex::maybeGetAlwaysViolatedRow() { // First look for rows that are clearly violated just from the big M // coefficient, without needing to perform any simplex queries on the domain. for (unsigned row = 0, e = getNumRows(); row < e; ++row) @@ -496,7 +496,7 @@ Optional SymbolicLexSimplex::maybeGetAlwaysViolatedRow() { return {}; } -Optional SymbolicLexSimplex::maybeGetNonIntegralVarRow() { +std::optional SymbolicLexSimplex::maybeGetNonIntegralVarRow() { for (const Unknown &u : var) { if (u.orientation == Orientation::Column) continue; @@ -510,7 +510,7 @@ Optional SymbolicLexSimplex::maybeGetNonIntegralVarRow() { /// The non-branching pivots are just the ones moving the rows /// that are always violated in the symbol domain. LogicalResult SymbolicLexSimplex::doNonBranchingPivots() { - while (Optional row = maybeGetAlwaysViolatedRow()) + while (std::optional row = maybeGetAlwaysViolatedRow()) if (moveRowUnknownToColumn(*row).failed()) return failure(); return success(); @@ -612,7 +612,7 @@ SymbolicLexMin SymbolicLexSimplex::computeSymbolicIntegerLexMin() { // The tableau is rationally consistent for the current domain. // Now we look for non-integral sample values and add cuts for them. - if (Optional row = maybeGetNonIntegralVarRow()) { + if (std::optional row = maybeGetNonIntegralVarRow()) { if (addSymbolicCut(*row).failed()) { // No integral points; return. --level; @@ -675,7 +675,7 @@ bool LexSimplex::rowIsViolated(unsigned row) const { return false; } -Optional LexSimplex::maybeGetViolatedRow() const { +std::optional LexSimplex::maybeGetViolatedRow() const { for (unsigned row = 0, e = getNumRows(); row < e; ++row) if (rowIsViolated(row)) return row; @@ -688,7 +688,7 @@ Optional LexSimplex::maybeGetViolatedRow() const { LogicalResult LexSimplex::restoreRationalConsistency() { if (empty) return failure(); - while (Optional maybeViolatedRow = maybeGetViolatedRow()) + while (std::optional maybeViolatedRow = maybeGetViolatedRow()) if (moveRowUnknownToColumn(*maybeViolatedRow).failed()) return failure(); return success(); @@ -865,8 +865,8 @@ unsigned LexSimplexBase::getLexMinPivotColumn(unsigned row, unsigned colA, /// /// If multiple columns are valid, we break ties by considering a lexicographic /// ordering where we prefer unknowns with lower index. -Optional Simplex::findPivot(int row, - Direction direction) const { +std::optional +Simplex::findPivot(int row, Direction direction) const { std::optional col; for (unsigned j = 2, e = getNumColumns(); j < e; ++j) { MPInt elem = tableau(row, j); @@ -885,7 +885,7 @@ Optional Simplex::findPivot(int row, Direction newDirection = tableau(row, *col) < 0 ? flippedDirection(direction) : direction; - Optional maybePivotRow = findPivotRow(row, newDirection, *col); + std::optional maybePivotRow = findPivotRow(row, newDirection, *col); return Pivot{maybePivotRow.value_or(row), *col}; } @@ -977,7 +977,7 @@ LogicalResult Simplex::restoreRow(Unknown &u) { "unknown should be in row position"); while (tableau(u.pos, 1) < 0) { - Optional maybePivot = findPivot(u.pos, Direction::Up); + std::optional maybePivot = findPivot(u.pos, Direction::Up); if (!maybePivot) break; @@ -1010,10 +1010,10 @@ LogicalResult Simplex::restoreRow(Unknown &u) { /// 0 and hence saturates the bound it imposes. We break ties between rows that /// impose the same bound by considering a lexicographic ordering where we /// prefer unknowns with lower index value. -Optional Simplex::findPivotRow(Optional skipRow, - Direction direction, - unsigned col) const { - Optional retRow; +std::optional Simplex::findPivotRow(std::optional skipRow, + Direction direction, + unsigned col) const { + std::optional retRow; // Initialize these to zero in order to silence a warning about retElem and // retConst being used uninitialized in the initialization of `diff` below. In // reality, these are always initialized when that line is reached since these @@ -1152,7 +1152,7 @@ void SimplexBase::removeLastConstraintRowOrientation() { // // If we have a variable, then the column has zero coefficients for every row // iff no constraints have been added with a non-zero coefficient for this row. -Optional SimplexBase::findAnyPivotRow(unsigned col) { +std::optional SimplexBase::findAnyPivotRow(unsigned col) { for (unsigned row = nRedundant, e = getNumRows(); row < e; ++row) if (tableau(row, col) != 0) return row; @@ -1173,13 +1173,14 @@ void Simplex::undoLastConstraint() { // coefficient for the column. findAnyPivotRow will always be able to // find such a row for a constraint. unsigned column = con.back().pos; - if (Optional maybeRow = findPivotRow({}, Direction::Up, column)) { + if (std::optional maybeRow = + findPivotRow({}, Direction::Up, column)) { pivot(*maybeRow, column); - } else if (Optional maybeRow = + } else if (std::optional maybeRow = findPivotRow({}, Direction::Down, column)) { pivot(*maybeRow, column); } else { - Optional row = findAnyPivotRow(column); + std::optional row = findAnyPivotRow(column); assert(row && "Pivot should always exist for a constraint!"); pivot(*row, column); } @@ -1198,7 +1199,7 @@ void LexSimplexBase::undoLastConstraint() { // snapshot, so what pivots we perform while undoing doesn't matter as // long as we get the unknown to row orientation and remove it. unsigned column = con.back().pos; - Optional row = findAnyPivotRow(column); + std::optional row = findAnyPivotRow(column); assert(row && "Pivot should always exist for a constraint!"); pivot(*row, column); } @@ -1324,7 +1325,7 @@ void SimplexBase::intersectIntegerRelation(const IntegerRelation &rel) { MaybeOptimum Simplex::computeRowOptimum(Direction direction, unsigned row) { // Keep trying to find a pivot for the row in the specified direction. - while (Optional maybePivot = findPivot(row, direction)) { + while (std::optional maybePivot = findPivot(row, direction)) { // If findPivot returns a pivot involving the row itself, then the optimum // is unbounded, so we return std::nullopt. if (maybePivot->row == row) @@ -1357,7 +1358,7 @@ MaybeOptimum Simplex::computeOptimum(Direction direction, return OptimumKind::Empty; if (u.orientation == Orientation::Column) { unsigned column = u.pos; - Optional pivotRow = findPivotRow({}, direction, column); + std::optional pivotRow = findPivotRow({}, direction, column); // If no pivot is returned, the constraint is unbounded in the specified // direction. if (!pivotRow) @@ -1424,7 +1425,8 @@ void Simplex::detectRedundant(unsigned offset, unsigned count) { Unknown &u = con[offset + i]; if (u.orientation == Orientation::Column) { unsigned column = u.pos; - Optional pivotRow = findPivotRow({}, Direction::Down, column); + std::optional pivotRow = + findPivotRow({}, Direction::Down, column); // If no downward pivot is returned, the constraint is unbounded below // and hence not redundant. if (!pivotRow) @@ -1546,7 +1548,7 @@ Simplex Simplex::makeProduct(const Simplex &a, const Simplex &b) { return result; } -Optional> Simplex::getRationalSample() const { +std::optional> Simplex::getRationalSample() const { if (empty) return {}; @@ -1601,7 +1603,7 @@ MaybeOptimum> LexSimplex::getRationalSample() const { return sample; } -Optional> Simplex::getSamplePointIfIntegral() const { +std::optional> Simplex::getSamplePointIfIntegral() const { // If the tableau is empty, no sample point exists. if (empty) return {}; @@ -1969,7 +1971,7 @@ void Simplex::reduceBasis(Matrix &basis, unsigned level) { /// /// To avoid potentially arbitrarily large recursion depths leading to stack /// overflows, this algorithm is implemented iteratively. -Optional> Simplex::findIntegerSample() { +std::optional> Simplex::findIntegerSample() { if (empty) return {}; diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp index d397744..89ccc4f 100644 --- a/mlir/lib/Analysis/Presburger/Utils.cpp +++ b/mlir/lib/Analysis/Presburger/Utils.cpp @@ -378,11 +378,11 @@ SmallVector presburger::getComplementIneq(ArrayRef ineq) { return coeffs; } -SmallVector, 4> +SmallVector, 4> DivisionRepr::divValuesAt(ArrayRef point) const { assert(point.size() == getNumNonDivs() && "Incorrect point size"); - SmallVector, 4> divValues(getNumDivs(), std::nullopt); + SmallVector, 4> divValues(getNumDivs(), std::nullopt); bool changed = true; while (changed) { changed = false; diff --git a/mlir/lib/AsmParser/AsmParserImpl.h b/mlir/lib/AsmParser/AsmParserImpl.h index 0463929..26e1f4f1 100644 --- a/mlir/lib/AsmParser/AsmParserImpl.h +++ b/mlir/lib/AsmParser/AsmParserImpl.h @@ -287,7 +287,7 @@ public: // Check for a hexadecimal float value. if (curTok.is(Token::integer)) { - Optional apResult; + std::optional apResult; if (failed(parser.parseFloatFromIntegerLiteral( apResult, curTok, isNegative, APFloat::IEEEdouble(), /*typeSizeInBits=*/64))) diff --git a/mlir/lib/AsmParser/AttributeParser.cpp b/mlir/lib/AsmParser/AttributeParser.cpp index 1668341..16e86e6 100644 --- a/mlir/lib/AsmParser/AttributeParser.cpp +++ b/mlir/lib/AsmParser/AttributeParser.cpp @@ -356,8 +356,8 @@ Attribute Parser::parseFloatAttr(Type type, bool isNegative) { /// Construct an APint from a parsed value, a known attribute type and /// sign. -static Optional buildAttributeAPInt(Type type, bool isNegative, - StringRef spelling) { +static std::optional buildAttributeAPInt(Type type, bool isNegative, + StringRef spelling) { // Parse the integer value into an APInt that is big enough to hold the value. APInt result; bool isHex = spelling.size() > 1 && spelling[1] == 'x'; @@ -417,7 +417,7 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { } if (auto floatType = type.dyn_cast()) { - Optional result; + std::optional result; if (failed(parseFloatFromIntegerLiteral(result, tok, isNegative, floatType.getFloatSemantics(), floatType.getWidth()))) @@ -435,7 +435,7 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { return nullptr; } - Optional apInt = buildAttributeAPInt(type, isNegative, spelling); + std::optional apInt = buildAttributeAPInt(type, isNegative, spelling); if (!apInt) return emitError(loc, "integer constant out of range for attribute"), nullptr; @@ -450,7 +450,7 @@ Attribute Parser::parseDecOrHexAttr(Type type, bool isNegative) { /// stored into 'result'. static ParseResult parseElementAttrHexValues(Parser &parser, Token tok, std::string &result) { - if (Optional value = tok.getHexStringValue()) { + if (std::optional value = tok.getHexStringValue()) { result = std::move(*value); return success(); } @@ -636,7 +636,7 @@ TensorLiteralParser::getIntAttrElements(SMLoc loc, Type eltTy, } // Create APInt values for each element with the correct bitwidth. - Optional apInt = + std::optional apInt = buildAttributeAPInt(eltTy, isNegative, token.getSpelling()); if (!apInt) return p.emitError(tokenLoc, "integer constant out of range for type"); @@ -656,7 +656,7 @@ TensorLiteralParser::getFloatAttrElements(SMLoc loc, FloatType eltTy, // Handle hexadecimal float literals. if (token.is(Token::integer) && token.getSpelling().startswith("0x")) { - Optional result; + std::optional result; if (failed(p.parseFloatFromIntegerLiteral(result, token, isNegative, eltTy.getFloatSemantics(), eltTy.getWidth()))) @@ -880,7 +880,7 @@ ParseResult DenseArrayElementParser::parseIntegerElement(Parser &p) { bool isNegative = p.consumeIf(Token::minus); // Parse an integer literal as an APInt. - Optional value; + std::optional value; StringRef spelling = p.getToken().getSpelling(); if (p.getToken().isAny(Token::kw_true, Token::kw_false)) { if (!type.isInteger(1)) @@ -903,7 +903,7 @@ ParseResult DenseArrayElementParser::parseFloatElement(Parser &p) { bool isNegative = p.consumeIf(Token::minus); Token token = p.getToken(); - Optional result; + std::optional result; auto floatType = type.cast(); if (p.consumeIf(Token::integer)) { // Parse an integer literal as a float. @@ -913,7 +913,7 @@ ParseResult DenseArrayElementParser::parseFloatElement(Parser &p) { return failure(); } else if (p.consumeIf(Token::floatliteral)) { // Parse a floating point literal. - Optional val = token.getFloatingPointValue(); + std::optional val = token.getFloatingPointValue(); if (!val) return failure(); result = APFloat(isNegative ? -*val : *val); @@ -1150,7 +1150,7 @@ Attribute Parser::parseStridedLayoutAttr() { // Parses either an integer token or a question mark token. Reports an error // and returns std::nullopt if the current token is neither. The integer token // must fit into int64_t limits. - auto parseStrideOrOffset = [&]() -> Optional { + auto parseStrideOrOffset = [&]() -> std::optional { if (consumeIf(Token::question)) return ShapedType::kDynamic; @@ -1163,7 +1163,7 @@ Attribute Parser::parseStridedLayoutAttr() { bool negative = consumeIf(Token::minus); if (getToken().is(Token::integer)) { - Optional value = getToken().getUInt64IntegerValue(); + std::optional value = getToken().getUInt64IntegerValue(); if (!value || *value > static_cast(std::numeric_limits::max())) return emitWrongTokenError(); @@ -1182,7 +1182,7 @@ Attribute Parser::parseStridedLayoutAttr() { SmallVector strides; if (!getToken().is(Token::r_square)) { do { - Optional stride = parseStrideOrOffset(); + std::optional stride = parseStrideOrOffset(); if (!stride) return nullptr; strides.push_back(*stride); @@ -1205,7 +1205,7 @@ Attribute Parser::parseStridedLayoutAttr() { failed(parseToken(Token::colon, "expected ':' after 'offset'"))) return nullptr; - Optional offset = parseStrideOrOffset(); + std::optional offset = parseStrideOrOffset(); if (!offset || failed(parseToken(Token::greater, "expected '>'"))) return nullptr; diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp index aad6b45..c56befe 100644 --- a/mlir/lib/AsmParser/Parser.cpp +++ b/mlir/lib/AsmParser/Parser.cpp @@ -276,7 +276,7 @@ OptionalParseResult Parser::parseOptionalInteger(APInt &result) { /// Parse a floating point value from an integer literal token. ParseResult Parser::parseFloatFromIntegerLiteral( - Optional &result, const Token &tok, bool isNegative, + std::optional &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics, size_t typeSizeInBits) { SMLoc loc = tok.getLoc(); StringRef spelling = tok.getSpelling(); @@ -292,7 +292,7 @@ ParseResult Parser::parseFloatFromIntegerLiteral( "leading minus"); } - Optional value = tok.getUInt64IntegerValue(); + std::optional value = tok.getUInt64IntegerValue(); if (!value) return emitError(loc, "hexadecimal float constant out of range for type"); @@ -534,12 +534,13 @@ public: /// skip parsing that component. ParseResult parseGenericOperationAfterOpName( OperationState &result, - Optional> parsedOperandUseInfo = std::nullopt, - Optional> parsedSuccessors = std::nullopt, - Optional>> parsedRegions = + std::optional> parsedOperandUseInfo = std::nullopt, - Optional> parsedAttributes = std::nullopt, - Optional parsedFnType = std::nullopt); + std::optional> parsedSuccessors = std::nullopt, + std::optional>> parsedRegions = + std::nullopt, + std::optional> parsedAttributes = std::nullopt, + std::optional parsedFnType = std::nullopt); /// Parse an operation instance that is in the generic form and insert it at /// the provided insertion point. @@ -1250,11 +1251,11 @@ struct CleanupOpStateRegions { ParseResult OperationParser::parseGenericOperationAfterOpName( OperationState &result, - Optional> parsedOperandUseInfo, - Optional> parsedSuccessors, - Optional>> parsedRegions, - Optional> parsedAttributes, - Optional parsedFnType) { + std::optional> parsedOperandUseInfo, + std::optional> parsedSuccessors, + std::optional>> parsedRegions, + std::optional> parsedAttributes, + std::optional parsedFnType) { // Parse the operand list, if not explicitly provided. SmallVector opInfo; @@ -1436,7 +1437,8 @@ public: // This can happen if an attribute set during parsing is also specified in // the attribute dictionary in the assembly, or the attribute is set // multiple during parsing. - Optional duplicate = opState.attributes.findDuplicate(); + std::optional duplicate = + opState.attributes.findDuplicate(); if (duplicate) return emitError(getNameLoc(), "attribute '") << duplicate->getName().getValue() @@ -1455,11 +1457,11 @@ public: ParseResult parseGenericOperationAfterOpName( OperationState &result, - Optional> parsedUnresolvedOperands, - Optional> parsedSuccessors, - Optional>> parsedRegions, - Optional> parsedAttributes, - Optional parsedFnType) final { + std::optional> parsedUnresolvedOperands, + std::optional> parsedSuccessors, + std::optional>> parsedRegions, + std::optional> parsedAttributes, + std::optional parsedFnType) final { return parser.parseGenericOperationAfterOpName( result, parsedUnresolvedOperands, parsedSuccessors, parsedRegions, parsedAttributes, parsedFnType); @@ -1777,7 +1779,7 @@ public: /// Parse a loc(...) specifier if present, filling in result if so. ParseResult - parseOptionalLocationSpecifier(Optional &result) override { + parseOptionalLocationSpecifier(std::optional &result) override { // If there is a 'loc' we parse a trailing location. if (!parser.consumeIf(Token::kw_loc)) return success(); @@ -1825,7 +1827,7 @@ FailureOr OperationParser::parseCustomOperationName() { consumeToken(); // Check to see if this operation name is already registered. - Optional opInfo = + std::optional opInfo = RegisteredOperationName::lookup(opName, getContext()); if (opInfo) return *opInfo; @@ -2395,7 +2397,7 @@ public: // Blob data within then textual format is represented as a hex string. // TODO: We could avoid an additional alloc+copy here if we pre-allocated // the buffer to use during hex processing. - Optional blobData = + std::optional blobData = value.is(Token::string) ? value.getHexStringValue() : std::nullopt; if (!blobData) return p.emitError(value.getLoc(), diff --git a/mlir/lib/AsmParser/Parser.h b/mlir/lib/AsmParser/Parser.h index e5cbd8b..c5e3297 100644 --- a/mlir/lib/AsmParser/Parser.h +++ b/mlir/lib/AsmParser/Parser.h @@ -140,7 +140,7 @@ public: OptionalParseResult parseOptionalInteger(APInt &result); /// Parse a floating point value from an integer literal token. - ParseResult parseFloatFromIntegerLiteral(Optional &result, + ParseResult parseFloatFromIntegerLiteral(std::optional &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics, size_t typeSizeInBits); diff --git a/mlir/lib/AsmParser/Token.cpp b/mlir/lib/AsmParser/Token.cpp index dd392b4..2e36bfb 100644 --- a/mlir/lib/AsmParser/Token.cpp +++ b/mlir/lib/AsmParser/Token.cpp @@ -26,7 +26,7 @@ SMRange Token::getLocRange() const { return SMRange(getLoc(), getEndLoc()); } /// For an integer token, return its value as an unsigned. If it doesn't fit, /// return std::nullopt. -Optional Token::getUnsignedIntegerValue() const { +std::optional Token::getUnsignedIntegerValue() const { bool isHex = spelling.size() > 1 && spelling[1] == 'x'; unsigned result = 0; @@ -37,7 +37,7 @@ Optional Token::getUnsignedIntegerValue() const { /// For an integer token, return its value as a uint64_t. If it doesn't fit, /// return std::nullopt. -Optional Token::getUInt64IntegerValue(StringRef spelling) { +std::optional Token::getUInt64IntegerValue(StringRef spelling) { bool isHex = spelling.size() > 1 && spelling[1] == 'x'; uint64_t result = 0; @@ -48,7 +48,7 @@ Optional Token::getUInt64IntegerValue(StringRef spelling) { /// For a floatliteral, return its value as a double. Return std::nullopt if the /// value underflows or overflows. -Optional Token::getFloatingPointValue() const { +std::optional Token::getFloatingPointValue() const { double result = 0; if (spelling.getAsDouble(result)) return std::nullopt; @@ -56,7 +56,7 @@ Optional Token::getFloatingPointValue() const { } /// For an inttype token, return its bitwidth. -Optional Token::getIntTypeBitwidth() const { +std::optional Token::getIntTypeBitwidth() const { assert(getKind() == inttype); unsigned bitwidthStart = (spelling[0] == 'i' ? 1 : 2); unsigned result = 0; @@ -65,7 +65,7 @@ Optional Token::getIntTypeBitwidth() const { return result; } -Optional Token::getIntTypeSignedness() const { +std::optional Token::getIntTypeSignedness() const { assert(getKind() == inttype); if (spelling[0] == 'i') return std::nullopt; @@ -127,7 +127,7 @@ std::string Token::getStringValue() const { /// Given a token containing a hex string literal, return its value or /// std::nullopt if the token does not contain a valid hex string. -Optional Token::getHexStringValue() const { +std::optional Token::getHexStringValue() const { assert(getKind() == string); // Get the internal string data, without the quotes. @@ -158,7 +158,7 @@ std::string Token::getSymbolReference() const { /// Given a hash_identifier token like #123, try to parse the number out of /// the identifier, returning std::nullopt if it is a named identifier like #x /// or if the integer doesn't fit. -Optional Token::getHashIdentifierNumber() const { +std::optional Token::getHashIdentifierNumber() const { assert(getKind() == hash_identifier); unsigned result = 0; if (spelling.drop_front().getAsInteger(10, result)) diff --git a/mlir/lib/AsmParser/Token.h b/mlir/lib/AsmParser/Token.h index 3f4db2e..4640e038 100644 --- a/mlir/lib/AsmParser/Token.h +++ b/mlir/lib/AsmParser/Token.h @@ -76,31 +76,31 @@ public: /// For an integer token, return its value as an unsigned. If it doesn't fit, /// return std::nullopt. - Optional getUnsignedIntegerValue() const; + std::optional getUnsignedIntegerValue() const; /// For an integer token, return its value as an uint64_t. If it doesn't fit, /// return std::nullopt. - static Optional getUInt64IntegerValue(StringRef spelling); - Optional getUInt64IntegerValue() const { + static std::optional getUInt64IntegerValue(StringRef spelling); + std::optional getUInt64IntegerValue() const { return getUInt64IntegerValue(getSpelling()); } /// For a floatliteral token, return its value as a double. Returns /// std::nullopt in the case of underflow or overflow. - Optional getFloatingPointValue() const; + std::optional getFloatingPointValue() const; /// For an inttype token, return its bitwidth. - Optional getIntTypeBitwidth() const; + std::optional getIntTypeBitwidth() const; /// For an inttype token, return its signedness semantics: std::nullopt means /// no signedness semantics; true means signed integer type; false means /// unsigned integer type. - Optional getIntTypeSignedness() const; + std::optional getIntTypeSignedness() const; /// Given a hash_identifier token like #123, try to parse the number out of /// the identifier, returning std::nullopt if it is a named identifier like #x /// or if the integer doesn't fit. - Optional getHashIdentifierNumber() const; + std::optional getHashIdentifierNumber() const; /// Given a token containing a string literal, return its value, including /// removing the quote characters and unescaping the contents of the string. @@ -110,7 +110,7 @@ public: /// std::nullopt if the token does not contain a valid hex string. A hex /// string literal is a string starting with `0x` and only containing hex /// digits. - Optional getHexStringValue() const; + std::optional getHexStringValue() const; /// Given a token containing a symbol reference, return the unescaped string /// value. diff --git a/mlir/lib/AsmParser/TypeParser.cpp b/mlir/lib/AsmParser/TypeParser.cpp index cf20ae8..fab7244 100644 --- a/mlir/lib/AsmParser/TypeParser.cpp +++ b/mlir/lib/AsmParser/TypeParser.cpp @@ -281,7 +281,7 @@ Type Parser::parseNonFunctionType() { } IntegerType::SignednessSemantics signSemantics = IntegerType::Signless; - if (Optional signedness = getToken().getIntTypeSignedness()) + if (std::optional signedness = getToken().getIntTypeSignedness()) signSemantics = *signedness ? IntegerType::Signed : IntegerType::Unsigned; consumeToken(Token::inttype); @@ -561,7 +561,7 @@ ParseResult Parser::parseIntegerInDimensionList(int64_t &value) { consumeToken(); } else { // Make sure this integer value is in bound and valid. - Optional dimension = getToken().getUInt64IntegerValue(); + std::optional dimension = getToken().getUInt64IntegerValue(); if (!dimension || *dimension > (uint64_t)std::numeric_limits::max()) return emitError("invalid dimension"); diff --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp index 6885ef9..da44141 100644 --- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp +++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp @@ -34,8 +34,8 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) { "get", [](py::object cls, std::vector dimLevelTypes, - llvm::Optional dimOrdering, - llvm::Optional higherOrdering, int pointerBitWidth, + std::optional dimOrdering, + std::optional higherOrdering, int pointerBitWidth, int indexBitWidth, MlirContext context) { return cls(mlirSparseTensorEncodingAttrGet( context, dimLevelTypes.size(), dimLevelTypes.data(), @@ -60,7 +60,7 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) { }) .def_property_readonly( "dim_ordering", - [](MlirAttribute self) -> llvm::Optional { + [](MlirAttribute self) -> std::optional { MlirAffineMap ret = mlirSparseTensorEncodingAttrGetDimOrdering(self); if (mlirAffineMapIsNull(ret)) @@ -69,7 +69,7 @@ static void populateDialectSparseTensorSubmodule(const py::module &m) { }) .def_property_readonly( "higher_ordering", - [](MlirAttribute self) -> llvm::Optional { + [](MlirAttribute self) -> std::optional { MlirAffineMap ret = mlirSparseTensorEncodingAttrGetHigherOrdering(self); if (mlirAffineMapIsNull(ret)) diff --git a/mlir/lib/Bindings/Python/Globals.h b/mlir/lib/Bindings/Python/Globals.h index fbe51a7..f3370a4 100644 --- a/mlir/lib/Bindings/Python/Globals.h +++ b/mlir/lib/Bindings/Python/Globals.h @@ -84,12 +84,12 @@ public: /// Looks up a registered dialect class by namespace. Note that this may /// trigger loading of the defining module and can arbitrarily re-enter. - llvm::Optional + std::optional lookupDialectClass(const std::string &dialectNamespace); /// Looks up a registered raw OpView class by operation name. Note that this /// may trigger a load of the dialect, which can arbitrarily re-enter. - llvm::Optional + std::optional lookupRawOpViewClass(llvm::StringRef operationName); private: diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp index c598aee..a29f163 100644 --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -546,8 +546,9 @@ public: using PyConcreteAttribute::PyConcreteAttribute; static PyDenseElementsAttribute - getFromBuffer(py::buffer array, bool signless, Optional explicitType, - Optional> explicitShape, + getFromBuffer(py::buffer array, bool signless, + std::optional explicitType, + std::optional> explicitShape, DefaultingPyMlirContext contextWrapper) { // Request a contiguous view. In exotic cases, this will cause a copy. int flags = PyBUF_C_CONTIGUOUS | PyBUF_FORMAT; @@ -573,7 +574,7 @@ public: // Notably, this excludes, bool (which needs to be bit-packed) and // other exotics which do not have a direct representation in the buffer // protocol (i.e. complex, etc). - Optional bulkLoadElementType; + std::optional bulkLoadElementType; if (explicitType) { bulkLoadElementType = *explicitType; } else if (arrayInfo.format == "f") { diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp index 7a9e8eb..eb7d18f 100644 --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -1066,7 +1066,7 @@ void PyOperation::checkValid() const { } void PyOperationBase::print(py::object fileObject, bool binary, - llvm::Optional largeElementsLimit, + std::optional largeElementsLimit, bool enableDebugInfo, bool prettyDebugInfo, bool printGenericOpForm, bool useLocalScope, bool assumeVerified) { @@ -1112,7 +1112,7 @@ void PyOperationBase::writeBytecode(const py::object &fileObject) { } py::object PyOperationBase::getAsm(bool binary, - llvm::Optional largeElementsLimit, + std::optional largeElementsLimit, bool enableDebugInfo, bool prettyDebugInfo, bool printGenericOpForm, bool useLocalScope, bool assumeVerified) { @@ -1151,7 +1151,7 @@ void PyOperationBase::moveBefore(PyOperationBase &other) { operation.parentKeepAlive = otherOp.parentKeepAlive; } -llvm::Optional PyOperation::getParentOperation() { +std::optional PyOperation::getParentOperation() { checkValid(); if (!isAttached()) throw SetPyError(PyExc_ValueError, "Detached operations have no parent"); @@ -1163,7 +1163,7 @@ llvm::Optional PyOperation::getParentOperation() { PyBlock PyOperation::getBlock() { checkValid(); - llvm::Optional parentOperation = getParentOperation(); + std::optional parentOperation = getParentOperation(); MlirBlock block = mlirOperationGetBlock(get()); assert(!mlirBlockIsNull(block) && "Attached operation has null parent"); assert(parentOperation && "Operation has no parent"); @@ -1199,12 +1199,13 @@ static void maybeInsertOperation(PyOperationRef &op, } } -py::object PyOperation::create( - const std::string &name, llvm::Optional> results, - llvm::Optional> operands, - llvm::Optional attributes, - llvm::Optional> successors, int regions, - DefaultingPyLocation location, const py::object &maybeIp) { +py::object PyOperation::create(const std::string &name, + std::optional> results, + std::optional> operands, + std::optional attributes, + std::optional> successors, + int regions, DefaultingPyLocation location, + const py::object &maybeIp) { llvm::SmallVector mlirOperands; llvm::SmallVector mlirResults; llvm::SmallVector mlirSuccessors; @@ -1357,12 +1358,13 @@ void PyOperation::erase() { // PyOpView //------------------------------------------------------------------------------ -py::object PyOpView::buildGeneric( - const py::object &cls, py::list resultTypeList, py::list operandList, - llvm::Optional attributes, - llvm::Optional> successors, - llvm::Optional regions, DefaultingPyLocation location, - const py::object &maybeIp) { +py::object +PyOpView::buildGeneric(const py::object &cls, py::list resultTypeList, + py::list operandList, std::optional attributes, + std::optional> successors, + std::optional regions, + DefaultingPyLocation location, + const py::object &maybeIp) { PyMlirContextRef context = location->getContext(); // Class level operation construction metadata. std::string name = py::cast(cls.attr("OPERATION_NAME")); @@ -2518,7 +2520,7 @@ void mlir::python::populateIRCore(py::module &m) { .def_static( "fused", [](const std::vector &pyLocations, - llvm::Optional metadata, + std::optional metadata, DefaultingPyMlirContext context) { llvm::SmallVector locations; locations.reserve(pyLocations.size()); @@ -2533,7 +2535,7 @@ void mlir::python::populateIRCore(py::module &m) { py::arg("context") = py::none(), kContextGetFusedLocationDocstring) .def_static( "name", - [](std::string name, llvm::Optional childLoc, + [](std::string name, std::optional childLoc, DefaultingPyMlirContext context) { return PyLocation( context->getRef(), diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp index f3e4e73..fed8a50 100644 --- a/mlir/lib/Bindings/Python/IRInterfaces.cpp +++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp @@ -185,9 +185,9 @@ public: /// Given the arguments required to build an operation, attempts to infer its /// return types. Throws value_error on faliure. std::vector - inferReturnTypes(llvm::Optional> operands, - llvm::Optional attributes, - llvm::Optional> regions, + inferReturnTypes(std::optional> operands, + std::optional attributes, + std::optional> regions, DefaultingPyMlirContext context, DefaultingPyLocation location) { llvm::SmallVector mlirOperands; diff --git a/mlir/lib/Bindings/Python/IRModule.cpp b/mlir/lib/Bindings/Python/IRModule.cpp index 3614360..e3b8ef1 100644 --- a/mlir/lib/Bindings/Python/IRModule.cpp +++ b/mlir/lib/Bindings/Python/IRModule.cpp @@ -112,7 +112,7 @@ PyGlobals::lookupAttributeBuilder(const std::string &attributeKind) { return std::nullopt; } -llvm::Optional +std::optional PyGlobals::lookupDialectClass(const std::string &dialectNamespace) { loadDialectModule(dialectNamespace); // Fast match against the class map first (common case). @@ -129,7 +129,7 @@ PyGlobals::lookupDialectClass(const std::string &dialectNamespace) { return std::nullopt; } -llvm::Optional +std::optional PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) { { auto foundIt = rawOpViewClassMapCache.find(operationName); diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h index b198b4b..d26fa20 100644 --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -347,7 +347,7 @@ public: private: MlirContext context; pybind11::object callback; - llvm::Optional registeredID; + std::optional registeredID; bool hadError = false; friend class PyMlirContext; }; @@ -504,11 +504,11 @@ public: virtual ~PyOperationBase() = default; /// Implements the bound 'print' method and helps with others. void print(pybind11::object fileObject, bool binary, - llvm::Optional largeElementsLimit, bool enableDebugInfo, + std::optional largeElementsLimit, bool enableDebugInfo, bool prettyDebugInfo, bool printGenericOpForm, bool useLocalScope, bool assumeVerified); pybind11::object getAsm(bool binary, - llvm::Optional largeElementsLimit, + std::optional largeElementsLimit, bool enableDebugInfo, bool prettyDebugInfo, bool printGenericOpForm, bool useLocalScope, bool assumeVerified); @@ -586,7 +586,7 @@ public: /// Gets the parent operation or raises an exception if the operation has /// no parent. - llvm::Optional getParentOperation(); + std::optional getParentOperation(); /// Gets a capsule wrapping the void* within the MlirOperation. pybind11::object getCapsule(); @@ -598,10 +598,10 @@ public: /// Creates an operation. See corresponding python docstring. static pybind11::object - create(const std::string &name, llvm::Optional> results, - llvm::Optional> operands, - llvm::Optional attributes, - llvm::Optional> successors, int regions, + create(const std::string &name, std::optional> results, + std::optional> operands, + std::optional attributes, + std::optional> successors, int regions, DefaultingPyLocation location, const pybind11::object &ip); /// Creates an OpView suitable for this operation. @@ -656,9 +656,9 @@ public: static pybind11::object buildGeneric(const pybind11::object &cls, pybind11::list resultTypeList, pybind11::list operandList, - llvm::Optional attributes, - llvm::Optional> successors, - llvm::Optional regions, DefaultingPyLocation location, + std::optional attributes, + std::optional> successors, + std::optional regions, DefaultingPyLocation location, const pybind11::object &maybeIp); private: @@ -738,10 +738,10 @@ public: private: // Trampoline constructor that avoids null initializing members while // looking up parents. - PyInsertionPoint(PyBlock block, llvm::Optional refOperation) + PyInsertionPoint(PyBlock block, std::optional refOperation) : refOperation(std::move(refOperation)), block(std::move(block)) {} - llvm::Optional refOperation; + std::optional refOperation; PyBlock block; }; /// Wrapper around the generic MlirType. diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp index ad46e52..3cc226d 100644 --- a/mlir/lib/Bindings/Python/IRTypes.cpp +++ b/mlir/lib/Bindings/Python/IRTypes.cpp @@ -401,8 +401,7 @@ public: c.def_static( "get", [](std::vector shape, PyType &elementType, - llvm::Optional &encodingAttr, - DefaultingPyLocation loc) { + std::optional &encodingAttr, DefaultingPyLocation loc) { MlirType t = mlirRankedTensorTypeGetChecked( loc, shape.size(), shape.data(), elementType, encodingAttr ? encodingAttr->get() : mlirAttributeGetNull()); @@ -423,8 +422,7 @@ public: py::arg("encoding") = py::none(), py::arg("loc") = py::none(), "Create a ranked tensor type"); c.def_property_readonly( - "encoding", - [](PyRankedTensorType &self) -> llvm::Optional { + "encoding", [](PyRankedTensorType &self) -> std::optional { MlirAttribute encoding = mlirRankedTensorTypeGetEncoding(self.get()); if (mlirAttributeIsNull(encoding)) return std::nullopt; diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 5860fd4..8dded64 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -1121,8 +1121,8 @@ private: // Resource Section LogicalResult - parseResourceSection(Optional> resourceData, - Optional> resourceOffsetData); + parseResourceSection(std::optional> resourceData, + std::optional> resourceOffsetData); //===--------------------------------------------------------------------===// // IR Section @@ -1269,7 +1269,8 @@ LogicalResult BytecodeReader::read(llvm::MemoryBufferRef buffer, Block *block) { }); // Parse the raw data for each of the top-level sections of the bytecode. - Optional> sectionDatas[bytecode::Section::kNumSections]; + std::optional> + sectionDatas[bytecode::Section::kNumSections]; while (!reader.empty()) { // Read the next section from the bytecode. bytecode::Section::ID sectionID; @@ -1389,8 +1390,8 @@ FailureOr BytecodeReader::parseOpName(EncodingReader &reader) { // Resource Section LogicalResult BytecodeReader::parseResourceSection( - Optional> resourceData, - Optional> resourceOffsetData) { + std::optional> resourceData, + std::optional> resourceOffsetData) { // Ensure both sections are either present or not. if (resourceData.has_value() != resourceOffsetData.has_value()) { if (resourceOffsetData) diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp index 13e8d20..68563a6 100644 --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -289,7 +289,7 @@ void mlirOperationStateEnableResultTypeInference(MlirOperationState *state) { static LogicalResult inferOperationTypes(OperationState &state) { MLIRContext *context = state.getContext(); - Optional info = state.name.getRegisteredInfo(); + std::optional info = state.name.getRegisteredInfo(); if (!info) { emitError(state.location) << "type inference was requested for the operation " << state.name diff --git a/mlir/lib/CAPI/IR/Pass.cpp b/mlir/lib/CAPI/IR/Pass.cpp index 9ae425f..b921154 100644 --- a/mlir/lib/CAPI/IR/Pass.cpp +++ b/mlir/lib/CAPI/IR/Pass.cpp @@ -112,7 +112,7 @@ namespace mlir { class ExternalPass : public Pass { public: ExternalPass(TypeID passID, StringRef name, StringRef argument, - StringRef description, Optional opName, + StringRef description, std::optional opName, ArrayRef dependentDialects, MlirExternalPassCallbacks callbacks, void *userData) : Pass(passID, opName), id(passID), name(name), argument(argument), @@ -143,7 +143,7 @@ protected: } bool canScheduleOn(RegisteredOperationName opName) const override { - if (Optional specifiedOpName = getOpName()) + if (std::optional specifiedOpName = getOpName()) return opName.getStringRef() == specifiedOpName; return true; } @@ -179,7 +179,8 @@ MlirPass mlirCreateExternalPass(MlirTypeID passID, MlirStringRef name, void *userData) { return wrap(static_cast(new mlir::ExternalPass( unwrap(passID), unwrap(name), unwrap(argument), unwrap(description), - opName.length > 0 ? Optional(unwrap(opName)) : std::nullopt, + opName.length > 0 ? std::optional(unwrap(opName)) + : std::nullopt, {dependentDialects, static_cast(nDependentDialects)}, callbacks, userData))); } diff --git a/mlir/lib/CAPI/Interfaces/Interfaces.cpp b/mlir/lib/CAPI/Interfaces/Interfaces.cpp index 61f1c95..5adccbd 100644 --- a/mlir/lib/CAPI/Interfaces/Interfaces.cpp +++ b/mlir/lib/CAPI/Interfaces/Interfaces.cpp @@ -19,7 +19,7 @@ using namespace mlir; bool mlirOperationImplementsInterface(MlirOperation operation, MlirTypeID interfaceTypeID) { - Optional info = + std::optional info = unwrap(operation)->getRegisteredInfo(); return info && info->hasInterface(unwrap(interfaceTypeID)); } @@ -27,7 +27,7 @@ bool mlirOperationImplementsInterface(MlirOperation operation, bool mlirOperationImplementsInterfaceStatic(MlirStringRef operationName, MlirContext context, MlirTypeID interfaceTypeID) { - Optional info = RegisteredOperationName::lookup( + std::optional info = RegisteredOperationName::lookup( StringRef(operationName.data, operationName.length), unwrap(context)); return info && info->hasInterface(unwrap(interfaceTypeID)); } @@ -42,7 +42,7 @@ MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes( intptr_t nRegions, MlirRegion *regions, MlirTypesCallback callback, void *userData) { StringRef name(opName.data, opName.length); - Optional info = + std::optional info = RegisteredOperationName::lookup(name, unwrap(context)); if (!info) return mlirLogicalResultFailure(); diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp index d924231..c1f720f 100644 --- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp +++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp @@ -312,7 +312,8 @@ static Value mfmaConcatIfNeeded(ConversionPatternRewriter &rewriter, /// Return the `rocdl` intrinsic corresponding to a MFMA operation `mfma` /// if one exists. This includes checking to ensure the intrinsic is supported /// on the architecture you are compiling for. -static Optional mfmaOpToIntrinsic(MFMAOp mfma, Chipset chipset) { +static std::optional mfmaOpToIntrinsic(MFMAOp mfma, + Chipset chipset) { uint32_t m = mfma.getM(), n = mfma.getN(), k = mfma.getK(), b = mfma.getBlocks(); Type sourceElem = mfma.getSourceA().getType(); @@ -428,7 +429,7 @@ struct MFMAOpLowering : public ConvertOpToLLVMPattern { getBlgpField |= op.getNegateA() | (op.getNegateB() << 1) | (op.getNegateC() << 2); } - Optional maybeIntrinsic = mfmaOpToIntrinsic(op, chipset); + std::optional maybeIntrinsic = mfmaOpToIntrinsic(op, chipset); if (!maybeIntrinsic.has_value()) return op.emitOpError("no intrinsic matching MFMA size on given chipset"); OperationState loweredOp(loc, *maybeIntrinsic); diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp index 5c21708..bd20f66 100644 --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp @@ -448,10 +448,10 @@ static Value createGroupReduceOpImpl(OpBuilder &builder, Location loc, .getResult(); } -static llvm::Optional createGroupReduceOp(OpBuilder &builder, - Location loc, Value arg, - gpu::AllReduceOperation opType, - bool isGroup, bool isUniform) { +static std::optional createGroupReduceOp(OpBuilder &builder, + Location loc, Value arg, + gpu::AllReduceOperation opType, + bool isGroup, bool isUniform) { using FuncT = Value (*)(OpBuilder &, Location, Value, bool, bool); struct OpHandler { gpu::AllReduceOperation type; diff --git a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp index 8918e50..93b58e2 100644 --- a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp +++ b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp @@ -154,7 +154,7 @@ ScalarOpToLibmCall::matchAndRewrite(Op op, void mlir::populateMathToLibmConversionPatterns( RewritePatternSet &patterns, PatternBenefit benefit, - llvm::Optional log1pBenefit) { + std::optional log1pBenefit) { patterns.add, VecOpToScalarOp, VecOpToScalarOp, VecOpToScalarOp, VecOpToScalarOp, VecOpToScalarOp, diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp index 7960b95..c6ce3f1 100644 --- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp @@ -116,7 +116,7 @@ static bool isAllocationSupported(Operation *allocOp, MemRefType type) { /// Returns the scope to use for atomic operations use for emulating store /// operations of unsupported integer bitwidths, based on the memref /// type. Returns std::nullopt on failure. -static Optional getAtomicOpScope(MemRefType type) { +static std::optional getAtomicOpScope(MemRefType type) { auto sc = type.getMemorySpace().dyn_cast_or_null(); switch (sc.getValue()) { case spirv::StorageClass::StorageBuffer: @@ -530,7 +530,7 @@ IntStoreOpPattern::matchAndRewrite(memref::StoreOp storeOp, OpAdaptor adaptor, storeVal = shiftValue(loc, storeVal, offset, mask, dstBits, rewriter); Value adjustedPtr = adjustAccessChainForBitwidth(typeConverter, accessChainOp, srcBits, dstBits, rewriter); - Optional scope = getAtomicOpScope(memrefType); + std::optional scope = getAtomicOpScope(memrefType); if (!scope) return failure(); Value result = rewriter.create( diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp index 55729de..03cf661 100644 --- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp +++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp @@ -153,7 +153,8 @@ namespace { // Helper structure that holds common state of the loop to GPU kernel // conversion. struct AffineLoopToGpuConverter { - Optional collectBounds(AffineForOp forOp, unsigned numLoops); + std::optional collectBounds(AffineForOp forOp, + unsigned numLoops); void createLaunch(AffineForOp rootForOp, AffineForOp innermostForOp, unsigned numBlockDims, unsigned numThreadDims); @@ -181,7 +182,7 @@ static bool isConstantOne(Value value) { // This may fail if the IR for computing loop bounds cannot be constructed, for // example if an affine loop uses semi-affine maps. Return the last loop to be // mapped on success, std::nullopt on failure. -Optional +std::optional AffineLoopToGpuConverter::collectBounds(AffineForOp forOp, unsigned numLoops) { OpBuilder builder(forOp.getOperation()); dims.reserve(numLoops); diff --git a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp index e9b0ec5..dfaa8b3 100644 --- a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp +++ b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp @@ -55,7 +55,7 @@ struct VectorToSCFPattern : public OpRewritePattern { /// memref should be unpacked in the next application of TransferOpConversion. /// A return value of std::nullopt indicates a broadcast. template -static Optional unpackedDim(OpTy xferOp) { +static std::optional unpackedDim(OpTy xferOp) { // TODO: support 0-d corner case. assert(xferOp.getTransferRank() > 0 && "unexpected 0-d transfer"); auto map = xferOp.getPermutationMap(); @@ -159,7 +159,7 @@ static Value generateMaskCheck(OpBuilder &b, OpTy xferOp, Value iv) { /// `resultTypes`. template static Value generateInBoundsCheck( - OpBuilder &b, OpTy xferOp, Value iv, Optional dim, + OpBuilder &b, OpTy xferOp, Value iv, std::optional dim, TypeRange resultTypes, function_ref inBoundsCase, function_ref outOfBoundsCase = nullptr) { @@ -217,7 +217,7 @@ static Value generateInBoundsCheck( /// a return value. Consequently, this function does not have a return value. template static void generateInBoundsCheck( - OpBuilder &b, OpTy xferOp, Value iv, Optional dim, + OpBuilder &b, OpTy xferOp, Value iv, std::optional dim, function_ref inBoundsCase, function_ref outOfBoundsCase = nullptr) { generateInBoundsCheck( @@ -1093,7 +1093,7 @@ namespace lowering_1_d { /// the transfer is operating. A return value of std::nullopt indicates a /// broadcast. template -static Optional +static std::optional get1dMemrefIndices(OpBuilder &b, OpTy xferOp, Value iv, SmallVector &memrefIndices) { auto indices = xferOp.getIndices(); diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp index c082088..ee73672 100644 --- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp +++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp @@ -68,7 +68,7 @@ LogicalResult RawBufferAtomicFaddOp::verify() { return verifyRawBufferOp(*this); } -static Optional getConstantUint32(Value v) { +static std::optional getConstantUint32(Value v) { APInt cst; if (!v.getType().isInteger(32)) return std::nullopt; @@ -90,7 +90,7 @@ static bool staticallyOutOfBounds(OpType op) { return false; int64_t result = offset + op.getIndexOffset().value_or(0); if (op.getSgprOffset()) { - Optional sgprOffset = getConstantUint32(op.getSgprOffset()); + std::optional sgprOffset = getConstantUint32(op.getSgprOffset()); if (!sgprOffset) return false; result += *sgprOffset; @@ -101,7 +101,7 @@ static bool staticallyOutOfBounds(OpType op) { for (auto pair : llvm::zip(strides, op.getIndices())) { int64_t stride = std::get<0>(pair); Value idx = std::get<1>(pair); - Optional idxVal = getConstantUint32(idx); + std::optional idxVal = getConstantUint32(idx); if (!idxVal) return false; indexVal += stride * *idxVal; diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp index e9fc4e5..6e73014 100644 --- a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp @@ -51,8 +51,8 @@ static Value getSupportedReduction(AffineForOp forOp, unsigned pos, return nullptr; Operation *combinerOp = combinerOps.back(); - Optional maybeKind = - TypeSwitch>(combinerOp) + std::optional maybeKind = + TypeSwitch>(combinerOp) .Case([](arith::AddFOp) { return arith::AtomicRMWKind::addf; }) .Case([](arith::MulFOp) { return arith::AtomicRMWKind::mulf; }) .Case([](arith::AddIOp) { return arith::AtomicRMWKind::addi; }) @@ -65,7 +65,7 @@ static Value getSupportedReduction(AffineForOp forOp, unsigned pos, .Case([](arith::MaxSIOp) { return arith::AtomicRMWKind::maxs; }) .Case([](arith::MinUIOp) { return arith::AtomicRMWKind::minu; }) .Case([](arith::MaxUIOp) { return arith::AtomicRMWKind::maxu; }) - .Default([](Operation *) -> Optional { + .Default([](Operation *) -> std::optional { // TODO: AtomicRMW supports other kinds of reductions this is // currently not detecting, add those when the need arises. return std::nullopt; diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp index 1ecbca5..5674342 100644 --- a/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp @@ -258,7 +258,7 @@ void FlatAffineValueConstraints::reset( unsigned newNumLocals, ArrayRef valArgs) { assert(newNumReservedCols >= newNumDims + newNumSymbols + newNumLocals + 1 && "minimum 1 column"); - SmallVector, 8> newVals; + SmallVector, 8> newVals; if (!valArgs.empty()) newVals.assign(valArgs.begin(), valArgs.end()); @@ -318,7 +318,7 @@ unsigned FlatAffineValueConstraints::insertVar(VarKind kind, unsigned pos, // If a Value is provided, insert it; otherwise use None. for (unsigned i = 0; i < num; ++i) values.insert(values.begin() + absolutePos + i, - vals[i] ? Optional(vals[i]) : std::nullopt); + vals[i] ? std::optional(vals[i]) : std::nullopt); assert(values.size() == getNumDimAndSymbolVars()); return absolutePos; @@ -326,7 +326,7 @@ unsigned FlatAffineValueConstraints::insertVar(VarKind kind, unsigned pos, bool FlatAffineValueConstraints::hasValues() const { return llvm::any_of( - values, [](const Optional &var) { return var.has_value(); }); + values, [](const std::optional &var) { return var.has_value(); }); } /// Checks if two constraint systems are in the same space, i.e., if they are @@ -359,9 +359,9 @@ static bool LLVM_ATTRIBUTE_UNUSED areVarsUnique( return true; SmallPtrSet uniqueVars; - ArrayRef> maybeValues = + ArrayRef> maybeValues = cst.getMaybeValues().slice(start, end - start); - for (Optional val : maybeValues) { + for (std::optional val : maybeValues) { if (val && !uniqueVars.insert(*val).second) return false; } @@ -403,13 +403,13 @@ static void mergeAndAlignVars(unsigned offset, FlatAffineValueConstraints *a, assert(areVarsUnique(*a) && "A's values aren't unique"); assert(areVarsUnique(*b) && "B's values aren't unique"); - assert( - llvm::all_of(llvm::drop_begin(a->getMaybeValues(), offset), - [](const Optional &var) { return var.has_value(); })); + assert(llvm::all_of( + llvm::drop_begin(a->getMaybeValues(), offset), + [](const std::optional &var) { return var.has_value(); })); - assert( - llvm::all_of(llvm::drop_begin(b->getMaybeValues(), offset), - [](const Optional &var) { return var.has_value(); })); + assert(llvm::all_of( + llvm::drop_begin(b->getMaybeValues(), offset), + [](const std::optional &var) { return var.has_value(); })); SmallVector aDimValues; a->getValues(offset, a->getNumDimVars(), &aDimValues); @@ -1370,7 +1370,7 @@ bool FlatAffineValueConstraints::findVar(Value val, unsigned *pos) const { } bool FlatAffineValueConstraints::containsVar(Value val) const { - return llvm::any_of(values, [&](const Optional &mayBeVar) { + return llvm::any_of(values, [&](const std::optional &mayBeVar) { return mayBeVar && *mayBeVar == val; }); } @@ -1431,7 +1431,7 @@ void FlatAffineValueConstraints::clearAndCopyFrom( void FlatAffineValueConstraints::fourierMotzkinEliminate( unsigned pos, bool darkShadow, bool *isResultIntegerExact) { - SmallVector, 8> newVals = values; + SmallVector, 8> newVals = values; if (getVarKindAt(pos) != VarKind::Local) newVals.erase(newVals.begin() + pos); // Note: Base implementation discards all associated Values. diff --git a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp index d13aa06..81d0655 100644 --- a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp @@ -83,7 +83,7 @@ void mlir::getTripCountMapAndOperands( /// otherwise. This method uses affine expression analysis (in turn using /// getTripCount) and is able to determine constant trip count in non-trivial /// cases. -Optional mlir::getConstantTripCount(AffineForOp forOp) { +std::optional mlir::getConstantTripCount(AffineForOp forOp) { SmallVector operands; AffineMap map; getTripCountMapAndOperands(forOp, &map, &operands); @@ -92,7 +92,7 @@ Optional mlir::getConstantTripCount(AffineForOp forOp) { return std::nullopt; // Take the min if all trip counts are constant. - Optional tripCount; + std::optional tripCount; for (auto resultExpr : map.getResults()) { if (auto constExpr = resultExpr.dyn_cast()) { if (tripCount.has_value()) diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp index 4ab91ba..ff88acd 100644 --- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp @@ -147,7 +147,7 @@ void ComputationSliceState::dump() const { /// and the dst loops for those dimensions have the same bounds. Returns false /// if both the src and the dst loops don't have the same bounds. Returns /// std::nullopt if none of the above can be proven. -Optional ComputationSliceState::isSliceMaximalFastCheck() const { +std::optional ComputationSliceState::isSliceMaximalFastCheck() const { assert(lbs.size() == ubs.size() && !lbs.empty() && !ivs.empty() && "Unexpected number of lbs, ubs and ivs in slice"); @@ -215,7 +215,7 @@ Optional ComputationSliceState::isSliceMaximalFastCheck() const { /// Returns true if it is deterministically verified that the original iteration /// space of the slice is contained within the new iteration space that is /// created after fusing 'this' slice into its destination. -Optional ComputationSliceState::isSliceValid() { +std::optional ComputationSliceState::isSliceValid() { // Fast check to determine if the slice is valid. If the following conditions // are verified to be true, slice is declared valid by the fast check: // 1. Each slice loop is a single iteration loop bound in terms of a single @@ -226,7 +226,7 @@ Optional ComputationSliceState::isSliceValid() { // expensive analysis. // TODO: Store the result of the fast check, as it might be used again in // `canRemoveSrcNodeAfterFusion`. - Optional isValidFastCheck = isSliceMaximalFastCheck(); + std::optional isValidFastCheck = isSliceMaximalFastCheck(); if (isValidFastCheck && *isValidFastCheck) return true; @@ -285,10 +285,10 @@ Optional ComputationSliceState::isSliceValid() { /// Returns true if the computation slice encloses all the iterations of the /// sliced loop nest. Returns false if it does not. Returns std::nullopt if it /// cannot determine if the slice is maximal or not. -Optional ComputationSliceState::isMaximal() const { +std::optional ComputationSliceState::isMaximal() const { // Fast check to determine if the computation slice is maximal. If the result // is inconclusive, we proceed with a more expensive analysis. - Optional isMaximalFastCheck = isSliceMaximalFastCheck(); + std::optional isMaximalFastCheck = isSliceMaximalFastCheck(); if (isMaximalFastCheck) return isMaximalFastCheck; @@ -339,7 +339,7 @@ unsigned MemRefRegion::getRank() const { return memref.getType().cast().getRank(); } -Optional MemRefRegion::getConstantBoundingSizeAndShape( +std::optional MemRefRegion::getConstantBoundingSizeAndShape( SmallVectorImpl *shape, std::vector> *lbs, SmallVectorImpl *lbDivisors) const { auto memRefType = memref.getType().cast(); @@ -370,7 +370,7 @@ Optional MemRefRegion::getConstantBoundingSizeAndShape( int64_t lbDivisor; for (unsigned d = 0; d < rank; d++) { SmallVector lb; - Optional diff = + std::optional diff = cstWithShapeBounds.getConstantBoundOnDimSize64(d, &lb, &lbDivisor); if (diff.has_value()) { diffConstant = *diff; @@ -611,7 +611,7 @@ static unsigned getMemRefEltSizeInBytes(MemRefType memRefType) { } // Returns the size of the region. -Optional MemRefRegion::getRegionSize() { +std::optional MemRefRegion::getRegionSize() { auto memRefType = memref.getType().cast(); if (!memRefType.getLayout().isIdentity()) { @@ -626,7 +626,7 @@ Optional MemRefRegion::getRegionSize() { SmallVector bufIndices; // Compute the extents of the buffer. - Optional numElements = getConstantBoundingSizeAndShape(); + std::optional numElements = getConstantBoundingSizeAndShape(); if (!numElements) { LLVM_DEBUG(llvm::dbgs() << "Dynamic shapes not yet supported\n"); return std::nullopt; @@ -638,7 +638,7 @@ Optional MemRefRegion::getRegionSize() { /// std::nullopt otherwise. If the element of the memref has vector type, takes /// into account size of the vector as well. // TODO: improve/complete this when we have target data. -Optional mlir::getMemRefSizeInBytes(MemRefType memRefType) { +std::optional mlir::getMemRefSizeInBytes(MemRefType memRefType) { if (!memRefType.hasStaticShape()) return std::nullopt; auto elementType = memRefType.getElementType(); @@ -956,7 +956,7 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, // Check if the slice computed is valid. Return success only if it is verified // that the slice is valid, otherwise return appropriate failure status. - Optional isSliceValid = sliceUnion->isSliceValid(); + std::optional isSliceValid = sliceUnion->isSliceValid(); if (!isSliceValid) { LLVM_DEBUG(llvm::dbgs() << "Cannot determine if the slice is valid\n"); return SliceComputationResult::GenericFailure; @@ -968,7 +968,8 @@ mlir::computeSliceUnion(ArrayRef opsA, ArrayRef opsB, } // TODO: extend this to handle multiple result maps. -static Optional getConstDifference(AffineMap lbMap, AffineMap ubMap) { +static std::optional getConstDifference(AffineMap lbMap, + AffineMap ubMap) { assert(lbMap.getNumResults() == 1 && "expected single result bound map"); assert(ubMap.getNumResults() == 1 && "expected single result bound map"); assert(lbMap.getNumDims() == ubMap.getNumDims()); @@ -1008,14 +1009,14 @@ bool mlir::buildSliceTripCountMap( forOp.getConstantUpperBound() - forOp.getConstantLowerBound(); continue; } - Optional maybeConstTripCount = getConstantTripCount(forOp); + std::optional maybeConstTripCount = getConstantTripCount(forOp); if (maybeConstTripCount.has_value()) { (*tripCountMap)[op] = *maybeConstTripCount; continue; } return false; } - Optional tripCount = getConstDifference(lbMap, ubMap); + std::optional tripCount = getConstDifference(lbMap, ubMap); // Slice bounds are created with a constant ub - lb difference. if (!tripCount.has_value()) return false; @@ -1129,7 +1130,7 @@ void mlir::getComputationSliceState( // 1. Slice is single trip count. // 2. Loop bounds of the source and destination match. // 3. Is being inserted at the innermost insertion point. - Optional isMaximal = sliceState->isMaximal(); + std::optional isMaximal = sliceState->isMaximal(); if (isLoopParallelAndContainsReduction(getSliceLoop(i)) && isInnermostInsertion() && srcIsUnitSlice() && isMaximal && *isMaximal) continue; @@ -1297,10 +1298,10 @@ unsigned mlir::getNumCommonSurroundingLoops(Operation &a, Operation &b) { return numCommonLoops; } -static Optional getMemoryFootprintBytes(Block &block, - Block::iterator start, - Block::iterator end, - int memorySpace) { +static std::optional getMemoryFootprintBytes(Block &block, + Block::iterator start, + Block::iterator end, + int memorySpace) { SmallDenseMap, 4> regions; // Walk this 'affine.for' operation to gather all memory regions. @@ -1333,7 +1334,7 @@ static Optional getMemoryFootprintBytes(Block &block, int64_t totalSizeInBytes = 0; for (const auto ®ion : regions) { - Optional size = region.second->getRegionSize(); + std::optional size = region.second->getRegionSize(); if (!size.has_value()) return std::nullopt; totalSizeInBytes += *size; @@ -1341,8 +1342,8 @@ static Optional getMemoryFootprintBytes(Block &block, return totalSizeInBytes; } -Optional mlir::getMemoryFootprintBytes(AffineForOp forOp, - int memorySpace) { +std::optional mlir::getMemoryFootprintBytes(AffineForOp forOp, + int memorySpace) { auto *forInst = forOp.getOperation(); return ::getMemoryFootprintBytes( *forInst->getBlock(), Block::iterator(forInst), @@ -1380,11 +1381,12 @@ IntegerSet mlir::simplifyIntegerSet(IntegerSet set) { return simplifiedSet; } -static void unpackOptionalValues(ArrayRef> source, +static void unpackOptionalValues(ArrayRef> source, SmallVector &target) { - target = llvm::to_vector<4>(llvm::map_range(source, [](Optional val) { - return val.has_value() ? *val : Value(); - })); + target = + llvm::to_vector<4>(llvm::map_range(source, [](std::optional val) { + return val.has_value() ? *val : Value(); + })); } /// Bound an identifier `pos` in a given FlatAffineValueConstraints with diff --git a/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp index cc658f1..0d84d38 100644 --- a/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/AffineDataCopyGeneration.cpp @@ -146,7 +146,7 @@ void AffineDataCopyGeneration::runOnBlock(Block *block, // Returns true if the footprint is known to exceed capacity. auto exceedsCapacity = [&](AffineForOp forOp) { - Optional footprint = + std::optional footprint = getMemoryFootprintBytes(forOp, /*memorySpace=*/0); return (footprint.has_value() && diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp index f836352..6561587 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp @@ -651,7 +651,7 @@ static bool canRemoveSrcNodeAfterFusion( // escaping memref, we can only remove it if the fusion slice is maximal so // that all the dependences are preserved. if (hasOutDepsAfterFusion || !escapingMemRefs.empty()) { - Optional isMaximal = fusionSlice.isMaximal(); + std::optional isMaximal = fusionSlice.isMaximal(); if (!isMaximal) { LLVM_DEBUG(llvm::dbgs() << "Src loop can't be removed: can't determine " "if fusion is maximal\n"); @@ -926,7 +926,7 @@ static unsigned getMemRefEltSizeInBytes(MemRefType memRefType) { // this one. static Value createPrivateMemRef(AffineForOp forOp, Operation *srcStoreOpInst, unsigned dstLoopDepth, - Optional fastMemorySpace, + std::optional fastMemorySpace, uint64_t localBufSizeThreshold) { Operation *forInst = forOp.getOperation(); @@ -950,7 +950,7 @@ static Value createPrivateMemRef(AffineForOp forOp, Operation *srcStoreOpInst, lbs.reserve(rank); // Query 'region' for 'newShape' and lower bounds of MemRefRegion accessed // by 'srcStoreOpInst' at depth 'dstLoopDepth'. - Optional numElements = + std::optional numElements = region.getConstantBoundingSizeAndShape(&newShape, &lbs, &lbDivisors); assert(numElements && "non-constant number of elts in local buffer"); @@ -1176,7 +1176,7 @@ static bool isFusionProfitable(Operation *srcOpInst, Operation *srcStoreOpInst, return false; } - Optional maybeSrcWriteRegionSizeBytes = + std::optional maybeSrcWriteRegionSizeBytes = srcWriteRegion.getRegionSize(); if (!maybeSrcWriteRegionSizeBytes.has_value()) return false; @@ -1218,7 +1218,7 @@ static bool isFusionProfitable(Operation *srcOpInst, Operation *srcStoreOpInst, continue; } - Optional maybeSliceWriteRegionSizeBytes = + std::optional maybeSliceWriteRegionSizeBytes = sliceWriteRegion.getRegionSize(); if (!maybeSliceWriteRegionSizeBytes.has_value() || *maybeSliceWriteRegionSizeBytes == 0) { @@ -1398,7 +1398,7 @@ public: // Parameter for local buffer size threshold. unsigned localBufSizeThreshold; // Parameter for fast memory space. - Optional fastMemorySpace; + std::optional fastMemorySpace; // If true, ignore any additional (redundant) computation tolerance threshold // that would have prevented fusion. bool maximalFusion; @@ -1409,7 +1409,7 @@ public: using Node = MemRefDependenceGraph::Node; GreedyFusion(MemRefDependenceGraph *mdg, unsigned localBufSizeThreshold, - Optional fastMemorySpace, bool maximalFusion, + std::optional fastMemorySpace, bool maximalFusion, double computeToleranceThreshold) : mdg(mdg), localBufSizeThreshold(localBufSizeThreshold), fastMemorySpace(fastMemorySpace), maximalFusion(maximalFusion), @@ -2016,7 +2016,7 @@ void LoopFusion::runOnBlock(Block *block) { if (!g.init(block)) return; - Optional fastMemorySpaceOpt; + std::optional fastMemorySpaceOpt; if (fastMemorySpace.hasValue()) fastMemorySpaceOpt = fastMemorySpace; unsigned localBufSizeThresholdBytes = localBufSizeThreshold * 1024; diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp index ee5dd98..319982b 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp @@ -76,7 +76,7 @@ static void adjustToDivisorsOfTripCounts(ArrayRef band, assert(band.size() == tileSizes->size() && "invalid tile size count"); for (unsigned i = 0, e = band.size(); i < e; i++) { unsigned &tSizeAdjusted = (*tileSizes)[i]; - Optional mayConst = getConstantTripCount(band[i]); + std::optional mayConst = getConstantTripCount(band[i]); if (!mayConst) continue; // Adjust the tile size to largest factor of the trip count less than @@ -122,7 +122,7 @@ void LoopTiling::getTileSizes(ArrayRef band, // the cache size. This is an approximation with the assumption that the // footprint increases with the tile size linearly in that dimension (i.e., // assumes one-to-one access function). - Optional fp = getMemoryFootprintBytes(band[0], 0); + std::optional fp = getMemoryFootprintBytes(band[0], 0); if (!fp) { // Fill with default tile sizes if footprint is unknown. std::fill(tileSizes->begin(), tileSizes->end(), diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp index a1cbb91..825a368 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopUnroll.cpp @@ -52,7 +52,7 @@ struct LoopUnroll : public impl::AffineLoopUnrollBase { = default; explicit LoopUnroll( - Optional unrollFactor = std::nullopt, + std::optional unrollFactor = std::nullopt, bool unrollUpToFactor = false, bool unrollFull = false, const std::function &getUnrollFactor = nullptr) : getUnrollFactor(getUnrollFactor) { @@ -100,7 +100,7 @@ void LoopUnroll::runOnOperation() { // so that loops are gathered from innermost to outermost (or else unrolling // an outer one may delete gathered inner ones). getOperation().walk([&](AffineForOp forOp) { - Optional tripCount = getConstantTripCount(forOp); + std::optional tripCount = getConstantTripCount(forOp); if (tripCount && *tripCount <= unrollFullThreshold) loops.push_back(forOp); }); @@ -146,6 +146,6 @@ std::unique_ptr> mlir::createLoopUnrollPass( int unrollFactor, bool unrollUpToFactor, bool unrollFull, const std::function &getUnrollFactor) { return std::make_unique( - unrollFactor == -1 ? std::nullopt : Optional(unrollFactor), + unrollFactor == -1 ? std::nullopt : std::optional(unrollFactor), unrollUpToFactor, unrollFull, getUnrollFactor); } diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp index 55d580b..a0fad4d 100644 --- a/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/LoopUnrollAndJam.cpp @@ -62,7 +62,8 @@ namespace { /// outer loop in a Function. struct LoopUnrollAndJam : public impl::AffineLoopUnrollAndJamBase { - explicit LoopUnrollAndJam(Optional unrollJamFactor = std::nullopt) { + explicit LoopUnrollAndJam( + std::optional unrollJamFactor = std::nullopt) { if (unrollJamFactor) this->unrollJamFactor = *unrollJamFactor; } @@ -75,7 +76,7 @@ std::unique_ptr> mlir::createLoopUnrollAndJamPass(int unrollJamFactor) { return std::make_unique( unrollJamFactor == -1 ? std::nullopt - : Optional(unrollJamFactor)); + : std::optional(unrollJamFactor)); } void LoopUnrollAndJam::runOnOperation() { diff --git a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp index a650395..30affbb 100644 --- a/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp @@ -582,7 +582,7 @@ isVectorizableLoopPtrFactory(const DenseSet ¶llelLoops, /// Up to 3-D patterns are supported. /// If the command line argument requests a pattern of higher order, returns an /// empty pattern list which will conservatively result in no vectorization. -static Optional +static std::optional makePattern(const DenseSet ¶llelLoops, int vectorRank, ArrayRef fastestVaryingPattern) { using matcher::For; @@ -1666,7 +1666,7 @@ static void vectorizeLoops(Operation *parentOp, DenseSet &loops, "Vectorizing reductions is supported only for 1-D vectors"); // Compute 1-D, 2-D or 3-D loop pattern to be matched on the target loops. - Optional pattern = + std::optional pattern = makePattern(loops, vectorSizes.size(), fastestVaryingPattern); if (!pattern) { LLVM_DEBUG(dbgs() << "\n[early-vect] pattern couldn't be computed\n"); diff --git a/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp index 59fdeb8..366c090 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp @@ -358,7 +358,7 @@ FusionResult mlir::canFuseLoops(AffineForOp srcForOp, AffineForOp dstForOp, LogicalResult promoteSingleIterReductionLoop(AffineForOp forOp, bool siblingFusionUser) { // Check if the reduction loop is a single iteration loop. - Optional tripCount = getConstantTripCount(forOp); + std::optional tripCount = getConstantTripCount(forOp); if (!tripCount || *tripCount != 1) return failure(); auto iterOperands = forOp.getIterOperands(); @@ -491,7 +491,7 @@ bool mlir::getLoopNestStats(AffineForOp forOpRoot, LoopNestStats *stats) { // Record trip count for 'forOp'. Set flag if trip count is not // constant. - Optional maybeConstTripCount = getConstantTripCount(forOp); + std::optional maybeConstTripCount = getConstantTripCount(forOp); if (!maybeConstTripCount) { // Currently only constant trip count loop nests are supported. LLVM_DEBUG(llvm::dbgs() << "Non-constant trip count unsupported\n"); diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp index 9b3ec21..5860086 100644 --- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp @@ -130,7 +130,7 @@ static void replaceIterArgsAndYieldResults(AffineForOp forOp) { /// was known to have a single iteration. // TODO: extend this for arbitrary affine bounds. LogicalResult mlir::promoteIfSingleIteration(AffineForOp forOp) { - Optional tripCount = getConstantTripCount(forOp); + std::optional tripCount = getConstantTripCount(forOp); if (!tripCount || *tripCount != 1) return failure(); @@ -791,7 +791,8 @@ constructTiledIndexSetHyperRect(MutableArrayRef origLoops, // Bounds for intra-tile loops. for (unsigned i = 0; i < width; i++) { int64_t largestDiv = getLargestDivisorOfTripCount(origLoops[i]); - Optional mayBeConstantCount = getConstantTripCount(origLoops[i]); + std::optional mayBeConstantCount = + getConstantTripCount(origLoops[i]); // The lower bound is just the tile-space loop. AffineMap lbMap = b.getDimIdentityMap(); newLoops[width + i].setLowerBound( @@ -971,7 +972,7 @@ void mlir::getTileableBands(func::FuncOp f, /// Unrolls this loop completely. LogicalResult mlir::loopUnrollFull(AffineForOp forOp) { - Optional mayBeConstantTripCount = getConstantTripCount(forOp); + std::optional mayBeConstantTripCount = getConstantTripCount(forOp); if (mayBeConstantTripCount.has_value()) { uint64_t tripCount = *mayBeConstantTripCount; if (tripCount == 0) @@ -987,7 +988,7 @@ LogicalResult mlir::loopUnrollFull(AffineForOp forOp) { /// whichever is lower. LogicalResult mlir::loopUnrollUpToFactor(AffineForOp forOp, uint64_t unrollFactor) { - Optional mayBeConstantTripCount = getConstantTripCount(forOp); + std::optional mayBeConstantTripCount = getConstantTripCount(forOp); if (mayBeConstantTripCount.has_value() && *mayBeConstantTripCount < unrollFactor) return loopUnrollByFactor(forOp, *mayBeConstantTripCount); @@ -1093,7 +1094,7 @@ LogicalResult mlir::loopUnrollByFactor( bool cleanUpUnroll) { assert(unrollFactor > 0 && "unroll factor should be positive"); - Optional mayBeConstantTripCount = getConstantTripCount(forOp); + std::optional mayBeConstantTripCount = getConstantTripCount(forOp); if (unrollFactor == 1) { if (mayBeConstantTripCount && *mayBeConstantTripCount == 1 && failed(promoteIfSingleIteration(forOp))) @@ -1156,7 +1157,7 @@ LogicalResult mlir::loopUnrollByFactor( LogicalResult mlir::loopUnrollJamUpToFactor(AffineForOp forOp, uint64_t unrollJamFactor) { - Optional mayBeConstantTripCount = getConstantTripCount(forOp); + std::optional mayBeConstantTripCount = getConstantTripCount(forOp); if (mayBeConstantTripCount.has_value() && *mayBeConstantTripCount < unrollJamFactor) return loopUnrollJamByFactor(forOp, *mayBeConstantTripCount); @@ -1209,7 +1210,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp, uint64_t unrollJamFactor) { assert(unrollJamFactor > 0 && "unroll jam factor should be positive"); - Optional mayBeConstantTripCount = getConstantTripCount(forOp); + std::optional mayBeConstantTripCount = getConstantTripCount(forOp); if (unrollJamFactor == 1) { if (mayBeConstantTripCount && *mayBeConstantTripCount == 1 && failed(promoteIfSingleIteration(forOp))) @@ -2095,7 +2096,7 @@ static LogicalResult generateCopy( std::vector> lbs; SmallVector lbDivisors; lbs.reserve(rank); - Optional numElements = region.getConstantBoundingSizeAndShape( + std::optional numElements = region.getConstantBoundingSizeAndShape( &fastBufferShape, &lbs, &lbDivisors); if (!numElements) { LLVM_DEBUG(llvm::dbgs() << "Non-constant region size not supported\n"); @@ -2376,7 +2377,7 @@ static bool getFullMemRefAsRegion(Operation *op, unsigned numParamLoopIVs, LogicalResult mlir::affineDataCopyGenerate(Block::iterator begin, Block::iterator end, const AffineCopyOptions ©Options, - Optional filterMemRef, + std::optional filterMemRef, DenseSet ©Nests) { if (begin == end) return success(); @@ -2565,7 +2566,7 @@ LogicalResult mlir::affineDataCopyGenerate(Block::iterator begin, // an AffineForOp. LogicalResult mlir::affineDataCopyGenerate(AffineForOp forOp, const AffineCopyOptions ©Options, - Optional filterMemRef, + std::optional filterMemRef, DenseSet ©Nests) { return affineDataCopyGenerate(forOp.getBody()->begin(), std::prev(forOp.getBody()->end()), copyOptions, diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp index 9140031..180fef8 100644 --- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp @@ -217,10 +217,9 @@ mlir::Value mlir::expandAffineExpr(OpBuilder &builder, Location loc, /// Create a sequence of operations that implement the `affineMap` applied to /// the given `operands` (as it it were an AffineApplyOp). -Optional> mlir::expandAffineMap(OpBuilder &builder, - Location loc, - AffineMap affineMap, - ValueRange operands) { +std::optional> +mlir::expandAffineMap(OpBuilder &builder, Location loc, AffineMap affineMap, + ValueRange operands) { auto numDims = affineMap.getNumDims(); auto expanded = llvm::to_vector<8>( llvm::map_range(affineMap.getResults(), @@ -1817,7 +1816,7 @@ MemRefType mlir::normalizeMemRefType(MemRefType memrefType, newShape[d] = ShapedType::kDynamic; } else { // The lower bound for the shape is always zero. - Optional ubConst = + std::optional ubConst = fac.getConstantBound64(IntegerPolyhedron::UB, d); // For a static memref and an affine map with no symbols, this is // always bounded. However, when we have symbols, we may not be able to diff --git a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp index f56aefa..10d6ef2 100644 --- a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp +++ b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp @@ -20,7 +20,7 @@ using namespace mlir::arith; /// Function that evaluates the result of doing something on arithmetic /// constants and returns std::nullopt on overflow. using ConstArithFn = - function_ref(const APInt &, const APInt &)>; + function_ref(const APInt &, const APInt &)>; /// Return the maxmially wide signed or unsigned range for a given bitwidth. @@ -30,8 +30,8 @@ static ConstantIntRanges computeBoundsBy(ConstArithFn op, const APInt &minLeft, const APInt &minRight, const APInt &maxLeft, const APInt &maxRight, bool isSigned) { - Optional maybeMin = op(minLeft, minRight); - Optional maybeMax = op(maxLeft, maxRight); + std::optional maybeMin = op(minLeft, minRight); + std::optional maybeMax = op(maxLeft, maxRight); if (maybeMin && maybeMax) return ConstantIntRanges::range(*maybeMin, *maybeMax, isSigned); return ConstantIntRanges::maxRange(minLeft.getBitWidth()); @@ -48,7 +48,7 @@ static ConstantIntRanges minMaxBy(ConstArithFn op, ArrayRef lhs, isSigned ? APInt::getSignedMinValue(width) : APInt::getZero(width); for (const APInt &left : lhs) { for (const APInt &right : rhs) { - Optional maybeThisResult = op(left, right); + std::optional maybeThisResult = op(left, right); if (!maybeThisResult) return ConstantIntRanges::maxRange(width); APInt result = std::move(*maybeThisResult); @@ -79,15 +79,17 @@ void arith::ConstantOp::inferResultRanges(ArrayRef argRanges, void arith::AddIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn uadd = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn uadd = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.uadd_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; - ConstArithFn sadd = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn sadd = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.sadd_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; ConstantIntRanges urange = computeBoundsBy( @@ -105,15 +107,17 @@ void arith::SubIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn usub = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn usub = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.usub_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; - ConstArithFn ssub = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn ssub = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.ssub_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; ConstantIntRanges urange = computeBoundsBy( usub, lhs.umin(), rhs.umax(), lhs.umax(), rhs.umin(), /*isSigned=*/false); @@ -130,15 +134,17 @@ void arith::MulIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn umul = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn umul = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.umul_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; - ConstArithFn smul = [](const APInt &a, const APInt &b) -> Optional { + ConstArithFn smul = [](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.smul_ov(b, overflowed); - return overflowed ? Optional() : result; + return overflowed ? std::optional() : result; }; ConstantIntRanges urange = @@ -157,7 +163,7 @@ void arith::MulIOp::inferResultRanges(ArrayRef argRanges, /// Fix up division results (ex. for ceiling and floor), returning an APInt /// if there has been no overflow -using DivisionFixupFn = function_ref( +using DivisionFixupFn = function_ref( const APInt &lhs, const APInt &rhs, const APInt &result)>; static ConstantIntRanges inferDivUIRange(const ConstantIntRanges &lhs, @@ -167,7 +173,8 @@ static ConstantIntRanges inferDivUIRange(const ConstantIntRanges &lhs, &rhsMax = rhs.umax(); if (!rhsMin.isZero()) { - auto udiv = [&fixup](const APInt &a, const APInt &b) -> Optional { + auto udiv = [&fixup](const APInt &a, + const APInt &b) -> std::optional { return fixup(a, b, a.udiv(b)); }; return minMaxBy(udiv, {lhsMin, lhsMax}, {rhsMin, rhsMax}, @@ -197,10 +204,11 @@ static ConstantIntRanges inferDivSIRange(const ConstantIntRanges &lhs, bool canDivide = rhsMin.isStrictlyPositive() || rhsMax.isNegative(); if (canDivide) { - auto sdiv = [&fixup](const APInt &a, const APInt &b) -> Optional { + auto sdiv = [&fixup](const APInt &a, + const APInt &b) -> std::optional { bool overflowed = false; APInt result = a.sdiv_ov(b, overflowed); - return overflowed ? Optional() : fixup(a, b, result); + return overflowed ? std::optional() : fixup(a, b, result); }; return minMaxBy(sdiv, {lhsMin, lhsMax}, {rhsMin, rhsMax}, /*isSigned=*/true); @@ -224,13 +232,14 @@ void arith::CeilDivUIOp::inferResultRanges( ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - DivisionFixupFn ceilDivUIFix = [](const APInt &lhs, const APInt &rhs, - const APInt &result) -> Optional { + DivisionFixupFn ceilDivUIFix = + [](const APInt &lhs, const APInt &rhs, + const APInt &result) -> std::optional { if (!lhs.urem(rhs).isZero()) { bool overflowed = false; APInt corrected = result.uadd_ov(APInt(result.getBitWidth(), 1), overflowed); - return overflowed ? Optional() : corrected; + return overflowed ? std::optional() : corrected; } return result; }; @@ -245,13 +254,14 @@ void arith::CeilDivSIOp::inferResultRanges( ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - DivisionFixupFn ceilDivSIFix = [](const APInt &lhs, const APInt &rhs, - const APInt &result) -> Optional { + DivisionFixupFn ceilDivSIFix = + [](const APInt &lhs, const APInt &rhs, + const APInt &result) -> std::optional { if (!lhs.srem(rhs).isZero() && lhs.isNonNegative() == rhs.isNonNegative()) { bool overflowed = false; APInt corrected = result.sadd_ov(APInt(result.getBitWidth(), 1), overflowed); - return overflowed ? Optional() : corrected; + return overflowed ? std::optional() : corrected; } return result; }; @@ -266,13 +276,14 @@ void arith::FloorDivSIOp::inferResultRanges( ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - DivisionFixupFn floorDivSIFix = [](const APInt &lhs, const APInt &rhs, - const APInt &result) -> Optional { + DivisionFixupFn floorDivSIFix = + [](const APInt &lhs, const APInt &rhs, + const APInt &result) -> std::optional { if (!lhs.srem(rhs).isZero() && lhs.isNonNegative() != rhs.isNonNegative()) { bool overflowed = false; APInt corrected = result.ssub_ov(APInt(result.getBitWidth(), 1), overflowed); - return overflowed ? Optional() : corrected; + return overflowed ? std::optional() : corrected; } return result; }; @@ -371,7 +382,7 @@ void arith::AndIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]); auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]); - auto andi = [](const APInt &a, const APInt &b) -> Optional { + auto andi = [](const APInt &a, const APInt &b) -> std::optional { return a & b; }; setResultRange(getResult(), @@ -387,7 +398,7 @@ void arith::OrIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]); auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]); - auto ori = [](const APInt &a, const APInt &b) -> Optional { + auto ori = [](const APInt &a, const APInt &b) -> std::optional { return a | b; }; setResultRange(getResult(), @@ -403,7 +414,7 @@ void arith::XOrIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { auto [lhsZeros, lhsOnes] = widenBitwiseBounds(argRanges[0]); auto [rhsZeros, rhsOnes] = widenBitwiseBounds(argRanges[1]); - auto xori = [](const APInt &a, const APInt &b) -> Optional { + auto xori = [](const APInt &a, const APInt &b) -> std::optional { return a ^ b; }; setResultRange(getResult(), @@ -604,8 +615,8 @@ bool isStaticallyTrue(arith::CmpIPredicate pred, const ConstantIntRanges &lhs, case arith::CmpIPredicate::ugt: return applyCmpPredicate(pred, lhs.umin(), rhs.umax()); case arith::CmpIPredicate::eq: { - Optional lhsConst = lhs.getConstantValue(); - Optional rhsConst = rhs.getConstantValue(); + std::optional lhsConst = lhs.getConstantValue(); + std::optional rhsConst = rhs.getConstantValue(); return lhsConst && rhsConst && lhsConst == rhsConst; } case arith::CmpIPredicate::ne: { @@ -644,7 +655,7 @@ void arith::CmpIOp::inferResultRanges(ArrayRef argRanges, void arith::SelectOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { - Optional mbCondVal = argRanges[0].getConstantValue(); + std::optional mbCondVal = argRanges[0].getConstantValue(); if (mbCondVal) { if (mbCondVal->isZero()) @@ -663,8 +674,9 @@ void arith::SelectOp::inferResultRanges(ArrayRef argRanges, void arith::ShLIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn shl = [](const APInt &l, const APInt &r) -> Optional { - return r.uge(r.getBitWidth()) ? Optional() : l.shl(r); + ConstArithFn shl = [](const APInt &l, + const APInt &r) -> std::optional { + return r.uge(r.getBitWidth()) ? std::optional() : l.shl(r); }; ConstantIntRanges urange = minMaxBy(shl, {lhs.umin(), lhs.umax()}, {rhs.umin(), rhs.umax()}, @@ -683,8 +695,9 @@ void arith::ShRUIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn lshr = [](const APInt &l, const APInt &r) -> Optional { - return r.uge(r.getBitWidth()) ? Optional() : l.lshr(r); + ConstArithFn lshr = [](const APInt &l, + const APInt &r) -> std::optional { + return r.uge(r.getBitWidth()) ? std::optional() : l.lshr(r); }; setResultRange(getResult(), minMaxBy(lshr, {lhs.umin(), lhs.umax()}, {rhs.umin(), rhs.umax()}, @@ -699,8 +712,9 @@ void arith::ShRSIOp::inferResultRanges(ArrayRef argRanges, SetIntRangeFn setResultRange) { const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1]; - ConstArithFn ashr = [](const APInt &l, const APInt &r) -> Optional { - return r.uge(r.getBitWidth()) ? Optional() : l.ashr(r); + ConstArithFn ashr = [](const APInt &l, + const APInt &r) -> std::optional { + return r.uge(r.getBitWidth()) ? std::optional() : l.ashr(r); }; setResultRange(getResult(), diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp index 92bc5ee..d07204d 100644 --- a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp +++ b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp @@ -88,7 +88,7 @@ struct CoroMachinery { // %0 = arith.constant ... : T // async.yield %0 : T // } - Optional asyncToken; // returned completion token + std::optional asyncToken; // returned completion token llvm::SmallVector returnValues; // returned async values Value coroHandle; // coroutine handle (!async.coro.getHandle value) @@ -163,7 +163,7 @@ static CoroMachinery setupCoroMachinery(func::FuncOp func) { // async computations bool isStateful = func.getCallableResults().front().isa(); - Optional retToken; + std::optional retToken; if (isStateful) retToken.emplace(builder.create(TokenType::get(ctx))); diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp index ca9aa68..e6f93d6 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -485,12 +485,12 @@ struct SimplifyClones : public OpRewritePattern { canonicalSource.getDefiningOp())) canonicalSource = iface.getViewSource(); - llvm::Optional maybeCloneDeallocOp = + std::optional maybeCloneDeallocOp = memref::findDealloc(cloneOp.getOutput()); // Skip if either of them has > 1 deallocate operations. if (!maybeCloneDeallocOp.has_value()) return failure(); - llvm::Optional maybeSourceDeallocOp = + std::optional maybeSourceDeallocOp = memref::findDealloc(canonicalSource); if (!maybeSourceDeallocOp.has_value()) return failure(); diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp index 49a6004..38d6919 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp @@ -79,7 +79,7 @@ void BufferPlacementAllocs::build(Operation *op) { // Get allocation result. Value allocValue = allocateResultEffects[0].getValue(); // Find the associated dealloc value and register the allocation entry. - llvm::Optional dealloc = memref::findDealloc(allocValue); + std::optional dealloc = memref::findDealloc(allocValue); // If the allocation has > 1 dealloc associated with it, skip handling it. if (!dealloc) return; diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp index 1bc3968..48f192a 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp @@ -277,7 +277,7 @@ struct OneShotBufferizePass } private: - llvm::Optional options; + std::optional options; }; } // namespace diff --git a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp index f67cde9..34cdf14 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp @@ -127,9 +127,9 @@ static FuncOpAnalysisState getFuncOpAnalysisState(const AnalysisState &state, /// Return the index of the bbArg in the given FuncOp that is equivalent to the /// specified return value (if any). -static Optional getEquivalentFuncArgIdx(FuncOp funcOp, - const FuncAnalysisState &state, - int64_t returnValIdx) { +static std::optional +getEquivalentFuncArgIdx(FuncOp funcOp, const FuncAnalysisState &state, + int64_t returnValIdx) { auto funcOpIt = state.equivalentFuncArgs.find(funcOp); if (funcOpIt == state.equivalentFuncArgs.end()) // No equivalence info stores for funcOp. @@ -240,7 +240,7 @@ struct CallOpInterface } const FuncAnalysisState &funcState = getFuncAnalysisState(state); - Optional maybeEquiv = + std::optional maybeEquiv = getEquivalentFuncArgIdx(funcOp, funcState, opResult.getResultNumber()); if (maybeEquiv) { #ifndef NDEBUG @@ -274,7 +274,8 @@ struct CallOpInterface SmallVector replacementValues(numResults, Value()); // For non-tensor results: A mapping from return val indices of the old // CallOp to return val indices of the bufferized CallOp. - SmallVector> retValMapping(numResults, std::nullopt); + SmallVector> retValMapping(numResults, + std::nullopt); // Operands of the bufferized CallOp. SmallVector newOperands(numOperands, Value()); diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp index 2ceb2bf..11ec604 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp @@ -455,7 +455,7 @@ bool canUseOpDominance(const DenseSet &usesRead, const DenseSet &usesWrite, const AnalysisState &state) { const BufferizationOptions &options = state.getOptions(); - Optional commonEnclosingRegion = std::nullopt; + std::optional commonEnclosingRegion = std::nullopt; // In case of a write, take the region in which the write takes place. for (OpOperand *uWrite : usesWrite) { diff --git a/mlir/lib/Dialect/GPU/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/GPU/IR/InferIntRangeInterfaceImpls.cpp index aacd8d5..cb2d66d 100644 --- a/mlir/lib/Dialect/GPU/IR/InferIntRangeInterfaceImpls.cpp +++ b/mlir/lib/Dialect/GPU/IR/InferIntRangeInterfaceImpls.cpp @@ -53,7 +53,7 @@ static Value valueByDim(KernelDim3 dims, Dimension dim) { static uint64_t zext(uint32_t arg) { return static_cast(arg); } template -static Optional getKnownLaunchDim(Op op, LaunchDims type) { +static std::optional getKnownLaunchDim(Op op, LaunchDims type) { Dimension dim = op.getDimension(); if (auto launch = op->template getParentOfType()) { KernelDim3 bounds; @@ -84,7 +84,8 @@ static Optional getKnownLaunchDim(Op op, LaunchDims type) { void BlockDimOp::inferResultRanges(ArrayRef, SetIntRangeFn setResultRange) { - Optional knownVal = getKnownLaunchDim(*this, LaunchDims::Block); + std::optional knownVal = + getKnownLaunchDim(*this, LaunchDims::Block); if (knownVal) setResultRange(getResult(), getIndexRange(*knownVal, *knownVal)); else @@ -99,7 +100,7 @@ void BlockIdOp::inferResultRanges(ArrayRef, void GridDimOp::inferResultRanges(ArrayRef, SetIntRangeFn setResultRange) { - Optional knownVal = getKnownLaunchDim(*this, LaunchDims::Grid); + std::optional knownVal = getKnownLaunchDim(*this, LaunchDims::Grid); if (knownVal) setResultRange(getResult(), getIndexRange(*knownVal, *knownVal)); else diff --git a/mlir/lib/Dialect/GPU/Transforms/LowerMemorySpaceAttributes.cpp b/mlir/lib/Dialect/GPU/Transforms/LowerMemorySpaceAttributes.cpp index 40c2647..9579111 100644 --- a/mlir/lib/Dialect/GPU/Transforms/LowerMemorySpaceAttributes.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/LowerMemorySpaceAttributes.cpp @@ -80,7 +80,7 @@ IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space) { void mlir::gpu::populateMemorySpaceAttributeTypeConversions( TypeConverter &typeConverter, const MemorySpaceMapping &mapping) { - typeConverter.addConversion([mapping](Type type) -> Optional { + typeConverter.addConversion([mapping](Type type) -> std::optional { auto subElementType = type.dyn_cast_or_null(); if (!subElementType) return type; diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp index 7520e85..3c4f005 100644 --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp @@ -36,7 +36,7 @@ gpu::SerializeToBlobPass::SerializeToBlobPass(TypeID passID) gpu::SerializeToBlobPass::SerializeToBlobPass(const SerializeToBlobPass &other) : OperationPass(other) {} -Optional +std::optional gpu::SerializeToBlobPass::translateToISA(llvm::Module &llvmModule, llvm::TargetMachine &targetMachine) { llvmModule.setDataLayout(targetMachine.createDataLayout()); @@ -73,7 +73,7 @@ void gpu::SerializeToBlobPass::runOnOperation() { if (!targetMachine) return signalPassFailure(); - Optional maybeTargetISA = + std::optional maybeTargetISA = translateToISA(*llvmModule, *targetMachine); if (!maybeTargetISA.has_value()) diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp index 63c9aac..42cb246 100644 --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp @@ -94,7 +94,7 @@ private: void getDependentDialects(DialectRegistry ®istry) const override; // Loads LLVM bitcode libraries - Optional, 3>> + std::optional, 3>> loadLibraries(SmallVectorImpl &path, SmallVectorImpl &libraries, llvm::LLVMContext &context); @@ -146,7 +146,7 @@ void SerializeToHsacoPass::getDependentDialects( gpu::SerializeToBlobPass::getDependentDialects(registry); } -Optional, 3>> +std::optional, 3>> SerializeToHsacoPass::loadLibraries(SmallVectorImpl &path, SmallVectorImpl &libraries, llvm::LLVMContext &context) { @@ -278,7 +278,7 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) { if (needOckl) libraries.push_back("ockl.bc"); - Optional, 3>> mbModules; + std::optional, 3>> mbModules; std::string theRocmPath = getRocmPath(); llvm::SmallString<32> bitcodePath(theRocmPath); llvm::sys::path::append(bitcodePath, "amdgcn", "bitcode"); diff --git a/mlir/lib/Dialect/Index/IR/IndexOps.cpp b/mlir/lib/Dialect/Index/IR/IndexOps.cpp index 8033c13..7f7cc50 100644 --- a/mlir/lib/Dialect/Index/IR/IndexOps.cpp +++ b/mlir/lib/Dialect/Index/IR/IndexOps.cpp @@ -64,14 +64,15 @@ Operation *IndexDialect::materializeConstant(OpBuilder &b, Attribute value, /// the integer result, which in turn must satisfy the above property. static OpFoldResult foldBinaryOpUnchecked( ArrayRef operands, - function_ref(const APInt &, const APInt &)> calculate) { + function_ref(const APInt &, const APInt &)> + calculate) { assert(operands.size() == 2 && "binary operation expected 2 operands"); auto lhs = dyn_cast_if_present(operands[0]); auto rhs = dyn_cast_if_present(operands[1]); if (!lhs || !rhs) return {}; - Optional result = calculate(lhs.getValue(), rhs.getValue()); + std::optional result = calculate(lhs.getValue(), rhs.getValue()); if (!result) return {}; assert(result->trunc(32) == @@ -89,7 +90,8 @@ static OpFoldResult foldBinaryOpUnchecked( /// not folded. static OpFoldResult foldBinaryOpChecked( ArrayRef operands, - function_ref(const APInt &, const APInt &lhs)> calculate) { + function_ref(const APInt &, const APInt &lhs)> + calculate) { assert(operands.size() == 2 && "binary operation expected 2 operands"); auto lhs = dyn_cast_if_present(operands[0]); auto rhs = dyn_cast_if_present(operands[1]); @@ -98,10 +100,10 @@ static OpFoldResult foldBinaryOpChecked( return {}; // Compute the 64-bit result and the 32-bit result. - Optional result64 = calculate(lhs.getValue(), rhs.getValue()); + std::optional result64 = calculate(lhs.getValue(), rhs.getValue()); if (!result64) return {}; - Optional result32 = + std::optional result32 = calculate(lhs.getValue().trunc(32), rhs.getValue().trunc(32)); if (!result32) return {}; @@ -149,7 +151,7 @@ OpFoldResult MulOp::fold(FoldAdaptor adaptor) { OpFoldResult DivSOp::fold(FoldAdaptor adaptor) { return foldBinaryOpChecked( adaptor.getOperands(), - [](const APInt &lhs, const APInt &rhs) -> Optional { + [](const APInt &lhs, const APInt &rhs) -> std::optional { // Don't fold division by zero. if (rhs.isZero()) return std::nullopt; @@ -164,7 +166,7 @@ OpFoldResult DivSOp::fold(FoldAdaptor adaptor) { OpFoldResult DivUOp::fold(FoldAdaptor adaptor) { return foldBinaryOpChecked( adaptor.getOperands(), - [](const APInt &lhs, const APInt &rhs) -> Optional { + [](const APInt &lhs, const APInt &rhs) -> std::optional { // Don't fold division by zero. if (rhs.isZero()) return std::nullopt; @@ -178,7 +180,7 @@ OpFoldResult DivUOp::fold(FoldAdaptor adaptor) { /// Compute `ceildivs(n, m)` as `x = m > 0 ? -1 : 1` and then /// `n*m > 0 ? (n+x)/m + 1 : -(-n/m)`. -static Optional calculateCeilDivS(const APInt &n, const APInt &m) { +static std::optional calculateCeilDivS(const APInt &n, const APInt &m) { // Don't fold division by zero. if (m.isZero()) return std::nullopt; @@ -211,7 +213,7 @@ OpFoldResult CeilDivUOp::fold(FoldAdaptor adaptor) { // Compute `ceildivu(n, m)` as `n == 0 ? 0 : (n-1)/m + 1`. return foldBinaryOpChecked( adaptor.getOperands(), - [](const APInt &n, const APInt &m) -> Optional { + [](const APInt &n, const APInt &m) -> std::optional { // Don't fold division by zero. if (m.isZero()) return std::nullopt; @@ -229,7 +231,7 @@ OpFoldResult CeilDivUOp::fold(FoldAdaptor adaptor) { /// Compute `floordivs(n, m)` as `x = m < 0 ? 1 : -1` and then /// `n*m < 0 ? -1 - (x-n)/m : n/m`. -static Optional calculateFloorDivS(const APInt &n, const APInt &m) { +static std::optional calculateFloorDivS(const APInt &n, const APInt &m) { // Don't fold division by zero. if (m.isZero()) return std::nullopt; @@ -322,7 +324,7 @@ OpFoldResult MinUOp::fold(FoldAdaptor adaptor) { OpFoldResult ShlOp::fold(FoldAdaptor adaptor) { return foldBinaryOpUnchecked( adaptor.getOperands(), - [](const APInt &lhs, const APInt &rhs) -> Optional { + [](const APInt &lhs, const APInt &rhs) -> std::optional { // We cannot fold if the RHS is greater than or equal to 32 because // this would be UB in 32-bit systems but not on 64-bit systems. RHS is // already treated as unsigned. @@ -339,7 +341,7 @@ OpFoldResult ShlOp::fold(FoldAdaptor adaptor) { OpFoldResult ShrSOp::fold(FoldAdaptor adaptor) { return foldBinaryOpChecked( adaptor.getOperands(), - [](const APInt &lhs, const APInt &rhs) -> Optional { + [](const APInt &lhs, const APInt &rhs) -> std::optional { // Don't fold if RHS is greater than or equal to 32. if (rhs.uge(32)) return {}; @@ -354,7 +356,7 @@ OpFoldResult ShrSOp::fold(FoldAdaptor adaptor) { OpFoldResult ShrUOp::fold(FoldAdaptor adaptor) { return foldBinaryOpChecked( adaptor.getOperands(), - [](const APInt &lhs, const APInt &rhs) -> Optional { + [](const APInt &lhs, const APInt &rhs) -> std::optional { // Don't fold if RHS is greater than or equal to 32. if (rhs.uge(32)) return {}; diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index ca5e93f..2f06d92 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -93,8 +93,8 @@ LoopOptionsAttrBuilder::LoopOptionsAttrBuilder(LoopOptionsAttr attr) : options(attr.getOptions().begin(), attr.getOptions().end()) {} template -LoopOptionsAttrBuilder &LoopOptionsAttrBuilder::setOption(LoopOptionCase tag, - Optional value) { +LoopOptionsAttrBuilder & +LoopOptionsAttrBuilder::setOption(LoopOptionCase tag, std::optional value) { auto option = llvm::find_if( options, [tag](auto option) { return option.first == tag; }); if (option != options.end()) { @@ -109,35 +109,35 @@ LoopOptionsAttrBuilder &LoopOptionsAttrBuilder::setOption(LoopOptionCase tag, } LoopOptionsAttrBuilder & -LoopOptionsAttrBuilder::setDisableLICM(Optional value) { +LoopOptionsAttrBuilder::setDisableLICM(std::optional value) { return setOption(LoopOptionCase::disable_licm, value); } /// Set the `interleave_count` option to the provided value. If no value /// is provided the option is deleted. LoopOptionsAttrBuilder & -LoopOptionsAttrBuilder::setInterleaveCount(Optional count) { +LoopOptionsAttrBuilder::setInterleaveCount(std::optional count) { return setOption(LoopOptionCase::interleave_count, count); } /// Set the `disable_unroll` option to the provided value. If no value /// is provided the option is deleted. LoopOptionsAttrBuilder & -LoopOptionsAttrBuilder::setDisableUnroll(Optional value) { +LoopOptionsAttrBuilder::setDisableUnroll(std::optional value) { return setOption(LoopOptionCase::disable_unroll, value); } /// Set the `disable_pipeline` option to the provided value. If no value /// is provided the option is deleted. LoopOptionsAttrBuilder & -LoopOptionsAttrBuilder::setDisablePipeline(Optional value) { +LoopOptionsAttrBuilder::setDisablePipeline(std::optional value) { return setOption(LoopOptionCase::disable_pipeline, value); } /// Set the `pipeline_initiation_interval` option to the provided value. /// If no value is provided the option is deleted. LoopOptionsAttrBuilder &LoopOptionsAttrBuilder::setPipelineInitiationInterval( - Optional count) { + std::optional count) { return setOption(LoopOptionCase::pipeline_initiation_interval, count); } @@ -146,7 +146,7 @@ LoopOptionsAttrBuilder &LoopOptionsAttrBuilder::setPipelineInitiationInterval( //===----------------------------------------------------------------------===// template -static Optional +static std::optional getOption(ArrayRef> options, LoopOptionCase option) { auto it = @@ -158,15 +158,15 @@ getOption(ArrayRef> options, return static_cast(it->second); } -Optional LoopOptionsAttr::disableUnroll() { +std::optional LoopOptionsAttr::disableUnroll() { return getOption(getOptions(), LoopOptionCase::disable_unroll); } -Optional LoopOptionsAttr::disableLICM() { +std::optional LoopOptionsAttr::disableLICM() { return getOption(getOptions(), LoopOptionCase::disable_licm); } -Optional LoopOptionsAttr::interleaveCount() { +std::optional LoopOptionsAttr::interleaveCount() { return getOption(getOptions(), LoopOptionCase::interleave_count); } diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index ac3da63..54cdf98 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -209,7 +209,7 @@ ParseResult AllocaOp::parse(OpAsmParser &parser, OperationState &result) { parser.getCurrentLocation(&trailingTypeLoc) || parser.parseType(type)) return failure(); - Optional alignmentAttr = + std::optional alignmentAttr = result.attributes.getNamed("alignment"); if (alignmentAttr.has_value()) { auto alignmentInt = alignmentAttr->getValue().dyn_cast(); @@ -782,8 +782,8 @@ void LoadOp::print(OpAsmPrinter &p) { // Extract the pointee type from the LLVM pointer type wrapped in MLIR. Return // the resulting type if any, null type if opaque pointers are used, and // std::nullopt if the given type is not the pointer type. -static Optional getLoadStoreElementType(OpAsmParser &parser, Type type, - SMLoc trailingTypeLoc) { +static std::optional +getLoadStoreElementType(OpAsmParser &parser, Type type, SMLoc trailingTypeLoc) { auto llvmTy = type.dyn_cast(); if (!llvmTy) { parser.emitError(trailingTypeLoc, "expected LLVM pointer type"); @@ -808,7 +808,7 @@ ParseResult LoadOp::parse(OpAsmParser &parser, OperationState &result) { parser.resolveOperand(addr, type, result.operands)) return failure(); - Optional elemTy = + std::optional elemTy = getLoadStoreElementType(parser, type, trailingTypeLoc); if (!elemTy) return failure(); @@ -877,7 +877,7 @@ ParseResult StoreOp::parse(OpAsmParser &parser, OperationState &result) { if (parser.parseType(type)) return failure(); } else { - Optional maybeOperandType = + std::optional maybeOperandType = getLoadStoreElementType(parser, type, trailingTypeLoc); if (!maybeOperandType) return failure(); @@ -1993,7 +1993,7 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result, bool dsoLocal, CConv cconv, ArrayRef attrs, ArrayRef argAttrs, - Optional functionEntryCount) { + std::optional functionEntryCount) { result.addRegion(); result.addAttribute(SymbolTable::getSymbolAttrName(), builder.getStringAttr(name)); @@ -2932,7 +2932,7 @@ LogicalResult LLVMDialect::verifyOperationAttribute(Operation *op, if (!loopAttr) return op->emitOpError() << "expected '" << LLVMDialect::getLoopAttrName() << "' to be a dictionary attribute"; - Optional parallelAccessGroup = + std::optional parallelAccessGroup = loopAttr.getNamed(LLVMDialect::getParallelAccessAttrName()); if (parallelAccessGroup) { auto accessGroups = parallelAccessGroup->getValue().dyn_cast(); @@ -2961,7 +2961,7 @@ LogicalResult LLVMDialect::verifyOperationAttribute(Operation *op, } } - Optional loopOptions = + std::optional loopOptions = loopAttr.getNamed(LLVMDialect::getLoopOptionsAttrName()); if (loopOptions && !loopOptions->getValue().isa()) return op->emitOpError() diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp index 3d59a63..8c27ee9 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp @@ -267,8 +267,8 @@ LLVMPointerType::verify(function_ref emitError, constexpr const static unsigned kDefaultPointerSizeBits = 64; constexpr const static unsigned kDefaultPointerAlignment = 8; -Optional mlir::LLVM::extractPointerSpecValue(Attribute attr, - PtrDLEntryPos pos) { +std::optional mlir::LLVM::extractPointerSpecValue(Attribute attr, + PtrDLEntryPos pos) { auto spec = attr.cast(); auto idx = static_cast(pos); if (idx >= spec.size()) @@ -280,7 +280,7 @@ Optional mlir::LLVM::extractPointerSpecValue(Attribute attr, /// given `type` by interpreting the list of entries `params`. For the pointer /// type in the default address space, returns the default value if the entries /// do not provide a custom one, for other address spaces returns std::nullopt. -static Optional +static std::optional getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type, PtrDLEntryPos pos) { // First, look for the entry for the pointer in the current address space. @@ -312,7 +312,7 @@ getPointerDataLayoutEntry(DataLayoutEntryListRef params, LLVMPointerType type, unsigned LLVMPointerType::getTypeSizeInBits(const DataLayout &dataLayout, DataLayoutEntryListRef params) const { - if (Optional size = + if (std::optional size = getPointerDataLayoutEntry(params, *this, PtrDLEntryPos::Size)) return *size; @@ -325,7 +325,7 @@ LLVMPointerType::getTypeSizeInBits(const DataLayout &dataLayout, unsigned LLVMPointerType::getABIAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const { - if (Optional alignment = + if (std::optional alignment = getPointerDataLayoutEntry(params, *this, PtrDLEntryPos::Abi)) return *alignment; @@ -337,7 +337,7 @@ unsigned LLVMPointerType::getABIAlignment(const DataLayout &dataLayout, unsigned LLVMPointerType::getPreferredAlignment(const DataLayout &dataLayout, DataLayoutEntryListRef params) const { - if (Optional alignment = + if (std::optional alignment = getPointerDataLayoutEntry(params, *this, PtrDLEntryPos::Preferred)) return *alignment; @@ -531,7 +531,7 @@ namespace { enum class StructDLEntryPos { Abi = 0, Preferred = 1 }; } // namespace -static Optional +static std::optional getStructDataLayoutEntry(DataLayoutEntryListRef params, LLVMStructType type, StructDLEntryPos pos) { const auto *currentEntry = @@ -568,7 +568,7 @@ static unsigned calculateStructAlignment(const DataLayout &dataLayout, } // Entries are only allowed to be stricter than the required alignment - if (Optional entryResult = + if (std::optional entryResult = getStructDataLayoutEntry(params, type, pos)) return std::max(*entryResult / kBitsInByte, structAlignment); diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp index 2e3355e..60d6197 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -314,7 +314,7 @@ ParseResult MmaOp::parse(OpAsmParser &parser, OperationState &result) { "multiplicandBPtxType"}; for (unsigned idx = 0; idx < names.size(); idx++) { const auto &frag = frags[idx]; - Optional attr = namedAttributes.getNamed(names[idx]); + std::optional attr = namedAttributes.getNamed(names[idx]); if (!frag.elemtype.has_value() && !attr.has_value()) { return parser.emitError( parser.getNameLoc(), diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp index a758137..e411de6 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -95,7 +95,7 @@ static void fillStructuredOpRegion(OpBuilder &opBuilder, Region ®ion, /// The body of the operation is filled using `regionBuilder`. All ods-gen /// created structured operations use the method to implement their builders. static void buildStructuredOp(OpBuilder &b, OperationState &state, - llvm::Optional resultTensorTypes, + std::optional resultTensorTypes, ValueRange inputs, ValueRange outputs, ArrayRef attributes, RegionBuilderFn regionBuilder) { @@ -1767,7 +1767,7 @@ LogicalResult IndexOp::verify() { #define GET_OP_CLASSES #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" -AffineMap mlir::linalg::extractOrIdentityMap(Optional maybeMap, +AffineMap mlir::linalg::extractOrIdentityMap(std::optional maybeMap, unsigned rank, MLIRContext *context) { if (maybeMap) diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp index 6162387..1a7d7a1 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ConstantFold.cpp @@ -40,8 +40,8 @@ template class FoldConstantBase : public OpRewritePattern { public: struct APIntOrFloat { - Optional apInt; - Optional apFloat; + std::optional apInt; + std::optional apFloat; }; struct APIntOrFloatArray { SmallVector apInts; diff --git a/mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp b/mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp index 0c6e9fb..4805354 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp @@ -44,13 +44,13 @@ struct PackInfo { llvm::DenseMap tileToPointMapping; // The permutation of outer dims (on domain). SmallVector outerDimsOnDomainPerm; - Optional paddingValue; + std::optional paddingValue; }; static PackInfo getPackingInfoFromConsumer( AffineMap indexingMap, ArrayRef innerTileSizes, ArrayRef innerDimsPos, ArrayRef outerDimsPerm, - Optional paddingValue = std::nullopt) { + std::optional paddingValue = std::nullopt) { LLVM_DEBUG( { llvm::dbgs() << "--- Construct PackInfo From A Consumer ---\n"; }); PackInfo packInfo; diff --git a/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp b/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp index 56b44e9..1fe0ba4 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/DecomposeLinalgOps.cpp @@ -162,7 +162,7 @@ DecomposeLinalgOp::createPeeledGenericOp(GenericOp genericOp, // If the result is yielded by the original op, use the operand, indexing // map and result type that correspond to the yielded value. - Optional resultNumber; + std::optional resultNumber; for (auto *user : scalarOpResult.getUsers()) { if (auto yieldOp = dyn_cast(user)) { // Find the first use of the `scalarOpResult` in the yield op. diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp index de501a6..e9a8c83 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp @@ -713,7 +713,7 @@ static void updateExpandedGenericOpRegion(PatternRewriter &rewriter, /// Implements the fusion of a tensor.collapse_shape or a tensor.expand_shape op /// and a generic op as explained in `isFusableWithReshapeByExpansion`. Assumes /// that those conditions have been satisfied. -static Optional> +static std::optional> fuseWithReshapeByExpansion(GenericOp genericOp, Operation *reshapeOp, OpOperand *fusableOpOperand, PatternRewriter &rewriter) { @@ -876,7 +876,7 @@ public: (!controlFoldingReshapes(opOperand))) continue; - Optional> replacementValues = + std::optional> replacementValues = fuseWithReshapeByExpansion(genericOp, reshapeOp, opOperand, rewriter); if (!replacementValues) return failure(); @@ -928,9 +928,11 @@ struct FoldReshapeWithGenericOpByExpansion "fusion blocked by control function"); } - Optional> replacementValues = fuseWithReshapeByExpansion( - producer, reshapeOp, - producer.getDpsInitOperand(producerResult.getResultNumber()), rewriter); + std::optional> replacementValues = + fuseWithReshapeByExpansion( + producer, reshapeOp, + producer.getDpsInitOperand(producerResult.getResultNumber()), + rewriter); if (!replacementValues) { return rewriter.notifyMatchFailure(reshapeOp, "fusion by expansion failed"); @@ -1539,7 +1541,7 @@ public: continue; } - Optional> replacements = + std::optional> replacements = collapseGenericOpIterationDims(genericOp, collapsableIterationDims, rewriter); if (!replacements) { @@ -1573,8 +1575,9 @@ public: if (collapsableIterationDims.empty()) return failure(); - Optional> replacements = collapseGenericOpIterationDims( - genericOp, collapsableIterationDims, rewriter); + std::optional> replacements = + collapseGenericOpIterationDims(genericOp, collapsableIterationDims, + rewriter); if (!replacements) { return rewriter.notifyMatchFailure(genericOp, "failed to collapse dimensions"); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp index fa04cf5..e3b6e67 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Fusion.cpp @@ -299,7 +299,7 @@ findFusableProducer(OpOperand &consumerOpOperand, << elem.getIndexingValue() << " and " << elem.getDependentValue() << "\n"); Value v = elem.getIndexingValue(); - Optional operandNum = + std::optional operandNum = elem.getIndexingOpViewOperandNum(); return isa(elem.getDependentOp()) && v == consumerOpOperand.get() && operandNum && @@ -334,8 +334,8 @@ findFusableProducer(OpOperand &consumerOpOperand, FailureOr mlir::linalg::fuseProducerOfBuffer(OpBuilder &b, OpOperand &consumerOpOperand, const LinalgDependenceGraph &graph) { - Optional fusableDependence = - findFusableProducer(consumerOpOperand, graph); + std::optional + fusableDependence = findFusableProducer(consumerOpOperand, graph); if (!fusableDependence) return failure(); @@ -348,7 +348,7 @@ mlir::linalg::fuseProducerOfBuffer(OpBuilder &b, OpOperand &consumerOpOperand, fusableDependence->getDependentValue().getParentBlock()) return failure(); - Optional producerMap = + std::optional producerMap = fusableDependence->getDependentOpViewIndexingMap(); if (!producerMap) return failure(); diff --git a/mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp b/mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp index f6bd4de..8fbf8b2 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/FusionOnTensors.cpp @@ -275,7 +275,7 @@ bool TileLoopNest::hasOtherUses(BlockArgument bbArg, LogicalResult TileLoopNest::tileRootOp( OpBuilder &b, ArrayRef tileSizes, ArrayRef tileInterchange, - Optional tileDistribution) { + std::optional tileDistribution) { // Exit if all tile sizes are zero. if (tileSizes.size() == static_cast(count(tileSizes, 0))) return success(); diff --git a/mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp b/mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp index 3df9cad..f597273 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp @@ -65,7 +65,7 @@ FailureOr mlir::linalg::splitReduction( return b.notifyMatchFailure(op, "Cannot match the reduction pattern"); Operation *reductionOp = combinerOps[0]; - Optional identity = getNeutralElement(reductionOp); + std::optional identity = getNeutralElement(reductionOp); if (!identity.has_value()) return b.notifyMatchFailure(op, "Unknown identity value for the reduction"); @@ -269,7 +269,7 @@ FailureOr mlir::linalg::splitReductionByScaling( SmallVector neutralElements; for (Operation *reductionOp : combinerOps) { - Optional neutralElement = getNeutralElement(reductionOp); + std::optional neutralElement = getNeutralElement(reductionOp); if (!neutralElement.has_value()) return b.notifyMatchFailure(op, "cannot find neutral element."); neutralElements.push_back(*neutralElement); diff --git a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp index b542750..4e6777e 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp @@ -268,7 +268,7 @@ struct LinalgOpPartialReductionInterface return op->emitOpError("Failed to anaysis the reduction operation."); Operation *reductionOp = combinerOps[0]; - Optional identity = getNeutralElement(reductionOp); + std::optional identity = getNeutralElement(reductionOp); if (!identity.has_value()) return op->emitOpError( "Failed to get an identity value for the reduction operation."); diff --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp index f421d9a..0bb31e9 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp @@ -78,9 +78,9 @@ struct VectorizationState { /// masking. Returns the masked operation or the original operation if masking /// is not needed. If provided, the canonical mask for this operation is /// permuted using `maybeMaskingMap`. - Operation *maskOperation(RewriterBase &rewriter, Operation *opToMask, - LinalgOp linalgOp, - Optional maybeMaskingMap = std::nullopt); + Operation * + maskOperation(RewriterBase &rewriter, Operation *opToMask, LinalgOp linalgOp, + std::optional maybeMaskingMap = std::nullopt); private: /// Initializes the iteration space static sizes using the Linalg op @@ -101,7 +101,7 @@ private: /// cached for future users. Value getOrCreateMaskFor(RewriterBase &rewriter, Operation *opToMask, LinalgOp linalgOp, - Optional maybeMaskingMap); + std::optional maybeMaskingMap); // Holds the compile-time static sizes of the iteration space to vectorize. // Dynamic dimensions are represented using ShapedType::kDynamicSize. @@ -200,7 +200,7 @@ VectorizationState::initState(RewriterBase &rewriter, LinalgOp linalgOp, /// future users. Value VectorizationState::getOrCreateMaskFor( RewriterBase &rewriter, Operation *opToMask, LinalgOp linalgOp, - Optional maybeMaskingMap) { + std::optional maybeMaskingMap) { // No mask is needed if the operation is not maskable. auto maskableOp = dyn_cast(opToMask); if (!maskableOp) @@ -279,7 +279,7 @@ Value VectorizationState::getOrCreateMaskFor( Operation * VectorizationState::maskOperation(RewriterBase &rewriter, Operation *opToMask, LinalgOp linalgOp, - Optional maybeMaskingMap) { + std::optional maybeMaskingMap) { LDBG("Trying to mask: " << *opToMask << "\n"); // Create or retrieve mask for this operation. diff --git a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp index 4c36083..e02702a 100644 --- a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp @@ -103,7 +103,7 @@ static bool isTiled(AffineMap map, ArrayRef tileSizes) { return false; } -Optional +std::optional RegionMatcher::matchAsScalarBinaryOp(GenericOp op) { auto ®ion = op.getRegion(); if (!llvm::hasSingleElement(region)) @@ -930,7 +930,7 @@ SmallVector insertSlicesBack(OpBuilder &builder, Location loc, return tensorResults; } -SmallVector> +SmallVector> computeAllSliceParameters(OpBuilder &builder, Location loc, LinalgOp linalgOp, ValueRange valuesToTile, ArrayRef ivs, ArrayRef tileSizes, @@ -951,7 +951,7 @@ computeAllSliceParameters(OpBuilder &builder, Location loc, LinalgOp linalgOp, assert(static_cast(valuesToTile.size()) <= linalgOp->getNumOperands() && "more value to tile than operands."); - SmallVector> allSliceParams; + SmallVector> allSliceParams; allSliceParams.reserve(valuesToTile.size()); for (auto [opOperand, val] : llvm::zip(linalgOp->getOpOperands(), valuesToTile)) { @@ -988,13 +988,13 @@ SmallVector makeTiledShapes(OpBuilder &builder, Location loc, ArrayRef tileSizes, ArrayRef sizeBounds, bool omitPartialTileCheck) { - SmallVector> allSliceParameter = + SmallVector> allSliceParameter = computeAllSliceParameters(builder, loc, linalgOp, valuesToTile, ivs, tileSizes, sizeBounds, omitPartialTileCheck); SmallVector tiledShapes; for (auto item : llvm::zip(valuesToTile, allSliceParameter)) { Value valueToTile = std::get<0>(item); - Optional sliceParams = std::get<1>(item); + std::optional sliceParams = std::get<1>(item); tiledShapes.push_back( sliceParams.has_value() ? materializeTiledShape(builder, loc, valueToTile, *sliceParams) @@ -1038,7 +1038,7 @@ void offsetIndices(RewriterBase &b, LinalgOp linalgOp, /// and offset is 0. Strictly speaking the offset 0 is not required in general, /// but non-zero offsets are not handled by SPIR-V backend at this point (and /// potentially cannot be handled). -Optional> +std::optional> getReassociationMapForFoldingUnitDims(ArrayRef mixedSizes) { SmallVector reassociation; ReassociationIndices curr; @@ -1061,7 +1061,7 @@ getReassociationMapForFoldingUnitDims(ArrayRef mixedSizes) { } /// Return the identity numeric value associated to the give op. -Optional getNeutralElement(Operation *op) { +std::optional getNeutralElement(Operation *op) { // Builder only used as helper for attribute creation. OpBuilder b(op->getContext()); Type resultType = op->getResult(0).getType(); diff --git a/mlir/lib/Dialect/Math/IR/MathOps.cpp b/mlir/lib/Dialect/Math/IR/MathOps.cpp index f379b4c..0dc0414 100644 --- a/mlir/lib/Dialect/Math/IR/MathOps.cpp +++ b/mlir/lib/Dialect/Math/IR/MathOps.cpp @@ -46,7 +46,7 @@ OpFoldResult math::AbsIOp::fold(FoldAdaptor adaptor) { OpFoldResult math::AtanOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(atan(a.convertToDouble())); @@ -65,7 +65,7 @@ OpFoldResult math::AtanOp::fold(FoldAdaptor adaptor) { OpFoldResult math::Atan2Op::fold(FoldAdaptor adaptor) { return constFoldBinaryOpConditional( adaptor.getOperands(), - [](const APFloat &a, const APFloat &b) -> Optional { + [](const APFloat &a, const APFloat &b) -> std::optional { if (a.isZero() && b.isZero()) return llvm::APFloat::getNaN(a.getSemantics()); @@ -113,7 +113,7 @@ OpFoldResult math::CopySignOp::fold(FoldAdaptor adaptor) { OpFoldResult math::CosOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(cos(a.convertToDouble())); @@ -131,7 +131,7 @@ OpFoldResult math::CosOp::fold(FoldAdaptor adaptor) { OpFoldResult math::SinOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(sin(a.convertToDouble())); @@ -182,7 +182,7 @@ OpFoldResult math::CtPopOp::fold(FoldAdaptor adaptor) { OpFoldResult math::ErfOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(erf(a.convertToDouble())); @@ -201,7 +201,7 @@ OpFoldResult math::ErfOp::fold(FoldAdaptor adaptor) { OpFoldResult math::IPowIOp::fold(FoldAdaptor adaptor) { return constFoldBinaryOpConditional( adaptor.getOperands(), - [](const APInt &base, const APInt &power) -> Optional { + [](const APInt &base, const APInt &power) -> std::optional { unsigned width = base.getBitWidth(); auto zeroValue = APInt::getZero(width); APInt oneValue{width, 1ULL, /*isSigned=*/true}; @@ -251,7 +251,7 @@ OpFoldResult math::IPowIOp::fold(FoldAdaptor adaptor) { OpFoldResult math::LogOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { if (a.isNegative()) return {}; @@ -271,7 +271,7 @@ OpFoldResult math::LogOp::fold(FoldAdaptor adaptor) { OpFoldResult math::Log2Op::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { if (a.isNegative()) return {}; @@ -291,7 +291,7 @@ OpFoldResult math::Log2Op::fold(FoldAdaptor adaptor) { OpFoldResult math::Log10Op::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { if (a.isNegative()) return {}; @@ -312,7 +312,7 @@ OpFoldResult math::Log10Op::fold(FoldAdaptor adaptor) { OpFoldResult math::Log1pOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: if ((a + APFloat(1.0)).isNegative()) @@ -335,7 +335,7 @@ OpFoldResult math::Log1pOp::fold(FoldAdaptor adaptor) { OpFoldResult math::PowFOp::fold(FoldAdaptor adaptor) { return constFoldBinaryOpConditional( adaptor.getOperands(), - [](const APFloat &a, const APFloat &b) -> Optional { + [](const APFloat &a, const APFloat &b) -> std::optional { if (a.getSizeInBits(a.getSemantics()) == 64 && b.getSizeInBits(b.getSemantics()) == 64) return APFloat(pow(a.convertToDouble(), b.convertToDouble())); @@ -354,7 +354,7 @@ OpFoldResult math::PowFOp::fold(FoldAdaptor adaptor) { OpFoldResult math::SqrtOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { if (a.isNegative()) return {}; @@ -375,7 +375,7 @@ OpFoldResult math::SqrtOp::fold(FoldAdaptor adaptor) { OpFoldResult math::ExpOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(exp(a.convertToDouble())); @@ -393,7 +393,7 @@ OpFoldResult math::ExpOp::fold(FoldAdaptor adaptor) { OpFoldResult math::Exp2Op::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(exp2(a.convertToDouble())); @@ -411,7 +411,7 @@ OpFoldResult math::Exp2Op::fold(FoldAdaptor adaptor) { OpFoldResult math::ExpM1Op::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(expm1(a.convertToDouble())); @@ -429,7 +429,7 @@ OpFoldResult math::ExpM1Op::fold(FoldAdaptor adaptor) { OpFoldResult math::TanOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(tan(a.convertToDouble())); @@ -447,7 +447,7 @@ OpFoldResult math::TanOp::fold(FoldAdaptor adaptor) { OpFoldResult math::TanhOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(tanh(a.convertToDouble())); @@ -491,7 +491,7 @@ OpFoldResult math::FloorOp::fold(FoldAdaptor adaptor) { OpFoldResult math::RoundOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(round(a.convertToDouble())); @@ -509,7 +509,7 @@ OpFoldResult math::RoundOp::fold(FoldAdaptor adaptor) { OpFoldResult math::TruncOp::fold(FoldAdaptor adaptor) { return constFoldUnaryOpConditional( - adaptor.getOperands(), [](const APFloat &a) -> Optional { + adaptor.getOperands(), [](const APFloat &a) -> std::optional { switch (a.getSizeInBits(a.getSemantics())) { case 64: return APFloat(trunc(a.convertToDouble())); diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp index 021f7ec..f5ddc94 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefDialect.cpp @@ -44,7 +44,7 @@ void mlir::memref::MemRefDialect::initialize() { } /// Finds the unique dealloc operation (if one exists) for `allocValue`. -llvm::Optional mlir::memref::findDealloc(Value allocValue) { +std::optional mlir::memref::findDealloc(Value allocValue) { Operation *dealloc = nullptr; for (Operation *user : allocValue.getUsers()) { if (!hasEffect(user, allocValue)) diff --git a/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp b/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp index 06c9c65..71c99e9 100644 --- a/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp +++ b/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp @@ -174,7 +174,7 @@ getExpandedSizes(memref::ExpandShapeOp expandShape, OpBuilder &builder, SmallVector expandedSizes(groupSize); uint64_t productOfAllStaticSizes = 1; - Optional dynSizeIdx; + std::optional dynSizeIdx; MemRefType expandShapeType = expandShape.getResultType(); // Fill up all the statically known sizes. @@ -239,7 +239,7 @@ SmallVector getExpandedStrides(memref::ExpandShapeOp expandShape, unsigned groupSize = reassocGroup.size(); MemRefType expandShapeType = expandShape.getResultType(); - Optional dynSizeIdx; + std::optional dynSizeIdx; // Fill up the expanded strides, with the information we can deduce from the // resulting shape. diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp index 511cae6..a450386 100644 --- a/mlir/lib/Dialect/PDL/IR/PDL.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp @@ -207,7 +207,7 @@ static LogicalResult verifyResultTypesAreInferrable(OperationOp op, std::optional rawOpName = op.getOpName(); if (!rawOpName) return success(); - Optional opName = + std::optional opName = RegisteredOperationName::lookup(*rawOpName, op.getContext()); if (!opName) return success(); @@ -382,7 +382,8 @@ LogicalResult PatternOp::verifyRegions() { } void PatternOp::build(OpBuilder &builder, OperationState &state, - Optional benefit, Optional name) { + std::optional benefit, + std::optional name) { build(builder, state, builder.getI16IntegerAttr(benefit ? *benefit : 0), name ? builder.getStringAttr(*name) : StringAttr()); state.regions[0]->emplaceBlock(); diff --git a/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp b/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp index e2454a0..487aa0d 100644 --- a/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp @@ -48,7 +48,7 @@ public: // actual conversion. It should return std::nullopt upon conversion failure // and return the converted operation upon success. // - // Optional convertSourceOp(SourceOp op, OpAdaptor adaptor, + // std::optional convertSourceOp(SourceOp op, OpAdaptor adaptor, // ConversionPatternRewriter &rewriter, // TypeRange dstTypes) const; @@ -66,7 +66,7 @@ public: } // Calls the actual converter implementation to convert the operation. - Optional newOp = + std::optional newOp = static_cast(this)->convertSourceOp( op, adaptor, rewriter, dstTypes); @@ -106,9 +106,9 @@ public: using Structural1ToNConversionPattern::Structural1ToNConversionPattern; // The callback required by CRTP. - Optional convertSourceOp(ForOp op, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter, - TypeRange dstTypes) const { + std::optional convertSourceOp(ForOp op, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter, + TypeRange dstTypes) const { // Create a empty new op and inline the regions from the old op. // // This is a little bit tricky. We have two concerns here: @@ -161,9 +161,9 @@ class ConvertIfOpTypes public: using Structural1ToNConversionPattern::Structural1ToNConversionPattern; - Optional convertSourceOp(IfOp op, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter, - TypeRange dstTypes) const { + std::optional convertSourceOp(IfOp op, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter, + TypeRange dstTypes) const { IfOp newOp = rewriter.create(op.getLoc(), dstTypes, adaptor.getCondition(), true); @@ -190,9 +190,9 @@ class ConvertWhileOpTypes public: using Structural1ToNConversionPattern::Structural1ToNConversionPattern; - Optional convertSourceOp(WhileOp op, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter, - TypeRange dstTypes) const { + std::optional convertSourceOp(WhileOp op, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter, + TypeRange dstTypes) const { // Unpacked the iteration arguments. SmallVector flatArgs; for (Value arg : adaptor.getOperands()) diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp index 1fa45cb..37b9051 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp @@ -29,7 +29,7 @@ using namespace mlir; /// Returns the boolean value under the hood if the given `boolAttr` is a scalar /// or splat vector bool constant. -static Optional getScalarOrSplatBoolAttr(Attribute attr) { +static std::optional getScalarOrSplatBoolAttr(Attribute attr) { if (!attr) return std::nullopt; @@ -237,7 +237,8 @@ OpFoldResult spirv::ISubOp::fold(FoldAdaptor adaptor) { //===----------------------------------------------------------------------===// OpFoldResult spirv::LogicalAndOp::fold(FoldAdaptor adaptor) { - if (Optional rhs = getScalarOrSplatBoolAttr(adaptor.getOperand2())) { + if (std::optional rhs = + getScalarOrSplatBoolAttr(adaptor.getOperand2())) { // x && true = x if (*rhs) return getOperand1(); @@ -255,7 +256,8 @@ OpFoldResult spirv::LogicalAndOp::fold(FoldAdaptor adaptor) { //===----------------------------------------------------------------------===// OpFoldResult spirv::LogicalNotEqualOp::fold(FoldAdaptor adaptor) { - if (Optional rhs = getScalarOrSplatBoolAttr(adaptor.getOperand2())) { + if (std::optional rhs = + getScalarOrSplatBoolAttr(adaptor.getOperand2())) { // x && false = x if (!rhs.value()) return getOperand1(); diff --git a/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp b/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp index 42ded31..74fb705 100644 --- a/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/TargetAndABI.cpp @@ -48,7 +48,7 @@ bool spirv::TargetEnv::allows(spirv::Capability capability) const { return givenCapabilities.count(capability); } -Optional +std::optional spirv::TargetEnv::allows(ArrayRef caps) const { const auto *chosen = llvm::find_if(caps, [this](spirv::Capability cap) { return givenCapabilities.count(cap); @@ -62,7 +62,7 @@ bool spirv::TargetEnv::allows(spirv::Extension extension) const { return givenExtensions.count(extension); } -Optional +std::optional spirv::TargetEnv::allows(ArrayRef exts) const { const auto *chosen = llvm::find_if(exts, [this](spirv::Extension ext) { return givenExtensions.count(ext); diff --git a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp index 027bfab..6e09a84 100644 --- a/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/UpdateVCEPass.cpp @@ -54,7 +54,7 @@ static LogicalResult checkAndUpdateExtensionRequirements( const spirv::SPIRVType::ExtensionArrayRefVector &candidates, SetVector &deducedExtensions) { for (const auto &ors : candidates) { - if (Optional chosen = targetEnv.allows(ors)) { + if (std::optional chosen = targetEnv.allows(ors)) { deducedExtensions.insert(*chosen); } else { SmallVector extStrings; @@ -82,7 +82,7 @@ static LogicalResult checkAndUpdateCapabilityRequirements( const spirv::SPIRVType::CapabilityArrayRefVector &candidates, SetVector &deducedCapabilities) { for (const auto &ors : candidates) { - if (Optional chosen = targetEnv.allows(ors)) { + if (std::optional chosen = targetEnv.allows(ors)) { deducedCapabilities.insert(*chosen); } else { SmallVector capStrings; diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp index d89f532..d844999 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp @@ -45,8 +45,8 @@ void CodegenEnv::startEmit(OpOperand *so, unsigned lv) { /*isSparseOut=*/sparseOut != nullptr, topSort); } -Optional CodegenEnv::genLoopBoundary( - function_ref(MutableArrayRef parameters)> +std::optional CodegenEnv::genLoopBoundary( + function_ref(MutableArrayRef parameters)> callback) { SmallVector params; if (isReduc()) diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h index 341cfb9..853ee4d 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.h @@ -53,9 +53,10 @@ public: /// Generates loop boundary statements (entering/exiting loops). The function /// passes and updates the passed-in parameters. - Optional genLoopBoundary( - function_ref(MutableArrayRef parameters)> - callback); + std::optional + genLoopBoundary(function_ref< + std::optional(MutableArrayRef parameters)> + callback); // // Merger delegates. diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp index fd91078..9466f6f 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp @@ -25,7 +25,7 @@ using namespace mlir::sparse_tensor; /// If the tensor is a sparse constant, generates and returns the pair of /// the constants for the indices and the values. -static Optional> +static std::optional> genSplitSparseConstant(OpBuilder &builder, Location loc, Value tensor) { if (auto constOp = tensor.getDefiningOp()) { if (auto attr = constOp.getValue().dyn_cast()) { diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseStorageSpecifierToLLVM.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseStorageSpecifierToLLVM.cpp index e900936f..d5d9dab 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseStorageSpecifierToLLVM.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseStorageSpecifierToLLVM.cpp @@ -140,7 +140,7 @@ public: } else { auto enc = op.getSpecifier().getType().getEncoding(); StorageLayout layout(enc); - Optional dim = std::nullopt; + std::optional dim = std::nullopt; if (op.getDim()) dim = op.getDim().value().getZExtValue(); unsigned idx = layout.getMemRefFieldIndex(op.getSpecifierKind(), dim); diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp index ab85c5f..975403e 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp @@ -134,8 +134,9 @@ Value sizeAtStoredDim(OpBuilder &builder, Location loc, static void createPushback(OpBuilder &builder, Location loc, MutSparseTensorDescriptor desc, - SparseTensorFieldKind kind, Optional dim, - Value value, Value repeat = Value()) { + SparseTensorFieldKind kind, + std::optional dim, Value value, + Value repeat = Value()) { Type etp = desc.getMemRefElementType(kind, dim); Value field = desc.getMemRefField(kind, dim); StorageSpecifierKind specFieldKind = toSpecifierKind(kind); diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp index 59f956f..719b1c6 100644 --- a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp @@ -346,8 +346,8 @@ static bool topSortOptimal(CodegenEnv &env, unsigned n, /// tidx < a = (i0 + i1) => tidx < i0, tidx < i1. static void addAffineOrderings(std::vector> &adjM, std::vector &inDegree, AffineExpr a, - AffineExpr b, Optional fidx, - Optional tidx) { + AffineExpr b, std::optional fidx, + std::optional tidx) { if (!a && !b) { // Recursion leaf. assert(fidx && tidx); @@ -387,9 +387,9 @@ static void addAffineOrderings(std::vector> &adjM, } static void tryLoosenAffineDenseConstraints(linalg::GenericOp op, - Optional &fldx, + std::optional &fldx, AffineExpr &fa, - Optional &tldx, + std::optional &tldx, AffineExpr &ta) { // We use a heuristic here to only pick one dim expression from each // compound affine expression to establish the order between two dense @@ -449,7 +449,7 @@ static bool computeIterationGraph(CodegenEnv &env, unsigned mask, // on the loop indices if no explicit dimension ordering is given. for (unsigned d = 0, rank = map.getNumResults(); d < rank; d++) { AffineExpr ta = map.getResult(toOrigDim(enc, d)); - Optional tldx = + std::optional tldx = env.merger().getLoopIdx(t.getOperandNumber(), d); // Filter loops should be constructed after all the dependent loops, @@ -473,7 +473,7 @@ static bool computeIterationGraph(CodegenEnv &env, unsigned mask, if (d > 0) { AffineExpr fa = map.getResult(toOrigDim(enc, d - 1)); - Optional fldx = + std::optional fldx = env.merger().getLoopIdx(t.getOperandNumber(), d - 1); // Applying order constraints on every pair of dimExpr between two @@ -916,7 +916,7 @@ static void genInvariants(CodegenEnv &env, OpBuilder &builder, unsigned exp, auto enc = getSparseTensorEncoding(t.get().getType()); for (unsigned d = 0, rank = map.getNumResults(); d < rank; d++) { AffineExpr a = map.getResult(toOrigDim(enc, d)); - Optional sldx = + std::optional sldx = env.merger().getLoopIdx(t.getOperandNumber(), d); if (sldx && env.merger().isFilterLoop(*sldx)) { if (!env.getLoopIdxValue(*sldx)) @@ -1202,8 +1202,8 @@ static bool startLoopSeq(CodegenEnv &env, OpBuilder &builder, unsigned exp, SmallVector tids; SmallVector dims; env.merger().foreachTidDimPairInBits( - env.lat(l0).bits, - [&](unsigned b, unsigned tid, Optional dim, DimLevelType dlt) { + env.lat(l0).bits, [&](unsigned b, unsigned tid, + std::optional dim, DimLevelType dlt) { assert(env.merger().index(b) == idx); if (isDenseDLT(dlt) || isUndefDLT(dlt)) { needsUniv = true; @@ -1271,9 +1271,10 @@ static bool translateBitsToTidDimPairs( unsigned numloopCond = 0; // Converts bits to array + dim pair - env.merger().foreachTidDimPairInBits(all, [&, idx](unsigned b, unsigned tid, - Optional dim, - DimLevelType dlt) { + env.merger().foreachTidDimPairInBits(all, [&, + idx](unsigned b, unsigned tid, + std::optional dim, + DimLevelType dlt) { if (simple.test(b)) { if (isUndefDLT(dlt)) { // An undefined dlt in the lattices, we probably mean to iterate based @@ -1528,7 +1529,7 @@ public: return failure(); // Builds the tensor expression for the Linalg operation in SSA form. - Optional optExp = env.merger().buildTensorExpFromLinalg(op); + std::optional optExp = env.merger().buildTensorExpFromLinalg(op); if (!optExp) return failure(); unsigned exp = *optExp; diff --git a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp index 1d06570..a0892b2 100644 --- a/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp +++ b/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp @@ -211,10 +211,10 @@ Merger::Merger(unsigned t, unsigned l, unsigned fl) numNativeLoops(l), numLoops(l + fl), hasSparseOut(false), dimTypes(numTensors, std::vector(numLoops, DimLevelType::Undef)), - loopIdxToDim(numTensors, - std::vector>(numLoops, std::nullopt)), - dimToLoopIdx(numTensors, - std::vector>(numLoops, std::nullopt)) {} + loopIdxToDim(numTensors, std::vector>( + numLoops, std::nullopt)), + dimToLoopIdx(numTensors, std::vector>( + numLoops, std::nullopt)) {} //===----------------------------------------------------------------------===// // Lattice methods. @@ -958,7 +958,7 @@ unsigned Merger::buildLattices(unsigned e, unsigned i) { llvm_unreachable("unexpected expression kind"); } -Optional Merger::buildTensorExpFromLinalg(linalg::GenericOp op) { +std::optional Merger::buildTensorExpFromLinalg(linalg::GenericOp op) { // Build the linalg semantics backward from yield. Operation *yield = op.getRegion().front().getTerminator(); assert(isa(yield)); @@ -1025,7 +1025,7 @@ static bool isAdmissibleBranch(Operation *op, Region ®ion) { return isAdmissibleBranchExp(op, ®ion.front(), yield->getOperand(0)); } -Optional Merger::buildTensorExp(linalg::GenericOp op, Value v) { +std::optional Merger::buildTensorExp(linalg::GenericOp op, Value v) { if (auto arg = v.dyn_cast()) { unsigned argN = arg.getArgNumber(); // Any argument of the generic op that is not marked as a scalar diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp index 55e5364..18ffbe3 100644 --- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp @@ -3248,7 +3248,7 @@ void PackOp::getAsmResultNames(function_ref setNameFn) { void PackOp::build(OpBuilder &builder, OperationState &state, Value source, Value dest, ArrayRef innerDimsPos, ArrayRef innerTiles, - Optional paddingValue, + std::optional paddingValue, ArrayRef outerDimsPerm) { assert(innerDimsPos.size() == innerTiles.size() && "number of tile sizes specified must match the specified number of " diff --git a/mlir/lib/Dialect/Traits.cpp b/mlir/lib/Dialect/Traits.cpp index fb4374e..a1a3032 100644 --- a/mlir/lib/Dialect/Traits.cpp +++ b/mlir/lib/Dialect/Traits.cpp @@ -32,7 +32,7 @@ bool OpTrait::util::staticallyKnownBroadcastable( // We look backwards through every column of `shapes`. for (size_t i = 0; i != maxRank; ++i) { bool seenDynamic = false; - Optional nonOneDim; + std::optional nonOneDim; for (ArrayRef extent : shapes) { int64_t dim = i >= extent.size() ? 1 : extent[extent.size() - i - 1]; @@ -150,16 +150,16 @@ Type OpTrait::util::getBroadcastedType(Type type1, Type type2, // Returns the type kind if the given type is a vector or ranked tensor type. // Returns std::nullopt otherwise. - auto getCompositeTypeKind = [](Type type) -> Optional { + auto getCompositeTypeKind = [](Type type) -> std::optional { if (type.isa()) return type.getTypeID(); return std::nullopt; }; // Make sure the composite type, if has, is consistent. - Optional compositeKind1 = getCompositeTypeKind(type1); - Optional compositeKind2 = getCompositeTypeKind(type2); - Optional resultCompositeKind; + std::optional compositeKind1 = getCompositeTypeKind(type1); + std::optional compositeKind2 = getCompositeTypeKind(type2); + std::optional resultCompositeKind; if (compositeKind1 && compositeKind2) { // Disallow mixing vector and tensor. diff --git a/mlir/lib/Dialect/Utils/IndexingUtils.cpp b/mlir/lib/Dialect/Utils/IndexingUtils.cpp index 71ff38f..4563d74 100644 --- a/mlir/lib/Dialect/Utils/IndexingUtils.cpp +++ b/mlir/lib/Dialect/Utils/IndexingUtils.cpp @@ -32,7 +32,7 @@ SmallVector mlir::computeElementwiseMul(ArrayRef v1, return result; } -Optional> +std::optional> mlir::computeShapeRatio(ArrayRef shape, ArrayRef subShape) { if (shape.size() < subShape.size()) return std::nullopt; diff --git a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp index 2e6499f..e022e5f 100644 --- a/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp +++ b/mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp @@ -16,7 +16,7 @@ using namespace mlir; -Optional> +std::optional> mlir::getReassociationIndicesForReshape(ShapedType sourceType, ShapedType targetType) { if (sourceType.getRank() > targetType.getRank()) @@ -28,7 +28,7 @@ mlir::getReassociationIndicesForReshape(ShapedType sourceType, return std::nullopt; } -Optional> +std::optional> mlir::getReassociationIndicesForCollapse(ArrayRef sourceShape, ArrayRef targetShape) { if (sourceShape.size() <= targetShape.size()) @@ -93,7 +93,8 @@ mlir::getReassociationIndicesForCollapse(ArrayRef sourceShape, return reassociationMap; } -Optional> mlir::composeReassociationIndices( +std::optional> +mlir::composeReassociationIndices( ArrayRef producerReassociations, ArrayRef consumerReassociations, MLIRContext *context) { @@ -356,10 +357,10 @@ SliceFromCollapseHelper::getInsertSliceParams(MLIRContext *ctx, /// Returns the index of the only non-unit dimension among `indices` of `shape`, /// if such a dimension exists and `indices` has more than one element. /// Otherwise, return none. -static Optional getUniqueNonUnitDim(ArrayRef indices, - ArrayRef shape) { +static std::optional getUniqueNonUnitDim(ArrayRef indices, + ArrayRef shape) { // Return false if more than one of the dimensions in this group are not 1. - Optional dimIndex = std::nullopt; + std::optional dimIndex = std::nullopt; if (indices.size() < 2) return std::nullopt; for (int64_t idx : indices) { @@ -375,10 +376,10 @@ static Optional getUniqueNonUnitDim(ArrayRef indices, // For each segment in the reassociation indices, check whether we can // simplify that segment with a rank-reducing extract slice. We can do this if // all but (exactly) one of the corresponding source dims is 1. -static SmallVector> getCollapseShapeTrivialSegments( +static SmallVector> getCollapseShapeTrivialSegments( RankedTensorType sourceType, ArrayRef reassociationIndices) { - SmallVector> trivialSegments; + SmallVector> trivialSegments; for (const auto &indices : reassociationIndices) trivialSegments.push_back( getUniqueNonUnitDim(indices, sourceType.getShape())); @@ -387,13 +388,13 @@ static SmallVector> getCollapseShapeTrivialSegments( /// Returns true if any of the segments of the reassociation indices for a /// collapsing reshape can be simplified using a rank-reducing slice. -static FailureOr>> +static FailureOr>> canCollapseShapeBeSimplifiedByRankReducingSlice( RankedTensorType sourceType, ArrayRef reassociationIndices) { - SmallVector> trivialSegments = + SmallVector> trivialSegments = getCollapseShapeTrivialSegments(sourceType, reassociationIndices); - if (!llvm::any_of(trivialSegments, [](const Optional &idx) { + if (!llvm::any_of(trivialSegments, [](const std::optional &idx) { return idx.has_value(); })) return failure(); @@ -404,7 +405,7 @@ FailureOr mlir::getSimplifyCollapseShapeWithRankReducingSliceInfo( RankedTensorType sourceType, ArrayRef reassociationIndices) { - FailureOr>> trivialSegments = + FailureOr>> trivialSegments = canCollapseShapeBeSimplifiedByRankReducingSlice(sourceType, reassociationIndices); if (failed(trivialSegments)) diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp index 6e2e2d4..c4aad0f 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp @@ -38,7 +38,7 @@ using namespace mlir; using namespace mlir::vector; -static Optional extractConstantIndex(Value v) { +static std::optional extractConstantIndex(Value v) { if (auto cstOp = v.getDefiningOp()) return cstOp.value(); if (auto affineApplyOp = v.getDefiningOp()) diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp index 09ff4dd..0872d10 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp @@ -135,7 +135,7 @@ static Operation *cloneOpWithOperandsAndTypes(OpBuilder &builder, Location loc, /// Return the target shape for unrolling for the given `op`. Return /// std::nullopt if the op shouldn't be or cannot be unrolled. -static Optional> +static std::optional> getTargetShape(const vector::UnrollVectorOptions &options, Operation *op) { if (options.filterConstraint && failed(options.filterConstraint(op))) return std::nullopt; @@ -148,7 +148,7 @@ getTargetShape(const vector::UnrollVectorOptions &options, Operation *op) { auto maybeUnrollShape = unrollableVectorOp.getShapeForUnroll(); if (!maybeUnrollShape) return std::nullopt; - Optional> targetShape = options.nativeShape(op); + std::optional> targetShape = options.nativeShape(op); if (!targetShape) return std::nullopt; auto maybeShapeRatio = computeShapeRatio(*maybeUnrollShape, *targetShape); @@ -164,7 +164,8 @@ getUnrollOrder(unsigned numLoops, Operation *op, SmallVector loopOrder = llvm::to_vector(llvm::seq(0, static_cast(numLoops))); if (options.traversalOrderCallback != nullptr) { - Optional> order = options.traversalOrderCallback(op); + std::optional> order = + options.traversalOrderCallback(op); if (order) { loopOrder = std::move(*order); } @@ -414,7 +415,7 @@ struct UnrollMultiReductionPattern LogicalResult matchAndRewrite(vector::MultiDimReductionOp reductionOp, PatternRewriter &rewriter) const override { - Optional> targetShape = + std::optional> targetShape = getTargetShape(options, reductionOp); if (!targetShape) return failure(); @@ -549,7 +550,7 @@ struct UnrollReductionPattern : public OpRewritePattern { LogicalResult matchAndRewrite(vector::ReductionOp reductionOp, PatternRewriter &rewriter) const override { - Optional> targetShape = + std::optional> targetShape = getTargetShape(options, reductionOp); if (!targetShape) return failure(); diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp index dddecc4..bd069a1 100644 --- a/mlir/lib/ExecutionEngine/JitRunner.cpp +++ b/mlir/lib/ExecutionEngine/JitRunner.cpp @@ -148,8 +148,8 @@ static inline Error makeStringError(const Twine &message) { llvm::inconvertibleErrorCode()); } -static Optional getCommandLineOptLevel(Options &options) { - Optional optLevel; +static std::optional getCommandLineOptLevel(Options &options) { + std::optional optLevel; SmallVector>, 4> optFlags{ options.optO0, options.optO1, options.optO2, options.optO3}; @@ -168,7 +168,7 @@ static Optional getCommandLineOptLevel(Options &options) { static Error compileAndExecute(Options &options, Operation *module, StringRef entryPoint, CompileAndExecuteConfig config, void **args) { - Optional jitCodeGenOptLevel; + std::optional jitCodeGenOptLevel; if (auto clOptLevel = getCommandLineOptLevel(options)) jitCodeGenOptLevel = static_cast(*clOptLevel); @@ -352,7 +352,7 @@ int mlir::JitRunnerMain(int argc, char **argv, const DialectRegistry ®istry, return 0; } - Optional optLevel = getCommandLineOptLevel(options); + std::optional optLevel = getCommandLineOptLevel(options); SmallVector>, 4> optFlags{ options.optO0, options.optO1, options.optO2, options.optO3}; diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp index 12af9d3..554452c 100644 --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -566,7 +566,7 @@ static AffineExpr simplifyAdd(AffineExpr lhs, AffineExpr rhs) { // Detect "c1 * expr + c_2 * expr" as "(c1 + c2) * expr". // c1 is rRhsConst, c2 is rLhsConst; firstExpr, secondExpr are their // respective multiplicands. - Optional rLhsConst, rRhsConst; + std::optional rLhsConst, rRhsConst; AffineExpr firstExpr, secondExpr; AffineConstantExpr rLhsConstExpr; auto lBinOpExpr = lhs.dyn_cast(); diff --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp index f25b1a1..90c5466 100644 --- a/mlir/lib/IR/AffineMap.cpp +++ b/mlir/lib/IR/AffineMap.cpp @@ -41,7 +41,7 @@ public: } private: - Optional constantFoldImpl(AffineExpr expr) { + std::optional constantFoldImpl(AffineExpr expr) { switch (expr.getKind()) { case AffineExprKind::Add: return constantFoldBinExpr( @@ -76,8 +76,8 @@ private: } // TODO: Change these to operate on APInts too. - Optional constantFoldBinExpr(AffineExpr expr, - int64_t (*op)(int64_t, int64_t)) { + std::optional constantFoldBinExpr(AffineExpr expr, + int64_t (*op)(int64_t, int64_t)) { auto binOpExpr = expr.cast(); if (auto lhs = constantFoldImpl(binOpExpr.getLHS())) if (auto rhs = constantFoldImpl(binOpExpr.getRHS())) @@ -341,7 +341,7 @@ unsigned AffineMap::getDimPosition(unsigned idx) const { return getResult(idx).cast().getPosition(); } -Optional AffineMap::getResultPosition(AffineExpr input) const { +std::optional AffineMap::getResultPosition(AffineExpr input) const { if (!input.isa()) return std::nullopt; diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 5839e2b..0981b3b 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -252,7 +252,7 @@ bool OpPrintingFlags::shouldElideElementsAttr(ElementsAttr attr) const { } /// Return the size limit for printing large ElementsAttr. -Optional OpPrintingFlags::getLargeElementsAttrLimit() const { +std::optional OpPrintingFlags::getLargeElementsAttrLimit() const { return elementsAttrElementLimit; } @@ -532,7 +532,7 @@ private: /// The alias for the attribute or type, or std::nullopt if the value has no /// alias. - Optional alias; + std::optional alias; /// The alias depth of this attribute or type, i.e. an indication of the /// relative ordering of when to print this alias. unsigned aliasDepth : 30; @@ -1214,7 +1214,7 @@ private: /// 'lookupResultNo'. 'lookupResultNo' is only filled in if the result group /// has more than 1 result. void getResultIDAndNumber(OpResult result, Value &lookupValue, - Optional &lookupResultNo) const; + std::optional &lookupResultNo) const; /// Set a special value name for the given value. void setValueName(Value value, StringRef name); @@ -1326,7 +1326,7 @@ void SSANameState::printValueID(Value value, bool printResultNo, return; } - Optional resultNo; + std::optional resultNo; auto lookupValue = value; // If this is an operation result, collect the head lookup value of the result @@ -1514,8 +1514,9 @@ void SSANameState::numberValuesInOp(Operation &op) { } } -void SSANameState::getResultIDAndNumber(OpResult result, Value &lookupValue, - Optional &lookupResultNo) const { +void SSANameState::getResultIDAndNumber( + OpResult result, Value &lookupValue, + std::optional &lookupResultNo) const { Operation *owner = result.getOwner(); if (owner->getNumResults() == 1) return; diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp index b5810ff..ff4aa65 100644 --- a/mlir/lib/IR/BuiltinAttributes.cpp +++ b/mlir/lib/IR/BuiltinAttributes.cpp @@ -94,9 +94,9 @@ static bool dictionaryAttrSort(ArrayRef value, /// Returns an entry with a duplicate name from the given sorted array of named /// attributes. Returns std::nullopt if all elements have unique names. -static Optional +static std::optional findDuplicateElement(ArrayRef value) { - const Optional none{std::nullopt}; + const std::optional none{std::nullopt}; if (value.size() < 2) return none; @@ -125,7 +125,7 @@ bool DictionaryAttr::sortInPlace(SmallVectorImpl &array) { return isSorted; } -Optional +std::optional DictionaryAttr::findDuplicate(SmallVectorImpl &array, bool isSorted) { if (!isSorted) @@ -172,13 +172,13 @@ Attribute DictionaryAttr::get(StringAttr name) const { } /// Return the specified named attribute if present, std::nullopt otherwise. -Optional DictionaryAttr::getNamed(StringRef name) const { +std::optional DictionaryAttr::getNamed(StringRef name) const { auto it = impl::findAttrSorted(begin(), end(), name); - return it.second ? *it.first : Optional(); + return it.second ? *it.first : std::optional(); } -Optional DictionaryAttr::getNamed(StringAttr name) const { +std::optional DictionaryAttr::getNamed(StringAttr name) const { auto it = impl::findAttrSorted(begin(), end(), name); - return it.second ? *it.first : Optional(); + return it.second ? *it.first : std::optional(); } /// Return whether the specified attribute is present. @@ -1552,7 +1552,7 @@ DenseResourceElementsAttrBase::get(ShapedType type, StringRef blobName, } template -Optional> +std::optional> DenseResourceElementsAttrBase::tryGetAsArrayRef() const { if (AsmResourceBlob *blob = this->getRawHandle().getBlob()) return blob->template getDataAs(); diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp index be1ec39..5926f2e 100644 --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -174,7 +174,7 @@ std::string Diagnostic::str() const { /// Attaches a note to this diagnostic. A new location may be optionally /// provided, if not, then the location defaults to the one specified for this /// diagnostic. Notes may not be attached to other notes. -Diagnostic &Diagnostic::attachNote(Optional noteLoc) { +Diagnostic &Diagnostic::attachNote(std::optional noteLoc) { // We don't allow attaching notes to notes. assert(severity != DiagnosticSeverity::Note && "cannot attach a note to a note"); @@ -391,7 +391,7 @@ struct SourceMgrDiagnosticHandlerImpl { } // namespace mlir /// Return a processable CallSiteLoc from the given location. -static Optional getCallSiteLoc(Location loc) { +static std::optional getCallSiteLoc(Location loc) { if (auto nameLoc = dyn_cast(loc)) return getCallSiteLoc(cast(loc).getChildLoc()); if (auto callLoc = dyn_cast(loc)) @@ -477,7 +477,7 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Location loc, Twine message, void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) { SmallVector> locationStack; auto addLocToStack = [&](Location loc, StringRef locContext) { - if (Optional showableLoc = findLocToShow(loc)) + if (std::optional showableLoc = findLocToShow(loc)) locationStack.emplace_back(*showableLoc, locContext); }; @@ -527,36 +527,37 @@ SourceMgrDiagnosticHandler::getBufferForFile(StringRef filename) { return nullptr; } -Optional SourceMgrDiagnosticHandler::findLocToShow(Location loc) { +std::optional +SourceMgrDiagnosticHandler::findLocToShow(Location loc) { if (!shouldShowLocFn) return loc; if (!shouldShowLocFn(loc)) return std::nullopt; // Recurse into the child locations of some of location types. - return TypeSwitch>(loc) - .Case([&](CallSiteLoc callLoc) -> Optional { + return TypeSwitch>(loc) + .Case([&](CallSiteLoc callLoc) -> std::optional { // We recurse into the callee of a call site, as the caller will be // emitted in a different note on the main diagnostic. return findLocToShow(callLoc.getCallee()); }) - .Case([&](FileLineColLoc) -> Optional { return loc; }) - .Case([&](FusedLoc fusedLoc) -> Optional { + .Case([&](FileLineColLoc) -> std::optional { return loc; }) + .Case([&](FusedLoc fusedLoc) -> std::optional { // Fused location is unique in that we try to find a sub-location to // show, rather than the top-level location itself. for (Location childLoc : fusedLoc.getLocations()) - if (Optional showableLoc = findLocToShow(childLoc)) + if (std::optional showableLoc = findLocToShow(childLoc)) return showableLoc; return std::nullopt; }) - .Case([&](NameLoc nameLoc) -> Optional { + .Case([&](NameLoc nameLoc) -> std::optional { return findLocToShow(nameLoc.getChildLoc()); }) - .Case([&](OpaqueLoc opaqueLoc) -> Optional { + .Case([&](OpaqueLoc opaqueLoc) -> std::optional { // OpaqueLoc always falls back to a different source location. return findLocToShow(opaqueLoc.getFallbackLocation()); }) - .Case([](UnknownLoc) -> Optional { + .Case([](UnknownLoc) -> std::optional { // Prefer not to show unknown locations. return std::nullopt; }); @@ -652,14 +653,15 @@ struct ExpectedDiag { StringRef substring; /// An optional regex matcher, if the expected diagnostic sub-string was a /// regex string. - Optional substringRegex; + std::optional substringRegex; }; struct SourceMgrDiagnosticVerifierHandlerImpl { SourceMgrDiagnosticVerifierHandlerImpl() : status(success()) {} /// Returns the expected diagnostics for the given source file. - Optional> getExpectedDiags(StringRef bufName); + std::optional> + getExpectedDiags(StringRef bufName); /// Computes the expected diagnostics for the given source buffer. MutableArrayRef @@ -695,7 +697,7 @@ static StringRef getDiagKindStr(DiagnosticSeverity kind) { llvm_unreachable("Unknown DiagnosticSeverity"); } -Optional> +std::optional> SourceMgrDiagnosticVerifierHandlerImpl::getExpectedDiags(StringRef bufName) { auto expectedDiags = expectedDiagsPerFile.find(bufName); if (expectedDiags != expectedDiagsPerFile.end()) diff --git a/mlir/lib/IR/DialectResourceBlobManager.cpp b/mlir/lib/IR/DialectResourceBlobManager.cpp index a47fe9b..b83b31e 100644 --- a/mlir/lib/IR/DialectResourceBlobManager.cpp +++ b/mlir/lib/IR/DialectResourceBlobManager.cpp @@ -31,7 +31,7 @@ void DialectResourceBlobManager::update(StringRef name, } auto DialectResourceBlobManager::insert(StringRef name, - Optional blob) + std::optional blob) -> BlobEntry & { llvm::sys::SmartScopedWriter writer(blobMapLock); diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index a354eed6..b0fe94f 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -785,7 +785,7 @@ OperationName::UnregisteredOpModel::verifyRegionInvariants(Operation *) { // RegisteredOperationName //===----------------------------------------------------------------------===// -Optional +std::optional RegisteredOperationName::lookup(StringRef name, MLIRContext *ctx) { auto &impl = ctx->getImpl(); auto it = impl.registeredOperations.find(name); diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index dc6b26d..8f3d379 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -42,8 +42,8 @@ NamedAttrList::NamedAttrList(const_iterator inStart, const_iterator inEnd) { ArrayRef NamedAttrList::getAttrs() const { return attrs; } -Optional NamedAttrList::findDuplicate() const { - Optional duplicate = +std::optional NamedAttrList::findDuplicate() const { + std::optional duplicate = DictionaryAttr::findDuplicate(attrs, isSorted()); // DictionaryAttr::findDuplicate will sort the list, so reset the sorted // state. @@ -91,13 +91,13 @@ Attribute NamedAttrList::get(StringAttr name) const { } /// Return the specified named attribute if present, std::nullopt otherwise. -Optional NamedAttrList::getNamed(StringRef name) const { +std::optional NamedAttrList::getNamed(StringRef name) const { auto it = findAttr(*this, name); - return it.second ? *it.first : Optional(); + return it.second ? *it.first : std::optional(); } -Optional NamedAttrList::getNamed(StringAttr name) const { +std::optional NamedAttrList::getNamed(StringAttr name) const { auto it = findAttr(*this, name); - return it.second ? *it.first : Optional(); + return it.second ? *it.first : std::optional(); } /// If the an attribute exists with the specified name, change it to the new @@ -423,7 +423,7 @@ MutableOperandRange::MutableOperandRange(Operation *owner) /// Slice this range into a sub range, with the additional operand segment. MutableOperandRange MutableOperandRange::slice(unsigned subStart, unsigned subLen, - Optional segment) const { + std::optional segment) const { assert((subStart + subLen) <= length && "invalid sub-range"); MutableOperandRange subSlice(owner, start + subStart, subLen, operandSegments); diff --git a/mlir/lib/IR/SubElementInterfaces.cpp b/mlir/lib/IR/SubElementInterfaces.cpp index 9eeb7b4..528e0ca 100644 --- a/mlir/lib/IR/SubElementInterfaces.cpp +++ b/mlir/lib/IR/SubElementInterfaces.cpp @@ -215,7 +215,7 @@ T AttrTypeReplacer::replaceImpl(T element, ReplaceFns &replaceFns, T result = element; WalkResult walkResult = WalkResult::advance(); for (auto &replaceFn : llvm::reverse(replaceFns)) { - if (Optional> newRes = replaceFn(element)) { + if (std::optional> newRes = replaceFn(element)) { std::tie(result, walkResult) = *newRes; break; } diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp index bec7c0b..4c3b3bb 100644 --- a/mlir/lib/IR/SymbolTable.cpp +++ b/mlir/lib/IR/SymbolTable.cpp @@ -77,13 +77,13 @@ collectValidReferencesFor(Operation *symbol, StringAttr symbolName, /// Walk all of the operations within the given set of regions, without /// traversing into any nested symbol tables. Stops walking if the result of the /// callback is anything other than `WalkResult::advance`. -static Optional +static std::optional walkSymbolTable(MutableArrayRef regions, - function_ref(Operation *)> callback) { + function_ref(Operation *)> callback) { SmallVector worklist(llvm::make_pointer_range(regions)); while (!worklist.empty()) { for (Operation &op : worklist.pop_back_val()->getOps()) { - Optional result = callback(&op); + std::optional result = callback(&op); if (result != WalkResult::advance()) return result; @@ -101,10 +101,10 @@ walkSymbolTable(MutableArrayRef regions, /// Walk all of the operations nested under, and including, the given operation, /// without traversing into any nested symbol tables. Stops walking if the /// result of the callback is anything other than `WalkResult::advance`. -static Optional +static std::optional walkSymbolTable(Operation *op, - function_ref(Operation *)> callback) { - Optional result = callback(op); + function_ref(Operation *)> callback) { + std::optional result = callback(op); if (result != WalkResult::advance() || op->hasTrait()) return result; return walkSymbolTable(op->getRegions(), callback); @@ -440,13 +440,13 @@ LogicalResult detail::verifySymbolTable(Operation *op) { // Verify any nested symbol user operations. SymbolTableCollection symbolTable; - auto verifySymbolUserFn = [&](Operation *op) -> Optional { + auto verifySymbolUserFn = [&](Operation *op) -> std::optional { if (SymbolUserOpInterface user = dyn_cast(op)) return WalkResult(user.verifySymbolUses(symbolTable)); return WalkResult::advance(); }; - Optional result = + std::optional result = walkSymbolTable(op->getRegions(), verifySymbolUserFn); return success(result && !result->wasInterrupted()); } @@ -550,21 +550,23 @@ walkSymbolRefs(Operation *op, /// Walk all of the uses, for any symbol, that are nested within the given /// regions, invoking the provided callback for each. This does not traverse /// into any nested symbol tables. -static Optional +static std::optional walkSymbolUses(MutableArrayRef regions, function_ref callback) { - return walkSymbolTable(regions, [&](Operation *op) -> Optional { - // Check that this isn't a potentially unknown symbol table. - if (isPotentiallyUnknownSymbolTable(op)) - return std::nullopt; - - return walkSymbolRefs(op, callback); - }); + return walkSymbolTable(regions, + [&](Operation *op) -> std::optional { + // Check that this isn't a potentially unknown symbol + // table. + if (isPotentiallyUnknownSymbolTable(op)) + return std::nullopt; + + return walkSymbolRefs(op, callback); + }); } /// Walk all of the uses, for any symbol, that are nested within the given /// operation 'from', invoking the provided callback for each. This does not /// traverse into any nested symbol tables. -static Optional +static std::optional walkSymbolUses(Operation *from, function_ref callback) { // If this operation has regions, and it, as well as its dialect, isn't @@ -600,7 +602,7 @@ struct SymbolScope { std::enable_if_t::result_t, void>::value> * = nullptr> - Optional walk(CallbackT cback) { + std::optional walk(CallbackT cback) { if (Region *region = limit.dyn_cast()) return walkSymbolUses(*region, cback); return walkSymbolUses(limit.get(), cback); @@ -611,7 +613,7 @@ struct SymbolScope { std::enable_if_t::result_t, void>::value> * = nullptr> - Optional walk(CallbackT cback) { + std::optional walk(CallbackT cback) { return walk([=](SymbolTable::SymbolUse use) { return cback(use), WalkResult::advance(); }); @@ -620,7 +622,7 @@ struct SymbolScope { /// Walk all of the operations nested under the current scope without /// traversing into any nested symbol tables. template - Optional walkSymbolTable(CallbackT &&cback) { + std::optional walkSymbolTable(CallbackT &&cback) { if (Region *region = limit.dyn_cast()) return ::walkSymbolTable(*region, cback); return ::walkSymbolTable(limit.get(), cback); @@ -878,7 +880,7 @@ replaceAllSymbolUsesImpl(SymbolT symbol, StringAttr newSymbol, IRUnitT *limit) { return {attr, WalkResult::skip()}; }); - auto walkFn = [&](Operation *op) -> Optional { + auto walkFn = [&](Operation *op) -> std::optional { replacer.replaceElementsIn(op); return WalkResult::advance(); }; diff --git a/mlir/lib/IR/Verifier.cpp b/mlir/lib/IR/Verifier.cpp index 60fa3e1..432d7bb 100644 --- a/mlir/lib/IR/Verifier.cpp +++ b/mlir/lib/IR/Verifier.cpp @@ -183,7 +183,8 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) { // If we can get operation info for this, check the custom hook. OperationName opName = op.getName(); - Optional registeredInfo = opName.getRegisteredInfo(); + std::optional registeredInfo = + opName.getRegisteredInfo(); if (registeredInfo && failed(registeredInfo->verifyInvariants(&op))) return failure(); diff --git a/mlir/lib/Interfaces/InferIntRangeInterface.cpp b/mlir/lib/Interfaces/InferIntRangeInterface.cpp index 212eea6..9248b11 100644 --- a/mlir/lib/Interfaces/InferIntRangeInterface.cpp +++ b/mlir/lib/Interfaces/InferIntRangeInterface.cpp @@ -113,7 +113,7 @@ ConstantIntRanges::intersection(const ConstantIntRanges &other) const { return {uminIntersect, umaxIntersect, sminIntersect, smaxIntersect}; } -Optional ConstantIntRanges::getConstantValue() const { +std::optional ConstantIntRanges::getConstantValue() const { // Note: we need to exclude the trivially-equal width 0 values here. if (umin() == umax() && umin().getBitWidth() != 0) return umin(); diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 2bb4f1a..8b5bd38 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -128,13 +128,14 @@ struct OpPassManagerImpl { LogicalResult finalizePassList(MLIRContext *ctx); /// Return the operation name of this pass manager. - Optional getOpName(MLIRContext &context) { + std::optional getOpName(MLIRContext &context) { if (!name.empty() && !opName) opName = OperationName(name, &context); return opName; } - Optional getOpName() const { - return name.empty() ? Optional() : Optional(name); + std::optional getOpName() const { + return name.empty() ? std::optional() + : std::optional(name); } /// Return the name used to anchor this pass manager. This is either the name @@ -153,7 +154,7 @@ struct OpPassManagerImpl { /// The cached OperationName (internalized in the context) for the name of the /// operation that passes of this pass manager operate on. - Optional opName; + std::optional opName; /// The set of passes to run as part of this pass manager. std::vector> passes; @@ -185,8 +186,8 @@ OpPassManager &OpPassManagerImpl::nest(OpPassManager &&nested) { void OpPassManagerImpl::addPass(std::unique_ptr pass) { // If this pass runs on a different operation than this pass manager, then // implicitly nest a pass manager for this operation if enabled. - Optional pmOpName = getOpName(); - Optional passOpName = pass->getOpName(); + std::optional pmOpName = getOpName(); + std::optional passOpName = pass->getOpName(); if (pmOpName && passOpName && *pmOpName != *passOpName) { if (nesting == OpPassManager::Nesting::Implicit) return nest(*passOpName).addPass(std::move(pass)); @@ -244,13 +245,14 @@ LogicalResult OpPassManagerImpl::finalizePassList(MLIRContext *ctx) { llvm::erase_if(passes, std::logical_not>()); // If this is a op-agnostic pass manager, there is nothing left to do. - Optional rawOpName = getOpName(*ctx); + std::optional rawOpName = getOpName(*ctx); if (!rawOpName) return success(); // Otherwise, verify that all of the passes are valid for the current // operation anchor. - Optional opName = rawOpName->getRegisteredInfo(); + std::optional opName = + rawOpName->getRegisteredInfo(); for (std::unique_ptr &pass : passes) { if (opName && !pass->canScheduleOn(*opName)) { return emitError(UnknownLoc::get(ctx)) @@ -266,13 +268,14 @@ bool OpPassManagerImpl::canScheduleOn(MLIRContext &context, OperationName opName) { // If this pass manager is op-specific, we simply check if the provided // operation name is the same as this one. - Optional pmOpName = getOpName(context); + std::optional pmOpName = getOpName(context); if (pmOpName) return pmOpName == opName; // Otherwise, this is an op-agnostic pass manager. Check that the operation // can be scheduled on all passes within the manager. - Optional registeredInfo = opName.getRegisteredInfo(); + std::optional registeredInfo = + opName.getRegisteredInfo(); if (!registeredInfo || !registeredInfo->hasTrait()) return false; @@ -343,12 +346,13 @@ size_t OpPassManager::size() const { return impl->passes.size(); } OpPassManagerImpl &OpPassManager::getImpl() { return *impl; } /// Return the operation name that this pass manager operates on. -Optional OpPassManager::getOpName() const { +std::optional OpPassManager::getOpName() const { return impl->getOpName(); } /// Return the operation name that this pass manager operates on. -Optional OpPassManager::getOpName(MLIRContext &context) const { +std::optional +OpPassManager::getOpName(MLIRContext &context) const { return impl->getOpName(context); } @@ -418,7 +422,7 @@ LogicalResult OpPassManager::initialize(MLIRContext *context, LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op, AnalysisManager am, bool verifyPasses, unsigned parentInitGeneration) { - Optional opInfo = op->getRegisteredInfo(); + std::optional opInfo = op->getRegisteredInfo(); if (!opInfo) return op->emitOpError() << "trying to schedule a pass on an unregistered operation"; @@ -579,7 +583,7 @@ LogicalResult OpToOpPassAdaptor::tryMergeInto(MLIRContext *ctx, // If this is a non-generic pass manager, a conflict will arise if a // non-generic pass manager's operation name can be scheduled on the // generic passmanager. - if (Optional pmOpName = pm.getOpName(*ctx)) + if (std::optional pmOpName = pm.getOpName(*ctx)) return genericPM.getImpl().canScheduleOn(*ctx, *pmOpName); // Otherwise, this is a generic pass manager. We current can't determine // when generic pass managers can be merged, so conservatively assume they @@ -618,8 +622,8 @@ LogicalResult OpToOpPassAdaptor::tryMergeInto(MLIRContext *ctx, // After coalescing, sort the pass managers within rhs by name. auto compareFn = [](const OpPassManager *lhs, const OpPassManager *rhs) { // Order op-specific pass managers first and op-agnostic pass managers last. - if (Optional lhsName = lhs->getOpName()) { - if (Optional rhsName = rhs->getOpName()) + if (std::optional lhsName = lhs->getOpName()) { + if (std::optional rhsName = rhs->getOpName()) return lhsName->compare(*rhsName); return -1; // lhs(op-specific) < rhs(op-agnostic) } @@ -713,7 +717,7 @@ void OpToOpPassAdaptor::runOnOperationAsyncImpl(bool verifyPasses) { // execute over. This ensures that an analysis manager exists for each // operation, as well as providing a queue of operations to execute over. std::vector opInfos; - DenseMap> knownOpPMIdx; + DenseMap> knownOpPMIdx; for (auto ®ion : getOperation()->getRegions()) { for (Operation &op : region.getOps()) { // Get the pass manager index for this operation type. @@ -778,7 +782,7 @@ void PassManager::enableVerifier(bool enabled) { verifyPasses = enabled; } /// Run the passes within this manager on the provided operation. LogicalResult PassManager::run(Operation *op) { MLIRContext *context = getContext(); - Optional anchorOp = getOpName(*context); + std::optional anchorOp = getOpName(*context); if (anchorOp && anchorOp != op->getName()) return emitError(op->getLoc()) << "can't run '" << getOpAnchorName() << "' pass manager on '" @@ -913,10 +917,10 @@ void detail::NestedAnalysisMap::invalidate( PassInstrumentation::~PassInstrumentation() = default; void PassInstrumentation::runBeforePipeline( - Optional name, const PipelineParentInfo &parentInfo) {} + std::optional name, const PipelineParentInfo &parentInfo) {} void PassInstrumentation::runAfterPipeline( - Optional name, const PipelineParentInfo &parentInfo) {} + std::optional name, const PipelineParentInfo &parentInfo) {} //===----------------------------------------------------------------------===// // PassInstrumentor @@ -939,7 +943,7 @@ PassInstrumentor::~PassInstrumentor() = default; /// See PassInstrumentation::runBeforePipeline for details. void PassInstrumentor::runBeforePipeline( - Optional name, + std::optional name, const PassInstrumentation::PipelineParentInfo &parentInfo) { llvm::sys::SmartScopedLock instrumentationLock(impl->mutex); for (auto &instr : impl->instrumentations) @@ -948,7 +952,7 @@ void PassInstrumentor::runBeforePipeline( /// See PassInstrumentation::runAfterPipeline for details. void PassInstrumentor::runAfterPipeline( - Optional name, + std::optional name, const PassInstrumentation::PipelineParentInfo &parentInfo) { llvm::sys::SmartScopedLock instrumentationLock(impl->mutex); for (auto &instr : llvm::reverse(impl->instrumentations)) diff --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp index c286b3a..3d10fe1 100644 --- a/mlir/lib/Pass/PassRegistry.cpp +++ b/mlir/lib/Pass/PassRegistry.cpp @@ -41,8 +41,8 @@ buildDefaultRegistryFn(const PassAllocatorFunction &allocator) { std::unique_ptr pass = allocator(); LogicalResult result = pass->initializeOptions(options); - Optional pmOpName = pm.getOpName(); - Optional passOpName = pass->getOpName(); + std::optional pmOpName = pm.getOpName(); + std::optional passOpName = pass->getOpName(); if ((pm.getNesting() == OpPassManager::Nesting::Explicit) && pmOpName && passOpName && *pmOpName != *passOpName) { return errorHandler(llvm::Twine("Can't add pass '") + pass->getName() + diff --git a/mlir/lib/Pass/PassTiming.cpp b/mlir/lib/Pass/PassTiming.cpp index c0100cc..9554c5d 100644 --- a/mlir/lib/Pass/PassTiming.cpp +++ b/mlir/lib/Pass/PassTiming.cpp @@ -53,7 +53,7 @@ struct PassTiming : public PassInstrumentation { // Pipeline //===--------------------------------------------------------------------===// - void runBeforePipeline(Optional name, + void runBeforePipeline(std::optional name, const PipelineParentInfo &parentInfo) override { auto tid = llvm::get_threadid(); auto &activeTimers = activeThreadTimers[tid]; @@ -75,7 +75,7 @@ struct PassTiming : public PassInstrumentation { })); } - void runAfterPipeline(Optional, + void runAfterPipeline(std::optional, const PipelineParentInfo &) override { auto &activeTimers = activeThreadTimers[llvm::get_threadid()]; assert(!activeTimers.empty() && "expected active timer"); diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp index 6b11220..1ea4bef 100644 --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -487,13 +487,13 @@ struct ByteCodeLiveRange { std::unique_ptr> liveness; /// The operation range storage index for this range. - Optional opRangeIndex; + std::optional opRangeIndex; /// The type range storage index for this range. - Optional typeRangeIndex; + std::optional typeRangeIndex; /// The value range storage index for this range. - Optional valueRangeIndex; + std::optional valueRangeIndex; }; } // namespace @@ -1107,7 +1107,7 @@ public: LogicalResult execute(PatternRewriter &rewriter, SmallVectorImpl *matches = nullptr, - Optional mainRewriteLoc = {}); + std::optional mainRewriteLoc = {}); private: /// Internal implementation of executing each of the bytecode commands. @@ -1450,11 +1450,11 @@ LogicalResult ByteCodeExecutor::executeApplyRewrite(PatternRewriter &rewriter) { // If the result is a range, we need to copy it over to the bytecodes // range memory. - if (Optional typeRange = result.dyn_cast()) { + if (std::optional typeRange = result.dyn_cast()) { unsigned rangeIndex = read(); typeRangeMemory[rangeIndex] = *typeRange; memory[read()] = &typeRangeMemory[rangeIndex]; - } else if (Optional valueRange = + } else if (std::optional valueRange = result.dyn_cast()) { unsigned rangeIndex = read(); valueRangeMemory[rangeIndex] = *valueRange; @@ -2110,7 +2110,7 @@ void ByteCodeExecutor::executeSwitchTypes() { LogicalResult ByteCodeExecutor::execute(PatternRewriter &rewriter, SmallVectorImpl *matches, - Optional mainRewriteLoc) { + std::optional mainRewriteLoc) { while (true) { // Print the location of the operation being executed. LLVM_DEBUG(llvm::dbgs() << readInline() << "\n"); diff --git a/mlir/lib/Rewrite/FrozenRewritePatternSet.cpp b/mlir/lib/Rewrite/FrozenRewritePatternSet.cpp index 947bada..0fa1668 100644 --- a/mlir/lib/Rewrite/FrozenRewritePatternSet.cpp +++ b/mlir/lib/Rewrite/FrozenRewritePatternSet.cpp @@ -106,13 +106,13 @@ FrozenRewritePatternSet::FrozenRewritePatternSet( impl->nativeOpSpecificPatternList.push_back(std::move(pat)); continue; } - if (Optional interfaceID = pat->getRootInterfaceID()) { + if (std::optional interfaceID = pat->getRootInterfaceID()) { addToOpsWhen(pat, [&](RegisteredOperationName info) { return info.hasInterface(*interfaceID); }); continue; } - if (Optional traitID = pat->getRootTraitID()) { + if (std::optional traitID = pat->getRootTraitID()) { addToOpsWhen(pat, [&](RegisteredOperationName info) { return info.hasTrait(*traitID); }); diff --git a/mlir/lib/Support/Timing.cpp b/mlir/lib/Support/Timing.cpp index 48eb1e8..844f629 100644 --- a/mlir/lib/Support/Timing.cpp +++ b/mlir/lib/Support/Timing.cpp @@ -509,7 +509,7 @@ void DefaultTimingManager::dumpAsTree(raw_ostream &os) { impl->rootTimer->print(os, DisplayMode::Tree); } -Optional DefaultTimingManager::rootTimer() { +std::optional DefaultTimingManager::rootTimer() { if (impl->enabled) return impl->rootTimer.get(); return std::nullopt; diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index c9ad8a8..b5c1bef 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -57,7 +57,7 @@ using namespace mlir::LLVM::detail; static FailureOr translateDataLayout(DataLayoutSpecInterface attribute, const DataLayout &dataLayout, - Optional loc = std::nullopt) { + std::optional loc = std::nullopt) { if (!loc) loc = UnknownLoc::get(attribute.getContext()); @@ -120,7 +120,7 @@ translateDataLayout(DataLayoutSpecInterface attribute, unsigned preferred = dataLayout.getTypePreferredAlignment(type) * 8u; layoutStream << size << ":" << abi << ":" << preferred; - if (Optional index = extractPointerSpecValue( + if (std::optional index = extractPointerSpecValue( entry.getValue(), PtrDLEntryPos::Index)) layoutStream << ":" << *index; return success(); diff --git a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp index aa64af7..78afcc7 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp @@ -74,10 +74,9 @@ Value spirv::Deserializer::getValue(uint32_t id) { return valueMap.lookup(id); } -LogicalResult -spirv::Deserializer::sliceInstruction(spirv::Opcode &opcode, - ArrayRef &operands, - Optional expectedOpcode) { +LogicalResult spirv::Deserializer::sliceInstruction( + spirv::Opcode &opcode, ArrayRef &operands, + std::optional expectedOpcode) { auto binarySize = binary.size(); if (curOffset >= binarySize) { return emitError(unknownLoc, "expected ") diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp index 73af433..8b0581d 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp @@ -501,7 +501,7 @@ spirv::Deserializer::processFunctionEnd(ArrayRef operands) { return success(); } -Optional> +std::optional> spirv::Deserializer::getConstant(uint32_t id) { auto constIt = constantMap.find(id); if (constIt == constantMap.end()) @@ -509,7 +509,7 @@ spirv::Deserializer::getConstant(uint32_t id) { return constIt->getSecond(); } -Optional +std::optional spirv::Deserializer::getSpecConstantOperation(uint32_t id) { auto constIt = specConstOperationMap.find(id); if (constIt == specConstOperationMap.end()) @@ -1513,7 +1513,7 @@ spirv::Deserializer::processBranchConditional(ArrayRef operands) { auto *trueBlock = getOrCreateBlock(operands[1]); auto *falseBlock = getOrCreateBlock(operands[2]); - Optional> weights; + std::optional> weights; if (operands.size() == 5) { weights = std::make_pair(operands[3], operands[4]); } diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h index 72c68a8..9d41166 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h +++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h @@ -186,11 +186,11 @@ private: LogicalResult processFunctionEnd(ArrayRef operands); /// Gets the constant's attribute and type associated with the given . - Optional> getConstant(uint32_t id); + std::optional> getConstant(uint32_t id); /// Gets the info needed to materialize the spec constant operation op /// associated with the given . - Optional + std::optional getSpecConstantOperation(uint32_t id); /// Gets the constant's integer attribute with the given . Returns a @@ -422,7 +422,7 @@ private: /// compose the error message) or the next instruction is malformed. LogicalResult sliceInstruction(spirv::Opcode &opcode, ArrayRef &operands, - Optional expectedOpcode = std::nullopt); + std::optional expectedOpcode = std::nullopt); /// Processes a SPIR-V instruction with the given `opcode` and `operands`. /// This method is the main entrance for handling SPIR-V instruction; it @@ -483,7 +483,7 @@ private: /// Contains the data of the OpLine instruction which precedes the current /// processing instruction. - llvm::Optional debugLine; + std::optional debugLine; /// The current word offset into the binary module. unsigned curOffset = 0; @@ -498,7 +498,7 @@ private: OwningOpRef module; /// The current function under construction. - Optional curFunction; + std::optional curFunction; /// The current block under construction. Block *curBlock = nullptr; diff --git a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp index 7a6a047..292ed97 100644 --- a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp @@ -1046,7 +1046,7 @@ LogicalResult Serializer::emitPhiForBlockArguments(Block *block) { predecessors.emplace_back(spirvPredecessor, branchOp.getOperands()); } else if (auto branchCondOp = dyn_cast(terminator)) { - Optional blockOperands; + std::optional blockOperands; if (branchCondOp.getTrueTarget() == block) { blockOperands = branchCondOp.getTrueTargetOperands(); } else { diff --git a/mlir/lib/Tools/PDLL/AST/NodePrinter.cpp b/mlir/lib/Tools/PDLL/AST/NodePrinter.cpp index c2b8aca..4155fd6 100644 --- a/mlir/lib/Tools/PDLL/AST/NodePrinter.cpp +++ b/mlir/lib/Tools/PDLL/AST/NodePrinter.cpp @@ -134,7 +134,7 @@ void NodePrinter::print(Type type) { .Case([&](ConstraintType) { os << "Constraint"; }) .Case([&](OperationType type) { os << "Op"; - if (Optional name = type.getName()) + if (std::optional name = type.getName()) os << "<" << *name << ">"; }) .Case([&](RangeType type) { @@ -298,7 +298,7 @@ void NodePrinter::printImpl(const TypeRangeConstraintDecl *decl) { void NodePrinter::printImpl(const UserConstraintDecl *decl) { os << "UserConstraintDecl " << decl << " Name<" << decl->getName().getName() << "> ResultType<" << decl->getResultType() << ">"; - if (Optional codeBlock = decl->getCodeBlock()) { + if (std::optional codeBlock = decl->getCodeBlock()) { os << " Code<"; llvm::printEscapedString(*codeBlock, os); os << ">"; @@ -330,7 +330,7 @@ void NodePrinter::printImpl(const NamedAttributeDecl *decl) { void NodePrinter::printImpl(const OpNameDecl *decl) { os << "OpNameDecl " << decl; - if (Optional name = decl->getName()) + if (std::optional name = decl->getName()) os << " Name<" << *name << ">"; os << "\n"; } @@ -339,7 +339,7 @@ void NodePrinter::printImpl(const PatternDecl *decl) { os << "PatternDecl " << decl; if (const Name *name = decl->getName()) os << " Name<" << name->getName() << ">"; - if (Optional benefit = decl->getBenefit()) + if (std::optional benefit = decl->getBenefit()) os << " Benefit<" << *benefit << ">"; if (decl->hasBoundedRewriteRecursion()) os << " Recursion"; @@ -351,7 +351,7 @@ void NodePrinter::printImpl(const PatternDecl *decl) { void NodePrinter::printImpl(const UserRewriteDecl *decl) { os << "UserRewriteDecl " << decl << " Name<" << decl->getName().getName() << "> ResultType<" << decl->getResultType() << ">"; - if (Optional codeBlock = decl->getCodeBlock()) { + if (std::optional codeBlock = decl->getCodeBlock()) { os << " Code<"; llvm::printEscapedString(*codeBlock, os); os << ">"; diff --git a/mlir/lib/Tools/PDLL/AST/Nodes.cpp b/mlir/lib/Tools/PDLL/AST/Nodes.cpp index 9842e39..4755629 100644 --- a/mlir/lib/Tools/PDLL/AST/Nodes.cpp +++ b/mlir/lib/Tools/PDLL/AST/Nodes.cpp @@ -326,7 +326,7 @@ OperationExpr::create(Context &ctx, SMRange loc, const ods::Operation *odsOp, return opExpr; } -Optional OperationExpr::getName() const { +std::optional OperationExpr::getName() const { return getNameDecl()->getName(); } @@ -405,7 +405,7 @@ OpConstraintDecl *OpConstraintDecl::create(Context &ctx, SMRange loc, OpConstraintDecl(loc, nameDecl); } -Optional OpConstraintDecl::getName() const { +std::optional OpConstraintDecl::getName() const { return getNameDecl()->getName(); } @@ -452,16 +452,17 @@ ValueRangeConstraintDecl::create(Context &ctx, SMRange loc, Expr *typeExpr) { // UserConstraintDecl //===----------------------------------------------------------------------===// -Optional +std::optional UserConstraintDecl::getNativeInputType(unsigned index) const { return hasNativeInputTypes ? getTrailingObjects()[index] - : Optional(); + : std::optional(); } UserConstraintDecl *UserConstraintDecl::createImpl( Context &ctx, const Name &name, ArrayRef inputs, ArrayRef nativeInputTypes, ArrayRef results, - Optional codeBlock, const CompoundStmt *body, Type resultType) { + std::optional codeBlock, const CompoundStmt *body, + Type resultType) { bool hasNativeInputTypes = !nativeInputTypes.empty(); assert(!hasNativeInputTypes || nativeInputTypes.size() == inputs.size()); @@ -516,7 +517,7 @@ OpNameDecl *OpNameDecl::create(Context &ctx, SMRange loc) { //===----------------------------------------------------------------------===// PatternDecl *PatternDecl::create(Context &ctx, SMRange loc, const Name *name, - Optional benefit, + std::optional benefit, bool hasBoundedRecursion, const CompoundStmt *body) { return new (ctx.getAllocator().Allocate()) @@ -530,7 +531,7 @@ PatternDecl *PatternDecl::create(Context &ctx, SMRange loc, const Name *name, UserRewriteDecl *UserRewriteDecl::createImpl(Context &ctx, const Name &name, ArrayRef inputs, ArrayRef results, - Optional codeBlock, + std::optional codeBlock, const CompoundStmt *body, Type resultType) { unsigned allocSize = UserRewriteDecl::totalSizeToAlloc( diff --git a/mlir/lib/Tools/PDLL/AST/Types.cpp b/mlir/lib/Tools/PDLL/AST/Types.cpp index 4ee2913..fc4cb61 100644 --- a/mlir/lib/Tools/PDLL/AST/Types.cpp +++ b/mlir/lib/Tools/PDLL/AST/Types.cpp @@ -70,16 +70,18 @@ ConstraintType ConstraintType::get(Context &context) { // OperationType //===----------------------------------------------------------------------===// -OperationType OperationType::get(Context &context, Optional name, +OperationType OperationType::get(Context &context, + std::optional name, const ods::Operation *odsOp) { return context.getTypeUniquer().get( /*initFn=*/function_ref(), std::make_pair(name.value_or(""), odsOp)); } -Optional OperationType::getName() const { +std::optional OperationType::getName() const { StringRef name = getImplAs()->getValue().first; - return name.empty() ? Optional() : Optional(name); + return name.empty() ? std::optional() + : std::optional(name); } const ods::Operation *OperationType::getODSOperation() const { diff --git a/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp b/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp index 3c490df..b02edc6 100644 --- a/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp +++ b/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp @@ -191,7 +191,7 @@ StringRef CodeGen::getNativeTypeName(ast::VariableDecl *decl) { // Try to extract a type name from the variable's constraints. for (ast::ConstraintRef &cst : decl->getConstraints()) { if (auto *userCst = dyn_cast(cst.constraint)) { - if (Optional name = userCst->getNativeInputType(0)) + if (std::optional name = userCst->getNativeInputType(0)) return *name; return getNativeTypeName(userCst->getInputs()[0]); } diff --git a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp index 432c649..8225680 100644 --- a/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp +++ b/mlir/lib/Tools/PDLL/CodeGen/MLIRGen.cpp @@ -283,7 +283,8 @@ void CodeGen::genImpl(const ast::PatternDecl *decl) { // here. pdl::PatternOp pattern = builder.create( genLoc(decl->getLoc()), decl->getBenefit(), - name ? Optional(name->getName()) : Optional()); + name ? std::optional(name->getName()) + : std::optional()); OpBuilder::InsertionGuard savedInsertPoint(builder); builder.setInsertionPointToStart(pattern.getBody()); @@ -496,7 +497,7 @@ Value CodeGen::genExprImpl(const ast::MemberAccessExpr *expr) { Value CodeGen::genExprImpl(const ast::OperationExpr *expr) { Location loc = genLoc(expr->getLoc()); - Optional opName = expr->getName(); + std::optional opName = expr->getName(); // Operands. SmallVector operands; diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 61a1f47..044aa61 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -131,7 +131,7 @@ private: /// Lookup ODS information for the given operation, returns nullptr if no /// information is found. - const ods::Operation *lookupODSOperation(Optional opName) { + const ods::Operation *lookupODSOperation(std::optional opName) { return opName ? ctx.getODSContext().lookupOperation(*opName) : nullptr; } @@ -186,13 +186,13 @@ private: /// This structure contains the set of pattern metadata that may be parsed. struct ParsedPatternMetadata { - Optional benefit; + std::optional benefit; bool hasBoundedRecursion = false; }; FailureOr parseTopLevelDecl(); FailureOr - parseNamedAttributeDecl(Optional parentOpName); + parseNamedAttributeDecl(std::optional parentOpName); /// Parse an argument variable as part of the signature of a /// UserConstraintDecl or UserRewriteDecl. @@ -299,7 +299,7 @@ private: /// that will be constrained by this constraint. `allowInlineTypeConstraints` /// allows the use of inline Type constraints, e.g. `Value`. FailureOr - parseConstraint(Optional &typeConstraint, + parseConstraint(std::optional &typeConstraint, ArrayRef existingConstraints, bool allowInlineTypeConstraints); @@ -424,17 +424,18 @@ private: MutableArrayRef attributes, SmallVectorImpl &results); LogicalResult - validateOperationOperands(SMRange loc, Optional name, + validateOperationOperands(SMRange loc, std::optional name, const ods::Operation *odsOp, SmallVectorImpl &operands); - LogicalResult validateOperationResults(SMRange loc, Optional name, + LogicalResult validateOperationResults(SMRange loc, + std::optional name, const ods::Operation *odsOp, SmallVectorImpl &results); void checkOperationResultTypeInferrence(SMRange loc, StringRef name, const ods::Operation *odsOp); LogicalResult validateOperationOperandsOrResults( - StringRef groupName, SMRange loc, Optional odsOpLoc, - Optional name, SmallVectorImpl &values, + StringRef groupName, SMRange loc, std::optional odsOpLoc, + std::optional name, SmallVectorImpl &values, ArrayRef odsValues, ast::Type singleTy, ast::RangeType rangeTy); FailureOr createTupleExpr(SMRange loc, @@ -461,7 +462,7 @@ private: /// results. LogicalResult codeCompleteMemberAccess(ast::Expr *parentExpr); - LogicalResult codeCompleteAttributeName(Optional opName); + LogicalResult codeCompleteAttributeName(std::optional opName); LogicalResult codeCompleteConstraintName(ast::Type inferredType, bool allowInlineTypeConstraints); LogicalResult codeCompleteDialectName(); @@ -470,9 +471,9 @@ private: LogicalResult codeCompleteIncludeFilename(StringRef curPath); void codeCompleteCallSignature(ast::Node *parent, unsigned currentNumArgs); - void codeCompleteOperationOperandsSignature(Optional opName, + void codeCompleteOperationOperandsSignature(std::optional opName, unsigned currentNumOperands); - void codeCompleteOperationResultsSignature(Optional opName, + void codeCompleteOperationResultsSignature(std::optional opName, unsigned currentNumResults); //===--------------------------------------------------------------------===// @@ -1048,7 +1049,7 @@ FailureOr Parser::parseTopLevelDecl() { } FailureOr -Parser::parseNamedAttributeDecl(Optional parentOpName) { +Parser::parseNamedAttributeDecl(std::optional parentOpName) { // Check for name code completion. if (curToken.is(Token::code_complete)) return codeCompleteAttributeName(parentOpName); @@ -1344,7 +1345,7 @@ FailureOr Parser::parseUserNativeConstraintOrRewriteDecl( ArrayRef results, ast::Type resultType) { // If followed by a string, the native code body has also been specified. std::string codeStrStorage; - Optional optCodeStr; + std::optional optCodeStr; if (curToken.isString()) { codeStrStorage = curToken.getStringValue(); optCodeStr = codeStrStorage; @@ -1528,8 +1529,8 @@ FailureOr Parser::parsePatternDecl() { LogicalResult Parser::parsePatternDeclMetadata(ParsedPatternMetadata &metadata) { - Optional benefitLoc; - Optional hasBoundedRecursionLoc; + std::optional benefitLoc; + std::optional hasBoundedRecursionLoc; do { // Handle metadata code completion. @@ -1641,7 +1642,7 @@ Parser::defineVariableDecl(StringRef name, SMRange nameLoc, ast::Type type, LogicalResult Parser::parseVariableDeclConstraintList( SmallVectorImpl &constraints) { - Optional typeConstraint; + std::optional typeConstraint; auto parseSingleConstraint = [&] { FailureOr constraint = parseConstraint( typeConstraint, constraints, /*allowInlineTypeConstraints=*/true); @@ -1663,7 +1664,7 @@ LogicalResult Parser::parseVariableDeclConstraintList( } FailureOr -Parser::parseConstraint(Optional &typeConstraint, +Parser::parseConstraint(std::optional &typeConstraint, ArrayRef existingConstraints, bool allowInlineTypeConstraints) { auto parseTypeConstraint = [&](ast::Expr *&typeExpr) -> LogicalResult { @@ -1783,7 +1784,7 @@ Parser::parseConstraint(Optional &typeConstraint, } FailureOr Parser::parseArgOrResultConstraint() { - Optional typeConstraint; + std::optional typeConstraint; return parseConstraint(typeConstraint, /*existingConstraints=*/std::nullopt, /*allowInlineTypeConstraints=*/false); } @@ -2029,7 +2030,7 @@ Parser::parseOperationExpr(OpResultTypeContext inputResultTypeContext) { parseWrappedOperationName(allowEmptyName); if (failed(opNameDecl)) return failure(); - Optional opName = (*opNameDecl)->getName(); + std::optional opName = (*opNameDecl)->getName(); // Functor used to create an implicit range variable, used for implicit "all" // operand or results variables. @@ -2813,7 +2814,7 @@ FailureOr Parser::createOperationExpr( SmallVectorImpl &operands, MutableArrayRef attributes, SmallVectorImpl &results) { - Optional opNameRef = name->getName(); + std::optional opNameRef = name->getName(); const ods::Operation *odsOp = lookupODSOperation(opNameRef); // Verify the inputs operands. @@ -2853,21 +2854,21 @@ FailureOr Parser::createOperationExpr( } LogicalResult -Parser::validateOperationOperands(SMRange loc, Optional name, +Parser::validateOperationOperands(SMRange loc, std::optional name, const ods::Operation *odsOp, SmallVectorImpl &operands) { return validateOperationOperandsOrResults( - "operand", loc, odsOp ? odsOp->getLoc() : Optional(), name, + "operand", loc, odsOp ? odsOp->getLoc() : std::optional(), name, operands, odsOp ? odsOp->getOperands() : std::nullopt, valueTy, valueRangeTy); } LogicalResult -Parser::validateOperationResults(SMRange loc, Optional name, +Parser::validateOperationResults(SMRange loc, std::optional name, const ods::Operation *odsOp, SmallVectorImpl &results) { return validateOperationOperandsOrResults( - "result", loc, odsOp ? odsOp->getLoc() : Optional(), name, + "result", loc, odsOp ? odsOp->getLoc() : std::optional(), name, results, odsOp ? odsOp->getResults() : std::nullopt, typeTy, typeRangeTy); } @@ -2914,8 +2915,8 @@ void Parser::checkOperationResultTypeInferrence(SMRange loc, StringRef opName, } LogicalResult Parser::validateOperationOperandsOrResults( - StringRef groupName, SMRange loc, Optional odsOpLoc, - Optional name, SmallVectorImpl &values, + StringRef groupName, SMRange loc, std::optional odsOpLoc, + std::optional name, SmallVectorImpl &values, ArrayRef odsValues, ast::Type singleTy, ast::RangeType rangeTy) { // All operation types accept a single range parameter. @@ -3111,7 +3112,8 @@ LogicalResult Parser::codeCompleteMemberAccess(ast::Expr *parentExpr) { return failure(); } -LogicalResult Parser::codeCompleteAttributeName(Optional opName) { +LogicalResult +Parser::codeCompleteAttributeName(std::optional opName) { if (opName) codeCompleteContext->codeCompleteOperationAttributeName(*opName); return failure(); @@ -3155,13 +3157,13 @@ void Parser::codeCompleteCallSignature(ast::Node *parent, } void Parser::codeCompleteOperationOperandsSignature( - Optional opName, unsigned currentNumOperands) { + std::optional opName, unsigned currentNumOperands) { codeCompleteContext->codeCompleteOperationOperandsSignature( opName, currentNumOperands); } -void Parser::codeCompleteOperationResultsSignature(Optional opName, - unsigned currentNumResults) { +void Parser::codeCompleteOperationResultsSignature( + std::optional opName, unsigned currentNumResults) { codeCompleteContext->codeCompleteOperationResultsSignature(opName, currentNumResults); } diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.h b/mlir/lib/Tools/lsp-server-support/Protocol.h index 0a001a0..3112e9f 100644 --- a/mlir/lib/Tools/lsp-server-support/Protocol.h +++ b/mlir/lib/Tools/lsp-server-support/Protocol.h @@ -528,7 +528,7 @@ struct Hover { /// An optional range is a range inside a text document that is used to /// visualize a hover, e.g. by changing the background color. - Optional range; + std::optional range; }; /// Add support for JSON serialization. @@ -931,7 +931,7 @@ struct ParameterInformation { /// Inclusive start and exclusive end offsets withing the containing signature /// label. - Optional> labelOffsets; + std::optional> labelOffsets; /// The documentation of this parameter. Optional. std::string documentation; @@ -1184,13 +1184,13 @@ struct CodeAction { /// The kind of the code action. /// Used to filter code actions. - Optional kind; + std::optional kind; const static llvm::StringLiteral kQuickFix; const static llvm::StringLiteral kRefactor; const static llvm::StringLiteral kInfo; /// The diagnostics that this code action resolves. - Optional> diagnostics; + std::optional> diagnostics; /// Marks this as a preferred action. Preferred actions are used by the /// `auto fix` command and can be targeted by keybindings. @@ -1200,7 +1200,7 @@ struct CodeAction { bool isPreferred = false; /// The workspace edit this code action performs. - Optional edit; + std::optional edit; }; /// Add support for JSON serialization. diff --git a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp index d65f77c..122d4e0 100644 --- a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp +++ b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp @@ -66,8 +66,8 @@ SMRange lsp::convertTokenLocToRange(SMLoc loc) { return SMRange(loc, SMLoc::getFromPointer(curPtr)); } -Optional lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, - SMLoc loc) { +std::optional +lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc) { // This is a heuristic, and isn't intended to cover every case, but should // cover the most common. We essentially look for a comment preceding the // line, and if we find one, use that as the documentation. @@ -81,7 +81,7 @@ Optional lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, StringRef buffer(bufferStart, loc.getPointer() - bufferStart); // Pop the last line from the buffer string. - auto popLastLine = [&]() -> Optional { + auto popLastLine = [&]() -> std::optional { size_t newlineOffset = buffer.find_last_of("\n"); if (newlineOffset == StringRef::npos) return std::nullopt; @@ -96,7 +96,7 @@ Optional lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, // Try to parse a comment string from the source file. SmallVector commentLines; - while (Optional line = popLastLine()) { + while (std::optional line = popLastLine()) { // Check for a comment at the beginning of the line. if (!line->startswith("//")) break; diff --git a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h index da57f3d..523ef89 100644 --- a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h +++ b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h @@ -31,8 +31,8 @@ SMRange convertTokenLocToRange(SMLoc loc); /// Extract a documentation comment for the given location within the source /// manager. Returns std::nullopt if no comment could be computed. -Optional extractSourceDocComment(llvm::SourceMgr &sourceMgr, - SMLoc loc); +std::optional extractSourceDocComment(llvm::SourceMgr &sourceMgr, + SMLoc loc); /// Returns true if the given range contains the given source location. Note /// that this has different behavior than SMRange because it is inclusive of the diff --git a/mlir/lib/Tools/lsp-server-support/Transport.cpp b/mlir/lib/Tools/lsp-server-support/Transport.cpp index a18603e..e5bceac 100644 --- a/mlir/lib/Tools/lsp-server-support/Transport.cpp +++ b/mlir/lib/Tools/lsp-server-support/Transport.cpp @@ -229,11 +229,11 @@ bool JSONTransport::handleMessage(llvm::json::Value msg, // Message must be an object with "jsonrpc":"2.0". llvm::json::Object *object = msg.getAsObject(); if (!object || - object->getString("jsonrpc") != llvm::Optional("2.0")) + object->getString("jsonrpc") != std::optional("2.0")) return false; // `id` may be any JSON value. If absent, this is a notification. - llvm::Optional id; + std::optional id; if (llvm::json::Value *i = object->get("id")) id = std::move(*i); std::optional method = object->getString("method"); diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp index 81053c1..ab98729e 100644 --- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp @@ -172,7 +172,8 @@ void LSPServer::onDocumentDidOpen(const DidOpenTextDocumentParams ¶ms) { publishDiagnostics(diagParams); } void LSPServer::onDocumentDidClose(const DidCloseTextDocumentParams ¶ms) { - Optional version = server.removeDocument(params.textDocument.uri); + std::optional version = + server.removeDocument(params.textDocument.uri); if (!version) return; diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp index 11015a3..3699b51 100644 --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -25,8 +25,8 @@ using namespace mlir; /// Returns a language server location from the given MLIR file location. /// `uriScheme` is the scheme to use when building new uris. -static Optional getLocationFromLoc(StringRef uriScheme, - FileLineColLoc loc) { +static std::optional getLocationFromLoc(StringRef uriScheme, + FileLineColLoc loc) { llvm::Expected sourceURI = lsp::URIForFile::fromFile(loc.getFilename(), uriScheme); if (!sourceURI) { @@ -46,16 +46,17 @@ static Optional getLocationFromLoc(StringRef uriScheme, /// std::nullopt if one couldn't be created. `uriScheme` is the scheme to use /// when building new uris. `uri` is an optional additional filter that, when /// present, is used to filter sub locations that do not share the same uri. -static Optional +static std::optional getLocationFromLoc(llvm::SourceMgr &sourceMgr, Location loc, StringRef uriScheme, const lsp::URIForFile *uri = nullptr) { - Optional location; + std::optional location; loc->walk([&](Location nestedLoc) { FileLineColLoc fileLoc = nestedLoc.dyn_cast(); if (!fileLoc) return WalkResult::advance(); - Optional sourceLoc = getLocationFromLoc(uriScheme, fileLoc); + std::optional sourceLoc = + getLocationFromLoc(uriScheme, fileLoc); if (sourceLoc && (!uri || sourceLoc->uri == *uri)) { location = *sourceLoc; SMLoc loc = sourceMgr.FindLocForLineAndColumn( @@ -64,7 +65,7 @@ getLocationFromLoc(llvm::SourceMgr &sourceMgr, Location loc, // Use range of potential identifier starting at location, else length 1 // range. location->range.end.character += 1; - if (Optional range = lsp::convertTokenLocToRange(loc)) { + if (std::optional range = lsp::convertTokenLocToRange(loc)) { auto lineCol = sourceMgr.getLineAndColumn(range->End); location->range.end.character = std::max(fileLoc.getColumn() + 1, lineCol.second - 1); @@ -87,7 +88,7 @@ static void collectLocationsFromLoc(Location loc, if (!fileLoc || !visitedLocs.insert(nestedLoc)) return WalkResult::advance(); - Optional sourceLoc = + std::optional sourceLoc = getLocationFromLoc(uri.scheme(), fileLoc); if (sourceLoc && sourceLoc->uri != uri) locations.push_back(*sourceLoc); @@ -128,7 +129,7 @@ static bool isDefOrUse(const AsmParserState::SMDefinition &def, SMLoc loc, /// Given a location pointing to a result, return the result number it refers /// to or std::nullopt if it refers to all of the results. -static Optional getResultNumberFromLoc(SMLoc loc) { +static std::optional getResultNumberFromLoc(SMLoc loc) { // Skip all of the identifier characters. auto isIdentifierChar = [](char c) { return isalnum(c) || c == '%' || c == '$' || c == '.' || c == '_' || @@ -149,13 +150,13 @@ static Optional getResultNumberFromLoc(SMLoc loc) { ++curPtr; StringRef numberStr(numberStart, curPtr - numberStart); unsigned resultNumber = 0; - return numberStr.consumeInteger(10, resultNumber) ? Optional() + return numberStr.consumeInteger(10, resultNumber) ? std::optional() : resultNumber; } /// Given a source location range, return the text covered by the given range. /// If the range is invalid, returns std::nullopt. -static Optional getTextFromRange(SMRange range) { +static std::optional getTextFromRange(SMRange range) { if (!range.isValid()) return std::nullopt; const char *startPtr = range.Start.getPointer(); @@ -171,7 +172,7 @@ static unsigned getBlockNumber(Block *block) { /// given output stream. static void printDefBlockName(raw_ostream &os, Block *block, SMRange loc = {}) { // Try to extract a name from the source location. - Optional text = getTextFromRange(loc); + std::optional text = getTextFromRange(loc); if (text && text->startswith("^")) { os << *text; return; @@ -200,7 +201,7 @@ static lsp::Diagnostic getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr, // TODO: For simplicity, we just grab the first one. It may be likely that we // will need a more interesting heuristic here.' StringRef uriScheme = uri.scheme(); - Optional lspLocation = + std::optional lspLocation = getLocationFromLoc(sourceMgr, diag.getLocation(), uriScheme, &uri); if (lspLocation) lspDiag.range = lspLocation->range; @@ -225,7 +226,7 @@ static lsp::Diagnostic getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr, std::vector relatedDiags; for (Diagnostic ¬e : diag.getNotes()) { lsp::Location noteLoc; - if (Optional loc = + if (std::optional loc = getLocationFromLoc(sourceMgr, note.getLocation(), uriScheme)) noteLoc = *loc; else @@ -541,7 +542,7 @@ lsp::Hover MLIRDocument::buildHoverForOperationResult(SMRange hoverRange, // Check to see if the location points to a specific result within the // group. - if (Optional resultNumber = getResultNumberFromLoc(posLoc)) { + if (std::optional resultNumber = getResultNumberFromLoc(posLoc)) { if ((resultStart + *resultNumber) < resultEnd) { resultStart += *resultNumber; resultEnd = resultStart + 1; @@ -1226,7 +1227,7 @@ void lsp::MLIRServer::addOrUpdateDocument( uri, contents, version, impl->registry, diagnostics); } -Optional lsp::MLIRServer::removeDocument(const URIForFile &uri) { +std::optional lsp::MLIRServer::removeDocument(const URIForFile &uri) { auto it = impl->files.find(uri.file()); if (it == impl->files.end()) return std::nullopt; diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h index 0224724..979be61 100644 --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.h @@ -49,7 +49,7 @@ public: /// Remove the document with the given uri. Returns the version of the removed /// document, or std::nullopt if the uri did not have a corresponding document /// within the server. - Optional removeDocument(const URIForFile &uri); + std::optional removeDocument(const URIForFile &uri); /// Return the locations of the object pointed at by the given position. void getLocationsOf(const URIForFile &uri, const Position &defPos, diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp index 8be034f..c91dc89 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp @@ -175,7 +175,8 @@ void LSPServer::onDocumentDidOpen(const DidOpenTextDocumentParams ¶ms) { publishDiagnostics(diagParams); } void LSPServer::onDocumentDidClose(const DidCloseTextDocumentParams ¶ms) { - Optional version = server.removeDocument(params.textDocument.uri); + std::optional version = + server.removeDocument(params.textDocument.uri); if (!version) return; diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp index 53afc8fb..f209f2a 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp @@ -64,7 +64,7 @@ static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMRange range, } /// Convert the given MLIR diagnostic to the LSP form. -static Optional +static std::optional getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr, const ast::Diagnostic &diag, const lsp::URIForFile &uri) { lsp::Diagnostic lspDiag; @@ -112,10 +112,10 @@ getLspDiagnoticFromDiag(llvm::SourceMgr &sourceMgr, const ast::Diagnostic &diag, } /// Get or extract the documentation for the given decl. -static Optional getDocumentationFor(llvm::SourceMgr &sourceMgr, - const ast::Decl *decl) { +static std::optional +getDocumentationFor(llvm::SourceMgr &sourceMgr, const ast::Decl *decl) { // If the decl already had documentation set, use it. - if (Optional doc = decl->getDocComment()) + if (std::optional doc = decl->getDocComment()) return doc->str(); // If the decl doesn't yet have documentation, try to extract it from the @@ -216,7 +216,7 @@ void PDLIndex::initialize(const ast::Module &module, module.walk([&](const ast::Node *node) { // Handle references to PDL decls. if (const auto *decl = dyn_cast(node)) { - if (Optional name = decl->getName()) + if (std::optional name = decl->getName()) insertODSOpRef(*name, decl->getLoc()); } else if (const ast::Decl *decl = dyn_cast(node)) { const ast::Name *name = decl->getName(); @@ -528,7 +528,7 @@ lsp::Hover PDLDocument::buildHoverForPattern(const ast::PatternDecl *decl, if (const ast::Name *name = decl->getName()) hoverOS << ": `" << name->getName() << "`"; hoverOS << "\n***\n"; - if (Optional benefit = decl->getBenefit()) + if (std::optional benefit = decl->getBenefit()) hoverOS << "Benefit: " << *benefit << "\n"; if (decl->hasBoundedRewriteRecursion()) hoverOS << "HasBoundedRewriteRecursion\n"; @@ -536,7 +536,7 @@ lsp::Hover PDLDocument::buildHoverForPattern(const ast::PatternDecl *decl, << decl->getRootRewriteStmt()->getRootOpExpr()->getType() << "`\n"; // Format the documentation for the decl. - if (Optional doc = getDocumentationFor(sourceMgr, decl)) + if (std::optional doc = getDocumentationFor(sourceMgr, decl)) hoverOS << "\n" << *doc << "\n"; } return hover; @@ -553,7 +553,7 @@ PDLDocument::buildHoverForCoreConstraint(const ast::CoreConstraintDecl *decl, .Case([&](const ast::AttrConstraintDecl *) { hoverOS << "Attr"; }) .Case([&](const ast::OpConstraintDecl *opCst) { hoverOS << "Op"; - if (Optional name = opCst->getName()) + if (std::optional name = opCst->getName()) hoverOS << "<" << *name << ">"; }) .Case([&](const ast::TypeConstraintDecl *) { hoverOS << "Type"; }) @@ -603,7 +603,7 @@ lsp::Hover PDLDocument::buildHoverForUserConstraintOrRewrite( } // Format the documentation for the decl. - if (Optional doc = getDocumentationFor(sourceMgr, decl)) + if (std::optional doc = getDocumentationFor(sourceMgr, decl)) hoverOS << "\n" << *doc << "\n"; } return hover; @@ -836,7 +836,8 @@ public: } // Format the documentation for the constraint. - if (Optional doc = getDocumentationFor(sourceMgr, cst)) { + if (std::optional doc = + getDocumentationFor(sourceMgr, cst)) { item.documentation = lsp::MarkupContent{lsp::MarkupKind::Markdown, std::move(*doc)}; } @@ -1027,14 +1028,15 @@ public: } // Format the documentation for the callable. - if (Optional doc = getDocumentationFor(sourceMgr, callable)) + if (std::optional doc = + getDocumentationFor(sourceMgr, callable)) signatureInfo.documentation = std::move(*doc); signatureHelp.signatures.emplace_back(std::move(signatureInfo)); } void - codeCompleteOperationOperandsSignature(Optional opName, + codeCompleteOperationOperandsSignature(std::optional opName, unsigned currentNumOperands) final { const ods::Operation *odsOp = opName ? odsContext.lookupOperation(*opName) : nullptr; @@ -1043,7 +1045,7 @@ public: currentNumOperands, "operand", "Value"); } - void codeCompleteOperationResultsSignature(Optional opName, + void codeCompleteOperationResultsSignature(std::optional opName, unsigned currentNumResults) final { const ods::Operation *odsOp = opName ? odsContext.lookupOperation(*opName) : nullptr; @@ -1053,7 +1055,7 @@ public: } void codeCompleteOperationOperandOrResultSignature( - Optional opName, const ods::Operation *odsOp, + std::optional opName, const ods::Operation *odsOp, ArrayRef values, unsigned currentValue, StringRef label, StringRef dataType) { signatureHelp.activeParameter = currentValue; @@ -1731,7 +1733,7 @@ void lsp::PDLLServer::updateDocument( impl->files.erase(it); } -Optional lsp::PDLLServer::removeDocument(const URIForFile &uri) { +std::optional lsp::PDLLServer::removeDocument(const URIForFile &uri) { auto it = impl->files.find(uri.file()); if (it == impl->files.end()) return std::nullopt; diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h index 68c807f..682c7b5 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h @@ -68,7 +68,7 @@ public: /// Remove the document with the given uri. Returns the version of the removed /// document, or std::nullopt if the uri did not have a corresponding document /// within the server. - Optional removeDocument(const URIForFile &uri); + std::optional removeDocument(const URIForFile &uri); /// Return the locations of the object pointed at by the given position. void getLocationsOf(const URIForFile &uri, const Position &defPos, diff --git a/mlir/lib/Tools/mlir-translate/Translation.cpp b/mlir/lib/Tools/mlir-translate/Translation.cpp index 2f578186..a39a467 100644 --- a/mlir/lib/Tools/mlir-translate/Translation.cpp +++ b/mlir/lib/Tools/mlir-translate/Translation.cpp @@ -50,7 +50,7 @@ static llvm::StringMap &getTranslationRegistry() { /// Register the given translation. static void registerTranslation(StringRef name, StringRef description, - Optional inputAlignment, + std::optional inputAlignment, const TranslateFunction &function) { auto ®istry = getTranslationRegistry(); if (registry.count(name)) @@ -76,7 +76,7 @@ TranslateRegistration::TranslateRegistration( static void registerTranslateToMLIRFunction( StringRef name, StringRef description, const DialectRegistrationFunction &dialectRegistration, - Optional inputAlignment, + std::optional inputAlignment, const TranslateSourceMgrToMLIRFunction &function) { auto wrappedFn = [function, dialectRegistration]( const std::shared_ptr &sourceMgr, @@ -97,7 +97,7 @@ TranslateToMLIRRegistration::TranslateToMLIRRegistration( StringRef name, StringRef description, const TranslateSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration, - Optional inputAlignment) { + std::optional inputAlignment) { registerTranslateToMLIRFunction(name, description, dialectRegistration, inputAlignment, function); } @@ -105,7 +105,7 @@ TranslateToMLIRRegistration::TranslateToMLIRRegistration( StringRef name, StringRef description, const TranslateRawSourceMgrToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration, - Optional inputAlignment) { + std::optional inputAlignment) { registerTranslateToMLIRFunction( name, description, dialectRegistration, inputAlignment, [function](const std::shared_ptr &sourceMgr, @@ -117,7 +117,7 @@ TranslateToMLIRRegistration::TranslateToMLIRRegistration( StringRef name, StringRef description, const TranslateStringRefToMLIRFunction &function, const DialectRegistrationFunction &dialectRegistration, - Optional inputAlignment) { + std::optional inputAlignment) { registerTranslateToMLIRFunction( name, description, dialectRegistration, inputAlignment, [function](const std::shared_ptr &sourceMgr, diff --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp index c8445ad..81fb5a01 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp +++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp @@ -127,7 +127,8 @@ void LSPServer::onDocumentDidOpen(const DidOpenTextDocumentParams ¶ms) { publishDiagnostics(diagParams); } void LSPServer::onDocumentDidClose(const DidCloseTextDocumentParams ¶ms) { - Optional version = server.removeDocument(params.textDocument.uri); + std::optional version = + server.removeDocument(params.textDocument.uri); if (!version) return; diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp index 55a3402..33d20c9 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp +++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp @@ -55,7 +55,7 @@ static lsp::Location getLocationFromLoc(llvm::SourceMgr &mgr, SMLoc loc, } /// Convert the given TableGen diagnostic to the LSP form. -static Optional +static std::optional getLspDiagnoticFromDiag(const llvm::SMDiagnostic &diag, const lsp::URIForFile &uri) { auto *sourceMgr = const_cast(diag.getSourceMgr()); @@ -583,7 +583,7 @@ lsp::Hover TableGenTextFile::buildHoverForRecord(const llvm::Record *record, printAndFormatField("description"); // Check for documentation in the source file. - if (Optional doc = + if (std::optional doc = lsp::extractSourceDocComment(sourceMgr, record->getLoc().front())) { hoverOS << "\n" << *doc << "\n"; } @@ -618,7 +618,7 @@ lsp::Hover TableGenTextFile::buildHoverForField(const llvm::Record *record, hoverOS << "`\n***\n"; // Check for documentation in the source file. - if (Optional doc = + if (std::optional doc = lsp::extractSourceDocComment(sourceMgr, value->getLoc())) { hoverOS << "\n" << *doc << "\n"; hoverOS << "\n***\n"; @@ -628,7 +628,7 @@ lsp::Hover TableGenTextFile::buildHoverForField(const llvm::Record *record, // documentation. auto [baseRecord, baseValue] = getBaseValue(record, value); if (baseValue) { - if (Optional doc = + if (std::optional doc = lsp::extractSourceDocComment(sourceMgr, baseValue->getLoc())) { hoverOS << "\n *From `" << baseRecord->getName() << "`*:\n\n" << *doc << "\n"; @@ -691,7 +691,8 @@ void lsp::TableGenServer::updateDocument( impl->files.erase(it); } -Optional lsp::TableGenServer::removeDocument(const URIForFile &uri) { +std::optional +lsp::TableGenServer::removeDocument(const URIForFile &uri) { auto it = impl->files.find(uri.file()); if (it == impl->files.end()) return std::nullopt; diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h index d8c79e7..d749a4f 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h +++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h @@ -60,7 +60,7 @@ public: /// Remove the document with the given uri. Returns the version of the removed /// document, or std::nullopt if the uri did not have a corresponding document /// within the server. - Optional removeDocument(const URIForFile &uri); + std::optional removeDocument(const URIForFile &uri); /// Return the locations of the object pointed at by the given position. void getLocationsOf(const URIForFile &uri, const Position &defPos, diff --git a/mlir/lib/Transforms/LocationSnapshot.cpp b/mlir/lib/Transforms/LocationSnapshot.cpp index 44b0560..b85850a 100644 --- a/mlir/lib/Transforms/LocationSnapshot.cpp +++ b/mlir/lib/Transforms/LocationSnapshot.cpp @@ -37,7 +37,7 @@ static void generateLocationsFromIR(raw_ostream &os, StringRef fileName, op->print(os, state); Builder builder(op->getContext()); - Optional tagIdentifier; + std::optional tagIdentifier; if (!tag.empty()) tagIdentifier = builder.getStringAttr(tag); diff --git a/mlir/lib/Transforms/Utils/InliningUtils.cpp b/mlir/lib/Transforms/Utils/InliningUtils.cpp index e47ce04..f9dc69c 100644 --- a/mlir/lib/Transforms/Utils/InliningUtils.cpp +++ b/mlir/lib/Transforms/Utils/InliningUtils.cpp @@ -145,8 +145,8 @@ static LogicalResult inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, Block::iterator inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc, bool shouldCloneInlinedRegion, - Operation *call = nullptr) { + std::optional inlineLoc, + bool shouldCloneInlinedRegion, Operation *call = nullptr) { assert(resultsToReplace.size() == regionResultTypes.size()); // We expect the region to have at least one block. if (src->empty()) @@ -233,7 +233,7 @@ inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, static LogicalResult inlineRegionImpl(InlinerInterface &interface, Region *src, Block *inlineBlock, Block::iterator inlinePoint, ValueRange inlinedOperands, - ValueRange resultsToReplace, Optional inlineLoc, + ValueRange resultsToReplace, std::optional inlineLoc, bool shouldCloneInlinedRegion, Operation *call = nullptr) { // We expect the region to have at least one block. if (src->empty()) @@ -264,7 +264,7 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc, + std::optional inlineLoc, bool shouldCloneInlinedRegion) { return inlineRegion(interface, src, inlinePoint->getBlock(), ++inlinePoint->getIterator(), mapper, resultsToReplace, @@ -275,7 +275,7 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, Block::iterator inlinePoint, IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes, - Optional inlineLoc, + std::optional inlineLoc, bool shouldCloneInlinedRegion) { return inlineRegionImpl(interface, src, inlineBlock, inlinePoint, mapper, resultsToReplace, regionResultTypes, inlineLoc, @@ -286,17 +286,19 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, ValueRange inlinedOperands, ValueRange resultsToReplace, - Optional inlineLoc, + std::optional inlineLoc, bool shouldCloneInlinedRegion) { return inlineRegion(interface, src, inlinePoint->getBlock(), ++inlinePoint->getIterator(), inlinedOperands, resultsToReplace, inlineLoc, shouldCloneInlinedRegion); } -LogicalResult -mlir::inlineRegion(InlinerInterface &interface, Region *src, Block *inlineBlock, - Block::iterator inlinePoint, ValueRange inlinedOperands, - ValueRange resultsToReplace, Optional inlineLoc, - bool shouldCloneInlinedRegion) { +LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, + Block *inlineBlock, + Block::iterator inlinePoint, + ValueRange inlinedOperands, + ValueRange resultsToReplace, + std::optional inlineLoc, + bool shouldCloneInlinedRegion) { return inlineRegionImpl(interface, src, inlineBlock, inlinePoint, inlinedOperands, resultsToReplace, inlineLoc, shouldCloneInlinedRegion); diff --git a/mlir/lib/Transforms/ViewOpGraph.cpp b/mlir/lib/Transforms/ViewOpGraph.cpp index 92505e5..186118b 100644 --- a/mlir/lib/Transforms/ViewOpGraph.cpp +++ b/mlir/lib/Transforms/ViewOpGraph.cpp @@ -34,7 +34,8 @@ static const StringRef kShapeNone = "plain"; /// Return the size limits for eliding large attributes. static int64_t getLargeAttributeSizeLimit() { // Use the default from the printer flags if possible. - if (Optional limit = OpPrintingFlags().getLargeElementsAttrLimit()) + if (std::optional limit = + OpPrintingFlags().getLargeElementsAttrLimit()) return *limit; return 16; } @@ -70,11 +71,11 @@ namespace { /// cluster, an invisible "anchor" node is created. struct Node { public: - Node(int id = 0, Optional clusterId = std::nullopt) + Node(int id = 0, std::optional clusterId = std::nullopt) : id(id), clusterId(clusterId) {} int id; - Optional clusterId; + std::optional clusterId; }; /// This pass generates a Graphviz dataflow visualization of an MLIR operation. @@ -254,7 +255,7 @@ private: valueToNode[blockArg] = emitNodeStmt(getLabel(blockArg)); // Emit a node for each operation. - Optional prevNode; + std::optional prevNode; for (Operation &op : block) { Node nextNode = processOperation(&op); if (printControlFlowEdges && prevNode) diff --git a/mlir/test/lib/Analysis/DataFlow/TestDenseDataFlowAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestDenseDataFlowAnalysis.cpp index e79e690..f885440 100644 --- a/mlir/test/lib/Analysis/DataFlow/TestDenseDataFlowAnalysis.cpp +++ b/mlir/test/lib/Analysis/DataFlow/TestDenseDataFlowAnalysis.cpp @@ -102,7 +102,7 @@ public: /// Get the last modifications of a value. Returns none if the last /// modifications are not known. - Optional> getLastModifiers(Value value) const { + std::optional> getLastModifiers(Value value) const { auto it = lastMods.find(value); if (it == lastMods.end()) return {}; @@ -260,7 +260,7 @@ struct TestLastModifiedPass return solver.lookupState(value); }); assert(value && "expected an underlying value"); - if (Optional> lastMod = + if (std::optional> lastMod = lastMods->getLastModifiers(value)) { for (Operation *lastModifier : *lastMod) { if (auto tagName = diff --git a/mlir/test/lib/Analysis/TestDataFlowFramework.cpp b/mlir/test/lib/Analysis/TestDataFlowFramework.cpp index ecacc36..0044924 100644 --- a/mlir/test/lib/Analysis/TestDataFlowFramework.cpp +++ b/mlir/test/lib/Analysis/TestDataFlowFramework.cpp @@ -62,7 +62,7 @@ public: private: /// An optional integer value. - Optional state; + std::optional state; }; /// This analysis computes `FooState` across operations and control-flow edges. diff --git a/mlir/test/lib/Dialect/Shape/TestShapeMappingAnalysis.cpp b/mlir/test/lib/Dialect/Shape/TestShapeMappingAnalysis.cpp index d3c5fa4..391cb50 100644 --- a/mlir/test/lib/Dialect/Shape/TestShapeMappingAnalysis.cpp +++ b/mlir/test/lib/Dialect/Shape/TestShapeMappingAnalysis.cpp @@ -24,7 +24,7 @@ struct TestShapeMappingPass return "Print the contents of a constructed shape mapping information."; } void runOnOperation() override { - llvm::Optional> + std::optional> maybeAnalysis = getCachedAnalysis(); if (maybeAnalysis.has_value()) maybeAnalysis->get().print(llvm::errs()); diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index 56e6bd2..e62d5a8 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -956,7 +956,7 @@ ParseResult PrettyPrintedRegionOp::parse(OpAsmParser &parser, StringAttr innerOpName = parseOpNameInfo->getIdentifier(); FunctionType opFntype; - Optional explicitLoc; + std::optional explicitLoc; if (parser.parseKeyword("end") || parser.parseColon() || parser.parseType(opFntype) || parser.parseOptionalLocationSpecifier(explicitLoc)) @@ -1059,7 +1059,7 @@ void PolyForOp::getAsmBlockArgumentNames(Region ®ion, //===----------------------------------------------------------------------===// static ParseResult parseOptionalLoc(OpAsmParser &p, Attribute &loc) { - Optional result; + std::optional result; SMLoc sourceLoc = p.getCurrentLocation(); if (p.parseOptionalLocationSpecifier(result)) return failure(); diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td index 81280d8..72e857c 100644 --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -219,7 +219,7 @@ def TestTypeStructCaptureAll : Test_Type<"TestStructTypeCaptureAll"> { def TestTypeOptionalParam : Test_Type<"TestTypeOptionalParam"> { let parameters = (ins - OptionalParameter<"mlir::Optional">:$a, + OptionalParameter<"std::optional">:$a, "int":$b, DefaultValuedParameter<"std::optional<::mlir::Attribute>", "std::nullopt">:$c @@ -229,7 +229,7 @@ def TestTypeOptionalParam : Test_Type<"TestTypeOptionalParam"> { } def TestTypeOptionalParams : Test_Type<"TestTypeOptionalParams"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, + let parameters = (ins OptionalParameter<"std::optional">:$a, StringRefParameter<>:$b); let mnemonic = "optional_params"; let assemblyFormat = "`<` params `>`"; @@ -238,48 +238,48 @@ def TestTypeOptionalParams : Test_Type<"TestTypeOptionalParams"> { def TestTypeOptionalParamsAfterRequired : Test_Type<"TestTypeOptionalParamsAfterRequired"> { let parameters = (ins StringRefParameter<>:$a, - OptionalParameter<"mlir::Optional">:$b); + OptionalParameter<"std::optional">:$b); let mnemonic = "optional_params_after"; let assemblyFormat = "`<` params `>`"; } def TestTypeOptionalStruct : Test_Type<"TestTypeOptionalStruct"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, + let parameters = (ins OptionalParameter<"std::optional">:$a, StringRefParameter<>:$b); let mnemonic = "optional_struct"; let assemblyFormat = "`<` struct(params) `>`"; } def TestTypeAllOptionalParams : Test_Type<"TestTypeAllOptionalParams"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, - OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins OptionalParameter<"std::optional">:$a, + OptionalParameter<"std::optional">:$b); let mnemonic = "all_optional_params"; let assemblyFormat = "`<` params `>`"; } def TestTypeAllOptionalStruct : Test_Type<"TestTypeAllOptionalStruct"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, - OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins OptionalParameter<"std::optional">:$a, + OptionalParameter<"std::optional">:$b); let mnemonic = "all_optional_struct"; let assemblyFormat = "`<` struct(params) `>`"; } def TestTypeOptionalGroup : Test_Type<"TestTypeOptionalGroup"> { - let parameters = (ins "int":$a, OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins "int":$a, OptionalParameter<"std::optional">:$b); let mnemonic = "optional_group"; let assemblyFormat = "`<` (`(` $b^ `)`) : (`x`)? $a `>`"; } def TestTypeOptionalGroupParams : Test_Type<"TestTypeOptionalGroupParams"> { - let parameters = (ins DefaultValuedParameter<"mlir::Optional", "10">:$a, - OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins DefaultValuedParameter<"std::optional", "10">:$a, + OptionalParameter<"std::optional">:$b); let mnemonic = "optional_group_params"; let assemblyFormat = "`<` (`(` params^ `)`) : (`x`)? `>`"; } def TestTypeOptionalGroupStruct : Test_Type<"TestTypeOptionalGroupStruct"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, - OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins OptionalParameter<"std::optional">:$a, + OptionalParameter<"std::optional">:$b); let mnemonic = "optional_group_struct"; let assemblyFormat = "`<` (`(` struct(params)^ `)`) : (`x`)? `>`"; } @@ -322,7 +322,7 @@ def TestTypeDefaultValuedType : Test_Type<"TestTypeDefaultValuedType"> { } def TestTypeCustom : Test_Type<"TestTypeCustom"> { - let parameters = (ins "int":$a, OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins "int":$a, OptionalParameter<"std::optional">:$b); let mnemonic = "custom_type"; let assemblyFormat = [{ `<` custom($a) `` custom(ref($a), $b) `>` }]; @@ -343,14 +343,14 @@ def TestTypeCustomString : Test_Type<"TestTypeCustomString"> { } def TestTypeElseAnchor : Test_Type<"TestTypeElseAnchor"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a); + let parameters = (ins OptionalParameter<"std::optional">:$a); let mnemonic = "else_anchor"; let assemblyFormat = "`<` (`?`) : ($a^)? `>`"; } def TestTypeElseAnchorStruct : Test_Type<"TestTypeElseAnchorStruct"> { - let parameters = (ins OptionalParameter<"mlir::Optional">:$a, - OptionalParameter<"mlir::Optional">:$b); + let parameters = (ins OptionalParameter<"std::optional">:$a, + OptionalParameter<"std::optional">:$b); let mnemonic = "else_anchor_struct"; let assemblyFormat = "`<` (`?`) : (struct($a, $b)^)? `>`"; } diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp index 067c9b2..4d5c9b8 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.cpp +++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp @@ -98,7 +98,7 @@ static LogicalResult parseCustomTypeA(AsmParser &parser, static void printCustomTypeA(AsmPrinter &printer, int a) { printer << a; } static LogicalResult parseCustomTypeB(AsmParser &parser, int a, - FailureOr> &bResult) { + FailureOr> &bResult) { if (a < 0) return success(); for (int i : llvm::seq(0, a)) @@ -108,7 +108,7 @@ static LogicalResult parseCustomTypeB(AsmParser &parser, int a, return parser.parseInteger(**bResult); } -static void printCustomTypeB(AsmPrinter &printer, int a, Optional b) { +static void printCustomTypeB(AsmPrinter &printer, int a, std::optional b) { if (a < 0) return; printer << ' '; diff --git a/mlir/test/lib/Dialect/Test/TestTypes.h b/mlir/test/lib/Dialect/Test/TestTypes.h index bb3751d..b6a7e27 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.h +++ b/mlir/test/lib/Dialect/Test/TestTypes.h @@ -74,9 +74,9 @@ inline mlir::AsmPrinter &operator<<(mlir::AsmPrinter &printer, /// Overload the attribute parameter parser for optional integers. template <> -struct FieldParser> { - static FailureOr> parse(AsmParser &parser) { - Optional value; +struct FieldParser> { + static FailureOr> parse(AsmParser &parser) { + std::optional value; value.emplace(); OptionalParseResult result = parser.parseOptionalInteger(*value); if (result.has_value()) { diff --git a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp index b0f11ff..68edea5e 100644 --- a/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp +++ b/mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp @@ -73,7 +73,7 @@ struct TestVectorToVectorLowering private: // Return the target shape based on op type. - static Optional> getShape(Operation *op) { + static std::optional> getShape(Operation *op) { if (isa(op)) return SmallVector(2, 2); if (isa(op)) @@ -315,7 +315,7 @@ struct TestVectorUnrollingPatterns if (unrollBasedOnType) { UnrollVectorOptions::NativeShapeFnType nativeShapeFn = - [](Operation *op) -> Optional> { + [](Operation *op) -> std::optional> { vector::ContractionOp contractOp = cast(op); SmallVector nativeShape(contractOp.getIteratorTypes().size(), 4); @@ -330,17 +330,20 @@ struct TestVectorUnrollingPatterns [](Operation *op) { return success(isa(op)); }); if (!unrollOrder.empty()) { - opts.setUnrollTraversalOrderFn([this](Operation *op) - -> Optional> { - vector::ContractionOp contractOp = cast(op); - if (contractOp.getIteratorTypes().size() == unrollOrder.size()) - return SmallVector(unrollOrder.begin(), unrollOrder.end()); - return std::nullopt; - }); + opts.setUnrollTraversalOrderFn( + [this](Operation *op) -> std::optional> { + vector::ContractionOp contractOp = + cast(op); + if (contractOp.getIteratorTypes().size() == unrollOrder.size()) + return SmallVector(unrollOrder.begin(), + unrollOrder.end()); + return std::nullopt; + }); } populateVectorUnrollPatterns(patterns, opts); } else { - auto nativeShapeFn = [](Operation *op) -> Optional> { + auto nativeShapeFn = + [](Operation *op) -> std::optional> { auto contractOp = dyn_cast(op); if (!contractOp) return std::nullopt; @@ -398,7 +401,7 @@ struct TestVectorTransferUnrollingPatterns }); if (reverseUnrollOrder.getValue()) { opts.setUnrollTraversalOrderFn( - [](Operation *op) -> Optional> { + [](Operation *op) -> std::optional> { int64_t numLoops = 0; if (auto readOp = dyn_cast(op)) numLoops = readOp.getVectorType().getRank(); diff --git a/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterface.cpp b/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterface.cpp index a7e90d4..d862d0b 100644 --- a/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterface.cpp +++ b/mlir/test/lib/Interfaces/TilingInterface/TestTilingInterface.cpp @@ -51,11 +51,11 @@ struct LinalgTransformationFilter { explicit LinalgTransformationFilter( ArrayRef matchDisjunction = {}, - Optional replacement = std::nullopt); + std::optional replacement = std::nullopt); explicit LinalgTransformationFilter( const FilterFunction &f, ArrayRef matchDisjunction = {}, - Optional replacement = std::nullopt); + std::optional replacement = std::nullopt); LinalgTransformationFilter(LinalgTransformationFilter &&) = default; LinalgTransformationFilter(const LinalgTransformationFilter &) = default; @@ -89,14 +89,15 @@ struct LinalgTransformationFilter { private: SmallVector filters; SmallVector matchDisjunction; - Optional replacement; + std::optional replacement; /// When set to true, if the attribute is not set, it will be treated as /// a match. Default is false. bool matchByDefault; }; LinalgTransformationFilter::LinalgTransformationFilter( - ArrayRef matchDisjunction, Optional replacement) + ArrayRef matchDisjunction, + std::optional replacement) : matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()), replacement(replacement), matchByDefault(false) {} diff --git a/mlir/test/lib/Transforms/TestIntRangeInference.cpp b/mlir/test/lib/Transforms/TestIntRangeInference.cpp index cb4ce71..64ff4ce 100644 --- a/mlir/test/lib/Transforms/TestIntRangeInference.cpp +++ b/mlir/test/lib/Transforms/TestIntRangeInference.cpp @@ -30,7 +30,7 @@ static LogicalResult replaceWithConstant(DataFlowSolver &solver, OpBuilder &b, return failure(); const ConstantIntRanges &inferredRange = maybeInferredRange->getValue().getValue(); - Optional maybeConstValue = inferredRange.getConstantValue(); + std::optional maybeConstValue = inferredRange.getConstantValue(); if (!maybeConstValue.has_value()) return failure(); diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp index d92c367..fdb5c2a 100644 --- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp +++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp @@ -393,7 +393,7 @@ static std::string interleaveToString(Container &container, return result; } -static Optional +static std::optional findTensorDefArgIndex(StringRef name, SmallVectorImpl &args) { for (const auto &it : llvm::enumerate(args)) { if (it.value().name == name) @@ -403,7 +403,7 @@ findTensorDefArgIndex(StringRef name, SmallVectorImpl &args) { } // Try to map the TypeVar to a predefined or an argument type. -static Optional +static std::optional findTypeValue(StringRef typeVar, SmallVectorImpl &args) { // Handle all predefined types. if (typeVar == "I32") @@ -1056,12 +1056,13 @@ if ({1}Iter != attrs.end()) {{ ++generatedAssignmentCount; // Recursively generate the expression. - std::function(ScalarExpression &)> + std::function(ScalarExpression &)> generateExpression = - [&](ScalarExpression &expression) -> Optional { + [&](ScalarExpression &expression) -> std::optional { if (expression.arg) { // Argument reference. - Optional argIndex = findTensorDefArgIndex(*expression.arg, args); + std::optional argIndex = + findTensorDefArgIndex(*expression.arg, args); if (!argIndex) { emitError(genContext.getLoc()) << "scalar argument not defined on the op: " << *expression.arg; @@ -1111,7 +1112,7 @@ if ({1}Iter != attrs.end()) {{ SmallVector operandCppValues; if (expression.scalarFn->kind == ScalarFnKind::Type) { assert(expression.scalarFn->typeVar.has_value()); - Optional typeCppValue = + std::optional typeCppValue = findTypeValue(*expression.scalarFn->typeVar, args); if (!typeCppValue) { emitError(genContext.getLoc()) @@ -1141,7 +1142,8 @@ if ({1}Iter != attrs.end()) {{ emitError(genContext.getLoc()) << "unknown ScalarExpression type"; return std::nullopt; }; - Optional cppValue = generateExpression(assignment->value); + std::optional cppValue = + generateExpression(assignment->value); if (!cppValue) return failure(); stmts.push_back(llvm::formatv("yields.push_back({0});", *cppValue)); diff --git a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp index 67c8b6d..abe4bc6 100644 --- a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp +++ b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp @@ -925,7 +925,7 @@ static void emitOperandDeserialization(const Operator &op, ArrayRef loc, if (valueArg->isVariableLength()) { if (i != e - 1) { PrintFatalError(loc, "SPIR-V ops can have Variadic<..> or " - "Optional<...> arguments only if " + "std::optional<...> arguments only if " "it's the last argument"); } os << tabs diff --git a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp index b3d6d54..cc55b96 100644 --- a/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp +++ b/mlir/unittests/Analysis/Presburger/IntegerPolyhedronTest.cpp @@ -60,7 +60,7 @@ static void dump(ArrayRef vec) { /// opposite of hasSample. static void checkSample(bool hasSample, const IntegerPolyhedron &poly, TestFunction fn = TestFunction::Sample) { - Optional> maybeSample; + std::optional> maybeSample; MaybeOptimum> maybeLexMin; switch (fn) { case TestFunction::Sample: @@ -1404,8 +1404,8 @@ TEST(IntegerPolyhedronTest, findSymbolicIntegerLexMin) { static void expectComputedVolumeIsValidOverapprox(const IntegerPolyhedron &poly, - Optional trueVolume, - Optional resultBound) { + std::optional trueVolume, + std::optional resultBound) { expectComputedVolumeIsValidOverapprox(poly.computeVolume(), trueVolume, resultBound); } diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp index 17feea0..25aa63f 100644 --- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp @@ -755,8 +755,8 @@ TEST(SetTest, coalesceDivOtherContained) { static void expectComputedVolumeIsValidOverapprox(const PresburgerSet &set, - Optional trueVolume, - Optional resultBound) { + std::optional trueVolume, + std::optional resultBound) { expectComputedVolumeIsValidOverapprox(set.computeVolume(), trueVolume, resultBound); } diff --git a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp index 8524826..2f4fa27 100644 --- a/mlir/unittests/Analysis/Presburger/SimplexTest.cpp +++ b/mlir/unittests/Analysis/Presburger/SimplexTest.cpp @@ -572,7 +572,7 @@ TEST(SimplexTest, addDivisionVariable) { simplex.addDivisionVariable(getMPIntVec({1, 0}), MPInt(2)); addInequality(simplex, {1, 0, -3}); // x >= 3. addInequality(simplex, {-1, 0, 9}); // x <= 9. - Optional> sample = simplex.findIntegerSample(); + std::optional> sample = simplex.findIntegerSample(); ASSERT_TRUE(sample.has_value()); EXPECT_EQ((*sample)[0] / 2, (*sample)[1]); } diff --git a/mlir/unittests/Analysis/Presburger/Utils.h b/mlir/unittests/Analysis/Presburger/Utils.h index e18f0eb..c3246a0 100644 --- a/mlir/unittests/Analysis/Presburger/Utils.h +++ b/mlir/unittests/Analysis/Presburger/Utils.h @@ -41,7 +41,8 @@ inline Matrix makeMatrix(unsigned numRow, unsigned numColumns, /// lhs and rhs represent non-negative integers or positive infinity. The /// infinity case corresponds to when the Optional is empty. -inline bool infinityOrUInt64LE(Optional lhs, Optional rhs) { +inline bool infinityOrUInt64LE(std::optional lhs, + std::optional rhs) { // No constraint. if (!rhs) return true; @@ -54,20 +55,19 @@ inline bool infinityOrUInt64LE(Optional lhs, Optional rhs) { /// Expect that the computed volume is a valid overapproximation of /// the true volume `trueVolume`, while also being at least as good an /// approximation as `resultBound`. -inline void -expectComputedVolumeIsValidOverapprox(const Optional &computedVolume, - const Optional &trueVolume, - const Optional &resultBound) { +inline void expectComputedVolumeIsValidOverapprox( + const std::optional &computedVolume, + const std::optional &trueVolume, + const std::optional &resultBound) { assert(infinityOrUInt64LE(trueVolume, resultBound) && "can't expect result to be less than the true volume"); EXPECT_TRUE(infinityOrUInt64LE(trueVolume, computedVolume)); EXPECT_TRUE(infinityOrUInt64LE(computedVolume, resultBound)); } -inline void -expectComputedVolumeIsValidOverapprox(const Optional &computedVolume, - Optional trueVolume, - Optional resultBound) { +inline void expectComputedVolumeIsValidOverapprox( + const std::optional &computedVolume, + std::optional trueVolume, std::optional resultBound) { expectComputedVolumeIsValidOverapprox( computedVolume, llvm::transformOptional(trueVolume, mpintFromInt64), llvm::transformOptional(resultBound, mpintFromInt64)); diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp index c4af61b..13c7762 100644 --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -272,7 +272,7 @@ static void checkNativeAccess(MLIRContext *ctx, ArrayRef data, UnmanagedAsmResourceBlob::allocateInferAlign(data)); // Check that we can access and iterate the data properly. - Optional> attrData = attr.tryGetAsArrayRef(); + std::optional> attrData = attr.tryGetAsArrayRef(); EXPECT_TRUE(attrData.has_value()); EXPECT_EQ(*attrData, data); -- 2.7.4