diff --git a/mlir/include/mlir/Support/LogicalResult.h b/llvm/include/llvm/Support/LogicalResult.h copy from mlir/include/mlir/Support/LogicalResult.h copy to llvm/include/llvm/Support/LogicalResult.h --- a/mlir/include/mlir/Support/LogicalResult.h +++ b/llvm/include/llvm/Support/LogicalResult.h @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#ifndef MLIR_SUPPORT_LOGICALRESULT_H -#define MLIR_SUPPORT_LOGICALRESULT_H +#ifndef LLVM_SUPPORT_LOGICALRESULT_H +#define LLVM_SUPPORT_LOGICALRESULT_H -#include "mlir/Support/LLVM.h" #include "llvm/ADT/Optional.h" -namespace mlir { +namespace llvm { /// This class represents an efficient way to signal success or failure. It /// should be preferred over the use of `bool` when appropriate, as it avoids @@ -74,8 +73,7 @@ /// This class provides support for representing a failure result, or a valid /// value of type `T`. This allows for integrating with LogicalResult, while /// also providing a value on the success path. -template -class LLVM_NODISCARD FailureOr : public Optional { +template class LLVM_NODISCARD FailureOr : public Optional { public: /// Allow constructing from a LogicalResult. The result *must* be a failure. /// Success results should use a proper instance of type `T`. @@ -99,25 +97,6 @@ using Optional::has_value; }; -/// This class represents success/failure for parsing-like operations that find -/// it important to chain together failable operations with `||`. This is an -/// extended version of `LogicalResult` that allows for explicit conversion to -/// bool. -/// -/// This class should not be used for general error handling cases - we prefer -/// to keep the logic explicit with the `succeeded`/`failed` predicates. -/// However, traditional monadic-style parsing logic can sometimes get -/// swallowed up in boilerplate without this, so we provide this for narrow -/// cases where it is important. -/// -class LLVM_NODISCARD ParseResult : public LogicalResult { -public: - ParseResult(LogicalResult result = success()) : LogicalResult(result) {} - - /// Failure is true in a boolean context. - explicit operator bool() const { return failed(); } -}; - -} // namespace mlir +} // namespace llvm -#endif // MLIR_SUPPORT_LOGICALRESULT_H +#endif // LLVM_SUPPORT_LOGICALRESULT_H diff --git a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h --- a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h +++ b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h @@ -14,7 +14,6 @@ namespace mlir { class AffineForOp; class Location; -struct LogicalResult; class OpBuilder; class Pass; class RewritePattern; diff --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h --- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h +++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h @@ -22,7 +22,6 @@ class LLVMTypeConverter; class Location; -struct LogicalResult; class ModuleOp; class Operation; class RewritePatternSet; diff --git a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h --- a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h +++ b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h @@ -13,7 +13,6 @@ namespace mlir { class AffineForOp; class ConversionTarget; -struct LogicalResult; class MLIRContext; class Value; class Operation; diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -32,8 +32,6 @@ class AllocOp; } // namespace memref -struct LogicalResult; - using ReductionLoopMap = DenseMap>; /// Replaces a parallel affine.for op with a 1-d affine.parallel op. `forOp`'s diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h --- a/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h +++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h @@ -9,9 +9,10 @@ #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; class ModuleOp; namespace bufferization { diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h b/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h --- a/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h +++ b/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h @@ -21,7 +21,6 @@ namespace mlir { class AffineMap; -struct LogicalResult; class Operation; class Region; diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h --- a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h +++ b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h @@ -16,7 +16,6 @@ #include "mlir/Support/LLVM.h" namespace mlir { -struct LogicalResult; class Operation; class Value; diff --git a/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h b/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h @@ -21,7 +21,6 @@ class AffineMap; class ConversionTarget; -struct LogicalResult; class MLIRContext; class Region; class RewriterBase; diff --git a/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h b/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h --- a/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h +++ b/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h @@ -18,7 +18,6 @@ namespace mlir { class AffineMap; -struct LogicalResult; class Operation; class OpFoldResult; class RewriterBase; diff --git a/mlir/include/mlir/ExecutionEngine/JitRunner.h b/mlir/include/mlir/ExecutionEngine/JitRunner.h --- a/mlir/include/mlir/ExecutionEngine/JitRunner.h +++ b/mlir/include/mlir/ExecutionEngine/JitRunner.h @@ -18,6 +18,7 @@ #ifndef MLIR_EXECUTIONENGINE_JITRUNNER_H #define MLIR_EXECUTIONENGINE_JITRUNNER_H +#include "mlir/Support/LLVM.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ExecutionEngine/Orc/Core.h" @@ -34,7 +35,6 @@ class DialectRegistry; class ModuleOp; -struct LogicalResult; struct JitRunnerConfig { /// MLIR transformer applied after parsing the input into MLIR IR and before diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -31,7 +31,6 @@ } // namespace detail class Attribute; -struct LogicalResult; class MLIRContext; /// A multi-dimensional affine map diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -24,7 +24,6 @@ namespace mlir { class DiagnosticEngine; -struct LogicalResult; class MLIRContext; class Operation; class OperationName; diff --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h --- a/mlir/include/mlir/IR/ExtensibleDialect.h +++ b/mlir/include/mlir/IR/ExtensibleDialect.h @@ -24,6 +24,7 @@ #include "mlir/IR/DialectInterface.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/OpDefinition.h" +#include "mlir/Support/LLVM.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/StringMap.h" @@ -35,7 +36,6 @@ class ExtensibleDialect; class MLIRContext; class OptionalParseResult; -class ParseResult; namespace detail { struct DynamicAttrStorage; diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -20,6 +20,7 @@ #include "mlir/IR/TypeRange.h" #include "mlir/IR/Types.h" #include "mlir/IR/Value.h" +#include "mlir/Support/LLVM.h" #include "mlir/Support/InterfaceSupport.h" #include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/PointerUnion.h" @@ -45,7 +46,6 @@ class OperandRange; class OperandRangeRange; class OpFoldResult; -class ParseResult; class Pattern; class Region; class ResultRange; diff --git a/mlir/include/mlir/IR/Verifier.h b/mlir/include/mlir/IR/Verifier.h --- a/mlir/include/mlir/IR/Verifier.h +++ b/mlir/include/mlir/IR/Verifier.h @@ -9,8 +9,9 @@ #ifndef MLIR_IR_VERIFIER_H #define MLIR_IR_VERIFIER_H +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; class Operation; /// Perform (potentially expensive) checks of invariants, used to detect diff --git a/mlir/include/mlir/Support/LLVM.h b/mlir/include/mlir/Support/LLVM.h --- a/mlir/include/mlir/Support/LLVM.h +++ b/mlir/include/mlir/Support/LLVM.h @@ -41,6 +41,11 @@ class StringLiteral; class Twine; +// Logical result types. +struct LogicalResult; +template +class FailureOr; + // Containers. template class ArrayRef; @@ -109,6 +114,10 @@ using llvm::StringRef; using llvm::Twine; +// Logical result types. +using llvm::FailureOr; +using llvm::LogicalResult; + // Container Related types // // Containers. diff --git a/mlir/include/mlir/Support/LogicalResult.h b/mlir/include/mlir/Support/LogicalResult.h --- a/mlir/include/mlir/Support/LogicalResult.h +++ b/mlir/include/mlir/Support/LogicalResult.h @@ -10,94 +10,14 @@ #define MLIR_SUPPORT_LOGICALRESULT_H #include "mlir/Support/LLVM.h" -#include "llvm/ADT/Optional.h" +#include "llvm/Support/LogicalResult.h" namespace mlir { -/// This class represents an efficient way to signal success or failure. It -/// should be preferred over the use of `bool` when appropriate, as it avoids -/// all of the ambiguity that arises in interpreting a boolean result. This -/// class is marked as NODISCARD to ensure that the result is processed. Users -/// may explicitly discard a result by using `(void)`, e.g. -/// `(void)functionThatReturnsALogicalResult();`. Given the intended nature of -/// this class, it generally shouldn't be used as the result of functions that -/// very frequently have the result ignored. This class is intended to be used -/// in conjunction with the utility functions below. -struct LLVM_NODISCARD LogicalResult { -public: - /// If isSuccess is true a `success` result is generated, otherwise a - /// 'failure' result is generated. - static LogicalResult success(bool isSuccess = true) { - return LogicalResult(isSuccess); - } - - /// If isFailure is true a `failure` result is generated, otherwise a - /// 'success' result is generated. - static LogicalResult failure(bool isFailure = true) { - return success(!isFailure); - } - - /// Returns true if the provided LogicalResult corresponds to a success value. - bool succeeded() const { return isSuccess; } - - /// Returns true if the provided LogicalResult corresponds to a failure value. - bool failed() const { return !succeeded(); } - -private: - LogicalResult(bool isSuccess) : isSuccess(isSuccess) {} - - /// Boolean indicating if this is a success result, if false this is a - /// failure result. - bool isSuccess; -}; - -/// Utility function to generate a LogicalResult. If isSuccess is true a -/// `success` result is generated, otherwise a 'failure' result is generated. -inline LogicalResult success(bool isSuccess = true) { - return LogicalResult::success(isSuccess); -} - -/// Utility function to generate a LogicalResult. If isFailure is true a -/// `failure` result is generated, otherwise a 'success' result is generated. -inline LogicalResult failure(bool isFailure = true) { - return LogicalResult::failure(isFailure); -} - -/// Utility function that returns true if the provided LogicalResult corresponds -/// to a success value. -inline bool succeeded(LogicalResult result) { return result.succeeded(); } - -/// Utility function that returns true if the provided LogicalResult corresponds -/// to a failure value. -inline bool failed(LogicalResult result) { return result.failed(); } - -/// This class provides support for representing a failure result, or a valid -/// value of type `T`. This allows for integrating with LogicalResult, while -/// also providing a value on the success path. -template -class LLVM_NODISCARD FailureOr : public Optional { -public: - /// Allow constructing from a LogicalResult. The result *must* be a failure. - /// Success results should use a proper instance of type `T`. - FailureOr(LogicalResult result) { - assert(failed(result) && - "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) {} - template ::value> * = nullptr> - FailureOr(const FailureOr &other) - : Optional(failed(other) ? Optional() : 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 llvm::failed; +using llvm::failure; +using llvm::succeeded; +using llvm::success; /// This class represents success/failure for parsing-like operations that find /// it important to chain together failable operations with `||`. This is an diff --git a/mlir/include/mlir/Support/ToolUtilities.h b/mlir/include/mlir/Support/ToolUtilities.h --- a/mlir/include/mlir/Support/ToolUtilities.h +++ b/mlir/include/mlir/Support/ToolUtilities.h @@ -22,7 +22,6 @@ } // namespace llvm namespace mlir { -struct LogicalResult; using ChunkBufferHandler = function_ref chunkBuffer, raw_ostream &os)>; diff --git a/mlir/include/mlir/Target/SPIRV/Serialization.h b/mlir/include/mlir/Target/SPIRV/Serialization.h --- a/mlir/include/mlir/Target/SPIRV/Serialization.h +++ b/mlir/include/mlir/Target/SPIRV/Serialization.h @@ -16,7 +16,6 @@ #include "mlir/Support/LLVM.h" namespace mlir { -struct LogicalResult; class MLIRContext; namespace spirv { diff --git a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h --- a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h +++ b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h @@ -13,9 +13,10 @@ #ifndef MLIR_TOOLS_MLIR_LSP_SERVER_MLIRLSPSERVERMAIN_H #define MLIR_TOOLS_MLIR_LSP_SERVER_MLIRLSPSERVERMAIN_H +#include "mlir/Support/LLVM.h" + namespace mlir { class DialectRegistry; -struct LogicalResult; /// Implementation for tools like `mlir-lsp-server`. /// - registry should contain all the dialects that can be parsed in source IR diff --git a/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h b/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h --- a/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h +++ b/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h @@ -14,8 +14,9 @@ #ifndef MLIR_TOOLS_MLIR_PDLL_LSP_SERVER_MLIRPDLLLSPSERVERMAIN_H #define MLIR_TOOLS_MLIR_PDLL_LSP_SERVER_MLIRPDLLLSPSERVERMAIN_H +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; /// Implementation for tools like `mlir-pdll-lsp-server`. LogicalResult MlirPdllLspServerMain(int argc, char **argv); diff --git a/mlir/include/mlir/Tools/mlir-translate/Translation.h b/mlir/include/mlir/Tools/mlir-translate/Translation.h --- a/mlir/include/mlir/Tools/mlir-translate/Translation.h +++ b/mlir/include/mlir/Tools/mlir-translate/Translation.h @@ -13,6 +13,7 @@ #ifndef MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H #define MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H +#include "mlir/Support/LLVM.h" #include "llvm/Support/CommandLine.h" namespace llvm { @@ -23,7 +24,6 @@ namespace mlir { class DialectRegistry; -struct LogicalResult; class MLIRContext; class ModuleOp; template diff --git a/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h b/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h --- a/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h +++ b/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h @@ -13,8 +13,9 @@ #ifndef MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENLSPSERVERMAIN_H #define MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENLSPSERVERMAIN_H +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; /// Implementation for tools like `tblgen-lsp-server`. LogicalResult TableGenLspServerMain(int argc, char **argv); diff --git a/mlir/include/mlir/Transforms/LocationSnapshot.h b/mlir/include/mlir/Transforms/LocationSnapshot.h --- a/mlir/include/mlir/Transforms/LocationSnapshot.h +++ b/mlir/include/mlir/Transforms/LocationSnapshot.h @@ -21,7 +21,6 @@ namespace mlir { class Location; -struct LogicalResult; class Operation; class OpPrintingFlags; class Pass; diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.h b/mlir/lib/Tools/PDLL/Parser/Lexer.h --- a/mlir/lib/Tools/PDLL/Parser/Lexer.h +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.h @@ -18,7 +18,6 @@ } // namespace llvm namespace mlir { -struct LogicalResult; namespace pdll { class CodeCompleteContext; diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.h b/mlir/lib/Tools/lsp-server-support/Protocol.h --- a/mlir/lib/Tools/lsp-server-support/Protocol.h +++ b/mlir/lib/Tools/lsp-server-support/Protocol.h @@ -35,7 +35,6 @@ #include namespace mlir { -struct LogicalResult; namespace lsp { diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h --- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h @@ -11,8 +11,9 @@ #include +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; namespace lsp { class JSONTransport; diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h --- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h @@ -11,8 +11,9 @@ #include +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; namespace lsp { class JSONTransport; diff --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h --- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h @@ -11,8 +11,9 @@ #include +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; namespace lsp { class JSONTransport; diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -9036,6 +9036,7 @@ ":LoopLikeInterface", ":MemRefDialect", ":Pass", + ":Support", ":TensorDialect", ":Transforms", "//llvm:Support",