diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index 413eaa6aa3fe..82da511f807a 100644 --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -940,6 +940,9 @@ MLIR_CAPI_EXPORTED void mlirValueReplaceAllUsesOfWith(MlirValue of, /// Returns whether the op operand is null. MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand); +/// Returns the value of an op operand. +MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand); + /// Returns the owner operation of an op operand. MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand); diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp index d1ee1b774c34..ac9889df11f8 100644 --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -986,6 +986,10 @@ MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand) { return wrap(unwrap(opOperand)->getOwner()); } +MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand) { + return wrap(unwrap(opOperand)->get()); +} + unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand) { return unwrap(opOperand)->getOperandNumber(); } diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c index 315458a08b61..a9850c0a132e 100644 --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -1970,6 +1970,15 @@ int testOperands(void) { fprintf(stderr, "\n"); // CHECK: Second replacement use owner: "dummy.op2" + MlirOpOperand use5 = mlirValueGetFirstUse(constTwoValue); + MlirOpOperand use6 = mlirOpOperandGetNextUse(use5); + if (!mlirValueEqual(mlirOpOperandGetValue(use5), + mlirOpOperandGetValue(use6))) { + fprintf(stderr, + "ERROR: First and second operand should share the same value\n"); + return 5; + } + mlirOperationDestroy(op); mlirOperationDestroy(op2); mlirOperationDestroy(constZero);