diff --git a/mlir/include/mlir-c/Support.h b/mlir/include/mlir-c/Support.h --- a/mlir/include/mlir-c/Support.h +++ b/mlir/include/mlir-c/Support.h @@ -56,35 +56,11 @@ /** A logical result value, essentially a boolean with named states. LLVM * convention for using boolean values to designate success or failure of an - * operation is a moving target, so MLIR opted for an explicit class. - * Instances of MlirLogicalResult must only be inspected using the associated - * functions. */ -struct MlirLogicalResult { - int8_t value; -}; -typedef struct MlirLogicalResult MlirLogicalResult; - -/** Checks if the given logical result represents a success. */ -inline int mlirLogicalResultIsSuccess(MlirLogicalResult res) { - return res.value != 0; -} - -/** Checks if the given logical result represents a failure. */ -inline int mlirLogicalResultIsFailure(MlirLogicalResult res) { - return res.value == 0; -} - -/** Creates a logical result representing a success. */ -inline static MlirLogicalResult mlirLogicalResultSuccess() { - MlirLogicalResult res = {1}; - return res; -} - -/** Creates a logical result representing a failure. */ -inline static MlirLogicalResult mlirLogicalResultFailure() { - MlirLogicalResult res = {0}; - return res; -} + * operation is a moving target, so MLIR opted for an explicit class. In C API, + * this is reflected as a two-element enum that is expected to be used in + * conjunction with explicit checks. */ +enum MlirLogicalResult { MlirLogicalResultFailure, MlirLogicalResultSuccess }; +typedef enum MlirLogicalResult MlirLogicalResult; #ifdef __cplusplus } diff --git a/mlir/include/mlir/CAPI/Support.h b/mlir/include/mlir/CAPI/Support.h --- a/mlir/include/mlir/CAPI/Support.h +++ b/mlir/include/mlir/CAPI/Support.h @@ -31,12 +31,12 @@ inline MlirLogicalResult wrap(mlir::LogicalResult res) { if (mlir::succeeded(res)) - return mlirLogicalResultSuccess(); - return mlirLogicalResultFailure(); + return MlirLogicalResultSuccess; + return MlirLogicalResultFailure; } inline mlir::LogicalResult unwrap(MlirLogicalResult res) { - return mlir::success(mlirLogicalResultIsSuccess(res)); + return mlir::success(res == MlirLogicalResultSuccess); } #endif // MLIR_CAPI_SUPPORT_H diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -837,7 +837,7 @@ mlirLocationPrint(loc, printToStderr, NULL); assert(mlirDiagnosticGetNumNotes(diagnostic) == 0); fprintf(stderr, ">> end of diagnostic\n"); - return mlirLogicalResultSuccess(); + return MlirLogicalResultSuccess; } void testDiagnostics() {