[mlir][CAPI] Add mlirOpOperandGetValue (#75032)

This commit is contained in:
Shenghang Tsai 2023-12-11 19:32:21 +08:00 committed by GitHub
parent 3764f5e816
commit dc2ce60024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -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);